From aselder at mac.com Sun Jun 1 00:20:09 2008 From: aselder at mac.com (Andrew Selder) Date: Sat, 31 May 2008 21:20:09 -0700 Subject: [rspec-users] Mixing mocking frameworks? Message-ID: First, it was great meeting a bunch of you at RailsConf. Recently I've run into a problem using RSpec, namely its support for multiple mocking frameworks. Wait you say, isn't that a good thing? Yes, it is until you end up mixing frameworks. I was writing my latest app, and I choose to get the app working and then add in the authentication system. So I went and wrote all my test using Mocha, and everything was all peachy. Then I went to github and got the latest version of restful_authentication. To the console, "script/generated authenticated user sessions --rspec", and run the test suite. BOOM!!!! It turns out that Rick Olson wrote all the specs for RESTful Authentication using RSpec's built-in mocking, and that didn't play nicely with Mocha being declared in the spec.opts file. I think it would be nice to be able to set a mock framework per example group or spec file. I'll grab a fork and start looking at it, but if you have any suggestions, they'd be greatly appreciated. Andrew -- Andrew Selder Lead Developer Boston Logic Technology Partners aselder at bostonlogic.com www.bostonlogic.com www.logicmaps.com www.logicrentals.com From ben at benmabey.com Sun Jun 1 06:19:36 2008 From: ben at benmabey.com (Ben Mabey) Date: Sun, 1 Jun 2008 04:19:36 -0600 (MDT) Subject: [rspec-users] Railsconf and textmate bundle for Story Runner Message-ID: <30482.12.157.240.2.1212315576.squirrel@mail.onticweb.com> Hey guys, A friend and I have been working on a textmate bundle for the story runner while up here at railsconf. It is still pretty new but we think it already has some very helpful features that removes some of the pain points while writing plain text stories. It is on my github account if you want to learn more and try it out: http://github.com/bmabey/rspec-story-tmbundle/tree/master We are hoping to show it off during the lighting talk session at 11:30am on Sunday if you want to see a quick demo. Also, great job David on your presentation. I think a lot of the audience who hadn't seen much of the story runner saw how useful it can be in the development process. Thanks, Ben From rspec-users at kero.tmfweb.nl Sun Jun 1 11:30:09 2008 From: rspec-users at kero.tmfweb.nl (Kero) Date: Sun, 1 Jun 2008 17:30:09 +0200 Subject: [rspec-users] how to write spec for infinite loop? In-Reply-To: <2977EE4D-2314-4ED2-BA4D-937FC90436B7@railsnewbie.com> References: <4ef750680805282325s1aa6e33du9ce80e003cc1b88f@mail.gmail.com> <2977EE4D-2314-4ED2-BA4D-937FC90436B7@railsnewbie.com> Message-ID: <20080601153009.GC26796@bumblebee.m38c.nl> >> I've got trouble when describe infinite loop. >> >> code snippet: >> >> def start_loop >> while true >> data = self.server.handle_client >> if data >> self.manager.dispatch(data) >> end >> end >> end >> >> without the loop, it is easy to test the logic. >> but how can I describe it to tell the developer ( me :-) ) that there >> should be an infinite loop inside. > > Here's a tip which Aslak gave me several months ago, and I find myself > repeating it in many different contexts on this mailing list: > > One way is with dependency injection: > > def start_loop(looping_infinitely = true) > while looping_infinitely > ... > end > end > > In your spec, you simply pass false (but production code can call the > method as if there is no option). "while true" is also known as "loop" in Ruby. Really, you do not want to test whether that ruby construct works, do you? (I can imagine it being in the test suite that is for RUby itself) What I think is interesting for you to test, is that your loop keeps running when the dispatcher dies, and possibly other bad-weather cases. I bet your loop is in another Thread, and checking whether a Thread still runs is easy enough (also interesting enough, since threads die by themselves in Ruby, by default, i.e. they do not raise exceptions in other threads unless you set Thread.abort_on_exception = true). From mhennemeyer at googlemail.com Sun Jun 1 15:17:12 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Sun, 1 Jun 2008 21:17:12 +0200 Subject: [rspec-users] != again Message-ID: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> Hey! I have implemented a quick solution for the should != .. , should ! ~ ... 'problem'. It uses source code inspection (I think it's the only way) and i've done some benchmarking to see if it's really that slow. A direct comparison of running '1.should == 1' with the unmodified rspec source against the rspec-version with source inspect shows that the latter is 7 times slower ... :( But benchmarks with '1.should == 1' inside a real example file are showing 'only' an overall speed decrease of 15% to 50%. That is still bad but having lots of people consider the passing of '1.should != 1' an rspec bug is bad too. Here is the benchmarking script: http://pastie.caboo.se/206853 And the code is at branch 'inspect' in: git://github.com/mhennemeyer/rspec There are examples for should and should_not != and !~ and i will definitely work on performance if you not totally reject this whole idea. Matthias. From pergesu at gmail.com Sun Jun 1 15:57:47 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 1 Jun 2008 12:57:47 -0700 Subject: [rspec-users] != again In-Reply-To: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> References: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> Message-ID: <810a540e0806011257u414454e0l2494c6bc14433d2b@mail.gmail.com> Very cool. Maybe we could print a warning when people use !=. That would let us get the ugly != bug fixed, but not have the perf issues. Pat On 6/1/08, Matthias Hennemeyer wrote: > Hey! > > I have implemented a quick solution for the should != .. , should ! > ~ ... 'problem'. > It uses source code inspection (I think it's the only way) and i've > done some > benchmarking to see if it's really that slow. > > A direct comparison of > running '1.should == 1' > with the unmodified rspec source against the rspec-version with > source inspect > shows that the latter is 7 times slower ... :( > > But benchmarks with '1.should == 1' inside a real example file are > showing 'only' > an overall speed decrease of 15% to 50%. That is still bad but having > lots of people > consider the passing of '1.should != 1' an rspec bug is bad too. > > Here is the benchmarking script: > http://pastie.caboo.se/206853 > > And the code is at branch 'inspect' in: > git://github.com/mhennemeyer/rspec > > There are examples for should and should_not != and !~ and i will > definitely work on performance if you not totally reject this whole > idea. > > Matthias. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jun 1 16:55:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 1 Jun 2008 13:55:03 -0700 Subject: [rspec-users] != again In-Reply-To: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> References: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> Message-ID: On Jun 1, 2008, at 12:17 PM, Matthias Hennemeyer wrote: > Hey! > > I have implemented a quick solution for the should != .. , should ! > ~ ... 'problem'. > It uses source code inspection (I think it's the only way) and i've > done some > benchmarking to see if it's really that slow. > > A direct comparison of > running '1.should == 1' > with the unmodified rspec source against the rspec-version with > source inspect > shows that the latter is 7 times slower ... :( > > But benchmarks with '1.should == 1' inside a real example file are > showing 'only' > an overall speed decrease of 15% to 50%. That is still bad but > having lots of people > consider the passing of '1.should != 1' an rspec bug is bad too. RSpec is already getting dinged for being slower than test/unit. Making it run any slower than it already does is a deal breaker for me. > Here is the benchmarking script: > http://pastie.caboo.se/206853 > > And the code is at branch 'inspect' in: > git://github.com/mhennemeyer/rspec > > There are examples for should and should_not != and !~ and i will > definitely work on performance if you not totally reject this whole > idea. If you can get the performance up to or better than current, I'm all for it. Cheers, David From mailing_lists at railsnewbie.com Sun Jun 1 22:13:46 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 1 Jun 2008 22:13:46 -0400 Subject: [rspec-users] != again In-Reply-To: References: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> Message-ID: <4EB229E8-FCA9-4E0A-996F-5634FE3B9837@railsnewbie.com> On Jun 1, 2008, at 4:55 PM, David Chelimsky wrote: > On Jun 1, 2008, at 12:17 PM, Matthias Hennemeyer wrote: > >> Hey! >> >> I have implemented a quick solution for the should != .. , should ! >> ~ ... 'problem'. >> It uses source code inspection (I think it's the only way) and i've >> done some >> benchmarking to see if it's really that slow. >> >> A direct comparison of >> running '1.should == 1' >> with the unmodified rspec source against the rspec-version with >> source inspect >> shows that the latter is 7 times slower ... :( >> >> But benchmarks with '1.should == 1' inside a real example file are >> showing 'only' >> an overall speed decrease of 15% to 50%. That is still bad but >> having lots of people >> consider the passing of '1.should != 1' an rspec bug is bad too. > > RSpec is already getting dinged for being slower than test/unit. > Making it run any slower than it already does is a deal breaker for > me. Maybe using autoloading instead of requiring would help the situation? It seems perfectly reasonable that rspec is bigger than test/unit: Test::Unit doesn't have a mocking framework, and so on. On the other hand, if no one uses (rspec's) mocking framework, should rspec have the code in place anyway? Anyway - I've never found it to be too slow. Has anyone done benchmarks on it? Scott > > >> Here is the benchmarking script: >> http://pastie.caboo.se/206853 >> >> And the code is at branch 'inspect' in: >> git://github.com/mhennemeyer/rspec >> >> There are examples for should and should_not != and !~ and i will >> definitely work on performance if you not totally reject this whole >> idea. > > If you can get the performance up to or better than current, I'm all > for it. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From tek.katu at gmail.com Sun Jun 1 23:29:08 2008 From: tek.katu at gmail.com (T K) Date: Mon, 2 Jun 2008 12:29:08 +0900 Subject: [rspec-users] Getting annotations in spec files. Message-ID: <5c17ebdc0806012029k1e4be6b9kcfc4808b8dd64822@mail.gmail.com> Hi, I just noticed that `rake notes` in rails 2.0.2 doesn't check `spec` directory. So, what I annotated with "FIXME", "TODO" and "OPTIMIZE" on *_spec.rb are discarded. Is there any quick way to `rake notes` task to check `spec` directory? -T From ashley.moran at patchspace.co.uk Mon Jun 2 06:51:59 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 2 Jun 2008 11:51:59 +0100 Subject: [rspec-users] Getting annotations in spec files. In-Reply-To: <5c17ebdc0806012029k1e4be6b9kcfc4808b8dd64822@mail.gmail.com> References: <5c17ebdc0806012029k1e4be6b9kcfc4808b8dd64822@mail.gmail.com> Message-ID: <91E63082-69E3-4501-9CC4-9E4C5201752D@patchspace.co.uk> On 2 Jun 2008, at 04:29, T K wrote: > I just noticed that `rake notes` in rails 2.0.2 doesn't check `spec` > directory. So, what I annotated with "FIXME", "TODO" and "OPTIMIZE" on > *_spec.rb are discarded. > > Is there any quick way to `rake notes` task to check `spec` directory? You could redefine the rake tast, but personally I prefer to leave pending specs. I think this is a better way to leave reminders than annotations. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From byrnejb at harte-lyne.ca Mon Jun 2 11:14:13 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Mon, 2 Jun 2008 11:14:13 -0400 (EDT) Subject: [rspec-users] GiT and RSpec In-Reply-To: References: Message-ID: <48476.216.185.71.22.1212419653.squirrel@webmail.harte-lyne.ca> > > Message: 2 > Date: Thu, 29 May 2008 06:35:01 -0700 > From: David Chelimsky > Subject: Re: [rspec-users] Coloured output in rspec 1.1.4 > To: rspec-users at rubyforge.org > Message-ID: <175B70FE-B706-4C03-8B20-C5B207268AD6 at gmail.com> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > On May 29, 2008, at 6:32 AM, Juanma Cervera wrote: > >> David Chelimsky wrote: >>> >>> Actually - that is not from 1.1.4 - it's a patch that was introduced >>> after the 1.1.4 release. Did you follow the install directions at >>> http://github.com/dchelimsky/rspec-rails/wikis? >> >> More or less. >> I have git-cloned from github repositories instead of make >> "script/plugin install" > > script/plugin install doesn't support getting a specific version from > git yet. To do that you have to use 'git clone' and then 'git checkout > 1.1.4' (in this case). > As an alternative to script/plugin or git-clone, you can employ git-submodules (on GiT v1.5.3 or later) to obtain the effect of subversion externals. For example: ---> $ git-submodule add \ git://github.com/dchelimsky/rspec.git \ vendor/plugins/rspec Initialized empty Git repository in /home/byrnejb/projects/proforma.git/vendor/plugins/rspec/.git/ remote: Counting objects: 46810, done. remote: Compressing objects: 100% (10646/10646), done. remote: Total 46810 (delta 33521), reused 46810 (delta 33521) Receiving objects: 100% (46810/46810), 5.99 MiB | 103 KiB/s, done. Resolving deltas: 100% (33521/33521), done. $ ll vendor/plugins total 16 drwxrwxr-x 6 byrnejb byrnejb 4096 May 28 14:06 routing_navigator drwxrwxr-x 12 byrnejb byrnejb 4096 Jun 2 10:09 rspec $ git-submodule add \ git://github.com/dchelimsky/rspec-rails.git \ vendor/plugins/rspec-rails Initialized empty Git repository in /home/byrnejb/projects/proforma.git/vendor/plugins/rspec-rails/.git/ remote: Counting objects: 46530, done. remote: Compressing objects: 100% (10649/10649), done. remote: Total 46530 (delta 33241), reused 46530 (delta 33241) Receiving objects: 100% (46530/46530), 5.94 MiB | 63 KiB/s, done. Resolving deltas: 100% (33241/33241), done. $ git-status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: .gitmodules # new file: vendor/plugins/rspec # new file: vendor/plugins/rspec-rails # $ git-submodule init Submodule 'vendor/plugins/rspec' (git://github.com/dchelimsky/rspec.git) registered for path 'vendor/plugins/rspec' Submodule 'vendor/plugins/rspec-rails' (git://github.com/dchelimsky/rspec-rails.git) registered for path 'vendor/plugins/rspec-rails' $ git-status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: .gitmodules # new file: vendor/plugins/rspec # new file: vendor/plugins/rspec-rails # $ git-commit -m "Added Rspec and Rspec-Rails as submodules" Created commit b4d1133: Added Rspec and Rspec-Rails as submodules 3 files changed, 8 insertions(+), 0 deletions(-) create mode 160000 vendor/plugins/rspec create mode 160000 vendor/plugins/rspec-rails $ git-status # On branch master nothing to commit (working directory clean) $ git-push # over ssh !!Warning!! - Any attempt to obtain access to this device without authorization is a criminal act. byrnejb at vcs-git.hamilton.harte-lyne.ca's password: Counting objects: 9, done. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 607 bytes, done. Total 5 (delta 1), reused 0 (delta 0) To ssh://byrnejb at vcs-git.hamilton.harte-lyne.ca/var/data/vcs-git/hll/proforma.git ab5353b..b4d1133 master -> master $ <--- Now, when anyone pulls from the canonical repository they will get Rspec and Rspec-on-Rails as well, but as submodules pulled directly from the RSpec repositories. Further, updating all submodules thereafter requires just these three steps: $git-submodule update $git-commit $git-push This is how I load edge rails as well, as a submodule: $ git-submodule add git://github.com/rails/rails.git vendor/rails $ git-submodule init $ git-commit $ git-push Once you do this you can locally checkout any version or branch that is available in the submodule. 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 rick.denatale at gmail.com Mon Jun 2 13:56:38 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 2 Jun 2008 13:56:38 -0400 Subject: [rspec-users] != again In-Reply-To: <4EB229E8-FCA9-4E0A-996F-5634FE3B9837@railsnewbie.com> References: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> <4EB229E8-FCA9-4E0A-996F-5634FE3B9837@railsnewbie.com> Message-ID: On Sun, Jun 1, 2008 at 10:13 PM, Scott Taylor wrote: > > On Jun 1, 2008, at 4:55 PM, David Chelimsky wrote: > >> >> RSpec is already getting dinged for being slower than test/unit. Making it >> run any slower than it already does is a deal breaker for me. >> > > It seems perfectly reasonable that rspec is bigger than test/unit: > Test::Unit doesn't have a mocking framework, and so on. On the other hand, > if no one uses (rspec's) mocking framework, should rspec have the code in > place anyway? I spoke up on the code size issue some months ago: http://talklikeaduck.denhaven2.com/articles/2008/01/29/why-i-dont-mind-using-rspec-in-fact-ive-come-to-love-it As for whether or not the rspec mocking framework should be separately loadable, that's a separate question. > > > Anyway - I've never found it to be too slow. Has anyone done benchmarks on > it? Like most other things, how slow or fast depends on how you use it. Here at @work, we have a really large rails app with a mixture of legacy tests and new specs. The slowest part of the overall test/spec suite, by far, is the legacy functional tests, which we hope to gradually convert to controller and view specs, using mocking as possible to avoid the db overhead, which is the real culprit. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Mon Jun 2 14:01:47 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 2 Jun 2008 11:01:47 -0700 Subject: [rspec-users] != again In-Reply-To: References: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> Message-ID: <810a540e0806021101o7f0e2363jdb345f03063352f1@mail.gmail.com> On Sun, Jun 1, 2008 at 1:55 PM, David Chelimsky wrote: > On Jun 1, 2008, at 12:17 PM, Matthias Hennemeyer wrote: > >> Hey! >> >> I have implemented a quick solution for the should != .. , should !~ ... >> 'problem'. >> It uses source code inspection (I think it's the only way) and i've done >> some >> benchmarking to see if it's really that slow. >> >> A direct comparison of >> running '1.should == 1' >> with the unmodified rspec source against the rspec-version with source >> inspect >> shows that the latter is 7 times slower ... :( >> >> But benchmarks with '1.should == 1' inside a real example file are >> showing 'only' >> an overall speed decrease of 15% to 50%. That is still bad but having lots >> of people >> consider the passing of '1.should != 1' an rspec bug is bad too. > > RSpec is already getting dinged for being slower than test/unit. Making it > run any slower than it already does is a deal breaker for me. What about showing an ugly warning in the test runner? != is a funky edge case that can really bite people. It'd be nice to have it fixed, but then tell the programmer to change it to == because of performance. Pat From ed.howland at gmail.com Mon Jun 2 14:06:12 2008 From: ed.howland at gmail.com (Ed Howland) Date: Mon, 2 Jun 2008 13:06:12 -0500 Subject: [rspec-users] get method under 1.1.4 in Stories is undefined Message-ID: <3df642dd0806021106t5d28d9bbi507596d0a3e4ab66@mail.gmail.com> HI, After I upgraded to RSpec 1.1.4 (from git), my stories all failed. I was using Webrat and the first thing I noticed was the 'visits' method was gone. I then backtracked to just using 'get' and got the same undefined method exception. I confirmed it was still working in 1.1.3 Eventually, I got it to work doing this: in my first Given: @app = ActionController::Integration::Session.new in some When @app.get page or using Webrat: @aop.visits "/" @app.fills_in field, :with => value Anyone els seen this? Why is creating the AIS needed? Thanks Ed . -- Ed Howland http://greenprogrammer.blogspot.com From pergesu at gmail.com Mon Jun 2 14:10:19 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 2 Jun 2008 11:10:19 -0700 Subject: [rspec-users] get method under 1.1.4 in Stories is undefined In-Reply-To: <3df642dd0806021106t5d28d9bbi507596d0a3e4ab66@mail.gmail.com> References: <3df642dd0806021106t5d28d9bbi507596d0a3e4ab66@mail.gmail.com> Message-ID: <810a540e0806021110h5eed6eacs1e1789d3d8ba2659@mail.gmail.com> On Mon, Jun 2, 2008 at 11:06 AM, Ed Howland wrote: > HI, > > After I upgraded to RSpec 1.1.4 (from git), my stories all failed. I > was using Webrat and the first thing I noticed was the 'visits' method > was gone. I then backtracked to just using 'get' and got the same > undefined method exception. I confirmed it was still working in 1.1.3 > > Eventually, I got it to work doing this: > > in my first Given: > @app = ActionController::Integration::Session.new > > in some When > @app.get page > > or using Webrat: > @aop.visits "/" > @app.fills_in field, :with => value > > Anyone els seen this? Why is creating the AIS needed? Are you running the stories as RailsStory? Seems like you might be missing that. Though it is odd that it worked before, but not now. Can you please paste all the relevant story code? (the step definitions and the line that runs the story) Pat From lists at ruby-forum.com Mon Jun 2 14:28:09 2008 From: lists at ruby-forum.com (Matt Wynne) Date: Mon, 2 Jun 2008 20:28:09 +0200 Subject: [rspec-users] Pretty HTML reporting for stories Message-ID: Hi all, I'm just getting to grips with rspec, and I'm trying to put together a showy demo. We're trying to use the (plain text) stories feature, rather than the specs. I'd like to show off a fancy HTML report of the results if possible. So it seems I can do this from the spec command line tool, but I can't make it work for a story. I've got the three files (story.txt, steps.rb, runner.rb) from the rspec.info homepage, and I can run then by doing ruby runner.rb All splendid so far. By when I try to do spec runner.rb It doesn't want to play. I don't get an error message or anything, it just seems to ignore me. Does spec support stories, or just specs? If so, what am I doing wrong? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jun 2 14:35:00 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 2 Jun 2008 11:35:00 -0700 Subject: [rspec-users] Pretty HTML reporting for stories In-Reply-To: References: Message-ID: <19DDB705-0EFC-40F3-9C3F-39D22D334408@gmail.com> On Jun 2, 2008, at 11:28 AM, Matt Wynne wrote: > Hi all, > > I'm just getting to grips with rspec, and I'm trying to put together a > showy demo. We're trying to use the (plain text) stories feature, > rather > than the specs. I'd like to show off a fancy HTML report of the > results > if possible. > > So it seems I can do this from the spec command line tool, but I can't > make it work for a story. > > I've got the three files (story.txt, steps.rb, runner.rb) from the > rspec.info homepage, and I can run then by doing > ruby runner.rb > > All splendid so far. > > By when I try to do > spec runner.rb > > It doesn't want to play. I don't get an error message or anything, it > just seems to ignore me. > > Does spec support stories, or just specs? If so, what am I doing > wrong? There is a bug right now when running stories w/ rails using the html formatter. I'm heading out the door right now, but will follow up later with a hack I used to get it to work. Should get fixed in source sometime soon. Cheers, David From rick.denatale at gmail.com Mon Jun 2 14:38:01 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 2 Jun 2008 14:38:01 -0400 Subject: [rspec-users] Cherry-picking mocks?! Message-ID: A colleague just came in and asked me about a problem he was having with stub_render, which reminded me of another issue he had a week or so ago, which seems related. Let me start with the earlier issue. He was trying to write specs for a method which sends the same message possibly multiple times, but with different arguments under different calling conditions. He wanted to write something.should_receive(:foo).with(someArguments) except that the other calls would cause this to fail. He was trying to get this to work by specifying ordered expectations but this was getting messy. What he really wanted was some kind of paired mock and stub, so that the expectation that the method would be invoked with the given arguments could be verified, but the other calls would just be stubbed. Now after today's question, and understanding how expect_render and mock_render differ from normal expectations, these seem to be related. Maybe we should be able to say something like: something.expects(:foo).with(someArguments).with(otherArguments).otherwise(:stub) something_else.expects(:bar).with(arguments).otherwise(:pass) # if the arguments don't match pass the method to the real object Which is really just a strawman to see if a discussion ensues. There are other issues like providing return values, and perhaps optionally passing a method through after verification that it was called with the expected arguments. Comments? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benmabey.com Mon Jun 2 14:40:36 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 02 Jun 2008 12:40:36 -0600 Subject: [rspec-users] Pretty HTML reporting for stories In-Reply-To: References: Message-ID: <48443EA4.9020100@benmabey.com> Matt Wynne wrote: > Hi all, > > I'm just getting to grips with rspec, and I'm trying to put together a > showy demo. We're trying to use the (plain text) stories feature, rather > than the specs. I'd like to show off a fancy HTML report of the results > if possible. > > So it seems I can do this from the spec command line tool, but I can't > make it work for a story. > > I've got the three files (story.txt, steps.rb, runner.rb) from the > rspec.info homepage, and I can run then by doing > ruby runner.rb > > All splendid so far. > > By when I try to do > spec runner.rb > > It doesn't want to play. I don't get an error message or anything, it > just seems to ignore me. > > Does spec support stories, or just specs? If so, what am I doing wrong? > The spec command is just for specs. Although the story runner now uses the same command line option parser. So you can pass in the args when running your runner file. Like so: ruby story.rb -f=html or the verbose way: ruby story.rb --format=html -Ben From ben at benmabey.com Mon Jun 2 14:45:18 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 02 Jun 2008 12:45:18 -0600 Subject: [rspec-users] Pretty HTML reporting for stories In-Reply-To: <19DDB705-0EFC-40F3-9C3F-39D22D334408@gmail.com> References: <19DDB705-0EFC-40F3-9C3F-39D22D334408@gmail.com> Message-ID: <48443FBE.7070407@benmabey.com> David Chelimsky wrote: > On Jun 2, 2008, at 11:28 AM, Matt Wynne wrote: > >> Hi all, >> >> I'm just getting to grips with rspec, and I'm trying to put together a >> showy demo. We're trying to use the (plain text) stories feature, rather >> than the specs. I'd like to show off a fancy HTML report of the results >> if possible. >> >> So it seems I can do this from the spec command line tool, but I can't >> make it work for a story. >> >> I've got the three files (story.txt, steps.rb, runner.rb) from the >> rspec.info homepage, and I can run then by doing >> ruby runner.rb >> >> All splendid so far. >> >> By when I try to do >> spec runner.rb >> >> It doesn't want to play. I don't get an error message or anything, it >> just seems to ignore me. >> >> Does spec support stories, or just specs? If so, what am I doing wrong? > > There is a bug right now when running stories w/ rails using the html > formatter. I'm heading out the door right now, but will follow up > later with a hack I used to get it to work. Should get fixed in source > sometime soon. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users David, Are you sure there is a bug? (what ticket number?) I can get it to work just fine, and just barely verified this. In fact, I am using it in my textmate story bundle that I have on github. -Ben From pergesu at gmail.com Mon Jun 2 14:50:56 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 2 Jun 2008 11:50:56 -0700 Subject: [rspec-users] Cherry-picking mocks?! In-Reply-To: References: Message-ID: <810a540e0806021150o33fe74bg497d3f37dd51cd0a@mail.gmail.com> On Mon, Jun 2, 2008 at 11:38 AM, Rick DeNatale wrote: > A colleague just came in and asked me about a problem he was having with > stub_render, which reminded me of another issue he had a week or so ago, > which seems related. > > Let me start with the earlier issue. > > He was trying to write specs for a method which sends the same message > possibly multiple times, but with different arguments under different > calling conditions. He wanted to write > > something.should_receive(:foo).with(someArguments) > > except that the other calls would cause this to fail. He was trying to get > this to work by specifying ordered expectations but this was getting messy. > > What he really wanted was some kind of paired mock and stub, so that the > expectation that the method would be invoked with the given arguments could > be verified, but the other calls would just be stubbed. > > Now after today's question, and understanding how expect_render and > mock_render differ from normal expectations, these seem to be related. > > Maybe we should be able to say something like: > > > something.expects(:foo).with(someArguments).with(otherArguments).otherwise(:stub) > something_else.expects(:bar).with(arguments).otherwise(:pass) # if the > arguments don't match pass the method to the real object > > Which is really just a strawman to see if a discussion ensues. There are > other issues like providing return values, and perhaps optionally passing a > method through after verification that it was called with the expected > arguments. > > Comments? I've never used *_render before so I'm going to ignore that part. I just tried out describe "Mixed mocks and stubs" do before(:each) do @object = Object.new @object.stub!(:foo).and_return 1 end it "should allow both mocking and stubbing" do @object.should_receive(:foo).with(:mock).and_return 2 @object.foo(:mock).should == 2 #mock @object.foo.should == 1 #stub end end and it passes. Would that be helpful to your coworker's situation? Pat From ed.howland at gmail.com Mon Jun 2 14:55:31 2008 From: ed.howland at gmail.com (Ed Howland) Date: Mon, 2 Jun 2008 13:55:31 -0500 Subject: [rspec-users] get method under 1.1.4 in Stories is undefined In-Reply-To: <810a540e0806021110h5eed6eacs1e1789d3d8ba2659@mail.gmail.com> References: <3df642dd0806021106t5d28d9bbi507596d0a3e4ab66@mail.gmail.com> <810a540e0806021110h5eed6eacs1e1789d3d8ba2659@mail.gmail.com> Message-ID: <3df642dd0806021155h1526994dk28e24ae620bbb21f@mail.gmail.com> Yes, that was it. Thanks Ed On Mon, Jun 2, 2008 at 1:10 PM, Pat Maddox wrote: > On Mon, Jun 2, 2008 at 11:06 AM, Ed Howland wrote: >> HI, >> >> After I upgraded to RSpec 1.1.4 (from git), my stories all failed. I >> was using Webrat and the first thing I noticed was the 'visits' method >> was gone. I then backtracked to just using 'get' and got the same >> uandefined method exception. I confirmed it was still working in 1.1.3 >> >> Eventually, I got it to work doing this: >> >> in my first Given: >> @app = ActionController::Integration::Session.new >> >> in some When >> @app.get page >> >> or using Webrat: >> @aop.visits "/" >> @app.fills_in field, :with => value >> >> Anyone els seen this? Why is creating the AIS needed? > > Are you running the stories as RailsStory? Seems like you might be > missing that. Though it is odd that it worked before, but not now. > Can you please paste all the relevant story code? (the step > definitions and the line that runs the story) > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Ed Howland http://greenprogrammer.blogspot.com "The information transmitted is intended only for the person or entity to which it is addressed and may contain proprietary, confidential and/or legally privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers." From lists at ruby-forum.com Mon Jun 2 15:20:35 2008 From: lists at ruby-forum.com (Matt Wynne) Date: Mon, 2 Jun 2008 21:20:35 +0200 Subject: [rspec-users] Pretty HTML reporting for stories In-Reply-To: <48443EA4.9020100@benmabey.com> References: <48443EA4.9020100@benmabey.com> Message-ID: Ben Mabey wrote: > The spec command is just for specs. Although the story runner now uses > the same command line option parser. So you can pass in the args when > running your runner file. Like so: > > ruby story.rb -f=html > or the verbose way: > ruby story.rb --format=html Man, you gentlemen are quick of the mark! Thanks for the info guys. Matt -- Posted via http://www.ruby-forum.com/. From steve.downtown at gmail.com Mon Jun 2 15:59:04 2008 From: steve.downtown at gmail.com (Steve Downey) Date: Mon, 2 Jun 2008 12:59:04 -0700 Subject: [rspec-users] Looking for help on two issues with Rails 2.1 and RSpec 1.14 Message-ID: <4fff79200806021259j29f4fb3i6b6b2a915fcbfb6f@mail.gmail.com> I have specs that ran fine in Rails 2.02/RSpec 1.13 that are failing on Rails 2.1/RSpec 1.14. There is one problem and one issue: problem: sometimes (but not always) I get a NoMethodError referencing a has_many association issue: in helper specs, instance variables don't get set unless the HelperModule is included. Using the preferred helper. I can't seem to find a way to check that an instance variable is set: I have several specs that used to look like: it "page_title should assign @browser_title" do page_title("foo") @browser_title.should == "foo" end Now changed to: it "page_title should assign @browser_title" do helper.page_title("foo") helper.assigns[:browser_title].should == "foo" # also tried: assigns[:browser_title].should == "foo" end The output is: expected: "foo", got: nil (using ==) Any help appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jun 2 16:50:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 2 Jun 2008 13:50:23 -0700 Subject: [rspec-users] Pretty HTML reporting for stories In-Reply-To: References: <48443EA4.9020100@benmabey.com> Message-ID: On Jun 2, 2008, at 12:20 PM, Matt Wynne wrote: > Ben Mabey wrote: >> The spec command is just for specs. Although the story runner now >> uses >> the same command line option parser. So you can pass in the args >> when >> running your runner file. Like so: >> >> ruby story.rb -f=html >> or the verbose way: >> ruby story.rb --format=html > > Man, you gentlemen are quick of the mark! > > Thanks for the info guys. Did that work? I'm not able to check this minute, but I recall a bug w/ rspec/rails/stories. > > > Matt > -- > 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 Jun 2 16:52:58 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 02 Jun 2008 14:52:58 -0600 Subject: [rspec-users] Pretty HTML reporting for stories In-Reply-To: References: <48443EA4.9020100@benmabey.com> Message-ID: <48445DAA.60605@benmabey.com> David Chelimsky wrote: > On Jun 2, 2008, at 12:20 PM, Matt Wynne wrote: > >> Ben Mabey wrote: >>> The spec command is just for specs. Although the story runner now uses >>> the same command line option parser. So you can pass in the args when >>> running your runner file. Like so: >>> >>> ruby story.rb -f=html >>> or the verbose way: >>> ruby story.rb --format=html >> >> Man, you gentlemen are quick of the mark! >> >> Thanks for the info guys. > > Did that work? I'm not able to check this minute, but I recall a bug > w/ rspec/rails/stories. > Yes, there was a bug that prevented it before. I believe this was resolved some time ago with a commit by Aslak... Not sure... But, it is working with rails now. -Ben > >> >> >> Matt >> -- >> 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 ben at benmabey.com Mon Jun 2 17:26:16 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 02 Jun 2008 15:26:16 -0600 Subject: [rspec-users] Looking for help on two issues with Rails 2.1 and RSpec 1.14 In-Reply-To: <4fff79200806021259j29f4fb3i6b6b2a915fcbfb6f@mail.gmail.com> References: <4fff79200806021259j29f4fb3i6b6b2a915fcbfb6f@mail.gmail.com> Message-ID: <48446578.6030900@benmabey.com> Steve Downey wrote: > I have specs that ran fine in Rails 2.02/RSpec 1.13 that are failing > on Rails 2.1/RSpec 1.14. > > There is one problem and one issue: > > problem: sometimes (but not always) I get a NoMethodError referencing > a has_many association > > issue: in helper specs, instance variables don't get set unless the > HelperModule is included. Using the preferred helper. I can't > seem to find a way to check that an instance variable is set: > > I have several specs that used to look like: > > it "page_title should assign @browser_title" do > page_title("foo") > @browser_title.should == "foo" > end > > > Now changed to: > > it "page_title should assign @browser_title" do > helper.page_title("foo") > helper.assigns[:browser_title].should == "foo" > # also tried: assigns[:browser_title].should == "foo" > end > > The output is: > > expected: "foo", > got: nil (using ==) > > > Any help appreciated. > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Steve, You are basically testing state here... With that said you can get around this a number of ways. You can forgoe the suggested way of using helper and just include the module directly. You can then verify that your expectation of that variable has been set. Like so: include YourHelper it "page_title should assign @browser_title" do page_title("foo") @browser_title.should == "foo" end You could also reach in and pull the variable out of the helper: it "page_title should assign @browser_title" do helper.page_title("foo") helper.instance_variable_get("@browser_title").should == "foo" end This way smells bad. In fact, both ways send off warning signals. Depending on what you are doing this may be needed though, so I hope one of these ways works for you. -Ben From lists at ruby-forum.com Mon Jun 2 18:46:59 2008 From: lists at ruby-forum.com (Ben Men) Date: Tue, 3 Jun 2008 00:46:59 +0200 Subject: [rspec-users] Cannot log in/authenticate within RSpec Story Message-ID: <0085856a78f867c978fdca90707fda1b@ruby-forum.com> I've been slamming my head against a wall for a while now, and would like some help. I believe this is session related. I have a story that looks like: -------------------------------------------------- Given that a post exists And I am logged in When I visit the post details page Then there should be a link to add a new comment -------------------------------------------------- I am using the following RSpec story functions to assist this scenario (along with others): -------------------------------------------------- Given("I am logged in") do post '/login/login', {:name => 'domain\\username', :password => 'password'} follow_redirect if redirect? end When "I visit the post details page" do get('/posts/1') end Then "there should be a link to add a new comment" do response.should have_text(/.*Add New Comment.*/) end -------------------------------------------------- The "Add New Comment" text will only show up within the view if !session['username'].nil? The login controller looks like this: -------------------------------------------------- def login if request.get? session['username'] = nil else # Split username on domain and alias split_username = params[:name].split('\\', 2) if split_username.length != 2 flash[:notice] = "You did not enter a properly formatted domain and alias" redirect_to :action => 'login' else # Authenticate username and password domain = split_username[0] username = split_username[1] password = params[:password] isAuthenticated = authenticate(domain, username, password) if isAuthenticated # User has been authenticated session['username'] = username redirect_back({:controller => 'posts', :action => 'index'}) else flash[:notice] = "Incorrect username or password" redirect_to :action => 'login' end end end end -------------------------------------------------- After the post to login/login occurs, I've attempted to check the session variable everywhere I could think to, and it does not contain a username in the data hash. Additionally, I'm told that session is a nil object within the login controller if I try something like: -------------------------------------------------- Given("I am logged in") do @lc = LoginController.new @lc.authenticate('domain', 'username', 'password') end -------------------------------------------------- I've also tried setting the session variable directly, but after that particular Given .. do clause is finished, any settings I make directly seem to be lost. Questions: 1. Can controllers within rspec stories set/get session data? 2. What is the scope of the persistence of sessions in rspec? (Scenario? Story?) 3. Any ideas on why my LoginController sets the session['username'] variable, only to have my PostsController unable to read it? Also, keep in mind that the code works when I'm actually using the site, but the rspec story fails because it's not displaying an "Add New Comment" link when it should be due to the PostsController thinking that the user isn't logged in. -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Mon Jun 2 18:55:20 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 02 Jun 2008 16:55:20 -0600 Subject: [rspec-users] Cannot log in/authenticate within RSpec Story In-Reply-To: <0085856a78f867c978fdca90707fda1b@ruby-forum.com> References: <0085856a78f867c978fdca90707fda1b@ruby-forum.com> Message-ID: <48447A58.4070706@benmabey.com> Ben Men wrote: > I've been slamming my head against a wall for a while now, and would > like some help. I believe this is session related. > > I have a story that looks like: > > -------------------------------------------------- > > Given that a post exists > And I am logged in > When I visit the post details page > Then there should be a link to add a new comment > > -------------------------------------------------- > > I am using the following RSpec story functions to assist this scenario > (along with others): > > -------------------------------------------------- > > Given("I am logged in") do > post '/login/login', {:name => 'domain\\username', :password => > 'password'} > follow_redirect if redirect? > end > > When "I visit the post details page" do > get('/posts/1') > end > > Then "there should be a link to add a new comment" do > response.should have_text(/.*Add New Comment.*/) > end > > -------------------------------------------------- > > The "Add New Comment" text will only show up within the view if > !session['username'].nil? > > The login controller looks like this: > > -------------------------------------------------- > > def login > if request.get? > session['username'] = nil > else > # Split username on domain and alias > split_username = params[:name].split('\\', 2) > if split_username.length != 2 > flash[:notice] = "You did not enter a properly formatted domain > and alias" > redirect_to :action => 'login' > else > # Authenticate username and password > domain = split_username[0] > username = split_username[1] > password = params[:password] > isAuthenticated = authenticate(domain, username, password) > if isAuthenticated > # User has been authenticated > session['username'] = username > redirect_back({:controller => 'posts', :action => 'index'}) > else > flash[:notice] = "Incorrect username or password" > redirect_to :action => 'login' > end > end > end > end > > -------------------------------------------------- > > After the post to login/login occurs, I've attempted to check the > session variable everywhere I could think to, and it does not contain a > username in the data hash. > > Additionally, I'm told that session is a nil object within the login > controller if I try something like: > > -------------------------------------------------- > > Given("I am logged in") do > @lc = LoginController.new > @lc.authenticate('domain', 'username', 'password') > end > > -------------------------------------------------- > > I've also tried setting the session variable directly, but after that > particular Given .. do clause is finished, any settings I make directly > seem to be lost. > > Questions: > 1. Can controllers within rspec stories set/get session data? > 2. What is the scope of the persistence of sessions in rspec? (Scenario? > Story?) > 3. Any ideas on why my LoginController sets the session['username'] > variable, only to have my PostsController unable to read it? > > Also, keep in mind that the code works when I'm actually using the site, > but the rspec story fails because it's not displaying an "Add New > Comment" link when it should be due to the PostsController thinking that > the user isn't logged in. > I don't have time to parse your entire post or send a lengthy reply. However, this blog post walks through how to do exactly what you are attempting: http://www.glennfu.com/2008/03/31/easy-plaintext-stories-in-ruby-on-rails-using-webrat/ Good luck. -Ben From lists at ruby-forum.com Mon Jun 2 19:54:51 2008 From: lists at ruby-forum.com (Ben Men) Date: Tue, 3 Jun 2008 01:54:51 +0200 Subject: [rspec-users] Cannot log in/authenticate within RSpec Story In-Reply-To: <48447A58.4070706@benmabey.com> References: <0085856a78f867c978fdca90707fda1b@ruby-forum.com> <48447A58.4070706@benmabey.com> Message-ID: <896aa46173633c42cebd0f89e7219d42@ruby-forum.com> Ben Mabey wrote: > > I don't have time to parse your entire post or send a lengthy reply. > However, this blog post walks through how to do exactly what you are > attempting: > >http://www.glennfu.com/2008/03/31/easy-plaintext-stories-in-ruby-on-rails-using-webrat/ I wrote the login "Given" clause using Webrat and now the tests are working, though it does feel like a workaround rather than a solution. I've read over your Webrat post, as well as the linked article, and am happy using Webrat in the manner you've written about, though I'd still like to know why the session variables weren't set upon trying to read them later when not using Webrat.. -- Posted via http://www.ruby-forum.com/. From hans at degraaff.org Tue Jun 3 01:36:16 2008 From: hans at degraaff.org (Hans de Graaff) Date: Tue, 03 Jun 2008 07:36:16 +0200 Subject: [rspec-users] Pretty HTML reporting for stories In-Reply-To: <48445DAA.60605@benmabey.com> References: <48443EA4.9020100@benmabey.com> <48445DAA.60605@benmabey.com> Message-ID: <1212471376.17934.1.camel@ip6-localhost> On Mon, 2008-06-02 at 14:52 -0600, Ben Mabey wrote: > David Chelimsky wrote: > > Did that work? I'm not able to check this minute, but I recall a bug > > w/ rspec/rails/stories. > > > > Yes, there was a bug that prevented it before. I believe this was > resolved some time ago with a commit by Aslak... Not sure... But, it is > working with rails now. I did notice that the stories output is now colored again in my rails project with rspec 1.1.4, so I guess this has also fixed http://rspec.lighthouseapp.com/projects/5645/tickets/286-c-does-not-run-stories-in-color Makes sense as this also involves passing throught the command line options. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From lists at ruby-forum.com Tue Jun 3 02:09:06 2008 From: lists at ruby-forum.com (Jose Fernandez) Date: Tue, 3 Jun 2008 08:09:06 +0200 Subject: [rspec-users] Build rspec-rails as a gem? Message-ID: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> I can't figure out how to build rspec-rails as a gem when just cloned from github... there isn't any .gemspec file or rake task that does this. Any help? -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Tue Jun 3 02:14:16 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 2 Jun 2008 23:14:16 -0700 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> Message-ID: <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> On Mon, Jun 2, 2008 at 11:09 PM, Jose Fernandez wrote: > I can't figure out how to build rspec-rails as a gem when just cloned > from github... there isn't any .gemspec file or rake task that does > this. Any help? rspec-rails is a rails plugin, not a gem. Pat From lists at ruby-forum.com Tue Jun 3 02:16:49 2008 From: lists at ruby-forum.com (Jose Fernandez) Date: Tue, 3 Jun 2008 08:16:49 +0200 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> Message-ID: <1d0a6550d45b0a168de22a56b7219fa1@ruby-forum.com> So how can I test a mocked rails controller within my plugin's specs? -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Tue Jun 3 02:20:29 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 2 Jun 2008 23:20:29 -0700 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <1d0a6550d45b0a168de22a56b7219fa1@ruby-forum.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> <1d0a6550d45b0a168de22a56b7219fa1@ruby-forum.com> Message-ID: <810a540e0806022320y761a5825q9827a3b262229bd1@mail.gmail.com> On Mon, Jun 2, 2008 at 11:16 PM, Jose Fernandez wrote: > So how can I test a mocked rails controller within my plugin's specs? I don't quite follow you. Can you post an example of what you're trying to do? Pat From lists at ruby-forum.com Tue Jun 3 02:23:20 2008 From: lists at ruby-forum.com (Jose Fernandez) Date: Tue, 3 Jun 2008 08:23:20 +0200 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <810a540e0806022320y761a5825q9827a3b262229bd1@mail.gmail.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> <1d0a6550d45b0a168de22a56b7219fa1@ruby-forum.com> <810a540e0806022320y761a5825q9827a3b262229bd1@mail.gmail.com> Message-ID: <2bfd6e2ba016a684baa24291d9db16e0@ruby-forum.com> Pat Maddox wrote: > On Mon, Jun 2, 2008 at 11:16 PM, Jose Fernandez > wrote: >> So how can I test a mocked rails controller within my plugin's specs? > > I don't quite follow you. Can you post an example of what you're trying > to do? > > Pat http://github.com/jfernandez/submarine/tree/b3853cb0a959813f156bb25239dcd4f4f2c0c406/spec/submarine/submarine_spec.rb That only test wont work because neither the 'controller_name' or 'get' methods are recognized, and I think thats because they are part of rspec-rails. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Tue Jun 3 02:32:44 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 2 Jun 2008 23:32:44 -0700 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <2bfd6e2ba016a684baa24291d9db16e0@ruby-forum.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> <1d0a6550d45b0a168de22a56b7219fa1@ruby-forum.com> <810a540e0806022320y761a5825q9827a3b262229bd1@mail.gmail.com> <2bfd6e2ba016a684baa24291d9db16e0@ruby-forum.com> Message-ID: <810a540e0806022332l6124e74m484a4fad6eaa7387@mail.gmail.com> On Mon, Jun 2, 2008 at 11:23 PM, Jose Fernandez wrote: > Pat Maddox wrote: >> On Mon, Jun 2, 2008 at 11:16 PM, Jose Fernandez >> wrote: >>> So how can I test a mocked rails controller within my plugin's specs? >> >> I don't quite follow you. Can you post an example of what you're trying >> to do? >> >> Pat > > http://github.com/jfernandez/submarine/tree/b3853cb0a959813f156bb25239dcd4f4f2c0c406/spec/submarine/submarine_spec.rb > > That only test wont work because neither the 'controller_name' or 'get' > methods are recognized, and I think thats because they are part of > rspec-rails. You need to include the app's spec-helper from within your spec. http://github.com/pat-maddox/rspec-plugin-generator/tree/master/generators/rspec_plugin/templates/spec_helper.rb shows what I did in my rspec_plugin generator. You might just be able to require spec/rails, I'm not sure, but you'd have to set up the load path. Pat From aselder at mac.com Tue Jun 3 10:08:53 2008 From: aselder at mac.com (Andrew Selder) Date: Tue, 03 Jun 2008 10:08:53 -0400 Subject: [rspec-users] Autotest/RSpec 1.1.4/Rails 2.1 Infinite Loop? Message-ID: <20A9C048-B70F-40D2-84C6-4169A7F0D44F@mac.com> I just got back from RailsConf, and upgraded on of my development apps to 2.1, and now autotest is going into an infinite loop. It runs tests continuously instead of waiting for files to be saved before rerunning. Has anybody else seen this, or know how to get around it? Thanks, Andrew From ben at benmabey.com Tue Jun 3 12:31:39 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 03 Jun 2008 10:31:39 -0600 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> Message-ID: <484571EB.4080606@benmabey.com> Pat Maddox wrote: > On Mon, Jun 2, 2008 at 11:09 PM, Jose Fernandez wrote: > >> I can't figure out how to build rspec-rails as a gem when just cloned >> from github... there isn't any .gemspec file or rake task that does >> this. Any help? >> > > rspec-rails is a rails plugin, not a gem. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I have needed to use it as a gem before. Why? Well, with ticket 383(http://rspec.lighthouseapp.com/projects/5645/tickets/383-extract-mock_model-out-of-railsexamplegroup) David extracted the mocking features for AR so that it could be reused easily. I was writing a merb app that used AR and I quickly began missing the mock_model and other mock helpers found in rspec-rails. So, I created a gem out of the plugin, installed it locally in my merb app I just required 'spec/rails/mocks'. The gemspec file I created to do this was: Gem::Specification.new do |s| s.name = %q{rspec-rails} s.version = "1.1.4" s.specification_version = 2 if s.respond_to? :specification_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["RSpec Development Team"] s.date = %q{2008-05-25} s.default_executable = %q{spec} s.description = %q{RSpec-Rails is an extension to RSpec to provide a better environment for specing rails.} s.email = %q{rspec-devel at rubyforge.org} s.extra_rdoc_files = ["README", "CHANGES", "MIT-LICENSE"] s.files = ["CHANGES", "MIT-LICENSE", "Rakefile", "README", "lib/autotest/discover.rb", "lib/autotest/rails_rspec.rb", "lib/spec/rails/example/assigns_hash_proxy.rb", "lib/spec/rails/example/controller_example _group.rb", "lib/spec/rails/example/functional_example_group.rb", "lib/spec/rails/example/helper_example_group.rb", "lib/spec/rails/example/model_example_group.rb", "lib/spec/rails/example/rails_example_group.r b", "lib/spec/rails/example/render_observer.rb", "lib/spec/rails/example/view_example_group.rb", "lib/spec/rails/example.rb", "lib/spec/rails/extensions/action_controller/base.rb", "lib/spec/rails/extensions/ac tion_controller/rescue.rb", "lib/spec/rails/extensions/action_controller/test_response.rb", "lib/spec/rails/extensions/action_view/base.rb", "lib/spec/rails/extensions/active_record/base.rb", "lib/spec/rails/ex tensions/object.rb", "lib/spec/rails/extensions/spec/example/configuration.rb", "lib/spec/rails/extensions/spec/matchers/have.rb", "lib/spec/rails/extensions.rb", "lib/spec/rails/matchers/assert_select.rb", "li b/spec/rails/matchers/have_text.rb", "lib/spec/rails/matchers/include_text.rb", "lib/spec/rails/matchers/redirect_to.rb", "lib/spec/rails/matchers/render_template.rb", "lib/spec/rails/matchers.rb", "lib/spec/ra ils/mocks.rb", "lib/spec/rails/story_adapter.rb", "lib/spec/rails/version.rb", "lib/spec/rails.rb"] s.has_rdoc = true s.homepage = %q{http://rspec.rubyforge.org} s.rdoc_options = ["--title", "RSpec-Rails", "--line-numbers", "--inline-source", "--main", "README"] s.require_paths = ["lib"] s.rubygems_version = %q{1.1.0} s.summary = %q{RSpec-Rails-1.1.4 (build 20080526202855) - BDD for Ruby http://rspec.rubyforge.org/} end From dchelimsky at gmail.com Tue Jun 3 12:42:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 3 Jun 2008 11:42:14 -0500 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <484571EB.4080606@benmabey.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> <484571EB.4080606@benmabey.com> Message-ID: <0C45494B-CFDA-43C4-B423-93E3376AC16C@gmail.com> On Jun 3, 2008, at 11:31 AM, Ben Mabey wrote: > Pat Maddox wrote: >> On Mon, Jun 2, 2008 at 11:09 PM, Jose Fernandez > forum.com> wrote: >> >>> I can't figure out how to build rspec-rails as a gem when just >>> cloned >>> from github... there isn't any .gemspec file or rake task that does >>> this. Any help? >>> >> >> rspec-rails is a rails plugin, not a gem. >> >> Pat >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > I have needed to use it as a gem before. Why? Well, with ticket > 383(http://rspec.lighthouseapp.com/projects/5645/tickets/383-extract-mock_model-out-of-railsexamplegroup > ) David extracted the mocking features for AR so that it could be > reused easily. I was writing a merb app that used AR and I quickly > began missing the mock_model and other mock helpers found in rspec- > rails. So, I created a gem out of the plugin, installed it locally > in my merb app I just required 'spec/rails/mocks'. > > > The gemspec file I created to do this was: > > Gem::Specification.new do |s| > s.name = %q{rspec-rails} > s.version = "1.1.4" > > s.specification_version = 2 if s.respond_to? :specification_version= > > s.required_rubygems_version = Gem::Requirement.new(">= 0") if > s.respond_to? :required_rubygems_version= > s.authors = ["RSpec Development Team"] > s.date = %q{2008-05-25} > s.default_executable = %q{spec} > s.description = %q{RSpec-Rails is an extension to RSpec to provide a > better environment for specing rails.} > s.email = %q{rspec-devel at rubyforge.org} > s.extra_rdoc_files = ["README", "CHANGES", "MIT-LICENSE"] > s.files = ["CHANGES", "MIT-LICENSE", "Rakefile", "README", "lib/ > autotest/discover.rb", "lib/autotest/rails_rspec.rb", "lib/spec/ > rails/example/assigns_hash_proxy.rb", "lib/spec/rails/example/ > controller_example > _group.rb", "lib/spec/rails/example/functional_example_group.rb", > "lib/spec/rails/example/helper_example_group.rb", "lib/spec/rails/ > example/model_example_group.rb", "lib/spec/rails/example/ > rails_example_group.r > b", "lib/spec/rails/example/render_observer.rb", "lib/spec/rails/ > example/view_example_group.rb", "lib/spec/rails/example.rb", "lib/ > spec/rails/extensions/action_controller/base.rb", "lib/spec/rails/ > extensions/ac > tion_controller/rescue.rb", "lib/spec/rails/extensions/ > action_controller/test_response.rb", "lib/spec/rails/extensions/ > action_view/base.rb", "lib/spec/rails/extensions/active_record/ > base.rb", "lib/spec/rails/ex > tensions/object.rb", "lib/spec/rails/extensions/spec/example/ > configuration.rb", "lib/spec/rails/extensions/spec/matchers/ > have.rb", "lib/spec/rails/extensions.rb", "lib/spec/rails/matchers/ > assert_select.rb", "li > b/spec/rails/matchers/have_text.rb", "lib/spec/rails/matchers/ > include_text.rb", "lib/spec/rails/matchers/redirect_to.rb", "lib/ > spec/rails/matchers/render_template.rb", "lib/spec/rails/ > matchers.rb", "lib/spec/ra > ils/mocks.rb", "lib/spec/rails/story_adapter.rb", "lib/spec/rails/ > version.rb", "lib/spec/rails.rb"] > s.has_rdoc = true > s.homepage = %q{http://rspec.rubyforge.org} > s.rdoc_options = ["--title", "RSpec-Rails", "--line-numbers", "-- > inline-source", "--main", "README"] > s.require_paths = ["lib"] > s.rubygems_version = %q{1.1.0} > s.summary = %q{RSpec-Rails-1.1.4 (build 20080526202855) - BDD for > Ruby http://rspec.rubyforge.org/} > end I can grab this and add it or, if you want, you can gimme a git-patch. Your call. Cheers, David From ben at benmabey.com Tue Jun 3 12:55:34 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 03 Jun 2008 10:55:34 -0600 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <0C45494B-CFDA-43C4-B423-93E3376AC16C@gmail.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> <484571EB.4080606@benmabey.com> <0C45494B-CFDA-43C4-B423-93E3376AC16C@gmail.com> Message-ID: <48457786.7060804@benmabey.com> David Chelimsky wrote: > > On Jun 3, 2008, at 11:31 AM, Ben Mabey wrote: > >> Pat Maddox wrote: >>> On Mon, Jun 2, 2008 at 11:09 PM, Jose Fernandez >>> wrote: >>> >>>> I can't figure out how to build rspec-rails as a gem when just cloned >>>> from github... there isn't any .gemspec file or rake task that does >>>> this. Any help? >>>> >>> >>> rspec-rails is a rails plugin, not a gem. >>> >>> Pat >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> I have needed to use it as a gem before. Why? Well, with ticket >> 383(http://rspec.lighthouseapp.com/projects/5645/tickets/383-extract-mock_model-out-of-railsexamplegroup) >> David extracted the mocking features for AR so that it could be >> reused easily. I was writing a merb app that used AR and I quickly >> began missing the mock_model and other mock helpers found in >> rspec-rails. So, I created a gem out of the plugin, installed it >> locally in my merb app I just required 'spec/rails/mocks'. >> >> >> The gemspec file I created to do this was: >> >> Gem::Specification.new do |s| >> s.name = %q{rspec-rails} >> s.version = "1.1.4" >> >> s.specification_version = 2 if s.respond_to? :specification_version= >> >> s.required_rubygems_version = Gem::Requirement.new(">= 0") if >> s.respond_to? :required_rubygems_version= >> s.authors = ["RSpec Development Team"] >> s.date = %q{2008-05-25} >> s.default_executable = %q{spec} >> s.description = %q{RSpec-Rails is an extension to RSpec to provide a >> better environment for specing rails.} >> s.email = %q{rspec-devel at rubyforge.org} >> s.extra_rdoc_files = ["README", "CHANGES", "MIT-LICENSE"] >> s.files = ["CHANGES", "MIT-LICENSE", "Rakefile", "README", >> "lib/autotest/discover.rb", "lib/autotest/rails_rspec.rb", >> "lib/spec/rails/example/assigns_hash_proxy.rb", >> "lib/spec/rails/example/controller_example >> _group.rb", "lib/spec/rails/example/functional_example_group.rb", >> "lib/spec/rails/example/helper_example_group.rb", >> "lib/spec/rails/example/model_example_group.rb", >> "lib/spec/rails/example/rails_example_group.r >> b", "lib/spec/rails/example/render_observer.rb", >> "lib/spec/rails/example/view_example_group.rb", >> "lib/spec/rails/example.rb", >> "lib/spec/rails/extensions/action_controller/base.rb", >> "lib/spec/rails/extensions/ac >> tion_controller/rescue.rb", >> "lib/spec/rails/extensions/action_controller/test_response.rb", >> "lib/spec/rails/extensions/action_view/base.rb", >> "lib/spec/rails/extensions/active_record/base.rb", "lib/spec/rails/ex >> tensions/object.rb", >> "lib/spec/rails/extensions/spec/example/configuration.rb", >> "lib/spec/rails/extensions/spec/matchers/have.rb", >> "lib/spec/rails/extensions.rb", >> "lib/spec/rails/matchers/assert_select.rb", "li >> b/spec/rails/matchers/have_text.rb", >> "lib/spec/rails/matchers/include_text.rb", >> "lib/spec/rails/matchers/redirect_to.rb", >> "lib/spec/rails/matchers/render_template.rb", >> "lib/spec/rails/matchers.rb", "lib/spec/ra >> ils/mocks.rb", "lib/spec/rails/story_adapter.rb", >> "lib/spec/rails/version.rb", "lib/spec/rails.rb"] >> s.has_rdoc = true >> s.homepage = %q{http://rspec.rubyforge.org} >> s.rdoc_options = ["--title", "RSpec-Rails", "--line-numbers", >> "--inline-source", "--main", "README"] >> s.require_paths = ["lib"] >> s.rubygems_version = %q{1.1.0} >> s.summary = %q{RSpec-Rails-1.1.4 (build 20080526202855) - BDD for >> Ruby http://rspec.rubyforge.org/} >> end > > > I can grab this and add it or, if you want, you can gimme a git-patch. > Your call. > I think a rake task like rspec has would be the best solution. I will create a patch and enter it on lighthouse when I get some time. -Ben From dchelimsky at gmail.com Tue Jun 3 13:06:27 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 3 Jun 2008 12:06:27 -0500 Subject: [rspec-users] Build rspec-rails as a gem? In-Reply-To: <48457786.7060804@benmabey.com> References: <74ec5dc5c3dab6179fabbb3c33153012@ruby-forum.com> <810a540e0806022314g2665d476j38ab4873cf5d092c@mail.gmail.com> <484571EB.4080606@benmabey.com> <0C45494B-CFDA-43C4-B423-93E3376AC16C@gmail.com> <48457786.7060804@benmabey.com> Message-ID: On Jun 3, 2008, at 11:55 AM, Ben Mabey wrote: > David Chelimsky wrote: >> >> On Jun 3, 2008, at 11:31 AM, Ben Mabey wrote: >> >>> Pat Maddox wrote: >>>> On Mon, Jun 2, 2008 at 11:09 PM, Jose Fernandez >>> > wrote: >>>> >>>>> I can't figure out how to build rspec-rails as a gem when just >>>>> cloned >>>>> from github... there isn't any .gemspec file or rake task that >>>>> does >>>>> this. Any help? >>>>> >>>> >>>> rspec-rails is a rails plugin, not a gem. >>>> >>>> Pat >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >>> I have needed to use it as a gem before. Why? Well, with ticket >>> 383(http://rspec.lighthouseapp.com/projects/5645/tickets/383-extract-mock_model-out-of-railsexamplegroup >>> ) David extracted the mocking features for AR so that it could be >>> reused easily. I was writing a merb app that used AR and I >>> quickly began missing the mock_model and other mock helpers found >>> in rspec-rails. So, I created a gem out of the plugin, installed >>> it locally in my merb app I just required 'spec/rails/mocks'. >>> >>> >>> The gemspec file I created to do this was: >>> >>> Gem::Specification.new do |s| >>> s.name = %q{rspec-rails} >>> s.version = "1.1.4" >>> >>> s.specification_version = 2 if s.respond_to? :specification_version= >>> >>> s.required_rubygems_version = Gem::Requirement.new(">= 0") if >>> s.respond_to? :required_rubygems_version= >>> s.authors = ["RSpec Development Team"] >>> s.date = %q{2008-05-25} >>> s.default_executable = %q{spec} >>> s.description = %q{RSpec-Rails is an extension to RSpec to provide >>> a better environment for specing rails.} >>> s.email = %q{rspec-devel at rubyforge.org} >>> s.extra_rdoc_files = ["README", "CHANGES", "MIT-LICENSE"] >>> s.files = ["CHANGES", "MIT-LICENSE", "Rakefile", "README", "lib/ >>> autotest/discover.rb", "lib/autotest/rails_rspec.rb", "lib/spec/ >>> rails/example/assigns_hash_proxy.rb", "lib/spec/rails/example/ >>> controller_example >>> _group.rb", "lib/spec/rails/example/functional_example_group.rb", >>> "lib/spec/rails/example/helper_example_group.rb", "lib/spec/rails/ >>> example/model_example_group.rb", "lib/spec/rails/example/ >>> rails_example_group.r >>> b", "lib/spec/rails/example/render_observer.rb", "lib/spec/rails/ >>> example/view_example_group.rb", "lib/spec/rails/example.rb", "lib/ >>> spec/rails/extensions/action_controller/base.rb", "lib/spec/rails/ >>> extensions/ac >>> tion_controller/rescue.rb", "lib/spec/rails/extensions/ >>> action_controller/test_response.rb", "lib/spec/rails/extensions/ >>> action_view/base.rb", "lib/spec/rails/extensions/active_record/ >>> base.rb", "lib/spec/rails/ex >>> tensions/object.rb", "lib/spec/rails/extensions/spec/example/ >>> configuration.rb", "lib/spec/rails/extensions/spec/matchers/ >>> have.rb", "lib/spec/rails/extensions.rb", "lib/spec/rails/matchers/ >>> assert_select.rb", "li >>> b/spec/rails/matchers/have_text.rb", "lib/spec/rails/matchers/ >>> include_text.rb", "lib/spec/rails/matchers/redirect_to.rb", "lib/ >>> spec/rails/matchers/render_template.rb", "lib/spec/rails/ >>> matchers.rb", "lib/spec/ra >>> ils/mocks.rb", "lib/spec/rails/story_adapter.rb", "lib/spec/rails/ >>> version.rb", "lib/spec/rails.rb"] >>> s.has_rdoc = true >>> s.homepage = %q{http://rspec.rubyforge.org} >>> s.rdoc_options = ["--title", "RSpec-Rails", "--line-numbers", "-- >>> inline-source", "--main", "README"] >>> s.require_paths = ["lib"] >>> s.rubygems_version = %q{1.1.0} >>> s.summary = %q{RSpec-Rails-1.1.4 (build 20080526202855) - BDD for >>> Ruby http://rspec.rubyforge.org/} >>> end >> >> >> I can grab this and add it or, if you want, you can gimme a git- >> patch. Your call. >> > > I think a rake task like rspec has would be the best solution. I > will create a patch and enter it on lighthouse when I get some time. Great. Thanks. From rfwatson at gmail.com Tue Jun 3 16:12:53 2008 From: rfwatson at gmail.com (rfwatson) Date: Tue, 3 Jun 2008 21:12:53 +0100 Subject: [rspec-users] Autotest/RSpec 1.1.4/Rails 2.1 Infinite Loop? In-Reply-To: <20A9C048-B70F-40D2-84C6-4169A7F0D44F@mac.com> References: <20A9C048-B70F-40D2-84C6-4169A7F0D44F@mac.com> Message-ID: Had this a few times - seems to be something to do with the .autotest file in your home folder, replacing that has helped me before, but I can't be more specific. 2008/6/3 Andrew Selder : > I just got back from RailsConf, and upgraded on of my development apps to > 2.1, and now autotest is going into an infinite loop. It runs tests > continuously instead of waiting for files to be saved before rerunning. > > Has anybody else seen this, or know how to get around it? > > Thanks, > > Andrew > > _______________________________________________ > 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 nabble at mattmcneil.org Tue Jun 3 20:31:03 2008 From: nabble at mattmcneil.org (Matt McNeil) Date: Tue, 3 Jun 2008 17:31:03 -0700 (PDT) Subject: [rspec-users] controller filters running twice in 1.1.4? Message-ID: <17629653.post@talk.nabble.com> since upgrading to 1.1.4 (I had been running without issue on a git snapshot), I'm noticing that my filter actions initiated from application.rb seem to be running twice. I created a test rails project with the rspec scaffold and am also seeing the same behavior here too. Adding this code to application.rb: before_filter :foo def foo "foo" end and an example in users_controller_spec.rb: it "should call foo via a before filter" do controller.should_receive(:foo) do_get end results in this: 1) Spec::Mocks::MockExpectationError in 'UsersController handling GET /users.xml should call foo' Mock 'UsersController' expected :foo with (any args) once, but received it twice script/spec:4: Is any one else seeing this? Thanks, Matt -- View this message in context: http://www.nabble.com/controller-filters-running-twice-in-1.1.4--tp17629653p17629653.html Sent from the rspec-users mailing list archive at Nabble.com. From pergesu at gmail.com Tue Jun 3 22:07:46 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 3 Jun 2008 19:07:46 -0700 Subject: [rspec-users] controller filters running twice in 1.1.4? In-Reply-To: <17629653.post@talk.nabble.com> References: <17629653.post@talk.nabble.com> Message-ID: <810a540e0806031907q60c4fr9c0ac2d45f5cb088@mail.gmail.com> On Tue, Jun 3, 2008 at 5:31 PM, Matt McNeil wrote: > > since upgrading to 1.1.4 (I had been running without issue on a git > snapshot), I'm noticing that my filter actions initiated from application.rb > seem to be running twice. I created a test rails project with the rspec > scaffold and am also seeing the same behavior here too. > > Adding this code to application.rb: > > before_filter :foo > > def foo > "foo" > end > > and an example in users_controller_spec.rb: > > it "should call foo via a before filter" do > controller.should_receive(:foo) > do_get > end > > results in this: > > 1) > Spec::Mocks::MockExpectationError in 'UsersController handling GET > /users.xml should call foo' > Mock 'UsersController' expected :foo with (any args) once, but received it > twice > script/spec:4: > > Is any one else seeing this? Can you put a print statement inside application.rb to see if the file itself is being loaded multiple times? Pat From nabble at mattmcneil.org Tue Jun 3 22:27:48 2008 From: nabble at mattmcneil.org (Matt McNeil) Date: Tue, 3 Jun 2008 19:27:48 -0700 (PDT) Subject: [rspec-users] controller filters running twice in 1.1.4? In-Reply-To: <810a540e0806031907q60c4fr9c0ac2d45f5cb088@mail.gmail.com> References: <17629653.post@talk.nabble.com> <810a540e0806031907q60c4fr9c0ac2d45f5cb088@mail.gmail.com> Message-ID: <17637883.post@talk.nabble.com> Pat Maddox wrote: > > On Tue, Jun 3, 2008 at 5:31 PM, Matt McNeil wrote: >> >> since upgrading to 1.1.4 (I had been running without issue on a git >> snapshot), I'm noticing that my filter actions initiated from >> application.rb >> seem to be running twice. I created a test rails project with the rspec >> scaffold and am also seeing the same behavior here too. >> >> Adding this code to application.rb: >> >> before_filter :foo >> >> def foo >> "foo" >> end >> >> and an example in users_controller_spec.rb: >> >> it "should call foo via a before filter" do >> controller.should_receive(:foo) >> do_get >> end >> >> results in this: >> >> 1) >> Spec::Mocks::MockExpectationError in 'UsersController handling GET >> /users.xml should call foo' >> Mock 'UsersController' expected :foo with (any args) once, but received >> it >> twice >> script/spec:4: >> >> Is any one else seeing this? > > Can you put a print statement inside application.rb to see if the file > itself is being loaded multiple times? > > Pat > _______________________________________________ > > Hi Pat, Yes, application.rb appears to be getting loaded twice. Things are fine when the before_filter is being called from the UsersController: class UsersController < ApplicationController before_filter :foo puts "#{__FILE__} loaded " + Time.now.to_s /opt/local/bin/ruby -S script/spec -O spec/spec.opts spec/controllers/users_controller_spec.rb /Users/matt/test/app/controllers/users_controller.rb loaded Tue Jun 03 19:20:44 -0700 2008 ................................... Finished in 0.256665 seconds 35 examples, 0 failures however, when that filter macro is moved to application.rb: class ApplicationController < ActionController::Base helper :all # include all helpers, all the time before_filter :foo puts "#{__FILE__} loaded " + Time.now.to_s here's what happens: /opt/local/bin/ruby -S script/spec -O spec/spec.opts spec/controllers/users_routing_spec.rb spec/controllers/users_controller_spec.rb /Users/matt/test/app/controllers/application.rb loaded Tue Jun 03 19:23:32 -0700 2008 /Users/matt/test/app/controllers/application.rb loaded Tue Jun 03 19:23:32 -0700 2008 ..........................................F..... 1) Spec::Mocks::MockExpectationError in 'UsersController handling GET /users.xml should call foo via a before filter' Mock 'UsersController' expected :foo with (any args) once, but received it twice script/spec:4: Finished in 0.2891 seconds 48 examples, 1 failure -- View this message in context: http://www.nabble.com/controller-filters-running-twice-in-1.1.4--tp17629653p17637883.html Sent from the rspec-users mailing list archive at Nabble.com. From pergesu at gmail.com Tue Jun 3 23:29:31 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 3 Jun 2008 20:29:31 -0700 Subject: [rspec-users] controller filters running twice in 1.1.4? In-Reply-To: <17637883.post@talk.nabble.com> References: <17629653.post@talk.nabble.com> <810a540e0806031907q60c4fr9c0ac2d45f5cb088@mail.gmail.com> <17637883.post@talk.nabble.com> Message-ID: <810a540e0806032029q13addaaeq760787843144288f@mail.gmail.com> On Tue, Jun 3, 2008 at 7:27 PM, Matt McNeil wrote: > > > Pat Maddox wrote: >> >> On Tue, Jun 3, 2008 at 5:31 PM, Matt McNeil wrote: >>> >>> since upgrading to 1.1.4 (I had been running without issue on a git >>> snapshot), I'm noticing that my filter actions initiated from >>> application.rb >>> seem to be running twice. I created a test rails project with the rspec >>> scaffold and am also seeing the same behavior here too. >>> >>> Adding this code to application.rb: >>> >>> before_filter :foo >>> >>> def foo >>> "foo" >>> end >>> >>> and an example in users_controller_spec.rb: >>> >>> it "should call foo via a before filter" do >>> controller.should_receive(:foo) >>> do_get >>> end >>> >>> results in this: >>> >>> 1) >>> Spec::Mocks::MockExpectationError in 'UsersController handling GET >>> /users.xml should call foo' >>> Mock 'UsersController' expected :foo with (any args) once, but received >>> it >>> twice >>> script/spec:4: >>> >>> Is any one else seeing this? >> >> Can you put a print statement inside application.rb to see if the file >> itself is being loaded multiple times? >> >> Pat >> _______________________________________________ >> >> > Hi Pat, > > Yes, application.rb appears to be getting loaded twice. Things are fine > when the before_filter is being called from the UsersController: > > class UsersController < ApplicationController > > before_filter :foo > > puts "#{__FILE__} loaded " + Time.now.to_s > > > /opt/local/bin/ruby -S script/spec -O spec/spec.opts > spec/controllers/users_controller_spec.rb > /Users/matt/test/app/controllers/users_controller.rb loaded Tue Jun 03 > 19:20:44 -0700 2008 > ................................... > > Finished in 0.256665 seconds > > 35 examples, 0 failures > > however, when that filter macro is moved to application.rb: > > class ApplicationController < ActionController::Base > helper :all # include all helpers, all the time > > before_filter :foo > > puts "#{__FILE__} loaded " + Time.now.to_s > > here's what happens: > > /opt/local/bin/ruby -S script/spec -O spec/spec.opts > spec/controllers/users_routing_spec.rb > spec/controllers/users_controller_spec.rb > /Users/matt/test/app/controllers/application.rb loaded Tue Jun 03 19:23:32 > -0700 2008 > /Users/matt/test/app/controllers/application.rb loaded Tue Jun 03 19:23:32 > -0700 2008 > ..........................................F..... > > 1) > Spec::Mocks::MockExpectationError in 'UsersController handling GET > /users.xml should call foo via a before filter' > Mock 'UsersController' expected :foo with (any args) once, but received it > twice > script/spec:4: > > Finished in 0.2891 seconds > > 48 examples, 1 failure Do you require application.rb from anywhere, but including the whole path? i.e. require File.join(RAILS_ROOT, "app", "controllers", "application"). If you require the same file twice, but using two different paths, then it'll be loaded twice. This may happen from a plugin you've got loaded as well. Another thing to check is the paths in your generated specs. I changed those a couple weeks ago, but to avoid this type of problem. I may have screwed up, or perhaps you've got a mix of requires from older gen'd specs and newer ones. Pat From hans at degraaff.org Wed Jun 4 01:18:03 2008 From: hans at degraaff.org (Hans de Graaff) Date: Wed, 04 Jun 2008 07:18:03 +0200 Subject: [rspec-users] autotest only passing spec files to rspec once In-Reply-To: <9adb5a83daf8fec81cd55225200e5433@ruby-forum.com> References: <9adb5a83daf8fec81cd55225200e5433@ruby-forum.com> Message-ID: <1212556683.29530.2.camel@ip6-localhost> On Fri, 2008-04-11 at 17:16 +0200, Andy Orahood wrote: > When I run autotest it works fine the first time, generating the command > line: > > /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts > spec/models/timespan_spec.rb spec/models/article_spec.rb ... spec files> > > and all my specs get run. After the first runthrough, however, autotest > pauses for a second and then, without me saving any files, generates > another command line without any of the spec files: > > /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts This happens because a file got saved that did not match a pattern that autotest can handle. It may even be your test.log. Run 'autotest -v' to see what is really going on and add_exception in the autotest initialize hook to avoid checking those files. Arguably autotest shouldn't even do this empty run when it doesn't find any matching files. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From hans at degraaff.org Wed Jun 4 01:26:15 2008 From: hans at degraaff.org (Hans de Graaff) Date: Wed, 04 Jun 2008 07:26:15 +0200 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> Message-ID: <1212557175.29530.8.camel@ip6-localhost> On Tue, 2008-04-01 at 08:48 +0100, Ashley Moran wrote: > > Hmm, exact same revision as me. Are we the only one s having > problems? I've also noticed errors along the lines of > "ActionController not found" and "expected XXX to respond to > respond_to?" (or something - that from the developer that sits behind > me). We are seeing the exact same thing with Zentest 3.9.2 and RSpec 1.1.4. The thing I noticed yesterday is that autotest seems to want to run the model or controller directly instead of the spec file, just like in Ashley's original mail. Obviously this leads to an error because that doesn't load spec_helper which in turn doesn't load the rails framework. Presto: ActiveRecord has not been initialized. The real question is: why is autotest running specs with the wrong names? Did anyone resolve this yet? Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From nabble at mattmcneil.org Wed Jun 4 03:37:50 2008 From: nabble at mattmcneil.org (Matt McNeil) Date: Wed, 4 Jun 2008 00:37:50 -0700 (PDT) Subject: [rspec-users] controller filters running twice in 1.1.4? In-Reply-To: <810a540e0806031907q60c4fr9c0ac2d45f5cb088@mail.gmail.com> References: <17629653.post@talk.nabble.com> <810a540e0806031907q60c4fr9c0ac2d45f5cb088@mail.gmail.com> Message-ID: <17640917.post@talk.nabble.com> Pat Maddox wrote: > > On Tue, Jun 3, 2008 at 5:31 PM, Matt McNeil wrote: >> >> since upgrading to 1.1.4 (I had been running without issue on a git >> snapshot), I'm noticing that my filter actions initiated from >> application.rb >> seem to be running twice. I created a test rails project with the rspec >> scaffold and am also seeing the same behavior here too. >> >> Adding this code to application.rb: >> >> before_filter :foo >> >> def foo >> "foo" >> end >> >> and an example in users_controller_spec.rb: >> >> it "should call foo via a before filter" do >> controller.should_receive(:foo) >> do_get >> end >> >> results in this: >> >> 1) >> Spec::Mocks::MockExpectationError in 'UsersController handling GET >> /users.xml should call foo' >> Mock 'UsersController' expected :foo with (any args) once, but received >> it >> twice >> script/spec:4: >> >> Is any one else seeing this? > > Can you put a print statement inside application.rb to see if the file > itself is being loaded multiple times? > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Application.rb (and the method called by the before filter) only seem to be loaded twice when they're being run with autotest/spec. To reproduce what I'm showing here: $ rails -v Rails 2.1.0 rails test cd test script/plugin install git://github.com/dchelimsky/rspec.git script/plugin install git://github.com/dchelimsky/rspec-rails.git script/generate rspec rsg rspec_scaffold User name:string then add the before_filter :foo to application.rb, the foo method to users_controller.rb, and the example to users_controller_spec.rb. then: $ /opt/local/bin/ruby -S script/spec -O spec/spec.opts spec/controllers/users_controller_spec.rb ..................................F 1) Spec::Mocks::MockExpectationError in 'UsersController handling GET /users should call foo via a before filter' Mock 'UsersController' expected :foo with (any args) once, but received it twice script/spec:4: Finished in 0.252162 seconds 35 examples, 1 failure -- View this message in context: http://www.nabble.com/controller-filters-running-twice-in-1.1.4--tp17629653p17640917.html Sent from the rspec-users mailing list archive at Nabble.com. From self at mattmower.com Wed Jun 4 04:20:43 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 09:20:43 +0100 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: <1212557175.29530.8.camel@ip6-localhost> References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> <1212557175.29530.8.camel@ip6-localhost> Message-ID: On Wed, Jun 4, 2008 at 6:26 AM, Hans de Graaff wrote: > On Tue, 2008-04-01 at 08:48 +0100, Ashley Moran wrote: >> Hmm, exact same revision as me. Are we the only one s having >> problems? I've also noticed errors along the lines of >> "ActionController not found" and "expected XXX to respond to >> respond_to?" (or something - that from the developer that sits behind >> me). > > We are seeing the exact same thing with Zentest 3.9.2 and RSpec 1.1.4. Oh thank goodness, it's not me. I am seeing the same kinds of weirdness too, but only since I upgraded to Rails 2.1 I'm kinda new to RSpec so I wasn't sure if it was something i was doing. In the meantime I've been trying to figure out whether 1.1.4 is the right version of RSpec to run against 2.1. > The thing I noticed yesterday is that autotest seems to want to run the > model or controller directly instead of the spec file, just like in > Ashley's original mail. Obviously this leads to an error because that > doesn't load spec_helper which in turn doesn't load the rails framework. > Presto: ActiveRecord has not been initialized. > Ah, that makes sense. > The real question is: why is autotest running specs with the wrong > names? Did anyone resolve this yet? > One thing I've noticed is that it never seems to do it from a fresh run (either when you start autotest or hit Ctrl+C), only when it re-runs a changed spec. And not every time, only occasionally. I've started running autotest with the -v option to try and figure out what it's doing. Regards, Matt -- Matt Mower :: http://matt.blogs.it/ From self at mattmower.com Wed Jun 4 04:25:55 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 09:25:55 +0100 Subject: [rspec-users] controller filters running twice in 1.1.4? In-Reply-To: <810a540e0806032029q13addaaeq760787843144288f@mail.gmail.com> References: <17629653.post@talk.nabble.com> <810a540e0806031907q60c4fr9c0ac2d45f5cb088@mail.gmail.com> <17637883.post@talk.nabble.com> <810a540e0806032029q13addaaeq760787843144288f@mail.gmail.com> Message-ID: On Wed, Jun 4, 2008 at 4:29 AM, Pat Maddox wrote: > On Tue, Jun 3, 2008 at 7:27 PM, Matt McNeil wrote: >> Yes, application.rb appears to be getting loaded twice. Things are fine >> when the before_filter is being called from the UsersController: >> >> class UsersController < ApplicationController >> > Do you require application.rb from anywhere, but including the whole > path? i.e. require File.join(RAILS_ROOT, "app", "controllers", > "application"). If you require the same file twice, but using two > different paths, then it'll be loaded twice. > > This may happen from a plugin you've got loaded as well. > I've been seeing the same problem. In my case the symptom was a warning about redefining a constant I have in ApplicationController. I checked across my application and the only places I see application being required (outside vendor/rails) are script/spec_server (and it's template) and rspec-rails/lib/spec/rails.rb. > Another thing to check is the paths in your generated specs. I > changed those a couple weeks ago, but to avoid this type of problem. > I may have screwed up, or perhaps you've got a mix of requires from > older gen'd specs and newer ones. > I'm not sure what "paths in your generated specs" means to check this myself. Regards, Matt -- Matt Mower :: http://matt.blogs.it/ From dchelimsky at gmail.com Wed Jun 4 04:26:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jun 2008 03:26:05 -0500 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> <1212557175.29530.8.camel@ip6-localhost> Message-ID: On Jun 4, 2008, at 3:20 AM, Matt Mower wrote: > On Wed, Jun 4, 2008 at 6:26 AM, Hans de Graaff > wrote: >> On Tue, 2008-04-01 at 08:48 +0100, Ashley Moran wrote: >>> Hmm, exact same revision as me. Are we the only one s having >>> problems? I've also noticed errors along the lines of >>> "ActionController not found" and "expected XXX to respond to >>> respond_to?" (or something - that from the developer that sits >>> behind >>> me). >> >> We are seeing the exact same thing with Zentest 3.9.2 and RSpec >> 1.1.4. > > Oh thank goodness, it's not me. I am seeing the same kinds of > weirdness too, but only since I upgraded to Rails 2.1 > > I'm kinda new to RSpec so I wasn't sure if it was something i was > doing. In the meantime I've been trying to figure out whether 1.1.4 is > the right version of RSpec to run against 2.1. > >> The thing I noticed yesterday is that autotest seems to want to run >> the >> model or controller directly instead of the spec file, just like in >> Ashley's original mail. Obviously this leads to an error because that >> doesn't load spec_helper which in turn doesn't load the rails >> framework. >> Presto: ActiveRecord has not been initialized. >> > > Ah, that makes sense. > >> The real question is: why is autotest running specs with the wrong >> names? Did anyone resolve this yet? >> > > One thing I've noticed is that it never seems to do it from a fresh > run (either when you start autotest or hit Ctrl+C), only when it > re-runs a changed spec. And not every time, only occasionally. > > I've started running autotest with the -v option to try and figure out > what it's doing. I've got it figured out. Fix coming shortly (like in 10 minutes) > > > Regards, > > Matt > > -- > Matt Mower :: http://matt.blogs.it/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Jun 4 04:37:26 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jun 2008 03:37:26 -0500 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> <1212557175.29530.8.camel@ip6-localhost> Message-ID: On Jun 4, 2008, at 3:26 AM, David Chelimsky wrote: > > On Jun 4, 2008, at 3:20 AM, Matt Mower wrote: > >> On Wed, Jun 4, 2008 at 6:26 AM, Hans de Graaff >> wrote: >>> On Tue, 2008-04-01 at 08:48 +0100, Ashley Moran wrote: >>>> Hmm, exact same revision as me. Are we the only one s having >>>> problems? I've also noticed errors along the lines of >>>> "ActionController not found" and "expected XXX to respond to >>>> respond_to?" (or something - that from the developer that sits >>>> behind >>>> me). >>> >>> We are seeing the exact same thing with Zentest 3.9.2 and RSpec >>> 1.1.4. >> >> Oh thank goodness, it's not me. I am seeing the same kinds of >> weirdness too, but only since I upgraded to Rails 2.1 >> >> I'm kinda new to RSpec so I wasn't sure if it was something i was >> doing. In the meantime I've been trying to figure out whether 1.1.4 >> is >> the right version of RSpec to run against 2.1. >> >>> The thing I noticed yesterday is that autotest seems to want to >>> run the >>> model or controller directly instead of the spec file, just like in >>> Ashley's original mail. Obviously this leads to an error because >>> that >>> doesn't load spec_helper which in turn doesn't load the rails >>> framework. >>> Presto: ActiveRecord has not been initialized. >>> >> >> Ah, that makes sense. >> >>> The real question is: why is autotest running specs with the wrong >>> names? Did anyone resolve this yet? >>> >> >> One thing I've noticed is that it never seems to do it from a fresh >> run (either when you start autotest or hit Ctrl+C), only when it >> re-runs a changed spec. And not every time, only occasionally. >> >> I've started running autotest with the -v option to try and figure >> out >> what it's doing. > > I've got it figured out. Fix coming shortly (like in 10 minutes) I believe this is now fixed in http://github.com/dchelimsky/rspec/commit/2b474ac . If any of you can still reproduce this, please let me know. Cheers, David From self at mattmower.com Wed Jun 4 04:47:52 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 09:47:52 +0100 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> <1212557175.29530.8.camel@ip6-localhost> Message-ID: On Wed, Jun 4, 2008 at 9:37 AM, David Chelimsky wrote: >> I've got it figured out. Fix coming shortly (like in 10 minutes) > > > I believe this is now fixed in > http://github.com/dchelimsky/rspec/commit/2b474ac. > > If any of you can still reproduce this, please let me know. > That's quick work David, thanks ;-) I'm still not entirely sure which version of rspec I should be running for Rails 2.1. Is edge a reasonable safe choice? Should I stick with 1.1.4 and wait for 1.1.5. I'm not sure how to make this judgement. Regards, Matt -- Matt Mower :: http://matt.blogs.it/ From dchelimsky at gmail.com Wed Jun 4 04:58:42 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jun 2008 03:58:42 -0500 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> <1212557175.29530.8.camel@ip6-localhost> Message-ID: On Jun 4, 2008, at 3:47 AM, Matt Mower wrote: > On Wed, Jun 4, 2008 at 9:37 AM, David Chelimsky > wrote: >>> I've got it figured out. Fix coming shortly (like in 10 minutes) >> >> >> I believe this is now fixed in >> http://github.com/dchelimsky/rspec/commit/2b474ac. >> >> If any of you can still reproduce this, please let me know. >> > > That's quick work David, thanks ;-) > > I'm still not entirely sure which version of rspec I should be running > for Rails 2.1. Is edge a reasonable safe choice? Should I stick with > 1.1.4 and wait for 1.1.5. I'm not sure how to make this judgement. There is some broken story stuff in edge right now that will get fixed in the next day or so. If you're not using plain text stories, just grab that. You could always grab the repo, make a 1.1.4 branch and cherry pick this commit. git clone git://github.com/dchelimsky/rspec.git git checkout -b 1.1.4 git cherry-pick 2b474ac78ad877c13d577490b16f4f3380944e83 Sadly there is a conflict in the CHANGES file, but it's easily fixed. After you resolve the conflict .... git add . git commit -c 2b474ac Cheers, David From self at mattmower.com Wed Jun 4 05:19:13 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 10:19:13 +0100 Subject: [rspec-users] any_instance Message-ID: Hi folks. I'm very interested in the status of a port of any_instance from Mocha to RSpec. In particular I have a spec suite that I wrote using RSpec but with Mocha that depends heavily on any_instance. This is because it stubs out one or two methods from an underlying API. In attempting to convert the suite to RSpec mocks (because that's what we're using for the rest of the project) I had to give up. Attempting to replace objects by stubbing :new and returning mocks felt like a huge amount of busy work compared to one-line with any_instance. I noticed that Brian Takita appears to have an implementation of any_instance here: http://github.com/btakita/pain-point/tree/ca9a65e7110ccaa37175c741e1cea1aaa9776180/vendor/plugins/rspec/lib/spec/mocks which I tried, without success, to make work in my own version of rspec (1.1.4). I was able to call any_instance but it didn't seem to be having an effect. I emailed Brian but I think he was at rails conf so I guess he may be fighting a backlog of work/email. Is there any likelyhood of any_instance making it into RSpec proper? If not, has anyone else had any luck implementing it? Regards, Matt. -- Matt Mower :: http://matt.blogs.it/ From raasdnil at gmail.com Wed Jun 4 07:10:38 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 4 Jun 2008 21:10:38 +1000 Subject: [rspec-users] Why has the --color gone from my life? Message-ID: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> Hi all, Running on OSX 10.5.3, Latest Rspec trunk, Rspec rails trunk, latest autotest gem and rails 2.1 I've lost my colour output in autotest. rake spec gives colour output, but autotest gives me black and white. It was working a little bit before, I think I upgraded to the latest versions of everything to get all the textmate snippets talking and being friendly to one another again after I upgraded Ruby from the shipped 111 patch level to 114. Not mission critical, but annoying :) I mean... without it, you can only aim for "All specs grey!" which doesn't quite sound as good. Anyone have any pointers? Mikel -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhennemeyer at googlemail.com Wed Jun 4 08:04:10 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Wed, 4 Jun 2008 14:04:10 +0200 Subject: [rspec-users] != again In-Reply-To: <810a540e0806021101o7f0e2363jdb345f03063352f1@mail.gmail.com> References: <34D041B6-6D30-4142-AFE9-62687D456E31@googlemail.com> <810a540e0806021101o7f0e2363jdb345f03063352f1@mail.gmail.com> Message-ID: <1B38F4F1-266E-4F23-95B6-99A54B29530C@googlemail.com> Am 02.06.2008 um 20:01 schrieb Pat Maddox: >> > > What about showing an ugly warning in the test runner? != is a funky > edge case that can really bite people. It'd be nice to have it fixed, > but then tell the programmer to change it to == because of > performance. > > Pat > ______________________________________________ The performance is much better now - but that warning thing is interesting. I think people should be able to decide if they use != or not and there should be an option that, when applied, turns out warnings and enables 'negative operator expectations'. One more word on performance: It is possible to see the difference in performance of both versions (with source inspect and without). But only if you run benchmarks that are exclusivley designed for this purpose. Running the rspec spec suite for both versions doesn't show any difference. Matthias -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattlins at gmail.com Wed Jun 4 09:06:56 2008 From: mattlins at gmail.com (Matthew Lins) Date: Wed, 04 Jun 2008 08:06:56 -0500 Subject: [rspec-users] Mock with an attributes that has state Message-ID: I'm developing a rails application. I have an Order model that has_many OrderItems. I mocked the OrderItem model in my Order specs using mock_model. I thought I should focus my specs on each model and always mock associated models. In my Order model I need a way to merge OrderItems which have the same cost and same product_id. That I can spec. The other thing this merge helper function should do is increment the quantity of the merged OrderItems. Below @order_item1 and @order_item4 would be merged into one item with a quantity of 2. Here are my OrderItems mocks: @order_item1 = mock_model(OrderItem, :valid? => true, :product_id => 1, :cost => 1, :null_object => true) @order_item2 = mock_model(OrderItem, :valid? => true, :product_id => 1, :cost => 2, :null_object => true) @order_item3 = mock_model(OrderItem, :valid? => true, :product_id => 2, :cost => 1, :null_object => true) @order_item4 = mock_model(OrderItem, :valid? => true, :product_id => 1, :cost => 1, :null_object => true) Here is the spec I wrote to check for the quantity: it "should increment the quanity of the merged items" do lambda { @order.valid? }.should change(@order_item1, :quantity).from(1).to(2) end How do I create an attribute for 'quantity' that has state on my OrderItem mocks? I realize I could do this differently and just do a should_receive on the OrderItem, looking for '+=' or something, but that doesn't feel right. I don't care how it's incremented, I just want to make sure it's changed. Thanks, Matt From self at mattmower.com Wed Jun 4 09:15:21 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 14:15:21 +0100 Subject: [rspec-users] Not running correct specs under autotest: Message-ID: I know this isn't autotest-users but I'm not sure where else to bring this up: [["app/controllers/contents_controller.rb", Wed Jun 04 14:11:03 +0100 2008]] [["app/controllers/contents_controller.rb", Wed Jun 04 14:11:03 +0100 2008]] /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S script/spec -O spec/spec.opts spec/models/user_spec.rb I had saved 'contents_controller.rb' but it did not decide to re-run the 'contents_controller_spec.rb' only 'user_spec.rb' (which has a failing spec so is probably held over from the previous runs). If I ctrl+c to run all specs it runs the controller spec again. If I resave the controller the change is again detected but the spec is not run. I'm using Rails 2.1, edge rspec & rspec-rails, and ZenTest 3.9.2 Anyone else seen this? Matt. -- Matt Mower :: http://matt.blogs.it/ From dchelimsky at gmail.com Wed Jun 4 09:18:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jun 2008 08:18:03 -0500 Subject: [rspec-users] Not running correct specs under autotest: In-Reply-To: References: Message-ID: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> On Jun 4, 2008, at 8:15 AM, Matt Mower wrote: > I know this isn't autotest-users but I'm not sure where else to > bring this up: > > [["app/controllers/contents_controller.rb", Wed Jun 04 14:11:03 > +0100 2008]] > [["app/controllers/contents_controller.rb", Wed Jun 04 14:11:03 > +0100 2008]] > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S > script/spec -O spec/spec.opts spec/models/user_spec.rb > > I had saved 'contents_controller.rb' but it did not decide to re-run > the 'contents_controller_spec.rb' only 'user_spec.rb' (which has a > failing spec so is probably held over from the previous runs). If I > ctrl+c to run all specs it runs the controller spec again. If I resave > the controller the change is again detected but the spec is not run. > > I'm using Rails 2.1, edge rspec & rspec-rails, and ZenTest 3.9.2 > > Anyone else seen this? This just got fixed a few hours ago. Grab the latest from git:// github.com/dchelimsky/rspec.git. Cheers, David From dchelimsky at gmail.com Wed Jun 4 09:24:00 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jun 2008 08:24:00 -0500 Subject: [rspec-users] any_instance In-Reply-To: References: Message-ID: <94D46FFB-24CD-45E1-A4B4-04FE966F0440@gmail.com> On Jun 4, 2008, at 4:19 AM, Matt Mower wrote: > Hi folks. > > I'm very interested in the status of a port of any_instance from > Mocha to RSpec. > > In particular I have a spec suite that I wrote using RSpec but with > Mocha that depends heavily on any_instance. This is because it stubs > out one or two methods from an underlying API. In attempting to > convert the suite to RSpec mocks (because that's what we're using for > the rest of the project) I had to give up. Attempting to replace > objects by stubbing :new and returning mocks felt like a huge amount > of busy work compared to one-line with any_instance. > > I noticed that Brian Takita appears to have an implementation of > any_instance here: > > http://github.com/btakita/pain-point/tree/ca9a65e7110ccaa37175c741e1cea1aaa9776180/vendor/plugins/rspec/lib/spec/mocks > > which I tried, without success, to make work in my own version of > rspec (1.1.4). I was able to call any_instance but it didn't seem to > be having an effect. I emailed Brian but I think he was at rails conf > so I guess he may be fighting a backlog of work/email. > > Is there any likelyhood of any_instance making it into RSpec proper? > If not, has anyone else had any luck implementing it? There was an implementation of it that didn't quite work for me in http://github.com/dchelimsky/rspec/commit/45a6837 so we reverted it. I have zero personal interest in this feature (use of which I find to be an anti-pattern) but am open to applying a patch as long as it meets criteria described in http://rspec.lighthouseapp.com/projects/5645/tickets/28 . Until such a patch comes my way, you can re-apply the existing patch (probably have to use git-format patch and tweak some things - any git- pros got advice on the best way to do that?) and it should work for most cases for you. Cheers, David From self at mattmower.com Wed Jun 4 09:33:29 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 14:33:29 +0100 Subject: [rspec-users] Not running correct specs under autotest: In-Reply-To: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> References: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> Message-ID: On Wed, Jun 4, 2008 at 2:18 PM, David Chelimsky wrote: > This just got fixed a few hours ago. Grab the latest from > git://github.com/dchelimsky/rspec.git. > Edge moves fast, I only installed it 3.5hrs ago ;-) Keeping up is awkward because my project is currently still using Subversion and I've not found a good way of managing Git externals in this setup. Another argument for switching the project to Git I guess... Thanks David. M. -- Matt Mower :: http://matt.blogs.it/ From self at mattmower.com Wed Jun 4 09:40:21 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 14:40:21 +0100 Subject: [rspec-users] any_instance In-Reply-To: <94D46FFB-24CD-45E1-A4B4-04FE966F0440@gmail.com> References: <94D46FFB-24CD-45E1-A4B4-04FE966F0440@gmail.com> Message-ID: Hi David. On Wed, Jun 4, 2008 at 2:24 PM, David Chelimsky wrote: > There was an implementation of it that didn't quite work for me in > http://github.com/dchelimsky/rspec/commit/45a6837 so we reverted it. I have > zero personal interest in this feature (use of which I find to be an > anti-pattern) but am open to applying a patch as long as it meets criteria > described in http://rspec.lighthouseapp.com/projects/5645/tickets/28. > I've read the ticket, I was hoping it would explain why you feel any_instance is an anti-pattern. In my situation I am spec'ing a library that depends upon a lower-level for network operations. I use any_instance at certain points to simulate data coming from the network. Trying to stub :new and return a mock was very problematic for me because the object involved does some work with the data which my code depends upon for it's own behaviour. Hence to test that I end up having to do a lot of work in my mocks and it quickly becomes cumbersome. What I really wanted was the "genuine" object with some behaviour changed which is what any_instance gives me. I tried searching the archives of this list but couldn't find an article where you (or anyone else) expands on this view about any_instance. And thanks for the pointer, I guess I will try and assemble the patch and see if I can make it work. Regards, Matt. -- Matt Mower :: http://matt.blogs.it/ From self at mattmower.com Wed Jun 4 09:42:24 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 14:42:24 +0100 Subject: [rspec-users] Not running correct specs under autotest: In-Reply-To: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> References: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> Message-ID: On Wed, Jun 4, 2008 at 2:18 PM, David Chelimsky wrote: > This just got fixed a few hours ago. Grab the latest from > git://github.com/dchelimsky/rspec.git. > It's not fixed for me. My copy of rspec was installed after the commit that closes #369. regards, Matt. -- Matt Mower :: http://matt.blogs.it/ From self at mattmower.com Wed Jun 4 09:44:08 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 14:44:08 +0100 Subject: [rspec-users] Not running correct specs under autotest: In-Reply-To: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> References: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> Message-ID: On Wed, Jun 4, 2008 at 2:18 PM, David Chelimsky wrote: > > On Jun 4, 2008, at 8:15 AM, Matt Mower wrote: > >> I know this isn't autotest-users but I'm not sure where else to bring this >> up: >> >> [["app/controllers/contents_controller.rb", Wed Jun 04 14:11:03 +0100 >> 2008]] >> [["app/controllers/contents_controller.rb", Wed Jun 04 14:11:03 +0100 >> 2008]] >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S >> script/spec -O spec/spec.opts spec/models/user_spec.rb >> >> I had saved 'contents_controller.rb' but it did not decide to re-run >> the 'contents_controller_spec.rb' only 'user_spec.rb' (which has a >> failing spec so is probably held over from the previous runs). If I >> ctrl+c to run all specs it runs the controller spec again. If I resave >> the controller the change is again detected but the spec is not run. >> >> I'm using Rails 2.1, edge rspec & rspec-rails, and ZenTest 3.9.2 >> >> Anyone else seen this? > > This just got fixed a few hours ago. Grab the latest from > git://github.com/dchelimsky/rspec.git. > Your last fix does seem to have fixed the problem of getting ActiveRecord::Base not found, etc... which was due to autotest running the controller or model as a spec. This problem is different, it's reporting that the controller has changed *but not running the associated spec*. Hope that helps. Matt. -- Matt Mower :: http://matt.blogs.it/ From dchelimsky at gmail.com Wed Jun 4 10:06:25 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jun 2008 09:06:25 -0500 Subject: [rspec-users] Not running correct specs under autotest: In-Reply-To: References: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> Message-ID: <80418110-A836-4D09-90C3-C04BA3609DC4@gmail.com> On Jun 4, 2008, at 8:33 AM, Matt Mower wrote: > On Wed, Jun 4, 2008 at 2:18 PM, David Chelimsky > wrote: >> This just got fixed a few hours ago. Grab the latest from >> git://github.com/dchelimsky/rspec.git. >> > > Edge moves fast, I only installed it 3.5hrs ago ;-) I wish it moved faster - this one's been sitting around for a bit. > Keeping up is awkward because my project is currently still using > Subversion and I've not found a good way of managing Git externals in > this setup. Rails 2.1 supports plugins from git. Are you using an older version of rails (come on - 2.1 has been out for 3 days already!). If you are, just follow directions at http://github.com/dchelimsky/rspec-rails/ wikis. Cheers, David From self at mattmower.com Wed Jun 4 10:14:14 2008 From: self at mattmower.com (Matt Mower) Date: Wed, 4 Jun 2008 15:14:14 +0100 Subject: [rspec-users] Not running correct specs under autotest: In-Reply-To: <80418110-A836-4D09-90C3-C04BA3609DC4@gmail.com> References: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> <80418110-A836-4D09-90C3-C04BA3609DC4@gmail.com> Message-ID: On Wed, Jun 4, 2008 at 3:06 PM, David Chelimsky wrote: > I wish it moved faster - this one's been sitting around for a bit. > ;-) > Rails 2.1 supports plugins from git. Are you using an older version of rails > (come on - 2.1 has been out for 3 days already!). If you are, just follow > directions at http://github.com/dchelimsky/rspec-rails/wikis. > Yep 2.1 and I used script/plugin to install from git this time. That's new again to me since I've been using piston for quite a while (or submodules with a git based project). The new, git compatible, "script/plugin update" takes care of the details? M. -- Matt Mower :: http://matt.blogs.it/ From dchelimsky at gmail.com Wed Jun 4 10:16:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jun 2008 09:16:07 -0500 Subject: [rspec-users] Not running correct specs under autotest: In-Reply-To: References: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> <80418110-A836-4D09-90C3-C04BA3609DC4@gmail.com> Message-ID: <1C868A85-3C39-4A9A-B729-5676FBACFF57@gmail.com> On Jun 4, 2008, at 9:14 AM, Matt Mower wrote: > On Wed, Jun 4, 2008 at 3:06 PM, David Chelimsky > wrote: >> I wish it moved faster - this one's been sitting around for a bit. >> > > ;-) > >> Rails 2.1 supports plugins from git. Are you using an older version >> of rails >> (come on - 2.1 has been out for 3 days already!). If you are, just >> follow >> directions at http://github.com/dchelimsky/rspec-rails/wikis. >> > > Yep 2.1 and I used script/plugin to install from git this time. That's > new again to me since I've been using piston for quite a while (or > submodules with a git based project). The new, git compatible, > "script/plugin update" takes care of the details? I haven't tried update (I usually run a bash script to update from my local repo - I pretty much always have the latest). From duelin.markers at gmail.com Wed Jun 4 10:50:45 2008 From: duelin.markers at gmail.com (John D. Hume) Date: Wed, 4 Jun 2008 10:50:45 -0400 Subject: [rspec-users] Mock with an attributes that has state In-Reply-To: References: Message-ID: On Wed, Jun 4, 2008 at 9:06 AM, Matthew Lins wrote: > I realize I could do this differently and just do a should_receive on the > OrderItem, looking for '+=' or something, but that doesn't feel right. I know this isn't what you're looking for, but note that whether you do: item.quantity = item.quantity + other_item.quantity or item.quantity += other_item.quantity the sequence of calls to item will be the same: first item.quantity, then item.quantity=, with + being sent to the return value of item.quantity in between. To try and help with what you're actually trying to do, I think you could define a singleton method on your mocked model. class << @order_item1 attr_accessor :quantity end but that's smelly. It feels to me like the logic for rolling one item into another belongs in OrderItem. So maybe instead your order spec turns out to be something like: @order_item1.should_receive(:merge).with(@order_item4) If the logic for determining whether to merge also moved into OrderItem, Order (and its spec) could forget about all the attributes of OrderItem. -hume. From mattlins at gmail.com Wed Jun 4 13:30:48 2008 From: mattlins at gmail.com (Matthew Lins) Date: Wed, 04 Jun 2008 12:30:48 -0500 Subject: [rspec-users] Mock with an attributes that has state In-Reply-To: Message-ID: Thanks John. Yes, I think I'm violating TDA with that merge helper sitting in order. But, it can't really sit in OrderItem. I think it'll have to sit on the association proxy. And, I'm assuming that would be tested by an integration test? I think your singleton class on the mock would work too, but you're right it is messy. I was wondering if there was something built in. Time to redesign! > From: "John D. Hume" > Reply-To: rspec-users > Date: Wed, 4 Jun 2008 10:50:45 -0400 > To: rspec-users > Subject: Re: [rspec-users] Mock with an attributes that has state > > On Wed, Jun 4, 2008 at 9:06 AM, Matthew Lins wrote: >> I realize I could do this differently and just do a should_receive on the >> OrderItem, looking for '+=' or something, but that doesn't feel right. > > I know this isn't what you're looking for, but note that whether you do: > item.quantity = item.quantity + other_item.quantity > or > item.quantity += other_item.quantity > the sequence of calls to item will be the same: first item.quantity, > then item.quantity=, with + being sent to the return value of > item.quantity in between. > > To try and help with what you're actually trying to do, I think you > could define a singleton method on your mocked model. > class << @order_item1 > attr_accessor :quantity > end > but that's smelly. > > It feels to me like the logic for rolling one item into another > belongs in OrderItem. So maybe instead your order spec turns out to be > something like: > @order_item1.should_receive(:merge).with(@order_item4) > If the logic for determining whether to merge also moved into > OrderItem, Order (and its spec) could forget about all the attributes > of OrderItem. > > -hume. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Wed Jun 4 22:05:30 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 4 Jun 2008 22:05:30 -0400 Subject: [rspec-users] any_instance In-Reply-To: References: <94D46FFB-24CD-45E1-A4B4-04FE966F0440@gmail.com> Message-ID: <2A25DACC-0E70-45F5-AB2E-7A3423A1ED19@railsnewbie.com> On Jun 4, 2008, at 9:40 AM, Matt Mower wrote: > Hi David. > > On Wed, Jun 4, 2008 at 2:24 PM, David Chelimsky > wrote: >> There was an implementation of it that didn't quite work for me in >> http://github.com/dchelimsky/rspec/commit/45a6837 so we reverted >> it. I have >> zero personal interest in this feature (use of which I find to be an >> anti-pattern) but am open to applying a patch as long as it meets >> criteria >> described in http://rspec.lighthouseapp.com/projects/5645/tickets/28. >> > > I've read the ticket, I was hoping it would explain why you feel > any_instance is an anti-pattern. > > In my situation I am spec'ing a library that depends upon a > lower-level for network operations. I use any_instance at certain > points to simulate data coming from the network. > > Trying to stub :new and return a mock was very problematic for me > because the object involved does some work with the data which my code > depends upon for it's own behaviour. Hence to test that I end up > having to do a lot of work in my mocks and it quickly becomes > cumbersome. > > What I really wanted was the "genuine" object with some behaviour > changed which is what any_instance gives me. Why can't you give public access to the object? You'd then be able to stub it, just as with stub_all_instances. There's a general idea with rspec (and one which probably isn't present in other testing frameworks) that says that testing *should* influence your design. I'm sure this is one of the reasons that David considers it an "anti-pattern" - as it does not influence your design in any way. In fact, I developed the the stub_any_instance patch because I needed to test legacy code (legacy because it wasn't designed well), and it was the only way to get to the object. I'm sure David would have specific examples, and I'd be curious to see them. Scott From raasdnil at gmail.com Thu Jun 5 01:33:20 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 5 Jun 2008 15:33:20 +1000 Subject: [rspec-users] xhr :post giving wrong number of arguments on rails 2.1? Message-ID: <57a815bf0806042233o6ad96265y1044ef4dd5ef9231@mail.gmail.com> Getting a strange error. In a story I have the following step: When "I submit a search name" do xhr :post, '/searches', {:search => {:given_name => "bob", :family_name => "smith"}} end I am getting: ArgumentError: wrong number of arguments (4 for 3) stories/searching_story_spec.rb:45 in "I submit a search name" But I only have 3 arguments in the above list, a symbol, a string and a hash. No exception comes up in the test.log I am on Rspec trunk from a couple of days ago and Rails 2.1. Any ideas? Mikel -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom at experthuman.com Thu Jun 5 04:11:44 2008 From: tom at experthuman.com (Tom Stuart) Date: Thu, 5 Jun 2008 09:11:44 +0100 Subject: [rspec-users] Not running correct specs under autotest: In-Reply-To: References: <48D0EF55-19E2-45C1-A09B-3CFF11F445FA@gmail.com> <80418110-A836-4D09-90C3-C04BA3609DC4@gmail.com> Message-ID: On 4 Jun 2008, at 15:14, Matt Mower wrote: > On Wed, Jun 4, 2008 at 3:06 PM, David Chelimsky > wrote: >> Rails 2.1 supports plugins from git. > Yep 2.1 and I used script/plugin to install from git this time. That's > new again to me since I've been using piston for quite a while (or > submodules with a git based project). The new, git compatible, > "script/plugin update" takes care of the details? AFAIK it doesn't -- script/plugin install from a git URL is no better than manually unpacking the tgz into vendor/plugins, i.e. completely useless. I've pretty much resigned myself to just blowing away each plugin directory when I want to update it, and either tracking my local changes manually (i.e. maintaining a diff that I laboriously reapply after updating) or monkeypatching plugins in lib/ rather than modifying them directly. (script/plugin update relies on svn:externals.) Rails dependency management is getting worse. Maybe piston 2.0, with git support, will make it better again? Cheers, -Tom From lists at ruby-forum.com Thu Jun 5 05:46:54 2008 From: lists at ruby-forum.com (Doug Livesey) Date: Thu, 5 Jun 2008 11:46:54 +0200 Subject: [rspec-users] Using and_yield to pass multiple or no iterations Message-ID: <7770b6ffbbd271a246d87c13678b9303@ruby-forum.com> Hi, imagine there's a class called Egg which has the following method (which calls another method): def do_thing has_iterated = false self.each_row do |row| has_iterated = true unless has_iterated end has_iterated end Stupid code, I know. I have two questions with it. The first is, would it be possible to set it up to test the case when each_row operates on an empty Array? Sort of like this: it "should return false if it does not iterate over anything" do @egg.stub!( each_row ).and_yield( nil ) # I know this doesn't work @egg.do_thing.should be_false end it "should return true if it does iterate over something" do @egg.stub!( each_row ).and_yield( :value ) @egg.do_thing.should be_true end Secondly, is this the best (correct) way to pass multiple values to iterate over? it "should be doing something else, too" @egg.stub!( :each_row ). and_yield( :first_value ). and_yield( :second_value ). and_yield( :third_value ) @egg.do_thing.should be_true end As you can see, my understanding of and_yield() is *very* imperfect, so any & all pointers are very gratefully received. Cheers, Doug. -- Posted via http://www.ruby-forum.com/. From self at mattmower.com Thu Jun 5 06:07:55 2008 From: self at mattmower.com (Matt Mower) Date: Thu, 5 Jun 2008 11:07:55 +0100 Subject: [rspec-users] any_instance In-Reply-To: <2A25DACC-0E70-45F5-AB2E-7A3423A1ED19@railsnewbie.com> References: <94D46FFB-24CD-45E1-A4B4-04FE966F0440@gmail.com> <2A25DACC-0E70-45F5-AB2E-7A3423A1ED19@railsnewbie.com> Message-ID: HI Scott. On Thu, Jun 5, 2008 at 3:05 AM, Scott Taylor wrote: > There's a general idea with rspec (and one which probably isn't present in > other testing frameworks) that says that testing *should* influence your > design. I'm sure this is one of the reasons that David considers it an > "anti-pattern" - as it does not influence your design in any way. In fact, > I developed the the stub_any_instance patch because I needed to test legacy > code (legacy because it wasn't designed well), and it was the only way to > get to the object. I guess that's how I see this. My code, that I am writing specs for, depends upon a lower-level library that does not expose the details of it's implementation to it's clients. The use of any_instance allows me to test my code simply. Without it I seem to be forced to build complex arrangements of mocks to, essentially, emulate the behaviour of the underlying library. This feels like busy work. Whilst it would be possible to re-write the underlying library I do not feel that's a worthwhile investment of my time right now. Especially not when I have a spec suite that already works but for the lack of any_instance. I'm all for encouraging good practice and wrapping any_instance in the shame of your peers. But I'm also all for being pragmatic. Does your patch work? I wasn't clear whether David was saying that it doesn't. Regards, Matt. -- Matt Mower :: http://matt.blogs.it/ From dchelimsky at gmail.com Thu Jun 5 07:21:39 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 5 Jun 2008 06:21:39 -0500 Subject: [rspec-users] any_instance In-Reply-To: <2A25DACC-0E70-45F5-AB2E-7A3423A1ED19@railsnewbie.com> References: <94D46FFB-24CD-45E1-A4B4-04FE966F0440@gmail.com> <2A25DACC-0E70-45F5-AB2E-7A3423A1ED19@railsnewbie.com> Message-ID: On Jun 4, 2008, at 9:05 PM, Scott Taylor wrote: > There's a general idea with rspec (and one which probably isn't > present in other testing frameworks) that says that testing *should* > influence your design. This isn't really a framework issue - it's about TDD. Remember that BDD started off as another way of framing TDD - it's roots are still in TDD. As you've read before, TDD is a design practice, not a testing practice. There is a testing benefit we get out of it, but the great benefit of writing tests first is that you start off thinking from a client's perspective. This and the fact that you're adding small bits at a time, doing the simplest thing that could possibly work, generally leads to more highly decoupled nuggets of code than back- filling tests. > I'm sure this is one of the reasons that David considers it an "anti- > pattern" - as it does not influence your design in any way. In > fact, I developed the the stub_any_instance patch because I needed > to test legacy code (legacy because it wasn't designed well), and it > was the only way to get to the object. > > I'm sure David would have specific examples, and I'd be curious to > see them. any_instance is a global concept. Any time you're doing something global in an executable example you're making it harder for yourself to understand failures later. I guess that it's a bit more harmless with stubs, so, as I said, I'm still open to adding a patch. I'm just not going to make it myself as it's low priority for me. Cheers, David From dchelimsky at gmail.com Thu Jun 5 07:23:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 5 Jun 2008 06:23:05 -0500 Subject: [rspec-users] any_instance In-Reply-To: References: <94D46FFB-24CD-45E1-A4B4-04FE966F0440@gmail.com> <2A25DACC-0E70-45F5-AB2E-7A3423A1ED19@railsnewbie.com> Message-ID: <463D8002-C455-4DA6-8EDE-C9772191EFF6@gmail.com> On Jun 5, 2008, at 5:07 AM, Matt Mower wrote: > Does your patch work? I wasn't clear whether David was saying that > it doesn't. The patch works but is incomplete and duplicates a bunch of code. You should probably be able to use it as/is for what you need. Cheers, David From aidy.lewis at googlemail.com Thu Jun 5 08:49:16 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Thu, 5 Jun 2008 13:49:16 +0100 Subject: [rspec-users] additional logging Message-ID: <7ac2300c0806050549j452fb3d8t93217cf3bcc2673a@mail.gmail.com> Hi, I am using the 'spec/story' module with Fire(Watir). Is there additional logging? I don't want to do this: Then "the resultant links are displayed with the search text in each description" do browser.links.each do |lnk| if lnk.id =~ /programmeLink/ lnk.click sleep 0.5 puts "pass" unless ui.does_the_html_include?(@text)== 0 #regex browser.back end end Or am I structuring this wrong? Is it one "Then" per verification point? Problem with that is I have a dynamic number of verification points. Regards Aidy -- Aidy www.agiletester.co.uk From zach.dennis at gmail.com Thu Jun 5 11:39:07 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 5 Jun 2008 11:39:07 -0400 Subject: [rspec-users] xhr :post giving wrong number of arguments on rails 2.1? In-Reply-To: <57a815bf0806042233o6ad96265y1044ef4dd5ef9231@mail.gmail.com> References: <57a815bf0806042233o6ad96265y1044ef4dd5ef9231@mail.gmail.com> Message-ID: <85d99afe0806050839l4ce13f2agea1ba7921d22a39f@mail.gmail.com> Use xml_http_request in your stories rather than xhr. I believe the "xhr" method is aliased to the wrong method... I haven't looked to see if this is a Rails issue or a rspec-rails issue, Zach On Thu, Jun 5, 2008 at 1:33 AM, Mikel Lindsaar wrote: > Getting a strange error. > In a story I have the following step: > > When "I submit a search name" do > xhr :post, '/searches', {:search => {:given_name => "bob", :family_name > => "smith"}} > end > > I am getting: > > ArgumentError: wrong number of arguments (4 for 3) > stories/searching_story_spec.rb:45 in "I submit a search name" > > But I only have 3 arguments in the above list, a symbol, a string and a > hash. > > No exception comes up in the test.log > > I am on Rspec trunk from a couple of days ago and Rails 2.1. > > Any ideas? > > Mikel > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From duelin.markers at gmail.com Thu Jun 5 12:30:27 2008 From: duelin.markers at gmail.com (John D. Hume) Date: Thu, 5 Jun 2008 12:30:27 -0400 Subject: [rspec-users] Using and_yield to pass multiple or no iterations In-Reply-To: <7770b6ffbbd271a246d87c13678b9303@ruby-forum.com> References: <7770b6ffbbd271a246d87c13678b9303@ruby-forum.com> Message-ID: On Thu, Jun 5, 2008 at 5:46 AM, Doug Livesey wrote: > I have two questions with it. The first is, would it be possible to set > it up to test the case when each_row operates on an empty Array? If there were no rows, each_row wouldn't yield at all, so you should just be able to do @o.stub! :each_row (with no and_yield). Note that Ruby is happy to let you associate a block with any method call, whether it's expected or not. -hume. From lists at ruby-forum.com Thu Jun 5 13:29:25 2008 From: lists at ruby-forum.com (Ben Men) Date: Thu, 5 Jun 2008 19:29:25 +0200 Subject: [rspec-users] RSpec Story - SystemStackError: stack level too deep Message-ID: I have a story that executes the following (as an example to show the bug I'm experiencing): ---------------------------------------------- Given "I have a fake post saved" do @postCount = Post.find(:all).length @post = Post.new @post.employee_id = 123 @post.name = "Name of the Post" @post.description = "Description of the Post" @post.save end Given "I have visited some page" do get("/posts/") end When "I get some other page" do get('/posts/'+ at post.id) end Then "my variable should still be set" do Post.find(:all).length.should == 1 + @postCount end ---------------------------------------------- It fails with "SystemStackError: stack level too deep" on the "When I get some other page" bit. If I remove the + at post.id bit, OR if I switch the order execution of the Given statements, the story works. What's going on? Is this a bug, or am I just missing something? Additionally, I've tried updating to RSpec Edge by running "script/plugin install git://github.com/dchelimsky/rspec", but I keep receiving Plugin not found: ["git://github.com/dchelimsky/rspec"]. -- Posted via http://www.ruby-forum.com/. From raasdnil at gmail.com Fri Jun 6 01:02:58 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 6 Jun 2008 15:02:58 +1000 Subject: [rspec-users] xhr :post giving wrong number of arguments on rails 2.1? In-Reply-To: <85d99afe0806050839l4ce13f2agea1ba7921d22a39f@mail.gmail.com> References: <57a815bf0806042233o6ad96265y1044ef4dd5ef9231@mail.gmail.com> <85d99afe0806050839l4ce13f2agea1ba7921d22a39f@mail.gmail.com> Message-ID: <57a815bf0806052202h396a2fdbs7ec7e26520cf551@mail.gmail.com> On Fri, Jun 6, 2008 at 1:39 AM, Zach Dennis wrote: > Use xml_http_request in your stories rather than xhr. I believe the "xhr" > method is aliased to the wrong method... I haven't looked to see if this is > a Rails issue or a rspec-rails issue, > Thanks, that worked. Mikel -------------- next part -------------- An HTML attachment was scrubbed... URL: From hans at degraaff.org Fri Jun 6 01:42:25 2008 From: hans at degraaff.org (Hans de Graaff) Date: Fri, 06 Jun 2008 07:42:25 +0200 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> <1212557175.29530.8.camel@ip6-localhost> Message-ID: <1212730945.422.2.camel@ip6-localhost> On Wed, 2008-06-04 at 03:37 -0500, David Chelimsky wrote: > I believe this is now fixed in http://github.com/dchelimsky/rspec/commit/2b474ac > . > > If any of you can still reproduce this, please let me know. I tracked this down on Wednesday to the same code. However, this patch doesn't quite fix the problem for us. In the backtrace output we also have files without the closing semi-colon, and the regexp doesn't catch those. I've fixed this locally by not requiring the last semi-colon and fix seems to work as expected again. I'm not sure if this is the right fix, as it may also be a bug that the last semi-colon is missing from the backtrace list? Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From jarmo.p at gmail.com Fri Jun 6 02:23:04 2008 From: jarmo.p at gmail.com (kasutaja) Date: Thu, 5 Jun 2008 23:23:04 -0700 (PDT) Subject: [rspec-users] `exit?': undefined method `run?' for Test::Unit:Module (NoMethodError)? Message-ID: <17685410.post@talk.nabble.com> Why am I getting this error if running from Netbeans or just from command line with executing blah_spec.rb? If I run with spec bla blah blah_spec.rb then it's fine. . Finished in 0.264 seconds 1 example, 0 failures c:/ruby/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec.rb:27:in `exit?': undefined method `run?' for Test::Unit:Module (NoMethodError) from c:/ruby/lib/ruby/gems/1.8/gems/rspec-1.1.4/lib/spec/runner.rb:193:in `register_at_exit_hook' from C:/projects/xpstuff/watir/src/list_sitt.rb:3 -- View this message in context: http://www.nabble.com/%60exit-%27%3A-undefined-method-%60run-%27-for-Test%3A%3AUnit%3AModule-%28NoMethodError%29--tp17685410p17685410.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Fri Jun 6 09:12:32 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jun 2008 08:12:32 -0500 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: <1212730945.422.2.camel@ip6-localhost> References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> <1212557175.29530.8.camel@ip6-localhost> <1212730945.422.2.camel@ip6-localhost> Message-ID: <05C1052C-D4DB-4C29-AB6C-28B924B29C29@gmail.com> On Jun 6, 2008, at 12:42 AM, Hans de Graaff wrote: > On Wed, 2008-06-04 at 03:37 -0500, David Chelimsky wrote: > >> I believe this is now fixed in http://github.com/dchelimsky/rspec/commit/2b474ac >> . >> >> If any of you can still reproduce this, please let me know. > > I tracked this down on Wednesday to the same code. However, this patch > doesn't quite fix the problem for us. In the backtrace output we also > have files without the closing semi-colon, and the regexp doesn't > catch > those. I've fixed this locally by not requiring the last semi-colon > and > fix seems to work as expected again. > > I'm not sure if this is the right fix, as it may also be a bug that > the > last semi-colon is missing from the backtrace list? That could be from different versions of Ruby. I'm not sure there is any harm in removing the second ':' - does anybody else think there is? From lists at ruby-forum.com Fri Jun 6 11:57:59 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Fri, 6 Jun 2008 17:57:59 +0200 Subject: [rspec-users] Why has the --color gone from my life? In-Reply-To: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> References: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> Message-ID: This was an error, but I thought it was corrected by D. Chelimsky. Check this topic: http://www.ruby-forum.com/topic/154595 Juanma Cervera -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Jun 6 12:09:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jun 2008 11:09:54 -0500 Subject: [rspec-users] Why has the --color gone from my life? In-Reply-To: References: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> Message-ID: <03EEC8AB-625A-4C36-8585-4782DA9F4E41@gmail.com> On Jun 6, 2008, at 10:57 AM, Juanma Cervera wrote: > This was an error, but I thought it was corrected by D. Chelimsky. That is correct - at least temporarily - there is a conflict with how rspec and autotest output to a terminal that makes it challenging for rspec to color code terminal output while not including the color code chars in html output. If anybody is interested in helping to solve that, check out http://rspec.lighthouseapp.com/projects/5645/tickets/413 . Cheers, David From lists at ruby-forum.com Fri Jun 6 12:20:13 2008 From: lists at ruby-forum.com (Pol Llovet) Date: Fri, 6 Jun 2008 18:20:13 +0200 Subject: [rspec-users] RSpec for testing REST webservices? (Not Rails) In-Reply-To: <483486C8.80702@ruby-lang.nl> References: <483486C8.80702@ruby-lang.nl> Message-ID: I am interested in this also, anyone out there have some best practices? -- Posted via http://www.ruby-forum.com/. From hayafirst at gmail.com Fri Jun 6 13:16:12 2008 From: hayafirst at gmail.com (Yi Wen) Date: Fri, 6 Jun 2008 12:16:12 -0500 Subject: [rspec-users] RSpec for testing REST webservices? (Not Rails) In-Reply-To: References: <483486C8.80702@ruby-lang.nl> Message-ID: I use http-access2 (http://dev.ctor.org/http-access2) for make requests. I also have a custom WebServiceExampleGroup to do setup work there. On Fri, Jun 6, 2008 at 11:20 AM, Pol Llovet wrote: > I am interested in this also, anyone out there have some best practices? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ramos.gaston at gmail.com Fri Jun 6 17:48:41 2008 From: ramos.gaston at gmail.com (Gaston Ramos) Date: Fri, 6 Jun 2008 18:48:41 -0300 Subject: [rspec-users] Problems with view spec and mocking will_paginate Message-ID: <20080606214841.GA19727@marlasina> Hi all, I have some failures that not I don't understand this the pastie with index.erb.html http://pastie.org/private/zgohh6dcts04wpfagfgz5q and this is the pastie for view's spec: http://pastie.org/210485 and the failure: 1) ActionView::TemplateError in '/posts/index.html.erb should render list of posts' undefined method `count' for [#]:Array I tried this: Array.stub!(:count).and_return(1) but didn't work. Can somebody help me? Regards. -- "Es imposible afinar un l?piz con una cuchilla desafilada. Es igualmente in?til tratar de hacerlo con diez." (Edsger Dijkstra) +-------------------------------------+ Gast?n Ramos http://gastonramos.wordpress.com/ GNU/Linux Counter user #450312 From mike.sch.list at gmail.com Fri Jun 6 23:46:58 2008 From: mike.sch.list at gmail.com (Mike Schiller) Date: Sat, 7 Jun 2008 12:46:58 +0900 Subject: [rspec-users] When to send "post" and "get" in blocks. Message-ID: <6a39e69d0806062046u3d923718m95e727611e806265@mail.gmail.com> Hi, I'm new to RSpec. I have a question about how to write controller specs. Here's a code generated by scaffolding (with Rspec). def do_get get :index end it "should be successful" do do_get response.should be_success end it "should render index template" do do_get response.should render_template('index') end it "should find all books" do Book.should_receive(:find).with(:all).and_return([@book]) do_get end it "should assign the found books for the view" do do_get assigns[:books].should == [@book] end end ################### What I don't understand is that, sometimes, "get" is done before an expectation(i.e., a line that contains "should"), but other times, the order is the opposite. In the third spec above, the sentence that has "should" comes first and do_get later. In my view, "get :index" needs to be done first to trigger "index" action. And the "index" action should trigger "Book.should_receive(:find).....". I'm a bit confused about all of this. Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From mauricio.linhares at gmail.com Fri Jun 6 23:57:03 2008 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Sat, 7 Jun 2008 00:57:03 -0300 Subject: [rspec-users] When to send "post" and "get" in blocks. In-Reply-To: <6a39e69d0806062046u3d923718m95e727611e806265@mail.gmail.com> References: <6a39e69d0806062046u3d923718m95e727611e806265@mail.gmail.com> Message-ID: Hi Mike, You should place the spectation before the "do_method" (a call to a controller method) when you are stating that something must happen inside your controller code, like asserting that some object should receive a specific method call, like your example, where it's stating that the Book class should receive the message :find (or should receive a call to the find method) with :all as a parameter, you place this before the "do_method" 'cos the call will happen inside the "do_method", so you have to explain in advance what you spect to see. And a spectation is placed after a "do_method" when you want to assert some state after the request is processed, like asserting that the correct template was rendered, asserting that a non-logged in user should receive a redirect to the login page or asserting that a variable will be available for your views. You are doing this after the "do_method" 'cos only after the controller execution you will have access to the generated response. On Sat, Jun 7, 2008 at 12:46 AM, Mike Schiller wrote: > Hi, > I'm new to RSpec. I have a question about how to write controller specs. > Here's a code generated by scaffolding (with Rspec). > def do_get > get :index > end > > it "should be successful" do > do_get > response.should be_success > end > it "should render index template" do > do_get > response.should render_template('index') > end > > it "should find all books" do > Book.should_receive(:find).with(:all).and_return([@book]) > do_get > end > > it "should assign the found books for the view" do > do_get > assigns[:books].should == [@book] > end > end > ################### > What I don't understand is that, sometimes, "get" is done before an > expectation(i.e., a line that contains "should"), but other times, the order > is the opposite. > In the third spec above, the sentence that has "should" comes first and > do_get later. In my view, "get :index" needs to be done first to trigger > "index" action. And the "index" action should trigger > "Book.should_receive(:find).....". I'm a bit confused about all of this. > Mike -- Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) Jo?o Pessoa, PB, +55 83 8867-7208 From mike.sch.list at gmail.com Sat Jun 7 00:19:22 2008 From: mike.sch.list at gmail.com (Mike Schiller) Date: Sat, 7 Jun 2008 13:19:22 +0900 Subject: [rspec-users] When to send "post" and "get" in blocks. In-Reply-To: References: <6a39e69d0806062046u3d923718m95e727611e806265@mail.gmail.com> Message-ID: <6a39e69d0806062119rb10fc7pf652731328a33f3f@mail.gmail.com> Mauricio, Thanks so much for your very clear explanation!! You saved my life. Thanks. Mike. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhennemeyer at googlemail.com Sat Jun 7 03:28:23 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Sat, 7 Jun 2008 09:28:23 +0200 Subject: [rspec-users] Problems with view spec and mocking will_paginate In-Reply-To: <20080606214841.GA19727@marlasina> References: <20080606214841.GA19727@marlasina> Message-ID: <6C0B3AEF-0156-4EA7-BAEB-F0D4B2A0B233@googlemail.com> You have to stub that count method for the Array object and not for class Array: comments = [comment] comments.stub!(:count).and_return(1) post_98.stub!(:comments).and_return(comments) post_99.stub!(:comments).and_return(comments) Matthias Am 06.06.2008 um 23:48 schrieb Gaston Ramos: > Hi all, I have some failures that not I don't understand > > this the pastie with index.erb.html > http://pastie.org/private/zgohh6dcts04wpfagfgz5q > > and this is the pastie for view's spec: > http://pastie.org/210485 > > and the failure: > > 1) > ActionView::TemplateError in '/posts/index.html.erb should render list > of posts' > undefined method `count' for [# @name="Comment_1001">]:Array > > I tried this: Array.stub!(:count).and_return(1) > but didn't work. > > Can somebody help me? > > Regards. > > -- > "Es imposible afinar un l?piz con una cuchilla desafilada. Es > igualmente in?til tratar de hacerlo con diez." > (Edsger Dijkstra) > > > +-------------------------------------+ > Gast?n Ramos > http://gastonramos.wordpress.com/ > GNU/Linux Counter user #450312 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From hans at degraaff.org Sat Jun 7 03:37:06 2008 From: hans at degraaff.org (Hans de Graaff) Date: Sat, 07 Jun 2008 09:37:06 +0200 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: <05C1052C-D4DB-4C29-AB6C-28B924B29C29@gmail.com> References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> <1212557175.29530.8.camel@ip6-localhost> <1212730945.422.2.camel@ip6-localhost> <05C1052C-D4DB-4C29-AB6C-28B924B29C29@gmail.com> Message-ID: <1212824226.20358.1.camel@ip6-localhost> On Fri, 2008-06-06 at 08:12 -0500, David Chelimsky wrote: > On Jun 6, 2008, at 12:42 AM, Hans de Graaff wrote: > > I'm not sure if this is the right fix, as it may also be a bug that > > the > > last semi-colon is missing from the backtrace list? > > That could be from different versions of Ruby. I'm not sure there is > any harm in removing the second ':' - does anybody else think there is? FWIW I'm using ruby 1.8.6 pl 114 here. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From mauricio.linhares at gmail.com Sat Jun 7 12:23:11 2008 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Sat, 7 Jun 2008 13:23:11 -0300 Subject: [rspec-users] Match render :nothing Message-ID: Hello guys, Is there any way to match a render :nothing? I coudn't find any way to do this so i've just changed my controllers to do a "head :ok", but it would be nice to know if there is any other way :) -- Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) Jo?o Pessoa, PB, +55 83 8867-7208 From pergesu at gmail.com Sat Jun 7 12:27:16 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 7 Jun 2008 09:27:16 -0700 Subject: [rspec-users] Match render :nothing In-Reply-To: References: Message-ID: <810a540e0806070927v56ad37cdrc9d52070b103ac66@mail.gmail.com> On Sat, Jun 7, 2008 at 9:23 AM, Maur?cio Linhares wrote: > Hello guys, > > Is there any way to match a render :nothing? > > I coudn't find any way to do this so i've just changed my controllers > to do a "head :ok", but it would be nice to know if there is any other > way :) I'm pretty sure you can do response.body.should be_blank # or == "" If you don't like how it reads, you could create a custom render_nothing matcher. Pat From mauricio.linhares at gmail.com Sat Jun 7 12:37:10 2008 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Sat, 7 Jun 2008 13:37:10 -0300 Subject: [rspec-users] Match render :nothing In-Reply-To: <810a540e0806070927v56ad37cdrc9d52070b103ac66@mail.gmail.com> References: <810a540e0806070927v56ad37cdrc9d52070b103ac66@mail.gmail.com> Message-ID: Hi Pat, 'response.body.should be_empty" does not work :( The string on the response after a "render :nothing" is " " (one space character), so i had to do a strip to make it work. I guess i'll write my own render_nothing matcher anyway. Here's how it is now: @assignments.should_receive( :find ).and_return( [ @assignment ] ) @assignments.should_not_receive( :create ) do_xhr response.should be_success response.body.strip.should be_empty On Sat, Jun 7, 2008 at 1:27 PM, Pat Maddox wrote: > > I'm pretty sure you can do > response.body.should be_blank # or == "" > > If you don't like how it reads, you could create a custom > render_nothing matcher. > > Pat -- Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) Jo?o Pessoa, PB, +55 83 8867-7208 From dchelimsky at gmail.com Sat Jun 7 13:11:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 7 Jun 2008 12:11:05 -0500 Subject: [rspec-users] Match render :nothing In-Reply-To: References: <810a540e0806070927v56ad37cdrc9d52070b103ac66@mail.gmail.com> Message-ID: <83553CCD-C1B4-4683-AB44-331C5BF50885@gmail.com> Oi Maur?cio, On Jun 7, 2008, at 11:37 AM, Maur?cio Linhares wrote: > Hi Pat, > > 'response.body.should be_empty" does not work :( > > The string on the response after a "render :nothing" is " " (one space > character), so i had to do a strip to make it work. I guess i'll write > my own render_nothing matcher anyway. Here's how it is now: > > > @assignments.should_receive( :find ).and_return( [ @assignment ] ) > @assignments.should_not_receive( :create ) I would put should_not_receive(:create) in a separate example as it's a different concept from rendering nothing. > do_xhr > response.should be_success > response.body.strip.should be_empty You can use the simple_matcher method for this quite ... simply: def render_nothing simple_matcher(:nothing) do |response| response.body.strip == '' end end The failure message on this is quite verbose, and I have an idea about a solution for that, but it'll work :) Tchau, David > > > On Sat, Jun 7, 2008 at 1:27 PM, Pat Maddox wrote: >> >> I'm pretty sure you can do >> response.body.should be_blank # or == "" >> >> If you don't like how it reads, you could create a custom >> render_nothing matcher. >> >> Pat > > > -- > Maur?cio Linhares > http://alinhavado.wordpress.com/ (pt-br) | http:// > blog.codevader.com/ (en) > Jo?o Pessoa, PB, +55 83 8867-7208 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mauricio.linhares at gmail.com Sat Jun 7 13:11:54 2008 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Sat, 7 Jun 2008 14:11:54 -0300 Subject: [rspec-users] rcov causing a segmentation fault on rspec 1.1.4 and rails 2.1 Message-ID: Hello again :) I'm trying to run rcov on my specs here but i'm getting a lot of segmentation faults (and they usually happen at different places): /home/mauricio/NetBeansProjects/reeds/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:211: [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i486-linux] /home/mauricio/NetBeansProjects/reeds/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/module/introspection.rb:60: [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i486-linux] Is there any way to fix this? I'm using rspec 1.1.4, rcov 0.8.1.2.0, rails 2.1 and Ubuntu Linux 8.4. -- Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) Jo?o Pessoa, PB, +55 83 8867-7208 From dchelimsky at gmail.com Sat Jun 7 13:18:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 7 Jun 2008 12:18:01 -0500 Subject: [rspec-users] rcov causing a segmentation fault on rspec 1.1.4 and rails 2.1 In-Reply-To: References: Message-ID: <66924006-11AF-41E2-B0D5-C1CE1FAA7FC2@gmail.com> On Jun 7, 2008, at 12:11 PM, Maur?cio Linhares wrote: > Hello again :) > > I'm trying to run rcov on my specs here but i'm getting a lot of > segmentation faults (and they usually happen at different places): > > /home/mauricio/NetBeansProjects/reeds/vendor/rails/activerecord/lib/ > active_record/attribute_methods.rb:211: > [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i486-linux] > > /home/mauricio/NetBeansProjects/reeds/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/core_ext/module/ > introspection.rb:60: > [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i486-linux] > > Is there any way to fix this? This has come up a few times before: http://rubyurl.com/i2jV Cheers, David > > > I'm using rspec 1.1.4, rcov 0.8.1.2.0, rails 2.1 and Ubuntu Linux 8.4. > > -- > Maur?cio Linhares > http://alinhavado.wordpress.com/ (pt-br) | http:// > blog.codevader.com/ (en) > Jo?o Pessoa, PB, +55 83 8867-7208 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From philodespotos at gmail.com Sat Jun 7 16:10:15 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Sat, 7 Jun 2008 15:10:15 -0500 Subject: [rspec-users] Rails integration tests without stories Message-ID: <60f3810c0806071310h5c7bc0a4obb2b093e2b1a857b@mail.gmail.com> I'm looking to drive the development of a rails app that does nothing but serve a JSON API. All of the models are well tested elsewhere, so I needn't worry about that. My only immediate goal is to be able to fire off requests to a path and check the returned JSON. I've tried a number of methods for this today, without being particularly enthused about any of them. I started with user stories, but the conversion to english was difficult for something largely developer-facing. "When I get /widgets/:id" where :id is actually determined behind the scenes did not read well, and a lot of my expectations were tough to express in sentence form. I've had a lot of success with stories in the application that is related to this API, but they don't seem to fit well here. I tried out using standard rails test/unit integration tests, but that would be a suite largely divorced from all of my other specs, and I miss the :should syntax. Requiring spec/expectations and spec/matchers alleviated some of that, but test_names_end_up_being_unpleasantly_long_and_cumbersome. I haven't yet looked at the test/unit interop support, but maybe that would be helpful here? I tried to make an IntegrationExampleGroup akin to the other rails example groups: module Spec::Rails::Example class IntegrationExampleGroup < ActionController::IntegrationTest Spec::Example::ExampleGroupFactory.register(:integration, self) end end describe 'GET /widgets', :type => :integration do it "should ..." do get '/widgets' [...] end end This roughly seems to work for the integration tests (I'd still need to add in transactions, maybe a few other things), but for reasons I haven't yet figured out means all my other specs try to run within an integration session. Finally, I could just test the serialization methods on the model (or build a WidgetSerializer), and then use mocks in controller specs. But I'm really looking for full-stack specs here, so I'd like to avoid that. Any suggestions? The path of least resistance is probably using the test/unit tests, followed closely by just sucking it up and having awkward user stories. My preferred solution would be the IntegrationExampleGroup, and I may yet get that to work, but I thought I'd ask here while I sit on it for a bit. Thanks Kyle From dchelimsky at gmail.com Sat Jun 7 16:16:48 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 7 Jun 2008 15:16:48 -0500 Subject: [rspec-users] Rails integration tests without stories In-Reply-To: <60f3810c0806071310h5c7bc0a4obb2b093e2b1a857b@mail.gmail.com> References: <60f3810c0806071310h5c7bc0a4obb2b093e2b1a857b@mail.gmail.com> Message-ID: On Jun 7, 2008, at 3:10 PM, Kyle Hargraves wrote: > I'm looking to drive the development of a rails app that does nothing > but serve a JSON API. All of the models are well tested elsewhere, so > I needn't worry about that. My only immediate goal is to be able to > fire off requests to a path and check the returned JSON. > > I've tried a number of methods for this today, without being > particularly enthused about any of them. > > I started with user stories, but the conversion to english was > difficult for something largely developer-facing. "When I get > /widgets/:id" where :id is actually determined behind the scenes did > not read well, and a lot of my expectations were tough to express in > sentence form. I've had a lot of success with stories in the > application that is related to this API, but they don't seem to fit > well here. Can you post an example or two? I'd like to see what's not working for you. No promises I can offer up anything better, but just curious. > I tried out using standard rails test/unit integration tests, but that > would be a suite largely divorced from all of my other specs, and I > miss the :should syntax. Requiring spec/expectations and spec/matchers > alleviated some of that, but > test_names_end_up_being_unpleasantly_long_and_cumbersome. I haven't > yet looked at the test/unit interop support, but maybe that would be > helpful here? > > I tried to make an IntegrationExampleGroup akin to the other rails > example groups: > > module Spec::Rails::Example > class IntegrationExampleGroup < ActionController::IntegrationTest > Spec::Example::ExampleGroupFactory.register(:integration, self) > end > end > describe 'GET /widgets', :type => :integration do > it "should ..." do > get '/widgets' > [...] > end > end > > This roughly seems to work for the integration tests (I'd still need > to add in transactions, maybe a few other things), but for reasons I > haven't yet figured out means all my other specs try to run within an > integration session. That definitely shouldn't happen. What you have here is very close to what > Finally, I could just test the serialization methods on the model (or > build a WidgetSerializer), and then use mocks in controller specs. But > I'm really looking for full-stack specs here, so I'd like to avoid > that. > > Any suggestions? The path of least resistance is probably using the > test/unit tests, followed closely by just sucking it up and having > awkward user stories. My preferred solution would be the > IntegrationExampleGroup, and I may yet get that to work, but I thought > I'd ask here while I sit on it for a bit. The IntegrationExampleGroup should work. Let's try to figure out why you're getting bleed into the other groups. Cheers, David From mailing_lists at railsnewbie.com Sat Jun 7 17:09:23 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 7 Jun 2008 17:09:23 -0400 Subject: [rspec-users] rcov causing a segmentation fault on rspec 1.1.4 and rails 2.1 In-Reply-To: References: Message-ID: On Jun 7, 2008, at 1:11 PM, Maur?cio Linhares wrote: > Hello again :) > > I'm trying to run rcov on my specs here but i'm getting a lot of > segmentation faults (and they usually happen at different places): > > /home/mauricio/NetBeansProjects/reeds/vendor/rails/activerecord/lib/ > active_record/attribute_methods.rb:211: > [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i486-linux] > > /home/mauricio/NetBeansProjects/reeds/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/core_ext/module/ > introspection.rb:60: > [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i486-linux] > > Is there any way to fix this? I'm not sure about this, but I can tell you *my* one run in with rcov seg-faulting (maybe it will be of some use): While testing FixtureReplacement, I decided to swap out Kernel#require for my specs. I didn't see any other option: My init.rb explicitly required a "db/example_data" file, and since I was testing it outside of a rails project there was no way to access a file which was outside of vendor/plugins/fixture_replacement. I tried the typical pattern of aliasing require, and overriding it, calling it only when the file didn't match "db/example_data.rb". At the time, the specs ran just fine. Much to my surpise, rcov segfaulted. I had to resort to the technique described on this page to get it to work: http://blog.jayfields.com/2006/12/ruby-alias-method-alternative.html I still don't know why this happened. My guess is that between rcov and rubygems, both of which probably swap out require, someone wasn't playing nice. Or, come to think of it, maybe it was me! General advice: I'd bet you could run the debugger (ruby-debug) on it, and see where it craps out... Scott > > > I'm using rspec 1.1.4, rcov 0.8.1.2.0, rails 2.1 and Ubuntu Linux 8.4. > > -- > Maur?cio Linhares > http://alinhavado.wordpress.com/ (pt-br) | http:// > blog.codevader.com/ (en) > Jo?o Pessoa, PB, +55 83 8867-7208 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From philodespotos at gmail.com Sat Jun 7 20:18:47 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Sat, 7 Jun 2008 19:18:47 -0500 Subject: [rspec-users] Rails integration tests without stories In-Reply-To: References: <60f3810c0806071310h5c7bc0a4obb2b093e2b1a857b@mail.gmail.com> Message-ID: <60f3810c0806071718i134db50et8f3e2ba09af68b9d@mail.gmail.com> On Sat, Jun 7, 2008 at 3:16 PM, David Chelimsky wrote: >> I started with user stories, but the conversion to english was >> difficult for something largely developer-facing. "When I get >> /widgets/:id" where :id is actually determined behind the scenes did >> not read well, and a lot of my expectations were tough to express in >> sentence form. I've had a lot of success with stories in the >> application that is related to this API, but they don't seem to fit >> well here. > > Can you post an example or two? I'd like to see what's not working for you. > No promises I can offer up anything better, but just curious. I've since rm'd what I wrote, but imagine the case where I need to create a widget, and then I'd like to spec what Widgets#show should return to me: Given a green widget named Panel When I get the JSON representation of the widget Then it should include its buttons And it should not include the widget's super secret name There's nothing inherently wrong with this -- I actually rather like it. Reasonably succinct, and a nice high-level overview. But notice that it doesn't really document the API, which is the goal of my specs. No mention that the widget is at /widgets/1. If I were to mention the URL, I'd have to use something like the /widgets/:id I mentioned, where :id is a bare string in the step name, but filled in with whatever id I happened to get when I created a widget in step #1. Nor is it very clear about what "should include its buttons" means. Again, that's a good thing if I were documenting behavior of something closer to an application, but it's awkward here. Cf. to: widget = create_widget(:name => 'Panel', :color => 'green') 3.times { create_button(:widget => widget) } obj = get_json('/widgets/' + widget.id) obj['buttons'].length.should == 3 obj.should_not have_key('super-secret-name') (I would actually split these up into separate examples, but you get the idea) Given well chosen example group/example names, it feels like this will be more useful when another developer opens them up to learn how to consume the API. And the specdocs have ended up being almost identical to the stories for the purposes of at-a-glance understanding. > The IntegrationExampleGroup should work. Let's try to figure out why you're > getting bleed into the other groups. The issue was that my other specs are for the models, which are shared between two applications in a plugin. Thus, the specs are living in plugins/mylib/spec/integration/models -- integration here opposed to the unit tests we have in spec/unit, as they lean on other plugins like will_paginate. That directory then matches :integration and they rightfully try to use the IntegrationExampleGroup. Just an unfortunate overlap of terminology. For now I've just opted to rename the :integration type key to :api, but hopefully I'll come up with a better name for spec/integration. Open to suggestions. =) Works like a charm now, I can use autotest to run them alongside our other specs, and it accomplishes everything I set out for. Big wins all around. k From willem at willemvandenende.com Sun Jun 8 08:56:47 2008 From: willem at willemvandenende.com (Willem van den Ende) Date: Sun, 08 Jun 2008 14:56:47 +0200 Subject: [rspec-users] RSpec Story - SystemStackError: stack level too deep Message-ID: <1212929807.15422.19.camel@vox> Hi Ben, This is probably not an rspec issue, but a rails defect ( http://dev.rubyonrails.org/ticket/10896 ). >From your code, I am assuming you are story testing a Rails app. I was bitten by this too recently... Took me a while to figure it out. The workaround is to replace post.id by post[:id] Looks ugly, but it works. On your second question, my guess is the script/install plugin from git only works as of rails 2.1.0 . At least that is what I understood from reading http://github.com/dchelimsky/rspec-rails/wikis/home I followed the steps under "Install an RSpec release >= 1.1.4:" and that worked on 2.0.2 . Hope this helps, Willem van den Ende p.s. I just joined the mailing list and found Ben's question in the archive. it didn't seem to have an answer yet. apologies for double posting if it already has p.s II. I got hooked on story testing after seeing David Chelimsky's presentation at qcon london this spring. On June 5, Ben Men Wrote: > I have a story that executes the following (as an example to show the > bug I'm experiencing): > > ---------------------------------------------- > > Given "I have a fake post saved" do > @postCount = Post.find(:all).length > @post = Post.new > @post.employee_id = 123 > @post.name = "Name of the Post" > @post.description = "Description of the Post" > @post.save > end > > Given "I have visited some page" do > get("/posts/") > end > > When "I get some other page" do > get('/posts/'+ at post.id) > end > > Then "my variable should still be set" do > Post.find(:all).length.should == 1 + @postCount > end > > ---------------------------------------------- > > It fails with "SystemStackError: stack level too deep" on the "When I > get some other page" bit. If I remove the + at post.id bit, OR if I switch > the order execution of the Given statements, the story works. What's > going on? Is this a bug, or am I just missing something? > > Additionally, I've tried updating to RSpec Edge by running > "script/plugin install git://github.com/dchelimsky/rspec", but I keep > receiving Plugin not found: ["git://github.com/dchelimsky/rspec"]. > -- > Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Jun 8 13:40:04 2008 From: lists at ruby-forum.com (Mark Dodwell) Date: Sun, 8 Jun 2008 19:40:04 +0200 Subject: [rspec-users] Full Trace for Stories Message-ID: <41dd9e22b9889e5cf1ec7633d7b29394@ruby-forum.com> Does anybody know how to get full backtraces for stories when they fail? I tried 'ruby stories/all.rb --trace' but it doesn't like that option. Thanks, ~ Mark -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Sun Jun 8 18:15:57 2008 From: ben at benmabey.com (Ben Mabey) Date: Sun, 08 Jun 2008 16:15:57 -0600 Subject: [rspec-users] Full Trace for Stories In-Reply-To: <41dd9e22b9889e5cf1ec7633d7b29394@ruby-forum.com> References: <41dd9e22b9889e5cf1ec7633d7b29394@ruby-forum.com> Message-ID: <484C5A1D.2000100@benmabey.com> Mark Dodwell wrote: > Does anybody know how to get full backtraces for stories when they fail? > > I tried 'ruby stories/all.rb --trace' but it doesn't like that option. > > Thanks, > > ~ Mark > Mark, Try 'ruby stories/all.rb --backtrace'. I've always had the full stack trace though... What kind of traces are you seeing? Would you mind posting one? -Ben From lists at ruby-forum.com Sun Jun 8 18:37:52 2008 From: lists at ruby-forum.com (Mark Dodwell) Date: Mon, 9 Jun 2008 00:37:52 +0200 Subject: [rspec-users] Full Trace for Stories In-Reply-To: <484C5A1D.2000100@benmabey.com> References: <41dd9e22b9889e5cf1ec7633d7b29394@ruby-forum.com> <484C5A1D.2000100@benmabey.com> Message-ID: <42b3d44d09f0ade901873a93e757085c@ruby-forum.com> Ben Mabey wrote: > Mark, > Try 'ruby stories/all.rb --backtrace'. Thanks, that worked. I think the test actually failed due to a bug in a gem I'm using (webrat). Without the -backtrace switch RSpec quietens the backtrace by stopping once it hits a gem it seems. Presumable that's intended? ~ Mark -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Jun 9 06:01:15 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Mon, 9 Jun 2008 12:01:15 +0200 Subject: [rspec-users] Selenium/Watir usage along side Webrat in story testing Message-ID: This is related to Selenium/Watir usage along side webrat in story testing. MHS_Testing and Rspec-ui provide some great help for testing through frameworks like Selenium/Watir. But there is something missing, Webrat has changed the landscape somewhat with Acceptance Tests/Story Driven development. Now I have a choice: 1. Tests and rails process run as one test process (Webrat) 2. Use framework accesses a separate test process than the one driving the tests. (Selenium) Option 1 is super fast but cannot run complex JavaScript/advanced UI actions (mouse over, etc.) So I use a mixture of both based on the test I have to write. So there are **two syntaxes I have to use**. When I have common Givens like login I have to duplicate the Given, one for Selenium one for Webrat. So I was thinking of ways to avoid this duplication: Create two classes (this is already what MHS_testing has done for Selenium) ---- class RailsSeleniumStory < RailsStory class RailsWebratStory < RailsStory ---- Create a common interface for all shared functionailty. (I suspect Webrat represents the smallest set of functionality - Selenium can do everything Webrat can do but not the other way around). The different UI testing frameworks implement such interface giving Selenium/Webrat/Other UI adapters. You choose which adapter to use by the story class. Example ------- #Webrat syntax steps_for(:login) do Given('I'm logged in') do visits '/login' fills_in 'username' 'test' fills_in 'password' 'password' clicks 'login' end end #Make webrat syntax work with selenium with_steps_for(:login) do run '/example/story', {:type => RailsSeleniumStory} end #Use Webrat with_steps_for(:login) do run '/example/story', {:type => RailsWebratStory} #Could just be RailsStory end class RailsSeleniumStory < RailsStory ... #Map webrats visit to seleniums open def visits(url) browser.open(url) browser.wait_for_page_to_load "30000" end ... end ------- I'm not sure what direction MHS_testing or Rspec-ui are going, whether they will merge? I'm looking at this problem now and want to start contributing to whatever project is going to be the best fit. So I'm interested to hear: *Feedback/discussion about this direction *Any better ideas of solving the problem *Any other frameworks out there were people have started to look at this problem. -- Joseph Wilk http://www.joesniff.co.uk -- Posted via http://www.ruby-forum.com/. From nicholas.wieland at gmail.com Mon Jun 9 08:05:47 2008 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Mon, 9 Jun 2008 14:05:47 +0200 Subject: [rspec-users] Testing file attachment with Paperclip Message-ID: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> Does someone have an example on faking a file upload for just ensuring it gets called, without actually uploading the file to s3. I thought that stubbing Model.has_attached_file would be enough, but it doesn't seem so ... This is what I did: Video.stub!( :has_attached_file ).with( :name ).and_return( true ) has_attached_file is from paperclip, it gets mixed to the model. 1) RightAws::AwsError in 'VideosController should create a valid Video' AWS access keys are required to operate on S3 /Users/ngw/zooppa-4/app/controllers/videos_controller.rb:6:in `create' /Users/ngw/zooppa-4/spec/controllers/videos_controller_spec.rb:17: Maybe I missed something ? TIA, ngw -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2435 bytes Desc: not available URL: From ramos.gaston at gmail.com Mon Jun 9 08:02:06 2008 From: ramos.gaston at gmail.com (Gaston Ramos) Date: Mon, 9 Jun 2008 09:02:06 -0300 Subject: [rspec-users] Problems with view spec and mocking will_paginate In-Reply-To: <6C0B3AEF-0156-4EA7-BAEB-F0D4B2A0B233@googlemail.com> References: <20080606214841.GA19727@marlasina> <6C0B3AEF-0156-4EA7-BAEB-F0D4B2A0B233@googlemail.com> Message-ID: <20080609120205.GC8405@marlasina> Thanks! El s?b, 07 de jun de 2008, a las 09:28:23 +0200, Matthias Hennemeyer dijo: > You have to stub that count method for the Array object and not for > class Array: > > comments = [comment] > comments.stub!(:count).and_return(1) > post_98.stub!(:comments).and_return(comments) > post_99.stub!(:comments).and_return(comments) > > Matthias > > Am 06.06.2008 um 23:48 schrieb Gaston Ramos: > >> Hi all, I have some failures that not I don't understand >> >> this the pastie with index.erb.html >> http://pastie.org/private/zgohh6dcts04wpfagfgz5q >> >> and this is the pastie for view's spec: >> http://pastie.org/210485 >> >> and the failure: >> >> 1) >> ActionView::TemplateError in '/posts/index.html.erb should render list >> of posts' >> undefined method `count' for [#> @name="Comment_1001">]:Array >> >> I tried this: Array.stub!(:count).and_return(1) >> but didn't work. >> >> Can somebody help me? >> >> Regards. >> >> >> >> +-------------------------------------+ >> Gast?n Ramos >> http://gastonramos.wordpress.com/ >> GNU/Linux Counter user #450312 >> _______________________________________________ >> 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 -- "Premature optimization is the root of all evil (or at least most of it) in programming." (Donald Knuth) +-------------------------------------+ Gast?n Ramos http://gastonramos.wordpress.com/ GNU/Linux Counter user #450312 From dchelimsky at gmail.com Mon Jun 9 08:11:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 9 Jun 2008 07:11:03 -0500 Subject: [rspec-users] Testing file attachment with Paperclip In-Reply-To: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> References: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> Message-ID: <3C05EE2D-BD8F-41C1-8CA9-2427A0F1ADE8@gmail.com> On Jun 9, 2008, at 7:05 AM, Nicholas Wieland wrote: > Does someone have an example on faking a file upload for just > ensuring it gets called http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin Cheers, David From nicholas.wieland at gmail.com Mon Jun 9 08:18:36 2008 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Mon, 9 Jun 2008 14:18:36 +0200 Subject: [rspec-users] Testing file attachment with Paperclip In-Reply-To: <3C05EE2D-BD8F-41C1-8CA9-2427A0F1ADE8@gmail.com> References: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> <3C05EE2D-BD8F-41C1-8CA9-2427A0F1ADE8@gmail.com> Message-ID: <267ADB18-AD00-48A9-BD51-1581A9EBCC43@gmail.com> Il giorno 09/giu/08, alle ore 14:11, David Chelimsky ha scritto: > On Jun 9, 2008, at 7:05 AM, Nicholas Wieland wrote: > >> Does someone have an example on faking a file upload for just >> ensuring it gets called > > http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin I haven't been clear enough, my point is not to fake the file upload (there's also fixture_file_upload for that) but to fake the receiver, making it dumb enough to avoid performing every operation on the file (in my case, uploading to s3). ngw -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2435 bytes Desc: not available URL: From ben at benmabey.com Mon Jun 9 14:11:13 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 09 Jun 2008 12:11:13 -0600 Subject: [rspec-users] Selenium/Watir usage along side Webrat in story testing In-Reply-To: References: Message-ID: <484D7241.9030501@benmabey.com> Joseph Wilk wrote: > Create two classes (this is already what MHS_testing has done for > Selenium) > > ---- > class RailsSeleniumStory < RailsStory > class RailsWebratStory < RailsStory > ---- > > Create a common interface for all shared functionailty. > > (I suspect Webrat represents the smallest set of functionality - > Selenium can do everything Webrat can do but not the other way around). > The different UI testing frameworks implement such interface giving > Selenium/Webrat/Other UI adapters. > > You choose which adapter to use by the story class. > > ... > > I'm not sure what direction MHS_testing or Rspec-ui are going, whether > they will merge? I'm looking at this problem now and want to start > contributing to whatever project is going to be the best fit. So I'm > interested to hear: > > *Feedback/discussion about this direction > *Any better ideas of solving the problem > *Any other frameworks out there were people have started to look at this > problem. > > -- > Joseph Wilk > http://www.joesniff.co.uk > Hey Joseph, Have you looked at webrat in github lately? http://github.com/brynary/webrat/tree/master Bryan is abstracting webrat so that different adapters can be plugged into it.. Meaning, the same wrappers/syntax can be used to drive rails, merb, mechanize, etc... I think a selenium or watir adapter for webrat would be awesome. I'm not too experienced with selenium but it doesn't strike me as being too hard to do. You make a good point in that webrat is a small subset of what the other JS aware frameworks can do but I think what webrat currently has would handle a lot of the use cases. One could then perhaps create an extension of webrat's language to form a uniform way of expressing JS/AJAX behaviour. The mechanize adapter idea is neat too, because you could then use it to test any website no matter what the implementation is. I know that part of Bryan's motivation behind the mechanize spike is to eventually use the stories to do performance testing as well. This is a problem I'm also interested in but I haven't yet needed to use selenium enough to make me want to do anything about it. :) I think the selenuim adapter for webrat approach would be a great way to approach this problem though. What do you think? -Ben From aslak.hellesoy at gmail.com Mon Jun 9 16:54:04 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Mon, 9 Jun 2008 22:54:04 +0200 Subject: [rspec-users] Selenium/Watir usage along side Webrat in story testing In-Reply-To: <484D7241.9030501@benmabey.com> References: <484D7241.9030501@benmabey.com> Message-ID: If Bryan wraps the webrat API around the Watir API, it can also be used against the new kid on the block: http://celerity.rubyforge.org, which implements the Watir API backed by JRuby and HTMLUnit - orders of magnitudes faster than Watir - and agnostic of webapp architecture (http based). This means webrat could be used against e.g. Java webapps. I'm planning on adding native webrat support to Cucumber (on Github) and you can see it in action in Ba (on Gitorious). Aslak. Sent from my iPhone On 9. juni. 2008, at 20.11, Ben Mabey wrote: > Joseph Wilk wrote: >> Create two classes (this is already what MHS_testing has done for >> Selenium) >> >> ---- >> class RailsSeleniumStory < RailsStory >> class RailsWebratStory < RailsStory >> ---- >> >> Create a common interface for all shared functionailty. >> >> (I suspect Webrat represents the smallest set of functionality - >> Selenium can do everything Webrat can do but not the other way >> around). >> The different UI testing frameworks implement such interface giving >> Selenium/Webrat/Other UI adapters. >> >> You choose which adapter to use by the story class. >> >> ... >> >> I'm not sure what direction MHS_testing or Rspec-ui are going, >> whether >> they will merge? I'm looking at this problem now and want to start >> contributing to whatever project is going to be the best fit. So I'm >> interested to hear: >> >> *Feedback/discussion about this direction >> *Any better ideas of solving the problem >> *Any other frameworks out there were people have started to look at >> this >> problem. >> >> -- >> Joseph Wilk >> http://www.joesniff.co.uk >> > > Hey Joseph, > Have you looked at webrat in github lately? http://github.com/brynary/webrat/tree/master > Bryan is abstracting webrat so that different adapters can be > plugged into it.. Meaning, the same wrappers/syntax can be used to > drive rails, merb, mechanize, etc... I think a selenium or watir > adapter for webrat would be awesome. I'm not too experienced with > selenium but it doesn't strike me as being too hard to do. You make > a good point in that webrat is a small subset of what the other JS > aware frameworks can do but I think what webrat currently has would > handle a lot of the use cases. One could then perhaps create an > extension of webrat's language to form a uniform way of expressing > JS/AJAX behaviour. > The mechanize adapter idea is neat too, because you could then use > it to test any website no matter what the implementation is. I know > that part of Bryan's motivation behind the mechanize spike is to > eventually use the stories to do performance testing as well. > > This is a problem I'm also interested in but I haven't yet needed to > use selenium enough to make me want to do anything about it. :) I > think the selenuim adapter for webrat approach would be a great way > to approach this problem though. What do you think? > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Mon Jun 9 17:18:51 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 9 Jun 2008 17:18:51 -0400 Subject: [rspec-users] Testing file attachment with Paperclip In-Reply-To: <267ADB18-AD00-48A9-BD51-1581A9EBCC43@gmail.com> References: <998249DD-DBC1-43C7-B3DD-41EDC97CCF88@gmail.com> <3C05EE2D-BD8F-41C1-8CA9-2427A0F1ADE8@gmail.com> <267ADB18-AD00-48A9-BD51-1581A9EBCC43@gmail.com> Message-ID: On Mon, Jun 9, 2008 at 8:18 AM, Nicholas Wieland wrote: > Il giorno 09/giu/08, alle ore 14:11, David Chelimsky ha scritto: > > On Jun 9, 2008, at 7:05 AM, Nicholas Wieland wrote: >> >> Does someone have an example on faking a file upload for just ensuring it >>> gets called >>> >> >> >> http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin >> > > I haven't been clear enough, my point is not to fake the file upload > (there's also fixture_file_upload for that) but to fake the receiver, making > it dumb enough to avoid performing every operation on the file (in my case, > uploading to s3). > I'm pretty sure the problem is that by the time you stub has_attached file, which is a class method run when the class is loaded, it's too late. Based on a quick look at the paperclip project site, it looks like what you want to stub is the save_attached_files method on the model INSTANCE, which the has_attached_file registers as an after_save callback. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramos.gaston at gmail.com Mon Jun 9 23:25:19 2008 From: ramos.gaston at gmail.com (Gaston Ramos) Date: Tue, 10 Jun 2008 00:25:19 -0300 Subject: [rspec-users] Refactoring's code needs refactoring's specs? Message-ID: <20080610032519.GA14105@marlasina> Hi guys, I have one question: When refactoring the working code I need or should refactoring the specs too? My old code is: http://pastie.org/private/gpskgtavm4yzutanq1ro3w My new refactored code: http://pastie.org/private/2emgi1hr5iga3m9jib4q and the specs that are still passing without refactoring: http://pastie.org/private/qn3uaoin0k2n8vjsusssg Regards. -- "Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." (Larry Wall) +-------------------------------------+ Gast?n Ramos http://gastonramos.wordpress.com/ GNU/Linux Counter user #450312 From raasdnil at gmail.com Tue Jun 10 01:05:51 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Tue, 10 Jun 2008 15:05:51 +1000 Subject: [rspec-users] Why has the --color gone from my life? In-Reply-To: <03EEC8AB-625A-4C36-8585-4782DA9F4E41@gmail.com> References: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> <03EEC8AB-625A-4C36-8585-4782DA9F4E41@gmail.com> Message-ID: <57a815bf0806092205v41f9a33el73e47af97a78c6e2@mail.gmail.com> This was fixed up updating to trunk: 3b76fda..befd422 master -> origin/master I now get colour, thanks all! Mikel On Sat, Jun 7, 2008 at 2:09 AM, David Chelimsky wrote: > On Jun 6, 2008, at 10:57 AM, Juanma Cervera wrote: > > This was an error, but I thought it was corrected by D. Chelimsky. >> > > That is correct - at least temporarily - there is a conflict with how rspec > and autotest output to a terminal that makes it challenging for rspec to > color code terminal output while not including the color code chars in html > output. > > If anybody is interested in helping to solve that, check out > http://rspec.lighthouseapp.com/projects/5645/tickets/413. > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhennemeyer at googlemail.com Tue Jun 10 02:58:23 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Tue, 10 Jun 2008 08:58:23 +0200 Subject: [rspec-users] Refactoring's code needs refactoring's specs? In-Reply-To: <20080610032519.GA14105@marlasina> References: <20080610032519.GA14105@marlasina> Message-ID: Pat Maddox posted about this: http://evang.eli.st/blog/2008/5/14/ refactoring-with-shared-example-groups Matthias. Am 10.06.2008 um 05:25 schrieb Gaston Ramos: > Hi guys, I have one question: > > When refactoring the working code I need or should refactoring the > specs too? > > My old code is: > > http://pastie.org/private/gpskgtavm4yzutanq1ro3w > > My new refactored code: > > http://pastie.org/private/2emgi1hr5iga3m9jib4q > > and the specs that are still passing without refactoring: > > http://pastie.org/private/qn3uaoin0k2n8vjsusssg > > Regards. > > > > -- > "Most of you are familiar with the virtues of a programmer. There > are three, of > course: laziness, impatience, and hubris." > > (Larry Wall) > > > +-------------------------------------+ > Gast?n Ramos > http://gastonramos.wordpress.com/ > GNU/Linux Counter user #450312 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aidy.lewis at googlemail.com Tue Jun 10 05:30:29 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Tue, 10 Jun 2008 02:30:29 -0700 Subject: [rspec-users] rspec logging Message-ID: <7ac2300c0806100230y7dfe498fp6c26f3e9f4d17620@mail.gmail.com> Hi, At the moment I am using the story runner with success. However, I would like to log to XML or HTML. Is there an API for this? Aidy From lists at ruby-forum.com Tue Jun 10 05:41:00 2008 From: lists at ruby-forum.com (Doug Livesey) Date: Tue, 10 Jun 2008 11:41:00 +0200 Subject: [rspec-users] Is there an equivalent to anything() for Hash parameters In-Reply-To: <26f77c8109402f61789e30179eb25e32@ruby-forum.com> References: <4beaa0e7094845590a199896a6520df9@ruby-forum.com> <937AC3C5-E675-498D-A404-F99F36212207@experthuman.com> <26f77c8109402f61789e30179eb25e32@ruby-forum.com> Message-ID: <177a97995da9e8ffff82f4aaeb8a6fe5@ruby-forum.com> Just a final word -- updated to the latest RSpec, and have been *loving* hash_including()! Cheers again for those responses! Doug. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Jun 10 12:10:11 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Tue, 10 Jun 2008 18:10:11 +0200 Subject: [rspec-users] Selenium/Watir usage along side Webrat in story testing In-Reply-To: <484D7241.9030501@benmabey.com> References: <484D7241.9030501@benmabey.com> Message-ID: My mind was stuck in Rspec but looking at this as an adapter for Webrat is a great idea. I've had a play with Webrat and a test Selenium adapter ala the Mechanize one. Things start to get a little tricky around having to have the domain defined first in the Selenium. Meaning in Selenium its hard to do: 1. visits('http://www.google.co.uk') 2. visits('http://www.monkeys.co.uk') Status codes are also not great fun (http://clearspace.openqa.org/message/8115#8115). I'll continue playing with this and see how easy it will be to squeeze Selenium into the Webrat box. >One could then perhaps create an extension of webrat's language to form >a uniform way of expressing JS/AJAX behavior. Sounds like a good idea. I guessing you mean some friendly wrapper to something like: 'xml_http_request' in ActionController::Integration::Session http://api.rubyonrails.com/classes/ActionController/Integration/Session.html#M000251 Aswell as just Ajax/JS stuff as an ability to perform more advanced interrogations (but always optional to keep the wonderful simplicity of Webrat's usage) would be a nice addition to Webrat. Something similar to Selenium's xpath like expressions. I'm not sure if Watir has something similar. The whole JS/AJAX behavior missing from Webrat has been making me look at the introduction of Server-side JS. Things like: Jaxer(http://www.aptana.com/jaxer) & Rhino(http://www.mozilla.org/rhino/). Whether its possible to push forward what JS Webrat can handle (be it that its never going to be a real browser). The real browser testing makes a lot of sense when examining different browsers JS/CSS processing but there are a lot of use-cases where simple DOM manipulation is good enough. http://www.magpiebrain.com/blog/2007/01/28/selenium-rocks-and-you-dont-need-it/ -- Joseph Wilk http://www.joesniff.co.uk Ben Mabey wrote: > Joseph Wilk wrote: >> (I suspect Webrat represents the smallest set of functionality - >> contributing to whatever project is going to be the best fit. So I'm >> > Hey Joseph, > Have you looked at webrat in github lately? > http://github.com/brynary/webrat/tree/master > Bryan is abstracting webrat so that different adapters can be plugged > into it.. Meaning, the same wrappers/syntax can be used to drive rails, > merb, mechanize, etc... I think a selenium or watir adapter for webrat > would be awesome. I'm not too experienced with selenium but it doesn't > strike me as being too hard to do. You make a good point in that webrat > is a small subset of what the other JS aware frameworks can do but I > think what webrat currently has would handle a lot of the use cases. > One could then perhaps create an extension of webrat's language to form > a uniform way of expressing JS/AJAX behaviour. > > The mechanize adapter idea is neat too, because you could then use it to > test any website no matter what the implementation is. I know that part > of Bryan's motivation behind the mechanize spike is to eventually use > the stories to do performance testing as well. > > This is a problem I'm also interested in but I haven't yet needed to use > selenium enough to make me want to do anything about it. :) I think the > selenuim adapter for webrat approach would be a great way to approach > this problem though. What do you think? > > -Ben -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Jun 10 13:18:12 2008 From: lists at ruby-forum.com (Ben Men) Date: Tue, 10 Jun 2008 19:18:12 +0200 Subject: [rspec-users] =?utf-8?q?RSpec_Story_-_SystemStackError=3A_stack_l?= =?utf-8?q?evel_too=09deep?= In-Reply-To: <1212929807.15422.19.camel@vox> References: <1212929807.15422.19.camel@vox> Message-ID: Willem van den Ende wrote: > Hi Ben, > > This is probably not an rspec issue, but a rails defect > ( http://dev.rubyonrails.org/ticket/10896 ). > >>From your code, I am assuming you are story testing a Rails app. I was > bitten by this too recently... Took me a while to figure it out. The > workaround is to replace > > post.id > > by > > post[:id] > > Thank you so much Willem, I only just saw your post and it did indeed fix my issue. -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Tue Jun 10 14:29:43 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 10 Jun 2008 12:29:43 -0600 Subject: [rspec-users] Selenium/Watir usage along side Webrat in story testing In-Reply-To: References: <484D7241.9030501@benmabey.com> Message-ID: <484EC817.6080606@benmabey.com> Joseph Wilk wrote: > My mind was stuck in Rspec but looking at this as an adapter for Webrat > is a great idea. > > I've had a play with Webrat and a test Selenium adapter ala the > Mechanize one. Things start to get a little tricky around having to have > the domain defined first in the Selenium. Meaning in Selenium its hard > to do: > > 1. visits('http://www.google.co.uk') > 2. visits('http://www.monkeys.co.uk') > > Status codes are also not great fun > (http://clearspace.openqa.org/message/8115#8115). I'll continue playing > with this and see how easy it will be to squeeze Selenium into the > Webrat box. > > >> One could then perhaps create an extension of webrat's language to form >> a uniform way of expressing JS/AJAX behavior. >> > > Sounds like a good idea. I guessing you mean some friendly wrapper to > something like: 'xml_http_request' in > ActionController::Integration::Session > http://api.rubyonrails.com/classes/ActionController/Integration/Session.html#M000251 > > Aswell as just Ajax/JS stuff as an ability to perform more advanced > interrogations (but always optional to keep the wonderful simplicity of > Webrat's usage) would be a nice addition to Webrat. Something similar to > Selenium's xpath like expressions. I'm not sure if Watir has something > similar. > > The whole JS/AJAX behavior missing from Webrat has been making me look > at the introduction of Server-side JS. Things like: > Jaxer(http://www.aptana.com/jaxer) & > Rhino(http://www.mozilla.org/rhino/). Whether its possible to push > forward what JS Webrat can handle (be it that its never going to be a > real browser). > The real browser testing makes a lot of sense when examining different > browsers JS/CSS processing but there are a lot of use-cases where simple > DOM manipulation is good enough. > http://www.magpiebrain.com/blog/2007/01/28/selenium-rocks-and-you-dont-need-it/ > > Very cool. Keep me posted on your progress. I would love to jump in and help but I don't have the bandwidth to do so quite yet... soon though. The post you linked to at the bottom talking about HTTPUnit is interesting. The project that Aslak mentioned is basically a JRuby wrapper for HTTPUnit using the watir API... So, as Aslak suggested if we had a webrat adapter for watir then we would not only get waitir support but HTTPUnit capabilities! That would be three wrappers! I'm a little confused by the JS capabilities of HTTPUnit... on the bottom of that post the author made a comment: " anything (not just Javascript) which manipulates the DOM after the page has been served will require in-browser testing ? either manual or automated." Does anyone have experience with HTTPUnit? My understanding of HTTPUnit is that it will process the JS after the page loaded (and there FAQ seems to suggest this as well.) Most of my sites use unobtrusive JS, meaning it all works without JS but then JS is used to add additional user interfaced niceties (AJAX, effects, etc..) So will HTTPUnit process the JS and update the DOM accordingly? This is probably the wrong mailing list to answer this, but if anyone has had experience with HTTPUnit please share. -Ben From jari.bakken at finntech.no Tue Jun 10 15:25:36 2008 From: jari.bakken at finntech.no (jari.bakken at finntech.no) Date: Tue, 10 Jun 2008 21:25:36 +0200 Subject: [rspec-users] Selenium/Watir usage along side Webrat in story testing In-Reply-To: <484EC817.6080606@benmabey.com> Message-ID: <91BE0AA2DBCB614592BEB6DF2E560CC90461D40A@sch-mail-07.schibsted.no> Hi Ben, > I'm a little confused by the JS capabilities of HTTPUnit... You're confusing HTTPUnit with HtmlUnit. We chose HtmlUnit for Celerity partly because they seem to care a lot about JavaScript support. Here's a comparison of the two (by a HtmlUnit committer, but still ;) http://daniel.gredler.net/2007/10/04/htmlunit-vs-httpunit/ A Watir adapter for WebRat sounds like a great idea. Jari From ben at benmabey.com Tue Jun 10 15:42:52 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 10 Jun 2008 13:42:52 -0600 Subject: [rspec-users] Selenium/Watir usage along side Webrat in story testing In-Reply-To: <91BE0AA2DBCB614592BEB6DF2E560CC90461D40A@sch-mail-07.schibsted.no> References: <91BE0AA2DBCB614592BEB6DF2E560CC90461D40A@sch-mail-07.schibsted.no> Message-ID: <484ED93C.1000908@benmabey.com> jari.bakken at finntech.no wrote: > Hi Ben, > > >> I'm a little confused by the JS capabilities of HTTPUnit... >> > > You're confusing HTTPUnit with HtmlUnit. We chose HtmlUnit for Celerity > partly because they seem to care a lot about JavaScript support. > > Here's a comparison of the two (by a HtmlUnit committer, but still ;) > > http://daniel.gredler.net/2007/10/04/htmlunit-vs-httpunit/ > > A Watir adapter for WebRat sounds like a great idea. > > Jari > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Ahh... I see. Thanks for the link. Those names are easily confused.... -Ben From cremes.devlist at mac.com Wed Jun 11 13:06:19 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 11 Jun 2008 12:06:19 -0500 Subject: [rspec-users] help with test design Message-ID: I'm having trouble figuring out how to drive the design of a class. I'm hoping I can get a hint or two from the more experienced BDDers on this list. I'm writing an adapter class that sits between a 3rd party library and my business logic. I would like to extract some information from objects available from the 3rd party lib and covert them into ruby objects. My desire is to insulate my ruby business logic from changes in the 3rd party library by putting all of this conversion code into a single adapter class (and some related "event" classes). Using BDD techniques I have created a pretty simple interface to the adapter class. So far the adapter class has two main public methods (plus a bunch of accessors to allow the dependency injection). #discover_instruments - this method calls into the 3rd party library and pulls out the 3rdPartyInstrument object and stores it off for further manipulation #save_components - this method permanently saves the 3rdPartyInstrument if it is a FUTURE, or if it is a COMBINATION it iterates through each sub-3rdPartyInstrument and saves it off Using mocks and ruby's brain-dead simple support for dependency injection I have been able to mock out and verify this behavior. Now I need to add another public method which I will call #generate_internal_instruments. What I would like this method to do is iterate through my #components and create two related objects. Object one will be my RubyInstrument class (called something else, but this will suffice) and a second is a RubyInstrumentCreationEvent. The intention is to pass the 3rdParty component to RubyInstrumentCreationEvent.new(component) where it will extract all salient details from the 3rdParty component (again, this is for insulating the business logic from knowing this 3rd Party lib). Then I will pass this RubyInstrumentCreationEvent to RubyInstrument.new (or RubyInstrument.build) where it will finish the construction of itself. Ideally, all of these steps would be private to the Adapter class and would expose a single public interface called #build. All of these public methods exist solely so I can test these specific behaviors. Any suggestions on how to accomplish my goals? Is my difficulty pointing at a code smell that I am not detecting? cr From byrnejb at harte-lyne.ca Wed Jun 11 14:53:28 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Wed, 11 Jun 2008 14:53:28 -0400 (EDT) Subject: [rspec-users] rspec and rspec-rails install hell Message-ID: <4522.12.10.246.2.1213210408.squirrel@webmail.harte-lyne.ca> I am attending a training course covering rspec. I am using a MS WinXPpro SP3 machine. I have installed the cygwin environment. I am using git 1.5.4. I am using ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] and rails 2.0.2 (albeit rails 2.1.0 is installed as well) I had to install rspec-rails and rspec via git and as a gem. Problem 1. If one goes to the rspec.info website and links through to download one sees: >From source (at github) http://github.com/dchelimsky/rspec/wikis/home http://github.com/dchelimsky/rspec-rails/wikis/home BUT! If one tries to install via git-clone form this repository one sees this! C:\temp\>git clone http://github.com/dchelimsky/rspec/wikis/home /tmprspec Initialized empty Git repository in /tmprspec/.git/ Cannot get remote repository information. Perhaps git-update-server-info needs to be run there? Poking around one finds buried under Documentation >> Spec::Rails >> Install a link to github wherein one sees this: Install RSpec?s edge for rails <= 2.0.2 cd vendor/plugins git clone git://github.com/dchelimsky/rspec.git git clone git://github.com/dchelimsky/rspec-rails.git cd ../../ script/generate rspec The git repository works. But, this leads to problem 2. > ruby script/generate rspec Couldn't find 'rspec' generator Now What???!!! So, poking around the googlespace I find reference to gem install rspec_generator so, I do that: > gem install rspec_generator Successfully installed rspec-0.5.15 Successfully installed rspec_generator-0.5.15 2 gems installed Installing ri documentation for rspec-0.5.15... Installing RDoc documentation for rspec-0.5.15... rspec-0.5.15 ???? Ok, now I have 1. rspec-0.5.15 2. rspec-1.1.4 installed and the latest from github in my project, which is required because I need rspec-rails. So, I run ruby script/generate rspec and then I encounter: Problem 3. >rake spec (in C:/temp/tmprspec) C:/temp/labs/08_rspec_rails/prag_hotel/vendor/plugins/rspec-rails/lib/spec/rails /version.rb:11: (RuntimeError) ############################################################################ Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 20080526202855 RSpec on Rails : 20080608062339 Make sure your RSpec on Rails plugin is compatible with your RSpec gem. See http://rspec.rubyforge.org/documentation/rails/install.html for details. ############################################################################ Bearing in mind that I have JUST THIS INSTANT installed both the gem rspec and the plugins this leaves me somewhat nonplussed. However, sycn problems do happen so now I do this: > gem uninstall rspec Select gem to uninstall: 1. rspec-0.5.15 2. rspec-1.1.4 3. All versions > 3 You have requested to uninstall the gem: rspec-0.5.15 rspec_generator-0.5.15 depends on [rspec (= 0.5.15)] If you remove this gems, one or more dependencies will not be met. Continue with Uninstall? [Yn] y Successfully uninstalled rspec-0.5.15 Successfully uninstalled rspec-1.1.4 Remove executables: spec, spec_translator in addition to the gem? [Yn] y Removing spec Removing spec_translator Which leads to Problem 5. C:\temp\labs\08_rspec_rails\prag_hotel>rake spec (in C:/temp/labs/08_rspec_rails/prag_hotel) rake aborted! no such file to load -- spec/rake/spectask C:/temp/labs/08_rspec_rails/prag_hotel/rakefile:10 (See full trace by running task with --trace) So, can anybody tell me if Rspec even runs on Windows any more? -- *** 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 Wed Jun 11 15:07:36 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 11 Jun 2008 14:07:36 -0500 Subject: [rspec-users] rspec and rspec-rails install hell In-Reply-To: <4522.12.10.246.2.1213210408.squirrel@webmail.harte-lyne.ca> References: <4522.12.10.246.2.1213210408.squirrel@webmail.harte-lyne.ca> Message-ID: On Jun 11, 2008, at 1:53 PM, James B. Byrne wrote: > > I am attending a training course covering rspec. Cool - I'd like to hear about it. > I am using a MS WinXPpro SP3 > machine. I have installed the cygwin environment. I am using git > 1.5.4. I am > using ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] and > rails 2.0.2 > (albeit rails 2.1.0 is installed as well) > > I had to install rspec-rails and rspec via git and as a gem. > > Problem 1. > > If one goes to the rspec.info website and links through to download > one sees: > >> From source (at github) > > http://github.com/dchelimsky/rspec/wikis/home > http://github.com/dchelimsky/rspec-rails/wikis/home > > BUT! If one tries to install via git-clone form this repository one > sees this! > > C:\temp\>git clone http://github.com/dchelimsky/rspec/wikis/home / > tmprspec > Initialized empty Git repository in /tmprspec/.git/ > Cannot get remote repository information. > Perhaps git-update-server-info needs to be run there? > > Poking around one finds buried under Documentation >> Spec::Rails >> > Install > a link to github wherein one sees this: > > Install RSpec?s edge for rails <= 2.0.2 > > cd vendor/plugins > git clone git://github.com/dchelimsky/rspec.git > git clone git://github.com/dchelimsky/rspec-rails.git > cd ../../ > script/generate rspec > > The git repository works. > > But, this leads to problem 2. > >> ruby script/generate rspec > Couldn't find 'rspec' generator > > Now What???!!! > > So, poking around the googlespace I find reference to gem install > rspec_generator so, I do that: > >> gem install rspec_generator > Successfully installed rspec-0.5.15 > Successfully installed rspec_generator-0.5.15 > 2 gems installed > Installing ri documentation for rspec-0.5.15... > Installing RDoc documentation for rspec-0.5.15... > > rspec-0.5.15 ???? > > Ok, now I have > 1. rspec-0.5.15 > 2. rspec-1.1.4 > > installed and the latest from github in my project, which is > required because > I need rspec-rails. So, I run ruby script/generate rspec and then I > encounter: > > Problem 3. > >> rake spec > (in C:/temp/tmprspec) > C:/temp/labs/08_rspec_rails/prag_hotel/vendor/plugins/rspec-rails/ > lib/spec/rails > /version.rb:11: (RuntimeError) > ############################################################################ > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > RSpec : 20080526202855 > RSpec on Rails : 20080608062339 This was because you pulled rspec and rspec-rails at different times. Make sure you always update both at the same time. > > > Make sure your RSpec on Rails plugin is compatible with your RSpec > gem. > See http://rspec.rubyforge.org/documentation/rails/install.html for > details. > ############################################################################ > > Bearing in mind that I have JUST THIS INSTANT installed both the gem > rspec and > the plugins this leaves me somewhat nonplussed. However, sycn > problems do > happen so now I do this: > >> gem uninstall rspec > > Select gem to uninstall: > 1. rspec-0.5.15 > 2. rspec-1.1.4 > 3. All versions >> 3 > > You have requested to uninstall the gem: > rspec-0.5.15 > rspec_generator-0.5.15 depends on [rspec (= 0.5.15)] > If you remove this gems, one or more dependencies will not be met. > Continue with Uninstall? [Yn] y > Successfully uninstalled rspec-0.5.15 > Successfully uninstalled rspec-1.1.4 > Remove executables: > spec, spec_translator > > in addition to the gem? [Yn] y > Removing spec > Removing spec_translator > > Which leads to > > Problem 5. > > C:\temp\labs\08_rspec_rails\prag_hotel>rake spec > (in C:/temp/labs/08_rspec_rails/prag_hotel) > rake aborted! > no such file to load -- spec/rake/spectask > C:/temp/labs/08_rspec_rails/prag_hotel/rakefile:10 > (See full trace by running task with --trace) > > So, can anybody tell me if Rspec even runs on Windows any more? > What a drag - sorry you went through all that. rspec_generator-0.5.15 and rspec-0.5.15 are old, old, old and unrelated to anything useful today. Get rid of them. Here's what I'd do: Make sure you do not have any rspec related plugins in vendor/plugins and follow the directions from the wiki again: cd vendor/plugins git clone git://github.com/dchelimsky/rspec.git git clone git://github.com/dchelimsky/rspec-rails.git cd ../../ script/generate rspec There's no reason that shouldn't work. Cheers, David > -- > *** 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 pergesu at gmail.com Wed Jun 11 15:09:06 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 11 Jun 2008 12:09:06 -0700 Subject: [rspec-users] help with test design In-Reply-To: References: Message-ID: <810a540e0806111209g395c5b13ia11ebb918ace1a10@mail.gmail.com> On Wed, Jun 11, 2008 at 10:06 AM, Chuck Remes wrote: > Ideally, all of these steps would be private to the Adapter class and would > expose a single public interface called #build. All of these public methods > exist solely so I can test these specific behaviors. > > Any suggestions on how to accomplish my goals? Is my difficulty pointing at > a code smell that I am not detecting? I feel a bit brain-dead today, so take this with a grain of salt...but after reading through your email several times, I'm not sure what your goals are, what you've currently tried, and what particular problems you're experiencing. Pat From dchelimsky at gmail.com Wed Jun 11 15:10:46 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 11 Jun 2008 14:10:46 -0500 Subject: [rspec-users] rspec and rspec-rails install hell In-Reply-To: <4522.12.10.246.2.1213210408.squirrel@webmail.harte-lyne.ca> References: <4522.12.10.246.2.1213210408.squirrel@webmail.harte-lyne.ca> Message-ID: <7F266778-B21F-44B5-A88E-D8344B07800A@gmail.com> On Jun 11, 2008, at 1:53 PM, James B. Byrne wrote: > Problem 1. > > If one goes to the rspec.info website and links through to download > one sees: > >> From source (at github) > > http://github.com/dchelimsky/rspec/wikis/home > http://github.com/dchelimsky/rspec-rails/wikis/home Ah - doco problem - that was not intended to be download links, but information links. I'll make that more clear. From dchelimsky at gmail.com Wed Jun 11 15:25:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 11 Jun 2008 14:25:23 -0500 Subject: [rspec-users] help with test design In-Reply-To: References: Message-ID: On Jun 11, 2008, at 12:06 PM, Chuck Remes wrote: > I'm having trouble figuring out how to drive the design of a class. > I'm hoping I can get a hint or two from the more experienced BDDers > on this list. > > I'm writing an adapter class that sits between a 3rd party library > and my business logic. I would like to extract some information from > objects available from the 3rd party lib and covert them into ruby > objects. My desire is to insulate my ruby business logic from > changes in the 3rd party library by putting all of this conversion > code into a single adapter class (and some related "event" classes). > > Using BDD techniques I have created a pretty simple interface to > the adapter class. So far the adapter class has two main public > methods (plus a bunch of accessors to allow the dependency injection). > > #discover_instruments > - this method calls into the 3rd party library and pulls out the > 3rdPartyInstrument object and stores it off for further manipulation > > #save_components > - this method permanently saves the 3rdPartyInstrument if it is a > FUTURE, or if it is a COMBINATION it iterates through each > sub-3rdPartyInstrument and saves it off > > Using mocks and ruby's brain-dead simple support for dependency > injection I have been able to mock out and verify this behavior. > > Now I need to add another public method which I will call > #generate_internal_instruments. What I would like this method to do > is iterate through my #components and create two related objects. > Object one will be my RubyInstrument class (called something else, > but this will suffice) and a second is a > RubyInstrumentCreationEvent. The intention is to pass the 3rdParty > component to RubyInstrumentCreationEvent.new(component) where it > will extract all salient details from the 3rdParty component (again, > this is for insulating the business logic from knowing this 3rd > Party lib). Then I will pass this RubyInstrumentCreationEvent to > RubyInstrument.new (or RubyInstrument.build) where it will finish > the construction of itself. > > Ideally, all of these steps would be private to the Adapter class > and would expose a single public interface called #build. All of > these public methods exist solely so I can test these specific > behaviors. > > Any suggestions on how to accomplish my goals? Is my difficulty > pointing at a code smell that I am not detecting? Hey Chuck - sounds like you're trying to plan the whole process out up front. TDD is about discovery. Here's what I'd recommend: Start w/ a simple example of what you want the adapter to do - the simplest think you can think of - when you send it the #generate_internal_instruments message. Get that to pass. Now the next simplest thing. Get that to pass. Refactor. Rinse. Repeat. As you do this, the method might start to do too much and you'll see opportunities to break it up into smaller private methods or perhaps even methods on a brand new object you don't know about yet. That's all good. Let the design emerge. If/when you do choose to move things out to other classes, you may want to introduce new mocks in the examples and move some of the examples to the group describing the new object. That's all fine. Don't anticipate code smells, but keep sniffing. When you *do* smell them, deal with them immediately. Don't wait. HTH, David From mike.sch.list at gmail.com Thu Jun 12 02:40:43 2008 From: mike.sch.list at gmail.com (Mike Schiller) Date: Thu, 12 Jun 2008 15:40:43 +0900 Subject: [rspec-users] Which "get" is being used in Controller spec Message-ID: <6a39e69d0806112340s5cedd516q9c3c0fb437c3883c@mail.gmail.com> Hi, I'm a bit puzzled with "get" in controller specs. When I write, it "should render index template" do get :index response.should render_template(:index) end Which "get" method is being used? I checked RDoc of RSpec and RSpec on Rails, but didn't find "get". In Rails RDoc, I found the following "get"s. get ActionController::Integration::Session get ActiveResource::Connection get ActiveResource::CustomMethods get ActiveResource::CustomMethods::InstanceMethods I'm not sure which one is working. But after playing a while, I noticed "get" doesn't take "path" as a parameter. For example, get "users" doesn't work. I also need to know about "post" because some code I saw seems to be passing parameters like: post :create :id => 1 Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikemondragon at gmail.com Thu Jun 12 05:03:10 2008 From: mikemondragon at gmail.com (Mike Mondragon) Date: Thu, 12 Jun 2008 02:03:10 -0700 Subject: [rspec-users] map.resources :foo_items, :as => :foo confusing my controller specs Message-ID: <967d3b9a0806120203w2f19a258m49922a63c049abc0@mail.gmail.com> I have following resource defined in my config/routes.rb (the model name is contrived) map.resources :foo_items, :as => :foo that I originally generated with rspec_scaffold: ruby script/generate rspec_scaffold foo_item but when I use the :as attribute in resources to make the URI path be '/foo' instead of '/foo_items' the default/generated controller specs for AdAssetsController become broken e.g. it "should be successful" do do_get response.should be_success end 'FooItemsController route generation should map { :controller => 'foo_items', :action => 'index' } to /foo_items' FAILED expected: "/foo_items", got: "/foo (using ==) How can I make my controller spec honor the modified resource? I searched through rspec group mail list to see if anyone else had this problem. Another person asked about it but it was not addressed. I also poked around the rspec code and documentation before resorting to mailing the list. Thanks mike -- Mike Mondragon Work> http://sas.quat.ch/ Blog> http://blog.mondragon.cc/ From mhennemeyer at googlemail.com Thu Jun 12 05:03:10 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Thu, 12 Jun 2008 11:03:10 +0200 Subject: [rspec-users] Which "get" is being used in Controller spec In-Reply-To: <6a39e69d0806112340s5cedd516q9c3c0fb437c3883c@mail.gmail.com> References: <6a39e69d0806112340s5cedd516q9c3c0fb437c3883c@mail.gmail.com> Message-ID: <49CDF86F-B2D1-4F93-95D3-5B2F89301F71@googlemail.com> Hi Mike, the request methods used in Controller tests are defined in Rails: ActionController::TestProcess. Rspec Rails Stories are basically Rails Integration tests and the methods used here are defined in Rails: ActionController::Integration::Session. Matthias Am 12.06.2008 um 08:40 schrieb Mike Schiller: > Hi, > > I'm a bit puzzled with "get" in controller specs. When I write, > > it "should render index template" do > get :index > response.should render_template(:index) > end > > > Which "get" method is being used? I checked RDoc of RSpec and RSpec > on Rails, but didn't find "get". > In Rails RDoc, I found the following "get"s. > > get ActionController::Integration::Session > get ActiveResource::Connection > get ActiveResource::CustomMethods > get ActiveResource::CustomMethods::InstanceMethods > > I'm not sure which one is working. But after playing a while, I > noticed "get" doesn't take "path" as a parameter. For example, > > get "users" > > doesn't work. I also need to know about "post" because some code I > saw seems to be passing > parameters like: > > post :create :id => 1 > > Mike > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jarmo.p at gmail.com Thu Jun 12 06:21:02 2008 From: jarmo.p at gmail.com (kasutaja) Date: Thu, 12 Jun 2008 03:21:02 -0700 (PDT) Subject: [rspec-users] after :each invoked before formatter? Message-ID: <17796760.post@talk.nabble.com> Hello. I'm using RSpec with Watir to do some automated tests on IE. I've ran into problem, where I want to make a screenshot of a browser window when example fails. For that I made custom formatter where in extra_failure_content i'm invoking screenshot taking methods. Now, everything works like a charm, as long as I'm not using after :each. I remember that I had this problem before with after :all with version 1.0.8 (at the moment I'm using 1.1.4). In after :each block I'm invoking Watir to close IE (and maybe some other stuff). So if each example finishes, IE is closed. Now, my logic is telling me that after example has failed, formatter's methods should be invoked (as example_failed or extra_failure_content methods), but it's not like that! Those methods are called AFTER after :each block has finished. So, at the moment it's like that: 1) it block executes 2) it block failed 3) after :each block executes 4) formatter's example_failed and extra_failure_content methods are executed shouldn't be step 4 before step 3? With after :all, everything is working as expected (so steps are executed as 1,2,4,3 with one failing it method in describe block). So the problem in my case is that when screenshot taking methods are invoked, IE has already been closed - thus unable to get any screenshots. As I mentioned before, everything was working alright with after :each in rspec 1.0.8, but the problem was with after :all... now the problem is vice-versa. Any ideas or suggestions or temporary patches? Thank You for great framework! -- View this message in context: http://www.nabble.com/after-%3Aeach-invoked-before-formatter--tp17796760p17796760.html Sent from the rspec-users mailing list archive at Nabble.com. From jarmo.p at gmail.com Thu Jun 12 07:03:58 2008 From: jarmo.p at gmail.com (kasutaja) Date: Thu, 12 Jun 2008 04:03:58 -0700 (PDT) Subject: [rspec-users] after :each invoked before formatter? In-Reply-To: <17796760.post@talk.nabble.com> References: <17796760.post@talk.nabble.com> Message-ID: <17797371.post@talk.nabble.com> I just reverted all my files from svn to revision prior upgrading rspec and it still doesn't work 8-) which might mean that I've ran out of ideas as to why was it working before and not anymore... kasutaja wrote: > > As I mentioned before, everything was working alright with after :each in > rspec 1.0.8, but the problem was with after :all... now the problem is > vice-versa. > -- View this message in context: http://www.nabble.com/after-%3Aeach-invoked-before-formatter--tp17796760p17797371.html Sent from the rspec-users mailing list archive at Nabble.com. From jarmo.p at gmail.com Thu Jun 12 07:12:32 2008 From: jarmo.p at gmail.com (kasutaja) Date: Thu, 12 Jun 2008 04:12:32 -0700 (PDT) Subject: [rspec-users] after :each invoked before formatter? In-Reply-To: <17797371.post@talk.nabble.com> References: <17796760.post@talk.nabble.com> <17797371.post@talk.nabble.com> Message-ID: <17797475.post@talk.nabble.com> Sorry for spamming. I just solved the problem. It was my close_browser method, which handled thread differently after refactoring. And I've confirmed that after :each was executed prior failure methods in formatter in RSpec 1.0.8 too. So, the question still remains - shouldn't these methods be invoked before "after" blocks? -- View this message in context: http://www.nabble.com/after-%3Aeach-invoked-before-formatter--tp17796760p17797475.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Thu Jun 12 07:28:46 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 12 Jun 2008 06:28:46 -0500 Subject: [rspec-users] after :each invoked before formatter? In-Reply-To: <17797475.post@talk.nabble.com> References: <17796760.post@talk.nabble.com> <17797371.post@talk.nabble.com> <17797475.post@talk.nabble.com> Message-ID: <179D1E2F-966F-40DC-A967-9911F11FCFBA@gmail.com> On Jun 12, 2008, at 6:12 AM, kasutaja wrote: > Sorry for spamming. I just solved the problem. It was my close_browser > method, which handled thread differently after refactoring. > > And I've confirmed that after :each was executed prior failure > methods in > formatter in RSpec 1.0.8 too. So, the question still remains - > shouldn't > these methods be invoked before "after" blocks? I don't think so. If we did that and something was failing in the 'after' blocks, you'd not see that reported. Make sense? From dchelimsky at gmail.com Thu Jun 12 07:35:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 12 Jun 2008 06:35:01 -0500 Subject: [rspec-users] map.resources :foo_items, :as => :foo confusing my controller specs In-Reply-To: <967d3b9a0806120203w2f19a258m49922a63c049abc0@mail.gmail.com> References: <967d3b9a0806120203w2f19a258m49922a63c049abc0@mail.gmail.com> Message-ID: <04C3B36B-C7B1-4C75-B7E4-9BDA87088D0E@gmail.com> On Jun 12, 2008, at 4:03 AM, Mike Mondragon wrote: > I have following resource defined in my config/routes.rb (the model > name is contrived) > > map.resources :foo_items, :as => :foo > > that I originally generated with rspec_scaffold: > > ruby script/generate rspec_scaffold foo_item > > but when I use the :as attribute in resources to make the URI path be > '/foo' instead of '/foo_items' the default/generated controller specs > for AdAssetsController become broken e.g. > > it "should be successful" do > do_get > response.should be_success > end > > 'FooItemsController route generation should map { :controller => > 'foo_items', :action => 'index' } to /foo_items' FAILED > expected: "/foo_items", > got: "/foo (using ==) > > How can I make my controller spec honor the modified resource? Sounds like either a bug or a missing feature. Please enter a ticket at the lighthouse: http://rspec.lighthouseapp.com > I searched through rspec group mail list to see if anyone else had > this problem. Another person asked about it but it was not addressed. > I also poked around the rspec code and documentation before resorting > to mailing the list. > > Thanks > mike > > -- > Mike Mondragon > Work> http://sas.quat.ch/ > Blog> http://blog.mondragon.cc/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From twscannell at gmail.com Thu Jun 12 11:00:41 2008 From: twscannell at gmail.com (TW Scannell) Date: Thu, 12 Jun 2008 08:00:41 -0700 Subject: [rspec-users] Looking for rspec learning resources. Message-ID: <12f0ca280806120800x5bc9228h609d6c1d9b7c563f@mail.gmail.com> Hi, I am at the point in my Rails learning journey where I need to cross the rspec river and need instructions on how to build a boat. Having spent a year learning Rails, one of the biggest traps has been the waste of effort caused by reading outdated material. I see David's page, which looks great, is dated May 14th 2007. Can anyone tell me if there are any parts of that page that have changed due to newer releases? I have the Peepcode movies and Obie's "The Ruby Way", both of which seem to have good info. Are there any other current resources out there that y'all recommend Thanks in advance. twscannell at that "Gee Mail" place. From jarmo.p at gmail.com Thu Jun 12 11:45:35 2008 From: jarmo.p at gmail.com (kasutaja) Date: Thu, 12 Jun 2008 08:45:35 -0700 (PDT) Subject: [rspec-users] after :each invoked before formatter? In-Reply-To: <179D1E2F-966F-40DC-A967-9911F11FCFBA@gmail.com> References: <17796760.post@talk.nabble.com> <17797371.post@talk.nabble.com> <17797475.post@talk.nabble.com> <179D1E2F-966F-40DC-A967-9911F11FCFBA@gmail.com> Message-ID: <17803189.post@talk.nabble.com> Hmm. How come? As far as I've understood so far, then reports are generated it-method-by-it-method. So, why couldn't RSpec handle after :each methods similar to it-methods? So it would go something like this: -invoke it method -it method fails -invoke reporter's methods to generate report for failing it-method -invoke after :each method -something fails in after :each block -invoke reporter's methods to generate report for failing after :each method -invoke next-it and so on I don't see any problems (maybe i'm just too narrow-minded, hehe) with that solution. Please be more specific if you still think that there is problem. David Chelimsky-2 wrote: > > I don't think so. If we did that and something was failing in the > 'after' blocks, you'd not see that reported. Make sense? > -- View this message in context: http://www.nabble.com/after-%3Aeach-invoked-before-formatter--tp17796760p17803189.html Sent from the rspec-users mailing list archive at Nabble.com. From mikemondragon at gmail.com Thu Jun 12 15:00:09 2008 From: mikemondragon at gmail.com (Mike Mondragon) Date: Thu, 12 Jun 2008 12:00:09 -0700 Subject: [rspec-users] disregard my map.resources :foo_items, :as => :foo question Message-ID: <967d3b9a0806121200x7f273050s1aa1b0d43e98d1e5@mail.gmail.com> disregard my map.resources :foo_items, :as => :foo question I was pulling some rookie moves. Thanks Mike -- Mike Mondragon Work> http://sas.quat.ch/ Blog> http://blog.mondragon.cc/ From rick.denatale at gmail.com Thu Jun 12 16:44:15 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 12 Jun 2008 16:44:15 -0400 Subject: [rspec-users] named_scope doesn't check for critical method names. Message-ID: I just entered this ticket. http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/404-named_scope-bashes-critical-methods It turns out that in an ActiveRecord model like this Model << ActiveRecord::Base named_scope :public private def private_method end public def public_method end end The method public_method will be private because named scope overrides Ruby's public method! Also this can cause additionally hard to debug failures in metaprogramming, I discovered this when the RSpec stub! method blew up when it used class_eval to generate a stub method which apparently caused public to be called internally by Ruby, at which time the named_scope generated method failed. See the ticket for details. I'm not sure what the fix should be, but I think that named_scope should not cause public/private, and the like to be clobbered. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Thu Jun 12 17:25:47 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 12 Jun 2008 17:25:47 -0400 Subject: [rspec-users] Mysterious interaction between RSpec 1.1.4 and has_finder/named_scope Message-ID: I just opened a Rails ticket on a problem with named_scope in Rails 2.1, and cross-posted a message here which I send to rails-core. I'm still a bit mystified, because I'm having a problem caused by this on RSpec 1.1.4, but not on 1.1.3, and I don't see a difference in code which would explain it. The basic problem, which I encountered upgrading our rails app to RSpec 1.1.4 was a case like this: class SpaceFile < ActiveRecord::Base named_scope :public ... end In a spec I have code like this: ... 11: model = Model.new 12: model.stub!(:path).and_return("x/y") NoMethodError in 'SpaceFile be readable' You have a nil object when you didn't expect it! The error occurred while evaluating nil.call /Users/rick/near-time/near-time.net-exp-migrate-to-rspec-1-1-4-6750/spec/models/space_file_spec.rb:12: What's happening is when Spec::Mocks::Proxy.define_expected_method uses class_eval to define the stub method, Ruby is calling public under the covers but instead of getting the standard method which makes the method public, it ends up calling the method generated by the named_scope method which tries to get a proc from an empty hash, and ends up trying to send call to nil. What I can't figure out is why this is failing under RSpec 1.1.4, but it doesn't fail under 1.1.3, the code I've looked at doesn't seem to have changed. Any ideas? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniellibanori at gmail.com Thu Jun 12 18:14:11 2008 From: daniellibanori at gmail.com (Daniel Libanori) Date: Thu, 12 Jun 2008 19:14:11 -0300 Subject: [rspec-users] Use of 'should' in another thread Message-ID: <1213308851.7267.6.camel@mersault> Hi, I've tried to find anything about using 'should' within a Thread, but it is a little hard do look up there, so I hope you forgive-me if I am asking an "old question". I guess this spec should fail: describe Thread do it "must be fine" do Thread.new { true.should_not be_true } # Why don't fail?! end end It seems that some parts of RSpec are not thread safe. Right? Thanks From dchelimsky at gmail.com Thu Jun 12 18:16:59 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 12 Jun 2008 17:16:59 -0500 Subject: [rspec-users] Use of 'should' in another thread In-Reply-To: <1213308851.7267.6.camel@mersault> References: <1213308851.7267.6.camel@mersault> Message-ID: <47272DA6-56AE-437D-808B-08B818323EEF@gmail.com> On Jun 12, 2008, at 5:14 PM, Daniel Libanori wrote: > Hi, > > I've tried to find anything about using 'should' within a Thread, but > it is a little hard do look up there, so I hope you forgive-me if I am > asking an "old question". > > I guess this spec should fail: > > describe Thread do > it "must be fine" do > Thread.new { true.should_not be_true } # Why don't fail?! > end > end > > It seems that some parts of RSpec are not thread safe. Right? If that's running in a separate Thread and you're not getting any feedback, that suggests to me that it is in fact thread safe. Unless I'm missing something. Which is entirely possible. Cheers, David From rick.denatale at gmail.com Thu Jun 12 18:54:31 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 12 Jun 2008 18:54:31 -0400 Subject: [rspec-users] Use of 'should' in another thread In-Reply-To: <1213308851.7267.6.camel@mersault> References: <1213308851.7267.6.camel@mersault> Message-ID: On Thu, Jun 12, 2008 at 6:14 PM, Daniel Libanori wrote: > Hi, > > I've tried to find anything about using 'should' within a Thread, but > it is a little hard do look up there, so I hope you forgive-me if I am > asking an "old question". > > I guess this spec should fail: > > describe Thread do > it "must be fine" do > Thread.new { true.should_not be_true } # Why don't fail?! > end > end > No, it's because you aren't waiting for the thread. Try: describe Thread do it "must be fine" do t = Thread.new { true.should_not be_true } t.join end end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From eagerwombat at gmail.com Thu Jun 12 18:56:49 2008 From: eagerwombat at gmail.com (john) Date: Thu, 12 Jun 2008 15:56:49 -0700 Subject: [rspec-users] how do I mock the Rails Logger with should_receive? Message-ID: <5b1b5e890806121556w2a5c7cc2p246ac6dcf3a1de24@mail.gmail.com> Hey Guys, I'm trying to mock the Rails Logger for the following code: ... rescue TimeoutError => error $logger.error("#{self.name} Timeout for #{path}: #{error}") and return rescue SocketError => error $logger.error("#{self.name} SocketError for #{path}: #{error}") and return rescue StandardError => error $logger.error("#{self.name} Error for #{path}: #{error}") and return end ... my failed attempt to spec: logger = mock_model(Logger) logger.stub(:error) logger.should_receive(:error).with(:any_args) Do you know of any solution for mocking this? Also, do you think the Rails Logger is worth mocking? Thanks very much in Advance, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From eagerwombat at gmail.com Thu Jun 12 19:03:17 2008 From: eagerwombat at gmail.com (john) Date: Thu, 12 Jun 2008 16:03:17 -0700 Subject: [rspec-users] Does anyone know how to mock the Rails Logger then set expectations with should_receive? Message-ID: <5b1b5e890806121603n7c9f2766xa19c06da746261af@mail.gmail.com> Hey Guys, I'm trying to mock the Rails Logger for the following code: ... rescue TimeoutError => error $logger.error("#{self.name} Timeout for #{path}: #{error}") and return rescue SocketError => error $logger.error("#{self.name} SocketError for #{path}: #{error}") and return rescue StandardError => error $logger.error("#{self.name} Error for #{path}: #{error}") and return end ... my failed attempt to spec: logger = mock_model(Logger) logger.stub(:error) logger.should_receive(:error).with(:any_args) Do you know of any solution for mocking this? Also, do you think the Rails Logger is worth mocking? Thanks very much in Advance, -------------- next part -------------- An HTML attachment was scrubbed... URL: From eagerwombat at gmail.com Thu Jun 12 19:03:17 2008 From: eagerwombat at gmail.com (john) Date: Thu, 12 Jun 2008 16:03:17 -0700 Subject: [rspec-users] Does anyone know how to mock the Rails Logger then set expectations with should_receive? Message-ID: <5b1b5e890806121603n7c9f2766xa19c06da746261af@mail.gmail.com> Hey Guys, I'm trying to mock the Rails Logger for the following code: ... rescue TimeoutError => error $logger.error("#{self.name} Timeout for #{path}: #{error}") and return rescue SocketError => error $logger.error("#{self.name} SocketError for #{path}: #{error}") and return rescue StandardError => error $logger.error("#{self.name} Error for #{path}: #{error}") and return end ... my failed attempt to spec: logger = mock_model(Logger) logger.stub(:error) logger.should_receive(:error).with(:any_args) Do you know of any solution for mocking this? Also, do you think the Rails Logger is worth mocking? Thanks very much in Advance, -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Thu Jun 12 19:30:45 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 12 Jun 2008 16:30:45 -0700 Subject: [rspec-users] Does anyone know how to mock the Rails Logger then set expectations with should_receive? In-Reply-To: <5b1b5e890806121603n7c9f2766xa19c06da746261af@mail.gmail.com> References: <5b1b5e890806121603n7c9f2766xa19c06da746261af@mail.gmail.com> Message-ID: <810a540e0806121630g45356eccye1c8a8897fc6f753@mail.gmail.com> On Thu, Jun 12, 2008 at 4:03 PM, john wrote: > Hey Guys, > > I'm trying to mock the Rails Logger for the following code: > > > ... > rescue TimeoutError => error > $logger.error("#{self.name} Timeout for #{path}: #{error}") and return > rescue SocketError => error > $logger.error("#{self.name} SocketError for #{path}: #{error}") and > return > rescue StandardError => error > $logger.error("#{self.name} Error for #{path}: #{error}") and return > end > ... > > > > my failed attempt to spec: > > logger = mock_model(Logger) > logger.stub(:error) > logger.should_receive(:error).with(:any_args) You never set the $logger var to your new logger. So it wouldn't do anything. > Do you know of any solution for mocking this? You could consider partially stubbing the rails logger. $logger.should_receive(:error) > Also, do you think the Rails Logger is worth mocking? I would say no. In particular, sometimes logging is a domain requirement. If that's the case, you want to separate that kind of logging from all the log info that Rails generates. Read http://www.mockobjects.com/2007/04/test-smell-logging-is-also-feature.html to get some info on mocking loggers. Pat From self at mattmower.com Fri Jun 13 10:36:01 2008 From: self at mattmower.com (Matt Mower) Date: Fri, 13 Jun 2008 15:36:01 +0100 Subject: [rspec-users] View spec failures without stack traces?!? Message-ID: Hi. I'm getting TemplateErrors from a couple of my view specs with an accompanying message, e.g.: 3) ActionView::TemplateError in 'playlists/show.rss.builder should render playlist RSS feed' You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.size But no stack trace. Shouldn't I get a stack trace? Regards, Matt. -- Matt Mower :: http://matt.blogs.it/ From dchelimsky at gmail.com Fri Jun 13 11:04:40 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 13 Jun 2008 10:04:40 -0500 Subject: [rspec-users] View spec failures without stack traces?!? In-Reply-To: References: Message-ID: Please post the code and examples. On Jun 13, 2008, at 9:36 AM, "Matt Mower" wrote: > Hi. > > I'm getting TemplateErrors from a couple of my view specs with an > accompanying message, e.g.: > > 3) > ActionView::TemplateError in 'playlists/show.rss.builder should render > playlist RSS feed' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.size > > But no stack trace. Shouldn't I get a stack trace? > > Regards, > > Matt. > > -- > Matt Mower :: http://matt.blogs.it/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jun 13 12:10:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 13 Jun 2008 11:10:23 -0500 Subject: [rspec-users] help with test design References: <0E78BCD8-F69F-42DA-9FB1-8665DD8D8140@mac.com> Message-ID: <0C361FE1-C82D-431C-BFD8-05C60E6C63DC@gmail.com> Forwarded message from Chuck Remes: Begin forwarded message: >> From: Chuck Remes >> Date: June 13, 2008 10:31:12 AM CDT >> To: rspec-users >> Subject: Re: [rspec-users] help with test design >> >> >> On Jun 11, 2008, at 2:25 PM, David Chelimsky wrote: >> >>> On Jun 11, 2008, at 12:06 PM, Chuck Remes wrote: >>> >>>> Ideally, all of these steps would be private to the Adapter class >>>> and would expose a single public interface called #build. All of >>>> these public methods exist solely so I can test these specific >>>> behaviors. >>>> >>>> Any suggestions on how to accomplish my goals? Is my difficulty >>>> pointing at a code smell that I am not detecting? >>> >>> Hey Chuck - sounds like you're trying to plan the whole process >>> out up front. TDD is about discovery. Here's what I'd recommend: >>> >>> Start w/ a simple example of what you want the adapter to do - the >>> simplest think you can think of - when you send it the >>> #generate_internal_instruments message. Get that to pass. Now the >>> next simplest thing. Get that to pass. Refactor. Rinse. Repeat. >>> >> >> [I apologize if this shows up multiple times. I sent it last night >> and again this morning but it never showed up on the list or in the >> archives. I subsequently unsubscribed and resubscribed. > fingers 3rd time is the charm>] >> >> >> Warning! Long post ahead! It responds to both Pat & David. >> >> Pat, no problem. Let me take another stab at this. I'll break >> things out into their own sections. I've actually made some >> progress since I sent the email so I'll incorporate those changes >> in my thinking. >> >> Oh, and to answer David's response that I am doing the whole >> process up front, the code I have so far is a direct result of >> tests. I *did* think through the problem beforehand a little bit >> because I had to pick where to start. >> >> Lastly, I have put the code for the class at the end of this email. >> The tests are sprinkled throughout but the class code is in one spot. >> >> GOALS >> >> 1. Practice BDD so no business-logic code is written without a test >> being written first. >> >> 2. Create an Adapter class to act as a proxy/adapter between a 3rd >> Party Library and my business logic >> >> 2a. Adapter class may use additional helper classes to convert the >> data inside objects from the 3rd Party lib into ruby objects used >> by my business logic >> >> 3. End up with well-tested code that only exposes as many public >> methods as necessary to accomplish the aforementioned goals >> >> CODE GOALS >> >> 1. To insulate my business logic from this 3rd party lib, I need to >> load and copy a bunch of things. I'm focusing on only one at a time >> so each "thing" will potentially get its own class unless I can >> refactor the load behavior out to a module or something else. >> >> 2. I need to do the following sequence of steps to load and copy >> the data. >> a. Get the Orc::Instruments from the 3rd party library >> b. Save the Orc::Instruments >> c. Build my internal shadow copy of the Orc::Instrument which I am >> calling Instrument in the ruby namespace >> d. Subscribe to market data updates for each Orc::Instrument >> e. Push all market data updates from Orc::Instrument to Instrument >> >> >> MY EFFORTS SO FAR >> >> I created a class called LiquidatorInstrumentAdapter. I skipped the >> tests to verify that it exists and other basics. The first test I >> wrote was: >> >> describe LiquidatorInstrumentAdapter, "discover_instruments" do >> before(:each) do >> @ia = LiquidatorInstrumentAdapter.new >> @orc = mock("orc") >> end >> >> it "should accept an orc strategy object" do >> @ia.orc_strategy.should be_nil >> @ia.orc_strategy = @orc >> @ia.orc_strategy.should_not be_nil >> end >> end >> >> In order to fetch the Orc::Instruments, I need to get a reference >> to them via a handle I call #orc_strategy. I created an accessor on >> the class so I could set the #orc_strategy field. Test went from >> failing to passing. I could have also passed this in the >> constructor but I prefer the freedom of creating empty objects and >> filling them out after the fact. Also, I could have skipped this >> test altogether since I'm really just testing that #attr_accessor >> works. So what... it helped prime the pump. >> >> Now that I have my reference to the orc strategy, I can get the >> Orc::Instruments loaded up. So I wrote this test (I created a new >> mock in my before block too): >> >> it "should get all instruments from Orc" do >> @orc_instruments.should_receive(:nil?).and_return(false) >> @orc_instruments >> .should_receive(:getKind).and_return(Orc::InstrumentKind::FUTURE) >> @orc >> .should_receive >> (:getInstrumentParameter >> ).with("instrument").and_return(@orc_instruments) >> @ia.orc_strategy = @orc >> @ia.discover_instruments >> end >> >> The logic here is that I should be able to call >> #orc_strategy.getInstrumentParameter and get an Orc::Instrument >> object for my efforts. I also make sure to do a sanity check for a >> nil instrument. Please note that in order for me to inject this >> orc_instrument mock that I need to expose another accessor (called >> #orc_instruments). This is one of the details that upsets me about >> testing, but I'll get to that at the end. >> >> This nil check lead me to my next test. >> >> it "should raise an exception if the instrument is nil" do >> @orc.should_receive(:getInstrumentParameter).and_return(nil) >> @ia.orc_strategy = @orc >> lambda { @ia.discover_instruments }.should raise_error >> end >> >> No surprises here; sometimes the 3rd party lib fails to return a >> valid object so I need to check for that. To save space, I'll skip >> the last test I wrote which was verifying that the Orc::Instrument >> it receives back is of type COMBINATION or FUTURE since those are >> the only instrument kinds I want to handle right now. I moved on to >> the next step in my logical sequence which was to save these >> Orc::Instruments for future reference. So I wrote another test: >> >> describe LiquidatorInstrumentAdapter, "save_components" do >> # skipping the #before block which sets up some mocks >> it "should save the component when the instrument is a FUTURE" do >> @ia >> .orc_instrument >> .should_receive(:getKind).and_return(Orc::InstrumentKind::FUTURE) >> @ia.orc_instrument.should_receive(:getInstrument).and_return(1) >> @ia.orc_strategy.should_receive(:setParameter).with("components", >> @ia.orc_components) >> @ia.orc_components.should be_empty >> @ia.save_components >> @ia.orc_components.length.should == 1 >> end >> end >> >> This test verifies that the Orc::Instrument is the proper kind and >> that my internal array called #orc_components is empty at the >> beginning and contains one element after sending the message. Note >> again that I had to expose what should likely be a private >> structure in order to test it (attr_accessor :orc_components). I >> wrote a few more tests to make sure it properly saves COMBINATIONS >> (which contain multiple FUTURES) and that they are saved off >> correctly. I also wrote a test to verify an exception is raised if >> the instrument is not a COMBINATION a FUTURE (this is probably >> unnecessary since it was validated in the prior method). >> >> At this point I have a class starting to take shape. Moving on to >> the next step takes me to building my shadow copy of these >> Orc::Instrument objects as ruby objects. I didn't know what this >> interface should look like so I started out by using mocks and >> letting it lead me. After a little experimentation it was clear >> that I needed to break this functionality out to its own class >> (lots of copying fields from one object to another). I elected to >> call it OrcInstrumentCreationEvent. Here's the test I wrote for it >> prior to actually creating that class for real (all mocks). >> >> describe LiquidatorInstrumentAdapter, >> "generate_instrument_creation_events" do >> before(:each) do >> @ia = LiquidatorInstrumentAdapter.new >> end >> >> it "should create a InstrumentCreationEvent for each component" do >> orc_components = mock("components") >> event = mock("instrument event class") >> event >> .should_receive >> (:new).exactly(:twice).with(orc_components).and_return(event) >> orc_components >> .should_receive >> (:each).and_yield(orc_components).and_yield(orc_components) >> >> @ia.orc_components = orc_components >> ary = @ia.generate_instrument_creation_events(event) >> ary.size.should == 2 >> end >> end >> >> So this verifies that I create a CreationEvent for each >> Orc::Instrument that I saved earlier. All the gory details of >> copying the right fields from the Orc::Instrument will be >> encapsulated by that class. Note that I need to pass a Class as a >> parameter to #generate_instrument_creation_events so that my test >> can pass it a mock and verify the behavior. In the real world I'll >> pass a ruby Instrument but ideally (in my mind) this wouldn't be a >> parameter at all. It looks like I am contorting my code so that it >> is testable. >> >> I still haven't created my shadow ruby Instrument object yet. >> Hmmm... let's write a test. >> >> describe LiquidatorInstrumentAdapter, >> "generate_internal_instruments" do >> before(:each) do >> @ia = LiquidatorInstrumentAdapter.new >> end >> >> it "should create a new Instrument for each event and #build it" do >> event_ary = mock("instrument creation event array") >> instrument_class = mock("instrument class") >> empty_mock = mock("placeholder") >> event_ary.should_receive(:each).and_yield(empty_mock) >> instrument_class.should_receive(:new).and_return(instrument_class) >> # reuse this mock >> instrument_class.should_receive(:build).with(empty_mock) >> @ia.generate_internal_instruments(event_ary, instrument_class) >> end >> end >> >> Taking my CreationEvents, I can pass these to the Instrument#build >> method and it will know which accessors to use to pull the >> appropriate data out. These are all mocks. I'll create the real >> objects a little bit later (not covered in this email). Now I'm >> scratching my head wondering if I know what the hell I'm doing. To >> test this I have to pass in both an event array and the class name >> of the object I want to instantiate and #build. This is all in the >> name of testability so I can inject my mocks into the stream and >> verify the behavior. But it looks fugly to me. Ideally the last two >> methods I wrote would be private to the class and never exposed to >> the outside world. But one of the cardinal rules of testing (from >> what I've read) is that we should *not* test private methods. Is >> this a circumstance where that rule doesn't apply? >> >> Anyway, the class code is relatively short. I have about double the >> lines in my spec file to test the class. That doesn't bother me too >> much but there are a few things bugging me which I'll list. >> >> THINGS THAT ARE BUGGING ME >> >> 1. To use mocks to verify behavior, I have to create many public >> accessors to inject the mocks. These public accessors, in most >> cases, would not be part of any public API that I would publish for >> another programmer to use. Ideally they would set a few things >> (like orc_strategy) and then call #build on the whole object which >> would privately call most of the methods I have defined as public. >> >> 2. I'm doing lots of mock setup in each test. My rule of thumb has >> been to break a method out to another (public) method if I have to >> setup more than 3 mocks to test its behavior. I don't know if this >> is pointing to a larger problem (lots of setup) or what, but I >> would be grateful for any insight. >> >> 3. I think some of my mocks are exposing too much of the class' >> implementation. For example, in my OrcInstrumentCreationEvent test >> I tell the orc_components mock to expect the message :each which is >> exposing how I am iterating. What if I want to use a while or a for >> loop? That shouldn't be any business of the test. It cares about >> behavior, not implementation but I don't see how else to get the >> mock to return what I need. >> >> I would love to have this critiqued by veteran BDDers. Be as blunt >> as necessary... I have broad shoulders. >> >> cr >> >> CLASS CODE >> >> module Orc >> import com.orcsoftware.liquidator.InstrumentKind >> end >> >> class LiquidatorInstrumentAdapter >> >> attr_accessor :orc_strategy >> attr_accessor :orc_components >> attr_accessor :orc_instrument >> attr_accessor :instruments >> >> def initialize >> @orc_components ||= [] >> @instruments ||= [] >> end >> >> def build >> discover_instruments >> save_components >> events = >> generate_instrument_creation_events >> (LiquidatorInstrumentCreationEvent) >> generate_internal_instruments(events, Instrument) >> subscribe_to_components >> end >> >> def discover_instruments >> @orc_instrument = orc_strategy.getInstrumentParameter("instrument") >> raise TypeError, "Instrument parameter was nil!", caller[0] if >> orc_instrument.nil? >> kind = orc_instrument.getKind >> if (kind != Orc::InstrumentKind::COMBINATION && kind != >> Orc::InstrumentKind::FUTURE) >> raise TypeError, "Instrument parameter was the wrong type >> [#{kind}], should be either [#{Orc::InstrumentKind::COMBINATION}] >> or [#{Orc::InstrumentKind::FUTURE}]" >> end >> end >> >> def save_components >> case orc_instrument.getKind >> when Orc::InstrumentKind::COMBINATION >> save_combination_components >> when Orc::InstrumentKind::FUTURE >> save_future_component >> else >> raise TypeError, "Instrument is the wrong kind! : >> [#{orc_instrument.getKind}]", caller[0] >> end >> orc_strategy.setParameter("components", orc_components) >> end >> >> def subscribe_to_components >> orc_components.each { |component| component.depthSubscribe } >> end >> >> def generate_instrument_creation_events(klass) >> events = [] >> orc_components.each do |component| >> events << klass.new(component) >> end >> events >> end >> >> def generate_internal_instruments(event_ary, klass) >> event_ary.each do |event| >> instruments << klass.new >> build_strategy_instrument(instruments.last, event) >> end >> end >> >> private >> >> def save_combination_components >> orc_instrument.getComponents.each do |component| >> orc_components << component.getInstrument >> end >> end >> >> def save_future_component >> orc_components << orc_instrument.getInstrument >> end >> >> def build_strategy_instrument(instrument, creation_event) >> instrument.build(creation_event) >> end >> end >> > From byrnejb at harte-lyne.ca Fri Jun 13 12:27:41 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Fri, 13 Jun 2008 12:27:41 -0400 (EDT) Subject: [rspec-users] rspec and rspec-rails install hell In-Reply-To: References: Message-ID: <3184.12.10.246.2.1213374461.squirrel@webmail.harte-lyne.ca> > > Message: 1 > Date: Wed, 11 Jun 2008 14:07:36 -0500 > From: David Chelimsky > > What a drag - sorry you went through all that. rspec_generator-0.5.15 and rspec-0.5.15 are old, old, old and unrelated to anything useful today. Get rid of them. > > Here's what I'd do: > > Make sure you do not have any rspec related plugins in vendor/plugins and follow the directions from the wiki again: > > cd vendor/plugins > git clone git://github.com/dchelimsky/rspec.git > git clone git://github.com/dchelimsky/rspec-rails.git > cd ../../ > script/generate rspec > > There's no reason that shouldn't work. This is what I am experiencing now: C:\temp\labs\08_rspec_rails\prag_hotel>gem list | grep rspec* C:\temp\labs\08_rspec_rails\prag_hotel> C:\temp\labs\08_rspec_rails\prag_hotel> C:\temp\labs\08_rspec_rails\prag_hotel>git clone git://github.com/dchelimsky/rsp ec.git vendor/plugins/rspec Initialized empty Git repository in /cygdrive/c/temp/labs/08_rspec_rails/prag_ho tel/vendor/plugins/rspec/.git/ remote: Counting objects: 46856, done. remote: Compressing objects: 100% (10654/10654), done. remote: Total 46856 (delta 33558), reused 46856 (delta 33558) Receiving objects: 100% (46856/46856), 6.00 MiB | 56 KiB/s, done. Resolving deltas: 100% (33558/33558), done. C:\temp\labs\08_rspec_rails\prag_hotel>git clone git://github.com/dchelimsky/rsp ec-rails.git vendor/plugins/rspec-rails Initialized empty Git repository in /cygdrive/c/temp/labs/08_rspec_rails/prag_ho tel/vendor/plugins/rspec-rails/.git/ remote: Counting objects: 46582, done. remote: Compressing objects: 100% (10669/10669), done. remote: Total 46582 (delta 33273), reused 46582 (delta 33273) Receiving objects: 100% (46582/46582), 5.95 MiB | 69 KiB/s, done. Resolving deltas: 100% (33273/33273), done. C:\temp\labs\08_rspec_rails\prag_hotel>script/generate rspec 'script' is not recognized as an internal or external command, operable program or batch file. C:\temp\labs\08_rspec_rails\prag_hotel>ruby script/generate rspec exists spec identical spec/spec_helper.rb identical spec/spec.opts identical spec/rcov.opts identical script/spec_server identical script/spec exists stories identical stories/all.rb identical stories/helper.rb C:\temp\labs\08_rspec_rails\prag_hotel> C:\temp\labs\08_rspec_rails\prag_hotel>rake spec (in C:/temp/labs/08_rspec_rails/prag_hotel) rake aborted! no such file to load -- spec/rake/spectask C:/temp/labs/08_rspec_rails/prag_hotel/rakefile:10 (See full trace by running task with --trace) C:\temp\labs\08_rspec_rails\prag_hotel>gem install rspec Bulk updating Gem source index for: http://gems.rubyforge.org/ Successfully installed rspec-1.1.4 1 gem installed Installing ri documentation for rspec-1.1.4... Installing RDoc documentation for rspec-1.1.4... C:\temp\labs\08_rspec_rails\prag_hotel>rake spec (in /cygdrive/c/temp/labs/08_rspec_rails/prag_hotel) /cygdrive/c/temp/labs/08_rspec_rails/prag_hotel/vendor/plugins/rspec-rails/lib/s pec/rails/version.rb:11: (RuntimeError) ############################################################################ Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 20080526202855 RSpec on Rails : 20080608062339 Make sure your RSpec on Rails plugin is compatible with your RSpec gem. See http://rspec.rubyforge.org/documentation/rails/install.html for details. ############################################################################ C:\temp\labs\08_rspec_rails\prag_hotel>gem uninstall rspec Successfully uninstalled rspec-1.1.4 Remove executables: spec, spec_translator in addition to the gem? [Yn] n Executables and scripts will remain installed. C:\temp\labs\08_rspec_rails\prag_hotel>rake spec (in /cygdrive/c/temp/labs/08_rspec_rails/prag_hotel) rake aborted! no such file to load -- spec/rake/spectask /cygdrive/c/temp/labs/08_rspec_rails/prag_hotel/rakefile:10 (See full trace by running task with --trace) Here is the problem. If RSpec gem is not installed then I get the rspec-rails / rspec version mismatch. If I remove the RSpec gem then the rake tasks will not run. Suggestions welcome. -- *** 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 Fri Jun 13 12:47:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 13 Jun 2008 11:47:22 -0500 Subject: [rspec-users] rspec and rspec-rails install hell In-Reply-To: <3184.12.10.246.2.1213374461.squirrel@webmail.harte-lyne.ca> References: <3184.12.10.246.2.1213374461.squirrel@webmail.harte-lyne.ca> Message-ID: On Jun 13, 2008, at 11:27 AM, James B. Byrne wrote: >> Message: 1 >> Date: Wed, 11 Jun 2008 14:07:36 -0500 >> From: David Chelimsky > >> >> What a drag - sorry you went through all that. >> rspec_generator-0.5.15 and > rspec-0.5.15 are old, old, old and unrelated to anything useful > today. Get > rid of them. >> >> Here's what I'd do: >> >> Make sure you do not have any rspec related plugins in vendor/ >> plugins and > follow the directions from the wiki again: >> >> cd vendor/plugins >> git clone git://github.com/dchelimsky/rspec.git >> git clone git://github.com/dchelimsky/rspec-rails.git >> cd ../../ >> script/generate rspec >> >> There's no reason that shouldn't work. > > This is what I am experiencing now: > > C:\temp\labs\08_rspec_rails\prag_hotel>gem list | grep rspec* > C:\temp\labs\08_rspec_rails\prag_hotel> > C:\temp\labs\08_rspec_rails\prag_hotel> > C:\temp\labs\08_rspec_rails\prag_hotel>git clone > git://github.com/dchelimsky/rsp > ec.git vendor/plugins/rspec > Initialized empty Git repository in > /cygdrive/c/temp/labs/08_rspec_rails/prag_ho > tel/vendor/plugins/rspec/.git/ > remote: Counting objects: 46856, done. > remote: Compressing objects: 100% (10654/10654), done. > remote: Total 46856 (delta 33558), reused 46856 (delta 33558) > Receiving objects: 100% (46856/46856), 6.00 MiB | 56 KiB/s, done. > Resolving deltas: 100% (33558/33558), done. > > C:\temp\labs\08_rspec_rails\prag_hotel>git clone > git://github.com/dchelimsky/rsp > ec-rails.git vendor/plugins/rspec-rails > Initialized empty Git repository in > /cygdrive/c/temp/labs/08_rspec_rails/prag_ho > tel/vendor/plugins/rspec-rails/.git/ > remote: Counting objects: 46582, done. > remote: Compressing objects: 100% (10669/10669), done. > remote: Total 46582 (delta 33273), reused 46582 (delta 33273) > Receiving objects: 100% (46582/46582), 5.95 MiB | 69 KiB/s, done. > Resolving deltas: 100% (33273/33273), done. > > C:\temp\labs\08_rspec_rails\prag_hotel>script/generate rspec > 'script' is not recognized as an internal or external command, > operable program or batch file. That one is a windows problem - guess you gotta use the ruby command. > C:\temp\labs\08_rspec_rails\prag_hotel>ruby script/generate rspec > exists spec > identical spec/spec_helper.rb > identical spec/spec.opts > identical spec/rcov.opts > identical script/spec_server > identical script/spec > exists stories > identical stories/all.rb > identical stories/helper.rb > > C:\temp\labs\08_rspec_rails\prag_hotel> > C:\temp\labs\08_rspec_rails\prag_hotel>rake spec > (in C:/temp/labs/08_rspec_rails/prag_hotel) > rake aborted! > no such file to load -- spec/rake/spectask > C:/temp/labs/08_rspec_rails/prag_hotel/rakefile:10 > (See full trace by running task with --trace) > > C:\temp\labs\08_rspec_rails\prag_hotel>gem install rspec > Bulk updating Gem source index for: http://gems.rubyforge.org/ > Successfully installed rspec-1.1.4 > 1 gem installed > Installing ri documentation for rspec-1.1.4... > Installing RDoc documentation for rspec-1.1.4... > > C:\temp\labs\08_rspec_rails\prag_hotel>rake spec > (in /cygdrive/c/temp/labs/08_rspec_rails/prag_hotel) > /cygdrive/c/temp/labs/08_rspec_rails/prag_hotel/vendor/plugins/rspec- > rails/lib/s > pec/rails/version.rb:11: (RuntimeError) > ############################################################################ > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > RSpec : 20080526202855 > RSpec on Rails : 20080608062339 > > Make sure your RSpec on Rails plugin is compatible with your RSpec > gem. > See http://rspec.rubyforge.org/documentation/rails/install.html for > details. > ############################################################################ > > C:\temp\labs\08_rspec_rails\prag_hotel>gem uninstall rspec > Successfully uninstalled rspec-1.1.4 > Remove executables: > spec, spec_translator > > in addition to the gem? [Yn] n > Executables and scripts will remain installed. > > C:\temp\labs\08_rspec_rails\prag_hotel>rake spec > (in /cygdrive/c/temp/labs/08_rspec_rails/prag_hotel) > rake aborted! > no such file to load -- spec/rake/spectask > /cygdrive/c/temp/labs/08_rspec_rails/prag_hotel/rakefile:10 > (See full trace by running task with --trace) > > > Here is the problem. If RSpec gem is not installed then I get the > rspec-rails > / rspec version mismatch. If I remove the RSpec gem then the rake > tasks will > not run. For some reason rails is not finding rspec in vendor/plugins. Don't know why. To get things running, you can just go into rspec-rails/lib/spec/rails/ version.rb and comment the code that's complaining about the version mismatch. The risk is fairly low at this point that you're going to have any trouble. If you don't want to do that - try checking out the 1.1.4 version of spec-rails, so starting clean (no rspec anywhere) you would do this: gem install rspec cd vendor/plugins git clone git://github.com/dchelimsky/rspec-rails.git cd rspec-rails git checkout 1.1.4 Now you should have the same versions of the rspec gem and rspec-rails plugin. Let us know if that works. From byrnejb at harte-lyne.ca Fri Jun 13 13:04:10 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Fri, 13 Jun 2008 13:04:10 -0400 (EDT) Subject: [rspec-users] rspec-users Digest, Vol 24, Issue 20 In-Reply-To: References: Message-ID: <3295.12.10.246.2.1213376650.squirrel@webmail.harte-lyne.ca> > > Message: 4 > Date: Fri, 13 Jun 2008 11:47:22 -0500 > From: David Chelimsky > Subject: Re: [rspec-users] rspec and rspec-rails install hell > To: rspec-users > Message-ID: > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > On Jun 13, 2008, at 11:27 AM, James B. Byrne wrote: > >> Here is the problem. If RSpec gem is installed then I get the >> rspec-rails / rspec version mismatch. If I remove the RSpec gem >> then the rake tasks will not run. > > For some reason rails is not finding rspec in vendor/plugins. Don't > know why. > > To get things running, you can just go into rspec-rails/lib/spec/rails/ > version.rb and comment the code that's complaining about the version > mismatch. The risk is fairly low at this point that you're going to > have any trouble. > > If you don't want to do that - try checking out the 1.1.4 version of > spec-rails, so starting clean (no rspec anywhere) you would do this: > > gem install rspec > cd vendor/plugins > git clone git://github.com/dchelimsky/rspec-rails.git > cd rspec-rails > git checkout 1.1.4 > > Now you should have the same versions of the rspec gem and rspec-rails > plugin. > > Let us know if that works. Yes, it did. Thank you. 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 Fri Jun 13 13:13:59 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Fri, 13 Jun 2008 13:13:59 -0400 (EDT) Subject: [rspec-users] RSpec and Rails 2.1 Message-ID: <3332.12.10.246.2.1213377239.squirrel@webmail.harte-lyne.ca> ON: Fri, 13 Jun 2008 11:47:22 -0500, David Chelimsky wrote: > > For some reason rails is not finding rspec in vendor/plugins. Don't > know why. Has Rails 2.1.0 changed the loading precedence? Does it now use a gem in preference to a plugin if both are available? -- *** 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 Fri Jun 13 13:15:18 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Fri, 13 Jun 2008 13:15:18 -0400 (EDT) Subject: [rspec-users] RSpec and Rails 2.1 In-Reply-To: <3332.12.10.246.2.1213377239.squirrel@webmail.harte-lyne.ca> References: <3332.12.10.246.2.1213377239.squirrel@webmail.harte-lyne.ca> Message-ID: <3341.12.10.246.2.1213377318.squirrel@webmail.harte-lyne.ca> On Fri, June 13, 2008 13:13, James B. Byrne wrote: > ON: Fri, 13 Jun 2008 11:47:22 -0500, David Chelimsky > wrote: >> >> For some reason rails is not finding rspec in vendor/plugins. Don't >> know why. > > Has Rails 2.1.0 changed the loading precedence? Does it now use a gem in > preference to a plugin if both are available? Scratch that thought. The demo lab is using Rails 2.0.2. -- *** 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 cremes.devlist at mac.com Fri Jun 13 13:44:32 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Fri, 13 Jun 2008 12:44:32 -0500 Subject: [rspec-users] test - ignore Message-ID: <3A97B47B-B5EE-4527-A354-2B36114C8AE7@mac.com> Verify I can successfully send to the list. From pergesu at gmail.com Fri Jun 13 16:25:08 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 13 Jun 2008 13:25:08 -0700 Subject: [rspec-users] test - ignore In-Reply-To: <3A97B47B-B5EE-4527-A354-2B36114C8AE7@mac.com> References: <3A97B47B-B5EE-4527-A354-2B36114C8AE7@mac.com> Message-ID: <810a540e0806131325s2f2b91d9g4125ba2cf50668f2@mail.gmail.com> Green! On Fri, Jun 13, 2008 at 10:44 AM, Chuck Remes wrote: > Verify I can successfully send to the list. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From raasdnil at gmail.com Sat Jun 14 06:03:02 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Sat, 14 Jun 2008 20:03:02 +1000 Subject: [rspec-users] Reusing story snippets Message-ID: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> I find myself doing this: Scenario "logged in user visiting the home page" do Given "A logged in user" do a_logged_in_user end When "..." Then "..." end The a_logged_in_user method is a helper method in helper.rb which sets up the state so that the user can browse the website. Later in the story of course, I can just do 'Given "A logged in user" and it will get the previous definition. Is there any way to avoid that duplicated Given call at the top of almost every story? Mikel From philodespotos at gmail.com Sat Jun 14 06:45:34 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Sat, 14 Jun 2008 05:45:34 -0500 Subject: [rspec-users] Reusing story snippets In-Reply-To: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> Message-ID: <60f3810c0806140345r30b6bae3h206e74adf3a8f57a@mail.gmail.com> On Sat, Jun 14, 2008 at 5:03 AM, Mikel Lindsaar wrote: > I find myself doing this: > > Scenario "logged in user visiting the home page" do > Given "A logged in user" do > a_logged_in_user > end > > When "..." > Then "..." > end > > The a_logged_in_user method is a helper method in helper.rb which sets > up the state so that the user can browse the website. > > Later in the story of course, I can just do 'Given "A logged in user" > and it will get the previous definition. > > Is there any way to avoid that duplicated Given call at the top of > almost every story? If it's implicit in almost every story, just call the helper in the first step of your scenarios. This might be an issue if you're striving to recycle steps, but otherwise it works perfectly well. If the story obviously requires authentication, why bother specifying it? Maybe others will see it differently, but I omit a lot of the "scaffolding" preconditions when it's clear from context: Given a user editing their account details Of course they have to be logged in for that. I may write a single scenario that shows users can't get to their account details page without being logged in, but the rest can happily just imply it: Given("a user editing their account details") do a_logged_in_user browse_to('account details page') end k From dchelimsky at gmail.com Sat Jun 14 10:40:32 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Jun 2008 09:40:32 -0500 Subject: [rspec-users] Reusing story snippets In-Reply-To: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> Message-ID: <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> On Jun 14, 2008, at 5:03 AM, Mikel Lindsaar wrote: > I find myself doing this: > > Scenario "logged in user visiting the home page" do > Given "A logged in user" do > a_logged_in_user > end > > When "..." > Then "..." > end Things have evolved a bit since Story Runner first came out. The approach you are using here is what we call in-line steps, and was the only option back then. You can now use disconnected steps in both plain text and Ruby: require 'steps/visitors' Story "logged in users see more stuff", %( As a registered user I want to see more stuff than non-registered users So I can feel like I'm getting some benefit in return for giving up my personal information ), :steps => :visitors do Scenario "logged in user visits home page" do Given "I am logged in as David" When "I visit the home page" Then "I should see the message 'Welcome David'" end end # in steps/visitors steps_for :visitors do Given "I am logged in as $name" do |name| # create a user w/ name and log in as that user end When ".." Then ".." end This approach really cleans up the story code leaving the informative bits while hiding the redundant detail. HTH, David > The a_logged_in_user method is a helper method in helper.rb which sets > up the state so that the user can browse the website. > > Later in the story of course, I can just do 'Given "A logged in user" > and it will get the previous definition. > > Is there any way to avoid that duplicated Given call at the top of > almost every story? > > Mikel > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aidy.lewis at googlemail.com Sat Jun 14 13:50:10 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Sat, 14 Jun 2008 10:50:10 -0700 Subject: [rspec-users] the Given, When, Then framework Message-ID: <7ac2300c0806141050n2da0de60y31127f1e4988857a@mail.gmail.com> Hi, Is the Given, When, Then framework, the user story, the acceptance criteria or both? Aidy From dchelimsky at gmail.com Sat Jun 14 14:14:48 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Jun 2008 13:14:48 -0500 Subject: [rspec-users] the Given, When, Then framework In-Reply-To: <7ac2300c0806141050n2da0de60y31127f1e4988857a@mail.gmail.com> References: <7ac2300c0806141050n2da0de60y31127f1e4988857a@mail.gmail.com> Message-ID: <071A10A7-C994-4DEF-A596-1FF296F6878F@gmail.com> On Jun 14, 2008, at 12:50 PM, aidy lewis wrote: > Hi, > > Is the Given, When, Then framework, the user story, the acceptance > criteria or both? From my talk at railsconf: http://en.oreilly.com/rails2008/public/schedule/detail/2055 ============================================= Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved ============================================= The story and the text before the first scenario is the User Story as we've always known it in XP. The Scenarios are automated, and represent acceptance criteria. Make sense? Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From aidy.lewis at googlemail.com Sat Jun 14 14:23:27 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Sat, 14 Jun 2008 11:23:27 -0700 Subject: [rspec-users] the Given, When, Then framework In-Reply-To: <071A10A7-C994-4DEF-A596-1FF296F6878F@gmail.com> References: <7ac2300c0806141050n2da0de60y31127f1e4988857a@mail.gmail.com> <071A10A7-C994-4DEF-A596-1FF296F6878F@gmail.com> Message-ID: <7ac2300c0806141123k2a0a0838lba670366dddd93d1@mail.gmail.com> Hi David, On 14/06/2008, David Chelimsky wrote: > > On Jun 14, 2008, at 12:50 PM, aidy lewis wrote: > > Hi, > > Is the Given, When, Then framework, the user story, the acceptance > criteria or both? > > From my talk at railsconf: > http://en.oreilly.com/rails2008/public/schedule/detail/2055 > > > ============================================= > Story: measure progress towards registration goals > As a conference organizer > I want to see a report of registrations > So that I can measure progress towards registration goals > > Scenario: one registration shows as 1% > Given a goal of 200 registrations > When 1 attendee registers > Then the goal should be 1% achieved > > Scenario: one registration less than the goal shows as 99% > Given a goal of 200 registrations > When 199 attendees register > Then the goal should be 99% achieved > ============================================= > > The story and the text before the first scenario is the User Story as we've > always known it in XP. > > The Scenarios are automated, and represent acceptance criteria. > > Make sense? > > Cheers, > David > Certainly does. I am automating the tests (only tester on my project), but I have asked the BA's not only to write the story then, but also give the scenarios. I do a lot of re-work on the story though. Should I just be asking just for the story and for me to add the tests (Given, When, Then) I also asked them for negative scenarios. Aidy From dchelimsky at gmail.com Sat Jun 14 14:29:29 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Jun 2008 13:29:29 -0500 Subject: [rspec-users] the Given, When, Then framework In-Reply-To: <7ac2300c0806141123k2a0a0838lba670366dddd93d1@mail.gmail.com> References: <7ac2300c0806141050n2da0de60y31127f1e4988857a@mail.gmail.com> <071A10A7-C994-4DEF-A596-1FF296F6878F@gmail.com> <7ac2300c0806141123k2a0a0838lba670366dddd93d1@mail.gmail.com> Message-ID: <96828FCE-F8D6-4429-ADCC-44D571DE8C62@gmail.com> On Jun 14, 2008, at 1:23 PM, aidy lewis wrote: > Hi David, > > On 14/06/2008, David Chelimsky wrote: >> >> On Jun 14, 2008, at 12:50 PM, aidy lewis wrote: >> >> Hi, >> >> Is the Given, When, Then framework, the user story, the acceptance >> criteria or both? >> >> From my talk at railsconf: >> http://en.oreilly.com/rails2008/public/schedule/detail/2055 >> >> >> ============================================= >> Story: measure progress towards registration goals >> As a conference organizer >> I want to see a report of registrations >> So that I can measure progress towards registration goals >> >> Scenario: one registration shows as 1% >> Given a goal of 200 registrations >> When 1 attendee registers >> Then the goal should be 1% achieved >> >> Scenario: one registration less than the goal shows as 99% >> Given a goal of 200 registrations >> When 199 attendees register >> Then the goal should be 99% achieved >> ============================================= >> >> The story and the text before the first scenario is the User Story >> as we've >> always known it in XP. >> >> The Scenarios are automated, and represent acceptance criteria. >> >> Make sense? >> >> Cheers, >> David >> > > Certainly does. I am automating the tests (only tester on my project), > but I have asked the BA's not only to write the story then, but also > give the scenarios. I do a lot of re-work on the story though. > > Should I just be asking just for the story and for me to add the tests > (Given, When, Then) > > I also asked them for negative scenarios. The ideal situation is that you and the BA's sit down together to work this out. The goal here is group communication rather than one role owning part of the communication. Short of that, there is no one right way to do this. Perhaps they provide stories, you add scenarios as demonstration, they add more scenarios for thoroughness, etc. What is a "negative scenario"? From aidy.lewis at googlemail.com Sat Jun 14 14:43:35 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Sat, 14 Jun 2008 11:43:35 -0700 Subject: [rspec-users] the Given, When, Then framework In-Reply-To: <96828FCE-F8D6-4429-ADCC-44D571DE8C62@gmail.com> References: <7ac2300c0806141050n2da0de60y31127f1e4988857a@mail.gmail.com> <071A10A7-C994-4DEF-A596-1FF296F6878F@gmail.com> <7ac2300c0806141123k2a0a0838lba670366dddd93d1@mail.gmail.com> <96828FCE-F8D6-4429-ADCC-44D571DE8C62@gmail.com> Message-ID: <7ac2300c0806141143u12aa7e3ax139830ea7c91ad34@mail.gmail.com> Hi David, On 14/06/2008, David Chelimsky wrote: > > What is a "negative scenario"? Thanks for getting back. I have been asked that twice in 2 days! In the use-case world they have negative or mis-use cases. These cases desribe forbidden or wrong input into the system that has not been specified. .... When the user enters alpha characters into the DoB field Then an error message appears informing him of this And gives an example of a correct input. Aidy From dchelimsky at gmail.com Sat Jun 14 14:47:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Jun 2008 13:47:03 -0500 Subject: [rspec-users] the Given, When, Then framework In-Reply-To: <7ac2300c0806141143u12aa7e3ax139830ea7c91ad34@mail.gmail.com> References: <7ac2300c0806141050n2da0de60y31127f1e4988857a@mail.gmail.com> <071A10A7-C994-4DEF-A596-1FF296F6878F@gmail.com> <7ac2300c0806141123k2a0a0838lba670366dddd93d1@mail.gmail.com> <96828FCE-F8D6-4429-ADCC-44D571DE8C62@gmail.com> <7ac2300c0806141143u12aa7e3ax139830ea7c91ad34@mail.gmail.com> Message-ID: <1A27AAF9-5EEF-47C5-B826-AEB5B0708E1B@gmail.com> On Jun 14, 2008, at 1:43 PM, aidy lewis wrote: > Hi David, > > On 14/06/2008, David Chelimsky wrote: >> >> What is a "negative scenario"? > > Thanks for getting back. > > I have been asked that twice in 2 days! > > In the use-case world they have negative or mis-use cases. > > These cases desribe forbidden or wrong input into the system > that has not been specified. > > .... > When the user enters alpha characters into the DoB field > Then an error message appears informing him of this > And gives an example of a correct input. Got it. For me, that is positive :) But I get the idea. Thanks From d at sofer.com Sun Jun 15 05:33:54 2008 From: d at sofer.com (Danny Sofer) Date: Sun, 15 Jun 2008 10:33:54 +0100 Subject: [rspec-users] RSpec story failing because of routing error on "/" Message-ID: <5D56A07E-6978-48FB-A5C6-F8CE3E7AB2D6@sofer.com> Greetings! Here's the problem. When running tests on the restful_authentication plugin, I am getting a routing error on "/". Which I don't really understand, because the route "/" certainly does exist as I can confirm when I run ./script/server and point my browser at http://localhost:3000/ Here is an example of the error I am getting when I run "ruby stories/ rest_auth_stories.rb": Scenario: Anonymous user can get a login form. Given an anonymous user (FAILED) When she goes to /login Then she should be at the new sessions page And the page should look AWESOME (SKIPPED) And she should see a
containing a textfield: Login, password: Password, and submit: 'Log in' FAILURES: 1) Creating an account (Anonymous user can start creating an account) FAILED ActionController::RoutingError: No route matches "/" with {:method=>:get} ./stories/steps/user_steps.rb:104:in `log_out!' ./stories/steps/user_steps.rb:12:in `an anonymous user' stories/rest_auth_stories.rb:17 I am running: Rails: 2.1.0 RSpec-1.1.4 And this is a completely fresh install with no code added by me. Here are the steps to replicate (from my app root): git clone git://github.com/rails/rails.git vendor/rails git clone git://github.com/dchelimsky/rspec.git vendor/plugins/rspec git clone git://github.com/dchelimsky/rspec-rails.git vendor/plugins/ rspec-rails git clone git://github.com/technoweenie/restful-authentication.git vendor/plugins/restful-authentication ./script/generate rspec ./script/generate authenticated user sessions mate app/controllers (and added " include AuthenticatedSystem" to the application controller) rake db:migrate rake db:test:prepare ruby stories/rest_auth_stories.rb Many thanks for your kind attention, danny sofer -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2458 bytes Desc: not available URL: From dchelimsky at gmail.com Sun Jun 15 09:09:12 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Jun 2008 08:09:12 -0500 Subject: [rspec-users] RSpec story failing because of routing error on "/" In-Reply-To: <5D56A07E-6978-48FB-A5C6-F8CE3E7AB2D6@sofer.com> References: <5D56A07E-6978-48FB-A5C6-F8CE3E7AB2D6@sofer.com> Message-ID: On Jun 15, 2008, at 4:33 AM, Danny Sofer wrote: > Greetings! > > Here's the problem. > > When running tests on the restful_authentication plugin, I am > getting a routing error on "/". > > Which I don't really understand, because the route "/" certainly > does exist as I can confirm when I run ./script/server and point my > browser at http://localhost:3000/ Actually, that route does NOT exist. You're seeing something because there is an index.html file in public, not because Rails routing is getting you there. Add an explicit root mapping to the appropriate controller and you'll get past this. Looks like there are more problems ahead, but they seem to be in restful_authentication. Cheers, David > Here is an example of the error I am getting when I run "ruby > stories/rest_auth_stories.rb": > > Scenario: Anonymous user can get a login form. > > Given an anonymous user (FAILED) > > When she goes to /login > > Then she should be at the new sessions page > And the page should look AWESOME (SKIPPED) > And she should see a containing a textfield: Login, > password: Password, and submit: 'Log in' > > > > FAILURES: > 1) Creating an account (Anonymous user can start creating an > account) FAILED > ActionController::RoutingError: No route matches "/" with > {:method=>:get} > ./stories/steps/user_steps.rb:104:in `log_out!' > ./stories/steps/user_steps.rb:12:in `an anonymous user' > stories/rest_auth_stories.rb:17 > > > > I am running: > > Rails: 2.1.0 > RSpec-1.1.4 > > And this is a completely fresh install with no code added by me. > > Here are the steps to replicate (from my app root): > > git clone git://github.com/rails/rails.git vendor/rails > git clone git://github.com/dchelimsky/rspec.git vendor/plugins/rspec > git clone git://github.com/dchelimsky/rspec-rails.git vendor/plugins/ > rspec-rails > git clone git://github.com/technoweenie/restful-authentication.git > vendor/plugins/restful-authentication > > ./script/generate rspec > ./script/generate authenticated user sessions > > mate app/controllers (and added " include AuthenticatedSystem" to > the application controller) > > rake db:migrate > rake db:test:prepare > > ruby stories/rest_auth_stories.rb > > > Many thanks for your kind attention, > > > danny sofer > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sun Jun 15 12:59:09 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Sun, 15 Jun 2008 18:59:09 +0200 Subject: [rspec-users] Create haml files with rspec_controller command? Message-ID: <90a4460742df826d9fb9fdaf1b123b0a@ruby-forum.com> It is a nuisance to have to rename all of your files from .erb to .haml. Is there a quick way around this? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Jun 15 13:06:40 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Jun 2008 12:06:40 -0500 Subject: [rspec-users] Create haml files with rspec_controller command? In-Reply-To: <90a4460742df826d9fb9fdaf1b123b0a@ruby-forum.com> References: <90a4460742df826d9fb9fdaf1b123b0a@ruby-forum.com> Message-ID: On Jun 15, 2008, at 11:59 AM, Chris Olsen wrote: > It is a nuisance to have to rename all of your files from .erb > to .haml. > Is there a quick way around this? Not yet. Feel free to file a feature request for an option on the generators: http://rspec.lighthouseapp.com/projects/5645 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sun Jun 15 13:18:36 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Sun, 15 Jun 2008 19:18:36 +0200 Subject: [rspec-users] Create haml files with rspec_controller command? In-Reply-To: References: <90a4460742df826d9fb9fdaf1b123b0a@ruby-forum.com> Message-ID: <887c6254e9961759528a0b63940ecf0f@ruby-forum.com> Thanks for letting me know. A ticket has been created. -- Posted via http://www.ruby-forum.com/. From d at sofer.com Sun Jun 15 17:33:45 2008 From: d at sofer.com (Danny Sofer) Date: Sun, 15 Jun 2008 22:33:45 +0100 Subject: [rspec-users] RSpec story failing because of routing error on "/" In-Reply-To: References: <5D56A07E-6978-48FB-A5C6-F8CE3E7AB2D6@sofer.com> Message-ID: On 15 Jun 2008, at 14:09, David Chelimsky wrote: > On Jun 15, 2008, at 4:33 AM, Danny Sofer wrote: > >> When running tests on the restful_authentication plugin, I am >> getting a routing error on "/". >> >> Which I don't really understand, because the route "/" certainly >> does exist as I can confirm when I run ./script/server and point my >> browser at http://localhost:3000/ > > Actually, that route does NOT exist. You're seeing something because > there is an index.html file in public, not because Rails routing is > getting you there. > > Add an explicit root mapping to the appropriate controller and > you'll get past this. Looks like there are more problems ahead, but > they seem to be in restful_authentication. > > Cheers, > David Oh, a bit obvious! Thank you so much. For the record, it is possible to get the Restful Authentication stories running with a few extra steps. After installing all the various plugins as outlined in my previous missive, do the following: 1. Add a "/" route to config.routes.rb: (as pointed out by David) map.login '/', :controller => 'sessions', :action => 'new' 2. Copy the line "include AuthenticatedSystem" into class ApplicationController in app/controllers/application.rb 3. Add app/views/layouts/application.html.erb with something like the following: Restful auth
<%= flash[:notice] %>
<%= flash[:error] %>
<%= yield :layout %> 4. In /stories/sessions/users/sessions.story there is a scenario which assumes that "fixtures have been run sometime". Well they haven't, so: "And her session store should have user_id: 1" (and not 4) on lines 56 and 110. Then run: ruby stories/rest_auth_stories.rb "16 scenarios: 16 succeeded, 0 failed, 0 pending" Hooray! > git clone git://github.com/rails/rails.git vendor/rails > git clone git://github.com/dchelimsky/rspec.git vendor/plugins/rspec > git clone git://github.com/dchelimsky/rspec-rails.git vendor/plugins/ > rspec-rails > git clone git://github.com/technoweenie/restful-authentication.git > vendor/plugins/restful-authentication > > ./script/generate rspec > ./script/generate authenticated user sessions > > mate app/controllers (and added " include AuthenticatedSystem" to > the application controller) > > rake db:migrate > rake db:test:prepare > > -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2458 bytes Desc: not available URL: From aidy.lewis at googlemail.com Mon Jun 16 07:27:19 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Mon, 16 Jun 2008 12:27:19 +0100 Subject: [rspec-users] minimise scenarios Message-ID: <7ac2300c0806160427l7e7a1f85kd1cb4c44be101cc1@mail.gmail.com> Hi, I have a number of scenarios that are virtually the same apart from one piece of test data Scenario: The user is returned search links with expected search text description Given a logged in xx user When clicks 'Advanced Search' And enters 'Aidy' in the Contributors field And clicks search Then the resultant links are displayed with the search text in each description So, in the first clause of the When method, I would like to change the string value. Is there any way of doing this better than copying and pasting the above Scenario with one different string value and re-running that test? Regards Aidy From lists at ruby-forum.com Mon Jun 16 07:37:58 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Mon, 16 Jun 2008 13:37:58 +0200 Subject: [rspec-users] rspec book Message-ID: <179298cf86522724ea39d7c88f79f9e6@ruby-forum.com> I know that David Chelimsky and Aslak Helles?y were writing a book about rspec for the pragmatic programmers. And I hoped it would be available as a beta book. will it be? David or Aslak, I would like if you can tell us something about the book. When can we expect it to arrive? Or maybe anyone knows about other book about the theme. Best Regards Juan M. Cervera -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Jun 16 07:38:31 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jun 2008 06:38:31 -0500 Subject: [rspec-users] rspec book In-Reply-To: <179298cf86522724ea39d7c88f79f9e6@ruby-forum.com> References: <179298cf86522724ea39d7c88f79f9e6@ruby-forum.com> Message-ID: <4898396E-3350-4B81-90E7-0A4D70DB4D56@gmail.com> On Jun 16, 2008, at 6:37 AM, Juanma Cervera wrote: > I know that David Chelimsky and Aslak Helles?y were writing a book > about > rspec for the pragmatic programmers. > > And I hoped it would be available as a beta book. will it be? > > David or Aslak, I would like if you can tell us something about the > book. > When can we expect it to arrive? Assuming no set-backs, beta by mid-summer. Cheers, David From dchelimsky at gmail.com Mon Jun 16 07:49:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jun 2008 06:49:22 -0500 Subject: [rspec-users] minimise scenarios In-Reply-To: <7ac2300c0806160427l7e7a1f85kd1cb4c44be101cc1@mail.gmail.com> References: <7ac2300c0806160427l7e7a1f85kd1cb4c44be101cc1@mail.gmail.com> Message-ID: On Jun 16, 2008, at 6:27 AM, aidy lewis wrote: > Hi, > > I have a number of scenarios that are virtually the same apart from > one piece of test data > > Scenario: The user is returned search links with expected search > text description > Given a logged in xx user > When clicks 'Advanced Search' > And enters 'Aidy' in the Contributors field > And clicks search > Then the resultant links are displayed with the search text in > each description > > So, in the first clause of the When method, I would like to change the > string value. > > Is there any way of doing this better than copying and pasting the > above Scenario with one different string value and re-running that > test? For now, no. There is an idea in the works. For right now, I would merge some of those steps: Scenario: display search links Given I am logged in as David When I do an Advanced Search for Contributors: 'Aidy' Then I should see blah de blah That one When covers the three in the original example, and reads quite naturally in the domain, no? In the future you'll be able to do *something* like this: Scenario: display search links Given I am logged in as David When I do an Advanced Search for Contributors: 'Aidy' Then I should see blah de blah More Examples: |User |Query |Result | |David |Contributors:'David' |RSpec | |David |Contributors:'Joe' |this or that | Not exactly sure how that's going to look yet, but it's basically a FIT-inspired tabular input/output format with the columns bound to the last Scenario. Coming soon to a workstation near you (but not too soon). Cheers, David Cheers, David From aidy.lewis at googlemail.com Mon Jun 16 08:12:18 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Mon, 16 Jun 2008 13:12:18 +0100 Subject: [rspec-users] minimise scenarios In-Reply-To: References: <7ac2300c0806160427l7e7a1f85kd1cb4c44be101cc1@mail.gmail.com> Message-ID: <7ac2300c0806160512x78259242te57f7e48e232fa46@mail.gmail.com> Thanks David, Maybe my steps are too granular and I will link them up as suggested. What I do like though is re-using steps in different domains. So I can have When "clicks '$link_text'" do | link_text | browser.link(:text, Regexp.new(link_text)).click end When "clicks on '$button_value' button" do | button_value| browser.button(:value, button_value).click end Which will click any link and button, so I can say to a manual tester and/or BA follow this step format and we have done a lot to actually having the automated UI testing straight away. Obviously this will not work on domain specific steps. Aidy On 16/06/2008, David Chelimsky wrote: > On Jun 16, 2008, at 6:27 AM, aidy lewis wrote: > > > > Hi, > > > > I have a number of scenarios that are virtually the same apart from > > one piece of test data > > > > Scenario: The user is returned search links with expected search > > text description > > Given a logged in xx user > > When clicks 'Advanced Search' > > And enters 'Aidy' in the Contributors field > > And clicks search > > Then the resultant links are displayed with the search text in > > each description > > > > So, in the first clause of the When method, I would like to change the > > string value. > > > > Is there any way of doing this better than copying and pasting the > > above Scenario with one different string value and re-running that > > test? > > > > For now, no. There is an idea in the works. For right now, I would merge > some of those steps: > > Scenario: display search links > Given I am logged in as David > When I do an Advanced Search for Contributors: 'Aidy' > Then I should see blah de blah > > That one When covers the three in the original example, and reads quite > naturally in the domain, no? > > In the future you'll be able to do *something* like this: > > Scenario: display search links > Given I am logged in as David > When I do an Advanced Search for Contributors: 'Aidy' > Then I should see blah de blah > > More Examples: > |User |Query |Result | > |David |Contributors:'David' |RSpec | > |David |Contributors:'Joe' |this or that | > > Not exactly sure how that's going to look yet, but it's basically a > FIT-inspired tabular input/output format with the columns bound to the last > Scenario. Coming soon to a workstation near you (but not too soon). > > Cheers, > David > > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aselder at mac.com Mon Jun 16 15:58:47 2008 From: aselder at mac.com (Andrew Selder) Date: Mon, 16 Jun 2008 15:58:47 -0400 Subject: [rspec-users] render_to_string confusing ControllerSpec Message-ID: Hi all, I have a controller I'm trying to spec out, and I'm running into some issues with render_to_string. Basically, the show gets an array of objects, calls render_to_string for each of them, and then renders the show template. So I have the standard spec: it "should render show template" do do_get response.should render_template('show') end but when I run the spec I get the following failure: 'SearchesController handling GET /searches/1 should render show template' FAILED expected "show", got "properties/_map_info_box" Does anybody have any ideas? Thanks, Andrew From dan at bakineggs.com Mon Jun 16 17:39:46 2008 From: dan at bakineggs.com (Daniel Barry) Date: Mon, 16 Jun 2008 16:39:46 -0500 Subject: [rspec-users] rspec license plate Message-ID: <64967b630806161439q50e2bcb6w92c4fea504b00d9e@mail.gmail.com> I was driving to my parents' house this weekend and saw this in their neighborhood: http://bakineggs.com/rspec1.jpg Whoever owns this car is awesome in my book. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hotfusionman at yahoo.com Mon Jun 16 17:45:21 2008 From: hotfusionman at yahoo.com (Al Chou) Date: Mon, 16 Jun 2008 14:45:21 -0700 (PDT) Subject: [rspec-users] rspec license plate Message-ID: <437704.47289.qm@web58711.mail.re1.yahoo.com> And notice that the car's red. Not ruby red, but then rubies usually aren't really the shade of red that most people think they should be. Al ----- Original Message ---- From: Daniel Barry To: rspec-users at rubyforge.org Sent: Monday, June 16, 2008 2:39:46 PM Subject: [rspec-users] rspec license plate I was driving to my parents' house this weekend and saw this in their neighborhood: http://bakineggs.com/rspec1.jpg Whoever owns this car is awesome in my book. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jun 16 17:52:34 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jun 2008 16:52:34 -0500 Subject: [rspec-users] rspec license plate In-Reply-To: <64967b630806161439q50e2bcb6w92c4fea504b00d9e@mail.gmail.com> References: <64967b630806161439q50e2bcb6w92c4fea504b00d9e@mail.gmail.com> Message-ID: <7D867FF2-F815-4DBE-A64A-FBFC7638270F@gmail.com> Cool! Hard to make out, but is that an Illinois plate? On Jun 16, 2008, at 4:39 PM, Daniel Barry wrote: > I was driving to my parents' house this weekend and saw this in > their neighborhood: > > http://bakineggs.com/rspec1.jpg > > Whoever owns this car is awesome in my book. > _______________________________________________ > 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 Mon Jun 16 18:15:18 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 17 Jun 2008 00:15:18 +0200 Subject: [rspec-users] rspec license plate In-Reply-To: <7D867FF2-F815-4DBE-A64A-FBFC7638270F@gmail.com> References: <64967b630806161439q50e2bcb6w92c4fea504b00d9e@mail.gmail.com> <7D867FF2-F815-4DBE-A64A-FBFC7638270F@gmail.com> Message-ID: <8d961d900806161515m80746b8s8bb530840ed9f474@mail.gmail.com> On Mon, Jun 16, 2008 at 11:52 PM, David Chelimsky wrote: > Cool! > Hard to make out, but is that an Illinois plate? > On Jun 16, 2008, at 4:39 PM, Daniel Barry wrote: > Noteworthy is also that it's a muda Toyota. -It has one pending. Aslak > I was driving to my parents' house this weekend and saw this in their > neighborhood: > > http://bakineggs.com/rspec1.jpg > > Whoever owns this car is awesome in my book. > _______________________________________________ > 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 wolfmanjm at gmail.com Mon Jun 16 19:18:29 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Mon, 16 Jun 2008 16:18:29 -0700 (PDT) Subject: [rspec-users] Reusing story snippets In-Reply-To: <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> Message-ID: <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> Along similar lines is there a way to do the equivalent of before(:all) and after(:all) or after(:each) in stories? Basically I have a similar situation as above, but I need to make sure the user is logged out after each scenario. or that the user is logged in once at the start of all scenarios then logged out after them regardless of errors etc. Thanks On Jun 14, 7:40 am, David Chelimsky wrote: > On Jun 14, 2008, at 5:03 AM, Mikel Lindsaar wrote: > > > I find myself doing this: > > > Scenario "logged in user visiting the home page" do > > Given "A logged in user" do > > a_logged_in_user > > end > > > When "..." > > Then "..." > > end > > Things have evolved a bit since Story Runner first came out. The > approach you are using here is what we call in-line steps, and was the > only option back then. > > You can now use disconnected steps in both plain text and Ruby: > > require 'steps/visitors' > > Story "logged in users see more stuff", %( > As a registered user > I want to see more stuff than non-registered users > So I can feel like I'm getting some benefit in return for giving > up my personal information > ), :steps => :visitors do > Scenario "logged in user visits home page" do > Given "I am logged in as David" > When "I visit the home page" > Then "I should see the message 'Welcome David'" > end > end > > # in steps/visitors > > steps_for :visitors do > Given "I am logged in as $name" do |name| > # create a user w/ name and log in as that user > end > > When ".." > Then ".." > end > > This approach really cleans up the story code leaving the informative > bits while hiding the redundant detail. > > HTH, > David > > > The a_logged_in_user method is a helper method in helper.rb which sets > > up the state so that the user can browse the website. > > > Later in the story of course, I can just do 'Given "A logged in user" > > and it will get the previous definition. > > > Is there any way to avoid that duplicated Given call at the top of > > almost every story? > > > Mikel > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Jun 16 21:32:04 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jun 2008 20:32:04 -0500 Subject: [rspec-users] Reusing story snippets In-Reply-To: <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> Message-ID: On Jun 16, 2008, at 6:18 PM, Jim Morris wrote: > Along similar lines is there a way to do the equivalent of > before(:all) and after(:all) or after(:each) in stories? > > Basically I have a similar situation as above, but I need to make sure > the user is logged out after each scenario. or that the user is logged > in once at the start of all scenarios then logged out after them > regardless of errors etc. Each scenario is run in its own instance of RailsStory, so it's got a new session (IntegrationSession). So you *should* get this isolation implicitly. There are callbacks you can use if you create and register a listener, but they won't have access to the same scope that exists inside the steps. Here's how you do it: class MyListener def method_missing sym, *args, &block # ignore all messages you don't care about end def run_started(num_scenarios); end def story_started(title, narrative); end etc end See http://rspec.info/rdoc/classes/Spec/Runner/Formatter/Story/PlainTextFormatter.html , which implements all the callback methods (we need better docs for it, but everything is there - don't use collected_steps though - that should really be marked nodoc). Cheers, David > Thanks > > > On Jun 14, 7:40 am, David Chelimsky wrote: >> On Jun 14, 2008, at 5:03 AM, Mikel Lindsaar wrote: >> >>> I find myself doing this: >> >>> Scenario "logged in user visiting the home page" do >>> Given "A logged in user" do >>> a_logged_in_user >>> end >> >>> When "..." >>> Then "..." >>> end >> >> Things have evolved a bit since Story Runner first came out. The >> approach you are using here is what we call in-line steps, and was >> the >> only option back then. >> >> You can now use disconnected steps in both plain text and Ruby: >> >> require 'steps/visitors' >> >> Story "logged in users see more stuff", %( >> As a registered user >> I want to see more stuff than non-registered users >> So I can feel like I'm getting some benefit in return for giving >> up my personal information >> ), :steps => :visitors do >> Scenario "logged in user visits home page" do >> Given "I am logged in as David" >> When "I visit the home page" >> Then "I should see the message 'Welcome David'" >> end >> end >> >> # in steps/visitors >> >> steps_for :visitors do >> Given "I am logged in as $name" do |name| >> # create a user w/ name and log in as that user >> end >> >> When ".." >> Then ".." >> end >> >> This approach really cleans up the story code leaving the informative >> bits while hiding the redundant detail. >> >> HTH, >> David >> >>> The a_logged_in_user method is a helper method in helper.rb which >>> sets >>> up the state so that the user can browse the website. >> >>> Later in the story of course, I can just do 'Given "A logged in >>> user" >>> and it will get the previous definition. >> >>> Is there any way to avoid that duplicated Given call at the top of >>> almost every story? >> >>> Mikel >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Jun 16 21:34:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jun 2008 20:34:38 -0500 Subject: [rspec-users] render_to_string confusing ControllerSpec In-Reply-To: References: Message-ID: <26268AB4-411D-47F4-80E6-F50452C6CE9A@gmail.com> On Jun 16, 2008, at 2:58 PM, Andrew Selder wrote: > Hi all, > > I have a controller I'm trying to spec out, and I'm running into > some issues with render_to_string. > > Basically, the show gets an array of objects, calls render_to_string > for each of them, and then renders the show template. > > So I have the standard spec: > > > it "should render show template" do > do_get > response.should render_template('show') > end > > > but when I run the spec I get the following failure: > > 'SearchesController handling GET /searches/1 should render show > template' FAILED > expected "show", got "properties/_map_info_box" > > > Does anybody have any ideas? Please post the controller action and the full backtrace: script/spec spec/controller/path/to/the/spec.rb -fsb Thx From aselder at mac.com Mon Jun 16 21:59:08 2008 From: aselder at mac.com (Andrew Selder) Date: Mon, 16 Jun 2008 21:59:08 -0400 Subject: [rspec-users] render_to_string confusing ControllerSpec In-Reply-To: <26268AB4-411D-47F4-80E6-F50452C6CE9A@gmail.com> References: <26268AB4-411D-47F4-80E6-F50452C6CE9A@gmail.com> Message-ID: <0ED66439-3E1D-4979-A97E-FF8AB94DCFD1@mac.com> Here's the back trace 1) 'SearchesController handling GET /searches/1 should render show template' FAILED expected "show", got "properties/_map_info_box" /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ expectations.rb:52:in `fail_with' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ expectations/handler.rb:25:in `handle_matcher' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ expectations/extensions/object.rb:31:in `should' ./spec/controllers/searches_controller_spec.rb:26: /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ example/example_methods.rb:84:in `instance_eval' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ example/example_methods.rb:84:in `run_with_description_capturing' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ example/example_methods.rb:21:in `execute' /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ example/example_methods.rb:18:in `execute' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ example/example_group_methods.rb:303:in `execute_examples' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ example/example_group_methods.rb:302:in `each' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ example/example_group_methods.rb:302:in `execute_examples' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ example/example_group_methods.rb:130:in `run' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ runner/example_group_runner.rb:22:in `run' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ runner/example_group_runner.rb:21:in `each' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ runner/example_group_runner.rb:21:in `run' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ runner/options.rb:106:in `run_examples' /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ runner/command_line.rb:19:in `run' script/spec:4: And here's the controller action: def show @search = Search.find(params[:id]) if @search.too_many_results? message_to_new "Your search returned too many results (#{@search.count }). Please narrow your criteria and search again." return elsif @search.no_results? message_to_new "Your search returned no results. Please change your criteria and search again." return end init_map @props = @search.do_search @markers = [] @props.each do |prop| coords = prop.latlng unless coords.lat == 0 || coords.lng == 0 prop.info_box = render_to_string(:partial => "/properties/ map_info_box", :object => prop) mark = prop.has_photos? ? "green" : "red" marker = GMarker.new(coords, :title => prop_help.bubble_header(prop), :info_window => prop.info_box, :icon => Variable.new(mark)) @map.overlay_init marker @markers << marker end end unless @markers.empty? @map.center_zoom_on_points_init(*(@markers.collect {|x| x.point})) else @map.center_zoom_init(@search.center, 12) end end Thanks, Andrew On Jun 16, 2008, at 9:34 PM, David Chelimsky wrote: > On Jun 16, 2008, at 2:58 PM, Andrew Selder wrote: > >> Hi all, >> >> I have a controller I'm trying to spec out, and I'm running into >> some issues with render_to_string. >> >> Basically, the show gets an array of objects, calls >> render_to_string for each of them, and then renders the show >> template. >> >> So I have the standard spec: >> >> >> it "should render show template" do >> do_get >> response.should render_template('show') >> end >> >> >> but when I run the spec I get the following failure: >> >> 'SearchesController handling GET /searches/1 should render show >> template' FAILED >> expected "show", got "properties/_map_info_box" >> >> >> Does anybody have any ideas? > > Please post the controller action and the full backtrace: > > script/spec spec/controller/path/to/the/spec.rb -fsb > > Thx > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Jun 16 22:03:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jun 2008 21:03:55 -0500 Subject: [rspec-users] render_to_string confusing ControllerSpec In-Reply-To: <0ED66439-3E1D-4979-A97E-FF8AB94DCFD1@mac.com> References: <26268AB4-411D-47F4-80E6-F50452C6CE9A@gmail.com> <0ED66439-3E1D-4979-A97E-FF8AB94DCFD1@mac.com> Message-ID: <663C9D94-7938-488E-924D-BCBBD52F00E4@gmail.com> On Jun 16, 2008, at 8:59 PM, Andrew Selder wrote: > Here's the back trace > > 1) > 'SearchesController handling GET /searches/1 should render show > template' FAILED > expected "show", got "properties/_map_info_box" > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > expectations.rb:52:in `fail_with' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > expectations/handler.rb:25:in `handle_matcher' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > expectations/extensions/object.rb:31:in `should' > ./spec/controllers/searches_controller_spec.rb:26: > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > example/example_methods.rb:84:in `instance_eval' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > example/example_methods.rb:84:in `run_with_description_capturing' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > example/example_methods.rb:21:in `execute' > /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > example/example_methods.rb:18:in `execute' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > example/example_group_methods.rb:303:in `execute_examples' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > example/example_group_methods.rb:302:in `each' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > example/example_group_methods.rb:302:in `execute_examples' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > example/example_group_methods.rb:130:in `run' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > runner/example_group_runner.rb:22:in `run' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > runner/example_group_runner.rb:21:in `each' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > runner/example_group_runner.rb:21:in `run' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > runner/options.rb:106:in `run_examples' > /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ > runner/command_line.rb:19:in `run' > script/spec:4: > > And here's the controller action: > > def show > @search = Search.find(params[:id]) > if @search.too_many_results? > message_to_new "Your search returned too many results (#{@search.count > }). Please narrow your criteria and search again." > return > elsif @search.no_results? > message_to_new "Your search returned no results. Please change > your criteria and search again." > return > end > init_map > @props = @search.do_search > @markers = [] > @props.each do |prop| > coords = prop.latlng > unless coords.lat == 0 || coords.lng == 0 > prop.info_box = render_to_string(:partial => "/properties/ > map_info_box", :object => prop) This is the line that's causing you trouble. Try stubbing this one out as well: response.stub_render(:partial => "/properties/map_info_box", :object => anything()) Let us know if it works. Cheers, David > > mark = prop.has_photos? ? "green" : "red" > marker = GMarker.new(coords, :title => > prop_help.bubble_header(prop), :info_window => prop.info_box, :icon > => Variable.new(mark)) > @map.overlay_init marker > @markers << marker > end > end > unless @markers.empty? > @map.center_zoom_on_points_init(*(@markers.collect {|x| > x.point})) > else > @map.center_zoom_init(@search.center, 12) > end > end > > Thanks, > > Andrew > > On Jun 16, 2008, at 9:34 PM, David Chelimsky wrote: > >> On Jun 16, 2008, at 2:58 PM, Andrew Selder wrote: >> >>> Hi all, >>> >>> I have a controller I'm trying to spec out, and I'm running into >>> some issues with render_to_string. >>> >>> Basically, the show gets an array of objects, calls >>> render_to_string for each of them, and then renders the show >>> template. >>> >>> So I have the standard spec: >>> >>> >>> it "should render show template" do >>> do_get >>> response.should render_template('show') >>> end >>> >>> >>> but when I run the spec I get the following failure: >>> >>> 'SearchesController handling GET /searches/1 should render show >>> template' FAILED >>> expected "show", got "properties/_map_info_box" >>> >>> >>> Does anybody have any ideas? >> >> Please post the controller action and the full backtrace: >> >> script/spec spec/controller/path/to/the/spec.rb -fsb >> >> Thx >> _______________________________________________ >> 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 aselder at mac.com Mon Jun 16 22:19:14 2008 From: aselder at mac.com (Andrew Selder) Date: Mon, 16 Jun 2008 22:19:14 -0400 Subject: [rspec-users] render_to_string confusing ControllerSpec In-Reply-To: <663C9D94-7938-488E-924D-BCBBD52F00E4@gmail.com> References: <26268AB4-411D-47F4-80E6-F50452C6CE9A@gmail.com> <0ED66439-3E1D-4979-A97E-FF8AB94DCFD1@mac.com> <663C9D94-7938-488E-924D-BCBBD52F00E4@gmail.com> Message-ID: <102510ED-B0F8-4CE0-9BBF-96B1C2175F44@mac.com> I updated the spec to look like this: it "should render show template" do do_get controller.stub_render(:partial => "/properties/ map_info_box", :object => anything()) response.should render_template('show') end and I still get the same failure and back trace. In addition to not working, the problem with stubbing out that render to string is that I can't then check for the presence of those strings in the final output. Thanks, Andrew On Jun 16, 2008, at 10:03 PM, David Chelimsky wrote: > On Jun 16, 2008, at 8:59 PM, Andrew Selder wrote: > >> Here's the back trace >> >> 1) >> 'SearchesController handling GET /searches/1 should render show >> template' FAILED >> expected "show", got "properties/_map_info_box" >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> expectations.rb:52:in `fail_with' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> expectations/handler.rb:25:in `handle_matcher' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> expectations/extensions/object.rb:31:in `should' >> ./spec/controllers/searches_controller_spec.rb:26: >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> example/example_methods.rb:84:in `instance_eval' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> example/example_methods.rb:84:in `run_with_description_capturing' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> example/example_methods.rb:21:in `execute' >> /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> example/example_methods.rb:18:in `execute' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> example/example_group_methods.rb:303:in `execute_examples' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> example/example_group_methods.rb:302:in `each' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> example/example_group_methods.rb:302:in `execute_examples' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> example/example_group_methods.rb:130:in `run' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> runner/example_group_runner.rb:22:in `run' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> runner/example_group_runner.rb:21:in `each' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> runner/example_group_runner.rb:21:in `run' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> runner/options.rb:106:in `run_examples' >> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/ >> runner/command_line.rb:19:in `run' >> script/spec:4: >> >> And here's the controller action: >> >> def show >> @search = Search.find(params[:id]) >> if @search.too_many_results? >> message_to_new "Your search returned too many results (#{@search.count >> }). Please narrow your criteria and search again." >> return >> elsif @search.no_results? >> message_to_new "Your search returned no results. Please change >> your criteria and search again." >> return >> end >> init_map >> @props = @search.do_search >> @markers = [] >> @props.each do |prop| >> coords = prop.latlng >> unless coords.lat == 0 || coords.lng == 0 >> prop.info_box = render_to_string(:partial => "/properties/ >> map_info_box", :object => prop) > > This is the line that's causing you trouble. Try stubbing this one > out as well: > > response.stub_render(:partial => "/properties/map_info_box", :object > => anything()) > > Let us know if it works. > > Cheers, > David > >> >> mark = prop.has_photos? ? "green" : "red" >> marker = GMarker.new(coords, :title => >> prop_help.bubble_header(prop), :info_window => prop.info_box, :icon >> => Variable.new(mark)) >> @map.overlay_init marker >> @markers << marker >> end >> end >> unless @markers.empty? >> @map.center_zoom_on_points_init(*(@markers.collect {|x| >> x.point})) >> else >> @map.center_zoom_init(@search.center, 12) >> end >> end >> >> Thanks, >> >> Andrew >> >> On Jun 16, 2008, at 9:34 PM, David Chelimsky wrote: >> >>> On Jun 16, 2008, at 2:58 PM, Andrew Selder wrote: >>> >>>> Hi all, >>>> >>>> I have a controller I'm trying to spec out, and I'm running into >>>> some issues with render_to_string. >>>> >>>> Basically, the show gets an array of objects, calls >>>> render_to_string for each of them, and then renders the show >>>> template. >>>> >>>> So I have the standard spec: >>>> >>>> >>>> it "should render show template" do >>>> do_get >>>> response.should render_template('show') >>>> end >>>> >>>> >>>> but when I run the spec I get the following failure: >>>> >>>> 'SearchesController handling GET /searches/1 should render show >>>> template' FAILED >>>> expected "show", got "properties/_map_info_box" >>>> >>>> >>>> Does anybody have any ideas? >>> >>> Please post the controller action and the full backtrace: >>> >>> script/spec spec/controller/path/to/the/spec.rb -fsb >>> >>> Thx >>> _______________________________________________ >>> 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 Mon Jun 16 23:05:50 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jun 2008 22:05:50 -0500 Subject: [rspec-users] render_to_string confusing ControllerSpec In-Reply-To: <102510ED-B0F8-4CE0-9BBF-96B1C2175F44@mac.com> References: <26268AB4-411D-47F4-80E6-F50452C6CE9A@gmail.com> <0ED66439-3E1D-4979-A97E-FF8AB94DCFD1@mac.com> <663C9D94-7938-488E-924D-BCBBD52F00E4@gmail.com> <102510ED-B0F8-4CE0-9BBF-96B1C2175F44@mac.com> Message-ID: <0BD90C77-CB22-4EBA-A69C-C241CFEB0ECC@gmail.com> On Jun 16, 2008, at 9:19 PM, Andrew Selder wrote: > I updated the spec to look like this: > > it "should render show template" do > do_get > controller.stub_render(:partial => "/properties/ > map_info_box", :object => anything()) > response.should render_template('show') > end > > and I still get the same failure and back trace. > > In addition to not working, the problem with stubbing out that > render to string is that I can't then check for the presence of > those strings in the final output. Well, therein lies the real problem :) This action is exhibiting a number of code smells. I don't know how familiar you might be w/ that, but: Long Method - a method that does too many things (I count at least 10) Feature Envy - one one object is doing work on another object's data There's also a lot of asking, violating the Tell Don't Ask principle. This block: @props.each do |prop| coords = prop.latlng unless coords.lat == 0 || coords.lng == 0 prop.info_box = render_to_string(:partial => "/properties/ map_info_box", :object => prop) mark = prop.has_photos? ? "green" : "red" marker = GMarker.new(coords, :title => prop_help.bubble_header(prop),\ :info_window => prop.info_box, :icon => Variable.new(mark)) @map.overlay_init marker @markers << marker end end .. could become: @props.each do |prop| @markers << prop.generate_marker if prop.needs_marker? end Much simpler to test at that point! I'd recommend heading down that path. HTH, David > Thanks, > > Andrew > > On Jun 16, 2008, at 10:03 PM, David Chelimsky wrote: > >> On Jun 16, 2008, at 8:59 PM, Andrew Selder wrote: >> >>> Here's the back trace >>> >>> 1) >>> 'SearchesController handling GET /searches/1 should render show >>> template' FAILED >>> expected "show", got "properties/_map_info_box" >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/expectations.rb:52:in `fail_with' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/expectations/handler.rb:25:in `handle_matcher' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/expectations/extensions/object.rb:31:in `should' >>> ./spec/controllers/searches_controller_spec.rb:26: >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/example/example_methods.rb:84:in `instance_eval' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/example/example_methods.rb:84:in >>> `run_with_description_capturing' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/example/example_methods.rb:21:in `execute' >>> /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/example/example_methods.rb:18:in `execute' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/example/example_group_methods.rb:303:in `execute_examples' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/example/example_group_methods.rb:302:in `each' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/example/example_group_methods.rb:302:in `execute_examples' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/example/example_group_methods.rb:130:in `run' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/runner/example_group_runner.rb:22:in `run' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/runner/example_group_runner.rb:21:in `each' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/runner/example_group_runner.rb:21:in `run' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/runner/options.rb:106:in `run_examples' >>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>> spec/runner/command_line.rb:19:in `run' >>> script/spec:4: >>> >>> And here's the controller action: >>> >>> def show >>> @search = Search.find(params[:id]) >>> if @search.too_many_results? >>> message_to_new "Your search returned too many results (#{@search.count >>> }). Please narrow your criteria and search again." >>> return >>> elsif @search.no_results? >>> message_to_new "Your search returned no results. Please change >>> your criteria and search again." >>> return >>> end >>> init_map >>> @props = @search.do_search >>> @markers = [] >>> @props.each do |prop| >>> coords = prop.latlng >>> unless coords.lat == 0 || coords.lng == 0 >>> prop.info_box = render_to_string(:partial => "/properties/ >>> map_info_box", :object => prop) >> >> This is the line that's causing you trouble. Try stubbing this one >> out as well: >> >> response.stub_render(:partial => "/properties/ >> map_info_box", :object => anything()) >> >> Let us know if it works. >> >> Cheers, >> David >> >>> >>> mark = prop.has_photos? ? "green" : "red" >>> marker = GMarker.new(coords, :title => >>> prop_help.bubble_header(prop), :info_window => >>> prop.info_box, :icon => Variable.new(mark)) >>> @map.overlay_init marker >>> @markers << marker >>> end >>> end >>> unless @markers.empty? >>> @map.center_zoom_on_points_init(*(@markers.collect {|x| >>> x.point})) >>> else >>> @map.center_zoom_init(@search.center, 12) >>> end >>> end >>> >>> Thanks, >>> >>> Andrew >>> >>> On Jun 16, 2008, at 9:34 PM, David Chelimsky wrote: >>> >>>> On Jun 16, 2008, at 2:58 PM, Andrew Selder wrote: >>>> >>>>> Hi all, >>>>> >>>>> I have a controller I'm trying to spec out, and I'm running into >>>>> some issues with render_to_string. >>>>> >>>>> Basically, the show gets an array of objects, calls >>>>> render_to_string for each of them, and then renders the show >>>>> template. >>>>> >>>>> So I have the standard spec: >>>>> >>>>> >>>>> it "should render show template" do >>>>> do_get >>>>> response.should render_template('show') >>>>> end >>>>> >>>>> >>>>> but when I run the spec I get the following failure: >>>>> >>>>> 'SearchesController handling GET /searches/1 should render show >>>>> template' FAILED >>>>> expected "show", got "properties/_map_info_box" >>>>> >>>>> >>>>> Does anybody have any ideas? >>>> >>>> Please post the controller action and the full backtrace: >>>> >>>> script/spec spec/controller/path/to/the/spec.rb -fsb >>>> >>>> Thx >>>> _______________________________________________ >>>> 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 aselder at mac.com Mon Jun 16 23:23:46 2008 From: aselder at mac.com (Andrew Selder) Date: Mon, 16 Jun 2008 23:23:46 -0400 Subject: [rspec-users] render_to_string confusing ControllerSpec In-Reply-To: <0BD90C77-CB22-4EBA-A69C-C241CFEB0ECC@gmail.com> References: <26268AB4-411D-47F4-80E6-F50452C6CE9A@gmail.com> <0ED66439-3E1D-4979-A97E-FF8AB94DCFD1@mac.com> <663C9D94-7938-488E-924D-BCBBD52F00E4@gmail.com> <102510ED-B0F8-4CE0-9BBF-96B1C2175F44@mac.com> <0BD90C77-CB22-4EBA-A69C-C241CFEB0ECC@gmail.com> Message-ID: <9ED7A531-07F2-495D-B4BC-4FEEA88C0816@mac.com> David, Valid point about the method needing some refactoring. But another key rule of refactoring is to have passing tests before refactoring. This is one of the things that's a minor annoyance I have about rails, you can't associate views with models. The problem with the refactoring suggested is that render_to_string is a member of ActionController::Base, and moving it in to a string construction method in the model is complicated by no helpers available in the model, and that partial uses tons of helpers. So it's hard to move a generate_marker method to the model. Regardless of all of the above, RSpec controller specs have issues when testing which template was rendered if you use render_to_string. Andrew On Jun 16, 2008, at 11:05 PM, David Chelimsky wrote: > On Jun 16, 2008, at 9:19 PM, Andrew Selder wrote: > >> I updated the spec to look like this: >> >> it "should render show template" do >> do_get >> controller.stub_render(:partial => "/properties/ >> map_info_box", :object => anything()) >> response.should render_template('show') >> end >> >> and I still get the same failure and back trace. >> >> In addition to not working, the problem with stubbing out that >> render to string is that I can't then check for the presence of >> those strings in the final output. > > Well, therein lies the real problem :) This action is exhibiting a > number of code smells. I don't know how familiar you might be w/ > that, but: > > Long Method - a method that does too many things (I count at least > 10) > Feature Envy - one one object is doing work on another object's data > > There's also a lot of asking, violating the Tell Don't Ask principle. > > This block: > > @props.each do |prop| > coords = prop.latlng > unless coords.lat == 0 || coords.lng == 0 > prop.info_box = render_to_string(:partial => "/properties/ > map_info_box", :object => prop) > mark = prop.has_photos? ? "green" : "red" > marker = GMarker.new(coords, :title => > prop_help.bubble_header(prop),\ > :info_window => prop.info_box, :icon => Variable.new(mark)) > @map.overlay_init marker > @markers << marker > end > end > > .. could become: > > @props.each do |prop| > @markers << prop.generate_marker if prop.needs_marker? > end > > Much simpler to test at that point! I'd recommend heading down that > path. > > HTH, > David > > > >> Thanks, >> >> Andrew >> >> On Jun 16, 2008, at 10:03 PM, David Chelimsky wrote: >> >>> On Jun 16, 2008, at 8:59 PM, Andrew Selder wrote: >>> >>>> Here's the back trace >>>> >>>> 1) >>>> 'SearchesController handling GET /searches/1 should render show >>>> template' FAILED >>>> expected "show", got "properties/_map_info_box" >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/expectations.rb:52:in `fail_with' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/expectations/handler.rb:25:in `handle_matcher' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/expectations/extensions/object.rb:31:in `should' >>>> ./spec/controllers/searches_controller_spec.rb:26: >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/example/example_methods.rb:84:in `instance_eval' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/example/example_methods.rb:84:in >>>> `run_with_description_capturing' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/example/example_methods.rb:21:in `execute' >>>> /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/example/example_methods.rb:18:in `execute' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/example/example_group_methods.rb:303:in `execute_examples' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/example/example_group_methods.rb:302:in `each' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/example/example_group_methods.rb:302:in `execute_examples' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/example/example_group_methods.rb:130:in `run' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/runner/example_group_runner.rb:22:in `run' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/runner/example_group_runner.rb:21:in `each' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/runner/example_group_runner.rb:21:in `run' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/runner/options.rb:106:in `run_examples' >>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/ >>>> spec/runner/command_line.rb:19:in `run' >>>> script/spec:4: >>>> >>>> And here's the controller action: >>>> >>>> def show >>>> @search = Search.find(params[:id]) >>>> if @search.too_many_results? >>>> message_to_new "Your search returned too many results (#{@search.count >>>> }). Please narrow your criteria and search again." >>>> return >>>> elsif @search.no_results? >>>> message_to_new "Your search returned no results. Please change >>>> your criteria and search again." >>>> return >>>> end >>>> init_map >>>> @props = @search.do_search >>>> @markers = [] >>>> @props.each do |prop| >>>> coords = prop.latlng >>>> unless coords.lat == 0 || coords.lng == 0 >>>> prop.info_box = render_to_string(:partial => "/properties/ >>>> map_info_box", :object => prop) >>> >>> This is the line that's causing you trouble. Try stubbing this one >>> out as well: >>> >>> response.stub_render(:partial => "/properties/ >>> map_info_box", :object => anything()) >>> >>> Let us know if it works. >>> >>> Cheers, >>> David >>> >>>> >>>> mark = prop.has_photos? ? "green" : "red" >>>> marker = GMarker.new(coords, :title => >>>> prop_help.bubble_header(prop), :info_window => >>>> prop.info_box, :icon => Variable.new(mark)) >>>> @map.overlay_init marker >>>> @markers << marker >>>> end >>>> end >>>> unless @markers.empty? >>>> @map.center_zoom_on_points_init(*(@markers.collect {|x| >>>> x.point})) >>>> else >>>> @map.center_zoom_init(@search.center, 12) >>>> end >>>> end >>>> >>>> Thanks, >>>> >>>> Andrew >>>> >>>> On Jun 16, 2008, at 9:34 PM, David Chelimsky wrote: >>>> >>>>> On Jun 16, 2008, at 2:58 PM, Andrew Selder wrote: >>>>> >>>>>> Hi all, >>>>>> >>>>>> I have a controller I'm trying to spec out, and I'm running >>>>>> into some issues with render_to_string. >>>>>> >>>>>> Basically, the show gets an array of objects, calls >>>>>> render_to_string for each of them, and then renders the show >>>>>> template. >>>>>> >>>>>> So I have the standard spec: >>>>>> >>>>>> >>>>>> it "should render show template" do >>>>>> do_get >>>>>> response.should render_template('show') >>>>>> end >>>>>> >>>>>> >>>>>> but when I run the spec I get the following failure: >>>>>> >>>>>> 'SearchesController handling GET /searches/1 should render show >>>>>> template' FAILED >>>>>> expected "show", got "properties/_map_info_box" >>>>>> >>>>>> >>>>>> Does anybody have any ideas? >>>>> >>>>> Please post the controller action and the full backtrace: >>>>> >>>>> script/spec spec/controller/path/to/the/spec.rb -fsb >>>>> >>>>> Thx >>>>> _______________________________________________ >>>>> 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 wolfmanjm at gmail.com Tue Jun 17 02:58:07 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Mon, 16 Jun 2008 23:58:07 -0700 (PDT) Subject: [rspec-users] Reusing story snippets In-Reply-To: References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> Message-ID: <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> I'm not using Rails, I am doing end to end integration testing talking to the server via net/http, so RailsStory is not involved. I think the listeners may do it, I can use story_started like before(:all) and story_ended like after(:all) which will be great, presuming story_ended is always called even after a failure. However I am missing the place where that listener gets registered, I am using the... Story "description", %{...}, :steps_for => steps do Scenario "sdsdsd" do ... end end syntax, so where is the listener set? Thanks On Jun 16, 6:32 pm, David Chelimsky wrote: > On Jun 16, 2008, at 6:18 PM, Jim Morris wrote: > > > Along similar lines is there a way to do the equivalent of > > before(:all) and after(:all) or after(:each) in stories? > > > Basically I have a similar situation as above, but I need to make sure > > the user is logged out after each scenario. or that the user is logged > > in once at the start of all scenarios then logged out after them > > regardless of errors etc. > > Each scenario is run in its own instance of RailsStory, so it's got a > new session (IntegrationSession). So you *should* get this isolation > implicitly. > > There are callbacks you can use if you create and register a listener, > but they won't have access to the same scope that exists inside the > steps. Here's how you do it: > > class MyListener > def method_missing sym, *args, &block > # ignore all messages you don't care about > end > > def run_started(num_scenarios); end > def story_started(title, narrative); end > > etc > end > > Seehttp://rspec.info/rdoc/classes/Spec/Runner/Formatter/Story/PlainTextF... > , which implements all the callback methods (we need better docs for > it, but everything is there - don't use collected_steps though - that > should really be marked nodoc). > > Cheers, > David > > > > > Thanks > > > On Jun 14, 7:40 am, David Chelimsky wrote: > >> On Jun 14, 2008, at 5:03 AM, Mikel Lindsaar wrote: > > >>> I find myself doing this: > > >>> Scenario "logged in user visiting the home page" do > >>> Given "A logged in user" do > >>> a_logged_in_user > >>> end > > >>> When "..." > >>> Then "..." > >>> end > > >> Things have evolved a bit since Story Runner first came out. The > >> approach you are using here is what we call in-line steps, and was > >> the > >> only option back then. > > >> You can now use disconnected steps in both plain text and Ruby: > > >> require 'steps/visitors' > > >> Story "logged in users see more stuff", %( > >> As a registered user > >> I want to see more stuff than non-registered users > >> So I can feel like I'm getting some benefit in return for giving > >> up my personal information > >> ), :steps => :visitors do > >> Scenario "logged in user visits home page" do > >> Given "I am logged in as David" > >> When "I visit the home page" > >> Then "I should see the message 'Welcome David'" > >> end > >> end > > >> # in steps/visitors > > >> steps_for :visitors do > >> Given "I am logged in as $name" do |name| > >> # create a user w/ name and log in as that user > >> end > > >> When ".." > >> Then ".." > >> end > > >> This approach really cleans up the story code leaving the informative > >> bits while hiding the redundant detail. > > >> HTH, > >> David > > >>> The a_logged_in_user method is a helper method in helper.rb which > >>> sets > >>> up the state so that the user can browse the website. > > >>> Later in the story of course, I can just do 'Given "A logged in > >>> user" > >>> and it will get the previous definition. > > >>> Is there any way to avoid that duplicated Given call at the top of > >>> almost every story? > > >>> Mikel > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-us... at rubyforge.org > >>>http://rubyforge.org/mailman/listinfo/rspec-users > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From wolfmanjm at gmail.com Tue Jun 17 03:28:28 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Tue, 17 Jun 2008 00:28:28 -0700 (PDT) Subject: [rspec-users] Reusing story snippets In-Reply-To: <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> Message-ID: <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> Ahh ok think I found it... In my test file at the start... class MyListener def method_missing sym, *args, &block # ignore all messages you don't care about end def story_started(title, narrative) puts "...Started story #{title}" end def story_ended(title, narrative) puts "...Ended story #{title}" end end Spec::Story::Runner.register_listener(MyListener.new) Then I define my steps using StepGroup.new Then the Scenarios It seems to work although not very intuitive :) I'd prefer a before(:all) and after(:all) On Jun 16, 11:58 pm, Jim Morris wrote: > I'm not using Rails, I am doing end to end integration testing talking > to the server via net/http, so RailsStory is not involved. > > I think the listeners may do it, I can use story_started like > before(:all) and story_ended like after(:all) which will be great, > presuming story_ended is always called even after a failure. > > However I am missing the place where that listener gets registered, I > am using the... > > Story "description", %{...}, :steps_for => steps do > Scenario "sdsdsd" do > ... > end > end > > syntax, so where is the listener set? > > Thanks > > On Jun 16, 6:32 pm, David Chelimsky wrote: > > > On Jun 16, 2008, at 6:18 PM, Jim Morris wrote: > > > > Along similar lines is there a way to do the equivalent of > > > before(:all) and after(:all) or after(:each) in stories? > > > > Basically I have a similar situation as above, but I need to make sure > > > the user is logged out after each scenario. or that the user is logged > > > in once at the start of all scenarios then logged out after them > > > regardless of errors etc. > > > Each scenario is run in its own instance of RailsStory, so it's got a > > new session (IntegrationSession). So you *should* get this isolation > > implicitly. > > > There are callbacks you can use if you create and register a listener, > > but they won't have access to the same scope that exists inside the > > steps. Here's how you do it: > > > class MyListener > > def method_missing sym, *args, &block > > # ignore all messages you don't care about > > end > > > def run_started(num_scenarios); end > > def story_started(title, narrative); end > > > etc > > end > > > Seehttp://rspec.info/rdoc/classes/Spec/Runner/Formatter/Story/PlainTextF... > > , which implements all the callback methods (we need better docs for > > it, but everything is there - don't use collected_steps though - that > > should really be marked nodoc). > > > Cheers, > > David > > > > Thanks > > > > On Jun 14, 7:40 am, David Chelimsky wrote: > > >> On Jun 14, 2008, at 5:03 AM, Mikel Lindsaar wrote: > > > >>> I find myself doing this: > > > >>> Scenario "logged in user visiting the home page" do > > >>> Given "A logged in user" do > > >>> a_logged_in_user > > >>> end > > > >>> When "..." > > >>> Then "..." > > >>> end > > > >> Things have evolved a bit since Story Runner first came out. The > > >> approach you are using here is what we call in-line steps, and was > > >> the > > >> only option back then. > > > >> You can now use disconnected steps in both plain text and Ruby: > > > >> require 'steps/visitors' > > > >> Story "logged in users see more stuff", %( > > >> As a registered user > > >> I want to see more stuff than non-registered users > > >> So I can feel like I'm getting some benefit in return for giving > > >> up my personal information > > >> ), :steps => :visitors do > > >> Scenario "logged in user visits home page" do > > >> Given "I am logged in as David" > > >> When "I visit the home page" > > >> Then "I should see the message 'Welcome David'" > > >> end > > >> end > > > >> # in steps/visitors > > > >> steps_for :visitors do > > >> Given "I am logged in as $name" do |name| > > >> # create a user w/ name and log in as that user > > >> end > > > >> When ".." > > >> Then ".." > > >> end > > > >> This approach really cleans up the story code leaving the informative > > >> bits while hiding the redundant detail. > > > >> HTH, > > >> David > > > >>> The a_logged_in_user method is a helper method in helper.rb which > > >>> sets > > >>> up the state so that the user can browse the website. > > > >>> Later in the story of course, I can just do 'Given "A logged in > > >>> user" > > >>> and it will get the previous definition. > > > >>> Is there any way to avoid that duplicated Given call at the top of > > >>> almost every story? > > > >>> Mikel > > >>> _______________________________________________ > > >>> rspec-users mailing list > > >>> rspec-us... at rubyforge.org > > >>>http://rubyforge.org/mailman/listinfo/rspec-users > > > >> _______________________________________________ > > >> rspec-users mailing list > > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.org > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Jun 17 07:14:30 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 17 Jun 2008 06:14:30 -0500 Subject: [rspec-users] render_to_string confusing ControllerSpec In-Reply-To: <9ED7A531-07F2-495D-B4BC-4FEEA88C0816@mac.com> References: <26268AB4-411D-47F4-80E6-F50452C6CE9A@gmail.com> <0ED66439-3E1D-4979-A97E-FF8AB94DCFD1@mac.com> <663C9D94-7938-488E-924D-BCBBD52F00E4@gmail.com> <102510ED-B0F8-4CE0-9BBF-96B1C2175F44@mac.com> <0BD90C77-CB22-4EBA-A69C-C241CFEB0ECC@gmail.com> <9ED7A531-07F2-495D-B4BC-4FEEA88C0816@mac.com> Message-ID: <57c63afe0806170414o47d3b0a9r82a218ef5eb75830@mail.gmail.com> On Mon, Jun 16, 2008 at 10:23 PM, Andrew Selder wrote: > David, > > Valid point about the method needing some refactoring. But another key rule > of refactoring is to have passing tests before refactoring. Catch 22 indeed. Are you familiar w/ Michael Feathers' book Working Effectively with Legacy Code? The working definition of Legacy Code in that book is any code without tests. He's got a bunch of strategies in there for dealing with situations like this - not in Rails, but the same general concepts and trade-offs apply. Following that book's advice, you might use integrate_views and create an example that is more like a Rails functional test to start. Maybe even an integration test (using RSpec Stories or Rails Integration Test direction). Then, as you refactor pieces out you can drive that process w/ smaller examples. > This is one of the things that's a minor annoyance I have about rails, you > can't associate views with models. The problem with the refactoring > suggested is that render_to_string is a member of ActionController::Base, > and moving it in to a string construction method in the model is complicated > by no helpers available in the model, and that partial uses tons of helpers. > So it's hard to move a generate_marker method to the model. Got it. I wonder if it would be justifiable in a case like this to create a special object for this purpose then - one that includes all the helpers you need. Just a thought. Unusual to do that sort of thing in Rails, but I used to see and do that sort of thing all the time in other frameworks. Makes things nicely decoupled and easier to test. > Regardless of all of the above, RSpec controller specs have issues when > testing which template was rendered if you use render_to_string. I don't think this is an RSpec problem at all. We'd have the same problem in any other framework. I'd say it's a conflict between Rails design choices and the desire to test at this level of granularity. Not saying either is "right." We get a lot of good from both things. But they are sometimes in conflict. I'd try testing this at the higher level (as suggested above) to start. The other thing you might try is mocking render_to_string directly on the controller. controller.should_receive(:render_to_string).with(...).any_number_of_times Or you could stub do_search and return a known set of props to get more specific, but to do that you're going to end up with a ton of mocks and stubs for this example and without anything higher level to begin with that's not always the safest bet. But all of this is temporary. I think we can agree that the goal is trim this puppy down somehow, so whatever you do to get there with confidence is OK and throwing out most of that in favor of more granular examples and methods as they emerge is definitely OK. Good luck. Cheers, David > Andrew > > > > On Jun 16, 2008, at 11:05 PM, David Chelimsky wrote: > >> On Jun 16, 2008, at 9:19 PM, Andrew Selder wrote: >> >>> I updated the spec to look like this: >>> >>> it "should render show template" do >>> do_get >>> controller.stub_render(:partial => "/properties/map_info_box", :object >>> => anything()) >>> response.should render_template('show') >>> end >>> >>> and I still get the same failure and back trace. >>> >>> In addition to not working, the problem with stubbing out that render to >>> string is that I can't then check for the presence of those strings in the >>> final output. >> >> Well, therein lies the real problem :) This action is exhibiting a number >> of code smells. I don't know how familiar you might be w/ that, but: >> >> Long Method - a method that does too many things (I count at least 10) >> Feature Envy - one one object is doing work on another object's data >> >> There's also a lot of asking, violating the Tell Don't Ask principle. >> >> This block: >> >> @props.each do |prop| >> coords = prop.latlng >> unless coords.lat == 0 || coords.lng == 0 >> prop.info_box = render_to_string(:partial => >> "/properties/map_info_box", :object => prop) >> mark = prop.has_photos? ? "green" : "red" >> marker = GMarker.new(coords, :title => prop_help.bubble_header(prop),\ >> :info_window => prop.info_box, :icon => Variable.new(mark)) >> @map.overlay_init marker >> @markers << marker >> end >> end >> >> .. could become: >> >> @props.each do |prop| >> @markers << prop.generate_marker if prop.needs_marker? >> end >> >> Much simpler to test at that point! I'd recommend heading down that path. >> >> HTH, >> David >> >> >> >>> Thanks, >>> >>> Andrew >>> >>> On Jun 16, 2008, at 10:03 PM, David Chelimsky wrote: >>> >>>> On Jun 16, 2008, at 8:59 PM, Andrew Selder wrote: >>>> >>>>> Here's the back trace >>>>> >>>>> 1) >>>>> 'SearchesController handling GET /searches/1 should render show >>>>> template' FAILED >>>>> expected "show", got "properties/_map_info_box" >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/expectations.rb:52:in >>>>> `fail_with' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/expectations/handler.rb:25:in >>>>> `handle_matcher' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb:31:in >>>>> `should' >>>>> ./spec/controllers/searches_controller_spec.rb:26: >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/example/example_methods.rb:84:in >>>>> `instance_eval' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/example/example_methods.rb:84:in >>>>> `run_with_description_capturing' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/example/example_methods.rb:21:in >>>>> `execute' >>>>> /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/example/example_methods.rb:18:in >>>>> `execute' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:303:in >>>>> `execute_examples' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:302:in >>>>> `each' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:302:in >>>>> `execute_examples' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:130:in >>>>> `run' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:22:in >>>>> `run' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:21:in >>>>> `each' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:21:in >>>>> `run' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/runner/options.rb:106:in >>>>> `run_examples' >>>>> >>>>> /Users/aselder/BostonLogic/one_system/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in >>>>> `run' >>>>> script/spec:4: >>>>> >>>>> And here's the controller action: >>>>> >>>>> def show >>>>> @search = Search.find(params[:id]) >>>>> if @search.too_many_results? >>>>> message_to_new "Your search returned too many results >>>>> (#{@search.count}). Please narrow your criteria and search again." >>>>> return >>>>> elsif @search.no_results? >>>>> message_to_new "Your search returned no results. Please change your >>>>> criteria and search again." >>>>> return >>>>> end >>>>> init_map >>>>> @props = @search.do_search >>>>> @markers = [] >>>>> @props.each do |prop| >>>>> coords = prop.latlng >>>>> unless coords.lat == 0 || coords.lng == 0 >>>>> prop.info_box = render_to_string(:partial => >>>>> "/properties/map_info_box", :object => prop) >>>> >>>> This is the line that's causing you trouble. Try stubbing this one out >>>> as well: >>>> >>>> response.stub_render(:partial => "/properties/map_info_box", :object => >>>> anything()) >>>> >>>> Let us know if it works. >>>> >>>> Cheers, >>>> David >>>> >>>>> >>>>> mark = prop.has_photos? ? "green" : "red" >>>>> marker = GMarker.new(coords, :title => >>>>> prop_help.bubble_header(prop), :info_window => prop.info_box, :icon => >>>>> Variable.new(mark)) >>>>> @map.overlay_init marker >>>>> @markers << marker >>>>> end >>>>> end >>>>> unless @markers.empty? >>>>> @map.center_zoom_on_points_init(*(@markers.collect {|x| x.point})) >>>>> else >>>>> @map.center_zoom_init(@search.center, 12) >>>>> end >>>>> end >>>>> >>>>> Thanks, >>>>> >>>>> Andrew >>>>> >>>>> On Jun 16, 2008, at 9:34 PM, David Chelimsky wrote: >>>>> >>>>>> On Jun 16, 2008, at 2:58 PM, Andrew Selder wrote: >>>>>> >>>>>>> Hi all, >>>>>>> >>>>>>> I have a controller I'm trying to spec out, and I'm running into some >>>>>>> issues with render_to_string. >>>>>>> >>>>>>> Basically, the show gets an array of objects, calls render_to_string >>>>>>> for each of them, and then renders the show template. >>>>>>> >>>>>>> So I have the standard spec: >>>>>>> >>>>>>> >>>>>>> it "should render show template" do >>>>>>> do_get >>>>>>> response.should render_template('show') >>>>>>> end >>>>>>> >>>>>>> >>>>>>> but when I run the spec I get the following failure: >>>>>>> >>>>>>> 'SearchesController handling GET /searches/1 should render show >>>>>>> template' FAILED >>>>>>> expected "show", got "properties/_map_info_box" >>>>>>> >>>>>>> >>>>>>> Does anybody have any ideas? >>>>>> >>>>>> Please post the controller action and the full backtrace: >>>>>> >>>>>> script/spec spec/controller/path/to/the/spec.rb -fsb >>>>>> >>>>>> Thx >>>>>> _______________________________________________ >>>>>> 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 dchelimsky at gmail.com Tue Jun 17 07:34:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 17 Jun 2008 06:34:14 -0500 Subject: [rspec-users] Reusing story snippets In-Reply-To: <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> Message-ID: <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> Reordered your posts so my comments make sense (we prefer to avoid top-posting - even though I sometimes violate that myself :) ). > On Jun 16, 11:58 pm, Jim Morris wrote: >> I'm not using Rails, I am doing end to end integration testing talking >> to the server via net/http, so RailsStory is not involved. Cool. Are you talking directly through ruby constructs or through a browser tool like selenium? >> I think the listeners may do it, I can use story_started like >> before(:all) and story_ended like after(:all) which will be great, >> presuming story_ended is always called even after a failure. Yep. >> However I am missing the place where that listener gets registered, I >> am using the... >> >> Story "description", %{...}, :steps_for => steps do >> Scenario "sdsdsd" do >> ... >> end >> end >> >> syntax, so where is the listener set? >> >> Thanks On Tue, Jun 17, 2008 at 2:28 AM, Jim Morris wrote: > Ahh ok think I found it... > > In my test file at the start... > > class MyListener > def method_missing sym, *args, &block > # ignore all messages you don't care about > end > > def story_started(title, narrative) > puts "...Started story #{title}" > end > > def story_ended(title, narrative) > puts "...Ended story #{title}" > end > end > > Spec::Story::Runner.register_listener(MyListener.new) Yep. That's the right way. > Then I define my steps using StepGroup.new You can just use the steps_for method and it'll still work. > Then the Scenarios > > It seems to work although not very intuitive :) > > I'd prefer a before(:all) and after(:all) I'm not with you on that, but I'm open :) We could solve the OP's problem with something like this: Before Each Scenario: Log in as admin Scenario: editing private data ... Before Each Scenario would match a Given step definition "Log in as $role" or something like that. I'm just not sure this really heads us down the right path. Next thing you know we'll have Before Story, After Each Scenario, After Story, etc and the stories are going to start looking less and less like stories and more and more and more like code, at which point you should be using example groups instead :) Anybody else have opinions about that? Cheers, David >> >> On Jun 16, 6:32 pm, David Chelimsky wrote: >> >> > On Jun 16, 2008, at 6:18 PM, Jim Morris wrote: >> >> > > Along similar lines is there a way to do the equivalent of >> > > before(:all) and after(:all) or after(:each) in stories? >> >> > > Basically I have a similar situation as above, but I need to make sure >> > > the user is logged out after each scenario. or that the user is logged >> > > in once at the start of all scenarios then logged out after them >> > > regardless of errors etc. >> >> > Each scenario is run in its own instance of RailsStory, so it's got a >> > new session (IntegrationSession). So you *should* get this isolation >> > implicitly. >> >> > There are callbacks you can use if you create and register a listener, >> > but they won't have access to the same scope that exists inside the >> > steps. Here's how you do it: >> >> > class MyListener >> > def method_missing sym, *args, &block >> > # ignore all messages you don't care about >> > end >> >> > def run_started(num_scenarios); end >> > def story_started(title, narrative); end >> >> > etc >> > end >> >> > Seehttp://rspec.info/rdoc/classes/Spec/Runner/Formatter/Story/PlainTextF... >> > , which implements all the callback methods (we need better docs for >> > it, but everything is there - don't use collected_steps though - that >> > should really be marked nodoc). >> >> > Cheers, >> > David >> >> > > Thanks >> >> > > On Jun 14, 7:40 am, David Chelimsky wrote: >> > >> On Jun 14, 2008, at 5:03 AM, Mikel Lindsaar wrote: >> >> > >>> I find myself doing this: >> >> > >>> Scenario "logged in user visiting the home page" do >> > >>> Given "A logged in user" do >> > >>> a_logged_in_user >> > >>> end >> >> > >>> When "..." >> > >>> Then "..." >> > >>> end >> >> > >> Things have evolved a bit since Story Runner first came out. The >> > >> approach you are using here is what we call in-line steps, and was >> > >> the >> > >> only option back then. >> >> > >> You can now use disconnected steps in both plain text and Ruby: >> >> > >> require 'steps/visitors' >> >> > >> Story "logged in users see more stuff", %( >> > >> As a registered user >> > >> I want to see more stuff than non-registered users >> > >> So I can feel like I'm getting some benefit in return for giving >> > >> up my personal information >> > >> ), :steps => :visitors do >> > >> Scenario "logged in user visits home page" do >> > >> Given "I am logged in as David" >> > >> When "I visit the home page" >> > >> Then "I should see the message 'Welcome David'" >> > >> end >> > >> end >> >> > >> # in steps/visitors >> >> > >> steps_for :visitors do >> > >> Given "I am logged in as $name" do |name| >> > >> # create a user w/ name and log in as that user >> > >> end >> >> > >> When ".." >> > >> Then ".." >> > >> end >> >> > >> This approach really cleans up the story code leaving the informative >> > >> bits while hiding the redundant detail. >> >> > >> HTH, >> > >> David >> >> > >>> The a_logged_in_user method is a helper method in helper.rb which >> > >>> sets >> > >>> up the state so that the user can browse the website. >> >> > >>> Later in the story of course, I can just do 'Given "A logged in >> > >>> user" >> > >>> and it will get the previous definition. >> >> > >>> Is there any way to avoid that duplicated Given call at the top of >> > >>> almost every story? >> >> > >>> Mikel >> > >>> _______________________________________________ >> > >>> rspec-users mailing list >> > >>> rspec-us... at rubyforge.org >> > >>>http://rubyforge.org/mailman/listinfo/rspec-users >> >> > >> _______________________________________________ >> > >> rspec-users mailing list >> > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ >> > > rspec-users mailing list >> > > rspec-us... at rubyforge.org >> > >http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Tue Jun 17 11:41:36 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 17 Jun 2008 09:41:36 -0600 Subject: [rspec-users] Reusing story snippets In-Reply-To: <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> Message-ID: <4857DB30.1080200@benmabey.com> David Chelimsky wrote: > Reordered your posts so my comments make sense (we prefer to avoid > top-posting - even though I sometimes violate that myself :) ). > > >> On Jun 16, 11:58 pm, Jim Morris wrote: >> >>> I'm not using Rails, I am doing end to end integration testing talking >>> to the server via net/http, so RailsStory is not involved. >>> > > Cool. Are you talking directly through ruby constructs or through a > browser tool like selenium? > > >>> I think the listeners may do it, I can use story_started like >>> before(:all) and story_ended like after(:all) which will be great, >>> presuming story_ended is always called even after a failure. >>> > > Yep. > > >>> However I am missing the place where that listener gets registered, I >>> am using the... >>> >>> Story "description", %{...}, :steps_for => steps do >>> Scenario "sdsdsd" do >>> ... >>> end >>> end >>> >>> syntax, so where is the listener set? >>> >>> Thanks >>> > > On Tue, Jun 17, 2008 at 2:28 AM, Jim Morris wrote: > >> Ahh ok think I found it... >> >> In my test file at the start... >> >> class MyListener >> def method_missing sym, *args, &block >> # ignore all messages you don't care about >> end >> >> def story_started(title, narrative) >> puts "...Started story #{title}" >> end >> >> def story_ended(title, narrative) >> puts "...Ended story #{title}" >> end >> end >> >> Spec::Story::Runner.register_listener(MyListener.new) >> > > Yep. That's the right way. > > >> Then I define my steps using StepGroup.new >> > > You can just use the steps_for method and it'll still work. > > >> Then the Scenarios >> >> It seems to work although not very intuitive :) >> >> I'd prefer a before(:all) and after(:all) >> > > I'm not with you on that, but I'm open :) We could solve the OP's > problem with something like this: > > Before Each Scenario: > Log in as admin > > Scenario: editing private data > ... > > Before Each Scenario would match a Given step definition "Log in as > $role" or something like that. > > I'm just not sure this really heads us down the right path. Next thing > you know we'll have Before Story, After Each Scenario, After Story, > etc and the stories are going to start looking less and less like > stories and more and more and more like code, at which point you > should be using example groups instead :) > > Anybody else have opinions about that? > > Cheers, > David > > I *really* don't like the idea of having a "Before Each Scenario" or similar construct. I have already seen abuses of the story runner where the stories look too much like code/examples. I think adding such language to the story runner would really hurt and confuse the original intent of stories. I'm not questioning whether such an addition would be helpful, I think it would and I may at times use it.. but IMO it would only be helpful to the developers point of view and I don't see it really adding much value to the stories. If someone can offer an example where they think such language would help the stakeholder I would be interested but to me it is starting too look too much like examples. Like Kyle said in a previous post, I think a better way to handle these situations is to rely on the fact that having an admin be logged in is somewhat implicit in the story and that the implementation can be handled under the covers, so to speak, with helper methods within the steps. This of course will require you to call the same helper method for all of your first Given steps. So I guess this is where the pain point is.. but it doesn't seem to be a big one most of the time. The Listeners are good for application-wide/story suite wide setup and cleanup, like databases as such. Placing the login of an admin into a listener would obviously be overkill unless all of your stories involved an Admin being logged in. What people seem to asking for is more control over the granularity of which stories a particular listener effects. Say, for example you have a set of stories that all require that an Admin account to exist with certain permissions and that the admin is logged in. What if you could define your AdminSetupListener and then hook it into the runner for your stories like so: with_steps_for(:admin_section, :webrat).and_listeners_for(:admin_setup) do run_story(File.expand_path(__FILE__)) end This could provide the setup/teardown capabilities for a certain set of stories without polluting the Story language. Does that make sense what I'm suggesting? I'm not sold entirely on it myself. It seems to add yet another layer of abstraction to help DRY up the steps and in so doing spreads the story's executable code throughout even more files. This could hurt maintainability so I think the use of this could also be abused... but if people want more granular control in there setup and teardown with the Stories I would vote for an option like this instead of placing it in the actual Story language/parser itself. I hope most of that makes sense. :) -Ben From dchelimsky at gmail.com Tue Jun 17 12:02:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 17 Jun 2008 11:02:53 -0500 Subject: [rspec-users] Reusing story snippets In-Reply-To: <4857DB30.1080200@benmabey.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> <4857DB30.1080200@benmabey.com> Message-ID: On Jun 17, 2008, at 10:41 AM, Ben Mabey wrote: > David Chelimsky wrote: >> Reordered your posts so my comments make sense (we prefer to avoid >> top-posting - even though I sometimes violate that myself :) ). >> >> >>> On Jun 16, 11:58 pm, Jim Morris wrote: >>> >>>> I'm not using Rails, I am doing end to end integration testing >>>> talking >>>> to the server via net/http, so RailsStory is not involved. >>>> >> >> Cool. Are you talking directly through ruby constructs or through a >> browser tool like selenium? >> >> >>>> I think the listeners may do it, I can use story_started like >>>> before(:all) and story_ended like after(:all) which will be great, >>>> presuming story_ended is always called even after a failure. >>>> >> >> Yep. >> >> >>>> However I am missing the place where that listener gets >>>> registered, I >>>> am using the... >>>> >>>> Story "description", %{...}, :steps_for => steps do >>>> Scenario "sdsdsd" do >>>> ... >>>> end >>>> end >>>> >>>> syntax, so where is the listener set? >>>> >>>> Thanks >>>> >> >> On Tue, Jun 17, 2008 at 2:28 AM, Jim Morris >> wrote: >> >>> Ahh ok think I found it... >>> >>> In my test file at the start... >>> >>> class MyListener >>> def method_missing sym, *args, &block >>> # ignore all messages you don't care about >>> end >>> >>> def story_started(title, narrative) >>> puts "...Started story #{title}" >>> end >>> >>> def story_ended(title, narrative) >>> puts "...Ended story #{title}" >>> end >>> end >>> >>> Spec::Story::Runner.register_listener(MyListener.new) >>> >> >> Yep. That's the right way. >> >> >>> Then I define my steps using StepGroup.new >>> >> >> You can just use the steps_for method and it'll still work. >> >> >>> Then the Scenarios >>> >>> It seems to work although not very intuitive :) >>> >>> I'd prefer a before(:all) and after(:all) >>> >> >> I'm not with you on that, but I'm open :) We could solve the OP's >> problem with something like this: >> >> Before Each Scenario: >> Log in as admin >> >> Scenario: editing private data >> ... >> >> Before Each Scenario would match a Given step definition "Log in as >> $role" or something like that. >> >> I'm just not sure this really heads us down the right path. Next >> thing >> you know we'll have Before Story, After Each Scenario, After Story, >> etc and the stories are going to start looking less and less like >> stories and more and more and more like code, at which point you >> should be using example groups instead :) >> >> Anybody else have opinions about that? >> >> Cheers, >> David >> >> > I *really* don't like the idea of having a "Before Each Scenario" or > similar construct. I have already seen abuses of the story runner > where the stories look too much like code/examples. I think adding > such language to the story runner would really hurt and confuse the > original intent of stories. I'm not questioning whether such an > addition would be helpful, I think it would and I may at times use > it.. but IMO it would only be helpful to the developers point of > view and I don't see it really adding much value to the stories. If > someone can offer an example where they think such language would > help the stakeholder I would be interested but to me it is starting > too look too much like examples. > > Like Kyle said in a previous post, I think a better way to handle > these situations is to rely on the fact that having an admin be > logged in is somewhat implicit in the story and that the > implementation can be handled under the covers, so to speak, with > helper methods within the steps. This of course will require you to > call the same helper method for all of your first Given steps. So I > guess this is where the pain point is.. but it doesn't seem to be a > big one most of the time. > > The Listeners are good for application-wide/story suite wide setup > and cleanup, like databases as such. Placing the login of an admin > into a listener would obviously be overkill unless all of your > stories involved an Admin being logged in. What people seem to > asking for is more control over the granularity of which stories a > particular listener effects. Say, for example you have a set of > stories that all require that an Admin account to exist with certain > permissions and that the admin is logged in. What if you could > define your AdminSetupListener and then hook it into the runner for > your stories like so: > > with_steps_for > (:admin_section, :webrat).and_listeners_for(:admin_setup) do > run_story(File.expand_path(__FILE__)) > end > > This could provide the setup/teardown capabilities for a certain set > of stories without polluting the Story language. > > Does that make sense what I'm suggesting? I'm not sold entirely on > it myself. It seems to add yet another layer of abstraction to help > DRY up the steps and in so doing spreads the story's executable code > throughout even more files. This could hurt maintainability so I > think the use of this could also be abused... but if people want > more granular control in there setup and teardown with the Stories I > would vote for an option like this instead of placing it in the > actual Story language/parser itself. > > I hope most of that makes sense. :) Perfect sense to me :) Cheers, David > > > -Ben > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From wolfmanjm at gmail.com Tue Jun 17 17:46:13 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Tue, 17 Jun 2008 14:46:13 -0700 (PDT) Subject: [rspec-users] Reusing story snippets In-Reply-To: <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> Message-ID: Hi, Not top posting (although I prefer it ;) > > Cool. Are you talking directly through ruby constructs or through a > browser tool like selenium? I have a helper that makes posts and gets and deletes and puts directly to the server which is implements a mostly REST-ful API and written in Java. I use an Hpricot based matcher that implements have_xpath to test the XML that is returned for each API call. It is a true integration test that can test the server running locally or the staging server running at the Colo. I was using (and do use) Example groups for most of my integration tests, however I started using Programmatic Stories (not plain text stories) for a number of reasons. Firstly I prefer it looking like code so I put the whole thing in a single file... steps = Spec::Story::StepGroup.new do |define| define.given("user has empty bag") do etc Story "test user can create, get and delete bags",...., :steps_for => steps do Scenario " create bag"... Scenario "get bag..." Scenario "delete bag..." etc I prefer this because I am a programmer, it keeps things in one place and makes it easy to maintain. I don't have stakeholders so plain text stories are just another layer for me. Although I would use them if I did have laymen stake holders. I am testing a REST-ful AJAX like API to a webservice, that is used by programmers, so my stakeholders would be/are programmers and again prefer programmatic code rather than plain text stories. The reason I like Stories in this case, rather than Examples, is that for integration testing, I can test all the edge cases for the API in the most DRY-full way. The steps are coded once and I can just define very thin Scenarios that test different parameters being passed in and exercise all those edge cases where parameters are bad or left out etc. Doing this the "old" way using Example groups was not at all DRY, but worked pretty well. (Although Example groups with tons of helpers maybe considered equivalent). The thing I have learned about all these BDD, TDD, XP, AGILE things is to be flexible and use the best tools and practices for the job. Being single minded and saying programmers can't use stories they are only for stake holders means we lose a good tool! (Not that I am accusing anyone of being single minded ;) Back to why I want/need these global setup/teardowns... And BDD purists stop reading now ;) When doing integration testing of a remote server this way you know all the tests need to have a login and a valid Sessionid in the cookie. You don't want to login/logoff every Scenario because it is SLOOOW. Logging in and out does not test the API other than the login and logoff API and that of course has been tested once already. It is not DRY to have to call login and logout in every Given, plus you need it to logout even if the tests fail. And lastly (Shudder) some tests have to rely on the state left by a previous test, hence the session id needs to be the same, for a group of scenarios like add a resource, modify the resource then delete the resource are best done as separate Scenarios, relying on the previous Scenario. It would be slow and not DRY to have to test add, then test add, modify, then test add, delete, it is better to have Scenario add, Scenario modify, Scenario delete. I know this flys in the face of SOP, but it is DRY and it is efficient (ie faster) and it works! I hope that explains where I am coming from and how I (Mis-)use these excellent tools you have written. Thanks Jim From wolfmanjm at gmail.com Tue Jun 17 18:17:13 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Tue, 17 Jun 2008 15:17:13 -0700 (PDT) Subject: [rspec-users] Confused - which is the correct Story API Message-ID: Hi, I am confused (a normal state for me) about the State-Of-The-Art Story API to use. examples/calculator.rb has one syntax, the Blogs have another Syntax, so do the various tutorials. I realize that Stories are ongoing work, but it would be nice if there were something I could refer to to make sure that I am not using a syntax that will soon be deprecated, and that I am doing "what is right". So for Plain text stories I believe the current SOTA syntax is... -- text file mystory.story --- Story: My story description As a user I want to buy something So I have stuff Scenario: user has money and buys something Given a user has 100 dollars etc... -- Ruby file mystory.rb -- require File.join(File.dirname(__FILE__), "spec_helper") steps_for(:my_steps) do Given... When... Then... etc... end with_steps_for :my_steps do run File.expand_path(__FILE__).gsub(".rb",".story") end Now for the non-plain text stories is it this? (splitting into separate files is a YMMV thing) --- mystory.rb --- require File.join(File.dirname(__FILE__), "spec_helper") steps_for(:my_steps) do Given... When... Then... etc... end Story "my story description", %(As a thing I want to be able to dp something clever So that I get paid), :steps_for => :my_steps do Scenario "my scenario1" do Given etc end end Thanks for any pointers here. Jim From ben at benmabey.com Tue Jun 17 18:38:18 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 17 Jun 2008 16:38:18 -0600 Subject: [rspec-users] Reusing story snippets In-Reply-To: References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> Message-ID: <48583CDA.5020108@benmabey.com> Jim Morris wrote: > Hi, Not top posting (although I prefer it ;) > > >> Cool. Are you talking directly through ruby constructs or through a >> browser tool like selenium? >> > > I have a helper that makes posts and gets and deletes and puts > directly to the server which is implements a mostly REST-ful API and > written in Java. > I use an Hpricot based matcher that implements have_xpath to test the > XML that is returned for each API call. > > It is a true integration test that can test the server running locally > or the staging server running at the Colo. > > I was using (and do use) Example groups for most of my integration > tests, however I started using Programmatic Stories (not plain text > stories) for a number of reasons. > > Firstly I prefer it looking like code so I put the whole thing in a > single file... > > steps = Spec::Story::StepGroup.new do |define| > define.given("user has empty bag") do > etc > > Story "test user can create, get and delete bags",...., :steps_for => > steps do > Scenario " create bag"... > Scenario "get bag..." > Scenario "delete bag..." > etc > > I prefer this because I am a programmer, it keeps things in one place > and makes it easy to maintain. I don't have stakeholders so plain text > stories are just another layer for me. Although I would use them if I > did have laymen stake holders. I am testing a REST-ful AJAX like API > to a webservice, that is used by programmers, so my stakeholders would > be/are programmers and again prefer programmatic code rather than > plain text stories. > > The reason I like Stories in this case, rather than Examples, is that > for integration testing, I can test all the edge cases for the API in > the most DRY-full way. The steps are coded once and I can just define > very thin Scenarios that test different parameters being passed in and > exercise all those edge cases where parameters are bad or left out > etc. Doing this the "old" way using Example groups was not at all DRY, > but worked pretty well. (Although Example groups with tons of helpers > maybe considered equivalent). > > The thing I have learned about all these BDD, TDD, XP, AGILE things > is to be flexible and use the best tools and practices for the job. > Being single minded and saying programmers can't use stories they are > only for stake holders means we lose a good tool! (Not that I am > accusing anyone of being single minded ;) > > Back to why I want/need these global setup/teardowns... And BDD > purists stop reading now ;) > > When doing integration testing of a remote server this way you know > all the tests need to have a login and a valid Sessionid in the > cookie. You don't want to login/logoff every Scenario because it is > SLOOOW. Logging in and out does not test the API other than the login > and logoff API and that of course has been tested once already. It is > not DRY to have to call login and logout in every Given, plus you need > it to logout even if the tests fail. And lastly (Shudder) some tests > have to rely on the state left by a previous test, hence the session > id needs to be the same, for a group of scenarios like add a resource, > modify the resource then delete the resource are best done as separate > Scenarios, relying on the previous Scenario. It would be slow and not > DRY to have to test add, then test add, modify, then test add, delete, > it is better to have Scenario add, Scenario modify, Scenario delete. I > know this flys in the face of SOP, but it is DRY and it is efficient > (ie faster) and it works! > > I hope that explains where I am coming from and how I (Mis-)use these > excellent tools you have written. > > Thanks > Jim > > > Ahh, I forgot that the original post was not dealing with plain-text stories. From what I understand now, you prefer the Given, When, Then language for your certain situation and want more flexibility to help DRY these programmer-only stories. That makes a lot more sense now that I'm reminded of the context, thanks. :) When testing all the different edge cases based on different parameters passed in the URL I find that nested describes (example groups), like you mentioned, provide a good way to DRY up specs. The spec-docs also lend themselves well to readable docs for programmers wanting to use the API. When using the story framework to do this are you suggesting that a story be able to have setup/teardown and also have specific setup/teardown for individual scenarios? Or are you just suggesting setup/teardown for an entire story (and not the scenarios)? That sounds reasonable and useful, so I hope I didn't come off sounding like I thought your idea was a poor one. In the context of plaintext stories I was thinking it would be a dangerous way to go down unless the language helped the stakeholder. Having more flexible setup/teardown for stories in general seems like a good idea that would help everyone though. -Ben From wolfmanjm at gmail.com Tue Jun 17 19:44:55 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Tue, 17 Jun 2008 16:44:55 -0700 (PDT) Subject: [rspec-users] Reusing story snippets In-Reply-To: <48583CDA.5020108@benmabey.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> <48583CDA.5020108@benmabey.com> Message-ID: Yep thats exactly the case, an entire Story specific setup/teardown for the Given, When Language API Scenario setup is obviously done in the Given, although a way to clean up if the spec fails would be nice. The listener works fine for this, its just not a very intuitive way of setting things up. However I could easily add some sugar to my spec_helper that does the listener setup for me, basically just wrap this... class MyListener def method_missing sym, *args, &block # ignore all messages you don't care about end def story_started(title, narrative) puts "...Started story #{title}" end def story_ended(title, narrative) puts "...Ended story #{title}" end end Spec::Story::Runner.register_listener(MyListener.new) On Jun 17, 3:38 pm, Ben Mabey wrote: > Jim Morris wrote: > > Hi, Not top posting (although I prefer it ;) > > >> Cool. Are you talking directly through ruby constructs or through a > >> browser tool like selenium? > > > I have a helper that makes posts and gets and deletes and puts > > directly to the server which is implements a mostly REST-ful API and > > written in Java. > > I use an Hpricot based matcher that implements have_xpath to test the > > XML that is returned for each API call. > > > It is a true integration test that can test the server running locally > > or the staging server running at the Colo. > > > I was using (and do use) Example groups for most of my integration > > tests, however I started using Programmatic Stories (not plain text > > stories) for a number of reasons. > > > Firstly I prefer it looking like code so I put the whole thing in a > > single file... > > > steps = Spec::Story::StepGroup.new do |define| > > define.given("user has empty bag") do > > etc > > > Story "test user can create, get and delete bags",...., :steps_for => > > steps do > > Scenario " create bag"... > > Scenario "get bag..." > > Scenario "delete bag..." > > etc > > > I prefer this because I am a programmer, it keeps things in one place > > and makes it easy to maintain. I don't have stakeholders so plain text > > stories are just another layer for me. Although I would use them if I > > did have laymen stake holders. I am testing a REST-ful AJAX like API > > to a webservice, that is used by programmers, so my stakeholders would > > be/are programmers and again prefer programmatic code rather than > > plain text stories. > > > The reason I like Stories in this case, rather than Examples, is that > > for integration testing, I can test all the edge cases for the API in > > the most DRY-full way. The steps are coded once and I can just define > > very thin Scenarios that test different parameters being passed in and > > exercise all those edge cases where parameters are bad or left out > > etc. Doing this the "old" way using Example groups was not at all DRY, > > but worked pretty well. (Although Example groups with tons of helpers > > maybe considered equivalent). > > > The thing I have learned about all these BDD, TDD, XP, AGILE things > > is to be flexible and use the best tools and practices for the job. > > Being single minded and saying programmers can't use stories they are > > only for stake holders means we lose a good tool! (Not that I am > > accusing anyone of being single minded ;) > > > Back to why I want/need these global setup/teardowns... And BDD > > purists stop reading now ;) > > > When doing integration testing of a remote server this way you know > > all the tests need to have a login and a valid Sessionid in the > > cookie. You don't want to login/logoff every Scenario because it is > > SLOOOW. Logging in and out does not test the API other than the login > > and logoff API and that of course has been tested once already. It is > > not DRY to have to call login and logout in every Given, plus you need > > it to logout even if the tests fail. And lastly (Shudder) some tests > > have to rely on the state left by a previous test, hence the session > > id needs to be the same, for a group of scenarios like add a resource, > > modify the resource then delete the resource are best done as separate > > Scenarios, relying on the previous Scenario. It would be slow and not > > DRY to have to test add, then test add, modify, then test add, delete, > > it is better to have Scenario add, Scenario modify, Scenario delete. I > > know this flys in the face of SOP, but it is DRY and it is efficient > > (ie faster) and it works! > > > I hope that explains where I am coming from and how I (Mis-)use these > > excellent tools you have written. > > > Thanks > > Jim > > Ahh, I forgot that the original post was not dealing with plain-text > stories. From what I understand now, you prefer the Given, When, Then > language for your certain situation and want more flexibility to help > DRY these programmer-only stories. That makes a lot more sense now that > I'm reminded of the context, thanks. :) > > When testing all the different edge cases based on different parameters > passed in the URL I find that nested describes (example groups), like > you mentioned, provide a good way to DRY up specs. The spec-docs also > lend themselves well to readable docs for programmers wanting to use the > API. When using the story framework to do this are you suggesting that > a story be able to have setup/teardown and also have specific > setup/teardown for individual scenarios? Or are you just suggesting > setup/teardown for an entire story (and not the scenarios)? > > That sounds reasonable and useful, so I hope I didn't come off sounding > like I thought your idea was a poor one. In the context of plaintext > stories I was thinking it would be a dangerous way to go down unless the > language helped the stakeholder. Having more flexible setup/teardown > for stories in general seems like a good idea that would help everyone > though. > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From wolfmanjm at gmail.com Tue Jun 17 20:17:22 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Tue, 17 Jun 2008 17:17:22 -0700 (PDT) Subject: [rspec-users] Reusing story snippets In-Reply-To: References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <6D904682-9650-4A3E-B2D0-338CACD2B128@gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> <48583CDA.5020108@benmabey.com> Message-ID: <37b388dc-38c1-41e8-b58c-1901af2b23fc@w8g2000prd.googlegroups.com> Ok here is my sugar, put in spec_helper.rb require 'rubygems' require 'spec' require 'spec/story' # simulate before(:all) and after(:all) for stories class MyListener def set_before(&block) @before= block end def set_after(&block) @after= block end def method_missing sym, *args, &block # ignore all messages you don't care about end def story_started(title, narrative) @before.call if @before end def story_ended(title, narrative) @after.call if @after end end def setup_listener(listener) unless $my_listener Spec::Story::Runner.register_listener(listener) $my_listener= listener end end def before_story(&block) listener ||= MyListener.new listener.set_before(&block) setup_listener(listener) end def after_story(&block) listener ||= MyListener.new listener.set_after(&block) setup_listener(listener) end Use it in your story ruby file thusly... require File.join(File.dirname(__FILE__), "spec_helper") # execute this code before story runs before_story do #stuff end # execute this code after the story runs after_story do # more stuff end I'm sure it could be cleaner! On Jun 17, 4:44 pm, Jim Morris wrote: > Yep thats exactly the case, an entire Story specific setup/teardown > for the Given, When Language API > > Scenario setup is obviously done in the Given, although a way to clean > up if the spec fails would be nice. > > The listener works fine for this, its just not a very intuitive way of > setting things up. However I could easily add some sugar > to my spec_helper that does the listener setup for me, basically just > wrap this... > > class MyListener > def method_missing sym, *args, &block > # ignore all messages you don't care about > end > > def story_started(title, narrative) > puts "...Started story #{title}" > end > > def story_ended(title, narrative) > puts "...Ended story #{title}" > end > end > > Spec::Story::Runner.register_listener(MyListener.new) > > On Jun 17, 3:38 pm, Ben Mabey wrote: > > > Jim Morris wrote: > > > Hi, Not top posting (although I prefer it ;) > > > >> Cool. Are you talking directly through ruby constructs or through a > > >> browser tool like selenium? > > > > I have a helper that makes posts and gets and deletes and puts > > > directly to the server which is implements a mostly REST-ful API and > > > written in Java. > > > I use an Hpricot based matcher that implements have_xpath to test the > > > XML that is returned for each API call. > > > > It is a true integration test that can test the server running locally > > > or the staging server running at the Colo. > > > > I was using (and do use) Example groups for most of my integration > > > tests, however I started using Programmatic Stories (not plain text > > > stories) for a number of reasons. > > > > Firstly I prefer it looking like code so I put the whole thing in a > > > single file... > > > > steps = Spec::Story::StepGroup.new do |define| > > > define.given("user has empty bag") do > > > etc > > > > Story "test user can create, get and delete bags",...., :steps_for => > > > steps do > > > Scenario " create bag"... > > > Scenario "get bag..." > > > Scenario "delete bag..." > > > etc > > > > I prefer this because I am a programmer, it keeps things in one place > > > and makes it easy to maintain. I don't have stakeholders so plain text > > > stories are just another layer for me. Although I would use them if I > > > did have laymen stake holders. I am testing a REST-ful AJAX like API > > > to a webservice, that is used by programmers, so my stakeholders would > > > be/are programmers and again prefer programmatic code rather than > > > plain text stories. > > > > The reason I like Stories in this case, rather than Examples, is that > > > for integration testing, I can test all the edge cases for the API in > > > the most DRY-full way. The steps are coded once and I can just define > > > very thin Scenarios that test different parameters being passed in and > > > exercise all those edge cases where parameters are bad or left out > > > etc. Doing this the "old" way using Example groups was not at all DRY, > > > but worked pretty well. (Although Example groups with tons of helpers > > > maybe considered equivalent). > > > > The thing I have learned about all these BDD, TDD, XP, AGILE things > > > is to be flexible and use the best tools and practices for the job. > > > Being single minded and saying programmers can't use stories they are > > > only for stake holders means we lose a good tool! (Not that I am > > > accusing anyone of being single minded ;) > > > > Back to why I want/need these global setup/teardowns... And BDD > > > purists stop reading now ;) > > > > When doing integration testing of a remote server this way you know > > > all the tests need to have a login and a valid Sessionid in the > > > cookie. You don't want to login/logoff every Scenario because it is > > > SLOOOW. Logging in and out does not test the API other than the login > > > and logoff API and that of course has been tested once already. It is > > > not DRY to have to call login and logout in every Given, plus you need > > > it to logout even if the tests fail. And lastly (Shudder) some tests > > > have to rely on the state left by a previous test, hence the session > > > id needs to be the same, for a group of scenarios like add a resource, > > > modify the resource then delete the resource are best done as separate > > > Scenarios, relying on the previous Scenario. It would be slow and not > > > DRY to have to test add, then test add, modify, then test add, delete, > > > it is better to have Scenario add, Scenario modify, Scenario delete. I > > > know this flys in the face of SOP, but it is DRY and it is efficient > > > (ie faster) and it works! > > > > I hope that explains where I am coming from and how I (Mis-)use these > > > excellent tools you have written. > > > > Thanks > > > Jim > > > Ahh, I forgot that the original post was not dealing with plain-text > > stories. From what I understand now, you prefer the Given, When, Then > > language for your certain situation and want more flexibility to help > > DRY these programmer-only stories. That makes a lot more sense now that > > I'm reminded of the context, thanks. :) > > > When testing all the different edge cases based on different parameters > > passed in the URL I find that nested describes (example groups), like > > you mentioned, provide a good way to DRY up specs. The spec-docs also > > lend themselves well to readable docs for programmers wanting to use the > > API. When using the story framework to do this are you suggesting that > > a story be able to have setup/teardown and also have specific > > setup/teardown for individual scenarios? Or are you just suggesting > > setup/teardown for an entire story (and not the scenarios)? > > > That sounds reasonable and useful, so I hope I didn't come off sounding > > like I thought your idea was a poor one. In the context of plaintext > > stories I was thinking it would be a dangerous way to go down unless the > > language helped the stakeholder. Having more flexible setup/teardown > > for stories in general seems like a good idea that would help everyone > > though. > > > -Ben > > > _______________________________________________ > > 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 pergesu at gmail.com Tue Jun 17 20:22:44 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 17 Jun 2008 17:22:44 -0700 Subject: [rspec-users] Confused - which is the correct Story API In-Reply-To: References: Message-ID: <810a540e0806171722r59672eer3f39bd2bae8bef2@mail.gmail.com> > Thanks for any pointers here. Hey Jim, You've got the correct syntax for both styles. Pat From lists at ruby-forum.com Wed Jun 18 07:39:41 2008 From: lists at ruby-forum.com (Nidhi Raval) Date: Wed, 18 Jun 2008 13:39:41 +0200 Subject: [rspec-users] `const_missing': uninitialized constant Spec::Rails In-Reply-To: References: <134397f35fcfb4757285f2038b3f9fcc@ruby-forum.com> Message-ID: Dmitry Vanidovsky wrote: > Dmitry Vanidovsky wrote: >> Have anyone had similar problem? What is by experience the most >> suiteable version of rspec framework for rails 1.1.2? Thanks! > > It appeared rspec/rspec_on_rails version 1.0.8 runs without errors for > env described obove. (used svn co for dovnloading rspec/rspec_on_rails) > Hope this saves someone time. Hello, I was stuck at with the same problem and I could get it solved from here http://rubyforge.org/pipermail/rspec-devel/2007-September/004032.html or http://www.nabble.com/Rspec-problem-in-testing-RoR-application-td14950031.html Take a look, It will surely help. Nidhi Raval -- Posted via http://www.ruby-forum.com/. From tastapod at gmail.com Wed Jun 18 13:59:25 2008 From: tastapod at gmail.com (Dan North) Date: Wed, 18 Jun 2008 18:59:25 +0100 Subject: [rspec-users] Reusing story snippets In-Reply-To: <37b388dc-38c1-41e8-b58c-1901af2b23fc@w8g2000prd.googlegroups.com> References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> <48583CDA.5020108@benmabey.com> <37b388dc-38c1-41e8-b58c-1901af2b23fc@w8g2000prd.googlegroups.com> Message-ID: The bottom line here is in understanding who is the stakeholder for this story - i.e. who cares about it, who will read it and who wants to know when it goes wrong. It seems to me you are using the construct of scenarios to describe machine interactions: the request and response of service invocations. In this case the stakeholder is actually another (client) application so it's appropriate to change the rules a bit. As someone else said (or it might have been you!), the point of any agile process is to adapt to the context and help you get work done, not to adhere to a rigid set of rules. It looks to me like you've found a solution to your specific situation, which is a trade-off between the Rule of Idempotency (all scenarios should be idempotent, i.e. rerunnable) and the Rule of Independence (scenarios should be runnable in any sequence) on the one hand, and the annoyance of having to log in for each scenario on the other. As David said, having story-level setup is a smell, but if you go in there with your eyes (nose?) open and you understand the trade-offs then you should be ok. fwiw I would probably define a separate Listener for each type of story setup/teardown that is named for why it's there, rather than a generic before/after story thing that I attach blocks to. So in this instance I would have a LoginOnceBeforeEachStoryListener. One other question: is there a way you can programmatically set the state of "logged in" without having to actually log in via the app? For the Givens I think it's perfectly acceptable to just "make it so". Whether that's putting some value in a session or shoving some data in a table. It's only the When steps that should be duty bound to operate the app like a regular user, because that's the behaviour you are exercising. If so you could have a super-fast "Given $user is logged in" step that runs at the start of each scenario. Cheers, Dan 2008/6/18 Jim Morris : > Ok here is my sugar, put in spec_helper.rb > > require 'rubygems' > require 'spec' > require 'spec/story' > > # simulate before(:all) and after(:all) for stories > class MyListener > def set_before(&block) > @before= block > end > > def set_after(&block) > @after= block > end > > def method_missing sym, *args, &block > # ignore all messages you don't care about > end > > def story_started(title, narrative) > @before.call if @before > end > > def story_ended(title, narrative) > @after.call if @after > end > end > > def setup_listener(listener) > unless $my_listener > Spec::Story::Runner.register_listener(listener) > $my_listener= listener > end > end > > def before_story(&block) > listener ||= MyListener.new > listener.set_before(&block) > setup_listener(listener) > end > > def after_story(&block) > listener ||= MyListener.new > listener.set_after(&block) > setup_listener(listener) > end > > Use it in your story ruby file thusly... > > require File.join(File.dirname(__FILE__), "spec_helper") > > # execute this code before story runs > before_story do > #stuff > end > > # execute this code after the story runs > after_story do > # more stuff > end > > > I'm sure it could be cleaner! > > On Jun 17, 4:44 pm, Jim Morris wrote: > > Yep thats exactly the case, an entire Story specific setup/teardown > > for the Given, When Language API > > > > Scenario setup is obviously done in the Given, although a way to clean > > up if the spec fails would be nice. > > > > The listener works fine for this, its just not a very intuitive way of > > setting things up. However I could easily add some sugar > > to my spec_helper that does the listener setup for me, basically just > > wrap this... > > > > class MyListener > > def method_missing sym, *args, &block > > # ignore all messages you don't care about > > end > > > > def story_started(title, narrative) > > puts "...Started story #{title}" > > end > > > > def story_ended(title, narrative) > > puts "...Ended story #{title}" > > end > > end > > > > Spec::Story::Runner.register_listener(MyListener.new) > > > > On Jun 17, 3:38 pm, Ben Mabey wrote: > > > > > Jim Morris wrote: > > > > Hi, Not top posting (although I prefer it ;) > > > > > >> Cool. Are you talking directly through ruby constructs or through a > > > >> browser tool like selenium? > > > > > > I have a helper that makes posts and gets and deletes and puts > > > > directly to the server which is implements a mostly REST-ful API and > > > > written in Java. > > > > I use an Hpricot based matcher that implements have_xpath to test the > > > > XML that is returned for each API call. > > > > > > It is a true integration test that can test the server running > locally > > > > or the staging server running at the Colo. > > > > > > I was using (and do use) Example groups for most of my integration > > > > tests, however I started using Programmatic Stories (not plain text > > > > stories) for a number of reasons. > > > > > > Firstly I prefer it looking like code so I put the whole thing in a > > > > single file... > > > > > > steps = Spec::Story::StepGroup.new do |define| > > > > define.given("user has empty bag") do > > > > etc > > > > > > Story "test user can create, get and delete bags",...., :steps_for => > > > > steps do > > > > Scenario " create bag"... > > > > Scenario "get bag..." > > > > Scenario "delete bag..." > > > > etc > > > > > > I prefer this because I am a programmer, it keeps things in one place > > > > and makes it easy to maintain. I don't have stakeholders so plain > text > > > > stories are just another layer for me. Although I would use them if I > > > > did have laymen stake holders. I am testing a REST-ful AJAX like API > > > > to a webservice, that is used by programmers, so my stakeholders > would > > > > be/are programmers and again prefer programmatic code rather than > > > > plain text stories. > > > > > > The reason I like Stories in this case, rather than Examples, is that > > > > for integration testing, I can test all the edge cases for the API in > > > > the most DRY-full way. The steps are coded once and I can just define > > > > very thin Scenarios that test different parameters being passed in > and > > > > exercise all those edge cases where parameters are bad or left out > > > > etc. Doing this the "old" way using Example groups was not at all > DRY, > > > > but worked pretty well. (Although Example groups with tons of helpers > > > > maybe considered equivalent). > > > > > > The thing I have learned about all these BDD, TDD, XP, AGILE things > > > > is to be flexible and use the best tools and practices for the job. > > > > Being single minded and saying programmers can't use stories they are > > > > only for stake holders means we lose a good tool! (Not that I am > > > > accusing anyone of being single minded ;) > > > > > > Back to why I want/need these global setup/teardowns... And BDD > > > > purists stop reading now ;) > > > > > > When doing integration testing of a remote server this way you know > > > > all the tests need to have a login and a valid Sessionid in the > > > > cookie. You don't want to login/logoff every Scenario because it is > > > > SLOOOW. Logging in and out does not test the API other than the login > > > > and logoff API and that of course has been tested once already. It is > > > > not DRY to have to call login and logout in every Given, plus you > need > > > > it to logout even if the tests fail. And lastly (Shudder) some tests > > > > have to rely on the state left by a previous test, hence the session > > > > id needs to be the same, for a group of scenarios like add a > resource, > > > > modify the resource then delete the resource are best done as > separate > > > > Scenarios, relying on the previous Scenario. It would be slow and not > > > > DRY to have to test add, then test add, modify, then test add, > delete, > > > > it is better to have Scenario add, Scenario modify, Scenario delete. > I > > > > know this flys in the face of SOP, but it is DRY and it is efficient > > > > (ie faster) and it works! > > > > > > I hope that explains where I am coming from and how I (Mis-)use these > > > > excellent tools you have written. > > > > > > Thanks > > > > Jim > > > > > Ahh, I forgot that the original post was not dealing with plain-text > > > stories. From what I understand now, you prefer the Given, When, Then > > > language for your certain situation and want more flexibility to help > > > DRY these programmer-only stories. That makes a lot more sense now that > > > I'm reminded of the context, thanks. :) > > > > > When testing all the different edge cases based on different parameters > > > passed in the URL I find that nested describes (example groups), like > > > you mentioned, provide a good way to DRY up specs. The spec-docs also > > > lend themselves well to readable docs for programmers wanting to use > the > > > API. When using the story framework to do this are you suggesting that > > > a story be able to have setup/teardown and also have specific > > > setup/teardown for individual scenarios? Or are you just suggesting > > > setup/teardown for an entire story (and not the scenarios)? > > > > > That sounds reasonable and useful, so I hope I didn't come off sounding > > > like I thought your idea was a poor one. In the context of plaintext > > > stories I was thinking it would be a dangerous way to go down unless > the > > > language helped the stakeholder. Having more flexible setup/teardown > > > for stories in general seems like a good idea that would help everyone > > > though. > > > > > -Ben > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.orghttp:// > rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp:// > rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfmanjm at gmail.com Wed Jun 18 15:47:39 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Wed, 18 Jun 2008 12:47:39 -0700 (PDT) Subject: [rspec-users] Reusing story snippets In-Reply-To: References: <57a815bf0806140303u25e7db2dr38a11d382959eee9@mail.gmail.com> <125df5d7-871a-4dee-b2ee-f9ddc7f2aae8@r37g2000prm.googlegroups.com> <13b724e1-b387-41e3-89f2-046014b2c758@r37g2000prm.googlegroups.com> <4b534d91-8255-4139-9384-65e27e187a9c@u36g2000prf.googlegroups.com> <57c63afe0806170434n4914f8a1yc1fb4dd4b373f8e0@mail.gmail.com> <48583CDA.5020108@benmabey.com> <37b388dc-38c1-41e8-b58c-1901af2b23fc@w8g2000prd.googlegroups.com> Message-ID: Hi Dan, Thanks for the analysis. Yes I am a strong proponent of using the best tools for the job, even it means bending the rules. I like the view of the stakeholder being another program, it certainly will make the phrasing of the header easier as I was struggling with that. > One other question: is there a way you can programmatically set the state of > "logged in" without having to actually log in via the app? In this case of a pure integration test where the server is usually remote there is no easy way to fake a login. I am exercising the actual WEB service API as if I were a real client. I have plenty of Unit tests using Mocks for testing the server at the method level of course. > ...For the Givens I > think it's perfectly acceptable to just "make it so". Whether that's putting > some value in a session or shoving some data in a table I also do that especially for setting up data in a database before running the test, the trick is to be able to clean the database from whatever state it was in previously.So I have things like "Given the database has no entries" which will truncate the tables etc. But these kinds of tests usually have to run locally as the database is generally not accessible remotely through the various firewalls etc. Setting up Sessions though means you actually need to go through the various states to get the session setup, rather than plugging something into a session, which would be more of a functional test and not an integration test. I have to say that using the steps and scenarios model for integration testing is very DRY and much easier to write than doing it with Example groups. When I get some time I'll write a blog entry on how I use rspec, stories and various helpers to do this integration testing. Thanks for the feedback. On Jun 18, 10:59 am, "Dan North" wrote: > The bottom line here is in understanding who is the stakeholder for this > story - i.e. who cares about it, who will read it and who wants to know when > it goes wrong. > > It seems to me you are using the construct of scenarios to describe machine > interactions: the request and response of service invocations. In this case > the stakeholder is actually another (client) application so it's appropriate > to change the rules a bit. > > As someone else said (or it might have been you!), the point of any agile > process is to adapt to the context and help you get work done, not to adhere > to a rigid set of rules. It looks to me like you've found a solution to your > specific situation, which is a trade-off between the Rule of Idempotency > (all scenarios should be idempotent, i.e. rerunnable) and the Rule of > Independence (scenarios should be runnable in any sequence) on the one hand, > and the annoyance of having to log in for each scenario on the other. > > As David said, having story-level setup is a smell, but if you go in there > with your eyes (nose?) open and you understand the trade-offs then you > should be ok. > > fwiw I would probably define a separate Listener for each type of story > setup/teardown that is named for why it's there, rather than a generic > before/after story thing that I attach blocks to. So in this instance I > would have a LoginOnceBeforeEachStoryListener. > > One other question: is there a way you can programmatically set the state of > "logged in" without having to actually log in via the app? For the Givens I > think it's perfectly acceptable to just "make it so". Whether that's putting > some value in a session or shoving some data in a table. It's only the When > steps that should be duty bound to operate the app like a regular user, > because that's the behaviour you are exercising. If so you could have a > super-fast "Given $user is logged in" step that runs at the start of each > scenario. > > Cheers, > Dan > > 2008/6/18 Jim Morris :> Ok here is my sugar, put in spec_helper.rb > > > require 'rubygems' > > require 'spec' > > require 'spec/story' > > > # simulate before(:all) and after(:all) for stories > > class MyListener > > def set_before(&block) > > @before= block > > end > > > def set_after(&block) > > @after= block > > end > > > def method_missing sym, *args, &block > > # ignore all messages you don't care about > > end > > > def story_started(title, narrative) > > @before.call if @before > > end > > > def story_ended(title, narrative) > > @after.call if @after > > end > > end > > > def setup_listener(listener) > > unless $my_listener > > Spec::Story::Runner.register_listener(listener) > > $my_listener= listener > > end > > end > > > def before_story(&block) > > listener ||= MyListener.new > > listener.set_before(&block) > > setup_listener(listener) > > end > > > def after_story(&block) > > listener ||= MyListener.new > > listener.set_after(&block) > > setup_listener(listener) > > end > > > Use it in your story ruby file thusly... > > > require File.join(File.dirname(__FILE__), "spec_helper") > > > # execute this code before story runs > > before_story do > > #stuff > > end > > > # execute this code after the story runs > > after_story do > > # more stuff > > end > > > I'm sure it could be cleaner! > > > On Jun 17, 4:44 pm, Jim Morris wrote: > > > Yep thats exactly the case, an entire Story specific setup/teardown > > > for the Given, When Language API > > > > Scenario setup is obviously done in the Given, although a way to clean > > > up if the spec fails would be nice. > > > > The listener works fine for this, its just not a very intuitive way of > > > setting things up. However I could easily add some sugar > > > to my spec_helper that does the listener setup for me, basically just > > > wrap this... > > > > class MyListener > > > def method_missing sym, *args, &block > > > # ignore all messages you don't care about > > > end > > > > def story_started(title, narrative) > > > puts "...Started story #{title}" > > > end > > > > def story_ended(title, narrative) > > > puts "...Ended story #{title}" > > > end > > > end > > > > Spec::Story::Runner.register_listener(MyListener.new) > > > > On Jun 17, 3:38 pm, Ben Mabey wrote: > > > > > Jim Morris wrote: > > > > > Hi, Not top posting (although I prefer it ;) > > > > > >> Cool. Are you talking directly through ruby constructs or through a > > > > >> browser tool like selenium? > > > > > > I have a helper that makes posts and gets and deletes and puts > > > > > directly to the server which is implements a mostly REST-ful API and > > > > > written in Java. > > > > > I use an Hpricot based matcher that implements have_xpath to test the > > > > > XML that is returned for each API call. > > > > > > It is a true integration test that can test the server running > > locally > > > > > or the staging server running at the Colo. > > > > > > I was using (and do use) Example groups for most of my integration > > > > > tests, however I started using Programmatic Stories (not plain text > > > > > stories) for a number of reasons. > > > > > > Firstly I prefer it looking like code so I put the whole thing in a > > > > > single file... > > > > > > steps = Spec::Story::StepGroup.new do |define| > > > > > define.given("user has empty bag") do > > > > > etc > > > > > > Story "test user can create, get and delete bags",...., :steps_for => > > > > > steps do > > > > > Scenario " create bag"... > > > > > Scenario "get bag..." > > > > > Scenario "delete bag..." > > > > > etc > > > > > > I prefer this because I am a programmer, it keeps things in one place > > > > > and makes it easy to maintain. I don't have stakeholders so plain > > text > > > > > stories are just another layer for me. Although I would use them if I > > > > > did have laymen stake holders. I am testing a REST-ful AJAX like API > > > > > to a webservice, that is used by programmers, so my stakeholders > > would > > > > > be/are programmers and again prefer programmatic code rather than > > > > > plain text stories. > > > > > > The reason I like Stories in this case, rather than Examples, is that > > > > > for integration testing, I can test all the edge cases for the API in > > > > > the most DRY-full way. The steps are coded once and I can just define > > > > > very thin Scenarios that test different parameters being passed in > > and > > > > > exercise all those edge cases where parameters are bad or left out > > > > > etc. Doing this the "old" way using Example groups was not at all > > DRY, > > > > > but worked pretty well. (Although Example groups with tons of helpers > > > > > maybe considered equivalent). > > > > > > The thing I have learned about all these BDD, TDD, XP, AGILE things > > > > > is to be flexible and use the best tools and practices for the job. > > > > > Being single minded and saying programmers can't use stories they are > > > > > only for stake holders means we lose a good tool! (Not that I am > > > > > accusing anyone of being single minded ;) > > > > > > Back to why I want/need these global setup/teardowns... And BDD > > > > > purists stop reading now ;) > > > > > > When doing integration testing of a remote server this way you know > > > > > all the tests need to have a login and a valid Sessionid in the > > > > > cookie. You don't want to login/logoff every Scenario because it is > > > > > SLOOOW. Logging in and out does not test the API other than the login > > > > > and logoff API and that of course has been tested once already. It is > > > > > not DRY to have to call login and logout in every Given, plus you > > need > > > > > it to logout even if the tests fail. And lastly (Shudder) some tests > > > > > have to rely on the state left by a previous test, hence the session > > > > > id needs to be the same, for a group of scenarios like add a > > resource, > > > > > modify the resource then delete the resource are best done as > > separate > > > > > Scenarios, relying on the previous Scenario. It would be slow and not > > > > > DRY to have to test add, then test add, modify, then test add, > > delete, > > > > > it is better to have Scenario add, Scenario modify, Scenario delete. > > I > > > > > know this flys in the face of SOP, but it is DRY and it is efficient > > > > > (ie faster) and it works! > > > > > > I hope that explains where I am coming from and how I (Mis-)use these > > > > > excellent tools you have written. > > > > > > Thanks > > > > > Jim > > > > > Ahh, I forgot that the original post was not dealing with plain-text > > > > stories. From what I understand now, you prefer the Given, When, Then > > > > language for your certain situation and want more flexibility to help > > > > DRY these programmer-only stories. That makes a lot more sense now that > > > > I'm reminded of the context, thanks. :) > > > > > When testing all the different edge cases based on different parameters > > > > passed in the URL I find that nested describes (example groups), like > > > > you mentioned, provide a good way to DRY up specs. The spec-docs also > > > > lend themselves well to readable docs for programmers wanting to use > > the > > > > API. When using the story framework to do this are you suggesting that > > > > a story be able to have setup/teardown and also have specific > > > > setup/teardown for individual scenarios? Or are you just suggesting > > > > setup/teardown for an entire story (and not the scenarios)? > > > > > That sounds reasonable and useful, so I hope I didn't come off sounding > > > > like I thought your idea was a poor one. In the context of plaintext > > > > stories I was thinking it would be a dangerous way to go down unless > > the > > > > language helped the stakeholder. Having more flexible setup/teardown > > > > for stories in general seems like a good idea that would help everyone > > > > though. > > > > > -Ben > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-us... at rubyforge.orghttp:// > > rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.orghttp:// > > rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Jun 19 05:26:54 2008 From: lists at ruby-forum.com (Nidhi Raval) Date: Thu, 19 Jun 2008 11:26:54 +0200 Subject: [rspec-users] `const_missing': uninitialized constant Spec::Rails In-Reply-To: References: <134397f35fcfb4757285f2038b3f9fcc@ruby-forum.com> Message-ID: Hello, In addition, I get some other errors and couldn't get the spec run. So finally I found that it was a compatibility issue of RSpec_1.0.8 and I have to use trunck for Rspec and Rspec_on_rails instead using plugin. http://www.ruby-forum.com/topic/129741 link to it, http://rspec.rubyforge.org/documentation/rails/install.html Nidhi Raval Software Engineer www.railshouse.com sales(AT)railshouse(DOT)com -- Posted via http://www.ruby-forum.com/. From chris at cobaltedge.com Thu Jun 19 10:31:33 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Thu, 19 Jun 2008 07:31:33 -0700 Subject: [rspec-users] MVC testing vs. models & Webrat+RailsStory? Message-ID: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> I just read David Chelimsky's slides from RailsConf. I was at RailsConf, but was unable to attend the session. The slides are excellent, and I've recently become VERY interested in stories. In particular I'm a bit unhappy with regular view testing (even with the easier notion of it in RSpec). I was wondering what folks think about testing the full stack these days, and any recommendations you have? Specifically, I'm wondering, or contemplating, if I do unit tests for my models, and then I use WebRat plus RailsStory, do I even need to then do functional testing of my controllers and views? I can see that I might want to do some particular view testing that ensured certain elements were on a page or something, but in terms of actually testing the workings of my app/site, it seems model unit tests combined with RailsStory+Webrat will do a pretty darn thorough job. I would then consider going to Selenium to test some of the detailed JavaScript as needed. Thoughts? What am I missing, or what are the downsides of such an approach? -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From chris at cobaltedge.com Thu Jun 19 10:31:33 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Thu, 19 Jun 2008 07:31:33 -0700 Subject: [rspec-users] MVC testing vs. models & Webrat+RailsStory? Message-ID: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> I just read David Chelimsky's slides from RailsConf. I was at RailsConf, but was unable to attend the session. The slides are excellent, and I've recently become VERY interested in stories. In particular I'm a bit unhappy with regular view testing (even with the easier notion of it in RSpec). I was wondering what folks think about testing the full stack these days, and any recommendations you have? Specifically, I'm wondering, or contemplating, if I do unit tests for my models, and then I use WebRat plus RailsStory, do I even need to then do functional testing of my controllers and views? I can see that I might want to do some particular view testing that ensured certain elements were on a page or something, but in terms of actually testing the workings of my app/site, it seems model unit tests combined with RailsStory+Webrat will do a pretty darn thorough job. I would then consider going to Selenium to test some of the detailed JavaScript as needed. Thoughts? What am I missing, or what are the downsides of such an approach? -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From jimlindley at gmail.com Thu Jun 19 10:41:51 2008 From: jimlindley at gmail.com (Jim Lindley) Date: Thu, 19 Jun 2008 10:41:51 -0400 Subject: [rspec-users] Autotest/RSpec 1.1.4/Rails 2.1 Infinite Loop? In-Reply-To: References: <20A9C048-B70F-40D2-84C6-4169A7F0D44F@mac.com> Message-ID: <1b165db00806190741tf533783u498164dc69467b8d@mail.gmail.com> >> I just got back from RailsConf, and upgraded on of my development apps to >> 2.1, and now autotest is going into an infinite loop. It runs tests >> continuously instead of waiting for files to be saved before rerunning. >> >> Has anybody else seen this, or know how to get around it? I had this or a similar problem. I tracked it down to sometimes requiring spec_helper with expand_path, and other times with just the relative path. So, spec_helper was getting included twice in some cases, resulting in errors on the full suite. The loop that I usually hit was that it would bounce from the failures in the full spec, to run the individual failing spec file, which was green since spec_helper was only required once, and so would run the full spec, and again and again and again. Sometimes even when the full spec was green, it would re-run itself. I didn't figure out exactly why it happened in that case since fixing all the require paths to match solved that too. From philodespotos at gmail.com Thu Jun 19 11:10:09 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Thu, 19 Jun 2008 10:10:09 -0500 Subject: [rspec-users] Autotest/RSpec 1.1.4/Rails 2.1 Infinite Loop? In-Reply-To: <1b165db00806190741tf533783u498164dc69467b8d@mail.gmail.com> References: <20A9C048-B70F-40D2-84C6-4169A7F0D44F@mac.com> <1b165db00806190741tf533783u498164dc69467b8d@mail.gmail.com> Message-ID: <60f3810c0806190810p9d76bacn2bfb3cffec600f5c@mail.gmail.com> On Thu, Jun 19, 2008 at 9:41 AM, Jim Lindley wrote: >>> I just got back from RailsConf, and upgraded on of my development apps to >>> 2.1, and now autotest is going into an infinite loop. It runs tests >>> continuously instead of waiting for files to be saved before rerunning. >>> >>> Has anybody else seen this, or know how to get around it? > > I had this or a similar problem. > > I tracked it down to sometimes requiring spec_helper with expand_path, > and other times with just the relative path. So, spec_helper was > getting included twice in some cases, resulting in errors on the full > suite. The loop that I usually hit was that it would bounce from the > failures in the full spec, to run the individual failing spec file, > which was green since spec_helper was only required once, and so would > run the full spec, and again and again and again. > > Sometimes even when the full spec was green, it would re-run itself. I > didn't figure out exactly why it happened in that case since fixing > all the require paths to match solved that too. The typical cause of these infinite loops is that your test suite updates some file in your project; autotest notices the change and immediately starts again. The solution is to simply add exceptions to your project's .autotest, ignoring any files generated/touched by your test runs. k From philodespotos at gmail.com Thu Jun 19 11:41:32 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Thu, 19 Jun 2008 10:41:32 -0500 Subject: [rspec-users] MVC testing vs. models & Webrat+RailsStory? In-Reply-To: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> References: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> Message-ID: <60f3810c0806190841qa7571as46d69aed5e3f426a@mail.gmail.com> On Thu, Jun 19, 2008 at 9:31 AM, Christopher Bailey wrote: > Specifically, I'm wondering, or contemplating, if I do unit tests for > my models, and then I use WebRat plus RailsStory, do I even need to > then do functional testing of my controllers and views? I can see > that I might want to do some particular view testing that ensured > certain elements were on a page or something, but in terms of actually > testing the workings of my app/site, it seems model unit tests > combined with RailsStory+Webrat will do a pretty darn thorough job. I > would then consider going to Selenium to test some of the detailed > JavaScript as needed. > > Thoughts? What am I missing, or what are the downsides of such an approach? In the project I'm working on, we lean pretty heavily on model/helper specs and webrat-driven plain text stories. We still do *some* controller specs, but only in those instances where we deviate from the standard REST design, or to test authentication requirements. With a custom it_should_... example generator, that can be as simple as: describe FooController do describe "GET :index" do it_should_require_admin_access(:get, :index) end end We currently have no view specs at all, though I am beginning to regret that decision somewhat. Initially we avoided them because the effort required to mock everything out wasn't jiving well with rapid prototyping, but I'm considering going back and pushing some things into view specs using stub_model(). There are a lot of simple requirements that are a good fit for view specs which we are currently doing in the user stories, solely because the infrastructure was already there. As far as controllers go, I wouldn't say we've seen any downside to relying on stories instead of isolated specs; I'm sure you've seen how 90% of every controller spec ends up looking the same, and they start to be a headache to maintain. Maybe the shoulda-esque rspec plugins out there would help, but when I can easily just exercise the full stack, I haven't bothered to try. I saw one big *win* of not testing controllers in isolation just this week, though, when I had to shift a lot of an application's view paths around; with standard controller specs, I would've been spending a lot of typing updating the render expectations, but with stories it wasn't an issue: the right markup either showed up or didn't. The primary downside for us has been speed; it takes a few minutes to run the full story suite. The ability to selectively run just a few stories, and then a good CI server, alleviates that for the most part. I always ramble too much so I'll stop here. HTH, k From chris at cobaltedge.com Thu Jun 19 12:56:27 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Thu, 19 Jun 2008 09:56:27 -0700 Subject: [rspec-users] MVC testing vs. models & Webrat+RailsStory? In-Reply-To: <60f3810c0806190841qa7571as46d69aed5e3f426a@mail.gmail.com> References: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> <60f3810c0806190841qa7571as46d69aed5e3f426a@mail.gmail.com> Message-ID: <443c240c0806190956s64bad4e0g9cf4ddf26bf47499@mail.gmail.com> Kyle, thanks much for sharing your experience. You mention the speed and so on. I've read that it is slow. Question: does Autotest work the same way with stories, or have a way to detect what file(s) changed and run the appropriate stories, or because they're integration tests, would it just re-run the entire story suite as it really doesn't have a way to correlate source files to stories? I presume the latter. I guess what I'd wonder, in terms of dealing with the speed issue is: - Can I run a single story via TextMate like I do with specs? That would allow me to concentrate on one particular thing if I needed quick turn around time. - I just always have autotest running, and most of the time, I just let it do its thing, listening for any failures (I use Mac's speech to alert me :) So, the speed isn't so bad as I typically just keep working until I hear a problem, then go fix that. - I am a huge fan of CI servers, and have one setup for every project I control. I do like to know my suite passes before I push my changes up, but the CI server is a great way to ensure everything passes on a clean system. I suppose if the story runner was really taking very long times, that I'd be ok pushing and seeing if the CI server caught a problem. I'd like to hear other's thoughts as well, but your experience seems consistent with my theory of the direction I want to go: unit test models and helpers, drop controller and view tests in favor of Webrat + RailsStory, and then, as needed drop in RSpec view tests for things that can't be as efficiently/effectively tested in stories. Final bit/question (for now ;-)... With Webrat, does it pay attention to whether or not div's and such are hidden/displayed in terms of whether it lets you enter values in them? In this particular project I use a fair bit of disclosure style UI, where some fields are shown after a use takes some other action or presses a button, etc. But they're all there, just not visible. So, wondering if I can simply tell Webrat to put data into them, and not worry about having to effect a button press that does its work via JavaScript. I can move to Selenium to handle that, but that's actually something I'm not wanting to do yet (I've used it in the past, and it's just a ton of overhead, truly slow, etc.). On Thu, Jun 19, 2008 at 8:41 AM, Kyle Hargraves wrote: > On Thu, Jun 19, 2008 at 9:31 AM, Christopher Bailey > wrote: >> Specifically, I'm wondering, or contemplating, if I do unit tests for >> my models, and then I use WebRat plus RailsStory, do I even need to >> then do functional testing of my controllers and views? I can see >> that I might want to do some particular view testing that ensured >> certain elements were on a page or something, but in terms of actually >> testing the workings of my app/site, it seems model unit tests >> combined with RailsStory+Webrat will do a pretty darn thorough job. I >> would then consider going to Selenium to test some of the detailed >> JavaScript as needed. >> >> Thoughts? What am I missing, or what are the downsides of such an approach? > > In the project I'm working on, we lean pretty heavily on model/helper > specs and webrat-driven plain text stories. > > We still do *some* controller specs, but only in those instances where > we deviate from the standard REST design, or to test authentication > requirements. With a custom it_should_... example generator, that can > be as simple as: > > describe FooController do > describe "GET :index" do > it_should_require_admin_access(:get, :index) > end > end > > We currently have no view specs at all, though I am beginning to > regret that decision somewhat. Initially we avoided them because the > effort required to mock everything out wasn't jiving well with rapid > prototyping, but I'm considering going back and pushing some things > into view specs using stub_model(). There are a lot of simple > requirements that are a good fit for view specs which we are currently > doing in the user stories, solely because the infrastructure was > already there. > > As far as controllers go, I wouldn't say we've seen any downside to > relying on stories instead of isolated specs; I'm sure you've seen how > 90% of every controller spec ends up looking the same, and they start > to be a headache to maintain. Maybe the shoulda-esque rspec plugins > out there would help, but when I can easily just exercise the full > stack, I haven't bothered to try. I saw one big *win* of not testing > controllers in isolation just this week, though, when I had to shift a > lot of an application's view paths around; with standard controller > specs, I would've been spending a lot of typing updating the render > expectations, but with stories it wasn't an issue: the right markup > either showed up or didn't. > > The primary downside for us has been speed; it takes a few minutes to > run the full story suite. The ability to selectively run just a few > stories, and then a good CI server, alleviates that for the most part. > > I always ramble too much so I'll stop here. HTH, > > k > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From chris at cobaltedge.com Thu Jun 19 12:58:37 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Thu, 19 Jun 2008 09:58:37 -0700 Subject: [rspec-users] MVC testing vs. models & Webrat+RailsStory? In-Reply-To: <443c240c0806190956s64bad4e0g9cf4ddf26bf47499@mail.gmail.com> References: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> <60f3810c0806190841qa7571as46d69aed5e3f426a@mail.gmail.com> <443c240c0806190956s64bad4e0g9cf4ddf26bf47499@mail.gmail.com> Message-ID: <443c240c0806190958p38ff2fe1la5dd56fc518ddd6@mail.gmail.com> Just found answer to one of my questions below on being able to run stories in TextMate. The new bundle for stories looks cool: http://github.com/bmabey/rspec-story-tmbundle/tree/master On Thu, Jun 19, 2008 at 9:56 AM, Christopher Bailey wrote: > Kyle, thanks much for sharing your experience. You mention the speed > and so on. I've read that it is slow. Question: does Autotest work > the same way with stories, or have a way to detect what file(s) > changed and run the appropriate stories, or because they're > integration tests, would it just re-run the entire story suite as it > really doesn't have a way to correlate source files to stories? I > presume the latter. > > I guess what I'd wonder, in terms of dealing with the speed issue is: > > - Can I run a single story via TextMate like I do with specs? That > would allow me to concentrate on one particular thing if I needed > quick turn around time. > - I just always have autotest running, and most of the time, I just > let it do its thing, listening for any failures (I use Mac's speech to > alert me :) So, the speed isn't so bad as I typically just keep > working until I hear a problem, then go fix that. > - I am a huge fan of CI servers, and have one setup for every project > I control. I do like to know my suite passes before I push my changes > up, but the CI server is a great way to ensure everything passes on a > clean system. I suppose if the story runner was really taking very > long times, that I'd be ok pushing and seeing if the CI server caught > a problem. > > I'd like to hear other's thoughts as well, but your experience seems > consistent with my theory of the direction I want to go: unit test > models and helpers, drop controller and view tests in favor of Webrat > + RailsStory, and then, as needed drop in RSpec view tests for things > that can't be as efficiently/effectively tested in stories. > > Final bit/question (for now ;-)... With Webrat, does it pay attention > to whether or not div's and such are hidden/displayed in terms of > whether it lets you enter values in them? In this particular project > I use a fair bit of disclosure style UI, where some fields are shown > after a use takes some other action or presses a button, etc. But > they're all there, just not visible. So, wondering if I can simply > tell Webrat to put data into them, and not worry about having to > effect a button press that does its work via JavaScript. I can move > to Selenium to handle that, but that's actually something I'm not > wanting to do yet (I've used it in the past, and it's just a ton of > overhead, truly slow, etc.). > > On Thu, Jun 19, 2008 at 8:41 AM, Kyle Hargraves wrote: >> On Thu, Jun 19, 2008 at 9:31 AM, Christopher Bailey >> wrote: >>> Specifically, I'm wondering, or contemplating, if I do unit tests for >>> my models, and then I use WebRat plus RailsStory, do I even need to >>> then do functional testing of my controllers and views? I can see >>> that I might want to do some particular view testing that ensured >>> certain elements were on a page or something, but in terms of actually >>> testing the workings of my app/site, it seems model unit tests >>> combined with RailsStory+Webrat will do a pretty darn thorough job. I >>> would then consider going to Selenium to test some of the detailed >>> JavaScript as needed. >>> >>> Thoughts? What am I missing, or what are the downsides of such an approach? >> >> In the project I'm working on, we lean pretty heavily on model/helper >> specs and webrat-driven plain text stories. >> >> We still do *some* controller specs, but only in those instances where >> we deviate from the standard REST design, or to test authentication >> requirements. With a custom it_should_... example generator, that can >> be as simple as: >> >> describe FooController do >> describe "GET :index" do >> it_should_require_admin_access(:get, :index) >> end >> end >> >> We currently have no view specs at all, though I am beginning to >> regret that decision somewhat. Initially we avoided them because the >> effort required to mock everything out wasn't jiving well with rapid >> prototyping, but I'm considering going back and pushing some things >> into view specs using stub_model(). There are a lot of simple >> requirements that are a good fit for view specs which we are currently >> doing in the user stories, solely because the infrastructure was >> already there. >> >> As far as controllers go, I wouldn't say we've seen any downside to >> relying on stories instead of isolated specs; I'm sure you've seen how >> 90% of every controller spec ends up looking the same, and they start >> to be a headache to maintain. Maybe the shoulda-esque rspec plugins >> out there would help, but when I can easily just exercise the full >> stack, I haven't bothered to try. I saw one big *win* of not testing >> controllers in isolation just this week, though, when I had to shift a >> lot of an application's view paths around; with standard controller >> specs, I would've been spending a lot of typing updating the render >> expectations, but with stories it wasn't an issue: the right markup >> either showed up or didn't. >> >> The primary downside for us has been speed; it takes a few minutes to >> run the full story suite. The ability to selectively run just a few >> stories, and then a good CI server, alleviates that for the most part. >> >> I always ramble too much so I'll stop here. HTH, >> >> k >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From loriolson at mac.com Thu Jun 19 13:32:12 2008 From: loriolson at mac.com (Lori M Olson) Date: Thu, 19 Jun 2008 11:32:12 -0600 Subject: [rspec-users] Autotest/RSpec 1.1.4/Rails 2.1 Infinite Loop? In-Reply-To: <60f3810c0806190810p9d76bacn2bfb3cffec600f5c@mail.gmail.com> References: <20A9C048-B70F-40D2-84C6-4169A7F0D44F@mac.com> <1b165db00806190741tf533783u498164dc69467b8d@mail.gmail.com> <60f3810c0806190810p9d76bacn2bfb3cffec600f5c@mail.gmail.com> Message-ID: <60299280-54E0-4F2B-823F-B66CF6F310CE@mac.com> On 19-Jun-08, at 9:10 AM, Kyle Hargraves wrote: > The typical cause of these infinite loops is that your test suite > updates some file in your project; autotest notices the change and > immediately starts again. > > The solution is to simply add exceptions to your project's .autotest, > ignoring any files generated/touched by your test runs. > > k > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Would you have an example of such an exception to share? Thanks, Lori From ben at benmabey.com Thu Jun 19 15:00:52 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 19 Jun 2008 13:00:52 -0600 Subject: [rspec-users] MVC testing vs. models & Webrat+RailsStory? In-Reply-To: <443c240c0806190958p38ff2fe1la5dd56fc518ddd6@mail.gmail.com> References: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> <60f3810c0806190841qa7571as46d69aed5e3f426a@mail.gmail.com> <443c240c0806190956s64bad4e0g9cf4ddf26bf47499@mail.gmail.com> <443c240c0806190958p38ff2fe1la5dd56fc518ddd6@mail.gmail.com> Message-ID: <485AACE4.7090801@benmabey.com> Christopher Bailey wrote: > Just found answer to one of my questions below on being able to run > stories in TextMate. The new bundle for stories looks cool: > http://github.com/bmabey/rspec-story-tmbundle/tree/master > > Hey Chris, There is actually a bug for running the stories that accidentally got introduced recently... We'll be pushing the fix out to github soon. We are also adding more flexibility to how you can structure your stories directories. Anyways, look for that as the running is currently broken. -Ben From olivierdupuis at gmail.com Thu Jun 19 15:04:13 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Thu, 19 Jun 2008 15:04:13 -0400 Subject: [rspec-users] Testing routes Message-ID: <745312bd0806191204k6d008973heb6ec42c5fc1cbac@mail.gmail.com> Hello, I'm creating a REST resource with the following map *map.resources :books, :member => { :prices => :get } * I would like to test the books controller *class BooksController < ApplicationController def prices render :text => "Test" end end* I have the following test *it "should render properly when getting /books/:id/prices" do get "prices" response.should be_success end* This is what I get *ActionController::RoutingError in 'BooksController requesting /books/:id/prices using GET should render properly when getting /books/:id/prices' No route matches {:controller=>"books", :action=>"prices"} ./spec/controllers/books_controller_spec.rb:5:* I've tried many different alternatives for get, but they always end up with the same error. I'm surely missing something. Any help would be appreciated. Thanks Olivier Dupuis -------------- next part -------------- An HTML attachment was scrubbed... URL: From mauricio.linhares at gmail.com Thu Jun 19 15:06:39 2008 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Thu, 19 Jun 2008 16:06:39 -0300 Subject: [rspec-users] Testing routes In-Reply-To: <745312bd0806191204k6d008973heb6ec42c5fc1cbac@mail.gmail.com> References: <745312bd0806191204k6d008973heb6ec42c5fc1cbac@mail.gmail.com> Message-ID: Try this: it "should render properly when getting /books/:id/prices" do get "prices", :id => '0' response.should be_success end Or even better (or what i think you wanted to do): map.resources :books, :collection => { :prices => :get } And your spec won't be changed. On Thu, Jun 19, 2008 at 4:04 PM, Olivier Dupuis wrote: > Hello, > > I'm creating a REST resource with the following map > > map.resources :books, :member => { :prices => :get } > > I would like to test the books controller > > class BooksController < ApplicationController > def prices > render :text => "Test" > end > end > > I have the following test > > it "should render properly when getting /books/:id/prices" do > get "prices" > response.should be_success > end > > This is what I get > > ActionController::RoutingError in 'BooksController requesting > /books/:id/prices > using GET should render properly when getting /books/:id/prices' > No route matches {:controller=>"books", :action=>"prices"} > ./spec/controllers/books_controller_spec.rb:5: > > I've tried many different alternatives for get, but they always end up with > the same error. I'm surely missing something. Any help would be > appreciated. > > Thanks > > Olivier Dupuis > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) Jo?o Pessoa, PB, +55 83 8867-7208 From philodespotos at gmail.com Thu Jun 19 17:52:44 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Thu, 19 Jun 2008 16:52:44 -0500 Subject: [rspec-users] Autotest/RSpec 1.1.4/Rails 2.1 Infinite Loop? In-Reply-To: <60299280-54E0-4F2B-823F-B66CF6F310CE@mac.com> References: <20A9C048-B70F-40D2-84C6-4169A7F0D44F@mac.com> <1b165db00806190741tf533783u498164dc69467b8d@mail.gmail.com> <60f3810c0806190810p9d76bacn2bfb3cffec600f5c@mail.gmail.com> <60299280-54E0-4F2B-823F-B66CF6F310CE@mac.com> Message-ID: <60f3810c0806191452w5a936547o7b40188c10de8703@mail.gmail.com> On Thu, Jun 19, 2008 at 12:32 PM, Lori M Olson wrote: > Would you have an example of such an exception to share? > > Thanks, Lori The .autotest at the base of one of my plugins, which updates a .sqlite3: Autotest.add_hook :initialize do |at| at.add_exception('spec/db/tracks_history.sqlite3') end And that's all there is to do. I should've mentioned in my last email that you can use `autotest -v` to figure out what files autotest has not yet been set up to ignore. k From olivierdupuis at gmail.com Fri Jun 20 08:40:20 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Fri, 20 Jun 2008 08:40:20 -0400 Subject: [rspec-users] Testing routes In-Reply-To: References: <745312bd0806191204k6d008973heb6ec42c5fc1cbac@mail.gmail.com> Message-ID: <745312bd0806200540x161a647gb05598f63e920811@mail.gmail.com> Hi Maur?cio, Thanks for your help. It now works. Olivier On Thu, Jun 19, 2008 at 3:06 PM, Maur?cio Linhares < mauricio.linhares at gmail.com> wrote: > Try this: > > it "should render properly when getting /books/:id/prices" do > get "prices", :id => '0' > response.should be_success > end > > Or even better (or what i think you wanted to do): > > map.resources :books, :collection => { :prices => :get } > > And your spec won't be changed. > > On Thu, Jun 19, 2008 at 4:04 PM, Olivier Dupuis > wrote: > > Hello, > > > > I'm creating a REST resource with the following map > > > > map.resources :books, :member => { :prices => :get } > > > > I would like to test the books controller > > > > class BooksController < ApplicationController > > def prices > > render :text => "Test" > > end > > end > > > > I have the following test > > > > it "should render properly when getting /books/:id/prices" do > > get "prices" > > response.should be_success > > end > > > > This is what I get > > > > ActionController::RoutingError in 'BooksController requesting > > /books/:id/prices > > using GET should render properly when getting /books/:id/prices' > > No route matches {:controller=>"books", :action=>"prices"} > > ./spec/controllers/books_controller_spec.rb:5: > > > > I've tried many different alternatives for get, but they always end up > with > > the same error. I'm surely missing something. Any help would be > > appreciated. > > > > Thanks > > > > Olivier Dupuis > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > Maur?cio Linhares > http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) > Jo?o Pessoa, PB, +55 83 8867-7208 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Jun 20 11:12:02 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Fri, 20 Jun 2008 17:12:02 +0200 Subject: [rspec-users] before_save model callback rspec testing Message-ID: hi all, i'm learning rspec and i can't figure out how to test if a callback is executed in a model. my model code is: class User < ActiveRecord::Base before_save :encrypt_password ... def encrypt(password) self.class.encrypt(password, salt) end thanks a lot, cs. -- Posted via http://www.ruby-forum.com/. From hayafirst at gmail.com Fri Jun 20 11:15:03 2008 From: hayafirst at gmail.com (Yi Wen) Date: Fri, 20 Jun 2008 10:15:03 -0500 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: References: Message-ID: user.should_receive(:encrypt_password).with(your_password) user.save Is this what you want? On Fri, Jun 20, 2008 at 10:12 AM, Csongor Bartus wrote: > hi all, > > i'm learning rspec and i can't figure out how to test if a callback is > executed in a model. > > my model code is: > > class User < ActiveRecord::Base > before_save :encrypt_password > > ... > > def encrypt(password) > self.class.encrypt(password, salt) > end > > > thanks a lot, > cs. > -- > 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 Jun 20 11:23:16 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Fri, 20 Jun 2008 17:23:16 +0200 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: References: Message-ID: It might be .... I've done this : it "should encrypt password before save" do user = mock("User") user.should_receive(:encrypt_password).with("password") user.save end but I've got : Spec::Mocks::MockExpectationError in 'User ActiveRecord Callbacks before save encrypt password' Mock 'User' received unexpected message :save with (no args) ./spec/models/user_spec.rb:84: -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Fri Jun 20 11:28:56 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 20 Jun 2008 08:28:56 -0700 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: References: Message-ID: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> Hey, This isn't doing much to test the *behavior* of the object. Why do you want to encrypt the password? Probably so you can authenticate, right? I would probably start off with describe "authenticate" do it "finds the user with the given credentials" do u = User.create!(:login => "pat", :password => "password") User.authenticate("pat", "password").should == u end end That might be a bit much to chew at first though. So you can write some interim tests that you then throw away. For example, you might do describe User, "when saved" do it "should create a salt" do u = User.create(:login => "pat", :password => "password") u.salt.should_not be_blank end it "should create a hashed pass" do u = User.create(:login => "pat", :password => "password") u.hashed_pass.should_not be_blank end end Once you have those passing, you can move to the User.authenticate spec. Once *that* passes, you can throw away the salt/hashed_pass specs, because they're no longer useful. They're testing implementation at this point, and were just a tool to get you where you wanted to go in small steps. Pat On Fri, Jun 20, 2008 at 8:15 AM, Yi Wen wrote: > user.should_receive(:encrypt_password).with(your_password) > user.save > > Is this what you want? > > On Fri, Jun 20, 2008 at 10:12 AM, Csongor Bartus wrote: >> hi all, >> >> i'm learning rspec and i can't figure out how to test if a callback is >> executed in a model. >> >> my model code is: >> >> class User < ActiveRecord::Base >> before_save :encrypt_password >> >> ... >> >> def encrypt(password) >> self.class.encrypt(password, salt) >> end >> >> >> thanks a lot, >> cs. >> -- >> 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 joshknowles at gmail.com Fri Jun 20 11:50:21 2008 From: joshknowles at gmail.com (Josh Knowles) Date: Fri, 20 Jun 2008 11:50:21 -0400 Subject: [rspec-users] MVC testing vs. models & Webrat+RailsStory? In-Reply-To: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> References: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> Message-ID: On 6/19/08, Christopher Bailey wrote: > Specifically, I'm wondering, or contemplating, if I do unit tests for > my models, and then I use WebRat plus RailsStory, do I even need to > then do functional testing of my controllers and views? I can see > that I might want to do some particular view testing that ensured > certain elements were on a page or something, but in terms of actually > testing the workings of my app/site, it seems model unit tests > combined with RailsStory+Webrat will do a pretty darn thorough job. I > would then consider going to Selenium to test some of the detailed > JavaScript as needed. > > Thoughts? What am I missing, or what are the downsides of such an approach? Having spent the last 3 months working on a project which heavily relied on Story Driven Development (currently 78 story files which encompass 401 scenarios) one thing that I have found is that the build has become quite slow. We made a decision early on that we wouldn't bother with view specs, as they felt redundant with our stories. Looking back now I think that was a mistake. If I were to do it over I would leverage stories for the happy path, as well as to catch expected error conditions, but I would also rely heavily on Controller/View/Helper specs to test all of the branches and abnormal use cases. Basically I think that you should test as much stuff at the unit level as possible, and leverage the integration tools where appropriate, but don't overuse without expecting some decrease in performance. -- Josh Knowles phone: 509-979-1593 email: joshknowles at gmail.com web: http://joshknowles.com From lists at ruby-forum.com Fri Jun 20 12:01:42 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Fri, 20 Jun 2008 18:01:42 +0200 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> Message-ID: Thanks Pat, I've tried this way but the test did not passed ... I'm trying to Rspec Authorization's plugin User class (http://www.writertopia.com/developers/authorization) Which looks like this: # == Schema Information # Schema version: 92 # # Table name: users # # id :integer(11) not null, primary key # login :string(255) # email :string(255) # crypted_password :string(40) # salt :string(40) # created_at :datetime # updated_at :datetime # remember_token :string(255) # remember_token_expires_at :datetime # require 'digest/sha1' class User < ActiveRecord::Base # Relationships # ------------- has_many :roles, :dependent => :destroy # Authentication plugins # ---------------------- acts_as_authorized_user acts_as_authorizable # Callbacks # --------- # for Authentication before_save :encrypt_password # methods from the Authentication plugin # -------------------------------------- # Hardwired roles def has_role?( role, authorized_object = nil ) # - site admin return true if self.login.downcase == 'admin' and (role == 'admin' or role == 'site_admin') super end # Authenticates a user by their login name and unencrypted password. Returns the user or nil. def self.authenticate(login, password) u = find_by_login(login) # need to get the salt u && u.authenticated?(password) ? u : nil end # Encrypts some data with the salt. def self.encrypt(password, salt) Digest::SHA1.hexdigest("--#{salt}--#{password}--") end # Encrypts the password with the user salt def encrypt(password) self.class.encrypt(password, salt) end def authenticated?(password) crypted_password == encrypt(password) end def remember_token? remember_token_expires_at && Time.now.utc < remember_token_expires_at end # These create and unset the fields required for remembering users between browser closes def remember_me self.remember_token_expires_at = 2.weeks.from_now.utc self.remember_token = encrypt("#{email}--#{remember_token_expires_at}") save(false) end def forget_me self.remember_token_expires_at = nil self.remember_token = nil save(false) end protected def encrypt_password return if password.blank? self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record? self.crypted_password = encrypt(password) end def password_required? crypted_password.blank? || !password.blank? end end I've managed to Rspec the following tests (copying from Rspec output): User validations - :login must be present - :email must be present - :password must be present - :password_confirmation must be present - :login length must be 2..40 - :email length must be 2..40 - :password length must be 2..40 - :login must be unique - :email must be unique - :login must not contain < > + : ; ! # $ % ^ & * / - :email must not contain < > + : ; ! # $ % ^ & * / - :password must not contain < > + : ; ! # $ % ^ & * / and User Acts As Authenticated Authentication - cannot login with empty username and empty password - cannot login with valid username and empty password - cannot login with empty username and valid password - cannot login with invalid username - cannot login with invalid password - can login with valid username and valid password - there can be two passwords with the same value But when I'm trying to test if the password is encrypted I'm getting errors. I'm trying "your" way: u = User.create(:login => "test", :email => "test at test.com", :password => "test123", :password_confirmation => "test123") u.crypted_password.should_not be_nil the error message is: NoMethodError in 'User ActiveRecord Callbacks before save encrypts password' You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each ./spec/models/user_spec.rb:82: [line 82 ia User.create(...) and "my" way: @user = User.new @user.login = "test" @user.email = "test at test.com" @user.password = "test123" @user.password_confirmation = "test123" @user.save @user.crypted_password.should_not be_nil the error message is: 'User Acts As Authenticated encrypts password' FAILED expected not nil, got nil -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Jun 20 12:04:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 20 Jun 2008 11:04:24 -0500 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> Message-ID: <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> On Jun 20, 2008, at 11:01 AM, Csongor Bartus wrote: > I'm trying "your" way: > > u = User.create(:login => "test", :email => "test at test.com", :password > => "test123", :password_confirmation => "test123") > u.crypted_password.should_not be_nil > > the error message is: > NoMethodError in 'User ActiveRecord Callbacks before save encrypts > password' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > ./spec/models/user_spec.rb:82: > > [line 82 ia User.create(...) > > > and "my" way: > > @user = User.new > @user.login = "test" > @user.email = "test at test.com" > @user.password = "test123" > @user.password_confirmation = "test123" > @user.save > @user.crypted_password.should_not be_nil > > the error message is: > 'User Acts As Authenticated encrypts password' FAILED > expected not nil, got nil Try using create! or save! - I'll bet the record is not being saved correctly and you're not seeing the error. From lists at ruby-forum.com Fri Jun 20 12:11:06 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Fri, 20 Jun 2008 18:11:06 +0200 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> Message-ID: <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> David Chelimsky wrote: > > Try using create! or save! - I'll bet the record is not being saved > correctly and you're not seeing the error. done, still the same errors (exactly) -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jun 20 12:15:37 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Fri, 20 Jun 2008 18:15:37 +0200 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> Message-ID: [Offtopic question] I might be paranoic testing if the password is salted/hashed correctly since all my login tests passed? In learning RSpec I find the most important to draw a line and don't look behind ... but what if, in this case, accidentally something happens with 'digest/sha1' and the logins will pass but the password will be not crypted? -- Posted via http://www.ruby-forum.com/. From olivierdupuis at gmail.com Fri Jun 20 12:32:09 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Fri, 20 Jun 2008 12:32:09 -0400 Subject: [rspec-users] Story for Rest Message-ID: <745312bd0806200932i7e309b1o52e0b2bf3ea2d373@mail.gmail.com> Hello all, I'm trying to write a story for a rest resource. Here's what I have so far: Story "Get prices for specific book", %{ As a client I want to get a list of prices for a specific book So that I can use it on my own application }, :type => RailsStory do Scenario "Requesting /books/:id/prices using GET" do Given "a regular rest request" When "visiting", "/books/:id/prices" do |path| get path end Then "it should return an xml file" end end How would I check that the format of my response is in xml? Also, is it possible to check the content of an xml file, to make sure that it's not empty? Any other suggestions on what would make this story more efficient? Thanks again Olivier Dupuis -------------- next part -------------- An HTML attachment was scrubbed... URL: From philodespotos at gmail.com Fri Jun 20 14:09:33 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Fri, 20 Jun 2008 13:09:33 -0500 Subject: [rspec-users] MVC testing vs. models & Webrat+RailsStory? In-Reply-To: <443c240c0806190956s64bad4e0g9cf4ddf26bf47499@mail.gmail.com> References: <443c240c0806190731v6c227cb6h4eb303bb1c049b3a@mail.gmail.com> <60f3810c0806190841qa7571as46d69aed5e3f426a@mail.gmail.com> <443c240c0806190956s64bad4e0g9cf4ddf26bf47499@mail.gmail.com> Message-ID: <60f3810c0806201109x2a22487bycbd0678b7f8bff18@mail.gmail.com> On Thu, Jun 19, 2008 at 11:56 AM, Christopher Bailey wrote: > Kyle, thanks much for sharing your experience. You mention the speed > and so on. I've read that it is slow. Question: does Autotest work > the same way with stories, or have a way to detect what file(s) > changed and run the appropriate stories, or because they're > integration tests, would it just re-run the entire story suite as it > really doesn't have a way to correlate source files to stories? I > presume the latter. > > - Can I run a single story via TextMate like I do with specs? That > would allow me to concentrate on one particular thing if I needed > quick turn around time. > - I just always have autotest running, and most of the time, I just > let it do its thing, listening for any failures (I use Mac's speech to > alert me :) So, the speed isn't so bad as I typically just keep > working until I hear a problem, then go fix that. I have not attempted to set up autotest + stories, but it should be possible to set up autotest to watch stories/**/*.story and rerun the corresponding story when *that* changes; like you say, it'd be difficult to map implementation files to their stories. I do miss autotest at times, but up+enter on your console to rerun some focused stories is not bad at all. I use a command-line runner without the maintenance requirements of the *.rb runner files (http://github.com/pd/story), so I can pretty easily select the individual foo.story, a full feature, or any mix I want, then just rerun those when I'm ready. Actually, I save files so often that waiting on the stories to catch up would probably be annoying. > I'd like to hear other's thoughts as well, but your experience seems > consistent with my theory of the direction I want to go: unit test > models and helpers, drop controller and view tests in favor of Webrat > + RailsStory, and then, as needed drop in RSpec view tests for things > that can't be as efficiently/effectively tested in stories. As Josh Knowles also said, dropping the unit level specs has turned out to be a mistake. I wouldn't say it's a BIG mistake, and the main issue is just waiting too damned long before you are comfortable pushing your code (which leads to saying "ah screw it" and then "ah crap it failed on CI" and then ...). But a mistake nonetheless. If I started a fresh project today, I would still probably ignore view specs early on; they're cumbersome and take a lot of tweaking when you're just barely figuring out what it is you want to accomplish. Once your ideas solidify a bit, tho, view specs using stub_model() seem perfectly good these days. For controller specs, I think I'd continue to do exactly what I'm already doing: spec the deviations from the pretty-much-scaffolding REST controllers, and wrap up authentication/authorization specs in a tidy DSL to generate that stuff for me. Thin controllers deserve thin controller specs! =) > Final bit/question (for now ;-)... With Webrat, does it pay attention > to whether or not div's and such are hidden/displayed in terms of > whether it lets you enter values in them? In this particular project > I use a fair bit of disclosure style UI, where some fields are shown > after a use takes some other action or presses a button, etc. But > they're all there, just not visible. So, wondering if I can simply > tell Webrat to put data into them, and not worry about having to > effect a button press that does its work via JavaScript. I can move > to Selenium to handle that, but that's actually something I'm not > wanting to do yet (I've used it in the past, and it's just a ton of > overhead, truly slow, etc.). Yes, I take extensive advantage of that. So you can click 'edit' next to something on the screen, which unhides a form, but the form is already on the page; webrat is entirely unaware of the CSS and will just fill it out and submit it. It's a minor headache when there are 10 'edit' links and 10 corresponding forms, cuz you'll need to dig through and be sure to fill out the right fields. Other than that, tho, nothin but sunshine. k From wolfmanjm at gmail.com Fri Jun 20 14:50:18 2008 From: wolfmanjm at gmail.com (Jim Morris) Date: Fri, 20 Jun 2008 11:50:18 -0700 Subject: [rspec-users] Story for Rest In-Reply-To: <745312bd0806200932i7e309b1o52e0b2bf3ea2d373@mail.gmail.com> References: <745312bd0806200932i7e309b1o52e0b2bf3ea2d373@mail.gmail.com> Message-ID: <485BFBEA.90900@gmail.com> Attached is a custom matcher using hpricot, (and the spec for it) it has a "have_xpath matcher for checking xml. I has an earlier one using rexml but hpricot is faster, you can read about that here.... http://blog.wolfman.com/articles/2008/01/02/xpath-matchers-for-rspec This new hpricot one is moslty based on someone elses work, and I'll credit them when I got my blog entry on it done. Olivier Dupuis wrote: > Hello all, > > I'm trying to write a story for a rest resource. > > Here's what I have so far: > > Story "Get prices for specific book", %{ > As a client > I want to get a list of prices for a specific book > So that I can use it on my own application > }, :type => RailsStory do > > Scenario "Requesting /books/:id/prices using GET" do > Given "a regular rest request" > > When "visiting", "/books/:id/prices" do |path| > get path > end > > Then "it should return an xml file" > end > end > > How would I check that the format of my response is in xml? Also, is it > possible to check the content of an xml file, to make sure that it's not > empty? Any other suggestions on what would make this story more efficient? > > Thanks again > > Olivier Dupuis > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- A non-text attachment was scrubbed... Name: hpricot_matchers.rb Type: application/x-ruby Size: 2811 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test_hpricot_matchers.rb Type: application/x-ruby Size: 2147 bytes Desc: not available URL: From pergesu at gmail.com Fri Jun 20 18:06:01 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 20 Jun 2008 15:06:01 -0700 Subject: [rspec-users] Story for Rest In-Reply-To: <745312bd0806200932i7e309b1o52e0b2bf3ea2d373@mail.gmail.com> References: <745312bd0806200932i7e309b1o52e0b2bf3ea2d373@mail.gmail.com> Message-ID: <810a540e0806201506l143ce9d9k7e8301504aee77af@mail.gmail.com> On Fri, Jun 20, 2008 at 9:32 AM, Olivier Dupuis wrote: > Hello all, > > I'm trying to write a story for a rest resource. > > Here's what I have so far: > > Story "Get prices for specific book", %{ > As a client > I want to get a list of prices for a specific book > So that I can use it on my own application > }, :type => RailsStory do > > Scenario "Requesting /books/:id/prices using GET" do > Given "a regular rest request" > > When "visiting", "/books/:id/prices" do |path| > get path > end > > Then "it should return an xml file" > end > end > > How would I check that the format of my response is in xml? Also, is it > possible to check the content of an xml file, to make sure that it's not > empty? Any other suggestions on what would make this story more efficient? I know a lot of people that do hpricot or xpath-style stuff to test XML. I really like my ghetto simple Hash.from_xml approach. hash = Hash.from_xml response.body hash['book'].should_not be_nil hash['book']['price'].should == 123.45 You could probably wrap it up a bit more, but I like how clear and straightforward it is. Pat From mileshosky at hotmail.com Sat Jun 21 18:03:11 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sat, 21 Jun 2008 15:03:11 -0700 Subject: [rspec-users] View Testing: Action with parameters Message-ID: I'm looking for the solution to testing for the correct format of a form action with extra parameters in the url in my view tests. I'm probably overlooking something simple, but I cannot figure out why this is not working. Should i event be testing for this in my view test, or should this be a controller-with-integrated-views specific test? Thanks for the help on my first question to this list! Test code abbreviated ---------------------------------------------------------------------------------------------------------------- @person = mock_model(Person) assigns[:person] = @person response.should have_tag("form[action=?][method=post]", categorizations_path(:person => @person) do View code abbreviated ---------------------------------------------------------------------------------------------------------------- <% form_for :categorization, :url => {:person => @person} do |f| %> Example should assert ---------------------------------------------------------------------------------------------------------------- should find form[action='/categorizations?person=1002'][method='post'] where 1002 is the autogenerated id of @person. _________________________________________________________________ The i?m Talkathon starts 6/24/08.? For now, give amongst yourselves. http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Jun 21 18:13:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 21 Jun 2008 17:13:14 -0500 Subject: [rspec-users] View Testing: Action with parameters In-Reply-To: References: Message-ID: <1D7F6F59-3AD6-4AEB-A9FA-42DA0D32AFBF@gmail.com> On Jun 21, 2008, at 5:03 PM, Britt Mileshosky wrote: > I'm looking for the solution to testing for the correct format of a > form action with extra parameters in the url in my view tests. > I'm probably overlooking something simple, but I cannot figure out > why this is not working. Should i event be testing for this > in my view test, or should this be a controller-with-integrated- > views specific test? > > Thanks for the help on my first question to this list! > > > Test code abbreviated > ---------------------------------------------------------------------------------------------------------------- > > @person = mock_model(Person) > assigns[:person] = @person > > response.should have_tag("form[action=?][method=post]", > categorizations_path(:person => @person) do > > > View code abbreviated > ---------------------------------------------------------------------------------------------------------------- > > <% form_for :categorization, :url => {:person => @person} do |f| %> > > > Example should assert > ---------------------------------------------------------------------------------------------------------------- > > should find form[action='/categorizations?person=1002'] > [method='post'] where 1002 is the autogenerated id of @person. A view example is the right place for this. What's the failure message you're getting? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mileshosky at hotmail.com Sat Jun 21 18:27:08 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sat, 21 Jun 2008 15:27:08 -0700 Subject: [rspec-users] View Testing: Action with parameters In-Reply-To: <1D7F6F59-3AD6-4AEB-A9FA-42DA0D32AFBF@gmail.com> References: <1D7F6F59-3AD6-4AEB-A9FA-42DA0D32AFBF@gmail.com> Message-ID: Expected at least 1 element matching "form[action='/categorizations?person=1002'][method='post']", found 0. is not true. From: dchelimsky at gmail.com To: rspec-users at rubyforge.org Date: Sat, 21 Jun 2008 17:13:14 -0500 Subject: Re: [rspec-users] View Testing: Action with parameters On Jun 21, 2008, at 5:03 PM, Britt Mileshosky wrote:I'm looking for the solution to testing for the correct format of a form action with extra parameters in the url in my view tests. I'm probably overlooking something simple, but I cannot figure out why this is not working. Should i event be testing for this in my view test, or should this be a controller-with-integrated-views specific test? Thanks for the help on my first question to this list! Test code abbreviated ---------------------------------------------------------------------------------------------------------------- @person = mock_model(Person) assigns[:person] = @person response.should have_tag("form[action=?][method=post]", categorizations_path(:person => @person) do View code abbreviated ---------------------------------------------------------------------------------------------------------------- <% form_for :categorization, :url => {:person => @person} do |f| %> Example should assert ---------------------------------------------------------------------------------------------------------------- should find form[action='/categorizations?person=1002'][method='post'] where 1002 is the autogenerated id of @person. A view example is the right place for this. What's the failure message you're getting? _________________________________________________________________ The i?m Talkathon starts 6/24/08.? For now, give amongst yourselves. http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Jun 21 18:30:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 21 Jun 2008 17:30:10 -0500 Subject: [rspec-users] View Testing: Action with parameters In-Reply-To: References: <1D7F6F59-3AD6-4AEB-A9FA-42DA0D32AFBF@gmail.com> Message-ID: <90381C11-B8C8-4967-A4F9-BC5B3BE3B902@gmail.com> > From: dchelimsky at gmail.com > To: rspec-users at rubyforge.org > Date: Sat, 21 Jun 2008 17:13:14 -0500 > Subject: Re: [rspec-users] View Testing: Action with parameters > > On Jun 21, 2008, at 5:03 PM, Britt Mileshosky wrote: > I'm looking for the solution to testing for the correct format of a > form action with extra parameters in the url in my view tests. > I'm probably overlooking something simple, but I cannot figure out > why this is not working. Should i event be testing for this > in my view test, or should this be a controller-with-integrated- > views specific test? > > Thanks for the help on my first question to this list! > > > Test code abbreviated > ---------------------------------------------------------------------------------------------------------------- > > @person = mock_model(Person) > assigns[:person] = @person > > response.should have_tag("form[action=?][method=post]", > categorizations_path(:person => @person) do > > > View code abbreviated > ---------------------------------------------------------------------------------------------------------------- > > <% form_for :categorization, :url => {:person => @person} do |f| %> > > > Example should assert > ---------------------------------------------------------------------------------------------------------------- > > should find form[action='/categorizations?person=1002'] > [method='post'] where 1002 is the autogenerated id of @person. > > A view example is the right place for this. > > What's the failure message you're getting? On Jun 21, 2008, at 5:27 PM, Britt Mileshosky wrote: > > Expected at least 1 element matching "form[action='/categorizations? > person=1002'][method='post']", found 0. > is not true. Please add 'puts response.body' to your example, run it again and copy the output back. And please post in-line rather than top posting in threads like this - it makes it much easier to follow the progression than top posting. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mileshosky at hotmail.com Sat Jun 21 18:45:33 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sat, 21 Jun 2008 15:45:33 -0700 Subject: [rspec-users] View Testing: Action with parameters In-Reply-To: <90381C11-B8C8-4967-A4F9-BC5B3BE3B902@gmail.com> References: <1D7F6F59-3AD6-4AEB-A9FA-42DA0D32AFBF@gmail.com> <90381C11-B8C8-4967-A4F9-BC5B3BE3B902@gmail.com> Message-ID: From: dchelimsky at gmail.com To: rspec-users at rubyforge.org Date: Sat, 21 Jun 2008 17:13:14 -0500 Subject: Re: [rspec-users] View Testing: Action with parameters On Jun 21, 2008, at 5:03 PM, Britt Mileshosky wrote:I'm looking for the solution to testing for the correct format of a form action with extra parameters in the url in my view tests. I'm probably overlooking something simple, but I cannot figure out why this is not working. Should i event be testing for this in my view test, or should this be a controller-with-integrated-views specific test? Thanks for the help on my first question to this list! Test code abbreviated ---------------------------------------------------------------------------------------------------------------- @person = mock_model(Person) assigns[:person] = @person response.should have_tag("form[action=?][method=post]", categorizations_path(:person => @person) do View code abbreviated ---------------------------------------------------------------------------------------------------------------- <% form_for :categorization, :url => {:person => @person} do |f| %> Example should assert ---------------------------------------------------------------------------------------------------------------- should find form[action='/categorizations?person=1002'][method='post'] where 1002 is the autogenerated id of @person. A view example is the right place for this. What's the failure message you're getting? On Jun 21, 2008, at 5:27 PM, Britt Mileshosky wrote:Expected at least 1 element matching "form[action='/categorizations?person=1002'][method='post']", found 0. is not true. From: dchelimsky at gmail.com To: rspec-users at rubyforge.org Date: Sat, 21 Jun 2008 17:30:10 -0500 Subject: Re: [rspec-users] View Testing: Action with parameters Please add 'puts response.body' to your example, run it again and copy the output back. And please post in-line rather than top posting in threads like this - it makes it much easier to follow the progression than top posting. Thanks. That puts did the trick. I was getting: Instead of: because when using: form_for :categorizations, :url => {:person=>@person} - it defaults to the current controller action which is 'new' the fix: form_for :categorizations, :url => {:action => "create", :person => @person} Thank you for your saturday responses! Believe it or not this is the first list ive ever subscribed to, so I hope this response is 'inline'. _________________________________________________________________ The other season of giving begins 6/24/08. Check out the i?m Talkathon. http://www.imtalkathon.com?source=TXT_EML_WLH_SeasonOfGiving -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhennemeyer at googlemail.com Sun Jun 22 05:01:46 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Sun, 22 Jun 2008 11:01:46 +0200 Subject: [rspec-users] RSpec Website not accessible at www.rspec.info Message-ID: <0110EC1E-C729-4D9A-A3D2-06A19E8A0009@googlemail.com> Hi, it would be nice if the rspec site could be also available at www.rspec.info. Matthias From tek.katu at gmail.com Sun Jun 22 09:10:02 2008 From: tek.katu at gmail.com (T K) Date: Sun, 22 Jun 2008 22:10:02 +0900 Subject: [rspec-users] RSpec Website not accessible at www.rspec.info In-Reply-To: <0110EC1E-C729-4D9A-A3D2-06A19E8A0009@googlemail.com> References: <0110EC1E-C729-4D9A-A3D2-06A19E8A0009@googlemail.com> Message-ID: <5c17ebdc0806220610o74a36c97g331749f17cad9715@mail.gmail.com> It's up for me. Can anybody else confirm this? From dchelimsky at gmail.com Sun Jun 22 09:14:00 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 22 Jun 2008 08:14:00 -0500 Subject: [rspec-users] RSpec Website not accessible at www.rspec.info In-Reply-To: <5c17ebdc0806220610o74a36c97g331749f17cad9715@mail.gmail.com> References: <0110EC1E-C729-4D9A-A3D2-06A19E8A0009@googlemail.com> <5c17ebdc0806220610o74a36c97g331749f17cad9715@mail.gmail.com> Message-ID: I just added www to the DNS, so everybody should have it sometime today. On Jun 22, 2008, at 8:10 AM, T K wrote: > It's up for me. Can anybody else confirm this? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mhennemeyer at googlemail.com Sun Jun 22 12:38:46 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Sun, 22 Jun 2008 18:38:46 +0200 Subject: [rspec-users] RSpec Website not accessible at www.rspec.info In-Reply-To: References: <0110EC1E-C729-4D9A-A3D2-06A19E8A0009@googlemail.com> <5c17ebdc0806220610o74a36c97g331749f17cad9715@mail.gmail.com> Message-ID: Thank you David! Matthias Am 22.06.2008 um 15:14 schrieb David Chelimsky: > I just added www to the DNS, so everybody should have it sometime > today. > > On Jun 22, 2008, at 8:10 AM, T K wrote: > >> It's up for me. Can anybody else confirm this? >> _______________________________________________ >> 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 hayafirst at gmail.com Mon Jun 23 09:50:13 2008 From: hayafirst at gmail.com (Yi Wen) Date: Mon, 23 Jun 2008 08:50:13 -0500 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> Message-ID: fire up script/console and copy line 82 and try it out. and report the result here. On Fri, Jun 20, 2008 at 11:11 AM, Csongor Bartus wrote: > David Chelimsky wrote: > >> >> Try using create! or save! - I'll bet the record is not being saved >> correctly and you're not seeing the error. > > done, still the same errors (exactly) > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Jun 23 10:59:46 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Mon, 23 Jun 2008 16:59:46 +0200 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> Message-ID: <4e04c305ec5821fb7ce2b0db22dcb021@ruby-forum.com> Yi Wen wrote: > fire up script/console and copy line 82 and try it out. and report the > result here. >> u = User.create!(:login => "test", :email => "test at test.com", :password => "test123", :password_confirmation => "test123") NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1671:in `attributes=' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1505:in `initialize_without_callbacks' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:225:in `initialize' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in `new' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in `create!' from (irb):1 >> -- Posted via http://www.ruby-forum.com/. From hayafirst at gmail.com Mon Jun 23 11:07:15 2008 From: hayafirst at gmail.com (Yi Wen) Date: Mon, 23 Jun 2008 10:07:15 -0500 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: <4e04c305ec5821fb7ce2b0db22dcb021@ruby-forum.com> References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> <4e04c305ec5821fb7ce2b0db22dcb021@ruby-forum.com> Message-ID: You don't have attr_accessor :password, :password_confirmation in User, do you? You may want to add this and try again On Mon, Jun 23, 2008 at 9:59 AM, Csongor Bartus wrote: > Yi Wen wrote: >> fire up script/console and copy line 82 and try it out. and report the >> result here. > >>> u = User.create!(:login => "test", :email => "test at test.com", :password => "test123", :password_confirmation => "test123") > NoMethodError: You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1671:in > `attributes=' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1505:in > `initialize_without_callbacks' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:225:in > `initialize' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in > `new' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in > `create!' > from (irb):1 >>> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Jun 23 11:26:00 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Mon, 23 Jun 2008 17:26:00 +0200 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> <4e04c305ec5821fb7ce2b0db22dcb021@ruby-forum.com> Message-ID: <040715c8269ebdb3af4ba09f11c07b94@ruby-forum.com> Yi Wen wrote: > You don't have attr_accessor :password, :password_confirmation in > User, do you? You may want to add this and try again I had :password, I've added :password_confirmation but still the same: >> u = User.create!(:login => "test", :email => "test at test.com", :password => "test123", :password_confirmation => "test123") NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1671:in `attributes=' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1505:in `initialize_without_callbacks' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:225:in `initialize' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in `new' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in `create!' from (irb):1 >> -- Posted via http://www.ruby-forum.com/. From hayafirst at gmail.com Mon Jun 23 11:50:19 2008 From: hayafirst at gmail.com (Yi Wen) Date: Mon, 23 Jun 2008 10:50:19 -0500 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: <040715c8269ebdb3af4ba09f11c07b94@ruby-forum.com> References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> <4e04c305ec5821fb7ce2b0db22dcb021@ruby-forum.com> <040715c8269ebdb3af4ba09f11c07b94@ruby-forum.com> Message-ID: Well, at least now we know this is nothing to do with RSpec. My suggestion is that you comment out the code which will be executed during a creation, bit by bit in User (such as before_save) and try to create a user. In this way you can pinpoint where the problem is. On Mon, Jun 23, 2008 at 10:26 AM, Csongor Bartus wrote: > Yi Wen wrote: >> You don't have attr_accessor :password, :password_confirmation in >> User, do you? You may want to add this and try again > > I had :password, I've added :password_confirmation but still the same: > >>> u = User.create!(:login => "test", :email => "test at test.com", :password => "test123", :password_confirmation => "test123") > NoMethodError: You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1671:in > `attributes=' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1505:in > `initialize_without_callbacks' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:225:in > `initialize' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in > `new' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in > `create!' > from (irb):1 >>> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Mon Jun 23 14:08:38 2008 From: cwdinfo at gmail.com (s.ross) Date: Mon, 23 Jun 2008 11:08:38 -0700 Subject: [rspec-users] Mocking MiddleMan Message-ID: I'm trying to verify (using expectations) that a backgroundrb job is being started. I ran across this thread: http://rubyforge.org/pipermail/rspec-users/2007-October/004115.html , in which Pat Maddox conditionally loads backgroundrb. However, I don't see why the original construct that started the thread doesn't work: MiddleMan .should_receive(:new_worker).with(whateveryourparticularargumentsare) What I'm observing is a failure connecting to dRuby, which makes sense if MiddleMan is not mocked but (to me) does not make sense when it is mocked. I'd prefer not to change the actual init code for the plugin as Pat suggests. What am I missing about how this expectation should work? Thanks From smingins at elctech.com Mon Jun 23 20:01:05 2008 From: smingins at elctech.com (Shane Mingins) Date: Tue, 24 Jun 2008 12:01:05 +1200 Subject: [rspec-users] Mocking MiddleMan In-Reply-To: References: Message-ID: <6456E97F-F72E-40DD-AA57-05B64FA4FA27@elctech.com> This is what worked for me back then: In our spec_helper I did: class Object; remove_const :MiddleMan; end MiddleMan = Object.new And then the spec looked like: it "should call the admin email worker" do MiddleMan.should_receive(:new_worker).with(:class => :admin_email_worker, :args => @email_params) post_with_successful_send end and often MiddleMan.stub!(:new_worker) HTH Shane On 24/06/2008, at 6:08 AM, s.ross wrote: > I'm trying to verify (using expectations) that a backgroundrb job is > being started. I ran across this thread: http://rubyforge.org/pipermail/rspec-users/2007-October/004115.html > , in which Pat Maddox conditionally loads backgroundrb. However, I > don't see why the original construct that started the thread doesn't > work: > > MiddleMan > .should_receive(:new_worker).with(whateveryourparticularargumentsare) > > What I'm observing is a failure connecting to dRuby, which makes > sense if MiddleMan is not mocked but (to me) does not make sense > when it is mocked. > > I'd prefer not to change the actual init code for the plugin as Pat > suggests. > > What am I missing about how this expectation should work? > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Mon Jun 23 21:54:03 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 23 Jun 2008 18:54:03 -0700 Subject: [rspec-users] Mocking MiddleMan In-Reply-To: References: Message-ID: <810a540e0806231854p6478c0ddn4d9d2b3171de4f2a@mail.gmail.com> On Mon, Jun 23, 2008 at 11:08 AM, s.ross wrote: > I'm trying to verify (using expectations) that a backgroundrb job is being > started. I ran across this thread: > http://rubyforge.org/pipermail/rspec-users/2007-October/004115.html, in > which Pat Maddox conditionally loads backgroundrb. However, I don't see why > the original construct that started the thread doesn't work: > > MiddleMan.should_receive(:new_worker).with(whateveryourparticularargumentsare) > > What I'm observing is a failure connecting to dRuby, which makes sense if > MiddleMan is not mocked but (to me) does not make sense when it is mocked. >From what I remember, the problem is that backgroundrb starts some stuff as soon as you reference MiddleMan. So even though you're stubbing the call to actually perform work, there's some other stuff that goes on behind the scenes before you're even at that point. Pat From lists at ruby-forum.com Tue Jun 24 03:56:10 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Tue, 24 Jun 2008 09:56:10 +0200 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> <4e04c305ec5821fb7ce2b0db22dcb021@ruby-forum.com> <040715c8269ebdb3af4ba09f11c07b94@ruby-forum.com> Message-ID: <788c527e60b0c7ec90fa147566f9c8ac@ruby-forum.com> Yi Wen wrote: > Well, at least now we know this is nothing to do with RSpec. My > suggestion is that you comment out the code which will be executed > during a creation, bit by bit in User (such as before_save) and try to > create a user. In this way you can pinpoint where the problem is. Thanks a lot Yi Wen, Now I'll find out easier where the bug lies ... But how did you realized the bug is not in RSpec but in the code? -- Posted via http://www.ruby-forum.com/. From hayafirst at gmail.com Tue Jun 24 09:24:56 2008 From: hayafirst at gmail.com (Yi Wen) Date: Tue, 24 Jun 2008 08:24:56 -0500 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: <788c527e60b0c7ec90fa147566f9c8ac@ruby-forum.com> References: <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> <4e04c305ec5821fb7ce2b0db22dcb021@ruby-forum.com> <040715c8269ebdb3af4ba09f11c07b94@ruby-forum.com> <788c527e60b0c7ec90fa147566f9c8ac@ruby-forum.com> Message-ID: That's because you executed the same creation code into the script/console, which has nothing to do with RSpec, and still get the same error message, right? Yi On Tue, Jun 24, 2008 at 2:56 AM, Csongor Bartus wrote: > Yi Wen wrote: >> Well, at least now we know this is nothing to do with RSpec. My >> suggestion is that you comment out the code which will be executed >> during a creation, bit by bit in User (such as before_save) and try to >> create a user. In this way you can pinpoint where the problem is. > > Thanks a lot Yi Wen, > > Now I'll find out easier where the bug lies ... > But how did you realized the bug is not in RSpec but in the code? > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Jun 24 11:20:50 2008 From: lists at ruby-forum.com (Csongor Bartus) Date: Tue, 24 Jun 2008 17:20:50 +0200 Subject: [rspec-users] before_save model callback rspec testing In-Reply-To: References: <810a540e0806200828l138d92b3s36f888b06a1eb59f@mail.gmail.com> <908FE301-FA13-47E4-9309-C0BA64AF47A4@gmail.com> <7ce377dcb7044a1b7f323ce8be86fbbe@ruby-forum.com> <4e04c305ec5821fb7ce2b0db22dcb021@ruby-forum.com> <040715c8269ebdb3af4ba09f11c07b94@ruby-forum.com> <788c527e60b0c7ec90fa147566f9c8ac@ruby-forum.com> Message-ID: <5cb3f3fa266f1086aa7a9c74c20947aa@ruby-forum.com> Yi Wen wrote: > That's because you executed the same creation code into the > script/console, which has nothing to do with RSpec, and still get the > same error message, right? > > Yi Gotcha :D It seems I've got tired ... Thanks a lot! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Jun 24 11:22:29 2008 From: lists at ruby-forum.com (Matthew Rudy Jacobs) Date: Tue, 24 Jun 2008 17:22:29 +0200 Subject: [rspec-users] Rspec-Rails setting a header in stories? Message-ID: Hi there, For my api controllers I need the following; request.ssl? == true and an api key "request.env['HTTP_OUR_API_KEY']" In my spec/controllers I just stub out the required code but in stories I don't want any stubs. I've tried changing the .env of the existing request, but this doesn't work. When "I GET /organisations/", "1" do |organisation_id| request.env['HTTP_OUR_API_KEY'] = "craziness" request.env['HTTPS'] = 'on' get "api/v1/organisations/#{organisation_id}" end and I've tried passing the extra headers as a 3 argument to "get" When "I GET /organisations/", "1" do |organisation_id| get "api/v1/organisations/#{organisation_id}", {}, {'HTTPS' => 'on', 'HTTP_ASPIRE_API_KEY' => 'something'} end but neither of these work. Anyone got any insight into this? My version of rspec-rails is as follows; module Spec module Rails module VERSION #:nodoc: BUILD_TIME_UTC = 20080528130840 end end end Thanks, MatthewRudy -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Jun 24 11:28:29 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 24 Jun 2008 10:28:29 -0500 Subject: [rspec-users] Rspec-Rails setting a header in stories? In-Reply-To: References: Message-ID: <9ADF2416-ABD3-4DB6-A99A-A8EE788BFD9D@gmail.com> On Jun 24, 2008, at 10:22 AM, Matthew Rudy Jacobs wrote: > Hi there, > > For my api controllers I need the following; > request.ssl? == true > and > an api key "request.env['HTTP_OUR_API_KEY']" > > In my spec/controllers I just stub out the required code > but in stories I don't want any stubs. Stories wrap Rails IntegrationTest, not Rails FunctionalTest, so what you have access to is different. The methods look the same, but they actually go through routing and work a little differently. Check out: http://api.rubyonrails.org/classes/ActionController/Integration/Session.html Cheers, David > I've tried changing the .env of the existing request, > but this doesn't work. > > When "I GET /organisations/", "1" do |organisation_id| > request.env['HTTP_OUR_API_KEY'] = "craziness" > request.env['HTTPS'] = 'on' > get "api/v1/organisations/#{organisation_id}" > end > > and I've tried passing the extra headers as a 3 argument to "get" > > When "I GET /organisations/", "1" do |organisation_id| > get "api/v1/organisations/#{organisation_id}", {}, {'HTTPS' => 'on', > 'HTTP_ASPIRE_API_KEY' => 'something'} > end > > but neither of these work. > > Anyone got any insight into this? > > My version of rspec-rails is as follows; > module Spec > module Rails > module VERSION #:nodoc: > BUILD_TIME_UTC = 20080528130840 > end > end > end > > Thanks, > > MatthewRudy > -- > 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 Jun 24 11:33:05 2008 From: lists at ruby-forum.com (Matthew Rudy Jacobs) Date: Tue, 24 Jun 2008 17:33:05 +0200 Subject: [rspec-users] Rspec-Rails setting a header in stories? In-Reply-To: <9ADF2416-ABD3-4DB6-A99A-A8EE788BFD9D@gmail.com> References: <9ADF2416-ABD3-4DB6-A99A-A8EE788BFD9D@gmail.com> Message-ID: <474cb55c6665d5bcfc839b38fee3f273@ruby-forum.com> David Chelimsky wrote: > On Jun 24, 2008, at 10:22 AM, Matthew Rudy Jacobs wrote: > >> Hi there, >> >> For my api controllers I need the following; >> request.ssl? == true >> and >> an api key "request.env['HTTP_OUR_API_KEY']" >> >> In my spec/controllers I just stub out the required code >> but in stories I don't want any stubs. > > Stories wrap Rails IntegrationTest, not Rails FunctionalTest, so what > you have access to is different. The methods look the same, but they > actually go through routing and work a little differently. > > Check out: > http://api.rubyonrails.org/classes/ActionController/Integration/Session.html > > Cheers, > David Oh really. Cheers David... so the "3rd argument" solution should be working. Will have to take a closer look... Thanks again -- Posted via http://www.ruby-forum.com/. From d at sofer.com Tue Jun 24 11:39:44 2008 From: d at sofer.com (Danny Sofer) Date: Tue, 24 Jun 2008 16:39:44 +0100 Subject: [rspec-users] Suggestions on how to use stub_model with webrat? Message-ID: <59EEFF3F-5447-464D-960C-04BED4F0F5A3@sofer.com> Hi all, I am using story runner with webrat, but I am not sure how to incorporate stub_model into my tests. The webrat steps only care about the user interface and have nothing to say about interaction with the database. Following Ben Mabey, I have a line in my story like: "When clicks the Create button" And a step like: When "clicks the $button button" do |button| clicks_button button end Would it be sensible to extend it as follows: "And clicks the Create button to create a new thing" With step: When "clicks the $button button to create a new $resource" do |button, resource| klass = resource.classify.constantize stub_model(klass) clicks_button button end Or is there a better way of making sure that all required models are stubbed? many thanks, danny From dchelimsky at gmail.com Tue Jun 24 11:49:31 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 24 Jun 2008 10:49:31 -0500 Subject: [rspec-users] Suggestions on how to use stub_model with webrat? In-Reply-To: <59EEFF3F-5447-464D-960C-04BED4F0F5A3@sofer.com> References: <59EEFF3F-5447-464D-960C-04BED4F0F5A3@sofer.com> Message-ID: On Jun 24, 2008, at 10:39 AM, Danny Sofer wrote: > Hi all, > > I am using story runner with webrat, but I am not sure how to > incorporate stub_model into my tests. I'd recommend avoiding this. Stories are for integration testing. Examples are for isolation - that's where you want to be stubbing out models. > The webrat steps only care about the user interface and have nothing > to say about interaction with the database. > > Following Ben Mabey, I have a line in my story like: > > "When clicks the Create button" > > And a step like: > > When "clicks the $button button" do |button| > clicks_button button > end > > Would it be sensible to extend it as follows: > > "And clicks the Create button to create a new thing" > > With step: > > When "clicks the $button button to create a new $resource" do | > button, resource| > klass = resource.classify.constantize > stub_model(klass) > clicks_button button > end The stub_model method is not implicitly available in stories, but they are in a module that you can include in RailsStory if you really want to: RailsStory.send :include, Spec::Rails::Mocks > Or is there a better way of making sure that all required models are > stubbed? If your concern is global DB access and you really think you don't need the DB for your stories, I'd recommend something like UnitRecord or NullDB instead. They can take care of things globally for you, reading schema.rb to get and cache the columns rather than hitting the db. HTH, David > > > many thanks, > > danny > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Tue Jun 24 12:34:06 2008 From: lists at ruby-forum.com (Matthew Rudy Jacobs) Date: Tue, 24 Jun 2008 18:34:06 +0200 Subject: [rspec-users] Rspec-Rails setting a header in stories? In-Reply-To: <9ADF2416-ABD3-4DB6-A99A-A8EE788BFD9D@gmail.com> References: <9ADF2416-ABD3-4DB6-A99A-A8EE788BFD9D@gmail.com> Message-ID: David Chelimsky wrote: > On Jun 24, 2008, at 10:22 AM, Matthew Rudy Jacobs wrote: > >> Hi there, >> >> For my api controllers I need the following; >> request.ssl? == true >> and >> an api key "request.env['HTTP_OUR_API_KEY']" >> >> In my spec/controllers I just stub out the required code >> but in stories I don't want any stubs. > > Stories wrap Rails IntegrationTest, not Rails FunctionalTest, so what > you have access to is different. The methods look the same, but they > actually go through routing and work a little differently. > > Check out: > http://api.rubyonrails.org/classes/ActionController/Integration/Session.html > > Cheers, > David I think much of my problem was not quite understanding how stories were supposed to work, (notably I was trying to redefine "When I call the api" in two different scenarios, but only one of these gets used in both cases) But I think I've got an agreeable end-product. http://pastie.org/221205 Thanks once more. MatthewRudy -- Posted via http://www.ruby-forum.com/. From hayafirst at gmail.com Tue Jun 24 12:40:21 2008 From: hayafirst at gmail.com (Yi Wen) Date: Tue, 24 Jun 2008 11:40:21 -0500 Subject: [rspec-users] Story HTML output Message-ID: Hi, If I write the HTML format stories output to ~/ccrb_build-build_number/Stories/index.html. To get all styles rendered, I also need to copy /vendor/plugins/rspec/story_server/prototype/stylesheets/ and /vendor/plugins/rspec/story_server/prototype/javascripts/ to the ~/ccrb_build-build_number/Stories/. Just wonder is this the right way to do it? or there is a better/preferred way? Thanks Yi From ben at benmabey.com Tue Jun 24 12:53:30 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 24 Jun 2008 10:53:30 -0600 Subject: [rspec-users] Story HTML output In-Reply-To: References: Message-ID: <4861268A.1020301@benmabey.com> Yi Wen wrote: > Hi, > > If I write the HTML format stories output to > ~/ccrb_build-build_number/Stories/index.html. To get all styles > rendered, I also need to copy > /vendor/plugins/rspec/story_server/prototype/stylesheets/ and > /vendor/plugins/rspec/story_server/prototype/javascripts/ to the > ~/ccrb_build-build_number/Stories/. > > Just wonder is this the right way to do it? or there is a > better/preferred way? Thanks > > Yi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Yi, AFAIK that is the only way right now. Or, you could write a new formatter that will point to a more central location for the CSS and JS files. The HTML formatting and the story server is not really done so it has some rough edges. -Ben From hayafirst at gmail.com Tue Jun 24 14:54:10 2008 From: hayafirst at gmail.com (Yi Wen) Date: Tue, 24 Jun 2008 13:54:10 -0500 Subject: [rspec-users] DRY up story Message-ID: In David's presentation @ RailsConf, he has this example: Story: measure progress towards registration goals As a conference organizer I want to see a report of registrations So that I can measure progress towards registration goals Scenario: one registration shows as 1% Given a goal of 200 registrations When 1 attendee registers Then the goal should be 1% achieved Scenario: one registration less than the goal shows as 99% Given a goal of 200 registrations When 199 attendees register Then the goal should be 99% achieved Notice that Given part is exactly the same for both scenarios. Does it possible to DRY up it a little bit by putting Given up to right after Story part? Or it is just too crazy? Yi From dchelimsky at gmail.com Tue Jun 24 15:00:40 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 24 Jun 2008 14:00:40 -0500 Subject: [rspec-users] DRY up story In-Reply-To: References: Message-ID: <8172F95C-A7E3-4F95-9670-BF54FB361B1F@gmail.com> On Jun 24, 2008, at 1:54 PM, Yi Wen wrote: > In David's presentation @ RailsConf, he has this example: > > Story: measure progress towards registration goals > As a conference organizer > I want to see a report of registrations > So that I can measure progress towards registration goals > > Scenario: one registration shows as 1% > Given a goal of 200 registrations > When 1 attendee registers > Then the goal should be 1% achieved > > Scenario: one registration less than the goal shows as 99% > Given a goal of 200 registrations > When 199 attendees register > Then the goal should be 99% achieved > > Notice that Given part is exactly the same for both scenarios. Does it > possible to DRY up it a little bit by putting Given up to right after > Story part? Or it is just too crazy? Depends on who the audience is. If you're using plain text w/ customers, yes it's crazy. The whole point is to keep things non- programatic. If you're a developer, then write the stuff in pure Ruby and you have plenty of language-tools to DRY things up to your heart's content. > > > Yi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From cwdinfo at gmail.com Tue Jun 24 16:16:25 2008 From: cwdinfo at gmail.com (s.ross) Date: Tue, 24 Jun 2008 13:16:25 -0700 Subject: [rspec-users] Mocking MiddleMan In-Reply-To: <810a540e0806231854p6478c0ddn4d9d2b3171de4f2a@mail.gmail.com> References: <810a540e0806231854p6478c0ddn4d9d2b3171de4f2a@mail.gmail.com> Message-ID: <4D4F0410-5FB1-422F-86A5-20217EC1DB96@gmail.com> On Jun 23, 2008, at 6:54 PM, Pat Maddox wrote: >> From what I remember, the problem is that backgroundrb starts some > stuff as soon as you reference MiddleMan. So even though you're > stubbing the call to actually perform work, there's some other stuff > that goes on behind the scenes before you're even at that point. Right. That was it. I used your workaround, but Shane's seems sensible to try because we're currently using an older version of backgroundrb (one dev is on Windows and there are apparently no binaries available for the current version). If Shane's solution works, it should future- proof us a bit because I won't have to modify the plugin's init.rb. Thanks to both of you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Tue Jun 24 17:31:26 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 24 Jun 2008 17:31:26 -0400 Subject: [rspec-users] DRY up story In-Reply-To: <8172F95C-A7E3-4F95-9670-BF54FB361B1F@gmail.com> References: <8172F95C-A7E3-4F95-9670-BF54FB361B1F@gmail.com> Message-ID: On Tue, Jun 24, 2008 at 3:00 PM, David Chelimsky wrote: > On Jun 24, 2008, at 1:54 PM, Yi Wen wrote: > > In David's presentation @ RailsConf, he has this example: >> >> Story: measure progress towards registration goals >> As a conference organizer >> I want to see a report of registrations >> So that I can measure progress towards registration goals >> >> Scenario: one registration shows as 1% >> Given a goal of 200 registrations >> When 1 attendee registers >> Then the goal should be 1% achieved >> >> Scenario: one registration less than the goal shows as 99% >> Given a goal of 200 registrations >> When 199 attendees register >> Then the goal should be 99% achieved >> >> Notice that Given part is exactly the same for both scenarios. Does it >> possible to DRY up it a little bit by putting Given up to right after >> Story part? Or it is just too crazy? >> > > Depends on who the audience is. If you're using plain text w/ customers, > yes it's crazy. The whole point is to keep things non-programatic. > > If you're a developer, then write the stuff in pure Ruby and you have > plenty of language-tools to DRY things up to your heart's content. > Or leave the plain-text MOIST* and rejoice in the fact that the step can be shared and therefor DRY things up. *MOIST = More Obvious In Simple Text -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Jun 24 17:31:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 24 Jun 2008 16:31:57 -0500 Subject: [rspec-users] DRY up story In-Reply-To: References: <8172F95C-A7E3-4F95-9670-BF54FB361B1F@gmail.com> Message-ID: <6AB98DDA-58AC-4FCD-A289-8FD6C4696606@gmail.com> On Jun 24, 2008, at 4:31 PM, Rick DeNatale wrote: > On Tue, Jun 24, 2008 at 3:00 PM, David Chelimsky > wrote: > On Jun 24, 2008, at 1:54 PM, Yi Wen wrote: > > In David's presentation @ RailsConf, he has this example: > > Story: measure progress towards registration goals > As a conference organizer > I want to see a report of registrations > So that I can measure progress towards registration goals > > Scenario: one registration shows as 1% > Given a goal of 200 registrations > When 1 attendee registers > Then the goal should be 1% achieved > > Scenario: one registration less than the goal shows as 99% > Given a goal of 200 registrations > When 199 attendees register > Then the goal should be 99% achieved > > Notice that Given part is exactly the same for both scenarios. Does it > possible to DRY up it a little bit by putting Given up to right after > Story part? Or it is just too crazy? > > Depends on who the audience is. If you're using plain text w/ > customers, yes it's crazy. The whole point is to keep things non- > programatic. > > If you're a developer, then write the stuff in pure Ruby and you > have plenty of language-tools to DRY things up to your heart's > content. > > Or leave the plain-text MOIST* and rejoice in the fact that the step > can be shared and therefor DRY things up. > > *MOIST = More Obvious In Simple Text w00t! Got one for CLEAR? > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From raasdnil at gmail.com Wed Jun 25 02:55:57 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 25 Jun 2008 16:55:57 +1000 Subject: [rspec-users] how do I mock the Rails Logger with should_receive? In-Reply-To: <5b1b5e890806121556w2a5c7cc2p246ac6dcf3a1de24@mail.gmail.com> References: <5b1b5e890806121556w2a5c7cc2p246ac6dcf3a1de24@mail.gmail.com> Message-ID: <57a815bf0806242355k40a4c313yc2b7ab8b92781f00@mail.gmail.com> On Fri, Jun 13, 2008 at 8:56 AM, john wrote: > I'm trying to mock the Rails Logger for the following code: > rescue TimeoutError => error > $logger.error("#{self.name} Timeout for #{path}: #{error}") and return > rescue SocketError => error > $logger.error("#{self.name} SocketError for #{path}: #{error}") and > return > rescue StandardError => error > $logger.error("#{self.name} Error for #{path}: #{error}") and return > end > > my failed attempt to spec: > > logger = mock_model(Logger) > logger.stub(:error) > logger.should_receive(:error).with(:any_args) > > Do you know of any solution for mocking this? The problem you are hitting is that the 'logger' you are accessing from within your code is different depending on what and where you are accessing it from. Assuming you are in a Rails Model, then the 'logger' is actually hooked into the model itself, so stubbing it would be like: class Person < ActiveRecord::Base def log_Test logger.warn("Hello!") end end it "should talk to the logger" do @person.logger.should_receive(:warn).with("Hello!") @person.log_test end > Also, do you think the Rails Logger is worth mocking? Well, that depends. Is logging the data a part of your application that you need to know works? If you are doing transaction processing, the you probably do want to ensure that your logger is tracing these transactions as part of an audit trail. It's up to your problem domain. Mikel From chris at cobaltedge.com Wed Jun 25 14:37:04 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Wed, 25 Jun 2008 11:37:04 -0700 Subject: [rspec-users] Dealing with dependent data Message-ID: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> If there's already been a thread on this, let me know (and if you can, point me to it)... In building my stories, I often need to setup a bunch of data where you have multiple levels of models that depend on each other. For example, I'd have models like Doctor, Organization, and Location. To run various scenarios that view doctors, say by organization, or by tags, or whatever, I need to setup fixture-like data for locations, then organizations (which belong to a location), then docs which belong to an organization. I am sure others have this in their apps, and I'm wondering how you organize you Given's/steps across these things. Right now, for example, I have doctor_steps, organization_steps, and location_steps, which have their respective Givens in them. But, what's been bugging me is that when one Given depends on another, the only place this is really hinted at is in the plain text story file, where I might have: Scenario: view doctors Given: existing locations And: existing organizations And: existing doctors My steps that depend on other data always check for that existance. e.g. in Organizations given, I'd do a "Location.count.should > 1" or more specific depending on my needs, etc. So, what are folks doing in this regard, any tips, recommendations, suggestions, etc.? Is there some way to indicate dependencies like this that I simply don't know about? -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From raasdnil at gmail.com Wed Jun 25 21:38:51 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 26 Jun 2008 11:38:51 +1000 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> Message-ID: <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> On Thu, Jun 26, 2008 at 4:37 AM, Christopher Bailey wrote: > If there's already been a thread on this, let me know (and if you can, > point me to it)... I asked something similar about a week or so ago, you can see it here: http://www.ruby-forum.com/topic/156392 It is on 'reusing story specs' But I have done some more work since then... > In building my stories, I often need to setup a bunch of data where > you have multiple levels of models that depend on each other. For > Scenario: view doctors > Given: existing locations > And: existing organizations > And: existing doctors You can use plain text stories and use multiple steps_for to get a similar effect. But in this case, on that set of stories, it would make sense to reduce that Given block down to: # viewing doctors story file... Scenario: view doctors Given: existing doctors in organizations that have a location When... And then I would use some helpers or fixture loading to handle your data loading... # spec helper file... def build_valid_doctor(params) location = Location.create(:blah...) org = Organization.create(:location => location) Doctor.create({:organization => org}.merge(params)) end # steps file.... steps_for :viewing_doctors do Given "existing doctors in organizations that have a location" build_valid_doctor(:surname => 'Hyde') build_valid_doctor(:surname => 'Jeckle') end end Of course you can make those factory methods do all sorts of things... Hope that helps Mikel -- http://lindsaar.net/ Rails, RSpec, Puppet andLife blog.... From mailing_lists at railsnewbie.com Wed Jun 25 22:07:39 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 25 Jun 2008 22:07:39 -0400 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> Message-ID: <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> On Jun 25, 2008, at 9:38 PM, Mikel Lindsaar wrote: > On Thu, Jun 26, 2008 at 4:37 AM, Christopher Bailey > wrote: >> If there's already been a thread on this, let me know (and if you >> can, >> point me to it)... > > I asked something similar about a week or so ago, you can see it here: > > http://www.ruby-forum.com/topic/156392 > > It is on 'reusing story specs' > > But I have done some more work since then... > >> In building my stories, I often need to setup a bunch of data where >> you have multiple levels of models that depend on each other. For > >> Scenario: view doctors >> Given: existing locations >> And: existing organizations >> And: existing doctors > > You can use plain text stories and use multiple steps_for to get a > similar effect. > > But in this case, on that set of stories, it would make sense to > reduce that Given block down to: > > # viewing doctors story file... > Scenario: view doctors > Given: existing doctors in organizations that have a location > When... > > And then I would use some helpers or fixture loading to handle your > data loading... > > # spec helper file... > def build_valid_doctor(params) > location = Location.create(:blah...) > org = Organization.create(:location => location) > Doctor.create({:organization => org}.merge(params)) > end > > # steps file.... > steps_for :viewing_doctors do > > Given "existing doctors in organizations that have a location" > build_valid_doctor(:surname => 'Hyde') > build_valid_doctor(:surname => 'Jeckle') > end > > end > > > Of course you can make those factory methods do all sorts of things... It really seems you are asking two questions: One about reusability, and one about setting up data. I can't add anything to the first, but factories are definitely the way to go regarding the second issue (setting up the data). Check out this post by Dan Manges (and look at the fixture options at the end of the post): http://www.dcmanges.com/blog/38 Scott > > > Hope that helps > > Mikel > > -- > http://lindsaar.net/ > Rails, RSpec, Puppet andLife blog.... > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From chris at cobaltedge.com Wed Jun 25 22:18:54 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Wed, 25 Jun 2008 19:18:54 -0700 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> Message-ID: <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> In reply to both of the last two replies to my post... I am already doing the factory stuff for data creation. My question is more about dependencies between fixture data sets. So, you have 3 related models: A, B, C. Model A can stand on its own. Model B can't exist without an A, and C can't exist without a B (which means it also indirectly requires an A). I have factories that create these things, and helper methods that create sets of them (since I need fairly specific relationships, not just randomly generated ones like say object_daddy or factory_girl plugins/gems help with (although I have used object_daddy and like it - tried to use factory girl, but had problems). It's not really a true "problem", it's more that there is an inherant dependency here, where there isn't a very expressive way of stating that. So, more a point of discussing how other folks are handling this and making things clear in their code that their are dependencies. The idea to combine the 3 givens is a point I'll look at, as I think I agree that that probably conveys the dependency and association between the three models better. The other thing I'm finding a lot is that I have a lot of the same needs for this fixture type data between my regular RSpec examples (model tests mostly, as I'm going light on controller and view tests and mostly doing stories) and my RSpec stories. Are folks using say a single helper/factory to generate fixture data for both? I guess I only just though of sharing it between them now, as there really is no technological barrier to doing so, although in my examples I do tend to leverage mocks and stubs when I can, but stay strictly "real" with stories. On Wed, Jun 25, 2008 at 7:07 PM, Scott Taylor wrote: > > On Jun 25, 2008, at 9:38 PM, Mikel Lindsaar wrote: > >> On Thu, Jun 26, 2008 at 4:37 AM, Christopher Bailey >> wrote: >>> >>> If there's already been a thread on this, let me know (and if you can, >>> point me to it)... >> >> I asked something similar about a week or so ago, you can see it here: >> >> http://www.ruby-forum.com/topic/156392 >> >> It is on 'reusing story specs' >> >> But I have done some more work since then... >> >>> In building my stories, I often need to setup a bunch of data where >>> you have multiple levels of models that depend on each other. For >> >>> Scenario: view doctors >>> Given: existing locations >>> And: existing organizations >>> And: existing doctors >> >> You can use plain text stories and use multiple steps_for to get a >> similar effect. >> >> But in this case, on that set of stories, it would make sense to >> reduce that Given block down to: >> >> # viewing doctors story file... >> Scenario: view doctors >> Given: existing doctors in organizations that have a location >> When... >> >> And then I would use some helpers or fixture loading to handle your >> data loading... >> >> # spec helper file... >> def build_valid_doctor(params) >> location = Location.create(:blah...) >> org = Organization.create(:location => location) >> Doctor.create({:organization => org}.merge(params)) >> end >> >> # steps file.... >> steps_for :viewing_doctors do >> >> Given "existing doctors in organizations that have a location" >> build_valid_doctor(:surname => 'Hyde') >> build_valid_doctor(:surname => 'Jeckle') >> end >> >> end >> >> >> Of course you can make those factory methods do all sorts of things... > > > It really seems you are asking two questions: One about reusability, and one > about setting up data. > > I can't add anything to the first, but factories are definitely the way to > go regarding the second issue (setting up the data). Check out this post by > Dan Manges (and look at the fixture options at the end of the post): > > http://www.dcmanges.com/blog/38 > > Scott > >> >> >> Hope that helps >> >> Mikel >> >> -- >> http://lindsaar.net/ >> Rails, RSpec, Puppet andLife blog.... >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From raasdnil at gmail.com Wed Jun 25 22:38:22 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 26 Jun 2008 12:38:22 +1000 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> Message-ID: <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> On Thu, Jun 26, 2008 at 12:18 PM, Christopher Bailey wrote: > The other thing I'm finding a lot is that I have a lot of the same > needs for this fixture type data between my regular RSpec examples > (model tests mostly, as I'm going light on controller and view tests > and mostly doing stories) and my RSpec stories. Are folks using say a > single helper/factory to generate fixture data for both? I guess I > only just though of sharing it between them now, as there really is no > technological barrier to doing so, although in my examples I do tend > to leverage mocks and stubs when I can, but stay strictly "real" with > stories. For me, I tend to use a Model.build_valid pattern to create objects required in my controller view or model specs and then only really stub required behaviour... sort of like cherry picking stubs. So I wouldn't stub the 'name' method on a person, instead, I would create a valid person with the name I need. But I would stub that 'save' returns 'true' or something of the like as I need to ensure a particular execution path. This arguably makes specs more brittle, but for me, finding and fixing failed dependencies as soon as possible is better than having to manually ensure that every method being called in a view is covered elsewhere by a spec... and in changing a spec later, I get instant feedback on if I have a regression failure elsewhere. The other drawback you have with fixture data in stories is that they are by definition an artificial state. It is not guaranteed that the state you create with fixtures could be reproduced by your code. Only through your code executing can you find the relevant states and you might introduce an arbitrary in your fixture data that creates an impossible state allowing your specs to pass. So I ban fixtures in stories in my team for that reason. Anything you need in a story needs to be encompassed in the Given of that story and the story needs to be able to be read in isolation with all requirements visible, see my blog post on "Being clever in specs is for dummies" at http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies For more on what I mean about that, the example is mainly for a describe BDD block, but it applies equally well to a story. Regards Mikel -- http://lindsaar.net/ Rails, RSpec, Puppet andLife blog.... From chris at cobaltedge.com Wed Jun 25 23:38:56 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Wed, 25 Jun 2008 20:38:56 -0700 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> Message-ID: <443c240c0806252038v7b24f365j25df642c8c890c3@mail.gmail.com> I agree in general on fixtures, depending on how you define "fixtures". I never use the standard Rails fixtures, or any YAML based fixture data. I always generate my data from a factory or real ActiveRecord call to create the object. But, I still consider this essentially "fixture" data, it's just created a different way. It's a trade-off. If in my stories I had to walk through the view and create the 30+ objects I needed just to setup my test, well, that test just might not get written. So to me, I use real ActiveRecord calls (via a factory or helper of whatever kind), so that at least I know the model creation is going through the real code, and is pretty close to the path that the controller would do. Then I test whatever it is I'm testing that needs to have data like that. For tests of new/create views, I of course actually create the models via the view (I use Webrat), and such, so that is definitely real, and that to me covers that case sufficiently. On Wed, Jun 25, 2008 at 7:38 PM, Mikel Lindsaar wrote: > On Thu, Jun 26, 2008 at 12:18 PM, Christopher Bailey > wrote: >> The other thing I'm finding a lot is that I have a lot of the same >> needs for this fixture type data between my regular RSpec examples >> (model tests mostly, as I'm going light on controller and view tests >> and mostly doing stories) and my RSpec stories. Are folks using say a >> single helper/factory to generate fixture data for both? I guess I >> only just though of sharing it between them now, as there really is no >> technological barrier to doing so, although in my examples I do tend >> to leverage mocks and stubs when I can, but stay strictly "real" with >> stories. > > For me, I tend to use a Model.build_valid pattern to create objects > required in my controller view or model specs and then only really > stub required behaviour... sort of like cherry picking stubs. > > So I wouldn't stub the 'name' method on a person, instead, I would > create a valid person with the name I need. But I would stub that > 'save' returns 'true' or something of the like as I need to ensure a > particular execution path. > > This arguably makes specs more brittle, but for me, finding and fixing > failed dependencies as soon as possible is better than having to > manually ensure that every method being called in a view is covered > elsewhere by a spec... and in changing a spec later, I get instant > feedback on if I have a regression failure elsewhere. > > The other drawback you have with fixture data in stories is that they > are by definition an artificial state. It is not guaranteed that the > state you create with fixtures could be reproduced by your code. Only > through your code executing can you find the relevant states and you > might introduce an arbitrary in your fixture data that creates an > impossible state allowing your specs to pass. > > So I ban fixtures in stories in my team for that reason. Anything you > need in a story needs to be encompassed in the Given of that story and > the story needs to be able to be read in isolation with all > requirements visible, see my blog post on "Being clever in specs is > for dummies" at > > http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies > > For more on what I mean about that, the example is mainly for a > describe BDD block, but it applies equally well to a story. > > Regards > > Mikel > > > -- > http://lindsaar.net/ > Rails, RSpec, Puppet andLife blog.... > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From dchelimsky at gmail.com Thu Jun 26 09:48:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 26 Jun 2008 08:48:01 -0500 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> Message-ID: <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> On Jun 25, 2008, at 9:38 PM, Mikel Lindsaar wrote: > http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies That post is fantastic. Thanks! From loop at superinfinite.com Thu Jun 26 11:25:27 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Thu, 26 Jun 2008 17:25:27 +0200 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> Message-ID: <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> On 26-jun-2008, at 15:48, David Chelimsky wrote: > On Jun 25, 2008, at 9:38 PM, Mikel Lindsaar wrote: >> http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is- >> for-dummies > > That post is fantastic. Thanks! Couldn't agree more with that post... For instance, restful_authentication now comes with specs, but, ehrm... See for yourself: http://pastie.org/222670 gr, bartz From raasdnil at gmail.com Thu Jun 26 19:55:39 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 27 Jun 2008 09:55:39 +1000 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> Message-ID: <57a815bf0806261655g3b5d4b4fw947b560b11df5dd2@mail.gmail.com> On Fri, Jun 27, 2008 at 1:25 AM, Bart Zonneveld wrote: > On 26-jun-2008, at 15:48, David Chelimsky wrote: >> On Jun 25, 2008, at 9:38 PM, Mikel Lindsaar wrote: >>> http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies >> That post is fantastic. Thanks! > Couldn't agree more with that post... For instance, restful_authentication Thanks guys. spread the word... I am sick of having to mentally translate everything in specs :) -- http://lindsaar.net/ Rails, RSpec, Puppet andLife blog.... From mailing_lists at railsnewbie.com Thu Jun 26 20:37:56 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 26 Jun 2008 20:37:56 -0400 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> Message-ID: <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> On Jun 26, 2008, at 11:25 AM, Bart Zonneveld wrote: > > On 26-jun-2008, at 15:48, David Chelimsky wrote: > >> On Jun 25, 2008, at 9:38 PM, Mikel Lindsaar wrote: >>> http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies >> >> That post is fantastic. Thanks! > > Couldn't agree more with that post... For instance, > restful_authentication now comes with specs, but, ehrm... See for > yourself: http://pastie.org/222670 > haha. I have no idea what's going on there. From chris at cobaltedge.com Fri Jun 27 13:20:12 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Fri, 27 Jun 2008 10:20:12 -0700 Subject: [rspec-users] TextMate language bindings/modes Message-ID: <443c240c0806271020o2093631dyd716022441484bab@mail.gmail.com> I'm wondering if anyone has TextMate working really smoothly where it properly sets the language binding for the given type of file, in relation to Rails, RSpec, RSpec Plain Text Story, RSpec Story Runner, and RSpec Story Steps files? Mine seems to get confused easily, and I'd like to figure out if there's a solid way to specify which binding to use for what files, etc.? Currently, it seems to detect the Plain Text Story files fine. But, it is not detecting steps files or the story runner files. From what I can tell, I've named these according to the usual rules. e.g. for steps files, I have them in .../stories/steps/theme_steps.rb for example. And for the plain text story and matching runner file, I have .../stories/themes_story and .../stories/themes_story.rb. Further, if I manually set a file to RSpec Story Runner, then after that every .rb file I open will be that way. It seems this is one of the core problems - the ".rb" binding is greedy - whoever sets it last sets it for everything, and anytime it changes, it changes for all. -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From ben at benmabey.com Thu Jun 26 21:52:03 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 26 Jun 2008 19:52:03 -0600 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> Message-ID: <486447C3.7030909@benmabey.com> Scott Taylor wrote: > > On Jun 26, 2008, at 11:25 AM, Bart Zonneveld wrote: > >> >> On 26-jun-2008, at 15:48, David Chelimsky wrote: >> >>> On Jun 25, 2008, at 9:38 PM, Mikel Lindsaar wrote: >>>> http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies >>>> >>> >>> That post is fantastic. Thanks! >> >> Couldn't agree more with that post... For instance, >> restful_authentication now comes with specs, but, ehrm... See for >> yourself: http://pastie.org/222670 >> > > haha. I have no idea what's going on there. > > This is slightly OT.. but looking at those specs brings up one of my other pet peeves, and that is excluding the "should" from the specs. I have seen a lot of projects and developers that I respect highly not use the word "should" in there specs. I have accepted it as just one of those things that people disagree on, but I think there is a lot of value of having the "should". For one it makes removing the example easier when it becomes incorrect (meaning, the expected behaviour has changed.) I guess I just see the "should" as being a bigger part of BDD than some people. Am I the only one who thinks this or what are the arguments for not using 'should'? -Ben From ben at benmabey.com Fri Jun 27 16:03:21 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 27 Jun 2008 14:03:21 -0600 Subject: [rspec-users] TextMate language bindings/modes In-Reply-To: <443c240c0806271020o2093631dyd716022441484bab@mail.gmail.com> References: <443c240c0806271020o2093631dyd716022441484bab@mail.gmail.com> Message-ID: <48654789.3000909@benmabey.com> Christopher Bailey wrote: > I'm wondering if anyone has TextMate working really smoothly where it > properly sets the language binding for the given type of file, in > relation to Rails, RSpec, RSpec Plain Text Story, RSpec Story Runner, > and RSpec Story Steps files? Mine seems to get confused easily, and > I'd like to figure out if there's a solid way to specify which binding > to use for what files, etc.? > > Currently, it seems to detect the Plain Text Story files fine. But, > it is not detecting steps files or the story runner files. From what > I can tell, I've named these according to the usual rules. e.g. for > steps files, I have them in .../stories/steps/theme_steps.rb for > example. And for the plain text story and matching runner file, I > have .../stories/themes_story and .../stories/themes_story.rb. > > Further, if I manually set a file to RSpec Story Runner, then after > that every .rb file I open will be that way. It seems this is one of > the core problems - the ".rb" binding is greedy - whoever sets it last > sets it for everything, and anytime it changes, it changes for all. > > Christopher, In the past I have had my bindings messed up so that all my ruby files were treated as rspec files. This post walks through how you can reset your bindings: http://blog.macromates.com/2007/file-type-detection-rspec-rails/ Hope that helps, Ben From jim at saturnflyer.com Fri Jun 27 19:58:11 2008 From: jim at saturnflyer.com (Jim Gay) Date: Fri, 27 Jun 2008 19:58:11 -0400 Subject: [rspec-users] Dealing with dependent data In-Reply-To: <486447C3.7030909@benmabey.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> <486447C3.7030909@benmabey.com> Message-ID: <38151879-BF78-41B0-A8FF-9F5AE0E7F694@saturnflyer.com> >>>>> http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies >>>> >>>> That post is fantastic. Thanks! >>> >>> Couldn't agree more with that post... For instance, >>> restful_authentication now comes with specs, but, ehrm... See for >>> yourself: http://pastie.org/222670 >> >> haha. I have no idea what's going on there. > > This is slightly OT.. but looking at those specs brings up one of my > other pet peeves, and that is excluding the "should" from the > specs. I have seen a lot of projects and developers that I respect > highly not use the word "should" in there specs. I have accepted it > as just one of those things that people disagree on, but I think > there is a lot of value of having the "should". For one it makes > removing the example easier when it becomes incorrect (meaning, the > expected behaviour has changed.) I guess I just see the "should" as > being a bigger part of BDD than some people. > > Am I the only one who thinks this or what are the arguments for not > using 'should'? I've been meaning to ask the list about this for a while now. I don't always use "should", but I've been trying to come up with a standard way to approach the Rails has_one, has_many, etc. as opposed to methods on the object such as name, description etc. What I mean is that I want to write specs so that I know if something refers to an associated object or not, without resorting to writing technically oriented specs that define implementation rather than behavior. "project should have an owner" unfortunately doesn't let me know if it's a method that returns a value, or a method that returns another object. Does anyone have advice or experience in writing the specs to provide that kind of information? I hope this isn't too much of a thread hijack. But to bring it back around, I totally agree with the article, and it's particularly apropos for open source projects (assuming the project owner wants new users to get involved in development) -Jim From dchelimsky at gmail.com Fri Jun 27 22:07:27 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 27 Jun 2008 21:07:27 -0500 Subject: [rspec-users] Should(not?) test associations (was: Dealing with dependent data) In-Reply-To: <38151879-BF78-41B0-A8FF-9F5AE0E7F694@saturnflyer.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> <486447C3.7030909@benmabey.com> <38151879-BF78-41B0-A8FF-9F5AE0E7F694@saturnflyer.com> Message-ID: On Jun 27, 2008, at 6:58 PM, Jim Gay wrote: > I've been meaning to ask the list about this for a while now. > > I don't always use "should", but I've been trying to come up with a > standard way to approach the Rails has_one, has_many, etc. as > opposed to methods on the object such as name, description etc. > What I mean is that I want to write specs so that I know if > something refers to an associated object or not, without resorting > to writing technically oriented specs that define implementation > rather than behavior. > "project should have an owner" unfortunately doesn't let me know if > it's a method that returns a value, or a method that returns another > object. An association does not want you to know that it's an association. It wants you to think of it as any other attribute. Why do you care what it IS? Focus on what it DOES. > Does anyone have advice or experience in writing the specs to > provide that kind of information? > > I hope this isn't too much of a thread hijack. We'll make a new thread then :) My opinion is that attributes and associations are equally about structure, not behaviour. The fact that a project has an owner is not behaviour. The fact that the owner has an email address is not behaviour. The facts that you can't save a project without an owner, and you can't save an owner without a valid email address are behaviour. And by setting expectations around those, the attributes and associations themselves are handled implicitly: describe Project do it "should not be valid without an owner" do Project.new(:owner => nil).should_not be_valid end end Watch that fail saying that Project does not respond to 'owner=' method. Add a migration and an association. Now it fails saying that it was valid. Add the validation and watch the example pass. That's TDD (yes, starting with a T). Any time I have a an attribute or an association that I *think* is supposed to be on a model, I try to think of what might be interesting about that attribute or association and set expectations about that. There are many who believe that we should have examples like "project.should have_one(:owner)." I can't say that those people are wrong if doing that is adding value to their process and helping them deliver quality software. For me, personally, it's just unnecessary noise that adds maintenance burden later when things move around. And it definitely ain't behaviour. Cheers, David From jim at saturnflyer.com Fri Jun 27 22:55:49 2008 From: jim at saturnflyer.com (Jim Gay) Date: Fri, 27 Jun 2008 22:55:49 -0400 Subject: [rspec-users] Should(not?) test associations (was: Dealing with dependent data) In-Reply-To: References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> <486447C3.7030909@benmabey.com> <38151879-BF78-41B0-A8FF-9F5AE0E7F694@saturnflyer.com> Message-ID: <89101FF4-6148-4FCB-BB00-042E5D0F9590@saturnflyer.com> On Jun 27, 2008, at 10:07 PM, David Chelimsky wrote: > An association does not want you to know that it's an association. > It wants you to think of it as any other attribute. Why do you care > what it IS? Focus on what it DOES. Good point. Being a newbie I sometimes find myself where I *think* I'm doing it well, but find out that it's not quite that good afterall. > > My opinion is that attributes and associations are equally about > structure, not behaviour. The fact that a project has an owner is > not behaviour. The fact that the owner has an email address is not > behaviour. > > The facts that you can't save a project without an owner, and you > can't save an owner without a valid email address are behaviour. And > by setting expectations around those, the attributes and > associations themselves are handled implicitly: > > describe Project do > it "should not be valid without an owner" do > Project.new(:owner => nil).should_not be_valid > end > end > > Watch that fail saying that Project does not respond to 'owner=' > method. Add a migration and an association. Now it fails saying that > it was valid. Add the validation and watch the example pass. That's > TDD (yes, starting with a T). > > Any time I have a an attribute or an association that I *think* is > supposed to be on a model, I try to think of what might be > interesting about that attribute or association and set expectations > about that. > > There are many who believe that we should have examples like > "project.should have_one(:owner)." I can't say that those people are > wrong if doing that is adding value to their process and helping > them deliver quality software. For me, personally, it's just > unnecessary noise that adds maintenance burden later when things > move around. And it definitely ain't behaviour. Thanks for the response. Perhaps I'm over thinking things. I agree that "project.should have_one(:owner)" is unnecessary. Somewhere the ideas get mangled for me. Suppose a simple spec like this: Project "should not be valid without a name" Owner "should not be valid without a name" How do you spec that the Owner may have 0 or more projects? Owner "should be valid with 0 projects" Owner "should be valid with more than 0 projects" Or would you combine them Owner "should have 0 or more projects" Or should I not care at all about that and just specify that a Project "should not be valid without an owner"? From chris at cobaltedge.com Sat Jun 28 00:27:17 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Fri, 27 Jun 2008 21:27:17 -0700 Subject: [rspec-users] TextMate language bindings/modes In-Reply-To: <48654789.3000909@benmabey.com> References: <443c240c0806271020o2093631dyd716022441484bab@mail.gmail.com> <48654789.3000909@benmabey.com> Message-ID: <443c240c0806272127q22776bbai625363e28fd2fdfc@mail.gmail.com> Thanks, went through that and nuked any bindings, as well as removed .rb from the regular Ruby filetypes. That helped some, but then RSpec Story Runner still wasn't working. What I found I had to do there was tweak it's filetypes, to not just be .rb (since now Rails binding picks that up), but be story.rb: fileTypes = ( 'story.rb' ); Now, as far as I can tell, it properly detects story runner files, steps files, regular RSpec spec files, plain text stories, and then all other .rb's get set to Ruby on Rails. Even plain Ruby scripts get properly set to Ruby since they have the "firstline" setting that searches for the ruby executable in the text. Awesome! Thanks for the tip Ben! Oh, and one note, while the RSpec Story Runner has detection for "steps_for", my story runner files don't usually start with that, they usually require some helpers or what not first, so that's why the standard rule there wasn't picking those up. On Fri, Jun 27, 2008 at 1:03 PM, Ben Mabey wrote: > Christopher Bailey wrote: >> >> I'm wondering if anyone has TextMate working really smoothly where it >> properly sets the language binding for the given type of file, in >> relation to Rails, RSpec, RSpec Plain Text Story, RSpec Story Runner, >> and RSpec Story Steps files? Mine seems to get confused easily, and >> I'd like to figure out if there's a solid way to specify which binding >> to use for what files, etc.? >> >> Currently, it seems to detect the Plain Text Story files fine. But, >> it is not detecting steps files or the story runner files. From what >> I can tell, I've named these according to the usual rules. e.g. for >> steps files, I have them in .../stories/steps/theme_steps.rb for >> example. And for the plain text story and matching runner file, I >> have .../stories/themes_story and .../stories/themes_story.rb. >> >> Further, if I manually set a file to RSpec Story Runner, then after >> that every .rb file I open will be that way. It seems this is one of >> the core problems - the ".rb" binding is greedy - whoever sets it last >> sets it for everything, and anytime it changes, it changes for all. >> >> > > Christopher, > In the past I have had my bindings messed up so that all my ruby files were > treated as rspec files. This post walks through how you can reset your > bindings: > http://blog.macromates.com/2007/file-type-detection-rspec-rails/ > > Hope that helps, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From dchelimsky at gmail.com Sat Jun 28 05:32:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 28 Jun 2008 04:32:07 -0500 Subject: [rspec-users] Should(not?) test associations (was: Dealing with dependent data) In-Reply-To: <89101FF4-6148-4FCB-BB00-042E5D0F9590@saturnflyer.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> <486447C3.7030909@benmabey.com> <38151879-BF78-41B0-A8FF-9F5AE0E7F694@saturnflyer.com> <89101FF4-6148-4FCB-BB00-042E5D0F9590@saturnflyer.com> Message-ID: <8D7FA11E-EDDC-4CF9-A09F-847CAABD9F13@gmail.com> On Jun 27, 2008, at 9:55 PM, Jim Gay wrote: > On Jun 27, 2008, at 10:07 PM, David Chelimsky wrote: >> An association does not want you to know that it's an association. >> It wants you to think of it as any other attribute. Why do you care >> what it IS? Focus on what it DOES. > > Good point. Being a newbie I sometimes find myself where I *think* > I'm doing it well, but find out that it's not quite that good > afterall. There's a great bit of advice in The Inner Game of Tennis that suggests that judging your progress with statements like "I'm doing well" or "I'm doing badly" is counter-productive; that it's more productive to think in terms of observing whether your actions get you to your goal and adjusting based on your observations. You're doing fine. >> My opinion is that attributes and associations are equally about >> structure, not behaviour. The fact that a project has an owner is >> not behaviour. The fact that the owner has an email address is not >> behaviour. >> >> The facts that you can't save a project without an owner, and you >> can't save an owner without a valid email address are behaviour. >> And by setting expectations around those, the attributes and >> associations themselves are handled implicitly: >> >> describe Project do >> it "should not be valid without an owner" do >> Project.new(:owner => nil).should_not be_valid >> end >> end >> >> Watch that fail saying that Project does not respond to 'owner=' >> method. Add a migration and an association. Now it fails saying >> that it was valid. Add the validation and watch the example pass. >> That's TDD (yes, starting with a T). >> >> Any time I have a an attribute or an association that I *think* is >> supposed to be on a model, I try to think of what might be >> interesting about that attribute or association and set >> expectations about that. >> >> There are many who believe that we should have examples like >> "project.should have_one(:owner)." I can't say that those people >> are wrong if doing that is adding value to their process and >> helping them deliver quality software. For me, personally, it's >> just unnecessary noise that adds maintenance burden later when >> things move around. And it definitely ain't behaviour. > > Thanks for the response. Perhaps I'm over thinking things. I agree > that "project.should have_one(:owner)" is unnecessary. > > Somewhere the ideas get mangled for me. > Suppose a simple spec like this: > > Project "should not be valid without a name" > Owner "should not be valid without a name" > > How do you spec that the Owner may have 0 or more projects? Again, structure. Why do you care? Does an owner behave differently if there are 0 projects or more than 0? Is there a maximum number of projects? Maybe projects should be tagged and you want to be able to get an owner's projects by tag? Now THAT's interesting behaviour that you can write examples for. > Owner "should be valid with 0 projects" > Owner "should be valid with more than 0 projects" > > Or would you combine them > > Owner "should have 0 or more projects" > > Or should I not care at all about that and just specify that a > Project "should not be valid without an owner"? I'm beginning to regret the validity example, because it is somewhat structural as well. The behaviour is not whether it's valid or not, but rather whether you can save it or not. So scratch the example I gave earlier and think about this: describe Project do describe "when trying to save" do it "should complain if it has no owner" do lambda do Project.new(:owner => nil).save! end.should raise_error(ActiveRecord::RecordInvalid) end end end (Zach Dennis - this nesting structure should make you happy :) ) That make a bit more sense? One key aspect of BDD is working Outside-In. I try to start with a story and to drive things down from the view to the model (in Rails). So maybe my story is that as an owner I can edit my projects, but not other people's projects. This is going to naturally lead me towards examples that will implicitly cover the fact that an owner can more than 0 projects without actually specifying that directly. HTH, David From jim at saturnflyer.com Sat Jun 28 09:52:17 2008 From: jim at saturnflyer.com (Jim Gay) Date: Sat, 28 Jun 2008 09:52:17 -0400 Subject: [rspec-users] Should(not?) test associations (was: Dealing with dependent data) In-Reply-To: <8D7FA11E-EDDC-4CF9-A09F-847CAABD9F13@gmail.com> References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> <486447C3.7030909@benmabey.com> <38151879-BF78-41B0-A8FF-9F5AE0E7F694@saturnflyer.com> <89101FF4-6148-4FCB-BB00-042E5D0F9590@saturnflyer.com> <8D7FA11E-EDDC-4CF9-A09F-847CAABD9F13@gmail.com> Message-ID: On Jun 28, 2008, at 5:32 AM, David Chelimsky wrote: > I'm beginning to regret the validity example, because it is somewhat > structural as well. The behaviour is not whether it's valid or not, > but rather whether you can save it or not. So scratch the example I > gave earlier and think about this: > > describe Project do > describe "when trying to save" do > it "should complain if it has no owner" do > lambda do > Project.new(:owner => nil).save! > end.should raise_error(ActiveRecord::RecordInvalid) > end > end > end > > (Zach Dennis - this nesting structure should make you happy :) ) > > That make a bit more sense? Absolutely! > One key aspect of BDD is working Outside-In. I try to start with a > story and to drive things down from the view to the model (in > Rails). So maybe my story is that as an owner I can edit my > projects, but not other people's projects. This is going to > naturally lead me towards examples that will implicitly cover the > fact that an owner can more than 0 projects without actually > specifying that directly. Trying to wrap my head around how to go about BDD has been difficult and I think I now understand why. Many of the examples I've seen for RSpec have used things like "should be valid" when that doesn't actually describe behavior at all. The first RSpec generated Rails specs that I used had plenty of this but that seems to be more about implementation than behavior, so I've had trouble understanding how to really describe behavior. Little by little I'm getting it, but I unfortunately don't feel like I have time to go BDD cold turkey. I still do some code first and then spec, but I understand the benefits of BDD and I'm sure I'll get to that point eventually. From dchelimsky at gmail.com Sat Jun 28 10:34:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 28 Jun 2008 09:34:43 -0500 Subject: [rspec-users] Should(not?) test associations (was: Dealing with dependent data) In-Reply-To: References: <443c240c0806251137m1fe25eacv5b2a1246626abe4d@mail.gmail.com> <57a815bf0806251838k5261ece6oaf4d1908e9d2c726@mail.gmail.com> <904D7D96-E987-427E-B9A1-FA906F51BF7C@railsnewbie.com> <443c240c0806251918h7100225dg71199a4904fc3564@mail.gmail.com> <57a815bf0806251938j56d05bd5ud33481540c50d25e@mail.gmail.com> <6288281C-DAD8-4E28-AA01-5DB2A472EDE4@gmail.com> <6B8BC87A-E0E0-4131-B62F-E771302991A3@superinfinite.com> <1178C00D-4187-43F1-AFB1-F948A5FAA11B@railsnewbie.com> <486447C3.7030909@benmabey.com> <38151879-BF78-41B0-A8FF-9F5AE0E7F694@saturnflyer.com> <89101FF4-6148-4FCB-BB00-042E5D0F9590@saturnflyer.com> <8D7FA11E-EDDC-4CF9-A09F-847CAABD9F13@gmail.com> Message-ID: <76A97A2A-4B45-40B8-8419-0395D5DA82AE@gmail.com> On Jun 28, 2008, at 8:52 AM, Jim Gay wrote: > On Jun 28, 2008, at 5:32 AM, David Chelimsky wrote: >> I'm beginning to regret the validity example, because it is >> somewhat structural as well. The behaviour is not whether it's >> valid or not, but rather whether you can save it or not. So scratch >> the example I gave earlier and think about this: >> >> describe Project do >> describe "when trying to save" do >> it "should complain if it has no owner" do >> lambda do >> Project.new(:owner => nil).save! >> end.should raise_error(ActiveRecord::RecordInvalid) >> end >> end >> end >> >> (Zach Dennis - this nesting structure should make you happy :) ) >> >> That make a bit more sense? > > Absolutely! > >> One key aspect of BDD is working Outside-In. I try to start with a >> story and to drive things down from the view to the model (in >> Rails). So maybe my story is that as an owner I can edit my >> projects, but not other people's projects. This is going to >> naturally lead me towards examples that will implicitly cover the >> fact that an owner can more than 0 projects without actually >> specifying that directly. > > Trying to wrap my head around how to go about BDD has been difficult > and I think I now understand why. Many of the examples I've seen for > RSpec have used things like "should be valid" when that doesn't > actually describe behavior at all. The first RSpec generated Rails > specs that I used had plenty of this Ugh! You're right. I'm going to review the generators (they were written a lot of water-under-the-bridge-ago). > ... but that seems to be more about implementation than behavior, so > I've had trouble understanding how to really describe behavior. > > Little by little I'm getting it, but I unfortunately don't feel like > I have time to go BDD cold turkey. I still do some code first and > then spec, but I understand the benefits of BDD and I'm sure I'll > get to that point eventually. Try this as a next step: * code a little * comment out your code * write a small example for a small bit of the commented code * watch it fail * uncomment just enough to make it pass * watch it pass * repeat the last 4 steps This is NOT the end-game, but it will give you a feel for the TDD flow. Plus, at some level, we're all usually operating with some knowledge about the code we're going to write. When we're not, it's common practice from old-school-TDD to code a little, throw out the code entirely (not comment it, but actually delete it) and then start w/ examples. The reason we throw it out is the "code a little" phase quite often introduces something we just don't need. In the comment/ uncomment approach, those unnecessary bits tend to stick around because we *think* we need them. One great promise of TDD is that it encourages less code because we're working against executable examples rather than assumptions about what the code does based on looking at it. Cheers, David From mileshosky at hotmail.com Sat Jun 28 18:57:36 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sat, 28 Jun 2008 15:57:36 -0700 Subject: [rspec-users] Stopping example execution? Message-ID: Hello, I'm wondering If I am missing something here when creating an example that sets an expecation at the top or beginning of an action but requires you to stub / mock everything that follows. Example: I want to test that a certain controller is running a before_filter...thats easy: - controller.should_receive(:require_user) - do_get But now i've got to mock / stub everything else that comes behind this filter so that I don't receive 'unexpected method' errors, or other blowups because I am requesting the whole action. Is there anyway to stop execution after an expectation has been met? It seems to me that this might clean things up a bit. Not sure, I'm still fairly new to BDD/Mocking by about 2 weeks. Thanks _________________________________________________________________ Need to know now? Get instant answers with Windows Live Messenger. http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008 From philodespotos at gmail.com Sat Jun 28 19:24:17 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Sat, 28 Jun 2008 18:24:17 -0500 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: Message-ID: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> On Sat, Jun 28, 2008 at 5:57 PM, Britt Mileshosky wrote: > > Hello, I'm wondering If I am missing something here when creating an example that sets an expecation at the top or beginning of an action but requires you to stub / mock everything that follows. > > Example: > I want to test that a certain controller is running a before_filter...thats easy: > > - controller.should_receive(:require_user) > - do_get > > But now i've got to mock / stub everything else that comes behind this filter so that I don't receive 'unexpected method' errors, or other blowups because I am requesting the whole action. Is there anyway to stop execution after an expectation has been met? It seems to me that this might clean things up a bit. Not sure, I'm still fairly new to BDD/Mocking by about 2 weeks. Yep, you can stub out the requested action on the controller. Say you're testing that the :index action requires authentication: controller.should_not_receive(:index) stub_not_logged_in do_get Or the opposite: controller.should_receive(:index) stub_logged_in do_get Personally I prefer expecting the action instead of expecting the filters, but I think both would accomplish the same goal, as long as you tested the filter on its own. If you just wanted to stub out the action to prevent it from doing anything, you could of course just use controller.stub!(:index). HTH k From mileshosky at hotmail.com Sat Jun 28 20:27:38 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sat, 28 Jun 2008 17:27:38 -0700 Subject: [rspec-users] Stopping example execution? In-Reply-To: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> Message-ID: ---------------------------------------- > Date: Sat, 28 Jun 2008 18:24:17 -0500 > From: philodespotos at gmail.com > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] Stopping example execution? > > On Sat, Jun 28, 2008 at 5:57 PM, Britt Mileshosky > wrote: >> >> Hello, I'm wondering If I am missing something here when creating an example that sets an expecation at the top or beginning of an action but requires you to stub / mock everything that follows. >> >> Example: >> I want to test that a certain controller is running a before_filter...thats easy: >> >> - controller.should_receive(:require_user) >> - do_get >> >> But now i've got to mock / stub everything else that comes behind this filter so that I don't receive 'unexpected method' errors, or other blowups because I am requesting the whole action. Is there anyway to stop execution after an expectation has been met? It seems to me that this might clean things up a bit. Not sure, I'm still fairly new to BDD/Mocking by about 2 weeks. > > Yep, you can stub out the requested action on the controller. Say > you're testing that the :index action requires authentication: > > controller.should_not_receive(:index) > stub_not_logged_in > do_get > > Or the opposite: > > controller.should_receive(:index) > stub_logged_in > do_get > > Personally I prefer expecting the action instead of expecting the > filters, but I think both would accomplish the same goal, as long as > you tested the filter on its own. If you just wanted to stub out the > action to prevent it from doing anything, you could of course just use > controller.stub!(:index). > > HTH > > k > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users So i did something like. - controller.should_receive(:before_filter_action) - controller.stub!(:action_after_filter) - do_get Works nicely... but if you think about it and look closely, we are still stubbing methods after the intended expectation was met. This method just happens to encapsulate a whole other set of methods, which is why it works nicely. But lets say i have something like this --------------------------------------------------------------------------------------------------- def some_action @user = self.current_user @account = self.current_account if self.has_account? @person = @account.people.find(params[:person]) end --------------------------------------------------------------------------------------------------- describe "with a logged in user" before(:each) do controller.stub!(:current_account) @account = stub_model(UserAccount) # Shouldn't have to stub here? @person = stub_model(User) # Shouldn't have to stub here? @people = mock("list of people") # Shouldn't have to stub here? @people.stub!(find) # Shouldn't have to stub here? @account.stub!(:people).and_return(@people) # Shouldn't have to stub here? end it "should find current user" do controller.should_receive(:current_user).and_return(@mockUser) do_get end describe "who has an account" do ... should put account stubbing here with examples describe "which has people" do ... should put people stubbing here with examples end describe "which has 0 people" do ... end end describe "who doesnt have an account" do ... end end ------------------------------------------------------------------------------------------------------------------------------ Notice I have to stub everything out at the first before(:each) declaration because my "should find current user" example will blow up because of unexpected methods after the expectation. All I want to know is that the current user is expected to be found and stop. My examples LATER should define stubs and expectations. I'd like something like - controller.should_receive(:current_user).and_return(@mockUser).end_example Am i going about it all wrong? Is there something I'm missing or does this just seem natural... Gracias, Britt _________________________________________________________________ Earn cashback on your purchases with Live Search - the search that pays you back! http://search.live.com/cashback/?&pkw=form=MIJAAF/publ=HMTGL/crea=earncashback From mailing_lists at railsnewbie.com Sat Jun 28 20:32:26 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 28 Jun 2008 20:32:26 -0400 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> Message-ID: <4679E130-F67A-4C81-8444-C7AC7B391423@railsnewbie.com> On Jun 28, 2008, at 8:27 PM, Britt Mileshosky wrote: > > > ---------------------------------------- >> Date: Sat, 28 Jun 2008 18:24:17 -0500 >> From: philodespotos at gmail.com >> To: rspec-users at rubyforge.org >> Subject: Re: [rspec-users] Stopping example execution? >> >> On Sat, Jun 28, 2008 at 5:57 PM, Britt Mileshosky >> wrote: >>> >>> Hello, I'm wondering If I am missing something here when creating >>> an example that sets an expecation at the top or beginning of an >>> action but requires you to stub / mock everything that follows. >>> >>> Example: >>> I want to test that a certain controller is running a >>> before_filter...thats easy: >>> >>> - controller.should_receive(:require_user) >>> - do_get >>> >>> But now i've got to mock / stub everything else that comes behind >>> this filter so that I don't receive 'unexpected method' errors, or >>> other blowups because I am requesting the whole action. Is there >>> anyway to stop execution after an expectation has been met? It >>> seems to me that this might clean things up a bit. Not sure, I'm >>> still fairly new to BDD/Mocking by about 2 weeks. >> >> Yep, you can stub out the requested action on the controller. Say >> you're testing that the :index action requires authentication: >> >> controller.should_not_receive(:index) >> stub_not_logged_in >> do_get >> >> Or the opposite: >> >> controller.should_receive(:index) >> stub_logged_in >> do_get >> >> Personally I prefer expecting the action instead of expecting the >> filters, but I think both would accomplish the same goal, as long as >> you tested the filter on its own. If you just wanted to stub out the >> action to prevent it from doing anything, you could of course just >> use >> controller.stub!(:index). >> >> HTH >> >> k >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > So i did something like. > > - controller.should_receive(:before_filter_action) > - controller.stub!(:action_after_filter) > - do_get > > Works nicely... but if you think about it and look closely, we are > still stubbing methods after the intended expectation was met. This > method just happens to encapsulate a whole other set of methods, > which is why it works nicely. > > But lets say i have something like this > > --------------------------------------------------------------------------------------------------- > > def some_action > @user = self.current_user > @account = self.current_account if self.has_account? > @person = @account.people.find(params[:person]) > end > > --------------------------------------------------------------------------------------------------- > > describe "with a logged in user" > > before(:each) do > controller.stub!(:current_account) > @account = stub_model(UserAccount) # Shouldn't have to stub here? > @person = stub_model(User) # Shouldn't have to stub > here? > @people = mock("list of people") # Shouldn't have to stub > here? > @people.stub!(find) # Shouldn't have > to stub here? > @account.stub!(:people).and_return(@people) # Shouldn't > have to stub here? > end Are you looking for the :null_object => true flag? Scott From mileshosky at hotmail.com Sat Jun 28 20:50:19 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sat, 28 Jun 2008 17:50:19 -0700 Subject: [rspec-users] Stopping example execution? In-Reply-To: <4679E130-F67A-4C81-8444-C7AC7B391423@railsnewbie.com> References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <4679E130-F67A-4C81-8444-C7AC7B391423@railsnewbie.com> Message-ID: ---------------------------------------- > From: mailing_lists at railsnewbie.com > To: rspec-users at rubyforge.org > Date: Sat, 28 Jun 2008 20:32:26 -0400 > Subject: Re: [rspec-users] Stopping example execution? > > > On Jun 28, 2008, at 8:27 PM, Britt Mileshosky wrote: > >> >> >> ---------------------------------------- >>> Date: Sat, 28 Jun 2008 18:24:17 -0500 >>> From: philodespotos at gmail.com >>> To: rspec-users at rubyforge.org >>> Subject: Re: [rspec-users] Stopping example execution? >>> >>> On Sat, Jun 28, 2008 at 5:57 PM, Britt Mileshosky >>> wrote: >>>> >>>> Hello, I'm wondering If I am missing something here when creating >>>> an example that sets an expecation at the top or beginning of an >>>> action but requires you to stub / mock everything that follows. >>>> >>>> Example: >>>> I want to test that a certain controller is running a >>>> before_filter...thats easy: >>>> >>>> - controller.should_receive(:require_user) >>>> - do_get >>>> >>>> But now i've got to mock / stub everything else that comes behind >>>> this filter so that I don't receive 'unexpected method' errors, or >>>> other blowups because I am requesting the whole action. Is there >>>> anyway to stop execution after an expectation has been met? It >>>> seems to me that this might clean things up a bit. Not sure, I'm >>>> still fairly new to BDD/Mocking by about 2 weeks. >>> >>> Yep, you can stub out the requested action on the controller. Say >>> you're testing that the :index action requires authentication: >>> >>> controller.should_not_receive(:index) >>> stub_not_logged_in >>> do_get >>> >>> Or the opposite: >>> >>> controller.should_receive(:index) >>> stub_logged_in >>> do_get >>> >>> Personally I prefer expecting the action instead of expecting the >>> filters, but I think both would accomplish the same goal, as long as >>> you tested the filter on its own. If you just wanted to stub out the >>> action to prevent it from doing anything, you could of course just >>> use >>> controller.stub!(:index). >>> >>> HTH >>> >>> k >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> So i did something like. >> >> - controller.should_receive(:before_filter_action) >> - controller.stub!(:action_after_filter) >> - do_get >> >> Works nicely... but if you think about it and look closely, we are >> still stubbing methods after the intended expectation was met. This >> method just happens to encapsulate a whole other set of methods, >> which is why it works nicely. >> >> But lets say i have something like this >> >> --------------------------------------------------------------------------------------------------- >> >> def some_action >> @user = self.current_user >> @account = self.current_account if self.has_account? >> @person = @account.people.find(params[:person]) >> end >> >> --------------------------------------------------------------------------------------------------- >> >> describe "with a logged in user" >> >> before(:each) do >> controller.stub!(:current_account) >> @account = stub_model(UserAccount) # Shouldn't have to stub here? >> @person = stub_model(User) # Shouldn't have to stub >> here? >> @people = mock("list of people") # Shouldn't have to stub >> here? >> @people.stub!(find) # Shouldn't have >> to stub here? >> @account.stub!(:people).and_return(@people) # Shouldn't >> have to stub here? >> end > > > > Are you looking for the :null_object => true flag? > > Scott > Scott, I don't believe so, but can you see where that might work in the example given above? I've never used the null_object flag, and looking at the documentation, it seems as though I'd still need to declare all my mocks at the very beginning, rather than incrementally as I work down through my code and examples. _________________________________________________________________ The i?m Talkathon starts 6/24/08.? For now, give amongst yourselves. http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst From mileshosky at hotmail.com Sat Jun 28 21:01:44 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sat, 28 Jun 2008 18:01:44 -0700 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <4679E130-F67A-4C81-8444-C7AC7B391423@railsnewbie.com> Message-ID: ---------------------------------------- > From: mileshosky at hotmail.com > To: rspec-users at rubyforge.org > Date: Sat, 28 Jun 2008 17:50:19 -0700 > Subject: Re: [rspec-users] Stopping example execution? > > > > ---------------------------------------- >> From: mailing_lists at railsnewbie.com >> To: rspec-users at rubyforge.org >> Date: Sat, 28 Jun 2008 20:32:26 -0400 >> Subject: Re: [rspec-users] Stopping example execution? >> >> >> On Jun 28, 2008, at 8:27 PM, Britt Mileshosky wrote: >> >>> >>> >>> ---------------------------------------- >>>> Date: Sat, 28 Jun 2008 18:24:17 -0500 >>>> From: philodespotos at gmail.com >>>> To: rspec-users at rubyforge.org >>>> Subject: Re: [rspec-users] Stopping example execution? >>>> >>>> On Sat, Jun 28, 2008 at 5:57 PM, Britt Mileshosky >>>> wrote: >>>>> >>>>> Hello, I'm wondering If I am missing something here when creating >>>>> an example that sets an expecation at the top or beginning of an >>>>> action but requires you to stub / mock everything that follows. >>>>> >>>>> Example: >>>>> I want to test that a certain controller is running a >>>>> before_filter...thats easy: >>>>> >>>>> - controller.should_receive(:require_user) >>>>> - do_get >>>>> >>>>> But now i've got to mock / stub everything else that comes behind >>>>> this filter so that I don't receive 'unexpected method' errors, or >>>>> other blowups because I am requesting the whole action. Is there >>>>> anyway to stop execution after an expectation has been met? It >>>>> seems to me that this might clean things up a bit. Not sure, I'm >>>>> still fairly new to BDD/Mocking by about 2 weeks. >>>> >>>> Yep, you can stub out the requested action on the controller. Say >>>> you're testing that the :index action requires authentication: >>>> >>>> controller.should_not_receive(:index) >>>> stub_not_logged_in >>>> do_get >>>> >>>> Or the opposite: >>>> >>>> controller.should_receive(:index) >>>> stub_logged_in >>>> do_get >>>> >>>> Personally I prefer expecting the action instead of expecting the >>>> filters, but I think both would accomplish the same goal, as long as >>>> you tested the filter on its own. If you just wanted to stub out the >>>> action to prevent it from doing anything, you could of course just >>>> use >>>> controller.stub!(:index). >>>> >>>> HTH >>>> >>>> k >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >>> So i did something like. >>> >>> - controller.should_receive(:before_filter_action) >>> - controller.stub!(:action_after_filter) >>> - do_get >>> >>> Works nicely... but if you think about it and look closely, we are >>> still stubbing methods after the intended expectation was met. This >>> method just happens to encapsulate a whole other set of methods, >>> which is why it works nicely. >>> >>> But lets say i have something like this >>> >>> --------------------------------------------------------------------------------------------------- >>> >>> def some_action >>> @user = self.current_user >>> @account = self.current_account if self.has_account? >>> @person = @account.people.find(params[:person]) >>> end >>> >>> --------------------------------------------------------------------------------------------------- >>> >>> describe "with a logged in user" >>> >>> before(:each) do >>> controller.stub!(:current_account) >>> @account = stub_model(UserAccount) # Shouldn't have to stub here? >>> @person = stub_model(User) # Shouldn't have to stub >>> here? >>> @people = mock("list of people") # Shouldn't have to stub >>> here? >>> @people.stub!(find) # Shouldn't have >>> to stub here? >>> @account.stub!(:people).and_return(@people) # Shouldn't >>> have to stub here? >>> end >> >> >> >> Are you looking for the :null_object => true flag? >> >> Scott >> > > Scott, I don't believe so, but can you see where that might work in the example given above? I've never used the null_object flag, and looking at the documentation, it seems as though I'd still need to declare all my mocks at the very beginning, rather than incrementally as I work down through my code and examples. > I just noticed, Scott truncated my email so the full example I gave is not shown above, please refer to the previous messages for my full example. _________________________________________________________________ Earn cashback on your purchases with Live Search - the search that pays you back! http://search.live.com/cashback/?&pkw=form=MIJAAF/publ=HMTGL/crea=earncashback From jony at jonysk.net Sat Jun 28 21:43:41 2008 From: jony at jonysk.net (Jony dos Santos Kostetzer) Date: Sat, 28 Jun 2008 22:43:41 -0300 Subject: [rspec-users] Fixtures in a story Message-ID: <4866E8CD.90806@jonysk.net> Hi there, I have some legacy fixtures of test/unit that come in handy and I'd like to use them in my stories. I'm wondering what is the best way to do it. Any suggestion? Jony From dchelimsky at gmail.com Sun Jun 29 07:09:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jun 2008 06:09:47 -0500 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> Message-ID: <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> On Jun 28, 2008, at 7:27 PM, Britt Mileshosky wrote: > ---------------------------------------- >> Date: Sat, 28 Jun 2008 18:24:17 -0500 >> From: philodespotos at gmail.com >> To: rspec-users at rubyforge.org >> Subject: Re: [rspec-users] Stopping example execution? >> >> On Sat, Jun 28, 2008 at 5:57 PM, Britt Mileshosky >> wrote: >>> >>> Hello, I'm wondering If I am missing something here when creating >>> an example that sets an expecation at the top or beginning of an >>> action but requires you to stub / mock everything that follows. >>> >>> Example: >>> I want to test that a certain controller is running a >>> before_filter...thats easy: >>> >>> - controller.should_receive(:require_user) >>> - do_get >>> >>> But now i've got to mock / stub everything else that comes behind >>> this filter so that I don't receive 'unexpected method' errors, or >>> other blowups because I am requesting the whole action. Is there >>> anyway to stop execution after an expectation has been met? It >>> seems to me that this might clean things up a bit. Not sure, I'm >>> still fairly new to BDD/Mocking by about 2 weeks. >> >> Yep, you can stub out the requested action on the controller. Say >> you're testing that the :index action requires authentication: >> >> controller.should_not_receive(:index) >> stub_not_logged_in >> do_get >> >> Or the opposite: >> >> controller.should_receive(:index) >> stub_logged_in >> do_get >> >> Personally I prefer expecting the action instead of expecting the >> filters, but I think both would accomplish the same goal, as long as >> you tested the filter on its own. If you just wanted to stub out the >> action to prevent it from doing anything, you could of course just >> use >> controller.stub!(:index). >> >> HTH >> >> k >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > So i did something like. > > - controller.should_receive(:before_filter_action) > - controller.stub!(:action_after_filter) > - do_get > > Works nicely... but if you think about it and look closely, we are > still stubbing methods after the intended expectation was met. This > method just happens to encapsulate a whole other set of methods, > which is why it works nicely. > > But lets say i have something like this > > --------------------------------------------------------------------------------------------------- > > def some_action > @user = self.current_user > @account = self.current_account if self.has_account? > @person = @account.people.find(params[:person]) > end > > --------------------------------------------------------------------------------------------------- > > describe "with a logged in user" > > before(:each) do > controller.stub!(:current_account) > @account = stub_model(UserAccount) # Shouldn't have to stub here? > @person = stub_model(User) # Shouldn't have to stub > here? > @people = mock("list of people") # Shouldn't have to stub > here? > @people.stub!(find) # Shouldn't have > to stub here? > @account.stub!(:people).and_return(@people) # Shouldn't > have to stub here? > end > > it "should find current user" do > controller.should_receive(:current_user).and_return(@mockUser) > do_get > end > > describe "who has an account" do > ... should put account stubbing here with examples > > > describe "which has people" do > ... should put people stubbing here with examples > end > > describe "which has 0 people" do > ... > end > > > end > > describe "who doesnt have an account" do > ... > end > > end > > ------------------------------------------------------------------------------------------------------------------------------ > > Notice I have to stub everything out at the first before(:each) > declaration because my "should find current user" example will blow > up because of unexpected methods after the expectation. All I want > to know is that the current user is expected to be found and stop. > My examples LATER should define stubs and expectations. > > I'd like something like > > - > controller > .should_receive(:current_user).and_return(@mockUser).end_example > > Am i going about it all wrong? Is there something I'm missing or > does this just seem natural... You're doing the right thing by handling the stubs before(:each) - that's what it's therefore - to set up the environment so things will run. I would recommend avoiding instance variable assignment there, however. If you need a variable, create it directly in the example. This is something that I've only recently started doing and I find that it keeps things much more clear. There are a few things you can do to tidy up the stubs a bit. You could organize things differently to express the relationships better: before(:each) do controller.stub!(:current_user).and_return(stub_model(User)) controller.stub!(:has_account?).and_return(true) controller.stub!(:current_account).and_return( stub_model(UserAccount, :people => stub('people', :find => stub_model(Person) ) ) ) end If you wrap self.people.find in self.find_person in Account (which fixes the Law of Demeter violation), like this: def some_action @user = self.current_user @account = self.current_account if self.has_account? @person = @account.find_person(params[:person]) end ... you can reduce the before to this: before(:each) do controller.stub!(:current_user).and_return(stub_model(User)) controller.stub!(:has_account?).and_return(true) controller.stub!(:current_account).and_return( stub_model(UserAccount, :find_person => stub_model(Person) ) ) end In cases like current_user, you don't really need to stub that because the controller will just return nil. If has_account? actually checks for current_account.nil?, then you don't have to stub that either. Now you just have this: before(:each) do controller.stub!(:current_account).and_return( stub_model(UserAccount, :find_person => stub_model(Person) ) ) end This is a *bit* more organized, but still quite busy. In the end, when you're dealing with code that violates Tell, Don't Ask (which is quite natural in Rails controllers), you have to stub a lot of stuff to get the isolation you want. It's a tradeoff. HTH, David From mileshosky at hotmail.com Sun Jun 29 12:18:40 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sun, 29 Jun 2008 09:18:40 -0700 Subject: [rspec-users] Stopping example execution? In-Reply-To: <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> Message-ID: ---------------------------------------- > From: dchelimsky at gmail.com > To: rspec-users at rubyforge.org > Date: Sun, 29 Jun 2008 06:09:47 -0500 > Subject: Re: [rspec-users] Stopping example execution? > > On Jun 28, 2008, at 7:27 PM, Britt Mileshosky wrote: > >> ---------------------------------------- >>> Date: Sat, 28 Jun 2008 18:24:17 -0500 >>> From: philodespotos at gmail.com >>> To: rspec-users at rubyforge.org >>> Subject: Re: [rspec-users] Stopping example execution? >>> >>> On Sat, Jun 28, 2008 at 5:57 PM, Britt Mileshosky >>> wrote: >>>> >>>> Hello, I'm wondering If I am missing something here when creating >>>> an example that sets an expecation at the top or beginning of an >>>> action but requires you to stub / mock everything that follows. >>>> >>>> Example: >>>> I want to test that a certain controller is running a >>>> before_filter...thats easy: >>>> >>>> - controller.should_receive(:require_user) >>>> - do_get >>>> >>>> But now i've got to mock / stub everything else that comes behind >>>> this filter so that I don't receive 'unexpected method' errors, or >>>> other blowups because I am requesting the whole action. Is there >>>> anyway to stop execution after an expectation has been met? It >>>> seems to me that this might clean things up a bit. Not sure, I'm >>>> still fairly new to BDD/Mocking by about 2 weeks. >>> >>> Yep, you can stub out the requested action on the controller. Say >>> you're testing that the :index action requires authentication: >>> >>> controller.should_not_receive(:index) >>> stub_not_logged_in >>> do_get >>> >>> Or the opposite: >>> >>> controller.should_receive(:index) >>> stub_logged_in >>> do_get >>> >>> Personally I prefer expecting the action instead of expecting the >>> filters, but I think both would accomplish the same goal, as long as >>> you tested the filter on its own. If you just wanted to stub out the >>> action to prevent it from doing anything, you could of course just >>> use >>> controller.stub!(:index). >>> >>> HTH >>> >>> k >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> So i did something like. >> >> - controller.should_receive(:before_filter_action) >> - controller.stub!(:action_after_filter) >> - do_get >> >> Works nicely... but if you think about it and look closely, we are >> still stubbing methods after the intended expectation was met. This >> method just happens to encapsulate a whole other set of methods, >> which is why it works nicely. >> >> But lets say i have something like this >> >> --------------------------------------------------------------------------------------------------- >> >> def some_action >> @user = self.current_user >> @account = self.current_account if self.has_account? >> @person = @account.people.find(params[:person]) >> end >> >> --------------------------------------------------------------------------------------------------- >> >> describe "with a logged in user" >> >> before(:each) do >> controller.stub!(:current_account) >> @account = stub_model(UserAccount) # Shouldn't have to stub here? >> @person = stub_model(User) # Shouldn't have to stub >> here? >> @people = mock("list of people") # Shouldn't have to stub >> here? >> @people.stub!(find) # Shouldn't have >> to stub here? >> @account.stub!(:people).and_return(@people) # Shouldn't >> have to stub here? >> end >> >> it "should find current user" do >> controller.should_receive(:current_user).and_return(@mockUser) >> do_get >> end >> >> describe "who has an account" do >> ... should put account stubbing here with examples >> >> >> describe "which has people" do >> ... should put people stubbing here with examples >> end >> >> describe "which has 0 people" do >> ... >> end >> >> >> end >> >> describe "who doesnt have an account" do >> ... >> end >> >> end >> >> ------------------------------------------------------------------------------------------------------------------------------ >> >> Notice I have to stub everything out at the first before(:each) >> declaration because my "should find current user" example will blow >> up because of unexpected methods after the expectation. All I want >> to know is that the current user is expected to be found and stop. >> My examples LATER should define stubs and expectations. >> >> I'd like something like >> >> - >> controller >> .should_receive(:current_user).and_return(@mockUser).end_example >> >> Am i going about it all wrong? Is there something I'm missing or >> does this just seem natural... > > > You're doing the right thing by handling the stubs before(:each) - > that's what it's therefore - to set up the environment so things will > run. > > I would recommend avoiding instance variable assignment there, > however. If you need a variable, create it directly in the example. > This is something that I've only recently started doing and I find > that it keeps things much more clear. > > There are a few things you can do to tidy up the stubs a bit. You > could organize things differently to express the relationships better: > > before(:each) do > controller.stub!(:current_user).and_return(stub_model(User)) > controller.stub!(:has_account?).and_return(true) > controller.stub!(:current_account).and_return( > stub_model(UserAccount, > :people => stub('people', > :find => stub_model(Person) > ) > ) > ) > end > > If you wrap self.people.find in self.find_person in Account (which > fixes the Law of Demeter violation), like this: > > def some_action > @user = self.current_user > @account = self.current_account if self.has_account? > @person = @account.find_person(params[:person]) > end > > ... you can reduce the before to this: > > before(:each) do > controller.stub!(:current_user).and_return(stub_model(User)) > controller.stub!(:has_account?).and_return(true) > controller.stub!(:current_account).and_return( > stub_model(UserAccount, > :find_person => stub_model(Person) > ) > ) > end > > In cases like current_user, you don't really need to stub that because > the controller will just return nil. > > If has_account? actually checks for current_account.nil?, then you > don't have to stub that either. Now you just have this: > > before(:each) do > controller.stub!(:current_account).and_return( > stub_model(UserAccount, > :find_person => stub_model(Person) > ) > ) > end > > This is a *bit* more organized, but still quite busy. In the end, when > you're dealing with code that violates Tell, Don't Ask (which is quite > natural in Rails controllers), you have to stub a lot of stuff to get > the isolation you want. It's a tradeoff. > > HTH, > David Thank you David, that helps quite a bit, I will adapt these principles and move on. However, do you see where something like a return statement or end example statement could be beneficial? If you are working from the top down with your controller action execution, then you only need to test your expectation and then bail out of your action. No need to further test or meet requirements on anything else in that action because your single test has been met. - in my example for making sure I find a user, I'd like to end execution once I DID find the user, i shouldn't have to satisfy requirements about finding an account and a person... I'll write those expectations later in another nested describe group, as you can see here, in a top down process PeopleController with a logged in user - should find user PeopleController with a logged in user who has an account - should find account PeopleController with a logged in user who doesnt have an account - shouldn't find account - should redirect ... PeopleController with a logged in user who has an account the person belongs to - should find person - should assign person for the view PeopleController with a logged in user who has an account the requested person does not belong to - should not find person - should ... _________________________________________________________________ The i?m Talkathon starts 6/24/08.? For now, give amongst yourselves. http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst From dchelimsky at gmail.com Sun Jun 29 12:20:46 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jun 2008 11:20:46 -0500 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> Message-ID: On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: > However, do you see where something like a return statement or end > example statement could be beneficial? > If you are working from the top down with your controller action > execution, then you only need to test your expectation > and then bail out of your action. No need to further test or meet > requirements on anything else in that action because your > single test has been met. > > - in my example for making sure I find a user, I'd like to end > execution once I DID find the user, i shouldn't have to satisfy > requirements about finding an account and a person... I'll write > those expectations later in another nested describe group, as you > can see here, in a top down process > > PeopleController with a logged in user > - should find user > > PeopleController with a logged in user who has an account > - should find account > > PeopleController with a logged in user who doesnt have an account > - shouldn't find account > - should redirect ... > > PeopleController with a logged in user who has an account the person > belongs to > - should find person > - should assign person for the view > > PeopleController with a logged in user who has an account the > requested person does not belong to > - should not find person > - should ... My instinct about this is that it would encourage long methods because it would make it less painful to test them, so I would be adverse to anything that let's you short circuit the method. Anybody else have opinions on that? From mileshosky at hotmail.com Sun Jun 29 12:38:42 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Sun, 29 Jun 2008 09:38:42 -0700 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> Message-ID: ---------------------------------------- > From: dchelimsky at gmail.com > To: rspec-users at rubyforge.org > Date: Sun, 29 Jun 2008 11:20:46 -0500 > Subject: Re: [rspec-users] Stopping example execution? > > On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: >> However, do you see where something like a return statement or end >> example statement could be beneficial? >> If you are working from the top down with your controller action >> execution, then you only need to test your expectation >> and then bail out of your action. No need to further test or meet >> requirements on anything else in that action because your >> single test has been met. >> >> - in my example for making sure I find a user, I'd like to end >> execution once I DID find the user, i shouldn't have to satisfy >> requirements about finding an account and a person... I'll write >> those expectations later in another nested describe group, as you >> can see here, in a top down process >> >> PeopleController with a logged in user >> - should find user >> >> PeopleController with a logged in user who has an account >> - should find account >> >> PeopleController with a logged in user who doesnt have an account >> - shouldn't find account >> - should redirect ... >> >> PeopleController with a logged in user who has an account the person >> belongs to >> - should find person >> - should assign person for the view >> >> PeopleController with a logged in user who has an account the >> requested person does not belong to >> - should not find person >> - should ... > > My instinct about this is that it would encourage long methods because > it would make it less painful to test them, so I would be adverse to > anything that let's you short circuit the method. > > Anybody else have opinions on that? > I understand your point, but should a testing framework be worried too much about how a user will be writing their application code? Leave it to the programmer to decide what logic they put in the controller, let the testing framework make it easy to test that certain conditions are met, no matter how those conditions are presented in the application. This short-circuting can be completely optional... it would just be nice to have it there if needed. In the end I honestly can see a more natural process to testing methods bit by bit, building up examples and stubs in their respective describe groups as needed. If someone wants to single describe group and all stubs at the top, so be it. I'd like mine to be incrementally built upon each other. I'll be quiet now and let others discuss, (...I'm cheering for this though!) _________________________________________________________________ Need to know now? Get instant answers with Windows Live Messenger. http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008 From dchelimsky at gmail.com Sun Jun 29 12:59:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jun 2008 11:59:57 -0500 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> Message-ID: On Jun 29, 2008, at 11:38 AM, Britt Mileshosky wrote: > ---------------------------------------- >> From: dchelimsky at gmail.com >> To: rspec-users at rubyforge.org >> Date: Sun, 29 Jun 2008 11:20:46 -0500 >> Subject: Re: [rspec-users] Stopping example execution? >> >> On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: >>> However, do you see where something like a return statement or end >>> example statement could be beneficial? >>> If you are working from the top down with your controller action >>> execution, then you only need to test your expectation >>> and then bail out of your action. No need to further test or meet >>> requirements on anything else in that action because your >>> single test has been met. >>> >> My instinct about this is that it would encourage long methods >> because >> it would make it less painful to test them, so I would be adverse to >> anything that let's you short circuit the method. >> >> Anybody else have opinions on that? >> > > I understand your point, but should a testing framework be worried > too much about how a user will be writing their application code? YES. This is Ruby, my friend, land of opinionated software. The whole point of RSpec is to encourage good practices. Long Methods (any method does more than one thing) are a known Code Smell. If you want to write them, it should be painful. You're certainly entitled to a different opinion, and you can express that opinion in a gem that extends rspec to do what you want! If you do that and enough people use it and it proves generally useful and pain-free, I'd be glad to peek at it again. Cheers, David > > Leave it to the programmer to decide what logic they put in the > controller, let the testing framework make it easy to test > that certain conditions are met, no matter how those conditions are > presented in the application. > > This short-circuting can be completely optional... it would just be > nice to have it there if needed. In the end I honestly can see a more > natural process to testing methods bit by bit, building up examples > and stubs in their respective describe groups as needed. If someone > wants to single describe group and all stubs at the top, so be it. > I'd like mine to be incrementally built upon each other. > > I'll be quiet now and let others discuss, (...I'm cheering for this > though!) > > _________________________________________________________________ > Need to know now? Get instant answers with Windows Live Messenger. > http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From raasdnil at gmail.com Sun Jun 29 22:38:37 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Mon, 30 Jun 2008 12:38:37 +1000 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> Message-ID: <57a815bf0806291938r6f43742cu2523ab1098b1169a@mail.gmail.com> On Mon, Jun 30, 2008 at 2:59 AM, David Chelimsky wrote: > On Jun 29, 2008, at 11:38 AM, Britt Mileshosky wrote: >>> My instinct about this is that it would encourage long methods because >>> it would make it less painful to test them, so I would be adverse to >>> anything that let's you short circuit the method. >>> >>> Anybody else have opinions on that? I agree with you here David. The long method syndrome is so easy to fall into in ruby and rails especially. Many times I have shown some of my team mates that coding small methods makes specing a lot easier and containable. Another way to go about this testing is to treat the controller method as a public interface and only spec the 'end result' behaviour with a given set of inputs using real objects (which has limits, but works in most cases). Britt, have a look at http://lindsaar.net/2008/6/30/examples-of-behaviour-spec-n to see what I mean. Doesn't totally solve the problem you are hitting now, but provides you with another way to go about it (albeit a bit slower in spec execution time) -- http://lindsaar.net/ Rails, RSpec, Puppet and Life blog.... From zach.dennis at gmail.com Mon Jun 30 13:57:53 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 30 Jun 2008 13:57:53 -0400 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> Message-ID: <85d99afe0806301057h3a09d9f4q970677c9d3ae056f@mail.gmail.com> On Sun, Jun 29, 2008 at 12:20 PM, David Chelimsky wrote: > On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: > >> However, do you see where something like a return statement or end example >> statement could be beneficial? >> If you are working from the top down with your controller action >> execution, then you only need to test your expectation >> and then bail out of your action. No need to further test or meet >> requirements on anything else in that action because your >> single test has been met. >> >> - in my example for making sure I find a user, I'd like to end execution >> once I DID find the user, i shouldn't have to satisfy >> requirements about finding an account and a person... I'll write those >> expectations later in another nested describe group, as you >> can see here, in a top down process >> >> PeopleController with a logged in user >> - should find user >> >> PeopleController with a logged in user who has an account >> - should find account >> >> PeopleController with a logged in user who doesnt have an account >> - shouldn't find account >> - should redirect ... >> >> PeopleController with a logged in user who has an account the person >> belongs to >> - should find person >> - should assign person for the view >> >> PeopleController with a logged in user who has an account the requested >> person does not belong to >> - should not find person >> - should ... >> > > My instinct about this is that it would encourage long methods because it > would make it less painful to test them, so I would be adverse to anything > that let's you short circuit the method. > > Anybody else have opinions on that? I'm just catching up on email now after being sick for the past six days, but health aside my opinion is that I agree with David's opinion. Rather than focusing on how-to write easier tests that complain less, start focusing on how-to write the right tests that complain when necessary. One of the benefits associated with feeling the pain of a test is that it may be a sign to re-assess and refactor your code. This usually happens early enough that it only takes a few minutes. Short circuiting essentially gives you the ability to not feel the pain. Its like CIPA [0], but for code. I would fear that the code would get so bad that by the time the test cried with pain your code was already beyond easy repair and instead required invasive surgery. Tests are part of the nervous system of your application. When they hurt, they're telling you something isn't right and that it should be addressed, 0 - http://en.wikipedia.org/wiki/Congenital_insensitivity_to_pain_with_anhidrosis -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mileshosky at hotmail.com Mon Jun 30 18:11:44 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Mon, 30 Jun 2008 15:11:44 -0700 Subject: [rspec-users] Stopping Example Execution? Message-ID: n Sun, Jun 29, 2008 at 12:20 PM, David Chelimsky wrote: On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: However, do you see where something like a return statement or end example statement could be beneficial? If you are working from the top down with your controller action execution, then you only need to test your expectation and then bail out of your action. No need to further test or meet requirements on anything else in that action because your single test has been met. - in my example for making sure I find a user, I'd like to end execution once I DID find the user, i shouldn't have to satisfy requirements about finding an account and a person... I'll write those expectations later in another nested describe group, as you can see here, in a top down process PeopleController with a logged in user - should find user PeopleController with a logged in user who has an account - should find account PeopleController with a logged in user who doesnt have an account - shouldn't find account - should redirect ... PeopleController with a logged in user who has an account the person belongs to - should find person - should assign person for the view PeopleController with a logged in user who has an account the requested person does not belong to - should not find person - should ... My instinct about this is that it would encourage long methods because it would make it less painful to test them, so I would be adverse to anything that let's you short circuit the method. Anybody else have opinions on that? I'm just catching up on email now after being sick for the past six days, but health aside my opinion is that I agree with David's opinion. Rather than focusing on how-to write easier tests that complain less, start focusing on how-to write the right tests that complain when necessary. One of the benefits associated with feeling the pain of a test is that it may be a sign to re-assess and refactor your code. This usually happens early enough that it only takes a few minutes. Short circuiting essentially gives you the ability to not feel the pain. Its like CIPA [0], but for code. I would fear that the code would get so bad that by the time the test cried with pain your code was already beyond easy repair and instead required invasive surgery. Tests are part of the nervous system of your application. When they hurt, they're telling you something isn't right and that it should be addressed, I wouldn't really say that anything I have been presenting has been a result of 'pains', more so an observation on how an example group with other example groups can be much more readable for myself and for other developers when they need to read the specs. Stubbing everything at the top doesn't make complete sense. Why not stub inside the example group that has a NICE describe statement telling you what this stubbing is related to. We can't do this because the first examples will blow up due to having to execute all the code. Take the 2 examples: ------------------------------------------------------------------------------------------------------------------------ PeopleController # stub everything way up here at the top where these # definitions are out of context (by means of position) with following examples # # stub controller requirments # stub logged in requirement # stub account requirement # stub no account requirement # stub account owns person # stub account doesn't own person PeopleController with before filters - should require user PeopleController with a logged in user - should find user PeopleController with a logged in user who has an account - should find account PeopleController with a logged in user who doesnt have an account - shouldn't find account - should redirect ... PeopleController with a logged in user who has an account the person belongs to - should find person - should assign person for the view PeopleController with a logged in user who has an account the requested person does not belong to - should not find person - should ... ------------------------------------------------------------------------------------------------------------------------ PeopleController # stub the minimum needed to get to the first example group up and running PeopleController with before filters - should require user PeopleController with a logged in user # stub logged in requirement - should find user PeopleController with a logged in user who has an account # stub account requirement - should find account PeopleController with a logged in user who doesnt have an account # stub no account requirement - shouldn't find account - should redirect ... PeopleController with a logged in user who has an account the person belongs to # stub account owns person - should find person - should assign person for the view PeopleController with a logged in user who has an account the requested person does not belong to # stub account doesn't own person - should not find person - should ... ------------------------------------------------------------------------------------------------------------------------ I prefer the second group, but unfortunately I am not able to write my specs in this organized fashion. Just sayin. Britt _________________________________________________________________ Need to know now? Get instant answers with Windows Live Messenger. http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008 From eagerwombat at gmail.com Mon Jun 30 18:51:04 2008 From: eagerwombat at gmail.com (john) Date: Mon, 30 Jun 2008 15:51:04 -0700 Subject: [rspec-users] HTTPERF + RSPEC + BONG = euphoric development Message-ID: <5b1b5e890806301551m7339cd53p89be54f082c44f2@mail.gmail.com> My coworker and I just discovered http://github.com/topfunky/bong/tree/master/lib/bong.rb It's a kool script written by topfunky himself that wraps httperf in ruby. It formats the input URLs and the results and yaml (so nice). Any thoughts on how to implement this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benmabey.com Mon Jun 30 18:55:23 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 30 Jun 2008 16:55:23 -0600 Subject: [rspec-users] HTTPERF + RSPEC + BONG = euphoric development In-Reply-To: <5b1b5e890806301551m7339cd53p89be54f082c44f2@mail.gmail.com> References: <5b1b5e890806301551m7339cd53p89be54f082c44f2@mail.gmail.com> Message-ID: <4869645B.20003@benmabey.com> john wrote: > My coworker and I just discovered > http://github.com/topfunky/bong/tree/master/lib/bong.rb > It's a kool script written by topfunky himself that wraps httperf in > ruby. > It formats the input URLs and the results and yaml (so nice). > > > > Any thoughts on how to implement this? > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Sorry.. what is your question? I may just be braindead today.. but what do you want to implement? -Ben From matt at matt-darby.com Mon Jun 30 22:04:38 2008 From: matt at matt-darby.com (Matt Darby) Date: Mon, 30 Jun 2008 22:04:38 -0400 Subject: [rspec-users] Odd Date-based spec failing Message-ID: Hrm. I have a spec for a model 'Phase'. a Phase has a start and end date, and a method 'percentage_complete' that calculates the percentage of time that has already elapsed between said start and end dates. This spec passes as expected: module PhaseHelper def valid_attributes { :start_date => Date.today - 5.days, :end_date => Date.tomorrow } end end describe Phase do include PhaseHelper before(:each) do @phase = Phase.new(valid_attributes) end it "should know how to generate the percentage_complete attribute" do @phase.percentage_complete.should == 83 end However, when I run 'rake spec:models', the spec fails: 'Phase should know how to generate the percentage_complete attribute' FAILED expected: 83, got: 100 (using ==) RSpec and rspec_on_rails are current from GitHub (RSpec gem has been reinstalled from source) From xtrmclmb at gmail.com Mon Jun 30 22:40:39 2008 From: xtrmclmb at gmail.com (Camilo Torres) Date: Tue, 1 Jul 2008 22:10:39 +1930 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: References: Message-ID: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> It seems your Phase.percentage_complete is not working as you expect. It clearly returns 100 when you are specting 83. The test clearly said that. ?What is the implementation of your percentage_complete method? 2008/7/1 Matt Darby : > Hrm. > > I have a spec for a model 'Phase'. a Phase has a start and end date, and a > method 'percentage_complete' that calculates the percentage of time that has > already elapsed between said start and end dates. > > This spec passes as expected: > > module PhaseHelper > def valid_attributes > { > :start_date => Date.today - 5.days, > :end_date => Date.tomorrow > } > end > end > > describe Phase do > > include PhaseHelper > > before(:each) do > @phase = Phase.new(valid_attributes) > end > > it "should know how to generate the percentage_complete attribute" do > @phase.percentage_complete.should == 83 > end > > > > However, when I run 'rake spec:models', the spec fails: > > 'Phase should know how to generate the percentage_complete attribute' FAILED > expected: 83, > got: 100 (using ==) > > > RSpec and rspec_on_rails are current from GitHub (RSpec gem has been > reinstalled from source) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at matt-darby.com Mon Jun 30 22:43:33 2008 From: matt at matt-darby.com (Matt Darby) Date: Mon, 30 Jun 2008 22:43:33 -0400 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> Message-ID: On Jul 1, 2008, at 10:10 PM, Camilo Torres wrote: > It seems your Phase.percentage_complete is not working as you expect. > It clearly returns 100 when you are specting 83. The test clearly said > that. > > ?What is the implementation of your percentage_complete method? It only fails when run via 'rake spec:models'; otherwise, it passes. def percentage_complete # Returns an integer representation of a percentage (i.e. '78') return 100 if Date.today >= self.end_date length_in_days = (self.end_date - self.start_date).to_f days_into_phase = (Date.today - self.start_date).to_f ((days_into_phase / length_in_days) * 100.0).round end