From lists at ruby-forum.com Sat Nov 1 01:02:07 2008 From: lists at ruby-forum.com (Pau Cor) Date: Sat, 1 Nov 2008 06:02:07 +0100 Subject: [rspec-users] Cucumber changes between 0.1.8 and edge Message-ID: When I run `rake features` after adding cucumber v0.1.8 to my rails app (as a plugin), I get success. But when I upgrade to edge, I get this error: " |/home/paul/sc/ror/cebu_heroku/vendor/plugins/cucumber/bin/../lib/cucumber/formatters/pretty_formatter.rb:205:in `ljust': no implicit conversion from nil to integer (TypeError)" Full message here: http://pastie.org/305371 Here is my feature file: http://pastie.org/305372 And here are my step definitions: http://pastie.org/305373 I tried looking through http://github.com/aslakhellesoy/cucumber/tree/master/History.txt but I didn't see anything that would help me find the difference. So what changed (and was it meant to)? Thanks, Paul -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Sat Nov 1 07:24:18 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 1 Nov 2008 12:24:18 +0100 Subject: [rspec-users] Cucumber changes between 0.1.8 and edge In-Reply-To: References: Message-ID: <8d961d900811010424t5aebd910h25931058580c2c17@mail.gmail.com> On Sat, Nov 1, 2008 at 6:02 AM, Pau Cor wrote: > When I run `rake features` after adding cucumber v0.1.8 to my rails app > (as a plugin), I get success. But when I upgrade to edge, I get this > error: > > " > |/home/paul/sc/ror/cebu_heroku/vendor/plugins/cucumber/bin/../lib/cucumber/formatters/pretty_formatter.rb:205:in > `ljust': no implicit conversion from nil to integer (TypeError)" > > Full message here: http://pastie.org/305371 > > Here is my feature file: http://pastie.org/305372 > > And here are my step definitions: http://pastie.org/305373 > > I tried looking through > http://github.com/aslakhellesoy/cucumber/tree/master/History.txt but I > didn't see anything that would help me find the difference. > > So what changed (and was it meant to)? > I think you have found a bug. Please put all of the relevant info in a ticket. Cheers, Aslak > Thanks, > Paul > -- > 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 Nov 1 07:42:21 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Sat, 1 Nov 2008 12:42:21 +0100 Subject: [rspec-users] Cucumber changes between 0.1.8 and edge In-Reply-To: References: Message-ID: <2830e8d2e68425af67bec90e0413b6b3@ruby-forum.com> Thanks for such a detailed report! Your steps and features look good to me. I believe this a bug. I think it came about due to some work that was done on aligning Scenario table values. Could you raise a ticket in lighthouse please? http://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/new Thanks, Joseph Wilk --http://www.joesniff.co.uk -- Posted via http://www.ruby-forum.com/. From barry.mitchelson at gmail.com Sat Nov 1 08:51:02 2008 From: barry.mitchelson at gmail.com (Barry Mitchelson) Date: Sat, 1 Nov 2008 12:51:02 +0000 Subject: [rspec-users] Cucumber changes between 0.1.8 and edge In-Reply-To: References: Message-ID: On Sat, Nov 1, 2008 at 5:02 AM, Pau Cor wrote: > When I run `rake features` after adding cucumber v0.1.8 to my rails app > (as a plugin), I get success. But when I upgrade to edge, I get this > error: > > " > > |/home/paul/sc/ror/cebu_heroku/vendor/plugins/cucumber/bin/../lib/cucumber/formatters/pretty_formatter.rb:205:in > `ljust': no implicit conversion from nil to integer (TypeError)" > > Full message here: http://pastie.org/305371 > > Here is my feature file: http://pastie.org/305372 > > And here are my step definitions: http://pastie.org/305373 > > I tried looking through > http://github.com/aslakhellesoy/cucumber/tree/master/History.txt but I > didn't see anything that would help me find the difference. > > So what changed (and was it meant to)? > This sounds like the issue I had here http://rspec.lighthouseapp.com/projects/16211/tickets/60-patch-next_column_index-not-resetting-after-large-tables. Is there a feature running before this one with a scenario table with at least 2 more columns than the one in the failing feature? -------------- next part -------------- An HTML attachment was scrubbed... URL: From vic at civrot.org Sat Nov 1 09:29:23 2008 From: vic at civrot.org (Victor Asteinza) Date: Sat, 1 Nov 2008 06:29:23 -0700 Subject: [rspec-users] Help In-Reply-To: References: Message-ID: <3277DBCC-A7E4-43C9-89EE-85064A860922@civrot.org> Sent from my iPhone. On Oct 31, 2008, at 14:35, 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: Help: Attempts to run specs quitting midstream (Scott Taylor) > 2. Re: Mocks and Refactoring - doing it wrong? (Scott Taylor) > 3. Re: spec'ing the :conditions argument of a find (Matt Wynne) > 4. Re: spec'ing the :conditions argument of a find (Ashley Moran) > 5. described_type (Matt Wynne) > 6. Re: described_type (Pat Maddox) > 7. Re: testing a render layout statement in a controller > (Harry Bishop) > 8. Re: Working outside-in with Cucumber and RSpec (Nick Hoffman) > 9. Fwd: spec_server not working... (Matt Darby) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 30 Oct 2008 21:23:31 -0400 > From: Scott Taylor > Subject: Re: [rspec-users] Help: Attempts to run specs quitting > midstream > To: rspec-users at rubyforge.org > Message-ID: <34EB771B-DED1-4031-A242-F2FC81AE761E at railsnewbie.com> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > > 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 > > > > ------------------------------ > > Message: 2 > Date: Thu, 30 Oct 2008 21:24:14 -0400 > From: Scott Taylor > Subject: Re: [rspec-users] Mocks and Refactoring - doing it wrong? > To: rspec-users at rubyforge.org > Message-ID: <6D3B0233-51F7-4083-B95A-44FDF12F1EEF at railsnewbie.com> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > > 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 > > > > ------------------------------ > > Message: 3 > Date: Fri, 31 Oct 2008 07:49:25 +0000 > From: Matt Wynne > Subject: Re: [rspec-users] spec'ing the :conditions argument of a find > To: rspec-users > Message-ID: <8E053474-34E5-4753-866D-DF549A06EFE3 at mattwynne.net> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > 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 > > > ------------------------------ > > Message: 4 > Date: Fri, 31 Oct 2008 08:24:03 +0000 > From: Ashley Moran > Subject: Re: [rspec-users] spec'ing the :conditions argument of a find > To: rspec-users > Message-ID: > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > > 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/ > > > > ------------------------------ > > Message: 5 > Date: Fri, 31 Oct 2008 09:36:28 +0000 > From: Matt Wynne > Subject: [rspec-users] described_type > To: rspec-users > Message-ID: <2F793D35-C491-46B8-8BF2-3EB8FEF1A17F at mattwynne.net> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > 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 > > > ------------------------------ > > Message: 6 > Date: Fri, 31 Oct 2008 03:50:30 -0700 > From: Pat Maddox > Subject: Re: [rspec-users] described_type > To: rspec-users > Message-ID: > Content-Type: text/plain; charset=us-ascii > > 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 > > > ------------------------------ > > Message: 7 > Date: Fri, 31 Oct 2008 18:26:17 +0100 > From: Harry Bishop > Subject: Re: [rspec-users] testing a render layout statement in a > controller > To: rspec-users at rubyforge.org > Message-ID: > Content-Type: text/plain; charset=utf-8 > > 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/. > > > ------------------------------ > > Message: 8 > Date: Fri, 31 Oct 2008 16:54:42 -0400 > From: Nick Hoffman > Subject: Re: [rspec-users] Working outside-in with Cucumber and RSpec > To: rspec-users > Message-ID: <364B2A62-F8E2-4159-924E-878B29E2AC3C at deadorange.com> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > 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 > > > ------------------------------ > > Message: 9 > Date: Fri, 31 Oct 2008 17:34:59 -0400 > From: Matt Darby > Subject: [rspec-users] Fwd: spec_server not working... > To: rspec-users > Message-ID: <4AE03859-BEC1-4ACF-AF91-AE189D8386CB at matt-darby.com> > Content-Type: text/plain; charset="us-ascii"; Format="flowed"; > DelSp="yes" > > 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: > > > ------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > End of rspec-users Digest, Vol 28, Issue 87 > ******************************************* From nick at deadorange.com Sat Nov 1 11:57:14 2008 From: nick at deadorange.com (Nick Hoffman) Date: Sat, 1 Nov 2008 11:57:14 -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> <364B2A62-F8E2-4159-924E-878B29E2AC3C@deadorange.com> Message-ID: <80DC106D-9C3F-4106-9717-A52BEF470D6B@deadorange.com> On 2008-10-31, at 20:17, Pat Maddox wrote: > Nick Hoffman writes: >> 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 Thanks for taking a look, Pat. Much appreciated! -Nick From lists at ruby-forum.com Sat Nov 1 16:25:30 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Sat, 1 Nov 2008 21:25:30 +0100 Subject: [rspec-users] Issues after removal of rpsec plugins and gem install Message-ID: <6d0ebc39b6fed43f7037c0587968c4ed@ruby-forum.com> autotest will no longer run my tests after I installed the rpsec gem and removed the plugins. I did install the rspec-rails gem as well. Is anyone else having this issue? -- Posted via http://www.ruby-forum.com/. From shot at hot.pl Sat Nov 1 17:49:18 2008 From: shot at hot.pl (Shot (Piotr Szotkowski)) Date: Sat, 1 Nov 2008 22:49:18 +0100 Subject: [rspec-users] =?utf-8?b?UlNwZWNpbmcgYSDigJhiaW5hcnnigJk=?= In-Reply-To: <08AF7A3F-E489-4CB0-BD6A-FD90B53ED753@patchspace.co.uk> References: <20081025070812.GA15630@durance.shot.pl> <08AF7A3F-E489-4CB0-BD6A-FD90B53ED753@patchspace.co.uk> Message-ID: <20081101214918.GA29430@durance.shot.pl> Ashley Moran: > 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. Thanks a lot, Ashley! This is what I?m going to do, then. :) I?ve just finished watching Rick Bradley?s ?flog << Test.new? presentation? from Ruby Hoedown 2008, and the first part (past the introduction) is about how he RSpeced the flog binary ? also most informative! ? http://rubyhoedown2008.confreaks.com/11-rick-bradley-flog-test-new.html -- Shot -- I've been almost exclusively hand-coding my JavaScript these past 4 or 5 months, and I've come to the conclusion that this experience has permanently altered my neurochemistry in some strange, pseudo-Stockholm Syndrome kind of way. -- Amy Hoy -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: not available URL: From dchelimsky at gmail.com Sat Nov 1 18:10:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 1 Nov 2008 17:10:03 -0500 Subject: [rspec-users] Issues after removal of rpsec plugins and gem install In-Reply-To: <6d0ebc39b6fed43f7037c0587968c4ed@ruby-forum.com> References: <6d0ebc39b6fed43f7037c0587968c4ed@ruby-forum.com> Message-ID: <57c63afe0811011510x2e519ef3gd8075e94cd77ccf6@mail.gmail.com> On Sat, Nov 1, 2008 at 3:25 PM, Chris Olsen wrote: > autotest will no longer run my tests after I installed the rpsec gem and > removed the plugins. I did install the rspec-rails gem as well. > > Is anyone else having this issue? Not sure how far back you're updating from, but we introduced autospec in 1.1.5: http://rspec.info/changes-rspec.html 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 Sat Nov 1 18:33:44 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Sat, 1 Nov 2008 23:33:44 +0100 Subject: [rspec-users] Issues after removal of rpsec plugins and gem install In-Reply-To: <57c63afe0811011510x2e519ef3gd8075e94cd77ccf6@mail.gmail.com> References: <6d0ebc39b6fed43f7037c0587968c4ed@ruby-forum.com> <57c63afe0811011510x2e519ef3gd8075e94cd77ccf6@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Sat, Nov 1, 2008 at 3:25 PM, Chris Olsen > wrote: >> autotest will no longer run my tests after I installed the rpsec gem and >> removed the plugins. I did install the rspec-rails gem as well. >> >> Is anyone else having this issue? > > Not sure how far back you're updating from, but we introduced autospec > in 1.1.5: > > http://rspec.info/changes-rspec.html > > Cheers, > David rspec (1.1.11) rspec-rails (1.1.11) ZenTest (3.11.0) I was under the impression that with the latest version a person no longer has to install the rails plugins. I have removed them, and as mentioned autotest just hangs. $ autotest loading autotest/rails [hangs] Thanks for the help. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sat Nov 1 18:35:31 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Sat, 1 Nov 2008 23:35:31 +0100 Subject: [rspec-users] Issues after removal of rpsec plugins and gem install In-Reply-To: References: <6d0ebc39b6fed43f7037c0587968c4ed@ruby-forum.com> <57c63afe0811011510x2e519ef3gd8075e94cd77ccf6@mail.gmail.com> Message-ID: I see that in 1.1.5 you are no longer supposed to use autotest. Things are now working using autospec. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sat Nov 1 18:38:09 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Sat, 1 Nov 2008 23:38:09 +0100 Subject: [rspec-users] Issues after removal of rpsec plugins and gem install In-Reply-To: References: <6d0ebc39b6fed43f7037c0587968c4ed@ruby-forum.com> <57c63afe0811011510x2e519ef3gd8075e94cd77ccf6@mail.gmail.com> Message-ID: <0f60c2eaa72a68df113a0fe850d3238b@ruby-forum.com> Chris Olsen wrote: > I see that in 1.1.5 you are no longer supposed to use autotest. Things > are now working using autospec. I now noticed that what you mentioned in your reply. I totally missed that point. Thanks again David. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Nov 1 18:39:46 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 1 Nov 2008 17:39:46 -0500 Subject: [rspec-users] Issues after removal of rpsec plugins and gem install In-Reply-To: <0f60c2eaa72a68df113a0fe850d3238b@ruby-forum.com> References: <6d0ebc39b6fed43f7037c0587968c4ed@ruby-forum.com> <57c63afe0811011510x2e519ef3gd8075e94cd77ccf6@mail.gmail.com> <0f60c2eaa72a68df113a0fe850d3238b@ruby-forum.com> Message-ID: <57c63afe0811011539w634e993fw6616aca3de285643@mail.gmail.com> On Sat, Nov 1, 2008 at 5:38 PM, Chris Olsen wrote: > Chris Olsen wrote: >> I see that in 1.1.5 you are no longer supposed to use autotest. Things >> are now working using autospec. > > I now noticed that what you mentioned in your reply. I totally missed > that point. > > Thanks again David. No problem. Glad it wasn't a new bug :) Cheers, David From lists at ruby-forum.com Sun Nov 2 01:16:00 2008 From: lists at ruby-forum.com (Pau Cor) Date: Sun, 2 Nov 2008 06:16:00 +0100 Subject: [rspec-users] Cucumber changes between 0.1.8 and edge In-Reply-To: References: Message-ID: <58772a24750a4e2ac71700a35c7862c1@ruby-forum.com> Barry Mitchelson wrote: > This sounds like the issue I had here > http://rspec.lighthouseapp.com/projects/16211/tickets/60-patch-next_column_index-not-resetting-after-large-tables. > Is there a feature running before this one with a scenario table with > at > least 2 more columns than the one in the failing feature? Thanks Barry. This seems to be the same issue. Applying your patch made my features pass. I made a comment on lighthouse. -- Posted via http://www.ruby-forum.com/. From barry.mitchelson at gmail.com Sun Nov 2 06:18:39 2008 From: barry.mitchelson at gmail.com (Barry Mitchelson) Date: Sun, 2 Nov 2008 11:18:39 +0000 Subject: [rspec-users] Cucumber changes between 0.1.8 and edge In-Reply-To: <58772a24750a4e2ac71700a35c7862c1@ruby-forum.com> References: <58772a24750a4e2ac71700a35c7862c1@ruby-forum.com> Message-ID: On Sun, Nov 2, 2008 at 5:16 AM, Pau Cor wrote: > Barry Mitchelson wrote: > > This sounds like the issue I had here > > > http://rspec.lighthouseapp.com/projects/16211/tickets/60-patch-next_column_index-not-resetting-after-large-tables > . > > Is there a feature running before this one with a scenario table with > > at > > least 2 more columns than the one in the failing feature? > > Thanks Barry. This seems to be the same issue. Applying your patch made > my features pass. I made a comment on lighthouse. OK. I've been a bit busy lately, but should be able to write the requested failing specs today. Barry > > -- > 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 lists at ruby-forum.com Sun Nov 2 10:54:36 2008 From: lists at ruby-forum.com (Steven Line) Date: Sun, 2 Nov 2008 16:54:36 +0100 Subject: [rspec-users] Setting session values In-Reply-To: References: Message-ID: <0f1888fe930805914242773f70156546@ruby-forum.com> Steve wrote: > On Wed, 24 Oct 2007 21:29:39 -0400, Jonathan Linowes wrote: > >> i've done this in controller specs >> >> session[:whatever] = something >> do_it >> > > Yeah, I did that, and it was turning up nil when I actually made the > request. I know your post was from over a year ago, but I'll post this anyway. I think the problem with Radiant is that in the SiteController it has session :off as the first line. So sessions will be disabled for any controller than inherits from SiteController as I understand it. My next step is to figure out why and see if re-enabling sessions is safe. -- Posted via http://www.ruby-forum.com/. From tadatoshi.mailinglist at gmail.com Sun Nov 2 12:07:26 2008 From: tadatoshi.mailinglist at gmail.com (Tadatoshi Takahashi) Date: Sun, 2 Nov 2008 12:07:26 -0500 Subject: [rspec-users] Problem running "rake spec" with Workling and Starling Message-ID: <96708edb0811020907o3829fe03q6c95c4769363b5da@mail.gmail.com> Hi, I installed Starling and Workling and set them up. Then when I tried to run "rake spec", it halts with a message "config/starling.yml configured to connect to starling on localhost:22122 for this environment. could not connect to starling on this host:port. pass starling the port with -p flag when starting it. If you don't want to use Starling at all, then explicitly set Workling::Remote.dispatcher (see README for an example)" But the port 22122 is set for development in config/starling.yml. I tried to execute rake spec ENV["RAILS_ENV"] = "test" But the same result. Does anybody know the reason why this happens and how to resolve it? Thank you. Tadatoshi -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sun Nov 2 22:29:26 2008 From: lists at ruby-forum.com (Sebastian W.) Date: Mon, 3 Nov 2008 04:29:26 +0100 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: <6D3B0233-51F7-4083-B95A-44FDF12F1EEF@railsnewbie.com> References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> <86e194aaa9d58c706b04879785e2cf51@ruby-forum.com> <6D3B0233-51F7-4083-B95A-44FDF12F1EEF@railsnewbie.com> Message-ID: > > +1 > > Tests *are* supposed to influence the way we write production code. > > Scott So maybe we could try it and see how it works out? If it makes things unhappy, it can always be labeled "a worthwhile effort and experiment". : ) -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Mon Nov 3 06:36:13 2008 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 3 Nov 2008 11:36:13 +0000 Subject: [rspec-users] stub! and null_object Message-ID: I have some code I want to stub out as it's not part of what I'm testing. It's got a bit of DSL going on, so there are method calls chained together. The call I want to stub out looks like this: user.record_action(:uploaded_a_photo => concert).with_result(photo) So ideally, I'd just do @user.stub!(:record_action) and that would return a null object that didn't care what we did to it. However, possibly due to my own ignorance, I'm having to do something a lot more ugly, like this: @user.stub!(:record_action).and_return(mock('blah',:null_object => true)) Can anyone beautify this a bit more? cheers, Matt From lists at ruby-forum.com Mon Nov 3 10:23:14 2008 From: lists at ruby-forum.com (Tom Hoen) Date: Mon, 3 Nov 2008 16:23:14 +0100 Subject: [rspec-users] Expected "with" matches received "with" in error message Message-ID: <0a3a931439557e429faa85f14fc131a7@ruby-forum.com> I am trying to spec a controller that sets up a page to add two instances of an object to another (many to many :through). In my controller_spec, I have the following statements: Student.should_receive(:new).and_return(mock_student) mock_student.should_receive(:relatives).twice mock_student.relatives.should_receive("<<").with(Relative.new(:parent => Parent.new)).twice When I run the test, I get the following error message: Spec::Mocks::MockExpectationError in 'StudentsController responding to GET new should expose a new student as @student' Mock 'NilClass' expected :<< with (#) but received it with (#) It seems what it is receiving and expecting are the same. Any ideas would be greatly appreciated. Tom -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Nov 3 10:30:20 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Nov 2008 09:30:20 -0600 Subject: [rspec-users] Expected "with" matches received "with" in error message In-Reply-To: <0a3a931439557e429faa85f14fc131a7@ruby-forum.com> References: <0a3a931439557e429faa85f14fc131a7@ruby-forum.com> Message-ID: <57c63afe0811030730k1a91973cm7379fe2f599896ba@mail.gmail.com> On Mon, Nov 3, 2008 at 9:23 AM, Tom Hoen wrote: > I am trying to spec a controller that sets up a page to add two > instances of an object to another (many to many :through). > > In my controller_spec, I have the following statements: > > Student.should_receive(:new).and_return(mock_student) > mock_student.should_receive(:relatives).twice > mock_student.relatives.should_receive("<<").with(Relative.new(:parent > => Parent.new)).twice > > When I run the test, I get the following error message: > > Spec::Mocks::MockExpectationError in 'StudentsController responding to > GET new should expose a new student as @student' > Mock 'NilClass' expected :<< with (# student_id: nil, created_at: nil, updated_at: nil, child_lives_with: > nil>) but received it with (# student_id: nil, created_at: nil, updated_at: nil, child_lives_with: > nil>) > > It seems what it is receiving and expecting are the same. > > Any ideas would be greatly appreciated. ActiveRecord treats two unsaved records as unequal, even if they have the same properties. Try this in script/console Relative.new == Relative.new => false To get this to work you'll have to either use real records (with IDs) or stub whatever it is that is supplying the Relative and then expect with(the_relative_you_supply_as_a_stub_value). Make sense? > > Tom > -- > 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 Mon Nov 3 10:50:45 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 03 Nov 2008 07:50:45 -0800 Subject: [rspec-users] Expected "with" matches received "with" in error message In-Reply-To: <57c63afe0811030730k1a91973cm7379fe2f599896ba@mail.gmail.com> (David Chelimsky's message of "Mon\, 3 Nov 2008 09\:30\:20 -0600") References: <0a3a931439557e429faa85f14fc131a7@ruby-forum.com> <57c63afe0811030730k1a91973cm7379fe2f599896ba@mail.gmail.com> Message-ID: "David Chelimsky" writes: > On Mon, Nov 3, 2008 at 9:23 AM, Tom Hoen wrote: >> I am trying to spec a controller that sets up a page to add two >> instances of an object to another (many to many :through). >> >> In my controller_spec, I have the following statements: >> >> Student.should_receive(:new).and_return(mock_student) >> mock_student.should_receive(:relatives).twice >> mock_student.relatives.should_receive("<<").with(Relative.new(:parent >> => Parent.new)).twice >> >> When I run the test, I get the following error message: >> >> Spec::Mocks::MockExpectationError in 'StudentsController responding to >> GET new should expose a new student as @student' >> Mock 'NilClass' expected :<< with (#> student_id: nil, created_at: nil, updated_at: nil, child_lives_with: >> nil>) but received it with (#> student_id: nil, created_at: nil, updated_at: nil, child_lives_with: >> nil>) >> >> It seems what it is receiving and expecting are the same. >> >> Any ideas would be greatly appreciated. > > ActiveRecord treats two unsaved records as unequal, even if they have > the same properties. Try this in script/console > > Relative.new == Relative.new > => false > > To get this to work you'll have to either use real records (with IDs) > or stub whatever it is that is supplying the Relative and then expect > with(the_relative_you_supply_as_a_stub_value). > > Make sense? Also I'd like to bring attention to "Mock 'NilClass' expected :<<". mock_student.relatives is nil, but you'll want to return something. As for the actual problem, what David said :) Pat From lists at ruby-forum.com Mon Nov 3 11:01:40 2008 From: lists at ruby-forum.com (Tom Hoen) Date: Mon, 3 Nov 2008 17:01:40 +0100 Subject: [rspec-users] Expected "with" matches received "with" in error message In-Reply-To: <57c63afe0811030730k1a91973cm7379fe2f599896ba@mail.gmail.com> References: <0a3a931439557e429faa85f14fc131a7@ruby-forum.com> <57c63afe0811030730k1a91973cm7379fe2f599896ba@mail.gmail.com> Message-ID: <7dc7d07465d81ab4c8c046662ee71dcd@ruby-forum.com> > > To get this to work you'll have to either use real records (with IDs) > or stub whatever it is that is supplying the Relative and then expect > with(the_relative_you_supply_as_a_stub_value). > > Make sense? In part, but not 100%. Here is the code from the controller. Since all objects are expected to be new, I am not clear whether using real objects would create a false test. I am quite new to rspec, and admittedly don't fully grasp when to mock and when to not. @student = Student.new 2.times { @student.relatives << Relative.new(:parent => Parent.new) } -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Nov 3 11:44:26 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Nov 2008 10:44:26 -0600 Subject: [rspec-users] Expected "with" matches received "with" in error message In-Reply-To: <57c63afe0811030730k1a91973cm7379fe2f599896ba@mail.gmail.com> References: <0a3a931439557e429faa85f14fc131a7@ruby-forum.com> <57c63afe0811030730k1a91973cm7379fe2f599896ba@mail.gmail.com> Message-ID: <57c63afe0811030844v1efbd2fcl9bac99319e8cb40e@mail.gmail.com> On Mon, Nov 3, 2008 at 9:30 AM, David Chelimsky wrote: > On Mon, Nov 3, 2008 at 9:23 AM, Tom Hoen wrote: >> I am trying to spec a controller that sets up a page to add two >> instances of an object to another (many to many :through). >> >> In my controller_spec, I have the following statements: >> >> Student.should_receive(:new).and_return(mock_student) >> mock_student.should_receive(:relatives).twice >> mock_student.relatives.should_receive("<<").with(Relative.new(:parent >> => Parent.new)).twice >> >> When I run the test, I get the following error message: >> >> Spec::Mocks::MockExpectationError in 'StudentsController responding to >> GET new should expose a new student as @student' >> Mock 'NilClass' expected :<< with (#> student_id: nil, created_at: nil, updated_at: nil, child_lives_with: >> nil>) but received it with (#> student_id: nil, created_at: nil, updated_at: nil, child_lives_with: >> nil>) >> >> It seems what it is receiving and expecting are the same. >> >> Any ideas would be greatly appreciated. > > ActiveRecord treats two unsaved records as unequal, even if they have > the same properties. Try this in script/console > > Relative.new == Relative.new > => false This fact has always bugged me, so I finally did something about it: http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1321 http://github.com/dchelimsky/rails/commit/03be483 Cheers, David > > To get this to work you'll have to either use real records (with IDs) > or stub whatever it is that is supplying the Relative and then expect > with(the_relative_you_supply_as_a_stub_value). > > Make sense? > >> >> Tom >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From ben at benmabey.com Mon Nov 3 15:14:42 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 03 Nov 2008 13:14:42 -0700 Subject: [rspec-users] Cucumber and autotest Message-ID: <490F5BB2.1060709@benmabey.com> Hey all, Does anyone know how to disable the cucumber autotest support on a project? With this commit: http://github.com/aslakhellesoy/cucumber/commit/93470e2580b5e3cfe0c8eb3fce86e21bf8afa219 The cucumber features are worked into the autotest cycle automatically. This is cool, but on some projects I don't think it fits well with my red->green->refactor cycle. Any ideas on how to disable this on a per-project basis? Thanks for any suggestions, Ben From dchelimsky at gmail.com Mon Nov 3 15:23:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Nov 2008 14:23:43 -0600 Subject: [rspec-users] Cucumber and autotest In-Reply-To: <490F5BB2.1060709@benmabey.com> References: <490F5BB2.1060709@benmabey.com> Message-ID: <57c63afe0811031223g325447b8qbd9fbfa1585388a9@mail.gmail.com> On Mon, Nov 3, 2008 at 2:14 PM, Ben Mabey wrote: > Hey all, > Does anyone know how to disable the cucumber autotest support on a project? > With this commit: > http://github.com/aslakhellesoy/cucumber/commit/93470e2580b5e3cfe0c8eb3fce86e21bf8afa219 > > The cucumber features are worked into the autotest cycle automatically. > This is cool, but on some projects I don't think it fits well with my > red->green->refactor cycle. Any ideas on how to disable this on a > per-project basis? Ben - can you report this to lighthouse? > > Thanks for any suggestions, > Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Mon Nov 3 15:31:40 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 03 Nov 2008 13:31:40 -0700 Subject: [rspec-users] Cucumber and autotest In-Reply-To: <57c63afe0811031223g325447b8qbd9fbfa1585388a9@mail.gmail.com> References: <490F5BB2.1060709@benmabey.com> <57c63afe0811031223g325447b8qbd9fbfa1585388a9@mail.gmail.com> Message-ID: <490F5FAC.4060003@benmabey.com> David Chelimsky wrote: > On Mon, Nov 3, 2008 at 2:14 PM, Ben Mabey wrote: > >> Hey all, >> Does anyone know how to disable the cucumber autotest support on a project? >> With this commit: >> http://github.com/aslakhellesoy/cucumber/commit/93470e2580b5e3cfe0c8eb3fce86e21bf8afa219 >> >> The cucumber features are worked into the autotest cycle automatically. >> This is cool, but on some projects I don't think it fits well with my >> red->green->refactor cycle. Any ideas on how to disable this on a >> per-project basis? >> > > Ben - can you report this to lighthouse? > http://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/78-allow-for-disabling-autotest For right now I just defined an autotest profile in my cucumber.yml that won't run any features. If I get some time later I'll investigate it more. -Ben > >> Thanks for any suggestions, >> Ben >> >> _______________________________________________ >> 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 andy.koch at pc-doctor.com Mon Nov 3 16:38:22 2008 From: andy.koch at pc-doctor.com (Andy Koch) Date: Mon, 03 Nov 2008 13:38:22 -0800 Subject: [rspec-users] rspec 'mock' method not found Message-ID: <490F6F4E.5040504@pc-doctor.com> Hi, I'm having trouble with "mock" and I can't seem to find any reason for this. The error... ******************** 1) NoMethodError in 'UserObserver should not call UserMailer.deliver_activation if user wasn't recently activated' undefined method `mock' for Spec::Rails::Example::ModelExampleGroup::Subclass_3:Class ./spec/models/user_observer_spec.rb:6: /var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active_support/callbacks.rb:177:in `call' /var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active_support/callbacks.rb:177:in `evaluate_method' /var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active_support/callbacks.rb:161:in `call' /var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active_support/callbacks.rb:90:in `run' /var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active_support/callbacks.rb:90:in `each' /var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active_support/callbacks.rb:90:in `send' /var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active_support/callbacks.rb:90:in `run' /var/lib/gems/1.8/gems/activesupport-2.1.2/lib/active_support/callbacks.rb:272:in `run_callbacks' spec/models/user_mailer_spec.rb:42: ******************** And the code.... ******************** require File.dirname(__FILE__) + '/../spec_helper' context "A UserObserver" do setup do @user = mock(User) @user_observer = UserObserver.instance end ........ end ******************** I've not found any other people with a similar issue via Google yet. Any help is much appreciated. -- Andy Koch From cameron.booth at gmail.com Mon Nov 3 16:55:45 2008 From: cameron.booth at gmail.com (Cameron Booth) Date: Mon, 3 Nov 2008 15:55:45 -0600 Subject: [rspec-users] concerned_with, and maybe require_dependency issues only when running specs? Message-ID: Hi all, So in the interests of keeping a few areas of my code a bit under control, I've been investigating the concept of "concerned_with" as described here: http://paulbarry.com/articles/2008/08/30/concerned-with-skinny-controller-skinny-model Basically allowing me to have: /app/models/user.rb class User < ActiveRecord::Base concerned_with :something end /app/models/user/something.rb class User < ActiveRecord::Base def something_method do_it end end I realize that there might be better ways to deal with this same issue...some of my code might be better off in separate classes, or modules, etc, but for now I'm hoping to try this out. And it's working working great in my code, when I run the server, script/console, etc... ....everywhere except in my specs. And, its working in my actual model spec just fine (spec/models/user_spec.rb). But where it's not working is in other specs that end up using the user model, such as some controller specs, and view specs where things aren't fully stubbed/mocked out. It seems like in those other specs, the User class doesn't have "something_method" defined. (the failure message is undefined_method "something_method" for # Anybody have any ideas? I have a feeling it's related to require_dependency or something, but I'm not really sure. I've turned on logging in require_dependency, and it seems like the files are being required. Any help would be great, thanks! Cameron -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Nov 4 00:24:02 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Nov 2008 23:24:02 -0600 Subject: [rspec-users] stub! and null_object In-Reply-To: References: Message-ID: <57c63afe0811032124y3b61ddeepb907fba9a3fd5fc3@mail.gmail.com> On Mon, Nov 3, 2008 at 5:36 AM, Matt Wynne wrote: > I have some code I want to stub out as it's not part of what I'm testing. > > It's got a bit of DSL going on, so there are method calls chained together. > > The call I want to stub out looks like this: > > user.record_action(:uploaded_a_photo => concert).with_result(photo) > > So ideally, I'd just do @user.stub!(:record_action) and that would return a > null object that didn't care what we did to it. stub! returns self (@user in this case), that's how it's able to chain methods like and_return > > However, possibly due to my own ignorance, I'm having to do something a lot > more ugly, like this: > > @user.stub!(:record_action).and_return(mock('blah',:null_object => true)) > > Can anyone beautify this a bit more? Only slightly: @user.stub!(:record_action).and_return(mock('blah').as_null_object) > > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Tue Nov 4 04:39:51 2008 From: tom at experthuman.com (Tom Stuart) Date: Tue, 4 Nov 2008 09:39:51 +0000 Subject: [rspec-users] Caboosers drop RSpec Message-ID: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> Hi, Any responses to http://blog.caboo.se/articles/2008/11/4/we-ve-stopped-using-rspec ? How much of this is due to legitimate bugs/problems versus unfortunate circumstances? Feels kind of worrying that they haven't been able to make it work for them. Cheers, -Tom From apremdas at gmail.com Tue Nov 4 06:10:48 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 4 Nov 2008 11:10:48 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec Message-ID: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> Is there any way to do foo.should (be_nil || be_empty) in rspec. Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From luislavena at gmail.com Tue Nov 4 06:16:43 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 4 Nov 2008 08:16:43 -0300 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> Message-ID: <71166b3b0811040316y5543a2a4v3cd33edbb8b97696@mail.gmail.com> On Tue, Nov 4, 2008 at 6:39 AM, Tom Stuart wrote: > Hi, > > Any responses to > http://blog.caboo.se/articles/2008/11/4/we-ve-stopped-using-rspec ? How much > of this is due to legitimate bugs/problems versus unfortunate circumstances? > Feels kind of worrying that they haven't been able to make it work for them. Oh my, the end of world is near! The gem dependency is a real problem. Coming from the Windows world where we have to deal with DLL inter-dependency and loading issues, we are quite familiar with these issues (not having the gem/library in the server, loading it break other tasks, etc). What is missing from the config.gem concept is the possibility to specify the context in which these gems get loaded. Why you need RSpec in production? why is that being loaded? Even if you define rspec and rspec gems as your application dependencies, they shouldn't be forced on *every* environment, which is the root of these issues. Other issues like specs not being executed I can agree on that, I found sometimes some before(:each) do not run, and sometimes they do... when tried to track that down, the problem disappeared. >From that I have plenty of stories, but any application or tool of the size of RSpec have these issues. Take for example Test::Unit... is a 3K lines of code beast. mini-unit from Ryan Davis is around 600 lines and do the same stuff, much more faster, and besides the war at ruby-core about it, I don't hear anyone ranting about the beast it is. So: the defacto vs. the newcomer. The full of classes and unpronounceable methods names vs. the descriptive ones. Pick your framework. -- 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 tom at experthuman.com Tue Nov 4 06:19:47 2008 From: tom at experthuman.com (Tom Stuart) Date: Tue, 4 Nov 2008 11:19:47 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> Message-ID: <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> On 4 Nov 2008, at 11:10, Andrew Premdas wrote: > Is there any way to do > foo.should (be_nil || be_empty) > in rspec. "foo.should be_blank" would work if you're using Rails (i.e. ActiveSupport is loaded). Cheers, -Tom From ashley.moran at patchspace.co.uk Tue Nov 4 06:23:03 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 11:23:03 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> Message-ID: <32138C6D-9664-485A-84A0-3D2FEBE7D37B@patchspace.co.uk> On 4 Nov 2008, at 11:10, Andrew Premdas wrote: > Is there any way to do > > foo.should (be_nil || be_empty) > > in rspec. That won't do what you want it to, at first glance it will always match with be_nil. You could write a custom matcher (be_nil_or_empty), but I suspect that's not the real answer here. Why do you want to do this? What is the distinction between nil and empty in your app? I suspect this is a data modelling issue rather than a spec issue. (Be very wary as soon as you see conditionals in your code.) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From apremdas at gmail.com Tue Nov 4 06:26:55 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 4 Nov 2008 11:26:55 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> Message-ID: <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> Sweet I'm using rails so will give it a go. Any ideas about the general case, is making a custom matcher the (only) way to go? All best Andrew 2008/11/4 Tom Stuart > On 4 Nov 2008, at 11:10, Andrew Premdas wrote: > >> Is there any way to do >> foo.should (be_nil || be_empty) >> in rspec. >> > > "foo.should be_blank" would work if you're using Rails (i.e. ActiveSupport > is loaded). > > Cheers, > -Tom > _______________________________________________ > 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 Tue Nov 4 06:51:27 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 11:51:27 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> Message-ID: On 4 Nov 2008, at 11:26, Andrew Premdas wrote: > Any ideas about the general case, is making a custom matcher the > (only) way to go? Can you give an example of what you're doing, or think you might do? Until I saw Tom's reply it never occurred to me that you might be dealing with strings (I thought you were doing something with an array or other collection.) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From apremdas at gmail.com Tue Nov 4 07:45:31 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 4 Nov 2008 12:45:31 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> Message-ID: <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> General case I'm thinking about is just testing that something should be one thing or another e.g x.should be(foo || bar) Haven't got a specific example at the moment apart from the blank one. What I'm thinking about is the syntax to say this in a spec, as I think there must be lots of times when having this sort of syntax would be useful. All best Andrew 2008/11/4 Ashley Moran > > On 4 Nov 2008, at 11:26, Andrew Premdas wrote: > > Any ideas about the general case, is making a custom matcher the (only) >> way to go? >> > > Can you give an example of what you're doing, or think you might do? Until > I saw Tom's reply it never occurred to me that you might be dealing with > strings (I thought you were doing something with an array or other > collection.) > > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aslak.hellesoy at gmail.com Tue Nov 4 08:25:00 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 4 Nov 2008 14:25:00 +0100 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> Message-ID: <8d961d900811040525x70cd1e6dh25838778e4d5b53f@mail.gmail.com> On Tue, Nov 4, 2008 at 10:39 AM, Tom Stuart wrote: > Hi, > > Any responses to > http://blog.caboo.se/articles/2008/11/4/we-ve-stopped-using-rspec ? How much > of this is due to legitimate bugs/problems versus unfortunate circumstances? > Feels kind of worrying that they haven't been able to make it work for them. > I wish people would seek out the developers (mailing list, bug tracker) before they go out and whine. See my comment in the blog post. Aslak > 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 Tue Nov 4 08:53:57 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 13:53:57 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> Message-ID: <3D18548F-9B81-4C35-8C5A-C7577871DCCD@patchspace.co.uk> On 4 Nov 2008, at 12:45, Andrew Premdas wrote: > General case I'm thinking about is just testing that something > should be one thing or another > > e.g x.should be(foo || bar) > > Haven't got a specific example at the moment apart from the blank > one. What I'm thinking about is the syntax to say this in a spec, > as I think there must be lots of times when having this sort of > syntax would be useful. Hi Andrew I suspect that in general the concept of an object O being (foo || bar) actually means there's a rule that makes your object baz instead. The reason is that if you spec foo and bar independently, you double the number of contexts for objects that depend on O. So this might not look to bad: describe MyObject do before(:each) do @o = MyObject.new end it "should be foo or bar" do @o.should be_foo_or_bar end end but it means everywhere else you're forced to duplicate that logic, eg: describe MyOtherObject do describe "when its MyObject is foo" do before(:each) do o = mock(MyObject, :foo => true, :bar => false) @oo = MyOtherObject.new(o) end it "should be faz" do @oo.should be_faz end end describe "when its MyObject is bar" do before(:each) do o = mock(MyObject, :foo => false, :bar => true) @oo = MyOtherObject.new(o) end it "should be faz" do @oo.should be_faz end end describe "when its MyObject is neither foo nor bar" do before(:each) do o = mock(MyObject, :foo => false, :bar => false) @oo = MyOtherObject.new(o) end it "should not be faz" do @oo.should_not be_faz end end end instead of just: describe MyOtherObject do describe "when its MyObject is baz" do before(:each) do o = mock(MyObject, :baz => true) @oo = MyOtherObject.new(o) end it "should be faz" do @oo.should be_faz end end describe "when its MyObject is not baz" do before(:each) do o = mock(MyObject, :baz => false) @oo = MyOtherObject.new(o) end it "should not be faz" do @oo.should_not be_faz end end end s/foo/nil/ s/bar/empty/ s/baz/blank/ This make sense? Sorry if it's a bit abstract, or has typos. I didn't actually run that code, of course... I think in summary, two branches in your specs => you are violating Tell Don't Ask (somewhere else) in your code. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Tue Nov 4 09:11:24 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 14:11:24 +0000 Subject: [rspec-users] BDD problems (Re: Caboosers drop RSpec) In-Reply-To: <8d961d900811040525x70cd1e6dh25838778e4d5b53f@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <8d961d900811040525x70cd1e6dh25838778e4d5b53f@mail.gmail.com> Message-ID: <1833C2C0-EB9C-4228-8A08-BFA0E97C4E13@patchspace.co.uk> On 4 Nov 2008, at 13:25, aslak hellesoy wrote: > I wish people would seek out the developers (mailing list, bug > tracker) before they go out and whine. See my comment in the blog > post. RSpec seems to be a victim of "when I do BDD wrong, RSpec makes my tests fragile/confusing/verbose, so I'll use something else and then I must be doing BDD right". There's a BarCamp in my area soon[1], which will have quite a lot of Rubyists (not that that's essential). Maybe there'd be some merit in offering a "How to diagnose BDD problems from spec problems" session? If that sounds like something worth doing let me know. Not that anyone here would attend (apart from Rahoul, maybe, he's the only person I know here that is local to me), but I could gather ideas, and post the slides back later. Ashley [1] http://barcampsheffield.net/ -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From steven at stevenrbaker.com Tue Nov 4 09:37:22 2008 From: steven at stevenrbaker.com (Steven Baker) Date: Tue, 4 Nov 2008 07:37:22 -0700 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> Message-ID: <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> > Subject: [rspec-users] Caboosers drop RSpec The subject is wrong too; Caboosers didn't drop RSpec. Two people from caboose dropped RSpec. Most of the caboosers I know are still using RSpec. > Any responses to http://blog.caboo.se/articles/2008/11/4/we-ve-stopped-using-rspec > ? How much of this is due to legitimate bugs/problems versus > unfortunate circumstances? Feels kind of worrying that they haven't > been able to make it work for them. Big difference between "haven't been able to" and "wouldn't learn the tools". Ashley's post below sums it up best. This is a problem that's seen regularly when working with new ideas. How many times have you seen Agile blamed when a project fails due to poor management? I personally see this all the time. A poor craftsman blames his tools. I don't get upset when people stop using RSpec, but I do get rather upset when people blame it because they mis-used it. The caboose post just seems to justify this kind of behaviour. Notice the first comment, which says: From Patrick Reagan: "We liked the BDD-style syntax and context, but found that it gave a false sense of security when it came to doing functional testing because the views were completely separated from the controllers under test." Patrick completely misses the point. He had bad examples (which are worse than no examples at all) and blames RSpec because he doesn't understand BDD. This isn't just BDD, decoupling is one of the benefits realized by the original TDD folks, and he's saying "No, I want my separate objects to be coupled tightly because it's less work." The tight coupling is actually what gives the false sense of security. -Steven From zach.dennis at gmail.com Tue Nov 4 09:58:36 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 4 Nov 2008 09:58:36 -0500 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> Message-ID: <85d99afe0811040658x53798c82ib0c767e46cdc9d0f@mail.gmail.com> On Tue, Nov 4, 2008 at 9:37 AM, Steven Baker wrote: >> >> Subject: [rspec-users] Caboosers drop RSpec > > The subject is wrong too; Caboosers didn't drop RSpec. Two people from caboose dropped RSpec. Most of the caboosers I know are still using RSpec. > >> Any responses to http://blog.caboo.se/articles/2008/11/4/we-ve-stopped-using-rspec ? How much of this is due to legitimate bugs/problems versus unfortunate circumstances? Feels kind of worrying that they haven't been able to make it work for them. > > Big difference between "haven't been able to" and "wouldn't learn the tools". Ashley's post below sums it up best. This is a problem that's seen regularly when working with new ideas. How many times have you seen Agile blamed when a project fails due to poor management? I personally see this all the time. > > A poor craftsman blames his tools. > > I don't get upset when people stop using RSpec, but I do get rather upset when people blame it because they mis-used it. The caboose post just seems to justify this kind of behaviour. Notice the first comment, which says: > > From Patrick Reagan: "We liked the BDD-style syntax and context, but found that it gave a false sense of security when it came to doing functional testing because the views were completely separated from the controllers under test." > > Patrick completely misses the point. He had bad examples (which are worse than no examples at all) and blames RSpec because he doesn't understand BDD. This isn't just BDD, decoupling is one of the benefits realized by the original TDD folks, and he's saying "No, I want my separate objects to be coupled tightly because it's less work." The tight coupling is actually what gives the false sense of security. > > -Steven I agree with your thoughts and sentiments Steven. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From zach.dennis at gmail.com Tue Nov 4 09:58:59 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 4 Nov 2008 09:58:59 -0500 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <8d961d900811040525x70cd1e6dh25838778e4d5b53f@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <8d961d900811040525x70cd1e6dh25838778e4d5b53f@mail.gmail.com> Message-ID: <85d99afe0811040658m5bdb35cg574a1b7f1ee51266@mail.gmail.com> On Tue, Nov 4, 2008 at 8:25 AM, aslak hellesoy wrote: > On Tue, Nov 4, 2008 at 10:39 AM, Tom Stuart wrote: >> Hi, >> >> Any responses to >> http://blog.caboo.se/articles/2008/11/4/we-ve-stopped-using-rspec ? How much >> of this is due to legitimate bugs/problems versus unfortunate circumstances? >> Feels kind of worrying that they haven't been able to make it work for them. >> > > I wish people would seek out the developers (mailing list, bug > tracker) before they go out and whine. See my comment in the blog > post. > I completely agree. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From ashley.moran at patchspace.co.uk Tue Nov 4 10:13:05 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 15:13:05 +0000 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> Message-ID: On 4 Nov 2008, at 14:37, Steven Baker wrote: > The subject is wrong too; Caboosers didn't drop RSpec. Two people > from caboose dropped RSpec. Most of the caboosers I know are still > using RSpec. Sadly this one has legs and is running wild: http://www.rubyflow.com/items/1131 Never let the facts get it the way of a good headline? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Tue Nov 4 10:17:05 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 15:17:05 +0000 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> Message-ID: <248FB2C6-143F-45AD-9D5C-4F5F377CA2A2@patchspace.co.uk> On 4 Nov 2008, at 15:13, Ashley Moran wrote: > Never let the facts get it the way of a good headline? in even -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From steven at stevenrbaker.com Tue Nov 4 10:20:01 2008 From: steven at stevenrbaker.com (Steven Baker) Date: Tue, 4 Nov 2008 08:20:01 -0700 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <248FB2C6-143F-45AD-9D5C-4F5F377CA2A2@patchspace.co.uk> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <248FB2C6-143F-45AD-9D5C-4F5F377CA2A2@patchspace.co.uk> Message-ID: <9d8eb37a0811040720m270c3d90sa23555b1dbf63b15@mail.gmail.com> >> Never let the facts get it the way of a good headline? This is typical of rubyflow. I wouldn't worry about it too much. It was only a matter of time before the unfortunate political climate of the Rails community started bleeding into our party. Please don't let this get in the way of learning and making use of good practices, people. -Steven From aslak.hellesoy at gmail.com Tue Nov 4 10:26:30 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 4 Nov 2008 16:26:30 +0100 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <9d8eb37a0811040720m270c3d90sa23555b1dbf63b15@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <248FB2C6-143F-45AD-9D5C-4F5F377CA2A2@patchspace.co.uk> <9d8eb37a0811040720m270c3d90sa23555b1dbf63b15@mail.gmail.com> Message-ID: <8d961d900811040726n4269f05eu3b30eb9bdf10a619@mail.gmail.com> On Tue, Nov 4, 2008 at 4:20 PM, Steven Baker wrote: >>> Never let the facts get it the way of a good headline? > > This is typical of rubyflow. I wouldn't worry about it too much. > > It was only a matter of time before the unfortunate political climate > of the Rails community started bleeding into our party. > > Please don't let this get in the way of learning and making use of > good practices, people. > exactly. DNFTT kthxbye > -Steven > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Tue Nov 4 10:29:40 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 07:29:40 -0800 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> (Andrew Premdas's message of "Tue\, 4 Nov 2008 12\:45\:31 +0000") References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> Message-ID: "Andrew Premdas" writes: > General case I'm thinking about is just testing that something should be one thing or another > > e.g x.should be(foo || bar) > > Haven't got a specific example at the moment apart from the blank one. What I'm thinking about is the syntax to say this in a spec, as I > think there must be lots of times when having this sort of syntax would be useful. Hi, This is a case where a custom matcher would be hiding a concept that belongs directly in your code. If you really don't care about the difference between empty and nil, you should create a method - such as #blank? - that handles that for you. Pat From jimlindley at gmail.com Tue Nov 4 10:32:07 2008 From: jimlindley at gmail.com (Jim Lindley) Date: Tue, 4 Nov 2008 10:32:07 -0500 Subject: [rspec-users] NoMethodError dependent on spec order Message-ID: <1b165db00811040732p38a1a1a1n7a7794137071bd32@mail.gmail.com> Hello, Sometimes when we place expectations on class methods, the class methods seem to be not available in their previous form for other, later specs. Calling the class methods in other specs result in a no method error. We commonly find this happening when model specs run after controller specs - the Model.find expectations in controller specs make Model.find actual calls in model specs result in errors. Running them in reverse removes the errors. I'm wondering if I'm using RSpec wrong, or if it's a bug. My assumption is that after the example group in which the expectation has been placed, the original functionality of the class is restored. That's supposed to be the function of of Proxy#reset_proxied_methods, if I'm understanding the RSpec source correctly. Here's a link to a minimal, standalone, example of what I'm talking about, although it deals with define_method instead of find. The output we get when running the specs is in the pastie at the bottom, commented out. http://gist.github.com/22144 It's extracted from a Rails app but has been modified to be run on it's own, with no external dependencies or configuration. The error happens under 1.1.11 and also edge RSpec from github. We are seeing it on Mac 10.5 and also Ubuntu 8.04. jlindley at Hypatia:~/sites/cpi2/spec/models(master)$ spec -v rspec 1.1.11 jlindley at Hypatia:~/sites/cpi2/spec/models(master)$ ruby -v ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0] Thanks! Jim Lindley From dchelimsky at gmail.com Tue Nov 4 10:35:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Nov 2008 09:35:21 -0600 Subject: [rspec-users] NoMethodError dependent on spec order In-Reply-To: <1b165db00811040732p38a1a1a1n7a7794137071bd32@mail.gmail.com> References: <1b165db00811040732p38a1a1a1n7a7794137071bd32@mail.gmail.com> Message-ID: <57c63afe0811040735i71e3438tcc8e81f299b803aa@mail.gmail.com> On Tue, Nov 4, 2008 at 9:32 AM, Jim Lindley wrote: > Hello, > > Sometimes when we place expectations on class methods, the class > methods seem to be not available in their previous form for other, > later specs. Calling the class methods in other specs result in a no > method error. We commonly find this happening when model specs run > after controller specs - the Model.find expectations in controller > specs make Model.find actual calls in model specs result in errors. > Running them in reverse removes the errors. > > I'm wondering if I'm using RSpec wrong, or if it's a bug. My > assumption is that after the example group in which the expectation > has been placed, the original functionality of the class is restored. > That's supposed to be the function of of Proxy#reset_proxied_methods, > if I'm understanding the RSpec source correctly. > > Here's a link to a minimal, standalone, example of what I'm talking > about, although it deals with define_method instead of find. The > output we get when running the specs is in the pastie at the bottom, > commented out. > > http://gist.github.com/22144 > > It's extracted from a Rails app but has been modified to be run on > it's own, with no external dependencies or configuration. The error > happens under 1.1.11 and also edge RSpec from github. We are seeing it > on Mac 10.5 and also Ubuntu 8.04. > > jlindley at Hypatia:~/sites/cpi2/spec/models(master)$ spec -v > rspec 1.1.11 > > jlindley at Hypatia:~/sites/cpi2/spec/models(master)$ ruby -v > ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0] > > Thanks! > > Jim Lindley Hey Jim - I think this is related to this: http://rspec.lighthouseapp.com/projects/5645/tickets/589 Would you kindly add your comments to that ticket? Thanks, David From lists at ruby-forum.com Tue Nov 4 10:32:29 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 16:32:29 +0100 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> Message-ID: <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> > A poor craftsman blames his tools. > And the poor toolmaker blames the craftsman for being too stupid to understand how to use his tools. You say these guys should have come over and posted to this mailing-list or submitted bugs. But when I read the posts here, most of the time, when someone has a problem he gets pointed to the unfriendly documentation pages or worse, the very thin docs available at github. That doesn't really motivate people to share their experiences with RSpec, and when they do, rspec supporters treat them as "whiners". -- Posted via http://www.ruby-forum.com/. From apremdas at gmail.com Tue Nov 4 10:41:34 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 4 Nov 2008 15:41:34 +0000 Subject: [rspec-users] Testing a wizard with Cucumber Message-ID: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> Assuming you have a multi-step wizard like thing, with lots of different states and paths through it. What approach would your use to write a feature for it? What I want to do is do the separate states and then reuse these things in more complex scenarios that cover paths. For example Scenario: State A Given I'm ... And I'm ... When I ... Then I should see And I at state A Now I'd like to reuse this to make my scenario from going from A to B shorter e.g Scenario: Test A to B Given State A When I ... ... Instead of Scenario: Test A to B Given I'm ... And I'm ... When I ... Then I should see And I at state A When I ... ... Is this possible? Do you have any other pointers about simplifying and organising complex scenarios? Thanks in advance... -------------- next part -------------- An HTML attachment was scrubbed... URL: From luislavena at gmail.com Tue Nov 4 10:55:56 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 4 Nov 2008 12:55:56 -0300 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> Message-ID: <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> On Tue, Nov 4, 2008 at 12:32 PM, Fernando Perez wrote: >> A poor craftsman blames his tools. >> > And the poor toolmaker blames the craftsman for being too stupid to > understand how to use his tools. > > You say these guys should have come over and posted to this mailing-list > or submitted bugs. But when I read the posts here, most of the time, > when someone has a problem he gets pointed to the unfriendly > documentation pages or worse, the very thin docs available at github. > Oh, your statement is wrong. There are plenty of threads in this list, and also rspec-devel that span across 20 or 30 messages to help other users solve RSpec issues or deal with BDD concepts. Pat, Ashley, David and Aslak give quite share of their time answering those emails, do a search and you will find out. > That doesn't really motivate people to share their experiences with > RSpec, and when they do, rspec supporters treat them as "whiners". A whiner can recognize other whiners, I love to whine about things (and rant about them too), but I first came to the list, ask, and when noone answers, *then* I whine. Given a problem I have with RSpec And I post to the mailing list When noone answer my post And has been N days since I posted Then I start whining in my blog about it -- Luis Lavena AREA 17 - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From jimlindley at gmail.com Tue Nov 4 10:56:37 2008 From: jimlindley at gmail.com (Jim Lindley) Date: Tue, 4 Nov 2008 10:56:37 -0500 Subject: [rspec-users] NoMethodError dependent on spec order In-Reply-To: <57c63afe0811040735i71e3438tcc8e81f299b803aa@mail.gmail.com> References: <1b165db00811040732p38a1a1a1n7a7794137071bd32@mail.gmail.com> <57c63afe0811040735i71e3438tcc8e81f299b803aa@mail.gmail.com> Message-ID: <1b165db00811040756i6ea4c1c4yf390d03c4573eb06@mail.gmail.com> > Hey Jim - I think this is related to this: > > http://rspec.lighthouseapp.com/projects/5645/tickets/589 > > Would you kindly add your comments to that ticket? > I updated the ticket, thanks David! I also changed the title to something more general then the existing case implied. It's not just Kernel that's affected in our case. From nick at deadorange.com Tue Nov 4 11:06:01 2008 From: nick at deadorange.com (Nick Hoffman) Date: Tue, 4 Nov 2008 11:06:01 -0500 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> Message-ID: On 2008-11-04, at 10:32, Fernando Perez wrote: > You say these guys should have come over and posted to this mailing- > list > or submitted bugs. But when I read the posts here, most of the time, > when someone has a problem he gets pointed to the unfriendly > documentation pages or worse, the very thin docs available at github. Hey there Fernando. I read about 80% of the emails on this ML, and find that most people are incredibly helpful, and devote a lot of their time to answering other peoples' questions and problems. Occasionally a question will be answered concisely with a URL, but that's usually when the question has been answered several times already, and the answer is explained well at the given URL. I couldn't be happier with the suggestions, feedback and help that I've received on this ML. You should check out some of the longer threads to see how dedicated the people here are to helping others. Cheers, Nick From sfeley at gmail.com Tue Nov 4 11:09:21 2008 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 4 Nov 2008 10:09:21 -0600 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> Message-ID: <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> On Tue, Nov 4, 2008 at 9:55 AM, Luis Lavena wrote: > On Tue, Nov 4, 2008 at 12:32 PM, Fernando Perez wrote: >> >> But when I read the posts here, most of the time, >> when someone has a problem he gets pointed to the unfriendly >> documentation pages or worse, the very thin docs available at github. > > Oh, your statement is wrong. Not all of it. The list is pretty helpful, sure, but the documentation _could_ stand for a lot of improvement. I find it very opaque, too, especially from a "Getting Started" perspective. There are posts and slideshows scattered all over the blogosphere, but finding them isn't straightforward. I know there's a book coming, but it ain't here yet. And the Peepcode videos are good (they're how I learned) but to watch all of the RSpec ones is over four hours. Also nearly forty bucks or an annual subscription. It's something I've been poking at a bit, though haven't had the time yet to bring things together. So I identify myself as part of the problem too. I could communicate what little _I_ know about RSpec... But I haven't yet. > Pat, Ashley, David and Aslak give quite share of their time answering > those emails, do a search and you will find out. That's not a replacement for good documentation. You have to have a certain grounding before you can even figure out where to go and what questions to ask -- and I don't feel the most visible resources for that grounding are as good as they could be. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From apremdas at gmail.com Tue Nov 4 11:20:58 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 4 Nov 2008 16:20:58 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <3D18548F-9B81-4C35-8C5A-C7577871DCCD@patchspace.co.uk> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <3D18548F-9B81-4C35-8C5A-C7577871DCCD@patchspace.co.uk> Message-ID: <88fd8ddc0811040820j6132622i12b4c79450e4b6f3@mail.gmail.com> Ashley, Thanks for your time on this, the reply does make sense, and I can see from an OO point of view that any particular object being (foo||bar) is equivalent to that object being baz. However with the dynamic nature of ruby we often don't know what object we are going to be dealing with in our tests/specs. Whilst a unit test will generally (always?) be aimed at a particular type, when implementing a plain text feature/story we are often working at a much higher level. In these cases the (foo || bar) construct could mean different types and a baz might not exist or be particularly easy to represent or formulate. I can see that wanting this construct, could indicate a smell maybe a badly worded story - i.e. a conjunction step. All best Andrew 2008/11/4 Ashley Moran > > On 4 Nov 2008, at 12:45, Andrew Premdas wrote: > > General case I'm thinking about is just testing that something should be >> one thing or another >> >> e.g x.should be(foo || bar) >> >> Haven't got a specific example at the moment apart from the blank one. >> What I'm thinking about is the syntax to say this in a spec, as I think >> there must be lots of times when having this sort of syntax would be useful. >> > > Hi Andrew > > I suspect that in general the concept of an object O being (foo || bar) > actually means there's a rule that makes your object baz instead. The > reason is that if you spec foo and bar independently, you double the number > of contexts for objects that depend on O. > > So this might not look to bad: > > describe MyObject do > before(:each) do > @o = MyObject.new > end > > it "should be foo or bar" do > @o.should be_foo_or_bar > end > end > > but it means everywhere else you're forced to duplicate that logic, eg: > > describe MyOtherObject do > describe "when its MyObject is foo" do > before(:each) do > o = mock(MyObject, :foo => true, :bar => false) > @oo = MyOtherObject.new(o) > end > it "should be faz" do > @oo.should be_faz > end > end > > describe "when its MyObject is bar" do > before(:each) do > o = mock(MyObject, :foo => false, :bar => true) > @oo = MyOtherObject.new(o) > end > it "should be faz" do > @oo.should be_faz > end > end > > describe "when its MyObject is neither foo nor bar" do > before(:each) do > o = mock(MyObject, :foo => false, :bar => false) > @oo = MyOtherObject.new(o) > end > it "should not be faz" do > @oo.should_not be_faz > end > end > end > > instead of just: > > describe MyOtherObject do > describe "when its MyObject is baz" do > before(:each) do > o = mock(MyObject, :baz => true) > @oo = MyOtherObject.new(o) > end > it "should be faz" do > @oo.should be_faz > end > end > > describe "when its MyObject is not baz" do > before(:each) do > o = mock(MyObject, :baz => false) > @oo = MyOtherObject.new(o) > end > it "should not be faz" do > @oo.should_not be_faz > end > end > end > > s/foo/nil/ > s/bar/empty/ > s/baz/blank/ > > This make sense? Sorry if it's a bit abstract, or has typos. I didn't > actually run that code, of course... > > I think in summary, two branches in your specs => you are violating Tell > Don't Ask (somewhere else) in your code. > > > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From luislavena at gmail.com Tue Nov 4 11:24:14 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 4 Nov 2008 13:24:14 -0300 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> Message-ID: <71166b3b0811040824h3de0a92ev21a866f09b057e1e@mail.gmail.com> On Tue, Nov 4, 2008 at 1:09 PM, Stephen Eley wrote: > On Tue, Nov 4, 2008 at 9:55 AM, Luis Lavena wrote: >> On Tue, Nov 4, 2008 at 12:32 PM, Fernando Perez wrote: >>> >>> But when I read the posts here, most of the time, >>> when someone has a problem he gets pointed to the unfriendly >>> documentation pages or worse, the very thin docs available at github. >> >> Oh, your statement is wrong. > > Not all of it. The list is pretty helpful, sure, but the > documentation _could_ stand for a lot of improvement. I find it very > opaque, too, especially from a "Getting Started" perspective. There > are posts and slideshows scattered all over the blogosphere, but > finding them isn't straightforward. I know there's a book coming, but > it ain't here yet. And the Peepcode videos are good (they're how I > learned) but to watch all of the RSpec ones is over four hours. Also > nearly forty bucks or an annual subscription. Neither Rails was the one with best documentation (which btw I wonder what happened with the caboose documentation project they collected 12K, anyway). I don't see any "tutorial" on internet for starting with XP, or either Scrum, or anything like that... took them years to evolve and be able to produce a book. Until then, you have mailing lists and blog posts to share the knowledge. > It's something I've been poking at a bit, though haven't had the time > yet to bring things together. So I identify myself as part of the > problem too. I could communicate what little _I_ know about RSpec... > But I haven't yet. > Welcome aboard, we are share the guilty part. > >> Pat, Ashley, David and Aslak give quite share of their time answering >> those emails, do a search and you will find out. > > That's not a replacement for good documentation. You have to have a > certain grounding before you can even figure out where to go and what > questions to ask -- and I don't feel the most visible resources for > that grounding are as good as they could be. > And what ranting and whining provides? -- 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 Tue Nov 4 11:20:47 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 4 Nov 2008 16:20:47 +0000 Subject: [rspec-users] Better RSpec newbie documentation (was: Caboosers drop RSpec) In-Reply-To: <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> Message-ID: <9DD3C2DB-9CC6-4E98-98E8-6E78F7911ED0@mattwynne.net> On 4 Nov 2008, at 16:09, Stephen Eley wrote: >> Pat, Ashley, David and Aslak give quite share of their time answering >> those emails, do a search and you will find out. > > That's not a replacement for good documentation. You have to have a > certain grounding before you can even figure out where to go and what > questions to ask -- and I don't feel the most visible resources for > that grounding are as good as they could be. This is a point I've made before (and David has rightly pointed me at the source of the rspec.info website), but I'm now so immersed in RSpec myself I would find it hard to see the gaps in the documentation, I think. Plus I'm lazy, and, y'know, busy at work. I almost wonder whether it would be worth ripping up the rspec.info site and pointing everyone at the github wiki, then putting some real effort into making that as good as it can be. Just a thought. cheers, Matt From matt at mattwynne.net Tue Nov 4 11:29:30 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 4 Nov 2008 16:29:30 +0000 Subject: [rspec-users] Testing a wizard with Cucumber In-Reply-To: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> References: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> Message-ID: <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> On 4 Nov 2008, at 15:41, Andrew Premdas wrote: > Assuming you have a multi-step wizard like thing, with lots of > different states and paths through it. What approach would your use > to write a feature for it? What I want to do is do the separate > states and then reuse these things in more complex scenarios that > cover paths. For example > > Scenario: State A > Given I'm ... > And I'm ... > When I ... > Then I should see > And I at state A > > Now I'd like to reuse this to make my scenario from going from A to > B shorter e.g > > Scenario: Test A to B > Given State A > When I ... > ... > > > Instead of > > Scenario: Test A to B > Given I'm ... > And I'm ... > When I ... > Then I should see > And I at state A > When I ... > ... > > Is this possible? Do you have any other pointers about simplifying > and organising complex scenarios? Thanks in advance... There's a relatively new (and possibly undocumented) feature in cucumber[1] where you can call steps from within other steps. So for example, you can have one scenario like this: Scenario: Log in as admin Given I visit the login page And I enter the username "matt" And I enter the password "secret" And I press "Submit" Then I should be on the admin page And another one like this: Scenario: View admin reports Given I log in as admin And I view the reports page Then I should see "reports" When you write the ruby step matcher for the first step in this scenario, you just call the step matchers that you wrote for the first scenario, like this: Given /I log in as admin/ do Given "I visit the login page" Given 'I enter the username "matt"' Given 'I enter the password "secret"' Given 'I press "Submit"' end Does that make sense? Does it help? cheers, Matt [1]http://rspec.lighthouseapp.com/projects/16211/tickets/3-create-givenscenario-dependency-accross-feature-files From lists at ruby-forum.com Tue Nov 4 11:33:17 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 17:33:17 +0100 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together Message-ID: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> Here is a very simple spec: -- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe Product, "The Product model" do describe "When a new blank product object gets created" do before(:each) do @product = Product.new end it "should not be valid" do @product.should_not be_valid @product.errors.on(:title).should_not be_nil # plenty other errors to display... end end end -- And here is the error message when I run this spec: -- spec product_spec.rb F 1) ActiveRecord::StatementInvalid in 'Product The Product model When a new blank product object gets created should not be valid' PGError: ERROR: relation "products" does not exist : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = 'products'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum ./product_spec.rb:7:in `new' ./product_spec.rb:7: Finished in 1.025511 seconds 1 example, 1 failure -- I don't understand why RSpec is trying to look for some kind of relation. In the spec I am simply calling Product.new This spec worked perfectly with MySQL. -- Posted via http://www.ruby-forum.com/. From apremdas at gmail.com Tue Nov 4 11:36:54 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 4 Nov 2008 16:36:54 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> Message-ID: <88fd8ddc0811040836y1ead5eedoc745b411c243fa88@mail.gmail.com> Ok I see. I was approaching this more from the syntax that my stories can express rather than what my code does. However from these replies and a re-read of the cucumber wiki I can see that any step that requires the (foo||bar) construct is by definition a conjunction and can be broken into smaller steps. However we only have 'And' available in stories, do we need 'Or'? All best Andrew 2008/11/4 Pat Maddox > "Andrew Premdas" writes: > > > General case I'm thinking about is just testing that something should be > one thing or another > > > > e.g x.should be(foo || bar) > > > > Haven't got a specific example at the moment apart from the blank one. > What I'm thinking about is the syntax to say this in a spec, as I > > think there must be lots of times when having this sort of syntax would > be useful. > > Hi, > > This is a case where a custom matcher would be hiding a concept that > belongs directly in your code. If you really don't care about the > difference between empty and nil, you should create a method - such as > #blank? - that handles that for you. > > 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 zach.dennis at gmail.com Tue Nov 4 11:44:14 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 4 Nov 2008 11:44:14 -0500 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <88fd8ddc0811040836y1ead5eedoc745b411c243fa88@mail.gmail.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <88fd8ddc0811040836y1ead5eedoc745b411c243fa88@mail.gmail.com> Message-ID: <85d99afe0811040844s674782daibf0bdc6a45252897@mail.gmail.com> On Tue, Nov 4, 2008 at 11:36 AM, Andrew Premdas wrote: > Ok I see. I was approaching this more from the syntax that my stories can > express rather than what my code does. However from these replies and a > re-read of the cucumber wiki I can see that any step that requires the > (foo||bar) construct is by definition a conjunction and can be broken into > smaller steps. > However we only have 'And' available in stories, do we need 'Or'? What is your scenario that you are thinking of using an "or" ? This may be helpful, otherwise we're going to speculating about the theoretical use cases. I'd rather focus on your specific use case. :) -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From zuperinfinite at gmail.com Tue Nov 4 11:45:25 2008 From: zuperinfinite at gmail.com (Bart Zonneveld) Date: Tue, 4 Nov 2008 17:45:25 +0100 Subject: [rspec-users] Better RSpec newbie documentation (was: Caboosers drop RSpec) In-Reply-To: <9DD3C2DB-9CC6-4E98-98E8-6E78F7911ED0@mattwynne.net> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <9DD3C2DB-9CC6-4E98-98E8-6E78F7911ED0@mattwynne.net> Message-ID: <357CD3F6-CB6B-496F-8D20-FB7EF513B0A4@gmail.com> On 4-nov-2008, at 17:20, Matt Wynne wrote: > On 4 Nov 2008, at 16:09, Stephen Eley wrote: >>> Pat, Ashley, David and Aslak give quite share of their time >>> answering >>> those emails, do a search and you will find out. >> >> That's not a replacement for good documentation. You have to have a >> certain grounding before you can even figure out where to go and what >> questions to ask -- and I don't feel the most visible resources for >> that grounding are as good as they could be. > > This is a point I've made before (and David has rightly pointed me > at the source of the rspec.info website), but I'm now so immersed > in RSpec myself I would find it hard to see the gaps in the > documentation, I think. Plus I'm lazy, and, y'know, busy at work. > > I almost wonder whether it would be worth ripping up the rspec.info > site and pointing everyone at the github wiki, then putting some > real effort into making that as good as it can be. That would be a good idea. No more rspec.info and rspec.rubyforge.net, but just github and The Book. The Book would be nice.. Already have an empty slot reserved on my bookshelf ;) cheers, bartz From zach.dennis at gmail.com Tue Nov 4 11:46:12 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 4 Nov 2008 11:46:12 -0500 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> Message-ID: <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> On Tue, Nov 4, 2008 at 11:33 AM, Fernando Perez wrote: > Here is a very simple spec: > -- > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > > describe Product, "The Product model" do > > describe "When a new blank product object gets created" do > before(:each) do > @product = Product.new > end > > it "should not be valid" do > @product.should_not be_valid > @product.errors.on(:title).should_not be_nil > # plenty other errors to display... > end > end > end > -- > > And here is the error message when I run this spec: > -- > spec product_spec.rb > F > > 1) > ActiveRecord::StatementInvalid in 'Product The Product model When a new > blank product object gets created should not be valid' > PGError: ERROR: relation "products" does not exist > : SELECT a.attname, format_type(a.atttypid, a.atttypmod), > d.adsrc, a.attnotnull > FROM pg_attribute a LEFT JOIN pg_attrdef d > ON a.attrelid = d.adrelid AND a.attnum = d.adnum > WHERE a.attrelid = 'products'::regclass > AND a.attnum > 0 AND NOT a.attisdropped > ORDER BY a.attnum > ./product_spec.rb:7:in `new' > ./product_spec.rb:7: > > Finished in 1.025511 seconds > > 1 example, 1 failure > -- > > I don't understand why RSpec is trying to look for some kind of > relation. In the spec I am simply calling Product.new > > This spec worked perfectly with MySQL. I am going to go out on a limb and say that I don't think this is an RSpec problem. Outside of the spec, if you launch script/console in both development and test environments, when you do Product.new, do you have any issues? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From zach.dennis at gmail.com Tue Nov 4 11:47:06 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 4 Nov 2008 11:47:06 -0500 Subject: [rspec-users] Better RSpec newbie documentation (was: Caboosers drop RSpec) In-Reply-To: <357CD3F6-CB6B-496F-8D20-FB7EF513B0A4@gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <9DD3C2DB-9CC6-4E98-98E8-6E78F7911ED0@mattwynne.net> <357CD3F6-CB6B-496F-8D20-FB7EF513B0A4@gmail.com> Message-ID: <85d99afe0811040847u2704c6a6q132d0c858bd7067a@mail.gmail.com> On Tue, Nov 4, 2008 at 11:45 AM, Bart Zonneveld wrote: > > On 4-nov-2008, at 17:20, Matt Wynne wrote: > >> On 4 Nov 2008, at 16:09, Stephen Eley wrote: >>>> >>>> Pat, Ashley, David and Aslak give quite share of their time answering >>>> those emails, do a search and you will find out. >>> >>> That's not a replacement for good documentation. You have to have a >>> certain grounding before you can even figure out where to go and what >>> questions to ask -- and I don't feel the most visible resources for >>> that grounding are as good as they could be. >> >> This is a point I've made before (and David has rightly pointed me at the >> source of the rspec.info website), but I'm now so immersed in RSpec myself I >> would find it hard to see the gaps in the documentation, I think. Plus I'm >> lazy, and, y'know, busy at work. >> >> I almost wonder whether it would be worth ripping up the rspec.info site >> and pointing everyone at the github wiki, then putting some real effort into >> making that as good as it can be. > > That would be a good idea. No more rspec.info and rspec.rubyforge.net, but > just github and The Book. The Book would be nice.. Already have an empty > slot reserved on my bookshelf ;) > Your real bookshelf, or your Shelfari one? :) http://www.shelfari.com/ -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From apremdas at gmail.com Tue Nov 4 11:53:06 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 4 Nov 2008 16:53:06 +0000 Subject: [rspec-users] Testing a wizard with Cucumber In-Reply-To: <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> References: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> Message-ID: <88fd8ddc0811040853j6dd4a240mb6314a73e9ebe3c1@mail.gmail.com> Thanks Matt, just what I was looking for :) Andrew 2008/11/4 Matt Wynne > On 4 Nov 2008, at 15:41, Andrew Premdas wrote: > > Assuming you have a multi-step wizard like thing, with lots of different >> states and paths through it. What approach would your use to write a feature >> for it? What I want to do is do the separate states and then reuse these >> things in more complex scenarios that cover paths. For example >> >> Scenario: State A >> Given I'm ... >> And I'm ... >> When I ... >> Then I should see >> And I at state A >> >> Now I'd like to reuse this to make my scenario from going from A to B >> shorter e.g >> >> Scenario: Test A to B >> Given State A >> When I ... >> ... >> >> >> Instead of >> >> Scenario: Test A to B >> Given I'm ... >> And I'm ... >> When I ... >> Then I should see >> And I at state A >> When I ... >> ... >> >> Is this possible? Do you have any other pointers about simplifying and >> organising complex scenarios? Thanks in advance... >> > > There's a relatively new (and possibly undocumented) feature in cucumber[1] > where you can call steps from within other steps. > > So for example, you can have one scenario like this: > > Scenario: Log in as admin > Given I visit the login page > And I enter the username "matt" > And I enter the password "secret" > And I press "Submit" > Then I should be on the admin page > > > And another one like this: > Scenario: View admin reports > Given I log in as admin > And I view the reports page > Then I should see "reports" > > When you write the ruby step matcher for the first step in this scenario, > you just call the step matchers that you wrote for the first scenario, like > this: > > Given /I log in as admin/ do > Given "I visit the login page" > Given 'I enter the username "matt"' > Given 'I enter the password "secret"' > Given 'I press "Submit"' > end > > Does that make sense? Does it help? > > cheers, > Matt > > [1] > http://rspec.lighthouseapp.com/projects/16211/tickets/3-create-givenscenario-dependency-accross-feature-files > _______________________________________________ > 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 apremdas at gmail.com Tue Nov 4 11:57:10 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 4 Nov 2008 16:57:10 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <85d99afe0811040844s674782daibf0bdc6a45252897@mail.gmail.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <88fd8ddc0811040836y1ead5eedoc745b411c243fa88@mail.gmail.com> <85d99afe0811040844s674782daibf0bdc6a45252897@mail.gmail.com> Message-ID: <88fd8ddc0811040857i12cd49ffv478f8ffdff7fd519@mail.gmail.com> Oh I was definitely into theoretical speculation here :) - haven't got a particular case at the moment 2008/11/4 Zach Dennis > On Tue, Nov 4, 2008 at 11:36 AM, Andrew Premdas > wrote: > > Ok I see. I was approaching this more from the syntax that my stories can > > express rather than what my code does. However from these replies and a > > re-read of the cucumber wiki I can see that any step that requires the > > (foo||bar) construct is by definition a conjunction and can be broken > into > > smaller steps. > > However we only have 'And' available in stories, do we need 'Or'? > > What is your scenario that you are thinking of using an "or" ? This > may be helpful, otherwise we're going to speculating about the > theoretical use cases. I'd rather focus on your specific use case. :) > > -- > 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 dchelimsky at gmail.com Tue Nov 4 12:07:20 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Nov 2008 11:07:20 -0600 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> Message-ID: <57c63afe0811040907q4c22b9eas11da6d2f9346e2cc@mail.gmail.com> On Tue, Nov 4, 2008 at 9:29 AM, Pat Maddox wrote: > "Andrew Premdas" writes: > >> General case I'm thinking about is just testing that something should be one thing or another >> >> e.g x.should be(foo || bar) >> >> Haven't got a specific example at the moment apart from the blank one. What I'm thinking about is the syntax to say this in a spec, as I >> think there must be lots of times when having this sort of syntax would be useful. > > Hi, > > This is a case where a custom matcher would be hiding a concept that > belongs directly in your code. If you really don't care about the > difference between empty and nil, you should create a method - such as > #blank? - that handles that for you. In which case you would get be_blank for free, in case you weren't aware. FYI - if you REALLY want to match against either, it's pretty easy to do w/ simple matcher: def be_nil_or_empty simple_matcher "nil? or empty? to return true" do |actual| actual.nil? || actual.empty? end end Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Nov 4 12:07:39 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 18:07:39 +0100 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> Message-ID: <30194912ad0ae021a94522cb12dcb6db@ruby-forum.com> Doh! I forgot to run the migrations in the newly created DB. Thanks. -- Posted via http://www.ruby-forum.com/. From mark at mwilden.com Tue Nov 4 12:15:00 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 4 Nov 2008 09:15:00 -0800 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> Message-ID: <3c30da400811040915q34e46cf3r3801b0756dde8ea3@mail.gmail.com> > > On Tue, Nov 4, 2008 at 11:33 AM, Fernando Perez > wrote: > > > @product = Product.new > > > PGError: ERROR: relation "products" does not exist > > > I don't understand why RSpec is trying to look for some kind of > > relation. In the spec I am simply calling Product.new > PostgreSQL uses the term 'relation' for 'table' (hence the term 'relational database'). Some folks think that a relation is a relationship between one table and another, via a shared column value, or key. However, a relation is actually the relationship between the values of the columns in a the rows of a table. A database consists of a set of these relations, each of which satisfies a given logical statement, or predicate. For example, your products table is set of related columns and rows such that every row corresponds to a "product" in your system, whose column values match attributes of that product. My first guess as to your problem is that you need to run 'rake db:migrate'. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From MikeG1 at larkfarm.com Tue Nov 4 11:47:01 2008 From: MikeG1 at larkfarm.com (Mike Gunderloy) Date: Tue, 4 Nov 2008 10:47:01 -0600 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <71166b3b0811040824h3de0a92ev21a866f09b057e1e@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <71166b3b0811040824h3de0a92ev21a866f09b057e1e@mail.gmail.com> Message-ID: <99D9DAB9-0E19-414F-BEC3-B17ED68F40DE@larkfarm.com> On Nov 4, 2008, at 10:24 AM, Luis Lavena wrote: > Neither Rails was the one with best documentation (which btw I wonder > what happened with the caboose documentation project they collected > 12K, anyway). Tangential to this discussion, but anyhow: some of that money is going into the Rails Guides hackfest right now. Rails docs can always use improvement (as can RSpec's - and I say that as a committed RSpec user who is still confused too much of the time), but we're making progress, I think. From luislavena at gmail.com Tue Nov 4 12:32:19 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 4 Nov 2008 14:32:19 -0300 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <99D9DAB9-0E19-414F-BEC3-B17ED68F40DE@larkfarm.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <71166b3b0811040824h3de0a92ev21a866f09b057e1e@mail.gmail.com> <99D9DAB9-0E19-414F-BEC3-B17ED68F40DE@larkfarm.com> Message-ID: <71166b3b0811040932m3817b837g33b4674014f7a011@mail.gmail.com> On Tue, Nov 4, 2008 at 1:47 PM, Mike Gunderloy wrote: > On Nov 4, 2008, at 10:24 AM, Luis Lavena wrote: > >> Neither Rails was the one with best documentation (which btw I wonder >> what happened with the caboose documentation project they collected >> 12K, anyway). > > Tangential to this discussion, but anyhow: some of that money is going into > the Rails Guides hackfest right now. Rails docs can always use improvement > (as can RSpec's - and I say that as a committed RSpec user who is still > confused too much of the time), but we're making progress, I think. > Actually I didn't know about it, sometimes lot of that stuff get lost between links. We are all still confused with RSpec, is hard when you need to jump from Test::Unit, NUnit and other testing frameworks back and forth (at least for me). What about something like the merb book? I know David cannot participate on it, but others can and we should bring the basic and advance techniques from blog posts and the mailing list to that document. -- 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 court3nay at gmail.com Tue Nov 4 12:32:08 2008 From: court3nay at gmail.com (court3nay) Date: Tue, 4 Nov 2008 09:32:08 -0800 (PST) Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <8d961d900811040525x70cd1e6dh25838778e4d5b53f@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <8d961d900811040525x70cd1e6dh25838778e4d5b53f@mail.gmail.com> Message-ID: On Nov 4, 5:25?am, "aslak hellesoy" wrote: > On Tue, Nov 4, 2008 at 10:39 AM, Tom Stuart wrote: > > Hi, > > > Any responses to > >http://blog.caboo.se/articles/2008/11/4/we-ve-stopped-using-rspec? How much > > of this is due to legitimate bugs/problems versus unfortunate circumstances? > > Feels kind of worrying that they haven't been able to make it work for them. > > I wish people would seek out the developers (mailing list, bug > tracker) before they go out and whine. See my comment in the blog > post. > Well, I didn't think we were whining. I've been using rSpec since the early days, have contributed code and bug reports back (our team has built plugins around rspec too). We have more than 30 active projects in production built with rSpec.. tens (hundreds?) of thousands of lines of test code.. it's been the best choice for us, so far, and obviously I'm not planning on throwing that out. It's really not a case of "waah, waah, rspec sucks", even if you want to hear it that way. However, in my opinion the upgrade path should not be difficult, and the ability to have development tools (rspec) not checked into the code base for production deployment (config.gems in test.rb) is important to me. So when we upgraded and versions started leaking between apps and specs start failing mysteriously for some developers and not others, we started casting about for something simpler and/or better. I don't want to be fighting my tools, I want them to be working with me.. I don't want to start getting weird failures from an upgrade. It might well be bugs in Rails not rSpec, but if the only thing that changed was rSpec, well, you see my problem. In my mind rspec has a long history of breaking things between versions. My blog post was an honest attempt at finding out what the wider community is using -- why, how -- for their testing needs. I'm not going to find that on the rspec-users mailing list. And, yes, it is obvious that many of the commenters don't understand how to use rSpec. Courtenay From pergesu at gmail.com Tue Nov 4 12:49:31 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 09:49:31 -0800 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> (Fernando Perez's message of "Tue\, 4 Nov 2008 17\:33\:17 +0100") References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> Message-ID: Fernando Perez writes: > Here is a very simple spec: > -- > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > > describe Product, "The Product model" do > > describe "When a new blank product object gets created" do > before(:each) do > @product = Product.new > end > > it "should not be valid" do > @product.should_not be_valid > @product.errors.on(:title).should_not be_nil > # plenty other errors to display... > end > end > end > -- > > And here is the error message when I run this spec: > -- > spec product_spec.rb > F > > 1) > ActiveRecord::StatementInvalid in 'Product The Product model When a new > blank product object gets created should not be valid' > PGError: ERROR: relation "products" does not exist > : SELECT a.attname, format_type(a.atttypid, a.atttypmod), > d.adsrc, a.attnotnull > FROM pg_attribute a LEFT JOIN pg_attrdef d > ON a.attrelid = d.adrelid AND a.attnum = d.adnum > WHERE a.attrelid = 'products'::regclass > AND a.attnum > 0 AND NOT a.attisdropped > ORDER BY a.attnum > ./product_spec.rb:7:in `new' > ./product_spec.rb:7: > > Finished in 1.025511 seconds > > 1 example, 1 failure > -- > > I don't understand why RSpec is trying to look for some kind of > relation. In the spec I am simply calling Product.new > > This spec worked perfectly with MySQL. Highly doubt it's an RSpec problem. Just looks like you didn't create the table. Try "rake db:migrate db:test:prepare" Pat From matt at mattwynne.net Tue Nov 4 12:58:49 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 4 Nov 2008 17:58:49 +0000 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <8d961d900811040525x70cd1e6dh25838778e4d5b53f@mail.gmail.com> Message-ID: <4E0721B2-AA4A-401E-8BF8-8375DCD59E9C@mattwynne.net> On 4 Nov 2008, at 17:32, court3nay wrote: > upgrade. It might well be bugs in Rails not rSpec, but if the only > thing that changed was rSpec, well, you see my problem. In my mind > rspec has a long history of breaking things between versions. If this is a common complaint, do we maybe need some better *acceptance tests* for rspec - some cucumber scripts which cover use cases like upgrades? How possible would that be to achieve? cheers, Matt From pergesu at gmail.com Tue Nov 4 13:05:37 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 10:05:37 -0800 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> (Fernando Perez's message of "Tue\, 4 Nov 2008 16\:32\:29 +0100") References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> Message-ID: Fernando Perez writes: >> A poor craftsman blames his tools. >> > And the poor toolmaker blames the craftsman for being too stupid to > understand how to use his tools. > > You say these guys should have come over and posted to this mailing-list > or submitted bugs. But when I read the posts here, most of the time, > when someone has a problem he gets pointed to the unfriendly > documentation pages or worse, the very thin docs available at github. > > That doesn't really motivate people to share their experiences with > RSpec, and when they do, rspec supporters treat them as "whiners". hrm...I'm not going to argue with your experience, but I will say that mine has shown the complete opposite. The RSpec list is a damn good one in my opinion, thanks to people like David, Aslak, Ben, Scott, Ashley, Matt, Joseph...and those are just a few off the top of my head. We've got a good little community here, and I'm proud to be a part of it. It's unfortunate that others have a less enjoyable experience than I have - what can we do to fix that? As far as the linked article goes, well, we're all trying to create great software. If something is keeping you from doing that, you either fix it or look somewhere else. And it's important to recognize that either choice is okay - we all have limited amounts of time and energy. Pat From pergesu at gmail.com Tue Nov 4 13:07:36 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 10:07:36 -0800 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> (Stephen Eley's message of "Tue\, 4 Nov 2008 10\:09\:21 -0600") References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> Message-ID: "Stephen Eley" writes: > The list is pretty helpful, sure, but the > documentation _could_ stand for a lot of improvement. Agree 100%. Got a git repo I can pull from? :) Pat From ben at benmabey.com Tue Nov 4 12:42:47 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 04 Nov 2008 10:42:47 -0700 Subject: [rspec-users] Testing a wizard with Cucumber In-Reply-To: <88fd8ddc0811040853j6dd4a240mb6314a73e9ebe3c1@mail.gmail.com> References: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> <88fd8ddc0811040853j6dd4a240mb6314a73e9ebe3c1@mail.gmail.com> Message-ID: <49108997.1040909@benmabey.com> Andrew Premdas wrote: > Thanks Matt, just what I was looking for :) > > Andrew You could also use GivenScenario. It works like this: Scenario: State A Given I'm ... And I'm ... When I ... Then I should see And I at state A Scenario: Test A to B GivenScenario A When I ... Or you could do a combination of this approach and what Matt suggested. Meaning, you could make a more descriptive "Given" step that simply calls the "GivenScenario State A" internally. Make sense? HTH, Ben > > 2008/11/4 Matt Wynne > > > On 4 Nov 2008, at 15:41, Andrew Premdas wrote: > > Assuming you have a multi-step wizard like thing, with lots of > different states and paths through it. What approach would > your use to write a feature for it? What I want to do is do > the separate states and then reuse these things in more > complex scenarios that cover paths. For example > > Scenario: State A > Given I'm ... > And I'm ... > When I ... > Then I should see > And I at state A > > Now I'd like to reuse this to make my scenario from going from > A to B shorter e.g > > Scenario: Test A to B > Given State A > When I ... > ... > > > Instead of > > Scenario: Test A to B > Given I'm ... > And I'm ... > When I ... > Then I should see > And I at state A > When I ... > ... > > Is this possible? Do you have any other pointers about > simplifying and organising complex scenarios? Thanks in advance... > > > There's a relatively new (and possibly undocumented) feature in > cucumber[1] where you can call steps from within other steps. > > So for example, you can have one scenario like this: > > Scenario: Log in as admin > Given I visit the login page > And I enter the username "matt" > And I enter the password "secret" > And I press "Submit" > Then I should be on the admin page > > > And another one like this: > Scenario: View admin reports > Given I log in as admin > And I view the reports page > Then I should see "reports" > > When you write the ruby step matcher for the first step in this > scenario, you just call the step matchers that you wrote for the > first scenario, like this: > > Given /I log in as admin/ do > Given "I visit the login page" > Given 'I enter the username "matt"' > Given 'I enter the password "secret"' > Given 'I press "Submit"' > end > > Does that make sense? Does it help? > > cheers, > Matt > > [1]http://rspec.lighthouseapp.com/projects/16211/tickets/3-create-givenscenario-dependency-accross-feature-files > _______________________________________________ > 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 Nov 4 13:18:52 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 4 Nov 2008 18:18:52 +0000 Subject: [rspec-users] Testing a wizard with Cucumber In-Reply-To: <49108997.1040909@benmabey.com> References: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> <88fd8ddc0811040853j6dd4a240mb6314a73e9ebe3c1@mail.gmail.com> <49108997.1040909@benmabey.com> Message-ID: <4FEF1D8E-D36E-40F0-B59F-EE08BB09118F@mattwynne.net> On 4 Nov 2008, at 17:42, Ben Mabey wrote: > Andrew Premdas wrote: >> Thanks Matt, just what I was looking for :) >> >> Andrew > > You could also use GivenScenario. Dude, that is soooo "Story Runner". ;) From ashley.moran at patchspace.co.uk Tue Nov 4 14:14:51 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 19:14:51 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <57c63afe0811040907q4c22b9eas11da6d2f9346e2cc@mail.gmail.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <57c63afe0811040907q4c22b9eas11da6d2f9346e2cc@mail.gmail.com> Message-ID: <96297C3F-9E68-46A8-9B6D-717451325CFA@patchspace.co.uk> On Nov 04, 2008, at 5:07 pm, David Chelimsky wrote: > FYI - if you REALLY want to match against either, it's pretty easy to > do w/ simple matcher: > > def be_nil_or_empty > simple_matcher "nil? or empty? to return true" do |actual| > actual.nil? || actual.empty? > end > end Wow, I completely forgot about simple_matcher. That REALLY deserves a more prominent place in the docs! It's a great feature. Would be really cool if you could do it like this though: simple_matcher :be_nil_or_empty, "nil? or empty? to return true" do | actual| actual.nil? || actual.empty? end and have it call define_method for you. That's one I could hopefully do myself in time, after I've got a few Merb/DataMapper jobs out of the way. WYDAT? Worth filing a ticket for? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Tue Nov 4 14:19:37 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 19:19:37 +0000 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: <30194912ad0ae021a94522cb12dcb6db@ruby-forum.com> References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> <30194912ad0ae021a94522cb12dcb6db@ruby-forum.com> Message-ID: On Nov 04, 2008, at 5:07 pm, Fernando Perez wrote: > Doh! I forgot to run the migrations in the newly created DB. Hi Fernando I used to do this all the time, so I made a db:migrate:all task[1] that means you don't have to remember which version which DB is on. Mine is for Merb, but I can only see a couple of lines that should need changing for Rails. You might find it useful. Ashley [1] http://aviewfromafar.net/2008/10/26/adventures-in-merbddland-3-reduce-migration-pain-with-db-migrate-all-rake-tasks -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Tue Nov 4 14:20:46 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 19:20:46 +0000 Subject: [rspec-users] Testing a wizard with Cucumber In-Reply-To: <4FEF1D8E-D36E-40F0-B59F-EE08BB09118F@mattwynne.net> References: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> <88fd8ddc0811040853j6dd4a240mb6314a73e9ebe3c1@mail.gmail.com> <49108997.1040909@benmabey.com> <4FEF1D8E-D36E-40F0-B59F-EE08BB09118F@mattwynne.net> Message-ID: On Nov 04, 2008, at 6:18 pm, Matt Wynne wrote: >> You could also use GivenScenario. > > Dude, that is soooo "Story Runner". And soooo deprecated too, right? -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From zach.dennis at gmail.com Tue Nov 4 14:24:57 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 4 Nov 2008 14:24:57 -0500 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <96297C3F-9E68-46A8-9B6D-717451325CFA@patchspace.co.uk> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <57c63afe0811040907q4c22b9eas11da6d2f9346e2cc@mail.gmail.com> <96297C3F-9E68-46A8-9B6D-717451325CFA@patchspace.co.uk> Message-ID: <85d99afe0811041124j631e594dh7c8bae36d6c77ee1@mail.gmail.com> On Tue, Nov 4, 2008 at 2:14 PM, Ashley Moran wrote: > > On Nov 04, 2008, at 5:07 pm, David Chelimsky wrote: > >> FYI - if you REALLY want to match against either, it's pretty easy to >> do w/ simple matcher: >> >> def be_nil_or_empty >> simple_matcher "nil? or empty? to return true" do |actual| >> actual.nil? || actual.empty? >> end >> end > > > Wow, I completely forgot about simple_matcher. That REALLY deserves a more > prominent place in the docs! It's a great feature. > > Would be really cool if you could do it like this though: > > simple_matcher :be_nil_or_empty, "nil? or empty? to return true" do > |actual| > actual.nil? || actual.empty? > end > > and have it call define_method for you. > > That's one I could hopefully do myself in time, after I've got a few > Merb/DataMapper jobs out of the way. > > WYDAT? Worth filing a ticket for? There are a few obstacles that it would have to overcome. As-is I don't think that will work. If you file a ticket I'll comment there as to why I think that. :) -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From dchelimsky at gmail.com Tue Nov 4 14:26:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Nov 2008 13:26:35 -0600 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <96297C3F-9E68-46A8-9B6D-717451325CFA@patchspace.co.uk> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <57c63afe0811040907q4c22b9eas11da6d2f9346e2cc@mail.gmail.com> <96297C3F-9E68-46A8-9B6D-717451325CFA@patchspace.co.uk> Message-ID: <57c63afe0811041126q16f3aa7dr2cff7757e7323ef3@mail.gmail.com> On Tue, Nov 4, 2008 at 1:14 PM, Ashley Moran wrote: > > On Nov 04, 2008, at 5:07 pm, David Chelimsky wrote: > >> FYI - if you REALLY want to match against either, it's pretty easy to >> do w/ simple matcher: >> >> def be_nil_or_empty >> simple_matcher "nil? or empty? to return true" do |actual| >> actual.nil? || actual.empty? >> end >> end > > > Wow, I completely forgot about simple_matcher. That REALLY deserves a more > prominent place in the docs! It's a great feature. > > Would be really cool if you could do it like this though: > > simple_matcher :be_nil_or_empty, "nil? or empty? to return true" do > |actual| > actual.nil? || actual.empty? > end > > and have it call define_method for you. > > That's one I could hopefully do myself in time, after I've got a few > Merb/DataMapper jobs out of the way. > > WYDAT? Worth filing a ticket for? If you can do it w/o breaking existing behaviour, sure. Alternatively, you could add a new method: def_matcher or something like that. Either way, it would be totally worth 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 ben at benmabey.com Tue Nov 4 14:28:09 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 04 Nov 2008 12:28:09 -0700 Subject: [rspec-users] Testing a wizard with Cucumber In-Reply-To: References: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> <88fd8ddc0811040853j6dd4a240mb6314a73e9ebe3c1@mail.gmail.com> <49108997.1040909@benmabey.com> <4FEF1D8E-D36E-40F0-B59F-EE08BB09118F@mattwynne.net> Message-ID: <4910A249.7080203@benmabey.com> Ashley Moran wrote: > > On Nov 04, 2008, at 6:18 pm, Matt Wynne wrote: > >>> You could also use GivenScenario. >> >> Dude, that is soooo "Story Runner". > > > And soooo deprecated too, right? > Oh really? Hmm.. I assumed it was still there. :) -Ben From lists at ruby-forum.com Tue Nov 4 14:38:51 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 20:38:51 +0100 Subject: [rspec-users] Unable to stub a class method in a before_filter Message-ID: Here is my spec: -- describe Admin::ProductsController, "A visitor wants to access admin/products" do before(:each) do @product = mock_model(Product, :traffic_available => 0) Product.stub!(:find_by_domain_name).and_return(@product) end it "should redirect to login path" do get :index response.should redirect_to(login_url) end end -- In my application.rb, I have the following before filter: -- def find_current_site @site = Site.find_by_domain_name(website_name) if @site.traffic_available < 0 render :nothing => :true end end -- As the test DB is empty and I don't use fixtures, it won't find any site, therefore nil.traffic_available < 0 returns an error when running the spec. I thought I could stub out the find_by_domain_name method to return a cooperative object with a traffic_available value, but it didn't work. How can I do that correctly? I have found a dirty workaround: controller.stub!(:find_current_site).and_return(:true) but I don't find it acceptable. I am not going to stub out all methods in my app, that's nonsense. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 4 14:44:11 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 20:44:11 +0100 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> Message-ID: <2f49f09409935899a97bf02d3402837c@ruby-forum.com> As a starter, can someone tell me if the specs defined in restful_authentication are clever? Can I learn from them? Because right now I find them overwhelming, complicated, over-testing, etc. Does anyone know of a good app with specs I could learn from? It always makes me laugh to think about all the good things people say about TDD, and if I take for instance Spree (a Ror ecommerce website), well the specs are almost not defined at all, whereas the code is present. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Nov 4 14:45:28 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Nov 2008 13:45:28 -0600 Subject: [rspec-users] Unable to stub a class method in a before_filter In-Reply-To: References: Message-ID: <57c63afe0811041145j3ed6f058ved3966e124f1a783@mail.gmail.com> On Tue, Nov 4, 2008 at 1:38 PM, Fernando Perez wrote: > Here is my spec: > -- > describe Admin::ProductsController, "A visitor wants to access > admin/products" do > > before(:each) do > @product = mock_model(Product, :traffic_available => 0) > Product.stub!(:find_by_domain_name).and_return(@product) > end > > it "should redirect to login path" do > get :index > response.should redirect_to(login_url) > end > > end > -- > > In my application.rb, I have the following before filter: > -- > def find_current_site > @site = Site.find_by_domain_name(website_name) > if @site.traffic_available < 0 > render :nothing => :true > end > end > -- > > As the test DB is empty and I don't use fixtures, it won't find any > site, therefore nil.traffic_available < 0 returns an error when running > the spec. > > I thought I could stub out the find_by_domain_name method to return a > cooperative object with a traffic_available value, but it didn't work. > > How can I do that correctly? > > I have found a dirty workaround: > controller.stub!(:find_current_site).and_return(:true) > > but I don't find it acceptable. I am not going to stub out all methods > in my app, that's nonsense. I don't know if this will satisfy you or not, but you *could* write that once and have it apply across your entire suite. Add this to spec/spec_helper.rb (or equivalent): Spec::Runner.configure do |config| config.before(:each, :type => :controller) do controller.stub!(:find_current_site).and_return(:true) end end That work? > -- > 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 Nov 4 14:47:29 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 11:47:29 -0800 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <57c63afe0811041126q16f3aa7dr2cff7757e7323ef3@mail.gmail.com> (David Chelimsky's message of "Tue\, 4 Nov 2008 13\:26\:35 -0600") References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <57c63afe0811040907q4c22b9eas11da6d2f9346e2cc@mail.gmail.com> <96297C3F-9E68-46A8-9B6D-717451325CFA@patchspace.co.uk> <57c63afe0811041126q16f3aa7dr2cff7757e7323ef3@mail.gmail.com> Message-ID: "David Chelimsky" writes: > Alternatively, you could add a new method: > > def_matcher I dig this. Pat From matt at mattwynne.net Tue Nov 4 14:51:19 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 4 Nov 2008 19:51:19 +0000 Subject: [rspec-users] Unable to stub a class method in a before_filter In-Reply-To: References: Message-ID: On 4 Nov 2008, at 19:38, Fernando Perez wrote: > Here is my spec: > -- > describe Admin::ProductsController, "A visitor wants to access > admin/products" do > > before(:each) do > @product = mock_model(Product, :traffic_available => 0) > Product.stub!(:find_by_domain_name).and_return(@product) Should this be Site.stub!(:find_by_domain_name)... ? > > end > > it "should redirect to login path" do > get :index > response.should redirect_to(login_url) > end > > end > -- > > In my application.rb, I have the following before filter: > -- > def find_current_site > @site = Site.find_by_domain_name(website_name) > if @site.traffic_available < 0 > render :nothing => :true > end > end > -- > > As the test DB is empty and I don't use fixtures, it won't find any > site, therefore nil.traffic_available < 0 returns an error when > running > the spec. > > I thought I could stub out the find_by_domain_name method to return a > cooperative object with a traffic_available value, but it didn't work. From dchelimsky at gmail.com Tue Nov 4 14:53:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Nov 2008 13:53:51 -0600 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <57c63afe0811040907q4c22b9eas11da6d2f9346e2cc@mail.gmail.com> <96297C3F-9E68-46A8-9B6D-717451325CFA@patchspace.co.uk> <57c63afe0811041126q16f3aa7dr2cff7757e7323ef3@mail.gmail.com> Message-ID: <57c63afe0811041153w6d7016e1s8d9dc6b0c2a96da4@mail.gmail.com> On Tue, Nov 4, 2008 at 1:47 PM, Pat Maddox wrote: > "David Chelimsky" writes: > >> Alternatively, you could add a new method: >> >> def_matcher > > I dig this. FYI - I was talking off-line (on line, really, but outside this list) to wycats and he's got some matcher stuff in merb that I, shamefully, have yet to check out in detail. It'd be good to peak at that and see if it makes sense to bring it into rspec, or maybe release it as a plugin/extension. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Tue Nov 4 15:01:45 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 04 Nov 2008 13:01:45 -0700 Subject: [rspec-users] restful_auth and good rspec examples (was: Caboosers drop RSpec) In-Reply-To: <2f49f09409935899a97bf02d3402837c@ruby-forum.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <2f49f09409935899a97bf02d3402837c@ruby-forum.com> Message-ID: <4910AA29.7030205@benmabey.com> Fernando Perez wrote: > As a starter, can someone tell me if the specs defined in > restful_authentication are clever? Can I learn from them? > Please don't look at restful_auth as an example on how to use rspec examples and/or the story runner. The stories in particular are very brittle. > Because right now I find them overwhelming, complicated, over-testing, > etc. > Yeah, they go a little overboard with keeping the specs DRY which results IMO hard to follow specs. They also test private methods directly and some other things which are TDD smells. > Does anyone know of a good app with specs I could learn from? It always > makes me laugh to think about all the good things people say about TDD, > and if I take for instance Spree (a Ror ecommerce website), well the > specs are almost not defined at all, whereas the code is present. > Hmm.. I've heard good things about Radiant (the CMS) but I haven't looked too closely myself. Also, the rspec code base itself is a very good place to learn from. I think there are plenty of open-source tools that use rspec that you can learn from but I can't seem to think of many open-source rails apps with stellar examples. I have been thinking for a while that a worthwhile project would be to fork restful_auth and add some clearer code examples (specs) and Cucumber features. Since so many rails developers start out with restful auth it would be a good way to illustrate some good rspec guidelines. Alas, I have been think this for a while but have done nothing... It has been one of those things on my endless OSS TODO lists. -Ben From ashley.moran at patchspace.co.uk Tue Nov 4 15:33:02 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 20:33:02 +0000 Subject: [rspec-users] Can I do foo.should (be_nil || be_empty) in rspec In-Reply-To: <85d99afe0811041124j631e594dh7c8bae36d6c77ee1@mail.gmail.com> References: <88fd8ddc0811040310l12ff4c35h2a13464b877ce49a@mail.gmail.com> <7E546BF6-D472-4D04-ACFC-6152983ECACC@experthuman.com> <88fd8ddc0811040326l4ef2fc3k9ccb7ecec508afc0@mail.gmail.com> <88fd8ddc0811040445i64fc9187ia78b50bc04231b48@mail.gmail.com> <57c63afe0811040907q4c22b9eas11da6d2f9346e2cc@mail.gmail.com> <96297C3F-9E68-46A8-9B6D-717451325CFA@patchspace.co.uk> <85d99afe0811041124j631e594dh7c8bae36d6c77ee1@mail.gmail.com> Message-ID: <1E748442-9B55-432B-AB95-3DE71BD62AB4@patchspace.co.uk> On Nov 04, 2008, at 7:24 pm, Zach Dennis wrote: > There are a few obstacles that it would have to overcome. As-is I > don't think that will work. If you file a ticket I'll comment there as > to why I think that. :) I've filed a ticket[1]. Unleash your scepticism, Zach! :) Ashley [1] http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/592-improve-simple_matcher -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Tue Nov 4 15:36:14 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 20:36:14 +0000 Subject: [rspec-users] Testing a wizard with Cucumber In-Reply-To: <4910A249.7080203@benmabey.com> References: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> <88fd8ddc0811040853j6dd4a240mb6314a73e9ebe3c1@mail.gmail.com> <49108997.1040909@benmabey.com> <4FEF1D8E-D36E-40F0-B59F-EE08BB09118F@mattwynne.net> <4910A249.7080203@benmabey.com> Message-ID: On Nov 04, 2008, at 7:28 pm, Ben Mabey wrote: > Oh really? Hmm.. I assumed it was still there. :) Search for Aslak's comments, I'm pretty sure it will be pulled in Cucumber 0.3. Calling steps is much neater from inside other steps is much neater, and doesn't produce the visible step-explosion you get with GivenScenario. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Tue Nov 4 15:42:06 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 21:42:06 +0100 Subject: [rspec-users] Unable to stub a class method in a before_filter In-Reply-To: <57c63afe0811041145j3ed6f058ved3966e124f1a783@mail.gmail.com> References: <57c63afe0811041145j3ed6f058ved3966e124f1a783@mail.gmail.com> Message-ID: > That work? It could. But in such case, how will I test my before_filter independently? My real problem is to stub the find_by_domain_name instance method. -- Posted via http://www.ruby-forum.com/. From josephwilk at joesniff.co.uk Tue Nov 4 15:43:22 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Tue, 4 Nov 2008 20:43:22 +0000 Subject: [rspec-users] Testing a wizard with Cucumber In-Reply-To: <4910A249.7080203@benmabey.com> References: <88fd8ddc0811040741n24f56200k47a6e6de12074943@mail.gmail.com> <899E0DE2-006F-43A7-A355-0A629F067A28@mattwynne.net> <88fd8ddc0811040853j6dd4a240mb6314a73e9ebe3c1@mail.gmail.com> <49108997.1040909@benmabey.com> <4FEF1D8E-D36E-40F0-B59F-EE08BB09118F@mattwynne.net> <4910A249.7080203@benmabey.com> Message-ID: Its still there in source. You can read why people felt calling steps from steps was a better approach here: http://rspec.lighthouseapp.com/projects/16211/tickets/3-create-givenscenario-dependency-accross-feature-files -- Joseph Wilk http://www.joesniff.co.uk On Tue, Nov 4, 2008 at 7:28 PM, Ben Mabey wrote: > Ashley Moran wrote: > >> >> On Nov 04, 2008, at 6:18 pm, Matt Wynne wrote: >> >> You could also use GivenScenario. >>>> >>> >>> Dude, that is soooo "Story Runner". >>> >> >> >> And soooo deprecated too, right? >> >> Oh really? Hmm.. I assumed it was still there. :) > > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Nov 4 15:46:45 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 21:46:45 +0100 Subject: [rspec-users] Unable to stub a class method in a before_filter In-Reply-To: References: <57c63afe0811041145j3ed6f058ved3966e124f1a783@mail.gmail.com> Message-ID: <46b35041b61ad771f0e2132ea0c29938@ruby-forum.com> Are the docs on mock outdated? I sometimes see mock_model, and sometimes mock. Which one should be used? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 4 15:51:10 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 21:51:10 +0100 Subject: [rspec-users] Unable to stub a class method in a before_filter In-Reply-To: <46b35041b61ad771f0e2132ea0c29938@ruby-forum.com> References: <57c63afe0811041145j3ed6f058ved3966e124f1a783@mail.gmail.com> <46b35041b61ad771f0e2132ea0c29938@ruby-forum.com> Message-ID: <9092b10325d5e787ecd2056568abfa20@ruby-forum.com> Crap! I was stubbing Product, instead of Site! It all works now. Matt's typo put me on the track! But I will definitely use the trick Spec::Runner.configure do |config|... to avoid having to type this stub in all my files. Thanks. -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Tue Nov 4 15:56:55 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 4 Nov 2008 20:56:55 +0000 Subject: [rspec-users] Unable to stub a class method in a before_filter In-Reply-To: <46b35041b61ad771f0e2132ea0c29938@ruby-forum.com> References: <57c63afe0811041145j3ed6f058ved3966e124f1a783@mail.gmail.com> <46b35041b61ad771f0e2132ea0c29938@ruby-forum.com> Message-ID: <7A5D8AA7-7CAC-4AB7-AED1-1974FEED1138@mattwynne.net> On 4 Nov 2008, at 20:46, Fernando Perez wrote: > Are the docs on mock outdated? I sometimes see mock_model, and > sometimes > mock. Which one should be used? For mock_model, you need to look at the rspec-rails gem, which is a separate library. You actually have three choices when mocking an ActiveRecord model: mock, mock_model and stub_model. mock() belongs to rspec's core library, while the latter two come with the rails-specific extension gem. See here for the documentation on the two rails mocking methods: http://rspec.rubyforge.org/rspec-rails/1.1.11/classes/Spec/Rails/Mocks.html#M000026 There's also a good blog post on David's blog about stub_model http://blog.davidchelimsky.net/2008/5/27/rspec-1-1-4 HTH, Matt From jim at saturnflyer.com Tue Nov 4 15:58:22 2008 From: jim at saturnflyer.com (Jim Gay) Date: Tue, 4 Nov 2008 15:58:22 -0500 Subject: [rspec-users] restful_auth and good rspec examples (was: Caboosers drop RSpec) In-Reply-To: <4910AA29.7030205@benmabey.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <2f49f09409935899a97bf02d3402837c@ruby-forum.com> <4910AA29.7030205@benmabey.com> Message-ID: <74930E90-4FED-4872-8EB3-5BE266AAF2F5@saturnflyer.com> On Nov 4, 2008, at 3:01 PM, Ben Mabey wrote: > Fernando Perez wrote: >> As a starter, can someone tell me if the specs defined in >> restful_authentication are clever? Can I learn from them? >> > > Please don't look at restful_auth as an example on how to use rspec > examples and/or the story runner. The stories in particular are > very brittle. >> Because right now I find them overwhelming, complicated, over- >> testing, etc. >> > Yeah, they go a little overboard with keeping the specs DRY which > results IMO hard to follow specs. They also test private methods > directly and some other things which are TDD smells. >> Does anyone know of a good app with specs I could learn from? It >> always makes me laugh to think about all the good things people say >> about TDD, and if I take for instance Spree (a Ror ecommerce >> website), well the specs are almost not defined at all, whereas the >> code is present. >> > > Hmm.. I've heard good things about Radiant (the CMS) but I haven't > looked too closely myself. Don't look too closely. There's lots of coverage, but the tests were converted from Test::Unit, so it wasn't done in traditional BDD, but we're moving to clear up the behavior descriptions which are lackluster. They'll be getting better. I have a branch where I'm trying to clear this up, but I've not worked on it in weeks (and it lags behind edge as a result) http://github.com/saturnflyer/radiant/tree/spec Perhaps this'll be the impetus to get it going again. > Also, the rspec code base itself is a very good place to learn > from. I think there are plenty of open-source tools that use rspec > that you can learn from but I can't seem to think of many open- > source rails apps with stellar examples. > > I have been thinking for a while that a worthwhile project would be > to fork restful_auth and add some clearer code examples (specs) and > Cucumber features. Since so many rails developers start out with > restful auth it would be a good way to illustrate some good rspec > guidelines. Alas, I have been think this for a while but have done > nothing... It has been one of those things on my endless OSS TODO > lists. > > -Ben From lists at ruby-forum.com Tue Nov 4 16:05:22 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 22:05:22 +0100 Subject: [rspec-users] restful_auth and good rspec examples (was: Caboosers drop RSpec) In-Reply-To: <4910AA29.7030205@benmabey.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <2f49f09409935899a97bf02d3402837c@ruby-forum.com> <4910AA29.7030205@benmabey.com> Message-ID: <9d7dc696adc915821d1e1aa2c38e693f@ruby-forum.com> Thank you Ben, my doubts about restful_auth specs have been confirmed. I think having a good solid Rails app, with well written specs to learn from is what prevents its adoption. I myself have got pissed a thousand times not knowing how to write a spec for a very simple piece of code. So I simply write code and don't care about testing it as I don't know how to test it. I would have one piece of advice to give: please remove rcov. This thing entices people to write shit loads of useless specs. 100% code coverage of poorly written specs doesn't prevent bugs nor does it guaranty secure code, so please trash it. I would like to know: does anyone in this mailing-list actually never ever writes a single line of code before having written its spec(s)? In other words: do you fully comply to TDD or do you sometimes break the rules? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 4 16:10:48 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 22:10:48 +0100 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> <30194912ad0ae021a94522cb12dcb6db@ruby-forum.com> Message-ID: Thanks Ashley. And I am sure I will forget to run migration for the test environment each time I make changes to it. I will create a dumb script that looks like: -- RAILS_ENV=production rake db:migrate RAILS_ENV=test rake db:migrate ... It's not DRY but it's so easy to read with so little lines of code. Well it would be very easy to refactor. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 4 16:12:10 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 22:12:10 +0100 Subject: [rspec-users] Unable to stub a class method in a before_filter In-Reply-To: <7A5D8AA7-7CAC-4AB7-AED1-1974FEED1138@mattwynne.net> References: <57c63afe0811041145j3ed6f058ved3966e124f1a783@mail.gmail.com> <46b35041b61ad771f0e2132ea0c29938@ruby-forum.com> <7A5D8AA7-7CAC-4AB7-AED1-1974FEED1138@mattwynne.net> Message-ID: Ok I get it. I was wondering why mock_model was not showing up in rspec's rdoc. Thanks for the clarification. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Tue Nov 4 16:19:35 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 13:19:35 -0800 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <2f49f09409935899a97bf02d3402837c@ruby-forum.com> (Fernando Perez's message of "Tue\, 4 Nov 2008 20\:44\:11 +0100") References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <2f49f09409935899a97bf02d3402837c@ruby-forum.com> Message-ID: Fernando Perez writes: > As a starter, can someone tell me if the specs defined in > restful_authentication are clever? Can I learn from them? > > Because right now I find them overwhelming, complicated, over-testing, > etc. I don't even use restful_auth, precisely because I thought the specs sucked. I remember checking it out, running the specs and stories and there were like 400 specs and 60 stories or something. It was like wtf isn't this thing just doing authentication? I've been working on giternal [1] a bit lately, which has specs and cucumber features. It's not the greatest thing in the world, but it's a lot more accessible than restful_auth I think. It's also been pretty interesting to me, sometimes if I'm having trouble writing a story, I try a lower-level example and it's trivial, and vice-versa. Pat From mailing_lists at railsnewbie.com Tue Nov 4 15:55:18 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 4 Nov 2008 15:55:18 -0500 Subject: [rspec-users] Unable to stub a class method in a before_filter In-Reply-To: <46b35041b61ad771f0e2132ea0c29938@ruby-forum.com> References: <57c63afe0811041145j3ed6f058ved3966e124f1a783@mail.gmail.com> <46b35041b61ad771f0e2132ea0c29938@ruby-forum.com> Message-ID: <10F2725A-E05C-4566-996A-AAC4FF46F7B2@railsnewbie.com> On Nov 4, 2008, at 3:46 PM, Fernando Perez wrote: > Are the docs on mock outdated? I sometimes see mock_model, and > sometimes > mock. Which one should be used? mock_model is for ActiveRecord objects. it's just a mock() call with a random id stub set, and a :new_record? => false Scott From matt at mattwynne.net Tue Nov 4 16:23:12 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 4 Nov 2008 21:23:12 +0000 Subject: [rspec-users] restful_auth and good rspec examples (was: Caboosers drop RSpec) In-Reply-To: <9d7dc696adc915821d1e1aa2c38e693f@ruby-forum.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <2f49f09409935899a97bf02d3402837c@ruby-forum.com> <4910AA29.7030205@benmabey.com> <9d7dc696adc915821d1e1aa2c38e693f@ruby-forum.com> Message-ID: On 4 Nov 2008, at 21:05, Fernando Perez wrote: > I would like to know: does anyone in this mailing-list actually never > ever writes a single line of code before having written its spec(s)? > In > other words: do you fully comply to TDD or do you sometimes break the > rules? As a friend of mine said recently, "you have to be dogmatic for a while to learn when it's OK to be pragmatic". But that's just his opinion: http://www.nabble.com/Working-outside-in-with-Cucumber-and-RSpec-td20162633.html From davids at tower-mt.com Tue Nov 4 15:51:02 2008 From: davids at tower-mt.com (David Schmidt) Date: Tue, 4 Nov 2008 12:51:02 -0800 Subject: [rspec-users] Problems stubbing @controller.stub!(:send) Message-ID: <4FFD5545-C0AE-4916-A225-99BBE003DEE1@tower-mt.com> In one of my controller tests I'm testing a method which uses self.send() to do some pre-processing if that private method name is defined: # If this task requires some additional preperation then create a # private method below with the same name as the task_type and # it will be executed here. if private_methods.include?(task_type) self.send(task_type) end I will be testing these private_methods separately so I want to just stub out the "self.send" line so that I can verify that it's called if there's a match. If I just stub out :send in my before() method: @controller.stub!(:send) then it appears that a *previous* send is stubbed, and my method never gets tested (shown by my first should not getting hit). If I specify a "with" for that stub: @controller.stub!(:send).with('private method') I then get a "stack level too deep" error. I have similar problems when attempt to use the following instead of the before/stub: it "should run any private methods if task_type matches" do @mock_task.should_receive(:run).and_return(@mock_task) @controller.should_receive(:send).with('private method') do_request end Here I get the error message "Mock 'TasksController' expected :send with ("private method" but received it with (:perform_action)" Is there any way that I can stub out *just* the :send with "private method" and leave the other one alone to execute? Thank you, David Schmidt davids at tower-mt.com From ben at benmabey.com Tue Nov 4 16:30:18 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 04 Nov 2008 14:30:18 -0700 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <2f49f09409935899a97bf02d3402837c@ruby-forum.com> Message-ID: <4910BEEA.5050205@benmabey.com> Pat Maddox wrote: > Fernando Perez writes: > > >> As a starter, can someone tell me if the specs defined in >> restful_authentication are clever? Can I learn from them? >> >> Because right now I find them overwhelming, complicated, over-testing, >> etc. >> > > I don't even use restful_auth, precisely because I thought the specs > sucked. I remember checking it out, running the specs and stories and > there were like 400 specs and 60 stories or something. It was like wtf > isn't this thing just doing authentication? > > I've been working on giternal [1] a bit lately, which has specs and > cucumber features. It's not the greatest thing in the world, but it's a > lot more accessible than restful_auth I think. It's also been pretty > interesting to me, sometimes if I'm having trouble writing a story, I > try a lower-level example and it's trivial, and vice-versa. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I believe Pat meant to add this reference at the bottom of his email: :) [1] http://github.com/pat-maddox/giternal/tree/master From lists at ruby-forum.com Tue Nov 4 16:48:15 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 4 Nov 2008 22:48:15 +0100 Subject: [rspec-users] mocking named_scope utilization In-Reply-To: References: <810a540e0809120732tb6f9205l8824e4996ab60248@mail.gmail.com> Message-ID: <4998060e259d9d06374fd6942efb5c39@ruby-forum.com> This trick to spec a named_scope method works very well. And it cleans up the chain mess in the controller. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Tue Nov 4 16:49:30 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 13:49:30 -0800 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <4910BEEA.5050205@benmabey.com> (Ben Mabey's message of "Tue\, 04 Nov 2008 14\:30\:18 -0700") References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <1fb4df0811040809o513c0e4dq6763fc7ba737c5eb@mail.gmail.com> <2f49f09409935899a97bf02d3402837c@ruby-forum.com> <4910BEEA.5050205@benmabey.com> Message-ID: Ben Mabey writes: > Pat Maddox wrote: >> Fernando Perez writes: >> >> >>> As a starter, can someone tell me if the specs defined in >>> restful_authentication are clever? Can I learn from them? >>> >>> Because right now I find them overwhelming, complicated, >>> over-testing, etc. >>> >> >> I don't even use restful_auth, precisely because I thought the specs >> sucked. I remember checking it out, running the specs and stories and >> there were like 400 specs and 60 stories or something. It was like wtf >> isn't this thing just doing authentication? >> >> I've been working on giternal [1] a bit lately, which has specs and >> cucumber features. It's not the greatest thing in the world, but it's a >> lot more accessible than restful_auth I think. It's also been pretty >> interesting to me, sometimes if I'm having trouble writing a story, I >> try a lower-level example and it's trivial, and vice-versa. >> >> Pat >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > I believe Pat meant to add this reference at the bottom of his email: :) > > [1] http://github.com/pat-maddox/giternal/tree/master > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users See what a great community we have!! From pergesu at gmail.com Tue Nov 4 16:53:34 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 13:53:34 -0800 Subject: [rspec-users] Problems stubbing @controller.stub!(:send) In-Reply-To: <4FFD5545-C0AE-4916-A225-99BBE003DEE1@tower-mt.com> (David Schmidt's message of "Tue\, 4 Nov 2008 12\:51\:02 -0800") References: <4FFD5545-C0AE-4916-A225-99BBE003DEE1@tower-mt.com> Message-ID: David Schmidt writes: > In one of my controller tests I'm testing a method which uses > self.send() to do some pre-processing if that > private method name is defined: > > # If this task requires some additional preperation then > create a > # private method below with the same name as the > task_type and > # it will be executed here. > if private_methods.include?(task_type) > self.send(task_type) > end > > I will be testing these private_methods separately so I want to just > stub out the "self.send" line so that I can verify that it's called if > there's a match. > > If I just stub out :send in my before() method: > > @controller.stub!(:send) > > then it appears that a *previous* send is stubbed, and my method never > gets tested (shown by my first should not getting hit). > > If I specify a "with" for that stub: > > @controller.stub!(:send).with('private method') > > I then get a "stack level too deep" error. > > I have similar problems when attempt to use the following instead of > the before/stub: > > it "should run any private methods if task_type matches" do > @mock_task.should_receive(:run).and_return(@mock_task) > @controller.should_receive(:send).with('private method') > do_request > end > > Here I get the error message "Mock 'TasksController' expected :send > with ("private method" but received it with (:perform_action)" > > Is there any way that I can stub out *just* the :send with "private > method" and leave the other one alone to execute? I'm not sure, but you should be able to stub out :private_method and it ought to work fine, even when you send it. Pat From matt at mattwynne.net Tue Nov 4 17:06:03 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 4 Nov 2008 22:06:03 +0000 Subject: [rspec-users] mocking named_scope utilization In-Reply-To: <4998060e259d9d06374fd6942efb5c39@ruby-forum.com> References: <810a540e0809120732tb6f9205l8824e4996ab60248@mail.gmail.com> <4998060e259d9d06374fd6942efb5c39@ruby-forum.com> Message-ID: <31A54D06-5A2F-4786-AD58-4D3C3FDB32BE@mattwynne.net> On 4 Nov 2008, at 21:48, Fernando Perez wrote: > This trick to spec a named_scope method works very well. And it cleans > up the chain mess in the controller. Which trick is that? Sorry if this sounds a bit patronising, but it does help if you quote the relevant bits of a post you're replying to, to give some context to your message. cheers, Matt From mark at mwilden.com Tue Nov 4 17:15:06 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 4 Nov 2008 14:15:06 -0800 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> <30194912ad0ae021a94522cb12dcb6db@ruby-forum.com> Message-ID: <3c30da400811041415k39f5461dk165acf4c06d8e250@mail.gmail.com> On Tue, Nov 4, 2008 at 1:10 PM, Fernando Perez wrote: > Thanks Ashley. And I am sure I will forget to run migration for the test > environment each time I make changes to it. I will create a dumb script > that looks like: > -- > RAILS_ENV=production rake db:migrate > RAILS_ENV=test rake db:migrate > I think it's actually simpler to do 'rake db:test:prepare' rather than migrate the test database. Migrations can be a pain when you've only got one database to worry about, much less two. The db:test:prepare task extracts the schema from the development database, drops the test database, then builds it again with the schema script. One reason I like it is that I know for sure that my tests are starting from a known state - empty. The other is that I know for sure that the test db matches the dev db. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.hauptmann.ruby at gmail.com Tue Nov 4 17:45:00 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Wed, 5 Nov 2008 08:45:00 +1000 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? Message-ID: hi, I have an issue in that I have some reference data my migrations run in. However when running "rake spec" it seems to remove the data in the test database up front. What do you recommend to workaround this issue? Thanks Greg From ashley.moran at patchspace.co.uk Tue Nov 4 17:54:12 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 4 Nov 2008 22:54:12 +0000 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: <3c30da400811041415k39f5461dk165acf4c06d8e250@mail.gmail.com> References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> <30194912ad0ae021a94522cb12dcb6db@ruby-forum.com> <3c30da400811041415k39f5461dk165acf4c06d8e250@mail.gmail.com> Message-ID: <3641C672-0AA7-498B-8D40-5D030530A2F6@patchspace.co.uk> On Nov 04, 2008, at 10:15 pm, Mark Wilden wrote: > I think it's actually simpler to do 'rake db:test:prepare' rather > than migrate the test database. Migrations can be a pain when you've > only got one database to worry about, much less two. The > db:test:prepare task extracts the schema from the development > database, drops the test database, then builds it again with the > schema script. One reason I like it is that I know for sure that my > tests are starting from a known state - empty. The other is that I > know for sure that the test db matches the dev db. Except, this doesn't work if your migrations contain seed data, eg lookup tables. In which case you have to compensate for this in your spec setups, which is a risky DRY violation. It's safer to get your test db into shape the same way you get your production one. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From mark at mwilden.com Tue Nov 4 17:58:41 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 4 Nov 2008 14:58:41 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: References: Message-ID: <3c30da400811041458i4394c14fk65320715a6ed79bb@mail.gmail.com> On Tue, Nov 4, 2008 at 2:45 PM, Greg Hauptmann < greg.hauptmann.ruby at gmail.com> wrote: > > I have an issue in that I have some reference data my migrations run > in. However when running "rake spec" it seems to remove the data in > the test database up front. > > What do you recommend to workaround this issue? > Don't do that. :) At least, that's my opinion. Depending on database contents for testing is a brittle road to hoe. As I just finished saying, I like my test database to be clean and identical in schema to my development database. 'rake spec' does that. Without knowing your situation exactly, I would suggest either mocking out calls that you expect to deliver the prepopulated data, creating that data in your specs as needed, writing fixtures that load the data in, and/or examining whether that data is really necessary for testing. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Tue Nov 4 18:05:13 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 15:05:13 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: (Greg Hauptmann's message of "Wed\, 5 Nov 2008 08\:45\:00 +1000") References: Message-ID: "Greg Hauptmann" writes: > hi, > > I have an issue in that I have some reference data my migrations run > in. However when running "rake spec" it seems to remove the data in > the test database up front. > > What do you recommend to workaround this issue? > > Thanks > Greg > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users You should probably create it in a before block, or if the reference data is always going to be the same, you'll want to insert it into the db BEFORE the test transactions start. That will require a bit of work...clear out all the tables and insert the data, that way when transactions get rolled back you're back at the db with reference data. I'm not quite sure how to do that though. Is there a before(:suite) that might work? Pat From mark at mwilden.com Tue Nov 4 18:06:59 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 4 Nov 2008 15:06:59 -0800 Subject: [rspec-users] RSpec and PostgreSQL not playing nicely together In-Reply-To: <3641C672-0AA7-498B-8D40-5D030530A2F6@patchspace.co.uk> References: <4cb53bfe1140886e628eec4e9039fe7c@ruby-forum.com> <85d99afe0811040846i7dffb552of064571410529bf8@mail.gmail.com> <30194912ad0ae021a94522cb12dcb6db@ruby-forum.com> <3c30da400811041415k39f5461dk165acf4c06d8e250@mail.gmail.com> <3641C672-0AA7-498B-8D40-5D030530A2F6@patchspace.co.uk> Message-ID: <3c30da400811041506i69737662o55d58a9095df85f6@mail.gmail.com> On Tue, Nov 4, 2008 at 2:54 PM, Ashley Moran wrote: > > On Nov 04, 2008, at 10:15 pm, Mark Wilden wrote: > > I think it's actually simpler to do 'rake db:test:prepare' rather than >> migrate the test database. Migrations can be a pain when you've only got one >> database to worry about, much less two. The db:test:prepare task extracts >> the schema from the development database, drops the test database, then >> builds it again with the schema script. One reason I like it is that I know >> for sure that my tests are starting from a known state - empty. The other is >> that I know for sure that the test db matches the dev db. >> > > Except, this doesn't work if your migrations contain seed data, eg lookup > tables. In which case you have to compensate for this in your spec setups, > which is a risky DRY violation. It's safer to get your test db into shape > the same way you get your production one. > See my response in the other thread. :) I can imagine situations in which none of the solutions I offered would apply, but if possible I would prefer them over depending on the contents of the test database. We had a similar situation at work, where we thought we needed certain data in order to test. We had all kinds of problems keeping test and development in sync (both schema and data). A closer look showed that that data was not in fact necessary. I'm not saying that applies in all cases, of course. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Nov 4 18:16:03 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 00:16:03 +0100 Subject: [rspec-users] Cucumber: Why rake features needs to call db:test:prepare? Message-ID: <4a9c0c1f3f0a843a8db5bf3312b7d494@ruby-forum.com> I am missing something here. Using PostgreSQL, when I remove this line from the rake task, I don't see the DB being populated although I do invoke create! on some models. When I use debug(@some_instance) I see its id gets increased, so there is definitely some data already in the DB. Why can't I see anything in the DB? Is it possible to mock models so that the rake features doesn't have to recreate the test DB each time to speed things up? I am interested in replacing controller specs by webrat features. I prefer the webrat's black box approach more for testing controllers and views. Would it be possible to have autotest trigger "rake features"? -- Posted via http://www.ruby-forum.com/. From drnic at mocra.com Tue Nov 4 18:09:08 2008 From: drnic at mocra.com (Dr Nic) Date: Tue, 4 Nov 2008 15:09:08 -0800 (PST) Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> Message-ID: On Nov 5, 1:55?am, "Luis Lavena" wrote: > Given a problem I have with RSpec > And I post to the mailing list > When noone answer my post > And has been N days since I posted > Then I start whining in my blog about it I'm still learning the ways of cucumber, though I think this could/ should be: Given a problem I have with RSpec When I post to the RSpec mailing list And noone answers my post after 10 days Then I start whining in my blog about RSpec :P From aslak.hellesoy at gmail.com Tue Nov 4 18:25:40 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 5 Nov 2008 00:25:40 +0100 Subject: [rspec-users] Cucumber: Why rake features needs to call db:test:prepare? In-Reply-To: <4a9c0c1f3f0a843a8db5bf3312b7d494@ruby-forum.com> References: <4a9c0c1f3f0a843a8db5bf3312b7d494@ruby-forum.com> Message-ID: <8d961d900811041525j4ba2159aqce32dae0fe5fb8aa@mail.gmail.com> On Wed, Nov 5, 2008 at 12:16 AM, Fernando Perez wrote: > I am missing something here. Using PostgreSQL, when I remove this line > from the rake task, I don't see the DB being populated although I do > invoke create! on some models. > Vanilla Rails test:* tasks do the same, as do the rspec:* tasks. db:test:prepare is a shortcut for running all the migrations from the first to the last. If you write a functional Test::Unit test and run rake test:functionals - do you still have problems? If so - this is likely not related to Cucumber. > When I use debug(@some_instance) I see its id gets increased, so there > is definitely some data already in the DB. > > Why can't I see anything in the DB? Is it possible to mock models so > that the rake features doesn't have to recreate the test DB each time to > speed things up? > > I am interested in replacing controller specs by webrat features. I > prefer the webrat's black box approach more for testing controllers and > views. > > Would it be possible to have autotest trigger "rake features"? > -- > 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 Tue Nov 4 18:29:57 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 00:29:57 +0100 Subject: [rspec-users] mocking named_scope utilization In-Reply-To: <31A54D06-5A2F-4786-AD58-4D3C3FDB32BE@mattwynne.net> References: <810a540e0809120732tb6f9205l8824e4996ab60248@mail.gmail.com> <4998060e259d9d06374fd6942efb5c39@ruby-forum.com> <31A54D06-5A2F-4786-AD58-4D3C3FDB32BE@mattwynne.net> Message-ID: <9c9205a149b6a6196a10bbda1300eb2a@ruby-forum.com> Here you go: It's not easy to test for the following named_scopes: -- Thing.method1(@current_user).method2.method3 :page => params[:page] -- I tried: -- Thing.should_receive(:method1).. Thing.should_receive(:method2).. Thing.should_receive(:method3) -- But testing for these three method calls didn't work. I have an error as "could not evaluate nil.method2". That's because of the way Rails treats chained named_scopes, each method only exists in the context of its surrounding scopes. method1 doesn't anything when followed by method2, it's because rails dynamically creates a method that would be called something like method1_and_method2 if you know what I'm sayin'. Therefore a workaround is to define an instance method: -- class Thing def self.method1_and_method2(arg) method1(arg).method2 end end -- Then in the controller, you would call: Thing.method1_and_method2 Now you can spec that easily with: -- Thing.should_receive(:method1_and_method2).with(...) -- And it works. -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Tue Nov 4 18:33:05 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 04 Nov 2008 16:33:05 -0700 Subject: [rspec-users] Cucumber: Why rake features needs to call db:test:prepare? In-Reply-To: <4a9c0c1f3f0a843a8db5bf3312b7d494@ruby-forum.com> References: <4a9c0c1f3f0a843a8db5bf3312b7d494@ruby-forum.com> Message-ID: <4910DBB1.4090409@benmabey.com> Fernando Perez wrote: > I am missing something here. Using PostgreSQL, when I remove this line > from the rake task, I don't see the DB being populated although I do > invoke create! on some models. > > When I use debug(@some_instance) I see its id gets increased, so there > is definitely some data already in the DB. > > Why can't I see anything in the DB? Is it possible to mock models so > that the rake features doesn't have to recreate the test DB each time to > speed things up? > I believe this can be explained by transactions. Cucumber wraps it's scenarios in ActiveRecord transactions (when in a rails app.) Most DBs by default will not allow you to see data that has been inserted until the transaction is committed. You may disable the transactions if you wish by commenting out the following line in env.rb: Cucumber::Rails.use_transactional_fixtures If you want to place data in your DB before cucumber is ran you could consider Zach's suggestion here: http://www.continuousthinking.com/2008/7/17/using-seed-data-with-rspec-stories > I am interested in replacing controller specs by webrat features. I > prefer the webrat's black box approach more for testing controllers and > views. > > Would it be possible to have autotest trigger "rake features"? > The latest version of cucumber (master from github-- not released yet) currently does it. But that default behavior might change in the future. (Reason being is that cucumber features are application level tests and may be too slow for the regular red->green->refactor cycle that autotest/autospec offers.) -Ben From pergesu at gmail.com Tue Nov 4 18:41:45 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 15:41:45 -0800 Subject: [rspec-users] mocking named_scope utilization In-Reply-To: <9c9205a149b6a6196a10bbda1300eb2a@ruby-forum.com> (Fernando Perez's message of "Wed\, 5 Nov 2008 00\:29\:57 +0100") References: <810a540e0809120732tb6f9205l8824e4996ab60248@mail.gmail.com> <4998060e259d9d06374fd6942efb5c39@ruby-forum.com> <31A54D06-5A2F-4786-AD58-4D3C3FDB32BE@mattwynne.net> <9c9205a149b6a6196a10bbda1300eb2a@ruby-forum.com> Message-ID: Fernando Perez writes: > Therefore a workaround is to define an instance method: > -- > class Thing > def self.method1_and_method2(arg) > method1(arg).method2 > end > end I'm inclined to call this an improvement rather than a workaround :) Pat From aslak.hellesoy at gmail.com Tue Nov 4 18:43:54 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Wed, 5 Nov 2008 00:43:54 +0100 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: References: Message-ID: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> Sent from my iPhone On 5. nov.. 2008, at 00.05, Pat Maddox wrote: > "Greg Hauptmann" writes: > >> hi, >> >> I have an issue in that I have some reference data my migrations run >> in. However when running "rake spec" it seems to remove the data in >> the test database up front. >> >> What do you recommend to workaround this issue? >> >> Thanks >> Greg >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > You should probably create it in a before block, or if the reference > data is always going to be the same, you'll want to insert it into the > db BEFORE the test transactions start. That will require a bit of > work...clear out all the tables and insert the data, that way when > transactions get rolled back you're back at the db with reference > data. > I'm not quite sure how to do that though. Is there a before(:suite) > that might work? > There is no need for a special construct. Just do it at the top level in env.rb or an adjacent file. Use at_exit for a global "teardown". > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Tue Nov 4 18:48:57 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 04 Nov 2008 16:48:57 -0700 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> Message-ID: <4910DF69.7030402@benmabey.com> Aslak Helles?y wrote: > > > Sent from my iPhone > > On 5. nov.. 2008, at 00.05, Pat Maddox wrote: > >> "Greg Hauptmann" writes: >> >>> hi, >>> >>> I have an issue in that I have some reference data my migrations run >>> in. However when running "rake spec" it seems to remove the data in >>> the test database up front. >>> >>> What do you recommend to workaround this issue? >>> >>> Thanks >>> Greg >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> You should probably create it in a before block, or if the reference >> data is always going to be the same, you'll want to insert it into the >> db BEFORE the test transactions start. That will require a bit of >> work...clear out all the tables and insert the data, that way when >> transactions get rolled back you're back at the db with reference data. >> I'm not quite sure how to do that though. Is there a before(:suite) >> that might work? >> > > There is no need for a special construct. Just do it at the top level > in env.rb or an adjacent file. Use at_exit for a global "teardown". I believe they are talking about rspec examples and not cucumber features... -Ben > >> 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 mark at mwilden.com Tue Nov 4 18:59:25 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 4 Nov 2008 15:59:25 -0800 Subject: [rspec-users] Cucumber: Why rake features needs to call db:test:prepare? In-Reply-To: <8d961d900811041525j4ba2159aqce32dae0fe5fb8aa@mail.gmail.com> References: <4a9c0c1f3f0a843a8db5bf3312b7d494@ruby-forum.com> <8d961d900811041525j4ba2159aqce32dae0fe5fb8aa@mail.gmail.com> Message-ID: <3c30da400811041559i4ffa6255jd748c4b6037d6da6@mail.gmail.com> On Tue, Nov 4, 2008 at 3:25 PM, aslak hellesoy wrote: > db:test:prepare is a shortcut for running all the migrations from the > first to the last. > Not quite. db:test:prepare just copies the schema from the development database to the test database. It aborts if there are any pending migrations, but it doesn't actually run any. That's why any data population in a migration does not get done in the test db. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashley.moran at patchspace.co.uk Tue Nov 4 19:01:21 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 5 Nov 2008 00:01:21 +0000 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> Message-ID: <64BA6A22-335D-46AE-9E11-742532B66FDC@patchspace.co.uk> On Nov 04, 2008, at 11:09 pm, Dr Nic wrote: > On Nov 5, 1:55 am, "Luis Lavena" wrote: >> Given a problem I have with RSpec >> And I post to the mailing list >> When noone answer my post >> And has been N days since I posted >> Then I start whining in my blog about it > > I'm still learning the ways of cucumber, though I think this could/ > should be: > > Given a problem I have with RSpec > When I post to the RSpec mailing list > And noone answers my post after 10 days > Then I start whining in my blog about RSpec Meh, you are both amateurs at whine-driven development. Please observe: Given a problem I have with RSpec When I post to the RSpec mailing list And noone answers my post after 10 days Then I start whining in my blog about RSpec More Examples: | days since post | whining medium | | 0.1 | Twitter | | 0.2 | Facebook | | 2 | Ruby Flow | | 5 | Ruby Forum | | 20 | Slashdot | | 50 | YouTube | To think of Aslak's hard work going to waste... (Bonus points for anyone who noticed that "YouTube" should be in the "slow-running" feature set and that "Slashdot" must be run with grammar checking disabled.) -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From omen.king at gmail.com Tue Nov 4 19:04:21 2008 From: omen.king at gmail.com (Andrew Brown) Date: Tue, 4 Nov 2008 19:04:21 -0500 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <64BA6A22-335D-46AE-9E11-742532B66FDC@patchspace.co.uk> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <64BA6A22-335D-46AE-9E11-742532B66FDC@patchspace.co.uk> Message-ID: <1B76410D-713E-4008-9F62-45013E3B7E5F@gmail.com> Did this person the mailing list first? On 4-Nov-08, at 7:01 PM, Ashley Moran wrote: > > On Nov 04, 2008, at 11:09 pm, Dr Nic wrote: > >> On Nov 5, 1:55 am, "Luis Lavena" wrote: >>> Given a problem I have with RSpec >>> And I post to the mailing list >>> When noone answer my post >>> And has been N days since I posted >>> Then I start whining in my blog about it >> >> I'm still learning the ways of cucumber, though I think this could/ >> should be: >> >> Given a problem I have with RSpec >> When I post to the RSpec mailing list >> And noone answers my post after 10 days >> Then I start whining in my blog about RSpec > > > Meh, you are both amateurs at whine-driven development. Please > observe: > > Given a problem I have with RSpec > When I post to the RSpec mailing list > And noone answers my post after 10 days > Then I start whining in my blog about RSpec > > More Examples: > | days since post | whining medium | > | 0.1 | Twitter | > | 0.2 | Facebook | > | 2 | Ruby Flow | > | 5 | Ruby Forum | > | 20 | Slashdot | > | 50 | YouTube | > > To think of Aslak's hard work going to waste... > > (Bonus points for anyone who noticed that "YouTube" should be in the > "slow-running" feature set and that "Slashdot" must be run with > grammar checking disabled.) > > -- > 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 aslak.hellesoy at gmail.com Tue Nov 4 19:10:20 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 5 Nov 2008 01:10:20 +0100 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <64BA6A22-335D-46AE-9E11-742532B66FDC@patchspace.co.uk> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> <64BA6A22-335D-46AE-9E11-742532B66FDC@patchspace.co.uk> Message-ID: <8d961d900811041610h2f07028awf857d36a20e62d93@mail.gmail.com> On Wed, Nov 5, 2008 at 1:01 AM, Ashley Moran wrote: > > On Nov 04, 2008, at 11:09 pm, Dr Nic wrote: > >> On Nov 5, 1:55 am, "Luis Lavena" wrote: >>> >>> Given a problem I have with RSpec >>> And I post to the mailing list >>> When noone answer my post >>> And has been N days since I posted >>> Then I start whining in my blog about it >> >> I'm still learning the ways of cucumber, though I think this could/ >> should be: >> >> Given a problem I have with RSpec >> When I post to the RSpec mailing list >> And noone answers my post after 10 days >> Then I start whining in my blog about RSpec > > > Meh, you are both amateurs at whine-driven development. Please observe: > > Given a problem I have with RSpec > When I post to the RSpec mailing list > And noone answers my post after 10 days > Then I start whining in my blog about RSpec > > More Examples: > | days since post | whining medium | > | 0.1 | Twitter | > | 0.2 | Facebook | > | 2 | Ruby Flow | > | 5 | Ruby Forum | > | 20 | Slashdot | > | 50 | YouTube | > > To think of Aslak's hard work going to waste... > Hahaha. That made me laugh out loud. > (Bonus points for anyone who noticed that "YouTube" should be in the > "slow-running" feature set and that "Slashdot" must be run with grammar > checking disabled.) > > -- > 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 pergesu at gmail.com Tue Nov 4 19:26:36 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 16:26:36 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: <4910DF69.7030402@benmabey.com> (Ben Mabey's message of "Tue\, 04 Nov 2008 16\:48\:57 -0700") References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> Message-ID: Ben Mabey writes: > Aslak Helles?y wrote: >> >> >> Sent from my iPhone >> >> On 5. nov.. 2008, at 00.05, Pat Maddox wrote: >> >>> "Greg Hauptmann" writes: >>> >>>> hi, >>>> >>>> I have an issue in that I have some reference data my migrations run >>>> in. However when running "rake spec" it seems to remove the data in >>>> the test database up front. >>>> >>>> What do you recommend to workaround this issue? >>>> >>>> Thanks >>>> Greg >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> You should probably create it in a before block, or if the reference >>> data is always going to be the same, you'll want to insert it into the >>> db BEFORE the test transactions start. That will require a bit of >>> work...clear out all the tables and insert the data, that way when >>> transactions get rolled back you're back at the db with reference data. >>> I'm not quite sure how to do that though. Is there a before(:suite) >>> that might work? >>> >> >> There is no need for a special construct. Just do it at the top >> level in env.rb or an adjacent file. Use at_exit for a global >> "teardown". > > I believe they are talking about rspec examples and not cucumber features... aslak's right though in that case too. In your spec_helper, just loop over the tables and delete everything, then insert the seed data you want, and it should be good to go. Pat From davids at tower-mt.com Tue Nov 4 19:27:08 2008 From: davids at tower-mt.com (David Schmidt) Date: Tue, 4 Nov 2008 16:27:08 -0800 Subject: [rspec-users] Problems stubbing @controller.stub!(:send) In-Reply-To: References: <4FFD5545-C0AE-4916-A225-99BBE003DEE1@tower-mt.com> Message-ID: <4C65793F-E380-41BE-8E7A-E08EDD9818FF@tower-mt.com> On Nov 4, 2008, at 1:53 PM, Pat Maddox wrote: > David Schmidt writes: > >> In one of my controller tests I'm testing a method which uses >> self.send() to do some pre-processing if that >> private method name is defined: >> >> # If this task requires some additional preperation then >> create a >> # private method below with the same name as the >> task_type and >> # it will be executed here. >> if private_methods.include?(task_type) >> self.send(task_type) >> end >> >> I will be testing these private_methods separately so I want to just >> stub out the "self.send" line so that I can verify that it's called >> if >> there's a match. >> >> [...] >> Is there any way that I can stub out *just* the :send with "private >> method" and leave the other one alone to execute? > > I'm not sure, but you should be able to stub out :private_method and > it > ought to work fine, even when you send it. > > Pat That did the trick and worked great. Thanks Pat! David Schmidt davids at tower-mt.com From mark at mwilden.com Tue Nov 4 19:37:00 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 4 Nov 2008 16:37:00 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> Message-ID: <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> On Tue, Nov 4, 2008 at 4:26 PM, Pat Maddox wrote: > > aslak's right though in that case too. In your spec_helper, just loop > over the tables and delete everything, then insert the seed data you > want, and it should be good to go. > But then Ashley's comment applies: you've got the same facts in two places. Best thing is to avoid the dependency, if at all possible. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From jesse at jesseclark.com Tue Nov 4 19:16:02 2008 From: jesse at jesseclark.com (Jesse Clark) Date: Tue, 4 Nov 2008 16:16:02 -0800 Subject: [rspec-users] Problem with namespaced controller, form_for, and view specs Message-ID: <48BB939E-6CF6-4C4A-833A-5F5A290B4E43@jesseclark.com> Hello, I have encountered a problem with the view tests involving a form_for tag that references a namespaced controller. My controller is: class Admin::AuthenticationProvidersController < ApplicationController The form_for tag from /app/views/admin/authentication_providers/ edit.html.erb: <% form_for( :authentication_provider, @authentication_provider, :url => { :controller=>"admin/ authentication_providers", :action=>"update" } ) do |f| %> This page renders in the browser by the way and 'rake routes' shows that the route is valid. However when I run: script/spec spec/views/admin/authentication_providers/ edit.html.erb_spec.rb I get: 1) ActionView::TemplateError in '/admin/authentication_providers/ edit.html.erb should render edit form' No route matches {:action=>"update", :controller=>"admin/ authentication_providers"} On line #3 of admin/authentication_providers/edit.html.erb 1:

Editing authentication_provider

2: 3: <% form_for( :authentication_provider, @authentication_provider, :url => { :controller=>"admin/ authentication_providers", :action=>"update" } ) do |f| %> 4: <%= f.error_messages %> 5: 6:

app/views/admin/authentication_providers/edit.html.erb:3:in ` _run_erb_47app47views47admin47authentication_providers47edit46html46erb' spec/views/admin/authentication_providers/edit.html.erb_spec.rb:20 script/spec:5 Seems like this might be related to: http://rspec.lighthouseapp.com/projects/5645/tickets/488-routes-requiring-additional-parameters-fail-to-generate-in-view-specs http://rspec.lighthouseapp.com/projects/5645/tickets/585-viewexamplegrouprender-needs-an-option-that-allows-population-of-requestpath_parameters Any suggestions on how to work around this would be greatly appreciated. Thanks, -Jesse From jimlindley at gmail.com Tue Nov 4 19:56:01 2008 From: jimlindley at gmail.com (Jim Lindley) Date: Tue, 4 Nov 2008 19:56:01 -0500 Subject: [rspec-users] NoMethodError dependent on spec order In-Reply-To: <1b165db00811040756i6ea4c1c4yf390d03c4573eb06@mail.gmail.com> References: <1b165db00811040732p38a1a1a1n7a7794137071bd32@mail.gmail.com> <57c63afe0811040735i71e3438tcc8e81f299b803aa@mail.gmail.com> <1b165db00811040756i6ea4c1c4yf390d03c4573eb06@mail.gmail.com> Message-ID: <1b165db00811041656p2f595af7gc975e6e8d7c1c9da@mail.gmail.com> I have created an updated example, the issue I am seeing happens when any method has been included into a class from a module. It doesn't get re-added like methods that have been inherited or added directly to a class are. http://gist.github.com/22159 I've updated the ticket as well, but I think it's a separate issue then the original ticket you directed me to. Thanks, Jim From pergesu at gmail.com Tue Nov 4 19:56:13 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 04 Nov 2008 16:56:13 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> (Mark Wilden's message of "Tue\, 4 Nov 2008 16\:37\:00 -0800") References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> Message-ID: "Mark Wilden" writes: > On Tue, Nov 4, 2008 at 4:26 PM, Pat Maddox wrote: > > aslak's right though in that case too. In your spec_helper, just loop > over the tables and delete everything, then insert the seed data you > want, and it should be good to go. > > But then Ashley's comment applies: you've got the same facts in two places. Best thing is to > avoid the dependency, if at all possible. Sure, but you can encapsulate all that stuff too. When I've done stuff like this in the past (and on second thought I have done it just as aslak suggested, I just didn't think of it :) we've created some seed data builders. Then it becomes a simple matter of SeedData.build_data to kick off the whole deal. Pat From mark at mwilden.com Tue Nov 4 20:03:23 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 4 Nov 2008 17:03:23 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> Message-ID: <3c30da400811041703v6647af1cpa9087b029182cecd@mail.gmail.com> On Tue, Nov 4, 2008 at 4:56 PM, Pat Maddox wrote: > Then it becomes a simple matter of SeedData.build_data > to kick off the whole deal. > That makes sense. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.hauptmann.ruby at gmail.com Tue Nov 4 22:25:25 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Wed, 5 Nov 2008 13:25:25 +1000 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> Message-ID: so is the concept to build up all seed data creation in one place/method, & then for the rake spec case run this in via the "test" environment.rb file? But then if you were to use rake:migrate to drop back a couple of version you might be in a spot of bother? (ie newest seed data not then tied to migration)? On 11/5/08, Pat Maddox wrote: > "Mark Wilden" writes: > >> On Tue, Nov 4, 2008 at 4:26 PM, Pat Maddox wrote: >> >> aslak's right though in that case too. In your spec_helper, just loop >> over the tables and delete everything, then insert the seed data you >> want, and it should be good to go. >> >> But then Ashley's comment applies: you've got the same facts in two >> places. Best thing is to >> avoid the dependency, if at all possible. > > Sure, but you can encapsulate all that stuff too. When I've done stuff > like this in the past (and on second thought I have done it just as > aslak suggested, I just didn't think of it :) we've created some seed > data builders. Then it becomes a simple matter of SeedData.build_data > to kick off the whole deal. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cflipse at gmail.com Tue Nov 4 22:26:39 2008 From: cflipse at gmail.com (Chris Flipse) Date: Tue, 4 Nov 2008 22:26:39 -0500 Subject: [rspec-users] mocking named_scope utilization In-Reply-To: References: <810a540e0809120732tb6f9205l8824e4996ab60248@mail.gmail.com> <4998060e259d9d06374fd6942efb5c39@ruby-forum.com> <31A54D06-5A2F-4786-AD58-4D3C3FDB32BE@mattwynne.net> <9c9205a149b6a6196a10bbda1300eb2a@ruby-forum.com> Message-ID: I dunno ... creating a bunch of joining methods seems to be an awfully disjoint way to deal with something that is, admittedly, designed to laugh in the face of the Law of Demeter. I've been handling chains through some heavy use of null_object stubs ... but, I've been doing that sort of manually. Could be rolled up, at least. I'm kind of spitballing something that might be somewhat less manual ... foo.stub_chains :method_1, :method_2 do |chain| end def stub_chains(*args) hades = stub("chain", :null_object => true) args.each do|chain| hades.stub!(chain).and_return(hades) self.stub!(chain).and_return(hades) end end This would more or less let named_scope be used like it's intended in Rails, with one not-so-little exception -- I have to know what gets called last, so it can return a real value. For me, in practice, that's been .paginate, so it's not been a huge issue, but that's a definite gotchya WDYT? On Tue, Nov 4, 2008 at 6:41 PM, Pat Maddox wrote: > Fernando Perez writes: > > > Therefore a workaround is to define an instance method: > > -- > > class Thing > > def self.method1_and_method2(arg) > > method1(arg).method2 > > end > > end > > I'm inclined to call this an improvement rather than a workaround :) > > Pat > _______________________________________________ > 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 cflipse at gmail.com Tue Nov 4 22:27:30 2008 From: cflipse at gmail.com (Chris Flipse) Date: Tue, 4 Nov 2008 22:27:30 -0500 Subject: [rspec-users] mocking named_scope utilization In-Reply-To: References: <810a540e0809120732tb6f9205l8824e4996ab60248@mail.gmail.com> <4998060e259d9d06374fd6942efb5c39@ruby-forum.com> <31A54D06-5A2F-4786-AD58-4D3C3FDB32BE@mattwynne.net> <9c9205a149b6a6196a10bbda1300eb2a@ruby-forum.com> Message-ID: Right. Example passed a block, but stub_chains didn't call it. Pretend there's a yield(hades) in there somewhere. On Tue, Nov 4, 2008 at 10:26 PM, Chris Flipse wrote: > I dunno ... creating a bunch of joining methods seems to be an awfully > disjoint way to deal with something that is, admittedly, designed to laugh > in the face of the Law of Demeter. > > I've been handling chains through some heavy use of null_object stubs ... > but, I've been doing that sort of manually. Could be rolled up, at least. > > I'm kind of spitballing something that might be somewhat less manual ... > > foo.stub_chains :method_1, :method_2 do |chain| > end > > def stub_chains(*args) > hades = stub("chain", :null_object => true) > args.each do|chain| > hades.stub!(chain).and_return(hades) > self.stub!(chain).and_return(hades) > end > end > > This would more or less let named_scope be used like it's intended in > Rails, with one not-so-little exception -- I have to know what gets called > last, so it can return a real value. For me, in practice, that's been > .paginate, so it's not been a huge issue, but that's a definite gotchya > > > WDYT? > > > On Tue, Nov 4, 2008 at 6:41 PM, Pat Maddox wrote: > >> Fernando Perez writes: >> >> > Therefore a workaround is to define an instance method: >> > -- >> > class Thing >> > def self.method1_and_method2(arg) >> > method1(arg).method2 >> > end >> > end >> >> I'm inclined to call this an improvement rather than a workaround :) >> >> Pat >> _______________________________________________ >> 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/ > -- // anything worth taking seriously is worth making fun of // http://blog.devcaffeine.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From raasdnil at gmail.com Tue Nov 4 22:58:49 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 5 Nov 2008 14:58:49 +1100 Subject: [rspec-users] rake features and cucumber feature/name not producing same result Message-ID: <57a815bf0811041958y9175882k60b55e40c083adb9@mail.gmail.com> Hi all. If I run rake features or cucumber features/* I get one failing FIT scenario in one of my features. If I then run that feature that contains the FIT table with the failing scenario manually, it passes. I run it again with rake features or cucumber features/* it fails, run individually, it passes. Obviously some state is carrying over between the features. Any idea where i would start looking to debug the problem? Are features transactional? Should I be investigating inter feature state contamination? Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Nov 5 03:10:32 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 5 Nov 2008 08:10:32 +0000 Subject: [rspec-users] rake features and cucumber feature/name not producing same result In-Reply-To: <57a815bf0811041958y9175882k60b55e40c083adb9@mail.gmail.com> References: <57a815bf0811041958y9175882k60b55e40c083adb9@mail.gmail.com> Message-ID: <07AC043B-DA59-44C7-BC86-E597C381C314@mattwynne.net> On 5 Nov 2008, at 03:58, Mikel Lindsaar wrote: > Hi all. > > If I run rake features or cucumber features/* I get one failing FIT > scenario in one of my features. > > If I then run that feature that contains the FIT table with the > failing scenario manually, it passes. > > I run it again with rake features or cucumber features/* it fails, > run individually, it passes. > > Obviously some state is carrying over between the features. > > Any idea where i would start looking to debug the problem? > > Are features transactional? Should I be investigating inter feature > state contamination? > > Mikel What is the failure message you're seeing? Could it be this? http://rspec.lighthouseapp.com/projects/16211/tickets/60-patch-next_column_index-not-resetting-after-large-tables cheers, Matt From luislavena at gmail.com Wed Nov 5 04:57:33 2008 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 5 Nov 2008 06:57:33 -0300 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <75a3b318d2be2ba1c8acaa0830a5ada1@ruby-forum.com> <71166b3b0811040755t28ac3351r68ca55b4fd0ed42f@mail.gmail.com> Message-ID: <71166b3b0811050157w2ea45d45uac81cddd313eeded@mail.gmail.com> On Tue, Nov 4, 2008 at 8:09 PM, Dr Nic wrote: > On Nov 5, 1:55 am, "Luis Lavena" wrote: >> Given a problem I have with RSpec >> And I post to the mailing list >> When noone answer my post >> And has been N days since I posted >> Then I start whining in my blog about it > > I'm still learning the ways of cucumber, though I think this could/ > should be: > > Given a problem I have with RSpec > When I post to the RSpec mailing list > And noone answers my post after 10 days > Then I start whining in my blog about RSpec > > :P Oh, let's put RSpec between quotes, so we can reuse the steps to whine about other projects too. Given a problem I have with 'Rails' When I post to the 'Rails' mailing list And noone answe my post after 2 days Then I start whining in my blog about 'Rails' ;-) Thanks Dr. Nic, your Scenarios from newgem inspired me to draw the lines for rake-compiler gem ;-) 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 grail at goldweb.com.au Wed Nov 5 05:58:28 2008 From: grail at goldweb.com.au (Alex Satrapa) Date: Wed, 5 Nov 2008 21:58:28 +1100 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> Message-ID: On 05/11/2008, at 01:37 , Steven Baker wrote: > Big difference between "haven't been able to" and "wouldn't learn > the tools". Ashley's post below sums it up best. This is a problem > that's seen regularly when working with new ideas. How many times > have you seen Agile blamed when a project fails due to poor > management? I personally see this all the time. Personally, the first question on my mind was why they weren't using separate environments for each of their production applications. I'm learning Django at the moment, which is kinda like a Python-on- Rails wannabe. The most useful tool I've come across recently has been "virtualenv" which basically takes your system-installed environment, copies it (including the specific version of the Python interpreter) into a stand-alone environment, then sets the path for Python libraries appropriately. Then when you go messing with the environment (adding new third-party software) it only affects that specific virtual environment. A similar thing in the Mac OS X world of Ruby on Rails programming is Locomotive. I love Locomotive. I can't understand why people who are serious about production environment stability would install multiple applications in the same environment. It's not healthy. Alex From robl at mail.pigdestroyer.co.uk Wed Nov 5 07:07:54 2008 From: robl at mail.pigdestroyer.co.uk (Rob Lacey) Date: Wed, 05 Nov 2008 12:07:54 +0000 Subject: [rspec-users] no such file "spec/rake/spectask" even when rspec is install Message-ID: <49118C9A.6010001@mail.pigdestroyer.co.uk> Hi there, I wonder if anyone can help, I've recently moved a project over from using an old version of the rspec and rspec-rails plugins to using the gems. This worked seamlessly for both myself and another colleague. But another colleague is now getting this problem. no such file "spec/rake/spectask" When trying to run the simplest of rake tasks. We've compared gem versions and we all have duplicate setups as far as I can see, rspec and rspec-rails gems appear to be installed fine. Is there anything else we can try to find out what is missing? RobL From dchelimsky at gmail.com Wed Nov 5 07:36:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 06:36:01 -0600 Subject: [rspec-users] no such file "spec/rake/spectask" even when rspec is install In-Reply-To: <49118C9A.6010001@mail.pigdestroyer.co.uk> References: <49118C9A.6010001@mail.pigdestroyer.co.uk> Message-ID: <57c63afe0811050436p6a3d12cbma235b6aa9bdf2080@mail.gmail.com> On Wed, Nov 5, 2008 at 6:07 AM, Rob Lacey wrote: > Hi there, > > I wonder if anyone can help, I've recently moved a project over from using > an old version of the rspec and rspec-rails plugins to using the gems. This > worked seamlessly for both myself and another colleague. But another > colleague is now getting this problem. > > no such file "spec/rake/spectask" > > When trying to run the simplest of rake tasks. We've compared gem versions > and we all have duplicate setups as far as I can see, rspec and rspec-rails > gems appear to be installed fine. Is there anything else we can try to find > out what is missing? That developer probably does not have the rspec gem installed on his/her system. In the next release, when this happens, you'll get a warning message (not an error, so that you can still run other rake tasks) that will tell you this, and instruct you to install the rspec gem. In the mean time, installing the rspec-rails and rspec gems on that system should solve the problem. Cheers, David > > RobL From lists at ruby-forum.com Wed Nov 5 07:51:38 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 13:51:38 +0100 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> Message-ID: > I'm learning Django at the moment, which is kinda like a Python-on- > Rails wannabe. Just to clear things out. Django is absolutely not a Python-on-Rails wannabe. See Rubies and Snakes conference for disambiguation. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 5 08:17:42 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 14:17:42 +0100 Subject: [rspec-users] Design Pattern proposal for better Rails development Message-ID: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> The biggest problems I have when developing (beside stupid typos) are: 1) The name of a method which I often change to a supposedly more descriptive name, which I will eventually change to an even more supposedly descriptive name 2) The arguments a method takes Let's say I have a class method: Product.find_if_purchased(product_id, user_id) Let's say it is called in 3 different controllers. Now I want to change the name of the method to make it more clear and at the same time I will throw a new argument to it: Product.find_if_purchased_by_user_id(product_id, user_id, site_id) Now this means I have to change the code in three controllers, and also change the specs that test it with should_receive(:find_if_purchased). This is painful. And it demonstrates that controllers are tightly coupled to models which shouldn't be the case. Therefore we need names that don't vary over time. We want our models and controllers to work in a black box manner. So based on the design pattern "convention over configuration", why not use methods such as: Product.find_for_products_index or ..._show, that are named after their controller and action where they are called? Moreover, instead of hardcoding the arguments that it requires, why not pass a hash of arguments which is much more flexible? Indeed, when using hardcoded arguments, if let's say I want to define a default value for product_id, then again I must change all code that calls it, because in Ruby, arguments that have default values must be defined last. What do you think about my idea? I have been trying it recently, and I find it more pleasant to work with. It also prevents me from putting too much code inside the controllers. They are drawbacks though: 1) the name of the method is not descriptive, a little comment in the controller helps well here. 2) when the method is reused by many actions, we need to create "dummy" methods that simply call the real method. For instance, find_for_products_show just passes the arguments to another method called find_for_subscriptions_show which is where the real code sits 3) there is a slight performance hit Has anyone experienced such thing? The idea came to me yesterday when trying to spec a chain of named_methods. I realized that the chain of named_methods doesn't belong to the controller, it should be wrapped in a dummy method that calls the named_scopes. Best regards, -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Nov 5 08:24:04 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 07:24:04 -0600 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> Message-ID: <57c63afe0811050524l2fd24429kd40a7cc3040fa4c9@mail.gmail.com> On Wed, Nov 5, 2008 at 7:17 AM, Fernando Perez wrote: > The biggest problems I have when developing (beside stupid typos) are: > 1) The name of a method which I often change to a supposedly more > descriptive name, which I will eventually change to an even more > supposedly descriptive name > 2) The arguments a method takes > > Let's say I have a class method: Product.find_if_purchased(product_id, > user_id) > > Let's say it is called in 3 different controllers. > > Now I want to change the name of the method to make it more clear and at > the same time I will throw a new argument to it: > Product.find_if_purchased_by_user_id(product_id, user_id, site_id) > > Now this means I have to change the code in three controllers, and also > change the specs that test it with should_receive(:find_if_purchased). > This is painful. > > And it demonstrates that controllers are tightly coupled to models which > shouldn't be the case. Therefore we need names that don't vary over > time. We want our models and controllers to work in a black box manner. > > So based on the design pattern "convention over configuration", why not > use methods such as: > > Product.find_for_products_index or ..._show, that are named after their > controller and action where they are called? > > Moreover, instead of hardcoding the arguments that it requires, why not > pass a hash of arguments which is much more flexible? Indeed, when using > hardcoded arguments, if let's say I want to define a default value for > product_id, then again I must change all code that calls it, because in > Ruby, arguments that have default values must be defined last. > > What do you think about my idea? I have been trying it recently, and I > find it more pleasant to work with. It also prevents me from putting too > much code inside the controllers. > > They are drawbacks though: > 1) the name of the method is not descriptive, a little comment in the > controller helps well here. > 2) when the method is reused by many actions, we need to create "dummy" > methods that simply call the real method. For instance, > find_for_products_show just passes the arguments to another method > called find_for_subscriptions_show which is where the real code sits > 3) there is a slight performance hit 4) as the names become more similar they become harder to find :) For me, I think having descriptive names that are easy to find makes it much easier to change the things I want to change. Just search and replace. FWIW, David > > Has anyone experienced such thing? The idea came to me yesterday when > trying to spec a chain of named_methods. I realized that the chain of > named_methods doesn't belong to the controller, it should be wrapped in > a dummy method that calls the named_scopes. > > > Best regards, > -- > 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 Nov 5 09:05:26 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 15:05:26 +0100 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> Message-ID: <3a7296d888b5eb011dc26f633b6b1a3a@ruby-forum.com> I'm also having problems stubbing current_user. I cannot put controller.stub!(:current_user).and_return(@current_user) in a before(:all) block. The stubbing doesn't happen. However if I put it in the it "should..." block, then it works. Why is that? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 5 09:06:48 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 15:06:48 +0100 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <3a7296d888b5eb011dc26f633b6b1a3a@ruby-forum.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> <3a7296d888b5eb011dc26f633b6b1a3a@ruby-forum.com> Message-ID: <19789dc886deab4736e333e4881539a1@ruby-forum.com> Actually, in a before(:each) block, the stubbing works. So why doesn't it work with a before(:all)? -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Wed Nov 5 09:11:13 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 5 Nov 2008 14:11:13 +0000 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> Message-ID: <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> On 5 Nov 2008, at 13:17, Fernando Perez wrote: > Let's say I have a class method: Product.find_if_purchased(product_id, > user_id) > > Let's say it is called in 3 different controllers. Hmmm, could you make a helper module and mix that into all three controllers? Then there'd be just one place to change it. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Wed Nov 5 09:12:31 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 08:12:31 -0600 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <19789dc886deab4736e333e4881539a1@ruby-forum.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> <3a7296d888b5eb011dc26f633b6b1a3a@ruby-forum.com> <19789dc886deab4736e333e4881539a1@ruby-forum.com> Message-ID: <57c63afe0811050612h2f4c8139s2e9210b5977d87c@mail.gmail.com> On Wed, Nov 5, 2008 at 8:06 AM, Fernando Perez wrote: > Actually, in a before(:each) block, the stubbing works. So why doesn't > it work with a before(:all)? Please, please, please quote the information from the previous email to which you are referring. I'll respond to your first email. From dchelimsky at gmail.com Wed Nov 5 09:14:48 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 08:14:48 -0600 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <3a7296d888b5eb011dc26f633b6b1a3a@ruby-forum.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> <3a7296d888b5eb011dc26f633b6b1a3a@ruby-forum.com> Message-ID: <57c63afe0811050614h2e7bc8f3g4438356fc479706c@mail.gmail.com> On Wed, Nov 5, 2008 at 8:05 AM, Fernando Perez wrote: > I'm also having problems stubbing current_user. > > I cannot put > controller.stub!(:current_user).and_return(@current_user) > in a before(:all) block. The stubbing doesn't happen. Stubs and mocks get cleared out after each example. before(:all) only runs once, so after the first example in a group runs, the stub gets cleared out and does not get recreated. before(:each) runs before each example, setting the stub each time. So use before(:each) instead of before(:all). Make sense? There's a little more info about this on http://rspec.info/documentation/before_and_after.html (near the bottom). Cheers, David > > However if I put it in the it "should..." block, then it works. > > Why is that? > -- > 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 Nov 5 09:20:26 2008 From: lists at ruby-forum.com (Pau Cor) Date: Wed, 5 Nov 2008 15:20:26 +0100 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> Message-ID: Alex Satrapa wrote: > I can't understand why people who are serious about production > environment stability would install multiple applications in the same > environment. It's not healthy. One very nice way to do this is to run each app with its own user, then have a ~/.gems directory. Then you can only install each app's gems here. For example: For my_app_1: The app code is here: /home/my_app_1/rails/current And the gems are here: /home/my_app_1/.gems For my_app_2: The app code is here: /home/my_app_2/rails/current And the gems are here: /home/my_app_2/.gems Both users have ~/.gems in their gem load path. So user my_app_1 doesn't see user my_app_2's gems, and vice versa. This is how some shared hosts let users install their own gems without breaking anyone else's apps. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 5 09:22:21 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 15:22:21 +0100 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <57c63afe0811050612h2f4c8139s2e9210b5977d87c@mail.gmail.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> <3a7296d888b5eb011dc26f633b6b1a3a@ruby-forum.com> <19789dc886deab4736e333e4881539a1@ruby-forum.com> <57c63afe0811050612h2f4c8139s2e9210b5977d87c@mail.gmail.com> Message-ID: <3f8548178aef6709cf9fb4fd36b4d9d3@ruby-forum.com> Thanks for the clarification. And from now on I will quote previous emails. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 5 09:28:34 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 15:28:34 +0100 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> Message-ID: <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> > Hmmm, could you make a helper module and mix that into all three > controllers? Then there'd be just one place to change it. > Can you be more descriptive? Let's say I have: def show Subscription.find_if_purchased ... end def update Subscription.find_if_purchased ... end Now if I change the method name to find_if_subscribed in the model, then necessarily I will have to change it twice in my controller, well I could use a before_filter, but what if the method is also called in other controllers? That's the main problem. How would you do that? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Nov 5 09:37:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 08:37:22 -0600 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <3f8548178aef6709cf9fb4fd36b4d9d3@ruby-forum.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> <3a7296d888b5eb011dc26f633b6b1a3a@ruby-forum.com> <19789dc886deab4736e333e4881539a1@ruby-forum.com> <57c63afe0811050612h2f4c8139s2e9210b5977d87c@mail.gmail.com> <3f8548178aef6709cf9fb4fd36b4d9d3@ruby-forum.com> Message-ID: <57c63afe0811050637u2b265182ma3fdf7d9add84630@mail.gmail.com> On Wed, Nov 5, 2008 at 8:22 AM, Fernando Perez wrote: > Thanks for the clarification. And from now on I will quote previous > emails. Sorry man, but I'm laughing my ass off over this. Readers of this email will have no idea what I clarified for you because you *didn't quote the clarification* :) :) :) We'll keep working on this and get it right sooner or later. Cheers, David From pergesu at gmail.com Wed Nov 5 09:42:38 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 05 Nov 2008 06:42:38 -0800 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> (Fernando Perez's message of "Wed\, 5 Nov 2008 15\:28\:34 +0100") References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> Message-ID: Fernando Perez writes: >> Hmmm, could you make a helper module and mix that into all three >> controllers? Then there'd be just one place to change it. >> > Can you be more descriptive? > > Let's say I have: > > def show > Subscription.find_if_purchased > ... > end > > def update > Subscription.find_if_purchased > ... > end > > > Now if I change the method name to find_if_subscribed in the model, then > necessarily I will have to change it twice in my controller, well I > could use a before_filter, but what if the method is also called in > other controllers? That's the main problem. How would you do that? I don't think this is a problem. Pat From dchelimsky at gmail.com Wed Nov 5 09:49:50 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 08:49:50 -0600 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> Message-ID: <57c63afe0811050649r44c6ff8fm564f81ac4b883643@mail.gmail.com> On Wed, Nov 5, 2008 at 8:42 AM, Pat Maddox wrote: > Fernando Perez writes: > >>> Hmmm, could you make a helper module and mix that into all three >>> controllers? Then there'd be just one place to change it. >>> >> Can you be more descriptive? >> >> Let's say I have: >> >> def show >> Subscription.find_if_purchased >> ... >> end >> >> def update >> Subscription.find_if_purchased >> ... >> end >> >> >> Now if I change the method name to find_if_subscribed in the model, then >> necessarily I will have to change it twice in my controller, well I >> could use a before_filter, but what if the method is also called in >> other controllers? That's the main problem. How would you do that? > > I don't think this is a problem. Seriously. What is motivating you here? David > Pat From lists at ruby-forum.com Wed Nov 5 09:53:49 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 15:53:49 +0100 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> Message-ID: > I don't think this is a problem. > > Pat Don't you find it painful to go through each controller and/or each controller spec to correct the name of the method that has just changed? So you don't mind having to change in many different places should_receive(:find_if_purchased) to should_receive(:find_if_subscribed) ? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Nov 5 10:02:37 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 09:02:37 -0600 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> Message-ID: <57c63afe0811050702x213522d6q818a8397c3396919@mail.gmail.com> On Wed, Nov 5, 2008 at 8:53 AM, Fernando Perez wrote: >> I don't think this is a problem. >> >> Pat > > Don't you find it painful to go through each controller and/or each > controller spec to correct the name of the method that has just changed? > > So you don't mind having to change in many different places > should_receive(:find_if_purchased) to > should_receive(:find_if_subscribed) ? Personally, no, I don't. It takes a minute with find and replace. Are you thinking that this is somehow related to the DRY principle? From josephwilk at joesniff.co.uk Wed Nov 5 10:04:35 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Wed, 05 Nov 2008 15:04:35 +0000 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> Message-ID: <4911B603.3050002@joesniff.co.uk> Fernando Perez wrote: >> I don't think this is a problem. >> >> Pat >> > > Don't you find it painful to go through each controller and/or each > controller spec to correct the name of the method that has just changed? > > So you don't mind having to change in many different places > should_receive(:find_if_purchased) to > should_receive(:find_if_subscribed) ? > I think as David mentioned 'search and replace' in an IDE helps ensure that is not painful. I'd even go so far as to say its quite fun, buts thats just me :) -- Joseph Wilk http://www.joesniff.co.uk From apremdas at gmail.com Wed Nov 5 10:12:16 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Wed, 5 Nov 2008 15:12:16 +0000 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> Message-ID: <88fd8ddc0811050712k5229ddebn6617445c3897f028@mail.gmail.com> What you are suggesting here changing your api to make it easier to refactor your api. Your trying to do this by 1) Generalising the descriptivness of the api 2) Reducing the number of calls to your api Both of these are not particularly good ideas 1) Generalising your api, reduces it descriptivness and in sample you give actually makes you api non descriptive. Instead of methods find_if_purchased, you now have methods like find_for_index. What you've done here is pollute the api for your model with stuff outside its concern (namely the controller) 2) You actually want to increase the number of calls to your api. The more it is called the more useful it is being, and the more thoroughly it is being tested. If you have no calls, you would not even need to implement it. As for solving the problem of refactoring api's quickly there are two solutions to this 1) Use your editors search and replace functionality 2) Use your tests/specs/stories/features combined with your experience to ensure you design a simple and clear api up front Finally your examples were of a poor api, being refactored into a poorer api. By increasing the number of parameters of your interface. you have increased by a factor of 4 the number of possible parameter combinations you have to deal with. Refactoring your unit test for this method should make that ubundantly clear, and encourage you to change your api. In fact in this case the method is in completely the wrong place what you should have is product.purchased? product.purchased_by_user?(user) Hope this helps All best Andrew 2008/11/5 Fernando Perez > > Hmmm, could you make a helper module and mix that into all three > > controllers? Then there'd be just one place to change it. > > > Can you be more descriptive? > > Let's say I have: > > def show > Subscription.find_if_purchased > ... > end > > def update > Subscription.find_if_purchased > ... > end > > > Now if I change the method name to find_if_subscribed in the model, then > necessarily I will have to change it twice in my controller, well I > could use a before_filter, but what if the method is also called in > other controllers? That's the main problem. How would you do that? > -- > 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 dchelimsky at gmail.com Wed Nov 5 10:20:04 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 09:20:04 -0600 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <88fd8ddc0811050712k5229ddebn6617445c3897f028@mail.gmail.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> <88fd8ddc0811050712k5229ddebn6617445c3897f028@mail.gmail.com> Message-ID: <57c63afe0811050720k3a10061dl343644c5a1356ee8@mail.gmail.com> On Wed, Nov 5, 2008 at 9:12 AM, Andrew Premdas wrote: > What you are suggesting here changing your api to make it easier to refactor > your api. Your trying to do this by > > 1) Generalising the descriptivness of the api > 2) Reducing the number of calls to your api > > Both of these are not particularly good ideas > > 1) Generalising your api, reduces it descriptivness and in sample you give > actually makes you api non descriptive. Instead of methods > find_if_purchased, you now have methods like find_for_index. What you've > done here is pollute the api for your model with stuff outside its concern > (namely the controller) > > 2) You actually want to increase the number of calls to your api. The more > it is called the more useful it is being, and the more thoroughly it is > being tested. If you have no calls, you would not even need to implement it. > > As for solving the problem of refactoring api's quickly there are two > solutions to this > > 1) Use your editors search and replace functionality > 2) Use your tests/specs/stories/features combined with your experience to > ensure you design a simple and clear api up front Be careful with the words "up front" here. To me, they imply that once the design is there that you should not expect it to change, which is the antithesis of agile. Definitely use your tests/specs/stories/features to drive out a simple and clear api, but you should also feel absolutely free to improve it at any time. > Finally your examples were of a poor api, being refactored into a poorer > api. By increasing the number of parameters of your interface. you have > increased by a factor of 4 the number of possible parameter combinations you > have to deal with. Refactoring your unit test for this method should make > that ubundantly clear, and encourage you to change your api. In fact in this > case the method is in completely the wrong place what you should have is > > product.purchased? > product.purchased_by_user?(user) > > Hope this helps > > All best > > Andrew Other than my note above about "up front", I generally agree with what Andrew says here. Cheers, David > > > 2008/11/5 Fernando Perez >> >> > Hmmm, could you make a helper module and mix that into all three >> > controllers? Then there'd be just one place to change it. >> > >> Can you be more descriptive? >> >> Let's say I have: >> >> def show >> Subscription.find_if_purchased >> ... >> end >> >> def update >> Subscription.find_if_purchased >> ... >> end >> >> >> Now if I change the method name to find_if_subscribed in the model, then >> necessarily I will have to change it twice in my controller, well I >> could use a before_filter, but what if the method is also called in >> other controllers? That's the main problem. How would you do that? >> -- >> 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 raasdnil at gmail.com Wed Nov 5 10:40:54 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 6 Nov 2008 02:40:54 +1100 Subject: [rspec-users] rake features and cucumber feature/name not producing same result In-Reply-To: <07AC043B-DA59-44C7-BC86-E597C381C314@mattwynne.net> References: <57a815bf0811041958y9175882k60b55e40c083adb9@mail.gmail.com> <07AC043B-DA59-44C7-BC86-E597C381C314@mattwynne.net> Message-ID: <57a815bf0811050740r38ba8492s1f2068238935d8cb@mail.gmail.com> On Wed, Nov 5, 2008 at 7:10 PM, Matt Wynne wrote: > On 5 Nov 2008, at 03:58, Mikel Lindsaar wrote: > > If I run rake features or cucumber features/* I get one failing FIT >> scenario in one of my features. >> If I then run that feature that contains the FIT table with the failing >> scenario manually, it passes. >> I run it again with rake features or cucumber features/* it fails, run >> individually, it passes. >> Obviously some state is carrying over between the features. >> Any idea where i would start looking to debug the problem? >> Are features transactional? Should I be investigating inter feature state >> contamination? >> > > What is the failure message you're seeing? > > Could it be this? > > http://rspec.lighthouseapp.com/projects/16211/tickets/60-patch-next_column_index-not-resetting-after-large-tables Alas no. I'm getting expected: "1" got: "0" on a simple should change(Model, :count).by(1) It follows the specific model around as well. If I change order of the fit table or not (the fit table has 20 rows of different models all being exercised the same way, they are part of a replication tool that copies a database). The only time it passes is when I run the feature independently. I guess I'll have to look at what the difference is between ( rake features || cucumber features/* ) and cucumber features/specific.feature and try and hunt down what beginning state I could be missing. Any other ideas? Mikel -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Nov 5 10:42:50 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 16:42:50 +0100 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <57c63afe0811050720k3a10061dl343644c5a1356ee8@mail.gmail.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> <88fd8ddc0811050712k5229ddebn6617445c3897f028@mail.gmail.com> <57c63afe0811050720k3a10061dl343644c5a1356ee8@mail.gmail.com> Message-ID: <737427255cb0d180e2179ad7bfa1f608@ruby-forum.com> Okay, I wanted to get some external point of views on an idea. Thanks for your input. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Nov 5 10:44:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 09:44:23 -0600 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <737427255cb0d180e2179ad7bfa1f608@ruby-forum.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> <88fd8ddc0811050712k5229ddebn6617445c3897f028@mail.gmail.com> <57c63afe0811050720k3a10061dl343644c5a1356ee8@mail.gmail.com> <737427255cb0d180e2179ad7bfa1f608@ruby-forum.com> Message-ID: <57c63afe0811050744m664760c3m94e47c7dc7ffc95c@mail.gmail.com> On Wed, Nov 5, 2008 at 9:42 AM, Fernando Perez wrote: > Okay, I wanted to get some external point of views on an idea. Thanks > for your input. You're allowed to disagree :) Does what we're saying make sense to you? From apremdas at gmail.com Wed Nov 5 10:44:41 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Wed, 5 Nov 2008 15:44:41 +0000 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <57c63afe0811050720k3a10061dl343644c5a1356ee8@mail.gmail.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> <88fd8ddc0811050712k5229ddebn6617445c3897f028@mail.gmail.com> <57c63afe0811050720k3a10061dl343644c5a1356ee8@mail.gmail.com> Message-ID: <88fd8ddc0811050744n54345b19x1f6c248ea94b702a@mail.gmail.com> Thanks David Just to confirm "up front" was not in any way meant to imply that the design is fixed or should not be refactored, or even will not need refactoring. Clarifying my point, 2) Use your tests/specs/stories/features combined with your experience to ensure you design an initial api that is clear and simple and consequently easier to refactor when the need arises 2008/11/5 David Chelimsky > On Wed, Nov 5, 2008 at 9:12 AM, Andrew Premdas wrote: > > What you are suggesting here changing your api to make it easier to > refactor > > your api. Your trying to do this by > > > > 1) Generalising the descriptivness of the api > > 2) Reducing the number of calls to your api > > > > Both of these are not particularly good ideas > > > > 1) Generalising your api, reduces it descriptivness and in sample you > give > > actually makes you api non descriptive. Instead of methods > > find_if_purchased, you now have methods like find_for_index. What you've > > done here is pollute the api for your model with stuff outside its > concern > > (namely the controller) > > > > 2) You actually want to increase the number of calls to your api. The > more > > it is called the more useful it is being, and the more thoroughly it is > > being tested. If you have no calls, you would not even need to implement > it. > > > > As for solving the problem of refactoring api's quickly there are two > > solutions to this > > > > 1) Use your editors search and replace functionality > > 2) Use your tests/specs/stories/features combined with your experience > to > > ensure you design a simple and clear api up front > > Be careful with the words "up front" here. To me, they imply that once > the design is there that you should not expect it to change, which is > the antithesis of agile. Definitely use your > tests/specs/stories/features to drive out a simple and clear api, but > you should also feel absolutely free to improve it at any time. > > > Finally your examples were of a poor api, being refactored into a poorer > > api. By increasing the number of parameters of your interface. you have > > increased by a factor of 4 the number of possible parameter combinations > you > > have to deal with. Refactoring your unit test for this method should make > > that ubundantly clear, and encourage you to change your api. In fact in > this > > case the method is in completely the wrong place what you should have is > > > > product.purchased? > > product.purchased_by_user?(user) > > > > Hope this helps > > > > All best > > > > Andrew > > Other than my note above about "up front", I generally agree with what > Andrew says here. > > Cheers, > David > > > > > > > 2008/11/5 Fernando Perez > >> > >> > Hmmm, could you make a helper module and mix that into all three > >> > controllers? Then there'd be just one place to change it. > >> > > >> Can you be more descriptive? > >> > >> Let's say I have: > >> > >> def show > >> Subscription.find_if_purchased > >> ... > >> end > >> > >> def update > >> Subscription.find_if_purchased > >> ... > >> end > >> > >> > >> Now if I change the method name to find_if_subscribed in the model, then > >> necessarily I will have to change it twice in my controller, well I > >> could use a before_filter, but what if the method is also called in > >> other controllers? That's the main problem. How would you do that? > >> -- > >> 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Nov 5 10:51:30 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 16:51:30 +0100 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <57c63afe0811050744m664760c3m94e47c7dc7ffc95c@mail.gmail.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> <88fd8ddc0811050712k5229ddebn6617445c3897f028@mail.gmail.com> <57c63afe0811050720k3a10061dl343644c5a1356ee8@mail.gmail.com> <737427255cb0d180e2179ad7bfa1f608@ruby-forum.com> <57c63afe0811050744m664760c3m94e47c7dc7ffc95c@mail.gmail.com> Message-ID: > You're allowed to disagree :) > > Does what we're saying make sense to you? > Yes, my model classes were starting to get hard to read with method calling other methods calling other methods. Yes, we can change ;-) -- Posted via http://www.ruby-forum.com/. From mauricio.linhares at gmail.com Wed Nov 5 10:55:54 2008 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Wed, 5 Nov 2008 12:55:54 -0300 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <57c63afe0811050744m664760c3m94e47c7dc7ffc95c@mail.gmail.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> <88fd8ddc0811050712k5229ddebn6617445c3897f028@mail.gmail.com> <57c63afe0811050720k3a10061dl343644c5a1356ee8@mail.gmail.com> <737427255cb0d180e2179ad7bfa1f608@ruby-forum.com> <57c63afe0811050744m664760c3m94e47c7dc7ffc95c@mail.gmail.com> Message-ID: I feel the same as Andrew, generalizing all calls to the model methods is bad, as you're making the simple (and common) complicated just to have the uncommon as possible. If you're making a big change as changing a method name and adding a new parameter, you're doing something new, it isn't the same thing or the same feature anymore. Once you have placed a method as public in your object it becomes part of the object's public API and this is always going to be hard to change, that's why we have testing tools like RSpec and refactoring proposals. And isn't this making your controller code ugly? Do you have any samples of this to exemplify what you're doing? - Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) Jo?o Pessoa, PB, +55 83 8867-7208 On Wed, Nov 5, 2008 at 12:44 PM, David Chelimsky wrote: > > You're allowed to disagree :) > > Does what we're saying make sense to you? From josephwilk at joesniff.co.uk Wed Nov 5 10:53:23 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Wed, 05 Nov 2008 15:53:23 +0000 Subject: [rspec-users] rake features and cucumber feature/name not producing same result In-Reply-To: <57a815bf0811050740r38ba8492s1f2068238935d8cb@mail.gmail.com> References: <57a815bf0811041958y9175882k60b55e40c083adb9@mail.gmail.com> <07AC043B-DA59-44C7-BC86-E597C381C314@mattwynne.net> <57a815bf0811050740r38ba8492s1f2068238935d8cb@mail.gmail.com> Message-ID: <4911C173.8080608@joesniff.co.uk> > I'm getting expected: "1" > got: "0" > > on a simple should change(Model, :count).by(1) > > It follows the specific model around as well. If I change order of > the fit table or not (the fit table has 20 rows of different models > all being exercised the same way, they are part of a replication tool > that copies a database). The only time it passes is when I run the > feature independently. > > I guess I'll have to look at what the difference is between ( rake > features || cucumber features/* ) and cucumber > features/specific.feature and try and hunt down what beginning state I > could be missing. > > Any other ideas? > > Mikel > Are you running using Webrat or Selenium/Watir? -- Joseph Wilk http://www.joesniff.co.uk From ashley.moran at patchspace.co.uk Wed Nov 5 11:25:31 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 5 Nov 2008 16:25:31 +0000 Subject: [rspec-users] Design Pattern proposal for better Rails development In-Reply-To: <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> References: <93dff5f8e3a462fda9206b8dfb55ea1f@ruby-forum.com> <64F0EA3C-3402-4649-B8B5-B5C7369C766B@patchspace.co.uk> <23e8acf6782f259aadda91de9a88666c@ruby-forum.com> Message-ID: <57542C3C-0833-449E-A61C-3C6194E52EE7@patchspace.co.uk> On 5 Nov 2008, at 14:28, Fernando Perez wrote: >> Hmmm, could you make a helper module and mix that into all three >> controllers? Then there'd be just one place to change it. >> > Can you be more descriptive? Well I was just thinking out loud really. Something like module SubscriptionStuff def subscriptions Subscription.find_if_purchased end end class MyController include SubscriptionStuff def show subscriptions.xyz end end I'm not saying that's a good idea though, it was just my first reaction to your description. > Let's say I have: > > def show > Subscription.find_if_purchased > ... > end > > def update > Subscription.find_if_purchased > ... > end > > > Now if I change the method name to find_if_subscribed in the model, > then > necessarily I will have to change it twice in my controller, well I > could use a before_filter, but what if the method is also called in > other controllers? That's the main problem. How would you do that? Find and replace has never bothered me. If I had something that had a potentially conflicting name, I'd redefine the old method to raise an error and run the specs again. But I've never needed to do this. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From court3nay at gmail.com Wed Nov 5 12:23:39 2008 From: court3nay at gmail.com (Courtenay) Date: Wed, 5 Nov 2008 09:23:39 -0800 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> Message-ID: <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> On Wed, Nov 5, 2008 at 2:58 AM, Alex Satrapa wrote: > On 05/11/2008, at 01:37 , Steven Baker wrote: > >> Big difference between "haven't been able to" and "wouldn't learn the >> tools". Ashley's post below sums it up best. This is a problem that's seen >> regularly when working with new ideas. How many times have you seen Agile >> blamed when a project fails due to poor management? I personally see this >> all the time. > > Personally, the first question on my mind was why they weren't using > separate environments for each of their production applications. > Not sure if this is a python troll or not.. however, our biggest problem was the development environment, not production. From lists at ruby-forum.com Wed Nov 5 12:35:11 2008 From: lists at ruby-forum.com (Togetherne Togetherne) Date: Wed, 5 Nov 2008 18:35:11 +0100 Subject: [rspec-users] Mulitbrowser selenium ruby In-Reply-To: <4901A5EF.5080903@joesniff.co.uk> References: <1730f07835c53026b54a5d23140194d4@ruby-forum.com> <4901A5EF.5080903@joesniff.co.uk> Message-ID: Joseph Wilk wrote: > 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). Thanks Joseph i looked at selenium grid and it seems to be the answer to all my problems!! thank you so much!! wondering if you could give me a hand to set it up so that it drives multiple drivers... I have downloaded the demo, and run the example ruby tests in sequence and parrallel. I know how to start the hub, how to set up different RC instances that support different browsers on different machines but.... im still unsure on how to get it to run all the tests in ie and firefox without having to manually chaning it everytime....can you shed some light?? Thanks appreciate the help you have given me so far... -- Posted via http://www.ruby-forum.com/. From nick at deadorange.com Wed Nov 5 13:51:34 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 5 Nov 2008 13:51:34 -0500 Subject: [rspec-users] Stubbing times: #from_now et al. Message-ID: I had a look around for how to stub Time.now , #from_now , etc, and came across this, which was useful: http://devblog.michaelgalero.com/2007/11/23/actioncontroller-rspec-stub-timenow/ Unfortunately, my situation is slightly different, and causes that solution to not be applicable. This is what I'm trying to spec: def remember_me_for(time) remember_me_until time.from_now.utc end I thought this would work: it 'should remember a user for a period of time' do user = create_user one_week = 1.week from_now = 1.week.from_now from_now_utc = 1.week.from_now.utc one_week.stub!(:from_now).and_return from_now from_now.stub!(:utc).and_return from_now_utc user.should_receive(:remember_me_until).with from_now_utc user.remember_me_for one_week end But that fails, referencing the stub on "one_week": TypeError in 'User should remember a user for a period of time' no virtual class for Fixnum Any suggestions for how to solve this? Thanks! Nick From rick.denatale at gmail.com Wed Nov 5 14:11:32 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 5 Nov 2008 14:11:32 -0500 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> Message-ID: My 2 cents http://talklikeaduck.denhaven2.com/articles/2008/11/05/the-rspec-caboo-se-brouhaha -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Wed Nov 5 14:18:41 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 05 Nov 2008 11:18:41 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: (Greg Hauptmann's message of "Wed\, 5 Nov 2008 13\:25\:25 +1000") References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> Message-ID: "Greg Hauptmann" writes: > so is the concept to build up all seed data creation in one > place/method, & then for the rake spec case run this in via the "test" > environment.rb file? That sounds good. I typically put it in spec_helper.rb so all test-related stuff is in one place, but I think it makes a lot of sense to treat this as part of the environment. > But then if you were to use rake:migrate to drop back a couple of > version you might be in a spot of bother? (ie newest seed data not > then tied to migration)? Let me know if I'm understanding your problem correctly...if you put the seed data in test.rb, then it'll try to load it regardless of whether it matches the db schema. Is that right? If that's the case, I suppose you could do a check to see if you even need to load seed data. Basically, if there are already users in the test db, no need to do anything. This would let you have a fully-migrated db with seed data that you then migrated down. But honestly I'm not sure why you would want to drop the schema back down a couple of versions in the first place? Pat > > > On 11/5/08, Pat Maddox wrote: >> "Mark Wilden" writes: >> >>> On Tue, Nov 4, 2008 at 4:26 PM, Pat Maddox wrote: >>> >>> aslak's right though in that case too. In your spec_helper, just loop >>> over the tables and delete everything, then insert the seed data you >>> want, and it should be good to go. >>> >>> But then Ashley's comment applies: you've got the same facts in two >>> places. Best thing is to >>> avoid the dependency, if at all possible. >> >> Sure, but you can encapsulate all that stuff too. When I've done stuff >> like this in the past (and on second thought I have done it just as >> aslak suggested, I just didn't think of it :) we've created some seed >> data builders. Then it becomes a simple matter of SeedData.build_data >> to kick off the whole deal. >> >> 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 mark at mwilden.com Wed Nov 5 14:30:24 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 5 Nov 2008 11:30:24 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> Message-ID: <3c30da400811051130t1ef8295cj61e8ffbcd49118be@mail.gmail.com> I'll just point out one more disadvantage of assuming the contents of the test database are correct (without 'rake db:test:prepare'). If you interrupt a test with Ctrl-C (especially when running autospec), it's possible for the transaction not to get rolled back. An uncommitted transaction should get rolled back automatically, but I've seen that fail to happen, at least with PostgreSQL 8.1. A test would assume that a given table is empty, they'd add a row, expect the count to be 1, and it would fail because of existing cruft. I eventually learned to run 'rake spec' when weird failures happened. Just something to keep in mind. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Nov 5 14:42:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 13:42:47 -0600 Subject: [rspec-users] Stubbing times: #from_now et al. In-Reply-To: References: Message-ID: <57c63afe0811051142m74477b7ds1db0c18be41f20de@mail.gmail.com> On Wed, Nov 5, 2008 at 12:51 PM, Nick Hoffman wrote: > I had a look around for how to stub Time.now , #from_now , etc, and came > across this, which was useful: > http://devblog.michaelgalero.com/2007/11/23/actioncontroller-rspec-stub-timenow/ > > Unfortunately, my situation is slightly different, and causes that solution > to not be applicable. This is what I'm trying to spec: > > def remember_me_for(time) > remember_me_until time.from_now.utc > end > > I thought this would work: > > it 'should remember a user for a period of time' do > user = create_user > one_week = 1.week > from_now = 1.week.from_now > from_now_utc = 1.week.from_now.utc > > one_week.stub!(:from_now).and_return from_now > from_now.stub!(:utc).and_return from_now_utc > > user.should_receive(:remember_me_until).with from_now_utc > > user.remember_me_for one_week > end > > But that fails, referencing the stub on "one_week": > > TypeError in 'User should remember a user for a period of time' > no virtual class for Fixnum > > Any suggestions for how to solve this? Thanks! Looks like you can't stub anything on a Fixnum because of the way RSpec's mocking works. >> require 'spec/mocks' => true >> 1.stub!(:foo) TypeError: no virtual class for Fixnum Same with mocha, apparently. >> require 'mocha' => true >> 1.stubs(:foo) TypeError: no virtual class for Fixnum Same with rr: >> require 'rr' => true >> mock(1).foo TypeError: no virtual class for Fixnum And lastly (but not leastly), flexmock: >> require 'flexmock' >> include FlexMock::MockContainer => Object >> flexmock(1).foo TypeError: no virtual class for Fixnum The problem is there is no Singleton Class for 1, probably an efficiency in Ruby since 1 is, itself, a Singleton. All of these frameworks try to manipulate methods on the object's singleton class. So no mocking/stubbing on Fixnums. Apparently. Not much help - sorry. David > Nick From pergesu at gmail.com Wed Nov 5 14:45:38 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 05 Nov 2008 11:45:38 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: <3c30da400811051130t1ef8295cj61e8ffbcd49118be@mail.gmail.com> (Mark Wilden's message of "Wed\, 5 Nov 2008 11\:30\:24 -0800") References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> <3c30da400811051130t1ef8295cj61e8ffbcd49118be@mail.gmail.com> Message-ID: "Mark Wilden" writes: > I'll just point out one more disadvantage of assuming the contents of the test database are > correct (without 'rake db:test:prepare'). If you interrupt a test with Ctrl-C (especially when > running autospec), it's possible for the transaction not to get rolled back. An uncommitted > transaction should get rolled back automatically, but I've seen that fail to happen, at least > with PostgreSQL 8.1. A test would assume that a given table is empty, they'd add a row, expect > the count to be 1, and it would fail because of existing cruft. I eventually learned to run > 'rake spec' when weird failures happened. Just something to keep in mind. Well that is fascinating. It seems very, very wrong. Something I might expect from MySQL, but never postgres... :) Pat From lists at ruby-forum.com Wed Nov 5 14:55:39 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 20:55:39 +0100 Subject: [rspec-users] RSpec whines when I set the value of an object Message-ID: In have the following code: def index @items = Item.find_for_payment(session[:order_id], @site.id) @cart.amount = @items.sum { |item| item.price.to_i * item.quantity.to_i } end @cart is set by a before_filter called find_cart which I stub. find_for_payment is stubbed too. In my spec I simply test for the following: -- it "should display cart" do @items = [] 1.upto(2) do |i| @items << mock_model(Item, :id => i, :price => 10 * i, :quantity => i, :order_id => 1) end Item.stub!(:find_for_payment).and_return(@items) @cart = mock_model(Order, :id => 1, :amount => 0, :tax => 0) Order.stub!(:find_cart).and_return(@cart) Item.should_receive(:find_for_payment).with(1, 1).and_return(@items) get :index end -- And I get the following error message: -- Mock 'Order_1' received unexpected message :amount= with (50) -- Well I know that @cart.amount will be set to 50, but why is RSpec complaining about that? If I put @cart.should_receive(:amount).with(50), rspec still throws an error message. What to do? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 5 14:59:03 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 20:59:03 +0100 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: References: Message-ID: <9670574370787e57c6e7f897b013b782@ruby-forum.com> To make RSpec happy, I tried to test for the following: -- @cart.amount.should eql(50) -- And now I get: -- FAILED expected 50, got 0 (using .eql?) -- So is @cart.amount being set to 50 or not in the spec? When I test manually it works fine. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Nov 5 14:59:33 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 13:59:33 -0600 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: References: Message-ID: <57c63afe0811051159u43113f8av3fa1024665b36a99@mail.gmail.com> On Wed, Nov 5, 2008 at 1:55 PM, Fernando Perez wrote: > In have the following code: > > def index > @items = Item.find_for_payment(session[:order_id], @site.id) > @cart.amount = @items.sum { |item| item.price.to_i * > item.quantity.to_i } > end > > @cart is set by a before_filter called find_cart which I stub. > find_for_payment is stubbed too. > > In my spec I simply test for the following: > -- > it "should display cart" do > @items = [] > 1.upto(2) do |i| > @items << mock_model(Item, :id => i, :price => 10 * i, :quantity > => i, :order_id => 1) > end > > Item.stub!(:find_for_payment).and_return(@items) > > @cart = mock_model(Order, :id => 1, :amount => 0, :tax => 0) > Order.stub!(:find_cart).and_return(@cart) > > Item.should_receive(:find_for_payment).with(1, 1).and_return(@items) > get :index > end > -- > > And I get the following error message: > -- > Mock 'Order_1' received unexpected message :amount= with (50) > -- > > > Well I know that @cart.amount will be set to 50, but why is RSpec > complaining about that? > > If I put @cart.should_receive(:amount).with(50), rspec still throws an > error message. What to do? @cart.should_receive(:amount=).with(50) amount and amount= are two different methods :) > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nick at deadorange.com Wed Nov 5 14:59:45 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 5 Nov 2008 14:59:45 -0500 Subject: [rspec-users] Stubbing times: #from_now et al. In-Reply-To: <57c63afe0811051142m74477b7ds1db0c18be41f20de@mail.gmail.com> References: <57c63afe0811051142m74477b7ds1db0c18be41f20de@mail.gmail.com> Message-ID: <0F8B5A74-5A2A-49DD-8DD3-6F13BA0E71EB@deadorange.com> On 2008-11-05, at 14:42, David Chelimsky wrote: > The problem is there is no Singleton Class for 1, probably an > efficiency in Ruby since 1 is, itself, a Singleton. > > All of these frameworks try to manipulate methods on the object's > singleton class. So no mocking/stubbing on Fixnums. Apparently. > > Not much help - sorry. That was a good explanation. Thanks, mate. At least now I know not to chase this path any further! From ben at benmabey.com Wed Nov 5 15:02:29 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 05 Nov 2008 13:02:29 -0700 Subject: [rspec-users] Stubbing times: #from_now et al. In-Reply-To: References: Message-ID: <4911FBD5.7040806@benmabey.com> Nick Hoffman wrote: > I had a look around for how to stub Time.now , #from_now , etc, and > came across this, which was useful: > http://devblog.michaelgalero.com/2007/11/23/actioncontroller-rspec-stub-timenow/ > > > Unfortunately, my situation is slightly different, and causes that > solution to not be applicable. This is what I'm trying to spec: > > def remember_me_for(time) > remember_me_until time.from_now.utc > end > > I thought this would work: > > it 'should remember a user for a period of time' do > user = create_user > one_week = 1.week > from_now = 1.week.from_now > from_now_utc = 1.week.from_now.utc > > one_week.stub!(:from_now).and_return from_now > from_now.stub!(:utc).and_return from_now_utc > > user.should_receive(:remember_me_until).with from_now_utc > > user.remember_me_for one_week > end > > But that fails, referencing the stub on "one_week": > > TypeError in 'User should remember a user for a period of time' > no virtual class for Fixnum > > Any suggestions for how to solve this? Thanks! > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Hey Nick, It is generally a bad idea to stub/mock a method on the object you are verifying the behaviour of. I would recommend a state-based approach of testing this method as opposed to the interaction-based one you are pursuing. The reason being is that you want to verify the behaviour of the object as a whole. How the object uses it's internal methods and state is none of the code example's business. Without knowing the other methods on User I don't know the best way to verify the behavior.. What other methods that deal with the remember functionality are part of the public API? Assuming it is an AR model and you have a 'remember_me_until' column you could do something like: it 'should remember a user for a period of time' do user = create_user user.remember_me_for(1.week) user.remember_me_until.should == 1.week.from_now.utc end Again, using the #remember_me_until method is testing the internal state of the object but without knowing your other methods I don't what the better options (if any) are. HTH, Ben From nick at deadorange.com Wed Nov 5 15:05:20 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 5 Nov 2008 15:05:20 -0500 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: References: Message-ID: <7E2E7EB8-DE90-457A-9C0B-DDB0E65D3BAB@deadorange.com> On 2008-11-05, at 14:55, Fernando Perez wrote: > And I get the following error message: > -- > Mock 'Order_1' received unexpected message :amount= with (50) > -- > > > Well I know that @cart.amount will be set to 50, but why is RSpec > complaining about that? > > If I put @cart.should_receive(:amount).with(50), rspec still throws an > error message. What to do? Hi Fernando. The error's occuring because #amount= hasn't been defined within the "Order_1" mock object. Try this: @cart.should_receive(:amount=).with 50 Cheers, Nick From lists at ruby-forum.com Wed Nov 5 15:08:42 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 21:08:42 +0100 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: <57c63afe0811051159u43113f8av3fa1024665b36a99@mail.gmail.com> References: <57c63afe0811051159u43113f8av3fa1024665b36a99@mail.gmail.com> Message-ID: > @cart.should_receive(:amount=).with(50) > > amount and amount= are two different methods :) Thanks Dave! So now if I test for: @cart.amount.should eql(50) Why do I get this error: expected 50, got 0 (using .eql?) I have to add that the @cart is not saved in DB after its amount attribute is set, it is only displayed in the view for the user to see what would be the total amount. Does the @cart object need to be saved to be able to test it with should eql(50)? -- Posted via http://www.ruby-forum.com/. From mark at mwilden.com Wed Nov 5 15:10:25 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 5 Nov 2008 12:10:25 -0800 Subject: [rspec-users] Stubbing times: #from_now et al. In-Reply-To: <57c63afe0811051142m74477b7ds1db0c18be41f20de@mail.gmail.com> References: <57c63afe0811051142m74477b7ds1db0c18be41f20de@mail.gmail.com> Message-ID: <3c30da400811051210k39240182rfc902dc655464a07@mail.gmail.com> On Wed, Nov 5, 2008 at 11:42 AM, David Chelimsky wrote: > Looks like you can't stub anything on a Fixnum because of the way > RSpec's mocking works. > > >> require 'spec/mocks' > => true > >> 1.stub!(:foo) > TypeError: no virtual class for Fixnum > What I can't figure out is this: >> 1.day => 1 day >> 1.day.class => Fixnum Is 1.day an ActiveSupport::Duration or a Fixnum? ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Nov 5 15:13:44 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Nov 2008 14:13:44 -0600 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: References: <57c63afe0811051159u43113f8av3fa1024665b36a99@mail.gmail.com> Message-ID: <57c63afe0811051213h697f0b72l6b2c3e4aa87f812a@mail.gmail.com> On Wed, Nov 5, 2008 at 2:08 PM, Fernando Perez wrote: >> @cart.should_receive(:amount=).with(50) >> >> amount and amount= are two different methods :) > > Thanks Dave! > > So now if I test for: @cart.amount.should eql(50) > > Why do I get this error: expected 50, got 0 (using .eql?) > > I have to add that the @cart is not saved in DB after its amount > attribute is set, it is only displayed in the view for the user to see > what would be the total amount. > > Does the @cart object need to be saved to be able to test it with should > eql(50)? Fernando - I'm happy to help, as are we all, but you make it difficult to understand the context if we have to look at other email in the thread to see the code. Please make sure, when you ask a question, that you quote enough of the thread so that the readers can understand what you're asking. From nick at deadorange.com Wed Nov 5 15:16:02 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 5 Nov 2008 15:16:02 -0500 Subject: [rspec-users] Stubbing times: #from_now et al. In-Reply-To: <4911FBD5.7040806@benmabey.com> References: <4911FBD5.7040806@benmabey.com> Message-ID: <21639A6B-3885-46BF-B471-B948B3D2F4AD@deadorange.com> On 2008-11-05, at 15:02, Ben Mabey wrote: > Hey Nick, > It is generally a bad idea to stub/mock a method on the object you > are verifying the behaviour of. I would recommend a state-based > approach of testing this method as opposed to the interaction-based > one you are pursuing. The reason being is that you want to verify > the behaviour of the object as a whole. How the object uses it's > internal methods and state is none of the code example's business. > Without knowing the other methods on User I don't know the best way > to verify the behavior.. What other methods that deal with the > remember functionality are part of the public API? Assuming it is > an AR model and you have a 'remember_me_until' column you could do > something like: > > > it 'should remember a user for a period of time' do > user = create_user > user.remember_me_for(1.week) > user.remember_me_until.should == 1.week.from_now.utc > end > > Again, using the #remember_me_until method is testing the internal > state of the object but without knowing your other methods I don't > what the better options (if any) are. > > HTH, > Ben Hi Ben. #remember_me is used to keep a user logged in to the website if they ticked the "Remember me?" checkbox in the login form. It's only called from one location in the app: case when valid_remember_cookie? then @current_user.refresh_token # keeping same expiry date when new_cookie_flag then @current_user.remember_me else @current_user.forget_me end So as you suggested, my spec example should probably just be checking to see that the User instance's "remember_me_until" attribute is set to an appropriate value. Thanks! Nick From lists at ruby-forum.com Wed Nov 5 15:23:55 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 21:23:55 +0100 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: <57c63afe0811051213h697f0b72l6b2c3e4aa87f812a@mail.gmail.com> References: <57c63afe0811051159u43113f8av3fa1024665b36a99@mail.gmail.com> <57c63afe0811051213h697f0b72l6b2c3e4aa87f812a@mail.gmail.com> Message-ID: <8021f7316fd0ee255026f61980b07480@ruby-forum.com> > Please make sure, when you ask a question, that you quote enough of > the thread so that the readers can understand what you're asking. Hmmm, I don't have this problem as I am using ruby-forum.com to browse threads, it is x100 times more readable with basic color highlighting. I'll do my best to include quotes for people who use regular mail clients. So here is my controller code: -- def index @items = Item.find_for_payment(session[:order_id], @site.id) @cart.amount = @items.sum { |item| item.price.to_i * item.quantity.to_i } end -- And my spec: -- it "should display cart" do @items = [] 1.upto(2) do |i| @items << mock_model(Item, :id => i, :price => 10 * i, :quantity => i, :order_id => 1) end Item.stub!(:find_for_payment).and_return(@items) @cart = mock_model(Order, :id => 1, :amount => 0, :tax => 0) Order.stub!(:find_cart).and_return(@cart) Item.should_receive(:find_for_payment).with(1, 1).and_return(@items) @cart.should_receive(:amount=).with(50) @cart.amount.should eql(50) get :index end -- This throws the error: expected 50, got 0 (using .eql?) As I said, I don't actually save the @cart object in DB, I just temporarily set its amount attribute so that it will print the value in the corresponding view. I am now wondering why RSpec doesn't see it is set to 50. -- Posted via http://www.ruby-forum.com/. From nick at deadorange.com Wed Nov 5 15:26:13 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 5 Nov 2008 15:26:13 -0500 Subject: [rspec-users] Stubbing times: #from_now et al. In-Reply-To: <3c30da400811051210k39240182rfc902dc655464a07@mail.gmail.com> References: <57c63afe0811051142m74477b7ds1db0c18be41f20de@mail.gmail.com> <3c30da400811051210k39240182rfc902dc655464a07@mail.gmail.com> Message-ID: <3D09811F-0E6F-4D10-A115-E68656558769@deadorange.com> On 2008-11-05, at 15:10, Mark Wilden wrote: > What I can't figure out is this: > > >> 1.day > => 1 day > > >> 1.day.class > => Fixnum > > Is 1.day an ActiveSupport::Duration or a Fixnum? > > ///ark It's an ActiveSupport::Duration : 48 def days 49 ActiveSupport::Duration.new(self * 24.hours, [[:days, self]]) 50 end 51 alias :day :days I've no idea why 1.day.class returns Fixnum though.. From nick at deadorange.com Wed Nov 5 15:32:47 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 5 Nov 2008 15:32:47 -0500 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: <8021f7316fd0ee255026f61980b07480@ruby-forum.com> References: <57c63afe0811051159u43113f8av3fa1024665b36a99@mail.gmail.com> <57c63afe0811051213h697f0b72l6b2c3e4aa87f812a@mail.gmail.com> <8021f7316fd0ee255026f61980b07480@ruby-forum.com> Message-ID: On 2008-11-05, at 15:23, Fernando Perez wrote: > This throws the error: expected 50, got 0 (using .eql?) This is because you told @cart to return 0 when #amount is called on it: @cart = mock_model(Order, :id => 1, :amount => 0, :tax => 0) I think maybe you're confusing what the arguments to #mock_model do. They don't set attributes' values in the mock object. The first argument specifies which class is being mocked. In this case, Order. The other arguments tell the mock what value to return for a given method. So this: @cart = mock_model Order, :amount => 0 tells the mock object in @cart to respond to #amount , and return the value 0 (zero). Does that make things a bit clearer? Cheers, Nick From sfeley at gmail.com Wed Nov 5 15:39:29 2008 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 5 Nov 2008 15:39:29 -0500 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> Message-ID: <1fb4df0811051239k7d8f1165s63f27029d4a3b6b2@mail.gmail.com> On Wed, Nov 5, 2008 at 12:23 PM, Courtenay wrote: > > Not sure if this is a python troll or not.. however, our biggest > problem was the development environment, not production. I hosed my development environment once. I did pair programming with a VIM junkie, and foolishly let him install whatever he wanted on my laptop to embed MacVIM and make it telepathic, or something. When he was done I couldn't find my usual shell vi again. (Yes, sometimes I use vi instead of Textmate to edit config files and such. But I don't want it in a window with its own kitchen sink.) Then the next day I installed Ruby 1.9 from MacPorts and, in the process of making it the default, managed to delete the Ruby that came with OS X. Gems blew up everywhere, yadda yadda, and then I didn't want it after all. Stupid. My point is that it did not take me days to recover from all this screwiness. I was using Time Machine. I booted from the Leopard DVD, said "Make it Wednesday again," and let it recopy my whole hard drive. Poof, problem never happened, and I didn't lose any work because documents and projects were all on .Mac or Github. (Prior to Time Machine I used dirvish, and recovery would have been slightly more complex but the same principle applied.) You guys are famous programmers, so I know you must be disciplined about backups and version control. Why did they fail you? Is it RSpec's fault? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From mark at mwilden.com Wed Nov 5 15:39:36 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 5 Nov 2008 12:39:36 -0800 Subject: [rspec-users] Stubbing times: #from_now et al. In-Reply-To: <3D09811F-0E6F-4D10-A115-E68656558769@deadorange.com> References: <57c63afe0811051142m74477b7ds1db0c18be41f20de@mail.gmail.com> <3c30da400811051210k39240182rfc902dc655464a07@mail.gmail.com> <3D09811F-0E6F-4D10-A115-E68656558769@deadorange.com> Message-ID: <3c30da400811051239p343b385dg68b848137af4eff7@mail.gmail.com> On Wed, Nov 5, 2008 at 12:26 PM, Nick Hoffman wrote: > On 2008-11-05, at 15:10, Mark Wilden wrote: > >> What I can't figure out is this: >> >> >> 1.day >> => 1 day >> >> >> 1.day.class >> => Fixnum >> >> I've no idea why 1.day.class returns Fixnum though.. > Yeah, I'd looked at the code. Why #class returns Fixnum was my question, actually. Something to do with coercion, maybe. The other thing is that if it were simply a Duration, I'd expect you to be able to stub it. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Wed Nov 5 15:37:54 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 5 Nov 2008 15:37:54 -0500 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: <8021f7316fd0ee255026f61980b07480@ruby-forum.com> References: <57c63afe0811051159u43113f8av3fa1024665b36a99@mail.gmail.com> <57c63afe0811051213h697f0b72l6b2c3e4aa87f812a@mail.gmail.com> <8021f7316fd0ee255026f61980b07480@ruby-forum.com> Message-ID: <5EC4D150-17BD-4615-A9DE-EDF09D9172C4@deadorange.com> On 2008-11-05, at 15:23, Fernando Perez wrote: > Hmmm, I don't have this problem as I am using ruby-forum.com to browse > threads, it is x100 times more readable with basic color highlighting. > I'll do my best to include quotes for people who use regular mail > clients. > > So here is my controller code: > -- > def index > @items = Item.find_for_payment(session[:order_id], @site.id) > @cart.amount = @items.sum { |item| item.price.to_i * > item.quantity.to_i } > end > -- > > And my spec: > -- > it "should display cart" do > @items = [] > 1.upto(2) do |i| > @items << mock_model(Item, :id => i, :price => 10 * i, :quantity > => i, :order_id => 1) > end > > Item.stub!(:find_for_payment).and_return(@items) > > @cart = mock_model(Order, :id => 1, :amount => 0, :tax => 0) > Order.stub!(:find_cart).and_return(@cart) > > Item.should_receive(:find_for_payment).with(1, > 1).and_return(@items) > @cart.should_receive(:amount=).with(50) > @cart.amount.should eql(50) > > get :index > end > -- > > This throws the error: expected 50, got 0 (using .eql?) > > As I said, I don't actually save the @cart object in DB, I just > temporarily set its amount attribute so that it will print the value > in > the corresponding view. I am now wondering why RSpec doesn't see it is > set to 50. This expectation: @cart.amount.should eql(50) is just testing Order#amount= . In my opinion, that's not necessary, because Order#amount= is provided by Rails, which you can be confident has been tested fully. This expectation: @cart.should_receive(:amount=).with(50) is what you really want, because it's ensuring that Order#amount= is being called with the correct value. So, just remove the "should eql(50)" expectation, and you're all set! -Nick From lists at ruby-forum.com Wed Nov 5 15:53:22 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Wed, 5 Nov 2008 21:53:22 +0100 Subject: [rspec-users] RSpec whines when I set the value of an object In-Reply-To: <5EC4D150-17BD-4615-A9DE-EDF09D9172C4@deadorange.com> References: <57c63afe0811051159u43113f8av3fa1024665b36a99@mail.gmail.com> <57c63afe0811051213h697f0b72l6b2c3e4aa87f812a@mail.gmail.com> <8021f7316fd0ee255026f61980b07480@ruby-forum.com> <5EC4D150-17BD-4615-A9DE-EDF09D9172C4@deadorange.com> Message-ID: <957960ad1f34b67b7b0d85dd265c7834@ruby-forum.com> > This expectation: > @cart.should_receive(:amount=).with(50) > is what you really want, because it's ensuring that Order#amount= is > being called with the correct value. > > So, just remove the "should eql(50)" expectation, and you're all set! > -Nick You are perfectly right Nick, I had just noticed that behavior which I couldn't understand so that's why I wanted to know what was behind it. At the same time it taught how exactly mock_model works which I first got completely wrong. Thanks for your assistance. -- Posted via http://www.ruby-forum.com/. From mark at mwilden.com Wed Nov 5 16:11:07 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 5 Nov 2008 13:11:07 -0800 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <1fb4df0811051239k7d8f1165s63f27029d4a3b6b2@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> <1fb4df0811051239k7d8f1165s63f27029d4a3b6b2@mail.gmail.com> Message-ID: <3c30da400811051311t3f6e28em67dca737e43d7ed8@mail.gmail.com> On Wed, Nov 5, 2008 at 12:39 PM, Stephen Eley wrote: > > My point is that it did not take me days to recover from all this > screwiness. I was using Time Machine. I booted from the Leopard DVD, > said "Make it Wednesday again," and let it recopy my whole hard drive. > Time Machine is especially cool because it backs up hourly. My criterion has always been, if a meteor annihilates my computer, how long would it take to get back to work? No meteors yet, but better safe than sorry. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From sfeley at gmail.com Wed Nov 5 16:32:06 2008 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 5 Nov 2008 16:32:06 -0500 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <3c30da400811051311t3f6e28em67dca737e43d7ed8@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> <1fb4df0811051239k7d8f1165s63f27029d4a3b6b2@mail.gmail.com> <3c30da400811051311t3f6e28em67dca737e43d7ed8@mail.gmail.com> Message-ID: <1fb4df0811051332s4f6b4a50xa37e42674fabe5c7@mail.gmail.com> On Wed, Nov 5, 2008 at 4:11 PM, Mark Wilden wrote: > > Time Machine is especially cool because it backs up hourly. > > My criterion has always been, if a meteor annihilates my computer, how long > would it take to get back to work? No meteors yet, but better safe than > sorry. It's not sufficient for that scenario, however, because that meteor would probably take out your nearby external backup drive as well. My preference is full-drive local backups and then important documents on the Internet. I have a JungleDisk (virtual network drives on top of Amazon S3) workgroup account for my podcasting team. It has some problems with doing live work on it, but for storage or backup it's easy and cheap. But this is getting off-topic. I just wanted to make the point that blaming an upgrade glitch, however whacked-out it might be, for cascading code fixes across all projects and losing a couple days of work was probably unnecessary. A good computer user should have the power to turn back time. I'm also unsure how moving from RSpec to three totally separate tools reduces the risk of such dependency glitches happening again. It wasn't good that this happened, but RSpec isn't the first and only gem ever to cause problems. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From mark at mwilden.com Wed Nov 5 17:18:19 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 5 Nov 2008 14:18:19 -0800 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <1fb4df0811051332s4f6b4a50xa37e42674fabe5c7@mail.gmail.com> References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> <1fb4df0811051239k7d8f1165s63f27029d4a3b6b2@mail.gmail.com> <3c30da400811051311t3f6e28em67dca737e43d7ed8@mail.gmail.com> <1fb4df0811051332s4f6b4a50xa37e42674fabe5c7@mail.gmail.com> Message-ID: <3c30da400811051418sbc22cf1g652d68e1aad2bc3b@mail.gmail.com> On Wed, Nov 5, 2008 at 1:32 PM, Stephen Eley wrote: > > It's not sufficient for that scenario, however, because that meteor > would probably take out your nearby external backup drive as well. That's a good point, which is why I didn't boast about my 1 TB Time Capsule. :) I plan to setup an rsync to my Web site, RSN. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From raasdnil at gmail.com Wed Nov 5 17:52:00 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 6 Nov 2008 09:52:00 +1100 Subject: [rspec-users] rake features and cucumber feature/name not producing same result In-Reply-To: <4911C173.8080608@joesniff.co.uk> References: <57a815bf0811041958y9175882k60b55e40c083adb9@mail.gmail.com> <07AC043B-DA59-44C7-BC86-E597C381C314@mattwynne.net> <57a815bf0811050740r38ba8492s1f2068238935d8cb@mail.gmail.com> <4911C173.8080608@joesniff.co.uk> Message-ID: <57a815bf0811051452vdb31636i5a7130fc59b2e1b7@mail.gmail.com> On Thu, Nov 6, 2008 at 2:53 AM, Joseph Wilk wrote: > I'm getting expected: "1" >> got: "0" >> on a simple should change(Model, :count).by(1) >> >> It follows the specific model around as well. If I change order of the >> fit table or not (the fit table has 20 rows of different models all being >> exercised the same way, they are part of a replication tool that copies a >> database). The only time it passes is when I run the feature independently. >> >> Are you running using Webrat or Selenium/Watir? Yes! Running webrat, latest trunk version (as of yesterday anyway). Though this feature doesn't use it specifically, webrat is loaded with a require line in the features/steps/env.rb file. -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: From glenn at aldenta.com Wed Nov 5 18:00:32 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 5 Nov 2008 17:00:32 -0600 Subject: [rspec-users] Fwd: spec_server not working... In-Reply-To: <7775AC65-C99E-4E9C-B793-7E4A6905F92F@deadorange.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> <7775AC65-C99E-4E9C-B793-7E4A6905F92F@deadorange.com> Message-ID: This is the same error that I get also. I'd love to get this working, Glenn On Oct 31, 2008, at 5:04 PM, Nick Hoffman wrote: > 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Wed Nov 5 19:18:33 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 05 Nov 2008 16:18:33 -0800 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: <3c30da400811051311t3f6e28em67dca737e43d7ed8@mail.gmail.com> (Mark Wilden's message of "Wed\, 5 Nov 2008 13\:11\:07 -0800") References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> <1fb4df0811051239k7d8f1165s63f27029d4a3b6b2@mail.gmail.com> <3c30da400811051311t3f6e28em67dca737e43d7ed8@mail.gmail.com> Message-ID: "Mark Wilden" writes: > On Wed, Nov 5, 2008 at 12:39 PM, Stephen Eley wrote: > > My point is that it did not take me days to recover from all this > screwiness. I was using Time Machine. I booted from the Leopard DVD, > said "Make it Wednesday again," and let it recopy my whole hard drive. > > Time Machine is especially cool because it backs up hourly. > > My criterion has always been, if a meteor annihilates my computer, how long would it take to > get back to work? No meteors yet, but better safe than sorry. Chuck Norris protects my computer from meteors and all other catastrophes. I don't need no stinkin' time machine. Pat From greg.hauptmann.ruby at gmail.com Thu Nov 6 02:31:19 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Thu, 6 Nov 2008 17:31:19 +1000 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> <3c30da400811051130t1ef8295cj61e8ffbcd49118be@mail.gmail.com> Message-ID: how to I get a model statement to run within "test.rb" by the way? For example to get the following to run: RecurringType.create(:name => "TYPE_BASIC") If I just stick this in I get: --------------------extract------------------ Macintosh-2:myequity greg$ rake spec (in /Users/greg/source/myequity) /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:265:in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished) from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:1149:in `columns' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2616:in `attributes_from_column_definition_without_lock' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/locking/optimistic.rb:55:in `attributes_from_column_definition' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2137:in `initialize' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in `new' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in `create' from /Users/greg/source/myequity/config/environments/test.rb:24:in `load_environment' ... 14 levels... from /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in `load_files' from /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/options.rb:98:in `run_examples' from /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' from /Users/greg/source/myequity/vendor/plugins/rspec/bin/spec:4 rake aborted! Command /opt/local/bin/ruby -I"/Users/greg/source/myequity/vendor/plugins/rspec/lib" "/Users/greg/source/myequity/vendor/plugins/rspec/bin/spec" "spec/lib/hash_extensions_spec.rb" "spec/models/bank_account_spec.rb" "spec/models/frequency_spec.rb" "spec/models/interest_rate_spec.rb" "spec/models/projections/projections_spec.rb" "spec/models/recurring_spec.rb" "spec/models/recurring_type_spec.rb" "spec/models/transaction_spec.rb" --options "/Users/greg/source/myequity/spec/spec.opts" failed -------------------------- On Thu, Nov 6, 2008 at 5:45 AM, Pat Maddox wrote: > "Mark Wilden" writes: > >> I'll just point out one more disadvantage of assuming the contents of the test database are >> correct (without 'rake db:test:prepare'). If you interrupt a test with Ctrl-C (especially when >> running autospec), it's possible for the transaction not to get rolled back. An uncommitted >> transaction should get rolled back automatically, but I've seen that fail to happen, at least >> with PostgreSQL 8.1. A test would assume that a given table is empty, they'd add a row, expect >> the count to be 1, and it would fail because of existing cruft. I eventually learned to run >> 'rake spec' when weird failures happened. Just something to keep in mind. > > Well that is fascinating. It seems very, very wrong. Something I might > expect from MySQL, but never postgres... :) > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From greg.hauptmann.ruby at gmail.com Thu Nov 6 04:42:52 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Thu, 6 Nov 2008 19:42:52 +1000 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) Message-ID: anyone able to explain logic behind "rake spec" startup? i.e. the below steps & why things occur when they do Macintosh-2:myequity greg$ rake spec --trace (in /Users/greg/source/myequity) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:load (first_time) ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:load ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Execute spec thanks From lists at ruby-forum.com Thu Nov 6 04:52:24 2008 From: lists at ruby-forum.com (Togetherne Togetherne) Date: Thu, 6 Nov 2008 10:52:24 +0100 Subject: [rspec-users] Parsing Variables from the RakeFile to spec_helper Message-ID: <4b135d4279f496ef0f0ce4a506c90162@ruby-forum.com> Is this possible, i basically want to create a loop in my Rakefile which updates a variable in my spec file with every run the variable is something like: browser = ENV['SELENIUM_RC_BROWSER'] || "*chrome" in my spec_helper i have: def create_selenium_driver remote_control_server = ENV['SELENIUM_RC_HOST'] || "localhost" port = ENV['SELENIUM_RC_PORT'] || 4444 browser = ENV['SELENIUM_RC_BROWSER'] #browser = ENV['SELENIUM_RC_BROWSER'] || "*chrome" timeout = ENV['SELENIUM_RC_TIMEOUT'] || 200 application_host = ENV['SELENIUM_APPLICATION_HOST'] || "" #application_port = ENV['SELENIUM_APPLICATION_PORT'] || "" @selenium_driver = Selenium::Client::Driver.new( remote_control_server, port, browser, "http://#{application_host}", timeout) end I basically want to change the browser variable in my RakeFile and parse it to my spechelper so i can change it with every run.....any ideas? -- Posted via http://www.ruby-forum.com/. From greg.hauptmann.ruby at gmail.com Thu Nov 6 05:33:39 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Thu, 6 Nov 2008 20:33:39 +1000 Subject: [rspec-users] When is spec_helper.rb actually executed? In-Reply-To: <993683E0-0D4C-4503-A5D5-112D94FA6EB9@railsnewbie.com> References: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> <48ED3909.1070101@att.net> <57c63afe0810081631g7e6a50behf30f395d30d458c2@mail.gmail.com> <993683E0-0D4C-4503-A5D5-112D94FA6EB9@railsnewbie.com> Message-ID: can someone advise how best to handle the situation where I want to keep (i.e. not have deleted) my configuration intact? Perhaps seed it in environment/test.rb - but how do I get a normal rails line of code to run in the "test.rb" file (i.e. only for when starting up in test mode)? I get "ActiveRecord::ConnectionNotEstablished" when I include "RecurringType.create(:name => "TYPE_BASIC")"... On Thu, Oct 9, 2008 at 11:52 AM, Scott Taylor wrote: > > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hongli at plan99.net Thu Nov 6 07:01:17 2008 From: hongli at plan99.net (Hongli Lai) Date: Thu, 06 Nov 2008 13:01:17 +0100 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) In-Reply-To: References: Message-ID: <4912DC8D.5090700@plan99.net> Greg Hauptmann wrote: > anyone able to explain logic behind "rake spec" startup? i.e. the > below steps & why things occur when they do > > Macintosh-2:myequity greg$ rake spec --trace > (in /Users/greg/source/myequity) > ** Invoke spec (first_time) > ** Invoke db:test:prepare (first_time) > ** Invoke db:abort_if_pending_migrations (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute db:abort_if_pending_migrations > ** Execute db:test:prepare > ** Invoke db:test:load (first_time) > ** Invoke db:test:purge (first_time) > ** Invoke environment > ** Execute db:test:purge > ** Execute db:test:load > ** Invoke db:schema:load (first_time) > ** Invoke environment > ** Execute db:schema:load > ** Execute spec > 'spec' depends on 'db:test:prepare'. 'db:test:prepare' runs any pending migrations on your development database, and copies the schema structure to the test database. This is to keep the development database's structure and the test database's structure in sync. Almost everything you see here is invoked by 'db:test:preare'. From dchelimsky at gmail.com Thu Nov 6 08:39:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Nov 2008 08:39:21 -0500 Subject: [rspec-users] Parsing Variables from the RakeFile to spec_helper In-Reply-To: <4b135d4279f496ef0f0ce4a506c90162@ruby-forum.com> References: <4b135d4279f496ef0f0ce4a506c90162@ruby-forum.com> Message-ID: <57c63afe0811060539m7fb0ab50nd27159fc6534a52a@mail.gmail.com> On Thu, Nov 6, 2008 at 4:52 AM, Togetherne Togetherne wrote: > Is this possible, i basically want to create a loop in my Rakefile which > updates a variable in my spec file with every run the variable is > something like: > > browser = ENV['SELENIUM_RC_BROWSER'] || "*chrome" > > in my spec_helper i have: > > > def create_selenium_driver > remote_control_server = ENV['SELENIUM_RC_HOST'] || "localhost" > port = ENV['SELENIUM_RC_PORT'] || 4444 > browser = ENV['SELENIUM_RC_BROWSER'] > #browser = ENV['SELENIUM_RC_BROWSER'] || "*chrome" > timeout = ENV['SELENIUM_RC_TIMEOUT'] || 200 > application_host = ENV['SELENIUM_APPLICATION_HOST'] || "" > #application_port = ENV['SELENIUM_APPLICATION_PORT'] || "" > > @selenium_driver = Selenium::Client::Driver.new( > remote_control_server, port, browser, > "http://#{application_host}", timeout) > > end > > I basically want to change the browser variable in my RakeFile and parse > it to my spechelper so i can change it with every run.....any ideas? Are you saying you want to type the same command and have it behave differently each time? I think you'd have to save something to a file each run and read it in each subsequent run. Why not create different tasks? There's a few ways you can handle that and keep control from the command line. From lists at ruby-forum.com Thu Nov 6 08:59:19 2008 From: lists at ruby-forum.com (Togetherne Togetherne) Date: Thu, 6 Nov 2008 14:59:19 +0100 Subject: [rspec-users] Parsing Variables from the RakeFile to spec_helper In-Reply-To: <57c63afe0811060539m7fb0ab50nd27159fc6534a52a@mail.gmail.com> References: <4b135d4279f496ef0f0ce4a506c90162@ruby-forum.com> <57c63afe0811060539m7fb0ab50nd27159fc6534a52a@mail.gmail.com> Message-ID: David Chelimsky wrote: > Why not create different tasks? There's a few ways you can handle that > and keep control from the command line. Thanks for the reply, i have managed i think to get half way there!!: @environment = ["*iehta", "*chrome"] @environment.each {|browse| desc("Run all tests in parallel using DeepTest.") Spec::Rake::SpecTask.new("tests:run_in_parallel") do |t| ENV['SELENIUM_RC_BROWSER'] = browse puts "running test on #{browse}" t.spec_files = FileList['google*.rb'] t.deep_test :number_of_workers => 2 # :timeout_in_seconds => 300 t.spec_opts << '--color' t.spec_opts << "--require 'rubygems,selenium/rspec/reporting/selenium_test_report_formatter'" t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./tmp/test_report.html" t.spec_opts << "--format=progress" end } task :'tests:run_in_parallel' => :create_report however everytime i run tests:run_in_parallel it runs the tests for *chrome twice!!?.... If i create a seperate rake task for each how would i chain them togethr to run 1 after eachother? -- Posted via http://www.ruby-forum.com/. From ramon.tayag at gmail.com Thu Nov 6 09:36:30 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Thu, 6 Nov 2008 22:36:30 +0800 Subject: [rspec-users] Testing variables in controllers? Message-ID: How do you test that your controller fetched the right records? I have an action that returns a different set of records based on whether or not the current_user is the "owner" of the profile being viewed. Code is here http://pastie.org/308685. "controller.submissions.size.should == 1" makes sense but it doesn't work. Of course, I might be doing this wrong altogether! Very new to rspec. Thanks! Ramon Tayag From lists at ruby-forum.com Thu Nov 6 10:02:07 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Thu, 6 Nov 2008 16:02:07 +0100 Subject: [rspec-users] Specing based on user roles Message-ID: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> On my website each user can have the following roles: 1) Not logged in 2) Logged in - active - administrator - sysadministrator How would you write DRY specs to test each action of a controller? Currently I am doing somethings that looks like: -- describe 'a non admin is signed in', :shared => true do before(:each) do @current_user = mock_model(User, :id => 1, :state => 'active') controller.stub!(:current_user).and_return(@current_user) @current_user.should_receive(:administrator?).and_return(false) @current_user.should_receive(:sysadministrator?).and_return(false) end end describe 'an administrator is signed in', :shared => true do before(:each) do @current_user = mock_model(User, :id => 1, :state => 'administrator') controller.stub!(:current_user).and_return(@current_user) @current_user.should_receive(:administrator?).and_return(true) end end describe Admin::OrdersController, 'index' do describe "A non admin wants to have access" do it_should_behave_like 'a non admin is signed in' it "should redirect" do get :index response.should redirect_to(products_url) end end describe "An admin wants to have access" do it_should_behave_like 'an administrator is signed in' it "should render index page" do controller.should_receive(:select_date_initializer).with({},nil) Order.should_not_receive(:admin_find_from_params) get :index end it "should accept search params on index page" do Order.should_receive(:admin_find_from_params).with('test.host', {}, {}) get :index, :commit => 'Search' end end end # describe Admin::OrdersController, 'index' --- I didn't test for the sysadministrator as it would force me to repeat all the tests for administrator, basically a sysadministrator has administrator rights and more. What is a better way of writing such specs? -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Thu Nov 6 10:31:00 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 6 Nov 2008 15:31:00 +0000 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) In-Reply-To: <4912DC8D.5090700@plan99.net> References: <4912DC8D.5090700@plan99.net> Message-ID: <70FC8B0A-A486-4623-B072-AF5C83DDEE36@mattwynne.net> If you want to speed things up, just run spec spec. That will work fine unless you have pending migrations that affect your specs. On 6 Nov 2008, at 12:01, Hongli Lai wrote: > Greg Hauptmann wrote: >> anyone able to explain logic behind "rake spec" startup? i.e. the >> below steps & why things occur when they do >> Macintosh-2:myequity greg$ rake spec --trace >> (in /Users/greg/source/myequity) >> ** Invoke spec (first_time) >> ** Invoke db:test:prepare (first_time) >> ** Invoke db:abort_if_pending_migrations (first_time) >> ** Invoke environment (first_time) >> ** Execute environment >> ** Execute db:abort_if_pending_migrations >> ** Execute db:test:prepare >> ** Invoke db:test:load (first_time) >> ** Invoke db:test:purge (first_time) >> ** Invoke environment >> ** Execute db:test:purge >> ** Execute db:test:load >> ** Invoke db:schema:load (first_time) >> ** Invoke environment >> ** Execute db:schema:load >> ** Execute spec >> > > 'spec' depends on 'db:test:prepare'. 'db:test:prepare' runs any > pending migrations on your development database, and copies the > schema structure to the test database. This is to keep the > development database's structure and the test database's structure > in sync. > > Almost everything you see here is invoked by 'db:test:preare'. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mark at mwilden.com Thu Nov 6 10:36:41 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 6 Nov 2008 07:36:41 -0800 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) In-Reply-To: <4912DC8D.5090700@plan99.net> References: <4912DC8D.5090700@plan99.net> Message-ID: <3c30da400811060736n4b8c125ai7a634f6c3341506a@mail.gmail.com> On Thu, Nov 6, 2008 at 4:01 AM, Hongli Lai wrote: > >> > > 'spec' depends on 'db:test:prepare'. 'db:test:prepare' runs any pending > migrations on your development database, and copies the schema structure to > the test database. This is to keep the development database's structure and > the test database's structure in sync. > > db:test:prepare does not run migrations. It simply checks whether there are any pending migrations and aborts if there are. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Thu Nov 6 10:37:34 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 6 Nov 2008 15:37:34 +0000 Subject: [rspec-users] Testing variables in controllers? In-Reply-To: References: Message-ID: <24E50AF9-9A1E-41B0-B738-744E1A5F4D4E@mattwynne.net> woah! You're exposing way too much of your model here, IMO. That is forcing you to do all that noisy mocking setup in your before block. Can you make a method on your user object like User#valid_submissions and have that return the correct submissions? How do you know whether the user is the profile owner? On 6 Nov 2008, at 14:36, Ramon Tayag wrote: > How do you test that your controller fetched the right records? > > I have an action that returns a different set of records based on > whether or not the current_user is the "owner" of the profile being > viewed. > > Code is here http://pastie.org/308685. > > "controller.submissions.size.should == 1" makes sense but it doesn't > work. Of course, I might be doing this wrong altogether! Very new to > rspec. > > Thanks! > Ramon Tayag > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mark at mwilden.com Thu Nov 6 10:38:45 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 6 Nov 2008 07:38:45 -0800 Subject: [rspec-users] Parsing Variables from the RakeFile to spec_helper In-Reply-To: References: <4b135d4279f496ef0f0ce4a506c90162@ruby-forum.com> <57c63afe0811060539m7fb0ab50nd27159fc6534a52a@mail.gmail.com> Message-ID: <3c30da400811060738t1f9f4cf6yce6e0f32f3d6220@mail.gmail.com> On Thu, Nov 6, 2008 at 5:59 AM, Togetherne Togetherne wrote: > If i create a seperate rake task for each how would i chain them togethr > to run 1 after eachother? > Make a dependency chain. task3 depends on task2 which depends on task1. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Nov 6 10:39:08 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Thu, 6 Nov 2008 16:39:08 +0100 Subject: [rspec-users] Testing variables in controllers? In-Reply-To: References: Message-ID: Ramon Tayag wrote: > How do you test that your controller fetched the right records? > > I have an action that returns a different set of records based on > whether or not the current_user is the "owner" of the profile being > viewed. > > Code is here http://pastie.org/308685. > > "controller.submissions.size.should == 1" makes sense but it doesn't > work. Of course, I might be doing this wrong altogether! Very new to > rspec. > > Thanks! > Ramon Tayag >From what I read and my little experience with rpsec, you shouldn't test for the exact return values. This kind of test should be done when testing the model alone. -- Posted via http://www.ruby-forum.com/. From mark at mwilden.com Thu Nov 6 10:46:10 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 6 Nov 2008 07:46:10 -0800 Subject: [rspec-users] Specing based on user roles In-Reply-To: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> Message-ID: <3c30da400811060746v6e4df1b1pd61b5e0cb9c58b83@mail.gmail.com> On Thu, Nov 6, 2008 at 7:02 AM, Fernando Perez wrote: > On my website each user can have the following roles: > > 1) Not logged in > > 2) Logged in > - active > - administrator > - sysadministrator > > > > How would you write DRY specs to test each action of a controller? > > Currently I am doing somethings that looks like: > -- > describe 'a non admin is signed in', :shared => true do > before(:each) do > @current_user = mock_model(User, :id => 1, :state => 'active') > controller.stub!(:current_user).and_return(@current_user) > @current_user.should_receive(:administrator?).and_return(false) > @current_user.should_receive(:sysadministrator?).and_return(false) > end > end > > describe 'an administrator is signed in', :shared => true do > before(:each) do > @current_user = mock_model(User, :id => 1, :state => > 'administrator') > controller.stub!(:current_user).and_return(@current_user) > @current_user.should_receive(:administrator?).and_return(true) > end > end > > describe Admin::OrdersController, 'index' do > > describe "A non admin wants to have access" do > it_should_behave_like 'a non admin is signed in' > > it "should redirect" do > get :index > response.should redirect_to(products_url) > end > end > > describe "An admin wants to have access" do > it_should_behave_like 'an administrator is signed in' > > it "should render index page" do > controller.should_receive(:select_date_initializer).with({},nil) > Order.should_not_receive(:admin_find_from_params) > > get :index > end > > it "should accept search params on index page" do > Order.should_receive(:admin_find_from_params).with('test.host', > {}, {}) > > get :index, :commit => 'Search' > end > end > > end # describe Admin::OrdersController, 'index' > --- > > I didn't test for the sysadministrator as it would force me to repeat > all the tests for administrator, basically a sysadministrator has > administrator rights and more. What is a better way of writing such > specs? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > One thing I've been trying lately is to share shared spec (somewhat like inheritance). I too have many tests that a essentially duplicates of each other. So by factoring out commonalities and differences, I'd have something like module NonAdminSpec describe 'acting like a non-admin', :shared => true before :each # log in as a non admin describe 'something that only applies to a NonAdmin' do # end module -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Nov 6 11:01:28 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Nov 2008 11:01:28 -0500 Subject: [rspec-users] Specing based on user roles In-Reply-To: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> Message-ID: <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> On Thu, Nov 6, 2008 at 10:02 AM, Fernando Perez wrote: > On my website each user can have the following roles: > > 1) Not logged in > > 2) Logged in > - active > - administrator > - sysadministrator > > > > How would you write DRY specs to test each action of a controller? > > Currently I am doing somethings that looks like: > -- > describe 'a non admin is signed in', :shared => true do > before(:each) do > @current_user = mock_model(User, :id => 1, :state => 'active') > controller.stub!(:current_user).and_return(@current_user) > @current_user.should_receive(:administrator?).and_return(false) > @current_user.should_receive(:sysadministrator?).and_return(false) > end > end > > describe 'an administrator is signed in', :shared => true do > before(:each) do > @current_user = mock_model(User, :id => 1, :state => > 'administrator') > controller.stub!(:current_user).and_return(@current_user) > @current_user.should_receive(:administrator?).and_return(true) > end > end > > describe Admin::OrdersController, 'index' do > > describe "A non admin wants to have access" do > it_should_behave_like 'a non admin is signed in' > > it "should redirect" do > get :index > response.should redirect_to(products_url) > end > end > > describe "An admin wants to have access" do > it_should_behave_like 'an administrator is signed in' > > it "should render index page" do > controller.should_receive(:select_date_initializer).with({},nil) > Order.should_not_receive(:admin_find_from_params) > > get :index > end > > it "should accept search params on index page" do > Order.should_receive(:admin_find_from_params).with('test.host', > {}, {}) > > get :index, :commit => 'Search' > end > end > > end # describe Admin::OrdersController, 'index' > --- > > I didn't test for the sysadministrator as it would force me to repeat > all the tests for administrator, basically a sysadministrator has > administrator rights and more. And why wouldn't you want to test that? > What is a better way of writing such specs? I've really moved away from shared example groups and started writing more targeted macros. So I might do something like this: def for_roles *roles roles.each do |role| before(:each) { login_as role } yield end end describe OrdersController do describe "GET index" do for_roles :admin, :sysadmin do |role| it "..." do ... end end for_roles :sysadmin do |role| it "..." do ... end end end describe "GET edit" do for_roles :admin, :sysadmin do |role| it "..." do ... end end for_roles :sysadmin do |role| it "..." do ... end end end end When you're doing this sort of thing, it is crucial that you keep things organized so that individual actions can change independently as requirements change. This is the thing that most people fail to realize when they try to DRY things up. This scheme makes it easy when we decide to remove a privilege from admin but keep it in sysadmin. Just move that example (it "...") to the other for_roles block. WDYT? From mark at mwilden.com Thu Nov 6 11:03:18 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 6 Nov 2008 08:03:18 -0800 Subject: [rspec-users] Specing based on user roles In-Reply-To: <3c30da400811060746v6e4df1b1pd61b5e0cb9c58b83@mail.gmail.com> References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <3c30da400811060746v6e4df1b1pd61b5e0cb9c58b83@mail.gmail.com> Message-ID: <3c30da400811060803v3288b97fj5c31bc35a819506b@mail.gmail.com> Mark Wilden to rspec-users show details 7:46 AM (0 minutes ago) Reply - Show quoted text - On Thu, Nov 6, 2008 at 7:02 AM, Fernando Perez wrote: > On my website each user can have the following roles: > > 1) Not logged in > > 2) Logged in > - active > - administrator > - sysadministrator > > > > How would you write DRY specs to test each action of a controller? > > Currently I am doing somethings that looks like: > -- > describe 'a non admin is signed in', :shared => true do > before(:each) do > @current_user = mock_model(User, :id => 1, :state => 'active') > controller.stub!(:current_user).and_return(@current_user) > @current_user.should_receive(:administrator?).and_return(false) > @current_user.should_receive(:sysadministrator?).and_return(false) > end > end > > describe 'an administrator is signed in', :shared => true do > before(:each) do > @current_user = mock_model(User, :id => 1, :state => > 'administrator') > controller.stub!(:current_user).and_return(@current_user) > @current_user.should_receive(:administrator?).and_return(true) > end > end > > describe Admin::OrdersController, 'index' do > > describe "A non admin wants to have access" do > it_should_behave_like 'a non admin is signed in' > > it "should redirect" do > get :index > response.should redirect_to(products_url) > end > end > > describe "An admin wants to have access" do > it_should_behave_like 'an administrator is signed in' > > it "should render index page" do > controller.should_receive(:select_date_initializer).with({},nil) > Order.should_not_receive(:admin_find_from_params) > > get :index > end > > it "should accept search params on index page" do > Order.should_receive(:admin_find_from_params).with('test.host', > {}, {}) > > get :index, :commit => 'Search' > end > end > > end # describe Admin::OrdersController, 'index' > --- > > I didn't test for the sysadministrator as it would force me to repeat > all the tests for administrator, basically a sysadministrator has > administrator rights and more. What is a better way of writing such > specs? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > One thing I've been trying lately is to share shared spec (somewhat like inheritance). I too have many tests that a essentially duplicates of each other. So by factoring out commonalities and differences, I'd have something like // anybody_spec.rb module AnybodySpec describe 'anybody', :shared => true end // nonadmin_spec.rb require 'anybody_spec' describe 'a nonadmin' include AnyBodySpec it_should_behave_like 'anybody' before :each # login as a nonadmin # specs that apply to anyone, given the right setup end // admin_spec.rb require 'anybody_spec' module AdminSpec include AnyBodySpec describe 'an admin', :shared => true it_should_behave_like 'anybody' # specs that apply to any admin, given the right setup end describe 'admin' # specs that only apply to admins end // sysadmin_spec.rb require 'admin_spec' module SysAdminSpec include AdminSpec describe 'a sysadmin' it_should_behave_like 'an admin' # specs that apply to any sysadmin, given the right setup end describe 'sysadmin' # specs that only apply to sysadmins end This is all from memory, so it's not complete. But the idea is that you can have shared specs behave_like other shared specs. before() is run from bottom to top, so you can set @instance variables to parameterize the specs, just making sure that an outer level spec doesn't overwrite an inner level spec's variables. I'm writing specs for a lot of different queries. There are three that group by date, week or month - they're different in some ways and the same in a lot of others. Those three are grouped by time period, which is the same in some ways as grouping by an entity, and different from others. There are two or three other types of queries, too, each sharing some stuff and being completely different in other ways. Using nested shared examples like this has massively reduced the duplication in my spec code. And it's also guaranteed that all the specs get run on all the code they apply to. Finally, it has suggested similar refactorings in the code under test. It seems to be working well for me. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at mwilden.com Thu Nov 6 11:07:30 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 6 Nov 2008 08:07:30 -0800 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) In-Reply-To: <70FC8B0A-A486-4623-B072-AF5C83DDEE36@mattwynne.net> References: <4912DC8D.5090700@plan99.net> <70FC8B0A-A486-4623-B072-AF5C83DDEE36@mattwynne.net> Message-ID: <3c30da400811060807q7d0383dfqb0803b6dae42acc0@mail.gmail.com> On Thu, Nov 6, 2008 at 7:31 AM, Matt Wynne wrote: > If you want to speed things up, just run spec spec. That will work fine > unless you have pending migrations that affect your specs. Or if you have migrations that were applied to the dev db, but you haven't run db:test:prepare yet. I still get bitten by that. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Thu Nov 6 11:16:51 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 06 Nov 2008 08:16:51 -0800 Subject: [rspec-users] how to avoid tests removing data that my migrations put in? In-Reply-To: (Greg Hauptmann's message of "Thu\, 6 Nov 2008 17\:31\:19 +1000") References: <7F94FADD-8615-4CE1-9986-5C9232CFADDB@gmail.com> <4910DF69.7030402@benmabey.com> <3c30da400811041637x7317fdd4j16b11b3ea78bf596@mail.gmail.com> <3c30da400811051130t1ef8295cj61e8ffbcd49118be@mail.gmail.com> Message-ID: Oh, I guess it makes sense that it wouldn't work there. The stuff in test.rb is run as part of the initializer block, meaning that Rails hasn't been set up yet there. I would just stick it all in spec_helper.rb. That's what I do and was my initial instinct, because it keeps all the test setup in one place. And it looks like it's by far the easiest way, too :) Pat "Greg Hauptmann" writes: > how to I get a model statement to run within "test.rb" by the way? > For example to get the following to run: > > RecurringType.create(:name => "TYPE_BASIC") > > If I just stick this in I get: > > --------------------extract------------------ > Macintosh-2:myequity greg$ rake spec > (in /Users/greg/source/myequity) > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:265:in > `retrieve_connection': ActiveRecord::ConnectionNotEstablished > (ActiveRecord::ConnectionNotEstablished) > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in > `connection' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:1149:in > `columns' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2616:in > `attributes_from_column_definition_without_lock' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/locking/optimistic.rb:55:in > `attributes_from_column_definition' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2137:in > `initialize' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in > `new' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in > `create' > from /Users/greg/source/myequity/config/environments/test.rb:24:in > `load_environment' > ... 14 levels... > from /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in > `load_files' > from /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/options.rb:98:in > `run_examples' > from /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in > `run' > from /Users/greg/source/myequity/vendor/plugins/rspec/bin/spec:4 > rake aborted! > Command /opt/local/bin/ruby > -I"/Users/greg/source/myequity/vendor/plugins/rspec/lib" > "/Users/greg/source/myequity/vendor/plugins/rspec/bin/spec" > "spec/lib/hash_extensions_spec.rb" "spec/models/bank_account_spec.rb" > "spec/models/frequency_spec.rb" "spec/models/interest_rate_spec.rb" > "spec/models/projections/projections_spec.rb" > "spec/models/recurring_spec.rb" "spec/models/recurring_type_spec.rb" > "spec/models/transaction_spec.rb" --options > "/Users/greg/source/myequity/spec/spec.opts" failed > -------------------------- > > > On Thu, Nov 6, 2008 at 5:45 AM, Pat Maddox wrote: >> "Mark Wilden" writes: >> >>> I'll just point out one more disadvantage of assuming the contents of the test database are >>> correct (without 'rake db:test:prepare'). If you interrupt a test with Ctrl-C (especially when >>> running autospec), it's possible for the transaction not to get rolled back. An uncommitted >>> transaction should get rolled back automatically, but I've seen that fail to happen, at least >>> with PostgreSQL 8.1. A test would assume that a given table is empty, they'd add a row, expect >>> the count to be 1, and it would fail because of existing cruft. I eventually learned to run >>> 'rake spec' when weird failures happened. Just something to keep in mind. >> >> Well that is fascinating. It seems very, very wrong. Something I might >> expect from MySQL, but never postgres... :) >> >> 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 nick at deadorange.com Thu Nov 6 11:50:09 2008 From: nick at deadorange.com (Nick Hoffman) Date: Thu, 6 Nov 2008 11:50:09 -0500 Subject: [rspec-users] Testing variables in controllers? In-Reply-To: References: Message-ID: On 2008-11-06, at 09:36, Ramon Tayag wrote: > How do you test that your controller fetched the right records? > > I have an action that returns a different set of records based on > whether or not the current_user is the "owner" of the profile being > viewed. > > Code is here http://pastie.org/308685. > > "controller.submissions.size.should == 1" makes sense but it doesn't > work. Of course, I might be doing this wrong altogether! Very new to > rspec. > > Thanks! > Ramon Tayag Hi Ramon. I'd refactor most of what's in the "before :show do" block into a couple of User instance methods (or whichever model @user belongs to). For example: http://pastie.org/308814 Cheers, Nick From matt at mattwynne.net Thu Nov 6 12:12:07 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 6 Nov 2008 17:12:07 +0000 Subject: [rspec-users] Caboosers drop RSpec In-Reply-To: References: <42BEDDCD-06ED-4AB3-968B-AC173339A2AE@experthuman.com> <11C34384-49CA-4C61-A049-431226708BBF@stevenrbaker.com> <4b430c8f0811050923s727cafeaqf85ef4612d38f6b@mail.gmail.com> <1fb4df0811051239k7d8f1165s63f27029d4a3b6b2@mail.gmail.com> <3c30da400811051311t3f6e28em67dca737e43d7ed8@mail.gmail.com> Message-ID: <31B5BC89-271C-43C0-97DC-00CF83D0C3B4@mattwynne.net> On 6 Nov 2008, at 00:18, Pat Maddox wrote: > Chuck Norris protects my computer from meteors and all other > catastrophes. I don't need no stinkin' time machine. Chuck Norris can travel through time. Chuck Norris invented time. From ramon.tayag at gmail.com Thu Nov 6 12:30:11 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Fri, 7 Nov 2008 01:30:11 +0800 Subject: [rspec-users] Testing variables in controllers? In-Reply-To: References: Message-ID: Cool thanks Fernando, Matt, Nick - it seems like I haven't made my models fat enough. That seems to be the answer :) Ramon Tayag On Fri, Nov 7, 2008 at 12:50 AM, Nick Hoffman wrote: > On 2008-11-06, at 09:36, Ramon Tayag wrote: >> >> How do you test that your controller fetched the right records? >> >> I have an action that returns a different set of records based on >> whether or not the current_user is the "owner" of the profile being >> viewed. >> >> Code is here http://pastie.org/308685. >> >> "controller.submissions.size.should == 1" makes sense but it doesn't >> work. Of course, I might be doing this wrong altogether! Very new to >> rspec. >> >> Thanks! >> Ramon Tayag > > Hi Ramon. I'd refactor most of what's in the "before :show do" block into a > couple of User instance methods (or whichever model @user belongs to). For > example: http://pastie.org/308814 > > Cheers, > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Thu Nov 6 12:48:45 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 06 Nov 2008 09:48:45 -0800 Subject: [rspec-users] mocking named_scope utilization References: <810a540e0809120732tb6f9205l8824e4996ab60248@mail.gmail.com> <4998060e259d9d06374fd6942efb5c39@ruby-forum.com> <31A54D06-5A2F-4786-AD58-4D3C3FDB32BE@mattwynne.net> <9c9205a149b6a6196a10bbda1300eb2a@ruby-forum.com> Message-ID: "Chris Flipse" writes: > I dunno ... creating a bunch of joining methods seems to be an awfully disjoint way to deal with something that is, admittedly, designed to > laugh in the face of the Law of Demeter. > > I've been handling chains through some heavy use of null_object stubs ... but, I've been doing that sort of manually. Could be rolled up, > at least. > > I'm kind of spitballing something that might be somewhat less manual ... > > foo.stub_chains :method_1, :method_2 do |chain| > end > > def stub_chains(*args) > hades = stub("chain", :null_object => true) > args.each do|chain| > hades.stub!(chain).and_return(hades) > self.stub!(chain).and_return(hades) > end > end Yeah, that's cool. In regards to Demeter, one of my former coworkers argued that if you don't gain much by that encapsulation, you should default to following the ontological structure. Makes a lot of sense to me. Pat From greg.hauptmann.ruby at gmail.com Thu Nov 6 16:07:39 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Fri, 7 Nov 2008 07:07:39 +1000 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) In-Reply-To: <3c30da400811060807q7d0383dfqb0803b6dae42acc0@mail.gmail.com> References: <4912DC8D.5090700@plan99.net> <70FC8B0A-A486-4623-B072-AF5C83DDEE36@mattwynne.net> <3c30da400811060807q7d0383dfqb0803b6dae42acc0@mail.gmail.com> Message-ID: I'm still a bit confused - I'll try to be more specific in questions: * rake db:test:prepare - Check for pending migrations and load the test schema ==> Q1. DOES NOT RUN IN PENDING MIGRATIONS TO TEST DATABASE? ==> Q2. RE TEST SCHEMA - ARE THE MIGRATIONS USE TO CREATE THE DATABASE OR THE DEVELOPMENT SCHEMA FILE??? ==> Q3. WHY DOES IT HAVE TO BE CALLED MORE THAN ONCE? * rake db:test:load - Recreate the test database from the current schema.rb ==> Q4. WHY DO WE NEED TO LOAD FROM THE SCHEMA RATHER THAN MIGRATIONS? IS IT TO AVOID ANY DATA BEING LOADED BY MIGRATIONS FOR THE TEST DATABASE? ==> Q5. WHY IS IT RUN MULTIPLE TIMES? * rake db:test:purge - Empty the test database => Q6. WHY IS IT RUN MULTIPLE TIMES? => Q7. DOES IT DROP TABLES ALSO? tks Confused :) On Fri, Nov 7, 2008 at 2:07 AM, Mark Wilden wrote: > On Thu, Nov 6, 2008 at 7:31 AM, Matt Wynne wrote: > >> >> If you want to speed things up, just run spec spec. That will work fine >> unless you have pending migrations that affect your specs. > > Or if you have migrations that were applied to the dev db, but you haven't > run db:test:prepare yet. I still get bitten by that. > > ///ark > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Nov 6 16:20:29 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Thu, 6 Nov 2008 22:20:29 +0100 Subject: [rspec-users] Specing based on user roles In-Reply-To: <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> Message-ID: > And why wouldn't you want to test that? > I want to test for it, it's just that I don't want to copy/paste spec like an idiot. > def for_roles *roles > roles.each do |role| > before(:each) { login_as role } > yield > end > end > > describe OrdersController do > describe "GET index" do > for_roles :admin, :sysadmin do |role| > it "..." do ... end > end > for_roles :sysadmin do |role| > it "..." do ... end > end > end > This scheme makes it easy when we decide to remove a privilege from > admin but keep it in sysadmin. Just move that example (it "...") to > the other for_roles block. > > WDYT? I like your idea very much, very clean, readable and maintainable. And thank you Mark, I will also use your idea to factor out commonalities in my specs. -- Posted via http://www.ruby-forum.com/. From walketim at gmail.com Thu Nov 6 16:30:26 2008 From: walketim at gmail.com (Tim Walker) Date: Thu, 6 Nov 2008 14:30:26 -0700 Subject: [rspec-users] cucumber docs Message-ID: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> Hi all, What is the best source for cucumber documentation. I did the rdoc thing but that was more of the API view. Is there any usage guides, etc. besides the examples and what you get when you download it or is the documentation hidden in there and I just didn't see it. Many thanks in advance! Tim From weyus at att.net Thu Nov 6 16:32:42 2008 From: weyus at att.net (Wes Gamble) Date: Thu, 06 Nov 2008 15:32:42 -0600 Subject: [rspec-users] Verifying some understanding about manipulating DB data in before/after callbacks in RSpec Message-ID: <4913627A.1000706@att.net> We had an after(:each) callback that looked like this: PurchaseOrder.find(:all).each {|po| DraftInvoice.find_all_by_po_number(po.po_number).each {|di| di.destroy}} which we were hoping would reset some purchase order data in a certain way. However, because we have "self.use_transactional_fixtures = true" set in test_helper.rb, this code was never getting committed. So, I just want to verify: Attempting to manipulate data directly in the DB in a before/after callback doesn't make sense since those changes will not persist across tests because of the transactionality implied by "self.use_transactional_fixtures = true". Is that correct? Thanks, Wes From pergesu at gmail.com Thu Nov 6 16:52:42 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 06 Nov 2008 13:52:42 -0800 Subject: [rspec-users] Specing based on user roles In-Reply-To: (Fernando Perez's message of "Thu\, 6 Nov 2008 22\:20\:29 +0100") References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> Message-ID: Fernando Perez writes: >> And why wouldn't you want to test that? >> > I want to test for it, it's just that I don't want to copy/paste spec > like an idiot. > > >> def for_roles *roles >> roles.each do |role| >> before(:each) { login_as role } >> yield >> end >> end >> >> describe OrdersController do >> describe "GET index" do >> for_roles :admin, :sysadmin do |role| >> it "..." do ... end >> end >> for_roles :sysadmin do |role| >> it "..." do ... end >> end >> end > >> This scheme makes it easy when we decide to remove a privilege from >> admin but keep it in sysadmin. Just move that example (it "...") to >> the other for_roles block. >> >> WDYT? > > I like your idea very much, very clean, readable and maintainable. > > And thank you Mark, I will also use your idea to factor out > commonalities in my specs. A lot of the time when I'm faced with this issue - there's a number of roles, each with a set of privileges - I find it easier to focus on the privileges rather than the roles themselves. This means creating domain-specific methods on the user object. #can_edit_orders?, #can_publish?, etc. Now when I'm specing at the controller level, I only have to deal with two cases - when the user has the privilege, and when he doesn't. Then we write examples for all of the different roles at the model level. No duplication, no fuss. One thing I've noticed is that when I'm writing controller specs and there seems to be too much duplication, I can usually eliminate it by pushing some logic down the stack. In fancier terms, it means I need to encapsulate a domain concept that I've missed up to that point. Pat From sfeley at gmail.com Thu Nov 6 17:03:10 2008 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 6 Nov 2008 17:03:10 -0500 Subject: [rspec-users] Verifying some understanding about manipulating DB data in before/after callbacks in RSpec In-Reply-To: <4913627A.1000706@att.net> References: <4913627A.1000706@att.net> Message-ID: <1fb4df0811061403w63af84a8hb97d574ec9630e15@mail.gmail.com> On Thu, Nov 6, 2008 at 4:32 PM, Wes Gamble wrote: > > Attempting to manipulate data directly in the DB in a before/after callback > doesn't make sense since those changes will not persist across tests because > of the transactionality implied by "self.use_transactional_fixtures = true". > Is that correct? That's correct. The philosophy of unit testing is that each test should be independent, without any reliance on the tests run before or after it. Each test with the same setup and teardown should begin with the database and environment in exactly the same state. This is important to RSpec because you can't guarantee the order in which tests or spec files might run. So if you're relying on state changes, they won't necessarily work the way you want them to. Anyway, what the heck are you writing where it's important that data be reset "in a certain way?" If that's crucial to your code, don't test it by relying on after(:each) -- just write an example where you destroy things in whatever order and then verify the results. I might also suggest, however, that you consider whether it's really a good idea to have it crucial to your code. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From ben at benmabey.com Thu Nov 6 17:05:36 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 06 Nov 2008 15:05:36 -0700 Subject: [rspec-users] cucumber docs In-Reply-To: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> References: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> Message-ID: <49136A30.7040501@benmabey.com> Tim Walker wrote: > Hi all, > > What is the best source for cucumber documentation. I did the rdoc > thing but that was more of the API view. Is there any usage guides, > etc. besides the examples and what you get when you download it or is > the documentation hidden in there and I just didn't see it. > > Many thanks in advance! > > Tim > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Have you seen the github wiki? http://github.com/aslakhellesoy/cucumber/wikis -Ben From mark at mwilden.com Thu Nov 6 17:13:19 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 6 Nov 2008 14:13:19 -0800 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) In-Reply-To: References: <4912DC8D.5090700@plan99.net> <70FC8B0A-A486-4623-B072-AF5C83DDEE36@mattwynne.net> <3c30da400811060807q7d0383dfqb0803b6dae42acc0@mail.gmail.com> Message-ID: <3c30da400811061413y3ceb9dfdr888a318ad5398c11@mail.gmail.com> On Thu, Nov 6, 2008 at 1:07 PM, Greg Hauptmann < greg.hauptmann.ruby at gmail.com> wrote: > I'm still a bit confused - I'll try to be more specific in questions: > > * rake db:test:prepare - Check for pending migrations and load the test > schema > ==> Q1. DOES NOT RUN IN PENDING MIGRATIONS TO TEST DATABASE? > Correct. It runs no migrations, period. It will abort if there are pending migrations for the development database. > ==> Q2. RE TEST SCHEMA - ARE THE MIGRATIONS USE TO CREATE THE > DATABASE OR THE DEVELOPMENT SCHEMA FILE??? > The development schema file, which db:test:prepare creates. > ==> Q3. WHY DOES IT HAVE TO BE CALLED MORE THAN ONCE? I didn't know it did have to be called more than once. :) > * rake db:test:load - Recreate the test database from the current schema.rb > ==> Q4. WHY DO WE NEED TO LOAD FROM THE SCHEMA RATHER THAN > MIGRATIONS? IS IT TO AVOID ANY DATA BEING LOADED BY MIGRATIONS FOR > THE TEST DATABASE? The main reason, I believe, is for speed. The thinking is that there's nothing in the test database that needs to be saved, whereas, you might have pseudo-real-world data in your development database that you don't want to repopulate. Therefore, the test db is created from scratch, but the development (and production) dbs are migrated. > ==> Q5. WHY IS IT RUN MULTIPLE TIMES? > Is that what you're seeing? I assume you're running 'rake db:test:prepare --trace'? * rake db:test:purge - Empty the test database > => Q6. WHY IS IT RUN MULTIPLE TIMES? > => Q7. DOES IT DROP TABLES ALSO? I haven't looked into those tasks, myself. Probably the very best way to answer these questions is to have a look at lib/tasks/databases.rake in your Rails framework directory. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at mwilden.com Thu Nov 6 17:19:01 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 6 Nov 2008 14:19:01 -0800 Subject: [rspec-users] Verifying some understanding about manipulating DB data in before/after callbacks in RSpec In-Reply-To: <4913627A.1000706@att.net> References: <4913627A.1000706@att.net> Message-ID: <3c30da400811061419k77a26c3fm4d2efe0c804a10a3@mail.gmail.com> On Thu, Nov 6, 2008 at 1:32 PM, Wes Gamble wrote: > We had an after(:each) callback that looked like this: > > PurchaseOrder.find(:all).each {|po| > DraftInvoice.find_all_by_po_number(po.po_number).each {|di| di.destroy}} > > which we were hoping would reset some purchase order data in a certain way. > If you're running 'rake spec' then your test database will be completely empty at the end, except for fixture data. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From weyus at att.net Thu Nov 6 17:21:31 2008 From: weyus at att.net (Wes Gamble) Date: Thu, 06 Nov 2008 16:21:31 -0600 Subject: [rspec-users] Verifying some understanding about manipulating DB data in before/after callbacks in RSpec In-Reply-To: <1fb4df0811061403w63af84a8hb97d574ec9630e15@mail.gmail.com> References: <4913627A.1000706@att.net> <1fb4df0811061403w63af84a8hb97d574ec9630e15@mail.gmail.com> Message-ID: <49136DEB.9000801@att.net> Stephen Eley wrote: > On Thu, Nov 6, 2008 at 4:32 PM, Wes Gamble wrote: > >> Attempting to manipulate data directly in the DB in a before/after callback >> doesn't make sense since those changes will not persist across tests because >> of the transactionality implied by "self.use_transactional_fixtures = true". >> Is that correct? >> >> Anyway, what the heck are you writing where it's important that data >> be reset "in a certain way?" Fair enough. No, I was just forgetting that the tests are supposed to be implicitly independent of each other. What happened here is that WATIR doesn't conform to this Test::Unit "rollback" contract, so we were committing changes in one test that were then breaking other tests later. Our attempt to remedy this mistake via a misbegotten after(:each) failed because of the transactional fixtures. We've since torn down that data via WATIR in the original test itself. Wes From josephwilk at joesniff.co.uk Thu Nov 6 17:22:33 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Thu, 6 Nov 2008 22:22:33 +0000 Subject: [rspec-users] cucumber docs In-Reply-To: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> References: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> Message-ID: I suggest you checkout the wiki that Cucumber has on Github . http://github.com/aslakhellesoy/cucumber/wikis Lots of useful information. HTH -- Joseph Wilk http://www.joesniff.co.uk On Thu, Nov 6, 2008 at 9:30 PM, Tim Walker wrote: > Hi all, > > What is the best source for cucumber documentation. I did the rdoc > thing but that was more of the API view. Is there any usage guides, > etc. besides the examples and what you get when you download it or is > the documentation hidden in there and I just didn't see it. > > Many thanks in advance! > > Tim > _______________________________________________ > 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 walketim at gmail.com Thu Nov 6 17:34:10 2008 From: walketim at gmail.com (Tim Walker) Date: Thu, 6 Nov 2008 15:34:10 -0700 Subject: [rspec-users] cucumber docs In-Reply-To: <49136A30.7040501@benmabey.com> References: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> <49136A30.7040501@benmabey.com> Message-ID: <1ebf5a4d0811061434q5ba498fetd280397df9566f06@mail.gmail.com> Yes, thank you very much. Not too much there. I had seen a blog post where Aslak mentioned he'd worked some on the documentation so thought I was missing the 1000 page tome "Cucumbers: Sometimes quality is long and green..." Thanks, Tim On Thu, Nov 6, 2008 at 3:05 PM, Ben Mabey wrote: > Tim Walker wrote: >> >> Hi all, >> >> What is the best source for cucumber documentation. I did the rdoc >> thing but that was more of the API view. Is there any usage guides, >> etc. besides the examples and what you get when you download it or is >> the documentation hidden in there and I just didn't see it. >> >> Many thanks in advance! >> >> Tim >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > Have you seen the github wiki? > > http://github.com/aslakhellesoy/cucumber/wikis > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From walketim at gmail.com Thu Nov 6 17:51:13 2008 From: walketim at gmail.com (Tim Walker) Date: Thu, 6 Nov 2008 15:51:13 -0700 Subject: [rspec-users] cucumber docs In-Reply-To: References: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> Message-ID: <1ebf5a4d0811061451k59f0da59w70768b499e771319@mail.gmail.com> Thanks guys, I may have overlooked some of the stuff there. A lot of what I was looking for was in the "Step Organization" page. Still not clear on some of the dynamic substitutions and syntax, etc. Thanks, Tim On Thu, Nov 6, 2008 at 3:22 PM, Joseph Wilk wrote: > I suggest you checkout the wiki that Cucumber has on Github . > > http://github.com/aslakhellesoy/cucumber/wikis > > Lots of useful information. > > HTH > -- > Joseph Wilk > http://www.joesniff.co.uk > > On Thu, Nov 6, 2008 at 9:30 PM, Tim Walker wrote: >> >> Hi all, >> >> What is the best source for cucumber documentation. I did the rdoc >> thing but that was more of the API view. Is there any usage guides, >> etc. besides the examples and what you get when you download it or is >> the documentation hidden in there and I just didn't see it. >> >> Many thanks in advance! >> >> Tim >> _______________________________________________ >> 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 aslak.hellesoy at gmail.com Thu Nov 6 18:38:07 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 7 Nov 2008 00:38:07 +0100 Subject: [rspec-users] cucumber docs In-Reply-To: <1ebf5a4d0811061451k59f0da59w70768b499e771319@mail.gmail.com> References: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> <1ebf5a4d0811061451k59f0da59w70768b499e771319@mail.gmail.com> Message-ID: <8d961d900811061538m3973bcd2tfd97cb939a268062@mail.gmail.com> On Thu, Nov 6, 2008 at 11:51 PM, Tim Walker wrote: > Thanks guys, I may have overlooked some of the stuff there. A lot of > what I was looking for was in the "Step Organization" page. > > Still not clear on some of the dynamic substitutions and syntax, etc. > I just jotted down some basics here: http://github.com/aslakhellesoy/cucumber/wikis/feature-introduction Please let us know of anything else that needs explaining. Cheers, Aslak > Thanks, > > Tim > > On Thu, Nov 6, 2008 at 3:22 PM, Joseph Wilk wrote: >> I suggest you checkout the wiki that Cucumber has on Github . >> >> http://github.com/aslakhellesoy/cucumber/wikis >> >> Lots of useful information. >> >> HTH >> -- >> Joseph Wilk >> http://www.joesniff.co.uk >> >> On Thu, Nov 6, 2008 at 9:30 PM, Tim Walker wrote: >>> >>> Hi all, >>> >>> What is the best source for cucumber documentation. I did the rdoc >>> thing but that was more of the API view. Is there any usage guides, >>> etc. besides the examples and what you get when you download it or is >>> the documentation hidden in there and I just didn't see it. >>> >>> Many thanks in advance! >>> >>> Tim >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Nov 6 19:25:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Nov 2008 19:25:05 -0500 Subject: [rspec-users] Specing based on user roles In-Reply-To: References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> Message-ID: <57c63afe0811061625q658b4e7cy35aa5a8702f0046@mail.gmail.com> On Thu, Nov 6, 2008 at 4:52 PM, Pat Maddox wrote: > Fernando Perez writes: > >>> And why wouldn't you want to test that? >>> >> I want to test for it, it's just that I don't want to copy/paste spec >> like an idiot. >> >> >>> def for_roles *roles >>> roles.each do |role| >>> before(:each) { login_as role } >>> yield >>> end >>> end >>> >>> describe OrdersController do >>> describe "GET index" do >>> for_roles :admin, :sysadmin do |role| >>> it "..." do ... end >>> end >>> for_roles :sysadmin do |role| >>> it "..." do ... end >>> end >>> end >> >>> This scheme makes it easy when we decide to remove a privilege from >>> admin but keep it in sysadmin. Just move that example (it "...") to >>> the other for_roles block. >>> >>> WDYT? >> >> I like your idea very much, very clean, readable and maintainable. >> >> And thank you Mark, I will also use your idea to factor out >> commonalities in my specs. > > A lot of the time when I'm faced with this issue - there's a number of > roles, each with a set of privileges - I find it easier to focus on the > privileges rather than the roles themselves. This means creating > domain-specific methods on the user object. #can_edit_orders?, > #can_publish?, etc. Now when I'm specing at the controller level, I > only have to deal with two cases - when the user has the privilege, and > when he doesn't. Then we write examples for all of the different roles > at the model level. No duplication, no fuss. > > One thing I've noticed is that when I'm writing controller specs and > there seems to be too much duplication, I can usually eliminate it by > pushing some logic down the stack. In fancier terms, it means I need to > encapsulate a domain concept that I've missed up to that point. +1 David > Pat From greg.hauptmann.ruby at gmail.com Thu Nov 6 19:35:32 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Fri, 7 Nov 2008 00:35:32 +0000 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) In-Reply-To: References: Message-ID: i run "rake spec --trace" On 11/6/08, Greg Hauptmann wrote: > anyone able to explain logic behind "rake spec" startup? i.e. the > below steps & why things occur when they do > > Macintosh-2:myequity greg$ rake spec --trace > (in /Users/greg/source/myequity) > ** Invoke spec (first_time) > ** Invoke db:test:prepare (first_time) > ** Invoke db:abort_if_pending_migrations (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute db:abort_if_pending_migrations > ** Execute db:test:prepare > ** Invoke db:test:load (first_time) > ** Invoke db:test:purge (first_time) > ** Invoke environment > ** Execute db:test:purge > ** Execute db:test:load > ** Invoke db:schema:load (first_time) > ** Invoke environment > ** Execute db:schema:load > ** Execute spec > > > thanks > -- Sent from my mobile device From walketim at gmail.com Thu Nov 6 20:02:07 2008 From: walketim at gmail.com (Tim Walker) Date: Thu, 6 Nov 2008 18:02:07 -0700 Subject: [rspec-users] cucumber docs In-Reply-To: <8d961d900811061538m3973bcd2tfd97cb939a268062@mail.gmail.com> References: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> <1ebf5a4d0811061451k59f0da59w70768b499e771319@mail.gmail.com> <8d961d900811061538m3973bcd2tfd97cb939a268062@mail.gmail.com> Message-ID: <1ebf5a4d0811061702p33dda16dq3f261639c923ac81@mail.gmail.com> Thank you very much Aslak. That looks great. FWIW I have taught a class "Executable Requirements with FitNesse" as the director of training and coaching at Valtech and on the faculty of agile university. I went back to a real job recently and am now employed on a new enterprise class RoR project as the requirements manager and QA dude rolled in to one. In my analysis and discussions with others it looks like we're putting a stake in the ground around Cucumber (having passed through the Rails Integration testing, RubyFIT and other approaches along the way). I'm sure we'll have lots of questions. It really is awesome stuff and am looking forward to this project with more excitement than I've felt in a long time (and I'm a fairly old dude, programming in assembler, fortran, c and even 360/40 JCL in my career). Seeing what you guys are doing is just over-the-top cool. BDD is great, Domain Driven Design is great. Stuff I wish I knew 20 years ago. Requirements are the tests that implement them, not a separate SRS, they are the same thing. Literally. We want to do away with defect tracking and just write tests that reproduce them and break the build, treated like any other story. Your work makes all this possible. Sincerely, Tim On Thu, Nov 6, 2008 at 4:38 PM, aslak hellesoy wrote: > On Thu, Nov 6, 2008 at 11:51 PM, Tim Walker wrote: >> Thanks guys, I may have overlooked some of the stuff there. A lot of >> what I was looking for was in the "Step Organization" page. >> >> Still not clear on some of the dynamic substitutions and syntax, etc. >> > > I just jotted down some basics here: > http://github.com/aslakhellesoy/cucumber/wikis/feature-introduction > > Please let us know of anything else that needs explaining. > > Cheers, > Aslak > >> Thanks, >> >> Tim >> >> On Thu, Nov 6, 2008 at 3:22 PM, Joseph Wilk wrote: >>> I suggest you checkout the wiki that Cucumber has on Github . >>> >>> http://github.com/aslakhellesoy/cucumber/wikis >>> >>> Lots of useful information. >>> >>> HTH >>> -- >>> Joseph Wilk >>> http://www.joesniff.co.uk >>> >>> On Thu, Nov 6, 2008 at 9:30 PM, Tim Walker wrote: >>>> >>>> Hi all, >>>> >>>> What is the best source for cucumber documentation. I did the rdoc >>>> thing but that was more of the API view. Is there any usage guides, >>>> etc. besides the examples and what you get when you download it or is >>>> the documentation hidden in there and I just didn't see it. >>>> >>>> Many thanks in advance! >>>> >>>> Tim >>>> _______________________________________________ >>>> 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 at mwilden.com Thu Nov 6 20:12:00 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 6 Nov 2008 17:12:00 -0800 Subject: [rspec-users] anyone able to explain logic behind "rake spec" startup (e.g. db:test:prepare => abort_if_pending_migration => invoke environment => etc etc) In-Reply-To: References: Message-ID: <3c30da400811061712i17e56aafsc9d5ea0e282b7b49@mail.gmail.com> > i run "rake spec --trace" That's not running anything twice, I think. "Invoke" is printed when the task is called, then the tasks it depends on are invoked, then the task is executed. The environment task is invoked several times, but it's only actually executed once. /// On Thu, Nov 6, 2008 at 4:35 PM, Greg Hauptmann < greg.hauptmann.ruby at gmail.com> wrote: > > On 11/6/08, Greg Hauptmann wrote: > > anyone able to explain logic behind "rake spec" startup? i.e. the > > below steps & why things occur when they do > > > > Macintosh-2:myequity greg$ rake spec --trace > > (in /Users/greg/source/myequity) > > ** Invoke spec (first_time) > > ** Invoke db:test:prepare (first_time) > > ** Invoke db:abort_if_pending_migrations (first_time) > > ** Invoke environment (first_time) > > ** Execute environment > > ** Execute db:abort_if_pending_migrations > > ** Execute db:test:prepare > > ** Invoke db:test:load (first_time) > > ** Invoke db:test:purge (first_time) > > ** Invoke environment > > ** Execute db:test:purge > > ** Execute db:test:load > > ** Invoke db:schema:load (first_time) > > ** Invoke environment > > ** Execute db:schema:load > > ** Execute spec > > > > > > thanks > > > > -- > Sent from my mobile device > _______________________________________________ > 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 ramon.tayag at gmail.com Thu Nov 6 21:53:29 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Fri, 7 Nov 2008 10:53:29 +0800 Subject: [rspec-users] Hash / params causing errors Message-ID: Hey everyone, I'm trying to spec a controller and I can't seem to get a test to pass because rspec seems to see the difference between params I expect and params that I pass. However, this comes from the same params variable. What should I do to get this to work? Spec::Mocks::MockExpectationError in 'UsersController handling POST /users should create a new user from params' Mock 'Class' expected :new with ({:email=>"user at email.com"}) but received it with ({"email"=>"user at email.com"}) Code is here: http://pastie.org/309263 Thanks! Ramon Tayag From dchelimsky at gmail.com Thu Nov 6 22:03:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Nov 2008 22:03:41 -0500 Subject: [rspec-users] Hash / params causing errors In-Reply-To: References: Message-ID: <57c63afe0811061903u30aa443le605e207861683ea@mail.gmail.com> On Thu, Nov 6, 2008 at 9:53 PM, Ramon Tayag wrote: > Hey everyone, > > I'm trying to spec a controller and I can't seem to get a test to pass > because rspec seems to see the difference between params I expect and > params that I pass. However, this comes from the same params > variable. What should I do to get this to work? > > Spec::Mocks::MockExpectationError in 'UsersController handling POST > /users should create a new user from params' > Mock 'Class' expected :new with ({:email=>"user at email.com"}) but > received it with ({"email"=>"user at email.com"}) expected {:email=>"user at email.com"} got {"email"=>"user at email.com"} Rails is converting what's really passed (with a Symbol key) to a String key. It'll work if you expect the String instead. > > Code is here: http://pastie.org/309263 > > Thanks! > Ramon Tayag > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ramon.tayag at gmail.com Thu Nov 6 22:28:29 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Fri, 7 Nov 2008 11:28:29 +0800 Subject: [rspec-users] Hash / params causing errors In-Reply-To: <57c63afe0811061903u30aa443le605e207861683ea@mail.gmail.com> References: <57c63afe0811061903u30aa443le605e207861683ea@mail.gmail.com> Message-ID: Thanks for you reply. With what you said I ended up doing this before do @user = mock_model(User, :to_param => "1", :login => "loginator", :email => "user at email.com", :save! => true) User.stub!(:new).and_return(@user) @params = { :login => "loginator", :email => "user at email.com" } end ... it "should create a new user from params" do User.should_receive(:new).with({"login" => "loginator", "email" => "user at email.com"}).and_return(@user) do_post end On Fri, Nov 7, 2008 at 11:03 AM, David Chelimsky wrote: > On Thu, Nov 6, 2008 at 9:53 PM, Ramon Tayag wrote: >> Hey everyone, >> >> I'm trying to spec a controller and I can't seem to get a test to pass >> because rspec seems to see the difference between params I expect and >> params that I pass. However, this comes from the same params >> variable. What should I do to get this to work? >> >> Spec::Mocks::MockExpectationError in 'UsersController handling POST >> /users should create a new user from params' >> Mock 'Class' expected :new with ({:email=>"user at email.com"}) but >> received it with ({"email"=>"user at email.com"}) > > expected {:email=>"user at email.com"} > got {"email"=>"user at email.com"} > > Rails is converting what's really passed (with a Symbol key) to a > String key. It'll work if you expect the String instead. > >> >> Code is here: http://pastie.org/309263 >> >> Thanks! >> Ramon Tayag From ramon.tayag at gmail.com Thu Nov 6 22:30:42 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Fri, 7 Nov 2008 11:30:42 +0800 Subject: [rspec-users] Hash / params causing errors In-Reply-To: References: <57c63afe0811061903u30aa443le605e207861683ea@mail.gmail.com> Message-ID: A bit dryer: ... @params = { "login" => "loginator", "email" => "user at email.com" } ... User.should_receive(:new).with(@params).and_return(@user) ... Ramon Tayag From raasdnil at gmail.com Fri Nov 7 00:03:45 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 7 Nov 2008 16:03:45 +1100 Subject: [rspec-users] rake features and cucumber feature/name not producing same result In-Reply-To: <4912E2F5.5030909@joesniff.co.uk> References: <57a815bf0811041958y9175882k60b55e40c083adb9@mail.gmail.com> <07AC043B-DA59-44C7-BC86-E597C381C314@mattwynne.net> <57a815bf0811050740r38ba8492s1f2068238935d8cb@mail.gmail.com> <4911C173.8080608@joesniff.co.uk> <57a815bf0811051452vdb31636i5a7130fc59b2e1b7@mail.gmail.com> <4912E2F5.5030909@joesniff.co.uk> Message-ID: <57a815bf0811062103u63b2e136ia03de2d969cf2387@mail.gmail.com> On Thu, Nov 6, 2008 at 11:28 PM, Joseph Wilk wrote: > If you are using cucumber with rails and used the rails generator you > should find in your generated features/steps/env.rb file (In the latest > cucumber version 0.1.9 this is in features/support/env.rb): > Yes, I was already using the transactional fixtures. This wasn't the problem. The final problem was actually two code bugs. One on a trigger in the database and the other was a namespace confliict in my code. Those two combined basically had me totally confused :) Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: From apremdas at gmail.com Fri Nov 7 01:09:21 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 7 Nov 2008 06:09:21 +0000 Subject: [rspec-users] features and form filling - going declarative? Message-ID: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> I'm working on writing features for a wizard. The wizard collects information from a number of different forms, and you can navigate through it in a number of ways. Anyhow one of these forms is a customer form collecting name, and email. In the context of the wizard I feel that the following scenarios Scenario: Given I step to customer And I fill in my customer details correctly Scenario: Given I step to customer And I fill in my customer details incorrectly Then I should see an error are preferable to Scenario: Given I step to customer And I fill in email with fred at example.com And I fill in name "Fred Bloggs" Given I step to customer And I fill in email with '' And I fill in name "Fred Bloggs" Then I should see an error # add table for different combinations of form fields that cause errors # consider checking that errors are appropriate note: Given I step to customer is nested step doing all sorts to get to the form What do you think? I'm looking for some input on this, and in particular am wondering where should I put the more specific tests for form validation, error messages etc. in my test hierarchy, or even if I should test them at all (could you argue they're in built rails functionality). All best Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.hauptmann.ruby at gmail.com Fri Nov 7 03:13:04 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Fri, 7 Nov 2008 18:13:04 +1000 Subject: [rspec-users] rspec gem vs "rspec plugin" vs "rspec-rails plugin" ??? Message-ID: Hi, I've got the rspec gem installed, as well as the two plugins "rspec" & "rspec-rails". I can't remember which is actual used and which isn't for my rails app when I go "rake spec"? Anyone know? Could I remove either of the core rpec gem OR the "rspec plugin"? or do I need all three components? Tks From aslak.hellesoy at gmail.com Fri Nov 7 03:53:15 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 7 Nov 2008 09:53:15 +0100 Subject: [rspec-users] cucumber docs In-Reply-To: <1ebf5a4d0811061702p33dda16dq3f261639c923ac81@mail.gmail.com> References: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> <1ebf5a4d0811061451k59f0da59w70768b499e771319@mail.gmail.com> <8d961d900811061538m3973bcd2tfd97cb939a268062@mail.gmail.com> <1ebf5a4d0811061702p33dda16dq3f261639c923ac81@mail.gmail.com> Message-ID: <8d961d900811070053k3120a2c3i1857036eca32da75@mail.gmail.com> On Fri, Nov 7, 2008 at 2:02 AM, Tim Walker wrote: > Thank you very much Aslak. That looks great. FWIW I have taught a > class "Executable Requirements with FitNesse" as the director of > training and coaching at Valtech and on the faculty of agile > university. I went back to a real job recently and am now employed on > a new enterprise class RoR project as the requirements manager and QA > dude rolled in to one. In my analysis and discussions with others it > looks like we're putting a stake in the ground around Cucumber (having > passed through the Rails Integration testing, RubyFIT and other > approaches along the way). I'm sure we'll have lots of questions. It Thanks for sharing that Tim. I take that as a confirmation that we're doing something right here :-) > really is awesome stuff and am looking forward to this project with > more excitement than I've felt in a long time (and I'm a fairly old > dude, programming in assembler, fortran, c and even 360/40 JCL in my > career). Seeing what you guys are doing is just over-the-top cool. BDD > is great, Domain Driven Design is great. Stuff I wish I knew 20 years Isn't it great to be in a field where you can feel there is some progress and learning? 80% of what you find in BDD, RSpec and Cucumber comes from elsewhere. Here is a list that I have often used when I present BDD so people can go and dig fro more. TDD/JUnit - Kent Beck FIT - Ward Cunningham Example Driven Development - Brian Marick User Stories - Connextra team (Nolan, MacKinnon et al) BDD daddys - Chris "business value" Matts and Dan "tastapod" North ATDD/ATDP - Richard Watt and David Leigh-Fellows (I might be wrong on origin) DDD/Ubiq Language - Eric Evans The RSpec list - the catalyst of bringing all of this into a consistent whole > ago. Requirements are the tests that implement them, not a separate > SRS, they are the same thing. Literally. We want to do away with > defect tracking and just write tests that reproduce them and break the > build, treated like any other story. Your work makes all this > possible. > Can I quote you on this? I need it for my campaign. Aslak > Sincerely, > > Tim > > On Thu, Nov 6, 2008 at 4:38 PM, aslak hellesoy wrote: >> On Thu, Nov 6, 2008 at 11:51 PM, Tim Walker wrote: >>> Thanks guys, I may have overlooked some of the stuff there. A lot of >>> what I was looking for was in the "Step Organization" page. >>> >>> Still not clear on some of the dynamic substitutions and syntax, etc. >>> >> >> I just jotted down some basics here: >> http://github.com/aslakhellesoy/cucumber/wikis/feature-introduction >> >> Please let us know of anything else that needs explaining. >> >> Cheers, >> Aslak >> >>> Thanks, >>> >>> Tim >>> >>> On Thu, Nov 6, 2008 at 3:22 PM, Joseph Wilk wrote: >>>> I suggest you checkout the wiki that Cucumber has on Github . >>>> >>>> http://github.com/aslakhellesoy/cucumber/wikis >>>> >>>> Lots of useful information. >>>> >>>> HTH >>>> -- >>>> Joseph Wilk >>>> http://www.joesniff.co.uk >>>> >>>> On Thu, Nov 6, 2008 at 9:30 PM, Tim Walker wrote: >>>>> >>>>> Hi all, >>>>> >>>>> What is the best source for cucumber documentation. I did the rdoc >>>>> thing but that was more of the API view. Is there any usage guides, >>>>> etc. besides the examples and what you get when you download it or is >>>>> the documentation hidden in there and I just didn't see it. >>>>> >>>>> Many thanks in advance! >>>>> >>>>> Tim >>>>> _______________________________________________ >>>>> 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 lists at ruby-forum.com Fri Nov 7 05:10:08 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Fri, 7 Nov 2008 11:10:08 +0100 Subject: [rspec-users] rspec gem vs "rspec plugin" vs "rspec-rails plugin" ??? In-Reply-To: References: Message-ID: Greg Hauptmann wrote: > Hi, > > I've got the rspec gem installed, as well as the two plugins "rspec" & > "rspec-rails". I can't remember which is actual used and which isn't > for my rails app when I go "rake spec"? Anyone know? > > Could I remove either of the core rpec gem OR the "rspec plugin"? or > do I need all three components? > > Tks The plugins are no longer required, you can only use the rspec and rspec-rails gems. For a rails app you will simply have to run "script/generate rspec" to generate a few files, and then you are all set. -- Posted via http://www.ruby-forum.com/. From greg.hauptmann.ruby at gmail.com Fri Nov 7 05:23:41 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Fri, 7 Nov 2008 20:23:41 +1000 Subject: [rspec-users] rspec gem vs "rspec plugin" vs "rspec-rails plugin" ??? In-Reply-To: References: Message-ID: so just to be clear are you saying: * rspec gem => All that is need for Ruby on Rails Rspec work * 'rspec plugin' => not needed (functionality in gem) * 'rspec-rails' plugin => not needed (functionality in gem) is this right? thanks again On Fri, Nov 7, 2008 at 8:10 PM, Fernando Perez wrote: > Greg Hauptmann wrote: >> Hi, >> >> I've got the rspec gem installed, as well as the two plugins "rspec" & >> "rspec-rails". I can't remember which is actual used and which isn't >> for my rails app when I go "rake spec"? Anyone know? >> >> Could I remove either of the core rpec gem OR the "rspec plugin"? or >> do I need all three components? >> >> Tks > > The plugins are no longer required, you can only use the rspec and > rspec-rails gems. For a rails app you will simply have to run > "script/generate rspec" to generate a few files, and then you are all > set. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From josephwilk at joesniff.co.uk Fri Nov 7 05:47:43 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Fri, 07 Nov 2008 10:47:43 +0000 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> Message-ID: <49141CCF.1030409@joesniff.co.uk> Andrew Premdas wrote: > I'm working on writing features for a wizard. The wizard collects > information from a number of different forms, and you can navigate > through it in a number of ways. Anyhow one of these forms is a > customer form collecting name, and email. > > In the context of the wizard I feel that the following scenarios > > Scenario: > Given I step to customer > And I fill in my customer details correctly > > Scenario: > Given I step to customer > And I fill in my customer details incorrectly > Then I should see an error > > are preferable to > > Scenario: > Given I step to customer > And I fill in email with fred at example.com > And I fill in name "Fred Bloggs" > > Given I step to customer > And I fill in email with '' > And I fill in name "Fred Bloggs" > Then I should see an error > > # add table for different combinations of form fields that cause > errors > # consider checking that errors are appropriate > > > note: Given I step to customer is nested step doing all sorts to get > to the form > > What do you think? > I'm not sure if you where just giving examples but its always a good idea to give your scenarios titles. Scenario titles generally describe what is different between the other scenarios. Also your Given 'And' steps feel a little like thens (Its generally a good idea to avoid talking about user interaction in givens [1] unless they happened earlier): >And I fill in email with fred at example.com So to ensure that it is clear 'filling in the email' happened in the past I would write it as: And I have filled in email with 'email'. I've tried both combinations as your mentioned. I think one of your questions is what is better: declarative steps - 'And I fill in my customer details incorrectly' imperative steps - 'And I fill in email with fred at example.com,' ' And I fill in name "Fred Bloggs"' Ben Mabley has written a great article on imperative vs declarative steps [2] which is a great read. I don't think there is a 'best way', It really depends on your customer. What is really important to them (be it that you might be mocking the role of the customer) and how would they express it. Is this a form which is payment/login and is fundamental to the business. If so the customer may want to express the scenarios in detail. If its a hugely complex form which would leave your with a massive number of steps at a low level it might (each customer is different) be hard to read and provide a lot of noise over the true value. > # add table for different combinations of form fields that cause errors > # consider checking that errors are appropriate Mentioning actual values in scenarios means you can take advantage of scenario tables. They allow your to test edge conditions without having lots of scenarios which is great! Something I've been trying out is dropping in and out of different levels of abstraction in your scenario. For example: @@@ Scenario: Bad passwords Given I filled in the form with the essential valid details And the password was entered as 'blah' When ... Then I should see 'error' | password | error | | womble | No wombles allowed as password | | password | Terrible password | @@@ I've found so far that customers really like this. It is a nice way it pull out the really interesting part to the customer and leave the other details (that are often noise) at a higher level. And it also means you can use Scenario tables to exercise edge conditions. WDYT? > I'm looking for some input on this, and in particular am wondering > where should I put the more specific tests for form validation, error > messages etc. in my test hierarchy, or even if I should test them at > all (could you argue they're in built rails functionality). > When it comes down to JavaScript form validation I have started to test these using screwunit [3]. As for controller based validation and errors I use specs. Error messages can play such a fundamental part in a site that I'm always keen on having some spec tests at the controller level for them. While these test can be a little brittle, I've seen too many error messages get changed or mangled. I also test forms and error ouput in Features. But more than 'test a form' I'm really testing a user value holds and it just so happens that this value is achieved through some form process. Its also important to remember that features cross cut through the whole application stack when testing unlike my spec tests. Sorry thats a bit of a brain dump, I hope it provides you with some helpful info. :(|) Joseph Wilk -- http://www.joesniff.co.uk [1] http://github.com/aslakhellesoy/cucumber/wikis/step-organisation [2] http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/ [3] http://github.com/grockit/screw-unit-server/tree/master From aslak.hellesoy at gmail.com Fri Nov 7 06:56:59 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 7 Nov 2008 12:56:59 +0100 Subject: [rspec-users] rspec gem vs "rspec plugin" vs "rspec-rails plugin" ??? In-Reply-To: References: Message-ID: <8d961d900811070356x24225bf4xf1c3141cf67c9bd5@mail.gmail.com> On Fri, Nov 7, 2008 at 11:23 AM, Greg Hauptmann wrote: > so just to be clear are you saying: > > * rspec gem => All that is need for Ruby on Rails Rspec work > * 'rspec plugin' => not needed (functionality in gem) > * 'rspec-rails' plugin => not needed (functionality in gem) > > is this right? > Not quite rspec gem or plugin => basic rspec without rails support (runner, rake task, api for describe/it, should etc) rspec-rails gem or plugin => extra support for rails model view and controller, database integration, code generation (script/generate) It doesn't matter whether you use the gem or the plugin. Just pick one that suits your team. (If you use the plugin you don't have to worry about people having different versions installed, but it's alittle more work to install) Aslak > thanks again > > On Fri, Nov 7, 2008 at 8:10 PM, Fernando Perez wrote: >> Greg Hauptmann wrote: >>> Hi, >>> >>> I've got the rspec gem installed, as well as the two plugins "rspec" & >>> "rspec-rails". I can't remember which is actual used and which isn't >>> for my rails app when I go "rake spec"? Anyone know? >>> >>> Could I remove either of the core rpec gem OR the "rspec plugin"? or >>> do I need all three components? >>> >>> Tks >> >> The plugins are no longer required, you can only use the rspec and >> rspec-rails gems. For a rails app you will simply have to run >> "script/generate rspec" to generate a few files, and then you are all >> set. >> -- >> 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 aslak.hellesoy at gmail.com Fri Nov 7 06:57:56 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 7 Nov 2008 12:57:56 +0100 Subject: [rspec-users] rspec gem vs "rspec plugin" vs "rspec-rails plugin" ??? In-Reply-To: <8d961d900811070356x24225bf4xf1c3141cf67c9bd5@mail.gmail.com> References: <8d961d900811070356x24225bf4xf1c3141cf67c9bd5@mail.gmail.com> Message-ID: <8d961d900811070357n682666caj4078dd5c6b58fe54@mail.gmail.com> On Fri, Nov 7, 2008 at 12:56 PM, aslak hellesoy wrote: > On Fri, Nov 7, 2008 at 11:23 AM, Greg Hauptmann > wrote: >> so just to be clear are you saying: >> >> * rspec gem => All that is need for Ruby on Rails Rspec work >> * 'rspec plugin' => not needed (functionality in gem) >> * 'rspec-rails' plugin => not needed (functionality in gem) >> >> is this right? >> > > Not quite > > rspec gem or plugin => basic rspec without rails support (runner, rake > task, api for describe/it, should etc) > rspec-rails gem or plugin => extra support for rails model view and > controller, database integration, code generation (script/generate) > forgot to clarify - for rails development you'll need both rspec and rspec-rails. > It doesn't matter whether you use the gem or the plugin. Just pick one > that suits your team. > (If you use the plugin you don't have to worry about people having > different versions installed, but it's alittle more work to install) > > Aslak > >> thanks again >> >> On Fri, Nov 7, 2008 at 8:10 PM, Fernando Perez wrote: >>> Greg Hauptmann wrote: >>>> Hi, >>>> >>>> I've got the rspec gem installed, as well as the two plugins "rspec" & >>>> "rspec-rails". I can't remember which is actual used and which isn't >>>> for my rails app when I go "rake spec"? Anyone know? >>>> >>>> Could I remove either of the core rpec gem OR the "rspec plugin"? or >>>> do I need all three components? >>>> >>>> Tks >>> >>> The plugins are no longer required, you can only use the rspec and >>> rspec-rails gems. For a rails app you will simply have to run >>> "script/generate rspec" to generate a few files, and then you are all >>> set. >>> -- >>> 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 Fri Nov 7 07:16:17 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Fri, 7 Nov 2008 13:16:17 +0100 Subject: [rspec-users] rspec gem vs "rspec plugin" vs "rspec-rails plugin" ??? In-Reply-To: <8d961d900811070357n682666caj4078dd5c6b58fe54@mail.gmail.com> References: <8d961d900811070356x24225bf4xf1c3141cf67c9bd5@mail.gmail.com> <8d961d900811070357n682666caj4078dd5c6b58fe54@mail.gmail.com> Message-ID: <90d70ab0d5dc1e7352933bf6a203f454@ruby-forum.com> > forgot to clarify - for rails development you'll need both rspec and > rspec-rails. What I meant is that you can go plugin-less, you just have to install the two following gems: rspec and rspec-rails, then bootstrap your app by generating a few files. And your set. I personally prefer using gems than plugins. -- Posted via http://www.ruby-forum.com/. From shot at hot.pl Fri Nov 7 08:05:51 2008 From: shot at hot.pl (Shot (Piotr Szotkowski)) Date: Fri, 7 Nov 2008 14:05:51 +0100 Subject: [rspec-users] =?utf-8?q?How_to_spec_a_=28Trollop-based=29_binary?= =?utf-8?q?=E2=80=99s_internal_state=3F?= Message-ID: <20081107130551.GC22622@durance.shot.pl> I?m trying to spec a ?binary?, and as previously discussed on this list, I?m trying to do it ?from outside? ? i.e., by calling it with Kernel#` and observing the (side-)effects. Unfortunately, this doesn?t really let me spec expectations about its internals. Let?s assume I have a -d flag and I parse it with Trollop to set Conf.debug: opts = Trollop::options do opt :debug, 'Print debug info', :default => false end Conf.debug = opts[:debug] To have a spec that actually expects this, I?d write something like this: it 'should set the debug option properly' do `binary -d` Conf.should_receive(:debug=).with true end This obviously doesn?t work, as the Kernel#` call is executed in a context that is not visible from the current Ruby interpreter. I assume that eval()-ing the binary (much like Rick Bradley does? for specing flog) would be the way to go, but then I don?t know how to pass the -d flag to Trollop. ? http://rubyhoedown2008.confreaks.com/11-rick-bradley-flog-test-new.html What would be the best practice in this case? Prepare ARGV for Trollop so that it believes we are calling the binary with the -d flag and then eval the binary, or run the binary with Kernel#`, pass it something that should generate debug output and then check whether the output was generated (rather than check whether the binary set Conf.debug)? -- Shot -- I've found that nurturing one's Zen nature is vital to dealing with technology. Violence is pretty damn useful too. -- Lionel Lauer, asr -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: not available URL: From aidy.lewis at googlemail.com Fri Nov 7 09:24:38 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Fri, 7 Nov 2008 14:24:38 +0000 Subject: [rspec-users] [Cucumber] The User Story File Message-ID: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> Hi, The customer is not happy about writing Stories in a text editor. Has anyone else experienced this? Is anyone using a wiki, spreadsheet, or word document and automatically converting to a text file? Thanks Aidy From matt at mattwynne.net Fri Nov 7 09:26:32 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 7 Nov 2008 14:26:32 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> Message-ID: <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> Are you pairing with them? Can you not just drive and do the typing, asking them questions all the while to keep them engaged? I think David is cooking something up (have a look at his blog) but it might be a while coming. If you can find a Mac, the TextMate text editor has nice syntax highlighting (thanks to Ben Mabey) that make it look a bit prettier. On 7 Nov 2008, at 14:24, aidy lewis wrote: > Hi, > > The customer is not happy about writing Stories in a text editor. > > Has anyone else experienced this? Is anyone using a wiki, spreadsheet, > or word document and automatically converting to a text file? > > Thanks > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From josephwilk at joesniff.co.uk Fri Nov 7 09:36:38 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Fri, 07 Nov 2008 14:36:38 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> Message-ID: <49145276.3060103@joesniff.co.uk> As Matt said there is no specalised tool for editing Features (Though textmate is great with Bens bundle). If you checkout Cucumbers Milestone 0.2 you will notice ' Provide a REST/AtomPub interface to Cucumber'. The idea of having some sort of wiki interface is something thats in the works for Cucumber, no quantifiable deadlines yet though I'm afraid. -- Joseph Wilk http://www.joesniff.co.uk Matt Wynne wrote: > Are you pairing with them? Can you not just drive and do the typing, > asking them questions all the while to keep them engaged? > > I think David is cooking something up (have a look at his blog) but it > might be a while coming. > > If you can find a Mac, the TextMate text editor has nice syntax > highlighting (thanks to Ben Mabey) that make it look a bit prettier. > > On 7 Nov 2008, at 14:24, aidy lewis wrote: > >> Hi, >> >> The customer is not happy about writing Stories in a text editor. >> >> Has anyone else experienced this? Is anyone using a wiki, spreadsheet, >> or word document and automatically converting to a text 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 Fri Nov 7 09:42:22 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Fri, 7 Nov 2008 14:42:22 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> Message-ID: <7ac2300c0811070642w79a25209p3150a676db08afa7@mail.gmail.com> Hi Matt, How are you? On 07/11/2008, Matt Wynne wrote: > Are you pairing with them? Can you not just drive and do the typing, asking > them questions all the while to keep them engaged? Cucumber is now the standard here, with all projects using it. The guys who were using Watin have now moved to Watir. In most conditions, I will pair with the customer. In other projects the BA has been writing the acceptance criteria. I saw an example today in Excel; using the Given, When, Then format. > I think David is cooking something up (have a look at his blog) but it > might be a while coming. Thanks for heads up. > > If you can find a Mac, the TextMate text editor has nice syntax > highlighting (thanks to Ben Mabey) that make it look a bit prettier. As you know Matt a majority of users here are using Windows, but I could ask for a Mac. I would be grateful if you could send me a screenshot. Thanks Aidy From matt at mattwynne.net Fri Nov 7 09:54:53 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 7 Nov 2008 14:54:53 +0000 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> Message-ID: <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> On 7 Nov 2008, at 06:09, Andrew Premdas wrote: > I'm working on writing features for a wizard. The wizard collects > information from a number of different forms, and you can navigate > through it in a number of ways. Anyhow one of these forms is a > customer form collecting name, and email. > > In the context of the wizard I feel that the following scenarios > > Scenario: > Given I step to customer > And I fill in my customer details correctly > > Scenario: > Given I step to customer > And I fill in my customer details incorrectly > Then I should see an error > > are preferable to > > Scenario: > Given I step to customer > And I fill in email with fred at example.com > And I fill in name "Fred Bloggs" > > Given I step to customer > And I fill in email with '' > And I fill in name "Fred Bloggs" > Then I should see an error > > # add table for different combinations of form fields that cause > errors > # consider checking that errors are appropriate > > > note: Given I step to customer is nested step doing all sorts to > get to the form > > What do you think? Good questions! You're getting into some pretty subtle stuff here, and it's hard to even articulate what I think about it as it's changing all the time as I get more experience working with cucumber. I guess as Joseph has said, you want to balance out keeping the noise down in the feature without hiding away important information about the desired behaviour. One technique is to have a single noisy 'declarative' scenario that explicitly walks around filling things in, then all the rest use more 'imperative' style steps where most of the detail is buried away. I think, and I know that this sounds wishy-washy, you need to try out both and see how they feel to you. In the example you gave, I where the specification seems be be about valid email addresses, I would probably make my step something like this: Given I step to the customer stage of the wizard When I fill in a valid name And I fill out an email address "blah" Then I should see an error Thereby hiding the irrelevant "Fred Bloggs", but surfacing the important "blah" > I'm looking for some input on this, and in particular am wondering > where should I put the more specific tests for form validation, > error messages etc. in my test hierarchy, or even if I should test > them at all (could you argue they're in built rails functionality). Hmm.... Again, this is getting from science to art. I think you need the features to tell you whether the whole things hangs together (e.g. can the form display a validation message at all?), but when you start to iterate more tightly with specific examples of a valid / invalid object, I that's where I would drop into unit tests and write code examples against the model object (or whatever you use for validation). Having said that, I'm putting more and more specification into cucumber features - the more steps you write, the more you build up a re-usable language for describing your system, the easier it gets. Make any sense? Does that help at all? cheers Matt http://blog.mattwynne.net From dchelimsky at gmail.com Fri Nov 7 09:58:28 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Nov 2008 09:58:28 -0500 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> Message-ID: <57c63afe0811070658j773ca7a7t447d34d0ee13ad8d@mail.gmail.com> On Fri, Nov 7, 2008 at 9:54 AM, Matt Wynne wrote: > One technique is to have a single noisy 'declarative' scenario that > explicitly walks around filling things in, then all the rest use more > 'imperative' style steps where most of the detail is buried away. You've got those backwards :) declarative: when I fill in the form correctly imperative: when I enter "David" in the "Name" field .... Cheers, David From dchelimsky at gmail.com Fri Nov 7 10:02:12 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Nov 2008 10:02:12 -0500 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <57c63afe0811070658j773ca7a7t447d34d0ee13ad8d@mail.gmail.com> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> <57c63afe0811070658j773ca7a7t447d34d0ee13ad8d@mail.gmail.com> Message-ID: <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> On Fri, Nov 7, 2008 at 9:58 AM, David Chelimsky wrote: > On Fri, Nov 7, 2008 at 9:54 AM, Matt Wynne wrote: >> One technique is to have a single noisy 'declarative' scenario that >> explicitly walks around filling things in, then all the rest use more >> 'imperative' style steps where most of the detail is buried away. > > You've got those backwards :) > > declarative: when I fill in the form correctly > imperative: when I enter "David" in the "Name" field .... Although - maybe we need to reconsider this naming, because you could argue that either are declarative, whereas imperative, meaning important/urgent, doesn't really convey the explicit nature. I think abstract/concrete could work. Maybe general/specific. Other ideas? > > Cheers, > David > From dchelimsky at gmail.com Fri Nov 7 10:03:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Nov 2008 10:03:41 -0500 Subject: [rspec-users] The RSpec Book Message-ID: <57c63afe0811070703w7a8320eoa5c259d7d8263c4b@mail.gmail.com> Hey all, I'm pleased to announce that the Pragmatic Bookshelf's The RSpec Book is almost here. The plan is: * beta/pdf in December, 2008 * print in April, 2009 The RSpec Book, authored by me, Dave Astels, Zach Dennis, Aslak Helles?y, Bryan Helmkamp, and Dan North, will comprise material on RSpec, Cucumber, Webrat and other tools, plus material on BDD, TDD, ATDP, mocks, BDD in Rails, extending RSpec, and more. You can read more about it at http://www.pragprog.com/titles/achbd/the-rspec-book. Cheers, David From luislavena at gmail.com Fri Nov 7 10:23:24 2008 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 7 Nov 2008 12:23:24 -0300 Subject: [rspec-users] [rspec-devel] The RSpec Book In-Reply-To: <57c63afe0811070703w7a8320eoa5c259d7d8263c4b@mail.gmail.com> References: <57c63afe0811070703w7a8320eoa5c259d7d8263c4b@mail.gmail.com> Message-ID: <71166b3b0811070723i77d77742pd0f25591767025fa@mail.gmail.com> On Fri, Nov 7, 2008 at 12:03 PM, David Chelimsky wrote: > Hey all, > > I'm pleased to announce that the Pragmatic Bookshelf's The RSpec Book > is almost here. The plan is: > > * beta/pdf in December, 2008 > * print in April, 2009 > > The RSpec Book, authored by me, Dave Astels, Zach Dennis, Aslak > Helles?y, Bryan Helmkamp, and Dan North, will comprise material on > RSpec, Cucumber, Webrat and other tools, plus material on BDD, TDD, > ATDP, mocks, BDD in Rails, extending RSpec, and more. > > You can read more about it at > http://www.pragprog.com/titles/achbd/the-rspec-book. > Yay! great news David! There is no pre-order button!?!? -- 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 Fri Nov 7 10:34:22 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 7 Nov 2008 15:34:22 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <7ac2300c0811070642w79a25209p3150a676db08afa7@mail.gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> <7ac2300c0811070642w79a25209p3150a676db08afa7@mail.gmail.com> Message-ID: On 7 Nov 2008, at 14:42, aidy lewis wrote: > On 07/11/2008, Matt Wynne wrote: >> Are you pairing with them? Can you not just drive and do the >> typing, asking >> them questions all the while to keep them engaged? > > Cucumber is now the standard here, with all projects using it. The > guys who were using Watin have now moved to Watir. Awesome! Looks like we snuck Ruby in! You should give Aslak a quote for the website - having the BBC on there will definitely give Cucumber some more gravitas. > In most conditions, I will pair with the customer. In other projects > the BA has been writing the acceptance criteria. > > I saw an example today in Excel; using the Given, When, Then format. It would be pretty trivial to write something to copy excel to plain text, but why bother? What's wrong with notepad? >> I think David is cooking something up (have a look at his blog) but >> it >> might be a while coming. > > Thanks for heads up. >> >> If you can find a Mac, the TextMate text editor has nice syntax >> highlighting (thanks to Ben Mabey) that make it look a bit prettier. > > As you know Matt a majority of users here are using Windows, but I > could ask for a Mac. I would be grateful if you could send me a > screenshot. Will do off-list, and we can catch up. Are you coming to XP day? From josephwilk at joesniff.co.uk Fri Nov 7 10:35:07 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Fri, 07 Nov 2008 15:35:07 +0000 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> <57c63afe0811070658j773ca7a7t447d34d0ee13ad8d@mail.gmail.com> <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> Message-ID: <4914602B.2040102@joesniff.co.uk> David Chelimsky wrote: > On Fri, Nov 7, 2008 at 9:58 AM, David Chelimsky wrote: > >> On Fri, Nov 7, 2008 at 9:54 AM, Matt Wynne wrote: >> >>> One technique is to have a single noisy 'declarative' scenario that >>> explicitly walks around filling things in, then all the rest use more >>> 'imperative' style steps where most of the detail is buried away. >>> >> You've got those backwards :) >> >> declarative: when I fill in the form correctly >> imperative: when I enter "David" in the "Name" field .... >> > > Although - maybe we need to reconsider this naming, because you could > argue that either are declarative, whereas imperative, meaning > important/urgent, doesn't really convey the explicit nature. I think > abstract/concrete could work. Maybe general/specific. > > Other ideas? > > >> Cheers, >> David >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > I like abstract/concrete My other suggestions: * Explicit / Implicit * High level / Low level * Coarse / fine -- Joseph Wilk http://www.joesniff.co.uk From matt at mattwynne.net Fri Nov 7 10:37:28 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 7 Nov 2008 15:37:28 +0000 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> <57c63afe0811070658j773ca7a7t447d34d0ee13ad8d@mail.gmail.com> <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> Message-ID: <771517BD-578B-4103-A11D-925C4DDF9A12@mattwynne.net> On 7 Nov 2008, at 15:02, David Chelimsky wrote: > On Fri, Nov 7, 2008 at 9:58 AM, David Chelimsky > wrote: >> On Fri, Nov 7, 2008 at 9:54 AM, Matt Wynne >> wrote: >>> One technique is to have a single noisy 'declarative' scenario that >>> explicitly walks around filling things in, then all the rest use >>> more >>> 'imperative' style steps where most of the detail is buried away. >> >> You've got those backwards :) Doh! What a chump. Sorry for the confusion. >> declarative: when I fill in the form correctly >> imperative: when I enter "David" in the "Name" field .... > > Although - maybe we need to reconsider this naming, because you could > argue that either are declarative, whereas imperative, meaning > important/urgent, doesn't really convey the explicit nature. I think > abstract/concrete could work. Maybe general/specific. > > Other ideas? To be honest, I find both words so boring I don't really read them, and hence make those sort of mistakes. But that's my own stupidity at fault, not the words'. I am lacking inspiration to find any better ones, though. It's more about whether the step is paramaterized, right? Is there a term in the cucumber code for differentiating the two? cheers, Matt From ben at benmabey.com Fri Nov 7 10:38:10 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 07 Nov 2008 08:38:10 -0700 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> Message-ID: <491460E2.6060103@benmabey.com> Matt Wynne wrote: > Are you pairing with them? Can you not just drive and do the typing, > asking them questions all the while to keep them engaged? > > I think David is cooking something up (have a look at his blog) but it > might be a while coming. > > If you can find a Mac, the TextMate text editor has nice syntax > highlighting (thanks to Ben Mabey) that make it look a bit prettier. You can now also get syntax highlighting in vim: http://github.com/bmabey/vim-cucumber/tree/master I would really like to see a non-technical stakeholder try to use vim. :) -Ben > > On 7 Nov 2008, at 14:24, aidy lewis wrote: > >> Hi, >> >> The customer is not happy about writing Stories in a text editor. >> >> Has anyone else experienced this? Is anyone using a wiki, spreadsheet, >> or word document and automatically converting to a text 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 aslak.hellesoy at gmail.com Fri Nov 7 10:38:03 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Fri, 7 Nov 2008 16:38:03 +0100 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> Message-ID: <0E2B0D48-52D8-4D4D-93EB-FBFC65C05D14@gmail.com> > Hi, > > The customer is not happy about writing Stories in a text editor. > > Has anyone else experienced this? Is anyone using a wiki, spreadsheet, > or word document and automatically converting to a text file? > There will be custom editors/wikis with aides like code completion, nice visuals, running etc. Kinda like FitNesse, but nicer. The plan is to make a RESTful API for Cucumber. I'm thinking a Sinatra web app that uses the Cucumber CLI and exposes it with AtomPub or a similar JSON api. The server would be part of the Cucumber gem, and can be started up with a single command on any machine. From there I hope to see people developing richer clients like standalone web apps, wikis, wiki plugins, Flex/Air apps, editor and IDE plugins, hell, word and excel plugins in VB.NET even! My experience tells me you can't get the customer/business to be comfy in a simple text editor. I have accepted that as a fact it's not worth working around in most cases. Kudos to those who can, I know some teams succeed. I have talked to a student who's working on the REST part as part of his thesis. Please work with him if he shows up here on the list. In order to successfuly make a usable REST API/server I will focus the next weeks and months on improving Cucumber internals. Part of that is an AST that will make manipulation of features, scenarios, tables and steps easier, as well as a better data structure for output and errors. I have started this work and I'm trying out different ideas. I expect to make some visible progress before the end of the year. Then I expect all the Cucumber forkers to take it and run. Thanks for all the great contributions so far folks! Aslak > Thanks > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From apremdas at gmail.com Fri Nov 7 10:41:57 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 7 Nov 2008 15:41:57 +0000 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <49141CCF.1030409@joesniff.co.uk> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <49141CCF.1030409@joesniff.co.uk> Message-ID: <88fd8ddc0811070741h163c913dmbfd371cd45304677@mail.gmail.com> Joseph, Thanks for your reply, much appreciated. The scenarios don't have titles just for this discussion. Felt including them would be a distraction. I agree that some of the Givens should be Whens in these examples e.g. Given I step to customer When I fill in my customer details incorrectly Then I should see an error I've read the Ben Mabey article many times its great. Thats where I got the declarative and imperative terms from. I'm not doing any javascript testing yet, I'l put screwunit on my toread list. The depends on the customer answer is an interesting one. In this case I am the customer (and the developer) and I'm not sure :). I quite like and have used scenario tables a number of times. In this case though I feel that they would pollute the feature. Its as if I want two levels of features, high level ones to test the overall wizard behaviour, and low level ones to test each screen. The tables would be highly appropriate in the lower level tests. I do wonder though if edge cases really belong in features. I think of them as more of a developer than customer concept. However the tables make it really nice to write plain text low level (dare I say unit) features, which have the benefit of clearly documenting intention in a way that any other test mechanism I've seen so far cannot. The brain dump is much appreciated and helps Cheers Andrew 2008/11/7 Joseph Wilk > Andrew Premdas wrote: > >> I'm working on writing features for a wizard. The wizard collects >> information from a number of different forms, and you can navigate through >> it in a number of ways. Anyhow one of these forms is a customer form >> collecting name, and email. >> >> In the context of the wizard I feel that the following scenarios >> >> Scenario: Given I step to customer >> And I fill in my customer details correctly >> >> Scenario: Given I step to customer >> And I fill in my customer details incorrectly >> Then I should see an error >> >> are preferable to >> >> Scenario: Given I step to customer >> And I fill in email with fred at example.com >> And I fill in name "Fred Bloggs" >> >> Given I step to customer >> And I fill in email with '' >> And I fill in name "Fred Bloggs" >> Then I should see an error >> >> # add table for different combinations of form fields that cause errors >> # consider checking that errors are appropriate >> >> >> note: Given I step to customer is nested step doing all sorts to get to >> the form >> >> What do you think? >> >> I'm not sure if you where just giving examples but its always a good idea > to give your scenarios titles. Scenario titles generally describe what is > different between the other scenarios. > > Also your Given 'And' steps feel a little like thens (Its generally a good > idea to avoid talking about user interaction in givens [1] unless they > happened earlier): > > >And I fill in email with fred at example.com > > So to ensure that it is clear 'filling in the email' happened in the past > I would write it as: > > And I have filled in email with 'email'. > > > I've tried both combinations as your mentioned. I think one of your > questions is what is better: > > declarative steps - 'And I fill in my customer details incorrectly' > > imperative steps - 'And I fill in email with fred at example.com,' ' > And I fill in name "Fred Bloggs"' > > Ben Mabley has written a great article on imperative vs declarative steps > [2] which is a great read. > > I don't think there is a 'best way', It really depends on your customer. > What is really important to them (be it that you might be mocking the role > of the customer) and how would they express it. Is this a form which is > payment/login and is fundamental to the business. If so the customer may > want to express the scenarios in detail. > > If its a hugely complex form which would leave your with a massive number > of steps at a low level it might (each customer is different) be hard to > read and provide a lot of noise over the true value. > > > > # add table for different combinations of form fields that cause > errors > > # consider checking that errors are appropriate > > Mentioning actual values in scenarios means you can take advantage of > scenario tables. They allow your to test edge conditions without having lots > of scenarios which is great! > > Something I've been trying out is dropping in and out of different levels > of abstraction in your scenario. For example: > > @@@ > Scenario: Bad passwords > Given I filled in the form with the essential valid details > And the password was entered as 'blah' > When ... > Then I should see 'error' > > | password | error | > | womble | No wombles allowed as password | > | password | Terrible password | > @@@ > > I've found so far that customers really like this. It is a nice way it pull > out the really interesting part to the customer and leave the other details > (that are often noise) at a higher level. And it also means you can use > Scenario tables to exercise edge conditions. > > WDYT? > >> I'm looking for some input on this, and in particular am wondering where >> should I put the more specific tests for form validation, error messages >> etc. in my test hierarchy, or even if I should test them at all (could you >> argue they're in built rails functionality). >> >> > When it comes down to JavaScript form validation I have started to test > these using screwunit [3]. As for controller based validation and errors I > use specs. Error messages can play such a fundamental part in a site that > I'm always keen on having some spec tests at the controller level for them. > While these test can be a little brittle, I've seen too many error messages > get changed or mangled. > > I also test forms and error ouput in Features. But more than 'test a form' > I'm really testing a user value holds and it just so happens that this value > is achieved through some form process. Its also important to remember that > features cross cut through the whole application stack when testing unlike > my spec tests. > > > Sorry thats a bit of a brain dump, I hope it provides you with some helpful > info. > > :(|) > Joseph Wilk > -- > http://www.joesniff.co.uk > > [1] http://github.com/aslakhellesoy/cucumber/wikis/step-organisation > [2] > http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/ > [3] http://github.com/grockit/screw-unit-server/tree/master > > > _______________________________________________ > 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 Nov 7 10:42:21 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 07 Nov 2008 07:42:21 -0800 Subject: [rspec-users] =?utf-8?q?How_to_spec_a_=28Trollop-based=29_binary?= =?utf-8?q?=E2=80=99s_internal_state=3F?= In-Reply-To: <20081107130551.GC22622@durance.shot.pl> (shot@hot.pl's message of "Fri\, 7 Nov 2008 14\:05\:51 +0100") References: <20081107130551.GC22622@durance.shot.pl> Message-ID: "Shot (Piotr Szotkowski)" writes: > I?m trying to spec a ?binary?, and as previously discussed on this list, > I?m trying to do it ?from outside? ? i.e., by calling it with Kernel#` > and observing the (side-)effects. > > Unfortunately, this doesn?t really let me spec expectations about its > internals. Let?s assume I have a -d flag and I parse it with Trollop to > set Conf.debug: > > opts = Trollop::options do > opt :debug, 'Print debug info', :default => false > end > Conf.debug = opts[:debug] > > To have a spec that actually expects > this, I?d write something like this: > > it 'should set the debug option properly' do > `binary -d` > Conf.should_receive(:debug=).with true > end > > This obviously doesn?t work, as the Kernel#` call is executed in > a context that is not visible from the current Ruby interpreter. > I assume that eval()-ing the binary (much like Rick Bradley does? > for specing flog) would be the way to go, but then I don?t know how > to pass the -d flag to Trollop. > > ? http://rubyhoedown2008.confreaks.com/11-rick-bradley-flog-test-new.html > > What would be the best practice in this case? Prepare ARGV for Trollop > so that it believes we are calling the binary with the -d flag and then > eval the binary, or run the binary with Kernel#`, pass it something > that should generate debug output and then check whether the output > was generated (rather than check whether the binary set Conf.debug)? > > -- Shot When you use backticks to execute the binary, it runs in a separate process, so you can't use mock expectations like that. I think you're kind of missing the intention though...what I think you want to do is write features with cucumber that use the built binary from the outside. But when you write code-level examples, you are not going to run the binary. You're just writing examples at a lower level, directly for the objects. Make sense? Pat From apremdas at gmail.com Fri Nov 7 10:44:58 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 7 Nov 2008 15:44:58 +0000 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> <57c63afe0811070658j773ca7a7t447d34d0ee13ad8d@mail.gmail.com> <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> Message-ID: <88fd8ddc0811070744y1a387b6fh250eb736fe2a32c0@mail.gmail.com> +1 for abstract and concrete as it gives an indication of what the story should contain i.e. I should get an error vs I should be told my email must have an @ sign and be ... Andrew 2008/11/7 David Chelimsky : > On Fri, Nov 7, 2008 at 9:58 AM, David Chelimsky wrote: >> On Fri, Nov 7, 2008 at 9:54 AM, Matt Wynne wrote: >>> One technique is to have a single noisy 'declarative' scenario that >>> explicitly walks around filling things in, then all the rest use more >>> 'imperative' style steps where most of the detail is buried away. >> >> You've got those backwards :) >> >> declarative: when I fill in the form correctly >> imperative: when I enter "David" in the "Name" field .... > > Although - maybe we need to reconsider this naming, because you could > argue that either are declarative, whereas imperative, meaning > important/urgent, doesn't really convey the explicit nature. I think > abstract/concrete could work. Maybe general/specific. > > Other ideas? > >> >> Cheers, >> David >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From apremdas at gmail.com Fri Nov 7 10:42:10 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 7 Nov 2008 15:42:10 +0000 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> Message-ID: <88fd8ddc0811070742t341106ddnaf4e3706295f98c5@mail.gmail.com> Matt, Thanks for reply much appreciated and very helpful I'm definitely feeling a need/desire to write features at different levels as you say, and in this case I am trying both, though I haven't quite worked out a nice way of organising things as yet. I definitely want to seperate my 'noisy' from 'quite'. In the example I gave the noisy version would have things about blank names as well as invalid emails. I'd probably use a scenario table, and might even include checks for the content of error messages. I just put a small part in the example to give a flavour. I do think this is a bit of an art discussion. Its a credit to cucumber that we can have such discussions as I think it has cracked most of the science part, which for such a young tool is really impressive. I think that the art of organisation is a key element in expressing intention clearly. If something is in the right place is much easier to find out what it is trying to do. Maybe there is a need for a feature hierarchy in the same way there is a test heirarchy ... All best Andrew 2008/11/7 Matt Wynne : > On 7 Nov 2008, at 06:09, Andrew Premdas wrote: >> >> I'm working on writing features for a wizard. The wizard collects >> information from a number of different forms, and you can navigate through >> it in a number of ways. Anyhow one of these forms is a customer form >> collecting name, and email. >> >> In the context of the wizard I feel that the following scenarios >> >> Scenario: >> Given I step to customer >> And I fill in my customer details correctly >> >> Scenario: >> Given I step to customer >> And I fill in my customer details incorrectly >> Then I should see an error >> >> are preferable to >> >> Scenario: >> Given I step to customer >> And I fill in email with fred at example.com >> And I fill in name "Fred Bloggs" >> >> Given I step to customer >> And I fill in email with '' >> And I fill in name "Fred Bloggs" >> Then I should see an error >> >> # add table for different combinations of form fields that cause errors >> # consider checking that errors are appropriate >> >> >> note: Given I step to customer is nested step doing all sorts to get to >> the form >> >> What do you think? > > Good questions! You're getting into some pretty subtle stuff here, and it's > hard to even articulate what I think about it as it's changing all the time > as I get more experience working with cucumber. > > I guess as Joseph has said, you want to balance out keeping the noise down > in the feature without hiding away important information about the desired > behaviour. > > One technique is to have a single noisy 'declarative' scenario that > explicitly walks around filling things in, then all the rest use more > 'imperative' style steps where most of the detail is buried away. I think, > and I know that this sounds wishy-washy, you need to try out both and see > how they feel to you. > > In the example you gave, I where the specification seems be be about valid > email addresses, I would probably make my step something like this: > > Given I step to the customer stage of the wizard > When I fill in a valid name > And I fill out an email address "blah" > Then I should see an error > > Thereby hiding the irrelevant "Fred Bloggs", but surfacing the important > "blah" > >> I'm looking for some input on this, and in particular am wondering where >> should I put the more specific tests for form validation, error messages >> etc. in my test hierarchy, or even if I should test them at all (could you >> argue they're in built rails functionality). > > Hmm.... > > Again, this is getting from science to art. I think you need the features to > tell you whether the whole things hangs together (e.g. can the form display > a validation message at all?), but when you start to iterate more tightly > with specific examples of a valid / invalid object, I that's where I would > drop into unit tests and write code examples against the model object (or > whatever you use for validation). > > Having said that, I'm putting more and more specification into cucumber > features - the more steps you write, the more you build up a re-usable > language for describing your system, the easier it gets. > > Make any sense? Does that help at all? > > cheers > Matt > > http://blog.mattwynne.net > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From apremdas at gmail.com Fri Nov 7 10:50:29 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 7 Nov 2008 15:50:29 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <7ac2300c0811070642w79a25209p3150a676db08afa7@mail.gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> <7ac2300c0811070642w79a25209p3150a676db08afa7@mail.gmail.com> Message-ID: <88fd8ddc0811070750s4fa975a7gaddf1d5c3fdf4feb@mail.gmail.com> You could try the bundle in the E editor on windows http://www.e-texteditor.com/ 2008/11/7 aidy lewis : > Hi Matt, > > How are you? > > On 07/11/2008, Matt Wynne wrote: >> Are you pairing with them? Can you not just drive and do the typing, asking >> them questions all the while to keep them engaged? > > Cucumber is now the standard here, with all projects using it. The > guys who were using Watin have now moved to Watir. > > In most conditions, I will pair with the customer. In other projects > the BA has been writing the acceptance criteria. > > I saw an example today in Excel; using the Given, When, Then format. > > >> I think David is cooking something up (have a look at his blog) but it >> might be a while coming. > > Thanks for heads up. >> >> If you can find a Mac, the TextMate text editor has nice syntax >> highlighting (thanks to Ben Mabey) that make it look a bit prettier. > > As you know Matt a majority of users here are using Windows, but I > could ask for a Mac. I would be grateful if you could send me a > screenshot. > > Thanks > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From josephwilk at joesniff.co.uk Fri Nov 7 10:52:34 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Fri, 07 Nov 2008 15:52:34 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <491460E2.6060103@benmabey.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <39DAC049-ABC0-4F38-929E-EA59C3EA3810@mattwynne.net> <491460E2.6060103@benmabey.com> Message-ID: <49146442.6010706@joesniff.co.uk> Ben Mabey wrote: > Matt Wynne wrote: >> Are you pairing with them? Can you not just drive and do the typing, >> asking them questions all the while to keep them engaged? >> >> I think David is cooking something up (have a look at his blog) but >> it might be a while coming. >> >> If you can find a Mac, the TextMate text editor has nice syntax >> highlighting (thanks to Ben Mabey) that make it look a bit prettier. > > You can now also get syntax highlighting in vim: > http://github.com/bmabey/vim-cucumber/tree/master > > > I would really like to see a non-technical stakeholder try to use vim. :) > > -Ben I know its terribly 20th century but you could use a pen and paper :) I've started doing this a lot more now we have a 21st century pen (http://www.amazon.com/Logitech-io2-Digital-Writing-System/dp/B00064FXH0). -- Joseph Wilk http://www.joesniff.co.uk From pergesu at gmail.com Fri Nov 7 11:04:07 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 07 Nov 2008 08:04:07 -0800 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> (Andrew Premdas's message of "Fri\, 7 Nov 2008 06\:09\:21 +0000") References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> Message-ID: "Andrew Premdas" writes: > I'm working on writing features for a wizard. The wizard collects information from a number of different forms, and you can navigate through > it in a number of ways. Anyhow one of these forms is a customer form collecting name, and email. > > In the context of the wizard I feel that the following scenarios > > Scenario: > Given I step to customer > And I fill in my customer details correctly > > Scenario: > Given I step to customer > And I fill in my customer details incorrectly > Then I should see an error > > are preferable to > > Scenario: > Given I step to customer > And I fill in email with fred at example.com > And I fill in name "Fred Bloggs" > > Given I step to customer > And I fill in email with '' > And I fill in name "Fred Bloggs" > Then I should see an error > > # add table for different combinations of form fields that cause errors > # consider checking that errors are appropriate > > note: Given I step to customer is nested step doing all sorts to get to the form > > What do you think? > > I'm looking for some input on this, and in particular am wondering where should I put the more specific tests for form validation, error > messages etc. in my test hierarchy, or even if I should test them at all (could you argue they're in built rails functionality). I typically go with the first style, because I'm lazy and don't want to write out a bunch of steps and their associated definitions. Also, I think that "fill in my customer details incorrectly" expresses the intent better. But really that's what the scenario title is for I guess. So mostly it's just that I'm lazy, cause declarative steps are less work up front and are more resilient to change. Pat From matt at mattwynne.net Fri Nov 7 11:45:40 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 7 Nov 2008 16:45:40 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <0E2B0D48-52D8-4D4D-93EB-FBFC65C05D14@gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <0E2B0D48-52D8-4D4D-93EB-FBFC65C05D14@gmail.com> Message-ID: <9931FC33-B8C8-404C-A219-3C9F25E9BFF4@mattwynne.net> On 7 Nov 2008, at 15:38, Aslak Helles?y wrote: >> Hi, >> >> The customer is not happy about writing Stories in a text editor. >> >> Has anyone else experienced this? Is anyone using a wiki, >> spreadsheet, >> or word document and automatically converting to a text file? >> > > There will be custom editors/wikis with aides like code completion, > nice visuals, running etc. Kinda like FitNesse, but nicer. > > The plan is to make a RESTful API for Cucumber. I'm thinking a > Sinatra web app that uses the Cucumber CLI and exposes it with > AtomPub or a similar JSON api. The server would be part of the > Cucumber gem, and can be started up with a single command on any > machine. > > From there I hope to see people developing richer clients like > standalone web apps, wikis, wiki plugins, Flex/Air apps, editor and > IDE plugins, hell, word and excel plugins in VB.NET even! > > My experience tells me you can't get the customer/business to be > comfy in a simple text editor. I have accepted that as a fact it's > not worth working around in most cases. Kudos to those who can, I > know some teams succeed. > > I have talked to a student who's working on the REST part as part of > his thesis. Please work with him if he shows up here on the list. > > In order to successfuly make a usable REST API/server I will focus > the next weeks and months on improving Cucumber internals. Part of > that is an AST that will make manipulation of features, scenarios, > tables and steps easier, as well as a better data structure for > output and errors. > > I have started this work and I'm trying out different ideas. I > expect to make some visible progress before the end of the year. > > Then I expect all the Cucumber forkers to take it and run. Thanks > for all the great contributions so far folks! Very nice indeed. If you can come up with some kind of mock suite for the API interface, that might help us get going with something. It would be really cool to have a web editor for features that doubles as a textbook RSpec / Cucumber reference app to answer the FAQ Fernando asked a few days ago ('is there a good example of a rails app using RSpec'). I'd love to collaborate on such a project. cheers, Matt http://blog.mattwynne.net From ben at benmabey.com Fri Nov 7 12:00:00 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 07 Nov 2008 10:00:00 -0700 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> <57c63afe0811070658j773ca7a7t447d34d0ee13ad8d@mail.gmail.com> <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> Message-ID: <49147410.1040607@benmabey.com> David Chelimsky wrote: > On Fri, Nov 7, 2008 at 9:58 AM, David Chelimsky wrote: > >> On Fri, Nov 7, 2008 at 9:54 AM, Matt Wynne wrote: >> >>> One technique is to have a single noisy 'declarative' scenario that >>> explicitly walks around filling things in, then all the rest use more >>> 'imperative' style steps where most of the detail is buried away. >>> >> You've got those backwards :) >> >> declarative: when I fill in the form correctly >> imperative: when I enter "David" in the "Name" field .... >> > > Although - maybe we need to reconsider this naming, because you could > argue that either are declarative, whereas imperative, meaning > important/urgent, doesn't really convey the explicit nature. I think > abstract/concrete could work. Maybe general/specific. > > Other ideas? > > To me the words imperative and declarative make sense in the programming language context... and we are just applying it to roles instead of computers. For example, this is the explanation given in my programming languages book[1]: ...declarative languages, in which the focus is on *what* the computer is to do, and the imperative languages, in which the focus is on *how* the computer should do it. Now swap out languages with scenarios and computer with user role: ...declarative scenarios, in which the focus is on *what* the role is to do, and the imperative scenarios, in which the focus is on *how* the role should do it. So, I don't see the word imperative meaning urgent, I see it meaning explicit. While declarative means the scenario is at a higher level and not concerned with exactly how the scenario is implemented (much like use cases.) That said these terms are programming terms so probably aren't the best if they are to be customer facing. I like general/specific. -Ben [1] Programming Language Pragmatics by Michael L. Scott From shot at hot.pl Fri Nov 7 12:24:21 2008 From: shot at hot.pl (Shot (Piotr Szotkowski)) Date: Fri, 7 Nov 2008 18:24:21 +0100 Subject: [rspec-users] =?utf-8?q?How_to_spec_a_=28Trollop-based=29_binary?= =?utf-8?q?=E2=80=99s_internal_state=3F?= In-Reply-To: References: <20081107130551.GC22622@durance.shot.pl> Message-ID: <20081107172421.GI22622@durance.shot.pl> Pat Maddox: > "Shot (Piotr Szotkowski)" writes: >> it 'should set the debug option properly' do >> `binary -d` >> Conf.should_receive(:debug=).with true >> end > When you use backticks to execute the binary, it runs in > a separate process, so you can't use mock expectations like that. Right, that?s why I suggested I could Kernel#eval the binary?s contents in the current process instead. This would require tricking Trollop, but I assume I could trick it by hand-crafting ARGV. > I think you're kind of missing the intention though... Yeah, I thought so ? that?s why I?m asking. :) The previous question ended up with the conclusion that RSpecing a ?binary? through Kernel#` is a sane way to go: ? http://groups.google.com/group/rspec/browse_thread/thread/66dc48522014c5eb > what I think you want to do is write features with > cucumber that use the built binary from the outside. Ah, Cucumber. :) I?ve yet to write my first story; I somehow assumed these are more oriented toward non-programmers and/or for driving implementation on a rather higher level, and have to be ?implemented? on the RSpec level somehow anyway. I take that these assumptions are flawed. :) > But when you write code-level examples, you are not going to run the > binary. You're just writing examples at a lower level, directly for > the objects. Make sense? Hm, I guess I simply need to read up on Cucumber and stories; I still can?t see how this kind of specification would differ (in the end) from Kernel#`-based RSpec ? i.e., why implementing the code behind these stories would side-step the underlying issue. (But the last time I read on stories was pre-Cucumber.) Is there an example of story/Cucumber-based specification of a binary?s behaviour available somewhere out there? -- Shot -- init.d is complete in the sense that brainfuck is Turing-complete. -- SanityInAnarchy, /. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: not available URL: From zach.dennis at gmail.com Fri Nov 7 13:07:54 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 7 Nov 2008 13:07:54 -0500 Subject: [rspec-users] deprecate integrate_views, WDYT? Message-ID: <85d99afe0811071007i50fb137bmcae69ffd93e70044@mail.gmail.com> I posted a ticket to lighthouse: http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/595-deprecate-integrate_views Please put your comments and thoughts there, as that is the best place for that discussion. I wanted to make it more "visible" so it could get wide community participation in case there are folks who absolutely feel integrate_views is necessary (considering that we now have Cucumber). -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From ngocdaothanh at gmail.com Fri Nov 7 15:09:49 2008 From: ngocdaothanh at gmail.com (Ngoc Dao) Date: Sat, 8 Nov 2008 05:09:49 +0900 Subject: [rspec-users] [rspec-devel] The RSpec Book In-Reply-To: <71166b3b0811070723i77d77742pd0f25591767025fa@mail.gmail.com> References: <57c63afe0811070703w7a8320eoa5c259d7d8263c4b@mail.gmail.com> <71166b3b0811070723i77d77742pd0f25591767025fa@mail.gmail.com> Message-ID: <5c493e530811071209n367514c1u6a84466281f7e438@mail.gmail.com> Great news (again :D). Ngoc. On Sat, Nov 8, 2008 at 12:23 AM, Luis Lavena wrote: > On Fri, Nov 7, 2008 at 12:03 PM, David Chelimsky > wrote: > > Hey all, > > > > I'm pleased to announce that the Pragmatic Bookshelf's The RSpec Book > > is almost here. The plan is: > > > > * beta/pdf in December, 2008 > > * print in April, 2009 > > > > The RSpec Book, authored by me, Dave Astels, Zach Dennis, Aslak > > Helles?y, Bryan Helmkamp, and Dan North, will comprise material on > > RSpec, Cucumber, Webrat and other tools, plus material on BDD, TDD, > > ATDP, mocks, BDD in Rails, extending RSpec, and more. > > > > You can read more about it at > > http://www.pragprog.com/titles/achbd/the-rspec-book. > > > > Yay! great news David! > > There is no pre-order button!?!? > -- > 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 lists-rspec at shopwatch.org Fri Nov 7 14:44:45 2008 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Fri, 07 Nov 2008 14:44:45 -0500 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <49141CCF.1030409@joesniff.co.uk> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <49141CCF.1030409@joesniff.co.uk> Message-ID: <49149AAD.2020803@shopwatch.org> Joseph Wilk wrote: > Ben Mabley has written a great article on imperative vs declarative > steps [2] which is a great read. +1! That article was a real eye-opener to me. But I keep realizing that, if you keep following the temptation to super-abstract your specs - from scenarios into matchers, and in other places - you end up reinventing Ruby. Or AppleScript. Or sendmail.cf. It's like the XML-heavy "configuration files" in Java that Rails tries so hard to get away from; at some point, your code becomes a generic execution environment for your config file, which is now really the code, which you then refactor into meta-config files... If you get too declarative, I think you make it impossible for end users to write stories; they can write them, sure, but they'll all require new step matchers, which will require actual coding. I don't think it's actually a solvable problem - something, somewhere has to know how to fill in the form. Either you do it in the scenario, where it gets repeated a lot, or you refactor it into the matcher, which requires enough programming ability to understand refactoring, abstraction, and function calls in the first place. Jay Levitt > [2] > http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/ From rsl at swimcommunity.org Fri Nov 7 16:35:51 2008 From: rsl at swimcommunity.org (Russell Norris) Date: Fri, 7 Nov 2008 16:35:51 -0500 Subject: [rspec-users] Confusion At Failing Specs Message-ID: <1d2f8d6f0811071335n3212b72ek93e20d9be64bbdba@mail.gmail.com> Can someone please explain to me why this spec fails it "should work" do template.stub!(:render) template.should_receive(:render).with(:partial => "foo") render @template_with_render_partial_foo end but this spec passes it "should work" do @foo.stub!(:bar) @foo.should_receive(:bar).with(:baz) @foo.bar :baz end It seems like they should work similarly and indeed this has worked for me until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure what I'm doing wrong here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sconds at gmail.com Fri Nov 7 16:48:16 2008 From: sconds at gmail.com (RSL) Date: Fri, 7 Nov 2008 16:48:16 -0500 Subject: [rspec-users] Confusion At Failing Specs Message-ID: <1d2f8d6f0811071348j7084299doe2a20836c54aabb1@mail.gmail.com> Can someone please explain to me why this spec fails it "should work" do template.stub!(:render) template.should_receive(:render).with(:partial => "foo") render @template_with_render_partial_foo end but this spec passes it "should work" do @foo.stub!(:bar) @foo.should_receive(:bar).with(:baz) @foo.bar :baz end It seems like they should work similarly and indeed this has worked for me until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure what I'm doing wrong here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Fri Nov 7 16:59:02 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 7 Nov 2008 16:59:02 -0500 Subject: [rspec-users] Confusion At Failing Specs In-Reply-To: <1d2f8d6f0811071335n3212b72ek93e20d9be64bbdba@mail.gmail.com> References: <1d2f8d6f0811071335n3212b72ek93e20d9be64bbdba@mail.gmail.com> Message-ID: <85d99afe0811071359m4c979430j797c6a2dcb79436f@mail.gmail.com> On Fri, Nov 7, 2008 at 4:35 PM, Russell Norris wrote: > Can someone please explain to me why this spec fails > > it "should work" do > > template.stub!(:render) > > template.should_receive(:render).with(:partial => "foo") > > render @template_with_render_partial_foo > > end > > but this spec passes > > it "should work" do > > @foo.stub!(:bar) > > @foo.should_receive(:bar).with(:baz) > > @foo.bar :baz > > end > > It seems like they should work similarly and indeed this has worked for me > until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure > what I'm doing wrong here. > In the first example, you call "stub!(:render)". This is stubbing all calls to render with any arguments. So you've stubbed the call that "render @template_with_render_partial_foo" makes. Try: template.stub!(:render).with(:partial => anything) -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From dchelimsky at gmail.com Fri Nov 7 17:06:58 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Nov 2008 17:06:58 -0500 Subject: [rspec-users] Confusion At Failing Specs In-Reply-To: <1d2f8d6f0811071335n3212b72ek93e20d9be64bbdba@mail.gmail.com> References: <1d2f8d6f0811071335n3212b72ek93e20d9be64bbdba@mail.gmail.com> Message-ID: <57c63afe0811071406h2ca8431frf9c1b38b4b027e9a@mail.gmail.com> On Fri, Nov 7, 2008 at 4:35 PM, Russell Norris wrote: > Can someone please explain to me why this spec fails > > it "should work" do > > template.stub!(:render) > > template.should_receive(:render).with(:partial => "foo") > > render @template_with_render_partial_foo Can you put the rest of the spec and the view in? What failure message are you getting? > > end > > but this spec passes > > it "should work" do > > @foo.stub!(:bar) > > @foo.should_receive(:bar).with(:baz) > > @foo.bar :baz > > end > > It seems like they should work similarly and indeed this has worked for me > until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure > what I'm doing wrong here. From rsl at swimcommunity.org Fri Nov 7 17:17:55 2008 From: rsl at swimcommunity.org (Russell Norris) Date: Fri, 7 Nov 2008 17:17:55 -0500 Subject: [rspec-users] Confusion At Failing Specs In-Reply-To: <85d99afe0811071359m4c979430j797c6a2dcb79436f@mail.gmail.com> References: <1d2f8d6f0811071335n3212b72ek93e20d9be64bbdba@mail.gmail.com> <85d99afe0811071359m4c979430j797c6a2dcb79436f@mail.gmail.com> Message-ID: <1d2f8d6f0811071417r3def8b3u16332aeb8ac0b020@mail.gmail.com> Zach, Thank you so much. That works for me. I'm still confused why stubbing all calls to :bar on @foo would allow @foo.should_receive(:bar).with(:baz) when this doesn't work though. But I feel like I'm looking a gift horse in the mouth here! RSL On Fri, Nov 7, 2008 at 4:59 PM, Zach Dennis wrote: > On Fri, Nov 7, 2008 at 4:35 PM, Russell Norris > wrote: > > Can someone please explain to me why this spec fails > > > > it "should work" do > > > > template.stub!(:render) > > > > template.should_receive(:render).with(:partial => "foo") > > > > render @template_with_render_partial_foo > > > > end > > > > but this spec passes > > > > it "should work" do > > > > @foo.stub!(:bar) > > > > @foo.should_receive(:bar).with(:baz) > > > > @foo.bar :baz > > > > end > > > > It seems like they should work similarly and indeed this has worked for > me > > until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure > > what I'm doing wrong here. > > > > In the first example, you call "stub!(:render)". This is stubbing all > calls to render with any arguments. So you've stubbed the call that > "render @template_with_render_partial_foo" makes. > > Try: template.stub!(:render).with(:partial => anything) > > > -- > 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 rsl at swimcommunity.org Fri Nov 7 17:31:23 2008 From: rsl at swimcommunity.org (Russell Norris) Date: Fri, 7 Nov 2008 17:31:23 -0500 Subject: [rspec-users] Confusion At Failing Specs In-Reply-To: <1d2f8d6f0811071417r3def8b3u16332aeb8ac0b020@mail.gmail.com> References: <1d2f8d6f0811071335n3212b72ek93e20d9be64bbdba@mail.gmail.com> <85d99afe0811071359m4c979430j797c6a2dcb79436f@mail.gmail.com> <1d2f8d6f0811071417r3def8b3u16332aeb8ac0b020@mail.gmail.com> Message-ID: <1d2f8d6f0811071431o242882eo4242ba82d50a2453@mail.gmail.com> Per David's request i made a pastie of the whole view and the whole test of an example of this. as well as the output. http://pastie.org/309868 RSL On Fri, Nov 7, 2008 at 5:17 PM, Russell Norris wrote: > Zach, > > Thank you so much. That works for me. > > I'm still confused why stubbing all calls to :bar on @foo would allow > @foo.should_receive(:bar).with(:baz) when this doesn't work though. But I > feel like I'm looking a gift horse in the mouth here! > > RSL > > > On Fri, Nov 7, 2008 at 4:59 PM, Zach Dennis wrote: > >> On Fri, Nov 7, 2008 at 4:35 PM, Russell Norris >> wrote: >> > Can someone please explain to me why this spec fails >> > >> > it "should work" do >> > >> > template.stub!(:render) >> > >> > template.should_receive(:render).with(:partial => "foo") >> > >> > render @template_with_render_partial_foo >> > >> > end >> > >> > but this spec passes >> > >> > it "should work" do >> > >> > @foo.stub!(:bar) >> > >> > @foo.should_receive(:bar).with(:baz) >> > >> > @foo.bar :baz >> > >> > end >> > >> > It seems like they should work similarly and indeed this has worked for >> me >> > until I switched to gem rspec-rails from vendor/plugin [recent]. Not >> sure >> > what I'm doing wrong here. >> > >> >> In the first example, you call "stub!(:render)". This is stubbing all >> calls to render with any arguments. So you've stubbed the call that >> "render @template_with_render_partial_foo" makes. >> >> Try: template.stub!(:render).with(:partial => anything) >> >> >> -- >> 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 greg.hauptmann.ruby at gmail.com Fri Nov 7 18:08:49 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Fri, 7 Nov 2008 23:08:49 +0000 Subject: [rspec-users] rspec gem vs "rspec plugin" vs "rspec-rails plugin" ??? In-Reply-To: References: Message-ID: oh, I hadn't known there was a "rspec-rails" gem. Thanks On 11/7/08, Fernando Perez wrote: > Greg Hauptmann wrote: >> Hi, >> >> I've got the rspec gem installed, as well as the two plugins "rspec" & >> "rspec-rails". I can't remember which is actual used and which isn't >> for my rails app when I go "rake spec"? Anyone know? >> >> Could I remove either of the core rpec gem OR the "rspec plugin"? or >> do I need all three components? >> >> Tks > > The plugins are no longer required, you can only use the rspec and > rspec-rails gems. For a rails app you will simply have to run > "script/generate rspec" to generate a few files, and then you are all > set. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Sent from my mobile device From walketim at gmail.com Fri Nov 7 18:11:08 2008 From: walketim at gmail.com (Tim Walker) Date: Fri, 7 Nov 2008 16:11:08 -0700 Subject: [rspec-users] cucumber docs In-Reply-To: <8d961d900811070053k3120a2c3i1857036eca32da75@mail.gmail.com> References: <1ebf5a4d0811061330h24abe74dydbc88600af6da8b1@mail.gmail.com> <1ebf5a4d0811061451k59f0da59w70768b499e771319@mail.gmail.com> <8d961d900811061538m3973bcd2tfd97cb939a268062@mail.gmail.com> <1ebf5a4d0811061702p33dda16dq3f261639c923ac81@mail.gmail.com> <8d961d900811070053k3120a2c3i1857036eca32da75@mail.gmail.com> Message-ID: <1ebf5a4d0811071511v11e7f79ft80b3dada1a428d43@mail.gmail.com> Absolutely and THANKS! Sincerely, Tim On Fri, Nov 7, 2008 at 1:53 AM, aslak hellesoy wrote: > On Fri, Nov 7, 2008 at 2:02 AM, Tim Walker wrote: >> Thank you very much Aslak. That looks great. FWIW I have taught a >> class "Executable Requirements with FitNesse" as the director of >> training and coaching at Valtech and on the faculty of agile >> university. I went back to a real job recently and am now employed on >> a new enterprise class RoR project as the requirements manager and QA >> dude rolled in to one. In my analysis and discussions with others it >> looks like we're putting a stake in the ground around Cucumber (having >> passed through the Rails Integration testing, RubyFIT and other >> approaches along the way). I'm sure we'll have lots of questions. It > > Thanks for sharing that Tim. I take that as a confirmation that we're > doing something right here :-) > >> really is awesome stuff and am looking forward to this project with >> more excitement than I've felt in a long time (and I'm a fairly old >> dude, programming in assembler, fortran, c and even 360/40 JCL in my >> career). Seeing what you guys are doing is just over-the-top cool. BDD >> is great, Domain Driven Design is great. Stuff I wish I knew 20 years > > Isn't it great to be in a field where you can feel there is some > progress and learning? > 80% of what you find in BDD, RSpec and Cucumber comes from elsewhere. > Here is a list > that I have often used when I present BDD so people can go and dig fro more. > > TDD/JUnit - Kent Beck > FIT - Ward Cunningham > Example Driven Development - Brian Marick > User Stories - Connextra team (Nolan, MacKinnon et al) > BDD daddys - Chris "business value" Matts and Dan "tastapod" North > ATDD/ATDP - Richard Watt and David Leigh-Fellows (I might be wrong on origin) > DDD/Ubiq Language - Eric Evans > The RSpec list - the catalyst of bringing all of this into a consistent whole > >> ago. Requirements are the tests that implement them, not a separate >> SRS, they are the same thing. Literally. We want to do away with >> defect tracking and just write tests that reproduce them and break the >> build, treated like any other story. Your work makes all this >> possible. >> > > Can I quote you on this? I need it for my campaign. > > Aslak > >> Sincerely, >> >> Tim >> >> On Thu, Nov 6, 2008 at 4:38 PM, aslak hellesoy wrote: >>> On Thu, Nov 6, 2008 at 11:51 PM, Tim Walker wrote: >>>> Thanks guys, I may have overlooked some of the stuff there. A lot of >>>> what I was looking for was in the "Step Organization" page. >>>> >>>> Still not clear on some of the dynamic substitutions and syntax, etc. >>>> >>> >>> I just jotted down some basics here: >>> http://github.com/aslakhellesoy/cucumber/wikis/feature-introduction >>> >>> Please let us know of anything else that needs explaining. >>> >>> Cheers, >>> Aslak >>> >>>> Thanks, >>>> >>>> Tim >>>> >>>> On Thu, Nov 6, 2008 at 3:22 PM, Joseph Wilk wrote: >>>>> I suggest you checkout the wiki that Cucumber has on Github . >>>>> >>>>> http://github.com/aslakhellesoy/cucumber/wikis >>>>> >>>>> Lots of useful information. >>>>> >>>>> HTH >>>>> -- >>>>> Joseph Wilk >>>>> http://www.joesniff.co.uk >>>>> >>>>> On Thu, Nov 6, 2008 at 9:30 PM, Tim Walker wrote: >>>>>> >>>>>> Hi all, >>>>>> >>>>>> What is the best source for cucumber documentation. I did the rdoc >>>>>> thing but that was more of the API view. Is there any usage guides, >>>>>> etc. besides the examples and what you get when you download it or is >>>>>> the documentation hidden in there and I just didn't see it. >>>>>> >>>>>> Many thanks in advance! >>>>>> >>>>>> Tim >>>>>> _______________________________________________ >>>>>> 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 greg.hauptmann.ruby at gmail.com Fri Nov 7 18:18:20 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Fri, 7 Nov 2008 23:18:20 +0000 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? Message-ID: -- Sent from my mobile device From greg.hauptmann.ruby at gmail.com Fri Nov 7 18:24:16 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Sat, 8 Nov 2008 09:24:16 +1000 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: References: Message-ID: (woops - full email below) Hi, My rails migrations / mysql database uses Decimal and I've noticed in my rspec when I do a "...should eql(5.5)" that they're failing as the expected result here is a float not a decimal. For example see extract below: expected 6.5, got # (using .eql?) What's the best way of addressing this? Is there trick regarding the easiest way to address this? Thanks On Sat, Nov 8, 2008 at 9:18 AM, Greg Hauptmann wrote: > -- > Sent from my mobile device > From mark at mwilden.com Fri Nov 7 18:47:58 2008 From: mark at mwilden.com (Mark Wilden) Date: Fri, 7 Nov 2008 15:47:58 -0800 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: References: Message-ID: <3c30da400811071547q127f4b9dq17410b940c561b9d@mail.gmail.com> On Fri, Nov 7, 2008 at 3:24 PM, Greg Hauptmann < greg.hauptmann.ruby at gmail.com> wrote: > > expected 6.5, got # (using .eql?) > How about just expecting BigDecimal('5.5')? ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at mwilden.com Fri Nov 7 18:48:47 2008 From: mark at mwilden.com (Mark Wilden) Date: Fri, 7 Nov 2008 15:48:47 -0800 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: <3c30da400811071547q127f4b9dq17410b940c561b9d@mail.gmail.com> References: <3c30da400811071547q127f4b9dq17410b940c561b9d@mail.gmail.com> Message-ID: <3c30da400811071548n1f43bf08wca752b3d58146c96@mail.gmail.com> There's my C roots showing. :) That should be BigDecimal.new('5.5'), of course. On Fri, Nov 7, 2008 at 3:47 PM, Mark Wilden wrote: > On Fri, Nov 7, 2008 at 3:24 PM, Greg Hauptmann < > greg.hauptmann.ruby at gmail.com> wrote: > >> >> expected 6.5, got # (using .eql?) >> > > How about just expecting BigDecimal('5.5')? > > ///ark > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Fri Nov 7 18:51:29 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 07 Nov 2008 15:51:29 -0800 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: (Greg Hauptmann's message of "Fri\, 7 Nov 2008 23\:18\:20 +0000") References: Message-ID: "Greg Hauptmann" writes: Do you mean BigDecimal? Anyway, you should probably be using == instead of eql. >> 5.5 == BigDecimal.new('5.5') => true >> 5.5.eql? BigDecimal.new('5.5') => false eql? is object identity and is generally not what you're after. Pat From mark at mwilden.com Fri Nov 7 19:09:55 2008 From: mark at mwilden.com (Mark Wilden) Date: Fri, 7 Nov 2008 16:09:55 -0800 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: References: Message-ID: <3c30da400811071609i5f250a2bj52c64b57613135f@mail.gmail.com> On Fri, Nov 7, 2008 at 3:51 PM, Pat Maddox wrote: > "Greg Hauptmann" writes: > > Do you mean BigDecimal? Anyway, you should probably be using == instead > of eql. > > >> 5.5 == BigDecimal.new('5.5') > => true > >> 5.5.eql? BigDecimal.new('5.5') > => false > > eql? is object identity and is generally not what you're after. > Yeah, but >> BigDecimal('5.5').eql? BigDecimal('5.5') => true So it's either creating value objects (like Symbol) or BigDecimal.eql? doesn't do object equality. What's interesting is that you can create BigDecimals this way (without calling new). You can do it with Strings, too. >> String('asdf') => "asdf" But not everything: >> Hash(:a => 5) NoMethodError: undefined method `Hash' for # from (irb):12 As Johnny Carson used to say, "I did not know that." ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.hauptmann.ruby at gmail.com Fri Nov 7 20:00:57 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Sat, 8 Nov 2008 01:00:57 +0000 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: <3c30da400811071547q127f4b9dq17410b940c561b9d@mail.gmail.com> References: <3c30da400811071547q127f4b9dq17410b940c561b9d@mail.gmail.com> Message-ID: in fact I guess I was fishing for an easier way than this...if one exists? or is ruby & rspec "eql()" just strict here in terms of types? On 11/7/08, Mark Wilden wrote: > On Fri, Nov 7, 2008 at 3:24 PM, Greg Hauptmann < > greg.hauptmann.ruby at gmail.com> wrote: > >> >> expected 6.5, got # (using .eql?) >> > > How about just expecting BigDecimal('5.5')? > > ///ark > -- Sent from my mobile device From zach.dennis at gmail.com Fri Nov 7 20:17:07 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 7 Nov 2008 20:17:07 -0500 Subject: [rspec-users] Confusion At Failing Specs In-Reply-To: <1d2f8d6f0811071417r3def8b3u16332aeb8ac0b020@mail.gmail.com> References: <1d2f8d6f0811071335n3212b72ek93e20d9be64bbdba@mail.gmail.com> <85d99afe0811071359m4c979430j797c6a2dcb79436f@mail.gmail.com> <1d2f8d6f0811071417r3def8b3u16332aeb8ac0b020@mail.gmail.com> Message-ID: <85d99afe0811071717r4aaf0977rd16b5ccaede6c835@mail.gmail.com> On Fri, Nov 7, 2008 at 5:17 PM, Russell Norris wrote: > Zach, > > Thank you so much. That works for me. > > I'm still confused why stubbing all calls to :bar on @foo would allow > @foo.should_receive(:bar).with(:baz) when this doesn't work though. But I > feel like I'm looking a gift horse in the mouth here! The reason this doesn't work is because rspec's "render" method in your view example is just wrapping a call to the actual template. Here's what I mean. Given your example: it "should work" do template.stub!(:render) template.should_receive(:render).with(:partial => "foo") render @template_with_render_partial_foo # in your view you call <%= render :partial => "foo" %> end Here's what it is really doing: it "should work" do @controller.template.stub!(:render) @controller.template.should_receive(:render).with(:partial => "foo") @controller.template.render @template_with_render_partial_foo # in your view you call <%= render :partial => "foo" %> @controller.template.render :partial => "foo" end The @controller.template is the actual template that gets rendered. The "render" call in your example is made on the same template object that the actual "render :partial" call is made on. So, when you make the call to render the @template_with_render_partial_foo you have stubbed out that render method and it never actually renders anything causing your example to fail because it never gets to the view template that calls 'render :partial => "foo"' Hopefully this helps clear it up? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From zach.dennis at gmail.com Fri Nov 7 20:48:05 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 7 Nov 2008 20:48:05 -0500 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: References: Message-ID: <85d99afe0811071748o7cfc1d84pf09593a20d8d78bc@mail.gmail.com> On Fri, Nov 7, 2008 at 6:24 PM, Greg Hauptmann wrote: > (woops - full email below) > > Hi, > > My rails migrations / mysql database uses Decimal and I've noticed in > my rspec when I do a "...should eql(5.5)" that they're failing as the > expected result here is a float not a decimal. For example see > extract below: > > expected 6.5, got # (using .eql?) > > What's the best way of addressing this? Is there trick regarding the > easiest way to address this? You aren't by chance using decimals to represent money are you? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From joshknowles at gmail.com Fri Nov 7 20:53:17 2008 From: joshknowles at gmail.com (Josh Knowles) Date: Fri, 7 Nov 2008 20:53:17 -0500 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> Message-ID: On Fri, Nov 7, 2008 at 9:24 AM, aidy lewis wrote: > The customer is not happy about writing Stories in a text editor. > > Has anyone else experienced this? Is anyone using a wiki, spreadsheet, > or word document and automatically converting to a text file? As Aslak mentioned there are lots of tools to come, but I just figured I'd throw out there that at weplay we pair with our customers on the initial generation of the feature files, once that is done we've given them a GitHub account and both the Business Owner and our QA will go in and tweak the feature files from within the GitHub web-based editor. Obviously we've had to build up a level of trust on both ends, and this level of integration didn't come over night, but its nice to see commits coming into the project from all members of the team (not just developers). Josh From greg.hauptmann.ruby at gmail.com Fri Nov 7 21:12:51 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Sat, 8 Nov 2008 12:12:51 +1000 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: <85d99afe0811071748o7cfc1d84pf09593a20d8d78bc@mail.gmail.com> References: <85d99afe0811071748o7cfc1d84pf09593a20d8d78bc@mail.gmail.com> Message-ID: yep - this was recommended on forums over float - why? On Sat, Nov 8, 2008 at 11:48 AM, Zach Dennis wrote: > On Fri, Nov 7, 2008 at 6:24 PM, Greg Hauptmann > wrote: >> (woops - full email below) >> >> Hi, >> >> My rails migrations / mysql database uses Decimal and I've noticed in >> my rspec when I do a "...should eql(5.5)" that they're failing as the >> expected result here is a float not a decimal. For example see >> extract below: >> >> expected 6.5, got # (using .eql?) >> >> What's the best way of addressing this? Is there trick regarding the >> easiest way to address this? > > You aren't by chance using decimals to represent money are you? > > -- > 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 Nov 7 21:18:53 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 7 Nov 2008 21:18:53 -0500 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: References: <85d99afe0811071748o7cfc1d84pf09593a20d8d78bc@mail.gmail.com> Message-ID: <85d99afe0811071818m472d3538y7fa927fef48fb785@mail.gmail.com> On Fri, Nov 7, 2008 at 9:12 PM, Greg Hauptmann wrote: > yep - this was recommended on forums over float - why? You are in for a lot of headaches in you application resorting to decimal fields in the database, since it restores them as BigDecimals. It sucks to deal with BigDecimals in your app. I very highly recommend the Money library. I recommend installing it as a plugin and using the CollectiveIdea fork. http://github.com/collectiveidea/money/tree/master Even if all you do is take 20 minutes to check out the Money library in a dummy app, I think you will be glad you did. Zach > > On Sat, Nov 8, 2008 at 11:48 AM, Zach Dennis wrote: >> On Fri, Nov 7, 2008 at 6:24 PM, Greg Hauptmann >> wrote: >>> (woops - full email below) >>> >>> Hi, >>> >>> My rails migrations / mysql database uses Decimal and I've noticed in >>> my rspec when I do a "...should eql(5.5)" that they're failing as the >>> expected result here is a float not a decimal. For example see >>> extract below: >>> >>> expected 6.5, got # (using .eql?) >>> >>> What's the best way of addressing this? Is there trick regarding the >>> easiest way to address this? >> >> You aren't by chance using decimals to represent money are you? >> >> -- >> 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 >> > -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From dchelimsky at gmail.com Fri Nov 7 21:30:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 7 Nov 2008 21:30:16 -0500 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> Message-ID: <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> On Fri, Nov 7, 2008 at 8:53 PM, Josh Knowles wrote: > On Fri, Nov 7, 2008 at 9:24 AM, aidy lewis wrote: >> The customer is not happy about writing Stories in a text editor. >> >> Has anyone else experienced this? Is anyone using a wiki, spreadsheet, >> or word document and automatically converting to a text file? > > As Aslak mentioned there are lots of tools to come, but I just figured > I'd throw out there that at weplay we pair with our customers on the > initial generation of the feature files, once that is done we've given > them a GitHub account and both the Business Owner and our QA will go > in and tweak the feature files from within the GitHub web-based > editor. Holy crap! I didn't know they had that. Josh - thanks for pointing this out - this changes a LOT! Next step .... Write a post commit hook to fire a message off to your build machine and have it run all the scenarios and email you the results. Sometimes everything will just pass. Sometimes you'll know you have new work to do. Any takers? And if you can train the business folk to make changes to their own branch (or maybe give them all their own forks - might be simpler) ... man - this opens up a ton of opportunity. Thanks for bringing this up. Cheers, David > > Obviously we've had to build up a level of trust on both ends, and > this level of integration didn't come over night, but its nice to see > commits coming into the project from all members of the team (not just > developers). > > Josh > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Fri Nov 7 23:10:38 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 07 Nov 2008 20:10:38 -0800 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: (Greg Hauptmann's message of "Sat\, 8 Nov 2008 01\:00\:57 +0000") References: <3c30da400811071547q127f4b9dq17410b940c561b9d@mail.gmail.com> Message-ID: "Greg Hauptmann" writes: > in fact I guess I was fishing for an easier way than this...if one > exists? or is ruby & rspec "eql()" just strict here in terms of > types? > > On 11/7/08, Mark Wilden wrote: >> On Fri, Nov 7, 2008 at 3:24 PM, Greg Hauptmann < >> greg.hauptmann.ruby at gmail.com> wrote: >> >>> >>> expected 6.5, got # (using .eql?) >>> >> >> How about just expecting BigDecimal('5.5')? >> >> ///ark >> I'm not sure if you got my email before, but 6.5 == BigDecimal.new('6.5'). So use == instead and you should be good. Pat From greg.hauptmann.ruby at gmail.com Sat Nov 8 00:37:10 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Sat, 8 Nov 2008 15:37:10 +1000 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: References: <3c30da400811071547q127f4b9dq17410b940c561b9d@mail.gmail.com> Message-ID: thanks Pat - yes I missed it when reading your email - I'd been using ".eql" for everything....thanks On Sat, Nov 8, 2008 at 2:10 PM, Pat Maddox wrote: > "Greg Hauptmann" writes: > >> in fact I guess I was fishing for an easier way than this...if one >> exists? or is ruby & rspec "eql()" just strict here in terms of >> types? >> >> On 11/7/08, Mark Wilden wrote: >>> On Fri, Nov 7, 2008 at 3:24 PM, Greg Hauptmann < >>> greg.hauptmann.ruby at gmail.com> wrote: >>> >>>> >>>> expected 6.5, got # (using .eql?) >>>> >>> >>> How about just expecting BigDecimal('5.5')? >>> >>> ///ark >>> > > I'm not sure if you got my email before, but 6.5 == > BigDecimal.new('6.5'). So use == instead and you should be good. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dbitsolutions at gmail.com Sat Nov 8 01:29:22 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Fri, 7 Nov 2008 22:29:22 -0800 (PST) Subject: [rspec-users] should_raise ain't workin' with the `spec` command Message-ID: <31436739-878c-49f5-9280-f4144abb2390@w24g2000prd.googlegroups.com> Hello my fellow RSpeckers, I am using the spec command like this: spec tokyo_record_spec.rb And the for some reason the should_raise Rspec command is not happening with my lambda block: it "should raise a NoSuchAttribute error if the attribute 'name' hasn't been declared yet and you try to create a persisted instance of the object." do lambda { User.create( :name => 'Dustin') }. should_raise( NoSuchAttribute ) end Here is the error: undefined method `should_raise' for # ./tokyo_record_spec.rb:77: I'm not sure how the `spec` command actually works, and I'm sure that's at least one source of my confusion. Also, I don't know where `should_raise` is defined either. If anybody could help me clear the clouds in my brain, I would greatly appreciate it. Please point me in a sunnier direction. This is straight Ruby code. It has nothing to do with Rails. My directory structure looks something like this: /tokyo /tokyo/tokyo_record.rb /tokyo/tokyo_record_spec.rb And at the top of /tokyo/tokyo_record_spec.rb I have only require 'tokyo_record' which is a homemade Ruby module that I'm trying to spec with RSpec. I am running gem version 1.2.0, RSpec 1.1.9 and hoe 1.8.0 on OS X 10.4.11. Thank you, David :) From greg.hauptmann.ruby at gmail.com Sat Nov 8 01:32:04 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Sat, 8 Nov 2008 16:32:04 +1000 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: References: <3c30da400811071547q127f4b9dq17410b940c561b9d@mail.gmail.com> Message-ID: very bizzare but whilst I needed to use this approach to fix one of my tests, I realised the test before was working without having to make it a big decimal - go figure :) -------------------------------- it "should return last IR when date > last interest rate" do @source_bank.ir(Time.now.to_date + 1.years).should == 8.5 # <== WORKED FINE end it "should return latest IR not greater than date specified when a date is passed" do @source_bank.ir(Time.now.to_date + 8.days).should == BigDecimal.new('6.5') # <== NEEDED TO USE BigDecimal here end -------------------------------- On Sat, Nov 8, 2008 at 3:37 PM, Greg Hauptmann wrote: > thanks Pat - yes I missed it when reading your email - I'd been using > ".eql" for everything....thanks > > On Sat, Nov 8, 2008 at 2:10 PM, Pat Maddox wrote: >> "Greg Hauptmann" writes: >> >>> in fact I guess I was fishing for an easier way than this...if one >>> exists? or is ruby & rspec "eql()" just strict here in terms of >>> types? >>> >>> On 11/7/08, Mark Wilden wrote: >>>> On Fri, Nov 7, 2008 at 3:24 PM, Greg Hauptmann < >>>> greg.hauptmann.ruby at gmail.com> wrote: >>>> >>>>> >>>>> expected 6.5, got # (using .eql?) >>>>> >>>> >>>> How about just expecting BigDecimal('5.5')? >>>> >>>> ///ark >>>> >> >> I'm not sure if you got my email before, but 6.5 == >> BigDecimal.new('6.5'). So use == instead and you should be good. >> >> Pat >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From matt at mattwynne.net Sat Nov 8 02:22:09 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 8 Nov 2008 07:22:09 +0000 Subject: [rspec-users] should_raise ain't workin' with the `spec` command In-Reply-To: <31436739-878c-49f5-9280-f4144abb2390@w24g2000prd.googlegroups.com> References: <31436739-878c-49f5-9280-f4144abb2390@w24g2000prd.googlegroups.com> Message-ID: <03C787D0-9013-4319-AFDF-6CD2E983471D@mattwynne.net> On 8 Nov 2008, at 06:29, David Beckwith wrote: > Hello my fellow RSpeckers, > > I am using the spec command like this: > > spec tokyo_record_spec.rb > > And the for some reason the should_raise Rspec command is not > happening with my lambda block: > > it "should raise a NoSuchAttribute error if the attribute 'name' > hasn't been declared yet and you try to create a persisted instance of > the object." do > lambda { > User.create( :name => 'Dustin') > }. should_raise( NoSuchAttribute ) > end > > Here is the error: > > undefined method `should_raise' for # tokyo_record_spec.rb:77> > ./tokyo_record_spec.rb:77: Okay the the first obvious problem is you've got the syntax wrong for asserting an exception. And you wouldn't be the first - I keep forgetting this myself as I don't do it very often. Try this instead: lamda { do_bad_stuff }.should raise_error Also, are you calling require 'spec' at the top of your spec file? That's what will ensure that the Proc object is patched with a #should method. > I'm not sure how the `spec` command actually works, and I'm sure > that's at least one source of my confusion. Also, I don't know where > `should_raise` is defined either. If anybody could help me clear the > clouds in my brain, I would greatly appreciate it. Please point me in > a sunnier direction. You can use ruby tokyo_record_spec.rb or spec tokyo_record_spec.rb at the command line to run your specs - both are valid, but spec will give you some more options to format your output in different ways etc. that start to become more useful as you write more specs. For now it might feel simpler to just call your specs using the ruby command. > This is straight Ruby code. It has nothing to do with Rails. My > directory structure looks something like this: > > /tokyo > /tokyo/tokyo_record.rb > /tokyo/tokyo_record_spec.rb > > And at the top of /tokyo/tokyo_record_spec.rb I have only require > 'tokyo_record' which is a homemade Ruby module that I'm trying to spec > with RSpec. It's pretty conventional to use a spec_helper.rb file somewhere that you just always require at the top of each spec file. That gives you an extensibility point if you want to do any global setup of your test environment that has to run before each set of spec. Also most people seem to keep their specs in a separate 'spec' directory. If you want to use tools like RSpactor you'd need to stick to this convention (for now at least). It might be worth creating a vanilla rails project, adding the rspec- rails gem, and running 'script/generate rspec' in there just to see how it's done - the examples are pretty good and give you a good idea of the conventions other people are using. HTH, Matt From dbitsolutions at gmail.com Sat Nov 8 03:01:46 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sat, 8 Nov 2008 00:01:46 -0800 (PST) Subject: [rspec-users] should_raise ain't workin' with the `spec` command In-Reply-To: <03C787D0-9013-4319-AFDF-6CD2E983471D@mattwynne.net> References: <31436739-878c-49f5-9280-f4144abb2390@w24g2000prd.googlegroups.com> <03C787D0-9013-4319-AFDF-6CD2E983471D@mattwynne.net> Message-ID: <882f7b8f-2649-4e6b-a959-0f7696618c70@f37g2000pri.googlegroups.com> awesome. thank you. that helps a lot. David ;) On Nov 7, 11:22?pm, Matt Wynne wrote: > On 8 Nov 2008, at 06:29, David Beckwith wrote: > > > > > Hello my fellow RSpeckers, > > > I am using the spec command like this: > > > ? ? ? ? ? ? ? ?spec tokyo_record_spec.rb > > > And the for some reason the should_raise Rspec command is not > > happening with my lambda block: > > > ? ?it "should raise a NoSuchAttribute error if the attribute 'name' > > hasn't been declared yet and you try to create a persisted instance of > > the object." do > > ? ? ?lambda { > > ? ? ? ?User.create( :name => 'Dustin') > > ? ? ?}. should_raise( NoSuchAttribute ) > > ? ?end > > > Here is the error: > > > undefined method `should_raise' for # > tokyo_record_spec.rb:77> > > ./tokyo_record_spec.rb:77: > > Okay the the first obvious problem is you've got the syntax wrong for ? > asserting an exception. And you wouldn't be the first - I keep ? > forgetting this myself as I don't do it very often. > > Try this instead: > ? ? lamda { do_bad_stuff }.should raise_error > > Also, are you calling require 'spec' at the top of your spec file? ? > That's what will ensure that the Proc object is patched with a #should ? > method. > > > I'm not sure how the `spec` command actually works, and I'm sure > > that's at least one source of my confusion. ?Also, I don't know where > > `should_raise` is defined either. ?If anybody could help me clear the > > clouds in my brain, I would greatly appreciate it. ?Please point me in > > a sunnier direction. > > You can use ruby tokyo_record_spec.rb or spec tokyo_record_spec.rb at ? > the command line to run your specs - both are valid, but spec will ? > give you some more options to format your output in different ways ? > etc. that start to become more useful as you write more specs. For now ? > it might feel simpler to just call your specs using the ruby command. > > > This is straight Ruby code. ?It has nothing to do with Rails. My > > directory structure looks something like this: > > > /tokyo > > /tokyo/tokyo_record.rb > > /tokyo/tokyo_record_spec.rb > > > And at the top of /tokyo/tokyo_record_spec.rb I have only require > > 'tokyo_record' which is a homemade Ruby module that I'm trying to spec > > with RSpec. > > It's pretty conventional to use a spec_helper.rb file somewhere that ? > you just always require at the top of each spec file. That gives you ? > an extensibility point if you want to do any global setup of your test ? > environment that has to run before each set of spec. Also most people ? > seem to keep their specs in a separate 'spec' directory. If you want ? > to use tools like RSpactor you'd need to stick to this convention (for ? > now at least). > > It might be worth creating a vanilla rails project, adding the rspec- > rails gem, and running 'script/generate rspec' in there just to see ? > how it's done - the examples are pretty good and give you a good idea ? > of the conventions other people are using. > > HTH, > Matt > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dbitsolutions at gmail.com Sat Nov 8 03:34:18 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sat, 8 Nov 2008 00:34:18 -0800 (PST) Subject: [rspec-users] should_raise ain't workin' with the `spec` command In-Reply-To: <03C787D0-9013-4319-AFDF-6CD2E983471D@mattwynne.net> References: <31436739-878c-49f5-9280-f4144abb2390@w24g2000prd.googlegroups.com> <03C787D0-9013-4319-AFDF-6CD2E983471D@mattwynne.net> Message-ID: I'm feeling pretty hip now with: spec -O spec/spec.opts spec/tokyo_record_spec.rb David :) On Nov 7, 11:22?pm, Matt Wynne wrote: > On 8 Nov 2008, at 06:29, David Beckwith wrote: > > > > > Hello my fellow RSpeckers, > > > I am using the spec command like this: > > > ? ? ? ? ? ? ? ?spec tokyo_record_spec.rb > > > And the for some reason the should_raise Rspec command is not > > happening with my lambda block: > > > ? ?it "should raise a NoSuchAttribute error if the attribute 'name' > > hasn't been declared yet and you try to create a persisted instance of > > the object." do > > ? ? ?lambda { > > ? ? ? ?User.create( :name => 'Dustin') > > ? ? ?}. should_raise( NoSuchAttribute ) > > ? ?end > > > Here is the error: > > > undefined method `should_raise' for # > tokyo_record_spec.rb:77> > > ./tokyo_record_spec.rb:77: > > Okay the the first obvious problem is you've got the syntax wrong for ? > asserting an exception. And you wouldn't be the first - I keep ? > forgetting this myself as I don't do it very often. > > Try this instead: > ? ? lamda { do_bad_stuff }.should raise_error > > Also, are you calling require 'spec' at the top of your spec file? ? > That's what will ensure that the Proc object is patched with a #should ? > method. > > > I'm not sure how the `spec` command actually works, and I'm sure > > that's at least one source of my confusion. ?Also, I don't know where > > `should_raise` is defined either. ?If anybody could help me clear the > > clouds in my brain, I would greatly appreciate it. ?Please point me in > > a sunnier direction. > > You can use ruby tokyo_record_spec.rb or spec tokyo_record_spec.rb at ? > the command line to run your specs - both are valid, but spec will ? > give you some more options to format your output in different ways ? > etc. that start to become more useful as you write more specs. For now ? > it might feel simpler to just call your specs using the ruby command. > > > This is straight Ruby code. ?It has nothing to do with Rails. My > > directory structure looks something like this: > > > /tokyo > > /tokyo/tokyo_record.rb > > /tokyo/tokyo_record_spec.rb > > > And at the top of /tokyo/tokyo_record_spec.rb I have only require > > 'tokyo_record' which is a homemade Ruby module that I'm trying to spec > > with RSpec. > > It's pretty conventional to use a spec_helper.rb file somewhere that ? > you just always require at the top of each spec file. That gives you ? > an extensibility point if you want to do any global setup of your test ? > environment that has to run before each set of spec. Also most people ? > seem to keep their specs in a separate 'spec' directory. If you want ? > to use tools like RSpactor you'd need to stick to this convention (for ? > now at least). > > It might be worth creating a vanilla rails project, adding the rspec- > rails gem, and running 'script/generate rspec' in there just to see ? > how it's done - the examples are pretty good and give you a good idea ? > of the conventions other people are using. > > HTH, > Matt > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dbitsolutions at gmail.com Sat Nov 8 03:39:43 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sat, 8 Nov 2008 00:39:43 -0800 (PST) Subject: [rspec-users] should_raise ain't workin' with the `spec` command In-Reply-To: <882f7b8f-2649-4e6b-a959-0f7696618c70@f37g2000pri.googlegroups.com> References: <31436739-878c-49f5-9280-f4144abb2390@w24g2000prd.googlegroups.com> <03C787D0-9013-4319-AFDF-6CD2E983471D@mattwynne.net> <882f7b8f-2649-4e6b-a959-0f7696618c70@f37g2000pri.googlegroups.com> Message-ID: I am feeling pretty hip with: spec -O spec/spec.opts spec/tokyo_record_spec.rb D :) On Nov 8, 12:01?am, David Beckwith wrote: > awesome. ?thank you. ?that helps a lot. > David ;) > > On Nov 7, 11:22?pm, Matt Wynne wrote: > > > On 8 Nov 2008, at 06:29, David Beckwith wrote: > > > > Hello my fellow RSpeckers, > > > > I am using the spec command like this: > > > > ? ? ? ? ? ? ? ?spec tokyo_record_spec.rb > > > > And the for some reason the should_raise Rspec command is not > > > happening with my lambda block: > > > > ? ?it "should raise a NoSuchAttribute error if the attribute 'name' > > > hasn't been declared yet and you try to create a persisted instance of > > > the object." do > > > ? ? ?lambda { > > > ? ? ? ?User.create( :name => 'Dustin') > > > ? ? ?}. should_raise( NoSuchAttribute ) > > > ? ?end > > > > Here is the error: > > > > undefined method `should_raise' for # > > tokyo_record_spec.rb:77> > > > ./tokyo_record_spec.rb:77: > > > Okay the the first obvious problem is you've got the syntax wrong for ? > > asserting an exception. And you wouldn't be the first - I keep ? > > forgetting this myself as I don't do it very often. > > > Try this instead: > > ? ? lamda { do_bad_stuff }.should raise_error > > > Also, are you calling require 'spec' at the top of your spec file? ? > > That's what will ensure that the Proc object is patched with a #should ? > > method. > > > > I'm not sure how the `spec` command actually works, and I'm sure > > > that's at least one source of my confusion. ?Also, I don't know where > > > `should_raise` is defined either. ?If anybody could help me clear the > > > clouds in my brain, I would greatly appreciate it. ?Please point me in > > > a sunnier direction. > > > You can use ruby tokyo_record_spec.rb or spec tokyo_record_spec.rb at ? > > the command line to run your specs - both are valid, but spec will ? > > give you some more options to format your output in different ways ? > > etc. that start to become more useful as you write more specs. For now ? > > it might feel simpler to just call your specs using the ruby command. > > > > This is straight Ruby code. ?It has nothing to do with Rails. My > > > directory structure looks something like this: > > > > /tokyo > > > /tokyo/tokyo_record.rb > > > /tokyo/tokyo_record_spec.rb > > > > And at the top of /tokyo/tokyo_record_spec.rb I have only require > > > 'tokyo_record' which is a homemade Ruby module that I'm trying to spec > > > with RSpec. > > > It's pretty conventional to use a spec_helper.rb file somewhere that ? > > you just always require at the top of each spec file. That gives you ? > > an extensibility point if you want to do any global setup of your test ? > > environment that has to run before each set of spec. Also most people ? > > seem to keep their specs in a separate 'spec' directory. If you want ? > > to use tools like RSpactor you'd need to stick to this convention (for ? > > now at least). > > > It might be worth creating a vanilla rails project, adding the rspec- > > rails gem, and running 'script/generate rspec' in there just to see ? > > how it's done - the examples are pretty good and give you a good idea ? > > of the conventions other people are using. > > > 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.orghttp://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Sat Nov 8 05:01:48 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 8 Nov 2008 10:01:48 +0000 Subject: [rspec-users] Sharing the little dialects we write in Cucumber Message-ID: The common_webrat.rb steps file that comes with cucumber when you add it to rails really inspired our team. We've extended it a fair bit to do various other things to check the content of a page such as [1] which enable us to write steps like this: Then I should see the text "dave" within the "friends" list We also have a bunch of generic steps that work with the factory_girl plugin to allow us easily create / manipulate different domain objects like this: Given there is a User or Given there are 3 Concerts Also, I've started writing some specs for a command-line tool, and will have a few steps that work with the command-line When I issue the command "ls" I feel like I want to share this stuff and collaborate on it in a broader group outside our team but I'm not sure what would be the appropriate route. Obviously this stuff is pretty easy to re-use - you just have to require a ruby file that defines the steps so it's not like cucumber needs a plug-in manager exactly... What do people think? Is this stuff so trivially easy to other people that they prefer just to write it from scratch? Or are you also writing step matchers that you think other people could be using? How do you think we could best share them and collaborate on them? cheers, Matt [1]http://gist.github.com/23044 From lists at ruby-forum.com Sat Nov 8 05:34:59 2008 From: lists at ruby-forum.com (Pau Cor) Date: Sat, 8 Nov 2008 11:34:59 +0100 Subject: [rspec-users] Sharing the little dialects we write in Cucumber In-Reply-To: References: Message-ID: Matt Wynne wrote: > What do people think? Is this stuff so trivially easy to other people > that they prefer just to write it from scratch? I think that sharing these will be a really good way to help people learning Cucumber write better features and steps. Writing cucumber features that pass is easy. Writing ones that are easy to maintain, increase confidence, and document functionality is REALLY hard (at least to learn). Being able to start with a lot of well written steps would get people on the right track. > How do you think we could best share them and collaborate on them? I think some could go on the Wiki. -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Sat Nov 8 06:22:53 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 8 Nov 2008 12:22:53 +0100 Subject: [rspec-users] Sharing the little dialects we write in Cucumber In-Reply-To: References: Message-ID: <8d961d900811080322v5250e6c7qef7fab06539153ad@mail.gmail.com> On Sat, Nov 8, 2008 at 11:01 AM, Matt Wynne wrote: > The common_webrat.rb steps file that comes with cucumber when you add it to > rails really inspired our team. > > We've extended it a fair bit to do various other things to check the content > of a page such as [1] which enable us to write steps like this: > > Then I should see the text "dave" within the "friends" list > > We also have a bunch of generic steps that work with the factory_girl plugin > to allow us easily create / manipulate different domain objects like this: > > Given there is a User > or > Given there are 3 Concerts > > Also, I've started writing some specs for a command-line tool, and will have > a few steps that work with the command-line > > When I issue the command "ls" > > I feel like I want to share this stuff and collaborate on it in a broader > group outside our team but I'm not sure what would be the appropriate route. > Obviously this stuff is pretty easy to re-use - you just have to require a > ruby file that defines the steps so it's not like cucumber needs a plug-in > manager exactly... > > What do people think? Is this stuff so trivially easy to other people that > they prefer just to write it from scratch? Or are you also writing step > matchers that you think other people could be using? How do you think we > could best share them and collaborate on them? > I think some basic steps for output validation is good. I like the essence in yours. Please add it in your fork. > cheers, > Matt > > [1]http://gist.github.com/23044 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From josephwilk at joesniff.co.uk Sat Nov 8 09:06:29 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Sat, 8 Nov 2008 14:06:29 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> Message-ID: On Sat, Nov 8, 2008 at 2:30 AM, David Chelimsky wrote: > On Fri, Nov 7, 2008 at 8:53 PM, Josh Knowles > wrote: > > On Fri, Nov 7, 2008 at 9:24 AM, aidy lewis > wrote: > >> The customer is not happy about writing Stories in a text editor. > >> > >> Has anyone else experienced this? Is anyone using a wiki, spreadsheet, > >> or word document and automatically converting to a text file? > > > > As Aslak mentioned there are lots of tools to come, but I just figured > > I'd throw out there that at weplay we pair with our customers on the > > initial generation of the feature files, once that is done we've given > > them a GitHub account and both the Business Owner and our QA will go > > in and tweak the feature files from within the GitHub web-based > > editor. > > Holy crap! I didn't know they had that. > > Josh - thanks for pointing this out - this changes a LOT! > > Next step .... > > Write a post commit hook to fire a message off to your build machine > and have it run all the scenarios and email you the results. Sometimes > everything will just pass. Sometimes you'll know you have new work to > do. Don't we already have this with something like cruisecontrol.rb [1]? Checkout the code from Github, set it up as a project in cruisecontrol. On any commit it will run the build and send emails if there were failures. Where you thinking something different or am I missing something? -- Joseph Wilk http://www.joesniff.co.uk [1] http://cruisecontrolrb.thoughtworks.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Sat Nov 8 09:16:25 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 8 Nov 2008 14:16:25 +0000 Subject: [rspec-users] Sharing the little dialects we write in Cucumber In-Reply-To: <8d961d900811080322v5250e6c7qef7fab06539153ad@mail.gmail.com> References: <8d961d900811080322v5250e6c7qef7fab06539153ad@mail.gmail.com> Message-ID: On 8 Nov 2008, at 11:22, aslak hellesoy wrote: > On Sat, Nov 8, 2008 at 11:01 AM, Matt Wynne > wrote: >> The common_webrat.rb steps file that comes with cucumber when you >> add it to >> rails really inspired our team. >> >> We've extended it a fair bit to do various other things to check >> the content >> of a page such as [1] which enable us to write steps like this: >> >> I feel like I want to share this stuff and collaborate on it in a >> broader >> group outside our team but I'm not sure what would be the >> appropriate route. >> Obviously this stuff is pretty easy to re-use - you just have to >> require a >> ruby file that defines the steps so it's not like cucumber needs a >> plug-in >> manager exactly... >> >> What do people think? Is this stuff so trivially easy to other >> people that >> they prefer just to write it from scratch? Or are you also writing >> step >> matchers that you think other people could be using? How do you >> think we >> could best share them and collaborate on them? >> > > I think some basic steps for output validation is good. I like the > essence in yours. Please add it in your fork. Glad you like the idea :) Okay, tentatively, I've factored over the obvious steps I can see in our project that could easily be reused: http://github.com/songkick/cucumber/commit/b80da2b024ac17dcf1ebe79ebd7445c45bf984a6 This would mean that the sample 'common_webrat.rb' step that's created by the rails generator could just consist of the following line: require 'cucumber/steps_library/webrat' In fact, this could just go into env.rb - that's what I've done in our project now the code is factored away in cucumber. Now this is just a spike, and I have my concerns / thoughts: * If other people are going to be depending on these steps, they really need automated tests of some sort that ship alongside them. * I've introduced three new methods in the global namespace - yuck! * How should these best be factored away somewhere non-polluting? * Should within_list() go into webrat maybe? * Is 'cucumber/steps_library' the right name / place to put these? Could be 'step_matchers_library' instead maybe? * If we're going to start squirrelling step matchers away in a library / libraries, do we need a way to ask the StepMother to list them (kinda like rake routes)? Okay that's it for now. All feedback extremely welcome :) cheers, Matt From matt at mattwynne.net Sat Nov 8 09:44:17 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 8 Nov 2008 14:44:17 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> Message-ID: <0BE3592E-74E2-426E-82C1-69DE0351B5CB@mattwynne.net> On 8 Nov 2008, at 02:30, David Chelimsky wrote: > On Fri, Nov 7, 2008 at 8:53 PM, Josh Knowles > wrote: > Next step .... > > Write a post commit hook to fire a message off to your build machine > and have it run all the scenarios and email you the results. Sometimes > everything will just pass. Sometimes you'll know you have new work to > do. > > Any takers? > > And if you can train the business folk to make changes to their own > branch (or maybe give them all their own forks - might be simpler) ... > man - this opens up a ton of opportunity. I've been thinking about this a lot. Assuming you have a stakeholder who can check changes to feature files, you're going to get a borked build sooner or later - it's unlikely they'll change requirements and the code will magically adjust itself! (not for a few years anyway!) I guess like you say (and I hadn't thought of this) the right idea is to get the stakeholder to check in their changes in a different branch to the one in which the developers are hacking on the actual changes. That way you can have a build on the stakeholder branch which is often broken, but the breakages are like a 'todo list' for the developers - it's basically your WIP. And you can have another build on the developers' branch which is sacred and people get the usual punishments for breaking. I think there's a nice synergy to be had here between cucumber, git and cruisecontrol.rb that will help you have a really lean workflow. Very interesting. cheers, Matt From joshknowles at gmail.com Sat Nov 8 12:33:53 2008 From: joshknowles at gmail.com (Josh Knowles) Date: Sat, 8 Nov 2008 12:33:53 -0500 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> Message-ID: On Fri, Nov 7, 2008 at 9:30 PM, David Chelimsky wrote: > Next step .... > > Write a post commit hook to fire a message off to your build machine > and have it run all the scenarios and email you the results. Sometimes > everything will just pass. Sometimes you'll know you have new work to > do. cruisecontrol.rb already takes care of this for you. -- Josh Knowles phone: 509-979-1593 email: joshknowles at gmail.com web: http://joshknowles.com From matt at mattwynne.net Sat Nov 8 12:48:07 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 8 Nov 2008 17:48:07 +0000 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> Message-ID: <9F827099-FE9B-4D0B-8C6B-BEE2E9F5CE64@mattwynne.net> On 8 Nov 2008, at 17:33, Josh Knowles wrote: > On Fri, Nov 7, 2008 at 9:30 PM, David Chelimsky > wrote: >> Next step .... >> >> Write a post commit hook to fire a message off to your build machine >> and have it run all the scenarios and email you the results. >> Sometimes >> everything will just pass. Sometimes you'll know you have new work to >> do. > > cruisecontrol.rb already takes care of this for you. So does your stakeholder break the build when this happens? Isn't it just broken most of the time in that case? cheers, Matt From greg.hauptmann.ruby at gmail.com Sat Nov 8 15:37:06 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Sun, 9 Nov 2008 06:37:06 +1000 Subject: [rspec-users] any way to have a different SOUND from growl for a 'pass' rather than a 'fail' when using "./script/autospec" ??? Message-ID: Hi, Is there any way to have a different SOUND from growl for a 'pass' rather than a 'fail' when using "./script/autospec" ??? thanks From ashley.moran at patchspace.co.uk Sun Nov 9 07:27:23 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 9 Nov 2008 12:27:23 +0000 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: <85d99afe0811071818m472d3538y7fa927fef48fb785@mail.gmail.com> References: <85d99afe0811071748o7cfc1d84pf09593a20d8d78bc@mail.gmail.com> <85d99afe0811071818m472d3538y7fa927fef48fb785@mail.gmail.com> Message-ID: <9F35163A-250D-4E95-B91D-4A004D5639E2@patchspace.co.uk> On Nov 08, 2008, at 2:18 am, Zach Dennis wrote: > wrote: >> yep - this was recommended on forums over float - why? > > You are in for a lot of headaches in you application resorting to > decimal fields in the database, since it restores them as BigDecimals. > It sucks to deal with BigDecimals in your app. I very highly recommend > the Money library. I recommend installing it as a plugin and using the > CollectiveIdea fork. Ha, I wrote the ActiveRecord patch so this was possible :) The reason for storing monetary values as SQL decimals is that they aren't subject to rounding errors[1]. I used to work in the finance sector, and it was absolutely unacceptable to expose financial calculations to these errors. Hence I added support in ActiveRecord so we could use Rails; it was just not an option otherwise. The decision you have to make is between the extra effort now of using decimals in your code vs the extra effort later of explaining to your users why your calculations sometimes come out wrong. And that depends on how much your users value knowing that these figures are correct. Ashley [1] http://www.theregister.co.uk/2006/08/12/floating_point_approximation/ -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Sun Nov 9 09:53:27 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sun, 9 Nov 2008 15:53:27 +0100 Subject: [rspec-users] TextMate File Type Detection for RSpec & Rails In-Reply-To: References: Message-ID: <7047af2c50bc2d699e9f4779b974b83f@ruby-forum.com> Carl Porth wrote: > For those of you struggling with TextMate not properly detecting > rspec files, Allan Odgaard (the author of TextMate) has kindly > provided a tutorial on how to set up TextMate to associate all .rb > files with rails and all _spec.rb files with rspec. > > http://macromates.com/blog/2007/file-type-detection-rspec-rails > > His instructions work great and switching between rspec and rails > files has never been easier. > > Carl Fantastic! I was just looking for a way to fix that annoying detection problem. -- Posted via http://www.ruby-forum.com/. From joshknowles at gmail.com Sun Nov 9 11:55:56 2008 From: joshknowles at gmail.com (Josh Knowles) Date: Sun, 9 Nov 2008 11:55:56 -0500 Subject: [rspec-users] [Cucumber] The User Story File In-Reply-To: <9F827099-FE9B-4D0B-8C6B-BEE2E9F5CE64@mattwynne.net> References: <7ac2300c0811070624y24894c8bo84eab7381c0462fc@mail.gmail.com> <57c63afe0811071830u42017a57k43cbcafd6c261c78@mail.gmail.com> <9F827099-FE9B-4D0B-8C6B-BEE2E9F5CE64@mattwynne.net> Message-ID: On Sat, Nov 8, 2008 at 12:48 PM, Matt Wynne wrote: > So does your stakeholder break the build when this happens? Isn't it just > broken most of the time in that case? More often then not they end up just creating pending scenarios that need to be implemented, as opposed to breaking the build. We have the luxury of all being in the same room, so we try and communicate if there are any questions or concerns on the changes that they are making. -- Josh Knowles phone: 509-979-1593 email: joshknowles at gmail.com web: http://joshknowles.com From lists at ruby-forum.com Sun Nov 9 12:05:00 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sun, 9 Nov 2008 18:05:00 +0100 Subject: [rspec-users] A smarter autospec? Message-ID: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> Let's say I change a method in one of my models in a Rails app. I hit save: autospec kicks in and starts specing. But I haven't yet edited my spec(s) to the new method name so the specs will obviously fail, but I already know that. So I edit my specs. Autospec will run a second time (or even more if more than one spec file is changed). But I haven't yet edited my controller(s) to reflect the new change(s), so I edit more files and save, therefore Autospec will run again. In such case (which happens often), autospec has been running a few times for nothing. Would it be possible to implement a sort of timeout (like 10") to let us make additional changes to other files before autospec starts his job? It's pretty annoying to have growl display plenty error messages as we already know specs will fail. -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Sun Nov 9 12:13:09 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 9 Nov 2008 17:13:09 +0000 Subject: [rspec-users] A smarter autospec? In-Reply-To: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> References: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> Message-ID: <6893FC76-FD6F-4EDD-A9EF-CC912893A585@mattwynne.net> On 9 Nov 2008, at 17:05, Fernando Perez wrote: > Let's say I change a method in one of my models in a Rails app. > > I hit save: autospec kicks in and starts specing. > > But I haven't yet edited my spec(s) to the new method name so the > specs > will obviously fail, but I already know that. So I edit my specs. > Autospec will run a second time (or even more if more than one spec > file > is changed). > > But I haven't yet edited my controller(s) to reflect the new > change(s), > so I edit more files and save, therefore Autospec will run again. > > In such case (which happens often), autospec has been running a few > times for nothing. Would it be possible to implement a sort of timeout > (like 10") to let us make additional changes to other files before > autospec starts his job? It's pretty annoying to have growl display > plenty error messages as we already know specs will fail. Personally, I draw great comfort from those error messages. http://www.google.co.uk/search?q=red+green+refactor cheers, Matt From josephwilk at joesniff.co.uk Sun Nov 9 12:16:23 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Sun, 09 Nov 2008 17:16:23 +0000 Subject: [rspec-users] A smarter autospec? In-Reply-To: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> References: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> Message-ID: <49171AE7.3010402@googlemail.com> Fernando Perez wrote: > Let's say I change a method in one of my models in a Rails app. > > I hit save: autospec kicks in and starts specing. > > But I haven't yet edited my spec(s) to the new method name so the specs > will obviously fail, but I already know that. So I edit my specs. > Autospec will run a second time (or even more if more than one spec file > is changed). > > But I haven't yet edited my controller(s) to reflect the new change(s), > so I edit more files and save, therefore Autospec will run again. > > In such case (which happens often), autospec has been running a few > times for nothing. Would it be possible to implement a sort of timeout > (like 10") to let us make additional changes to other files before > autospec starts his job? It's pretty annoying to have growl display > plenty error messages as we already know specs will fail. > The problem is I would want feedback asap on a fail. The faster I get feedback the earlier I realize I've broken something and the easier it will be to localise the error. I think getting error messages I already know about is easily worth the sacrifice of this. -- Joseph Wilk http://blog.josephwilk.net From ashley.moran at patchspace.co.uk Sun Nov 9 12:26:47 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 9 Nov 2008 17:26:47 +0000 Subject: [rspec-users] A smarter autospec? In-Reply-To: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> References: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> Message-ID: On Nov 09, 2008, at 5:05 pm, Fernando Perez wrote: > Let's say I change a method in one of my models in a Rails app. > > I hit save: autospec kicks in and starts specing. > > But I haven't yet edited my spec(s) to the new method name so the > specs > will obviously fail, but I already know that. So I edit my specs. > Autospec will run a second time (or even more if more than one spec > file > is changed). Why are you routinely changing the code without updating the specs in advance? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Sun Nov 9 12:58:43 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sun, 9 Nov 2008 18:58:43 +0100 Subject: [rspec-users] A smarter autospec? In-Reply-To: References: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> Message-ID: <7eef0e0433358b172263d63fd5c02359@ruby-forum.com> > Why are you routinely changing the code without updating the specs in > advance? > > Ashley That's not the point of my question. Anyway I have just discovered TextMate has a "save-all" keyboard shortcut that works exactly as I want it. Now autospec runs only once. Sweet :-) -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Sun Nov 9 14:07:32 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 9 Nov 2008 19:07:32 +0000 Subject: [rspec-users] A smarter autospec? In-Reply-To: <7eef0e0433358b172263d63fd5c02359@ruby-forum.com> References: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> <7eef0e0433358b172263d63fd5c02359@ruby-forum.com> Message-ID: <353F5397-3F66-49AA-9564-C7A26C75A5F4@patchspace.co.uk> On Nov 09, 2008, at 5:58 pm, Fernando Perez wrote: >> Why are you routinely changing the code without updating the specs in >> advance? > > That's not the point of my question. I learnt early on when I joined this list, that whenever I ask a question of the form "When I do XXX, I get weird/undesirable behaviour, how do I avoid it?", 90%+ of the time the answer is of the form "Don't do XXX."*. What you were describing sounded like something you shouldn't be doing often enough to worry about it's consequences, but I wanted to rule that out first... Ashley * Probably half the emails I write to rspec-users I delete without sending, because by the time I've explained the problem in enough detail, I realise I've answered my own question -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From caius at caius.name Sun Nov 9 14:35:55 2008 From: caius at caius.name (Caius Durling) Date: Sun, 9 Nov 2008 19:35:55 +0000 Subject: [rspec-users] A smarter autospec? In-Reply-To: <353F5397-3F66-49AA-9564-C7A26C75A5F4@patchspace.co.uk> References: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> <7eef0e0433358b172263d63fd5c02359@ruby-forum.com> <353F5397-3F66-49AA-9564-C7A26C75A5F4@patchspace.co.uk> Message-ID: On 9 Nov 2008, at 19:07, Ashley Moran wrote: > * Probably half the emails I write to rspec-users I delete without > sending, because by the time I've explained the problem in enough > detail, I realise I've answered my own question Technical term is "Teddy Bear Programming" :) C --- Caius Durling caius at caius.name +44 (0) 7960 268 100 http://caius.name/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashley.moran at patchspace.co.uk Sun Nov 9 15:07:15 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 9 Nov 2008 20:07:15 +0000 Subject: [rspec-users] A smarter autospec? In-Reply-To: References: <3109eb24b15874c2c4c9637f0dbc7e55@ruby-forum.com> <7eef0e0433358b172263d63fd5c02359@ruby-forum.com> <353F5397-3F66-49AA-9564-C7A26C75A5F4@patchspace.co.uk> Message-ID: <34D1FE40-5261-4805-9A0A-CECF5A05A2EF@patchspace.co.uk> On Nov 09, 2008, at 7:35 pm, Caius Durling wrote: >> * Probably half the emails I write to rspec-users I delete without >> sending, because by the time I've explained the problem in enough >> detail, I realise I've answered my own question > > > Technical term is "Teddy Bear Programming" :) So it is :) http://headrush.typepad.com/creating_passionate_users/2005/01/rubberducking_a.html And it's known as rubber-ducking too. There's a definite Sesame Street vibe here. From now on all my programming sessions are going to look like this: http://uk.youtube.com/watch?v=B8IfCSnYPYo And I'll have NO bugs! Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Sun Nov 9 16:07:37 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 9 Nov 2008 21:07:37 +0000 Subject: [rspec-users] =?windows-1252?q?How_to_spec_a_=28Trollop-based=29_?= =?windows-1252?q?binary=92s_internal_state=3F?= In-Reply-To: <20081107172421.GI22622@durance.shot.pl> References: <20081107130551.GC22622@durance.shot.pl> <20081107172421.GI22622@durance.shot.pl> Message-ID: <1FE91266-D2EB-436E-B814-4FBF53B18740@patchspace.co.uk> On Nov 07, 2008, at 5:24 pm, Shot (Piotr Szotkowski) wrote: > Right, that?s why I suggested I could Kernel#eval the binary?s > contents > in the current process instead. This would require tricking Trollop, > but > I assume I could trick it by hand-crafting ARGV. You might find Rick Bradley's talk[1] on regression testing flog useful here. He starts by speccing the binary at a Ruby level. Note, however, that later in the talk he admits he made a mistake in not writing end-to-end tests soon enough. I think he should have run the binary as a black box and just pushed binary code into lib sooner. > Ah, Cucumber. :) I?ve yet to write my first story; I somehow assumed > these are more oriented toward non-programmers and/or for driving > implementation on a rather higher level, and have to be ?implemented? > on the RSpec level somehow anyway. I take that these assumptions are > flawed. :) Yes and no. I wouldn't say they are oriented towards the end user - Cucumber files are code and must be formatted strictly. But they are readable enough that they can be understood by the end user. You don't actually need to use RSpec in Cucumber steps - just raising an exception when you see something you don't like is enough - but the matchers make the steps readable. I recommending stopping the line until you have your current functionality described in Cucumber feature definitions, it will save you a lot of pain in the long run. > Hm, I guess I simply need to read up on Cucumber and stories; > I still can?t see how this kind of specification would differ > (in the end) from Kernel#`-based RSpec ? i.e., why implementing > the code behind these stories would side-step the underlying issue. > (But the last time I read on stories was pre-Cucumber.) Cucumber with Kernel#` and RSpec with Kernel#` would achieve the same thing, the difference being the structure of the files. Cucumber is optimised to deal with higher-lever concepts, where natural language is a more important part of the spec. RSpec is more suited to lower- level specs where the aim is to cover every edge case or object interaction. This would be too cumbersome with Cucumber. > Is there an example of story/Cucumber-based specification > of a binary?s behaviour available somewhere out there? There is now :) Well, it's a really crappy, trivial example I just made it about 10 mins. No use of STDERR, no file input/output, no network connections. Flagrant abuse of FIT tables. Oh, and wanton sharing of data between steps. But apart from that it's model code. Don't take any of this as best practice! It's just to show the concept (seeing how "sort" is presumably written in C): # sort.feature Feature: sort So that I can search faster As a person that likes searching I want to sort data Scenario: data ordered already Given the following data: | STDIN | | apple | | banana | | cherry | | mango | | pear | When I sort the data Then the output should be: | STDOUT | | apple | | banana | | cherry | | mango | | pear | Scenario: data out of order Given the following data: | STDIN | | pear | | mango | | apple | | cherry | | banana | When I sort the data Then the output should be: | STDOUT | | apple | | banana | | cherry | | mango | | pear | # steps/sort.rb require 'spec' Given %r/^the following data:$/ do |table| @stdin = table.hashes.map { |r| r["STDIN"] }.join("\n") end When %r/^I sort the data$/ do @result = `sort < References: <85d99afe0811071748o7cfc1d84pf09593a20d8d78bc@mail.gmail.com> <85d99afe0811071818m472d3538y7fa927fef48fb785@mail.gmail.com> <9F35163A-250D-4E95-B91D-4A004D5639E2@patchspace.co.uk> Message-ID: Ashley - what's you're recommendation re using BigDecimal (which does work as you point out) and the Money gem (which it sounds like makes a dev's life a bit easier)??? Is it worth trying to port an application from use of BigDecimal to Money gem??? On Sun, Nov 9, 2008 at 10:27 PM, Ashley Moran wrote: > > On Nov 08, 2008, at 2:18 am, Zach Dennis wrote: > >> wrote: >>> >>> yep - this was recommended on forums over float - why? >> >> You are in for a lot of headaches in you application resorting to >> decimal fields in the database, since it restores them as BigDecimals. >> It sucks to deal with BigDecimals in your app. I very highly recommend >> the Money library. I recommend installing it as a plugin and using the >> CollectiveIdea fork. > > > Ha, I wrote the ActiveRecord patch so this was possible :) > > The reason for storing monetary values as SQL decimals is that they aren't > subject to rounding errors[1]. I used to work in the finance sector, and it > was absolutely unacceptable to expose financial calculations to these > errors. Hence I added support in ActiveRecord so we could use Rails; it was > just not an option otherwise. > > The decision you have to make is between the extra effort now of using > decimals in your code vs the extra effort later of explaining to your users > why your calculations sometimes come out wrong. And that depends on how > much your users value knowing that these figures are correct. > > Ashley > > > [1] http://www.theregister.co.uk/2006/08/12/floating_point_approximation/ > > -- > 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 Mon Nov 10 06:10:17 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 10 Nov 2008 11:10:17 +0000 Subject: [rspec-users] any tricks re using " eql(5.5)", but where 5.5 is a decimal not float? In-Reply-To: References: <85d99afe0811071748o7cfc1d84pf09593a20d8d78bc@mail.gmail.com> <85d99afe0811071818m472d3538y7fa927fef48fb785@mail.gmail.com> <9F35163A-250D-4E95-B91D-4A004D5639E2@patchspace.co.uk> Message-ID: On Nov 10, 2008, at 12:21 am, Greg Hauptmann wrote: > Ashley - what's you're recommendation re using BigDecimal (which does > work as you point out) and the Money gem (which it sounds like makes a > dev's life a bit easier)??? Is it worth trying to port an application > from use of BigDecimal to Money gem??? Hi Greg I'd use the money gem if and only if it's underlying implementation is BigDecimal or some other fixed-precision system. I've had a look over it and it appears to use integers to store values as small as 1/100 of the base unit. So as long as you don't need to use anything smaller than that in calculations (ie, you only add, and never multiply, values - eg for tax calculations) it will be fine. I'll try not to say too much more, we're straying well away from RSpec territory... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From nick at deadorange.com Mon Nov 10 13:53:05 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 10 Nov 2008 13:53:05 -0500 Subject: [rspec-users] Running an entire #describe block Message-ID: <2A2E4572-3A66-4ED9-AF3C-911D1651CE85@deadorange.com> I know that it's possible to run a single spec example (IE: #it block) with the -e option for script/spec . Is it possible to run an entire context (IE: #describe block)? Cheers, Nick From mark at mwilden.com Mon Nov 10 14:06:22 2008 From: mark at mwilden.com (Mark Wilden) Date: Mon, 10 Nov 2008 11:06:22 -0800 Subject: [rspec-users] Running an entire #describe block In-Reply-To: <2A2E4572-3A66-4ED9-AF3C-911D1651CE85@deadorange.com> References: <2A2E4572-3A66-4ED9-AF3C-911D1651CE85@deadorange.com> Message-ID: <3c30da400811101106i1a08f6c1o524b95a420243c09@mail.gmail.com> On Mon, Nov 10, 2008 at 10:53 AM, Nick Hoffman wrote: > I know that it's possible to run a single spec example (IE: #it block) with > the -e option for script/spec . Is it possible to run an entire context (IE: > #describe block)? > Use the -l option to specify the line number of the describe call. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Mon Nov 10 16:26:32 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 10 Nov 2008 16:26:32 -0500 Subject: [rspec-users] Running an entire #describe block In-Reply-To: <3c30da400811101106i1a08f6c1o524b95a420243c09@mail.gmail.com> References: <2A2E4572-3A66-4ED9-AF3C-911D1651CE85@deadorange.com> <3c30da400811101106i1a08f6c1o524b95a420243c09@mail.gmail.com> Message-ID: <987CE512-B686-40EB-A7E6-F35043AFC353@deadorange.com> On 2008-11-10, at 14:06, Mark Wilden wrote: > On Mon, Nov 10, 2008 at 10:53 AM, Nick Hoffman > wrote: > I know that it's possible to run a single spec example (IE: #it > block) with the -e option for script/spec . Is it possible to run an > entire context (IE: #describe block)? > > Use the -l option to specify the line number of the describe call. > > ///ark Hi Mark. I've tried -l (that's a lower-case "L"), but it never executes any specs. Am I using it wrong?: http://pastie.org/311721 Thanks, Nick From nick at deadorange.com Mon Nov 10 16:44:19 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 10 Nov 2008 16:44:19 -0500 Subject: [rspec-users] Specs for authorisation Message-ID: <20AEB3CA-B606-4835-9403-1005893E2902@deadorange.com> I'm writing specs to check that certain user types are authorised to access certain controller actions. In addition to writing specs for authorised user types and for users who aren't logged-in, I feel that I should write specs for all of the other user types. However, the number of examples that must be written quickly soars as the number of user types and controller actions increase. Other than writing methods and/or shared examples to mock and stub logging different types of users in, what can be done to reduce the size of the spec files...or should I not care about that? Thanks, Nick From chris at cobaltedge.com Mon Nov 10 16:51:56 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Mon, 10 Nov 2008 13:51:56 -0800 Subject: [rspec-users] any way to have a different SOUND from growl for a 'pass' rather than a 'fail' when using "./script/autospec" ??? In-Reply-To: References: Message-ID: <443c240c0811101351t380a7726l5f7dbb66e589af20@mail.gmail.com> I'm not sure what platform you're on, or if this is what you're after, but the .autospec I use on the Mac uses the built in speech stuff to say what happens at the end of an autotest run. So, it tells me things like "all tests passed", or "tests passed" (depends on whether or not it ran the full suite, or just a changed file/spec), "some pending", and of course fails. I use different voices depending on the results :) http://gist.github.com/23649 On Sat, Nov 8, 2008 at 12:37 PM, Greg Hauptmann < greg.hauptmann.ruby at gmail.com> wrote: > Hi, > > Is there any way to have a different SOUND from growl for a 'pass' > rather than a 'fail' when using "./script/autospec" ??? > > thanks > _______________________________________________ > 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 mark at mwilden.com Mon Nov 10 17:12:47 2008 From: mark at mwilden.com (Mark Wilden) Date: Mon, 10 Nov 2008 14:12:47 -0800 Subject: [rspec-users] Running an entire #describe block In-Reply-To: <987CE512-B686-40EB-A7E6-F35043AFC353@deadorange.com> References: <2A2E4572-3A66-4ED9-AF3C-911D1651CE85@deadorange.com> <3c30da400811101106i1a08f6c1o524b95a420243c09@mail.gmail.com> <987CE512-B686-40EB-A7E6-F35043AFC353@deadorange.com> Message-ID: <3c30da400811101412h62e960cdq5354acc88bc0cc7@mail.gmail.com> On Mon, Nov 10, 2008 at 1:26 PM, Nick Hoffman wrote: > On 2008-11-10, at 14:06, Mark Wilden wrote: > >> On Mon, Nov 10, 2008 at 10:53 AM, Nick Hoffman >> wrote: >> I know that it's possible to run a single spec example (IE: #it block) >> with the -e option for script/spec . Is it possible to run an entire context >> (IE: #describe block)? >> >> Use the -l option to specify the line number of the describe call. >> >> ///ark >> > > Hi Mark. I've tried -l (that's a lower-case "L"), but it never executes any > specs. Am I using it wrong?: > http://pastie.org/311721 > I have to admit that I don't use -l to run a describe block very often, but it does seem to work when I do. However, after playing around a bit, I found that -l works on the innermost block, but not on enclosing blocks (0 examples), which matches what you're seeing. So I guess it only works with the innermost block. Rats. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Mon Nov 10 17:54:36 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 10 Nov 2008 17:54:36 -0500 Subject: [rspec-users] Running an entire #describe block In-Reply-To: <3c30da400811101412h62e960cdq5354acc88bc0cc7@mail.gmail.com> References: <2A2E4572-3A66-4ED9-AF3C-911D1651CE85@deadorange.com> <3c30da400811101106i1a08f6c1o524b95a420243c09@mail.gmail.com> <987CE512-B686-40EB-A7E6-F35043AFC353@deadorange.com> <3c30da400811101412h62e960cdq5354acc88bc0cc7@mail.gmail.com> Message-ID: <2F5B4E3C-2EAF-495C-AE66-0D0ADDD10A4C@deadorange.com> On 2008-11-10, at 17:12, Mark Wilden wrote: > On Mon, Nov 10, 2008 at 1:26 PM, Nick Hoffman > wrote: > On 2008-11-10, at 14:06, Mark Wilden wrote: > On Mon, Nov 10, 2008 at 10:53 AM, Nick Hoffman > wrote: > I know that it's possible to run a single spec example (IE: #it > block) with the -e option for script/spec . Is it possible to run an > entire context (IE: #describe block)? > > Use the -l option to specify the line number of the describe call. > > ///ark > > Hi Mark. I've tried -l (that's a lower-case "L"), but it never > executes any specs. Am I using it wrong?: > http://pastie.org/311721 > > I have to admit that I don't use -l to run a describe block very > often, but it does seem to work when I do. However, after playing > around a bit, I found that -l works on the innermost block, but not > on enclosing blocks (0 examples), which matches what you're seeing. > So I guess it only works with the innermost block. Rats. Thanks for trying that out for me, Mark. The -l option does in fact work for me when I specify the line number for an inner-most #desrcibe . One of these days when I upgrade to the latest version of rspec, I'll log a ticket in Lighthouse. -Nick From greg.hauptmann.ruby at gmail.com Mon Nov 10 19:03:41 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Tue, 11 Nov 2008 10:03:41 +1000 Subject: [rspec-users] any way to have a different SOUND from growl for a 'pass' rather than a 'fail' when using "./script/autospec" ??? In-Reply-To: <443c240c0811101351t380a7726l5f7dbb66e589af20@mail.gmail.com> References: <443c240c0811101351t380a7726l5f7dbb66e589af20@mail.gmail.com> Message-ID: I'm on Mac too - so it may be as simple as changing the Growl Preferences to get this working then? (assuming I'm using vanilla Rspec gem). I've also customised (copy/pasted from a recommendation) my ~/.autotest file. Is this an issue? Does this file actually get used now I'm using RSpec and "./script/autospec" (as opposed to just using ZenTest's autotest)? regards Greg -------------------------------------- Macintosh-2:myequity greg$ cat ~/.autotest # -*- ruby -*- # NOTE Copy this to your home folder as .autotest # # Originally from http://wincent.com/knowledge-base/Setting_up_autotest_to_use_Growl # # Modifications: # * Minor refactoring to use .autotest_images directory # [Geoffrey Grosenbach http://peepcode.com] # * Test::Unit compatibility [Pat Nakajima] # module Autotest::Growl AUTOTEST_IMAGE_ROOT = "~/.autotest_images" def self.growl title, msg, img, pri=0, sticky="" # puts "GREGS: growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" end def self.growl_fail(output) # puts "GREGS: growl FAIL, #{output}" growl "FAIL", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/fail.png", 2 end def self.growl_pass(output) # puts "GREGS: growl_pass PASS, #{output}" growl "Pass", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/pass.png" end Autotest.add_hook :ran_command do |at| results = [at.results].flatten.join("\n") if results.include? 'tests' output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/) if output $~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output) end else output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/) if output $~[2].to_i > 0 ? growl_fail(output) : growl_pass(output) end end end end ------------------------------------------------------ On Tue, Nov 11, 2008 at 7:51 AM, Christopher Bailey wrote: > I'm not sure what platform you're on, or if this is what you're after, but > the .autospec I use on the Mac uses the built in speech stuff to say what > happens at the end of an autotest run. So, it tells me things like "all > tests passed", or "tests passed" (depends on whether or not it ran the full > suite, or just a changed file/spec), "some pending", and of course fails. I > use different voices depending on the results :) > http://gist.github.com/23649 > > On Sat, Nov 8, 2008 at 12:37 PM, Greg Hauptmann > wrote: >> >> Hi, >> >> Is there any way to have a different SOUND from growl for a 'pass' >> rather than a 'fail' when using "./script/autospec" ??? >> >> thanks >> _______________________________________________ >> 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 nick at deadorange.com Mon Nov 10 20:23:33 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 10 Nov 2008 20:23:33 -0500 Subject: [rspec-users] How to expect no layout Message-ID: <2B2C3943-BDF9-4A6A-BA97-A076BE800973@deadorange.com> Hey guys. I've told one of my controllers to not render a layout for a certain action: layout false, :only => :map_info_window Now I'm trying to spec that, but this: it 'should not render a layout' do controller.expect_render :layout do_get end fails with this: Spec::Mocks::MockExpectationError in 'PropertiesController handling GET /properties/1/map_info_window should not render a layout' Mock 'expect_render_mock_proxy' expected :render with (:layout) once, but received it 0 times I'm using RSpec v1.1.4 . I know it's old, but I haven't gotten around to upgrading yet! -Nick From srogers1 at gmail.com Mon Nov 10 20:56:32 2008 From: srogers1 at gmail.com (Steven Rogers) Date: Mon, 10 Nov 2008 19:56:32 -0600 Subject: [rspec-users] any way to have a different SOUND from growl for a 'pass' rather than a 'fail' when using "./script/autospec" ??? In-Reply-To: References: <443c240c0811101351t380a7726l5f7dbb66e589af20@mail.gmail.com> Message-ID: On Nov 10, 2008, at 6:03 PM, Greg Hauptmann wrote: > I'm on Mac too - so it may be as simple as changing the Growl > Preferences to get this working then? > (assuming I'm using vanilla Rspec gem). One easy way is to use qp - a command line utility for playing QuickTIme sounds. It's been removed from it's original home, but you can get it from the wayback machine: go to http://www.archive.org/index.php and search for: http://www.ed.com/qp/QP.dmg.gz then you can use qp in the script to play a sound file based on the event. SR From pergesu at gmail.com Tue Nov 11 00:53:37 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 10 Nov 2008 21:53:37 -0800 Subject: [rspec-users] Specs for authorisation In-Reply-To: <20AEB3CA-B606-4835-9403-1005893E2902@deadorange.com> (Nick Hoffman's message of "Mon\, 10 Nov 2008 16\:44\:19 -0500") References: <20AEB3CA-B606-4835-9403-1005893E2902@deadorange.com> Message-ID: Nick Hoffman writes: > I'm writing specs to check that certain user types are authorised to > access certain controller actions. In addition to writing specs for > authorised user types and for users who aren't logged-in, I feel that > I should write specs for all of the other user types. However, the > number of examples that must be written quickly soars as the number of > user types and controller actions increase. > > Other than writing methods and/or shared examples to mock and stub > logging different types of users in, what can be done to reduce the > size of the spec files...or should I not care about that? Please take a look at http://rubyforge.org/pipermail/rspec-users/2008-November/010076.html I think it'll help out. Once you express the authorization rules in domain terms on the controller side and implement them in the model, you will end up with one or two examples for the controller, and several for the model. The model specs are much tighter in focus, so if you extract any shared behaviors from them then you will have extracted the essence of the specs, rather than covering up a code smell as you would were you to abtract it at the controller level. Pat From greg.hauptmann.ruby at gmail.com Tue Nov 11 05:26:15 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Tue, 11 Nov 2008 20:26:15 +1000 Subject: [rspec-users] any way to have a different SOUND from growl for a 'pass' rather than a 'fail' when using "./script/autospec" ??? In-Reply-To: <443c240c0811101351t380a7726l5f7dbb66e589af20@mail.gmail.com> References: <443c240c0811101351t380a7726l5f7dbb66e589af20@mail.gmail.com> Message-ID: thanks Chris - the help in http://gist.github.com/23649 worked great On Tue, Nov 11, 2008 at 7:51 AM, Christopher Bailey wrote: > I'm not sure what platform you're on, or if this is what you're after, but > the .autospec I use on the Mac uses the built in speech stuff to say what > happens at the end of an autotest run. So, it tells me things like "all > tests passed", or "tests passed" (depends on whether or not it ran the full > suite, or just a changed file/spec), "some pending", and of course fails. I > use different voices depending on the results :) > http://gist.github.com/23649 > > On Sat, Nov 8, 2008 at 12:37 PM, Greg Hauptmann > wrote: >> >> Hi, >> >> Is there any way to have a different SOUND from growl for a 'pass' >> rather than a 'fail' when using "./script/autospec" ??? >> >> thanks >> _______________________________________________ >> 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 lists at ruby-forum.com Tue Nov 11 05:46:19 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 11 Nov 2008 11:46:19 +0100 Subject: [rspec-users] How to expect no layout In-Reply-To: <2B2C3943-BDF9-4A6A-BA97-A076BE800973@deadorange.com> References: <2B2C3943-BDF9-4A6A-BA97-A076BE800973@deadorange.com> Message-ID: <56cfd0bd254166361aac2846b0e78965@ruby-forum.com> Nick Hoffman wrote: > Hey guys. I've told one of my controllers to not render a layout for a > certain action: > layout false, :only => :map_info_window > > Now I'm trying to spec that, but this: > it 'should not render a layout' do > controller.expect_render :layout > do_get > end > > fails with this: > Spec::Mocks::MockExpectationError in 'PropertiesController handling > GET /properties/1/map_info_window should not render a layout' > Mock 'expect_render_mock_proxy' expected :render with (:layout) once, > but received it 0 times > > I'm using RSpec v1.1.4 . I know it's old, but I haven't gotten around > to upgrading yet! > -Nick Try: controller.should_receive(:layout).with(false, {:only => :map_info_window}) -- Posted via http://www.ruby-forum.com/. From nick at deadorange.com Tue Nov 11 08:51:25 2008 From: nick at deadorange.com (Nick Hoffman) Date: Tue, 11 Nov 2008 08:51:25 -0500 Subject: [rspec-users] How to expect no layout In-Reply-To: <56cfd0bd254166361aac2846b0e78965@ruby-forum.com> References: <2B2C3943-BDF9-4A6A-BA97-A076BE800973@deadorange.com> <56cfd0bd254166361aac2846b0e78965@ruby-forum.com> Message-ID: <3D34C5E7-A6CB-4418-AEB7-F67733556F36@deadorange.com> On 2008-11-11, at 05:46, Fernando Perez wrote: > Nick Hoffman wrote: >> Hey guys. I've told one of my controllers to not render a layout >> for a >> certain action: >> layout false, :only => :map_info_window >> >> Now I'm trying to spec that, but this: >> it 'should not render a layout' do >> controller.expect_render :layout >> do_get >> end >> >> fails with this: >> Spec::Mocks::MockExpectationError in 'PropertiesController handling >> GET /properties/1/map_info_window should not render a layout' >> Mock 'expect_render_mock_proxy' expected :render with (:layout) once, >> but received it 0 times >> >> I'm using RSpec v1.1.4 . I know it's old, but I haven't gotten around >> to upgrading yet! >> -Nick > > Try: > controller.should_receive(:layout).with(false, {:only => > :map_info_window}) Hi Fernando. Unfortunately, that didn't work either. It seems that the controller object in the "controller" variable doesn't actually receive the call to #layout : Spec::Mocks::MockExpectationError in 'PropertiesController handling GET /properties/1/map_info_window should not render a layout' Mock 'PropertiesController' expected :layout with (false, {:only=>:map_info_window}) once, but received it 0 times Thanks, Nick From dchelimsky at gmail.com Tue Nov 11 08:56:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Nov 2008 07:56:24 -0600 Subject: [rspec-users] How to expect no layout In-Reply-To: <56cfd0bd254166361aac2846b0e78965@ruby-forum.com> References: <2B2C3943-BDF9-4A6A-BA97-A076BE800973@deadorange.com> <56cfd0bd254166361aac2846b0e78965@ruby-forum.com> Message-ID: <57c63afe0811110556s2cc57596g8c3a9f32428a53f7@mail.gmail.com> On Tue, Nov 11, 2008 at 4:46 AM, Fernando Perez wrote: > Nick Hoffman wrote: >> Hey guys. I've told one of my controllers to not render a layout for a >> certain action: >> layout false, :only => :map_info_window >> >> Now I'm trying to spec that, but this: >> it 'should not render a layout' do >> controller.expect_render :layout >> do_get >> end >> >> fails with this: >> Spec::Mocks::MockExpectationError in 'PropertiesController handling >> GET /properties/1/map_info_window should not render a layout' >> Mock 'expect_render_mock_proxy' expected :render with (:layout) once, >> but received it 0 times >> >> I'm using RSpec v1.1.4 . I know it's old, but I haven't gotten around >> to upgrading yet! >> -Nick > > Try: > controller.should_receive(:layout).with(false, {:only => > :map_info_window}) Declarations like #layout happen when the class definition is interpreted (when the class is loaded) so you can't really intercept them the same way you do with calls that happen as a result of an action or an instance method call. One trick for spec'ing class level declarations is to set the expectation and reload the class file. I've seen this used successfully with models: ActiveRecord::Base.should_receive(:has_many).with(:cows) load RAILS_ROOT + "/app/models/cowboy.rb" Sadly, I've not seen that succeed with controllers. I'm not clear why yet, but there is something in Rails' internals that make it a challenge. One way I've handled this successfully is to integrate_views for this one example (in its own group) and specify that html elements from the layout are not present in the form. It's a brittle example, but it's only one. Any better approaches out there? From nick at deadorange.com Tue Nov 11 09:36:03 2008 From: nick at deadorange.com (Nick Hoffman) Date: Tue, 11 Nov 2008 09:36:03 -0500 Subject: [rspec-users] Specs for authorisation In-Reply-To: References: <20AEB3CA-B606-4835-9403-1005893E2902@deadorange.com> Message-ID: <46C48BF6-FB9F-486B-A9D0-44C8BE8DF9E9@deadorange.com> On 2008-11-11, at 00:53, Pat Maddox wrote: > Nick Hoffman writes: >> I'm writing specs to check that certain user types are authorised to >> access certain controller actions. In addition to writing specs for >> authorised user types and for users who aren't logged-in, I feel that >> I should write specs for all of the other user types. However, the >> number of examples that must be written quickly soars as the number >> of >> user types and controller actions increase. >> >> Other than writing methods and/or shared examples to mock and stub >> logging different types of users in, what can be done to reduce the >> size of the spec files...or should I not care about that? > > Please take a look at > http://rubyforge.org/pipermail/rspec-users/2008-November/010076.html I > think it'll help out. > > Once you express the authorization rules in domain terms on the > controller side and implement them in the model, you will end up with > one or two examples for the controller, and several for the model. > The > model specs are much tighter in focus, so if you extract any shared > behaviors from them then you will have extracted the essence of the > specs, rather than covering up a code smell as you would were you to > abtract it at the controller level. > > Pat Wow, that's embarassing on my part =P I remember enjoying that thread as it was being discussed, and that was only a couple of days ago! Apologies for the duplication, guys! Pat, thanks for pointing me to it again. Much appreciated. -Nick From byrnejb at harte-lyne.ca Tue Nov 11 15:00:56 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Tue, 11 Nov 2008 15:00:56 -0500 (EST) Subject: [rspec-users] Installing rspec, cucumber, et al. In-Reply-To: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> References: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> Message-ID: <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> I am confused. I ran this in my rails project root: $ git submodule status 3b76fda741dfe2de84b4d5a33766653589ad36fb vendor/plugins/rspec (1.1.4-22-g3b76fda) 5adb47e5bed39569b435fadf8c34bd836d4287d3 vendor/plugins/rspec-rails (1.1.4-10-g5adb47e) $ git update # does nothing I checked my .gitmodules and .git/config entries and they both say this: [submodule "vendor/plugins/rspec"] path = vendor/plugins/rspec url = git://github.com/dchelimsky/rspec.git [submodule "vendor/plugins/rspec-rails"] path = vendor/plugins/rspec-rails url = git://github.com/dchelimsky/rspec-rails.git However, the rspec.info page says the the most recent rspec version is 1.1.11. So, what is going on? Where is the 1.1.11 git repository? rspec.info points to http://github.com/dchelimsky/rspec/wikis/home which refers one to git://github.com/dchelimsky/rspec.git which is what I already have. Am I missing something obvious here? P.S. I am a digest subscriber so I very much appreciate a directly addressed copy of any replies (reply all); and I track the archives at ruby-forge when I have a question to the list outstanding but I see no traffic for this list after Tue Nov 11 09:36:03 EST 2008, including my own previous message. Is the list down or are the archives generated only periodically? -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From dchelimsky at gmail.com Tue Nov 11 15:05:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Nov 2008 14:05:05 -0600 Subject: [rspec-users] Installing rspec, cucumber, et al. In-Reply-To: <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> References: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> Message-ID: <57c63afe0811111205o1593f235h91a03aa0f88c5b84@mail.gmail.com> On Tue, Nov 11, 2008 at 2:00 PM, James B. Byrne wrote: > I am confused. I ran this in my rails project root: > > $ git submodule status > 3b76fda741dfe2de84b4d5a33766653589ad36fb vendor/plugins/rspec > (1.1.4-22-g3b76fda) > 5adb47e5bed39569b435fadf8c34bd836d4287d3 vendor/plugins/rspec-rails > (1.1.4-10-g5adb47e) > > $ git update # does nothing > > I checked my .gitmodules and .git/config entries and they both say this: > > [submodule "vendor/plugins/rspec"] > path = vendor/plugins/rspec > url = git://github.com/dchelimsky/rspec.git > [submodule "vendor/plugins/rspec-rails"] > path = vendor/plugins/rspec-rails > url = git://github.com/dchelimsky/rspec-rails.git > > > However, the rspec.info page says the the most recent rspec version is > 1.1.11. So, what is going on? Where is the 1.1.11 git repository? > rspec.info points to http://github.com/dchelimsky/rspec/wikis/home which > refers one to git://github.com/dchelimsky/rspec.git which is what I > already have. Am I missing something obvious here? You must have installed rspec during the short time we were using git-submodules. You'll want to remove them and reinstall as plugins (or as gems). Here's some info on un-doing git-submodules: http://pitupepito.homelinux.org/?p=24 Cheers, David > > P.S. > > I am a digest subscriber so I very much appreciate a directly addressed > copy of any replies (reply all); and > > I track the archives at ruby-forge when I have a question to the list > outstanding but I see no traffic for this list after Tue Nov 11 09:36:03 > EST 2008, including my own previous message. Is the list down or are the > archives generated only periodically? Not sure about this - I'll look into it. From byrnejb at harte-lyne.ca Tue Nov 11 15:16:57 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Tue, 11 Nov 2008 15:16:57 -0500 (EST) Subject: [rspec-users] Installing rspec, cucumber, et al. In-Reply-To: <57c63afe0811111205o1593f235h91a03aa0f88c5b84@mail.gmail.com> References: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> <57c63afe0811111205o1593f235h91a03aa0f88c5b84@mail.gmail.com> Message-ID: <36932.216.185.71.22.1226434617.squirrel@webmail.harte-lyne.ca> On Tue, November 11, 2008 15:05, David Chelimsky wrote: > > You must have installed rspec during the short time we were using > git-submodules. > > You'll want to remove them and reinstall as plugins (or as gems). > Here's some info on un-doing git-submodules: > Removing git submodules is well-practised art for me, much to my embarassment. However, I would like the present situation with respect to rspec and rspec-rails clarified for me. I seem to recall that at some point one had to have rspec installed as a plugin if one intended to use rspec-rails, which also had to be installed as a plugin. Has this situation been altered, are gems alone now sufficient? Regards, -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From byrnejb at harte-lyne.ca Tue Nov 11 10:20:47 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Tue, 11 Nov 2008 10:20:47 -0500 (EST) Subject: [rspec-users] Installing rspec, cucumber, et al. Message-ID: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> I have a project that I am returning to after some time away on other issues. When last I worked on it I had rspec and rspec for rails installed as git submodules but I recall that I also had to have rspec installed as a gem and that the gem and the plugin versions had to exactly match. Having read a little about cucumber I went tot he cucumber site and read this: If you use Git for your Rails app, add the following plugins: git submodule add git://github.com/aslakhellesoy/cucumber.git vendor/plugins/cucumber git submodule add git://github.com/brynary/webrat.git vendor/plugins/webrat git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec-rails ... Install Other dependencies gem install term-ansicolor treetop diff-lcs hpricot Bootstrap Cucumber You?ll need a Rake task and a couple of files that configure Cucumber for use with Ruby on Rails and Webrat. You create these with: ruby script/generate cucumber ... There is nowhere a mention of gems. I am aware that rspec was/is anything but stable in its configuration requirements so I wish to know: What is the exact canonical method of installing rspec and all dependences for use with cucumber. Are the gems gone, or simply unnecessary? Are the cucumber instructions out of date? Regards, -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From dchelimsky at gmail.com Tue Nov 11 15:44:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Nov 2008 14:44:53 -0600 Subject: [rspec-users] Installing rspec, cucumber, et al. In-Reply-To: <36932.216.185.71.22.1226434617.squirrel@webmail.harte-lyne.ca> References: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> <57c63afe0811111205o1593f235h91a03aa0f88c5b84@mail.gmail.com> <36932.216.185.71.22.1226434617.squirrel@webmail.harte-lyne.ca> Message-ID: <57c63afe0811111244n6ea4b680v9d4bf95609faa36c@mail.gmail.com> On Tue, Nov 11, 2008 at 2:16 PM, James B. Byrne wrote: > > On Tue, November 11, 2008 15:05, David Chelimsky wrote: > >> >> You must have installed rspec during the short time we were using >> git-submodules. >> >> You'll want to remove them and reinstall as plugins (or as gems). >> Here's some info on un-doing git-submodules: >> > > Removing git submodules is well-practised art for me, much to my > embarassment. However, I would like the present situation with respect to > rspec and rspec-rails clarified for me. I seem to recall that at some > point one had to have rspec installed as a plugin if one intended to use > rspec-rails, which also had to be installed as a plugin. Has this > situation been altered, are gems alone now sufficient? Your options are: system gems vendor/gems vendor/plugins The rspec-rails gem has a hard dependency on the rspec gem of the same version, so if you install rspec-rails-1.1.11.gem with dependencies, it will install rspec-1.1.11.gem as well. There have been reports of problems with system gems, so right now it seems the safest way is to use vendor/gems or vendor/pugins. HTH, David From mailing_lists at railsnewbie.com Tue Nov 11 15:47:56 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 11 Nov 2008 15:47:56 -0500 Subject: [rspec-users] Installing rspec, cucumber, et al. In-Reply-To: <57c63afe0811111244n6ea4b680v9d4bf95609faa36c@mail.gmail.com> References: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> <57c63afe0811111205o1593f235h91a03aa0f88c5b84@mail.gmail.com> <36932.216.185.71.22.1226434617.squirrel@webmail.harte-lyne.ca> <57c63afe0811111244n6ea4b680v9d4bf95609faa36c@mail.gmail.com> Message-ID: <182CDE1D-0D0E-488D-885A-E11DFCBD96C3@railsnewbie.com> On Nov 11, 2008, at 3:44 PM, David Chelimsky wrote: > On Tue, Nov 11, 2008 at 2:16 PM, James B. Byrne lyne.ca> wrote: >> >> On Tue, November 11, 2008 15:05, David Chelimsky wrote: >> >>> >>> You must have installed rspec during the short time we were using >>> git-submodules. >>> >>> You'll want to remove them and reinstall as plugins (or as gems). >>> Here's some info on un-doing git-submodules: >>> >> >> Removing git submodules is well-practised art for me, much to my >> embarassment. However, I would like the present situation with >> respect to >> rspec and rspec-rails clarified for me. I seem to recall that at >> some >> point one had to have rspec installed as a plugin if one intended >> to use >> rspec-rails, which also had to be installed as a plugin. Has this >> situation been altered, are gems alone now sufficient? > > Your options are: > > system gems > vendor/gems > vendor/plugins > > The rspec-rails gem has a hard dependency on the rspec gem of the same > version, so if you install rspec-rails-1.1.11.gem with dependencies, > it will install rspec-1.1.11.gem as well. > > There have been reports of problems with system gems, so right now it > seems the safest way is to use vendor/gems or vendor/pugins. +1 for vendor/plugins. It's the tested and tried method. Scott From byrnejb at harte-lyne.ca Tue Nov 11 15:56:14 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Tue, 11 Nov 2008 15:56:14 -0500 (EST) Subject: [rspec-users] Installing rspec, cucumber, et al. In-Reply-To: <57c63afe0811111244n6ea4b680v9d4bf95609faa36c@mail.gmail.com> References: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> <57c63afe0811111205o1593f235h91a03aa0f88c5b84@mail.gmail.com> <36932.216.185.71.22.1226434617.squirrel@webmail.harte-lyne.ca> <57c63afe0811111244n6ea4b680v9d4bf95609faa36c@mail.gmail.com> Message-ID: <44608.216.185.71.22.1226436974.squirrel@webmail.harte-lyne.ca> On Tue, November 11, 2008 15:44, David Chelimsky wrote: > > Your options are: > > system gems > vendor/gems > vendor/plugins > > The rspec-rails gem has a hard dependency on the rspec gem of the same > version, so if you install rspec-rails-1.1.11.gem with dependencies, > it will install rspec-1.1.11.gem as well. > Thank you very much for the information. I have, for the time being, installed rspec et al as system gems. If that causes problems for me then I will change to vendor gems and test that before bothering people with my woes. Regards, -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From pergesu at gmail.com Tue Nov 11 16:07:40 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 11 Nov 2008 13:07:40 -0800 Subject: [rspec-users] Installing rspec, cucumber, et al. In-Reply-To: <57c63afe0811111244n6ea4b680v9d4bf95609faa36c@mail.gmail.com> (David Chelimsky's message of "Tue\, 11 Nov 2008 14\:44\:53 -0600") References: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> <57c63afe0811111205o1593f235h91a03aa0f88c5b84@mail.gmail.com> <36932.216.185.71.22.1226434617.squirrel@webmail.harte-lyne.ca> <57c63afe0811111244n6ea4b680v9d4bf95609faa36c@mail.gmail.com> Message-ID: "David Chelimsky" writes: > On Tue, Nov 11, 2008 at 2:16 PM, James B. Byrne wrote: >> >> On Tue, November 11, 2008 15:05, David Chelimsky wrote: >> >>> >>> You must have installed rspec during the short time we were using >>> git-submodules. >>> >>> You'll want to remove them and reinstall as plugins (or as gems). >>> Here's some info on un-doing git-submodules: >>> >> >> Removing git submodules is well-practised art for me, much to my >> embarassment. However, I would like the present situation with respect to >> rspec and rspec-rails clarified for me. I seem to recall that at some >> point one had to have rspec installed as a plugin if one intended to use >> rspec-rails, which also had to be installed as a plugin. Has this >> situation been altered, are gems alone now sufficient? > > Your options are: > > system gems > vendor/gems > vendor/plugins > > The rspec-rails gem has a hard dependency on the rspec gem of the same > version, so if you install rspec-rails-1.1.11.gem with dependencies, > it will install rspec-1.1.11.gem as well. > > There have been reports of problems with system gems, so right now it > seems the safest way is to use vendor/gems or vendor/pugins. I thought it was vendor/gems that had problems? At any rate, I've been using system gems on several projects with no troubles. Pat From aslak.hellesoy at gmail.com Tue Nov 11 16:29:01 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 11 Nov 2008 22:29:01 +0100 Subject: [rspec-users] Installing rspec, cucumber, et al. In-Reply-To: <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> References: <52262.216.185.71.22.1226416847.squirrel@webmail.harte-lyne.ca> <35243.216.185.71.22.1226433656.squirrel@webmail.harte-lyne.ca> Message-ID: <8d961d900811111329s6d00a414s918d2b8252839818@mail.gmail.com> On Tue, Nov 11, 2008 at 9:00 PM, James B. Byrne wrote: > I am confused. I ran this in my rails project root: > > $ git submodule status > 3b76fda741dfe2de84b4d5a33766653589ad36fb vendor/plugins/rspec > (1.1.4-22-g3b76fda) > 5adb47e5bed39569b435fadf8c34bd836d4287d3 vendor/plugins/rspec-rails > (1.1.4-10-g5adb47e) > > $ git update # does nothing > Try this: cd vendor/plugins/rspec git checkout master git pull origin master cd ../../.. git status git add vendor/plugins/rspec git commit -m "Updated to newer RSpec" etc... HTH, Aslak > I checked my .gitmodules and .git/config entries and they both say this: > > [submodule "vendor/plugins/rspec"] > path = vendor/plugins/rspec > url = git://github.com/dchelimsky/rspec.git > [submodule "vendor/plugins/rspec-rails"] > path = vendor/plugins/rspec-rails > url = git://github.com/dchelimsky/rspec-rails.git > > > However, the rspec.info page says the the most recent rspec version is > 1.1.11. So, what is going on? Where is the 1.1.11 git repository? > rspec.info points to http://github.com/dchelimsky/rspec/wikis/home which > refers one to git://github.com/dchelimsky/rspec.git which is what I > already have. Am I missing something obvious here? > > P.S. > > I am a digest subscriber so I very much appreciate a directly addressed > copy of any replies (reply all); and > > I track the archives at ruby-forge when I have a question to the list > outstanding but I see no traffic for this list after Tue Nov 11 09:36:03 > EST 2008, including my own previous message. Is the list down or are the > archives generated only periodically? > > > -- > *** E-Mail is NOT a SECURE channel *** > James B. Byrne mailto:ByrneJB at Harte-Lyne.ca > Harte & Lyne Limited http://www.harte-lyne.ca > 9 Brockley Drive vox: +1 905 561 1241 > Hamilton, Ontario fax: +1 905 561 0757 > Canada L8E 3C3 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Nov 11 17:24:10 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 11 Nov 2008 23:24:10 +0100 Subject: [rspec-users] Specing based on user roles In-Reply-To: <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> Message-ID: <53b24e494802255d22b4bfac4635cb19@ruby-forum.com> > I've really moved away from shared example groups and started writing > more targeted macros. So I might do something like this: > > def for_roles *roles > roles.each do |role| > before(:each) { login_as role } > yield > end > end > > describe OrdersController do > describe "GET index" do > for_roles :admin, :sysadmin do |role| > it "..." do ... end > end > for_roles :sysadmin do |role| > it "..." do ... end > end > end > > describe "GET edit" do > for_roles :admin, :sysadmin do |role| > it "..." do ... end > end > for_roles :sysadmin do |role| > it "..." do ... end > end > end > end > I can't write my specs so that they work as expected. What does login_as look like? And where do you put this code? I am not sure mine (if working) gets initialized correctly. I think I have to write my specs from scratch. -- Posted via http://www.ruby-forum.com/. From nick at deadorange.com Tue Nov 11 17:30:36 2008 From: nick at deadorange.com (Nick Hoffman) Date: Tue, 11 Nov 2008 17:30:36 -0500 Subject: [rspec-users] Specing based on user roles In-Reply-To: <53b24e494802255d22b4bfac4635cb19@ruby-forum.com> References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> <53b24e494802255d22b4bfac4635cb19@ruby-forum.com> Message-ID: On 2008-11-11, at 17:24, Fernando Perez wrote: >> I've really moved away from shared example groups and started writing >> more targeted macros. So I might do something like this: >> >> def for_roles *roles >> roles.each do |role| >> before(:each) { login_as role } >> yield >> end >> end >> >> describe OrdersController do >> describe "GET index" do >> for_roles :admin, :sysadmin do |role| >> it "..." do ... end >> end >> for_roles :sysadmin do |role| >> it "..." do ... end >> end >> end >> >> describe "GET edit" do >> for_roles :admin, :sysadmin do |role| >> it "..." do ... end >> end >> for_roles :sysadmin do |role| >> it "..." do ... end >> end >> end >> end >> > > I can't write my specs so that they work as expected. What does > login_as > look like? And where do you put this code? I am not sure mine (if > working) gets initialized correctly. > > I think I have to write my specs from scratch. Hi Fernando. #login_as is a custom method that you need to write yourself. It should simply login as the given user, or a user with the given role. Its implementation will depend on which authentication and authorisation system you're using. Cheers, Nick From lists at ruby-forum.com Tue Nov 11 17:39:07 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 11 Nov 2008 23:39:07 +0100 Subject: [rspec-users] Specing based on user roles In-Reply-To: References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> <53b24e494802255d22b4bfac4635cb19@ruby-forum.com> Message-ID: <3289cdb4836a9bf96ac61ec9cfb70516@ruby-forum.com> Nick Hoffman wrote: > On 2008-11-11, at 17:24, Fernando Perez wrote: >>> describe OrdersController do >>> for_roles :admin, :sysadmin do |role| >> login_as >> look like? And where do you put this code? I am not sure mine (if >> working) gets initialized correctly. >> >> I think I have to write my specs from scratch. > > Hi Fernando. #login_as is a custom method that you need to write > yourself. It should simply login as the given user, or a user with the > given role. Its implementation will depend on which authentication and > authorisation system you're using. > > Cheers, > Nick I am using restful_authentication. I tried to look at their specs, but they are unreadable. So I am trying to throw together my own authentication mocker/stuber but with no luck. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 11 17:49:17 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Tue, 11 Nov 2008 23:49:17 +0100 Subject: [rspec-users] Specing based on user roles In-Reply-To: <3289cdb4836a9bf96ac61ec9cfb70516@ruby-forum.com> References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> <53b24e494802255d22b4bfac4635cb19@ruby-forum.com> <3289cdb4836a9bf96ac61ec9cfb70516@ruby-forum.com> Message-ID: <166dec707d7c36572ecd98af78076b26@ruby-forum.com> > > I am using restful_authentication. I tried to look at their specs, but > they are unreadable. So I am trying to throw together my own > authentication mocker/stuber but with no luck. Just to clear things out, can you tell me which snippet is correct: 1) get :index response.should be_redirect 2) response.should be_redirect get :index It appears to me that 1) is correct, as 2) seems to be messing up all my specs. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Tue Nov 11 18:10:08 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 11 Nov 2008 15:10:08 -0800 Subject: [rspec-users] Specing based on user roles In-Reply-To: <166dec707d7c36572ecd98af78076b26@ruby-forum.com> (Fernando Perez's message of "Tue\, 11 Nov 2008 23\:49\:17 +0100") References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> <53b24e494802255d22b4bfac4635cb19@ruby-forum.com> <3289cdb4836a9bf96ac61ec9cfb70516@ruby-forum.com> <166dec707d7c36572ecd98af78076b26@ruby-forum.com> Message-ID: Fernando Perez writes: >> >> I am using restful_authentication. I tried to look at their specs, but >> they are unreadable. So I am trying to throw together my own >> authentication mocker/stuber but with no luck. > > Just to clear things out, can you tell me which snippet is correct: > > 1) > get :index > response.should be_redirect > > 2) > response.should be_redirect > get :index > > > > It appears to me that 1) is correct, as 2) seems to be messing up all my > specs. Yep, #1 Pat From greg.hauptmann.ruby at gmail.com Tue Nov 11 18:16:08 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Wed, 12 Nov 2008 09:16:08 +1000 Subject: [rspec-users] what triggers "./script/autospec" to kick in? when I change my model it doesn't always retest Message-ID: Hi, Does anyone know what exactly trigger autospec to rerun tests? I ask as I have a model file that has spec tests for it, but I've noticed when I fix the line in the model file it's not automatically retriggering a retest (where I'd expect to see a pass whereas before it was a fail). If I close autospec & restart it then it gives the pass. Thanks From nick at deadorange.com Tue Nov 11 19:25:11 2008 From: nick at deadorange.com (Nick Hoffman) Date: Tue, 11 Nov 2008 19:25:11 -0500 Subject: [rspec-users] Mixing in spec helper methods Message-ID: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> I've written a module for my specs that contains a helper method, and am mixing the module into my specs with #include . It seems that the method must be called with an #it block. If it isn't, this error occurs: ... in `method_missing': undefined method `it_should_behave_like_an_action_that_sets_the_flash_notice' for Spec::Rails::Example::ControllerExampleGroup::Subclass_1:Class (NoMethodError) from ./spec/controllers/properties_controller_spec.rb:8 Is there a way to call my helper method from outside of an #it block? Here's the code: http://pastie.org/312680 Thanks! Nick From ben at benmabey.com Tue Nov 11 19:31:08 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 11 Nov 2008 17:31:08 -0700 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> Message-ID: <491A23CC.6040202@benmabey.com> Nick Hoffman wrote: > I've written a module for my specs that contains a helper method, and > am mixing the module into my specs with #include . It seems that the > method must be called with an #it block. If it isn't, this error occurs: > > ... in `method_missing': undefined method > `it_should_behave_like_an_action_that_sets_the_flash_notice' for > Spec::Rails::Example::ControllerExampleGroup::Subclass_1:Class > (NoMethodError) from ./spec/controllers/properties_controller_spec.rb:8 > > Is there a way to call my helper method from outside of an #it block? > Here's the code: > http://pastie.org/312680 > > Thanks! > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users It looks like you want those methods in your module as class method, not instance methods. Try extending, not including, your module (extend AuthSpecHelpers.) You might want to read my post about creating rspec macros as well: http://www.benmabey.com/2008/06/08/writing-macros-in-rspec/ -Ben From pergesu at gmail.com Tue Nov 11 19:39:28 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 11 Nov 2008 16:39:28 -0800 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> (Nick Hoffman's message of "Tue\, 11 Nov 2008 19\:25\:11 -0500") References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> Message-ID: Nick Hoffman writes: > I've written a module for my specs that contains a helper method, and > am mixing the module into my specs with #include . It seems that the > method must be called with an #it block. If it isn't, this error > occurs: > > ... in `method_missing': undefined method > it_should_behave_like_an_action_that_sets_the_flash_notice' for > Spec::Rails::Example::ControllerExampleGroup::Subclass_1:Class > (NoMethodError) from > ./spec/controllers/properties_controller_spec.rb:8 > > Is there a way to call my helper method from outside of an #it block? > Here's the code: > http://pastie.org/312680 You want extend instead of include. Also, if you want to share this among many example groups, you can do it in the config block instead of extending it in every single example group: Spec::Runner.configure do |config| config.extend AuthSpecHelpers end You can even do it for particular example group types if you want: Spec::Runner.configure do |config| config.extend AuthSpecHelpers, :type => :controller end Pat From dchelimsky at gmail.com Tue Nov 11 19:46:36 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Nov 2008 18:46:36 -0600 Subject: [rspec-users] what triggers "./script/autospec" to kick in? when I change my model it doesn't always retest In-Reply-To: References: Message-ID: <57c63afe0811111646i23f58a2duac6aba28949a20e3@mail.gmail.com> On Tue, Nov 11, 2008 at 5:16 PM, Greg Hauptmann wrote: > Hi, > > Does anyone know what exactly trigger autospec to rerun tests? > > I ask as I have a model file that has spec tests Please don't say "spec tests" lest you desire being banned from the list. Choose any of "specs," "tests" or even "rspec tests" but "spec tests" is like nails on a chalkboard to my eyes :) > for it, but I've > noticed when I fix the line in the model file it's not automatically > retriggering a retest (where I'd expect to see a pass whereas before > it was a fail). If I close autospec & restart it then it gives the > pass. autospec is a thin wrapper around autotest, so the issue is one of autotest mappings. What are the actual filenames and what directories are they in? > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jesse at jesseclark.com Tue Nov 11 19:51:59 2008 From: jesse at jesseclark.com (Jesse Clark) Date: Tue, 11 Nov 2008 16:51:59 -0800 (PST) Subject: [rspec-users] Correct way to spec partials In-Reply-To: <57c63afe0810260549i2d6f49c0o6e195fe65c1d2a9b@mail.gmail.com> References: <6e9d2bb40810231807p48485868td431255bb387ac7f@mail.gmail.com> <57c63afe0810260549i2d6f49c0o6e195fe65c1d2a9b@mail.gmail.com> Message-ID: On Oct 26, 4:49?am, "David Chelimsky" wrote: > 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 testpartials: 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. Where can I find more information about how various contexts affect the choice between #1 and #2? I have a partial that is shared by two view templates and I only want to test the partial once. So I created a new spec file with a describe block for the partial. The partial is passed some locals and I would like to test in my examples that these local variables are displayed as expected. How would I go about setting these in the example so they are available to the partial when it renders? Thanks, -Jesse From dchelimsky at gmail.com Tue Nov 11 19:49:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Nov 2008 18:49:24 -0600 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> Message-ID: <57c63afe0811111649r3de57fbalc0c47b9eb930f680@mail.gmail.com> On Tue, Nov 11, 2008 at 6:39 PM, Pat Maddox wrote: > Nick Hoffman writes: > >> I've written a module for my specs that contains a helper method, and >> am mixing the module into my specs with #include . It seems that the >> method must be called with an #it block. If it isn't, this error >> occurs: >> >> ... in `method_missing': undefined method >> it_should_behave_like_an_action_that_sets_the_flash_notice' for >> Spec::Rails::Example::ControllerExampleGroup::Subclass_1:Class >> (NoMethodError) from >> ./spec/controllers/properties_controller_spec.rb:8 >> >> Is there a way to call my helper method from outside of an #it block? >> Here's the code: >> http://pastie.org/312680 > > You want extend instead of include. > > Also, if you want to share this among many example groups, you can do it > in the config block instead of extending it in every single example > group: > > Spec::Runner.configure do |config| > config.extend AuthSpecHelpers > end > > You can even do it for particular example group types if you want: > > Spec::Runner.configure do |config| > config.extend AuthSpecHelpers, :type => :controller > end Note that config.extend was only added recently, in rspec-1.1.9. Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From greg.hauptmann.ruby at gmail.com Tue Nov 11 20:01:40 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Wed, 12 Nov 2008 11:01:40 +1000 Subject: [rspec-users] what triggers "./script/autospec" to kick in? when I change my model it doesn't always retest In-Reply-To: <57c63afe0811111646i23f58a2duac6aba28949a20e3@mail.gmail.com> References: <57c63afe0811111646i23f58a2duac6aba28949a20e3@mail.gmail.com> Message-ID: tks David - the files are: * app/models/recurring/projections.rb <== one I was changing & not always triggering a retest * spec/models/projections/projections_spec.rb <== where the associated tests are tks On Wed, Nov 12, 2008 at 10:46 AM, David Chelimsky wrote: > On Tue, Nov 11, 2008 at 5:16 PM, Greg Hauptmann > wrote: >> Hi, >> >> Does anyone know what exactly trigger autospec to rerun tests? >> >> I ask as I have a model file that has spec tests > > Please don't say "spec tests" lest you desire being banned from the > list. Choose any of "specs," "tests" or even "rspec tests" but "spec > tests" is like nails on a chalkboard to my eyes :) > >> for it, but I've >> noticed when I fix the line in the model file it's not automatically >> retriggering a retest (where I'd expect to see a pass whereas before >> it was a fail). If I close autospec & restart it then it gives the >> pass. > > autospec is a thin wrapper around autotest, so the issue is one of > autotest mappings. > > What are the actual filenames and what directories are they in? > >> >> Thanks >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mark at mwilden.com Tue Nov 11 20:22:27 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 11 Nov 2008 17:22:27 -0800 Subject: [rspec-users] what triggers "./script/autospec" to kick in? when I change my model it doesn't always retest In-Reply-To: References: <57c63afe0811111646i23f58a2duac6aba28949a20e3@mail.gmail.com> Message-ID: <3c30da400811111722p71e449adp15f842940143c1d6@mail.gmail.com> On Tue, Nov 11, 2008 at 5:01 PM, Greg Hauptmann < greg.hauptmann.ruby at gmail.com> wrote: > > * app/models/recurring/projections.rb <== one I was changing & not > always triggering a retest > * spec/models/projections/projections_spec.rb <== where the associated > tests are > The model and the spec are in different subdirectories under app and spec. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.hauptmann.ruby at gmail.com Tue Nov 11 21:00:55 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Wed, 12 Nov 2008 12:00:55 +1000 Subject: [rspec-users] what triggers "./script/autospec" to kick in? when I change my model it doesn't always retest In-Reply-To: <3c30da400811111722p71e449adp15f842940143c1d6@mail.gmail.com> References: <57c63afe0811111646i23f58a2duac6aba28949a20e3@mail.gmail.com> <3c30da400811111722p71e449adp15f842940143c1d6@mail.gmail.com> Message-ID: thanks - this seemed to fix it wonder why it was working for the first time run (i.e. tests were working) but just not re-triggering? just the way autotest works I guess On Wed, Nov 12, 2008 at 11:22 AM, Mark Wilden wrote: > On Tue, Nov 11, 2008 at 5:01 PM, Greg Hauptmann > wrote: >> >> * app/models/recurring/projections.rb <== one I was changing & not >> always triggering a retest >> * spec/models/projections/projections_spec.rb <== where the associated >> tests are > > The model and the spec are in different subdirectories under app and spec. > > ///ark > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Nov 11 21:05:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Nov 2008 20:05:01 -0600 Subject: [rspec-users] what triggers "./script/autospec" to kick in? when I change my model it doesn't always retest In-Reply-To: References: <57c63afe0811111646i23f58a2duac6aba28949a20e3@mail.gmail.com> <3c30da400811111722p71e449adp15f842940143c1d6@mail.gmail.com> Message-ID: <57c63afe0811111805y72f277c7r579d966d653717e7@mail.gmail.com> On Tue, Nov 11, 2008 at 8:00 PM, Greg Hauptmann wrote: > thanks - this seemed to fix it > > wonder why it was working for the first time run (i.e. tests were > working) but just not re-triggering? just the way autotest works I > guess The first time it loads everything in the spec directory, or spec/models if you type 'rake spec:models' etc etc etc After that it looks at changes and looks to the mappings to know what to do. > > On Wed, Nov 12, 2008 at 11:22 AM, Mark Wilden wrote: >> On Tue, Nov 11, 2008 at 5:01 PM, Greg Hauptmann >> wrote: >>> >>> * app/models/recurring/projections.rb <== one I was changing & not >>> always triggering a retest >>> * spec/models/projections/projections_spec.rb <== where the associated >>> tests are >> >> The model and the spec are in different subdirectories under app and spec. >> >> ///ark >> >> _______________________________________________ >> 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 richard.t.lloyd at gmail.com Wed Nov 12 00:22:47 2008 From: richard.t.lloyd at gmail.com (Richard Lloyd) Date: Tue, 11 Nov 2008 19:22:47 -1000 Subject: [rspec-users] Is this a bug? Message-ID: <5e171bfa0811112122y36528a64q1b1f6e96c8464595@mail.gmail.com> I'm new to rspec and, of course, my first time out and I'm tripped up by what appears to me to be a bug. A simple demonstration: script/generate rspec_scaffold GoodDocument title:string body:text >From spec/views/good_documents/edit.html.erb_spec.rb: before(:each) do assigns[:good_document] = @good_document = stub_model(GoodDocument, :new_record? => false, :title => "value for title", :body => "value for body" ) end script/generate rspec_scaffold BadDocument some_id:integer title:string body:text someother_id:integer >From spec/views/bad_documents/edit.html.erb_spec.rb: before(:each) do assigns[:bad_document] = @bad_document = stub_model(BadDocument, :new_record? => false, :title => "value for title", :body => "value for body", ) end Notice how bad_documents/edit...'s stub_model is missing both the *:..._id*fields and how the *:body* field line is comma terminated. After chasing down the comma (which caused rspec test to fail with a syntax error) I found that using * :..._identifier* will also trigger the problem. This only appears in the spec/views, spec/models have all attributes included in the * @valid_attributes* hash. So I think there are two problems here: 1) field name which includes some undefined magic will be silently untested in the generated view specs 2) same name if it occupies the last slot in the record will cause the test to fail due to spec format Rick -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Nov 12 00:27:32 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Nov 2008 23:27:32 -0600 Subject: [rspec-users] Is this a bug? In-Reply-To: <5e171bfa0811112122y36528a64q1b1f6e96c8464595@mail.gmail.com> References: <5e171bfa0811112122y36528a64q1b1f6e96c8464595@mail.gmail.com> Message-ID: <57c63afe0811112127u2a82bc52x69e21c042ebb5ce0@mail.gmail.com> On Tue, Nov 11, 2008 at 11:22 PM, Richard Lloyd wrote: > I'm new to rspec and, of course, my first time out and I'm tripped up by > what appears to me to be a bug. > > A simple demonstration: > > script/generate rspec_scaffold GoodDocument title:string body:text > > >From spec/views/good_documents/edit.html.erb_spec.rb: > > before(:each) do > assigns[:good_document] = @good_document = stub_model(GoodDocument, > :new_record? => false, > :title => "value for title", > :body => "value for body" > ) > end > > > script/generate rspec_scaffold BadDocument some_id:integer title:string > body:text someother_id:integer > > From spec/views/bad_documents/edit.html.erb_spec.rb: > > before(:each) do > assigns[:bad_document] = @bad_document = stub_model(BadDocument, > :new_record? => false, > :title => "value for title", > :body => "value for body", > ) > end > > Notice how bad_documents/edit...'s stub_model is missing both the :..._id > fields and how the :body field line is comma terminated. After chasing down > the comma (which caused rspec test to fail with a syntax error) I found that > using :..._identifier will also trigger the problem. This only appears in > the spec/views, spec/models have all attributes included in the > @valid_attributes hash. > > So I think there are two problems here: > > 1) field name which includes some undefined magic will be silently untested > in the generated view specs > 2) same name if it occupies the last slot in the record will cause the test > to fail due to spec format Yep - seems like a bug. Please file a bug report at http://rspec.lighthouseapp.com/projects/5645. Thanks, David > > Rick > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Wed Nov 12 03:11:50 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 12 Nov 2008 08:11:50 +0000 Subject: [rspec-users] Correct way to spec partials In-Reply-To: References: <6e9d2bb40810231807p48485868td431255bb387ac7f@mail.gmail.com> <57c63afe0810260549i2d6f49c0o6e195fe65c1d2a9b@mail.gmail.com> Message-ID: <9D8BF58C-2B7F-411F-BA07-57847A2A3E0E@mattwynne.net> On 12 Nov 2008, at 00:51, Jesse Clark wrote: > On Oct 26, 4:49 am, "David Chelimsky" wrote: >> 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 testpartials: 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. > > Where can I find more information about how various contexts affect > the choice between #1 and #2? > > I have a partial that is shared by two view templates and I only want > to test the partial once. So I created a new spec file with a describe > block for the partial. The partial is passed some locals and I would > like to test in my examples that these local variables are displayed > as expected. How would I go about setting these in the example so they > are available to the partial when it renders? What you can do is call the template from the example and set up a stub for each of the locals. So if I have a partial like this: <%= name %> makes cheese for <%= friend_name %> Then in the example, you can do this: describe "when there's a name and a friend name" before(:each) do template.stub!(:name).and_return("Mike") template.stub!(:friend_name).and_return("Susan") end end Make sense? In order to keep your view specs from becoming too brittle, I would strongly suggest that you 'stub out' the rendering of the shared partial in the specs for the two view templates that use the partial. I usually do this by making a special helper method for rendering the partial: <%= for relationship in relationships %> <%= render_relationship(relationship) %> <% end %> This makes is easy to stub out the rendering in your main view templates' specs: before(:each) do template.stub!(:render_relationship) end Of course you'll really want a Cucumber test that makes sure the whole stack fits together (locals are passed through with the correct names) but I'd suggest that's a much more flexible solution than tying your view specs together. HTH, Matt From lists at ruby-forum.com Wed Nov 12 04:18:16 2008 From: lists at ruby-forum.com (Mano ah) Date: Wed, 12 Nov 2008 10:18:16 +0100 Subject: [rspec-users] testing an action which requires picture Message-ID: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> How can i test the action of a controller which requires picture? I mean, as part of the test I want to pass a picture (somekind of fixture) and test to see if the result is correct -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Wed Nov 12 08:12:48 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 12 Nov 2008 13:12:48 +0000 Subject: [rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc Message-ID: My use case is that I want to be able to use a Logging::Logger[1] within my scenario code. I can create the logger explicitly within the step block, but this is a hackaround. I think I could monkey-patch Cucumber::Rails::World to include my logger, but that also feels dirty. Is there a nice clean way I can use on of the above (AFAIK undocumented) methods to help me? Better, is there some documentation / a blog post I can be pointed to so I can help myself? I have had a pretty thorough read of the code but I'm not quite there yet with my Ruby to make sufficient sense of it. cheers, Matt From dchelimsky at gmail.com Wed Nov 12 08:40:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Nov 2008 07:40:21 -0600 Subject: [rspec-users] testing an action which requires picture In-Reply-To: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> Message-ID: <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> On Wed, Nov 12, 2008 at 3:18 AM, Mano ah wrote: > How can i test the action of a controller which requires picture? > > I mean, as part of the test I want to pass a picture (somekind of > fixture) and test to see if the result is correct I'm pretty sure you're looking for this: http://api.rubyonrails.com/classes/ActionController/TestProcess.html#M000229 You can use fixture_file_upload with rspec-rails. In fact, you can use any of rails' test/unit helpers and extensions when working with rspec-rails. From aslak.hellesoy at gmail.com Wed Nov 12 08:30:42 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 12 Nov 2008 14:30:42 +0100 Subject: [rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc In-Reply-To: References: Message-ID: <8d961d900811120530i4258d8c4g37bbcf799d44d75e@mail.gmail.com> On Wed, Nov 12, 2008 at 2:12 PM, Matt Wynne wrote: > My use case is that I want to be able to use a Logging::Logger[1] within my > scenario code. > > I can create the logger explicitly within the step block, but this is a > hackaround. > > I think I could monkey-patch Cucumber::Rails::World to include my logger, > but that also feels dirty. > > Is there a nice clean way I can use on of the above (AFAIK undocumented) > methods to help me? > Try this: World do world = Object.new world.extend(Logging::Logger) world end Aslak > Better, is there some documentation / a blog post I can be pointed to so I > can help myself? I have had a pretty thorough read of the code but I'm not > quite there yet with my Ruby to make sufficient sense of it. > > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Nov 12 08:59:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Nov 2008 07:59:22 -0600 Subject: [rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc In-Reply-To: <8d961d900811120530i4258d8c4g37bbcf799d44d75e@mail.gmail.com> References: <8d961d900811120530i4258d8c4g37bbcf799d44d75e@mail.gmail.com> Message-ID: <57c63afe0811120559xc12bc80t66f0e6441900cac1@mail.gmail.com> On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy wrote: > On Wed, Nov 12, 2008 at 2:12 PM, Matt Wynne wrote: >> My use case is that I want to be able to use a Logging::Logger[1] within my >> scenario code. >> >> I can create the logger explicitly within the step block, but this is a >> hackaround. >> >> I think I could monkey-patch Cucumber::Rails::World to include my logger, >> but that also feels dirty. >> >> Is there a nice clean way I can use on of the above (AFAIK undocumented) >> methods to help me? >> > > Try this: > > World do > world = Object.new > world.extend(Logging::Logger) > world > end Or, since you're using Rails here: World do returning Cucumber::Rails::World do |world| world.extend(Logging::Logger) end end David > > Aslak > >> Better, is there some documentation / a blog post I can be pointed to so I >> can help myself? I have had a pretty thorough read of the code but I'm not >> quite there yet with my Ruby to make sufficient sense of it. >> >> 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 joahking at gmail.com Wed Nov 12 09:38:17 2008 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Wed, 12 Nov 2008 15:38:17 +0100 Subject: [rspec-users] Cucumber feature checking sort order of list Message-ID: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> hi there, I would like to assure in my scenario that the list shown is in the correct order (e.g. ASC or DESC). I can spec that but I feel it would be more client-oriented if I could do it in the feature... any ideas? thanks, joahking -------------- next part -------------- An HTML attachment was scrubbed... URL: From pe at dipe.de Wed Nov 12 10:05:20 2008 From: pe at dipe.de (Peter Ehrenberg) Date: Wed, 12 Nov 2008 16:05:20 +0100 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> Message-ID: 2008/11/12 Joaquin Rivera Padron : > I would like to assure in my scenario that the list shown is in the correct > order (e.g. ASC or DESC). > > I can spec that but I feel it would be more client-oriented if I could do it > in the feature... any ideas? You ask how to implement such a step? I've done this by using Hpricot - fetching the item-lines from the result into an array and checking this for the right order. Not very nice. Any better ideas? From joahking at gmail.com Wed Nov 12 10:31:53 2008 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Wed, 12 Nov 2008 16:31:53 +0100 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> Message-ID: <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> > You ask how to implement such a step? yes > I've done this by using Hpricot - fetching the item-lines from the result into > an array and checking this for the right order. thanks Peter, seems I will give that a try, though I like you do not like very much joaquin -------------- next part -------------- An HTML attachment was scrubbed... URL: From pe at dipe.de Wed Nov 12 10:47:27 2008 From: pe at dipe.de (Peter Ehrenberg) Date: Wed, 12 Nov 2008 16:47:27 +0100 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> Message-ID: 2008/11/12 Joaquin Rivera Padron : >> [...] > thanks Peter, seems I will give that a try, though I like you do not like > very much This is my code. Maybe it helps: Then /the title are in alphabetic order/ do # FIXME: Ugly titles = [] doc = Hpricot(response.body) (doc/"tr/td[1]/*/text()").each do |e| titles << e.to_s end titles.should == titles.sort end From aslak.hellesoy at gmail.com Wed Nov 12 10:53:39 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 12 Nov 2008 16:53:39 +0100 Subject: [rspec-users] ANN Cucumber 0.1.9 Message-ID: <8d961d900811120753j131130e5oca9694239653c130@mail.gmail.com> I'm pleased to announce Cucumber 0.1.9 - full changelog here: http://github.com/aslakhellesoy/cucumber/tree/v0.1.9/History.txt gem install cucumber (As usual, the gem will take a few hours to rsync around the world). With this release Cucumber supports 19 natural languages! Cucumber is now represented on all continents. Please send more translations. (I know that Australians say "Nifty shit" for "Feature", but I don't know the other words). Cucumber also has Autotest support now. It turns out Git+GitHub is working great for this project. There are 50+ forks and 300+ followers and I keep pulling in high quality improvements several times a week. I'd especially like to thank Joseph Wilk, who has contributed a ton of great features and fixes. Joseph is now part of the "official" Cucumber team. So what's next? A couple of things. I will focus on improving the internal structure of features to make it easier to manipulate the contents of features programmatically. I'm planning to introduce a better AST. For users of Cucumber this will not be noticeable, except that support for tables will be much better. One thing I have in mind is to be able to push actual values back into a table and open up for custom interpretation of tables. I also want to make it possible to customise how table "results" are displayed (for example comparing actual and expected values inside individual cells). When these internal changes start to take shape it's time to slap some REST around Cucumber so we can integrate it better with authoring tools. Then we will invite the customers to the party. Thanks to everybody who has reported bugs, come with suggestions and contributed code so far. Enjoy the new release! Cheers, Aslak From matt at mattwynne.net Wed Nov 12 10:55:36 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 12 Nov 2008 15:55:36 +0000 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> Message-ID: <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> How about something more like Given there are two items in a list: "Zulu and Abba" And I have sorted the list alphabetically Then "Abba" should appear before "Zulu" Then /"(.*)" should appear before "(.*)"/ do |first_example, second_example| response.body.should =~ /#{first_example}.*#{second_example}/ end On 12 Nov 2008, at 15:47, Peter Ehrenberg wrote: > 2008/11/12 Joaquin Rivera Padron : >>> [...] >> thanks Peter, seems I will give that a try, though I like you do >> not like >> very much > > This is my code. Maybe it helps: > > Then /the title are in alphabetic order/ do > # FIXME: Ugly > titles = [] > doc = Hpricot(response.body) > (doc/"tr/td[1]/*/text()").each do |e| > titles << e.to_s > end > titles.should == titles.sort > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From joahking at gmail.com Wed Nov 12 11:03:07 2008 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Wed, 12 Nov 2008 17:03:07 +0100 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> Message-ID: <8277b7f40811120803kc7f1e41v52de1b5f484deb7@mail.gmail.com> > Matt Wynne: > How about something more like > > Given there are two items in a list: "Zulu and Abba" > And I have sorted the list alphabetically > Then "Abba" should appear before "Zulu" > > Then /"(.*)" should appear before "(.*)"/ do |first_example, > second_example| > response.body.should =~ /#{first_example}.*#{second_example}/ > end yep, this one looks better to me thanks Matt jk -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Nov 12 11:12:07 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 12 Nov 2008 16:12:07 +0000 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: <8277b7f40811120803kc7f1e41v52de1b5f484deb7@mail.gmail.com> References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> <8277b7f40811120803kc7f1e41v52de1b5f484deb7@mail.gmail.com> Message-ID: <819744F5-5180-41EC-AABF-9A4DC1DC1651@mattwynne.net> On 12 Nov 2008, at 16:03, Joaquin Rivera Padron wrote: > > Matt Wynne: > How about something more like > > Given there are two items in a list: "Zulu and Abba" > And I have sorted the list alphabetically > Then "Abba" should appear before "Zulu" > > Then /"(.*)" should appear before "(.*)"/ do |first_example, > second_example| > response.body.should =~ /#{first_example}.*#{second_example}/ > end > > yep, this one looks better to me > thanks Matt Might not compile - I wrote it in my email client ;) The looser the better with these, IMO. Just enough to catch your code being broken, not a bit more. cheers, Matt From byrnejb at harte-lyne.ca Wed Nov 12 11:17:38 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Wed, 12 Nov 2008 11:17:38 -0500 (EST) Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: References: Message-ID: <39898.216.185.71.22.1226506658.squirrel@webmail.harte-lyne.ca> I have installed all of the various bit and pieces for rspec and cucumber and have used: script/generate feature Frooble name color description To create a dummy feature and related steps. Now, while I have been poking at Ruby, Rails, RSpec and Stories for a long time, I have never really grasped much of what I have been exposed to. Therefore, I crave your indulgence for the next little while as I buckle down to master this stuff. My questions over the next little while will likely be novice level. Taking the frooble skeleton I have reworked it to this: #manage_entities.feature Feature: Manage entities In order to keep track of entities A entity maintainer Should be able to manage entities To Protect Revenue Scenario: Register a new entity Given I am on the new entity page When I fill in "entity_name" with "My New Entity" And I fill in "entity_legal_name" with "My New Enitity is a CORP" And I fill in "entity_legal_form" with "CORP" And I press "Create" Then I should see "My New Entity" And I should see "My New Enitity is a CORP" And I should see "CORP" ... And #steps/entity_steps.rb Given /I am on the new entity page/ do visits "/entities/new" end ... When I run # rake features I see this: Feature: Manage entities # features/manage_entities.feature In order to keep track of entities A entity maintainer Should be able to manage multiple entities To Protect Revenue Scenario: Register a new entity # features/manage_entities.feature:7 Given I am on the new entity page # features/steps/entity_steps.rb:1 undefined method `visits' for # (NoMethodError) Now, "visits" is an action predefined in the step file, and one that I presume is connected somehow to webrat (installed), which means to me that I should not have to define it myself. Therefore my questions are: Is there some manual configuration I am required to do to wire this up correctly or am I missing the boat on this altogether? If there are additional set-up steps that I must perform then where to I discover them? Regards, -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From aslak.hellesoy at gmail.com Wed Nov 12 11:35:40 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 12 Nov 2008 17:35:40 +0100 Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: <39898.216.185.71.22.1226506658.squirrel@webmail.harte-lyne.ca> References: <39898.216.185.71.22.1226506658.squirrel@webmail.harte-lyne.ca> Message-ID: <8d961d900811120835h4443afddjf2f1d0fcb21cd15a@mail.gmail.com> On Wed, Nov 12, 2008 at 5:17 PM, James B. Byrne wrote: > I have installed all of the various bit and pieces for rspec and cucumber > and have used: > > script/generate feature Frooble name color description > > To create a dummy feature and related steps. Now, while I have been > poking at Ruby, Rails, RSpec and Stories for a long time, I have never > really grasped much of what I have been exposed to. Therefore, I crave > your indulgence for the next little while as I buckle down to master this > stuff. My questions over the next little while will likely be novice > level. > > Taking the frooble skeleton I have reworked it to this: > > #manage_entities.feature > > Feature: Manage entities > In order to keep track of entities > A entity maintainer > Should be able to manage entities > To Protect Revenue > > Scenario: Register a new entity > Given I am on the new entity page > When I fill in "entity_name" with "My New Entity" > And I fill in "entity_legal_name" with "My New Enitity is a CORP" > And I fill in "entity_legal_form" with "CORP" > And I press "Create" > Then I should see "My New Entity" > And I should see "My New Enitity is a CORP" > And I should see "CORP" > ... > > And > > #steps/entity_steps.rb > > Given /I am on the new entity page/ do > visits "/entities/new" > end > ... > > When I run # rake features I see this: > > Feature: Manage entities # features/manage_entities.feature > In order to keep track of entities > A entity maintainer > Should be able to manage multiple entities > To Protect Revenue > Scenario: Register a new entity # > features/manage_entities.feature:7 > Given I am on the new entity page # > features/steps/entity_steps.rb:1 > undefined method `visits' for > # (NoMethodError) > > Now, "visits" is an action predefined in the step file, and one that I > presume is connected somehow to webrat (installed), which means to me that > I should not have to define it myself. Therefore my questions are: Is > there some manual configuration I am required to do to wire this up > correctly or am I missing the boat on this altogether? If there are > additional set-up steps that I must perform then where to I discover them? > Do you have vendor/plugins/webrat ? If you have webrat as a gem you must require 'webrat' in env.rb Maybe the generated env.rb should have: require 'webrat' if !defined?(Webrat) HTH, Aslak > Regards, > > -- > *** E-Mail is NOT a SECURE channel *** > James B. Byrne mailto:ByrneJB at Harte-Lyne.ca > Harte & Lyne Limited http://www.harte-lyne.ca > 9 Brockley Drive vox: +1 905 561 1241 > Hamilton, Ontario fax: +1 905 561 0757 > Canada L8E 3C3 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From byrnejb at harte-lyne.ca Wed Nov 12 12:27:42 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Wed, 12 Nov 2008 12:27:42 -0500 (EST) Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: References: Message-ID: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> On: Wed, 12 Nov 2008 17:35:40 +0100, "aslak hellesoy" wrote > > Do you have vendor/plugins/webrat ? > If you have webrat as a gem you must require 'webrat' in env.rb > > Maybe the generated env.rb should have: > require 'webrat' if !defined?(Webrat) > Yes. That worked fine. Now I have another question. Please be patient with me. The features test now shows this: $ rake features (in /home/byrnejb/Software/Development/Projects/proforma.git) Feature: Manage entities # features/manage_entities.feature In order to keep track of entities A entity maintainer Should be able to manage multiple entities To Protect Revenue Scenario: Register a new entity # features/manage_entities.feature:7 Given I am on the new entity page # features/steps/entity_steps.rb:1 wrong number of arguments (3 for 1) (ActionView::TemplateError) On line #10 of app/views/entities/new.html.erb 7: <% form_for(@entity) do |f| %> 8: 9: <%= render :partial => 'entities/entity_header', 10: :object => @entity -%> 11: 12:

13: <%= f.submit "Create" -%> vendor/plugins/rspec-rails/lib/spec/rails/extensions/action_view/base.rb:13:in `render_partial' vendor/plugins/rspec-rails/lib/spec/rails/extensions/action_view/base.rb:13:in `render_partial' I am obviously retro-fitting tests on code that I have already written. In this instance I have extracted code common to the new and the edit views into a partial. What is this test error telling me and how do I get my feature/step to accommodate my existing ( and working ) code? # steps/entity_steps.rb Given /I am on the new entity page/ do visits "/entities/new" end Regards, -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From mark at mwilden.com Wed Nov 12 12:43:47 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 12 Nov 2008 09:43:47 -0800 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> Message-ID: <3c30da400811120943g393731b0s7680dbf44b44e5ce@mail.gmail.com> On Wed, Nov 12, 2008 at 7:55 AM, Matt Wynne wrote: > How about something more like > > Given there are two items in a list: "Zulu and Abba" > And I have sorted the list alphabetically > Then "Abba" should appear before "Zulu" > > Then /"(.*)" should appear before "(.*)"/ do |first_example, > second_example| > response.body.should =~ /#{first_example}.*#{second_example}/ > end The trouble with that is that you still have a 50-50 chance that your code is broken. :) Testing sorting is always problematic. Given a particular data set, other factors may be producing the "right" order (sorting on a different attribute, randomization). I usually use three items, and realize that it's not definitive. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at mwilden.com Wed Nov 12 12:46:54 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 12 Nov 2008 09:46:54 -0800 Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> References: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> Message-ID: <3c30da400811120946ib54a843r4aa7350ab015d9df@mail.gmail.com> On Wed, Nov 12, 2008 at 9:27 AM, James B. Byrne wrote: > Feature: Manage entities # features/manage_entities.feature > This is just a side note, but is "manage entities" really a feature? It sounds pretty vague. I'm not experienced with cucumber, so I don't know if that's typical usage. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Nov 12 12:53:52 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 12 Nov 2008 17:53:52 +0000 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: <3c30da400811120943g393731b0s7680dbf44b44e5ce@mail.gmail.com> References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> <3c30da400811120943g393731b0s7680dbf44b44e5ce@mail.gmail.com> Message-ID: <2E5FC534-1C4E-40CF-812F-268D678D1049@mattwynne.net> On 12 Nov 2008, at 17:43, Mark Wilden wrote: > On Wed, Nov 12, 2008 at 7:55 AM, Matt Wynne > wrote: > How about something more like > > Given there are two items in a list: "Zulu and Abba" > And I have sorted the list alphabetically > Then "Abba" should appear before "Zulu" > > Then /"(.*)" should appear before "(.*)"/ do |first_example, > second_example| > response.body.should =~ /#{first_example}.*#{second_example}/ > end > > The trouble with that is that you still have a 50-50 chance that > your code is broken. :) Testing sorting is always problematic. Given > a particular data set, other factors may be producing the "right" > order (sorting on a different attribute, randomization). I usually > use three items, and realize that it's not definitive. Sure, but balance it with another scenario that sorts it the other way, and you'd have to be pretty unlucky to get a false positive from both at the same time. :) cheers, Matt From aslak.hellesoy at gmail.com Wed Nov 12 12:58:59 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 12 Nov 2008 18:58:59 +0100 Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: <3c30da400811120946ib54a843r4aa7350ab015d9df@mail.gmail.com> References: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> <3c30da400811120946ib54a843r4aa7350ab015d9df@mail.gmail.com> Message-ID: <8d961d900811120958l332e8140i322324207f0dd979@mail.gmail.com> On Wed, Nov 12, 2008 at 6:46 PM, Mark Wilden wrote: > On Wed, Nov 12, 2008 at 9:27 AM, James B. Byrne > wrote: > >> >> Feature: Manage entities # features/manage_entities.feature > > This is just a side note, but is "manage entities" really a feature? It Good catch. It is not - it's just what the generator generates. Read the disclaimer here: http://github.com/aslakhellesoy/cucumber/wikis/ruby-on-rails (Start a feature) Suggestions about how to generate starter-features that are at the same time valuable features and tie into Rails' REST are welcome. > sounds pretty vague. I'm not experienced with cucumber, so I don't know if > that's typical usage. > > ///ark > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From joahking at gmail.com Wed Nov 12 13:00:36 2008 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Wed, 12 Nov 2008 19:00:36 +0100 Subject: [rspec-users] Warning: cucumber and spec generators on rails 2.1.0 Message-ID: <8277b7f40811121000l54f362a4k1be4f59aa39244da@mail.gmail.com> hey there, I've come back to one Rails 2.1.0 project and notice that using ruby script/generate rspec (or the cucumber one) produces this warning: Warning: Gem::SourceIndex#search support for Regexp patterns is deprecated the generators work anyway and this warning is not seeing on rails 2.1.[greater than 0], just try and change the environment.rb to point to Rails 2.1.0 version and the warning appears. I've tried the lattest Cucumber and Rspec releases as well as some older and they behave well on rails 2.1.[greater than 0] but not on rails 2.1.0 David was working on this: http://rspec.lighthouseapp.com/projects/5645/tickets/574 and http://rspec.lighthouseapp.com/projects/5645/tickets/575 but there he pointed was the issue was not 100% a Rake or Rails thing, but now I'm a bit confused. anyway I wanted to share this, as I said is only a warning joaquin -------------- next part -------------- An HTML attachment was scrubbed... URL: From jesse at jesseclark.com Wed Nov 12 13:01:58 2008 From: jesse at jesseclark.com (Jesse Clark) Date: Wed, 12 Nov 2008 10:01:58 -0800 Subject: [rspec-users] Correct way to spec partials In-Reply-To: <9D8BF58C-2B7F-411F-BA07-57847A2A3E0E@mattwynne.net> References: <6e9d2bb40810231807p48485868td431255bb387ac7f@mail.gmail.com> <57c63afe0810260549i2d6f49c0o6e195fe65c1d2a9b@mail.gmail.com> <9D8BF58C-2B7F-411F-BA07-57847A2A3E0E@mattwynne.net> Message-ID: On Nov 12, 2008, at 12:11 AM, Matt Wynne wrote: > On 12 Nov 2008, at 00:51, Jesse Clark wrote: >> On Oct 26, 4:49 am, "David Chelimsky" wrote: >>> 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 testpartials: 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. >> >> Where can I find more information about how various contexts affect >> the choice between #1 and #2? >> >> I have a partial that is shared by two view templates and I only want >> to test the partial once. So I created a new spec file with a >> describe >> block for the partial. The partial is passed some locals and I would >> like to test in my examples that these local variables are displayed >> as expected. How would I go about setting these in the example so >> they >> are available to the partial when it renders? > > What you can do is call the template from the example and set up a > stub for each of the locals. So if I have a partial like this: > > <%= name %> makes cheese for <%= friend_name %> > > Then in the example, you can do this: > > describe "when there's a name and a friend name" > before(:each) do > template.stub!(:name).and_return("Mike") > template.stub!(:friend_name).and_return("Susan") > end > end > > Make sense? Yep. Exactly what I was looking for. Thanks. > > In order to keep your view specs from becoming too brittle, I would > strongly suggest that you 'stub out' the rendering of the shared > partial in the specs for the two view templates that use the > partial. I usually do this by making a special helper method for > rendering the partial: > > <%= for relationship in relationships %> > <%= render_relationship(relationship) %> > <% end %> > > This makes is easy to stub out the rendering in your main view > templates' specs: > > before(:each) do > template.stub!(:render_relationship) > end > > Of course you'll really want a Cucumber test that makes sure the > whole stack fits together (locals are passed through with the > correct names) but I'd suggest that's a much more flexible solution > than tying your view specs together. > I am stubbing out the rendering of the partial in the other view specs. Although, I am just using: 'template.stub!(:render)' in expectations describing other portions of the view and then I have an expectation that uses 'should_receive' to make sure the partial is getting called with the expected locals values. Learning how to use Cucumber is on my list of things to do... > HTH, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Nov 12 13:10:44 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Nov 2008 12:10:44 -0600 Subject: [rspec-users] Warning: cucumber and spec generators on rails 2.1.0 In-Reply-To: <8277b7f40811121000l54f362a4k1be4f59aa39244da@mail.gmail.com> References: <8277b7f40811121000l54f362a4k1be4f59aa39244da@mail.gmail.com> Message-ID: <57c63afe0811121010q4e7395x2d0b7c53a04662e9@mail.gmail.com> On Wed, Nov 12, 2008 at 12:00 PM, Joaquin Rivera Padron wrote: > hey there, > I've come back to one Rails 2.1.0 project and notice that using > > ruby script/generate rspec (or the cucumber one) > > produces this warning: > Warning: Gem::SourceIndex#search support for Regexp patterns is deprecated > > the generators work anyway and this warning is not seeing on rails > 2.1.[greater than 0], just try and change the environment.rb to point to > Rails 2.1.0 version and the warning appears. > > I've tried the lattest Cucumber and Rspec releases as well as some older and > they behave well on rails 2.1.[greater than 0] but not on rails 2.1.0 > > David was working on this: > http://rspec.lighthouseapp.com/projects/5645/tickets/574 and > http://rspec.lighthouseapp.com/projects/5645/tickets/575 but there he > pointed was the issue was not 100% a Rake or Rails thing, but now I'm a bit > confused. I believe that's actually a rails thing. The rspec generators wrap the rails generators, which do some path searching in a now-deprecated way. Thanks for the heads up though. Cheers, David > > anyway I wanted to share this, as I said is only a warning > joaquin > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From byrnejb at harte-lyne.ca Wed Nov 12 13:24:21 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Wed, 12 Nov 2008 13:24:21 -0500 (EST) Subject: [rspec-users] rspec-users Digest, Vol 29, Issue 48 In-Reply-To: References: Message-ID: <50688.216.185.71.22.1226514261.squirrel@webmail.harte-lyne.ca> en.com On: Wed Nov 12 12:46:54 EST 2008, Mark Wilden mark at mwild wrote: > On Wed, Nov 12, 2008 at 9:27 AM, James B. Byrne lyne.ca> wrote: > >> Feature: Manage entities # features/manage_entities.feature >> > > This is just a side note, but is "manage entities" really a feature? It > sounds pretty vague. I'm not experienced with cucumber, so I don't know > if that's typical usage. I am open to any suggestions as to how to better describe this artifact. Essentially we have a design wherein the concept of a legal entity predominates and then those entities are assigned "roles" such as client, vendor, employee. etc. As part of the prototyping process we have a requirement to create and delete these instances by hand, independent of any role. The decision is not yet made whether this capability will be required, or even desired, in the finished system; although I rather suspect that it will persist if only as an administrator's tool. Nonetheless, in this particular case it is coded, it works, and I have chosen it to begin learning the process of BDD/TDD here. I realize however that nomenclature can have a very large impact on how a conceptual expression develops and so I am most interested in seeing whether there exists a better way to describe this. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From mark at mwilden.com Wed Nov 12 13:33:54 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 12 Nov 2008 10:33:54 -0800 Subject: [rspec-users] rspec-users Digest, Vol 29, Issue 48 In-Reply-To: <50688.216.185.71.22.1226514261.squirrel@webmail.harte-lyne.ca> References: <50688.216.185.71.22.1226514261.squirrel@webmail.harte-lyne.ca> Message-ID: <3c30da400811121033u708b593axa59ff53ae37d2010@mail.gmail.com> On Wed, Nov 12, 2008 at 10:24 AM, James B. Byrne wrote: > > I am open to any suggestions as to how to better describe this artifact. > Essentially we have a design wherein the concept of a legal entity > predominates and then those entities are assigned "roles" such as client, > vendor, employee. etc. As part of the prototyping process we have a > requirement to create and delete these instances by hand How about "Manually create and delete entities"? :) At least that's something that a user could say, "yeah, the system does that." ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From byrnejb at harte-lyne.ca Wed Nov 12 13:59:49 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Wed, 12 Nov 2008 13:59:49 -0500 (EST) Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> References: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> Message-ID: <46912.216.185.71.22.1226516389.squirrel@webmail.harte-lyne.ca> On Wed, November 12, 2008 12:27, James B. Byrne wrote: > > The features test now shows this: > > $ rake features ... > Scenario: Register a new entity # > features/manage_entities.feature:7 > Given I am on the new entity page # > features/steps/entity_steps.rb:1 > wrong number of arguments (3 for 1) (ActionView::TemplateError) > On line #10 of app/views/entities/new.html.erb > > 7: <% form_for(@entity) do |f| %> > 8: > 9: <%= render :partial => 'entities/entity_header', > 10: :object => @entity -%> > 11: > 12:

> 13: <%= f.submit "Create" -%> > > vendor/plugins/rspec-rails/lib/spec/rails/extensions/action_view/base.rb:13:in > `render_partial' > vendor/plugins/rspec-rails/lib/spec/rails/extensions/action_view/base.rb:13:in > `render_partial' > ... > > # steps/entity_steps.rb > Given /I am on the new entity page/ do > visits "/entities/new" > end Any hints on what I am doing wrong here? Should I be asking this question on a webrat list? Is there one? I cannot find it. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From pe at dipe.de Wed Nov 12 14:05:49 2008 From: pe at dipe.de (Peter Ehrenberg) Date: Wed, 12 Nov 2008 20:05:49 +0100 Subject: [rspec-users] Cucumber feature checking sort order of list In-Reply-To: <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> References: <8277b7f40811120638q2118105dmeef6e7f4f2977c96@mail.gmail.com> <8277b7f40811120731n432e0a66le7565bba4ad96982@mail.gmail.com> <878D59E6-7C8A-4A68-A30B-8E396D9C80B5@mattwynne.net> Message-ID: Mutch better as mine! From joahking at gmail.com Wed Nov 12 14:55:13 2008 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Wed, 12 Nov 2008 20:55:13 +0100 Subject: [rspec-users] Warning: cucumber and spec generators on rails 2.1.0 In-Reply-To: <57c63afe0811121010q4e7395x2d0b7c53a04662e9@mail.gmail.com> References: <8277b7f40811121000l54f362a4k1be4f59aa39244da@mail.gmail.com> <57c63afe0811121010q4e7395x2d0b7c53a04662e9@mail.gmail.com> Message-ID: <8277b7f40811121155p7b1ef827m2ad7d729183fab90@mail.gmail.com> ooops, The files generated with rails 2.1.0 with ruby script/generate cucumber are not good actually. When running features nothing got printed in console. I solved it by _sort of_ following one of your tips at lighthouse: * switch project to rails 2.1.2 * generated the cucumber files again * switch back to old 2.1.0 and voila I began seeing greens, reds and all of them anyone else seeing this happening? or is it just me :-( thanks jk -------------- next part -------------- An HTML attachment was scrubbed... URL: From byrnejb at harte-lyne.ca Wed Nov 12 15:15:01 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Wed, 12 Nov 2008 15:15:01 -0500 (EST) Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: <46912.216.185.71.22.1226516389.squirrel@webmail.harte-lyne.ca> References: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> <46912.216.185.71.22.1226516389.squirrel@webmail.harte-lyne.ca> Message-ID: <46877.216.185.71.22.1226520901.squirrel@webmail.harte-lyne.ca> For what it is worth the contents of the log/test.log file are: $ tail log/test.log Completed in 67ms (View: 7, DB: 2) | 200 OK [http://www.example.com/entities] SQL (0.7ms) SELECT count(*) AS count_all FROM "entities" REQUESTING PAGE: GET /entities/new with {} and HTTP headers {} Processing EntitiesController#new (for 127.0.0.1 at 2008-11-12 15:11:44) [GET] Session ID: 04a1f0098c54dba8a812645fbb015380 Parameters: {"action"=>"new", "controller"=>"entities"} Rendering template within layouts/application Rendering entities/new While, the same page rendered in Firefox using the development environment shows this: REQUESTING PAGE: GET /entities/new with {} and HTTP headers {} Processing EntitiesController#new (for 127.0.0.1 at 2008-11-12 15:11:44) [GET] Session ID: 04a1f0098c54dba8a812645fbb015380 Parameters: {"action"=>"new", "controller"=>"entities"} Rendering template within layouts/application Rendering entities/new [byrnejb at inet02 proforma.git]$ tail log/development.log Rendering template within layouts/application Rendering entities/new Rendered entities/_entity_header (15.2ms) Completed in 98ms (View: 57, DB: 0) | 200 OK [http://localhost/entities/new] SQL (4.3ms) SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' SQL (1.1ms) SELECT version FROM schema_migrations SQL (1.7ms) SELECT version FROM schema_migrations I really could use from help from someone who can explain this behaviour. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From nick at deadorange.com Wed Nov 12 15:44:58 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 12 Nov 2008 15:44:58 -0500 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: <491A23CC.6040202@benmabey.com> References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> <491A23CC.6040202@benmabey.com> Message-ID: On 2008-11-11, at 19:31, Ben Mabey wrote: > Nick Hoffman wrote: >> I've written a module for my specs that contains a helper method, >> and am mixing the module into my specs with #include . It seems >> that the method must be called with an #it block. If it isn't, this >> error occurs: >> >> ... in `method_missing': undefined method >> `it_should_behave_like_an_action_that_sets_the_flash_notice' for >> Spec::Rails::Example::ControllerExampleGroup::Subclass_1:Class >> (NoMethodError) from ./spec/controllers/ >> properties_controller_spec.rb:8 >> >> Is there a way to call my helper method from outside of an #it >> block? Here's the code: >> http://pastie.org/312680 >> >> Thanks! >> Nick >> > > It looks like you want those methods in your module as class method, > not instance methods. Try extending, not including, your module > (extend AuthSpecHelpers.) You might want to read my post about > creating rspec macros as well: > http://www.benmabey.com/2008/06/08/writing-macros-in-rspec/ > > -Ben That was post was gold, Ben. It cleared up most of my questions and confusion regarding #include, #extend, and mix-ins. Thanks, mate. From nick at deadorange.com Wed Nov 12 15:56:20 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 12 Nov 2008 15:56:20 -0500 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> Message-ID: <3DF128DF-85CE-43CD-9D41-CDC60A137074@deadorange.com> On 2008-11-11, at 19:39, Pat Maddox wrote: > Nick Hoffman writes: >> I've written a module for my specs that contains a helper method, and >> am mixing the module into my specs with #include . It seems that the >> method must be called with an #it block. If it isn't, this error >> occurs: >> >> ... in `method_missing': undefined method >> it_should_behave_like_an_action_that_sets_the_flash_notice' for >> Spec::Rails::Example::ControllerExampleGroup::Subclass_1:Class >> (NoMethodError) from >> ./spec/controllers/properties_controller_spec.rb:8 >> >> Is there a way to call my helper method from outside of an #it block? >> Here's the code: >> http://pastie.org/312680 > > You want extend instead of include. > > Also, if you want to share this among many example groups, you can > do it > in the config block instead of extending it in every single example > group: > > Spec::Runner.configure do |config| > config.extend AuthSpecHelpers > end > > You can even do it for particular example group types if you want: > > Spec::Runner.configure do |config| > config.extend AuthSpecHelpers, :type => :controller > end > > Pat That's convenient. What I've done is add this to the beginning: require 'spec/shared/auth_spec_helpers' and add this to the 'config' block: config.extend AuthSpecHelpers, :type => :controller of spec_helper.rb . Is that a suitable, or preferred, method of extending the helper methods in the AuthSpecHelpers module to controller specs? Thanks, Nick From nick at deadorange.com Wed Nov 12 15:58:27 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 12 Nov 2008 15:58:27 -0500 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: <57c63afe0811111649r3de57fbalc0c47b9eb930f680@mail.gmail.com> References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> <57c63afe0811111649r3de57fbalc0c47b9eb930f680@mail.gmail.com> Message-ID: <219884A9-DBD8-4A49-9FAA-5215F0221B31@deadorange.com> On 2008-11-11, at 19:49, David Chelimsky wrote: > On Tue, Nov 11, 2008 at 6:39 PM, Pat Maddox wrote: >> You can even do it for particular example group types if you want: >> >> Spec::Runner.configure do |config| >> config.extend AuthSpecHelpers, :type => :controller >> end > > Note that config.extend was only added recently, in rspec-1.1.9. > > Cheers, > David Thanks for remembering that I'm using an old version of RSpec and RSpec-Rails, mate ;) That was enough of a reason to upgrade, so now I'm running 1.1.11 of the plugins. Hoorah! -Nick From nick at deadorange.com Wed Nov 12 16:08:46 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 12 Nov 2008 16:08:46 -0500 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: <491A23CC.6040202@benmabey.com> References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> <491A23CC.6040202@benmabey.com> Message-ID: On 2008-11-11, at 19:31, Ben Mabey wrote: > Nick Hoffman wrote: >> I've written a module for my specs that contains a helper method, >> and am mixing the module into my specs with #include . It seems >> that the method must be called with an #it block. If it isn't, this >> error occurs: >> >> ... in `method_missing': undefined method >> `it_should_behave_like_an_action_that_sets_the_flash_notice' for >> Spec::Rails::Example::ControllerExampleGroup::Subclass_1:Class >> (NoMethodError) from ./spec/controllers/ >> properties_controller_spec.rb:8 >> >> Is there a way to call my helper method from outside of an #it >> block? Here's the code: >> http://pastie.org/312680 >> >> Thanks! >> Nick >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > It looks like you want those methods in your module as class method, > not instance methods. Try extending, not including, your module > (extend AuthSpecHelpers.) You might want to read my post about > creating rspec macros as well: > http://www.benmabey.com/2008/06/08/writing-macros-in-rspec/ > > -Ben After digesting that post again, especially the contents of #self.included , I noticed that one could alternatively do this: module AssignMacro def self.extended(receiver) receiver.extend ExampleGroupMethods receiver.send :include, ExampleMethods end end describe UserPhotosController do describe "GET 'users/1/photos/2'" do extend AssignMacro # ... end end Is one approach more preferable? Or should one do this so that both "include AssignMacro" and "extend AssignMacro" give the same, desired, result?: module AssignMacro def self.included(receiver) receiver.extend ExampleGroupMethods receiver.send :include, ExampleMethods end class << self alias_method :extended, :included end end Thanks for your input, guys. -Nick From byrnejb at harte-lyne.ca Wed Nov 12 16:10:18 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Wed, 12 Nov 2008 16:10:18 -0500 (EST) Subject: [rspec-users] Cucumber Scaffolds [SOLVED] In-Reply-To: <46877.216.185.71.22.1226520901.squirrel@webmail.harte-lyne.ca> References: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> <46912.216.185.71.22.1226516389.squirrel@webmail.harte-lyne.ca> <46877.216.185.71.22.1226520901.squirrel@webmail.harte-lyne.ca> Message-ID: <43397.216.185.71.22.1226524218.squirrel@webmail.harte-lyne.ca> Thanks to a suggestion from the Ruby on Rails list I checked my vendor plugins directory and discovered that I had not actually removed the older rspec and rspec-rails plugins, just detached them from git. They both are now gone and my tests are running, if not passing. But at least I am past this problem anyway. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From ben at benmabey.com Wed Nov 12 16:38:08 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 12 Nov 2008 14:38:08 -0700 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> <491A23CC.6040202@benmabey.com> Message-ID: <491B4CC0.6070607@benmabey.com> Nick Hoffman wrote: > On 2008-11-11, at 19:31, Ben Mabey wrote: >> Nick Hoffman wrote: >>> I've written a module for my specs that contains a helper method, >>> and am mixing the module into my specs with #include . It seems that >>> the method must be called with an #it block. If it isn't, this error >>> occurs: >>> >>> ... in `method_missing': undefined method >>> `it_should_behave_like_an_action_that_sets_the_flash_notice' for >>> Spec::Rails::Example::ControllerExampleGroup::Subclass_1:Class >>> (NoMethodError) from ./spec/controllers/properties_controller_spec.rb:8 >>> >>> Is there a way to call my helper method from outside of an #it >>> block? Here's the code: >>> http://pastie.org/312680 >>> >>> Thanks! >>> Nick >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> It looks like you want those methods in your module as class method, >> not instance methods. Try extending, not including, your module >> (extend AuthSpecHelpers.) You might want to read my post about >> creating rspec macros as well: >> http://www.benmabey.com/2008/06/08/writing-macros-in-rspec/ >> >> -Ben > > After digesting that post again, especially the contents of > #self.included , I noticed that one could alternatively do this: > > module AssignMacro > def self.extended(receiver) > receiver.extend ExampleGroupMethods > receiver.send :include, ExampleMethods > end > end > > describe UserPhotosController do > describe "GET 'users/1/photos/2'" do > extend AssignMacro > # ... > end > end > > Is one approach more preferable? Or should one do this so that both > "include AssignMacro" and "extend AssignMacro" give the same, desired, > result?: > > module AssignMacro > def self.included(receiver) > receiver.extend ExampleGroupMethods > receiver.send :include, ExampleMethods > end > > class << self > alias_method :extended, :included > end > end > > Thanks for your input, guys. > -Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Some people would say that using the included or extended module hooks like that are evil.[1] That said it is a very common ruby idiom even if it is bad. If you are going to use the evil idiom then I would suggest using include and not extend since it is the idiom. :) Another way to do it that wouldn't take advantage of the evil hooks would be: describe UserPhotosController do describe "GET 'users/1/photos/2'" do extend AssignMacro::ExampleGroupMethods include AssignMacro::ExampleMethods # ... end Of course that is somewhat annoying to type everywhere. So perhaps you could add another example group method that would mix in macors.. likes so: describe UserPhotosController do describe "GET 'users/1/photos/2'" do use_macro AssignMacro # ... end end The 'use_maco' would be a module that you mix in onto all rspec's example group methods that would simply include and extend the given module's ExampleMethods and ExampleGroupMethods modules respectively. The 'use_macro' is probably more clear than the hooks. Just a thought. -Ben 1. http://olabini.com/blog/2008/09/evil-hook-methods/ From jesse at jesseclark.com Wed Nov 12 19:12:21 2008 From: jesse at jesseclark.com (Jesse Clark) Date: Wed, 12 Nov 2008 16:12:21 -0800 Subject: [rspec-users] Specing based on user roles In-Reply-To: <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> References: <3e96fa4187edd2e0929a6f4d2db4a2e4@ruby-forum.com> <57c63afe0811060801r4a9a47e5t12ff97158fa711c@mail.gmail.com> Message-ID: <8D9DC06B-7E6F-4652-A3C7-BA6A01831961@jesseclark.com> On Nov 6, 2008, at 8:01 AM, David Chelimsky wrote: > I've really moved away from shared example groups and started writing > more targeted macros. So I might do something like this: > > def for_roles *roles > roles.each do |role| > before(:each) { login_as role } > yield > end > end > > describe OrdersController do > describe "GET index" do > for_roles :admin, :sysadmin do |role| > it "..." do ... end > end > for_roles :sysadmin do |role| > it "..." do ... end > end > end I was attempting to follow this example and discovered that before(scope, &block) is an alias for append_before which, as the method name indicates, appends the before block to the existing collection of before blocks. So, in your example code above it seems that login_as would get called for each role passed to for_roles before each example is executed. Since the before blocks are stored internally as an array, the last element of the array would win. Another example: require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') def for_roles *roles roles.each do |role| before(:each) do puts role.to_s end yield end end describe "DRY roles test" do describe "GET index" do for_roles :admin, :sysadmin do |role| it "..." do puts 'in example' end end end end Running this sample spec from the command line generates this output: admin sysadmin in example .admin sysadmin in example . I noticed that there is a method called 'remove_after' in before_and_after_hooks.rb but no corresponding remove_before. Looking at the code: def remove_after(scope, &block) after_each_parts.delete(block) end I noticed that this method doesn't use the scope parameter at all and just attempts to delete the block from after_each_parts. So, I modified the method to honor the scope parameter and wrote a corresponding remove_before method: def remove_after(scope, &block) parts = after_parts_from_scope(scope) parts.delete(block) end def remove_before(scope, &block) parts = before_parts_from_scope(scope) parts.delete(block) end However, this doesn't work as expected because if you do something like: before(:each) { login_as role } remove_before(:each) { login_as role } two different Proc objects are created by each method call so parts.delete(block) will always fail. The only way I could see around this was if there were versions of append_before and remove_before which took a Proc object as a parameter instead of converting the block so you could maintain a reference to it in the calling code, i.e. def append_before_proc(*args, block) scope, options = scope_and_options(*args) parts = before_parts_from_scope(scope) parts << block end def remove_before_proc(scope, block) parts = before_parts_from_scope(scope) parts.delete(block) end my_block = Proc.new { login_as role } append_before_proc(:each, my_block) remove_before_proc(:each, my_block) Which seems like a lot of monkey patching to get this working. So now (finally) my questions: 1) Is there a better way to do this? 2) The current version of remove_after seems broken. Should I report this as a bug? Thanks, -Jesse From apremdas at gmail.com Thu Nov 13 01:03:52 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Thu, 13 Nov 2008 06:03:52 +0000 Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: <46877.216.185.71.22.1226520901.squirrel@webmail.harte-lyne.ca> References: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> <46912.216.185.71.22.1226516389.squirrel@webmail.harte-lyne.ca> <46877.216.185.71.22.1226520901.squirrel@webmail.harte-lyne.ca> Message-ID: <88fd8ddc0811122203i12ba942bub67158584c7d3bcc@mail.gmail.com> A couple of tips may help here. 1) You can debug features by putting 'debugger' in the step file. Just make sure there is a line after debugger e.g ... debugger response end If there's nothing after debugger you will stop in the cucumber code, which is not what you want. 2) You can also put debugger statements in your rails files. Perhaps you could do a <%- debugger %> before you render your partial in the form. (You might have to use <%=) HTH Andrew 2008/11/12 James B. Byrne : > > For what it is worth the contents of the log/test.log file are: > > $ tail log/test.log > Completed in 67ms (View: 7, DB: 2) | 200 OK [http://www.example.com/entities] > SQL (0.7ms) SELECT count(*) AS count_all FROM "entities" > REQUESTING PAGE: GET /entities/new with {} and HTTP headers {} > > > Processing EntitiesController#new (for 127.0.0.1 at 2008-11-12 15:11:44) > [GET] > Session ID: 04a1f0098c54dba8a812645fbb015380 > Parameters: {"action"=>"new", "controller"=>"entities"} > Rendering template within layouts/application > Rendering entities/new > > While, the same page rendered in Firefox using the development environment > shows this: > > REQUESTING PAGE: GET /entities/new with {} and HTTP headers {} > > > Processing EntitiesController#new (for 127.0.0.1 at 2008-11-12 15:11:44) > [GET] > Session ID: 04a1f0098c54dba8a812645fbb015380 > Parameters: {"action"=>"new", "controller"=>"entities"} > Rendering template within layouts/application > Rendering entities/new > [byrnejb at inet02 proforma.git]$ tail log/development.log > Rendering template within layouts/application > Rendering entities/new > Rendered entities/_entity_header (15.2ms) > Completed in 98ms (View: 57, DB: 0) | 200 OK [http://localhost/entities/new] > SQL (4.3ms) SELECT name > FROM sqlite_master > WHERE type = 'table' AND NOT name = 'sqlite_sequence' > > SQL (1.1ms) SELECT version FROM schema_migrations > SQL (1.7ms) SELECT version FROM schema_migrations > > I really could use from help from someone who can explain this behaviour. > > > > > -- > *** E-Mail is NOT a SECURE channel *** > James B. Byrne mailto:ByrneJB at Harte-Lyne.ca > Harte & Lyne Limited http://www.harte-lyne.ca > 9 Brockley Drive vox: +1 905 561 1241 > Hamilton, Ontario fax: +1 905 561 0757 > Canada L8E 3C3 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mark at mwilden.com Thu Nov 13 01:35:44 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 12 Nov 2008 22:35:44 -0800 Subject: [rspec-users] Cucumber Scaffolds In-Reply-To: <88fd8ddc0811122203i12ba942bub67158584c7d3bcc@mail.gmail.com> References: <38944.216.185.71.22.1226510862.squirrel@webmail.harte-lyne.ca> <46912.216.185.71.22.1226516389.squirrel@webmail.harte-lyne.ca> <46877.216.185.71.22.1226520901.squirrel@webmail.harte-lyne.ca> <88fd8ddc0811122203i12ba942bub67158584c7d3bcc@mail.gmail.com> Message-ID: <3c30da400811122235h163efb4ave66a0f3caaf94d94@mail.gmail.com> On Wed, Nov 12, 2008 at 10:03 PM, Andrew Premdas wrote: > > 1) You can debug features by putting 'debugger' in the step file. Just > make sure there is a line after debugger > And require ruby-debug. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramon.tayag at gmail.com Thu Nov 13 06:13:54 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Thu, 13 Nov 2008 19:13:54 +0800 Subject: [rspec-users] Autotest style autotest/rails_rspec doesn't seem to exist. Aborting. Message-ID: Just upgraded my rspec because I wanted to start using cucumber. Autotest stopped working though. I got the error shown in the subject: "Autotest style autotest/rails_rspec doesn't seem to exist. Aborting." What should I do? ZenTest = Ramon Tayag From lists at ruby-forum.com Thu Nov 13 06:18:51 2008 From: lists at ruby-forum.com (Mano ah) Date: Thu, 13 Nov 2008 12:18:51 +0100 Subject: [rspec-users] testing an action which requires picture In-Reply-To: <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> Message-ID: Actually i need to test sending a barcode image and also test a value returned by it. -- Posted via http://www.ruby-forum.com/. From ramon.tayag at gmail.com Thu Nov 13 06:20:18 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Thu, 13 Nov 2008 19:20:18 +0800 Subject: [rspec-users] Autotest style autotest/rails_rspec doesn't seem to exist. Aborting. Message-ID: Just upgraded rspec because I want to use cucumber. I downloaded the gems listed in the github wiki, and I submoduled the rspec and rspec-rails plugins. Autotest started to fail on me though. "Autotest style autotest/rails_rspec doesn't seem to exist. Aborting." What should I do to fix it? ZenTest: 3.11.0 rspec: 1.1.11 Thanks, Ramon Tayag From ramon.tayag at gmail.com Thu Nov 13 06:25:07 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Thu, 13 Nov 2008 19:25:07 +0800 Subject: [rspec-users] testing an action which requires picture In-Reply-To: References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> Message-ID: You can put that barcode in the spec/fixtures directory. However, you'll need to manually place it there. Ramon Tayag On Thu, Nov 13, 2008 at 7:18 PM, Mano ah wrote: > Actually i need to test sending a barcode image and also test a value > returned by it. > -- > 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 Nov 13 06:37:34 2008 From: lists at ruby-forum.com (Mano ah) Date: Thu, 13 Nov 2008 12:37:34 +0100 Subject: [rspec-users] testing an action which requires picture In-Reply-To: References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> Message-ID: <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> Ramon Tayag wrote: > You can put that barcode in the spec/fixtures directory. However, > you'll need to manually place it there. > > Ramon Tayag ok. Also please can i know how to test sending an image using rspec. -- Posted via http://www.ruby-forum.com/. From ramon.tayag at gmail.com Thu Nov 13 06:53:27 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Thu, 13 Nov 2008 19:53:27 +0800 Subject: [rspec-users] testing an action which requires picture In-Reply-To: <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> Message-ID: I suggest doing those tests in the model, not in the controller. Just do that fixture thing for the controller spec to pass. But pass the same thing in the model. Here's a sample of how I do it require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ProductImage do before(:all) do @valid_attributes = { :uploaded_data => fixture_file_upload("100x100.jpg",'image/jpg'), :product_id => 1 } @product_image = ProductImage.create(@valid_attributes) end it "should create a new instance given valid attributes" do ProductImage.create!(@valid_attributes) end end Ramon Tayag On Thu, Nov 13, 2008 at 7:37 PM, Mano ah wrote: > Ramon Tayag wrote: >> You can put that barcode in the spec/fixtures directory. However, >> you'll need to manually place it there. >> >> Ramon Tayag > > ok. Also please can i know how to test sending an image using rspec. > -- > 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 Nov 13 07:48:15 2008 From: lists at ruby-forum.com (Mano ah) Date: Thu, 13 Nov 2008 13:48:15 +0100 Subject: [rspec-users] testing an action which requires picture In-Reply-To: References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> Message-ID: <3ed504aea01d24117705eaecb53cb437@ruby-forum.com> Ramon Tayag wrote: > I suggest doing those tests in the model, not in the controller. Just > do that fixture thing for the controller spec to pass. But pass the > same thing in the model. Here's a sample of how I do it > > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > > describe ProductImage do > before(:all) do > @valid_attributes = { > :uploaded_data => fixture_file_upload("100x100.jpg",'image/jpg'), > :product_id => 1 > } > @product_image = ProductImage.create(@valid_attributes) > end > > it "should create a new instance given valid attributes" do > ProductImage.create!(@valid_attributes) > end > end > > Ramon Tayag Can I know what the create action handle. I am getting undefined method 'create' error -- Posted via http://www.ruby-forum.com/. From emmanuel at pirsch.org Thu Nov 13 08:38:17 2008 From: emmanuel at pirsch.org (Emmanuel Pirsch) Date: Thu, 13 Nov 2008 08:38:17 -0500 Subject: [rspec-users] .with(:anything) issue Message-ID: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> Hi, I'm using a expectation like this : repository.should_receive(:add_gem).with("test.txt", :anything) When I run my spec, it fails with the following message : Spec::Mocks::MockExpectationError in 'MiniGemServer should add a new gem to the repository after it has been uploaded' # expected :add_gem with ("test.txt", :anything) but received it with ("test.txt", "C:/DOCUME~1/xyzuser/LOCALS~1/Temp/RackMultipart20081113-8392-1vodbzf-0") Shouldn't it be working? The first argument is the same and I don't really care about the second one as long as it is there. I also tried to replace :anything with :string and got the same error. Any idea why I get this? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Nov 13 08:42:44 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Nov 2008 07:42:44 -0600 Subject: [rspec-users] .with(:anything) issue In-Reply-To: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> References: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> Message-ID: <57c63afe0811130542u74143bfewd3419495070c5571@mail.gmail.com> On Thu, Nov 13, 2008 at 7:38 AM, Emmanuel Pirsch wrote: > Hi, > > I'm using a expectation like this : > repository.should_receive(:add_gem).with("test.txt", :anything) Try the anything() method. Support for symbols as argument matchers was deprecated and removed. Are you still seeing docs somewhere that talk about using symbols? > > When I run my spec, it fails with the following message : > Spec::Mocks::MockExpectationError in 'MiniGemServer should add a new gem to > the repository after it has been uploaded' > # expected :add_gem with ("test.txt", > :anything) but received it with ("test.txt", > "C:/DOCUME~1/xyzuser/LOCALS~1/Temp/RackMultipart20081113-8392-1vodbzf-0") > > Shouldn't it be working? The first argument is the same and I don't really > care about the second one as long as it is there. I also tried to replace > :anything with :string and got the same error. > > Any idea why I get this? > > Thanks! > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From luislavena at gmail.com Thu Nov 13 08:43:55 2008 From: luislavena at gmail.com (Luis Lavena) Date: Thu, 13 Nov 2008 10:43:55 -0300 Subject: [rspec-users] .with(:anything) issue In-Reply-To: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> References: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> Message-ID: <71166b3b0811130543g55f9ce99w7546c5c9cf0728b1@mail.gmail.com> On Thu, Nov 13, 2008 at 10:38 AM, Emmanuel Pirsch wrote: > Hi, > > I'm using a expectation like this : > repository.should_receive(:add_gem).with("test.txt", :anything) > > When I run my spec, it fails with the following message : > Spec::Mocks::MockExpectationError in 'MiniGemServer should add a new gem to > the repository after it has been uploaded' > # expected :add_gem with ("test.txt", > :anything) but received it with ("test.txt", > "C:/DOCUME~1/xyzuser/LOCALS~1/Temp/RackMultipart20081113-8392-1vodbzf-0") > > Shouldn't it be working? The first argument is the same and I don't really > care about the second one as long as it is there. I also tried to replace > :anything with :string and got the same error. > > Any idea why I get this? > Did you tried "anything" (not a symbol) 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 matt at mattwynne.net Thu Nov 13 08:44:26 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 13 Nov 2008 13:44:26 +0000 Subject: [rspec-users] .with(:anything) issue In-Reply-To: <57c63afe0811130542u74143bfewd3419495070c5571@mail.gmail.com> References: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> <57c63afe0811130542u74143bfewd3419495070c5571@mail.gmail.com> Message-ID: On 13 Nov 2008, at 13:42, David Chelimsky wrote: > On Thu, Nov 13, 2008 at 7:38 AM, Emmanuel Pirsch > wrote: >> Hi, >> >> I'm using a expectation like this : >> repository.should_receive(:add_gem).with("test.txt", :anything) > > Try the anything() method. Support for symbols as argument matchers > was deprecated and removed. > > Are you still seeing docs somewhere that talk about using symbols? I know I always go on about this (and never do anything about it) but the symbols are still all over the docs: http://rspec.info/documentation/mocks/message_expectations.html > Argument Constraints > > Constraints can be placed on individual arguments which are looser > than value > equivalence (as above). > :anything > > accepts any value for this argument, e.g.: > > my_mock.should_receive(:msg).with(1, :anything, "A") cheers, Matt From dchelimsky at gmail.com Thu Nov 13 08:44:32 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Nov 2008 07:44:32 -0600 Subject: [rspec-users] Autotest style autotest/rails_rspec doesn't seem to exist. Aborting. In-Reply-To: References: Message-ID: <57c63afe0811130544mc8693d8t2e4fe5ccb76e818c@mail.gmail.com> On Thu, Nov 13, 2008 at 5:20 AM, Ramon Tayag wrote: > Just upgraded rspec because I want to use cucumber. I downloaded the > gems listed in the github wiki, and I submoduled the rspec and > rspec-rails plugins. Autotest started to fail on me though. > > "Autotest style autotest/rails_rspec doesn't seem to exist. Aborting." > > What should I do to fix it? > > ZenTest: 3.11.0 > rspec: 1.1.11 You need rspec-rails as well (plugin or gem, same version as rspec). Do you have that already? Cheers, David > > Thanks, > Ramon Tayag > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Nov 13 08:45:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Nov 2008 07:45:24 -0600 Subject: [rspec-users] .with(:anything) issue In-Reply-To: References: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> <57c63afe0811130542u74143bfewd3419495070c5571@mail.gmail.com> Message-ID: <57c63afe0811130545w5638c0caj999efb3f3b80d711@mail.gmail.com> On Thu, Nov 13, 2008 at 7:44 AM, Matt Wynne wrote: > On 13 Nov 2008, at 13:42, David Chelimsky wrote: >> >> On Thu, Nov 13, 2008 at 7:38 AM, Emmanuel Pirsch >> wrote: >>> >>> Hi, >>> >>> I'm using a expectation like this : >>> repository.should_receive(:add_gem).with("test.txt", :anything) >> >> Try the anything() method. Support for symbols as argument matchers >> was deprecated and removed. >> >> Are you still seeing docs somewhere that talk about using symbols? > > I know I always go on about this (and never do anything about it) but the > symbols are still all over the docs: > http://rspec.info/documentation/mocks/message_expectations.html > >> Argument Constraints >> >> Constraints can be placed on individual arguments which are looser than >> value >> equivalence (as above). >> :anything >> >> accepts any value for this argument, e.g.: >> >> my_mock.should_receive(:msg).with(1, :anything, "A") carapola! There is just no time for the present. Update coming shortly. > > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From emmanuel at pirsch.org Thu Nov 13 08:45:35 2008 From: emmanuel at pirsch.org (Emmanuel Pirsch) Date: Thu, 13 Nov 2008 08:45:35 -0500 Subject: [rspec-users] .with(:anything) issue In-Reply-To: <57c63afe0811130542u74143bfewd3419495070c5571@mail.gmail.com> References: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> <57c63afe0811130542u74143bfewd3419495070c5571@mail.gmail.com> Message-ID: <4ebe19940811130545k52c8b789k179573db1ee1d4b8@mail.gmail.com> Great, it worked! Here is where I found the doc which talk about using symbols : http://rspec.info/documentation/mocks/message_expectations.html Thanks! On Thu, Nov 13, 2008 at 8:42 AM, David Chelimsky wrote: > On Thu, Nov 13, 2008 at 7:38 AM, Emmanuel Pirsch > wrote: > > Hi, > > > > I'm using a expectation like this : > > repository.should_receive(:add_gem).with("test.txt", :anything) > > Try the anything() method. Support for symbols as argument matchers > was deprecated and removed. > > Are you still seeing docs somewhere that talk about using symbols? > > > > > When I run my spec, it fails with the following message : > > Spec::Mocks::MockExpectationError in 'MiniGemServer should add a new gem > to > > the repository after it has been uploaded' > > # expected :add_gem with ("test.txt", > > :anything) but received it with ("test.txt", > > "C:/DOCUME~1/xyzuser/LOCALS~1/Temp/RackMultipart20081113-8392-1vodbzf-0") > > > > Shouldn't it be working? The first argument is the same and I don't > really > > care about the second one as long as it is there. I also tried to replace > > :anything with :string and got the same error. > > > > Any idea why I get this? > > > > 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 dchelimsky at gmail.com Thu Nov 13 09:13:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Nov 2008 08:13:21 -0600 Subject: [rspec-users] .with(:anything) issue In-Reply-To: <4ebe19940811130545k52c8b789k179573db1ee1d4b8@mail.gmail.com> References: <4ebe19940811130538y841ddaexbf7566ee755732e2@mail.gmail.com> <57c63afe0811130542u74143bfewd3419495070c5571@mail.gmail.com> <4ebe19940811130545k52c8b789k179573db1ee1d4b8@mail.gmail.com> Message-ID: <57c63afe0811130613r64176663k183a40832371f64e@mail.gmail.com> On Thu, Nov 13, 2008 at 7:45 AM, Emmanuel Pirsch wrote: > Great, it worked! > > Here is where I found the doc which talk about using symbols : > http://rspec.info/documentation/mocks/message_expectations.html Fixed. Sorry for the misinformation and thanks for the heads up. Cheers, David > > Thanks! > > On Thu, Nov 13, 2008 at 8:42 AM, David Chelimsky > wrote: >> >> On Thu, Nov 13, 2008 at 7:38 AM, Emmanuel Pirsch >> wrote: >> > Hi, >> > >> > I'm using a expectation like this : >> > repository.should_receive(:add_gem).with("test.txt", :anything) >> >> Try the anything() method. Support for symbols as argument matchers >> was deprecated and removed. >> >> Are you still seeing docs somewhere that talk about using symbols? >> >> > >> > When I run my spec, it fails with the following message : >> > Spec::Mocks::MockExpectationError in 'MiniGemServer should add a new gem >> > to >> > the repository after it has been uploaded' >> > # expected :add_gem with >> > ("test.txt", >> > :anything) but received it with ("test.txt", >> > >> > "C:/DOCUME~1/xyzuser/LOCALS~1/Temp/RackMultipart20081113-8392-1vodbzf-0") >> > >> > Shouldn't it be working? The first argument is the same and I don't >> > really >> > care about the second one as long as it is there. I also tried to >> > replace >> > :anything with :string and got the same error. >> > >> > Any idea why I get this? >> > >> > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From peter.a.jaros at gmail.com Thu Nov 13 09:59:23 2008 From: peter.a.jaros at gmail.com (Peter Jaros) Date: Thu, 13 Nov 2008 09:59:23 -0500 Subject: [rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc In-Reply-To: <57c63afe0811120559xc12bc80t66f0e6441900cac1@mail.gmail.com> References: <8d961d900811120530i4258d8c4g37bbcf799d44d75e@mail.gmail.com> <57c63afe0811120559xc12bc80t66f0e6441900cac1@mail.gmail.com> Message-ID: <937d9d810811130659k4172be69n420217bd0541a51b@mail.gmail.com> On Wed, Nov 12, 2008 at 8:59 AM, David Chelimsky wrote: > On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy > wrote: >> World do >> world = Object.new >> world.extend(Logging::Logger) >> world >> end > > World do > returning Cucumber::Rails::World do |world| > world.extend(Logging::Logger) > end > end It would be really nice to be able to do: World do |world| returning world do |w| w.extend(Logging::Logger) end end This way steps files could extend the world by adding to a chain, agnostic of the nature of the original world object. Peter From dchelimsky at gmail.com Thu Nov 13 10:01:29 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Nov 2008 09:01:29 -0600 Subject: [rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc In-Reply-To: <937d9d810811130659k4172be69n420217bd0541a51b@mail.gmail.com> References: <8d961d900811120530i4258d8c4g37bbcf799d44d75e@mail.gmail.com> <57c63afe0811120559xc12bc80t66f0e6441900cac1@mail.gmail.com> <937d9d810811130659k4172be69n420217bd0541a51b@mail.gmail.com> Message-ID: <57c63afe0811130701g44570a3ak4acca4180566a8f4@mail.gmail.com> On Thu, Nov 13, 2008 at 8:59 AM, Peter Jaros wrote: > On Wed, Nov 12, 2008 at 8:59 AM, David Chelimsky wrote: >> On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy >> wrote: >>> World do >>> world = Object.new >>> world.extend(Logging::Logger) >>> world >>> end >> >> World do >> returning Cucumber::Rails::World do |world| >> world.extend(Logging::Logger) >> end >> end > > It would be really nice to be able to do: > > World do |world| > returning world do |w| > w.extend(Logging::Logger) > end > end > > This way steps files could extend the world by adding to a chain, > agnostic of the nature of the original world object. That's a cool idea - can you put a feature request in lighthouse? http://rspec.lighthouseapp.com/projects/16211-cucumber/overview Cheers, David > > Peter > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Thu Nov 13 10:15:01 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 13 Nov 2008 15:15:01 +0000 Subject: [rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc In-Reply-To: <57c63afe0811130701g44570a3ak4acca4180566a8f4@mail.gmail.com> References: <8d961d900811120530i4258d8c4g37bbcf799d44d75e@mail.gmail.com> <57c63afe0811120559xc12bc80t66f0e6441900cac1@mail.gmail.com> <937d9d810811130659k4172be69n420217bd0541a51b@mail.gmail.com> <57c63afe0811130701g44570a3ak4acca4180566a8f4@mail.gmail.com> Message-ID: <7AB07197-6AEC-4F8A-BE47-A4D758BB1BBB@mattwynne.net> On 13 Nov 2008, at 15:01, David Chelimsky wrote: > On Thu, Nov 13, 2008 at 8:59 AM, Peter Jaros > wrote: >> On Wed, Nov 12, 2008 at 8:59 AM, David Chelimsky > > wrote: >>> On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy >>> wrote: >>>> World do >>>> world = Object.new >>>> world.extend(Logging::Logger) >>>> world >>>> end >>> >>> World do >>> returning Cucumber::Rails::World do |world| >>> world.extend(Logging::Logger) >>> end >>> end >> >> It would be really nice to be able to do: >> >> World do |world| >> returning world do |w| >> w.extend(Logging::Logger) >> end >> end >> >> This way steps files could extend the world by adding to a chain, >> agnostic of the nature of the original world object. > > That's a cool idea - can you put a feature request in lighthouse? > > http://rspec.lighthouseapp.com/projects/16211-cucumber/overview > > Cheers, > David That's how I'd originally expected it to work, TBH. When I looked at the source and it didn't, I got scared :) cheers, Matt From ramon.tayag at gmail.com Thu Nov 13 10:18:11 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Thu, 13 Nov 2008 23:18:11 +0800 Subject: [rspec-users] Autotest style autotest/rails_rspec doesn't seem to exist. Aborting. In-Reply-To: <57c63afe0811130544mc8693d8t2e4fe5ccb76e818c@mail.gmail.com> References: <57c63afe0811130544mc8693d8t2e4fe5ccb76e818c@mail.gmail.com> Message-ID: Yup, I submoduled them :) I suppose that's just like an external svn repo. I'll try reinstalling them... but in the mean time, got any ideas? Ramon Tayag On Thu, Nov 13, 2008 at 9:44 PM, David Chelimsky wrote: > You need rspec-rails as well (plugin or gem, same version as rspec). > Do you have that already? > > Cheers, > David From ramon.tayag at gmail.com Thu Nov 13 10:24:16 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Thu, 13 Nov 2008 23:24:16 +0800 Subject: [rspec-users] testing an action which requires picture In-Reply-To: <3ed504aea01d24117705eaecb53cb437@ruby-forum.com> References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> <3ed504aea01d24117705eaecb53cb437@ruby-forum.com> Message-ID: Hmm.. not sure what that error is. The veterans in here might be able to help you. The create action should work... btw, this is a model spec, not a controller spec, just in case you're a newbie. Ramon Tayag On Thu, Nov 13, 2008 at 8:48 PM, Mano ah wrote: > Can I know what the create action handle. > > I am getting undefined method 'create' error From aslak.hellesoy at gmail.com Thu Nov 13 10:28:21 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 13 Nov 2008 16:28:21 +0100 Subject: [rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc In-Reply-To: <937d9d810811130659k4172be69n420217bd0541a51b@mail.gmail.com> References: <8d961d900811120530i4258d8c4g37bbcf799d44d75e@mail.gmail.com> <57c63afe0811120559xc12bc80t66f0e6441900cac1@mail.gmail.com> <937d9d810811130659k4172be69n420217bd0541a51b@mail.gmail.com> Message-ID: <8d961d900811130728l4d8d3a89j81473e94d6952c2c@mail.gmail.com> On Thu, Nov 13, 2008 at 3:59 PM, Peter Jaros wrote: > On Wed, Nov 12, 2008 at 8:59 AM, David Chelimsky wrote: >> On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy >> wrote: >>> World do >>> world = Object.new >>> world.extend(Logging::Logger) >>> world >>> end >> >> World do >> returning Cucumber::Rails::World do |world| >> world.extend(Logging::Logger) >> end >> end > > It would be really nice to be able to do: > > World do |world| > returning world do |w| > w.extend(Logging::Logger) > end > end > > This way steps files could extend the world by adding to a chain, > agnostic of the nature of the original world object. > You *may* want to be in control over the world type (class). For example, in Rails the world instance is a ActionController::Integration::Session instance (off the top of my head) and in vanilla Cucumber it is Object. what if you want to change that? Maybe Cucumber could send in a world instance it *thinks* is the one you want (allowing what you suggest (and allow the user to instantiate a different class if they want to). # I'm happy with the suggested type World do |world| returning world do |w| w.extend(Logging::Logger) end end # I want my own type! World do world = MyType.new returning world do |w| w.extend(Logging::Logger) end end I didn't see a ticket yet, so please add my comment or link to mail archive for this thread when you create the ticket. Cheers, Aslak > Peter > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From peter.a.jaros at gmail.com Thu Nov 13 11:04:59 2008 From: peter.a.jaros at gmail.com (Peter Jaros) Date: Thu, 13 Nov 2008 11:04:59 -0500 Subject: [rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc In-Reply-To: <57c63afe0811130701g44570a3ak4acca4180566a8f4@mail.gmail.com> References: <8d961d900811120530i4258d8c4g37bbcf799d44d75e@mail.gmail.com> <57c63afe0811120559xc12bc80t66f0e6441900cac1@mail.gmail.com> <937d9d810811130659k4172be69n420217bd0541a51b@mail.gmail.com> <57c63afe0811130701g44570a3ak4acca4180566a8f4@mail.gmail.com> Message-ID: <937d9d810811130804x75bf5e40o2aab460aeea3b72b@mail.gmail.com> On Thu, Nov 13, 2008 at 10:01 AM, David Chelimsky wrote: > That's a cool idea - can you put a feature request in lighthouse? Done: http://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/87-yield-existing-world-object-to-world-block Peter From byrnejb at harte-lyne.ca Thu Nov 13 11:51:27 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Thu, 13 Nov 2008 11:51:27 -0500 (EST) Subject: [rspec-users] Learning Cucumber Message-ID: <58350.216.185.71.22.1226595087.squirrel@webmail.harte-lyne.ca> Here is the scenario: Scenario: Create a new entity row Given I am on the new entity page When I fill in a textbox labelled "Common Name" with "My New Entity" And I fill in a textbox labelled "Full Legal Name:" with "My New Enitity is a CORP" And I select from a listbox labelled "Legal Form:" the value "CORP" And I press "Create" Then I should see "Entity was successfully created." Now, the suggestions that cucumber makes about missing step definitions are very useful, but I am not yet at the point where I understand enough of this to proceed. For the moment I need to sort out the relationship of cucumber with webrat. In the case above, what I see when I run rake features is this: Scenario: Create a new entity row # features/manage_entities.feature:7 Given I am on the new entity page # features/steps/entity_steps.rb:1 When I fill in a textbox labelled \ "Common Name" with "My New Entity" # features/steps/entity_steps.rb:5 And I fill in a textbox labelled \ "Full Legal Name:" with "My New Enitity is a CORP" \ # features/steps/entity_steps.rb:8 And I select from a listbox labelled \ "Legal Form:" the value "CORP" # features/steps/entity_steps.rb:11 And I press "Create" # features/steps/common_webrat.rb:4 Then I should see \ "Entity was successfully created." # features/steps/common_webrat.rb:36 expected: /Entity was successfully created./m, got: "\r\n References: <58350.216.185.71.22.1226595087.squirrel@webmail.harte-lyne.ca> Message-ID: <33030.216.185.71.22.1226595847.squirrel@webmail.harte-lyne.ca> On Thu, November 13, 2008 11:51, James B. Byrne wrote: > So, evidently I need some other specification to check the validity of the > action with respect to the web page displayed. Can some one give me a > hint as to what "I should see "X" should actually say? Should this be a > regex? In other worlds should the outcome be specified as: > > Then I should see "*Entity was successfully created*" > > Actually, I have discovered that what I need to do is to create some steps to move the data passed by the When clauses into the form variables and thus get the expected result instead of an error. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From peter.a.jaros at gmail.com Thu Nov 13 12:41:27 2008 From: peter.a.jaros at gmail.com (Peter Jaros) Date: Thu, 13 Nov 2008 12:41:27 -0500 Subject: [rspec-users] Skipped steps running stealthily Message-ID: <937d9d810811130941l220d011fnfd1825a3398c2a60@mail.gmail.com> I've just noticed that my "skipped" steps are actually running, but their errors are being swallowed. They can print to the screen, however. Is that intentional? It's certainly not what I was expecting. I assumed skipped steps were...skipped. Peter From dchelimsky at gmail.com Thu Nov 13 13:02:20 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Nov 2008 12:02:20 -0600 Subject: [rspec-users] Skipped steps running stealthily In-Reply-To: <937d9d810811130941l220d011fnfd1825a3398c2a60@mail.gmail.com> References: <937d9d810811130941l220d011fnfd1825a3398c2a60@mail.gmail.com> Message-ID: <57c63afe0811131002m12dc00a4la1b67233a64c3c15@mail.gmail.com> On Thu, Nov 13, 2008 at 11:41 AM, Peter Jaros wrote: > I've just noticed that my "skipped" steps are actually running, but > their errors are being swallowed. They can print to the screen, > however. Is that intentional? It's certainly not what I was > expecting. I assumed skipped steps were...skipped. Swallowing the errors is intentional, because once a previous step is either pending or failing, subsequent failures/successes don't really mean anything. Perhaps the thing to do is really skip them. If you think that is the way to go, please add a ticket. Another possibility would be to really skip these by default, but have a flag that runs and reports all steps (even the ones that are currently skipped). I can imagine that this would be useful in debugging, but I wouldn't want it to be the default because of the unnecessary noise it would create most of the time. WDYT? > > Peter > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From msassak at gmail.com Thu Nov 13 13:49:26 2008 From: msassak at gmail.com (Mike Sassak) Date: Thu, 13 Nov 2008 13:49:26 -0500 Subject: [rspec-users] Selecting a date with Webrat Message-ID: <339800360811131049v79555fb8n3a1ef6a67db397d@mail.gmail.com> Hi, I'm writing a scenario that needs to select date values from a form created with Rails' form_for() method, and I'm looking for a clean way to do that by specifying only the label (in this case "Date"), rather than by selecting from each select list one by one. What I'd like to be able to write is: When I select "2008-November-13" from "Date" (or something similar), but this fails because the Date label doesn't really apply to the individual select_lists. If I write instead When I select "2008" from "id_from_year_select_1i" it works, but then I not only need to do that once for each select, but I need to specify the id, which could change if my model changes. The first problem could be gotten around by writing a new webrat step (corresponding to, say, "When I select the date "2008-November-13" from "Date") but I would still need to specify the ids from each select. Is there is a better way to do this? Thanks, Mike From nick at deadorange.com Thu Nov 13 13:50:32 2008 From: nick at deadorange.com (Nick Hoffman) Date: Thu, 13 Nov 2008 13:50:32 -0500 Subject: [rspec-users] Mixing in spec helper methods In-Reply-To: <491B4CC0.6070607@benmabey.com> References: <15E2472C-4E9D-4C85-84C6-243B00071EEC@deadorange.com> <491A23CC.6040202@benmabey.com> <491B4CC0.6070607@benmabey.com> Message-ID: <16107A9D-5B1B-4B67-986C-4671042EB942@deadorange.com> On 2008-11-12, at 16:38, Ben Mabey wrote: > Nick Hoffman wrote: >> After digesting that post again, especially the contents of >> #self.included , I noticed that one could alternatively do this: >> >> module AssignMacro >> def self.extended(receiver) >> receiver.extend ExampleGroupMethods >> receiver.send :include, ExampleMethods >> end >> end >> >> describe UserPhotosController do >> describe "GET 'users/1/photos/2'" do >> extend AssignMacro >> # ... >> end >> end >> >> Is one approach more preferable? Or should one do this so that both >> "include AssignMacro" and "extend AssignMacro" give the same, >> desired, result?: >> >> module AssignMacro >> def self.included(receiver) >> receiver.extend ExampleGroupMethods >> receiver.send :include, ExampleMethods >> end >> >> class << self >> alias_method :extended, :included >> end >> end >> >> Thanks for your input, guys. >> -Nick > > Some people would say that using the included or extended module > hooks like that are evil.[1] That said it is a very common ruby > idiom even if it is bad. If you are going to use the evil idiom > then I would suggest using include and not extend since it is the > idiom. :) > > Another way to do it that wouldn't take advantage of the evil hooks > would be: > > describe UserPhotosController do > describe "GET 'users/1/photos/2'" do > extend AssignMacro::ExampleGroupMethods > include AssignMacro::ExampleMethods > # ... > end > > Of course that is somewhat annoying to type everywhere. So perhaps > you could add another example group method that would mix in > macors.. likes so: > > describe UserPhotosController do > describe "GET 'users/1/photos/2'" do > use_macro AssignMacro > # ... > end > end > > The 'use_maco' would be a module that you mix in onto all rspec's > example group methods that would simply include and extend the given > module's ExampleMethods and ExampleGroupMethods modules respectively. > > The 'use_macro' is probably more clear than the hooks. Just a > thought. > > -Ben > > > 1. http://olabini.com/blog/2008/09/evil-hook-methods/ The "evil hook methods" article explained exactly how I was feeling. Everyone's different, but I feel dirty extending the receiver in #included , and vice versa. I've decided to go along with your first suggested alternative: ## spec/spec_helper.rb # ..snip.. Spec::Runner.configure do |config| # ..snip.. config.extend AuthSpecHelpers::ExampleGroupMethods, :type => :controller config.include AuthSpecHelpers::ExampleMethods, :type => :controller end Thanks again for taking the time to explain all of this, Ben. I really learned a lot. Cheers, Nick From byrnejb at harte-lyne.ca Thu Nov 13 14:02:15 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Thu, 13 Nov 2008 14:02:15 -0500 (EST) Subject: [rspec-users] webrat cannot find label? Message-ID: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> Cucumber 0.1.9, Rails 2.2.0RC1, Ruby 1.8.6, Webrat... etc. Here is the scenario: Scenario: Attempt to ADD a VALID entity Given I am on the new entity page When I fill in "Common Name" with "My Common Name" And I to select "CORP" from the list labelled "Legal Form" And I fill in "Full Legal Name" with "My Full Legal Name"e And I press "Create" Then I should see "was successfully created" What is the correct syntax to test selecting from a range of values present in an input box? I have tried several variants of "select x from y" and I have tried to match the syntax of webrat to cucumber but nothing I do seems to work as I anticipate. Do I have to write my own step for this sort of thing? The "fill in" syntax seems to find a generated step, because I certainly have not written one for it. I so,. should not all of the input methods do likewise? Guidance will be greatly appreciated. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From ben at benmabey.com Thu Nov 13 14:14:52 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 13 Nov 2008 12:14:52 -0700 Subject: [rspec-users] Selecting a date with Webrat In-Reply-To: <339800360811131049v79555fb8n3a1ef6a67db397d@mail.gmail.com> References: <339800360811131049v79555fb8n3a1ef6a67db397d@mail.gmail.com> Message-ID: <491C7CAC.8080003@benmabey.com> Mike Sassak wrote: > Hi, > > I'm writing a scenario that needs to select date values from a form > created with Rails' form_for() method, and I'm looking for a clean way > to do that by specifying only the label (in this case "Date"), rather > than by selecting from each select list one by one. > > What I'd like to be able to write is: > > When I select "2008-November-13" from "Date" > > (or something similar), but this fails because the Date label doesn't > really apply to the individual select_lists. If I write instead > > When I select "2008" from "id_from_year_select_1i" > > it works, but then I not only need to do that once for each select, > but I need to specify the id, which could change if my model changes. > The first problem could be gotten around by writing a new webrat step > (corresponding to, say, "When I select the date "2008-November-13" > from "Date") but I would still need to specify the ids from each > select. Is there is a better way to do this? > > Thanks, > Mike > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hey Mike, What I have done in the past is used the following helper in my stories: def selects_time(id_prefix, time) selects time.year, :from => "#{id_prefix}_1i" selects time.strftime('%B'), :from => "#{id_prefix}_2i" # month name, selects time.day, :from => "#{id_prefix}_3i" selects time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_4i" selects time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_5i" end I would use Time.parse to convert the string from the scenario to feed it into the helper. In my particular case the id prefix could be inferred easily from th the step, but your case might be different. That should hopefully get you started though. -Ben From msassak at gmail.com Thu Nov 13 14:20:59 2008 From: msassak at gmail.com (Mike Sassak) Date: Thu, 13 Nov 2008 14:20:59 -0500 Subject: [rspec-users] webrat cannot find label? In-Reply-To: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> Message-ID: <339800360811131120t70439cafyf4b5a98212770d14@mail.gmail.com> Hi James, If you're using the generated common_webrat steps that cucumber generates for Rails projects, then "I select X from Y" should work just fine. The step itself calls Webrat's select method like so: selects(value, :from => field). You can see an example of sorts in the first comments here: http://www.benmabey.com/2008/02/04/rspec-plain-text-stories-webrat-chunky-bacon/ HTH, Mike On Thu, Nov 13, 2008 at 2:02 PM, James B. Byrne wrote: > Cucumber 0.1.9, Rails 2.2.0RC1, Ruby 1.8.6, Webrat... etc. > > Here is the scenario: > > Scenario: Attempt to ADD a VALID entity > Given I am on the new entity page > When I fill in "Common Name" with "My Common Name" > And I to select "CORP" from the list labelled "Legal Form" > And I fill in "Full Legal Name" with "My Full Legal Name"e > And I press "Create" > Then I should see "was successfully created" > > What is the correct syntax to test selecting from a range of values > present in an input box? I have tried several variants of "select x from > y" and I have tried to match the syntax of webrat to cucumber but nothing > I do seems to work as I anticipate. Do I have to write my own step for > this sort of thing? The "fill in" syntax seems to find a generated step, > because I certainly have not written one for it. I so,. should not all of > the input methods do likewise? > > Guidance will be greatly appreciated. > > > -- > *** E-Mail is NOT a SECURE channel *** > James B. Byrne mailto:ByrneJB at Harte-Lyne.ca > Harte & Lyne Limited http://www.harte-lyne.ca > 9 Brockley Drive vox: +1 905 561 1241 > Hamilton, Ontario fax: +1 905 561 0757 > Canada L8E 3C3 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Nov 13 14:20:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Nov 2008 13:20:18 -0600 Subject: [rspec-users] Selecting a date with Webrat In-Reply-To: <491C7CAC.8080003@benmabey.com> References: <339800360811131049v79555fb8n3a1ef6a67db397d@mail.gmail.com> <491C7CAC.8080003@benmabey.com> Message-ID: <57c63afe0811131120y28efb2d2p95801d21ae2ef1a2@mail.gmail.com> On Thu, Nov 13, 2008 at 1:14 PM, Ben Mabey wrote: > Mike Sassak wrote: >> >> Hi, >> >> I'm writing a scenario that needs to select date values from a form >> created with Rails' form_for() method, and I'm looking for a clean way >> to do that by specifying only the label (in this case "Date"), rather >> than by selecting from each select list one by one. >> >> What I'd like to be able to write is: >> >> When I select "2008-November-13" from "Date" >> >> (or something similar), but this fails because the Date label doesn't >> really apply to the individual select_lists. If I write instead >> >> When I select "2008" from "id_from_year_select_1i" >> >> it works, but then I not only need to do that once for each select, >> but I need to specify the id, which could change if my model changes. >> The first problem could be gotten around by writing a new webrat step >> (corresponding to, say, "When I select the date "2008-November-13" >> from "Date") but I would still need to specify the ids from each >> select. Is there is a better way to do this? >> >> Thanks, >> Mike >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > Hey Mike, > What I have done in the past is used the following helper in my stories: > > def selects_time(id_prefix, time) > selects time.year, :from => "#{id_prefix}_1i" > selects time.strftime('%B'), :from => "#{id_prefix}_2i" # month name, > selects time.day, :from => "#{id_prefix}_3i" > selects time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_4i" > selects time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_5i" > end Somebody should wrap that up in a plugin! I've done that before too. I can do it in March sometime, so if any of you can do it sooner, that'd rock :) > > I would use Time.parse to convert the string from the scenario to feed it > into the helper. In my particular case the id prefix could be inferred > easily from th the step, but your case might be different. That should > hopefully get you started though. > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From byrnejb at harte-lyne.ca Thu Nov 13 14:41:02 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Thu, 13 Nov 2008 14:41:02 -0500 (EST) Subject: [rspec-users] webrat cannot find label? In-Reply-To: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> Message-ID: <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> On Thu, November 13, 2008 14:02, James B. Byrne wrote: > > What is the correct syntax to test selecting from a range of values > present in an input box? ... The webrat API specifies this: selects(option_text, options = {}) Verifies that a an option element exists on the current page with the specified text. You can optionally restrict the search to a specific select list by assigning options[:from] the value of the select list?s name or a label. Stores the option?s value to be sent when the form is submitted. Examples: selects "January" selects "February", :from => "event_month" selects "February", :from => "Event Month" But when I try to use something like: And I select "CORP" from "Legal Form" # features/step_definitions/webrat_steps.rb:16 This is what happens: You have a nil object when you didn't expect it! The error occurred while evaluating nil.choose (NoMethodError) /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/core/scope.rb:91:in `selects' /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/rails.rb:88:in `send' So, checking out webrat.steps I see this: When /^I select "(.*)" from "(.*)"$/ do |value, field| selects(value, :from => field) end So, as far as I can make out, given the webrat API specifies that a label is an acceptable target, this should work. But it evidently does not. Is this a webrat problem then? -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From msassak at gmail.com Thu Nov 13 14:42:20 2008 From: msassak at gmail.com (Mike Sassak) Date: Thu, 13 Nov 2008 14:42:20 -0500 Subject: [rspec-users] Selecting a date with Webrat In-Reply-To: <491C7CAC.8080003@benmabey.com> References: <339800360811131049v79555fb8n3a1ef6a67db397d@mail.gmail.com> <491C7CAC.8080003@benmabey.com> Message-ID: <339800360811131142k1c303f1xf646536743e0d618@mail.gmail.com> It sure does. Thanks! On Thu, Nov 13, 2008 at 2:14 PM, Ben Mabey wrote: > Mike Sassak wrote: >> >> Hi, >> >> I'm writing a scenario that needs to select date values from a form >> created with Rails' form_for() method, and I'm looking for a clean way >> to do that by specifying only the label (in this case "Date"), rather >> than by selecting from each select list one by one. >> >> What I'd like to be able to write is: >> >> When I select "2008-November-13" from "Date" >> >> (or something similar), but this fails because the Date label doesn't >> really apply to the individual select_lists. If I write instead >> >> When I select "2008" from "id_from_year_select_1i" >> >> it works, but then I not only need to do that once for each select, >> but I need to specify the id, which could change if my model changes. >> The first problem could be gotten around by writing a new webrat step >> (corresponding to, say, "When I select the date "2008-November-13" >> from "Date") but I would still need to specify the ids from each >> select. Is there is a better way to do this? >> >> Thanks, >> Mike >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > Hey Mike, > What I have done in the past is used the following helper in my stories: > > def selects_time(id_prefix, time) > selects time.year, :from => "#{id_prefix}_1i" > selects time.strftime('%B'), :from => "#{id_prefix}_2i" # month name, > selects time.day, :from => "#{id_prefix}_3i" > selects time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_4i" > selects time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_5i" > end > > I would use Time.parse to convert the string from the scenario to feed it > into the helper. In my particular case the id prefix could be inferred > easily from th the step, but your case might be different. That should > hopefully get you started though. > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Nov 13 14:44:58 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Nov 2008 13:44:58 -0600 Subject: [rspec-users] webrat cannot find label? In-Reply-To: <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> Message-ID: <57c63afe0811131144r7d4babfchdc219e56afb18640@mail.gmail.com> On Thu, Nov 13, 2008 at 1:41 PM, James B. Byrne wrote: > > On Thu, November 13, 2008 14:02, James B. Byrne wrote: > >> >> What is the correct syntax to test selecting from a range of values >> present in an input box? ... > > The webrat API specifies this: > > selects(option_text, options = {}) > > Verifies that a an option element exists on the current page with the > specified text. You can optionally restrict the search to a specific > select list by assigning options[:from] the value of the select list's > name or a label. Stores the option's value to be sent when the form is > submitted. > > Examples: > > selects "January" > selects "February", :from => "event_month" > selects "February", :from => "Event Month" > > > > But when I try to use something like: > > And I select "CORP" from "Legal Form" > # features/step_definitions/webrat_steps.rb:16 > > This is what happens: > > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.choose (NoMethodError) > /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/core/scope.rb:91:in > `selects' > /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/rails.rb:88:in > `send' > > > So, checking out webrat.steps I see this: > > When /^I select "(.*)" from "(.*)"$/ do |value, field| > selects(value, :from => field) > end > > So, as far as I can make out, given the webrat API specifies that a label > is an acceptable target, this should work. But it evidently does not. Is > this a webrat problem then? It seems like it. Webrat has its own tracker at http://webrat.lighthouseapp.com - can you submit a ticket there please? > > > -- > *** E-Mail is NOT a SECURE channel *** > James B. Byrne mailto:ByrneJB at Harte-Lyne.ca > Harte & Lyne Limited http://www.harte-lyne.ca > 9 Brockley Drive vox: +1 905 561 1241 > Hamilton, Ontario fax: +1 905 561 0757 > Canada L8E 3C3 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From byrnejb at harte-lyne.ca Thu Nov 13 14:59:33 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Thu, 13 Nov 2008 14:59:33 -0500 (EST) Subject: [rspec-users] webrat cannot find label? In-Reply-To: <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> Message-ID: <55015.216.185.71.22.1226606373.squirrel@webmail.harte-lyne.ca> On Thu, November 13, 2008 14:41, James B. Byrne wrote: > > So, as far as I can make out, given the webrat API specifies that a label > is an acceptable target, this should work. But it evidently does not. Is > this a webrat problem then? > Does anyone know why webrat does this for select: def selects(option_text, options = {}) find_select_option(option_text, options[:from]).choose end But uses field_locator for everything else except click: def fill_in(field_locator, options = {}) def uncheck(field_locator) def choose(field_locator) def attach_file(field_locator, path, content_type = nil -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From msassak at gmail.com Thu Nov 13 15:53:34 2008 From: msassak at gmail.com (Mike Sassak) Date: Thu, 13 Nov 2008 15:53:34 -0500 Subject: [rspec-users] webrat cannot find label? In-Reply-To: <55015.216.185.71.22.1226606373.squirrel@webmail.harte-lyne.ca> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> <55015.216.185.71.22.1226606373.squirrel@webmail.harte-lyne.ca> Message-ID: <339800360811131253x6f495b25y35fa63d5d7486b44@mail.gmail.com> That's odd. I use the same step in my own scenarios and it works fine. One problem I did run into is that the label alone isn't always enough for webrat to find the input field. The id on the label must match the id on the labeled field for selection by label to work. Sometimes they differ, for example, if you use form_for() but don't call the label method on the yielded form object, and instead use the label_tag helper method. I ran into this just yesterday with one of the views restful_authentication generates. It had generated something like this (for a Reviewer model): <%= label_tag 'password_confirmation', 'Confirm Password' %> <%= f.text_field :password_confirmation %> Which produced HTML like this: I changed it to this: <%= f.label :password_confirmation, "Confirm Password" %> <%= f.text_field :password_confirmation %> Which produces this:
And it worked fine. Mike On Nov 13, 2008 2:42 PM, "James B. Byrne" wrote: On Thu, November 13, 2008 14:02, James B. Byrne wrote: > > What is the correct syntax to test sele... > present in an input box? ... The webrat API specifies this: selects(option_text, options = {}) Verifies that a an option element exists on the current page with the specified text. You can optionally restrict the search to a specific select list by assigning options[:from] the value of the select list's name or a label. Stores the option's value to be sent when the form is submitted. Examples: selects "January" selects "February", :from => "event_month" selects "February", :from => "Event Month" But when I try to use something like: And I select "CORP" from "Legal Form" # features/step_definitions/webrat_steps.rb:16 This is what happens: You have a nil object when you didn't expect it! The error occurred while evaluating nil.choose (NoMethodError) /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/core/scope.rb:91:in `selects' /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/rails.rb:88:in `send' So, checking out webrat.steps I see this: When /^I select "(.*)" from "(.*)"$/ do |value, field| selects(value, :from => field) end So, as far as I can make out, given the webrat API specifies that a label is an acceptable target, this should work. But it evidently does not. Is this a webrat problem then? -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:... From aslak.hellesoy at gmail.com Thu Nov 13 16:36:02 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 13 Nov 2008 22:36:02 +0100 Subject: [rspec-users] Selecting a date with Webrat In-Reply-To: <57c63afe0811131120y28efb2d2p95801d21ae2ef1a2@mail.gmail.com> References: <339800360811131049v79555fb8n3a1ef6a67db397d@mail.gmail.com> <491C7CAC.8080003@benmabey.com> <57c63afe0811131120y28efb2d2p95801d21ae2ef1a2@mail.gmail.com> Message-ID: <8d961d900811131336i20abd64fwf219a8cf1810d049@mail.gmail.com> On Thu, Nov 13, 2008 at 8:20 PM, David Chelimsky wrote: > On Thu, Nov 13, 2008 at 1:14 PM, Ben Mabey wrote: >> Mike Sassak wrote: >>> >>> Hi, >>> >>> I'm writing a scenario that needs to select date values from a form >>> created with Rails' form_for() method, and I'm looking for a clean way >>> to do that by specifying only the label (in this case "Date"), rather >>> than by selecting from each select list one by one. >>> >>> What I'd like to be able to write is: >>> >>> When I select "2008-November-13" from "Date" >>> >>> (or something similar), but this fails because the Date label doesn't >>> really apply to the individual select_lists. If I write instead >>> >>> When I select "2008" from "id_from_year_select_1i" >>> >>> it works, but then I not only need to do that once for each select, >>> but I need to specify the id, which could change if my model changes. >>> The first problem could be gotten around by writing a new webrat step >>> (corresponding to, say, "When I select the date "2008-November-13" >>> from "Date") but I would still need to specify the ids from each >>> select. Is there is a better way to do this? >>> >>> Thanks, >>> Mike >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> Hey Mike, >> What I have done in the past is used the following helper in my stories: >> >> def selects_time(id_prefix, time) >> selects time.year, :from => "#{id_prefix}_1i" >> selects time.strftime('%B'), :from => "#{id_prefix}_2i" # month name, >> selects time.day, :from => "#{id_prefix}_3i" >> selects time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_4i" >> selects time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_5i" >> end > > Somebody should wrap that up in a plugin! I've done that before too. I > can do it in March sometime, so if any of you can do it sooner, that'd > rock :) > Or better yet - add it to webrat proper and ask Bryan to pull it. (It's rails specific, so it should only be in the rails part of webrat). Aslak >> >> I would use Time.parse to convert the string from the scenario to feed it >> into the helper. In my particular case the id prefix could be inferred >> easily from th the step, but your case might be different. That should >> hopefully get you started though. >> >> -Ben >> _______________________________________________ >> 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 byrnejb at harte-lyne.ca Thu Nov 13 16:54:11 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Thu, 13 Nov 2008 16:54:11 -0500 (EST) Subject: [rspec-users] webrat cannot find label? In-Reply-To: <55015.216.185.71.22.1226606373.squirrel@webmail.harte-lyne.ca> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> <55015.216.185.71.22.1226606373.squirrel@webmail.harte-lyne.ca> Message-ID: <43114.216.185.71.22.1226613251.squirrel@webmail.harte-lyne.ca> On Thu, November 13, 2008 14:59, James B. Byrne wrote: > > So, as far as I can make out, given the webrat API specifies that a > label is an acceptable target, this should work. But it evidently > does not. Is this a webrat problem then? It seems as if I have run into two separate webrat problems. One is reported as ticket 28 and is fixed by the patch submitted by ticket 29. This involves not having the input field tags nested within the associated label tags. However, even with this cured the locator still returns a nil object for the select, whether searched for by label or by name, causing a failure so there is still a problem with webrat. Does anyone have any workarounds that they can suggest? -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From ben at benmabey.com Thu Nov 13 23:48:11 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 13 Nov 2008 21:48:11 -0700 Subject: [rspec-users] Selecting a date with Webrat In-Reply-To: <8d961d900811131336i20abd64fwf219a8cf1810d049@mail.gmail.com> References: <339800360811131049v79555fb8n3a1ef6a67db397d@mail.gmail.com> <491C7CAC.8080003@benmabey.com> <57c63afe0811131120y28efb2d2p95801d21ae2ef1a2@mail.gmail.com> <8d961d900811131336i20abd64fwf219a8cf1810d049@mail.gmail.com> Message-ID: <491D030B.3090901@benmabey.com> aslak hellesoy wrote: > On Thu, Nov 13, 2008 at 8:20 PM, David Chelimsky wrote: > >> On Thu, Nov 13, 2008 at 1:14 PM, Ben Mabey wrote: >> >>> Mike Sassak wrote: >>> >>>> Hi, >>>> >>>> I'm writing a scenario that needs to select date values from a form >>>> created with Rails' form_for() method, and I'm looking for a clean way >>>> to do that by specifying only the label (in this case "Date"), rather >>>> than by selecting from each select list one by one. >>>> >>>> What I'd like to be able to write is: >>>> >>>> When I select "2008-November-13" from "Date" >>>> >>>> (or something similar), but this fails because the Date label doesn't >>>> really apply to the individual select_lists. If I write instead >>>> >>>> When I select "2008" from "id_from_year_select_1i" >>>> >>>> it works, but then I not only need to do that once for each select, >>>> but I need to specify the id, which could change if my model changes. >>>> The first problem could be gotten around by writing a new webrat step >>>> (corresponding to, say, "When I select the date "2008-November-13" >>>> from "Date") but I would still need to specify the ids from each >>>> select. Is there is a better way to do this? >>>> >>>> Thanks, >>>> Mike >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> >>> Hey Mike, >>> What I have done in the past is used the following helper in my stories: >>> >>> def selects_time(id_prefix, time) >>> selects time.year, :from => "#{id_prefix}_1i" >>> selects time.strftime('%B'), :from => "#{id_prefix}_2i" # month name, >>> selects time.day, :from => "#{id_prefix}_3i" >>> selects time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_4i" >>> selects time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_5i" >>> end >>> >> Somebody should wrap that up in a plugin! I've done that before too. I >> can do it in March sometime, so if any of you can do it sooner, that'd >> rock :) >> >> > > Or better yet - add it to webrat proper and ask Bryan to pull it. > (It's rails specific, so it should only be in the rails part of > webrat). > > Aslak > > Good idea, guys! And yes, I can take a hint. :) Here is what I was able to get done tonight: http://github.com/bmabey/webrat/commit/80d3eba59e386790ca67175e412317648c92191a There are still some things I need to address and test more but the functionality is mostly there. I'll report back if/when Bryan merges it into webrat and I'll create a step for it in cucumber's webrat_steps.rb. You can also follow the progress on webrat's lighthouse: http://webrat.lighthouseapp.com/projects/10503-webrat/tickets/36-add-selects_time-helper -Ben >>> I would use Time.parse to convert the string from the scenario to feed it >>> into the helper. In my particular case the id prefix could be inferred >>> easily from th the step, but your case might be different. That should >>> hopefully get you started though. >>> >>> -Ben >>> _______________________________________________ >>> 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 apremdas at gmail.com Fri Nov 14 01:53:14 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 14 Nov 2008 06:53:14 +0000 Subject: [rspec-users] Learning Cucumber In-Reply-To: <33030.216.185.71.22.1226595847.squirrel@webmail.harte-lyne.ca> References: <58350.216.185.71.22.1226595087.squirrel@webmail.harte-lyne.ca> <33030.216.185.71.22.1226595847.squirrel@webmail.harte-lyne.ca> Message-ID: <88fd8ddc0811132253w146dfc37s594e1b1cd91b8ea3@mail.gmail.com> What you're doing here is writing imperative features. Writing declarative features might be a better alternative. Instead of Given I am on the new entity page When I fill in a textbox labelled "Common Name" with "My New Entity" And I fill in a textbox labelled "Full Legal Name:" with "My New Enitity is a CORP" And I select from a listbox labelled "Legal Form:" the value "CORP" And I press "Create" Then I should see "Entity was successfully created." You could consider Given I am on the new entity page When I correctly fill in the new entity form Then I should see a confirmation Then the feature has much less technical stuff in it that 1) Hide the intent 2) Make the story brittle to cosmetic changes, in particular to small rewordings of error messages and confirmations A side effect of this is you need much less regex magic to match your expressions. HTH Andrew 2008/11/13 James B. Byrne : > > On Thu, November 13, 2008 11:51, James B. Byrne wrote: > >> So, evidently I need some other specification to check the validity of the >> action with respect to the web page displayed. Can some one give me a >> hint as to what "I should see "X" should actually say? Should this be a >> regex? In other worlds should the outcome be specified as: >> >> Then I should see "*Entity was successfully created*" >> >> > > Actually, I have discovered that what I need to do is to create some steps > to move the data passed by the When clauses into the form variables and > thus get the expected result instead of an error. > > > -- > *** E-Mail is NOT a SECURE channel *** > James B. Byrne mailto:ByrneJB at Harte-Lyne.ca > Harte & Lyne Limited http://www.harte-lyne.ca > 9 Brockley Drive vox: +1 905 561 1241 > Hamilton, Ontario fax: +1 905 561 0757 > Canada L8E 3C3 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Fri Nov 14 06:29:54 2008 From: lists at ruby-forum.com (Mano ah) Date: Fri, 14 Nov 2008 12:29:54 +0100 Subject: [rspec-users] testing an action which requires picture In-Reply-To: References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> <3ed504aea01d24117705eaecb53cb437@ruby-forum.com> Message-ID: can i know how to test a picture upload which dosent interact with db my code is def scan #------- if request.post? image = Image.new image.blob= params[:image][:blob] image.save_picture end -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Fri Nov 14 07:25:00 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 14 Nov 2008 12:25:00 +0000 Subject: [rspec-users] LinkedIn Group Message-ID: <25968557-0505-4BDE-8A14-260845EBCD5D@patchspace.co.uk> Hi I was just thinking, would it be a good thing to have a LinkedIn group for RSpec? It'd be great to be able to find other RSpec users, either to help organise local Ruby events or to help when hiring people. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From matt at mattwynne.net Fri Nov 14 07:27:08 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 14 Nov 2008 12:27:08 +0000 Subject: [rspec-users] LinkedIn Group In-Reply-To: <25968557-0505-4BDE-8A14-260845EBCD5D@patchspace.co.uk> References: <25968557-0505-4BDE-8A14-260845EBCD5D@patchspace.co.uk> Message-ID: <9ABD7E89-83DE-45B1-869D-58BCA6E6C023@mattwynne.net> On 14 Nov 2008, at 12:25, Ashley Moran wrote: > Hi > > I was just thinking, would it be a good thing to have a LinkedIn > group for RSpec? It'd be great to be able to find other RSpec > users, either to help organise local Ruby events or to help when > hiring people. What about abstracting it a level and making it a BDD group? The 'Outside In' Club. Or something. :) From ashley.moran at patchspace.co.uk Fri Nov 14 07:46:01 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 14 Nov 2008 12:46:01 +0000 Subject: [rspec-users] LinkedIn Group In-Reply-To: <9ABD7E89-83DE-45B1-869D-58BCA6E6C023@mattwynne.net> References: <25968557-0505-4BDE-8A14-260845EBCD5D@patchspace.co.uk> <9ABD7E89-83DE-45B1-869D-58BCA6E6C023@mattwynne.net> Message-ID: On Nov 14, 2008, at 12:27 pm, Matt Wynne wrote: > What about abstracting it a level and making it a BDD group? The > 'Outside In' Club. Or something. :) There's probably room for both. There's a Web Application Frameworks Users Group as well as Rails and Merb groups, for example. But a BDD group would be cool too. Anyone here willing to start an RSpec group? It'd make sense for it to be one of the RSpec core team, I guess, but failing that I'd be happy to. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From zuperinfinite at gmail.com Fri Nov 14 07:51:15 2008 From: zuperinfinite at gmail.com (Bart Zonneveld) Date: Fri, 14 Nov 2008 13:51:15 +0100 Subject: [rspec-users] webrat cannot find label? In-Reply-To: <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> Message-ID: <1D14481D-16CB-4043-A444-BAF937D1C5B3@gmail.com> On 13-nov-2008, at 20:41, James B. Byrne wrote: > > On Thu, November 13, 2008 14:02, James B. Byrne wrote: > >> >> What is the correct syntax to test selecting from a range of values >> present in an input box? ... > > The webrat API specifies this: > > selects(option_text, options = {}) > > Verifies that a an option element exists on the current page with the > specified text. You can optionally restrict the search to a specific > select list by assigning options[:from] the value of the select list?s > name or a label. Stores the option?s value to be sent when the form is > submitted. > > Examples: > > selects "January" > selects "February", :from => "event_month" > selects "February", :from => "Event Month" > > > > But when I try to use something like: > > And I select "CORP" from "Legal Form" > # features/step_definitions/webrat_steps.rb:16 > > This is what happens: > > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.choose (NoMethodError) > /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/core/ > scope.rb:91:in > `selects' > /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/rails.rb: > 88:in > `send' Are you 100% sure the thing you are selecting exists in the select box? That has bitten me in the butt a few times.. cheers, bartz From matt at mattwynne.net Fri Nov 14 10:25:04 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 14 Nov 2008 15:25:04 +0000 Subject: [rspec-users] Cucumber: Fix for Textmate syntax highlighting Message-ID: <0F61A7F9-3FCE-4209-B2AA-DC48B370A4F5@mattwynne.net> It's been bugging me for a while that a lot of the regular expressions in my step matchers look ugly in TextMate because it doesn't recognise them. I patched the Ruby tmbundle with a fix. If this bugs you too, you can pull down my Ruby.tmbundle from here: http://github.com/mattwynne/textmate-bundles/tree/master Or has somebody already solved this problem some other way? cheers, Matt From ashley.moran at patchspace.co.uk Fri Nov 14 11:13:37 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 14 Nov 2008 16:13:37 +0000 Subject: [rspec-users] Cucumber: Fix for Textmate syntax highlighting In-Reply-To: <0F61A7F9-3FCE-4209-B2AA-DC48B370A4F5@mattwynne.net> References: <0F61A7F9-3FCE-4209-B2AA-DC48B370A4F5@mattwynne.net> Message-ID: <790E5AA0-356D-4FD1-96B6-52A0FE08AA9E@patchspace.co.uk> On Nov 14, 2008, at 3:25 pm, Matt Wynne wrote: > It's been bugging me for a while that a lot of the regular > expressions in my step matchers look ugly in TextMate because it > doesn't recognise them. > > I patched the Ruby tmbundle with a fix. If this bugs you too, you > can pull down my Ruby.tmbundle from here: > http://github.com/mattwynne/textmate-bundles/tree/master > > Or has somebody already solved this problem some other way? I've always stuck %r in front of the regex: Given %r/blah/ But I'd prefer a better fix! Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From nick at deadorange.com Fri Nov 14 11:53:32 2008 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 14 Nov 2008 11:53:32 -0500 Subject: [rspec-users] testing an action which requires picture In-Reply-To: References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> <3ed504aea01d24117705eaecb53cb437@ruby-forum.com> Message-ID: On 2008-11-14, at 06:29, Mano ah wrote: > can i know how to test a picture upload which dosent interact with db > > my code is > > > def scan > #------- > > if request.post? > > image = Image.new > > image.blob= params[:image][:blob] > > image.save_picture > > end > -- Hi Mano. It doesn't really matter whether or not your "picture" model interacts with a database. Simply use mocks and stubs when speccing #scan , and you'll be good. For example: describe '#scan' do describe 'receives a POST request' do before :each do # mock an Image instance # stub Image#new end it 'should create a new Image' it "should set the new image's 'blob' attribute" it 'should save the new image' end describe 'receives a non-POST request' do # stuff here end end Obviously you have to fill in the contents of those #it blocks, but that's really all you need. -Nick From lists at ruby-forum.com Fri Nov 14 12:32:44 2008 From: lists at ruby-forum.com (James Byrne) Date: Fri, 14 Nov 2008 18:32:44 +0100 Subject: [rspec-users] webrat cannot find label? In-Reply-To: <1D14481D-16CB-4043-A444-BAF937D1C5B3@gmail.com> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> <1D14481D-16CB-4043-A444-BAF937D1C5B3@gmail.com> Message-ID: Bart Zonneveld wrote: > On 13-nov-2008, at 20:41, James B. Byrne wrote: > > Are you 100% sure the thing you are selecting exists in the select > box? That has bitten me in the butt a few times.. > > cheers, > bartz This is what Rails generates from the view:

So, it appears to me that the label and target ids match, "entity_entity_legal_form"; and the value that I am testing, "CORP" is available in the list of values. -- Posted via http://www.ruby-forum.com/. From peter.a.jaros at gmail.com Fri Nov 14 12:37:43 2008 From: peter.a.jaros at gmail.com (Peter Jaros) Date: Fri, 14 Nov 2008 12:37:43 -0500 Subject: [rspec-users] Skipped steps running stealthily In-Reply-To: <57c63afe0811131002m12dc00a4la1b67233a64c3c15@mail.gmail.com> References: <937d9d810811130941l220d011fnfd1825a3398c2a60@mail.gmail.com> <57c63afe0811131002m12dc00a4la1b67233a64c3c15@mail.gmail.com> Message-ID: <937d9d810811140937u7890431diee1f58686debdefe@mail.gmail.com> On Thu, Nov 13, 2008 at 1:02 PM, David Chelimsky wrote: > Perhaps the thing to do is really skip them. If you think that is the > way to go, please add a ticket. Ticketed: http://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/90-really-skip-skipped-steps From msassak at gmail.com Fri Nov 14 13:00:08 2008 From: msassak at gmail.com (Mike Sassak) Date: Fri, 14 Nov 2008 13:00:08 -0500 Subject: [rspec-users] webrat cannot find label? In-Reply-To: References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> <1D14481D-16CB-4043-A444-BAF937D1C5B3@gmail.com> Message-ID: <339800360811141000y3a2993b8r8e935676cdff6dc3@mail.gmail.com> What happens if you remove the b and br tags from within the label and change the text to "Legal Form" only, without the colon? On Fri, Nov 14, 2008 at 12:32 PM, James Byrne wrote: > Bart Zonneveld wrote: >> On 13-nov-2008, at 20:41, James B. Byrne wrote: > >> >> Are you 100% sure the thing you are selecting exists in the select >> box? That has bitten me in the butt a few times.. >> >> cheers, >> bartz > > This is what Rails generates from the view: > >

> > >

> > So, it appears to me that the label and target ids match, > "entity_entity_legal_form"; and the value that I am testing, "CORP" is > available in the list of values. > -- > 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 Fri Nov 14 13:45:19 2008 From: lists at ruby-forum.com (James Byrne) Date: Fri, 14 Nov 2008 19:45:19 +0100 Subject: [rspec-users] webrat cannot find label? In-Reply-To: <339800360811141000y3a2993b8r8e935676cdff6dc3@mail.gmail.com> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> <1D14481D-16CB-4043-A444-BAF937D1C5B3@gmail.com> <339800360811141000y3a2993b8r8e935676cdff6dc3@mail.gmail.com> Message-ID: <9e0054b063821b63ef62dcde366a7a3c@ruby-forum.com> Mike Sassak wrote: > What happens if you remove the b and br tags from within the label and > change the text to "Legal Form" only, without the colon? I get exactly the same behaviour: entities/new ...


... # rake features ... And I select "CORP" from "Legal Form" # features/step_definitions/webrat_steps.rb:16 You have a nil object when you didn't expect it! The error occurred while evaluating nil.choose (NoMethodError) /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/core/scope.rb:91:in `selects' -- Posted via http://www.ruby-forum.com/. From barry.mitchelson at gmail.com Fri Nov 14 13:54:07 2008 From: barry.mitchelson at gmail.com (Barry Mitchelson) Date: Fri, 14 Nov 2008 18:54:07 +0000 Subject: [rspec-users] webrat cannot find label? In-Reply-To: <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> Message-ID: On Thu, Nov 13, 2008 at 7:41 PM, James B. Byrne wrote: > > On Thu, November 13, 2008 14:02, James B. Byrne wrote: > > > > > What is the correct syntax to test selecting from a range of values > > present in an input box? ... > > The webrat API specifies this: > > selects(option_text, options = {}) > > Verifies that a an option element exists on the current page with the > specified text. You can optionally restrict the search to a specific > select list by assigning options[:from] the value of the select list's > name or a label. Stores the option's value to be sent when the form is > submitted. > The API says to use the option text, not the value. > > But when I try to use something like: > > And I select "CORP" from "Legal Form" > # features/step_definitions/webrat_steps.rb:16 > CORP is the value of the option, the text is "CORP - Corporation" Does this work? Barry > > This is what happens: > > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.choose (NoMethodError) > > /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/core/scope.rb:91:in > `selects' > /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/rails.rb:88:in > `send' > > > So, checking out webrat.steps I see this: > > When /^I select "(.*)" from "(.*)"$/ do |value, field| > selects(value, :from => field) > end > > So, as far as I can make out, given the webrat API specifies that a label > is an acceptable target, this should work. But it evidently does not. Is > this a webrat problem then? > > > -- > *** E-Mail is NOT a SECURE channel *** > James B. Byrne mailto:ByrneJB at Harte-Lyne.ca > Harte & Lyne Limited http://www.harte-lyne.ca > 9 Brockley Drive vox: +1 905 561 1241 > Hamilton, Ontario fax: +1 905 561 0757 > Canada L8E 3C3 > > _______________________________________________ > 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 Fri Nov 14 14:04:19 2008 From: lists at ruby-forum.com (James Byrne) Date: Fri, 14 Nov 2008 20:04:19 +0100 Subject: [rspec-users] Learning Cucumber In-Reply-To: <88fd8ddc0811132253w146dfc37s594e1b1cd91b8ea3@mail.gmail.com> References: <58350.216.185.71.22.1226595087.squirrel@webmail.harte-lyne.ca> <33030.216.185.71.22.1226595847.squirrel@webmail.harte-lyne.ca> <88fd8ddc0811132253w146dfc37s594e1b1cd91b8ea3@mail.gmail.com> Message-ID: <6cd3ec3dce0463bd0a7e9731d7c3e752@ruby-forum.com> Andrew Premdas wrote: > What you're doing here is writing imperative features. Writing > declarative features might be a better alternative. Instead of ... > > Given I am on the new entity page > When I correctly fill in the new entity form > Then I should see a confirmation > > Then the feature has much less technical stuff in it that > > 1) Hide the intent > 2) Make the story brittle to cosmetic changes, in particular to small > rewordings of error messages and confirmations > > A side effect of this is you need much less regex magic to match your > expressions. > This advice does help. Thank you. Is there a way to mix webrat and hard coded steps? In other words, if I have this in my steps file. Given /I am on the new entity page/ do visits "/entities/new" end When /I fill out the form correctly/ do fills_in("Common Name", :with => "My Common Name") fills_in("Legal Name", :with => "My Legal Name") Entity.entity_legal_name = "CORP" # does not work end Is this possible? How do I set the attribute "entity_legal_form" to "CORP" for that entity? I cannot figure out how to reference that entity instance. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Nov 14 15:38:59 2008 From: lists at ruby-forum.com (James Byrne) Date: Fri, 14 Nov 2008 21:38:59 +0100 Subject: [rspec-users] webrat cannot find label? In-Reply-To: References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> Message-ID: <2a58c2d66443cf1ca1386bd65116b109@ruby-forum.com> Barry Mitchelson wrote: > On Thu, Nov 13, 2008 at 7:41 PM, James B. Byrne > wrote: > >> >> On Thu, November 13, 2008 14:02, James B. Byrne wrote: >> >> > >> > What is the correct syntax to test selecting from a range of values >> > present in an input box? ... >> > >> The webrat API specifies this: >> >> selects(option_text, options = {}) >> >> Verifies that a an option element exists on the current page with the >> specified text. You can optionally restrict the search to a specific >> select list by assigning options[:from] the value of the select list's >> name or a label. Stores the option's value to be sent when the form is >> submitted. >> > > The API says to use the option text, not the value. > ... > > CORP is the value of the option, the text is "CORP - Corporation" > > Does this work? > > Barry I'll be damned... It works. Thank you so very much. I would never have connected "option_text" to the description portion of the list. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Nov 14 15:45:42 2008 From: lists at ruby-forum.com (James Byrne) Date: Fri, 14 Nov 2008 21:45:42 +0100 Subject: [rspec-users] webrat cannot find label? In-Reply-To: <2a58c2d66443cf1ca1386bd65116b109@ruby-forum.com> References: <44319.216.185.71.22.1226602935.squirrel@webmail.harte-lyne.ca> <59028.216.185.71.22.1226605262.squirrel@webmail.harte-lyne.ca> <2a58c2d66443cf1ca1386bd65116b109@ruby-forum.com> Message-ID: <04ca62aae5eacd8fdf2f79248a7e2537@ruby-forum.com> James Byrne wrote: > > I'll be damned... It works. > > Thank you so very much. I would never have connected "option_text" to > the description portion of the list. This is what I ended up with: features/entity.features ... Scenario: Attempt to ADD a VALID entity Given I am on the new entity page When I add a new entity correctly And I press "Create" Then I should see a success confirmation ... steps/entity.steps ... Given /I am on the new entity page/ do visits "/entities/new" end When /I add a new entity correctly/ do fills_in("Common Name", :with => "My Common Name") fills_in("Full Legal Name", :with => "My Legal Name") selects("CORP - Corporation", :from => "Legal Form") end Then /I should see a success confirmation/ do response.body.should =~ /successfully created/m end -- Posted via http://www.ruby-forum.com/. From shot at hot.pl Fri Nov 14 15:56:48 2008 From: shot at hot.pl (Shot (Piotr Szotkowski)) Date: Fri, 14 Nov 2008 21:56:48 +0100 Subject: [rspec-users] =?utf-8?q?How_to_spec_a_=28Trollop-based=29_binary?= =?utf-8?q?=E2=80=99s_internal_state=3F?= In-Reply-To: <1FE91266-D2EB-436E-B814-4FBF53B18740@patchspace.co.uk> References: <20081107130551.GC22622@durance.shot.pl> <20081107172421.GI22622@durance.shot.pl> <1FE91266-D2EB-436E-B814-4FBF53B18740@patchspace.co.uk> Message-ID: <20081114205648.GC3069@durance.shot.pl> Ashley Moran: > On Nov 07, 2008, at 5:24 pm, Shot (Piotr Szotkowski) wrote: >> Right, that?s why I suggested I could Kernel#eval the binary?s contents >> in the current process instead. This would require tricking Trollop, but >> I assume I could trick it by hand-crafting ARGV. > You might find Rick Bradley's talk[1] on regression testing flog > useful here. He starts by speccing the binary at a Ruby level. Heh ? I brought exactly this talk up twice when talking about specing binaries here (it was what pointed me in the direction that it would be actually good to spec/test them, actually). :) > Note, however, that later in the talk he admits he made a mistake in > not writing end-to-end tests soon enough. I think he should have run > the binary as a black box and just pushed binary code into lib sooner. Right. I think I agree that?s the best (and most elegant) way to test binaries. In my case, asfter some specing and some coding, it turns out I can?t really do this the way I wanted; most of the cases I need to test for are triggered with input that makes the binary run a long time (it?s the code behind my PhD thesis, so tons of computations). As I?m testing a black box with Kernel#`, I can?t mock/stub anything out. Seeing as my binary grew to over 80 lines, I guess my best bet is to pull out the gist of it into a separate Runner class, spec it (with mocks/stubs/fixtures) so it runs in a sane time and then only create a think binary wrapper around it (which will basically parse the options, set the config and then run the runner). Thanks a lot for the nice Cucumber example! It was most informative. -- Shot -- As the Slashdot distributed brain engine has observed, the ultimate test of any piece of equipment is to build a Beowulf cluster of it. -- Peter Seebach -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: not available URL: From matt at mattwynne.net Fri Nov 14 17:59:09 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 14 Nov 2008 22:59:09 +0000 Subject: [rspec-users] =?windows-1252?q?How_to_spec_a_=28Trollop-based=29_?= =?windows-1252?q?binary=92s_internal_state=3F?= In-Reply-To: <20081114205648.GC3069@durance.shot.pl> References: <20081107130551.GC22622@durance.shot.pl> <20081107172421.GI22622@durance.shot.pl> <1FE91266-D2EB-436E-B814-4FBF53B18740@patchspace.co.uk> <20081114205648.GC3069@durance.shot.pl> Message-ID: <6C577CEE-00CB-4B63-BB9F-342B68A2C3A8@mattwynne.net> On 14 Nov 2008, at 20:56, Shot (Piotr Szotkowski) wrote: > Seeing as my binary grew to over 80 lines, I guess my best bet is to > pull out the gist of it into a separate Runner class, spec it (with > mocks/stubs/fixtures) so it runs in a sane time and then only create > a think binary wrapper around it (which will basically parse the > options, set the config and then run the runner). Have a look at the source code for cucumber's binary, or rspec's 'spec' command. They're both about four lines long creating a (eminently spec-able) class that does the rest. cheers, Matt From bret at pettichord.com Fri Nov 14 19:13:03 2008 From: bret at pettichord.com (Bret Pettichord) Date: Fri, 14 Nov 2008 18:13:03 -0600 Subject: [rspec-users] undefined method `run?' for Test::Unit:Module Message-ID: Hello. I just ran into an error I wanted to share. The error message is below. I tracked down the error to the following conditions: 1. I am using the new version of Watir (1.6.2) 2. This version of Watir uses the "user-choices" gem (from Marick) 3. This gem does not load Test::Unit, but does define a Test constant (not sure why, but Marick likes testing) 4. Rspec thinks that Test::Unit has been loaded (even though it hasn't) because the Test constant is defined. As a result, my rspec script gives me this error. Any suggestions? Increase the guard on the failing method call? Bret ..C:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec.rb:25:in `exit?' Finished in 18.625 seconds 2 examples, 0 failures : undefined method `run?' for Test::Unit:Module (NoMethodError) from C:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner.rb:192:in `register_at_exit_hook' from samples/lab6-refactored.rb:4 -- Bret Pettichord GTalk: bpettichord at gmail.com CTO, WatirCraft LLC, http://www.watircraft.com Lead Developer, Watir, http://wtr.rubyforge.org Blog (Essays), http://www.io.com/~wazmo/blog MiniBlog (Links), http://feeds.feedburner.com/bretshotlist -------------- next part -------------- An HTML attachment was scrubbed... URL: From apremdas at gmail.com Fri Nov 14 20:33:38 2008 From: apremdas at gmail.com (Andrew Premdas) Date: Sat, 15 Nov 2008 01:33:38 +0000 Subject: [rspec-users] Learning Cucumber In-Reply-To: <6cd3ec3dce0463bd0a7e9731d7c3e752@ruby-forum.com> References: <58350.216.185.71.22.1226595087.squirrel@webmail.harte-lyne.ca> <33030.216.185.71.22.1226595847.squirrel@webmail.harte-lyne.ca> <88fd8ddc0811132253w146dfc37s594e1b1cd91b8ea3@mail.gmail.com> <6cd3ec3dce0463bd0a7e9731d7c3e752@ruby-forum.com> Message-ID: <88fd8ddc0811141733x3fe11ab2k225f00e3525760da@mail.gmail.com> Generally you can do whatever you want in step as its a ruby file. The thing to do is use a debugger statement to stop in the step (make sure there is a line after debugger) and then explore. In your step the Entity you are referring to is probably a class not a variable HTH Andrew 2008/11/14 James Byrne : > Andrew Premdas wrote: >> What you're doing here is writing imperative features. Writing >> declarative features might be a better alternative. Instead of > ... >> >> Given I am on the new entity page >> When I correctly fill in the new entity form >> Then I should see a confirmation >> >> Then the feature has much less technical stuff in it that >> >> 1) Hide the intent >> 2) Make the story brittle to cosmetic changes, in particular to small >> rewordings of error messages and confirmations >> >> A side effect of this is you need much less regex magic to match your >> expressions. >> > > This advice does help. Thank you. > > Is there a way to mix webrat and hard coded steps? In other words, if I > have this in my steps file. > > Given /I am on the new entity page/ do > visits "/entities/new" > end > > When /I fill out the form correctly/ do > fills_in("Common Name", :with => "My Common Name") > fills_in("Legal Name", :with => "My Legal Name") > Entity.entity_legal_name = "CORP" # does not work > end > > Is this possible? > > How do I set the attribute "entity_legal_form" to "CORP" for that > entity? I cannot figure out how to reference that entity instance. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Sat Nov 15 05:51:11 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 15 Nov 2008 10:51:11 +0000 Subject: [rspec-users] =?windows-1252?q?How_to_spec_a_=28Trollop-based=29_?= =?windows-1252?q?binary=92s_internal_state=3F?= In-Reply-To: <20081114205648.GC3069@durance.shot.pl> References: <20081107130551.GC22622@durance.shot.pl> <20081107172421.GI22622@durance.shot.pl> <1FE91266-D2EB-436E-B814-4FBF53B18740@patchspace.co.uk> <20081114205648.GC3069@durance.shot.pl> Message-ID: <6BFF5E7F-E26E-4524-AD6B-E05C2868F159@patchspace.co.uk> On Nov 14, 2008, at 8:56 pm, Shot (Piotr Szotkowski) wrote: > Heh ? I brought exactly this talk up twice when talking about specing > binaries here (it was what pointed me in the direction that it would > be actually good to spec/test them, actually). :) Ha, so you did :) There was a delay after I read your email to when I finally replied, in that time it clearly left my head... > In my case, asfter some specing and some coding, it turns out I can?t > really do this the way I wanted; most of the cases I need to test for > are triggered with input that makes the binary run a long time (it?s > the code behind my PhD thesis, so tons of computations). As I?m > testing > a black box with Kernel#`, I can?t mock/stub anything out. Well, like Matt says, all the binary needs to do is get your code up and running. For that, I imagine you can use selectively-chosen inputs that don't produce long run times. The cucumber files just need to prove that all the command line options work, and that the app is directing IO to and from the right places. The details of the algorithms can be dealt with in your spec suite. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From brian.takita at gmail.com Sat Nov 15 17:44:14 2008 From: brian.takita at gmail.com (Brian Takita) Date: Sat, 15 Nov 2008 17:44:14 -0500 Subject: [rspec-users] undefined method `run?' for Test::Unit:Module In-Reply-To: References: Message-ID: <1d7ddd110811151444k61895d6g5886a68d32c69074@mail.gmail.com> On Fri, Nov 14, 2008 at 7:13 PM, Bret Pettichord wrote: > Hello. I just ran into an error I wanted to share. > > The error message is below. I tracked down the error to the following > conditions: > 1. I am using the new version of Watir (1.6.2) > 2. This version of Watir uses the "user-choices" gem (from Marick) > 3. This gem does not load Test::Unit, but does define a Test constant (not > sure why, but Marick likes testing) > 4. Rspec thinks that Test::Unit has been loaded (even though it hasn't) > because the Test constant is defined. > > As a result, my rspec script gives me this error. Any suggestions? Increase > the guard on the failing method call? Bret, try requiring test/unit before requiring rspec. I think this has to do with Rails trying to reopen a test/unit module that doesn't exists (since test/unit was not required), so it defines the Test module instead. > > Bret > > ..C:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec.rb:25:in > `exit?' > > Finished in 18.625 seconds > > 2 examples, 0 failures > : undefined method `run?' for Test::Unit:Module (NoMethodError) > from > C:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner.rb:192:in > `register_at_exit_hook' > from samples/lab6-refactored.rb:4 > > -- > Bret Pettichord > GTalk: bpettichord at gmail.com > CTO, WatirCraft LLC, http://www.watircraft.com > Lead Developer, Watir, http://wtr.rubyforge.org > Blog (Essays), http://www.io.com/~wazmo/blog > MiniBlog (Links), http://feeds.feedburner.com/bretshotlist > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sat Nov 15 23:54:15 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 15 Nov 2008 23:54:15 -0500 Subject: [rspec-users] undefined method `run?' for Test::Unit:Module In-Reply-To: References: Message-ID: On Nov 14, 2008, at 7:13 PM, Bret Pettichord wrote: > Hello. I just ran into an error I wanted to share. > > The error message is below. I tracked down the error to the > following conditions: > 1. I am using the new version of Watir (1.6.2) > 2. This version of Watir uses the "user-choices" gem (from Marick) > 3. This gem does not load Test::Unit, but does define a Test > constant (not sure why, but Marick likes testing) > 4. Rspec thinks that Test::Unit has been loaded (even though it > hasn't) because the Test constant is defined. > > As a result, my rspec script gives me this error. Any suggestions? > Increase the guard on the failing method call? > > Bret > > ..C:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec.rb: > 25:in `exit?' > > Finished in 18.625 seconds > > 2 examples, 0 failures > : undefined method `run?' for Test::Unit:Module (NoMethodError) > from C:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ > runner.rb:192:in `register_at_exit_hook' > from samples/lab6-refactored.rb:4 File it on lighthouse. I cued David into this bug @ rubyconf, and he seemed somewhat surprised by it. No doubt, it has something to do with active_record/active_support requiring test/unit. Scott From nick at deadorange.com Sun Nov 16 14:40:40 2008 From: nick at deadorange.com (Nick Hoffman) Date: Sun, 16 Nov 2008 14:40:40 -0500 Subject: [rspec-users] How to kill a running spec Message-ID: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> Hi guys. Occasionally, I'll want to kill a long spec process that's running. Usually I hit CTRL+c to kill a running process, but doing that for a running spec just causes "^C" to be printed to the terminal, and whichever spec example was running to fail. I've also tried using /bin/kill to kill the spec process, but that just causes whichever spec example was running to catch a SignalException, and fail. Any suggestions for how to do this? Thanks, Nick From pergesu at gmail.com Sun Nov 16 15:21:00 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 16 Nov 2008 12:21:00 -0800 Subject: [rspec-users] How to kill a running spec In-Reply-To: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> References: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> Message-ID: <810a540e0811161221g30fe5ac8y47aa8e6126f0362c@mail.gmail.com> I just hold ctl+c until it quits out. Pat On 11/16/08, Nick Hoffman wrote: > Hi guys. Occasionally, I'll want to kill a long spec process that's > running. Usually I hit CTRL+c to kill a running process, but doing > that for a running spec just causes "^C" to be printed to the > terminal, and whichever spec example was running to fail. > > I've also tried using /bin/kill to kill the spec process, but that > just causes whichever spec example was running to catch a > SignalException, and fail. > > Any suggestions for how to do this? Thanks, > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nick at deadorange.com Sun Nov 16 16:18:19 2008 From: nick at deadorange.com (Nick Hoffman) Date: Sun, 16 Nov 2008 16:18:19 -0500 Subject: [rspec-users] How to kill a running spec In-Reply-To: <810a540e0811161221g30fe5ac8y47aa8e6126f0362c@mail.gmail.com> References: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> <810a540e0811161221g30fe5ac8y47aa8e6126f0362c@mail.gmail.com> Message-ID: On 2008-11-16, at 15:21, Pat Maddox wrote: > I just hold ctl+c until it quits out. > > Pat Hahha, brute force it, eh? From mailing_lists at railsnewbie.com Sun Nov 16 17:46:25 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 16 Nov 2008 17:46:25 -0500 Subject: [rspec-users] How to kill a running spec In-Reply-To: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> References: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> Message-ID: <2BB21086-638D-404C-8A57-8E1EE81CCF9E@railsnewbie.com> On Nov 16, 2008, at 2:40 PM, Nick Hoffman wrote: > Hi guys. Occasionally, I'll want to kill a long spec process that's > running. Usually I hit CTRL+c to kill a running process, but doing > that for a running spec just causes "^C" to be printed to the > terminal, and whichever spec example was running to fail. > > I've also tried using /bin/kill to kill the spec process, but that > just causes whichever spec example was running to catch a > SignalException, and fail. What signal are you sending? Is it a kill -9 (a KILL, a TERM, ...?)? Scott From osahyoun at gmail.com Sun Nov 16 17:53:09 2008 From: osahyoun at gmail.com (Sahyoun) Date: Sun, 16 Nov 2008 23:53:09 +0100 Subject: [rspec-users] mocking and stub comprehension In-Reply-To: References: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> <810a540e0811161221g30fe5ac8y47aa8e6126f0362c@mail.gmail.com> Message-ID: <229FE750-66BD-47DB-B315-CDD37F925227@gmail.com> Hello, I'm specing a controller, but having trouble getting my head around what I've created. I'm specing a products controller for an admin user. Two before filters check the user is logged in and authorized. A logged-in user only has admin privileges within her own subdomain. So, sarah, when logged in can only administer products at sarah.mysite.com/admin/products. Since there are two account types that require authentication (supplier and customer), the user model is polymorphic: class User belongs_to :allowable, :polymorphic => true ... end class Supplier has_many :users, :as => :allowable end class Customer has_one :user, :as => :allowable end A supplier has their own subdmain (sarah.mysite.com) and a customer has a profile page at mysite.com/people/joe. When sarah is logged-in, I check she has permission to edit content at sarah.mysite.com with: def authorized_resource?(resource) current_user.allowable == resource end 'resource' being a supplier or customer object. My mind is failing me trying to describe Admin::ProductsController: http://pastie.org/316414 Both examples pass, but I'm not sure I understand exactly what I'm doing. In particular, can I make: it "should send unauthorized user to home page" do controller.should_receive(:authorized_resource?).and_return false do_get response.should redirect_to(home_path) end pass without stubbing the false return. How can I set up the mock instances, so that the controller method 'authorized_resource?' actually returns a false method. Any guidance would be much appreciated. many thanks Omar From zach.dennis at gmail.com Sun Nov 16 18:13:55 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 16 Nov 2008 18:13:55 -0500 Subject: [rspec-users] mocking and stub comprehension In-Reply-To: <229FE750-66BD-47DB-B315-CDD37F925227@gmail.com> References: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> <810a540e0811161221g30fe5ac8y47aa8e6126f0362c@mail.gmail.com> <229FE750-66BD-47DB-B315-CDD37F925227@gmail.com> Message-ID: <85d99afe0811161513x7d2fa7c5wb3cc4b33ae6b9cea@mail.gmail.com> On Sun, Nov 16, 2008 at 5:53 PM, Sahyoun wrote: > Hello, > > I'm specing a controller, but having trouble getting my head around what > I've created. > > I'm specing a products controller for an admin user. Two before filters > check the user is logged in and authorized. > A logged-in user only has admin privileges within her own subdomain. So, > sarah, when logged in > can only administer products at sarah.mysite.com/admin/products. > > Since there are two account types that require authentication (supplier and > customer), > the user model is polymorphic: > > class User > belongs_to :allowable, :polymorphic => true > ... > end > > class Supplier > has_many :users, :as => :allowable > end > > > class Customer > has_one :user, :as => :allowable > end > > A supplier has their own subdmain (sarah.mysite.com) and a customer has a > profile page at mysite.com/people/joe. > > When sarah is logged-in, I check she has permission to edit content at > sarah.mysite.com with: > > def authorized_resource?(resource) > current_user.allowable == resource > end I would probably change this method so you are pushing the responsibility onto your user. For example, I might change the authorized_resourced method to look like: def authorized_resource?(resource) current_user.can_access?(resource) end Now in your example you can stub/expect the interaction with the user object. Pushing this decision for who can access what really should stay out of your controller. Even though the authorization check is quite simple right now (ie: user.allowable == resource) this puts more logic in your controller, makes it slightly harder to test and also re-use. Hope this helps, Zach > > 'resource' being a supplier or customer object. > > My mind is failing me trying to describe Admin::ProductsController: > > http://pastie.org/316414 > > Both examples pass, but I'm not sure I understand exactly what I'm doing. In > particular, can I make: > > it "should send unauthorized user to home page" do > controller.should_receive(:authorized_resource?).and_return false > do_get > response.should redirect_to(home_path) > end > > > pass without stubbing the false return. How can I set up the mock instances, > so that the controller method > 'authorized_resource?' actually returns a false method. Any guidance would > be much appreciated. > > many thanks > > Omar > > > _______________________________________________ > 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 Sun Nov 16 19:15:19 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Nov 2008 18:15:19 -0600 Subject: [rspec-users] undefined method `run?' for Test::Unit:Module In-Reply-To: References: Message-ID: <57c63afe0811161615x68c410efid0f300fe05464a7a@mail.gmail.com> On Sat, Nov 15, 2008 at 10:54 PM, Scott Taylor wrote: > > On Nov 14, 2008, at 7:13 PM, Bret Pettichord wrote: > >> Hello. I just ran into an error I wanted to share. >> >> The error message is below. I tracked down the error to the following >> conditions: >> 1. I am using the new version of Watir (1.6.2) >> 2. This version of Watir uses the "user-choices" gem (from Marick) >> 3. This gem does not load Test::Unit, but does define a Test constant (not >> sure why, but Marick likes testing) >> 4. Rspec thinks that Test::Unit has been loaded (even though it hasn't) >> because the Test constant is defined. >> >> As a result, my rspec script gives me this error. Any suggestions? >> Increase the guard on the failing method call? >> >> Bret >> >> ..C:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec.rb:25:in >> `exit?' >> >> Finished in 18.625 seconds >> >> 2 examples, 0 failures >> : undefined method `run?' for Test::Unit:Module (NoMethodError) >> from >> C:/ruby-186-26/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner.rb:192:in >> `register_at_exit_hook' >> from samples/lab6-refactored.rb:4 > > > File it on lighthouse. I cued David into this bug @ rubyconf, and he seemed > somewhat surprised by it. No doubt, it has something to do with > active_record/active_support requiring test/unit. Fixed: http://github.com/dchelimsky/rspec/commit/5b163e285d2e774ac474d3ffad5676bf273820f9 Cheers, David > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Nov 16 19:19:27 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Nov 2008 18:19:27 -0600 Subject: [rspec-users] Autotest style autotest/rails_rspec doesn't seem to exist. Aborting. In-Reply-To: References: <57c63afe0811130544mc8693d8t2e4fe5ccb76e818c@mail.gmail.com> Message-ID: <57c63afe0811161619k11d206e5n3bdb456234885c54@mail.gmail.com> On Thu, Nov 13, 2008 at 9:18 AM, Ramon Tayag wrote: > Yup, I submoduled them :) I suppose that's just like an external svn > repo. I'll try reinstalling them... but in the mean time, got any > ideas? Is this only happening in one rails app? or all of them? > > Ramon Tayag > > On Thu, Nov 13, 2008 at 9:44 PM, David Chelimsky wrote: >> You need rspec-rails as well (plugin or gem, same version as rspec). >> Do you have that already? >> >> Cheers, >> David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From alvin.schur at gmail.com Sun Nov 16 20:00:02 2008 From: alvin.schur at gmail.com (Alvin Schur) Date: Sun, 16 Nov 2008 18:00:02 -0700 Subject: [rspec-users] Examples using cucumber, celerity, rspec Message-ID: <429cba880811161700m1590d919n919fdc45be0559e8@mail.gmail.com> I created some simple examples using cucumber, celerity, and rspec to verify the behaviour of a web application. The examples include: * verifying javascript ran on page load * verifying results of AJAX calls * responding to alerts and confirm dialog boxes * accessing iframes The examples are located at: http://github.com/alvinschur/celerity-examples/tree/master Many thanks to core team for the great tools. Thanks to Ashley Moran for the slides and code using celerity, rspec, and cucumber. http://aviewfromafar.net/2008/10/2/geekup-sheffield-vi-from-specification-to-success Feedback and improvements are welcome. Alvin. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Mon Nov 17 11:52:56 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 17 Nov 2008 11:52:56 -0500 Subject: [rspec-users] How to kill a running spec In-Reply-To: <2BB21086-638D-404C-8A57-8E1EE81CCF9E@railsnewbie.com> References: <81878EE2-F7AE-4213-B16B-217F898AC031@deadorange.com> <2BB21086-638D-404C-8A57-8E1EE81CCF9E@railsnewbie.com> Message-ID: <7C4F1443-8F01-428E-B6F5-9EE59A06E374@deadorange.com> On 2008-11-16, at 17:46, Scott Taylor wrote: > On Nov 16, 2008, at 2:40 PM, Nick Hoffman wrote: >> Hi guys. Occasionally, I'll want to kill a long spec process that's >> running. Usually I hit CTRL+c to kill a running process, but doing >> that for a running spec just causes "^C" to be printed to the >> terminal, and whichever spec example was running to fail. >> >> I've also tried using /bin/kill to kill the spec process, but that >> just causes whichever spec example was running to catch a >> SignalException, and fail. > > What signal are you sending? Is it a kill -9 (a KILL, a TERM, ...?)? > > Scott I've just been running it as ``kill 12345''. I stay away from -9, as it's a pretty harsh thing to do. I haven't tried other signals though, so I should give them a whirl and report back if any of them succeed in killing the entire spec process. -Nick From byrnejb at harte-lyne.ca Mon Nov 17 15:33:21 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Mon, 17 Nov 2008 15:33:21 -0500 (EST) Subject: [rspec-users] More Examples Message-ID: <53292.216.185.71.22.1226954001.squirrel@webmail.harte-lyne.ca> I have a feature spec that looks like this: Scenario: The entity common name should be normalized Given 1 valid entity And I am on the edit entity page When I fill in "Common Name" with " ANYThing WronG wITh tHiS? " And I press "Update" Then I should see an update success confirmation And I should see "Anything Wrong With This?" More Examples: | initial | after | | "ALL CAPS" | "All Caps" | | " Squeeze leading space" | "Squeeze Leading Space" | | " Compact Internal space" | "Compact Internal Space" | The first bit passes but for the life of me I cannot figure out what I am supposed to do to get the More Examples to work. I will grant from the outset that testing a string normalization feature might be done somewhere/someway else but I am learning RSpec/Cucumber and for now am taking that single minded approach to testing. On the other hand, I am not adverse to suggestions on how this might be best handled. Guidance Please? -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From matt at mattwynne.net Mon Nov 17 15:49:26 2008 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 17 Nov 2008 20:49:26 +0000 Subject: [rspec-users] More Examples In-Reply-To: <53292.216.185.71.22.1226954001.squirrel@webmail.harte-lyne.ca> References: <53292.216.185.71.22.1226954001.squirrel@webmail.harte-lyne.ca> Message-ID: <2F025861-BC5F-4D17-BA30-55D1032A5832@mattwynne.net> On 17 Nov 2008, at 20:33, James B. Byrne wrote: > I have a feature spec that looks like this: > > > Scenario: The entity common name should be normalized > Given 1 valid entity > And I am on the edit entity page > When I fill in "Common Name" with " ANYThing WronG wITh tHiS? " > And I press "Update" > Then I should see an update success confirmation > And I should see "Anything Wrong With This?" > > More Examples: > | initial | after | > | "ALL CAPS" | "All Caps" | > | " Squeeze leading space" | "Squeeze Leading Space" | > | " Compact Internal space" | "Compact Internal Space" | > > The first bit passes but for the life of me I cannot figure out what > I am > supposed to do to get the More Examples to work. You're probably not specifying all the variables you need to. Until we get the Scenario Outlines feature[1], you have to put a column in your More Examples table for every capture group in the regular expressions in your matchers. The way I usually do this is look at the output in the console from Cucumber and see where the bits are underlined, and make a column for each of them. That can feel a bit silly when most of them don't vary during your extra examples, but that's why we need the Scenario Outline feature. For the time being it's still great that we can do this at all. cheers, Matt [1]http://rspec.lighthouseapp.com/projects/16211/tickets/57-scenario-templates-to-allow-for-terse-scenario-tables From lists at ruby-forum.com Mon Nov 17 16:22:28 2008 From: lists at ruby-forum.com (James Byrne) Date: Mon, 17 Nov 2008 22:22:28 +0100 Subject: [rspec-users] More Examples In-Reply-To: <2F025861-BC5F-4D17-BA30-55D1032A5832@mattwynne.net> References: <53292.216.185.71.22.1226954001.squirrel@webmail.harte-lyne.ca> <2F025861-BC5F-4D17-BA30-55D1032A5832@mattwynne.net> Message-ID: <5a9a947aae8ff71abf48dae24c4b4712@ruby-forum.com> Matt Wynne wrote: > On 17 Nov 2008, at 20:33, James B. Byrne wrote: >> >> More Examples: >> | initial | after | >> | "ALL CAPS" | "All Caps" | >> | " Squeeze leading space" | "Squeeze Leading Space" | >> | " Compact Internal space" | "Compact Internal Space" | >> >> The first bit passes but for the life of me I cannot figure out what >> I am >> supposed to do to get the More Examples to work. > > You're probably not specifying all the variables you need to. > > Until we get the Scenario Outlines feature[1], you have to put a > column in your More Examples table for every capture group in the > regular expressions in your matchers. > I took out the check for the success confirmation to simplify things. I added columns for the field and the action. The remaining matcher is in webrat_steps: Then /^I should see "(.*)"$/ do |text| response.body.should =~ /#{text}/m end This is what I see in the console: Scenario: The entity common name should be normalized # features/manage_entities.feature:41 Given 1 valid entity # features/step_definitions/entity_steps.rb:25 And I am on the edit entity page # features/step_definitions/entity_steps.rb:54 When I fill in "Common Name" with " ANYThing WronG wITh tHiS? " # features/step_definitions/webrat_steps.rb:12 And I press "Update" # features/step_definitions/webrat_steps.rb:4 Then I should see "Anything Wrong With This?" # features/step_definitions/webrat_steps.rb:36 |field |input |action |display | |"Common Name"|"ALL CAPS" |"Update"|"All Caps" |/usr/lib/ruby/gems/1.8/gems/cucumber-0.1.9/bin/../lib/cucumber/formatters/pretty_formatter.rb:212:in `print_row': You have a nil object when you didn't expect it! (NoMethodError) do I misunderstand what you tried to tell me? -- Posted via http://www.ruby-forum.com/. From tastapod at gmail.com Mon Nov 17 17:02:40 2008 From: tastapod at gmail.com (Dan North) Date: Mon, 17 Nov 2008 14:02:40 -0800 Subject: [rspec-users] features and form filling - going declarative? In-Reply-To: <4914602B.2040102@joesniff.co.uk> References: <88fd8ddc0811062209l45f75364t82a7078750e75c63@mail.gmail.com> <06B7D58C-2426-4434-8443-149F82EDD625@mattwynne.net> <57c63afe0811070658j773ca7a7t447d34d0ee13ad8d@mail.gmail.com> <57c63afe0811070702h6b08cc0dy52c6db7de718fd2e@mail.gmail.com> <4914602B.2040102@joesniff.co.uk> Message-ID: Bit of a ramble, but see inline comments. Cheers, Dan 2008/11/7 Joseph Wilk > David Chelimsky wrote: > >> On Fri, Nov 7, 2008 at 9:58 AM, David Chelimsky >> wrote: >> >> >>> On Fri, Nov 7, 2008 at 9:54 AM, Matt Wynne wrote: >>> >>> >>>> One technique is to have a single noisy 'declarative' scenario that >>>> explicitly walks around filling things in, then all the rest use more >>>> 'imperative' style steps where most of the detail is buried away. >>>> >>>> >>> You've got those backwards :) >>> >>> declarative: when I fill in the form correctly >>> imperative: when I enter "David" in the "Name" field .... >>> >>> >> >> Although - maybe we need to reconsider this naming, because you could >> argue that either are declarative, whereas imperative, meaning >> important/urgent, doesn't really convey the explicit nature. I think >> abstract/concrete could work. Maybe general/specific. > > I agree with abstract and concrete, and in fact this is where scenarios first came from. A business analyst thinks in abstract terms ("we're going to have to be able to withdraw cash"), and the tester's job is then to map that to concrete examples ("start with $100, request $80, make sure we get $80 and have $20 left in the account"). The tester's description will necessarily be finer grained. The scenario title should be at the analyst (more abstract) level of granularity: "withdraw funds from an account with sufficient balance" The imperative/declarative terminology is a bogus one. Imperative means "how", and declarative means "what". Any level of abstraction is both a how and a what depending on your perspective. There's an exercise you can do with any statement to demonstrate this. Simply ask "how?" to move down the stack of abstraction or "what for?" to move up. It's turtles in both directions. Here's an example: SQL is the canonical example of declarative, so: select count(*) from accounts where balance < 0 But if I ask "what for?" I get: find out how many accounts are overdrawn ("more" declarative) What for? calculate our exposure to dollar fluctuations What for? what is our operating risk in the current financial climate What for? ... etc Now going the other way: select count(*) from accounts where balance < 0 How? set up a counter variable, then scan the accounts table and increment whenever you see a negative balance How? cue up a number of subtasks that will scan segments of the accounts table, then aggregate the results How? ... etc. Having said all that, it's important to be able to define your own abstractions over the operations you carry out in your application. "Login as Dan" is a sensible chunk to have a conversation about. At that point I would probably use ruby methods to aggregate multiple steps into coarser-grained abstractions. Of course each of these abstractions tells you something new about your domain, and in that regard it has value to someone coming along later and reading your examples. ("These three steps always seem to occur together - perhaps we should have a name for that".) Cheers, Dan ps. David is right - the list-of-instructions is imperative, the what-I-want is declarative. >> >> Other ideas? >> >> >> >>> Cheers, >>> David >>> >>> >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> > I like abstract/concrete > My other suggestions: > > * Explicit / Implicit > * High level / Low level > * Coarse / fine > > -- > Joseph Wilk > http://www.joesniff.co.uk > > _______________________________________________ > 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 tastapod at gmail.com Mon Nov 17 17:33:15 2008 From: tastapod at gmail.com (Dan North) Date: Mon, 17 Nov 2008 14:33:15 -0800 Subject: [rspec-users] cucumber feature description In-Reply-To: <8d961d900810260852u1cc4f3edle1d61bc39f3d84ed@mail.gmail.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> <8d961d900810260852u1cc4f3edle1d61bc39f3d84ed@mail.gmail.com> Message-ID: 2008/10/26 aslak hellesoy > 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. > This is an evolution of the Connextra story format (as a.. I want.. so that..) to put the emphasis on the value. Liz Keogh blogged about ita while ago and it's starting to catch on with the teams I work with. It has a really nice secondary effect which is that often the active participant in a story isn't the person who benefits, and the Connextra format struggles with this. Liz's favourite example is the capcha. No-one *wants* to type in some wobbly letters! Using the value-first format, you get something like this: In order to minimise spam on the blog site The *site administrator* Wants *a commentator* to answer a capcha when they submit a comment So now we have identified two stakeholders - the one who benefits and the one who does the work. This can be useful in understanding someone's motivation in a scenario. Cheers, Dan > > > > > 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 agree. But Yoda language it is not. Oh crap. I do agree that the concrete template we're currently using is a > little awkward though. How can we improve it? > In order to [goal] [stakeholder] Wants [behaviour] (The Yoda variant would be [behaviour] wants :) Aslak Cheers, Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From hayafirst at gmail.com Mon Nov 17 18:25:54 2008 From: hayafirst at gmail.com (Yi Wen) Date: Mon, 17 Nov 2008 17:25:54 -0600 Subject: [rspec-users] How to use config.gem for rspec and rspec-rails Message-ID: Hi, Is there anyway I can specify config.gem rspec :lib => "spec" config.gem rspec-rails :lib => "spec/rails" in my test.rb? Basically I got this after I specify rspec rake gems:unpack RAILS_ENV=test (in /home/ywen/projects/kod) rake aborted! uninitialized constant Spec::Rake /home/ywen/projects/kod/Rakefile:10 (See full trace by running task with --trace) Thanks yi -------------- next part -------------- An HTML attachment was scrubbed... URL: From harry at harrylove.org Mon Nov 17 22:19:42 2008 From: harry at harrylove.org (Harry Love) Date: Mon, 17 Nov 2008 20:19:42 -0700 Subject: [rspec-users] Cucumber autotest load error between 0.1.8 and 0.1.9 Message-ID: <978195830811171919of32a1bboc47caa31d7377254@mail.gmail.com> Hi, I'm new to the list and to Cucumber (and RSpec and testing in general) so I apologize if this has already come up. I searched the archive and didn't see anything. Last week I installed Cucumber 0.1.8 for my Rails app and both 'cucumber features' and 'rake features' worked fine. Features and steps were evaluated. Today I upgraded Cucumber to 0.1.9 and tried to set up autotest. It didn't work. Long story short, I installed the gems but didn't put them in my vendor/plugins directory (by choice). In 0.1.8, script/cucumber was only looking in vendor/plugins. In 0.1.9, there's a LoadError exception rescue that defaults to the local gem if it can't be found in vendor/plugins. 0.1.8 #!/usr/bin/env ruby load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber") 0.1.9 #!/usr/bin/env ruby begin load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber") rescue LoadError require "rubygems" load File.join(Gem.bindir, "cucumber") I hope that helps somebody else. Cheers, Harry From nick at deadorange.com Tue Nov 18 00:41:36 2008 From: nick at deadorange.com (Nick Hoffman) Date: Tue, 18 Nov 2008 00:41:36 -0500 Subject: [rspec-users] Mocking and stubbing model relationships Message-ID: Before writing specs for a one-to-many relationship between two models, I did some research and found that some people were creating proxy mocks, and others were using Matthew Heidemann's #stub_association! (which essentially does that for, but in a nice, DRY way): http://www.ruby-forum.com/topic/126993 Are those two methods currently the accepted "best practice" for mocking and stubbing calls such like these?: @properties = @user.properties @property = @user.properties.new @property = @user.properties.find_by_id params[:id] Thanks, Nick From lists at ruby-forum.com Tue Nov 18 01:25:47 2008 From: lists at ruby-forum.com (Pau Cor) Date: Tue, 18 Nov 2008 07:25:47 +0100 Subject: [rspec-users] More Examples In-Reply-To: <5a9a947aae8ff71abf48dae24c4b4712@ruby-forum.com> References: <53292.216.185.71.22.1226954001.squirrel@webmail.harte-lyne.ca> <2F025861-BC5F-4D17-BA30-55D1032A5832@mattwynne.net> <5a9a947aae8ff71abf48dae24c4b4712@ruby-forum.com> Message-ID: James Byrne wrote: > This is what I see in the console: The underlining didn't come through in you post, so that doesn't help us. If you post your step matchers, then we can tell you what your columns need to be. Essentially, for every (.*) in your step matchers, you need a column. And they have to be in the order they are in the story. Here is an example: Scenario: The entity common name should be normalized Given I am on the edit entity page When I fill in "Common Name" with " ANYThing WronG wITh tHiS? " And I press "Update" Then I should see "Anything Wrong With This?" More Examples: | page | field | initial | Button | after | | the edit entity page | Common Name | "ALL CAPS" | Update | "All Caps" | | the edit entity page | Common Name | " Squeeze leading space" | Update | "Squeeze Leading Space" | | the edit entity page | Common Name | " Compact Internal space" | Update | "Compact Internal Space" | Given /^I am on the "(.*)"$/ do |page| When /^I fill in "(.*)" with "(.*)"$/ do |field, value| When /^I press "(.*)"$/ do |button| Then /^I should see "(.*)"$/ do |text| You also need to be careful about ". I'm not sure if the way you are using those will include " in the string. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 18 01:53:26 2008 From: lists at ruby-forum.com (Mano ah) Date: Tue, 18 Nov 2008 07:53:26 +0100 Subject: [rspec-users] testing an action which requires picture In-Reply-To: References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> <3ed504aea01d24117705eaecb53cb437@ruby-forum.com> Message-ID: Nick Hoffman wrote: > On 2008-11-14, at 06:29, Mano ah wrote: >> image = Image.new >> >> image.blob= params[:image][:blob] >> >> image.save_picture >> >> end >> -- > > Hi Mano. It doesn't really matter whether or not your "picture" model > interacts with a database. Simply use mocks and stubs when speccing > #scan , and you'll be good. For example: > > describe '#scan' do > describe 'receives a POST request' do > before :each do > # mock an Image instance > # stub Image#new > end > > it 'should create a new Image' > it "should set the new image's 'blob' attribute" > it 'should save the new image' > end > > describe 'receives a non-POST request' do > # stuff here > end > end > > Obviously you have to fill in the contents of those #it blocks, but > that's really all you need. > -Nick Thank you All the above specification passed. Now I want to test the return value. I mean def scan #------- if request.post? image = Image.new image.blob= params[:image][:blob] if image.save_picture @code = returns a blog image value end end What is the rspec code to test the return value and make it pass -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 18 01:55:26 2008 From: lists at ruby-forum.com (Mano ah) Date: Tue, 18 Nov 2008 07:55:26 +0100 Subject: [rspec-users] testing an action which requires picture In-Reply-To: References: <987d9f55b86ac6fed449f87deecf0836@ruby-forum.com> <57c63afe0811120540o5acbff4fwe3a032e24b7d64bf@mail.gmail.com> <09ace9134cc31876a42ebceb0ab7c890@ruby-forum.com> <3ed504aea01d24117705eaecb53cb437@ruby-forum.com> Message-ID: <0408992c1b5cb78b75f200e17b3c213a@ruby-forum.com> Thank you All the above specification passed. Now I want to test the return value. I mean def scan #------- if request.post? image = Image.new image.blob= params[:image][:blob] if image.save_picture @code = returns a barcode image value end end What is the rspec code to test the return value and make it pass -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Tue Nov 18 03:43:20 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 18 Nov 2008 08:43:20 +0000 Subject: [rspec-users] Mocking and stubbing model relationships In-Reply-To: References: Message-ID: <39C3C1E9-FEA4-49CC-82E9-862B29664471@mattwynne.net> On 18 Nov 2008, at 05:41, Nick Hoffman wrote: > Before writing specs for a one-to-many relationship between two > models, I did some research and found that some people were creating > proxy mocks, and others were using Matthew Heidemann's > #stub_association! (which essentially does that for, but in a nice, > DRY way): > http://www.ruby-forum.com/topic/126993 > > Are those two methods currently the accepted "best practice" for > mocking and stubbing calls such like these?: I don't know about any "best practice". In the realm of TDD vs ActiveRecord Associations, you're looking at something more like "least-worst" practice, IMO. The way the AssociationCollections behave is pretty complex and difficult to simulate with a simple mock or two. I started out trying to stay 'pure' and not touch the database, but TBH, these days I've given up the fight and mostly just throw a few records in a database table - that way you can actually specify the behaviour you want rather than the gory implementation details. As you can probably tell by my grumbling, this is one of my least favourite bits of working on rails. > @properties = @user.properties > @property = @user.properties.new > @property = @user.properties.find_by_id params[:id] Saying that, it is often still reasonable, I think, to fake an association proxy collection using an array that's patched with a few extra methods. We have a helper method in the Songkick spec code that's called something like FakeCollection, which subclasses array and has a few helpful methods to make it look enough like an association collection to make the specs run OK. HTH, Matt From smingins at elctech.com Tue Nov 18 03:44:04 2008 From: smingins at elctech.com (Shane Mingins) Date: Tue, 18 Nov 2008 21:44:04 +1300 Subject: [rspec-users] Spec'ing specific before_filters in controllers Message-ID: <230478B4-F9D7-440A-9DA2-02FE69A797BB@elctech.com> Hi I like using before_filter in controllers to dry up code. From what I have read I understand that this is not something everyone agrees upon. Never mind. I was looking for a way in my controller spec's to basically 1. assert that I have applied the before_filter on the actions I want and 2. execute the before_filter if it is defined in that controller and assert that it is doing as it should. To me that seems to be the specific behaviour I am after. I really only wanted to do this in one place ... and not have to "share" it anywhere. Also I wanted to do a little more than some of the solutions I found. Anyways ... I ended up with a spec description like this: http://pastie.org/317459 And then in the rest of the spec I can stub the before_filter methods like here http://www.caboo.se/articles/2007/8/24/skinny-controllers-skinnier-controller-specs So just wondered any thoughts ... have you seen anything else around? The code behind it at the moment is quite trivial and will probably grow if I have other filter types. I can post a better write up if this sounds like something useful for others. There is this matcher: http://github.com/ngty/have_filter/tree/ master .... but again, it wasn't quite what I felt I wanted. Cheers Shane -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2423 bytes Desc: not available URL: From ramon.tayag at gmail.com Tue Nov 18 04:42:00 2008 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Tue, 18 Nov 2008 17:42:00 +0800 Subject: [rspec-users] Autotest style autotest/rails_rspec doesn't seem to exist. Aborting. In-Reply-To: <57c63afe0811161619k11d206e5n3bdb456234885c54@mail.gmail.com> References: <57c63afe0811130544mc8693d8t2e4fe5ccb76e818c@mail.gmail.com> <57c63afe0811161619k11d206e5n3bdb456234885c54@mail.gmail.com> Message-ID: Thanks for you replies. I reinstalled it and it works fine. It seems that it didn't install properly before! :o thanks goodness that's it. hehe Ramon Tayag On Mon, Nov 17, 2008 at 8:19 AM, David Chelimsky wrote: > Is this only happening in one rails app? or all of them? From raasdnil at gmail.com Tue Nov 18 05:12:03 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Tue, 18 Nov 2008 21:12:03 +1100 Subject: [rspec-users] Cucumber - how to spec a quick search box Message-ID: <57a815bf0811180212kf2ae4bam645e735d89935024@mail.gmail.com> Hello all. Wondering if anyone else has solved this. Some websites (including the intranet app I am working on) have a form in the top corner of the site that is buttonless. If you focus on this form enter text and hit enter, it submits. usually used for quick search boxes. Question, has anyone managed to tie that into a cucumber feature? Scenario: Using the quick search box Given I am logged in And I visit the home page And there is someone called 'Bob Smith' to search for When I put 'Bob Smith' into the quick search box And I hit enter Then I should be shown the search results page And there should be 'Bob Smith' on the page it's the 'And I hit enter' that is bugging me :) Any ideas? Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: From josephwilk at joesniff.co.uk Tue Nov 18 05:44:39 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Tue, 18 Nov 2008 10:44:39 +0000 Subject: [rspec-users] Cucumber - how to spec a quick search box In-Reply-To: <57a815bf0811180212kf2ae4bam645e735d89935024@mail.gmail.com> References: <57a815bf0811180212kf2ae4bam645e735d89935024@mail.gmail.com> Message-ID: <49229C97.4000101@joesniff.co.uk> Mikel Lindsaar wrote: > Hello all. > > Wondering if anyone else has solved this. > > Some websites (including the intranet app I am working on) have a form > in the top corner of the site that is buttonless. If you focus on this > form enter text and hit enter, it submits. usually used for quick > search boxes. > > Question, has anyone managed to tie that into a cucumber feature? > > Scenario: Using the quick search box > Given I am logged in > And I visit the home page > And there is someone called 'Bob Smith' to search for > When I put 'Bob Smith' into the quick search box > And I hit enter > Then I should be shown the search results page > And there should be 'Bob Smith' on the page > > it's the 'And I hit enter' that is bugging me :) > > Any ideas? > I've encountered the same problem. I generally try and pull the abstraction up a bit a say something like: When I submit a quick search for 'Bob Smith' But here I'm assuming that its not really important to the customer how they submit the form just that they can. WDYT? -- Joseph Wilk http://blog.josephwilk.net From zach.dennis at gmail.com Tue Nov 18 07:58:37 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 18 Nov 2008 07:58:37 -0500 Subject: [rspec-users] Cucumber - how to spec a quick search box In-Reply-To: <49229C97.4000101@joesniff.co.uk> References: <57a815bf0811180212kf2ae4bam645e735d89935024@mail.gmail.com> <49229C97.4000101@joesniff.co.uk> Message-ID: <85d99afe0811180458o3422456cm2ffc6ceaeb695c44@mail.gmail.com> On Tue, Nov 18, 2008 at 5:44 AM, Joseph Wilk wrote: > Mikel Lindsaar wrote: >> >> Hello all. >> >> Wondering if anyone else has solved this. >> >> Some websites (including the intranet app I am working on) have a form in >> the top corner of the site that is buttonless. If you focus on this form >> enter text and hit enter, it submits. usually used for quick search boxes. >> >> Question, has anyone managed to tie that into a cucumber feature? >> >> Scenario: Using the quick search box >> Given I am logged in >> And I visit the home page >> And there is someone called 'Bob Smith' to search for >> When I put 'Bob Smith' into the quick search box >> And I hit enter >> Then I should be shown the search results page >> And there should be 'Bob Smith' on the page >> >> it's the 'And I hit enter' that is bugging me :) >> >> Any ideas? >> > I've encountered the same problem. I generally try and pull the abstraction > up a bit a say something like: > > When I submit a quick search for 'Bob Smith' > > But here I'm assuming that its not really important to the customer how they > submit the form just that they can. > > WDYT? I agree with Matt. Unless it was really really really important to the customer how the thing was submitted I wouldn't try to automate the pressing of the enter button in the browser. I would more or less just say what I was doing rather than how I was doing it. I might end up with: Given I'm a logged in user at the home page And there is someone called 'Bob Smith' to earch for When I do a quick search for 'Bob Smith' Then I should see that 'Bob Smith' is found in the search results If you're wondering how you submit the quick search (since it has no button) then here's a suggestion that Ben Mabey gave me back in September: use