From dbatshaw at gmail.com Thu Apr 1 02:30:14 2010 From: dbatshaw at gmail.com (drewB) Date: Wed, 31 Mar 2010 23:30:14 -0700 (PDT) Subject: [rspec-users] matcher for bad request Message-ID: <77fdb147-7eef-46c9-9120-640d63e14e43@y14g2000yqm.googlegroups.com> Is there a built-in matcher for a response returning a bad request (e.g. header code in the 400s)? For example, "response.should be_bad_request". From dchelimsky at gmail.com Thu Apr 1 02:37:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Apr 2010 01:37:05 -0500 Subject: [rspec-users] matcher for bad request In-Reply-To: <77fdb147-7eef-46c9-9120-640d63e14e43@y14g2000yqm.googlegroups.com> References: <77fdb147-7eef-46c9-9120-640d63e14e43@y14g2000yqm.googlegroups.com> Message-ID: <22AD56E6-8EC2-4617-8F5B-EAB022E376A7@gmail.com> On Apr 1, 2010, at 1:30 AM, drewB wrote: > Is there a built-in matcher for a response returning a bad request > (e.g. header code in the 400s)? For example, "response.should > be_bad_request". No, but its dead simple to write your own: Spec::Matchers.define :be_bad_request do match do |response| response.code.to_s =~ /^4/ end end From dchelimsky at gmail.com Thu Apr 1 08:57:16 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Apr 2010 06:57:16 -0600 Subject: [rspec-users] subject in the before block? In-Reply-To: References: <64174ba2-546f-48db-a930-267714d8428f@20g2000vbr.googlegroups.com> <6F651928-BCA0-43F8-97A1-5C1003877A4D@gmail.com> Message-ID: Looks like a bug. Wanna file a report? This is rspec-1, so http://rspec.lighthouseapp.com is fine. Thx On Wed, Mar 31, 2010 at 9:51 PM, Brian Cardarella wrote: > RSpec 1 and before :each > > On Mar 31, 5:33?pm, David Chelimsky wrote: >> On Mar 31, 2010, at 3:54 PM, Brian Cardarella wrote: >> >> > Is there a reason why I cannot access the subject in the before block? >> > It seems to me that anything that I have access to in the it blocks >> > should also be accessible in the before block. >> >> No reason. You using rspec 1 or 2? Also, before(:each) or before(:all)? >> _______________________________________________ >> 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 bcardarella at gmail.com Thu Apr 1 10:56:52 2010 From: bcardarella at gmail.com (Brian Cardarella) Date: Thu, 1 Apr 2010 07:56:52 -0700 (PDT) Subject: [rspec-users] subject in the before block? In-Reply-To: References: <64174ba2-546f-48db-a930-267714d8428f@20g2000vbr.googlegroups.com> <6F651928-BCA0-43F8-97A1-5C1003877A4D@gmail.com> Message-ID: <15e8dc51-a385-4c32-822b-f4756991d30e@o24g2000vbo.googlegroups.com> So I did some deeper investigation and it seems that it actually is not an issue with the before block but with 'its' I have an example here: http://github.com/bcardarella/thingy subject is updated in the before block and that update is reflected in 'it' but not in 'its' I also opened a Lighthouse ticket for this - Brian On Apr 1, 8:57?am, David Chelimsky wrote: > Looks like a bug. Wanna file a report? This is rspec-1, sohttp://rspec.lighthouseapp.comis fine. > > Thx > > > > > > On Wed, Mar 31, 2010 at 9:51 PM, Brian Cardarella wrote: > > RSpec 1 and before :each > > > On Mar 31, 5:33?pm, David Chelimsky wrote: > >> On Mar 31, 2010, at 3:54 PM, Brian Cardarella wrote: > > >> > Is there a reason why I cannot access the subject in the before block? > >> > It seems to me that anything that I have access to in the it blocks > >> > should also be accessible in the before block. > > >> No reason. You using rspec 1 or 2? Also, before(:each) or before(:all)? > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Apr 1 11:01:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Apr 2010 10:01:10 -0500 Subject: [rspec-users] subject in the before block? In-Reply-To: <15e8dc51-a385-4c32-822b-f4756991d30e@o24g2000vbo.googlegroups.com> References: <64174ba2-546f-48db-a930-267714d8428f@20g2000vbr.googlegroups.com> <6F651928-BCA0-43F8-97A1-5C1003877A4D@gmail.com> <15e8dc51-a385-4c32-822b-f4756991d30e@o24g2000vbo.googlegroups.com> Message-ID: On Apr 1, 2010, at 9:56 AM, Brian Cardarella wrote: > So I did some deeper investigation and it seems that it actually is > not an issue with the before block but with 'its' > > I have an example here: > > http://github.com/bcardarella/thingy > > subject is updated in the before block and that update is reflected in > 'it' but not in 'its' > > I also opened a Lighthouse ticket for this Cool. Thanks. > > - Brian > > > On Apr 1, 8:57 am, David Chelimsky wrote: >> Looks like a bug. Wanna file a report? This is rspec-1, sohttp://rspec.lighthouseapp.comis fine. >> >> Thx >> >> >> >> >> >> On Wed, Mar 31, 2010 at 9:51 PM, Brian Cardarella wrote: >>> RSpec 1 and before :each >> >>> On Mar 31, 5:33 pm, David Chelimsky wrote: >>>> On Mar 31, 2010, at 3:54 PM, Brian Cardarella wrote: >> >>>>> Is there a reason why I cannot access the subject in the before block? >>>>> It seems to me that anything that I have access to in the it blocks >>>>> should also be accessible in the before block. >> >>>> No reason. You using rspec 1 or 2? Also, before(:each) or before(:all)? >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From edgargonzalez at gmail.com Thu Apr 1 11:27:22 2010 From: edgargonzalez at gmail.com (Edgar Gonzalez) Date: Thu, 1 Apr 2010 10:57:22 -0430 Subject: [rspec-users] Broken pipe error in progress_bar_formatter when autotest detects changes and try to run the specs again Message-ID: Hi, I have a Broken pipe error in progress_bar_formatter when autotest detects changes and try to run the specs again: 508 $ autospec loading autotest/rspec /usr/bin/ruby1.8 /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec --autospec /home/edgar/sandboxes/buzz/models/spec/domain_spec.rb /home/edgar/sandboxes/buzz/models/spec/base_spec.rb -O spec/spec.opts ............. Finished in 0.02858 seconds 13 examples, 0 failures /usr/bin/ruby1.8 /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec --autospec /home/edgar/sandboxes/buzz/models/spec/base_spec.rb -O spec/spec.opts /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/formatter/progress_bar_formatter.rb:17:in `flush': Broken pipe (Errno::EPIPE) from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/formatter/progress_bar_formatter.rb:17:in `example_passed' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `example_passed' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `each' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:136:in `example_passed' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/reporter.rb:31:in `example_finished' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:55:in `execute' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:214:in `run_examples' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `each' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `run_examples' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:103:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:23:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `each' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:152:in `run_examples' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run' from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:5 Interrupt a second time to quit I guess it is related to ruby 1.8 vs 1.9 issue, like this http://rubyforge.org/tracker/index.php?func=detail&aid=28034&group_id=419&atid=1678 My environment: ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux] rubygem 1.3.6 rspec (1.3.0, 1.2.9, 1.2.4, 1.1.12, 1.1.4) rspec-rails (1.3.2, 1.2.9, 1.2.4, 1.1.12) ZenTest (4.3.1) autotest-rails (4.1.0) any clue about it? Thanks -- Edgar Gonz?lez Gonz?lez E-mail: edgargonzalez at gmail.com http://twitter.com/edgar http://www.hasmanydevelopers.com http://edgar.gonzalez.net.ve -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From dbatshaw at gmail.com Thu Apr 1 14:03:42 2010 From: dbatshaw at gmail.com (drewB) Date: Thu, 1 Apr 2010 11:03:42 -0700 (PDT) Subject: [rspec-users] matcher for bad request In-Reply-To: <22AD56E6-8EC2-4617-8F5B-EAB022E376A7@gmail.com> References: <77fdb147-7eef-46c9-9120-640d63e14e43@y14g2000yqm.googlegroups.com> <22AD56E6-8EC2-4617-8F5B-EAB022E376A7@gmail.com> Message-ID: <75f65442-b807-4fad-aed7-34fafeac8ac9@o24g2000vbo.googlegroups.com> Thanks! On Mar 31, 11:37?pm, David Chelimsky wrote: > On Apr 1, 2010, at 1:30 AM, drewB wrote: > > > Is there a built-in matcher for a response returning a bad request > > (e.g. header code in the 400s)? ?For example, "response.should > > be_bad_request". > > No, but its dead simple to write your own: > > Spec::Matchers.define :be_bad_request do > ? match do |response| > ? ? response.code.to_s =~ /^4/ > ? end > end > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dbatshaw at gmail.com Thu Apr 1 16:14:08 2010 From: dbatshaw at gmail.com (drewB) Date: Thu, 1 Apr 2010 13:14:08 -0700 (PDT) Subject: [rspec-users] setting partial stub for just one value and letting obj handle the rest Message-ID: <93778c0b-bc8c-4073-bc05-d5543cee9a20@u32g2000vbc.googlegroups.com> Occasionally, I find myself in a situation where I want to have a mock obj returned if a method is called with a particular argument but handled normally otherwise. For example, lets say I have a Model named User and I am specing a controller that sends messages from one user to another. When User.find is called for the user who is making the request I want it to run normally but when User.find is called for the receiver I want it to return a mocked obj. In this case, I can do something like (http://gist.github.com/352305): user = mock_model(User) User.stub!(:find).at_least(1).and_return do |id| if id == mock_user.id.to_s user else User.find_by_id(id) end end If I didn't have another method that allowed me to find a User by it's id this won't work. Is there an easier way to accomplish this? From dchelimsky at gmail.com Thu Apr 1 16:35:34 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Apr 2010 15:35:34 -0500 Subject: [rspec-users] setting partial stub for just one value and letting obj handle the rest In-Reply-To: <93778c0b-bc8c-4073-bc05-d5543cee9a20@u32g2000vbc.googlegroups.com> References: <93778c0b-bc8c-4073-bc05-d5543cee9a20@u32g2000vbc.googlegroups.com> Message-ID: <492DDE02-102C-4182-8009-F18CC8379F38@gmail.com> On Apr 1, 2010, at 3:14 PM, drewB wrote: > Occasionally, I find myself in a situation where I want to have a mock > obj returned if a method is called with a particular argument but > handled normally otherwise. For example, lets say I have a Model > named User and I am specing a controller that sends messages from one > user to another. When User.find is called for the user who is making > the request I want it to run normally but when User.find is called for > the receiver I want it to return a mocked obj. In this case, I can do > something like (http://gist.github.com/352305): > > user = mock_model(User) > User.stub!(:find).at_least(1).and_return do |id| > if id == mock_user.id.to_s > user > else > User.find_by_id(id) > end > end > > If I didn't have another method that allowed me to find a User by it's > id this won't work. > > Is there an easier way to accomplish this? Not really. When you stub a method, the framework overrides that method with its own implementation. There's no mechanism in place to say "pass the message onto the real object if it doesn't have the arguments I'm interested in." I'm not sure of any framework that does that. Maybe RR, but I'm not sure. Good luck. David From matt at mattwynne.net Thu Apr 1 16:45:36 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 1 Apr 2010 21:45:36 +0100 Subject: [rspec-users] setting partial stub for just one value and letting obj handle the rest In-Reply-To: <492DDE02-102C-4182-8009-F18CC8379F38@gmail.com> References: <93778c0b-bc8c-4073-bc05-d5543cee9a20@u32g2000vbc.googlegroups.com> <492DDE02-102C-4182-8009-F18CC8379F38@gmail.com> Message-ID: <821FD210-48A1-43D2-8381-5EC8B04EE384@mattwynne.net> On 1 Apr 2010, at 21:35, David Chelimsky wrote: > On Apr 1, 2010, at 3:14 PM, drewB wrote: > >> Occasionally, I find myself in a situation where I want to have a >> mock >> obj returned if a method is called with a particular argument but >> handled normally otherwise. For example, lets say I have a Model >> named User and I am specing a controller that sends messages from one >> user to another. When User.find is called for the user who is making >> the request I want it to run normally but when User.find is called >> for >> the receiver I want it to return a mocked obj. In this case, I can >> do >> something like (http://gist.github.com/352305): >> >> user = mock_model(User) >> User.stub!(:find).at_least(1).and_return do |id| >> if id == mock_user.id.to_s >> user >> else >> User.find_by_id(id) >> end >> end >> >> If I didn't have another method that allowed me to find a User by >> it's >> id this won't work. >> >> Is there an easier way to accomplish this? > > Not really. When you stub a method, the framework overrides that > method with its own implementation. There's no mechanism in place to > say "pass the message onto the real object if it doesn't have the > arguments I'm interested in." I'm not sure of any framework that > does that. Maybe RR, but I'm not sure. > > Good luck. > David I can't help but chime in here that I would be pretty irritated to come across a test that mixed up using mocks and real objects, especially when they're the same class. Can you not use a mock for the other instance of User too? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From mattvanhorn at gmail.com Thu Apr 1 17:23:46 2010 From: mattvanhorn at gmail.com (Matthew Van Horn) Date: Thu, 1 Apr 2010 17:23:46 -0400 Subject: [rspec-users] rspec and resque - tips? Message-ID: <1B0EDD80-71E7-4729-8E59-D6D193EEC0A6@gmail.com> I've just gotten started refactoring my app to use Resque/Redis to do things like email and order capture asynchronously. I'm wondering if anyone has any tips on how to test my job classes, and how to run integration tests for this kind of thing. BTW - we're a very small group, and the tests are mostly just for me, so my integration is all webrat w/ rspec, not cucumber. Thanks, Matt Van Horn From dbatshaw at gmail.com Thu Apr 1 18:12:01 2010 From: dbatshaw at gmail.com (drewB) Date: Thu, 1 Apr 2010 15:12:01 -0700 (PDT) Subject: [rspec-users] setting partial stub for just one value and letting obj handle the rest In-Reply-To: <821FD210-48A1-43D2-8381-5EC8B04EE384@mattwynne.net> References: <93778c0b-bc8c-4073-bc05-d5543cee9a20@u32g2000vbc.googlegroups.com> <492DDE02-102C-4182-8009-F18CC8379F38@gmail.com> <821FD210-48A1-43D2-8381-5EC8B04EE384@mattwynne.net> Message-ID: <3dab8694-3c77-40a1-9841-5ef001090904@e21g2000vbb.googlegroups.com> David, thanks for your response. Matt, I totally hear you. In this contrived example, you probably could but in the project I am working on it would be very difficult. One of the challenges of joining a project already in progress... On Apr 1, 1:45?pm, Matt Wynne wrote: > On 1 Apr 2010, at 21:35, David Chelimsky wrote: > > > > > On Apr 1, 2010, at 3:14 PM, drewB wrote: > > >> Occasionally, I find myself in a situation where I want to have a ? > >> mock > >> obj returned if a method is called with a particular argument but > >> handled normally otherwise. ?For example, lets say I have a Model > >> named User and I am specing a controller that sends messages from one > >> user to another. ?When User.find is called for the user who is making > >> the request I want it to run normally but when User.find is called ? > >> for > >> the receiver I want it to return a mocked obj. ?In this case, I can ? > >> do > >> something like (http://gist.github.com/352305): > > >> user = mock_model(User) > >> User.stub!(:find).at_least(1).and_return do |id| > >> ? if id == mock_user.id.to_s > >> ? ? user > >> ? else > >> ? ? User.find_by_id(id) > >> ? end > >> end > > >> If I didn't have another method that allowed me to find a User by ? > >> it's > >> id this won't work. > > >> Is there an easier way to accomplish this? > > > Not really. When you stub a method, the framework overrides that ? > > method with its own implementation. There's no mechanism in place to ? > > say "pass the message onto the real object if it doesn't have the ? > > arguments I'm interested in." I'm not sure of any framework that ? > > does that. Maybe RR, but I'm not sure. > > > Good luck. > > David > > I can't help but chime in here that I would be pretty irritated to ? > come across a test that mixed up using mocks and real objects, ? > especially when they're the same class. Can you not use a mock for the ? > other instance of User too? > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dbatshaw at gmail.com Thu Apr 1 18:29:43 2010 From: dbatshaw at gmail.com (drewB) Date: Thu, 1 Apr 2010 15:29:43 -0700 (PDT) Subject: [rspec-users] setting partial stub for just one value and letting obj handle the rest In-Reply-To: <3dab8694-3c77-40a1-9841-5ef001090904@e21g2000vbb.googlegroups.com> References: <93778c0b-bc8c-4073-bc05-d5543cee9a20@u32g2000vbc.googlegroups.com> <492DDE02-102C-4182-8009-F18CC8379F38@gmail.com> <821FD210-48A1-43D2-8381-5EC8B04EE384@mattwynne.net> <3dab8694-3c77-40a1-9841-5ef001090904@e21g2000vbb.googlegroups.com> Message-ID: For anyone who might come across this message looking for a solution to the same problem, I wrote the following function to take care of it (http://gist.github.com/352449) def stub_find_for_specific_values(model, stubs) model.stub!(:find).at_least(1).and_return do |id| if stubs.has_key? id stubs[id] else model.find_by_id(id) end end end #example below will return the mock_user if its id is search for otherwise find will search as normal mock_user = mock_model(User) stub_find_for_specific_values(User, mock_user.id => mock_user) On Apr 1, 3:12?pm, drewB wrote: > David, thanks for your response. > > Matt, I totally hear you. ?In this contrived example, you probably > could but in the project I am working on it would be very difficult. > One of the challenges of joining a project already in progress... > > On Apr 1, 1:45?pm, Matt Wynne wrote: > > > On 1 Apr 2010, at 21:35, David Chelimsky wrote: > > > > On Apr 1, 2010, at 3:14 PM, drewB wrote: > > > >> Occasionally, I find myself in a situation where I want to have a ? > > >> mock > > >> obj returned if a method is called with a particular argument but > > >> handled normally otherwise. ?For example, lets say I have a Model > > >> named User and I am specing a controller that sends messages from one > > >> user to another. ?When User.find is called for the user who is making > > >> the request I want it to run normally but when User.find is called ? > > >> for > > >> the receiver I want it to return a mocked obj. ?In this case, I can ? > > >> do > > >> something like (http://gist.github.com/352305): > > > >> user = mock_model(User) > > >> User.stub!(:find).at_least(1).and_return do |id| > > >> ? if id == mock_user.id.to_s > > >> ? ? user > > >> ? else > > >> ? ? User.find_by_id(id) > > >> ? end > > >> end > > > >> If I didn't have another method that allowed me to find a User by ? > > >> it's > > >> id this won't work. > > > >> Is there an easier way to accomplish this? > > > > Not really. When you stub a method, the framework overrides that ? > > > method with its own implementation. There's no mechanism in place to ? > > > say "pass the message onto the real object if it doesn't have the ? > > > arguments I'm interested in." I'm not sure of any framework that ? > > > does that. Maybe RR, but I'm not sure. > > > > Good luck. > > > David > > > I can't help but chime in here that I would be pretty irritated to ? > > come across a test that mixed up using mocks and real objects, ? > > especially when they're the same class. Can you not use a mock for the ? > > other instance of User too? > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.org > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > cheers, > > Matt > > >http://mattwynne.net > > +447974 430184 > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Thu Apr 1 20:35:50 2010 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 2 Apr 2010 01:35:50 +0100 Subject: [rspec-users] setting partial stub for just one value and letting obj handle the rest In-Reply-To: <3dab8694-3c77-40a1-9841-5ef001090904@e21g2000vbb.googlegroups.com> References: <93778c0b-bc8c-4073-bc05-d5543cee9a20@u32g2000vbc.googlegroups.com> <492DDE02-102C-4182-8009-F18CC8379F38@gmail.com> <821FD210-48A1-43D2-8381-5EC8B04EE384@mattwynne.net> <3dab8694-3c77-40a1-9841-5ef001090904@e21g2000vbb.googlegroups.com> Message-ID: <9D76A549-EAAB-4C5B-8BAE-DF2703827028@mattwynne.net> On 1 Apr 2010, at 23:12, drewB wrote: > David, thanks for your response. > > Matt, I totally hear you. In this contrived example, you probably > could but in the project I am working on it would be very difficult. > One of the challenges of joining a project already in progress... I have felt that pain many times :) This book is a great read when you're working with other people's crap: http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052 > > On Apr 1, 1:45 pm, Matt Wynne wrote: >> On 1 Apr 2010, at 21:35, David Chelimsky wrote: >> >> >> >>> On Apr 1, 2010, at 3:14 PM, drewB wrote: >> >>>> Occasionally, I find myself in a situation where I want to have a >>>> mock >>>> obj returned if a method is called with a particular argument but >>>> handled normally otherwise. For example, lets say I have a Model >>>> named User and I am specing a controller that sends messages from >>>> one >>>> user to another. When User.find is called for the user who is >>>> making >>>> the request I want it to run normally but when User.find is called >>>> for >>>> the receiver I want it to return a mocked obj. In this case, I can >>>> do >>>> something like (http://gist.github.com/352305): >> >>>> user = mock_model(User) >>>> User.stub!(:find).at_least(1).and_return do |id| >>>> if id == mock_user.id.to_s >>>> user >>>> else >>>> User.find_by_id(id) >>>> end >>>> end >> >>>> If I didn't have another method that allowed me to find a User by >>>> it's >>>> id this won't work. >> >>>> Is there an easier way to accomplish this? >> >>> Not really. When you stub a method, the framework overrides that >>> method with its own implementation. There's no mechanism in place to >>> say "pass the message onto the real object if it doesn't have the >>> arguments I'm interested in." I'm not sure of any framework that >>> does that. Maybe RR, but I'm not sure. >> >>> Good luck. >>> David >> >> I can't help but chime in here that I would be pretty irritated to >> come across a test that mixed up using mocks and real objects, >> especially when they're the same class. Can you not use a mock for >> the >> other instance of User too? >> >> >> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> cheers, >> Matt >> >> http://mattwynne.net >> +447974 430184 >> >> _______________________________________________ >> 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 cheers, Matt http://mattwynne.net +447974 430184 From brian.takita at gmail.com Thu Apr 1 21:28:44 2010 From: brian.takita at gmail.com (Brian Takita) Date: Thu, 1 Apr 2010 18:28:44 -0700 Subject: [rspec-users] setting partial stub for just one value and letting obj handle the rest In-Reply-To: References: <93778c0b-bc8c-4073-bc05-d5543cee9a20@u32g2000vbc.googlegroups.com> <492DDE02-102C-4182-8009-F18CC8379F38@gmail.com> <821FD210-48A1-43D2-8381-5EC8B04EE384@mattwynne.net> <3dab8694-3c77-40a1-9841-5ef001090904@e21g2000vbb.googlegroups.com> Message-ID: I used to do the following when I used rspec mocks. user = mock_model(User) find_method = User.method(:find) User.stub!(:find).at_least(1).and_return do |id| if id == mock_user.id.to_s user else find_method.call(id) # May need to instance_eval here, but I think .call is sufficient. end end In fact this sort of inspired me to mock.proxy method call. Of course YMMV :-) On Thu, Apr 1, 2010 at 3:29 PM, drewB wrote: > For anyone who might come across this message looking for a solution > to the same problem, I wrote the following function to take care of it > (http://gist.github.com/352449) > > def stub_find_for_specific_values(model, stubs) > ?model.stub!(:find).at_least(1).and_return do |id| > ? ?if stubs.has_key? id > ? ? ?stubs[id] > ? ?else > ? ? ?model.find_by_id(id) > ? ?end > ?end > end > > #example below will return the mock_user if its id is search for > otherwise find will search as normal > mock_user = mock_model(User) > stub_find_for_specific_values(User, mock_user.id => mock_user) > > On Apr 1, 3:12?pm, drewB wrote: >> David, thanks for your response. >> >> Matt, I totally hear you. ?In this contrived example, you probably >> could but in the project I am working on it would be very difficult. >> One of the challenges of joining a project already in progress... >> >> On Apr 1, 1:45?pm, Matt Wynne wrote: >> >> > On 1 Apr 2010, at 21:35, David Chelimsky wrote: >> >> > > On Apr 1, 2010, at 3:14 PM, drewB wrote: >> >> > >> Occasionally, I find myself in a situation where I want to have a >> > >> mock >> > >> obj returned if a method is called with a particular argument but >> > >> handled normally otherwise. ?For example, lets say I have a Model >> > >> named User and I am specing a controller that sends messages from one >> > >> user to another. ?When User.find is called for the user who is making >> > >> the request I want it to run normally but when User.find is called >> > >> for >> > >> the receiver I want it to return a mocked obj. ?In this case, I can >> > >> do >> > >> something like (http://gist.github.com/352305): >> >> > >> user = mock_model(User) >> > >> User.stub!(:find).at_least(1).and_return do |id| >> > >> ? if id == mock_user.id.to_s >> > >> ? ? user >> > >> ? else >> > >> ? ? User.find_by_id(id) >> > >> ? end >> > >> end >> >> > >> If I didn't have another method that allowed me to find a User by >> > >> it's >> > >> id this won't work. >> >> > >> Is there an easier way to accomplish this? >> >> > > Not really. When you stub a method, the framework overrides that >> > > method with its own implementation. There's no mechanism in place to >> > > say "pass the message onto the real object if it doesn't have the >> > > arguments I'm interested in." I'm not sure of any framework that >> > > does that. Maybe RR, but I'm not sure. >> >> > > Good luck. >> > > David >> >> > I can't help but chime in here that I would be pretty irritated to >> > come across a test that mixed up using mocks and real objects, >> > especially when they're the same class. Can you not use a mock for the >> > other instance of User too? >> >> > > _______________________________________________ >> > > rspec-users mailing list >> > > rspec-us... at rubyforge.org >> > >http://rubyforge.org/mailman/listinfo/rspec-users >> >> > cheers, >> > Matt >> >> >http://mattwynne.net >> > +447974 430184 >> >> > _______________________________________________ >> > 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 mkolenda at gmail.com Fri Apr 2 13:16:45 2010 From: mkolenda at gmail.com (Matt Kolenda) Date: Fri, 2 Apr 2010 10:16:45 -0700 Subject: [rspec-users] Passing get request parameters in an rspec test Message-ID: Hello Please forgive my noobness to rspec. I have a controller method that inspects the params[:id] object and renders a view that depends on the existence of that :id. I want to ensure that the view is rendered in the controller rspec test. The rspec code is: describe "GET 'enrollments'" do it "should be successful" do get 'enrollments' response.should be_success end end The 'enrollments' controller method inspects the params object, pulls out the :id and uses it in a few queries to populate a couple of instance variables. My question is "How do I pass in the params[:id] parameter to the get 'enrollments' line?" Thanks in advance Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Fri Apr 2 13:51:44 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Fri, 02 Apr 2010 12:51:44 -0500 Subject: [rspec-users] Passing get request parameters in an rspec test In-Reply-To: References: Message-ID: <4BB62EB0.802@gmail.com> On 2010-04-02 12:16 PM, Matt Kolenda wrote: > Hello > > Please forgive my noobness to rspec. We're all noobs at some point in regard to something. No forgiveness necessary. :) > I have a controller method that inspects the params[:id] object and > renders a view that depends on the existence of that :id. > > I want to ensure that the view is rendered in the controller rspec > test. The rspec code is: > > describe "GET 'enrollments'" do > it "should be successful" do > get 'enrollments' > response.should be_success > end > end > > The 'enrollments' controller method inspects the params object, pulls > out the :id and uses it in a few queries to populate a couple of > instance variables. > > My question is "How do I pass in the params[:id] parameter to the get > 'enrollments' line?" > get 'enrollments', {:id => '1') One thing I've learned is to pay attention to the data type you use in the params hash when you use get|post|put|delete. The params hash in a real application is filled with strings, so yours should be too. > Thanks in advance > > Matt Peace, Phillip From phillipkoebbe at gmail.com Fri Apr 2 13:53:12 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Fri, 02 Apr 2010 12:53:12 -0500 Subject: [rspec-users] Passing get request parameters in an rspec test In-Reply-To: <4BB62EB0.802@gmail.com> References: <4BB62EB0.802@gmail.com> Message-ID: <4BB62F08.3070503@gmail.com> > get 'enrollments', {:id => '1') And, of course, that should be a curly at the end! get 'enrollments', {:id => '1'} Phillip From orengolan at gmail.com Thu Apr 1 14:36:15 2010 From: orengolan at gmail.com (oren) Date: Thu, 1 Apr 2010 11:36:15 -0700 (PDT) Subject: [rspec-users] help me refactor a step for finding href in specific link In-Reply-To: References: <8a243488009b2a91d246316a695420a3@ruby-forum.com> Message-ID: <68ee8f06-0bfb-4037-b53a-91565af204c3@g28g2000yqh.googlegroups.com> thanks! i'll use cucumber list next time. On Mar 31, 11:09?pm, David Chelimsky wrote: > On Mar 31, 2010, at 5:13 PM, Oren Golan wrote: > > > > > I want to verify the href is correct: > >

> > ? ?Website > >

> > > my step in the cucumber file: > > And the "website" class should have "www.happyhour.com" > > > the step definition: > > Then /^the "([^\"]*)" class should have "([^\"]*)"$/ do |link, url| > > ?response.should have_selector(".#{link}") do |site| > > ? ?site.inner_html.include?(url).should be_true > > ?end > > end > > > it's doesn't look good and would like to hear suggestion for improving > > it. > > Thanks! > > Cucumber has its own list:http://groups.google.com/group/cukes, so you may get more responses there. > > I'd do something like this (incomplete and untested, but ....): > > And "Website" should link to "www.happyhour.com" > > Then /^"([^\"]*)" should link to "([^\"]*)"$/ do |text, href| > ? response.should have_xpath(
) > end > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From zero0xxx at gmail.com Sat Apr 3 07:56:37 2010 From: zero0xxx at gmail.com (Vojto Rinik) Date: Sat, 3 Apr 2010 13:56:37 +0200 Subject: [rspec-users] Can I use mocking in this way? Message-ID: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> Hello RSpec users! I have one abstract class and a few classes that inherit from that abstract one. I'd like to test if my abstract class works with RSpec, but I can't test directly abstract class (or can I?) and I don't wanna test some particular class that inherits, because I wanna test general behaviour. So I was just wondering. Can I use mocking somehow to create a subclass of my base class, add some functionality in it and test methods of the base class? Hope that makes sense. Vojto Rinik http://infinite.sk ?Perfection is achieved perfection not when there is nothing left to add, but when there is nothing left to take away? ? Antoine de Saint-Exupery -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Apr 3 17:32:08 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 3 Apr 2010 18:32:08 -0300 Subject: [rspec-users] Can I use mocking in this way? In-Reply-To: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> References: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> Message-ID: On Sat, Apr 3, 2010 at 8:56 AM, Vojto Rinik wrote: > Hello RSpec users! > I have one abstract class and a few classes that inherit from that abstract > one. Ruby doesn't have abstract classes. You can have a base class that you don't _intend_ to instantiate directly, but there's nothing stopping you from doing so, so it's not like an abstract class in java, which you actually can't instantiate directly. I've seen some cases where the initialize method is made private so you can't just call Foo.new, so it sort of feels like an abstract class, but even in that case you can still use send() to instantiate one in a test: AbstractIshClass.send(:new) > I'd like to test if my abstract class works with RSpec, but I can't test > directly abstract > class (or can I?) Yes, you can. I'd either do that, or use a shared example group and apply it to all of the subclasses (see http://rspec.info/documentation/). > and I don't wanna test some particular class that > inherits, because > I wanna test general behaviour. > So I was just wondering. Can I use mocking somehow to create a subclass of > my > base class, add some functionality in it and test methods of the base class? Mocks are for specifying interactions between objects, which is a different situation than you are describing. HTH, David From julian at leviston.net Sat Apr 3 21:45:26 2010 From: julian at leviston.net (Julian Leviston) Date: Sun, 4 Apr 2010 11:45:26 +1000 Subject: [rspec-users] Can I use mocking in this way? In-Reply-To: References: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> Message-ID: On 04/04/2010, at 7:32 AM, David Chelimsky wrote: > On Sat, Apr 3, 2010 at 8:56 AM, Vojto Rinik wrote: >> Hello RSpec users! >> I have one abstract class and a few classes that inherit from that abstract >> one. > > Ruby doesn't have abstract classes. You can have a base class that you > don't _intend_ to instantiate directly, but there's nothing stopping > you from doing so, so it's not like an abstract class in java, which > you actually can't instantiate directly. > > I've seen some cases where the initialize method is made private so > you can't just call Foo.new, so it sort of feels like an abstract > class, but even in that case you can still use send() to instantiate > one in a test: > > AbstractIshClass.send(:new) > How about if you overrode new and __new__ ? Julian. From dchelimsky at gmail.com Sun Apr 4 00:00:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 4 Apr 2010 01:00:57 -0300 Subject: [rspec-users] Can I use mocking in this way? In-Reply-To: References: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> Message-ID: On Sat, Apr 3, 2010 at 10:45 PM, Julian Leviston wrote: > > On 04/04/2010, at 7:32 AM, David Chelimsky wrote: > >> On Sat, Apr 3, 2010 at 8:56 AM, Vojto Rinik wrote: >>> Hello RSpec users! >>> I have one abstract class and a few classes that inherit from that abstract >>> one. >> >> Ruby doesn't have abstract classes. You can have a base class that you >> don't _intend_ to instantiate directly, but there's nothing stopping >> you from doing so, so it's not like an abstract class in java, which >> you actually can't instantiate directly. >> >> I've seen some cases where the initialize method is made private so >> you can't just call Foo.new, so it sort of feels like an abstract >> class, but even in that case you can still use send() to instantiate >> one in a test: >> >> ?AbstractIshClass.send(:new) >> > > How about if you overrode new and __new__ ? Then override the override. AFAIK, there's really no preventing a client from using an object however it chooses in Ruby. You can make it difficult, but I'm pretty sure there's always a way around it. From julian at leviston.net Sun Apr 4 00:08:46 2010 From: julian at leviston.net (Julian Leviston) Date: Sun, 4 Apr 2010 14:08:46 +1000 Subject: [rspec-users] Can I use mocking in this way? In-Reply-To: References: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> Message-ID: Sorry I meant send AND __send__ Julian. On 04/04/2010, at 11:45 AM, Julian Leviston wrote: > > On 04/04/2010, at 7:32 AM, David Chelimsky wrote: > >> On Sat, Apr 3, 2010 at 8:56 AM, Vojto Rinik wrote: >>> Hello RSpec users! >>> I have one abstract class and a few classes that inherit from that abstract >>> one. >> >> Ruby doesn't have abstract classes. You can have a base class that you >> don't _intend_ to instantiate directly, but there's nothing stopping >> you from doing so, so it's not like an abstract class in java, which >> you actually can't instantiate directly. >> >> I've seen some cases where the initialize method is made private so >> you can't just call Foo.new, so it sort of feels like an abstract >> class, but even in that case you can still use send() to instantiate >> one in a test: >> >> AbstractIshClass.send(:new) >> > > How about if you overrode new and __new__ ? > > Julian. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Sun Apr 4 05:33:08 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 4 Apr 2010 10:33:08 +0100 Subject: [rspec-users] Can I use mocking in this way? In-Reply-To: References: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> Message-ID: <275406FA-3443-4844-880C-F4660DC2DAF3@mattwynne.net> When I started programming Ruby and I wanted abstract classes I would raise an exception in the initialize method telling the client that they were trying to instantiate an abstract class. That was my best attempt at self-documenting code at the time. Nowadays, however, when I have behaviour that is abstract, I just put it in a module. That feels like much more idiomatic Ruby. On 4 Apr 2010, at 05:00, David Chelimsky wrote: > On Sat, Apr 3, 2010 at 10:45 PM, Julian Leviston > wrote: >> >> On 04/04/2010, at 7:32 AM, David Chelimsky wrote: >> >>> On Sat, Apr 3, 2010 at 8:56 AM, Vojto Rinik >>> wrote: >>>> Hello RSpec users! >>>> I have one abstract class and a few classes that inherit from >>>> that abstract >>>> one. >>> >>> Ruby doesn't have abstract classes. You can have a base class that >>> you >>> don't _intend_ to instantiate directly, but there's nothing stopping >>> you from doing so, so it's not like an abstract class in java, which >>> you actually can't instantiate directly. >>> >>> I've seen some cases where the initialize method is made private so >>> you can't just call Foo.new, so it sort of feels like an abstract >>> class, but even in that case you can still use send() to instantiate >>> one in a test: >>> >>> AbstractIshClass.send(:new) >>> >> >> How about if you overrode new and __new__ ? > > Then override the override. AFAIK, there's really no preventing a > client from using an object however it chooses in Ruby. You can make > it difficult, but I'm pretty sure there's always a way around it. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From celoserpa at gmail.com Mon Apr 5 00:21:25 2010 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Sun, 4 Apr 2010 22:21:25 -0600 Subject: [rspec-users] Stub a class and instances Message-ID: For example, I have this scenario where a Directory model will only save if it can connect to the LDAP server. In a test I'm writting, though, connecting to the LDAP server is not relevant, so I tried doing this: context "LDAP is on" do before(:each) do Directory.stub!(:authenticate_user).and_return(@user). @account.directory = Directory.make :ldap_on end ... end However, the Directory.make fails (since the before_save ldap test fails, because authenticate_user can't connect to the LDAP server). The issue is that it stubs the method as a singleton method of Directory. One alternative is opening the Directory class and redefining the authenticate_user method, but I'd like to know if rSpec supports somehow stubing a class and let it stub instance too. Cheers, Marcelo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Apr 5 08:48:44 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 5 Apr 2010 07:48:44 -0500 Subject: [rspec-users] Stub a class and instances In-Reply-To: References: Message-ID: On Apr 4, 2010, at 11:21 PM, Marcelo de Moraes Serpa wrote: > For example, I have this scenario where a Directory model will only save if it can connect to the LDAP server. In a test I'm writting, though, connecting to the LDAP server is not relevant, so I tried doing this: > > context "LDAP is on" do > before(:each) do > Directory.stub!(:authenticate_user).and_return(@user). > @account.directory = Directory.make :ldap_on > end > ... > end > > However, the Directory.make fails (since the before_save ldap test fails, because authenticate_user can't connect to the LDAP server). The issue is that it stubs the method as a singleton method of Directory. That is how stubbing works in RSpec, and every other Ruby stubbing/mocking framework I know of. If you tell a class to stub a method, it stubs a class method. If you want to stub an instance method, you stub it directly on an instance. Mocha has an any_instance method, which RSpec doesn't have (yet), that allows you to say: Directory.any_instance.stubs(:authenticate_user).returns(@user) You can either switch to mocha and do that, or stub whatever creation mechanism is being used: directory = Directory.new directory.stub(:authenticate_user).and_return(@user) Directory.stub(:new).and_return(directory) account.directory = Directory.make :ldap_on > One alternative is opening the Directory class and redefining the authenticate_user method, but I'd like to know if rSpec supports somehow stubing a class and let it stub instance too. I don't think you'd want to stub the same method on the class and instance automatically. You might end up with false positives when one object calls a class method on an instance. HTH, David From mailinglists at patmaddox.com Mon Apr 5 11:09:50 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Mon, 5 Apr 2010 08:09:50 -0700 Subject: [rspec-users] Can I use mocking in this way? In-Reply-To: References: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> Message-ID: <89770DA8-2417-474C-BB97-169DBE465132@patmaddox.com> Sounds like a lot of work On Apr 3, 2010, at 9:08 PM, Julian Leviston wrote: > Sorry I meant send AND __send__ > > Julian. > > On 04/04/2010, at 11:45 AM, Julian Leviston wrote: > >> >> On 04/04/2010, at 7:32 AM, David Chelimsky wrote: >> >>> On Sat, Apr 3, 2010 at 8:56 AM, Vojto Rinik wrote: >>>> Hello RSpec users! >>>> I have one abstract class and a few classes that inherit from that abstract >>>> one. >>> >>> Ruby doesn't have abstract classes. You can have a base class that you >>> don't _intend_ to instantiate directly, but there's nothing stopping >>> you from doing so, so it's not like an abstract class in java, which >>> you actually can't instantiate directly. >>> >>> I've seen some cases where the initialize method is made private so >>> you can't just call Foo.new, so it sort of feels like an abstract >>> class, but even in that case you can still use send() to instantiate >>> one in a test: >>> >>> AbstractIshClass.send(:new) >>> >> >> How about if you overrode new and __new__ ? >> >> Julian. >> >> >> _______________________________________________ >> 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 cwdinfo at gmail.com Mon Apr 5 22:37:22 2010 From: cwdinfo at gmail.com (steve ross) Date: Mon, 5 Apr 2010 19:37:22 -0700 Subject: [rspec-users] Can I use mocking in this way? In-Reply-To: <89770DA8-2417-474C-BB97-169DBE465132@patmaddox.com> References: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> <89770DA8-2417-474C-BB97-169DBE465132@patmaddox.com> Message-ID: On Apr 5, 2010, at 8:09 AM, Pat Maddox wrote: > > Sounds like a lot of work > > > On Apr 3, 2010, at 9:08 PM, Julian Leviston wrote: > >> Sorry I meant send AND __send__ >> >> Julian. >> >> On 04/04/2010, at 11:45 AM, Julian Leviston wrote: >> >>> >>> On 04/04/2010, at 7:32 AM, David Chelimsky wrote: >>> >>>> On Sat, Apr 3, 2010 at 8:56 AM, Vojto Rinik wrote: >>>>> Hello RSpec users! >>>>> I have one abstract class and a few classes that inherit from that abstract >>>>> one. >>>> >>>> Ruby doesn't have abstract classes. You can have a base class that you >>>> don't _intend_ to instantiate directly, but there's nothing stopping >>>> you from doing so, so it's not like an abstract class in java, which >>>> you actually can't instantiate directly. >>>> >>>> I've seen some cases where the initialize method is made private so >>>> you can't just call Foo.new, so it sort of feels like an abstract >>>> class, but even in that case you can still use send() to instantiate >>>> one in a test: >>>> >>>> AbstractIshClass.send(:new) >>>> >>> >>> How about if you overrode new and __new__ ? >>> >>> Julian. How about: class AbstractClassException < RuntimeError; end class AbstractishClass def initialize raise AbstractClassException.new("don't do that.") end end That way, even sending a message to new causes a failure. And that's what you're looking for, right? From dchelimsky at gmail.com Mon Apr 5 22:52:27 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 5 Apr 2010 21:52:27 -0500 Subject: [rspec-users] Can I use mocking in this way? In-Reply-To: References: <00A730C5-DF73-4E42-B25E-201043E77A39@gmail.com> <89770DA8-2417-474C-BB97-169DBE465132@patmaddox.com> Message-ID: On Apr 5, 2010, at 9:37 PM, steve ross wrote: > On Apr 5, 2010, at 8:09 AM, Pat Maddox wrote: >> >> Sounds like a lot of work >> >> >> On Apr 3, 2010, at 9:08 PM, Julian Leviston wrote: >> >>> Sorry I meant send AND __send__ >>> >>> Julian. >>> >>> On 04/04/2010, at 11:45 AM, Julian Leviston wrote: >>> >>>> >>>> On 04/04/2010, at 7:32 AM, David Chelimsky wrote: >>>> >>>>> On Sat, Apr 3, 2010 at 8:56 AM, Vojto Rinik wrote: >>>>>> Hello RSpec users! >>>>>> I have one abstract class and a few classes that inherit from that abstract >>>>>> one. >>>>> >>>>> Ruby doesn't have abstract classes. You can have a base class that you >>>>> don't _intend_ to instantiate directly, but there's nothing stopping >>>>> you from doing so, so it's not like an abstract class in java, which >>>>> you actually can't instantiate directly. >>>>> >>>>> I've seen some cases where the initialize method is made private so >>>>> you can't just call Foo.new, so it sort of feels like an abstract >>>>> class, but even in that case you can still use send() to instantiate >>>>> one in a test: >>>>> >>>>> AbstractIshClass.send(:new) >>>>> >>>> >>>> How about if you overrode new and __new__ ? >>>> >>>> Julian. > > How about: > > class AbstractClassException < RuntimeError; end > class AbstractishClass > def initialize > raise AbstractClassException.new("don't do that.") > end > end > > That way, even sending a message to new causes a failure. And that's what you're looking for, right? As Matt suggested earlier in this thread, this is not really idiomatic Ruby. If you want behavior in a structure that is not directly instantiable, use a module: module GeneralBehavior def something_general ... end end class SpecificClass include GeneralBehavior end describe GeneralBehavior do it "does something general" do klass = Class.new { include GeneralBehavior } klass.new.something_general.should ..... end end From ben.rooney62 at googlemail.com Tue Apr 6 19:44:08 2010 From: ben.rooney62 at googlemail.com (ben rooney) Date: Wed, 7 Apr 2010 00:44:08 +0100 Subject: [rspec-users] Scaffold views spec failing Message-ID: Forgive a very nooooob question. I am trying to get my head around all of this. Have a couple of simple models (weird spelling of tipe was in case type was a reserved word ...). They were all generated with the rspec_scaffold generator class Category < ActiveRecord::Base has_many :tipes validates_uniqueness_of :name validates_presence_of :name end class Tipe < ActiveRecord::Base belongs_to :category validates_uniqueness_of :name validates_presence_of :name end I have a line in my tipes/index.html.erb <%=h tipe.category.name %> All works just fine in the development environment, but when I run autospec, it fails with the the following error: "ActionView::TemplateError in '/tipes/index.html.erb renders a list of tipes' undefined method `name' for nil:NilClass" The tipes/index.html.erb_spec.rb is the standard rspec_scaffold generated one : require 'spec_helper' describe "/tipes/index.html.erb" do include TipesHelper before(:each) do assigns[:tipes] = [ stub_model(Tipe, :name => "value for name", :live => false, :category_id => 1 ), stub_model(Tipe, :name => "value for name", :live => false, :category_id => 1 ) ] end it "renders a list of tipes" do render response.should have_tag("tr>td", "value for name".to_s, 2) response.should have_tag("tr>td", false.to_s, 2) response.should have_tag("tr>td", 1.to_s, 2) end end Clearly there is some problem with the association - it isn't understanding it. So my dumb nooob question is ... what do I do to get this to work? If I leave the line in the index.html.erb as <%=h tipe.category_id %> it is all sweetness and light. If I change it ot <%=h tipe.category.name %> the world is a dark, cold place... (PS - I don't really understand the assigns[:tipe] thing either ...) (this is the error trace app/views/tipes/index.html.erb:14 app/views/tipes/index.html.erb:10:in `each' app/views/tipes/index.html.erb:10 vendor/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action_view/base.rb:27:in `render' vendor/gems/rspec-rails-1.3.2/lib/spec/rails/example/view_example_group.rb:170:in `__send__' vendor/gems/rspec-rails-1.3.2/lib/spec/rails/example/view_example_group.rb:170:in `render' spec/views/tipes/index.html.erb_spec.rb:30 rspec (1.3.0) lib/spec/example/example_methods.rb:40:in `instance_eval' rspec (1.3.0) lib/spec/example/example_methods.rb:40:in `execute' /usr/local/lib/ruby/1.8/timeout.rb:53:in `timeout' rspec (1.3.0) lib/spec/example/example_methods.rb:37:in `execute' rspec (1.3.0) lib/spec/example/example_group_methods.rb:214:in `run_examples' rspec (1.3.0) lib/spec/example/example_group_methods.rb:212:in `each' rspec (1.3.0) lib/spec/example/example_group_methods.rb:212:in `run_examples' rspec (1.3.0) lib/spec/example/example_group_methods.rb:103:in `run' rspec (1.3.0) lib/spec/runner/example_group_runner.rb:23:in `run' rspec (1.3.0) lib/spec/runner/example_group_runner.rb:22:in `each' rspec (1.3.0) lib/spec/runner/example_group_runner.rb:22:in `run' rspec (1.3.0) lib/spec/runner/options.rb:152:in `run_examples' rspec (1.3.0) lib/spec/runner/command_line.rb:9:in `run' rspec (1.3.0) bin/spec:5 ) Any help v much appreciated ... Ben From mkolenda at gmail.com Tue Apr 6 23:56:56 2010 From: mkolenda at gmail.com (Matt Kolenda) Date: Tue, 6 Apr 2010 20:56:56 -0700 Subject: [rspec-users] Passing get request parameters in an rspec test In-Reply-To: <4BB62F08.3070503@gmail.com> References: <4BB62EB0.802@gmail.com> <4BB62F08.3070503@gmail.com> Message-ID: Phillip - Yes, that worked, thanks a million! Matt On Fri, Apr 2, 2010 at 10:53 AM, Phillip Koebbe wrote: > > get 'enrollments', {:id => '1') >> > > And, of course, that should be a curly at the end! > > get 'enrollments', {:id => '1'} > > > Phillip > _______________________________________________ > 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 avdi at avdi.org Wed Apr 7 00:38:24 2010 From: avdi at avdi.org (Avdi Grimm) Date: Wed, 7 Apr 2010 00:38:24 -0400 Subject: [rspec-users] NullDB has a new maintainer Message-ID: As also reported on my blog [http://avdi.org/devblog/2010/04/06/nulldb-has-a-new-maintainer/], Myron Marston is now the official maintainer of NullDB. I thought I'd report it here as well since some of the list participants have expressed interest in NullDB in the past. Myron has brought much-needed energy and updates to the project, and I'm confident the project is in good hands. -- Avdi Home: http://avdi.org Developer Blog: http://avdi.org/devblog/ York Coworking: http://www.meetup.com/york-coworking/ Twitter: http://twitter.com/avdi Work: http://devver.net The Lazy Faire: http://thelazyfaire.org Journal: http://avdi.livejournal.com From cid.dennis at gmail.com Wed Apr 7 03:24:06 2010 From: cid.dennis at gmail.com (Cid Dennis) Date: Wed, 7 Apr 2010 01:24:06 -0600 Subject: [rspec-users] Rspec and Selenium Question Message-ID: <53D1D0EF-19E9-4B96-ADA5-0DB61549DF3A@gmail.com> So I have created a number of rspec test using the selenium ruby client. The problem is I can not figure out a easy way to say run all the test I have on each browser I want to support. The current work around I have is to use and environment variable and have the specs look at a config file to find the browser information it is suppose to use. But this requires running spec for each change to the environment. What I really want to do is a way to loop over all the test in a example file and say do it for each on of these configurations. I am using the most recent version of rspec. Any pointers would be appreciated. Thanks From angrygreg at gmail.com Wed Apr 7 13:05:52 2010 From: angrygreg at gmail.com (Greg Akins) Date: Wed, 7 Apr 2010 13:05:52 -0400 Subject: [rspec-users] Rspec and Selenium Question In-Reply-To: <53D1D0EF-19E9-4B96-ADA5-0DB61549DF3A@gmail.com> References: <53D1D0EF-19E9-4B96-ADA5-0DB61549DF3A@gmail.com> Message-ID: Are you running on a *nix box? You could always just use a bash one-liner, or script for env in ie firefox opera ; do rspec ENV=$env ; spec ; done On Wed, Apr 7, 2010 at 3:24 AM, Cid Dennis wrote: > So I have created a number of rspec test using the selenium ruby client. > > The problem is I can not figure out a easy way to say run all the test I have on each browser I want to support. ? The current work around I have is to use and environment variable and have the specs look at a config file to find the browser information it is suppose to use. ? ? But this requires running spec for each change to the environment. > > What I really want to do is a way to loop over all the test in a example file and say do it for each on of these configurations. > > I am using the most recent version of rspec. > > Any pointers would be appreciated. > > Thanks > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Greg Akins http://insomnia-consulting.org http://www.pghcodingdojo.org http://pittjug.dev.java.net http://twitter.com/akinsgre http://www.linkedin.com/in/akinsgre From raasdnil at gmail.com Thu Apr 8 02:59:28 2010 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 8 Apr 2010 16:59:28 +1000 Subject: [rspec-users] Best way to match several attributes of an object? In-Reply-To: References: <65bd6a51-b455-40c2-ab8a-20a8399523be@33g2000yqj.googlegroups.com> Message-ID: >> When you need to check several properties of an object, what is the >> best way to match them all? In the mail library I use a custom matcher, which lets me do things like: it "should handle |Minero Aoki |" do address = Mail::Address.new('Minero Aoki ') address.should break_down_to({ :display_name => 'Minero Aoki', :address => 'aamine at loveruby.net', :local => 'aamine', :domain => 'loveruby.net', :format => 'Minero Aoki ', :comments => nil, :raw => 'Minero Aoki '}) end The matcher in question is: # encoding: utf-8 module CustomMatchers class BreakDownTo def initialize(expected) @expected = expected end def matches?(target) @target = target @failed = false @expected.each_pair do |k,v| unless @target.send(k) == @expected[k] @failed = k end end !@failed end def failure_message "expected #{@failed} to be |#{@expected[@failed]}| " + "but was |#{@target.send(@failed)}|" end def megative_failure_message "expected #{@failed} not to be |#{@expected[@failed]}| " + "and was |#{@target.send(@failed)}|" end end # Actual matcher that is exposed. def break_down_to(expected) BreakDownTo.new(expected) end end -- http://rubyx.com/ http://lindsaar.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben.rooney62 at googlemail.com Thu Apr 8 16:34:11 2010 From: ben.rooney62 at googlemail.com (ben rooney) Date: Thu, 8 Apr 2010 21:34:11 +0100 Subject: [rspec-users] Scaffold views spec failing Message-ID: Obviously my noooooob question was embarrassingly noob - so I was forced to actually do some work and answer my own questions. The answer was that I had to stub out the association - natch... before(:each) do assigns[:tipes] = [ stub_model(Tipe, :name => "value for name", :live => true, :category => stub_model(Category, :name =>"category", :live => true, :id => 1) ), stub_model(Tipe, :name => "value for name", :live => true, :category => stub_model(Category, :name =>"category", :live => true, :id => 1) ) ] And lo - it all works! Hurrah. So if anyone else is as much as an idiot as me (unlikely, but you never know) that is what you do. Ben From adman1965 at gmail.com Sat Apr 10 03:24:36 2010 From: adman1965 at gmail.com (Adman65) Date: Sat, 10 Apr 2010 00:24:36 -0700 (PDT) Subject: [rspec-users] autospec exiting without results In-Reply-To: <57c63afe1002111300s66ecbf97q9ae9be8ddc6b0e10@mail.gmail.com> References: <9e44e64c-93ea-4132-9183-e996a2823e7b@v20g2000prb.googlegroups.com> <57c63afe1002111015g5a3a77cx7645247bf8d93e23@mail.gmail.com> <3bdf8ec6-062d-4b7d-8e29-d707cd08b104@g8g2000pri.googlegroups.com> <57c63afe1002111300s66ecbf97q9ae9be8ddc6b0e10@mail.gmail.com> Message-ID: <4cf93c27-3256-461e-9593-4df52ccf6150@z11g2000yqz.googlegroups.com> I too am having the same problem: Mini:crm adam$ autospec (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) loading autotest/rails_rspec style: RailsRspec Mini:crm adam$ Here are my gem versions: ZenTest 4.3.1 rspec 1.3.0 rspec-rails 1.3.2 autotest 4.2.9 autotest-rails 4.1.0 On Feb 11, 2:00?pm, David Chelimsky wrote: > On Thu, Feb 11, 2010 at 4:11 PM, Andy Koch wrote: > > have that gem installed, still no luck > > versions of rspec, rails, etc? > > > > > > > > > On Feb 11, 10:15?am, David Chelimsky wrote: > >> On Thu, Feb 11, 2010 at 1:56 PM, Andy Koch wrote: > >> > Hi, > > >> > trying to getautospecworking on a new Mac (snow lep) but when > >> > runningautospecon cmd it just exists with no result or output of any > >> > kind > > >> > rake spec runs all tests as expected > > >> > I've followed the Rspec wiki and looked through some blog posts > >> > related but nothing gained > > >> > any ideas what might be amiss? > > >> > any help much appreciated > > >> > thank you > > >> If this is a rails app you also need the autotest-rails gem. > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From adman1965 at gmail.com Sat Apr 10 03:36:10 2010 From: adman1965 at gmail.com (Adman65) Date: Sat, 10 Apr 2010 00:36:10 -0700 (PDT) Subject: [rspec-users] Autospec doesn't run any files Message-ID: I'm trying to use autospec and when I run it i see this: Mini:crm adam$ autospec (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) (Not running features. To run features in autotest, set AUTOFEATURE=true.) loading autotest/rails_rspec style: RailsRspec Mini:crm adam$ Here are my gem versions rspec 1.3.0 rspec-rails 1.3.2 ZenTest - 4.3.1 autotest - 4.2.9 autospec-rails - 4.1.0 From dchelimsky at gmail.com Sat Apr 10 17:22:23 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 10 Apr 2010 16:22:23 -0500 Subject: [rspec-users] autospec exiting without results In-Reply-To: <4cf93c27-3256-461e-9593-4df52ccf6150@z11g2000yqz.googlegroups.com> References: <9e44e64c-93ea-4132-9183-e996a2823e7b@v20g2000prb.googlegroups.com> <57c63afe1002111015g5a3a77cx7645247bf8d93e23@mail.gmail.com> <3bdf8ec6-062d-4b7d-8e29-d707cd08b104@g8g2000pri.googlegroups.com> <57c63afe1002111300s66ecbf97q9ae9be8ddc6b0e10@mail.gmail.com> <4cf93c27-3256-461e-9593-4df52ccf6150@z11g2000yqz.googlegroups.com> Message-ID: >> > On Feb 11, 10:15?am, David Chelimsky wrote: >> >> On Thu, Feb 11, 2010 at 1:56 PM, Andy Koch wrote: >> >> > Hi, >> >> >> > trying to getautospecworking on a new Mac (snow lep) but when >> >> > runningautospecon cmd it just exists with no result or output of any >> >> > kind >> >> >> > rake spec runs all tests as expected >> >> >> > I've followed the Rspec wiki and looked through some blog posts >> >> > related but nothing gained >> >> >> > any ideas what might be amiss? >> >> >> > any help much appreciated >> >> >> > thank you >> >> >> If this is a rails app you also need the autotest-rails gem. > On Feb 11, 2:00?pm, David Chelimsky wrote: >> On Thu, Feb 11, 2010 at 4:11 PM, Andy Koch wrote: >> > have that gem installed, still no luck >> >> versions of rspec, rails, etc? >> On Sat, Apr 10, 2010 at 2:24 AM, Adman65 wrote: > I too am having the same problem: > > Mini:crm adam$ autospec > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > (Not running features. ?To run features in autotest, set > AUTOFEATURE=true.) > loading autotest/rails_rspec > style: RailsRspec > Mini:crm adam$ > > Here are my gem versions: > ZenTest 4.3.1 > rspec 1.3.0 > rspec-rails 1.3.2 > autotest 4.2.9 > autotest-rails 4.1.0 What versions of Ruby and rails? Are you running autospec in the project root folder? Are your specs in conventional directories? Do you have a .autotest file in the app? Or a ~/.autotest file? If so, what's in them? From mguterl at gmail.com Mon Apr 12 12:17:16 2010 From: mguterl at gmail.com (Michael Guterl) Date: Mon, 12 Apr 2010 12:17:16 -0400 Subject: [rspec-users] test spies Message-ID: I'm curious what the current state of test spies in rspec is? What is everyone using for this? not a mock? rr? rspec-spies? I see that spies were going to be added to rspec 1.3.0, but pulled because of a bug (https://rspec.lighthouseapp.com/projects/5645/tickets/938), will this be brought back in? I really like the rspec standard mock / stub syntax and am hesitant to move to another solution. Best, Michael Guterl From dchelimsky at gmail.com Mon Apr 12 13:16:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 12 Apr 2010 12:16:56 -0500 Subject: [rspec-users] test spies In-Reply-To: References: Message-ID: <21BAA808-67CC-43BE-A0C6-E8C5F34C6B61@gmail.com> On Apr 12, 2010, at 11:17 AM, Michael Guterl wrote: > I'm curious what the current state of test spies in rspec is? > > What is everyone using for this? not a mock? rr? rspec-spies? > I see that spies were going to be added to rspec 1.3.0, but pulled > because of a bug > (https://rspec.lighthouseapp.com/projects/5645/tickets/938), will this > be brought back in? I really like the rspec standard mock / stub > syntax and am hesitant to move to another solution. Not-a-mock works. Any reason not to just use that? From mguterl at gmail.com Mon Apr 12 15:38:50 2010 From: mguterl at gmail.com (Michael Guterl) Date: Mon, 12 Apr 2010 15:38:50 -0400 Subject: [rspec-users] test spies In-Reply-To: <21BAA808-67CC-43BE-A0C6-E8C5F34C6B61@gmail.com> References: <21BAA808-67CC-43BE-A0C6-E8C5F34C6B61@gmail.com> Message-ID: On Mon, Apr 12, 2010 at 1:16 PM, David Chelimsky wrote: > On Apr 12, 2010, at 11:17 AM, Michael Guterl wrote: > >> I'm curious what the current state of test spies in rspec is? >> >> What is everyone using for this? ?not a mock? ?rr? ?rspec-spies? >> I see that spies were going to be added to rspec 1.3.0, but pulled >> because of a bug >> (https://rspec.lighthouseapp.com/projects/5645/tickets/938), will this >> be brought back in? ?I really like the rspec standard mock / stub >> syntax and am hesitant to move to another solution. > > Not-a-mock works. Any reason not to just use that? > Mostly because I like the default rspec stub / mock syntax. Adding not-a-mock replaces the entire mock framework: config.mock_with NotAMock::RspecMockFrameworkAdapter doing so causes all of my existing specs to break. It seemed like the built-in rspec solution did not require changing all of my existing mocks/stubs. Best, Michael Guterl From ashley.moran at patchspace.co.uk Tue Apr 13 06:29:55 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 13 Apr 2010 11:29:55 +0100 Subject: [rspec-users] Colour support in RSpec 1.3 with Spork Message-ID: Hi I can't find any reference to this being a known issue or not. I'm having to work on a Rails 2.3 project for a bit, so I'm back with RSpec 1.3. I've got Spork working and I'm running it with this command: ruby -S spec --drb --colour --format progress -o spec/spec.opts ... But I only get a monochrome output. Any idea what might be going on? Thought I'd ask here as it seems more RSpec- than Spork-based. Cheers Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From dchelimsky at gmail.com Tue Apr 13 10:38:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Apr 2010 09:38:53 -0500 Subject: [rspec-users] test spies In-Reply-To: References: <21BAA808-67CC-43BE-A0C6-E8C5F34C6B61@gmail.com> Message-ID: On Apr 12, 2010, at 2:38 PM, Michael Guterl wrote: > On Mon, Apr 12, 2010 at 1:16 PM, David Chelimsky wrote: >> On Apr 12, 2010, at 11:17 AM, Michael Guterl wrote: >> >>> I'm curious what the current state of test spies in rspec is? >>> >>> What is everyone using for this? not a mock? rr? rspec-spies? >>> I see that spies were going to be added to rspec 1.3.0, but pulled >>> because of a bug >>> (https://rspec.lighthouseapp.com/projects/5645/tickets/938), will this >>> be brought back in? I really like the rspec standard mock / stub >>> syntax and am hesitant to move to another solution. >> >> Not-a-mock works. Any reason not to just use that? >> > > Mostly because I like the default rspec stub / mock syntax. Adding > not-a-mock replaces the entire mock framework: > > config.mock_with NotAMock::RspecMockFrameworkAdapter > > doing so causes all of my existing specs to break. It seemed like the > built-in rspec solution did not require changing all of my existing > mocks/stubs. Sounds like not-a-mock is broken then, which is no surprise since rspec's mocks don't really offer any extension APIs. It must have broken after internal changes in rspec-mocks. Per the lighthouse ticket, the addition of have_received raised new questions about sync'ing the should_receive and have_received APIs. I think that a fair sum of refactoring would be required to do this properly. This is very low on a very long list of priorities right now, so my recommendation is to fix not-a-mock to work with the latest rspec. HTH, David From raasdnil at gmail.com Wed Apr 14 08:37:52 2010 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 14 Apr 2010 22:37:52 +1000 Subject: [rspec-users] State of autospec/test and Rails 3 Message-ID: Hi all, David, before I begin, thanks for your hard work :) I saw a thread or a blog post, I think it was on your site David, that Autotest is not working with Rails at the moment, circa beta4. Has that since changed? If not, anything I can do to help? At least on beta6 it still seems to be failing with: $ autotest loading autotest/rails /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:181:in `load': no such file to load -- ./.autotest (LoadError) from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:181:in `initialize' from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:180:in `each' from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:180:in `initialize' from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/autotest-rails-4.1.0/lib/autotest/rails.rb:7:in `initialize' from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:124:in `new' from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:124:in `run' from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/bin/autotest:55 relevant gem list: autotest-rails (4.1.0) rspec-core (2.0.0.beta.6) rspec-expectations (2.0.0.beta.6) rspec-mocks (2.0.0.beta.6) ZenTest (4.3.1) Autotest file: $ cat .autotest/discover.rb Autotest.add_discovery { "rspec2" } From dchelimsky at gmail.com Wed Apr 14 09:37:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 14 Apr 2010 08:37:22 -0500 Subject: [rspec-users] State of autospec/test and Rails 3 In-Reply-To: References: Message-ID: <4D55C8A0-017D-4013-B33E-749D56D35C40@gmail.com> On Apr 14, 2010, at 7:37 AM, Mikel Lindsaar wrote: > Hi all, > > David, before I begin, thanks for your hard work :) > > I saw a thread or a blog post, I think it was on your site David, that Autotest is not working with Rails at the moment, circa beta4. > > Has that since changed? If not, anything I can do to help? > > At least on beta6 it still seems to be failing with: > > $ autotest > loading autotest/rails > /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:181:in `load': no such file to load -- ./.autotest (LoadError) > from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:181:in `initialize' > from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:180:in `each' > from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:180:in `initialize' > from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/autotest-rails-4.1.0/lib/autotest/rails.rb:7:in `initialize' > from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:124:in `new' > from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/lib/autotest.rb:124:in `run' > from /Users/mikel/.rvm/gems/ruby-1.8.7-p249 at t/gems/ZenTest-4.3.1/bin/autotest:55 > > > relevant gem list: > > autotest-rails (4.1.0) > rspec-core (2.0.0.beta.6) > rspec-expectations (2.0.0.beta.6) > rspec-mocks (2.0.0.beta.6) > ZenTest (4.3.1) > > > Autotest file: > > $ cat .autotest/discover.rb > Autotest.add_discovery { "rspec2" } Hi Mikel, I'm having success with it. Take a look at http://gist.github.com/365816 - anything you're missing there? Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogerdpack at gmail.com Wed Apr 14 15:28:11 2010 From: rogerdpack at gmail.com (rogerdpack) Date: Wed, 14 Apr 2010 12:28:11 -0700 (PDT) Subject: [rspec-users] raise_error suggestion Message-ID: <503328ca-1e98-4a3c-9109-cf261db09496@z11g2000yqz.googlegroups.com> I remember reading a post where somebody mentioned something like "sometimes after a refactoring, a test block like lambda { ... }.should raise_error catches a NoMethodError in error, thus is actually failing, but the user isn't notified of the same." A suggestion in this regard: change it so that if raise_error is called without parameters, and it catches NoMethodError, it outputs a warning somehow. The objection to this might be "what if I *expect* a NoMethodError-- I'll get spurious warnings" Answer: user can, at that point, put in NoMethodError as a parameter, and warning goes away (and that's a rare enough case that it probably won't cause conflicts). Thoughts? Thanks! -rp From paul.t.hinze at gmail.com Wed Apr 14 15:53:34 2010 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Wed, 14 Apr 2010 14:53:34 -0500 Subject: [rspec-users] raise_error suggestion In-Reply-To: <503328ca-1e98-4a3c-9109-cf261db09496@z11g2000yqz.googlegroups.com> References: <503328ca-1e98-4a3c-9109-cf261db09496@z11g2000yqz.googlegroups.com> Message-ID: On Wed, Apr 14, 2010 at 2:28 PM, rogerdpack wrote: > change it so that if raise_error is called without parameters, and it > catches NoMethodError, it outputs a warning somehow. > > Thoughts? +1; I have been burned by this several times, and this is seems like an elegant solution to clear up the potential confusion in this behavior. Less confusion = happier devs Cheers, Paul From mailinglists at patmaddox.com Wed Apr 14 16:42:16 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 14 Apr 2010 13:42:16 -0700 Subject: [rspec-users] raise_error suggestion In-Reply-To: <503328ca-1e98-4a3c-9109-cf261db09496@z11g2000yqz.googlegroups.com> References: <503328ca-1e98-4a3c-9109-cf261db09496@z11g2000yqz.googlegroups.com> Message-ID: <02530ACD-3135-46A0-BB08-BA2D51257331@patmaddox.com> On Apr 14, 2010, at 12:28 PM, rogerdpack wrote: > I remember reading a post where somebody mentioned something like > > "sometimes after a refactoring, a test block like > > lambda { ... }.should raise_error > > catches a NoMethodError in error, thus is actually failing, but the > user isn't notified of the same." > > A suggestion in this regard: > change it so that if raise_error is called without parameters, and it > catches NoMethodError, it outputs a warning somehow. > > The objection to this might be "what if I *expect* a NoMethodError-- > I'll get spurious warnings" > > Answer: user can, at that point, put in NoMethodError as a parameter, > and warning goes away (and that's a rare enough case that it probably > won't cause conflicts). Be explicit about the error you expect to get: lambda { ... }.should raise_error(SomeErrorClass, /match the message/) Read the documentation at http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Matchers.html#M000184 Nothing kills me more than a generic raise_error. Especially when the block is wrapped around a whole bunch of code that doesn't need it e.g. lambda { some_setup some_setup some.stupid_typo_that_blows_up call_that_we_expect_to_raise_an_error }.should raise_error Anyone on my team using a naked raise_error matcher gets a smack on the head from me...and I have a special spiky dunce cap for whoever does the above example. Also note in RSpec 1.3.0 #lambda is aliased to #expect, and #should to #to, so you can do expect { ... }.to raise_error(SomeErrorClass, /match the message/) which you may find more pleasant to read. Pat From raasdnil at gmail.com Wed Apr 14 23:43:10 2010 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 15 Apr 2010 13:43:10 +1000 Subject: [rspec-users] State of autospec/test and Rails 3 In-Reply-To: <4D55C8A0-017D-4013-B33E-749D56D35C40@gmail.com> References: <4D55C8A0-017D-4013-B33E-749D56D35C40@gmail.com> Message-ID: <28AF8839-F842-4BFE-9AD3-032825EE39EA@gmail.com> On 14, April 2010, at 14 Apr 23:37, David Chelimsky wrote: > On Apr 14, 2010, at 7:37 AM, Mikel Lindsaar wrote: >> I saw a thread or a blog post, I think it was on your site David, that Autotest is not working with Rails at the moment, circa beta4. > I'm having success with it. Take a look at http://gist.github.com/365816 - anything you're missing there? Hi David, Two things I had wrong: 1) I wasn't installing autotest as a gem 2) I was installing rspec-rails from git instead of from a gem 3) I had ./.autotest/discover.rb instead of ./autotest/discover.rb I blame it on a late night :) One thing though, running rspec-rails from :git would not run, giving: $ autotest loading autotest/rails_rspec2 Error loading Autotest style autotest/rails_rspec2 (no such file to load -- autotest/rails_rspec2). Aborting. Changing the Gemfile to use ">= 2.0.0.beta" fixed it. Thanks :) Mikel http://rubyx.com/ http://lindsaar.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Apr 15 11:40:02 2010 From: lists at ruby-forum.com (Mark Pittillo) Date: Thu, 15 Apr 2010 17:40:02 +0200 Subject: [rspec-users] Rails 3, Rspec 2, Autotest Message-ID: <1fe754a00478376a73632b794f3c9f43@ruby-forum.com> Trying to set up a Rails 3 project with RSpec and Autotest. I followed these steps exactly: http://gist.github.com/365816 But when I start up autotest, I get: $ autotest loading autotest/rails style: Rails instead of: $ autotest loading autotest/rails_rspec2 style: RailsRspec2 And autotest doesn't seem to do anything. Any idea what's happening? I'm using Ruby 1.9.2-head in rvm. Relevant gems: autotest (4.2.9) autotest-rails (4.1.0) rspec (2.0.0.beta.6) rspec-core (2.0.0.beta.6) rspec-expectations (2.0.0.beta.6) rspec-mocks (2.0.0.beta.6) rspec-rails (2.0.0.beta.6) ZenTest (4.3.1) Thanks a lot for any help. Mark -- Posted via http://www.ruby-forum.com/. From phillipkoebbe at gmail.com Thu Apr 15 16:32:56 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 15 Apr 2010 15:32:56 -0500 Subject: [rspec-users] Spec templates Message-ID: <4BC777F8.7040601@gmail.com> David et al, Has anyone ever toyed with the idea of templates for specs? I have a relative consistent way of specing models, controllers, etc, and invariably, I have to delete the stock code that the rspec generator creates and add a bunch of stuff that I always want. I was just thinking it would be nice of there were a way to have my own template for models, controllers, etc and not have to do so much repetitive work for every spec. Maybe it could be as easy as having a folder such as spec/templates and in that have model_spec.rb controller_spec.rb view_spec.rb helper_spec.rb There would have to be a bit of standardization regarding placeholders in those files, but it shouldn't be unbearable, especially considering what it could offer. Thoughts? Peace, Phillip From godfoca at gmail.com Thu Apr 15 16:39:27 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 15 Apr 2010 17:39:27 -0300 Subject: [rspec-users] Spec templates In-Reply-To: <4BC777F8.7040601@gmail.com> References: <4BC777F8.7040601@gmail.com> Message-ID: On Thu, Apr 15, 2010 at 5:32 PM, Phillip Koebbe wrote: > ?David et al, > > Has anyone ever toyed with the idea of templates for specs? I have a > relative consistent way of specing models, controllers, etc, and invariably, > I have to delete the stock code that the rspec generator creates and add a > bunch of stuff that I always want. I was just thinking it would be nice of > there were a way to have my own template for models, controllers, etc and > not have to do so much repetitive work for every spec. Maybe it could be as > easy as having a folder such as > > spec/templates > > and in that have > > model_spec.rb > controller_spec.rb > view_spec.rb > helper_spec.rb > > There would have to be a bit of standardization regarding placeholders in > those files, but it shouldn't be unbearable, especially considering what it > could offer. > > Thoughts? You could always define your own generators with your own templates. I'd probably try that first and see how well it works. Cheers, -foca > Peace, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rogerpack2005 at gmail.com Thu Apr 15 16:32:59 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Thu, 15 Apr 2010 13:32:59 -0700 (PDT) Subject: [rspec-users] raise_error suggestion In-Reply-To: <02530ACD-3135-46A0-BB08-BA2D51257331@patmaddox.com> References: <503328ca-1e98-4a3c-9109-cf261db09496@z11g2000yqz.googlegroups.com> <02530ACD-3135-46A0-BB08-BA2D51257331@patmaddox.com> Message-ID: <1951f007-7922-4094-ac53-566cf5021bd4@r18g2000yqd.googlegroups.com> > Be explicit about the error you expect to get: > > lambda { ... }.should raise_error(SomeErrorClass, /match the message/) > > Read the documentation athttp://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Matchers.html#M00... Perhaps it should be changed so that if you don't pass a class it outputs a warning. That might be an acceptable option. (If not then I still recommend my previous suggestion). Thanks! -rp From nicholas.wieland at gmail.com Fri Apr 16 08:15:38 2010 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Fri, 16 Apr 2010 14:15:38 +0200 Subject: [rspec-users] Writing rails plugins Message-ID: Hi *, I'm trying to write a plugin to integrate my SSO server into my rails app. I'm finding the whole process quite difficult, I'm still blocked at configuring rspec, and the lack of documentation is not helping. I've put this inside my /vendor/plugins/foobar/spec/spec_helper.rb ENV["RAILS_ENV"] = "test" require File.dirname(__FILE__) + "/../../../../config/environment" require 'spec' require 'spec/rails' of course it will break up when I will package the plugin as a gem, the path to the environment variable will be different. My question is more about best practices I guess, I would like to know how people includes rspec in a plugin that could be installed both inside /vendor/plugins (useful also during development time) and as a gem. I've seen some plugins (restful_authentication for example) provide an --rspec option to write all specs directly into RAILS_ROOT/spec, but it seems rather suboptimal, especially because plugins are not using this with consistence. Someone has any experience ? TIA, ngw From nicholas.wieland at gmail.com Fri Apr 16 09:07:30 2010 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Fri, 16 Apr 2010 15:07:30 +0200 Subject: [rspec-users] Rack::Test + cookies + rspec Message-ID: <355F2859-E22A-4442-A6AE-C2E39498DC43@gmail.com> Hi *, I need to test cookie creation with rspec and using Rack::Test, but for some reason I'm not able to pair the real app that creates a cookie with the rspec tests. The spec is like this: it "should authenticate using cookies" do user = Factory.create :user remember_token = Charon.make_remember_token set_cookie "warden=#{ remember_token }" user.update :remember_token => remember_token post '/authenticate' last_request.env[ 'warden' ].should be_authenticated end Inside the main app I set the cookie like: if !request.cookies[ 'warden' ] response.set_cookie( 'warden', :value => env[ 'warden' ].user.remember_token ) end I can clearly see it works when testing manually. For some reasons, the rspec cookie is different than the one set by the app. Is someone trying something similar and can share some code ? I think that the problem is in Rack::Test but I'm not sure and I'm not able prove it. ngw From dchelimsky at gmail.com Fri Apr 16 09:12:04 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 16 Apr 2010 08:12:04 -0500 Subject: [rspec-users] Rack::Test + cookies + rspec In-Reply-To: <355F2859-E22A-4442-A6AE-C2E39498DC43@gmail.com> References: <355F2859-E22A-4442-A6AE-C2E39498DC43@gmail.com> Message-ID: On Apr 16, 2010, at 8:07 AM, Nicholas Wieland wrote: > Hi *, > I need to test cookie creation with rspec and using Rack::Test, but for some reason I'm not able to pair the real app that creates a cookie with the rspec tests. > The spec is like this: > > it "should authenticate using cookies" do > user = Factory.create :user > remember_token = Charon.make_remember_token > set_cookie "warden=#{ remember_token }" > user.update :remember_token => remember_token > post '/authenticate' > last_request.env[ 'warden' ].should be_authenticated > end > > Inside the main app I set the cookie like: > > if !request.cookies[ 'warden' ] > response.set_cookie( 'warden', :value => env[ 'warden' ].user.remember_token ) > end > > I can clearly see it works when testing manually. For some reasons, the rspec cookie is different than the one set by the app. > > Is someone trying something similar and can share some code ? I think that the problem is in Rack::Test but I'm not sure and I'm not able prove it. What versions of rails, rspec, rspec-rails, ruby, etc? Where does this spec live? From douglas at theros.info Fri Apr 16 09:29:36 2010 From: douglas at theros.info (Douglas Campos) Date: Fri, 16 Apr 2010 10:29:36 -0300 Subject: [rspec-users] Skipping Slow Specs Message-ID: Hi! I have a slow spec. Before anyone shouts, it's an service integration test, that needs the server available. As I don't have this server near every time, is there an easy way to skip this spec during rake spec / autospec? I ended renaming the file, which is IMO, ugly. Any ideas? -- Douglas Campos (qmx) +55 11 6762 5959 -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicholas.wieland at gmail.com Fri Apr 16 09:49:16 2010 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Fri, 16 Apr 2010 15:49:16 +0200 Subject: [rspec-users] Rack::Test + cookies + rspec In-Reply-To: References: <355F2859-E22A-4442-A6AE-C2E39498DC43@gmail.com> Message-ID: On Apr 16, 2010, at 3:12 PM, David Chelimsky wrote: > On Apr 16, 2010, at 8:07 AM, Nicholas Wieland wrote: > > What versions of rails, rspec, rspec-rails, ruby, etc? > > Where does this spec live? It's sinatra 1.0, not rails. ruby 1.8.7 (2010-01-10 patchlevel 249) rspec (1.3.0) rack-test (0.5.3) rack (1.1.0) ngw -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Apr 16 10:20:59 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 16 Apr 2010 09:20:59 -0500 Subject: [rspec-users] Rack::Test + cookies + rspec In-Reply-To: References: <355F2859-E22A-4442-A6AE-C2E39498DC43@gmail.com> Message-ID: On Apr 16, 2010, at 8:49 AM, Nicholas Wieland wrote: > On Apr 16, 2010, at 3:12 PM, David Chelimsky wrote: > >> On Apr 16, 2010, at 8:07 AM, Nicholas Wieland wrote: >> >> What versions of rails, rspec, rspec-rails, ruby, etc? >> >> Where does this spec live? > > It's sinatra 1.0, not rails. In which case this is probably not an rspec problem. Where is the set_cookie method defined in this example (from your earlier post in this thread)? it "should authenticate using cookies" do user = Factory.create :user remember_token = Charon.make_remember_token set_cookie "warden=#{ remember_token }" user.update :remember_token => remember_token post '/authenticate' last_request.env[ 'warden' ].should be_authenticated end Also, can you try the same example using test/unit? Do you get the same result? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Apr 16 10:30:50 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 16 Apr 2010 09:30:50 -0500 Subject: [rspec-users] Skipping Slow Specs In-Reply-To: References: Message-ID: On Apr 16, 2010, at 8:29 AM, Douglas Campos wrote: > Hi! > > I have a slow spec. Before anyone shouts, it's an service integration test, that needs the server available. As I don't have this server near every time, is there an easy way to skip this spec during rake spec / autospec? I ended renaming the file, which is IMO, ugly. > > Any ideas? rspec-2 offers filtering, but rspec-1 does not. If you're using rspec-2, you can do this: it "does something expensive", :slow => true do ... end Rspec.configure do |c| c.exclusion_filter = {:slow => true} end HTH, David From benjamin.lovell at gmail.com Fri Apr 16 10:59:40 2010 From: benjamin.lovell at gmail.com (Ben Lovell) Date: Fri, 16 Apr 2010 15:59:40 +0100 Subject: [rspec-users] Rack::Test + cookies + rspec In-Reply-To: References: <355F2859-E22A-4442-A6AE-C2E39498DC43@gmail.com> Message-ID: Try: post 'whatever', {}, {'rack.session' => {:something=>'value'}} To put things through the session with rack test/sinatra. Sent from my iPhone On 16 Apr 2010, at 15:20, David Chelimsky wrote: > On Apr 16, 2010, at 8:49 AM, Nicholas Wieland wrote: > >> On Apr 16, 2010, at 3:12 PM, David Chelimsky wrote: >> >>> On Apr 16, 2010, at 8:07 AM, Nicholas Wieland wrote: >>> >>> What versions of rails, rspec, rspec-rails, ruby, etc? >>> >>> Where does this spec live? >> >> It's sinatra 1.0, not rails. > > In which case this is probably not an rspec problem. Where is the set_cookie method defined in this example (from your earlier post in this thread)? > > it "should authenticate using cookies" do > user =Factory.create :user > remember_token = Charon.make_remember_token > set_cookie "warden=#{ remember_token }" > user.update :remember_token => remember_token > post '/authenticate' > last_request.env[ 'warden' ].should be_authenticated > end > > Also, can you try the same example using test/unit? Do you get the same result? > _______________________________________________ > 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 phillipkoebbe at gmail.com Fri Apr 16 11:14:04 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Fri, 16 Apr 2010 10:14:04 -0500 Subject: [rspec-users] Spec templates In-Reply-To: References: <4BC777F8.7040601@gmail.com> Message-ID: <4BC87EBC.4010404@gmail.com> > You could always define your own generators with your own templates. > I'd probably try that first and see how well it works. > > Cheers, > -foca > That's a good idea, foca. Thanks. I'll give it a try. Peace, Phillip From benjamin.lovell at gmail.com Fri Apr 16 12:08:14 2010 From: benjamin.lovell at gmail.com (Ben Lovell) Date: Fri, 16 Apr 2010 17:08:14 +0100 Subject: [rspec-users] Rack::Test + cookies + rspec In-Reply-To: References: <355F2859-E22A-4442-A6AE-C2E39498DC43@gmail.com> Message-ID: On 16 April 2010 15:59, Ben Lovell wrote: > Try: > > post 'whatever', {}, {'rack.session' => {:something=>'value'}} > > To put things through the session with rack test/sinatra. > > Sent from my iPhone > > Hmm, hold up, that isn't what you asked for :) You have to remember that the default Rack::Test::CookieJar#[] only returns cookies that exactly match the domain and path of the current request so be sure to check there first. > On 16 Apr 2010, at 15:20, David Chelimsky wrote: > > On Apr 16, 2010, at 8:49 AM, Nicholas Wieland wrote: > > On Apr 16, 2010, at 3:12 PM, David Chelimsky wrote: > > On Apr 16, 2010, at 8:07 AM, Nicholas Wieland wrote: > > What versions of rails, rspec, rspec-rails, ruby, etc? > > Where does this spec live? > > > It's sinatra 1.0, not rails. > > > In which case this is probably not an rspec problem. Where is the > set_cookie method defined in this example (from your earlier post in this > thread)? > > it "should authenticate using cookies" do > user =Factory.create :user > remember_token = Charon.make_remember_token > set_cookie "warden=#{ remember_token }" > user.update :remember_token => remember_token > post '/authenticate' > last_request.env[ 'warden' ].should be_authenticated > end > > Also, can you try the same example using test/unit? Do you get the same > result? > > _______________________________________________ > > 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 scott at railsnewbie.com Fri Apr 16 14:54:42 2010 From: scott at railsnewbie.com (Scott Taylor) Date: Fri, 16 Apr 2010 14:54:42 -0400 Subject: [rspec-users] Writing rails plugins In-Reply-To: References: Message-ID: On Apr 16, 2010, at 8:15 AM, Nicholas Wieland wrote: > Hi *, > I'm trying to write a plugin to integrate my SSO server into my rails app. > I'm finding the whole process quite difficult, I'm still blocked at configuring rspec, and the lack of documentation is not helping. > I've put this inside my /vendor/plugins/foobar/spec/spec_helper.rb I like garlic for testing plugins against (different) versions of rails: http://github.com/ianwhite/garlic Here's a project that's using it (for reference): http://github.com/markaby/markaby Scott > > ENV["RAILS_ENV"] = "test" > require File.dirname(__FILE__) + "/../../../../config/environment" > require 'spec' > require 'spec/rails' > > of course it will break up when I will package the plugin as a gem, the path to the environment variable will be different. > My question is more about best practices I guess, I would like to know how people includes rspec in a plugin that could be installed both inside /vendor/plugins (useful also during development time) and as a gem. I've seen some plugins (restful_authentication for example) provide an --rspec option to write all specs directly into RAILS_ROOT/spec, but it seems rather suboptimal, especially because plugins are not using this with consistence. > Someone has any experience ? > > TIA, > ngw > _______________________________________________ > 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 tim at wanlord.com Sat Apr 17 10:42:19 2010 From: tim at wanlord.com (Tim Riendeau) Date: Sat, 17 Apr 2010 10:42:19 -0400 Subject: [rspec-users] Rails 3, Rspec 2, Autotest In-Reply-To: <1fe754a00478376a73632b794f3c9f43@ruby-forum.com> References: <1fe754a00478376a73632b794f3c9f43@ruby-forum.com> Message-ID: I am having similar issue getting this working. I am running rails3.beta3 with ruby 1.8.7. I followed http://gist.github.com/365816 and I get the following: loading autotest/rails_rspec2 Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. I uninstalled and reinstalled the ZenTest & autotest gems with no luck. The same thing occurs in other rails3 apps. Any help would be much appreciated --Tim On Apr 15, 2010, at 11:40 AM, Mark Pittillo wrote: > Trying to set up a Rails 3 project with RSpec and Autotest. I followed > these steps exactly: > > http://gist.github.com/365816 > > But when I start up autotest, I get: > > $ autotest > loading autotest/rails > style: Rails > > instead of: > > $ autotest > loading autotest/rails_rspec2 > style: RailsRspec2 > > And autotest doesn't seem to do anything. Any idea what's happening? > I'm using Ruby 1.9.2-head in rvm. Relevant gems: > > autotest (4.2.9) > autotest-rails (4.1.0) > rspec (2.0.0.beta.6) > rspec-core (2.0.0.beta.6) > rspec-expectations (2.0.0.beta.6) > rspec-mocks (2.0.0.beta.6) > rspec-rails (2.0.0.beta.6) > ZenTest (4.3.1) > > > Thanks a lot for any help. > Mark > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3814 bytes Desc: not available URL: From dchelimsky at gmail.com Sat Apr 17 11:10:18 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 17 Apr 2010 10:10:18 -0500 Subject: [rspec-users] Rails 3, Rspec 2, Autotest In-Reply-To: References: <1fe754a00478376a73632b794f3c9f43@ruby-forum.com> Message-ID: On Apr 17, 2010, at 9:42 AM, Tim Riendeau wrote: > I am having similar issue getting this working. I am running rails3.beta3 with ruby 1.8.7. I followed http://gist.github.com/365816 and I get the following: > > loading autotest/rails_rspec2 > Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. > > I uninstalled and reinstalled the ZenTest & autotest gems with no luck. The same thing occurs in other rails3 apps. > > Any help would be much appreciated I just modified the gist slightly. It looks like rubygems won't find rspec-rails-2.0.0.beta.7 if we ask for ">= 2.0.0.beta". Anyhow, if I follow the setup in http://gist.github.com/365816, it works for me with ruby 1.8.7. > > --Tim > > On Apr 15, 2010, at 11:40 AM, Mark Pittillo wrote: > >> Trying to set up a Rails 3 project with RSpec and Autotest. I followed >> these steps exactly: >> >> http://gist.github.com/365816 >> >> But when I start up autotest, I get: >> >> $ autotest >> loading autotest/rails >> style: Rails >> >> instead of: >> >> $ autotest >> loading autotest/rails_rspec2 >> style: RailsRspec2 >> >> And autotest doesn't seem to do anything. Any idea what's happening? >> I'm using Ruby 1.9.2-head in rvm. Relevant gems: >> >> autotest (4.2.9) >> autotest-rails (4.1.0) >> rspec (2.0.0.beta.6) >> rspec-core (2.0.0.beta.6) >> rspec-expectations (2.0.0.beta.6) >> rspec-mocks (2.0.0.beta.6) >> rspec-rails (2.0.0.beta.6) >> ZenTest (4.3.1) >> >> >> Thanks a lot for any help. >> Mark >> -- >> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Mark.Nijhof at Cre8iveThought.com Thu Apr 15 19:39:23 2010 From: Mark.Nijhof at Cre8iveThought.com (Mark Nijhof) Date: Thu, 15 Apr 2010 16:39:23 -0700 (PDT) Subject: [rspec-users] Mocking question Message-ID: <15cd13e7-9e75-4833-b042-a34a41237eb3@y14g2000yqm.googlegroups.com> Hi, I am working on creating something that will monitor some files and do something when they are changed. I am using FSSM for the actual monitoring. Now I want to verify that it gets initialized with the correct parameters: @monitor.path path do glob = filter end So below is my mock setup: def setup_monitor_mock mock_monitor = mock('monitor') #mock_monitor.should_receive(:path).with(".") FSSM::Monitor.stub!(:new).and_return(mock_monitor) mock_monitor end But the problem is that I don't know how to verify the values for path and filter that are used to setup the monitor are correct. I saw some older posts about the same topic, but I couldn't find something definitive. I hope I explained myself correctly. -Mark From dchelimsky at gmail.com Sun Apr 18 12:06:37 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 18 Apr 2010 11:06:37 -0500 Subject: [rspec-users] Mocking question In-Reply-To: <15cd13e7-9e75-4833-b042-a34a41237eb3@y14g2000yqm.googlegroups.com> References: <15cd13e7-9e75-4833-b042-a34a41237eb3@y14g2000yqm.googlegroups.com> Message-ID: On Thu, Apr 15, 2010 at 6:39 PM, Mark Nijhof wrote: > Hi, > > I am working on creating something that will monitor some files and do > something when they are changed. I am using FSSM for the actual > monitoring. Now I want to verify that it gets initialized with the > correct parameters: > > @monitor.path path do > ? ?glob = filter > end > > So below is my mock setup: > > def setup_monitor_mock > ?mock_monitor = mock('monitor') > ?#mock_monitor.should_receive(:path).with(".") > > ?FSSM::Monitor.stub!(:new).and_return(mock_monitor) > > ?mock_monitor > end > > But the problem is that I don't know how to verify the values for path > and filter that are used to setup the monitor are correct. I saw some > older posts about the same topic, but I couldn't find something > definitive. > > I hope I explained myself correctly. I wouldn't use a mock for this. Take a look at FSSM's own specs: http://github.com/ttilley/fssm/blob/master/spec/path_spec.rb. They just query the monitor object to make sure it's configured correctly. I'd do something like that in this case. HTH, David From mguterl at gmail.com Sun Apr 18 12:30:15 2010 From: mguterl at gmail.com (Michael Guterl) Date: Sun, 18 Apr 2010 12:30:15 -0400 Subject: [rspec-users] Rails 3, Rspec 2, Autotest In-Reply-To: References: <1fe754a00478376a73632b794f3c9f43@ruby-forum.com> Message-ID: On Sat, Apr 17, 2010 at 11:10 AM, David Chelimsky wrote: > On Apr 17, 2010, at 9:42 AM, Tim Riendeau wrote: > > I am having similar issue getting this working. I am running rails3.beta3 > with ruby 1.8.7. I followed http://gist.github.com/365816 and I get the > following: > > loading autotest/rails_rspec2 > Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. > > I uninstalled and reinstalled the ZenTest & autotest gems with no luck. The > same thing occurs in other rails3 apps. > > Any help would be much appreciated > > > I just modified the gist slightly. It looks like rubygems won't find > rspec-rails-2.0.0.beta.7 if we ask for ">= 2.0.0.beta". Anyhow, if I follow > the setup in?http://gist.github.com/365816, it works for me with ruby 1.8.7. > Using 1.9.2-head and following the steps in the updated gist I am seeing the same behavior that Mark is reporting. michaelguterl at carini ~/code/example$ autotest loading autotest/rails style: Rails -------------------------------------------------------------------------------- Best, Michael Guterl From tim at wanlord.com Sun Apr 18 12:46:47 2010 From: tim at wanlord.com (Tim Riendeau) Date: Sun, 18 Apr 2010 12:46:47 -0400 Subject: [rspec-users] Rails 3, Rspec 2, Autotest In-Reply-To: References: <1fe754a00478376a73632b794f3c9f43@ruby-forum.com> Message-ID: <5DE68901-5DFC-4945-9FA3-F48E9F1548DF@wanlord.com> I am still not able to get this going either using 1.8.7 or ruby 1.9.2 Macintosh-7:example tim$ autotest loading autotest/rails_rspec2 Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. Macintosh-7:example tim$ rvm use ruby-head Using ruby head Macintosh-7:example tim$ autotest loading autotest/rails style: Rails I am assuming its something particular to my systems but have not been able to isolate it. Any thoughts as to how i might debug or isolate the dependency? --Tim On Apr 18, 2010, at 12:30 PM, Michael Guterl wrote: > On Sat, Apr 17, 2010 at 11:10 AM, David Chelimsky wrote: >> On Apr 17, 2010, at 9:42 AM, Tim Riendeau wrote: >> >> I am having similar issue getting this working. I am running rails3.beta3 >> with ruby 1.8.7. I followed http://gist.github.com/365816 and I get the >> following: >> >> loading autotest/rails_rspec2 >> Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. >> >> I uninstalled and reinstalled the ZenTest & autotest gems with no luck. The >> same thing occurs in other rails3 apps. >> >> Any help would be much appreciated >> >> >> I just modified the gist slightly. It looks like rubygems won't find >> rspec-rails-2.0.0.beta.7 if we ask for ">= 2.0.0.beta". Anyhow, if I follow >> the setup in http://gist.github.com/365816, it works for me with ruby 1.8.7. >> > Using 1.9.2-head and following the steps in the updated gist I am > seeing the same behavior that Mark is reporting. > > michaelguterl at carini ~/code/example$ autotest > loading autotest/rails > style: Rails > > > -------------------------------------------------------------------------------- > > Best, > Michael Guterl > _______________________________________________ > 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: smime.p7s Type: application/pkcs7-signature Size: 3814 bytes Desc: not available URL: From mguterl at gmail.com Sun Apr 18 12:52:29 2010 From: mguterl at gmail.com (Michael Guterl) Date: Sun, 18 Apr 2010 12:52:29 -0400 Subject: [rspec-users] Rails 3, Rspec 2, Autotest In-Reply-To: References: <1fe754a00478376a73632b794f3c9f43@ruby-forum.com> Message-ID: On Sun, Apr 18, 2010 at 12:30 PM, Michael Guterl wrote: > On Sat, Apr 17, 2010 at 11:10 AM, David Chelimsky wrote: >> On Apr 17, 2010, at 9:42 AM, Tim Riendeau wrote: >> >> I am having similar issue getting this working. I am running rails3.beta3 >> with ruby 1.8.7. I followed http://gist.github.com/365816 and I get the >> following: >> >> loading autotest/rails_rspec2 >> Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. >> >> I uninstalled and reinstalled the ZenTest & autotest gems with no luck. The >> same thing occurs in other rails3 apps. >> >> Any help would be much appreciated >> >> >> I just modified the gist slightly. It looks like rubygems won't find >> rspec-rails-2.0.0.beta.7 if we ask for ">= 2.0.0.beta". Anyhow, if I follow >> the setup in?http://gist.github.com/365816, it works for me with ruby 1.8.7. >> > Using 1.9.2-head and following the steps in the updated gist I am > seeing the same behavior that Mark is reporting. > > michaelguterl at carini ~/code/example$ autotest > loading autotest/rails > style: Rails > > > -------------------------------------------------------------------------------- > This looks to be a bug with autotest and 1.9.2 as I was able to get everything working fine with 1.8.7. >From within the project directory in 1.8.7 Autotest.autodiscover # => ["rails", "rspec2"] from within the project directory in 1.9.2 Autotest.autodiscover # => ["rails"] Best, Michael Guterl From mguterl at gmail.com Sun Apr 18 13:09:52 2010 From: mguterl at gmail.com (Michael Guterl) Date: Sun, 18 Apr 2010 13:09:52 -0400 Subject: [rspec-users] Rails 3, Rspec 2, Autotest In-Reply-To: References: <1fe754a00478376a73632b794f3c9f43@ruby-forum.com> Message-ID: On Sun, Apr 18, 2010 at 12:52 PM, Michael Guterl wrote: > On Sun, Apr 18, 2010 at 12:30 PM, Michael Guterl wrote: >> On Sat, Apr 17, 2010 at 11:10 AM, David Chelimsky wrote: >>> On Apr 17, 2010, at 9:42 AM, Tim Riendeau wrote: >>> >>> I am having similar issue getting this working. I am running rails3.beta3 >>> with ruby 1.8.7. I followed http://gist.github.com/365816 and I get the >>> following: >>> >>> loading autotest/rails_rspec2 >>> Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. >>> >>> I uninstalled and reinstalled the ZenTest & autotest gems with no luck. The >>> same thing occurs in other rails3 apps. >>> >>> Any help would be much appreciated >>> >>> >>> I just modified the gist slightly. It looks like rubygems won't find >>> rspec-rails-2.0.0.beta.7 if we ask for ">= 2.0.0.beta". Anyhow, if I follow >>> the setup in?http://gist.github.com/365816, it works for me with ruby 1.8.7. >>> >> Using 1.9.2-head and following the steps in the updated gist I am >> seeing the same behavior that Mark is reporting. >> >> michaelguterl at carini ~/code/example$ autotest >> loading autotest/rails >> style: Rails >> >> >> -------------------------------------------------------------------------------- >> > This looks to be a bug with autotest and 1.9.2 as I was able to get > everything working fine with 1.8.7. > > From within the project directory in 1.8.7 > > Autotest.autodiscover # => ["rails", "rspec2"] > > from within the project directory in 1.9.2 > > Autotest.autodiscover # => ["rails"] > Digging even further, this happens because in Ruby 1.9.2 the current directory is not added to $LOAD_PATH which results in Gem.find_files("autotest/discover") not finding the autotest/discover.rb in RAILS_ROOT. I believe this is a bug in autotest and I have filed a report here: http://rubyforge.org/tracker/index.php?func=detail&aid=28113&group_id=419&atid=1678 Best, Michael Guterl From rick.denatale at gmail.com Mon Apr 19 11:46:08 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 19 Apr 2010 11:46:08 -0400 Subject: [rspec-users] Anyone used RSpec to write specs for rake tasks? Message-ID: I released a new gem this past weekend which adds a new rake task for Jeweler to generate a release announcement. I was lazy and didn't write any specs, mostly because I couldn't quickly come up with a reasonably way to write a spec for a rake task. I was wondering if anyone had done some kind of testing harness for Rake tasks with RSpec. I tried googling but kept coming up with stuff about using the rake tasks provided by RSpec. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From mailinglists at patmaddox.com Mon Apr 19 17:13:25 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Mon, 19 Apr 2010 14:13:25 -0700 Subject: [rspec-users] Anyone used RSpec to write specs for rake tasks? In-Reply-To: References: Message-ID: Put the interesting bits in a basic Ruby class and test that, then make the Rake tasks a very thin layer over the class. On Apr 19, 2010, at 8:46 AM, Rick DeNatale wrote: > I released a new gem this past weekend which adds a new rake task for > Jeweler to generate a release announcement. > > I was lazy and didn't write any specs, mostly because I couldn't > quickly come up with a reasonably way to write a spec for a rake task. > > I was wondering if anyone had done some kind of testing harness for > Rake tasks with RSpec. I tried googling but kept coming up with stuff > about using the rake tasks provided by RSpec. > > -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Github: http://github.com/rubyredrick > Twitter: @RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From hooligan495 at gmail.com Mon Apr 19 17:50:03 2010 From: hooligan495 at gmail.com (Jay McGaffigan) Date: Mon, 19 Apr 2010 17:50:03 -0400 Subject: [rspec-users] Anyone used RSpec to write specs for rake tasks? In-Reply-To: References: Message-ID: <5E2D6CAC-9A4D-47FD-872C-E43155D5F97A@gmail.com> In the source for rspec there is an spectask class and spectask_spec spec for it. That might give you what you are looking for Jay On Apr 19, 2010, at 5:13 PM, Pat Maddox wrote: > Put the interesting bits in a basic Ruby class and test that, then > make the Rake tasks a very thin layer over the class. > > > On Apr 19, 2010, at 8:46 AM, Rick DeNatale wrote: > >> I released a new gem this past weekend which adds a new rake task for >> Jeweler to generate a release announcement. >> >> I was lazy and didn't write any specs, mostly because I couldn't >> quickly come up with a reasonably way to write a spec for a rake >> task. >> >> I was wondering if anyone had done some kind of testing harness for >> Rake tasks with RSpec. I tried googling but kept coming up with >> stuff >> about using the rake tasks provided by RSpec. >> >> -- >> Rick DeNatale >> >> Blog: http://talklikeaduck.denhaven2.com/ >> Github: http://github.com/rubyredrick >> Twitter: @RickDeNatale >> WWR: http://www.workingwithrails.com/person/9021-rick-denatale >> LinkedIn: http://www.linkedin.com/in/rickdenatale >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From nick at deadorange.com Tue Apr 20 08:33:17 2010 From: nick at deadorange.com (Nick Hoffman) Date: Tue, 20 Apr 2010 08:33:17 -0400 Subject: [rspec-users] Speccing the creation of a singleton resource Message-ID: Hey guys. I'm writing a Rails gem that's used by controllers. The gem creates a singleton resource at run-time, along the lines of: controller_name = ...dynamically generated... ActionController::Routing::Routes.draw do |map| map.resource controller_name, :only => :show end I'm trying to figure out how to spec the creation of the singleton resource. The best that I've come up with so far is checking that a route exists: ActionController::Routing::Routes.routes.last.defaults[:controller].should == controller_name.to_s However, that doesn't test whether or not it's a singleton resource. Any suggestions? Thanks, Nick From ed.howland at gmail.com Tue Apr 20 14:33:28 2010 From: ed.howland at gmail.com (Ed Howland) Date: Tue, 20 Apr 2010 14:33:28 -0400 Subject: [rspec-users] Cucumber vs, RSpec Message-ID: Please forgive the x-post. I just got back from the Great Lakes Ruby Bash. They had several good presentations, two specific to BDD and Cucumber. I also talked to several CEOs and devs afterwards, and the overall takeaway I gathered was a shift to less RSpec and more Cucumber. Some people even claimed a 90/10 split (cukes/specs) on current projects. This was surorising to me and not at all how I worked up to this point. I was more 20/80. I usually cuked a feature, then spec'ed the code to make the cuke work. Each release had some new features and specs for all the underlying code. Apparently, the feeling is that you should do all your main thrusts with Cucumber and use RSpec for edge cases. The theory is that you can change out all the underlying code and the cukes still pass. What is the communities consensus on this? Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From msassak at gmail.com Tue Apr 20 14:57:07 2010 From: msassak at gmail.com (Mike Sassak) Date: Tue, 20 Apr 2010 14:57:07 -0400 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: On Tue, Apr 20, 2010 at 2:33 PM, Ed Howland wrote: > Please forgive the x-post. > > I just got back from the Great Lakes Ruby Bash. They had several good > presentations, two specific to BDD and Cucumber. I also talked to > several CEOs and devs afterwards, and the overall takeaway I gathered > was a shift to less RSpec and more Cucumber. Some people even claimed > a 90/10 split (cukes/specs) on current projects. > > This was surorising to me and not at all how I worked up to this > point. I was more 20/80. I usually cuked a feature, then spec'ed the > code to make the cuke work. Each release had some new features and > specs for all the underlying code. Apparently, the feeling is that you > should do all your main thrusts with Cucumber and use RSpec for edge > cases. The theory is that you can change out all the underlying code > and the cukes still pass. > > What is the communities consensus on this? > Hi Ed, I was also at the GLRB, and was a bit aghast at the claim that you should have a 90/10 split between cukes and rspec. In my experience, favoring Cucumber so heavily invites developing code that behaves correctly, but is messy and difficult to change. I would go so far as to claim there is a positive correlation between over-reliance on Cucumber features and rampant violations of the SOLID principles. Cucumber simply doesn't excel at enforcing simple, testable contracts between the objects in your code base the way RSpec does. The result is that your code is hard to refactor and change, which from the developer's point of view is practically the whole reason to maintain a good test suite in the first place. This isn't the whole of the story by any means, but I think it's close to the place to start. $0.02 Mike P.S. Hello RSpec Group! What's the etiquette here for cross-posting? > > Cheers, > Ed > > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > > -- > You received this message because you are subscribed to the Google Groups "Cukes" group. > To post to this group, send email to cukes at googlegroups.com. > To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. > For more options, visit this group at http://groups.google.com/group/cukes?hl=en. > > From dchelimsky at gmail.com Tue Apr 20 15:05:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Apr 2010 14:05:03 -0500 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: On Apr 20, 2010, at 1:57 PM, Mike Sassak wrote: > On Tue, Apr 20, 2010 at 2:33 PM, Ed Howland wrote: >> Please forgive the x-post. >> >> I just got back from the Great Lakes Ruby Bash. They had several good >> presentations, two specific to BDD and Cucumber. I also talked to >> several CEOs and devs afterwards, and the overall takeaway I gathered >> was a shift to less RSpec and more Cucumber. Some people even claimed >> a 90/10 split (cukes/specs) on current projects. >> >> This was surorising to me and not at all how I worked up to this >> point. I was more 20/80. I usually cuked a feature, then spec'ed the >> code to make the cuke work. Each release had some new features and >> specs for all the underlying code. Apparently, the feeling is that you >> should do all your main thrusts with Cucumber and use RSpec for edge >> cases. The theory is that you can change out all the underlying code >> and the cukes still pass. >> >> What is the communities consensus on this? >> > > Hi Ed, > > I was also at the GLRB, and was a bit aghast at the claim that you > should have a 90/10 split between cukes and rspec. In my experience, > favoring Cucumber so heavily invites developing code that behaves > correctly, but is messy and difficult to change. I would go so far as > to claim there is a positive correlation between over-reliance on > Cucumber features and rampant violations of the SOLID principles. > Cucumber simply doesn't excel at enforcing simple, testable contracts > between the objects in your code base the way RSpec does. The result > is that your code is hard to refactor and change, which from the > developer's point of view is practically the whole reason to maintain > a good test suite in the first place. This isn't the whole of the > story by any means, but I think it's close to the place to start. > > $0.02 > Mike > > P.S. Hello RSpec Group! What's the etiquette here for cross-posting? Etiquette, schmetiquette :) I'd say, in the interest of keeping the thread in one place, post to the rspec list w/ a link to this thread in the cuke group and invite folks to join the convo. Cheers, David > >> >> Cheers, >> Ed >> >> Ed Howland >> http://greenprogrammer.wordpress.com >> http://twitter.com/ed_howland >> >> -- >> You received this message because you are subscribed to the Google Groups "Cukes" group. >> To post to this group, send email to cukes at googlegroups.com. >> To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/cukes?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups "Cukes" group. > To post to this group, send email to cukes at googlegroups.com. > To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. > For more options, visit this group at http://groups.google.com/group/cukes?hl=en. > From Robert.Hanson at Calabrio.com Tue Apr 20 14:43:49 2010 From: Robert.Hanson at Calabrio.com (Robert Hanson) Date: Tue, 20 Apr 2010 13:43:49 -0500 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: <7A4A1C3056D0EB46BD030FF762B77BFA14076FB50B@calex01.Calabrio.ld> With Cucumber, you can't possibly specify tests for all the corner cases. That's what your rspecs (unit tests) are for. -----Original Message----- From: cukes at googlegroups.com [mailto:cukes at googlegroups.com] On Behalf Of Ed Howland Sent: Tuesday, April 20, 2010 1:33 PM To: rspec-users; cukes at googlegroups.com Subject: [Cucumber:4066] Cucumber vs, RSpec Please forgive the x-post. I just got back from the Great Lakes Ruby Bash. They had several good presentations, two specific to BDD and Cucumber. I also talked to several CEOs and devs afterwards, and the overall takeaway I gathered was a shift to less RSpec and more Cucumber. Some people even claimed a 90/10 split (cukes/specs) on current projects. This was surorising to me and not at all how I worked up to this point. I was more 20/80. I usually cuked a feature, then spec'ed the code to make the cuke work. Each release had some new features and specs for all the underlying code. Apparently, the feeling is that you should do all your main thrusts with Cucumber and use RSpec for edge cases. The theory is that you can change out all the underlying code and the cukes still pass. What is the communities consensus on this? Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland -- You received this message because you are subscribed to the Google Groups "Cukes" group. To post to this group, send email to cukes at googlegroups.com. To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. For more options, visit this group at http://groups.google.com/group/cukes?hl=en. From dchelimsky at gmail.com Tue Apr 20 15:48:02 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 20 Apr 2010 14:48:02 -0500 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: On Tue, Apr 20, 2010 at 2:05 PM, David Chelimsky wrote: > > On Apr 20, 2010, at 1:57 PM, Mike Sassak wrote: > >> On Tue, Apr 20, 2010 at 2:33 PM, Ed Howland wrote: >>> Please forgive the x-post. >>> >>> I just got back from the Great Lakes Ruby Bash. They had several good >>> presentations, two specific to BDD and Cucumber. I also talked to >>> several CEOs and devs afterwards, and the overall takeaway I gathered >>> was a shift to less RSpec and more Cucumber. Some people even claimed >>> a 90/10 split (cukes/specs) on current projects. >>> >>> This was surorising to me and not at all how I worked up to this >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the >>> code to make the cuke work. Each release had some new features and >>> specs for all the underlying code. Apparently, the feeling is that you >>> should do all your main thrusts with Cucumber and use RSpec for edge >>> cases. The theory is that you can change out all the underlying code >>> and the cukes still pass. >>> >>> What is the communities consensus on this? >>> >> >> Hi Ed, >> >> I was also at the GLRB, and was a bit aghast at the claim that you >> should have a 90/10 split between cukes and rspec. In my experience, >> favoring Cucumber so heavily invites developing code that behaves >> correctly, but is messy and difficult to change. I would go so far as >> to claim there is a positive correlation between over-reliance on >> Cucumber features and rampant violations of the SOLID principles. >> Cucumber simply doesn't excel at enforcing simple, testable contracts >> between the objects in your code base the way RSpec does. The result >> is that your code is hard to refactor and change, which from the >> developer's point of view is practically the whole reason to maintain >> a good test suite in the first place. This isn't the whole of the >> story by any means, but I think it's close to the place to start. >> >> $0.02 >> Mike >> >> P.S. Hello RSpec Group! What's the etiquette here for cross-posting? > > Etiquette, schmetiquette :) > > I'd say, in the interest of keeping the thread in one place, post to the rspec list w/ a link to this thread in the cuke group and invite folks to join the convo. I answered this before I realized you were already x-posting :) I think this conversation is relevant to both communities, so let's keep it going in both. > > Cheers, > David > >> >>> >>> Cheers, >>> Ed >>> >>> Ed Howland >>> http://greenprogrammer.wordpress.com >>> http://twitter.com/ed_howland >>> >>> -- >>> You received this message because you are subscribed to the Google Groups "Cukes" group. >>> To post to this group, send email to cukes at googlegroups.com. >>> To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. >>> For more options, visit this group at http://groups.google.com/group/cukes?hl=en. >>> >>> >> >> -- >> You received this message because you are subscribed to the Google Groups "Cukes" group. >> To post to this group, send email to cukes at googlegroups.com. >> To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/cukes?hl=en. >> > > From joe at josephwilk.net Tue Apr 20 15:58:17 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Tue, 20 Apr 2010 20:58:17 +0100 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: On Tue, Apr 20, 2010 at 8:05 PM, David Chelimsky wrote: > > On Apr 20, 2010, at 1:57 PM, Mike Sassak wrote: > >> On Tue, Apr 20, 2010 at 2:33 PM, Ed Howland wrote: >>> Please forgive the x-post. >>> >>> I just got back from the Great Lakes Ruby Bash. They had several good >>> presentations, two specific to BDD and Cucumber. I also talked to >>> several CEOs and devs afterwards, and the overall takeaway I gathered >>> was a shift to less RSpec and more Cucumber. Some people even claimed >>> a 90/10 split (cukes/specs) on current projects. >>> >>> This was surorising to me and not at all how I worked up to this >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the >>> code to make the cuke work. Each release had some new features and >>> specs for all the underlying code. Apparently, the feeling is that you >>> should do all your main thrusts with Cucumber and use RSpec for edge >>> cases. The theory is that you can change out all the underlying code >>> and the cukes still pass. >>> >>> What is the communities consensus on this? >>> >> >> Hi Ed, >> >> I was also at the GLRB, and was a bit aghast at the claim that you >> should have a 90/10 split between cukes and rspec. In my experience, >> favoring Cucumber so heavily invites developing code that behaves >> correctly, but is messy and difficult to change. I would go so far as >> to claim there is a positive correlation between over-reliance on >> Cucumber features and rampant violations of the SOLID principles. >> Cucumber simply doesn't excel at enforcing simple, testable contracts >> between the objects in your code base the way RSpec does. The result >> is that your code is hard to refactor and change, which from the >> developer's point of view is practically the whole reason to maintain >> a good test suite in the first place. This isn't the whole of the >> story by any means, but I think it's close to the place to start. First up Rspec and Cucumber are just tools, they can be used in many ways. So this answer belies my personal usage of these tools. A big issue for me is scaling tests. Cucumber tests tend to be end-to-end tests so they cut through the whole application stack. This is great in terms of freeing you up to refactor the heck out of your code without having to rewrite lots of tests. But end-to-end tests are slow, now this can be ok if you working on a small project. In smaller projects I've worked on I've only used Cukes. In others I've only tended to drop down to Rspec (which I very much use as a specing/unit testing tool) when there is complexity, I feel the feedback loop is not fast enough or I need to explore the design more. If however you are working on an application thats long lived or lives in a domain where you're dealing with asynchronous issues (such as javascript or evented systems) I've seen people very quickly hit 1 hour + test build time. Primarily because they have such a heavy focus on Cucumber or end-to-end tests. So one direction to help avoid this is to exploring a few good and bad paths with cucumber but having more detailed spec coverage. This would help you manage better test build times. The other option is to not worry about heavy Cukes usage and throw lots of hardware at the scaling problem. Ok for some, but it does end-up costing lots. One other point is that Cucumber for me is part of a process about facilitating conversations with non techs. So as a developer its not always a question of how many Cukes do I think I should have. Its a question of how much does the stakeholders who I'm writing the software want. Do they want to edit and write the cukes with us? Will they go back and reference the cukes in the future? So in conclusion my split on Cucumbers/Rspecs really depends on the context of the project. An important factor to think about is scaling when you only use end-to-end tests. Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 >> >> $0.02 >> Mike >> >> P.S. Hello RSpec Group! What's the etiquette here for cross-posting? > > Etiquette, schmetiquette :) > > I'd say, in the interest of keeping the thread in one place, post to the rspec list w/ a link to this thread in the cuke group and invite folks to join the convo. > > Cheers, > David > >> >>> >>> Cheers, >>> Ed >>> >>> Ed Howland >>> http://greenprogrammer.wordpress.com >>> http://twitter.com/ed_howland >>> >>> -- >>> You received this message because you are subscribed to the Google Groups "Cukes" group. >>> To post to this group, send email to cukes at googlegroups.com. >>> To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. >>> For more options, visit this group at http://groups.google.com/group/cukes?hl=en. >>> >>> >> >> -- >> You received this message because you are subscribed to the Google Groups "Cukes" group. >> To post to this group, send email to cukes at googlegroups.com. >> To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/cukes?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups "Cukes" group. > To post to this group, send email to cukes at googlegroups.com. > To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. > For more options, visit this group at http://groups.google.com/group/cukes?hl=en. > > From jgoodsen at radsoft.com Tue Apr 20 16:12:30 2010 From: jgoodsen at radsoft.com (John Goodsen) Date: Tue, 20 Apr 2010 16:12:30 -0400 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: Watch Ben Mabey's slides and talk at Ruby Conf on outside in development with Cucumber. It positions rspec and cucumber properly On Tue, Apr 20, 2010 at 3:58 PM, Joseph Wilk wrote: > On Tue, Apr 20, 2010 at 8:05 PM, David Chelimsky > wrote: > > > > On Apr 20, 2010, at 1:57 PM, Mike Sassak wrote: > > > >> On Tue, Apr 20, 2010 at 2:33 PM, Ed Howland > wrote: > >>> Please forgive the x-post. > >>> > >>> I just got back from the Great Lakes Ruby Bash. They had several good > >>> presentations, two specific to BDD and Cucumber. I also talked to > >>> several CEOs and devs afterwards, and the overall takeaway I gathered > >>> was a shift to less RSpec and more Cucumber. Some people even claimed > >>> a 90/10 split (cukes/specs) on current projects. > >>> > >>> This was surorising to me and not at all how I worked up to this > >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the > >>> code to make the cuke work. Each release had some new features and > >>> specs for all the underlying code. Apparently, the feeling is that you > >>> should do all your main thrusts with Cucumber and use RSpec for edge > >>> cases. The theory is that you can change out all the underlying code > >>> and the cukes still pass. > >>> > >>> What is the communities consensus on this? > >>> > >> > >> Hi Ed, > >> > >> I was also at the GLRB, and was a bit aghast at the claim that you > >> should have a 90/10 split between cukes and rspec. In my experience, > >> favoring Cucumber so heavily invites developing code that behaves > >> correctly, but is messy and difficult to change. I would go so far as > >> to claim there is a positive correlation between over-reliance on > >> Cucumber features and rampant violations of the SOLID principles. > >> Cucumber simply doesn't excel at enforcing simple, testable contracts > >> between the objects in your code base the way RSpec does. The result > >> is that your code is hard to refactor and change, which from the > >> developer's point of view is practically the whole reason to maintain > >> a good test suite in the first place. This isn't the whole of the > >> story by any means, but I think it's close to the place to start. > > First up Rspec and Cucumber are just tools, they can be used in many > ways. So this answer belies my personal usage of these tools. > > A big issue for me is scaling tests. Cucumber tests tend to be > end-to-end tests so they cut through the whole application stack. This > is great in terms of freeing you up to refactor the heck out of your > code without having to rewrite lots of tests. But end-to-end tests are > slow, now this can be ok if you working on a small project. In smaller > projects I've worked on I've only used Cukes. In others I've only > tended to drop down to Rspec (which I very much use as a specing/unit > testing tool) when there is complexity, I feel the feedback loop is > not fast enough or I need to explore the design more. > > If however you are working on an application thats long lived or lives > in a domain where you're dealing with asynchronous issues (such as > javascript or evented systems) I've seen people very quickly hit 1 > hour + test build time. Primarily because they have such a heavy focus > on Cucumber or end-to-end tests. So one direction to help avoid this > is to exploring a few good and bad paths with cucumber but having more > detailed spec coverage. This would help you manage better test build > times. > > The other option is to not worry about heavy Cukes usage and throw > lots of hardware at the scaling problem. Ok for some, but it does > end-up costing lots. > > One other point is that Cucumber for me is part of a process about > facilitating conversations with non techs. So as a developer its not > always a question of how many Cukes do I think I should have. Its a > question of how much does the stakeholders who I'm writing the > software want. Do they want to edit and write the cukes with us? Will > they go back and reference the cukes in the future? > > So in conclusion my split on Cucumbers/Rspecs really depends on the > context of the project. An important factor to think about is scaling > when you only use end-to-end tests. > > Joseph Wilk > http://blog.josephwilk.net > http://www.songkick.com > +44 (0)7812 816431 > > >> > >> $0.02 > >> Mike > >> > >> P.S. Hello RSpec Group! What's the etiquette here for cross-posting? > > > > Etiquette, schmetiquette :) > > > > I'd say, in the interest of keeping the thread in one place, post to the > rspec list w/ a link to this thread in the cuke group and invite folks to > join the convo. > > > > Cheers, > > David > > > >> > >>> > >>> Cheers, > >>> Ed > >>> > >>> Ed Howland > >>> http://greenprogrammer.wordpress.com > >>> http://twitter.com/ed_howland > >>> > >>> -- > >>> You received this message because you are subscribed to the Google > Groups "Cukes" group. > >>> To post to this group, send email to cukes at googlegroups.com. > >>> To unsubscribe from this group, send email to > cukes+unsubscribe at googlegroups.com . > >>> For more options, visit this group at > http://groups.google.com/group/cukes?hl=en. > >>> > >>> > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "Cukes" group. > >> To post to this group, send email to cukes at googlegroups.com. > >> To unsubscribe from this group, send email to > cukes+unsubscribe at googlegroups.com . > >> For more options, visit this group at > http://groups.google.com/group/cukes?hl=en. > >> > > > > -- > > You received this message because you are subscribed to the Google Groups > "Cukes" group. > > To post to this group, send email to cukes at googlegroups.com. > > To unsubscribe from this group, send email to > cukes+unsubscribe at googlegroups.com . > > For more options, visit this group at > http://groups.google.com/group/cukes?hl=en. > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- John Goodsen RADSoft / Better Software Faster jgoodsen at radsoft.com Lean/Agile/XP/Scrum Coaching and Training http://www.radsoft.com Ruby on Rails and Java Solutions -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at josephwilk.net Tue Apr 20 16:14:30 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Tue, 20 Apr 2010 21:14:30 +0100 Subject: [rspec-users] Anyone used RSpec to write specs for rake tasks? In-Reply-To: References: Message-ID: <4BCE0B26.1000004@josephwilk.net> On 19/04/2010 22:13, Pat Maddox wrote: > Put the interesting bits in a basic Ruby class and test that, then make the Rake tasks a very thin layer over the class. > > > On Apr 19, 2010, at 8:46 AM, Rick DeNatale wrote: > > >> I released a new gem this past weekend which adds a new rake task for >> Jeweler to generate a release announcement. >> >> I was lazy and didn't write any specs, mostly because I couldn't >> quickly come up with a reasonably way to write a spec for a rake task. >> >> I was wondering if anyone had done some kind of testing harness for >> Rake tasks with RSpec. I tried googling but kept coming up with stuff >> about using the rake tasks provided by RSpec. >> I tend to do what Pat suggested with Rspec. In Cucumber I've had cases where I really wanted to run a rake task directly. This was pretty easy: http://gist.github.com/373000 -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 >> -- >> Rick DeNatale >> >> Blog: http://talklikeaduck.denhaven2.com/ >> Github: http://github.com/rubyredrick >> Twitter: @RickDeNatale >> WWR: http://www.workingwithrails.com/person/9021-rick-denatale >> LinkedIn: http://www.linkedin.com/in/rickdenatale >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- Joseph Wilk http://blog.josephwilk.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at josephwilk.net Tue Apr 20 16:24:32 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Tue, 20 Apr 2010 21:24:32 +0100 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: On Tue, Apr 20, 2010 at 9:12 PM, John Goodsen wrote: > Watch Ben Mabey's slides and talk at Ruby Conf on outside in development > with Cucumber.? It positions rspec and cucumber properly I used an analogy at Scotland on Rails that might be helpful. I was thinking about Rspec and Cucumber in terms of planning a driving route between London and Edinburgh. Cucumber would test the output, the value: "Then I am in Edinburgh" So while driving, knowing I'm not in Edinburgh yet is not really not that much help for me. Its my end value but the feedback loop is too big. I could drive to Edinburgh via the USA and still achieve the value. I like to think of Rspec as a route planner which is giving me continuous feedback, helping me improve the design of my route. The feedback loop is fast and it helps me get to my value. You checkout the presentation: http://blog.josephwilk.net/ruby/outside-in-development-with-cucumber-and-rspec.html -- Joseph Wilk http://blog.josephwilk.net http://www.songkick.com +44 (0)7812 816431 > > On Tue, Apr 20, 2010 at 3:58 PM, Joseph Wilk wrote: >> >> On Tue, Apr 20, 2010 at 8:05 PM, David Chelimsky >> wrote: >> > >> > On Apr 20, 2010, at 1:57 PM, Mike Sassak wrote: >> > >> >> On Tue, Apr 20, 2010 at 2:33 PM, Ed Howland >> >> wrote: >> >>> Please forgive the x-post. >> >>> >> >>> I just got back from the Great Lakes Ruby Bash. They had several good >> >>> presentations, two specific to BDD and Cucumber. I also talked to >> >>> several CEOs and devs afterwards, and the overall takeaway I gathered >> >>> was a shift to less RSpec and more Cucumber. Some people even claimed >> >>> a 90/10 split (cukes/specs) on current projects. >> >>> >> >>> This was surorising to me and not at all how I worked up to this >> >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the >> >>> code to make the cuke work. Each release had some new features and >> >>> specs for all the underlying code. Apparently, the feeling is that you >> >>> should do all your main thrusts with Cucumber and use RSpec for edge >> >>> cases. The theory is that you can change out all the underlying code >> >>> and the cukes still pass. >> >>> >> >>> What is the communities consensus on this? >> >>> >> >> >> >> Hi Ed, >> >> >> >> I was also at the GLRB, and was a bit aghast at the claim that you >> >> should have a 90/10 split between cukes and rspec. In my experience, >> >> favoring Cucumber so heavily invites developing code that behaves >> >> correctly, but is messy and difficult to change. I would go so far as >> >> to claim there is a positive correlation between over-reliance on >> >> Cucumber features and rampant violations of the SOLID principles. >> >> Cucumber simply doesn't excel at enforcing simple, testable contracts >> >> between the objects in your code base the way RSpec does. The result >> >> is that your code is hard to refactor and change, which from the >> >> developer's point of view is practically the whole reason to maintain >> >> a good test suite in the first place. This isn't the whole of the >> >> story by any means, but I think it's close to the place to start. >> >> First up Rspec and Cucumber are just tools, they can be used in many >> ways. So this answer belies my personal usage of these tools. >> >> A big issue for me is scaling tests. Cucumber tests tend to be >> end-to-end tests so they cut through the whole application stack. This >> is great in terms of freeing you up to refactor the heck out of your >> code without having to rewrite lots of tests. But end-to-end tests are >> slow, now this can be ok if you working on a small project. In smaller >> projects I've worked on I've only used Cukes. In others I've only >> tended to drop down to Rspec (which I very much use as a specing/unit >> testing tool) when there is complexity, I feel the feedback loop is >> not fast enough or I need to explore the design more. >> >> If however you are working on an application thats long lived or lives >> in a domain where you're dealing with asynchronous issues (such as >> javascript or evented systems) I've seen people very quickly hit 1 >> hour + test build time. Primarily because they have such a heavy focus >> on Cucumber or end-to-end tests. So one direction to help avoid this >> is to exploring a few good and bad paths with cucumber but having more >> detailed spec coverage. This would help you manage better test build >> times. >> >> The other option is to not worry about heavy Cukes usage and throw >> lots of hardware at the scaling problem. Ok for some, but it does >> end-up costing lots. >> >> One other point is that Cucumber for me is part of a process about >> facilitating conversations with non techs. So as a developer its not >> always a question of how many Cukes do I think I should have. Its a >> question of how much does the stakeholders who I'm writing the >> software want. Do they want to edit and write the cukes with us? Will >> they go back and reference the cukes in the future? >> >> So in conclusion my split on Cucumbers/Rspecs really depends on the >> context of the project. An important factor to think about is scaling >> when you only use end-to-end tests. >> >> Joseph Wilk >> http://blog.josephwilk.net >> http://www.songkick.com >> +44 (0)7812 816431 >> >> >> >> >> $0.02 >> >> Mike >> >> >> >> P.S. Hello RSpec Group! What's the etiquette here for cross-posting? >> > >> > Etiquette, schmetiquette :) >> > >> > I'd say, in the interest of keeping the thread in one place, post to the >> > rspec list w/ a link to this thread in the cuke group and invite folks to >> > join the convo. >> > >> > Cheers, >> > David >> > >> >> >> >>> >> >>> Cheers, >> >>> Ed >> >>> >> >>> Ed Howland >> >>> http://greenprogrammer.wordpress.com >> >>> http://twitter.com/ed_howland >> >>> >> >>> -- >> >>> You received this message because you are subscribed to the Google >> >>> Groups "Cukes" group. >> >>> To post to this group, send email to cukes at googlegroups.com. >> >>> To unsubscribe from this group, send email to >> >>> cukes+unsubscribe at googlegroups.com. >> >>> For more options, visit this group at >> >>> http://groups.google.com/group/cukes?hl=en. >> >>> >> >>> >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> >> Groups "Cukes" group. >> >> To post to this group, send email to cukes at googlegroups.com. >> >> To unsubscribe from this group, send email to >> >> cukes+unsubscribe at googlegroups.com. >> >> For more options, visit this group at >> >> http://groups.google.com/group/cukes?hl=en. >> >> >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups "Cukes" group. >> > To post to this group, send email to cukes at googlegroups.com. >> > To unsubscribe from this group, send email to >> > cukes+unsubscribe at googlegroups.com. >> > For more options, visit this group at >> > http://groups.google.com/group/cukes?hl=en. >> > >> > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > John Goodsen ? ? ? ? ? ? ? ? RADSoft / Better Software Faster > jgoodsen at radsoft.com ? ? ? ? ? ?Lean/Agile/XP/Scrum Coaching and Training > http://www.radsoft.com ? ? ? ? ?Ruby on Rails and Java Solutions > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lucas.prim at gmail.com Tue Apr 20 16:30:29 2010 From: lucas.prim at gmail.com (Lucas Prim) Date: Tue, 20 Apr 2010 17:30:29 -0300 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: For me, cukes acts more as an acceptance test that tells me when to stop the development and release a feature as rspec goes down to the internals of the app in order to make sure everything works ok. In this context, I think there is no magic recipe that tells you how much cucumber code you should have on your project in contrast with rspec code. It all depends on the context you're working. Complex enterprise applications require extensive unit testing and there i wouldn't wanna miss rspec. Im my personal experience, i use cucumber-only for CRUDS and other down-to-the-basic stuff and whenever i need to develop a challenging chunk of code i firstly spec it with rspec and then make sure it works with the rest by running the cucumber feature. Sometimes it's like 500 lines of rspec and 30 lines of cucumber. It has been working very well! Lucas Prim lucas.prim at gmail.com +55 (48) 9921-9303 +55 (48) 3334-1979 On Tue, Apr 20, 2010 at 5:12 PM, John Goodsen wrote: > Watch Ben Mabey's slides and talk at Ruby Conf on outside in development > with Cucumber. It positions rspec and cucumber properly > > On Tue, Apr 20, 2010 at 3:58 PM, Joseph Wilk wrote: > >> On Tue, Apr 20, 2010 at 8:05 PM, David Chelimsky >> wrote: >> > >> > On Apr 20, 2010, at 1:57 PM, Mike Sassak wrote: >> > >> >> On Tue, Apr 20, 2010 at 2:33 PM, Ed Howland >> wrote: >> >>> Please forgive the x-post. >> >>> >> >>> I just got back from the Great Lakes Ruby Bash. They had several good >> >>> presentations, two specific to BDD and Cucumber. I also talked to >> >>> several CEOs and devs afterwards, and the overall takeaway I gathered >> >>> was a shift to less RSpec and more Cucumber. Some people even claimed >> >>> a 90/10 split (cukes/specs) on current projects. >> >>> >> >>> This was surorising to me and not at all how I worked up to this >> >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the >> >>> code to make the cuke work. Each release had some new features and >> >>> specs for all the underlying code. Apparently, the feeling is that you >> >>> should do all your main thrusts with Cucumber and use RSpec for edge >> >>> cases. The theory is that you can change out all the underlying code >> >>> and the cukes still pass. >> >>> >> >>> What is the communities consensus on this? >> >>> >> >> >> >> Hi Ed, >> >> >> >> I was also at the GLRB, and was a bit aghast at the claim that you >> >> should have a 90/10 split between cukes and rspec. In my experience, >> >> favoring Cucumber so heavily invites developing code that behaves >> >> correctly, but is messy and difficult to change. I would go so far as >> >> to claim there is a positive correlation between over-reliance on >> >> Cucumber features and rampant violations of the SOLID principles. >> >> Cucumber simply doesn't excel at enforcing simple, testable contracts >> >> between the objects in your code base the way RSpec does. The result >> >> is that your code is hard to refactor and change, which from the >> >> developer's point of view is practically the whole reason to maintain >> >> a good test suite in the first place. This isn't the whole of the >> >> story by any means, but I think it's close to the place to start. >> >> First up Rspec and Cucumber are just tools, they can be used in many >> ways. So this answer belies my personal usage of these tools. >> >> A big issue for me is scaling tests. Cucumber tests tend to be >> end-to-end tests so they cut through the whole application stack. This >> is great in terms of freeing you up to refactor the heck out of your >> code without having to rewrite lots of tests. But end-to-end tests are >> slow, now this can be ok if you working on a small project. In smaller >> projects I've worked on I've only used Cukes. In others I've only >> tended to drop down to Rspec (which I very much use as a specing/unit >> testing tool) when there is complexity, I feel the feedback loop is >> not fast enough or I need to explore the design more. >> >> If however you are working on an application thats long lived or lives >> in a domain where you're dealing with asynchronous issues (such as >> javascript or evented systems) I've seen people very quickly hit 1 >> hour + test build time. Primarily because they have such a heavy focus >> on Cucumber or end-to-end tests. So one direction to help avoid this >> is to exploring a few good and bad paths with cucumber but having more >> detailed spec coverage. This would help you manage better test build >> times. >> >> The other option is to not worry about heavy Cukes usage and throw >> lots of hardware at the scaling problem. Ok for some, but it does >> end-up costing lots. >> >> One other point is that Cucumber for me is part of a process about >> facilitating conversations with non techs. So as a developer its not >> always a question of how many Cukes do I think I should have. Its a >> question of how much does the stakeholders who I'm writing the >> software want. Do they want to edit and write the cukes with us? Will >> they go back and reference the cukes in the future? >> >> So in conclusion my split on Cucumbers/Rspecs really depends on the >> context of the project. An important factor to think about is scaling >> when you only use end-to-end tests. >> >> Joseph Wilk >> http://blog.josephwilk.net >> http://www.songkick.com >> +44 (0)7812 816431 >> >> >> >> >> $0.02 >> >> Mike >> >> >> >> P.S. Hello RSpec Group! What's the etiquette here for cross-posting? >> > >> > Etiquette, schmetiquette :) >> > >> > I'd say, in the interest of keeping the thread in one place, post to the >> rspec list w/ a link to this thread in the cuke group and invite folks to >> join the convo. >> > >> > Cheers, >> > David >> > >> >> >> >>> >> >>> Cheers, >> >>> Ed >> >>> >> >>> Ed Howland >> >>> http://greenprogrammer.wordpress.com >> >>> http://twitter.com/ed_howland >> >>> >> >>> -- >> >>> You received this message because you are subscribed to the Google >> Groups "Cukes" group. >> >>> To post to this group, send email to cukes at googlegroups.com. >> >>> To unsubscribe from this group, send email to >> cukes+unsubscribe at googlegroups.com >> . >> >>> For more options, visit this group at >> http://groups.google.com/group/cukes?hl=en. >> >>> >> >>> >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups "Cukes" group. >> >> To post to this group, send email to cukes at googlegroups.com. >> >> To unsubscribe from this group, send email to >> cukes+unsubscribe at googlegroups.com >> . >> >> For more options, visit this group at >> http://groups.google.com/group/cukes?hl=en. >> >> >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups "Cukes" group. >> > To post to this group, send email to cukes at googlegroups.com. >> > To unsubscribe from this group, send email to >> cukes+unsubscribe at googlegroups.com >> . >> > For more options, visit this group at >> http://groups.google.com/group/cukes?hl=en. >> > >> > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > John Goodsen RADSoft / Better Software Faster > jgoodsen at radsoft.com Lean/Agile/XP/Scrum Coaching and Training > http://www.radsoft.com Ruby on Rails and Java Solutions > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Apr 21 02:59:55 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 21 Apr 2010 07:59:55 +0100 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: <92A52DD6-7454-43DA-8C57-1A48D11717B7@mattwynne.net> Here's an idea relevant to this discussion that came up last week when I did a talk on Cucumber to ScotRUG. Paul Wilson was describing how he used to use Fit, back in the day, for testing at different levels in the stack rather than just for end- to-end tests. The idea was to surface the tests at the same customer- facing level, but steer them at the *appropriate* level in the stack, depending on what was being tested. So for example in the canonical problem of roles with different access rights to a system, you could write the nice readable tabulated test in Cucumber, but instead of running that cuke against the whole stack, stepping through the login form etc, you could just run it against whatever class is responsible for managing roles. In order for this to work, you'd need to write the Cukes in a declarative style, avoiding too much detail about exactly how you'd carry out the step. This allows the same step to be run against the whole stack or a focussed piece of the system instead. I tend to think now that this is just good practice anyway. This isn't something I've tried myself, but I imagine it means you'd still get the benefit of customer-readable tests that validate the behaviour of the system, but running potentially much faster than if they were end-to-end tests. I can see a disadvantage that it could make the test code more complex and confusing. You'd obviously still need a few end-to-end tests in order to make sure the whole thing still wired up together. On a team with good customer-developer trust, I'd probably just use RSpec for these kind of tests, but it's interesting to try thinking about cucumber as The Place where business rules are surfaced. Anyone tried doing anything like this? On 20 Apr 2010, at 19:33, Ed Howland wrote: > Please forgive the x-post. > > I just got back from the Great Lakes Ruby Bash. They had several good > presentations, two specific to BDD and Cucumber. I also talked to > several CEOs and devs afterwards, and the overall takeaway I gathered > was a shift to less RSpec and more Cucumber. Some people even claimed > a 90/10 split (cukes/specs) on current projects. > > This was surorising to me and not at all how I worked up to this > point. I was more 20/80. I usually cuked a feature, then spec'ed the > code to make the cuke work. Each release had some new features and > specs for all the underlying code. Apparently, the feeling is that you > should do all your main thrusts with Cucumber and use RSpec for edge > cases. The theory is that you can change out all the underlying code > and the cukes still pass. > > What is the communities consensus on this? > > > Cheers, > Ed > > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > > -- > You received this message because you are subscribed to the Google > Groups "Cukes" group. > To post to this group, send email to cukes at googlegroups.com. > To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com > . > For more options, visit this group at http://groups.google.com/group/cukes?hl=en > . > cheers, Matt http://mattwynne.net +447974 430184 From mailinglists at patmaddox.com Wed Apr 21 19:05:31 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 21 Apr 2010 16:05:31 -0700 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> Cucumber features are the best tool I know of for capturing requirements from my customer. RSpec specs are the best tool I know of for communicating intent and gauging code quality among the developer team. I'm not sure how exactly you're quantifying a 90/10 or 80/20 split. I would expect that there would be a lot of overlap in coverage. That is, any given line of code is likely to have some cucumber and some rspec coverage. Personally I shoot for 100% RSpec coverage, and Cucumber is based entirely on what my customer wants. If we discuss a new feature or bug fix and they feel I know exactly what they're talking about and don't need a cucumber test for it, I don't write the cucumber test. Cukes are for teasing out requirements, which is most important when there's domain complexity that I don't understand, because I'm a programmer and not a domain expert. Every line of code I write gets RSpec coverage. That's how I personally feel confident that my code does what I think it does, and also helps me keep my dependencies under control. It's true that you can change out all the underlying code and cucumber tests still pass. But you should be able to change out a lot of code and have your specs still pass, as well. If you're changing the API then some specs might no longer be valid, or need to be moved, or whatever. That's just a part of refactoring. Although to be honest I think focused specs help me refactor more than other people, because I take really small steps when I refactor. When most people "refactor" they tear out a bunch of shit and see if it still works. Cucumber tests tend to take longer because they're written at a much higher level. That requires more setup, and more steps through the codebase. For that reason, Cucumber isn't particularly good at giving me rapid feedback. I want feedback in 10 seconds rather than 10 minutes. The best mantra I have for using Cucumber & RSpec in harmony is, "RSpec lets me know my code works right, Cucumber lets me know my code is doing the right work." Pat On Apr 20, 2010, at 11:33 AM, Ed Howland wrote: > Please forgive the x-post. > > I just got back from the Great Lakes Ruby Bash. They had several good > presentations, two specific to BDD and Cucumber. I also talked to > several CEOs and devs afterwards, and the overall takeaway I gathered > was a shift to less RSpec and more Cucumber. Some people even claimed > a 90/10 split (cukes/specs) on current projects. > > This was surorising to me and not at all how I worked up to this > point. I was more 20/80. I usually cuked a feature, then spec'ed the > code to make the cuke work. Each release had some new features and > specs for all the underlying code. Apparently, the feeling is that you > should do all your main thrusts with Cucumber and use RSpec for edge > cases. The theory is that you can change out all the underlying code > and the cukes still pass. > > What is the communities consensus on this? > > > Cheers, > Ed > > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > > -- > You received this message because you are subscribed to the Google Groups "Cukes" group. > To post to this group, send email to cukes at googlegroups.com. > To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. > For more options, visit this group at http://groups.google.com/group/cukes?hl=en. > From spovich at gmail.com Wed Apr 21 19:13:59 2010 From: spovich at gmail.com (John Dell) Date: Wed, 21 Apr 2010 16:13:59 -0700 Subject: [rspec-users] how to --debug rspec2 w/rails3? Message-ID: I'm diving into rails3 and rspec2. Things are a bit rough.... New application using RVM w/ruby 1.8.7 p249, Rails (3.0.0.beta3), RSpec (2.0.0.beta.7), ruby-debug (0.10.3), ruby-debug-base (0.10.3) I created a .rspec file in my Rails.root with the following --debug --colour --format progress Then I add a 'debugger' statement in one of my .spec files, and run 'rake spec', I get the following: "debugger statement ignored, use -d or --debug option on rspec to enable debugging" Running "rspec -d ./spec/**" gives the same result. So, am I calling debugger wrong, or is it not working yet? Thanks! John -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Apr 21 19:24:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 21 Apr 2010 18:24:56 -0500 Subject: [rspec-users] how to --debug rspec2 w/rails3? In-Reply-To: References: Message-ID: On Wed, Apr 21, 2010 at 6:13 PM, John Dell wrote: > I'm diving into rails3 and rspec2.? Things are a bit rough.... > > New application using RVM w/ruby 1.8.7 p249, Rails (3.0.0.beta3), RSpec > (2.0.0.beta.7), ruby-debug (0.10.3), ruby-debug-base (0.10.3) > > I created a .rspec file in my Rails.root with the following > > --debug > --colour > --format progress > > Then I add a 'debugger' statement in one of my .spec files, and run 'rake > spec', I get the following: > > "debugger statement ignored, use -d or --debug option on rspec to enable > debugging" > > Running "rspec -d ./spec/**" gives the same result.? So, am I calling > debugger wrong, or is it not working yet? Looks like it's broken, as it should be working. Please do two things (I'm on my way out the door): 1. enter an issue at http://github.com/rspec/rspec-core/issues 2. try this: rdebug rspec ./spec > > Thanks! > John > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From spovich at gmail.com Wed Apr 21 19:41:50 2010 From: spovich at gmail.com (John Dell) Date: Wed, 21 Apr 2010 16:41:50 -0700 Subject: [rspec-users] how to --debug rspec2 w/rails3? In-Reply-To: References: Message-ID: On Wed, Apr 21, 2010 at 4:24 PM, David Chelimsky wrote: > Looks like it's broken, as it should be working. Please do two things > (I'm on my way out the door): > > 1. enter an issue at http://github.com/rspec/rspec-core/issues Done. http://github.com/rspec/rspec-core/issues/issue/24 > > 2. try this: > > rdebug rspec ./spec > Yep, that works fine. Thanks for your fast reply! John -------------- next part -------------- An HTML attachment was scrubbed... URL: From sgruhier at gmail.com Wed Apr 21 06:13:12 2010 From: sgruhier at gmail.com (seb) Date: Wed, 21 Apr 2010 03:13:12 -0700 (PDT) Subject: [rspec-users] request and cookies (rspec2) Message-ID: Hi How do I setg/get cookie value in rspec2? Thanks From msassak at gmail.com Thu Apr 22 01:26:50 2010 From: msassak at gmail.com (Mike Sassak) Date: Thu, 22 Apr 2010 01:26:50 -0400 Subject: [rspec-users] [Cucumber:4095] Cucumber vs, RSpec In-Reply-To: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> References: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> Message-ID: On Wed, Apr 21, 2010 at 7:05 PM, Pat Maddox wrote: > Cucumber features are the best tool I know of for capturing requirements from my customer. ?RSpec specs are the best tool I know of for communicating intent and gauging code quality among the developer team. > > I'm not sure how exactly you're quantifying a 90/10 or 80/20 split. ?I would expect that there would be a lot of overlap in coverage. ?That is, any given line of code is likely to have some cucumber and some rspec coverage. ?Personally I shoot for 100% RSpec coverage, and Cucumber is based entirely on what my customer wants. ?If we discuss a new feature or bug fix and they feel I know exactly what they're talking about and don't need a cucumber test for it, I don't write the cucumber test. ?Cukes are for teasing out requirements, which is most important when there's domain complexity that I don't understand, because I'm a programmer and not a domain expert. ?Every line of code I write gets RSpec coverage. ?That's how I personally feel confident that my code does what I think it does, and also helps me keep my dependencies under control. > > It's true that you can change out all the underlying code and cucumber tests still pass. ?But you should be able to change out a lot of code and have your specs still pass, as well. ?If you're changing the API then some specs might no longer be valid, or need to be moved, or whatever. ?That's just a part of refactoring. ?Although to be honest I think focused specs help me refactor more than other people, because I take really small steps when I refactor. ?When most people "refactor" they tear out a bunch of shit and see if it still works. > > Cucumber tests tend to take longer because they're written at a much higher level. ?That requires more setup, and more steps through the codebase. ?For that reason, Cucumber isn't particularly good at giving me rapid feedback. ?I want feedback in 10 seconds rather than 10 minutes. > > The best mantra I have for using Cucumber & RSpec in harmony is, "RSpec lets me know my code works right, Cucumber lets me know my code is doing the right work." > I don't think the percentage splits were meant quantitatively, but rather as a way of saying that integration/full-stack tests with Cucumber drastically reduce the need for RSpec or unit tests. I'm skeptical of such claims myself, and not only because I think Cucumber and RSpec are tools that target very different needs. I'm sure my own limitations as a developer have a lot to do with feeling this way, but leaning hard on integration tests reminds me of the Brian Kernighan quote about debugging being twice as hard as writing the program in the first place. Full-stack black box tests make it too easy for me to write overly-complex code and still have a system that satisfies the business rules. The idea of writing two sets of steps, one for integration and one for the domain is very intriguing, and one that I might try in the future, but I think that sidesteps the issue that prompted Ed's post in the first place. I think your mantra hits the nail on the head, but then I'm a sucker for a good chiasmus. :-) Mike > Pat > > > On Apr 20, 2010, at 11:33 AM, Ed Howland wrote: > >> Please forgive the x-post. >> >> I just got back from the Great Lakes Ruby Bash. They had several good >> presentations, two specific to BDD and Cucumber. I also talked to >> several CEOs and devs afterwards, and the overall takeaway I gathered >> was a shift to less RSpec and more Cucumber. Some people even claimed >> a 90/10 split (cukes/specs) on current projects. >> >> This was surorising to me and not at all how I worked up to this >> point. I was more 20/80. I usually cuked a feature, then spec'ed the >> code to make the cuke work. Each release had some new features and >> specs for all the underlying code. Apparently, the feeling is that you >> should do all your main thrusts with Cucumber and use RSpec for edge >> cases. The theory is that you can change out all the underlying code >> and the cukes still pass. >> >> What is the communities consensus on this? >> >> >> Cheers, >> Ed >> >> Ed Howland >> http://greenprogrammer.wordpress.com >> http://twitter.com/ed_howland >> >> -- >> You received this message because you are subscribed to the Google Groups "Cukes" group. >> To post to this group, send email to cukes at googlegroups.com. >> To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/cukes?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups "Cukes" group. > To post to this group, send email to cukes at googlegroups.com. > To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. > For more options, visit this group at http://groups.google.com/group/cukes?hl=en. > > From ben.rooney62 at googlemail.com Thu Apr 22 09:28:52 2010 From: ben.rooney62 at googlemail.com (ben rooney) Date: Thu, 22 Apr 2010 14:28:52 +0100 Subject: [rspec-users] File creation Message-ID: I have a model that generates the authorization_rules.rb for declarative_auth. I am not sure how I can go about testing the model - apart from anything I don't want my test to over-write the file - so, er, I am not quite sure how to go about it. I *could* have some sort of sniffer in my model to see if I am in the Test environment and generate a different file, but putting code into my model to pass tests doesn't seem a very, well, sensible thing to do. Anyone been there, done that? Ben From steve at steveklabnik.com Thu Apr 22 14:32:40 2010 From: steve at steveklabnik.com (Steve Klabnik) Date: Thu, 22 Apr 2010 14:32:40 -0400 Subject: [rspec-users] Spec-ing delayed_jobs in the future Message-ID: I've been looking into rspec-ing delayed_jobs lately, and I found a few resources on testing jobs that execute right away. But I couldn't find any that delt with testing a job that is delayed a week in the future, for example. Does anyone have any good resources on this? I'd appreciate it. Thanks, Steve -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Thu Apr 22 15:07:56 2010 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 22 Apr 2010 15:07:56 -0400 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: > I just got back from the Great Lakes Ruby Bash. They had several good > presentations, two specific to BDD and Cucumber. I also talked to > several CEOs and devs afterwards, and the overall takeaway I gathered > was a shift to less RSpec and more Cucumber. Some people even claimed > a 90/10 split (cukes/specs) on current projects. I spoke at the GLRB, specifically reflecting on my experience with BDD and outside-in development over the past few years, but I didn't attend the first half of the conference, so I'm not familiar with the other talks or comments made in those talks about a 90/10 split, or some of the other things Ed mentioned in original post. Ed, if you got any of this impression from me, please contact me off list. Below are my thoughts in general... > This was surorising to me and not at all how I worked up to this > point. I was more 20/80. I usually cuked a feature, then spec'ed the > code to make the cuke work. Each release had some new features and > specs for all the underlying code. Apparently, the feeling is that you > should do all your main thrusts with Cucumber and use RSpec for edge > cases. For me, Cucumber and RSpec fill different roles in my approach to software development. It's not really an either/or proposition. I do want a tool that supports high level plain text customer readable language which describes the application. I also want a tool to drive behaviour, interaction, and design of underlying components. These tools have different audiences and provide different types of value. There are times when I will use a Cucumber feature to drive the behaviour of the application and not drop down to RSpec. And there are times when I add change behaviour at a low-level where I do not expose a new Cucumber feature. This all depends on the system, what's currently in-place, what's being changed or added, etc. In my experience there are several parts of webapps which are extremely shallow and simplistic. There's not rich behaviour, interesting interactions, or really any complexities. It's just monotonous work (like CRUD, writing a basic RSS feed, etc.) In many cases, after an application has evolved to a certain point a lot of new features are simply re-using existing functionality you've already built. It's just being packaged differently to present information in another way or to provide downloadable reports, etc. This is another area where I may not drop down to RSpec, and I let Cucumber drive this behaviour. But I don't do this for everything. I do this when it makes sense. I'm not in the business of writing examples just for the sake of writing examples. They need to provide value. Example-driving code usually help drive behaviour because they support emergent design, provide regression, readability/maintainability. If these things are already handled, then I need to ask myself why I am writing the example. This is the case for a lot of vanilla Rails stuff. Rails has made decisions for you on the design (ie: how associations are defined), so you don't receive that value by example driving an association at a low level. If you are driving the feature from the outside-in with Cucumber then Cucumber will provide regression to ensure that association exists in the future. And since a declarative statement like "belongs_to" is not complex, does not drive design, and adding an example doesn't offer additional readability, why are people still writing specs around the association? I don't care how easy shoulda makes it to write, it doesn't mean it should be written. Knowing when to not use a tool is just as important as knowing how to use the tool. One thing I mentioned in my talk @ GLRB was that Cucumber provides implementation flexibility. This was in relation to my observation that example-driving code well (with tools like RSpec/etc) requires experience, courage, self-reflection, and willingness to change. A lot of folks don't have that experience. They want to do things well, but they're kind of guessing as they go. While I love apprenticeship, mentoring, and truly engaged/collaborative/thought-provoking teams, I realize not everyone is in these environments. I want to help folks to get some experience before making a commitment to a decision, I encourage folks to utilize spikes. Cucumber happens to act as a wonderful umbrella for folks to spike on lower level details so they can get feedback on if what they're thinking is moving them in the right direction. Spikes provide learning, they help folks obtain some more experience, and folks are ultimately able to make better decisions since spikes are focused on problems being solved now. It may not be the best decision in the universe, but making a better decision is usually much much better than making simply a uninformed decision which can easily lead to commitment. Spikes aren't only tied to implementation either, they can be an exploration for how you would go about writing a good example to describe and drive some behaviour. My intent for the statement about "Cucumber provides flexibility" wasn't to encourage folks to drop unit-level examples because they have supreme flexibility with Cucumber. It was to encourage folks to take a step back and explore with a spike what they're attempting to accomplish, so they can come back and make a better decision moving forward. I would love to rid the world of unnecessary examples, brittle examples, impossible to read/maintain examples. Spikes put folks in a better position to make bette decisions in that regard so I feel like my encouragement and observations are still accurate and relevant. And as Joseph said it's all project, client, and context specific. My 2 cents. :) -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Thu Apr 22 15:14:42 2010 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 22 Apr 2010 15:14:42 -0400 Subject: [rspec-users] [Cucumber:4095] Cucumber vs, RSpec In-Reply-To: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> References: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> Message-ID: On Wed, Apr 21, 2010 at 7:05 PM, Pat Maddox wrote: > Cucumber features are the best tool I know of for capturing requirements > from my customer. RSpec specs are the best tool I know of for communicating > intent and gauging code quality among the developer team. > > I'm not sure how exactly you're quantifying a 90/10 or 80/20 split. I > would expect that there would be a lot of overlap in coverage. That is, any > given line of code is likely to have some cucumber and some rspec coverage. > Personally I shoot for 100% RSpec coverage, and Cucumber is based entirely > on what my customer wants. If we discuss a new feature or bug fix and they > feel I know exactly what they're talking about and don't need a cucumber > test for it, I don't write the cucumber test. Cukes are for teasing out > requirements, which is most important when there's domain complexity that I > don't understand, because I'm a programmer and not a domain expert. Every > line of code I write gets RSpec coverage. That's how I personally feel > confident that my code does what I think it does, and also helps me keep my > dependencies under control. > > It's true that you can change out all the underlying code and cucumber > tests still pass. But you should be able to change out a lot of code and > have your specs still pass, as well. If you're changing the API then some > specs might no longer be valid, or need to be moved, or whatever. That's > just a part of refactoring. Although to be honest I think focused specs > help me refactor more than other people, because I take really small steps > when I refactor. When most people "refactor" they tear out a bunch of shit > and see if it still works. > > Cucumber tests tend to take longer because they're written at a much higher > level. That requires more setup, and more steps through the codebase. For > that reason, Cucumber isn't particularly good at giving me rapid feedback. > I want feedback in 10 seconds rather than 10 minutes. > > The best mantra I have for using Cucumber & RSpec in harmony is, "RSpec > lets me know my code works right, Cucumber lets me know my code is doing the > right work." > +1 -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephen.bannasch at deanbrook.org Thu Apr 22 15:29:58 2010 From: stephen.bannasch at deanbrook.org (Stephen Bannasch) Date: Thu, 22 Apr 2010 15:29:58 -0400 Subject: [rspec-users] running: 'rake spec' mixes ApplicationHelper into my ActiveRecord model instances Message-ID: When I run the a controllers spec test on it's own I get just what I expect. But when I run the same tests with: rake spec I get some strange errors because ApplicationHelper ends up getting mixed into my ActiveRecord model instances. Is this normal? It seems nutty to me -- maybe it's a problem just in my codebase. This is a rails 2.3.4 project using these versions of rspec and rspec-rails: $ gem list rspec *** LOCAL GEMS *** rspec (1.3.0) rspec-rails (1.3.2) This gist shows some details of the issue: http://gist.github.com/375634 The code is in the emb-test branch of http://github.com/stepheneb/rigse From spovich at gmail.com Thu Apr 22 18:11:23 2010 From: spovich at gmail.com (John Dell) Date: Thu, 22 Apr 2010 15:11:23 -0700 Subject: [rspec-users] rspec2 - set example as pending? Message-ID: I'm trying to mark an example as pending w/rspec2 & rails3, but I'm getting: Failure/Error: pending undefined local variable or method `pending' for # Is 'pending' pending for rspec2? ;-) Thanks, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From godfoca at gmail.com Thu Apr 22 18:19:42 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Thu, 22 Apr 2010 19:19:42 -0300 Subject: [rspec-users] rspec2 - set example as pending? In-Reply-To: References: Message-ID: Yeah, just that now you define your entire example as pending. So instead of: it "does something" do pending this_will_fail end You now do pending "does something" do this_will_fail end Cheers On Thu, Apr 22, 2010 at 7:11 PM, John Dell wrote: > I'm trying to mark an example as pending w/rspec2 & rails3, but I'm getting: > > Failure/Error: pending > undefined local variable or method `pending' for > # > > Is 'pending' pending for rspec2? ;-) > > Thanks, > John > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Apr 22 18:27:28 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 22 Apr 2010 17:27:28 -0500 Subject: [rspec-users] rspec2 - set example as pending? In-Reply-To: References: Message-ID: > > On Thu, Apr 22, 2010 at 7:11 PM, John Dell wrote: >> I'm trying to mark an example as pending w/rspec2 & rails3, but I'm getting: >> >> Failure/Error: pending >> undefined local variable or method `pending' for >> # >> >> Is 'pending' pending for rspec2? ;-) >> >> Thanks, >> John On Apr 22, 2010, at 5:19 PM, Nicol?s Sanguinetti wrote: > Yeah, just that now you define your entire example as pending. So instead of: > > it "does something" do > pending > this_will_fail > end > > You now do > > pending "does something" do > this_will_fail > end > > Cheers That's true as of 2.0.0.beta.7, but the next beta will support both forms: pending "example" do ... end AND it "does something" do pending end See http://github.com/rspec/rspec-core/issues/closed#issue/7 Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed.howland at gmail.com Thu Apr 22 18:32:03 2010 From: ed.howland at gmail.com (Ed Howland) Date: Thu, 22 Apr 2010 18:32:03 -0400 Subject: [rspec-users] [Cucumber:4066] Cucumber vs, RSpec In-Reply-To: References: Message-ID: +1 BTW, here is the URL for his talk: http://www.benmabey.com/2009/03/14/slides-from-outside-in-development-with-cucumber/ It is back in the webrat days (pre-capybara). And the World() method is simpler nowadays. Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland On Tue, Apr 20, 2010 at 4:12 PM, John Goodsen wrote: > Watch Ben Mabey's slides and talk at Ruby Conf on outside in development > with Cucumber.? It positions rspec and cucumber properly > > On Tue, Apr 20, 2010 at 3:58 PM, Joseph Wilk wrote: >> >> On Tue, Apr 20, 2010 at 8:05 PM, David Chelimsky >> wrote: >> > >> > On Apr 20, 2010, at 1:57 PM, Mike Sassak wrote: >> > >> >> On Tue, Apr 20, 2010 at 2:33 PM, Ed Howland >> >> wrote: >> >>> Please forgive the x-post. >> >>> >> >>> I just got back from the Great Lakes Ruby Bash. They had several good >> >>> presentations, two specific to BDD and Cucumber. I also talked to >> >>> several CEOs and devs afterwards, and the overall takeaway I gathered >> >>> was a shift to less RSpec and more Cucumber. Some people even claimed >> >>> a 90/10 split (cukes/specs) on current projects. >> >>> >> >>> This was surorising to me and not at all how I worked up to this >> >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the >> >>> code to make the cuke work. Each release had some new features and >> >>> specs for all the underlying code. Apparently, the feeling is that you >> >>> should do all your main thrusts with Cucumber and use RSpec for edge >> >>> cases. The theory is that you can change out all the underlying code >> >>> and the cukes still pass. >> >>> >> >>> What is the communities consensus on this? >> >>> >> >> >> >> Hi Ed, >> >> >> >> I was also at the GLRB, and was a bit aghast at the claim that you >> >> should have a 90/10 split between cukes and rspec. In my experience, >> >> favoring Cucumber so heavily invites developing code that behaves >> >> correctly, but is messy and difficult to change. I would go so far as >> >> to claim there is a positive correlation between over-reliance on >> >> Cucumber features and rampant violations of the SOLID principles. >> >> Cucumber simply doesn't excel at enforcing simple, testable contracts >> >> between the objects in your code base the way RSpec does. The result >> >> is that your code is hard to refactor and change, which from the >> >> developer's point of view is practically the whole reason to maintain >> >> a good test suite in the first place. This isn't the whole of the >> >> story by any means, but I think it's close to the place to start. >> >> First up Rspec and Cucumber are just tools, they can be used in many >> ways. So this answer belies my personal usage of these tools. >> >> A big issue for me is scaling tests. Cucumber tests tend to be >> end-to-end tests so they cut through the whole application stack. This >> is great in terms of freeing you up to refactor the heck out of your >> code without having to rewrite lots of tests. But end-to-end tests are >> slow, now this can be ok if you working on a small project. In smaller >> projects I've worked on I've only used Cukes. In others I've only >> tended to drop down to Rspec (which I very much use as a specing/unit >> testing tool) when there is complexity, I feel the feedback loop is >> not fast enough or I need to explore the design more. >> >> If however you are working on an application thats long lived or lives >> in a domain where you're dealing with asynchronous issues (such as >> javascript or evented systems) I've seen people very quickly hit 1 >> hour + test build time. Primarily because they have such a heavy focus >> on Cucumber or end-to-end tests. So one direction to help avoid this >> is to exploring a few good and bad paths with cucumber but having more >> detailed spec coverage. This would help you manage better test build >> times. >> >> The other option is to not worry about heavy Cukes usage and throw >> lots of hardware at the scaling problem. Ok for some, but it does >> end-up costing lots. >> >> One other point is that Cucumber for me is part of a process about >> facilitating conversations with non techs. So as a developer its not >> always a question of how many Cukes do I think I should have. Its a >> question of how much does the stakeholders who I'm writing the >> software want. Do they want to edit and write the cukes with us? Will >> they go back and reference the cukes in the future? >> >> So in conclusion my split on Cucumbers/Rspecs really depends on the >> context of the project. An important factor to think about is scaling >> when you only use end-to-end tests. >> >> Joseph Wilk >> http://blog.josephwilk.net >> http://www.songkick.com >> +44 (0)7812 816431 >> >> >> >> >> $0.02 >> >> Mike >> >> >> >> P.S. Hello RSpec Group! What's the etiquette here for cross-posting? >> > >> > Etiquette, schmetiquette :) >> > >> > I'd say, in the interest of keeping the thread in one place, post to the >> > rspec list w/ a link to this thread in the cuke group and invite folks to >> > join the convo. >> > >> > Cheers, >> > David >> > >> >> >> >>> >> >>> Cheers, >> >>> Ed >> >>> >> >>> Ed Howland >> >>> http://greenprogrammer.wordpress.com >> >>> http://twitter.com/ed_howland >> >>> >> >>> -- >> >>> You received this message because you are subscribed to the Google >> >>> Groups "Cukes" group. >> >>> To post to this group, send email to cukes at googlegroups.com. >> >>> To unsubscribe from this group, send email to >> >>> cukes+unsubscribe at googlegroups.com. >> >>> For more options, visit this group at >> >>> http://groups.google.com/group/cukes?hl=en. >> >>> >> >>> >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> >> Groups "Cukes" group. >> >> To post to this group, send email to cukes at googlegroups.com. >> >> To unsubscribe from this group, send email to >> >> cukes+unsubscribe at googlegroups.com. >> >> For more options, visit this group at >> >> http://groups.google.com/group/cukes?hl=en. >> >> >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups "Cukes" group. >> > To post to this group, send email to cukes at googlegroups.com. >> > To unsubscribe from this group, send email to >> > cukes+unsubscribe at googlegroups.com. >> > For more options, visit this group at >> > http://groups.google.com/group/cukes?hl=en. >> > >> > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > John Goodsen ? ? ? ? ? ? ? ? RADSoft / Better Software Faster > jgoodsen at radsoft.com ? ? ? ? ? ?Lean/Agile/XP/Scrum Coaching and Training > http://www.radsoft.com ? ? ? ? ?Ruby on Rails and Java Solutions > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From spovich at gmail.com Thu Apr 22 18:35:36 2010 From: spovich at gmail.com (John Dell) Date: Thu, 22 Apr 2010 15:35:36 -0700 Subject: [rspec-users] rspec2 - set example as pending? In-Reply-To: References: Message-ID: 2010/4/22 Nicol?s Sanguinetti > Yeah, just that now you define your entire example as pending. So instead > of: > > You now do > > pending "does something" do > this_will_fail > end > Thank you! I like it, very clean. Is that documented somehwere? I couldn't find it. John -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at patmaddox.com Fri Apr 23 00:40:54 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Thu, 22 Apr 2010 21:40:54 -0700 Subject: [rspec-users] [Cucumber:4144] Cucumber vs, RSpec In-Reply-To: <66A69281-DC00-4B3F-AE8C-797D5052E930@gmail.com> References: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> <66A69281-DC00-4B3F-AE8C-797D5052E930@gmail.com> Message-ID: <57AC02A0-9E45-490D-814C-CB40FC86BBC1@patmaddox.com> On Apr 22, 2010, at 9:57 AM, Zach Moazeni wrote: > I'll jump in here as I was one of the guys who presented a shift in my testing strategies at the Great Lakes Ruby Bash. > > To give some context, I've built projects that were very focused on isolation tests that used Rspec and Mocks to assert behavior. I do think there is merit in using BDD as a code-design tool, however I have also maintained large test suites that had more historical context than regression value. I consider this inside-out testing. Developing/Testing at the unit level and then bubbling out to an Acceptance test. > > I've been subtly migrating to what I consider outside-in testing, starting with Acceptance tests and then moving to a unit level if necessary. And as a result I've felt much better about the codebases (including the tests). Although I was getting a bit uneasy since I haven't heard of other developers experiencing similar pain points. Talking with a few developers at the Great Lakes Ruby Bash was really refreshing because not only did it sound like they had similar pains, but they were going down the same path I was. > > I was one of the guys who did a lightning talk on a library I'm working on (Harvested, a Ruby API wrapper for Harvest http://github.com/zmoazeni/harvested). And I do have a 90/10 split in Acceptance vs Unit with I'm cool with. I wasn't throwing out those numbers as what you should shoot for, but just anecdotal experience. > > I recognize that I may be criticized for writing untested code or that I'm disagreeing with BDD/TDD. I'm don't think I am. I feel I've gone way too far on the side of testing, and after reflecting on my experiences with past projects feeling the pendulum swinging back towards a healthy balance. > > Some specific opinions I have are: I don't test Controllers or Views or Rails-DSL validations (e.g. validates_presence_of, validates_uniqueness_of). I do test "interesting validations", and instead of testing "interesting controller actions" I prefer to refactor that so the controller is very minimalist. The same goes for views, I pull away anything that looks "interesting" in a view. This is totally subjective, so I don't have a great way to clarify what I mean by "interesting". > > I don't disagree with mocks, but I would rather have a "boxed functional test" (sorry running out of language here) that test how multiple objects behave together and use mocks/stubs to form the boundaries of the tests. > > Hopefully this doesn't come across as another post of "I don't see the point of testing", or "Mocks are silly". Additionally, I'm a bit nervous posting these thoughts to an audience that are most likely going to disagree with this strategy. So I would welcome any support along with critiques on these ideas. I know several people who have reported success using a similar approach. Pat From stephen.bannasch at deanbrook.org Fri Apr 23 01:32:20 2010 From: stephen.bannasch at deanbrook.org (Stephen Bannasch) Date: Fri, 23 Apr 2010 01:32:20 -0400 Subject: [rspec-users] running: 'rake spec' mixes ApplicationHelper into my ActiveRecord model instances In-Reply-To: References: Message-ID: solved ... Running the ApplicationHelper spec tests mixed the ApplicationHelper methods into Object. Actually I don't remember making the helper being tested or the spec ;-) Might have been generated by restful authentication ... Here's what's in spec/helpers/application_helper_spec.rb (which is what is causing the problem): require File.dirname(__FILE__) + '/../spec_helper' include ApplicationHelper include AuthenticatedTestHelper describe ApplicationHelper do describe "title" do it "should set @page_title" do title('hello').should be_nil @page_title.should eql('hello') end it "should output container if set" do title('hello', :h2).should have_tag('h2', 'hello') end end end Evidently self is Object when that file is loaded and mixes the methods in ApplicationHelper into Object -- not useful -- but I'll bet I'm still doing something wrong ... Here's what I replaced it with which works fine: require 'spec_helper' class ViewWithApplicationHelper < ActionView::Base include ApplicationHelper # When actually running in a view the controller's instance variables are # mixed into the object that is self when rendering, but instances # created from a class that just inherits from ActionView::Base don't have # those instance variables (like @page_title) mixed in. So I add it by hand. attr_accessor :page_title end describe ViewWithApplicationHelper do before(:each) do @view = ViewWithApplicationHelper.new end describe "title" do it "should set @page_title" do @view.title('hello').should be_nil @view.page_title.should eql('hello') end it "should output container if set" do @view.title('hello', :h2).should have_tag('h2', 'hello') end end end http://gist.github.com/375634 updated with the description of using ruby-debug to find this problem. From lists at ruby-forum.com Fri Apr 23 03:15:44 2010 From: lists at ruby-forum.com (Ben Prew) Date: Fri, 23 Apr 2010 09:15:44 +0200 Subject: [rspec-users] Rack::Test + cookies + rspec In-Reply-To: References: <355F2859-E22A-4442-A6AE-C2E39498DC43@gmail.com> Message-ID: <7efa114dc7b92f1f7306769b0ae2197e@ruby-forum.com> Ben Lovell wrote: > On 16 April 2010 15:59, Ben Lovell wrote: > >> Try: >> >> post 'whatever', {}, {'rack.session' => {:something=>'value'}} >> >> To put things through the session with rack test/sinatra. >> >> Sent from my iPhone >> >> > Hmm, hold up, that isn't what you asked for :) > > You have to remember that the default Rack::Test::CookieJar#[] only > returns > cookies that exactly match the domain and path of the current request so > be > sure to check there first. I think this is more of a Sinatra issue, and not an rspec issue. But, since I'm a Sinatra fan, I thought I'd weigh in, since I just went through this and it was harder then I would've expected. If you want to pass session values in tests, you'll have to disable sessions in your sinatra app. I've got a blog post at http://benprew.posterous.com/ with the details. Also, I had to do this in one of my apps recently, take a look at the Rakefile, picklespears.com and test/test_player.rb at http://github.com/benprew/picklespears -- Posted via http://www.ruby-forum.com/. From michael at schuerig.de Fri Apr 23 18:54:57 2010 From: michael at schuerig.de (Michael Schuerig) Date: Sat, 24 Apr 2010 00:54:57 +0200 Subject: [rspec-users] Cucumber + capybara: checking list items Message-ID: <201004240054.58577.michael@schuerig.de> I'm unsure how to check a few things related to lists of items. In this specific case, I have a articles with title and abstract. When there are no articles, I'd like to ensure that there *is* a list on the page, but that it does not contain any articles. When there are articles, they should be displayed in such a way that their attributes are not mixed. For the empty list check I've come up with this, however, I noticed that the capybara README advises against "x.should_not have_y". Is there a better way? Then /^I should see an empty article list$/ do with_scope("#articles") do page.should_not have_css("li") end end For checking existing articles like this
  • Article 1 foo bar
  • ...
I have this broken step Then /^I should see an article with title "([^\"]*)" and abstract "([^\"]*)"$/ do |title, abstract| with_scope('#articles li') do with_scope('.title') { page.should have_content(title) } with_scope('.abstract') { page.should have_content(abstract) } end end It is broken in that it does not ensure that corresponding titles and abstracts are within the same LI. I understand why it doesn't work, for with_scope just builds up a scope chain. Unfortunately, I don't see how to get the check I want. Michael -- Michael Schuerig mailto:michael at schuerig.de http://www.schuerig.de/michael/ From vertebrate at gmail.com Sat Apr 24 14:05:02 2010 From: vertebrate at gmail.com (Steve V) Date: Sat, 24 Apr 2010 13:05:02 -0500 Subject: [rspec-users] controller_name in rspec-rails2? Message-ID: I'm trying to use some temporary spec only namespaced controllers with rspec-rails2 and rails3 and my specs fail saying no method for 'controller_name'. The same specs work perfectly fine with rails2 and rspec-rails. Putting the specific controller into the describe doesn't work. What is the current way to do this with rspec v2? Thanks, Steve From patrick at collinatorstudios.com Sun Apr 25 04:43:35 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sun, 25 Apr 2010 01:43:35 -0700 (PDT) Subject: [rspec-users] a MockExpectationError problem Message-ID: Hi everyone, I have a test for importing vcards, and I was finding that each time it was being run, it was generating new photos and since it was using the test database, it was actually overwriting real photos that were being stored in the file system (they are named based on the record's id). So it was apparent to me that I need to use mocking to intercept Photo.create so that it doesn't really happen... I tried to do this, but I am getting this MockExpectationError, which I don't quite understand the meaning of :[]= --- The relationships are: Photo belongs_to :contact Contact has_one :photo --- this is how I am mocking in my test: @photo = mock_model(Photo) Photo.should_receive(:create).and_return(@photo) --- the relevant code that is getting called to create the photo: def card_photo @contact.photo = Photo.create(:image_file_string => @card.photos.first) end --- And... the error: 1) Spec::Mocks::MockExpectationError in 'Vcard importing a vcard a card with an invalid address, a photo, birthday, url, phone, and email should update an existing contact when an email is found' Mock "Photo_1001" received unexpected message :[]= with ("contact_id", 201) /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:185:in `set_belongs_to_association_for' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/has_one_association.rb:56:in `replace' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations.rb:1281:in `photo=' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:217:in `send' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:217:in `method_missing' /Users/patrick/coding/rails/xyz/app/models/vcard.rb:164:in `card_photo' ---- Any ideas? Thanks.. Patrick J. Collins http://collinatorstudios.com From phillipkoebbe at gmail.com Sun Apr 25 12:00:52 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 25 Apr 2010 11:00:52 -0500 Subject: [rspec-users] a MockExpectationError problem In-Reply-To: References: Message-ID: <4BD46734.2070608@gmail.com> On 2010-04-25 3:43 AM, Patrick J. Collins wrote: > Hi everyone, > > I have a test for importing vcards, and I was finding that each time it was > being run, it was generating new photos and since it was using the test > database, it was actually overwriting real photos that were being stored in the > file system (they are named based on the record's id). So it was apparent to > me that I need to use mocking to intercept Photo.create so that it doesn't > really happen... > > ...snip... > Any ideas? > > Thanks.. > > Patrick J. Collins > http://collinatorstudios.com Hi Patrick, See http://gist.github.com/378489 for how I ended up specing a file upload. This isn't the exact same situation, but maybe you will get some ideas that will help. And there may be a better way, but this seems to work and is fairly easy for me understand. Here's a little info on the app to shed some light on what I'm doing in the spec. I am working on an app that has a "media library" that users can upload into. There are four types of media: audio, video, images, and documents. During the upload process, I try to determine the mime type automatically, and from that, the type of media, but I do allow those things to be set manually. I have a run-time constant (APP_CONFIG[:media_root_path]) that defines where the files should be on the file system, and I have to change that during the test to make sure development files don't get overwritten. That's accomplished with the call to set_app_config, which is really nothing more than replacing a constant. Its definition is def set_app_config(new_app_config) saved_app_config = APP_CONFIG.dup Kernel::silence_warnings { Object.const_set(:APP_CONFIG, new_app_config ) } return saved_app_config end Let me know if you have any questions. Peace, Phillip From patrick at collinatorstudios.com Sun Apr 25 17:25:40 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sun, 25 Apr 2010 14:25:40 -0700 (PDT) Subject: [rspec-users] a MockExpectationError problem In-Reply-To: <4BD46734.2070608@gmail.com> References: <4BD46734.2070608@gmail.com> Message-ID: On Sun, 25 Apr 2010, Phillip Koebbe wrote: > See http://gist.github.com/378489 for how I ended up specing a file upload. > This isn't the exact same situation, but maybe you will get some ideas that > will help. And there may be a better way, but this seems to work and is fairly > easy for me understand. Yeah, I see what you're doing, but I don't quite get how I could apply this to what I am doing. I have a method that creates a contact and then creates a photo and assigns it to that contact. So my problem comes from doing (in my model method): @contact.photo = Photo.create(...) ... Although the code works fine in the real world app use, the spec fails because it's trying to do something with "[]=" .. which I don't get. ---- Also, I have a couple side questions-- 1) is there some sort of caching done to before(:all/:each) blocks? I had a before block that set an instance variable to something, and then I removed it-- and was getting weird behavior, and after doing some inspecting I found that the instance variable was still set-- even though it was not set anywhere in the code... I had to put a blank before block in there to get that behavior to stop... Just wondered if this is normal? ... 2) I still am struggling with mock vs stub-- or I should say stub! vs. should_receive. Initially I had something like this: before(:all) do foo = mock_model) Foo.should_receive(:find_by_name).with("bar").and_receive(foo) end it "blah" do 3.times { @blah.do_something } do it "blah2" do 3.times { @blah.do_something } end (blah model) def do_something @foo = Foo.find_by_name("bar") end This wasn't working, because apparently it's only good for one usage. I was thinking that declating "should_receive" would mean that anytime Foo gets .find_by_name called on it, it will have that behavior. I ended up changing that to a before(:each), and then I got errors like expected it 1 time but got it 3 times.... So not knowing how to deal with that, I changed .should_receive to .stub! and then the errors went away. Not sure if that was the right thing to do in that case. Patrick J. Collins http://collinatorstudios.com From phillipkoebbe at gmail.com Sun Apr 25 17:51:26 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 25 Apr 2010 16:51:26 -0500 Subject: [rspec-users] a MockExpectationError problem In-Reply-To: References: <4BD46734.2070608@gmail.com> Message-ID: <4BD4B95E.9050201@gmail.com> On 2010-04-25 4:25 PM, Patrick J. Collins wrote: > On Sun, 25 Apr 2010, Phillip Koebbe wrote: >> See http://gist.github.com/378489 for how I ended up specing a file upload. >> This isn't the exact same situation, but maybe you will get some ideas that >> will help. And there may be a better way, but this seems to work and is fairly >> easy for me understand. > Yeah, I see what you're doing, but I don't quite get how I could apply this to > what I am doing. > I was just thinking that since your problem had to do with files on the file system getting overwritten, seeing how to someone worked around that problem with uploads might trigger some ideas in your mind. > I have a method that creates a contact and then creates a photo and assigns it > to that contact. > > So my problem comes from doing (in my model method): > > @contact.photo = Photo.create(...) > > ... Although the code works fine in the real world app use, the spec fails > because it's trying to do something with "[]=" .. which I don't get. > I may be mistaken, but []= looks like an array assignment, which would suggest to me something to do with adding an element to a collection somewhere. Do you have any hooks defined that affect the creation process? Or is this a straight-forward, vanilla Photo.create call that goes straight into ActiveRecord? Maybe you should gist your spec and file. > ---- > > Also, I have a couple side questions-- > > 1) is there some sort of caching done to before(:all/:each) blocks? > > I had a before block that set an instance variable to something, and then I > removed it-- and was getting weird behavior, and after doing some inspecting I > found that the instance variable was still set-- even though it was not set > anywhere in the code... I had to put a blank before block in there to get that > behavior to stop... Just wondered if this is normal? > I've not experienced that problem, so I can't help with this. > 2) I still am struggling with mock vs stub-- or I should say stub! vs. > should_receive. Initially I had something like this: > > before(:all) do > foo = mock_model) > Foo.should_receive(:find_by_name).with("bar").and_receive(foo) > end > > it "blah" do > 3.times { @blah.do_something } > do > > it "blah2" do > 3.times { @blah.do_something } > end > > (blah model) > def do_something > @foo = Foo.find_by_name("bar") > end > > This wasn't working, because apparently it's only good for one usage. I was > thinking that declating "should_receive" would mean that anytime Foo gets > .find_by_name called on it, it will have that behavior. I ended up changing > that to a before(:each), and then I got errors like expected it 1 time but got > it 3 times.... > > So not knowing how to deal with that, I changed .should_receive to .stub! and > then the errors went away. > > Not sure if that was the right thing to do in that case. > Use stub when you just want to provide the plumbing. Use should_receive when you are setting an expectation. As an example, you could do Photo.stub(:create) just to provide the method to avoid errors when your code calls it. But if you actually want to verify that your code calls it, then do Photo.should_receive(:create). After David gave his input a few weeks ago, I've adopted an approach in which I stub methods in before(:each), including return values where appropriate, and then put an expectation in an example. So I might have something like: before(:each) do widget = stub_model(Widget).as_new_record Widget.stub(:new).and_return(widget) end it 'should call Widget.new' do Widget.should_receive(:new) get :new end it 'should render the new template' do get :new response.should render_template(:new) end In this example, the real code is going to call .new both times, but I'm setting an expectation just once (trying to follow the convention of one test per example). In the first example, where the expectation is set, I'll get a failure if .new isn't called. In the second one, no expectation is set, but since I'm using a stubbed model, I don't want the class actually calling real methods, hence the stub. I personally find it's easier and more logical to do it this way. Doing it like this, I could remove the first example and nothing else breaks and it still makes perfectly good sense. Peace, Phillip From patrick at collinatorstudios.com Sun Apr 25 18:25:25 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sun, 25 Apr 2010 15:25:25 -0700 (PDT) Subject: [rspec-users] a MockExpectationError problem In-Reply-To: <4BD4B95E.9050201@gmail.com> References: <4BD46734.2070608@gmail.com> <4BD4B95E.9050201@gmail.com> Message-ID: Here is a gist of my code: http://gist.github.com/378778 > Use stub when you just want to provide the plumbing. Use should_receive when > you are setting an expectation. As an example, you could do > Photo.stub(:create) just to provide the method to avoid errors when your code > calls it. But if you actually want to verify that your code calls it, then do Well, as you can see by my code, I am actually doing a loop @card.addresses.each .... This is calling the @country = get_country || Country.find_by_name("United States") So-- the number of times .find_by_name needs to be intercepted by .should_receive is dependent on the number of addresses in a vcard. This was the problem I didn't know how to address, and using stub! resolved it, but like I said-- I didn't know if there's a more appropriate way to do it. Patrick J. Collins http://collinatorstudios.com From celoserpa at gmail.com Sun Apr 25 18:52:49 2010 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Sun, 25 Apr 2010 17:52:49 -0500 Subject: [rspec-users] Controller tests fail to parse route based on resource Message-ID: Hello list, I have a controller example that looks like this: it 'Should update (PUT /users/:id)' do @attributes = @user.attributes @attributes[:firstname] = "Another one" lambda { put user_url(@user), at attributes User.find(@user.id).firstname == @attributes[:firstname] response.should redirect_to(users_path) }.should_not raise_error end However, this fails with the following error message ActionController::UnknownAction in 'UsersController#update on (snip) No action responded to /users/89/edit. Actions: (snip) I'm not sure why it is not routing PUT /users/:id to UsersController#update. Any ideas? The workaround I have as of now is to: post :update, {:id => @user.id, :user => @attributes}, which works fine, but not RESTful. Cheers, Marcelo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Sun Apr 25 19:01:28 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 25 Apr 2010 18:01:28 -0500 Subject: [rspec-users] Controller tests fail to parse route based on resource In-Reply-To: References: Message-ID: <4BD4C9C8.2020307@gmail.com> On 2010-04-25 5:52 PM, Marcelo de Moraes Serpa wrote: > Hello list, > > I have a controller example that looks like this: > > it 'Should update (PUT /users/:id)' do > @attributes = @user.attributes > @attributes[:firstname] = "Another one" > lambda { > put user_url(@user), at attributes > User.find(@user.id ).firstname == > @attributes[:firstname] > response.should redirect_to(users_path) > }.should_not raise_error > end > > However, this fails with the following error message > > ActionController::UnknownAction in 'UsersController#update on (snip) > No action responded to /users/89/edit. Actions: (snip) > > I'm not sure why it is not routing PUT /users/:id to > UsersController#update. Any ideas? > > The workaround I have as of now is to: > > post :update, {:id => @user.id , :user => > @attributes}, which works fine, but not RESTful. > What happens if you change that to put :update, ... ? Peace, Phillip From phillipkoebbe at gmail.com Sun Apr 25 19:22:31 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 25 Apr 2010 18:22:31 -0500 Subject: [rspec-users] a MockExpectationError problem In-Reply-To: References: <4BD46734.2070608@gmail.com> <4BD4B95E.9050201@gmail.com> Message-ID: <4BD4CEB7.1040800@gmail.com> On 2010-04-25 5:25 PM, Patrick J. Collins wrote: > Here is a gist of my code: > http://gist.github.com/378778 > >> Use stub when you just want to provide the plumbing. Use should_receive when >> you are setting an expectation. As an example, you could do >> Photo.stub(:create) just to provide the method to avoid errors when your code >> calls it. But if you actually want to verify that your code calls it, then do > Well, as you can see by my code, I am actually doing a loop > > @card.addresses.each .... This is calling the @country = get_country || > Country.find_by_name("United States") > > So-- the number of times .find_by_name needs to be intercepted by > .should_receive is dependent on the number of addresses in a vcard. And this would be the difference between stubbing and expecting. Do you need to set an expectation that it gets called a certain number of times? If not, just stub it (which is what you did and the error went away). Only use should_receive when you want to verify that a method is actually being called in your code. I generally do that when I want to make sure different branches of execution are followed correctly. > This was the problem I didn't know how to address, and using stub! resolved it, > but like I said-- I didn't know if there's a more appropriate way to do it. > > Patrick J. Collins > http://collinatorstudios.com Regarding your original problem of the mocking error, have you debugged into the FlexImage code? In looking at your gist, you have this: # @photo = mock_model(Photo, {:image_file_string => photo_content}) which says "create a mock object based on the Photo model, and if #image_file_string gets called on that object, return photo_content". Then you have # Photo.should_receive(:create).and_return(@photo) which obviously says "Photo should receive a call to the .create method, and when it does, return @photo". The potential problem that I see (though I may not be understanding something correctly), is when you call Photo.create, .image_file_string= is being called in the FlexImage codebase. I'm wondering if your issue might be somewhere down in there. I'd do some more digging, but I have to run right now. Good luck! Peace, Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patrick at collinatorstudios.com Sun Apr 25 19:58:08 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sun, 25 Apr 2010 16:58:08 -0700 (PDT) Subject: [rspec-users] a MockExpectationError problem In-Reply-To: <4BD4CEB7.1040800@gmail.com> References: <4BD46734.2070608@gmail.com> <4BD4B95E.9050201@gmail.com> <4BD4CEB7.1040800@gmail.com> Message-ID: > Regarding your original problem of the mocking error, have you debugged into > the FlexImage code? In looking at your gist, you have this: > > # @photo = mock_model(Photo, {:image_file_string => photo_content}) > > which says "create a mock object based on the Photo model, and if > #image_file_string gets called on that object, return photo_content". Then you > have > > # Photo.should_receive(:create).and_return(@photo) ... Well, from what I can tell, the problem is not with Photo.should_receive... If I change @contact.photo = Photo.create(...) to Photo.create(...) then the spec passes... It's when that @contact.photo = is there that it breaks. Patrick J. Collins http://collinatorstudios.com From celoserpa at gmail.com Sun Apr 25 20:14:15 2010 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Sun, 25 Apr 2010 19:14:15 -0500 Subject: [rspec-users] Controller tests fail to parse route based on resource In-Reply-To: <4BD4C9C8.2020307@gmail.com> References: <4BD4C9C8.2020307@gmail.com> Message-ID: Hi Phillip, The code is actually post :update, I have mistyped there. But that's not the issue. The problem is when I try to use the Rails-generated resource method: put user_url(@user). It does generate the URL correctly ( http://test.domain/users/int where int is any integer) but it fails to actually map this to UsersController#update: PUT /users/:id should map to controller => 'users',:action => 'update': But I get the following error when in the controlle test example (the put user_url(@user)): ActionController:: UnknownAction in 'UsersController#update on (snip) *No action responded to /users/89*. Actions: (snip) Thanks, Marcelo. On Sun, Apr 25, 2010 at 6:01 PM, Phillip Koebbe wrote: > On 2010-04-25 5:52 PM, Marcelo de Moraes Serpa wrote: > >> Hello list, >> >> I have a controller example that looks like this: >> >> it 'Should update (PUT /users/:id)' do >> @attributes = @user.attributes >> @attributes[:firstname] = "Another one" >> lambda { >> put user_url(@user), at attributes >> User.find(@user.id ).firstname == >> @attributes[:firstname] >> >> response.should redirect_to(users_path) >> }.should_not raise_error >> end >> >> However, this fails with the following error message >> >> ActionController::UnknownAction in 'UsersController#update on (snip) >> No action responded to /users/89/edit. Actions: (snip) >> >> I'm not sure why it is not routing PUT /users/:id to >> UsersController#update. Any ideas? >> >> The workaround I have as of now is to: >> >> post :update, {:id => @user.id , :user => @attributes}, >> which works fine, but not RESTful. >> >> > What happens if you change that to > > put :update, ... > > ? > > Peace, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Sun Apr 25 21:32:30 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sun, 25 Apr 2010 21:32:30 -0400 Subject: [rspec-users] File creation In-Reply-To: References: Message-ID: On Thu, Apr 22, 2010 at 9:28 AM, ben rooney wrote: > I have a model that generates the authorization_rules.rb for > declarative_auth. I am not sure how I can go about testing the model - > apart from anything I don't want my test to over-write the file - so, > er, I am not quite sure how to go about it. > > I *could* have some sort of sniffer in my model to see if I am in the > Test environment and generate a different file, but putting code into > my model to pass tests doesn't seem a very, well, sensible thing to > do. > > Anyone been there, done that? Assuming that in you code you write the file with say File.open(path_to_authorization_rules_dot_rb, 'w') do | f | #code to write the file contents to f end where path_to_authorization_rules_dot_rb is some constant, variable or expression which evaluates to the path to the file. You could do something like @iostream = StringIO.new File.stub(:open) { yield @iostream} # call your code # test the contents of @iostream.string This should work assuming your code doesn't open any other files. Another way would be to extract the code in the open block to a separate method which takes the IO object as a parameter, and test that method passing in a StringIO. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From johnf.pub at distb.net Mon Apr 26 17:29:28 2010 From: johnf.pub at distb.net (John Feminella) Date: Mon, 26 Apr 2010 17:29:28 -0400 Subject: [rspec-users] Using RSpec to test Rake tests In-Reply-To: References: Message-ID: hi guys, I'm trying to be diligent about checking my `rake` tasks with RSpec tests, but in the process of feeling my way around I seem to have hit a wall. I've got a really simple RSpec test that looks like this: ? ?# ./test/meta_spec.rb ? ?describe "Rake tasks" do ? ? ?require 'rake' ? ? ?before(:each) do ? ? ? ?@rake = Rake::Application.new ? ? ? ?@rake.load_rakefile ?# => Error here! ? ? ? ?Rake.application = @rake ? ? ?end ? ? ?after(:each) do ? ? ? ?Rake.application = nil ? ? ?end ? ? ?it "should have at least one RSpec test to execute" do ? ? ? ?Rake.application["specs"].spec_files.size.should > 0 ? ? ?end ? ?end I have a simple task called "specs" defined in `./Rakefile.rb` which has a Spec::Rake::SpecTask that includes all the `*_spec.rb` files. If I put the `@rake.load_rakefile` method in (which is my understanding of what the Rake docs tell you to do when programmatically instantiating Rake::Application instances), I want that Rakefile to load. But instead it just bombs out. If I comment it out, however, the test fails because the "specs" task is (understandably) not defined. Where am I going wrong? (I suspect this might be more of a Rake question than a RSpec one, but I've posted on this list just in case my assessment is off.) Or is the goal of testing Rake tasks better served by something other than RSpec? Any help is appreciated. Thanks very much! ~ jf -- John Feminella Principal Consultant, Distilled Brilliance From mauricioaniche at gmail.com Mon Apr 26 21:11:06 2010 From: mauricioaniche at gmail.com (Mauricio Aniche) Date: Mon, 26 Apr 2010 22:11:06 -0300 Subject: [rspec-users] Problems testing destroy method in rspec2 In-Reply-To: <313e92a61003290920m179fbd31na9dc0da3b201f494@mail.gmail.com> References: <313e92a61003242039o162cb9c6l85b3d14dd98764e1@mail.gmail.com> <57c63afe1003250419t5ab699eew75e6695c9c6cfb92@mail.gmail.com> <313e92a61003250615l25f4823y8c39e2ad60be4654@mail.gmail.com> <313e92a61003290920m179fbd31na9dc0da3b201f494@mail.gmail.com> Message-ID: Hi, Just to close this one.. RSpec wasn't the problem! My bad! :) Thanks, Mauricio On Mon, Mar 29, 2010 at 1:20 PM, Mauricio Aniche wrote: > Hi, > > Is there anyone else who had this problem? > > Thanks, > Mauricio > > > On Thu, Mar 25, 2010 at 10:15 AM, Mauricio Aniche < > mauricioaniche at gmail.com> wrote: > >> Hi David, >> >> I am using rspec2 beta4, which is the latest version in gemcutter. >> >> Hi Julian, >> >> The problem only happens in my spec. My rails3 applications works fine >> (I use a post with a hidden _method set as delete, but I guess this is >> a browser problem!) >> >> Regards, >> Mauricio >> >> On 3/25/10, David Chelimsky wrote: >> > On Wed, Mar 24, 2010 at 10:39 PM, Mauricio Aniche >> > wrote: >> >> Hi, >> >> I am trying to test the destroy method in my rails 3 controller, but I >> >> always get an "no route matches {}" error. But the route do exist, as I >> >> can >> >> see by running rake routes. >> > >> > What version of rspec and rspec-rails are you using? >> > >> >> I have something like this: >> >> delete :destroy, :id => "1" >> >> The stack trace: >> >> Failure/Error: delete :destroy, :id => "1" >> >> No route matches {} >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/routing/route_set.rb:415:in >> >> `generate' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:43:in >> >> `rewrite' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/url_rewriter.rb:16:in >> >> `rewrite' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/url_for.rb:145:in >> >> `url_for' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:86:in >> >> `_compute_redirect_to_location' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/redirecting.rb:58:in >> >> `redirect_to' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/flash.rb:25:in >> >> `redirect_to' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:59:in >> >> `redirect_to' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in >> >> `instrument' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in >> >> `__send__' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in >> >> `instrument' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:58:in >> >> `redirect_to' >> >> # /Users/> >> user>/dev/easyclinica/app/controllers/convenios_controller.rb:55 >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in >> >> `call' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/mime_responds.rb:189:in >> >> `respond_to' >> >> # /Users/> >> user>/dev/easyclinica/app/controllers/convenios_controller.rb:53:in >> >> `destroy' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in >> >> `send_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/base.rb:44:in >> >> `send_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:145:in >> >> `process_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:18:in >> >> `process_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:438:in >> >> `_run__2086632925__process_action__988268021__callbacks' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in >> >> `send' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:403:in >> >> `_run_process_action_callbacks' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in >> >> `send' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/callbacks.rb:88:in >> >> `run_callbacks' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/callbacks.rb:17:in >> >> `process_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rendering.rb:12:in >> >> `process_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/compatibility.rb:66:in >> >> `process_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:29:in >> >> `process_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications/instrumenter.rb:18:in >> >> `instrument' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in >> >> `__send__' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/activesupport-3.0.0.beta/lib/active_support/notifications.rb:49:in >> >> `instrument' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/instrumentation.rb:28:in >> >> `process_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rescue.rb:8:in >> >> `process_action' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/abstract_controller/base.rb:115:in >> >> `process' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:64:in >> >> `dispatch' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal/rack_delegation.rb:19:in >> >> `dispatch' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_controller/metal.rb:89:in >> >> `call' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/mock_session.rb:30:in >> >> `request' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:207:in >> >> `process_request' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/rack-test-0.5.3/lib/rack/test.rb:105:in >> >> `request' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:272:in >> >> `process' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:48:in >> >> `delete' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in >> >> `__send__' >> >> # /Users/> >> >> user>/.rvm/gems/ree-1.8.7-2010.01%rails3/gems/actionpack-3.0.0.beta/lib/action_dispatch/testing/integration.rb:315:in >> >> `delete' >> >> # (eval):3:in `delete' >> >> # ./spec/controllers/_spec.rb:49 >> >> Have you guys ever been through this problem? >> >> Thanks, >> >> Mauricio >> >> _______________________________________________ >> >> rspec-users mailing list >> >> rspec-users at rubyforge.org >> >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-users at rubyforge.org >> > http://rubyforge.org/mailman/listinfo/rspec-users >> > >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martindemello at gmail.com Tue Apr 27 05:36:19 2010 From: martindemello at gmail.com (Martin DeMello) Date: Tue, 27 Apr 2010 15:06:19 +0530 Subject: [rspec-users] testing against a live environment Message-ID: I have a series of tests I want to automate, which involve running shell scripts in a "live" environment (i.e. nothing mocked or stubbed), and then verifying the state of the system. I thought that, even though it doesn't fit the classic definition of "testing", RSpec would still be a handy way to organise the tests. Is it likely to be useful, or am I going against the grain enough that I'd run into problems? martin From matt at mattwynne.net Tue Apr 27 06:02:21 2010 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 27 Apr 2010 11:02:21 +0100 Subject: [rspec-users] testing against a live environment In-Reply-To: References: Message-ID: On 27 Apr 2010, at 10:36, Martin DeMello wrote: > I have a series of tests I want to automate, which involve running > shell scripts in a "live" environment (i.e. nothing mocked or > stubbed), and then verifying the state of the system. I thought that, > even though it doesn't fit the classic definition of "testing", RSpec > would still be a handy way to organise the tests. Is it likely to be > useful, or am I going against the grain enough that I'd run into > problems? Should be fine, though you might find cucumber/aruba a nice combination for this too. > > martin > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From martindemello at gmail.com Tue Apr 27 06:31:47 2010 From: martindemello at gmail.com (Martin DeMello) Date: Tue, 27 Apr 2010 16:01:47 +0530 Subject: [rspec-users] testing against a live environment In-Reply-To: References: Message-ID: On Tue, Apr 27, 2010 at 3:32 PM, Matt Wynne wrote: > > Should be fine, though you might find cucumber/aruba a nice combination for > this too. Thanks, aruba looks really interesting! Will explore it. martin From dchelimsky at gmail.com Tue Apr 27 07:18:48 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 06:18:48 -0500 Subject: [rspec-users] Using RSpec to test Rake tests In-Reply-To: References: Message-ID: On Apr 26, 2010, at 4:29 PM, John Feminella wrote: > hi guys, > > I'm trying to be diligent about checking my `rake` tasks with RSpec > tests, but in the process of feeling my way around I seem to have hit > a wall. I've got a really simple RSpec test that looks like this: > > # ./test/meta_spec.rb > describe "Rake tasks" do > require 'rake' > > before(:each) do > @rake = Rake::Application.new > @rake.load_rakefile # => Error here! > Rake.application = @rake > end > > after(:each) do > Rake.application = nil > end > > it "should have at least one RSpec test to execute" do > Rake.application["specs"].spec_files.size.should > 0 > end > end > > I have a simple task called "specs" defined in `./Rakefile.rb` which > has a Spec::Rake::SpecTask that includes all the `*_spec.rb` files. This is what the default spec task does, and it is well specified in rspec's own specs. There is a general rule of thumb that says "test your code, not everybody else's." This suggests that you don't really need to be testing this. Any reason you feel the need to? David > If I put the `@rake.load_rakefile` method in (which is my > understanding of what the Rake docs tell you to do when > programmatically instantiating Rake::Application instances), I want > that Rakefile to load. But instead it just bombs out. If I comment it > out, however, the test fails because the "specs" task is > (understandably) not defined. > > Where am I going wrong? (I suspect this might be more of a Rake > question than a RSpec one, but I've posted on this list just in case > my assessment is off.) Or is the goal of testing Rake tasks better > served by something other than RSpec? > > Any help is appreciated. Thanks very much! > > ~ jf > -- > John Feminella > Principal Consultant, Distilled Brilliance > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From johnf.pub at distb.net Tue Apr 27 09:42:09 2010 From: johnf.pub at distb.net (John Feminella) Date: Tue, 27 Apr 2010 09:42:09 -0400 Subject: [rspec-users] Using RSpec to test Rake tests In-Reply-To: References: Message-ID: > There is a general rule of thumb that says "test your code, > not everybody else's." This suggests that you don't really > need to be testing this. Any reason you feel the need to? The "specs" task is generated programmatically based on several initial conditions, and eventually it will become more complex and selective about (for instance) what it will put in the FileList[...] to examine. My understanding is that this isn't so much checking that Rake successfully made the task, but rather that the conditional logic which generates that task is sound. Since that exists on my side, not Rake's, I thought it was appropriate to test. In your view, is that an abuse of RSpec/Rake, or is this a useful thing to test? -- John Feminella Principal Consultant, Distilled Brilliance On Tue, Apr 27, 2010 at 07:18, David Chelimsky wrote: > On Apr 26, 2010, at 4:29 PM, John Feminella wrote: > >> hi guys, >> >> I'm trying to be diligent about checking my `rake` tasks with RSpec >> tests, but in the process of feeling my way around I seem to have hit >> a wall. I've got a really simple RSpec test that looks like this: >> >> ? ?# ./test/meta_spec.rb >> ? ?describe "Rake tasks" do >> ? ? ?require 'rake' >> >> ? ? ?before(:each) do >> ? ? ? ?@rake = Rake::Application.new >> ? ? ? ?@rake.load_rakefile ?# => Error here! >> ? ? ? ?Rake.application = @rake >> ? ? ?end >> >> ? ? ?after(:each) do >> ? ? ? ?Rake.application = nil >> ? ? ?end >> >> ? ? ?it "should have at least one RSpec test to execute" do >> ? ? ? ?Rake.application["specs"].spec_files.size.should > 0 >> ? ? ?end >> ? ?end >> >> I have a simple task called "specs" defined in `./Rakefile.rb` which >> has a Spec::Rake::SpecTask that includes all the `*_spec.rb` files. > > This is what the default spec task does, and it is well specified in rspec's own specs. There is a general rule of thumb that says "test your code, not everybody else's." This suggests that you don't really need to be testing this. Any reason you feel the need to? > > David > >> If I put the `@rake.load_rakefile` method in (which is my >> understanding of what the Rake docs tell you to do when >> programmatically instantiating Rake::Application instances), I want >> that Rakefile to load. But instead it just bombs out. If I comment it >> out, however, the test fails because the "specs" task is >> (understandably) not defined. >> >> Where am I going wrong? (I suspect this might be more of a Rake >> question than a RSpec one, but I've posted on this list just in case >> my assessment is off.) Or is the goal of testing Rake tasks better >> served by something other than RSpec? >> >> Any help is appreciated. Thanks very much! >> >> ~ jf >> -- >> John Feminella >> Principal Consultant, Distilled Brilliance >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > From dchelimsky at gmail.com Tue Apr 27 09:58:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 08:58:36 -0500 Subject: [rspec-users] Using RSpec to test Rake tests In-Reply-To: References: Message-ID: On Apr 27, 2010, at 8:42 AM, John Feminella wrote: >> There is a general rule of thumb that says "test your code, >> not everybody else's." This suggests that you don't really >> need to be testing this. Any reason you feel the need to? > > The "specs" task is generated programmatically based on several > initial conditions, and eventually it will become more complex and > selective about (for instance) what it will put in the FileList[...] > to examine. > > My understanding is that this isn't so much checking that Rake > successfully made the task, but rather that the conditional logic > which generates that task is sound. Since that exists on my side, not > Rake's, I thought it was appropriate to test. > > In your view, is that an abuse of RSpec/Rake, or is this a useful thing to test? Given that you're generating it programmatically it seems reasonable to me. More below ... > On Tue, Apr 27, 2010 at 07:18, David Chelimsky wrote: >> On Apr 26, 2010, at 4:29 PM, John Feminella wrote: >> >>> hi guys, >>> >>> I'm trying to be diligent about checking my `rake` tasks with RSpec >>> tests, but in the process of feeling my way around I seem to have hit >>> a wall. I've got a really simple RSpec test that looks like this: >>> >>> # ./test/meta_spec.rb >>> describe "Rake tasks" do >>> require 'rake' >>> >>> before(:each) do >>> @rake = Rake::Application.new >>> @rake.load_rakefile # => Error here! >>> Rake.application = @rake >>> end >>> >>> after(:each) do >>> Rake.application = nil >>> end >>> >>> it "should have at least one RSpec test to execute" do >>> Rake.application["specs"].spec_files.size.should > 0 >>> end >>> end >>> >>> I have a simple task called "specs" defined in `./Rakefile.rb` which >>> has a Spec::Rake::SpecTask that includes all the `*_spec.rb` files. If this were me, I'd drive out an object with a method that determines the file list and then just use it in the rake task. class SpecFileFilter def files ... end end Spec::Rake::SpecTask.new('specs') do |t| t.spec_files = SpecFileFilter.new.files ] There is little need to dig into Rake's plumbing for this purpose, and the only risk you bear is that somebody updates the rake task to stop using the SpecFileFilter object. Make sense? >> >> This is what the default spec task does, and it is well specified in rspec's own specs. There is a general rule of thumb that says "test your code, not everybody else's." This suggests that you don't really need to be testing this. Any reason you feel the need to? >> >> David >> >>> If I put the `@rake.load_rakefile` method in (which is my >>> understanding of what the Rake docs tell you to do when >>> programmatically instantiating Rake::Application instances), I want >>> that Rakefile to load. But instead it just bombs out. If I comment it >>> out, however, the test fails because the "specs" task is >>> (understandably) not defined. >>> >>> Where am I going wrong? (I suspect this might be more of a Rake >>> question than a RSpec one, but I've posted on this list just in case >>> my assessment is off.) Or is the goal of testing Rake tasks better >>> served by something other than RSpec? >>> >>> Any help is appreciated. Thanks very much! >>> >>> ~ jf >>> -- >>> John Feminella >>> Principal Consultant, Distilled Brilliance >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> From mailinglists at patmaddox.com Tue Apr 27 14:14:28 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Tue, 27 Apr 2010 11:14:28 -0700 Subject: [rspec-users] [Cucumber:4100] Cucumber vs, RSpec In-Reply-To: References: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> Message-ID: <61E5E08C-1DBD-4C2B-926A-4A0B82BE6794@patmaddox.com> My other contribution to this thread is that if your code is tested primarily via Cucumber, you probably have SRP violations all over the place. That's what I've noticed in my own code, anyway. The tricky thing is that SRP violations are not necessarily crippling, particularly in Rails apps (where SRP violations are pretty much built-in). They just make your test suite a bit slower, limit reuse, etc... things that are valuable to us but typically not as valuable as just shipping. Pat > On Wed, Apr 21, 2010 at 7:05 PM, Pat Maddox wrote: >> Cucumber features are the best tool I know of for capturing requirements from my customer. RSpec specs are the best tool I know of for communicating intent and gauging code quality among the developer team. >> >> I'm not sure how exactly you're quantifying a 90/10 or 80/20 split. I would expect that there would be a lot of overlap in coverage. That is, any given line of code is likely to have some cucumber and some rspec coverage. Personally I shoot for 100% RSpec coverage, and Cucumber is based entirely on what my customer wants. If we discuss a new feature or bug fix and they feel I know exactly what they're talking about and don't need a cucumber test for it, I don't write the cucumber test. Cukes are for teasing out requirements, which is most important when there's domain complexity that I don't understand, because I'm a programmer and not a domain expert. Every line of code I write gets RSpec coverage. That's how I personally feel confident that my code does what I think it does, and also helps me keep my dependencies under control. >> >> It's true that you can change out all the underlying code and cucumber tests still pass. But you should be able to change out a lot of code and have your specs still pass, as well. If you're changing the API then some specs might no longer be valid, or need to be moved, or whatever. That's just a part of refactoring. Although to be honest I think focused specs help me refactor more than other people, because I take really small steps when I refactor. When most people "refactor" they tear out a bunch of shit and see if it still works. >> >> Cucumber tests tend to take longer because they're written at a much higher level. That requires more setup, and more steps through the codebase. For that reason, Cucumber isn't particularly good at giving me rapid feedback. I want feedback in 10 seconds rather than 10 minutes. >> >> The best mantra I have for using Cucumber & RSpec in harmony is, "RSpec lets me know my code works right, Cucumber lets me know my code is doing the right work." >> >> On Apr 20, 2010, at 11:33 AM, Ed Howland wrote: >> >>> Please forgive the x-post. >>> >>> I just got back from the Great Lakes Ruby Bash. They had several good >>> presentations, two specific to BDD and Cucumber. I also talked to >>> several CEOs and devs afterwards, and the overall takeaway I gathered >>> was a shift to less RSpec and more Cucumber. Some people even claimed >>> a 90/10 split (cukes/specs) on current projects. >>> >>> This was surorising to me and not at all how I worked up to this >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the >>> code to make the cuke work. Each release had some new features and >>> specs for all the underlying code. Apparently, the feeling is that you >>> should do all your main thrusts with Cucumber and use RSpec for edge >>> cases. The theory is that you can change out all the underlying code >>> and the cukes still pass. >>> >>> What is the communities consensus on this? >>> >>> >>> Cheers, >>> Ed >>> >>> Ed Howland >>> http://greenprogrammer.wordpress.com >>> http://twitter.com/ed_howland >>> >>> -- >>> You received this message because you are subscribed to the Google Groups "Cukes" group. >>> To post to this group, send email to cukes at googlegroups.com. >>> To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. >>> For more options, visit this group at http://groups.google.com/group/cukes?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups "Cukes" group. >> To post to this group, send email to cukes at googlegroups.com. >> To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/cukes?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups "Cukes" group. > To post to this group, send email to cukes at googlegroups.com. > To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com. > For more options, visit this group at http://groups.google.com/group/cukes?hl=en. > From erdoss at gmail.com Tue Apr 27 16:46:16 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Tue, 27 Apr 2010 16:46:16 -0400 Subject: [rspec-users] Rspec 2 and Rails 3 - missing template Message-ID: Hello, I am following the example in the Rspec book, starting page 372, where a controller's create message is spec'd. it "creates a new message" do Message.should_receive(:new).with("text" => "a quick brown fox" ) post :create, :message => { "text" => "a quick brown fox" } end When i run this spec, the test is not being run and a 'Missing Template' error is thrown. Failure/Error: post :create, :question => { "text" =>"a quick brown fox" } Missing template messages/create with {:locale=>[:en, :en], :handlers=>[:haml, :rjs, :builder, :rhtml, :erb, :rxml], :formats=>[:html]} in view paths "/myapps/app/views" I am using Rspec 2, Rails 3 and Haml. Did anybody else have this issue? Has something changed in the Rspec api, but it hasn't been updated in the book? Thanks, -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Apr 27 16:51:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 15:51:36 -0500 Subject: [rspec-users] Rspec 2 and Rails 3 - missing template In-Reply-To: References: Message-ID: <9307D322-8ECC-487F-B991-F8DAEB7DE4C7@gmail.com> On Apr 27, 2010, at 3:46 PM, Andrei Erdoss wrote: > Hello, > > I am following the example in the Rspec book, starting page 372, where a controller's create message is spec'd. > > it "creates a new message" do > Message.should_receive(:new).with("text" => "a quick brown fox" ) > post :create, :message => { "text" => "a quick brown fox" } > end > > When i run this spec, the test is not being run and a 'Missing Template' error is thrown. > > Failure/Error: post :create, :question => { "text" =>"a quick brown fox" } > Missing template messages/create with {:locale=>[:en, :en], :handlers=>[:haml, :rjs, :builder, :rhtml, :erb, :rxml], :formats=>[:html]} in view paths "/myapps/app/views" > > > I am using Rspec 2, Rails 3 and Haml. > > Did anybody else have this issue? Has something changed in the Rspec api, but it hasn't been updated in the book? The book has not been updated to Rails 3, nor does rspec-rails-2.0.0.beta.8 provide isolation from view templates. Please use the versions cited in the book as you go through the book. Cheers, Davidf From erdoss at gmail.com Tue Apr 27 17:04:08 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Tue, 27 Apr 2010 17:04:08 -0400 Subject: [rspec-users] Rspec 2 and Rails 3 - missing template In-Reply-To: <9307D322-8ECC-487F-B991-F8DAEB7DE4C7@gmail.com> References: <9307D322-8ECC-487F-B991-F8DAEB7DE4C7@gmail.com> Message-ID: Thank you for the fast response. What's the best way to handle the scenario described with Rails 3, Rspec 2? On Tue, Apr 27, 2010 at 4:51 PM, David Chelimsky wrote: > On Apr 27, 2010, at 3:46 PM, Andrei Erdoss wrote: > > > Hello, > > > > I am following the example in the Rspec book, starting page 372, where a > controller's create message is spec'd. > > > > it "creates a new message" do > > Message.should_receive(:new).with("text" => "a quick brown > fox" ) > > post :create, :message => { "text" => "a quick brown fox" } > > end > > > > When i run this spec, the test is not being run and a 'Missing Template' > error is thrown. > > > > Failure/Error: post :create, :question => { "text" =>"a quick brown fox" > } > > Missing template messages/create with {:locale=>[:en, :en], > :handlers=>[:haml, :rjs, :builder, :rhtml, :erb, :rxml], :formats=>[:html]} > in view paths "/myapps/app/views" > > > > > > I am using Rspec 2, Rails 3 and Haml. > > > > Did anybody else have this issue? Has something changed in the Rspec api, > but it hasn't been updated in the book? > > The book has not been updated to Rails 3, nor does rspec-rails-2.0.0.beta.8 > provide isolation from view templates. > > Please use the versions cited in the book as you go through the book. > > Cheers, > Davidf > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Apr 27 17:12:20 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 16:12:20 -0500 Subject: [rspec-users] Rspec 2 and Rails 3 - missing template In-Reply-To: References: <9307D322-8ECC-487F-B991-F8DAEB7DE4C7@gmail.com> Message-ID: On Tue, Apr 27, 2010 at 4:04 PM, Andrei Erdoss wrote: > Thank you for the fast response. What's the best way to handle the scenario > described with Rails 3, Rspec 2? touch messages/create.html.haml :) Keep in mind that once rails 3 and rspec 2 go final, we'll have this worked out. Everything's still in beta (and in progress) right now. > > On Tue, Apr 27, 2010 at 4:51 PM, David Chelimsky > wrote: >> >> On Apr 27, 2010, at 3:46 PM, Andrei Erdoss wrote: >> >> > Hello, >> > >> > I am following the example in the Rspec book, starting page 372, where a >> > controller's create message is spec'd. >> > >> > it "creates a new message" do >> > ? Message.should_receive(:new).with("text" ? ?=> ? ?"a ? ?quick ? ?brown >> > ? ?fox" ) >> > ? post :create, :message => { "text" => "a quick brown fox" } >> > end >> > >> > When i run this spec, the test is not being run and a 'Missing Template' >> > error is thrown. >> > >> > Failure/Error: post :create, :question => { "text" =>"a quick brown fox" >> > } >> > ? ? Missing template messages/create with {:locale=>[:en, :en], >> > :handlers=>[:haml, :rjs, :builder, :rhtml, :erb, :rxml], :formats=>[:html]} >> > in view paths "/myapps/app/views" >> > >> > >> > I am using Rspec 2, Rails 3 and Haml. >> > >> > Did anybody else have this issue? Has something changed in the Rspec >> > api, but it hasn't been updated in the book? >> >> The book has not been updated to Rails 3, nor does >> rspec-rails-2.0.0.beta.8 provide isolation from view templates. >> >> Please use the versions cited in the book as you go through the book. >> >> Cheers, >> Davidf >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Andrei Erdoss > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Apr 27 17:12:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 16:12:46 -0500 Subject: [rspec-users] Rspec 2 and Rails 3 - missing template In-Reply-To: References: <9307D322-8ECC-487F-B991-F8DAEB7DE4C7@gmail.com> Message-ID: On Tue, Apr 27, 2010 at 4:12 PM, David Chelimsky wrote: > On Tue, Apr 27, 2010 at 4:04 PM, Andrei Erdoss wrote: >> Thank you for the fast response. What's the best way to handle the scenario >> described with Rails 3, Rspec 2? > > touch messages/create.html.haml :) or, rather: touch app/views/messages/create.html.haml > > Keep in mind that once rails 3 and rspec 2 go final, we'll have this > worked out. Everything's still in beta (and in progress) right now. > >> >> On Tue, Apr 27, 2010 at 4:51 PM, David Chelimsky >> wrote: >>> >>> On Apr 27, 2010, at 3:46 PM, Andrei Erdoss wrote: >>> >>> > Hello, >>> > >>> > I am following the example in the Rspec book, starting page 372, where a >>> > controller's create message is spec'd. >>> > >>> > it "creates a new message" do >>> > ? Message.should_receive(:new).with("text" ? ?=> ? ?"a ? ?quick ? ?brown >>> > ? ?fox" ) >>> > ? post :create, :message => { "text" => "a quick brown fox" } >>> > end >>> > >>> > When i run this spec, the test is not being run and a 'Missing Template' >>> > error is thrown. >>> > >>> > Failure/Error: post :create, :question => { "text" =>"a quick brown fox" >>> > } >>> > ? ? Missing template messages/create with {:locale=>[:en, :en], >>> > :handlers=>[:haml, :rjs, :builder, :rhtml, :erb, :rxml], :formats=>[:html]} >>> > in view paths "/myapps/app/views" >>> > >>> > >>> > I am using Rspec 2, Rails 3 and Haml. >>> > >>> > Did anybody else have this issue? Has something changed in the Rspec >>> > api, but it hasn't been updated in the book? >>> >>> The book has not been updated to Rails 3, nor does >>> rspec-rails-2.0.0.beta.8 provide isolation from view templates. >>> >>> Please use the versions cited in the book as you go through the book. >>> >>> Cheers, >>> Davidf >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> -- >> Andrei Erdoss >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From patrick at collinatorstudios.com Tue Apr 27 17:20:02 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 27 Apr 2010 14:20:02 -0700 (PDT) Subject: [rspec-users] more rspec questions Message-ID: Hi everyone, I still am on my quest to understand Rspec, and I have a few new questions... If I have a "complex" method which calls other methods, say something like: ----- class Foo def complex_method setup setup_something_else mini_method1 mini_method2 mini_method3 end private def setup @somevar = Something.something_else end def setup_something_else @someothervar = SomethingElse.something_else end def mini_method1 # do something end ... etc end ----- One way to properly test this would be to write a spec that calls complex_method and it's output returns what I am expecting.. but if it's broken, it becomes difficult for me to figure out why without writing individual tests for the mini_methods. However, I cannot do tests for mini_methods because they are private, and 2ndly they require initializer methods (setup/setup_something_else) to be called. So I am just wondering, what is the proper technique to test these private mini_methods? Patrick J. Collins http://collinatorstudios.com From erdoss at gmail.com Tue Apr 27 17:25:20 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Tue, 27 Apr 2010 17:25:20 -0400 Subject: [rspec-users] Rspec 2 and Rails 3 - missing template In-Reply-To: References: <9307D322-8ECC-487F-B991-F8DAEB7DE4C7@gmail.com> Message-ID: Great! Thanks. Will Rspec 2 provide isolation from view templates or is this a design change? On Tue, Apr 27, 2010 at 5:12 PM, David Chelimsky wrote: > On Tue, Apr 27, 2010 at 4:12 PM, David Chelimsky > wrote: > > On Tue, Apr 27, 2010 at 4:04 PM, Andrei Erdoss wrote: > >> Thank you for the fast response. What's the best way to handle the > scenario > >> described with Rails 3, Rspec 2? > > > > touch messages/create.html.haml :) > > or, rather: > > touch app/views/messages/create.html.haml > > > > > > Keep in mind that once rails 3 and rspec 2 go final, we'll have this > > worked out. Everything's still in beta (and in progress) right now. > > > >> > >> On Tue, Apr 27, 2010 at 4:51 PM, David Chelimsky > >> wrote: > >>> > >>> On Apr 27, 2010, at 3:46 PM, Andrei Erdoss wrote: > >>> > >>> > Hello, > >>> > > >>> > I am following the example in the Rspec book, starting page 372, > where a > >>> > controller's create message is spec'd. > >>> > > >>> > it "creates a new message" do > >>> > Message.should_receive(:new).with("text" => "a quick > brown > >>> > fox" ) > >>> > post :create, :message => { "text" => "a quick brown fox" } > >>> > end > >>> > > >>> > When i run this spec, the test is not being run and a 'Missing > Template' > >>> > error is thrown. > >>> > > >>> > Failure/Error: post :create, :question => { "text" =>"a quick brown > fox" > >>> > } > >>> > Missing template messages/create with {:locale=>[:en, :en], > >>> > :handlers=>[:haml, :rjs, :builder, :rhtml, :erb, :rxml], > :formats=>[:html]} > >>> > in view paths "/myapps/app/views" > >>> > > >>> > > >>> > I am using Rspec 2, Rails 3 and Haml. > >>> > > >>> > Did anybody else have this issue? Has something changed in the Rspec > >>> > api, but it hasn't been updated in the book? > >>> > >>> The book has not been updated to Rails 3, nor does > >>> rspec-rails-2.0.0.beta.8 provide isolation from view templates. > >>> > >>> Please use the versions cited in the book as you go through the book. > >>> > >>> Cheers, > >>> Davidf > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> > >> > >> -- > >> Andrei Erdoss > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From adam.sroka at gmail.com Tue Apr 27 17:39:15 2010 From: adam.sroka at gmail.com (Adam Sroka) Date: Tue, 27 Apr 2010 14:39:15 -0700 Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: On Tue, Apr 27, 2010 at 2:20 PM, Patrick J. Collins wrote: > Hi everyone, > > I still am on my quest to understand Rspec, and I have a few new questions... > > If I have a "complex" method which calls other methods, say something like: > > ----- > > class Foo > > ?def complex_method > ? ? ? ? setup > ? ?setup_something_else > > ? ? ? ? mini_method1 > ? ? ? ? mini_method2 > ? ? ? ? mini_method3 > ?end > > ?private > > ?def setup > ? ?@somevar = Something.something_else > ?end > > ?def setup_something_else > ? ?@someothervar = SomethingElse.something_else > ?end > > ?def mini_method1 > ? ?# do something > ?end > > ?... etc > end > > ----- > > One way to properly test this would be to write a spec that calls > complex_method and it's output returns what I am expecting.. ?but if it's > broken, it becomes difficult for me to figure out why without writing > individual tests for the mini_methods. > Yep. You need small focused specs that each test one bit of behavior so that when they fail you know why. > However, I cannot do tests for mini_methods because they are private, and 2ndly > they require initializer methods (setup/setup_something_else) to be called. > What if they didn't? Is there a different way you could design this so that the interesting bits (The small methods) didn't depend so much on the other bits around them? BTW, those kind of dependencies are what design experts call coupling. Over the years many of us have come to believe that less coupling == better design. The fact that your spec is telling you that this is hard to test is a really important clue that the design could be improved. > So I am just wondering, what is the proper technique to test these > private mini_methods? > Make them public. Move them to their own classes that encapsulate the stuff they need to know about (e.g. the "setup".) When you test the higher level methods you can mock this stuff. When you test the small methods you should call them directly. There are a number of other techniques that might be helpful too. If you have a more specific example of what you are trying to do we might be able to give you more specific advice. From patrick at collinatorstudios.com Tue Apr 27 17:51:22 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 27 Apr 2010 14:51:22 -0700 (PDT) Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: Hi, > What if they didn't? Is there a different way you could design this so > that the interesting bits (The small methods) didn't depend so much on > the other bits around them? > Well this is for importing vCards... http://gist.github.com/381384 So for example, I would like to just make a spec that does: ... before(:all) do card_data = File.read(RAILS_ROOT + "/spec/fixtures/vcard/kirk_no_photo.vcf") @vcard = Vcard.create!(:data => card_data) Contact.all.map(&:destroy) end describe "finding a contact" do it "should find the contact when an email for the contact exists" do email = Email.create!(:address => "kirk at enterprise.com") contact = Contact.create!(:first_name => 'James', :last_name => 'Kirk') contact.emails << email @vcard.find_contact.should == contact end end ... But, like I said, I am not quite sure how to structure it so that my @card ivar gets set.. > Make them public. Move them to their own classes that encapsulate the > stuff they need to know about (e.g. the "setup".) When you test the > higher level methods you can mock this stuff. When you test the small > methods you should call them directly. So is it bad practice then to use private methods? I have a habit of doing that-- but from what you're saying there is no way to test those things individually.... Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Tue Apr 27 17:48:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 16:48:39 -0500 Subject: [rspec-users] Rspec 2 and Rails 3 - missing template In-Reply-To: References: <9307D322-8ECC-487F-B991-F8DAEB7DE4C7@gmail.com> Message-ID: On Apr 27, 2010, at 4:25 PM, Andrei Erdoss wrote: > Great! Thanks. > > Will Rspec 2 provide isolation from view templates or is this a design change? There will be some sort of view isolation, but the jury is out on how it will work. I'm hopeful it will feel exactly like it does in rspec-rails-1. > > On Tue, Apr 27, 2010 at 5:12 PM, David Chelimsky wrote: > On Tue, Apr 27, 2010 at 4:12 PM, David Chelimsky wrote: > > On Tue, Apr 27, 2010 at 4:04 PM, Andrei Erdoss wrote: > >> Thank you for the fast response. What's the best way to handle the scenario > >> described with Rails 3, Rspec 2? > > > > touch messages/create.html.haml :) > > or, rather: > > touch app/views/messages/create.html.haml > > > > > > Keep in mind that once rails 3 and rspec 2 go final, we'll have this > > worked out. Everything's still in beta (and in progress) right now. > > > >> > >> On Tue, Apr 27, 2010 at 4:51 PM, David Chelimsky > >> wrote: > >>> > >>> On Apr 27, 2010, at 3:46 PM, Andrei Erdoss wrote: > >>> > >>> > Hello, > >>> > > >>> > I am following the example in the Rspec book, starting page 372, where a > >>> > controller's create message is spec'd. > >>> > > >>> > it "creates a new message" do > >>> > Message.should_receive(:new).with("text" => "a quick brown > >>> > fox" ) > >>> > post :create, :message => { "text" => "a quick brown fox" } > >>> > end > >>> > > >>> > When i run this spec, the test is not being run and a 'Missing Template' > >>> > error is thrown. > >>> > > >>> > Failure/Error: post :create, :question => { "text" =>"a quick brown fox" > >>> > } > >>> > Missing template messages/create with {:locale=>[:en, :en], > >>> > :handlers=>[:haml, :rjs, :builder, :rhtml, :erb, :rxml], :formats=>[:html]} > >>> > in view paths "/myapps/app/views" > >>> > > >>> > > >>> > I am using Rspec 2, Rails 3 and Haml. > >>> > > >>> > Did anybody else have this issue? Has something changed in the Rspec > >>> > api, but it hasn't been updated in the book? > >>> > >>> The book has not been updated to Rails 3, nor does > >>> rspec-rails-2.0.0.beta.8 provide isolation from view templates. > >>> > >>> Please use the versions cited in the book as you go through the book. > >>> > >>> Cheers, > >>> Davidf > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> > >> > >> -- > >> Andrei Erdoss > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Andrei Erdoss > _______________________________________________ > 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 erdoss at gmail.com Tue Apr 27 17:48:55 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Tue, 27 Apr 2010 17:48:55 -0400 Subject: [rspec-users] Rails 3, Rspec 2 - flash notice Message-ID: Hello, I also tried testing for the flash notice being set, but it's not working. it "sets a flash[:notice] message" do post :create flash[:notice].should == "The message was saved successfully." end this is the line in the controller that's setting the notice. redirect_to messages_path, :notice => "The message was saved successfully." Anybody have some insight on this? -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Apr 27 17:59:37 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 16:59:37 -0500 Subject: [rspec-users] Rails 3, Rspec 2 - flash notice In-Reply-To: References: Message-ID: <10E61622-82D6-4B25-B3B4-94983ECD82EA@gmail.com> On Apr 27, 2010, at 4:48 PM, Andrei Erdoss wrote: > Hello, > > I also tried testing for the flash notice being set, but it's not working. > > it "sets a flash[:notice] message" do > post :create > flash[:notice].should == "The message was saved successfully." > end > > this is the line in the controller that's setting the notice. > > redirect_to messages_path, :notice => "The message was saved successfully." > > Anybody have some insight on this? Are you using rspec-rails-2.0.0.beta.8? From vertebrate at gmail.com Fri Apr 23 11:37:46 2010 From: vertebrate at gmail.com (Steve) Date: Fri, 23 Apr 2010 08:37:46 -0700 (PDT) Subject: [rspec-users] controller_name in rspec-rails2? Message-ID: <5ee4e433-1a62-4ed5-89f0-f34ba71c6061@g30g2000yqc.googlegroups.com> I have some specs that use controller_name because of namespaced temporary controllers in my specs. In rspec-rails2 I'm told that controller_name is not a valid method. Is there a workaround for this? Thanks, Steve From daniel.amselem at gmail.com Fri Apr 23 09:25:31 2010 From: daniel.amselem at gmail.com (Daniel Salmeron Amselem) Date: Fri, 23 Apr 2010 06:25:31 -0700 (PDT) Subject: [rspec-users] (LoadError) no such file to load when using rspec 2.0.0.beta.7, rails 3.0.0.beta3 and ruby 1.9.2 with RVM Message-ID: I am trying to run a test for a controller with the "spec" command like this: spec spec/controllers/account_controller_spec.rb and this is the result: damselem at logicmail$ spec spec/controllers/accounts_controller_spec.rb /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- core-2.0.0.beta.7/lib/rspec/core/configuration.rb:233:in `require': no such file to load -- spec/controllers/accounts_controller_spec.rb (LoadError) from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- core-2.0.0.beta.7/lib/rspec/core/configuration.rb:233:in `block in require_files_to_run' from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- core-2.0.0.beta.7/lib/rspec/core/configuration.rb:233:in `map' from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- core-2.0.0.beta.7/lib/rspec/core/configuration.rb:233:in `require_files_to_run' from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- core-2.0.0.beta.7/lib/rspec/core/runner.rb:37:in `configure' from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- core-2.0.0.beta.7/lib/rspec/core/runner.rb:24:in `run' from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- core-2.0.0.beta.7/lib/rspec/core/runner.rb:12:in `block in autorun' When using "ruby -Ispec spec/controllers/account_controller_spec.rb" everything works fine. Then, I thought that could be a problem with the path to the controller spec, so I tried: "spec ~/Documents/Freelancing/Projects/logicmail/spec/controllers/ accounts_controller_spec.rb" which worked fine. Does anybody know why is this happening? In the previous versions of rspec, I could run the first command without any problem, but now I have to use either the last command with an absolute path or: "spec -I . spec/controllers/accounts_controller_spec.rb" Any thought on this? From curtis.schofield at gmail.com Tue Apr 27 14:39:32 2010 From: curtis.schofield at gmail.com (Curtis Schofield) Date: Tue, 27 Apr 2010 11:39:32 -0700 Subject: [rspec-users] [Cucumber:4242] Cucumber vs, RSpec In-Reply-To: References: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> <61E5E08C-1DBD-4C2B-926A-4A0B82BE6794@patmaddox.com> Message-ID: Single responsibility Principle On Tue, Apr 27, 2010 at 11:38 AM, Curtis Schofield < curtis.schofield at gmail.com> wrote: > Personally SRP violations are making my work hell right now on a 2 year old > rails system. My first concern when re-factoring is putting test in place - > there isn't much coverage when i started. > > I've been doing that for the past 2 weeks and I've found that cucumber is > doing well for getting higher level coverage of 'it works' or 'it needs to > work like this' - but even so - the real guts of the problem is far and away > from Cucumber and so i've been using Cucumber to assist my design by > covering basic behaviors and then writing tests for the places where new > things must live and then moving them in while keeping the cukes functioning > an extracting responsibilities as the rspec tests require. > > It's quite a job - now testing the views is another thing entirely - cuke > sorta works for this - but not so much - since i'm in a codebase that has > degenerated to rhtml bog in many ways - it's a bit of a trick and i have no > really good way to ensure coverage or confidence. > > Great thread. > > > > On Tue, Apr 27, 2010 at 11:14 AM, Pat Maddox wrote: > >> My other contribution to this thread is that if your code is tested >> primarily via Cucumber, you probably have SRP violations all over the place. >> That's what I've noticed in my own code, anyway. >> >> The tricky thing is that SRP violations are not necessarily crippling, >> particularly in Rails apps (where SRP violations are pretty much built-in). >> They just make your test suite a bit slower, limit reuse, etc... things >> that are valuable to us but typically not as valuable as just shipping. >> >> Pat >> >> >> >> > On Wed, Apr 21, 2010 at 7:05 PM, Pat Maddox >> wrote: >> >> Cucumber features are the best tool I know of for capturing >> requirements from my customer. RSpec specs are the best tool I know of for >> communicating intent and gauging code quality among the developer team. >> >> >> >> I'm not sure how exactly you're quantifying a 90/10 or 80/20 split. I >> would expect that there would be a lot of overlap in coverage. That is, any >> given line of code is likely to have some cucumber and some rspec coverage. >> Personally I shoot for 100% RSpec coverage, and Cucumber is based entirely >> on what my customer wants. If we discuss a new feature or bug fix and they >> feel I know exactly what they're talking about and don't need a cucumber >> test for it, I don't write the cucumber test. Cukes are for teasing out >> requirements, which is most important when there's domain complexity that I >> don't understand, because I'm a programmer and not a domain expert. Every >> line of code I write gets RSpec coverage. That's how I personally feel >> confident that my code does what I think it does, and also helps me keep my >> dependencies under control. >> >> >> >> It's true that you can change out all the underlying code and cucumber >> tests still pass. But you should be able to change out a lot of code and >> have your specs still pass, as well. If you're changing the API then some >> specs might no longer be valid, or need to be moved, or whatever. That's >> just a part of refactoring. Although to be honest I think focused specs >> help me refactor more than other people, because I take really small steps >> when I refactor. When most people "refactor" they tear out a bunch of shit >> and see if it still works. >> >> >> >> Cucumber tests tend to take longer because they're written at a much >> higher level. That requires more setup, and more steps through the >> codebase. For that reason, Cucumber isn't particularly good at giving me >> rapid feedback. I want feedback in 10 seconds rather than 10 minutes. >> >> >> >> The best mantra I have for using Cucumber & RSpec in harmony is, "RSpec >> lets me know my code works right, Cucumber lets me know my code is doing the >> right work." >> >> >> >> On Apr 20, 2010, at 11:33 AM, Ed Howland wrote: >> >> >> >>> Please forgive the x-post. >> >>> >> >>> I just got back from the Great Lakes Ruby Bash. They had several good >> >>> presentations, two specific to BDD and Cucumber. I also talked to >> >>> several CEOs and devs afterwards, and the overall takeaway I gathered >> >>> was a shift to less RSpec and more Cucumber. Some people even claimed >> >>> a 90/10 split (cukes/specs) on current projects. >> >>> >> >>> This was surorising to me and not at all how I worked up to this >> >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the >> >>> code to make the cuke work. Each release had some new features and >> >>> specs for all the underlying code. Apparently, the feeling is that you >> >>> should do all your main thrusts with Cucumber and use RSpec for edge >> >>> cases. The theory is that you can change out all the underlying code >> >>> and the cukes still pass. >> >>> >> >>> What is the communities consensus on this? >> >>> >> >>> >> >>> Cheers, >> >>> Ed >> >>> >> >>> Ed Howland >> >>> http://greenprogrammer.wordpress.com >> >>> http://twitter.com/ed_howland >> >>> >> >>> -- >> >>> You received this message because you are subscribed to the Google >> Groups "Cukes" group. >> >>> To post to this group, send email to cukes at googlegroups.com. >> >>> To unsubscribe from this group, send email to >> cukes+unsubscribe at googlegroups.com >> . >> >>> For more options, visit this group at >> http://groups.google.com/group/cukes?hl=en. >> >>> >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups "Cukes" group. >> >> To post to this group, send email to cukes at googlegroups.com. >> >> To unsubscribe from this group, send email to >> cukes+unsubscribe at googlegroups.com >> . >> >> For more options, visit this group at >> http://groups.google.com/group/cukes?hl=en. >> >> >> >> >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups "Cukes" group. >> > To post to this group, send email to cukes at googlegroups.com. >> > To unsubscribe from this group, send email to >> cukes+unsubscribe at googlegroups.com >> . >> > For more options, visit this group at >> http://groups.google.com/group/cukes?hl=en. >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Cukes" group. >> To post to this group, send email to cukes at googlegroups.com. >> To unsubscribe from this group, send email to >> cukes+unsubscribe at googlegroups.com >> . >> For more options, visit this group at >> http://groups.google.com/group/cukes?hl=en. >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From curtis.schofield at gmail.com Tue Apr 27 14:38:54 2010 From: curtis.schofield at gmail.com (Curtis Schofield) Date: Tue, 27 Apr 2010 11:38:54 -0700 Subject: [rspec-users] [Cucumber:4242] Cucumber vs, RSpec In-Reply-To: <61E5E08C-1DBD-4C2B-926A-4A0B82BE6794@patmaddox.com> References: <6F9DE766-D161-4F9E-A198-4E4BD9330519@patmaddox.com> <61E5E08C-1DBD-4C2B-926A-4A0B82BE6794@patmaddox.com> Message-ID: Personally SRP violations are making my work hell right now on a 2 year old rails system. My first concern when re-factoring is putting test in place - there isn't much coverage when i started. I've been doing that for the past 2 weeks and I've found that cucumber is doing well for getting higher level coverage of 'it works' or 'it needs to work like this' - but even so - the real guts of the problem is far and away from Cucumber and so i've been using Cucumber to assist my design by covering basic behaviors and then writing tests for the places where new things must live and then moving them in while keeping the cukes functioning an extracting responsibilities as the rspec tests require. It's quite a job - now testing the views is another thing entirely - cuke sorta works for this - but not so much - since i'm in a codebase that has degenerated to rhtml bog in many ways - it's a bit of a trick and i have no really good way to ensure coverage or confidence. Great thread. On Tue, Apr 27, 2010 at 11:14 AM, Pat Maddox wrote: > My other contribution to this thread is that if your code is tested > primarily via Cucumber, you probably have SRP violations all over the place. > That's what I've noticed in my own code, anyway. > > The tricky thing is that SRP violations are not necessarily crippling, > particularly in Rails apps (where SRP violations are pretty much built-in). > They just make your test suite a bit slower, limit reuse, etc... things > that are valuable to us but typically not as valuable as just shipping. > > Pat > > > > > On Wed, Apr 21, 2010 at 7:05 PM, Pat Maddox > wrote: > >> Cucumber features are the best tool I know of for capturing requirements > from my customer. RSpec specs are the best tool I know of for communicating > intent and gauging code quality among the developer team. > >> > >> I'm not sure how exactly you're quantifying a 90/10 or 80/20 split. I > would expect that there would be a lot of overlap in coverage. That is, any > given line of code is likely to have some cucumber and some rspec coverage. > Personally I shoot for 100% RSpec coverage, and Cucumber is based entirely > on what my customer wants. If we discuss a new feature or bug fix and they > feel I know exactly what they're talking about and don't need a cucumber > test for it, I don't write the cucumber test. Cukes are for teasing out > requirements, which is most important when there's domain complexity that I > don't understand, because I'm a programmer and not a domain expert. Every > line of code I write gets RSpec coverage. That's how I personally feel > confident that my code does what I think it does, and also helps me keep my > dependencies under control. > >> > >> It's true that you can change out all the underlying code and cucumber > tests still pass. But you should be able to change out a lot of code and > have your specs still pass, as well. If you're changing the API then some > specs might no longer be valid, or need to be moved, or whatever. That's > just a part of refactoring. Although to be honest I think focused specs > help me refactor more than other people, because I take really small steps > when I refactor. When most people "refactor" they tear out a bunch of shit > and see if it still works. > >> > >> Cucumber tests tend to take longer because they're written at a much > higher level. That requires more setup, and more steps through the > codebase. For that reason, Cucumber isn't particularly good at giving me > rapid feedback. I want feedback in 10 seconds rather than 10 minutes. > >> > >> The best mantra I have for using Cucumber & RSpec in harmony is, "RSpec > lets me know my code works right, Cucumber lets me know my code is doing the > right work." > >> > >> On Apr 20, 2010, at 11:33 AM, Ed Howland wrote: > >> > >>> Please forgive the x-post. > >>> > >>> I just got back from the Great Lakes Ruby Bash. They had several good > >>> presentations, two specific to BDD and Cucumber. I also talked to > >>> several CEOs and devs afterwards, and the overall takeaway I gathered > >>> was a shift to less RSpec and more Cucumber. Some people even claimed > >>> a 90/10 split (cukes/specs) on current projects. > >>> > >>> This was surorising to me and not at all how I worked up to this > >>> point. I was more 20/80. I usually cuked a feature, then spec'ed the > >>> code to make the cuke work. Each release had some new features and > >>> specs for all the underlying code. Apparently, the feeling is that you > >>> should do all your main thrusts with Cucumber and use RSpec for edge > >>> cases. The theory is that you can change out all the underlying code > >>> and the cukes still pass. > >>> > >>> What is the communities consensus on this? > >>> > >>> > >>> Cheers, > >>> Ed > >>> > >>> Ed Howland > >>> http://greenprogrammer.wordpress.com > >>> http://twitter.com/ed_howland > >>> > >>> -- > >>> You received this message because you are subscribed to the Google > Groups "Cukes" group. > >>> To post to this group, send email to cukes at googlegroups.com. > >>> To unsubscribe from this group, send email to > cukes+unsubscribe at googlegroups.com . > >>> For more options, visit this group at > http://groups.google.com/group/cukes?hl=en. > >>> > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "Cukes" group. > >> To post to this group, send email to cukes at googlegroups.com. > >> To unsubscribe from this group, send email to > cukes+unsubscribe at googlegroups.com . > >> For more options, visit this group at > http://groups.google.com/group/cukes?hl=en. > >> > >> > > > > -- > > You received this message because you are subscribed to the Google Groups > "Cukes" group. > > To post to this group, send email to cukes at googlegroups.com. > > To unsubscribe from this group, send email to > cukes+unsubscribe at googlegroups.com . > > For more options, visit this group at > http://groups.google.com/group/cukes?hl=en. > > > > -- > You received this message because you are subscribed to the Google Groups > "Cukes" group. > To post to this group, send email to cukes at googlegroups.com. > To unsubscribe from this group, send email to > cukes+unsubscribe at googlegroups.com . > For more options, visit this group at > http://groups.google.com/group/cukes?hl=en. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From adam.sroka at gmail.com Tue Apr 27 18:35:08 2010 From: adam.sroka at gmail.com (Adam Sroka) Date: Tue, 27 Apr 2010 15:35:08 -0700 Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: On Tue, Apr 27, 2010 at 2:51 PM, Patrick J. Collins wrote: > Hi, > >> What if they didn't? Is there a different way you could design this so >> that the interesting bits (The small methods) didn't depend so much on >> the other bits around them? >> > > Well this is for importing vCards... > http://gist.github.com/381384 > > So for example, I would like to just make a spec that does: > > ... > > ?before(:all) do > ? ?card_data = File.read(RAILS_ROOT + "/spec/fixtures/vcard/kirk_no_photo.vcf") > ? ?@vcard = Vcard.create!(:data => card_data) > ? ?Contact.all.map(&:destroy) > ?end > > ?describe "finding a contact" do > > ? ?it "should find the contact when an email for the contact exists" do > ? ? ?email = Email.create!(:address => "kirk at enterprise.com") > ? ? ?contact = Contact.create!(:first_name => 'James', :last_name => 'Kirk') > ? ? ?contact.emails << email > > ? ? ?@vcard.find_contact.should == contact > ? ?end > ?end > > ... > > > But, like I said, I am not quite sure how to structure it so that my @card ivar gets set.. > Based on the above I think the Vcard is a good opportunity for a mock. That would most likely imply that you create the Vcard somewhere else and pass it into this method. Also, you should directly test the implementation of the Vcard outside of this spec (i.e. in it's own spec.) >> Make them public. Move them to their own classes that encapsulate the >> stuff they need to know about (e.g. the "setup".) When you test the >> higher level methods you can mock this stuff. When you test the small >> methods you should call them directly. > > So is it bad practice then to use private methods? ?I have a habit of doing > that-- but from what you're saying there is no way to test those things individually.... > No, it's not bad practice to use private methods. However, private methods should mostly be helpers that encapsulate some small calculation. If the method is interesting enough to be tested on its own then it probably should be part of the public API. If the method is not interesting enough to be tested on its own then it should be private and tested through the public method that calls it. As with anything, YMMV. From dchelimsky at gmail.com Tue Apr 27 18:35:44 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 17:35:44 -0500 Subject: [rspec-users] controller_name in rspec-rails2? In-Reply-To: <5ee4e433-1a62-4ed5-89f0-f34ba71c6061@g30g2000yqc.googlegroups.com> References: <5ee4e433-1a62-4ed5-89f0-f34ba71c6061@g30g2000yqc.googlegroups.com> Message-ID: On Fri, Apr 23, 2010 at 10:37 AM, Steve wrote: > I have some specs that use controller_name because of namespaced > temporary controllers in my specs. In rspec-rails2 I'm told that > controller_name is not a valid method. Is there a workaround for this? Try: describe "blah de blah" do subject { MyTempController } end No guarantees, but probably the right direction. From dchelimsky at gmail.com Tue Apr 27 18:42:04 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Apr 2010 17:42:04 -0500 Subject: [rspec-users] (LoadError) no such file to load when using rspec 2.0.0.beta.7, rails 3.0.0.beta3 and ruby 1.9.2 with RVM In-Reply-To: References: Message-ID: <5C3CB554-6863-42E3-AC3B-3592CA91F6CC@gmail.com> On Apr 23, 2010, at 8:25 AM, Daniel Salmeron Amselem wrote: > I am trying to run a test for a controller with the "spec" command > like this: spec spec/controllers/account_controller_spec.rb and this > is the result: > > damselem at logicmail$ spec spec/controllers/accounts_controller_spec.rb > /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- > core-2.0.0.beta.7/lib/rspec/core/configuration.rb:233:in `require': no > such file to load -- spec/controllers/accounts_controller_spec.rb > (LoadError) > from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- > core-2.0.0.beta.7/lib/rspec/core/configuration.rb:233:in `block in > require_files_to_run' > from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- > core-2.0.0.beta.7/lib/rspec/core/configuration.rb:233:in `map' > from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- > core-2.0.0.beta.7/lib/rspec/core/configuration.rb:233:in > `require_files_to_run' > from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- > core-2.0.0.beta.7/lib/rspec/core/runner.rb:37:in `configure' > from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- > core-2.0.0.beta.7/lib/rspec/core/runner.rb:24:in `run' > from /Users/damselem/.rvm/gems/ruby-1.9.2-head at rails3/gems/rspec- > core-2.0.0.beta.7/lib/rspec/core/runner.rb:12:in `block in autorun' > > When using "ruby -Ispec spec/controllers/account_controller_spec.rb" > everything works fine. Then, I thought that could be a problem with > the path to the controller spec, so I tried: > > "spec ~/Documents/Freelancing/Projects/logicmail/spec/controllers/ > accounts_controller_spec.rb" which worked fine. Does anybody know why > is this happening? In the previous versions of rspec, I could run the > first command without any problem, but now I have to use either the > last command with an absolute path or: > > "spec -I . spec/controllers/accounts_controller_spec.rb" > > Any thought on this? ruby-1.9.2 does not add "." to the load path, so you do need to either add . yourself (with -I) or just prefix the path with ./ rspec ./spec/controllers/accounts_controller_spec.rb HTH, David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Tue Apr 27 18:45:21 2010 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 27 Apr 2010 23:45:21 +0100 Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: On 27 Apr 2010, at 22:51, Patrick J. Collins wrote: > Hi, > >> What if they didn't? Is there a different way you could design this >> so >> that the interesting bits (The small methods) didn't depend so much >> on >> the other bits around them? >> > > Well this is for importing vCards... > http://gist.github.com/381384 > > So for example, I would like to just make a spec that does: > > ... > > before(:all) do > card_data = File.read(RAILS_ROOT + "/spec/fixtures/vcard/ > kirk_no_photo.vcf") > @vcard = Vcard.create!(:data => card_data) > Contact.all.map(&:destroy) > end > > describe "finding a contact" do > > it "should find the contact when an email for the contact exists" > do > email = Email.create!(:address => "kirk at enterprise.com") > contact = Contact.create!(:first_name => 'James', :last_name => > 'Kirk') > contact.emails << email > > @vcard.find_contact.should == contact > end > end > > ... > > > But, like I said, I am not quite sure how to structure it so that my > @card ivar gets set.. > >> Make them public. Move them to their own classes that encapsulate the >> stuff they need to know about (e.g. the "setup".) When you test the >> higher level methods you can mock this stuff. When you test the small >> methods you should call them directly. > > So is it bad practice then to use private methods? I have a habit > of doing > that-- but from what you're saying there is no way to test those > things individually.... It's not bad practice to use private methods - lots of small methods in your classes is a good thing! As Adam says though, when a class gets hard to write microtests for, that's generally a sign that the design needs a re-think. This subject has been discussed at length on this list before. Here's a good example: http://groups.google.com/group/rspec/browse_thread/thread/9e3d879f712ce4f2/030af755918967dd > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From patrick at collinatorstudios.com Tue Apr 27 18:53:13 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 27 Apr 2010 15:53:13 -0700 (PDT) Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: > Also, you should directly test the implementation of the Vcard outside of > this spec (i.e. in it's own spec) Could you explain what you mean by that? Patrick J. Collins http://collinatorstudios.com From patrick at collinatorstudios.com Tue Apr 27 19:02:08 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 27 Apr 2010 16:02:08 -0700 (PDT) Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: > Based on the above I think the Vcard is a good opportunity for a mock. > That would most likely imply that you create the Vcard somewhere else > and pass it into this method. Also, you should directly test the Ok, and regarding mocking-- Something that is still very unclear to me is how can I affect instance variables through mocking? If I do: def master_method @foo = "foo" slave_method end def slave_method @foo end .. it "should be foo" do foo = mock_model(Foo) foo.slave_method.should == "foo" end ... This will be false because @foo is set in the msater method which I am bypassing because I just want to test the slave method. So how can I set an instance variabel within my spec so that @foo will be properly set? Should I use setter/getter methods in this case?? def master_method foo = "foo" slave_method end def slave_method foo end def foo=(new_foo) @foo = new_foo end def foo @foo end ......... ? Is that the way to go??? Patrick J. Collins http://collinatorstudios.com From adam.sroka at gmail.com Tue Apr 27 19:31:28 2010 From: adam.sroka at gmail.com (Adam Sroka) Date: Tue, 27 Apr 2010 16:31:28 -0700 Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: If something in the code you are testing depends on the return value of a method then you would use a stub. e.g.: foo = mock(Foo) foo.stub!(:slave_method).and_return("foo") However, in some cases what matters is not what the method returns but the fact that slave_method gets called. i.e.: foo.should_receive(:slave_method) There is plenty of info about this in the RSpec docs. Re-reading your example, I don't think I would mock Vcard. From what I can see Vcard reads data that you got from a file and creates a list of Contact objects from it. The only interesting thing about Vcard is that it is able to parse this data in string form. So, I would write a spec for that (i.e. what are the interesting permutations of strings that Vcard can parse? And what representation should result from parsing them?) The second interesting thing is that I can create new Contacts and put them into the collection that Vcard maintains. I would consider separating the parsing from maintaining the list as these seem like different responsibilities. There really doesn't seem to be anything else going on here from the information you've given. Contact and Email seem like pure values, so there probably isn't any point in mocking them. However, if they contain some interesting behavior then that should be tested as well. On Tue, Apr 27, 2010 at 4:02 PM, Patrick J. Collins wrote: >> Based on the above I think the Vcard is a good opportunity for a mock. >> That would most likely imply that you create the Vcard somewhere else >> and pass it into this method. Also, you should directly test the > > Ok, and regarding mocking-- ?Something that is still very unclear to me is how > can I affect instance variables through mocking? ?If I do: > > > def master_method > ?@foo = "foo" > > ?slave_method > end > > def slave_method > > ?@foo > > end > > .. > > it "should be foo" do > > ?foo = mock_model(Foo) > > ?foo.slave_method.should == "foo" > > end > > ... > > > This will be false because @foo is set in the msater method which I am > bypassing because I just want to test the slave method. ?So how can I set an > instance variabel within my spec so that @foo will be properly set? ?Should I > use setter/getter methods in this case?? > > def master_method > ?foo = "foo" > > ?slave_method > end > > def slave_method > > ?foo > > end > > def foo=(new_foo) > ?@foo = new_foo > end > > def foo > ?@foo > end > > ......... ? ?Is that the way to go??? > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From patrick at collinatorstudios.com Tue Apr 27 19:56:48 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 27 Apr 2010 16:56:48 -0700 (PDT) Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: > If something in the code you are testing depends on the return value > of a method then you would use a stub. e.g.: Right, but what I am asking is--- if all of my "slave methods" are relying on stored card data from the @card instance variable-- how is the best way to have access to the variable if it's only defined in the master method? if I have a method that does @card.addresses.each do |address| ... end and I want to test that a contact does in fact get a new address created after that method is called with a vcard that has a valid address. I mean, one way to do this would be the getter/setter way-- have a card=/card method.. Another way would be to just pass card into each method def process_addresses(card) card.addresses.each... .. But then I start feeling like my code is going to be less-elegant due to the fact that I am trying to write things that can be tested. Passing in a variable is definitely less elegant than using an instance variable, and a getter/setter is somewhat too (in my opinion). Patrick J. Collins http://collinatorstudios.com From erdoss at gmail.com Tue Apr 27 22:19:33 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Tue, 27 Apr 2010 22:19:33 -0400 Subject: [rspec-users] Rails 3, Rspec 2 - flash notice In-Reply-To: <10E61622-82D6-4B25-B3B4-94983ECD82EA@gmail.com> References: <10E61622-82D6-4B25-B3B4-94983ECD82EA@gmail.com> Message-ID: I am using this line in my Gemfile: gem "rspec-rails", :git => "git:// github.com/rspec/rspec-rails.git" which installs the rspec-rails-2.0.0.beta.7 I tried beta.8 but I get an error: Rspec is not missing constant Matchers! (ArgumentError) On Tue, Apr 27, 2010 at 5:59 PM, David Chelimsky wrote: > On Apr 27, 2010, at 4:48 PM, Andrei Erdoss wrote: > > > Hello, > > > > I also tried testing for the flash notice being set, but it's not > working. > > > > it "sets a flash[:notice] message" do > > post :create > > flash[:notice].should == "The message was saved successfully." > > end > > > > this is the line in the controller that's setting the notice. > > > > redirect_to messages_path, :notice => "The message was saved > successfully." > > > > Anybody have some insight on this? > > Are you using rspec-rails-2.0.0.beta.8? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Apr 28 01:08:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 28 Apr 2010 00:08:12 -0500 Subject: [rspec-users] Rails 3, Rspec 2 - flash notice In-Reply-To: References: <10E61622-82D6-4B25-B3B4-94983ECD82EA@gmail.com> Message-ID: <54069BFC-9DD4-4C2B-BAA5-9B7A25DB2F9A@gmail.com> On Apr 27, 2010, at 9:19 PM, Andrei Erdoss wrote: > I am using this line in my Gemfile: gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git" > > which installs the rspec-rails-2.0.0.beta.7 I released beta.8 yesterday, so if you "bundle install" you should get the update. I just changed controller specs to pull in behavior from rails' functional tests (AC::TestCase) on Sunday in the source code, and released it just this morning. Anything before that would not have supported spec'ing flash messages > I tried beta.8 but I get an error: Rspec is not missing constant Matchers! (ArgumentError) There is a ticket on this: http://github.com/rspec/rspec-rails/issues#issue/12 Unfortunately, I've not been able to reproduce it yet. > On Tue, Apr 27, 2010 at 5:59 PM, David Chelimsky wrote: > On Apr 27, 2010, at 4:48 PM, Andrei Erdoss wrote: > > > Hello, > > > > I also tried testing for the flash notice being set, but it's not working. > > > > it "sets a flash[:notice] message" do > > post :create > > flash[:notice].should == "The message was saved successfully." > > end > > > > this is the line in the controller that's setting the notice. > > > > redirect_to messages_path, :notice => "The message was saved successfully." > > > > Anybody have some insight on this? > > Are you using rspec-rails-2.0.0.beta.8? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Andrei Erdoss > _______________________________________________ > 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 erdoss at gmail.com Wed Apr 28 10:01:58 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Wed, 28 Apr 2010 10:01:58 -0400 Subject: [rspec-users] Rails 3, Rspec 2 - flash notice In-Reply-To: <54069BFC-9DD4-4C2B-BAA5-9B7A25DB2F9A@gmail.com> References: <10E61622-82D6-4B25-B3B4-94983ECD82EA@gmail.com> <54069BFC-9DD4-4C2B-BAA5-9B7A25DB2F9A@gmail.com> Message-ID: The flash notice test is not working in 2.0.0.beta.8. I tried it with redirect_to messages_path, :notice => "message" or redirect_to messages_path, :flash => {:notice => "message" } On Wed, Apr 28, 2010 at 1:08 AM, David Chelimsky wrote: > On Apr 27, 2010, at 9:19 PM, Andrei Erdoss wrote: > > I am using this line in my Gemfile: gem "rspec-rails", :git => "git:// > github.com/rspec/rspec-rails.git" > > which installs the rspec-rails-2.0.0.beta.7 > > > I released beta.8 yesterday, so if you "bundle install" you should get the > update. I just changed controller specs to pull in behavior from rails' > functional tests (AC::TestCase) on Sunday in the source code, and released > it just this morning. Anything before that would not have supported spec'ing > flash messages > > I tried beta.8 but I get an error: Rspec is not missing constant Matchers! > (ArgumentError) > > > There is a ticket on this: > http://github.com/rspec/rspec-rails/issues#issue/12 > > Unfortunately, I've not been able to reproduce it yet. > This happens when specifying directly the gem version in the gem file. gem 'rspec-rails', '>= 2.0.0.beta.8' > > On Tue, Apr 27, 2010 at 5:59 PM, David Chelimsky wrote: > >> On Apr 27, 2010, at 4:48 PM, Andrei Erdoss wrote: >> >> > Hello, >> > >> > I also tried testing for the flash notice being set, but it's not >> working. >> > >> > it "sets a flash[:notice] message" do >> > post :create >> > flash[:notice].should == "The message was saved successfully." >> > end >> > >> > this is the line in the controller that's setting the notice. >> > >> > redirect_to messages_path, :notice => "The message was saved >> successfully." >> > > >> > Anybody have some insight on this? >> >> Are you using rspec-rails-2.0.0.beta.8? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Andrei Erdoss > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattvanhorn at gmail.com Wed Apr 28 12:50:20 2010 From: mattvanhorn at gmail.com (Matthew Van Horn) Date: Wed, 28 Apr 2010 12:50:20 -0400 Subject: [rspec-users] testing against a live environment In-Reply-To: References: Message-ID: <213ADA47-A707-4F35-B656-7B90161B2C6C@gmail.com> I've been using rspec with webrat, for exactly this sort of thing, as detailed here: http://blog.veez.us/2009/09/11/integration-testing-without-cucumber On Apr 27, 2010, at 5:36 AM, Martin DeMello wrote: > I have a series of tests I want to automate, which involve running > shell scripts in a "live" environment (i.e. nothing mocked or > stubbed), and then verifying the state of the system. I thought that, > even though it doesn't fit the classic definition of "testing", RSpec > would still be a handy way to organise the tests. Is it likely to be > useful, or am I going against the grain enough that I'd run into > problems? > > martin > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben.rooney62 at googlemail.com Wed Apr 28 13:19:34 2010 From: ben.rooney62 at googlemail.com (ben rooney) Date: Wed, 28 Apr 2010 18:19:34 +0100 Subject: [rspec-users] File creation Message-ID: Rick Many thanks - I think the idea of breaking out the actual file writing from the code generation is a great one. I don't need to test File I/O - I think I can assume that that works just fine... Many thanks for your help Ben From aidy.lewis at googlemail.com Wed Apr 28 13:53:56 2010 From: aidy.lewis at googlemail.com (aidy lewis) Date: Wed, 28 Apr 2010 18:53:56 +0100 Subject: [rspec-users] .size.should === (4..5) Message-ID: Hi, I would like to test whether an array size is either of two integer obejects mark_up_parser.sorted_xml.size.should === (4..5) However I am recieiving an exception of: expected: 4..5, got: 4 (using ===) Do I need to write a custom matcher? Thanks Aidy From jbhuter at gmail.com Wed Apr 28 14:00:16 2010 From: jbhuter at gmail.com (Jeff Huter) Date: Wed, 28 Apr 2010 11:00:16 -0700 (PDT) Subject: [rspec-users] Google App Engine Message-ID: <45a7a486-458d-494f-b8e6-a9d3b5ca9ae0@r9g2000vbk.googlegroups.com> Can someone provide instructions for setting up rspec with Rails on Google App Engine? From dchelimsky at gmail.com Wed Apr 28 14:01:51 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 28 Apr 2010 13:01:51 -0500 Subject: [rspec-users] .size.should === (4..5) In-Reply-To: References: Message-ID: <1AE02E72-65F4-4061-9D08-AFA457F12C5B@gmail.com> On Apr 28, 2010, at 12:53 PM, aidy lewis wrote: > Hi, > > I would like to test whether an array size is either of two integer obejects > > mark_up_parser.sorted_xml.size.should === (4..5) > > However I am recieiving an exception of: > > expected: 4..5, > got: 4 (using ===) > > Do I need to write a custom matcher? To phrase it like that, yes. You could to this now: [4,5].should include(obj.size) HTH, David From dchelimsky at gmail.com Wed Apr 28 14:03:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 28 Apr 2010 13:03:39 -0500 Subject: [rspec-users] Rails 3, Rspec 2 - flash notice In-Reply-To: References: <10E61622-82D6-4B25-B3B4-94983ECD82EA@gmail.com> <54069BFC-9DD4-4C2B-BAA5-9B7A25DB2F9A@gmail.com> Message-ID: On Apr 28, 2010, at 9:01 AM, Andrei Erdoss wrote: > The flash notice test is not working in 2.0.0.beta.8. I tried it with redirect_to messages_path, :notice => "message" or redirect_to messages_path, :flash => {:notice => "message" } Please add an issue for this: http://github.com/rspec/rspec-rails/issues Thx > > On Wed, Apr 28, 2010 at 1:08 AM, David Chelimsky wrote: > On Apr 27, 2010, at 9:19 PM, Andrei Erdoss wrote: > >> I am using this line in my Gemfile: gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git" >> >> which installs the rspec-rails-2.0.0.beta.7 > > I released beta.8 yesterday, so if you "bundle install" you should get the update. I just changed controller specs to pull in behavior from rails' functional tests (AC::TestCase) on Sunday in the source code, and released it just this morning. Anything before that would not have supported spec'ing flash messages > >> I tried beta.8 but I get an error: Rspec is not missing constant Matchers! (ArgumentError) > > There is a ticket on this: http://github.com/rspec/rspec-rails/issues#issue/12 > > Unfortunately, I've not been able to reproduce it yet. > > This happens when specifying directly the gem version in the gem file. gem 'rspec-rails', '>= 2.0.0.beta.8' > >> On Tue, Apr 27, 2010 at 5:59 PM, David Chelimsky wrote: >> On Apr 27, 2010, at 4:48 PM, Andrei Erdoss wrote: >> >> > Hello, >> > >> > I also tried testing for the flash notice being set, but it's not working. >> > >> > it "sets a flash[:notice] message" do >> > post :create >> > flash[:notice].should == "The message was saved successfully." >> > end >> > >> > this is the line in the controller that's setting the notice. >> > >> > redirect_to messages_path, :notice => "The message was saved successfully." >> > >> > Anybody have some insight on this? >> >> Are you using rspec-rails-2.0.0.beta.8? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> -- >> Andrei Erdoss >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Andrei Erdoss > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From aidy.lewis at googlemail.com Wed Apr 28 14:24:12 2010 From: aidy.lewis at googlemail.com (aidy lewis) Date: Wed, 28 Apr 2010 19:24:12 +0100 Subject: [rspec-users] .size.should === (4..5) In-Reply-To: <1AE02E72-65F4-4061-9D08-AFA457F12C5B@gmail.com> References: <1AE02E72-65F4-4061-9D08-AFA457F12C5B@gmail.com> Message-ID: On 28 April 2010 19:01, David Chelimsky wrote: > To phrase it like that, yes. You could to this now: > > [4,5].should include(obj.size) Nice > HTH, > David Thanks Aidy From patrick at collinatorstudios.com Wed Apr 28 23:10:27 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 28 Apr 2010 20:10:27 -0700 (PDT) Subject: [rspec-users] rcov not working? Message-ID: I followed the instructions in the rspec book to setup rcov. I appened to the end of my RAILS_ROOT/Rakefile: require 'rake' require 'spec/rake/spectask' namespace :spec do desc "Run specs with RCov" Spec::Rake::SpecTask.new('rcov') do |t| t.spec_files = FileList['spec/**/*_spec.rb'] t.rcov = true t.rcov_opts = ['--exclude', '\/Library\/Ruby'] end end When running I get: >rake spec:rcov --trace (in /Users/patrick/coding/rails/xyz_app) ** Invoke spec:rcov (first_time) ** Invoke spec:clobber_rcov (first_time) ** Execute spec:clobber_rcov rm -r coverage rm -r coverage ** Execute spec:rcov /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: No such file or directory -- rcov (LoadError) rake aborted! Command /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib" -S rcov --exclude "spec/*,gems/*" --rails -o "coverage" "/Users/patrick/coding/rails/xyz_app/vendor/gems/rspec-1.2.9/bin/spec" -- "spec/controllers/admin/media_files_controller_spec.rb" "spec/controllers/admin/photos_controller_spec.rb" "spec/controllers/admin/trees_controller_spec.rb" "spec/controllers/admin/webpages_controller_spec.rb" "spec/helpers/admin/media_files_helper_spec.rb" "spec/helpers/admin/trees_helper_spec.rb" "spec/helpers/admin/webpages_helper_spec.rb" "spec/models/flashparam_spec.rb" "spec/models/flashvar_spec.rb" "spec/models/photo_album_spec.rb" "spec/models/vcard_spec.rb" "spec/renderers/content_renderer_spec.rb" "spec/renderers/tree_select_renderer_spec.rb" --options "/Users/patrick/coding/rails/xyz_app/spec/spec.opts" failed /Users/patrick/coding/rails/xyz_app/vendor/gems/rspec-1.2.9/lib/spec/rake/spectask.rb:177:in `define' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1112:in `verbose' /Users/patrick/coding/rails/xyz_app/vendor/gems/rspec-1.2.9/lib/spec/rake/spectask.rb:153:in `define' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:in `load' /usr/bin/rake:19 Patrick J. Collins http://collinatorstudios.com From hooligan495 at gmail.com Thu Apr 29 00:13:08 2010 From: hooligan495 at gmail.com (Jay McGaffigan) Date: Thu, 29 Apr 2010 00:13:08 -0400 Subject: [rspec-users] rcov not working? In-Reply-To: References: Message-ID: It looks like it can't find Rcov... do you have rcov installed? can you rcov --help from a command line? Thanks Jay On Wed, Apr 28, 2010 at 11:10 PM, Patrick J. Collins wrote: > I followed the instructions in the rspec book to setup rcov. ?I appened to the end of my RAILS_ROOT/Rakefile: > require 'rake' > require 'spec/rake/spectask' > namespace :spec do > ?desc "Run specs with RCov" > ? ?Spec::Rake::SpecTask.new('rcov') do |t| > ? ? ? ? ? ? ? ?t.spec_files = FileList['spec/**/*_spec.rb'] > ? ? ? ? ? ? ? ?t.rcov = true > ? ? ? ? ? ? ? ?t.rcov_opts = ['--exclude', '\/Library\/Ruby'] > ? ? ? ?end > end > > When running I get: > >>rake spec:rcov --trace > (in /Users/patrick/coding/rails/xyz_app) > > ** Invoke spec:rcov (first_time) > ** Invoke spec:clobber_rcov (first_time) > ** Execute spec:clobber_rcov > rm -r coverage > rm -r coverage > ** Execute spec:rcov > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: No such file or directory -- rcov (LoadError) > rake aborted! > Command /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib" -S rcov --exclude "spec/*,gems/*" --rails -o "coverage" "/Users/patrick/coding/rails/xyz_app/vendor/gems/rspec-1.2.9/bin/spec" -- "spec/controllers/admin/media_files_controller_spec.rb" "spec/controllers/admin/photos_controller_spec.rb" "spec/controllers/admin/trees_controller_spec.rb" "spec/controllers/admin/webpages_controller_spec.rb" "spec/helpers/admin/media_files_helper_spec.rb" "spec/helpers/admin/trees_helper_spec.rb" "spec/helpers/admin/webpages_helper_spec.rb" "spec/models/flashparam_spec.rb" "spec/models/flashvar_spec.rb" "spec/models/photo_album_spec.rb" "spec/models/vcard_spec.rb" "spec/renderers/content_renderer_spec.rb" "spec/renderers/tree_select_renderer_spec.rb" --options "/Users/patrick/coding/rails/xyz_app/spec/spec.opts" failed > /Users/patrick/coding/rails/xyz_app/vendor/gems/rspec-1.2.9/lib/spec/rake/spectask.rb:177:in `define' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1112:in `verbose' > /Users/patrick/coding/rails/xyz_app/vendor/gems/rspec-1.2.9/lib/spec/rake/spectask.rb:153:in `define' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' > /Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31 > /usr/bin/rake:19:in `load' > /usr/bin/rake:19 > > > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From adam.sroka at gmail.com Thu Apr 29 01:51:07 2010 From: adam.sroka at gmail.com (Adam Sroka) Date: Wed, 28 Apr 2010 22:51:07 -0700 Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: On Tue, Apr 27, 2010 at 4:56 PM, Patrick J. Collins wrote: >> If something in the code you are testing depends on the return value >> of a method then you would use a stub. e.g.: > Right, but what I am asking is--- ?if all of my "slave methods" are relying on > stored card data from the @card instance variable-- ?how is the best way to > have access to the variable if it's only defined in the master method? > > if I have a method that does > > @card.addresses.each do |address| > ?... > end > > and I want to test that a contact does in fact get a new address created after > that method is called with a vcard that has a valid address. > It might be that the problem is with the way you are stating your test. It seems to me that the code you wrote above is the least interesting part. We can just assume that iterating over addresses works, it is what we do with them that is interesting. So that leaves us with two ideas: 1) is an address that a vcard contains valid? 2) can I add an address to a contact. I would go a step further and say that adding an address to card is not very interesting (Just like iterating over addresses, adding them should work out of the box assuming Ruby itself isn't broken.) So if the only interesting part of the above is that vcards can parse addresses then there should be a public method for that which you test by passing in a string and getting out an address object. > I mean, one way to do this would be the getter/setter way-- have a card=/card > method.. > > Another way would be to just pass card into each method > > def process_addresses(card) > > card.addresses.each... > > > .. ?But then I start feeling like my code is going to be less-elegant due to > the fact that I am trying to write things that can be tested. ?Passing in a > variable is definitely less elegant than using an instance variable, and a > getter/setter is somewhat too (in my opinion). > I wouldn't say that it was a good idea to create a way to pass in a card just for the sake of the test. However, I am presuming that at some point you are going to want to do something with the cards. Otherwise, why have them in the first place. So, if there is some logic that gets the cards, and you have a Spec for that, then you will need to set them somehow so that that Spec works. From patrick at collinatorstudios.com Thu Apr 29 02:37:26 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 28 Apr 2010 23:37:26 -0700 (PDT) Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: > I would go a step further and say that adding an address to card is > not very interesting (Just like iterating over addresses, adding them > should work out of the box assuming Ruby itself isn't broken.) Well, I ended up restructuring my code and I wrote tests for everything I thought were important that would help me know when something is broken. Maybe you'd say some of these cases aren't necessary-- I don't know.. But when I was going through my code and making sure it worked, the tests seemed to be very helpful for me... Here's how it looks now: http://gist.github.com/383233 I solved my @contact.photo = problem by approaching it a different way... Though I still wish someone could tell me what the deal was with that mock expectation error. No one seemed to reply to that question... Anyway, everything passes so I guess I can move on to the next thing... Patrick J. Collins http://collinatorstudios.com From timo.roessner at googlemail.com Thu Apr 29 06:27:23 2010 From: timo.roessner at googlemail.com (jollyroger) Date: Thu, 29 Apr 2010 03:27:23 -0700 (PDT) Subject: [rspec-users] rspec doesnt recognize a custom mime type Message-ID: <05510e28-b0b6-4ecc-8fe7-58f2bb308eab@d39g2000yqa.googlegroups.com> Hey guys, I have a custom MIME type registered like that: cat config/initializers/mime_types.rb Mime::Type.register "lightbox", :lightbox -> This works perfectly well in my application. However my corresponding specs keep failing, the code: The controller-spec: describe UserSessionsController do describe 'new action' do it 'should render the new-template on lightbox-request' do get :new, :format => :lightbox response.should render_template(:new) end end end The controller-action: def new @user_session = UserSession.new respond_to do |format| format.lightbox do render :layout => false end format.html do render end end end Running the spec: bin/spec spec/controllers/user_sessions_controller_spec.rb -l 25 F 1) 'UserSessionsController new action should render the new-template on lightbox-request' FAILED expected "new", got nil ./spec/controllers/user_sessions_controller_spec.rb: 26: Finished in 0.338956 1 example, 1 failure With line 26 of the spec being: response.should render_template(:new) The interesting thing now is in test.log: Processing UserSessionsController#new to lightbox (for 0.0.0.0 at 2010-04-29 11:31:41) [GET] Parameters: {"format"=>:lightbox, "action"=>"new", "controller"=>"user_sessions"} Completed in 84ms (View: 2, DB: 558) | 406 Not Acceptable [http:// test.host/user_sessions/new.lightbox] SQL (10.0ms) ROLLBACK Hmmm -> 406 Not Acceptable? However, i can call up http://test.host/user_sessions/new.lightbox manually in the browser without problems - the view is rendered, without a layout, just as specified in the controller. So this seems to be an rspec-specific problem - any ideas on how to proceed? From timo.roessner at googlemail.com Thu Apr 29 08:40:48 2010 From: timo.roessner at googlemail.com (jollyroger) Date: Thu, 29 Apr 2010 05:40:48 -0700 (PDT) Subject: [rspec-users] rspec doesnt recognize a custom mime type In-Reply-To: <05510e28-b0b6-4ecc-8fe7-58f2bb308eab@d39g2000yqa.googlegroups.com> References: <05510e28-b0b6-4ecc-8fe7-58f2bb308eab@d39g2000yqa.googlegroups.com> Message-ID: Ok, fixed it, in a nutshell: Doesnt work: get :new, :format => :lightbox Works: get :new, :format => 'lightbox' What was really confusing was that in BOTH cases the same URL appeared in the log. Here is my turn on what happened: Internally - when rails sees a mime-type / format - rails distinguishes between a string and a symbol, saying that when using something like respond_to do |format| format.lightbox {} end "lightbox" is expected to be a string. When doing a normal request via a browser I passed in the format in the URL, so as a string. When running a spec apparently this is passed directly the way I wrote it, so as a symbol. That's why one and the same URL worked in the browser, but not in my spec. Does this sound plausible? From dchelimsky at gmail.com Thu Apr 29 09:00:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 29 Apr 2010 08:00:22 -0500 Subject: [rspec-users] rspec doesnt recognize a custom mime type In-Reply-To: References: <05510e28-b0b6-4ecc-8fe7-58f2bb308eab@d39g2000yqa.googlegroups.com> Message-ID: <330DC160-1984-46B3-B245-704DA1991F3D@gmail.com> On Apr 29, 2010, at 7:40 AM, jollyroger wrote: > Ok, > > fixed it, in a nutshell: > > Doesnt work: > > get :new, :format => :lightbox > > Works: > > get :new, :format => 'lightbox' > > What was really confusing was that in BOTH cases the same URL appeared > in the log. > > Here is my turn on what happened: > > Internally - when rails sees a mime-type / format - rails > distinguishes between a string and a symbol, saying that when using > something like > > respond_to do |format| > format.lightbox {} > end > > "lightbox" is expected to be a string. > > When doing a normal request via a browser I passed in the format in > the URL, so as a string. > When running a spec apparently this is passed directly the way I wrote > it, so as a symbol. > > That's why one and the same URL worked in the browser, but not in my > spec. > > Does this sound plausible? Definitely. I believe what's happening is that the options hash produced by the Rails router is a hash with indifferent access (allows you to access any key as a symbol or a string), but the test helper methods (get, post, etc) don't do the same thing. Glad you solved it. Cheers, David From phillipkoebbe at gmail.com Thu Apr 29 09:10:52 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 29 Apr 2010 08:10:52 -0500 Subject: [rspec-users] rspec doesnt recognize a custom mime type In-Reply-To: References: <05510e28-b0b6-4ecc-8fe7-58f2bb308eab@d39g2000yqa.googlegroups.com> Message-ID: <4BD9855C.70305@gmail.com> On 2010-04-29 7:40 AM, jollyroger wrote: > Ok, > > fixed it, in a nutshell: > > Doesnt work: > > get :new, :format => :lightbox > > Works: > > get :new, :format => 'lightbox' > > What was really confusing was that in BOTH cases the same URL appeared > in the log. > > Here is my turn on what happened: > > Internally - when rails sees a mime-type / format - rails > distinguishes between a string and a symbol, saying that when using > something like > > respond_to do |format| > format.lightbox {} > end > > "lightbox" is expected to be a string. > > When doing a normal request via a browser I passed in the format in > the URL, so as a string. > When running a spec apparently this is passed directly the way I wrote > it, so as a symbol. > > That's why one and the same URL worked in the browser, but not in my > spec. > > Does this sound plausible? Perfectly. I struggled with this a couple of months ago doing something like: get :show, {:id => 1} and whatever it was in my controller wasn't expecting an integer, so I had to change it to: get :show, {:id => '1'} and it was fine. As I dug into it, I noticed that the params hash in controllers has everything as strings, and then the light bulb went on in my head. Since then, I've paid more attention to what the params hash in my specs looks like. And I'm sure you will, too :) Peace, Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From erdoss at gmail.com Thu Apr 29 09:55:05 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Thu, 29 Apr 2010 09:55:05 -0400 Subject: [rspec-users] Rails 3, Rspec 2 - flash notice In-Reply-To: References: <10E61622-82D6-4B25-B3B4-94983ECD82EA@gmail.com> <54069BFC-9DD4-4C2B-BAA5-9B7A25DB2F9A@gmail.com> Message-ID: My mistake. I left out a very important piece of the spec. @message.stub(:save).and_return(true) Everything is working fine. Thanks for your help. On Wed, Apr 28, 2010 at 2:03 PM, David Chelimsky wrote: > On Apr 28, 2010, at 9:01 AM, Andrei Erdoss wrote: > > The flash notice test is not working in 2.0.0.beta.8. I tried it with > redirect_to messages_path, :notice => "message" or redirect_to > messages_path, :flash => {:notice => "message" } > > > Please add an issue for this: > > http://github.com/rspec/rspec-rails/issues > > Thx > > > On Wed, Apr 28, 2010 at 1:08 AM, David Chelimsky wrote: > >> On Apr 27, 2010, at 9:19 PM, Andrei Erdoss wrote: >> >> I am using this line in my Gemfile: gem "rspec-rails", :git => "git:// >> github.com/rspec/rspec-rails.git" >> >> which installs the rspec-rails-2.0.0.beta.7 >> >> >> I released beta.8 yesterday, so if you "bundle install" you should get the >> update. I just changed controller specs to pull in behavior from rails' >> functional tests (AC::TestCase) on Sunday in the source code, and released >> it just this morning. Anything before that would not have supported spec'ing >> flash messages >> >> I tried beta.8 but I get an error: Rspec is not missing constant Matchers! >> (ArgumentError) >> >> >> There is a ticket on this: >> http://github.com/rspec/rspec-rails/issues#issue/12 >> >> Unfortunately, I've not been able to reproduce it yet. >> > > This happens when specifying directly the gem version in the gem file. gem > 'rspec-rails', '>= 2.0.0.beta.8' > >> >> On Tue, Apr 27, 2010 at 5:59 PM, David Chelimsky wrote: >> >>> On Apr 27, 2010, at 4:48 PM, Andrei Erdoss wrote: >>> >>> > Hello, >>> > >>> > I also tried testing for the flash notice being set, but it's not >>> working. >>> > >>> > it "sets a flash[:notice] message" do >>> > post :create >>> > flash[:notice].should == "The message was saved successfully." >>> > end >>> > >>> > this is the line in the controller that's setting the notice. >>> > >>> > redirect_to messages_path, :notice => "The message was saved >>> successfully." >>> >> > >>> > Anybody have some insight on this? >>> >>> Are you using rspec-rails-2.0.0.beta.8? >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> >> -- >> Andrei Erdoss >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Andrei Erdoss > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From martindemello at gmail.com Thu Apr 29 10:21:25 2010 From: martindemello at gmail.com (Martin DeMello) Date: Thu, 29 Apr 2010 19:51:25 +0530 Subject: [rspec-users] testing against a live environment In-Reply-To: References: Message-ID: On Tue, Apr 27, 2010 at 3:32 PM, Matt Wynne wrote: > > Should be fine, though you might find cucumber/aruba a nice combination for > this too. Cucumber seems to make things a lot more verbose :( Very ingenious idea, but in practice I prefer specifying stuff in ruby to specifying it in English. martin From martindemello at gmail.com Thu Apr 29 10:25:36 2010 From: martindemello at gmail.com (Martin DeMello) Date: Thu, 29 Apr 2010 19:55:36 +0530 Subject: [rspec-users] testing against a live environment In-Reply-To: <213ADA47-A707-4F35-B656-7B90161B2C6C@gmail.com> References: <213ADA47-A707-4F35-B656-7B90161B2C6C@gmail.com> Message-ID: On Wed, Apr 28, 2010 at 10:20 PM, Matthew Van Horn wrote: > I've been using rspec with webrat, for exactly this sort of thing, as > detailed here: > http://blog.veez.us/2009/09/11/integration-testing-without-cucumber Thanks! martin From joahking at gmail.com Thu Apr 29 10:40:23 2010 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Thu, 29 Apr 2010 16:40:23 +0200 Subject: [rspec-users] testing against a live environment In-Reply-To: References: Message-ID: maybe then check http://github.com/cavalle/steak joaquin 2010/4/29 Martin DeMello > On Tue, Apr 27, 2010 at 3:32 PM, Matt Wynne wrote: > > > > Should be fine, though you might find cucumber/aruba a nice combination > for > > this too. > > Cucumber seems to make things a lot more verbose :( Very ingenious > idea, but in practice I prefer specifying stuff in ruby to specifying > it in English. > > martin > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- www.least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Apr 29 10:54:32 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Thu, 29 Apr 2010 16:54:32 +0200 Subject: [rspec-users] Cucumber login problem Message-ID: <91937a525bdf260e3ee6abb47b22678d@ruby-forum.com> Hello all, I am facing a weird problem.I am just trying to login but after entering correct parameters it is showing error as invalid username and password. I think there is some configuration or fixtures problem because if i try to login from GUI then it is working fine(using same database) Following are the detailed list of gems and code. Rspec (1.3.0, 1.1.12) Rspec-rails (1.3.2, 1.1.12) cucumber (0.6.3) cucumber-rails (0.3.0) Webrat (0.5.3, 0.4.3) config/environments/cucumber.rb # Edit at your own peril - it's recommended to regenerate this file # in the future when you upgrade to a newer version of Cucumber. # IMPORTANT: Setting config.cache_classes to false is known to # break Cucumber's use_transactional_fixtures method. # For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165 config.cache_classes = true # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails')) config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner')) config.gem 'webrat', :lib => false, :version => '>=0.5.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat')) config.gem 'rspec', :lib => false, :version => '>=1.3.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec')) config.gem 'rspec-rails', :lib => false, :version => '>=1.3.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails')) features/support/env.rb # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. # It is recommended to regenerate this file in the future when you upgrade to a # newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. ENV["RAILS_ENV"] ||= "test" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support require 'cucumber/rails/rspec' require 'cucumber/rails/world' require 'cucumber/rails/active_record' require 'cucumber/web/tableish' require 'webrat' require 'webrat/core/matchers' Webrat.configure do |config| config.mode = :rails config.open_error_files = false # Set to true if you want error pages to pop up in the browser end Before do Fixtures.reset_cache fixtures_folder = File.join(RAILS_ROOT, 'spec', 'fixtures') fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') } Fixtures.create_fixtures(fixtures_folder, fixtures) end # If you set this to false, any error raised from within your app will bubble # up to your step definition and out to cucumber unless you catch it somewhere # on the way. You can make Rails rescue errors and render error pages on a # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag. # # If you set this to true, Rails will rescue all errors and render error # pages, more or less in the same way your application would behave in the # default production environment. It's not recommended to do this for all # of your scenarios, as this makes it hard to discover errors in your application. ActionController::Base.allow_rescue = false # If you set this to true, each scenario will run in a database transaction. # You can still turn off transactions on a per-scenario basis, simply tagging # a feature or scenario with the @no-txn tag. If you are using Capybara, # tagging with @culerity or @javascript will also turn transactions off. # # If you set this to false, transactions will be off for all scenarios, # regardless of whether you use @no-txn or not. # # Beware that turning transactions off will leave data in your database # after each scenario, which can lead to hard-to-debug failures in # subsequent scenarios. If you do this, we recommend you create a Before # block that will explicitly put your database in a known state. Cucumber::Rails::World.use_transactional_fixtures = true # How to clean your database when transactions are turned off. See # http://github.com/bmabey/database_cleaner for more info. if defined?(ActiveRecord::Base) begin require 'database_cleaner' DatabaseCleaner.strategy = :truncation rescue LoadError => ignore_if_database_cleaner_not_present end end features/manage_users.feature Given a registered user When he clicks on login link And after filling all the details Then the user should be logged in features/step_definitions/user_steps.rb Given /^a registered user$/ do visit '/login' end When /^he clicks on login link$/ do visit '/login' fill_in("login", :with => "test") fill_in("password", :with => "test123") click_button "Log in" p current_url p response.body end Then /^that user should get created$/ do @user = User.find_by_login("test") @user.test.should == "test" end This is my whole scenario.Now if i see the current url it says '/session' which actually should be '/users' and in response.body it says 'invalid username and password' Also in my database list of users are already present Please suggest -- Posted via http://www.ruby-forum.com/. From chris.webstar at gmail.com Thu Apr 29 11:29:10 2010 From: chris.webstar at gmail.com (Michishige Kaito) Date: Thu, 29 Apr 2010 16:29:10 +0100 Subject: [rspec-users] Google App Engine In-Reply-To: <45a7a486-458d-494f-b8e6-a9d3b5ca9ae0@r9g2000vbk.googlegroups.com> References: <45a7a486-458d-494f-b8e6-a9d3b5ca9ae0@r9g2000vbk.googlegroups.com> Message-ID: 2010/4/28 Jeff Huter > Can someone provide instructions for setting up rspec with Rails on > Google App Engine? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I know I'm not answering your question but why would you want rspec to run on app engine? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbhuter at gmail.com Thu Apr 29 11:37:51 2010 From: jbhuter at gmail.com (Jeff Huter) Date: Thu, 29 Apr 2010 08:37:51 -0700 (PDT) Subject: [rspec-users] Google App Engine In-Reply-To: References: <45a7a486-458d-494f-b8e6-a9d3b5ca9ae0@r9g2000vbk.googlegroups.com> Message-ID: <212dbea7-f690-41b3-a747-aeff2f81e15e@s29g2000yqd.googlegroups.com> \> > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > I know I'm not answering your question but why would you want rspec to run > on app engine? Probably a poorly worded question. I'm toying with the idea of moving a rails app to the Google App Engine. The Google App Engine creates a skeletal rails app on the dev machine which you can publish to the App Engine. The skeletal app uses Datamapper, NullDB, and jruby. The issue I have is that I can't seem to get rspec to work within this environment so that I can test the app on the dev machine before publishing it to the App Engine. From dchelimsky at gmail.com Thu Apr 29 11:55:18 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 29 Apr 2010 10:55:18 -0500 Subject: [rspec-users] Cucumber login problem In-Reply-To: <91937a525bdf260e3ee6abb47b22678d@ruby-forum.com> References: <91937a525bdf260e3ee6abb47b22678d@ruby-forum.com> Message-ID: On Apr 29, 2010, at 9:54 AM, Amit Kulkarni wrote: > Hello all, > I am facing a weird problem.I am just trying to login but after entering > correct parameters it is showing error as invalid username and password. > I think there is some configuration or fixtures problem because if i try > to login from GUI then it is working fine(using same database) > Following are the detailed list of gems and code. > Rspec (1.3.0, 1.1.12) > Rspec-rails (1.3.2, 1.1.12) > cucumber (0.6.3) > cucumber-rails (0.3.0) > Webrat (0.5.3, 0.4.3) > > config/environments/cucumber.rb > # Edit at your own peril - it's recommended to regenerate this file > # in the future when you upgrade to a newer version of Cucumber. > > # IMPORTANT: Setting config.cache_classes to false is known to > # break Cucumber's use_transactional_fixtures method. > # For more information see > https://rspec.lighthouseapp.com/projects/16211/tickets/165 > config.cache_classes = true > > # Log error messages when you accidentally call methods on nil. > config.whiny_nils = true > > # Show full error reports and disable caching > config.action_controller.consider_all_requests_local = true > config.action_controller.perform_caching = false > > # Disable request forgery protection in test environment > config.action_controller.allow_forgery_protection = false > > # Tell Action Mailer not to deliver emails to the real world. > # The :test delivery method accumulates sent emails in the > # ActionMailer::Base.deliveries array. > config.action_mailer.delivery_method = :test > > config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.0' > unless File.directory?(File.join(Rails.root, > 'vendor/plugins/cucumber-rails')) > config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' > unless File.directory?(File.join(Rails.root, > 'vendor/plugins/database_cleaner')) > config.gem 'webrat', :lib => false, :version => '>=0.5.3' > unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat')) > config.gem 'rspec', :lib => false, :version => '>=1.3.0' > unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec')) > config.gem 'rspec-rails', :lib => false, :version => '>=1.3.2' > unless File.directory?(File.join(Rails.root, > 'vendor/plugins/rspec-rails')) > > features/support/env.rb > # IMPORTANT: This file is generated by cucumber-rails - edit at your own > peril. > # It is recommended to regenerate this file in the future when you > upgrade to a > # newer version of cucumber-rails. Consider adding your own code to a > new file > # instead of editing this one. Cucumber will automatically load all > features/**/*.rb > # files. > > ENV["RAILS_ENV"] ||= "test" > require File.expand_path(File.dirname(__FILE__) + > '/../../config/environment') > > require 'cucumber/formatter/unicode' # Remove this line if you don't > want Cucumber Unicode support > require 'cucumber/rails/rspec' > require 'cucumber/rails/world' > require 'cucumber/rails/active_record' > require 'cucumber/web/tableish' > > require 'webrat' > require 'webrat/core/matchers' > > Webrat.configure do |config| > config.mode = :rails > config.open_error_files = false # Set to true if you want error pages > to pop up in the browser > end > > Before do > Fixtures.reset_cache > fixtures_folder = File.join(RAILS_ROOT, 'spec', 'fixtures') > fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| > File.basename(f, '.yml') } > Fixtures.create_fixtures(fixtures_folder, fixtures) > end > > > # If you set this to false, any error raised from within your app will > bubble > # up to your step definition and out to cucumber unless you catch it > somewhere > # on the way. You can make Rails rescue errors and render error pages on > a > # per-scenario basis by tagging a scenario or feature with the > @allow-rescue tag. > # > # If you set this to true, Rails will rescue all errors and render error > # pages, more or less in the same way your application would behave in > the > # default production environment. It's not recommended to do this for > all > # of your scenarios, as this makes it hard to discover errors in your > application. > ActionController::Base.allow_rescue = false > > # If you set this to true, each scenario will run in a database > transaction. > # You can still turn off transactions on a per-scenario basis, simply > tagging > # a feature or scenario with the @no-txn tag. If you are using Capybara, > # tagging with @culerity or @javascript will also turn transactions off. > # > # If you set this to false, transactions will be off for all scenarios, > # regardless of whether you use @no-txn or not. > # > # Beware that turning transactions off will leave data in your database > # after each scenario, which can lead to hard-to-debug failures in > # subsequent scenarios. If you do this, we recommend you create a Before > # block that will explicitly put your database in a known state. > Cucumber::Rails::World.use_transactional_fixtures = true > > # How to clean your database when transactions are turned off. See > # http://github.com/bmabey/database_cleaner for more info. > if defined?(ActiveRecord::Base) > begin > require 'database_cleaner' > DatabaseCleaner.strategy = :truncation > rescue LoadError => ignore_if_database_cleaner_not_present > end > end > > features/manage_users.feature > Given a registered user > When he clicks on login link > And after filling all the details > Then the user should be logged in > > features/step_definitions/user_steps.rb > Given /^a registered user$/ do > visit '/login' > end > > When /^he clicks on login link$/ do > visit '/login' > fill_in("login", :with => "test") > fill_in("password", :with => "test123") > click_button "Log in" > p current_url > p response.body > end > > Then /^that user should get created$/ do > @user = User.find_by_login("test") > @user.test.should == "test" > end > > This is my whole scenario.Now if i see the current url it says > '/session' which actually should be '/users' and in response.body it > says 'invalid username and password' > > Also in my database list of users are already present > Please suggest Please post cucumber issues to http://groups.google.com/group/cukes. Good luck! David From james.herdman at gmail.com Thu Apr 29 13:48:12 2010 From: james.herdman at gmail.com (James H) Date: Thu, 29 Apr 2010 10:48:12 -0700 (PDT) Subject: [rspec-users] Future of RSpec Integration Testing Message-ID: <85dfcdab-6aa8-4afa-8d2c-6eeb75950583@e28g2000vbd.googlegroups.com> Greetings. My team at work is trying to decide between Cucumber and RSpec integration tests for all future integration-style testing. The team is divided on this, so I thought I'd approach the community to see what the future of RSpec integration tests are. I've heard a rumor that they're being removed, and RSpec 2 appears to be using Cucumber for integration testing. What's the scoop here? Does the community have any recommendations on the matter? Thank you for your time, James Herdman From dchelimsky at gmail.com Thu Apr 29 13:56:32 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 29 Apr 2010 12:56:32 -0500 Subject: [rspec-users] Future of RSpec Integration Testing In-Reply-To: <85dfcdab-6aa8-4afa-8d2c-6eeb75950583@e28g2000vbd.googlegroups.com> References: <85dfcdab-6aa8-4afa-8d2c-6eeb75950583@e28g2000vbd.googlegroups.com> Message-ID: On Apr 29, 2010, at 12:48 PM, James H wrote: > Greetings. > > My team at work is trying to decide between Cucumber and RSpec > integration tests for all future integration-style testing. The team > is divided on this, so I thought I'd approach the community to see > what the future of RSpec integration tests are. I've heard a rumor > that they're being removed rspec-rails-2 (for rails-3) has request specs, which mix in behavior from rails integration tests. So the rumor is incorrect, at least as it pertains to rspec-rails. That said, request specs and Cucumber can cover the same features and functionality. It's really a matter of team make-up and personal preference. HTH, David > , and RSpec 2 appears to be using Cucumber > for integration testing. > > What's the scoop here? Does the community have any recommendations on > the matter? > > Thank you for your time, > > James Herdman > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Thu Apr 29 14:22:39 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 29 Apr 2010 19:22:39 +0100 Subject: [rspec-users] Future of RSpec Integration Testing In-Reply-To: <85dfcdab-6aa8-4afa-8d2c-6eeb75950583@e28g2000vbd.googlegroups.com> References: <85dfcdab-6aa8-4afa-8d2c-6eeb75950583@e28g2000vbd.googlegroups.com> Message-ID: On 29 Apr 2010, at 18:48, James H wrote: > Greetings. > > My team at work is trying to decide between Cucumber and RSpec > integration tests for all future integration-style testing. The team > is divided on this, so I thought I'd approach the community to see > what the future of RSpec integration tests are. I've heard a rumor > that they're being removed, and RSpec 2 appears to be using Cucumber > for integration testing. > > What's the scoop here? Does the community have any recommendations on > the matter? What exactly do you mean by integration testing? Do you mean those things that the rails generators put in ./test/integration, or something else? cheers, Matt http://mattwynne.net +447974 430184 From adam.sroka at gmail.com Thu Apr 29 14:38:44 2010 From: adam.sroka at gmail.com (Adam Sroka) Date: Thu, 29 Apr 2010 11:38:44 -0700 Subject: [rspec-users] more rspec questions In-Reply-To: References: Message-ID: With only a cursory look that looks good to me. If I have some time later I will look more carefully and maybe suggest some refactorings, but you look to be on the right track. The important thing is just to practice and continually improve. Best, Adam On Wed, Apr 28, 2010 at 11:37 PM, Patrick J. Collins wrote: >> I would go a step further and say that adding an address to card is >> not very interesting (Just like iterating over addresses, adding them >> should work out of the box assuming Ruby itself isn't broken.) > > Well, I ended up restructuring my code and I wrote tests for everything I > thought were important that would help me know when something is broken. ?Maybe > you'd say some of these cases aren't necessary-- I don't know.. ?But when I was > going through my code and making sure it worked, the tests seemed to be very > helpful for me... > > Here's how it looks now: > http://gist.github.com/383233 > > I solved my @contact.photo = problem by approaching it a different way... > Though I still wish someone could tell me what the deal was with that mock > expectation error. ?No one seemed to reply to that question... > > Anyway, everything passes so I guess I can move on to the next thing... > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From musicmanryan at gmail.com Wed Apr 28 16:51:42 2010 From: musicmanryan at gmail.com (Ryan S) Date: Wed, 28 Apr 2010 13:51:42 -0700 (PDT) Subject: [rspec-users] Running code on error Message-ID: <78a0f92f-86f9-4094-83b9-ff32fb6de407@r11g2000yqa.googlegroups.com> describe "Test" do after(:each) do if ERRORS #execute custom code here end it "should explode" do #Test.explode --> "fizzle" Test.explode.should == "KABOOM" end end Let's say I have the above test and the validation fails and I want some sort of custom action to take place. Is there a way to do that? This is a very simplified example but I am just curious if it is possible. From mailinglists at patmaddox.com Thu Apr 29 20:31:53 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Thu, 29 Apr 2010 17:31:53 -0700 Subject: [rspec-users] Running code on error In-Reply-To: <78a0f92f-86f9-4094-83b9-ff32fb6de407@r11g2000yqa.googlegroups.com> References: <78a0f92f-86f9-4094-83b9-ff32fb6de407@r11g2000yqa.googlegroups.com> Message-ID: Could you share a bit more about what you are actually trying to achieve? On Apr 28, 2010, at 1:51 PM, Ryan S wrote: > describe "Test" do > after(:each) do > if ERRORS #execute custom code here > end > > it "should explode" do > #Test.explode --> "fizzle" > Test.explode.should == "KABOOM" > end > end > > Let's say I have the above test and the validation fails and I want > some sort of custom action to take place. Is there a way to do that? > This is a very simplified example but I am just curious if it is > possible. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From martindemello at gmail.com Fri Apr 30 04:23:35 2010 From: martindemello at gmail.com (Martin DeMello) Date: Fri, 30 Apr 2010 13:53:35 +0530 Subject: [rspec-users] testing against a live environment In-Reply-To: References: Message-ID: perfect :) martin On Thu, Apr 29, 2010 at 8:10 PM, Joaquin Rivera Padron wrote: > maybe then check http://github.com/cavalle/steak > > joaquin > > 2010/4/29 Martin DeMello >> >> On Tue, Apr 27, 2010 at 3:32 PM, Matt Wynne wrote: >> > >> > Should be fine, though you might find cucumber/aruba a nice combination >> > for >> > this too. >> >> Cucumber seems to make things a lot more verbose :( Very ingenious >> idea, but in practice I prefer specifying stuff in ruby to specifying >> it in English. >> >> martin >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > www.least-significant-bit.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From stefan.kanev at gmail.com Fri Apr 30 04:26:01 2010 From: stefan.kanev at gmail.com (Stefan Kanev) Date: Fri, 30 Apr 2010 10:26:01 +0200 Subject: [rspec-users] Good practices on spec'ing views? Message-ID: Hey guys. I've been doing RSpec for more than a year by now, yet I cannot help but feel that I've never got a single view spec right. I can see that I have very few view specs and that my views tend be a lot messier than everything else. I've read the chapter in the RSpec book about spec'ing views, but I still think I'm not getting it right. Assuming that I'm a view spec noob, would you guys care to share your experience with writing them? What works and what doesn't? What should I avoid at all cost? And most importantly, how does the process of writing view specs feel? Thanks, Stefan -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Fri Apr 30 08:39:20 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 30 Apr 2010 08:39:20 -0400 Subject: [rspec-users] Good practices on spec'ing views? In-Reply-To: References: Message-ID: On Fri, Apr 30, 2010 at 4:26 AM, Stefan Kanev wrote: > Hey guys. > I've been doing RSpec for more than a year by now, yet I cannot help but > feel that I've never got a single view spec right. I can see that I have > very few view specs and that my views tend be a lot messier than everything > else. I've read the chapter in the RSpec book about spec'ing views, but I > still think I'm not getting it right. > Assuming that I'm a view spec noob, would you guys care to share your > experience with writing them? What works and what doesn't? What should I > avoid at all cost? And most importantly, how does the process of writing > view specs feel? After my initial learning of RSpec, I don't think I've written (m)any view specs. Why? 1. Views shouldn't have much if any logic, so not much behavior to spec 2. Views tend to change a lot as the UI of an application evolves, so specs tend to be brittle. If views have a lot of logic, that's a code smell. In rails such behavior belongs in either the controller, or a helper, and that's where I invest my spec efforts. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From steve at steveklabnik.com Fri Apr 30 10:36:32 2010 From: steve at steveklabnik.com (Steve Klabnik) Date: Fri, 30 Apr 2010 10:36:32 -0400 Subject: [rspec-users] Future of RSpec Integration Testing In-Reply-To: References: <85dfcdab-6aa8-4afa-8d2c-6eeb75950583@e28g2000vbd.googlegroups.com> Message-ID: "Integration testing" is also known as "full-stack testing." Basically, you're not testing isolated parts of the system, but the system as a whole. Cucumber is integration testing. rspec with 'integrate_views' is integration testing. -------------- next part -------------- An HTML attachment was scrubbed... URL: From musicmanryan at gmail.com Fri Apr 30 11:27:23 2010 From: musicmanryan at gmail.com (Ryan S) Date: Fri, 30 Apr 2010 08:27:23 -0700 (PDT) Subject: [rspec-users] Running code on error In-Reply-To: References: <78a0f92f-86f9-4094-83b9-ff32fb6de407@r11g2000yqa.googlegroups.com> Message-ID: Well, I am using SauceOnDemand with rspec. So when a test fails I want to download the video that corresponds to the failing test. I figured I could do a: it "should download video" do begin #some failing test here rescue Exception => e #download video raise e end end But this would get very repetitive for every rspec test. On Apr 29, 7:31?pm, Pat Maddox wrote: > Could you share a bit more about what you are actually trying to achieve? > > On Apr 28, 2010, at 1:51 PM, Ryan S wrote: > > > > > describe "Test" do > > ?after(:each) do > > ? ? ?if ERRORS #execute custom code here > > ?end > > > ?it "should explode" do > > ? ?#Test.explode --> "fizzle" > > ? ?Test.explode.should == "KABOOM" > > ?end > > end > > > Let's say I have the above test and the validation fails and I want > > some sort of custom action to take place. Is there a way to do that? > > This is a very simplified example but I am just curious if it is > > possible. > > _______________________________________________ > > 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 > > -- > You received this message because you are subscribed to the Google Groups "rspec" group. > To post to this group, send email to rspec at googlegroups.com. > To unsubscribe from this group, send email to rspec+unsubscribe at googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rspec?hl=en. From dchelimsky at gmail.com Fri Apr 30 12:13:16 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 30 Apr 2010 11:13:16 -0500 Subject: [rspec-users] Future of RSpec Integration Testing In-Reply-To: References: <85dfcdab-6aa8-4afa-8d2c-6eeb75950583@e28g2000vbd.googlegroups.com> Message-ID: On Apr 30, 2010, at 9:36 AM, Steve Klabnik wrote: > "Integration testing" is also known as "full-stack testing." This is true in the Rails world but it is far from a universal truth. Before Rails came around, integration testing (testing the integration between two or more non-trivial components) was actually a subset of functional testing (testing the system from the perspective of a user). I'll venture a guess as to why Rails turned that around: functional tests were part of the Rails testing infrastructure earlier on and when a new form of testing was introduced that had a wider scope, it needed a name, and "integration" seemed to fit the bill. I think "full-stack" or "end-to-end" testing are much more descriptive than "integration testing." > Basically, you're not testing isolated parts of the system, but the system as a whole. Cucumber is integration testing. rspec with 'integrate_views' is integration testing. _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Fri Apr 30 12:19:59 2010 From: ben at benmabey.com (Ben Mabey) Date: Fri, 30 Apr 2010 10:19:59 -0600 Subject: [rspec-users] Running code on error In-Reply-To: References: <78a0f92f-86f9-4094-83b9-ff32fb6de407@r11g2000yqa.googlegroups.com> Message-ID: <4BDB032F.7020108@benmabey.com> Ryan S wrote: > Well, I am using SauceOnDemand with rspec. So when a test fails I want > to download the video that corresponds to the failing test. I figured > I could do a: > > it "should download video" do > begin > #some failing test here > rescue Exception => e > #download video > raise e > end > end > > But this would get very repetitive for every rspec test. > Have you investigated creating a custom formatter? I think that approach might be better suited for what you are doing. It has been a while since I've dug into that code but I imagine that the exception will be passed to you for inspection. If that doesn't suit your needs you will have to decorate 'it' on ExampleGroup. -Ben > > On Apr 29, 7:31 pm, Pat Maddox wrote: > >> Could you share a bit more about what you are actually trying to achieve? >> >> On Apr 28, 2010, at 1:51 PM, Ryan S wrote: >> >> >> >> >>> describe "Test" do >>> after(:each) do >>> if ERRORS #execute custom code here >>> end >>> >>> it "should explode" do >>> #Test.explode --> "fizzle" >>> Test.explode.should == "KABOOM" >>> end >>> end >>> >>> Let's say I have the above test and the validation fails and I want >>> some sort of custom action to take place. Is there a way to do that? >>> This is a very simplified example but I am just curious if it is >>> possible. >>> _______________________________________________ >>> 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 >> >> -- >> You received this message because you are subscribed to the Google Groups "rspec" group. >> To post to this group, send email to rspec at googlegroups.com. >> To unsubscribe from this group, send email to rspec+unsubscribe at googlegroups.com. >> For more options, visit this group athttp://groups.google.com/group/rspec?hl=en. >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From phillipkoebbe at gmail.com Fri Apr 30 12:34:33 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Fri, 30 Apr 2010 11:34:33 -0500 Subject: [rspec-users] multiple return values with stub Message-ID: <4BDB0699.1030506@gmail.com> I have a helper method def login_as(role) user = stub_model(User) user.stub(:is_administrator?).and_return(role == :admin) User.stub(:find_by_id).and_return(user) session[:user_id] = user.id user end which has been dandy until yesterday. I am now working on an admin controller for user maintenance, and in it, I want to do this: before :each do login_as(:admin) @some_user = stub_model(User, valid_user_hash) User.stub(:find_by_id).and_return(@some_user) end which obviously conflicts with the stub in login_as. I have experimented with adding .with() to each one, hoping that multiple stubs would be created, but that does not seem to be the case. Is there a way to stub the same method but have it return different values? Or can someone suggest a better way of handling this situation? Peace, Phillip From dchelimsky at gmail.com Fri Apr 30 12:54:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 30 Apr 2010 11:54:45 -0500 Subject: [rspec-users] multiple return values with stub In-Reply-To: <4BDB0699.1030506@gmail.com> References: <4BDB0699.1030506@gmail.com> Message-ID: On Apr 30, 2010, at 11:34 AM, Phillip Koebbe wrote: > I have a helper method > > def login_as(role) > user = stub_model(User) > user.stub(:is_administrator?).and_return(role == :admin) > User.stub(:find_by_id).and_return(user) > session[:user_id] = user.id > user > end > > which has been dandy until yesterday. I am now working on an admin controller for user maintenance, and in it, I want to do this: > > before :each do > login_as(:admin) > @some_user = stub_model(User, valid_user_hash) > User.stub(:find_by_id).and_return(@some_user) > end > > which obviously conflicts with the stub in login_as. > > I have experimented with adding .with() to each one, hoping that multiple stubs would be created, but that does not seem to be the case. Is there a way to stub the same method but have it return different values? Or can someone suggest a better way of handling this situation? Two ways to do it: 1 is documented here; http://rspec.info/documentation/mocks/stubs.html The other: User.stub(:find_by_id) do |id| if id == $admin_id admin_user else non_admin_user end end or some such. HTH, David > > Peace, > Phillip > _______________________________________________ > 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 phillipkoebbe at gmail.com Fri Apr 30 13:04:13 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Fri, 30 Apr 2010 12:04:13 -0500 Subject: [rspec-users] multiple return values with stub In-Reply-To: <4BDB0699.1030506@gmail.com> References: <4BDB0699.1030506@gmail.com> Message-ID: <4BDB0D8D.7010703@gmail.com> On 2010-04-30 11:34 AM, Phillip Koebbe wrote: > I have a helper method > > def login_as(role) > user = stub_model(User) > user.stub(:is_administrator?).and_return(role == :admin) > User.stub(:find_by_id).and_return(user) > session[:user_id] = user.id > user > end > > which has been dandy until yesterday. I am now working on an admin > controller for user maintenance, and in it, I want to do this: > > before :each do > login_as(:admin) > @some_user = stub_model(User, valid_user_hash) > User.stub(:find_by_id).and_return(@some_user) > end > > which obviously conflicts with the stub in login_as. > > I have experimented with adding .with() to each one, hoping that > multiple stubs would be created, but that does not seem to be the > case. Is there a way to stub the same method but have it return > different values? Or can someone suggest a better way of handling this > situation? > To answer my own question, I discovered I could stub @controller in login_as: @controller.stub(:current_user).and_return(user) which works. Can anyone think of a reason I would not want to do that? Peace, Phillip From patrick at collinatorstudios.com Fri Apr 30 14:14:02 2010 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 30 Apr 2010 11:14:02 -0700 (PDT) Subject: [rspec-users] update_attributes fails in rake spec but not in script/spec??? Message-ID: Hi, So I just wrote a spec, and tested it by running script/spec models/result_list_spec.rb I get: ----------------------------- ..... Finished in 28.558841 seconds 5 examples, 0 failures ----------------------------- So then I did: rake spec and I get a bunch of errors on that same file "wrong number of arguments (0 for 3)" I then threw a debugger into the code to try to see where it was failing, and it was failing when I was doing self.update_attributes in the model... I tried assigning this myself in the debugger console: (rdb:1) self.update_attribute(:job_item_count, 4) ArgumentError Exception: wrong number of arguments (0 for 3) (rdb:1) self # ... ???????????? Can anyone please explain to me why this is behaving this way? Patrick J. Collins http://collinatorstudios.com