From nathanvda at gmail.com Wed Sep 1 05:13:01 2010 From: nathanvda at gmail.com (nathanvda) Date: Wed, 1 Sep 2010 02:13:01 -0700 (PDT) Subject: [rspec-users] rspec2: autotest keeps rerunning failing tests In-Reply-To: <5b785ae0-c1c3-4a09-ac43-bdfa3b8e75bb@x25g2000yqj.googlegroups.com> References: <6695fcfe-dbd1-47d0-9938-f227f0b16125@q22g2000yqm.googlegroups.com> <71e7f167-69c1-47c8-b396-7b86d27ffea4@t20g2000yqa.googlegroups.com> <85022101-9fbc-40bc-ab34-6ade946aad7f@q22g2000yqm.googlegroups.com> <2FC8921D-CDCB-4596-903A-FE98A76E4EB7@gmail.com> <5b785ae0-c1c3-4a09-ac43-bdfa3b8e75bb@x25g2000yqj.googlegroups.com> Message-ID: <675e8c68-9558-4d89-a417-13829bf7f204@l20g2000yqm.googlegroups.com> I spoke too soon. Adding "autotest-rails" did not solve my problems either. Trying "bundle exec autotest" also did not help. I have been trying to use watchr, which seems faster, but when i save multiple files at once, only one file is tested again. But maybe i have to write a better wachtr script for that :) I will try to investigate the autotest-problem further if i can make some time today. From michael at schuerig.de Wed Sep 1 08:49:25 2010 From: michael at schuerig.de (Michael Schuerig) Date: Wed, 1 Sep 2010 14:49:25 +0200 Subject: [rspec-users] Undefined methods: has_selector? and flunk Message-ID: <201009011449.25835.michael@schuerig.de> I'm in the process of updating an app for Rails 3.0 and rspec-rails 2.0.0.beta20. When I'm running my specs (rake spec) I get a large number of errors caused by two undefined methods undefined method `has_selector?' for # undefined method `flunk' for # I've seen the upgrade notice for beta20 and now include capybara explicitly in the test group of my Gemfile. The version of capybara on my system is 0.3.9 and noticeably, it does not define has_selector? (or have_selector? as webrat does). Presumably, this is all just a dependency problem, but I have no clear idea where to look. Michael -- Michael Schuerig mailto:michael at schuerig.de http://www.schuerig.de/michael/ From dchelimsky at gmail.com Wed Sep 1 09:02:11 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Sep 2010 08:02:11 -0500 Subject: [rspec-users] Undefined methods: has_selector? and flunk In-Reply-To: <201009011449.25835.michael@schuerig.de> References: <201009011449.25835.michael@schuerig.de> Message-ID: On Sep 1, 2010, at 7:49 AM, Michael Schuerig wrote: > > I'm in the process of updating an app for Rails 3.0 and rspec-rails > 2.0.0.beta20. When I'm running my specs (rake spec) I get a large number > of errors caused by two undefined methods > > undefined method `has_selector?' for # See http://github.com/rspec/rspec-rails/issues/issue/190 > > undefined method `flunk' for > # Please report this one to http://github.com/rspec/rspec-rails/issues including the spec, code, versions, and full backtrace of the error. Thx, David > I've seen the upgrade notice for beta20 and now include capybara > explicitly in the test group of my Gemfile. The version of capybara on > my system is 0.3.9 and noticeably, it does not define has_selector? (or > have_selector? as webrat does). > > Presumably, this is all just a dependency problem, but I have no clear > idea where to look. From dchelimsky at gmail.com Wed Sep 1 09:07:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Sep 2010 08:07:43 -0500 Subject: [rspec-users] rspec2: autotest keeps rerunning failing tests In-Reply-To: <675e8c68-9558-4d89-a417-13829bf7f204@l20g2000yqm.googlegroups.com> References: <6695fcfe-dbd1-47d0-9938-f227f0b16125@q22g2000yqm.googlegroups.com> <71e7f167-69c1-47c8-b396-7b86d27ffea4@t20g2000yqa.googlegroups.com> <85022101-9fbc-40bc-ab34-6ade946aad7f@q22g2000yqm.googlegroups.com> <2FC8921D-CDCB-4596-903A-FE98A76E4EB7@gmail.com> <5b785ae0-c1c3-4a09-ac43-bdfa3b8e75bb@x25g2000yqj.googlegroups.com> <675e8c68-9558-4d89-a417-13829bf7f204@l20g2000yqm.googlegroups.com> Message-ID: <4DD08D15-AFC8-4696-A1E0-051D208AE851@gmail.com> On Sep 1, 2010, at 4:13 AM, nathanvda wrote: > I spoke too soon. Adding "autotest-rails" did not solve my problems > either. > Trying "bundle exec autotest" also did not help. > > I have been trying to use watchr, which seems faster, but when i save > multiple files at once, only one file is tested again. > But maybe i have to write a better wachtr script for that :) > > I will try to investigate the autotest-problem further if i can make > some time today. Looks like someone else discovered, reported, and is in the process of trying to fix this: http://github.com/rspec/rspec-rails/issues/#issue/191 From michael at schuerig.de Wed Sep 1 09:47:20 2010 From: michael at schuerig.de (Michael Schuerig) Date: Wed, 1 Sep 2010 15:47:20 +0200 Subject: [rspec-users] Undefined methods: has_selector? and flunk In-Reply-To: References: <201009011449.25835.michael@schuerig.de> Message-ID: <201009011547.21206.michael@schuerig.de> On Wednesday 01 September 2010, David Chelimsky wrote: > On Sep 1, 2010, at 7:49 AM, Michael Schuerig wrote: > > I'm in the process of updating an app for Rails 3.0 and rspec-rails > > 2.0.0.beta20. When I'm running my specs (rake spec) I get a large > > number of errors caused by two undefined methods > > > > undefined method `has_selector?' for # > > See http://github.com/rspec/rspec-rails/issues/issue/190 Thanks, I've just switched to webrat. Things look much better now. > > undefined method `flunk' for > > > > # > 2:0x7fdbd0c48fe8> > > Please report this one to http://github.com/rspec/rspec-rails/issues > including the spec, code, versions, and full backtrace of the error. http://github.com/rspec/rspec-rails/issues/issue/192 Michael -- Michael Schuerig mailto:michael at schuerig.de http://www.schuerig.de/michael/ From nathanvda at gmail.com Thu Sep 2 11:16:58 2010 From: nathanvda at gmail.com (nathanvda) Date: Thu, 2 Sep 2010 08:16:58 -0700 (PDT) Subject: [rspec-users] rails3/rspec2: how to write mailer tests? Message-ID: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> This will sound awfully stupid, but i have no idea how to start writing any mailer tests. I have a mailer class class SmsMailer < ActionMailer::Base def fake_sms(envelope) mail(:to => envelope.user.email) end end how do I test this? I tried googling for documentation, but was unable to find something relevant (probable used wrong search terms). Or do i just do view-tests on the corresponding view? From dchelimsky at gmail.com Thu Sep 2 11:22:19 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Sep 2010 10:22:19 -0500 Subject: [rspec-users] rails3/rspec2: how to write mailer tests? In-Reply-To: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> References: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> Message-ID: On Sep 2, 2010, at 10:16 AM, nathanvda wrote: > This will sound awfully stupid, but i have no idea how to start > writing any mailer tests. > > I have a mailer class > > class SmsMailer < ActionMailer::Base > > def fake_sms(envelope) > mail(:to => envelope.user.email) > end > end > > how do I test this? > I tried googling for documentation, but was unable to find something > relevant (probable used wrong search terms). > > Or do i just do view-tests on the corresponding view? Start with "script/rails generate rspec:mailer sms" - that will generate a stub for you and you can go from there. From dchelimsky at gmail.com Thu Sep 2 11:23:44 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Sep 2010 10:23:44 -0500 Subject: [rspec-users] rails3/rspec2: how to write mailer tests? In-Reply-To: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> References: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> Message-ID: <15FE5A63-C9B9-44BB-81D2-16702320F232@gmail.com> On Sep 2, 2010, at 10:16 AM, nathanvda wrote: > This will sound awfully stupid, but i have no idea how to start > writing any mailer tests. > > I have a mailer class > > class SmsMailer < ActionMailer::Base > > def fake_sms(envelope) > mail(:to => envelope.user.email) > end > end > > how do I test this? > I tried googling for documentation, but was unable to find something > relevant (probable used wrong search terms). > > Or do i just do view-tests on the corresponding view? Start with "script/rails generate rspec:mailer sms" - that will generate a stub for you and you can go from there. From tjtuom at utu.fi Thu Sep 2 11:24:26 2010 From: tjtuom at utu.fi (Toni Tuominen) Date: Thu, 2 Sep 2010 18:24:26 +0300 Subject: [rspec-users] rails3/rspec2: how to write mailer tests? In-Reply-To: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> References: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> Message-ID: On Thu, Sep 2, 2010 at 6:16 PM, nathanvda wrote: > This will sound awfully stupid, but i have no idea how to start > writing any mailer tests. > > I have a mailer class > > ? ?class SmsMailer < ActionMailer::Base > > ? ? ?def fake_sms(envelope) > ? ? ? ?mail(:to => envelope.user.email) > ? ? ?end > ? ?end > > how do I test this? > I tried googling for documentation, but was unable to find something > relevant (probable used wrong search terms). > > Or do i just do view-tests on the corresponding view? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > What you want is http://github.com/bmabey/email-spec. From jko170 at gmail.com Thu Sep 2 11:27:45 2010 From: jko170 at gmail.com (Justin Ko) Date: Thu, 2 Sep 2010 08:27:45 -0700 (PDT) Subject: [rspec-users] rails3/rspec2: how to write mailer tests? In-Reply-To: References: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> Message-ID: <374b927c-4877-4b5c-b79e-e7b8c205e94b@q2g2000yqq.googlegroups.com> On Sep 2, 11:24?am, Toni Tuominen wrote: > On Thu, Sep 2, 2010 at 6:16 PM, nathanvda wrote: > > This will sound awfully stupid, but i have no idea how to start > > writing any mailer tests. > > > I have a mailer class > > > ? ?class SmsMailer < ActionMailer::Base > > > ? ? ?def fake_sms(envelope) > > ? ? ? ?mail(:to => envelope.user.email) > > ? ? ?end > > ? ?end > > > how do I test this? > > I tried googling for documentation, but was unable to find something > > relevant (probable used wrong search terms). > > > Or do i just do view-tests on the corresponding view? > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > What you want ishttp://github.com/bmabey/email-spec. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users +1 for the email-spec gem From nathanvda at gmail.com Fri Sep 3 02:56:42 2010 From: nathanvda at gmail.com (nathanvda) Date: Thu, 2 Sep 2010 23:56:42 -0700 (PDT) Subject: [rspec-users] rails3/rspec2: how to write mailer tests? In-Reply-To: <15FE5A63-C9B9-44BB-81D2-16702320F232@gmail.com> References: <3b51f138-b41b-4a5a-a842-07e64808b6a4@l20g2000yqm.googlegroups.com> <15FE5A63-C9B9-44BB-81D2-16702320F232@gmail.com> Message-ID: <3f65d280-4dc4-49b6-8789-6688bc7e1cbd@x25g2000yqj.googlegroups.com> > > Start with "script/rails generate rspec:mailer sms" - that will generate a stub for you and you can go from there. I am sorry if that was not clear, but i am using rspec2 and rails. I did use "rails g mailer SomethingMailer" and that produced an empty test. But when i did "rails g mailer SomethingMailer some_mail" i got a good example. Feels stupid again :) From lille.penguini at gmail.com Fri Sep 3 13:12:43 2010 From: lille.penguini at gmail.com (Lille) Date: Fri, 3 Sep 2010 10:12:43 -0700 (PDT) Subject: [rspec-users] how to invoke multiple controllers in the same describe block? Message-ID: <26b38a03-e5d7-46e3-93e0-21e8155d97cd@q40g2000prg.googlegroups.com> Hi, I seek to authenticate and then test other routing in RSpec, but the standard RSpec vernacular... describe SomeController do it "blah-blah" do get :new ... end end ...doesn't seem to allow me to post my login data, as in the following pseudo-code: describe SomeController do before(:each) do post :controller=>"authentication", :action=> "create", :new_session=>{"user_name"=>"Lille"...} end ... end I've scanned all the methods in the RDoc, but I cannot identify the manner in which I may specify the controller directly. Any help? Thanks, Lille From dchelimsky at gmail.com Fri Sep 3 13:53:23 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Sep 2010 12:53:23 -0500 Subject: [rspec-users] how to invoke multiple controllers in the same describe block? In-Reply-To: <26b38a03-e5d7-46e3-93e0-21e8155d97cd@q40g2000prg.googlegroups.com> References: <26b38a03-e5d7-46e3-93e0-21e8155d97cd@q40g2000prg.googlegroups.com> Message-ID: On Sep 3, 2010, at 12:12 PM, Lille wrote: > Hi, > > I seek to authenticate and then test other routing in RSpec, but the > standard RSpec vernacular... > > describe SomeController do > > it "blah-blah" do > get :new > ... > end > > end > > ...doesn't seem to allow me to post my login data, as in the following > pseudo-code: > > describe SomeController do > > before(:each) do > post :controller=>"authentication", :action=> > "create", :new_session=>{"user_name"=>"Lille"...} > end > ... > end > > I've scanned all the methods in the RDoc, but I cannot identify the > manner in which I may specify the controller directly. Any help? Controller specs wrap behaviour of ActionController::TestCase, which is designed to handle one request per example. You could do this in request specs (integration specs in rspec-2), which derive behaviour from rails integration tests. HTH, David From patmaddox at me.com Fri Sep 3 17:22:00 2010 From: patmaddox at me.com (Pat Maddox) Date: Fri, 03 Sep 2010 14:22:00 -0700 Subject: [rspec-users] how to invoke multiple controllers in the same describe block? In-Reply-To: <26b38a03-e5d7-46e3-93e0-21e8155d97cd@q40g2000prg.googlegroups.com> References: <26b38a03-e5d7-46e3-93e0-21e8155d97cd@q40g2000prg.googlegroups.com> Message-ID: <4C8166F8.4060508@me.com> Lille wrote: > Hi, > > I seek to authenticate and then test other routing in RSpec, but the > standard RSpec vernacular... > > describe SomeController do > > it "blah-blah" do > get :new > ... > end > > end > > ...doesn't seem to allow me to post my login data, as in the following > pseudo-code: > > describe SomeController do > > before(:each) do > post :controller=>"authentication", :action=> > "create", :new_session=>{"user_name"=>"Lille"...} > end > ... > end > > I've scanned all the methods in the RDoc, but I cannot identify the > manner in which I may specify the controller directly. Any help? > > Thanks, > > Lille > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You can't do that with basic controller specs. What you _can_ do is stub a method on the controller (maybe #current_user) or set a bit of session info like session[:user_id]. So you can set up the spec so that a user is logged in when making the request, but you can't make multiple requests in a single spec. For that you'll want the integration specs or Cucumber. Pat From ericmilford at gmail.com Fri Sep 3 19:02:20 2010 From: ericmilford at gmail.com (ericindc) Date: Fri, 3 Sep 2010 16:02:20 -0700 (PDT) Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs Message-ID: Any idea why autotest would miss some of my tests? I run autotest and everything passes, but rake spec results in 2 failures. The 2 failures are from the model spec that is not being included when run in autotest. From dchelimsky at gmail.com Fri Sep 3 19:04:13 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Sep 2010 18:04:13 -0500 Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: References: Message-ID: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> On Sep 3, 2010, at 6:02 PM, ericindc wrote: > Any idea why autotest would miss some of my tests? I run autotest and > everything passes, but rake spec results in 2 failures. The 2 > failures are from the model spec that is not being included when run > in autotest. Are you sure that the model spec is excluded from autotest rather than it's just passing? Also - versions? rspec, rails, ruby, os? From ericmilford at gmail.com Fri Sep 3 19:07:56 2010 From: ericmilford at gmail.com (ericindc) Date: Fri, 3 Sep 2010 16:07:56 -0700 (PDT) Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> Message-ID: <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> On Sep 3, 7:04?pm, David Chelimsky wrote: > On Sep 3, 2010, at 6:02 PM, ericindc wrote: > > > Any idea why autotest would miss some of my tests? ?I run autotest and > > everything passes, but rake spec results in 2 failures. ?The 2 > > failures are from the model spec that is not being included when run > > in autotest. > > Are you sure that the model spec is excluded from autotest rather than it's just passing? > > Also - versions? rspec, rails, ruby, os? I also verified in the autotest output that the model spec is not included. Not sure if there are others. From dchelimsky at gmail.com Fri Sep 3 19:09:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Sep 2010 18:09:03 -0500 Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> Message-ID: On Sep 3, 2010, at 6:07 PM, ericindc wrote: > On Sep 3, 7:04 pm, David Chelimsky wrote: >> On Sep 3, 2010, at 6:02 PM, ericindc wrote: >> >>> Any idea why autotest would miss some of my tests? I run autotest and >>> everything passes, but rake spec results in 2 failures. The 2 >>> failures are from the model spec that is not being included when run >>> in autotest. >> >> Are you sure that the model spec is excluded from autotest rather than it's just passing? >> >> Also - versions? rspec, rails, ruby, os? > > I also verified in the autotest output that the model spec is not > included. Not sure if there are others. Versions? From ericmilford at gmail.com Fri Sep 3 19:06:58 2010 From: ericmilford at gmail.com (ericindc) Date: Fri, 3 Sep 2010 16:06:58 -0700 (PDT) Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> Message-ID: I purposefully broke the test and everything passes. Running rake spec, however, caught the error. I am running a Rails 3 app on OS X and RVM 1.8.7-p302 and the the following: rspec (2.0.0.beta.20) rspec-core (2.0.0.beta.20) rspec-expectations (2.0.0.beta.20) rspec-mocks (2.0.0.beta.20) rspec-rails (2.0.0.beta.20) autotest (4.3.2) autotest-fsevent (0.2.3) autotest-growl (0.2.5) autotest-rails (4.1.0) On Sep 3, 7:04?pm, David Chelimsky wrote: > On Sep 3, 2010, at 6:02 PM, ericindc wrote: > > > Any idea why autotest would miss some of my tests? ?I run autotest and > > everything passes, but rake spec results in 2 failures. ?The 2 > > failures are from the model spec that is not being included when run > > in autotest. > > Are you sure that the model spec is excluded from autotest rather than it's just passing? > > Also - versions? rspec, rails, ruby, os? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ericmilford at gmail.com Fri Sep 3 19:33:42 2010 From: ericmilford at gmail.com (ericindc) Date: Fri, 3 Sep 2010 16:33:42 -0700 (PDT) Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> Message-ID: On Sep 3, 7:09?pm, David Chelimsky wrote: > On Sep 3, 2010, at 6:07 PM, ericindc wrote: > > > On Sep 3, 7:04 pm, David Chelimsky wrote: > >> On Sep 3, 2010, at 6:02 PM, ericindc wrote: > > >>> Any idea why autotest would miss some of my tests? ?I run autotest and > >>> everything passes, but rake spec results in 2 failures. ?The 2 > >>> failures are from the model spec that is not being included when run > >>> in autotest. > > >> Are you sure that the model spec is excluded from autotest rather than it's just passing? > > >> Also - versions? rspec, rails, ruby, os? > > > I also verified in the autotest output that the model spec is not > > included. ?Not sure if there are others. > > Versions? I purposefully broke the test and everything passes. Running rake spec, however, caught the error. I am running a Rails 3 app on OS X and RVM 1.8.7-p302 and the the following: rspec (2.0.0.beta.20) rspec-core (2.0.0.beta.20) rspec-expectations (2.0.0.beta.20) rspec-mocks (2.0.0.beta.20) rspec-rails (2.0.0.beta.20) autotest (4.3.2) autotest-fsevent (0.2.3) autotest-growl (0.2.5) autotest-rails (4.1.0) > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From me at jbrains.ca Fri Sep 3 19:38:48 2010 From: me at jbrains.ca (J. B. Rainsberger) Date: Fri, 3 Sep 2010 20:38:48 -0300 Subject: [rspec-users] Factories vs. stubs/mocks In-Reply-To: References: <7BE1FA57-FC86-4508-89BC-BDBFB4409C53@brennonbortz.com> <254b982d-3e2a-46a8-bdfe-f0512aa8080e@f42g2000yqn.googlegroups.com> <0594856A-5DC7-43B1-B9EA-456135FCABB5@brennonbortz.com> Message-ID: On Mon, Aug 30, 2010 at 14:09, Rob Biedenharn > And THAT is the problem with using mocks (or stubs) for this. ?You run the > very real risk of specifying the implementation details in the structure of > the spec/test. ?There is a problem when you've limited the refactoring that > can be done without altering the spec/test. Since Widget.find(:all) and > Widget.all should always have the same result, the mere presence of the mock > has cut off one possible refactoring. ?(The one that I distaste most limits > changing .find(params[:id]) to .find_by_id(params[:id]) by mocking/stubbing > the call to find.) On the contrary: by stubbing you've uncovered that you had used a low-level API (#find) instead of a high-level API (#all). This prompted you to make a conscious choice, which you did, and I prefer the choice you made, to invoke #all instead of #find. ?and THAT is the magic of using stubs and expectations for this. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From ericmilford at gmail.com Fri Sep 3 19:42:45 2010 From: ericmilford at gmail.com (ericindc) Date: Fri, 3 Sep 2010 16:42:45 -0700 (PDT) Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> Message-ID: <9d9f422e-8798-46ac-9dc9-d9edc7647375@c13g2000vbr.googlegroups.com> On Sep 3, 7:33?pm, ericindc wrote: > On Sep 3, 7:09?pm, David Chelimsky wrote: > > > > > > > On Sep 3, 2010, at 6:07 PM, ericindc wrote: > > > > On Sep 3, 7:04 pm, David Chelimsky wrote: > > >> On Sep 3, 2010, at 6:02 PM, ericindc wrote: > > > >>> Any idea why autotest would miss some of my tests? ?I run autotest and > > >>> everything passes, but rake spec results in 2 failures. ?The 2 > > >>> failures are from the model spec that is not being included when run > > >>> in autotest. > > > >> Are you sure that the model spec is excluded from autotest rather than it's just passing? > > > >> Also - versions? rspec, rails, ruby, os? > > > > I also verified in the autotest output that the model spec is not > > > included. ?Not sure if there are others. > > > Versions? > > I purposefully broke the test and everything passes. ?Running rake > spec, however, caught the error. ?I am running a Rails 3 app on OS X > and RVM 1.8.7-p302 and the the following: > > rspec (2.0.0.beta.20) > rspec-core (2.0.0.beta.20) > rspec-expectations (2.0.0.beta.20) > rspec-mocks (2.0.0.beta.20) > rspec-rails (2.0.0.beta.20) > autotest (4.3.2) > autotest-fsevent (0.2.3) > autotest-growl (0.2.5) > autotest-rails (4.1.0)> _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > I also just noticed that renaming the file to something random causes autotest to pick it up. It blows up because the corresponding model does not exist. Naming it back to it's original causes it to miss again. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From me at jbrains.ca Fri Sep 3 19:43:06 2010 From: me at jbrains.ca (J. B. Rainsberger) Date: Fri, 3 Sep 2010 20:43:06 -0300 Subject: [rspec-users] there should be one test or two? In-Reply-To: References: Message-ID: On Fri, Aug 27, 2010 at 02:43, Zhenning Guan wrote: > in real world, when user deposit money into their bank, bank have money > and can check deposit record. so what would it be in rspec? I prefer two specs, because you are checking two unrelated things: bank account balance and transaction record. In general, I like to put each check in a separate spec, then combine checks if I see they are related. This is my style. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From dchelimsky at gmail.com Fri Sep 3 20:34:27 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Sep 2010 19:34:27 -0500 Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: <9d9f422e-8798-46ac-9dc9-d9edc7647375@c13g2000vbr.googlegroups.com> References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> <9d9f422e-8798-46ac-9dc9-d9edc7647375@c13g2000vbr.googlegroups.com> Message-ID: On Sep 3, 2010, at 6:42 PM, ericindc wrote: > > > On Sep 3, 7:33 pm, ericindc wrote: >> On Sep 3, 7:09 pm, David Chelimsky wrote: >> >> >> >> >> >>> On Sep 3, 2010, at 6:07 PM, ericindc wrote: >> >>>> On Sep 3, 7:04 pm, David Chelimsky wrote: >>>>> On Sep 3, 2010, at 6:02 PM, ericindc wrote: >> >>>>>> Any idea why autotest would miss some of my tests? I run autotest and >>>>>> everything passes, but rake spec results in 2 failures. The 2 >>>>>> failures are from the model spec that is not being included when run >>>>>> in autotest. >> >>>>> Are you sure that the model spec is excluded from autotest rather than it's just passing? >> >>>>> Also - versions? rspec, rails, ruby, os? >> >>>> I also verified in the autotest output that the model spec is not >>>> included. Not sure if there are others. >> >>> Versions? >> >> I purposefully broke the test and everything passes. Running rake >> spec, however, caught the error. I am running a Rails 3 app on OS X >> and RVM 1.8.7-p302 and the the following: >> >> rspec (2.0.0.beta.20) >> rspec-core (2.0.0.beta.20) >> rspec-expectations (2.0.0.beta.20) >> rspec-mocks (2.0.0.beta.20) >> rspec-rails (2.0.0.beta.20) >> autotest (4.3.2) >> autotest-fsevent (0.2.3) >> autotest-growl (0.2.5) >> autotest-rails (4.1.0)> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> > > I also just noticed that renaming the file to something random causes > autotest to pick it up. It blows up because the corresponding model > does not exist. Naming it back to it's original causes it to miss > again. Are the names perfectly aligned with the specs? i.e. app/models/thing.rb and spec/models/thing_spec.rb? By default, autotest requires this mapping, though it can be customized if you have a need. From ericmilford at gmail.com Fri Sep 3 21:12:29 2010 From: ericmilford at gmail.com (ericindc) Date: Fri, 3 Sep 2010 18:12:29 -0700 (PDT) Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> <9d9f422e-8798-46ac-9dc9-d9edc7647375@c13g2000vbr.googlegroups.com> Message-ID: <81185ff0-6007-4f74-b4e7-a031947aa0c7@g18g2000vbn.googlegroups.com> On Sep 3, 8:34?pm, David Chelimsky wrote: > On Sep 3, 2010, at 6:42 PM, ericindc wrote: > > > > > > > > > On Sep 3, 7:33 pm, ericindc wrote: > >> On Sep 3, 7:09 pm, David Chelimsky wrote: > > >>> On Sep 3, 2010, at 6:07 PM, ericindc wrote: > > >>>> On Sep 3, 7:04 pm, David Chelimsky wrote: > >>>>> On Sep 3, 2010, at 6:02 PM, ericindc wrote: > > >>>>>> Any idea why autotest would miss some of my tests? ?I run autotest and > >>>>>> everything passes, but rake spec results in 2 failures. ?The 2 > >>>>>> failures are from the model spec that is not being included when run > >>>>>> in autotest. > > >>>>> Are you sure that the model spec is excluded from autotest rather than it's just passing? > > >>>>> Also - versions? rspec, rails, ruby, os? > > >>>> I also verified in the autotest output that the model spec is not > >>>> included. ?Not sure if there are others. > > >>> Versions? > > >> I purposefully broke the test and everything passes. ?Running rake > >> spec, however, caught the error. ?I am running a Rails 3 app on OS X > >> and RVM 1.8.7-p302 and the the following: > > >> rspec (2.0.0.beta.20) > >> rspec-core (2.0.0.beta.20) > >> rspec-expectations (2.0.0.beta.20) > >> rspec-mocks (2.0.0.beta.20) > >> rspec-rails (2.0.0.beta.20) > >> autotest (4.3.2) > >> autotest-fsevent (0.2.3) > >> autotest-growl (0.2.5) > >> autotest-rails (4.1.0)> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > I also just noticed that renaming the file to something random causes > > autotest to pick it up. ?It blows up because the corresponding model > > does not exist. ?Naming it back to it's original causes it to miss > > again. > > Are the names perfectly aligned with the specs? i.e. app/models/thing.rb and spec/models/thing_spec.rb? By default, autotest requires this mapping, though it can be customized if you have a need. Yes, and I don't see any mention of the model in the "No tests match...." output from autotest. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Sep 3 21:37:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Sep 2010 20:37:43 -0500 Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: <81185ff0-6007-4f74-b4e7-a031947aa0c7@g18g2000vbn.googlegroups.com> References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> <9d9f422e-8798-46ac-9dc9-d9edc7647375@c13g2000vbr.googlegroups.com> <81185ff0-6007-4f74-b4e7-a031947aa0c7@g18g2000vbn.googlegroups.com> Message-ID: On Sep 3, 2010, at 8:12 PM, ericindc wrote: > > > On Sep 3, 8:34 pm, David Chelimsky wrote: >> On Sep 3, 2010, at 6:42 PM, ericindc wrote: >> >> >> >> >> >> >> >>> On Sep 3, 7:33 pm, ericindc wrote: >>>> On Sep 3, 7:09 pm, David Chelimsky wrote: >> >>>>> On Sep 3, 2010, at 6:07 PM, ericindc wrote: >> >>>>>> On Sep 3, 7:04 pm, David Chelimsky wrote: >>>>>>> On Sep 3, 2010, at 6:02 PM, ericindc wrote: >> >>>>>>>> Any idea why autotest would miss some of my tests? I run autotest and >>>>>>>> everything passes, but rake spec results in 2 failures. The 2 >>>>>>>> failures are from the model spec that is not being included when run >>>>>>>> in autotest. >> >>>>>>> Are you sure that the model spec is excluded from autotest rather than it's just passing? >> >>>>>>> Also - versions? rspec, rails, ruby, os? >> >>>>>> I also verified in the autotest output that the model spec is not >>>>>> included. Not sure if there are others. >> >>>>> Versions? >> >>>> I purposefully broke the test and everything passes. Running rake >>>> spec, however, caught the error. I am running a Rails 3 app on OS X >>>> and RVM 1.8.7-p302 and the the following: >> >>>> rspec (2.0.0.beta.20) >>>> rspec-core (2.0.0.beta.20) >>>> rspec-expectations (2.0.0.beta.20) >>>> rspec-mocks (2.0.0.beta.20) >>>> rspec-rails (2.0.0.beta.20) >>>> autotest (4.3.2) >>>> autotest-fsevent (0.2.3) >>>> autotest-growl (0.2.5) >>>> autotest-rails (4.1.0)> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> >>> I also just noticed that renaming the file to something random causes >>> autotest to pick it up. It blows up because the corresponding model >>> does not exist. Naming it back to it's original causes it to miss >>> again. >> >> Are the names perfectly aligned with the specs? i.e. app/models/thing.rb and spec/models/thing_spec.rb? By default, autotest requires this mapping, though it can be customized if you have a need. > > > Yes, and I don't see any mention of the model in the "No tests > match...." output from autotest. Just noticed your post a few back with the versions - try removing autotest-rails from your Gemfile and make sure you're running autotest with bundle exec. From ericmilford at gmail.com Fri Sep 3 23:56:56 2010 From: ericmilford at gmail.com (ericindc) Date: Fri, 3 Sep 2010 20:56:56 -0700 (PDT) Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> <9d9f422e-8798-46ac-9dc9-d9edc7647375@c13g2000vbr.googlegroups.com> <81185ff0-6007-4f74-b4e7-a031947aa0c7@g18g2000vbn.googlegroups.com> Message-ID: On Sep 3, 9:37?pm, David Chelimsky wrote: > On Sep 3, 2010, at 8:12 PM, ericindc wrote: > > > > > > > > > On Sep 3, 8:34 pm, David Chelimsky wrote: > >> On Sep 3, 2010, at 6:42 PM, ericindc wrote: > > >>> On Sep 3, 7:33 pm, ericindc wrote: > >>>> On Sep 3, 7:09 pm, David Chelimsky wrote: > > >>>>> On Sep 3, 2010, at 6:07 PM, ericindc wrote: > > >>>>>> On Sep 3, 7:04 pm, David Chelimsky wrote: > >>>>>>> On Sep 3, 2010, at 6:02 PM, ericindc wrote: > > >>>>>>>> Any idea why autotest would miss some of my tests? ?I run autotest and > >>>>>>>> everything passes, but rake spec results in 2 failures. ?The 2 > >>>>>>>> failures are from the model spec that is not being included when run > >>>>>>>> in autotest. > > >>>>>>> Are you sure that the model spec is excluded from autotest rather than it's just passing? > > >>>>>>> Also - versions? rspec, rails, ruby, os? > > >>>>>> I also verified in the autotest output that the model spec is not > >>>>>> included. ?Not sure if there are others. > > >>>>> Versions? > > >>>> I purposefully broke the test and everything passes. ?Running rake > >>>> spec, however, caught the error. ?I am running a Rails 3 app on OS X > >>>> and RVM 1.8.7-p302 and the the following: > > >>>> rspec (2.0.0.beta.20) > >>>> rspec-core (2.0.0.beta.20) > >>>> rspec-expectations (2.0.0.beta.20) > >>>> rspec-mocks (2.0.0.beta.20) > >>>> rspec-rails (2.0.0.beta.20) > >>>> autotest (4.3.2) > >>>> autotest-fsevent (0.2.3) > >>>> autotest-growl (0.2.5) > >>>> autotest-rails (4.1.0)> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > >>> I also just noticed that renaming the file to something random causes > >>> autotest to pick it up. ?It blows up because the corresponding model > >>> does not exist. ?Naming it back to it's original causes it to miss > >>> again. > > >> Are the names perfectly aligned with the specs? i.e. app/models/thing.rb and spec/models/thing_spec.rb? By default, autotest requires this mapping, though it can be customized if you have a need. > > > Yes, and I don't see any mention of the model in the "No tests > > match...." output from autotest. > > Just noticed your post a few back with the versions - try removing autotest-rails from your Gemfile and make sure you're running autotest with bundle exec. Hrm...I'm not sure what's going on. I already removed autotest-rails, etc. so that I only have: $ gem list | grep -i test autotest (4.3.2) autotest-growl (0.2.5) rack-test (0.5.4) ZenTest (4.4.0) I did notice that it does not appear to be running through bundle exec: /Users/Eric/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -rrubygems Is something misconfigured on my end? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sat Sep 4 09:08:08 2010 From: lists at ruby-forum.com (Zhenning Guan) Date: Sat, 4 Sep 2010 15:08:08 +0200 Subject: [rspec-users] how to wrtie this test?(test true but change when refactor) Message-ID: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> def process! #transaction block bankbook = self.bankbooks.build bankbook = user.bank.bankbooks.build bankbook.withdraw #end end it "should process the withdrawal request" do #something here omit withdrawal.process! @ning.bankbooks.last.price.should == BigDecimal('1.00') @ning.bankbooks.last.action.should == 'withdraw' end bank will withdraw money and bankbook create a record for this withdraw. after a while, I think bankbook should create withdraw item after bank withdraw. so I change the code like following code. def process! #transaction block bank.withdraw #end end # bank model def xxxx bankbook = bankbooks.build bankbook.withdraw end the 'should process the withdrawal request' it's true. but after the change we got two bankbook items. so what's the correct way to create this test? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Sep 4 09:20:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Sep 2010 08:20:39 -0500 Subject: [rspec-users] how to wrtie this test?(test true but change when refactor) In-Reply-To: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> References: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> Message-ID: <16BC1121-3843-4AE4-A768-4D0197449927@gmail.com> On Sep 4, 2010, at 8:08 AM, Zhenning Guan wrote: > def process! > #transaction block > bankbook = self.bankbooks.build > bankbook = user.bank.bankbooks.build > bankbook.withdraw > #end > end > > it "should process the withdrawal request" do > #something here omit > withdrawal.process! > @ning.bankbooks.last.price.should == BigDecimal('1.00') > @ning.bankbooks.last.action.should == 'withdraw' > end > > bank will withdraw money and bankbook create a record for this withdraw. > after a while, I think bankbook should create withdraw item after bank > withdraw. > so I change the code like following code. > def process! > #transaction block > bank.withdraw > #end > end > > # bank model > def xxxx > bankbook = bankbooks.build > bankbook.withdraw > end > > the 'should process the withdrawal request' it's true. but after the > change we got two bankbook items. so what's the correct way to create > this test? I'm having a hard time understanding what you're trying to do here. Can you please post the full before and after code and spec listing in a gist or pastie? http://gist.github.com http://pastie.org From dchelimsky at gmail.com Sat Sep 4 10:42:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Sep 2010 09:42:22 -0500 Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> <9d9f422e-8798-46ac-9dc9-d9edc7647375@c13g2000vbr.googlegroups.com> <81185ff0-6007-4f74-b4e7-a031947aa0c7@g18g2000vbn.googlegroups.com> Message-ID: On Sep 3, 2010, at 10:56 PM, ericindc wrote: > > > On Sep 3, 9:37 pm, David Chelimsky wrote: >> On Sep 3, 2010, at 8:12 PM, ericindc wrote: >> >> >> >> >> >> >> >>> On Sep 3, 8:34 pm, David Chelimsky wrote: >>>> On Sep 3, 2010, at 6:42 PM, ericindc wrote: >> >>>>> On Sep 3, 7:33 pm, ericindc wrote: >>>>>> On Sep 3, 7:09 pm, David Chelimsky wrote: >> >>>>>>> On Sep 3, 2010, at 6:07 PM, ericindc wrote: >> >>>>>>>> On Sep 3, 7:04 pm, David Chelimsky wrote: >>>>>>>>> On Sep 3, 2010, at 6:02 PM, ericindc wrote: >> >>>>>>>>>> Any idea why autotest would miss some of my tests? I run autotest and >>>>>>>>>> everything passes, but rake spec results in 2 failures. The 2 >>>>>>>>>> failures are from the model spec that is not being included when run >>>>>>>>>> in autotest. >> >>>>>>>>> Are you sure that the model spec is excluded from autotest rather than it's just passing? >> >>>>>>>>> Also - versions? rspec, rails, ruby, os? >> >>>>>>>> I also verified in the autotest output that the model spec is not >>>>>>>> included. Not sure if there are others. >> >>>>>>> Versions? >> >>>>>> I purposefully broke the test and everything passes. Running rake >>>>>> spec, however, caught the error. I am running a Rails 3 app on OS X >>>>>> and RVM 1.8.7-p302 and the the following: >> >>>>>> rspec (2.0.0.beta.20) >>>>>> rspec-core (2.0.0.beta.20) >>>>>> rspec-expectations (2.0.0.beta.20) >>>>>> rspec-mocks (2.0.0.beta.20) >>>>>> rspec-rails (2.0.0.beta.20) >>>>>> autotest (4.3.2) >>>>>> autotest-fsevent (0.2.3) >>>>>> autotest-growl (0.2.5) >>>>>> autotest-rails (4.1.0)> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> >>>>> I also just noticed that renaming the file to something random causes >>>>> autotest to pick it up. It blows up because the corresponding model >>>>> does not exist. Naming it back to it's original causes it to miss >>>>> again. >> >>>> Are the names perfectly aligned with the specs? i.e. app/models/thing.rb and spec/models/thing_spec.rb? By default, autotest requires this mapping, though it can be customized if you have a need. >> >>> Yes, and I don't see any mention of the model in the "No tests >>> match...." output from autotest. >> >> Just noticed your post a few back with the versions - try removing autotest-rails from your Gemfile and make sure you're running autotest with bundle exec. > > Hrm...I'm not sure what's going on. I already removed autotest-rails, > etc. so that I only have: > > $ gem list | grep -i test > autotest (4.3.2) > autotest-growl (0.2.5) > rack-test (0.5.4) > ZenTest (4.4.0) > > > I did notice that it does not appear to be running through bundle > exec: > > /Users/Eric/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -rrubygems > > Is something misconfigured on my end? Nope - wasn't handling bundler. Is now: http://github.com/rspec/rspec-core/commit/976b935bde657aebf6f5f7dbb26d6d4e29cc1ac1 Try setting up your gemfile per Living on edge on http://github.com/rspec/rspec-rails. Don't know if it'll help, but it's probably worth trying. From dlidstrom at gmail.com Sat Sep 4 14:41:13 2010 From: dlidstrom at gmail.com (=?ISO-8859-1?Q?Daniel_Lidstr=F6m?=) Date: Sat, 4 Sep 2010 11:41:13 -0700 (PDT) Subject: [rspec-users] render_template failure Message-ID: Hello, I am trying to run this integration test of my user controller within a rails 3 application: # spec/requests/users_spec.rb require 'spec_helper' describe "Users" do describe "success" do it "should make a new user" do lambda do visit signup_path fill_in "Name", :with => "Example User" fill_in "Email", :with => "user at example.com" fill_in "Password", :with => "foobar" fill_in "Confirmation", :with => "foobar" click_button "Sign up" page.should have_css("div.flash.success", :text => "Welcome") response.should render_template("user/show") end.should change(User, :count).by(1) end end end The test fails when render_template is being called: daniel at ubuntu /home/daniel/programming/bowling (signing-up) $ rspec spec/requests/users_spec.rb -e "should make a new user" Run filtered using {:full_description=>/(?-mix:should make a new user)/} F Failures: 1) Users signup success should make a new user Failure/Error: response.should render_template("user/show") @request must be an ActionDispatch::Request # ./spec/requests/users_spec.rb:34 # ./spec/requests/users_spec.rb:26 Finished in 0.41306 seconds 1 example, 1 failure I am using rspec-rails (2.0.0.beta.20) with capybara (0.3.9). What am I missing here? For what it's worth I have verified the behaviour manually: registering a new user does indeed take me to the show page. Thanks in advance! Daniel From dlidstrom at gmail.com Sat Sep 4 14:47:00 2010 From: dlidstrom at gmail.com (=?ISO-8859-1?Q?Daniel_Lidstr=F6m?=) Date: Sat, 4 Sep 2010 11:47:00 -0700 (PDT) Subject: [rspec-users] render_template failure In-Reply-To: References: Message-ID: <36c28669-5cf5-42ef-b442-4eac278e532b@l20g2000yqm.googlegroups.com> On Sep 4, 8:41?pm, Daniel Lidstr?m wrote: > ? ? ? ? ? response.should render_template("user/show") I noticed a mistake on the above line. However, the correct line (with "users/show") also fails: daniel at ubuntu /home/daniel/programming/bowling (signing-up) $ ls app/ views/users/show.html.erb app/views/users/show.html.erb daniel at ubuntu /home/daniel/programming/bowling (signing-up) $ rspec spec/requests/users_spec.rb -e "should make a new user" Run filtered using {:full_description=>/(?-mix:should make a new user)/} F Failures: 1) Users signup success should make a new user Failure/Error: response.should render_template("users/show") @request must be an ActionDispatch::Request # ./spec/requests/users_spec.rb:34 # ./spec/requests/users_spec.rb:26 Finished in 0.27922 seconds 1 example, 1 failure From dchelimsky at gmail.com Sat Sep 4 15:26:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Sep 2010 14:26:10 -0500 Subject: [rspec-users] render_template failure In-Reply-To: References: Message-ID: On Sep 4, 2010, at 1:41 PM, Daniel Lidstr?m wrote: > Hello, > > I am trying to run this integration test of my user controller within > a rails 3 application: > > # spec/requests/users_spec.rb > > require 'spec_helper' > > describe "Users" do > > describe "success" do > > it "should make a new user" do > lambda do > visit signup_path > fill_in "Name", :with => "Example User" > fill_in "Email", :with => "user at example.com" > fill_in "Password", :with => "foobar" > fill_in "Confirmation", :with => "foobar" > click_button "Sign up" > page.should have_css("div.flash.success", :text => > "Welcome") > response.should render_template("user/show") > end.should change(User, :count).by(1) > end > end > end > > The test fails when render_template is being called: > > daniel at ubuntu /home/daniel/programming/bowling (signing-up) $ rspec > spec/requests/users_spec.rb -e "should make a new user" > Run filtered using {:full_description=>/(?-mix:should make a new > user)/} > F > > Failures: > 1) Users signup success should make a new user > Failure/Error: response.should render_template("user/show") > @request must be an ActionDispatch::Request > # ./spec/requests/users_spec.rb:34 > # ./spec/requests/users_spec.rb:26 > > Finished in 0.41306 seconds > 1 example, 1 failure > > I am using rspec-rails (2.0.0.beta.20) with capybara (0.3.9). What am > I missing here? For what it's worth I have verified the behaviour > manually: registering a new user does indeed take me to the show page. > Thanks in advance! The problem is that capybara doesn't assign anything to the @request variable after visit, so it doesn't support any of the built-in rails assertions that rely on @request, and render_template delegates to assert_template. I'd file a bug with capybara on this one. Cheers, David From dchelimsky at gmail.com Sat Sep 4 15:29:02 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Sep 2010 14:29:02 -0500 Subject: [rspec-users] render_template failure In-Reply-To: References: Message-ID: <8355C025-BB5D-45F5-A976-813BB69ADD4F@gmail.com> On Sep 4, 2010, at 2:26 PM, David Chelimsky wrote: > > On Sep 4, 2010, at 1:41 PM, Daniel Lidstr?m wrote: > >> Hello, >> >> I am trying to run this integration test of my user controller within >> a rails 3 application: >> >> # spec/requests/users_spec.rb >> >> require 'spec_helper' >> >> describe "Users" do >> >> describe "success" do >> >> it "should make a new user" do >> lambda do >> visit signup_path >> fill_in "Name", :with => "Example User" >> fill_in "Email", :with => "user at example.com" >> fill_in "Password", :with => "foobar" >> fill_in "Confirmation", :with => "foobar" >> click_button "Sign up" >> page.should have_css("div.flash.success", :text => >> "Welcome") >> response.should render_template("user/show") >> end.should change(User, :count).by(1) >> end >> end >> end >> >> The test fails when render_template is being called: >> >> daniel at ubuntu /home/daniel/programming/bowling (signing-up) $ rspec >> spec/requests/users_spec.rb -e "should make a new user" >> Run filtered using {:full_description=>/(?-mix:should make a new >> user)/} >> F >> >> Failures: >> 1) Users signup success should make a new user >> Failure/Error: response.should render_template("user/show") >> @request must be an ActionDispatch::Request >> # ./spec/requests/users_spec.rb:34 >> # ./spec/requests/users_spec.rb:26 >> >> Finished in 0.41306 seconds >> 1 example, 1 failure >> >> I am using rspec-rails (2.0.0.beta.20) with capybara (0.3.9). What am >> I missing here? For what it's worth I have verified the behaviour >> manually: registering a new user does indeed take me to the show page. >> Thanks in advance! > > The problem is that capybara doesn't assign anything to the @request variable after visit, so it doesn't support any of the built-in rails assertions that rely on @request, and render_template delegates to assert_template. For more context, this works fine with the rails built-in get, post, etc methods: get things_path response.should render_template("things/index") ... as well as webrat's visit method: visit things_path response.should render_template("things/index") That's why I say it's really a capybara issue. Make sense? > I'd file a bug with capybara on this one. > > Cheers, > David From tjtuom at utu.fi Sat Sep 4 16:15:07 2010 From: tjtuom at utu.fi (Toni Tuominen) Date: Sat, 4 Sep 2010 23:15:07 +0300 Subject: [rspec-users] render_template failure In-Reply-To: <8355C025-BB5D-45F5-A976-813BB69ADD4F@gmail.com> References: <8355C025-BB5D-45F5-A976-813BB69ADD4F@gmail.com> Message-ID: Capybara is not a rails-specific solution so it doesn't know anything about rails's rendering logic etc. I'm also fairly sure Jonas will say that it's something that won't be implemented. I think the key thing here is that rendering a template is a controller level thing and Capybara is designed to be an acceptance testing tool, hence you need to test results and not implementation with it. - Toni On Sat, Sep 4, 2010 at 10:29 PM, David Chelimsky wrote: > > On Sep 4, 2010, at 2:26 PM, David Chelimsky wrote: > >> >> On Sep 4, 2010, at 1:41 PM, Daniel Lidstr?m wrote: >> >>> Hello, >>> >>> I am trying to run this integration test of my user controller within >>> a rails 3 application: >>> >>> # spec/requests/users_spec.rb >>> >>> require 'spec_helper' >>> >>> describe "Users" do >>> >>> ? describe "success" do >>> >>> ? ? it "should make a new user" do >>> ? ? ? lambda do >>> ? ? ? ? visit signup_path >>> ? ? ? ? fill_in "Name", :with => "Example User" >>> ? ? ? ? fill_in "Email", :with => "user at example.com" >>> ? ? ? ? fill_in "Password", :with => "foobar" >>> ? ? ? ? fill_in "Confirmation", :with => "foobar" >>> ? ? ? ? click_button "Sign up" >>> ? ? ? ? page.should have_css("div.flash.success", :text => >>> "Welcome") >>> ? ? ? ? response.should render_template("user/show") >>> ? ? ? end.should change(User, :count).by(1) >>> ? ? end >>> ? end >>> end >>> >>> The test fails when render_template is being called: >>> >>> daniel at ubuntu /home/daniel/programming/bowling (signing-up) $ rspec >>> spec/requests/users_spec.rb -e "should make a new user" >>> Run filtered using {:full_description=>/(?-mix:should make a new >>> user)/} >>> F >>> >>> Failures: >>> 1) Users signup success should make a new user >>> ? ?Failure/Error: response.should render_template("user/show") >>> ? ?@request must be an ActionDispatch::Request >>> ? ?# ./spec/requests/users_spec.rb:34 >>> ? ?# ./spec/requests/users_spec.rb:26 >>> >>> Finished in 0.41306 seconds >>> 1 example, 1 failure >>> >>> I am using rspec-rails (2.0.0.beta.20) with capybara (0.3.9). What am >>> I missing here? For what it's worth I have verified the behaviour >>> manually: registering a new user does indeed take me to the show page. >>> Thanks in advance! >> >> The problem is that capybara doesn't assign anything to the @request variable after visit, so it doesn't support any of the built-in rails assertions that rely on @request, and render_template delegates to assert_template. > > For more context, this works fine with the rails built-in get, post, etc methods: > > ?get things_path > ?response.should render_template("things/index") > > ... as well as webrat's visit method: > > ?visit things_path > ?response.should render_template("things/index") > > That's why I say it's really a capybara issue. Make sense? > >> I'd file a bug with capybara on this one. >> >> Cheers, >> David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Sep 4 16:18:16 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Sep 2010 15:18:16 -0500 Subject: [rspec-users] render_template failure In-Reply-To: References: <8355C025-BB5D-45F5-A976-813BB69ADD4F@gmail.com> Message-ID: On Sep 4, 2010, at 3:15 PM, Toni Tuominen wrote: > On Sat, Sep 4, 2010 at 10:29 PM, David Chelimsky wrote: >> >> On Sep 4, 2010, at 2:26 PM, David Chelimsky wrote: >> >>> >>> On Sep 4, 2010, at 1:41 PM, Daniel Lidstr?m wrote: >>> >>>> Hello, >>>> >>>> I am trying to run this integration test of my user controller within >>>> a rails 3 application: >>>> >>>> # spec/requests/users_spec.rb >>>> >>>> require 'spec_helper' >>>> >>>> describe "Users" do >>>> >>>> describe "success" do >>>> >>>> it "should make a new user" do >>>> lambda do >>>> visit signup_path >>>> fill_in "Name", :with => "Example User" >>>> fill_in "Email", :with => "user at example.com" >>>> fill_in "Password", :with => "foobar" >>>> fill_in "Confirmation", :with => "foobar" >>>> click_button "Sign up" >>>> page.should have_css("div.flash.success", :text => >>>> "Welcome") >>>> response.should render_template("user/show") >>>> end.should change(User, :count).by(1) >>>> end >>>> end >>>> end >>>> >>>> The test fails when render_template is being called: >>>> >>>> daniel at ubuntu /home/daniel/programming/bowling (signing-up) $ rspec >>>> spec/requests/users_spec.rb -e "should make a new user" >>>> Run filtered using {:full_description=>/(?-mix:should make a new >>>> user)/} >>>> F >>>> >>>> Failures: >>>> 1) Users signup success should make a new user >>>> Failure/Error: response.should render_template("user/show") >>>> @request must be an ActionDispatch::Request >>>> # ./spec/requests/users_spec.rb:34 >>>> # ./spec/requests/users_spec.rb:26 >>>> >>>> Finished in 0.41306 seconds >>>> 1 example, 1 failure >>>> >>>> I am using rspec-rails (2.0.0.beta.20) with capybara (0.3.9). What am >>>> I missing here? For what it's worth I have verified the behaviour >>>> manually: registering a new user does indeed take me to the show page. >>>> Thanks in advance! >>> >>> The problem is that capybara doesn't assign anything to the @request variable after visit, so it doesn't support any of the built-in rails assertions that rely on @request, and render_template delegates to assert_template. >> >> For more context, this works fine with the rails built-in get, post, etc methods: >> >> get things_path >> response.should render_template("things/index") >> >> ... as well as webrat's visit method: >> >> visit things_path >> response.should render_template("things/index") >> >> That's why I say it's really a capybara issue. Make sense? >> >>> I'd file a bug with capybara on this one. Please post at the bottom or in-line (I move your post from the top). > Capybara is not a rails-specific solution so it doesn't know anything > about rails's rendering logic etc. I'm also fairly sure Jonas will say > that it's something that won't be implemented. Makes sense. So if we decided this was a bug, which lib should own this? > I think the key thing here is that rendering a template is a > controller level thing and Capybara is designed to be an acceptance > testing tool, hence you need to test results and not implementation > with it. +1 Cheers, David From lailsonbm at gmail.com Sat Sep 4 16:27:02 2010 From: lailsonbm at gmail.com (Lailson Bandeira) Date: Sat, 4 Sep 2010 17:27:02 -0300 Subject: [rspec-users] [Rails] [Bug] use_transactional_fixtures = false suppress the 'fixtures' method In-Reply-To: References: Message-ID: Hi folks, I'm having a problem with fixtures. When I configure RSpec to don't use transactional fixtures, the fixtures method goes away. Supposing there's a State model and a fixture file with two records, this works flawlessly: RSpec.configure do |config| #... config.use_transactional_fixtures = true end describe State do *fixtures :all* it 'should bring the fixtures from database' do State.all.should have(2).states end end But when I set config.use_transactional_fixtures = false, I get this error: ./spec/models/state_spec.rb:4:in `block in
': undefined method `fixtures' for # (NoMethodError) from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `module_eval' from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `subclass' from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:116:in `describe' from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/extensions/object.rb:7:in `describe' from ./spec/models/state_spec.rb:3:in `
' I'm using Rails 3, RSpec 2.0.0.beta.20 and the same version of rspec-rails (I also used the code directly from Gihub but it didn't work too). I suppose this is a bug, but I just wanted to confirm with you guys before opening the issue ticket. And thanks for this great thing that RSpec is -- LAILSON BANDEIRA http://lailsonbandeira.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lailsonbm at gmail.com Fri Sep 3 20:41:04 2010 From: lailsonbm at gmail.com (Lailson Bandeira) Date: Fri, 3 Sep 2010 21:41:04 -0300 Subject: [rspec-users] [Rails] [Bug] use_transactional_fixtures = false suppress the 'fixtures' method Message-ID: Hi folks, I'm having a problem with fixtures. When I configure RSpec to don't use transactional fixtures, the fixtures method goes away. Supposing there's a State model and a fixture file with two records, this works flawlessly: RSpec.configure do |config| #... config.use_transactional_fixtures = true end describe State do *fixtures :all* it 'should bring the fixtures from database' do State.all.should have(2).states end end But when I set config.use_transactional_fixtures = false, I get this error: ./spec/models/state_spec.rb:4:in `block in
': undefined method `fixtures' for # (NoMethodError) from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `module_eval' from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `subclass' from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:116:in `describe' from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/extensions/object.rb:7:in `describe' from ./spec/models/state_spec.rb:3:in `
' I'm using Rails 3, RSpec 2.0.0.beta.20 and the same version of rspec-rails (I also used the code directly from Gihub but it didn't work too). I suppose this is a bug, but I just wanted to confirm with you guys before opening the issue ticket. And thanks for this great thing that RSpec is -- LAILSON BANDEIRA http://lailsonbandeira.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.denlinger at gmail.com Sat Sep 4 13:25:16 2010 From: paul.denlinger at gmail.com (Paul Denlinger) Date: Sat, 4 Sep 2010 10:25:16 -0700 (PDT) Subject: [rspec-users] Error when trying to run rspec Message-ID: Just tried to run rspec and got this error message even though the rspec gem installed successfully: $ spec hello_spec.rb /Users/pdenlinger/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb: 340:in `bin_path': can't find executable spec for rspec-2.0.0.beta.18 (Gem::Exception) from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0/bin/spec:19:in `
' What do I need to do to make things work? Thanks in advance, Paul Denlinger From dchelimsky at gmail.com Sat Sep 4 16:47:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Sep 2010 15:47:03 -0500 Subject: [rspec-users] [Rails] [Bug] use_transactional_fixtures = false suppress the 'fixtures' method In-Reply-To: References: Message-ID: On Sep 3, 2010, at 7:41 PM, Lailson Bandeira wrote: > Hi folks, > > > I'm having a problem with fixtures. When I configure RSpec to don't use transactional fixtures, the fixtures method goes away. > Supposing there's a State model and a fixture file with two records, this works flawlessly: > > RSpec.configure do |config| > #... > config.use_transactional_fixtures = true > end > describe State do > fixtures :all > > it 'should bring the fixtures from database' do > State.all.should have(2).states > end > end > > But when I set config.use_transactional_fixtures = false, I get this error: > > ./spec/models/state_spec.rb:4:in `block in
': undefined method `fixtures' for # (NoMethodError) > from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `module_eval' > from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in `subclass' > from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:116:in `describe' > from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/extensions/object.rb:7:in `describe' > from ./spec/models/state_spec.rb:3:in `
' > > I'm using Rails 3, RSpec 2.0.0.beta.20 and the same version of rspec-rails (I also used the code directly from Gihub but it didn't work too). > I suppose this is a bug, but I just wanted to confirm with you guys before opening the issue ticket. Yep. Bug. Please report to http://github.com/rspec/rspec-rails/issues. > And thanks for this great thing that RSpec is Thanks for that. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Sep 4 16:48:04 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Sep 2010 15:48:04 -0500 Subject: [rspec-users] Error when trying to run rspec In-Reply-To: References: Message-ID: On Sep 4, 2010, at 12:25 PM, Paul Denlinger wrote: > Just tried to run rspec and got this error message even though the > rspec gem installed successfully: > > > $ spec hello_spec.rb > /Users/pdenlinger/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb: > 340:in `bin_path': can't find executable spec for rspec-2.0.0.beta.18 > (Gem::Exception) > from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0/bin/spec:19:in > `
' > > What do I need to do to make things work? The command is now rspec. http://github.com/rspec/rspec-core/blob/master/Upgrade.markdown Cheers, David From lailsonbm at gmail.com Sat Sep 4 17:18:36 2010 From: lailsonbm at gmail.com (Lailson Bandeira) Date: Sat, 4 Sep 2010 18:18:36 -0300 Subject: [rspec-users] [Rails] [Bug] use_transactional_fixtures = false suppress the 'fixtures' method In-Reply-To: References: Message-ID: Ok David. Here it is: http://github.com/rspec/rspec-rails/issues#issue/197 Thanks for your fast response -- LAILSON BANDEIRA http://lailsonbandeira.com/ On Sat, Sep 4, 2010 at 5:47 PM, David Chelimsky wrote: > > On Sep 3, 2010, at 7:41 PM, Lailson Bandeira wrote: > > Hi folks, > > > I'm having a problem with fixtures. When I configure RSpec to don't use > transactional fixtures, the fixtures method goes away. > Supposing there's a State model and a fixture file with two records, this > works flawlessly: > > RSpec.configure do |config| > #... > config.use_transactional_fixtures = true > end > describe State do > *fixtures :all* > > it 'should bring the fixtures from database' do > State.all.should have(2).states > end > end > > > But when I set config.use_transactional_fixtures = false, I get this > error: > > ./spec/models/state_spec.rb:4:in `block in
': undefined method > `fixtures' for # (NoMethodError) > from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in > `module_eval' > from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:129:in > `subclass' > from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/example_group.rb:116:in > `describe' > from /Users/lailsonbm/.rvm/gems/ruby-1.9.2-p0 at rails3/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/extensions/object.rb:7:in > `describe' > from ./spec/models/state_spec.rb:3:in `
' > > I'm using Rails 3, RSpec 2.0.0.beta.20 and the same version of rspec-rails > (I also used the code directly from Gihub but it didn't work too). > I suppose this is a bug, but I just wanted to confirm with you guys before > opening the issue ticket. > > > Yep. Bug. Please report to http://github.com/rspec/rspec-rails/issues. > > And thanks for this great thing that RSpec is > > > Thanks for that. > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericmilford at gmail.com Sat Sep 4 22:52:30 2010 From: ericmilford at gmail.com (ericindc) Date: Sat, 4 Sep 2010 19:52:30 -0700 (PDT) Subject: [rspec-users] [rspec-autotest] Autotest is missing some of my specs In-Reply-To: References: <20D88951-F8FB-43E0-8069-20F8936DEFFF@gmail.com> <90a753e0-01a6-4270-8dd3-340ba1f1f54f@l17g2000vbf.googlegroups.com> <9d9f422e-8798-46ac-9dc9-d9edc7647375@c13g2000vbr.googlegroups.com> <81185ff0-6007-4f74-b4e7-a031947aa0c7@g18g2000vbn.googlegroups.com> Message-ID: <74d3070e-287c-401a-a10f-fe01dfb4d1bc@e14g2000yqe.googlegroups.com> On Sep 4, 10:42?am, David Chelimsky wrote: > On Sep 3, 2010, at 10:56 PM, ericindc wrote: > > > > > > > > > On Sep 3, 9:37 pm, David Chelimsky wrote: > >> On Sep 3, 2010, at 8:12 PM, ericindc wrote: > > >>> On Sep 3, 8:34 pm, David Chelimsky wrote: > >>>> On Sep 3, 2010, at 6:42 PM, ericindc wrote: > > >>>>> On Sep 3, 7:33 pm, ericindc wrote: > >>>>>> On Sep 3, 7:09 pm, David Chelimsky wrote: > > >>>>>>> On Sep 3, 2010, at 6:07 PM, ericindc wrote: > > >>>>>>>> On Sep 3, 7:04 pm, David Chelimsky wrote: > >>>>>>>>> On Sep 3, 2010, at 6:02 PM, ericindc wrote: > > >>>>>>>>>> Any idea why autotest would miss some of my tests? ?I run autotest and > >>>>>>>>>> everything passes, but rake spec results in 2 failures. ?The 2 > >>>>>>>>>> failures are from the model spec that is not being included when run > >>>>>>>>>> in autotest. > > >>>>>>>>> Are you sure that the model spec is excluded from autotest rather than it's just passing? > > >>>>>>>>> Also - versions? rspec, rails, ruby, os? > > >>>>>>>> I also verified in the autotest output that the model spec is not > >>>>>>>> included. ?Not sure if there are others. > > >>>>>>> Versions? > > >>>>>> I purposefully broke the test and everything passes. ?Running rake > >>>>>> spec, however, caught the error. ?I am running a Rails 3 app on OS X > >>>>>> and RVM 1.8.7-p302 and the the following: > > >>>>>> rspec (2.0.0.beta.20) > >>>>>> rspec-core (2.0.0.beta.20) > >>>>>> rspec-expectations (2.0.0.beta.20) > >>>>>> rspec-mocks (2.0.0.beta.20) > >>>>>> rspec-rails (2.0.0.beta.20) > >>>>>> autotest (4.3.2) > >>>>>> autotest-fsevent (0.2.3) > >>>>>> autotest-growl (0.2.5) > >>>>>> autotest-rails (4.1.0)> _______________________________________________ > >>>>>>> rspec-users mailing list > >>>>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > >>>>> I also just noticed that renaming the file to something random causes > >>>>> autotest to pick it up. ?It blows up because the corresponding model > >>>>> does not exist. ?Naming it back to it's original causes it to miss > >>>>> again. > > >>>> Are the names perfectly aligned with the specs? i.e. app/models/thing.rb and spec/models/thing_spec.rb? By default, autotest requires this mapping, though it can be customized if you have a need. > > >>> Yes, and I don't see any mention of the model in the "No tests > >>> match...." output from autotest. > > >> Just noticed your post a few back with the versions - try removing autotest-rails from your Gemfile and make sure you're running autotest with bundle exec. > > > Hrm...I'm not sure what's going on. ?I already removed autotest-rails, > > etc. so that I only have: > > > $ gem list | grep -i test > > autotest (4.3.2) > > autotest-growl (0.2.5) > > rack-test (0.5.4) > > ZenTest (4.4.0) > > > I did notice that it does not appear to be running through bundle > > exec: > > > /Users/Eric/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -rrubygems > > > Is something misconfigured on my end? > > Nope - wasn't handling bundler. Is now:http://github.com/rspec/rspec-core/commit/976b935bde657aebf6f5f7dbb26... > > Try setting up your gemfile per Living on edge onhttp://github.com/rspec/rspec-rails. Don't know if it'll help, but it's probably worth trying. No luck. Even with living on the edge, it's still not running under bundler (could it be something with RVM) and I get 144 tests with autotest and 151 with rake spec. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From tjtuom at utu.fi Sun Sep 5 02:45:12 2010 From: tjtuom at utu.fi (Toni Tuominen) Date: Sun, 5 Sep 2010 09:45:12 +0300 Subject: [rspec-users] render_template failure In-Reply-To: References: <8355C025-BB5D-45F5-A976-813BB69ADD4F@gmail.com> Message-ID: > >> Capybara is not a rails-specific solution so it doesn't know anything >> about rails's rendering logic etc. I'm also fairly sure Jonas will say >> that it's something that won't be implemented. > > Makes sense. So if we decided this was a bug, which lib should own this? Personally I don't see why rspec needs to offer integration level tools in controller specs at all. If people want to render views and assert the rendered content I think they should use this gem for that http://github.com/grimen/rspec_tag_matchers. Overall it's an excellent tool for any case where you need to assert html. I've found it to be of great value in helper specs. From david.spurr at gmail.com Mon Sep 6 05:37:43 2010 From: david.spurr at gmail.com (DEfusion) Date: Mon, 6 Sep 2010 02:37:43 -0700 (PDT) Subject: [rspec-users] How can I set the host for testing subdomain constrained routes in RSpec 2? Message-ID: I've tried: host = 'foo.bar.com' host! (undefined method) request.host (request undefined) controller.request.host (controller undefined) @controller.request.host (undefined method `request' for nil:NilClass) From brennon at brennonbortz.com Mon Sep 6 09:15:37 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Mon, 6 Sep 2010 14:15:37 +0100 Subject: [rspec-users] should contain vs. =~ Message-ID: <27C158AD-EDB5-4FE6-9B47-91BF85FACEDB@brennonbortz.com> I'm developing another view test. Relevant example: it "should show the item's url" do rendered.should contain("http://www.example.com") end I'm calling render in a before block. I have other similar examples on the page in which I'm simply using: rendered.should =~ "..." These all work fine, as does the first example I posted here. However, when trying to express that first example with a regex (which I prefer), the example fails: it "should show the item's url" do rendered.should =~ /http:\/\/www.example.com/ end Am I missing something? Thanks, Brennon Bortz Software Researcher Dundalk Institute of Technology brennon.bortz at casala.ie Ph.D. Researcher & Composer - Sonic Arts Research Centre Queen's University, Belfast brennon at brennonbortz.com / bbortz01 at qub.ac.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Sep 6 09:47:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Sep 2010 08:47:22 -0500 Subject: [rspec-users] How can I set the host for testing subdomain constrained routes in RSpec 2? In-Reply-To: References: Message-ID: <926F5F06-19A5-48C5-BE78-21651660A4DB@gmail.com> On Sep 6, 2010, at 4:37 AM, DEfusion wrote: > I've tried: > host = 'foo.bar.com' > host! (undefined method) > request.host (request undefined) > controller.request.host (controller undefined) > @controller.request.host (undefined method `request' for nil:NilClass) { :get => "http://sub.top.com/foo/bar" }.should route_to(:controller => "foo", :action => "bar", :subdomain => "sub") HTH, David From dchelimsky at gmail.com Mon Sep 6 09:55:17 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Sep 2010 08:55:17 -0500 Subject: [rspec-users] should contain vs. =~ In-Reply-To: <27C158AD-EDB5-4FE6-9B47-91BF85FACEDB@brennonbortz.com> References: <27C158AD-EDB5-4FE6-9B47-91BF85FACEDB@brennonbortz.com> Message-ID: On Sep 6, 2010, at 8:15 AM, Brennon Bortz wrote: > I'm developing another view test. Relevant example: > > it "should show the item's url" do > rendered.should contain("http://www.example.com") > end > > I'm calling render in a before block. I have other similar examples on the page in which I'm simply using: > > rendered.should =~ "..." > > These all work fine, as does the first example I posted here. However, when trying to express that first example with a regex (which I prefer), the example fails: > > it "should show the item's url" do > rendered.should =~ /http:\/\/www.example.com/ > end > > Am I missing something? Please post the failure message. -------------- next part -------------- An HTML attachment was scrubbed... URL: From brennon at brennonbortz.com Mon Sep 6 10:20:44 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Mon, 6 Sep 2010 15:20:44 +0100 Subject: [rspec-users] should contain vs. =~ In-Reply-To: References: <27C158AD-EDB5-4FE6-9B47-91BF85FACEDB@brennonbortz.com> Message-ID: On 6 Sep 2010, at 14:55, David Chelimsky wrote: > On Sep 6, 2010, at 8:15 AM, Brennon Bortz wrote: > >> I'm developing another view test. Relevant example: >> >> it "should show the item's url" do >> rendered.should contain("http://www.example.com") >> end >> >> I'm calling render in a before block. I have other similar examples on the page in which I'm simply using: >> >> rendered.should =~ "..." >> >> These all work fine, as does the first example I posted here. However, when trying to express that first example with a regex (which I prefer), the example fails: >> >> it "should show the item's url" do >> rendered.should =~ /http:\/\/www.example.com/ >> end >> >> Am I missing something? Failures: 1) widgets/show.html.erb widget details should show the widget's url Failure/Error: rendered.should =~ /http:\/\/www.example.com/ expected: /http:\/\/www.example.com/, got: "http://www.example.com" (using =~) I realise this is because of the escaped HTML output, but I'm not quite sure what to do about it... -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Sep 6 10:39:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Sep 2010 09:39:58 -0500 Subject: [rspec-users] should contain vs. =~ In-Reply-To: References: <27C158AD-EDB5-4FE6-9B47-91BF85FACEDB@brennonbortz.com> Message-ID: <8AEFFBD6-BA8B-49AE-A6D7-66CA50137864@gmail.com> On Sep 6, 2010, at 9:20 AM, Brennon Bortz wrote: > On 6 Sep 2010, at 14:55, David Chelimsky wrote: > >> On Sep 6, 2010, at 8:15 AM, Brennon Bortz wrote: >> >>> I'm developing another view test. Relevant example: >>> >>> it "should show the item's url" do >>> rendered.should contain("http://www.example.com") >>> end >>> >>> I'm calling render in a before block. I have other similar examples on the page in which I'm simply using: >>> >>> rendered.should =~ "..." >>> >>> These all work fine, as does the first example I posted here. However, when trying to express that first example with a regex (which I prefer), the example fails: >>> >>> it "should show the item's url" do >>> rendered.should =~ /http:\/\/www.example.com/ >>> end >>> >>> Am I missing something? > > > Failures: > 1) widgets/show.html.erb widget details should show the widget's url > Failure/Error: rendered.should =~ /http:\/\/www.example.com/ > expected: /http:\/\/www.example.com/, > got: "http://www.example.com" (using =~) > > I realise this is because of the escaped HTML output, but I'm not quite sure what to do about it... I think contain is your best bet here, unless you actually want to change the expectation so it includes the escaped characters. FWIW, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.spurr at gmail.com Mon Sep 6 10:47:42 2010 From: david.spurr at gmail.com (DEfusion) Date: Mon, 6 Sep 2010 07:47:42 -0700 (PDT) Subject: [rspec-users] How can I set the host for testing subdomain constrained routes in RSpec 2? In-Reply-To: <926F5F06-19A5-48C5-BE78-21651660A4DB@gmail.com> References: <926F5F06-19A5-48C5-BE78-21651660A4DB@gmail.com> Message-ID: <544dbfe7-7805-4f61-8811-1b6bd6f6b320@z28g2000yqh.googlegroups.com> Thanks David, that works perfect, I didn't think about passing the whole URL to get. On Sep 6, 2:47?pm, David Chelimsky wrote: > On Sep 6, 2010, at 4:37 AM, DEfusion wrote: > > > I've tried: > > host = 'foo.bar.com' > > host! (undefined method) > > request.host (request undefined) > > controller.request.host (controller undefined) > > @controller.request.host (undefined method `request' for nil:NilClass) > > { :get => "http://sub.top.com/foo/bar" }.should route_to(:controller => "foo", :action => "bar", :subdomain => "sub") > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From brennon at brennonbortz.com Mon Sep 6 10:51:13 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Mon, 6 Sep 2010 15:51:13 +0100 Subject: [rspec-users] should contain vs. =~ In-Reply-To: <8AEFFBD6-BA8B-49AE-A6D7-66CA50137864@gmail.com> References: <27C158AD-EDB5-4FE6-9B47-91BF85FACEDB@brennonbortz.com> <8AEFFBD6-BA8B-49AE-A6D7-66CA50137864@gmail.com> Message-ID: On 6 Sep 2010, at 15:39, David Chelimsky wrote: > On Sep 6, 2010, at 9:20 AM, Brennon Bortz wrote: > >> On 6 Sep 2010, at 14:55, David Chelimsky wrote: >> >>> On Sep 6, 2010, at 8:15 AM, Brennon Bortz wrote: >>> >>>> I'm developing another view test. Relevant example: >>>> >>>> it "should show the item's url" do >>>> rendered.should contain("http://www.example.com") >>>> end >>>> >>>> I'm calling render in a before block. I have other similar examples on the page in which I'm simply using: >>>> >>>> rendered.should =~ "..." >>>> >>>> These all work fine, as does the first example I posted here. However, when trying to express that first example with a regex (which I prefer), the example fails: >>>> >>>> it "should show the item's url" do >>>> rendered.should =~ /http:\/\/www.example.com/ >>>> end >>>> >>>> Am I missing something? >> >> >> Failures: >> 1) widgets/show.html.erb widget details should show the widget's url >> Failure/Error: rendered.should =~ /http:\/\/www.example.com/ >> expected: /http:\/\/www.example.com/, >> got: "http://www.example.com" (using =~) >> >> I realise this is because of the escaped HTML output, but I'm not quite sure what to do about it... > > I think contain is your best bet here, unless you actually want to change the expectation so it includes the escaped characters. I've got no problem doing that. On a related note, though, is there any possibility that Capybara matchers will ever be available in view/helper examples? should_contain is a little bit open-ended for my taste. Thanks, BB -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Sep 6 11:15:52 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Sep 2010 10:15:52 -0500 Subject: [rspec-users] should contain vs. =~ In-Reply-To: References: <27C158AD-EDB5-4FE6-9B47-91BF85FACEDB@brennonbortz.com> <8AEFFBD6-BA8B-49AE-A6D7-66CA50137864@gmail.com> Message-ID: On Sep 6, 2010, at 9:51 AM, Brennon Bortz wrote: > On 6 Sep 2010, at 15:39, David Chelimsky wrote: > >> On Sep 6, 2010, at 9:20 AM, Brennon Bortz wrote: >> >>> On 6 Sep 2010, at 14:55, David Chelimsky wrote: >>> >>>> On Sep 6, 2010, at 8:15 AM, Brennon Bortz wrote: >>>> >>>>> I'm developing another view test. Relevant example: >>>>> >>>>> it "should show the item's url" do >>>>> rendered.should contain("http://www.example.com") >>>>> end >>>>> >>>>> I'm calling render in a before block. I have other similar examples on the page in which I'm simply using: >>>>> >>>>> rendered.should =~ "..." >>>>> >>>>> These all work fine, as does the first example I posted here. However, when trying to express that first example with a regex (which I prefer), the example fails: >>>>> >>>>> it "should show the item's url" do >>>>> rendered.should =~ /http:\/\/www.example.com/ >>>>> end >>>>> >>>>> Am I missing something? >>> >>> >>> Failures: >>> 1) widgets/show.html.erb widget details should show the widget's url >>> Failure/Error: rendered.should =~ /http:\/\/www.example.com/ >>> expected: /http:\/\/www.example.com/, >>> got: "http://www.example.com" (using =~) >>> >>> I realise this is because of the escaped HTML output, but I'm not quite sure what to do about it... >> >> I think contain is your best bet here, unless you actually want to change the expectation so it includes the escaped characters. > > I've got no problem doing that. On a related note, though, is there any possibility that Capybara matchers will ever be available in view/helper examples? should_contain is a little bit open-ended for my taste. I'd like that very much, but, as things stand today, they're bound to the Capybara session, so they won't work in view specs (which don't have a full request cycle). I've chatted w/ Jonas about this and he's interested in decoupling the matchers so we could use them against an arbitrary string, but there's no definite commitment to that or an ETA. Wish I had better news than that, but that's the state of things. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjtuom at utu.fi Mon Sep 6 11:20:26 2010 From: tjtuom at utu.fi (Toni Tuominen) Date: Mon, 6 Sep 2010 18:20:26 +0300 Subject: [rspec-users] should contain vs. =~ In-Reply-To: References: <27C158AD-EDB5-4FE6-9B47-91BF85FACEDB@brennonbortz.com> <8AEFFBD6-BA8B-49AE-A6D7-66CA50137864@gmail.com> Message-ID: Capybara matchers I think will stay Capybara specific. However, you can use this gem to test any kind of string containing html: http://github.com/grimen/rspec_tag_matchers. David: Maybe you should consider adding that gem to the rspec-rails core or at least mention it in the docs. Need for it seems to be popping up everywhere. - Toni On Mon, Sep 6, 2010 at 5:51 PM, Brennon Bortz wrote: > On 6 Sep 2010, at 15:39, David Chelimsky wrote: > > On Sep 6, 2010, at 9:20 AM, Brennon Bortz wrote: > > On 6 Sep 2010, at 14:55, David Chelimsky wrote: > > On Sep 6, 2010, at 8:15 AM, Brennon Bortz wrote: > > I'm developing another view test. ?Relevant example: > it "should show the item's url" do > ?? ? ?rendered.should contain("http://www.example.com") > end > I'm calling render in a before block. ?I have other similar examples on the > page in which I'm simply using: > rendered.should =~ "..." > These all work fine, as does the first example I posted here. ?However, when > trying to express that first example with a regex (which I prefer), the > example fails: > it "should show the item's url" do > ?? ? ?rendered.should =~ /http:\/\/www.example.com/ > end > Am I missing something? > > Failures: > ??1) widgets/show.html.erb widget details should show the widget's url > ?? ? Failure/Error: rendered.should =~ /http:\/\/www.example.com/ > ?? ? expected: /http:\/\/www.example.com/, > ?? ? ? ? ?got: "http://www.example.com" (using =~) > I realise this is because of the escaped HTML output, but I'm not quite sure > what to do about it... > > I think contain is your best bet here, unless you actually want to change > the expectation so it includes the escaped characters. > > I've got no problem doing that. ?On a related note, though, is there any > possibility that Capybara matchers will ever be available in view/helper > examples? ?should_contain is a little bit open-ended for my taste. > Thanks, > BB > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From amir.nagri at gmail.com Mon Sep 6 11:40:29 2010 From: amir.nagri at gmail.com (Amiruddin Nagri) Date: Mon, 6 Sep 2010 21:10:29 +0530 Subject: [rspec-users] render_with_layout not working with RSpec 2 + Rails 3 + shoulda 2.11.3 Message-ID: Hello, I am trying to assert that my controller is rendered with particular layout file it "should render application layout" do get :index should render_with_layout('application') end but it is giving error like undefined method `layout' for nil:NilClass # /Users/userX/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing' # /Users/userX/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb:67:in `rendered_layouts' # /Users/userX/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb:55:in `rendered_with_layout?' # /Users/userX/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb:31:in `matches?' # ./spec/controllers/some_controller_spec.rb:6:in `block (2 levels) in
' I have uploaded a sample app where the issue can be produced here -> http://github.com/anagri/shoulda_rspec_sample What am I doing wrong ? is it a good idea to jump on Rails 3 while issues with a lot of essential plugins still being ironed out ? Thanks, Amiruddin Nagri -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon Sep 6 21:37:29 2010 From: lists at ruby-forum.com (Zhenning Guan) Date: Tue, 7 Sep 2010 03:37:29 +0200 Subject: [rspec-users] how to wrtie this test?(test true but change when refactor) In-Reply-To: <16BC1121-3843-4AE4-A768-4D0197449927@gmail.com> References: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> <16BC1121-3843-4AE4-A768-4D0197449927@gmail.com> Message-ID: <20538ebf07a06d0a5f8175c34c2fc092@ruby-forum.com> David Chelimsky wrote: > I'm having a hard time understanding what you're trying to do here. Can > you please post the full before and after code and spec listing in a > gist or pastie? > > http://gist.github.com > http://pastie.org the before just mock a user. and user request to withdraw money from he's bank account, after that, we record his action like 'david withdraw $10' in bankbook. the problem above is I expect one bankbook 'david withdraw $10' but create two 'david withdraw $10'.in database, just because the I use last api to receive last record. @ning.bankbooks.last.action.should == 'withdraw' I guess I should do a count check like lambda{ withdrawal.process!}.should change {Bankbook.count}.by(1) -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Sep 6 22:11:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Sep 2010 21:11:45 -0500 Subject: [rspec-users] how to wrtie this test?(test true but change when refactor) In-Reply-To: <20538ebf07a06d0a5f8175c34c2fc092@ruby-forum.com> References: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> <16BC1121-3843-4AE4-A768-4D0197449927@gmail.com> <20538ebf07a06d0a5f8175c34c2fc092@ruby-forum.com> Message-ID: <821CFB24-19EC-42EB-AF37-D8F9FA2980C5@gmail.com> On Sep 6, 2010, at 8:37 PM, Zhenning Guan wrote: > David Chelimsky wrote: >> I'm having a hard time understanding what you're trying to do here. Can >> you please post the full before and after code and spec listing in a >> gist or pastie? >> >> http://gist.github.com >> http://pastie.org > > the before just mock a user. and user request to withdraw money from > he's bank account, after that, we record his action like 'david withdraw > $10' in bankbook. > the problem above is I expect one bankbook 'david withdraw $10' but > create two 'david withdraw $10'.in database, just because the I use last > api to receive last record. > @ning.bankbooks.last.action.should == 'withdraw' > > I guess I should do a count check like > > lambda{ withdrawal.process!}.should change {Bankbook.count}.by(1) By "before and after" I meant what the code looked like before you made the change you want to make, and what it looked like after the change. From lists at ruby-forum.com Mon Sep 6 22:28:54 2010 From: lists at ruby-forum.com (Zhenning Guan) Date: Tue, 7 Sep 2010 04:28:54 +0200 Subject: [rspec-users] how to wrtie this test?(test true but change when refactor) In-Reply-To: <821CFB24-19EC-42EB-AF37-D8F9FA2980C5@gmail.com> References: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> <16BC1121-3843-4AE4-A768-4D0197449927@gmail.com> <20538ebf07a06d0a5f8175c34c2fc092@ruby-forum.com> <821CFB24-19EC-42EB-AF37-D8F9FA2980C5@gmail.com> Message-ID: <329067c65d08ede2486eac818d85020c@ruby-forum.com> David Chelimsky wrote: > By "before and after" I meant what the code looked like before you made > the change you want to make, and what it looked like after the change. sorry I misunderstood your word. def process! #transaction block bankbook = self.bankbooks.build bankbook = user.bank.bankbooks.build bankbook.withdraw #end end that's the before code.and I change it to. def process! #transaction block bank.withdraw #end end because I have been miss the create banbooks in bank model withdraw method. code like -- # bank model def xxxx bankbook = bankbooks.build bankbook.withdraw end -- hope I clear my thought. -- Posted via http://www.ruby-forum.com/. From dolzenko at gmail.com Tue Sep 7 05:21:09 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Tue, 7 Sep 2010 13:21:09 +0400 Subject: [rspec-users] render_with_layout not working with RSpec 2 + Rails 3 + shoulda 2.11.3 In-Reply-To: References: Message-ID: My 2cents: while upgrading my test suite I replaced all such cases with just it { should render_template("layouts/application") } Worked for me. On Mon, Sep 6, 2010 at 7:40 PM, Amiruddin Nagri wrote: > Hello, > > I am trying to assert that my controller is rendered with particular layout > file > > ? it "should render application layout" do > ??? get :index > ??? should render_with_layout('application') > ? end > > but it is giving error like > > ???? undefined method `layout' for nil:NilClass > ???? # > /Users/userX/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in > `method_missing' > ???? # > /Users/userX/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb:67:in > `rendered_layouts' > ???? # > /Users/userX/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb:55:in > `rendered_with_layout?' > ???? # > /Users/userX/.rvm/gems/ruby-1.9.2-p0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb:31:in > `matches?' > ???? # ./spec/controllers/some_controller_spec.rb:6:in `block (2 levels) in >
' > > > I have uploaded a sample app where the issue can be produced here -> > http://github.com/anagri/shoulda_rspec_sample > > What am I doing wrong ? is it a good idea to jump on Rails 3 while issues > with a lot of essential plugins still being ironed out ? > > Thanks, > Amiruddin Nagri > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Sep 7 06:44:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Sep 2010 05:44:58 -0500 Subject: [rspec-users] how to wrtie this test?(test true but change when refactor) In-Reply-To: <329067c65d08ede2486eac818d85020c@ruby-forum.com> References: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> <16BC1121-3843-4AE4-A768-4D0197449927@gmail.com> <20538ebf07a06d0a5f8175c34c2fc092@ruby-forum.com> <821CFB24-19EC-42EB-AF37-D8F9FA2980C5@gmail.com> <329067c65d08ede2486eac818d85020c@ruby-forum.com> Message-ID: <750FCD5D-9C23-4090-B2CE-AD09AE6A176F@gmail.com> On Sep 6, 2010, at 9:28 PM, Zhenning Guan wrote: > David Chelimsky wrote: >> By "before and after" I meant what the code looked like before you made >> the change you want to make, and what it looked like after the change. > > > sorry I misunderstood your word. > > > > def process! > #transaction block > bankbook = self.bankbooks.build > bankbook = user.bank.bankbooks.build > bankbook.withdraw > #end > end > > that's the before code.and I change it to. > > def process! > #transaction block > bank.withdraw > #end > end > > because I have been miss the create banbooks in bank model withdraw > method. > code like > -- > # bank model > def xxxx Is this withdraw instead of xxxx? > bankbook = bankbooks.build > bankbook.withdraw > end > -- > > hope I clear my thought. In your original post you said you were getting two bankbook items after the change. Do you want one or two? And where is the 2nd one coming from? From lists at ruby-forum.com Tue Sep 7 07:01:46 2010 From: lists at ruby-forum.com (Cameron Caine) Date: Tue, 7 Sep 2010 13:01:46 +0200 Subject: [rspec-users] Correct spec for a scoped controller Message-ID: In almost all my controllers I scope everything through an @account model object, e.g: #teams_controller.rb def new @team = @account.teams.build end So far I have got passing specs using these: describe TeamsController do let(:account) { Account.new } before(:each) do Account.stub!(:find_by_subdomain!).and_return(account) account.stub!(:teams) end describe "GET new" do let(:team) { Team.new("account_id" => account.id) } before(:each) do account.teams.should_receive(:build).and_return(team) end it "assigns @team to a new scoped instance of Team" do get :new assigns[:team].should eq(team) end it "renders the new template" do get :new response.should render_template("new") end end end I am interested to know if this is best practice for scoping everything through an existing model object. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Sep 7 07:58:01 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Sep 2010 06:58:01 -0500 Subject: [rspec-users] Correct spec for a scoped controller In-Reply-To: References: Message-ID: <9F1B5B62-6F26-4B31-AEC3-B2EF20CA81EA@gmail.com> On Sep 7, 2010, at 6:01 AM, Cameron Caine wrote: > In almost all my controllers I scope everything through an @account > model object, e.g: > > #teams_controller.rb > def new > @team = @account.teams.build > end > > So far I have got passing specs using these: > > describe TeamsController do > let(:account) { Account.new } > > before(:each) do > Account.stub!(:find_by_subdomain!).and_return(account) > account.stub!(:teams) > end > > describe "GET new" do > let(:team) { Team.new("account_id" => account.id) } > > before(:each) do > account.teams.should_receive(:build).and_return(team) > end > > it "assigns @team to a new scoped instance of Team" do > get :new > assigns[:team].should eq(team) > end > > it "renders the new template" do > get :new > response.should render_template("new") > end > end > end > > I am interested to know if this is best practice for scoping everything > through an existing model object. That's a lot of noise for two simple examples. I'd either just use AR (no stubs) or add a build_team method to Account. I also prefer to keep message expectations (should_receive) in the examples that specify the expectation. In the spec above "renders the new template" would fail for the wrong reason if the other example failed. I also like to keep the let() statements near each other since they're eval'd lazily (makes it easier to find them). That would lead me to something like: describe TeamsController do let(:account) { stub_model(Account).as_null_object } let(:team) { stub_model(Team) } before(:each) do Account.stub(:find_by_subdomain!) { account } end describe "GET new" do it "assigns @team to a new scoped instance of Team" do account.should_receive(:build_team) { team } get :new assigns(:team).should eq(team) end it "renders the new template" do get :new response.should render_template("new") end end end HTH, David From lists at ruby-forum.com Tue Sep 7 08:18:10 2010 From: lists at ruby-forum.com (Zhenning Guan) Date: Tue, 7 Sep 2010 14:18:10 +0200 Subject: [rspec-users] how to wrtie this test?(test true but change when refactor) In-Reply-To: <750FCD5D-9C23-4090-B2CE-AD09AE6A176F@gmail.com> References: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> <16BC1121-3843-4AE4-A768-4D0197449927@gmail.com> <20538ebf07a06d0a5f8175c34c2fc092@ruby-forum.com> <821CFB24-19EC-42EB-AF37-D8F9FA2980C5@gmail.com> <329067c65d08ede2486eac818d85020c@ruby-forum.com> <750FCD5D-9C23-4090-B2CE-AD09AE6A176F@gmail.com> Message-ID: <8a1b58b84924dd9ecb5fd450ad2cbe9c@ruby-forum.com> > In your original post you said you were getting two bankbook items after > the change. Do you want one or two? And where is the 2nd one coming > from? I always want one . after change the code I got two. and the original test doesn't fail. def process! #transaction block bank.withdraw bankbook = user.bank.bankbooks.build bankbook.withdraw #end end #change version def process! #transaction block bank.withdraw #end end so obviously, bankbook = user.bank.bankbooks.build create a bankbook record. and bank.withdraw jsut about decrease money. after change. bank.withdraw Model#withdraw the withdraw method will create bankbook record. so we just don't need create bankbook in process! but my test is @ning.bankbooks.last.price.should == BigDecimal('1.00') @ning.bankbooks.last.action.should == 'withdraw' it doesn't care how many bankbook record was created. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Sep 7 09:20:42 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Sep 2010 08:20:42 -0500 Subject: [rspec-users] how to wrtie this test?(test true but change when refactor) In-Reply-To: <8a1b58b84924dd9ecb5fd450ad2cbe9c@ruby-forum.com> References: <29abaada2387b78e9028dc1ae4c358ce@ruby-forum.com> <16BC1121-3843-4AE4-A768-4D0197449927@gmail.com> <20538ebf07a06d0a5f8175c34c2fc092@ruby-forum.com> <821CFB24-19EC-42EB-AF37-D8F9FA2980C5@gmail.com> <329067c65d08ede2486eac818d85020c@ruby-forum.com> <750FCD5D-9C23-4090-B2CE-AD09AE6A176F@gmail.com> <8a1b58b84924dd9ecb5fd450ad2cbe9c@ruby-forum.com> Message-ID: <2B028AF6-99D4-453B-9EBC-20DFB41B40C9@gmail.com> On Sep 7, 2010, at 7:18 AM, Zhenning Guan wrote: >> In your original post you said you were getting two bankbook items after >> the change. Do you want one or two? And where is the 2nd one coming >> from? > I always want one . after change the code I got two. and the original > test doesn't fail. > def process! > #transaction block > bank.withdraw > bankbook = user.bank.bankbooks.build > bankbook.withdraw > #end > end > > #change version > def process! > #transaction block > bank.withdraw > #end > end > > so obviously, bankbook = user.bank.bankbooks.build create a bankbook > record. and bank.withdraw jsut about decrease money. > after change. bank.withdraw Model#withdraw the withdraw method will > create bankbook record. so we just don't need create bankbook in > process! but my test is > @ning.bankbooks.last.price.should == BigDecimal('1.00') > @ning.bankbooks.last.action.should == 'withdraw' > it doesn't care how many bankbook record was created. So are you asking how to specify that only one record gets created? If so, your suggestion a few posts back is good: lambda{ withdrawal.process! }.should change {Bankbook.count}.by(1) HTH, David From brennon at brennonbortz.com Wed Sep 8 11:20:48 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Wed, 8 Sep 2010 16:20:48 +0100 Subject: [rspec-users] Testing views of nested resources Message-ID: I've searched and searched, and just can't find an answer on the list or elsewhere. Forgive me if I'm missing something... I've got the following bits of code: ### app/controllers/widget_layouts_controller.rb: class WidgetLayoutsController < ApplicationController def new @widget = Widget.find(params[:widget_id]) @widget_layout = WidgetLayout.new end end ### app/models/widget_layout.rb: class WidgetLayout < ActiveRecord::Base belongs_to :widget end ### app/models/widget.rb: class Widget < ActiveRecord::Base has_one :widget_layout, :dependent => :destroy end ### From config/routes.rb: resources :widgets do resource :widget_layout end ### spec/widget_layouts/new.html_spec.rb: require "spec_helper" describe "widget_layouts/new.html.erb" do it "should render the new widget layout form" do widget = stub_model(Widget) assign(params[:widget_id], widget) render rendered.should have_selector("form", :method => "post", :action => widget_widget_layout_path(widget)) end end ### app/views/widget_layouts/new.html.erb <%= form_for @widget_layout, :url => widget_widget_layout_path(@widget) do |f| %> <%= f.submit "Submit Widget Layout Information" %> <% end %> Here's the error I get when running that spec: widget_layouts/new.html.erb should render the new widget layout form (FAILED - 1) Failures: 1) widget_layouts/new.html.erb should render the new widget layout form Failure/Error: render No route matches {:controller=>"widget_layouts", :action=>"destroy"} # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:398:in `generate' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:450:in `generate' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:478:in `url_for' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/url_for.rb:132:in `url_for' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/helpers/url_helper.rb:99:in `url_for' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:195:in `widget_widget_layout_path' # ./app/views/widget_layouts/new.html.erb:1:in `_app_views_widget_layouts_new_html_erb___4529585855698402853_2170042420_599441616533773267' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/template.rb:135:in `block in render' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications.rb:52:in `block in instrument' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications/instrumenter.rb:21:in `instrument' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications.rb:52:in `instrument' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/template.rb:127:in `render' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/render/rendering.rb:59:in `block in _render_template' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications.rb:52:in `block in instrument' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications/instrumenter.rb:21:in `instrument' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications.rb:52:in `instrument' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/render/rendering.rb:56:in `_render_template' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/render/rendering.rb:26:in `render' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/test_case.rb:103:in `render' # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/rspec-rails-2.0.0.beta.20/lib/rspec/rails/example/view_example_group.rb:70:in `render' # ./spec/views/widget_layouts/new.html_spec.rb:7:in `block (2 levels) in ' I believe this is because params[:widget_id] isn't assigned when I'm rendering new.html.erb. I know that's an improper usage of #assign up there, but this is what I was trying to rectify (obviously incorrectly...) I'm confused as to how to mock/stub and specify parent resource(s) when trying to test views of children resources. What should I be doing differently? Also--not an RSpec question--that's the only way I can get that #form_for call to work correctly. Everywhere I looked, it seemed that I could simply use: form_for [@widget, @widget_layout] do |f| %> but alas, all I get is the following errors: _______________________ NoMethodError in Widget_layouts#new Showing /Users/brennon/Documents/Programming/checkouts/rails_projects/stan/app/views/widget_layouts/new.html.erb where line #1 raised: undefined method `widget_widget_layouts_path' for #<#:0x00000102c3fa48> Extracted source (around line #1): 1: <%= form_for [@widget, @widget_layout] do |f| %> 2: <%= f.submit "Submit Widget Layout Information" %> 3: <% end %> ________________________ Any chance I might get some help on this one while I'm at it? :) Many thanks, Brennon Bortz Software Researcher Dundalk Institute of Technology brennon.bortz at casala.ie Ph.D. Researcher & Composer - Sonic Arts Research Centre Queen's University, Belfast brennon at brennonbortz.com / bbortz01 at qub.ac.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From brennon at brennonbortz.com Wed Sep 8 11:39:18 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Wed, 8 Sep 2010 16:39:18 +0100 Subject: [rspec-users] Testing views of nested resources In-Reply-To: References: Message-ID: <11F44F77-FBAA-4942-B208-F5BF800CA9E0@brennonbortz.com> On 8 Sep 2010, at 16:20, Brennon Bortz wrote: > I've searched and searched, and just can't find an answer on the list or elsewhere. Forgive me if I'm missing something... > > I've got the following bits of code: > > ### app/controllers/widget_layouts_controller.rb: > class WidgetLayoutsController < ApplicationController > def new > @widget = Widget.find(params[:widget_id]) > @widget_layout = WidgetLayout.new > end > end > > ### app/models/widget_layout.rb: > class WidgetLayout < ActiveRecord::Base > belongs_to :widget > end > > ### app/models/widget.rb: > class Widget < ActiveRecord::Base > has_one :widget_layout, :dependent => :destroy > end > > ### From config/routes.rb: > resources :widgets do > resource :widget_layout > end > > ### spec/widget_layouts/new.html_spec.rb: > require "spec_helper" > > describe "widget_layouts/new.html.erb" do > it "should render the new widget layout form" do > widget = stub_model(Widget) > assign(params[:widget_id], widget) > render > rendered.should have_selector("form", :method => "post", :action => widget_widget_layout_path(widget)) > end > end > > ### app/views/widget_layouts/new.html.erb > <%= form_for @widget_layout, :url => widget_widget_layout_path(@widget) do |f| %> > <%= f.submit "Submit Widget Layout Information" %> > <% end %> > > Here's the error I get when running that spec: > > widget_layouts/new.html.erb > should render the new widget layout form (FAILED - 1) > > Failures: > 1) widget_layouts/new.html.erb should render the new widget layout form > Failure/Error: render > No route matches {:controller=>"widget_layouts", :action=>"destroy"} > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:398:in `generate' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:450:in `generate' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:478:in `url_for' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/url_for.rb:132:in `url_for' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/helpers/url_helper.rb:99:in `url_for' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:195:in `widget_widget_layout_path' > # ./app/views/widget_layouts/new.html.erb:1:in `_app_views_widget_layouts_new_html_erb___4529585855698402853_2170042420_599441616533773267' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/template.rb:135:in `block in render' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications.rb:52:in `block in instrument' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications/instrumenter.rb:21:in `instrument' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications.rb:52:in `instrument' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/template.rb:127:in `render' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/render/rendering.rb:59:in `block in _render_template' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications.rb:52:in `block in instrument' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications/instrumenter.rb:21:in `instrument' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/activesupport-3.0.0.rc/lib/active_support/notifications.rb:52:in `instrument' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/render/rendering.rb:56:in `_render_template' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/render/rendering.rb:26:in `render' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/actionpack-3.0.0.rc/lib/action_view/test_case.rb:103:in `render' > # /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/rspec-rails-2.0.0.beta.20/lib/rspec/rails/example/view_example_group.rb:70:in `render' > # ./spec/views/widget_layouts/new.html_spec.rb:7:in `block (2 levels) in ' > > I believe this is because params[:widget_id] isn't assigned when I'm rendering new.html.erb. I know that's an improper usage of #assign up there, but this is what I was trying to rectify (obviously incorrectly...) I'm confused as to how to mock/stub and specify parent resource(s) when trying to test views of children resources. What should I be doing differently? > > Also--not an RSpec question--that's the only way I can get that #form_for call to work correctly. Everywhere I looked, it seemed that I could simply use: > > form_for [@widget, @widget_layout] do |f| %> > > but alas, all I get is the following errors: > _______________________ > NoMethodError in Widget_layouts#new > Showing /Users/brennon/Documents/Programming/checkouts/rails_projects/stan/app/views/widget_layouts/new.html.erb where line #1 raised: > > undefined method `widget_widget_layouts_path' for #<#:0x00000102c3fa48> > Extracted source (around line #1): > 1: <%= form_for [@widget, @widget_layout] do |f| %> > 2: <%= f.submit "Submit Widget Layout Information" %> > 3: <% end %> > ________________________ > Any chance I might get some help on this one while I'm at it? :) Well, that was certainly a stupid mistake...figured it out with this: it "should render the new widget layout form" do widget = stub_model(Widget, :id => "1") assign(:widget, widget) params[:widget_id] = widget.id assign(:widget_layout, mock_model(WidgetLayout).as_null_object) render rendered.should have_selector("form", :method => "post", :action => widget_widget_layout_path(widget)) end Now, can anyone provide some insight on a more elegant #form_for call for me? Thanks again, Brennon -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian at vermonster.com Wed Sep 8 13:42:28 2010 From: brian at vermonster.com (Brian Kaney) Date: Wed, 8 Sep 2010 13:42:28 -0400 Subject: [rspec-users] Re-using Rspec Matchers Message-ID: <49FCFC55-583B-45C2-911C-D850BBC178F6@vermonster.com> Hey Everyone, Is it good practice to call matchers from within matchers? Kinda like this pattern: See: http://gist.github.com/570467 -- Brian From me at jbrains.ca Wed Sep 8 14:17:52 2010 From: me at jbrains.ca (J. B. Rainsberger) Date: Wed, 8 Sep 2010 15:17:52 -0300 Subject: [rspec-users] Re-using Rspec Matchers In-Reply-To: <49FCFC55-583B-45C2-911C-D850BBC178F6@vermonster.com> References: <49FCFC55-583B-45C2-911C-D850BBC178F6@vermonster.com> Message-ID: On Wed, Sep 8, 2010 at 14:42, Brian Kaney wrote: > Is it good practice to call matchers from within matchers? ? Kinda like this pattern: > > ?See: http://gist.github.com/570467 David Chelimsky taught me not to invoke #should in a matcher, but rather just answer a boolean, so I expect that, rather than matcher using matcher, you could extract the low-level matcher behavior into methods that both matchers would use. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From brian at vermonster.com Wed Sep 8 18:19:56 2010 From: brian at vermonster.com (Brian Kaney) Date: Wed, 8 Sep 2010 18:19:56 -0400 Subject: [rspec-users] Re-using Rspec Matchers In-Reply-To: References: <49FCFC55-583B-45C2-911C-D850BBC178F6@vermonster.com> Message-ID: <70BBEB61-11FD-47D7-BB14-AAFB75ACA1ED@vermonster.com> On Sep 8, 2010, at 2:17 PM, "J. B. Rainsberger" wrote: > On Wed, Sep 8, 2010 at 14:42, Brian Kaney wrote: > >> Is it good practice to call matchers from within matchers? Kinda like this pattern: >> >> See: http://gist.github.com/570467 > > David Chelimsky taught me not to invoke #should in a matcher, but > rather just answer a boolean, so I expect that, rather than matcher > using matcher, you could extract the low-level matcher behavior into > methods that both matchers would use. > Okay thanks. I'll refractor matcher logic but was hoping I could be lazy and reuse / cascade failure messages. -- Brian From dchelimsky at gmail.com Wed Sep 8 18:25:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Sep 2010 17:25:46 -0500 Subject: [rspec-users] Re-using Rspec Matchers In-Reply-To: <70BBEB61-11FD-47D7-BB14-AAFB75ACA1ED@vermonster.com> References: <49FCFC55-583B-45C2-911C-D850BBC178F6@vermonster.com> <70BBEB61-11FD-47D7-BB14-AAFB75ACA1ED@vermonster.com> Message-ID: On Sep 8, 2010, at 5:19 PM, Brian Kaney wrote: > On Sep 8, 2010, at 2:17 PM, "J. B. Rainsberger" wrote: > >> On Wed, Sep 8, 2010 at 14:42, Brian Kaney wrote: >> >>> Is it good practice to call matchers from within matchers? Kinda like this pattern: >>> >>> See: http://gist.github.com/570467 >> >> David Chelimsky taught me not to invoke #should in a matcher, but >> rather just answer a boolean, so I expect that, rather than matcher >> using matcher, you could extract the low-level matcher behavior into >> methods that both matchers would use. >> > > Okay thanks. > > I'll refractor matcher logic but was hoping I could be lazy and reuse / cascade failure messages. You can :) The reason to avoid cascading matchers is they become somewhat useless in the negative form (should_not). If you're NEVER going to use them that way, you're fine cascading. From ben at benmabey.com Wed Sep 8 17:26:41 2010 From: ben at benmabey.com (Ben Mabey) Date: Wed, 08 Sep 2010 15:26:41 -0600 Subject: [rspec-users] Re-using Rspec Matchers In-Reply-To: <49FCFC55-583B-45C2-911C-D850BBC178F6@vermonster.com> References: <49FCFC55-583B-45C2-911C-D850BBC178F6@vermonster.com> Message-ID: <4C87FF91.4040907@benmabey.com> On 9/8/10 11:42 AM, Brian Kaney wrote: > Hey Everyone, > > Is it good practice to call matchers from within matchers? Kinda like this pattern: > > See: http://gist.github.com/570467 > No, that should be avoided. The problem is that the "internal" matcher will throw an exception that will bubble up and be reported. Meaning that the parent matcher (link_one in your case) is not reported and the resulting stacktrace can be confusing. Try something like this: include_association(expected).matches?(actual) && associate_one(expected).matches?(actual) (Note, I have not tried the above but I think it should work.) -Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Sep 12 22:24:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Sep 2010 21:24:05 -0500 Subject: [rspec-users] rspec-2.0.0.beta.22 has been released! Message-ID: <5FD3197B-A9DA-42FA-86A3-BF08257946FF@gmail.com> rspec-2.0.0.beta.22 has been released! We're getting very close to a 2.0 release candidate, so if you're not already using rspec-2 (with or without rails-3), now is the time to start. I need your feedback, so from here on in I'll be sending out announcements and release notes for each beta release. As for rspec-2 with rails-2, there are a few efforts underway to make that work, but that will be in the form of a separate gem and our priority is getting rspec-2 out the door. Please report issues or submit pull requests (yes, pull requests are fine now that github has integrated them so well with issues) to the appropriate repos: http://github.com/rspec/rspec-core/issues http://github.com/rspec/rspec-expectations/issues http://github.com/rspec/rspec-mocks/issues http://github.com/rspec/rspec-rails/issues Below are release notes for each gem in this beta release, drawn from the nascent History.md files in each project. Thanks, and enjoy! David and the RSpec Development Team ================================== rspec-core-2.0.0.beta.22 / 2010-09-12 full changelog: http://github.com/rspec/rspec-core/compare/v2.0.0.beta.20...v2.0.0.beta.22 ? Enhancements ? removed at_exit hook ? CTRL-C stops the run (almost) immediately ? first it cleans things up by running the appropriate after(:all) and after(:suite) hooks ? then it reports on any examples that have already run ? cleaned up rake task ? generate correct task under variety of conditions ? options are more consistent ? deprecated redundant options ? run 'bundle exec autotest' when Gemfile is present ? support ERB in .rspec options files (Justin Ko) ? depend on bundler for development tasks (Myron Marsten) ? add example_group_finished to formatters and reporter (Roman Chernyatchik) ? Bug fixes ? support paths with spaces when using autotest (Andreas Neuhaus) ? fix module_exec with ruby 1.8.6 (Myron Marsten) ? remove context method from top-level ? was conflicting with irb, for example ? errors in before(:all) are now reported correctly (Chad Humphries) ? Removals ? removed -o --options-file command line option ? use ./.rspec and ~/.rspec ================================== rspec-expectations-2.0.0.beta.22 / 2010-09-12 full changelog: http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.20...v2.0.0.beta.22 ? Enhancements ? diffing improvements ? diff multiline strings ? don't diff single line strings ? don't diff numbers (silly) ? diff regexp + multiline string ? Bug fixes ? should[_not] change now handles boolean values correctly ================================== rspec-mocks-2.0.0.beta.22 / 2010-09-12 full changelog: http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.20...v2.0.0.beta.22 ? Bug fixes ? fixed regression that broke obj.stub_chain(:a, :b => :c) ? fixed regression that broke obj.stub_chain(:a, :b) { :c } ? respond_to? always returns true when using as_null_object ================================== 2.0.0.beta.22 / 2010-09-12 full changelog: http://github.com/rspec/rspec-rails/compare/v2.0.0.beta.20...v2.0.0.beta.22 ? Enhancements ? autotest mapping improvements (Andreas Neuhaus) ? Bug fixes ? delegate flunk to assertion delegate ================================== From nathanvda at gmail.com Mon Sep 13 03:49:15 2010 From: nathanvda at gmail.com (nathanvda) Date: Mon, 13 Sep 2010 00:49:15 -0700 (PDT) Subject: [rspec-users] rails3: in production i get uninitialised constant rspec? Message-ID: I am trying to deploy my rails3 application in a production environment. But when i run my first rake task: RAILS_ENV=production rake db:setup i always get the following result: rake aborted! uninitialized constant RSpec and then points to the line in the Rakefile where it says MyApp::Application.load_tasks I do not have any lib/tasks referring to rspec; my gemfile does not refer to any rspec or test gem in production. Has anybody else encountered this? (i have upgraded to beta.22, but encountered it with beta.20 first) From nathanvda at gmail.com Mon Sep 13 03:58:16 2010 From: nathanvda at gmail.com (nathanvda) Date: Mon, 13 Sep 2010 00:58:16 -0700 (PDT) Subject: [rspec-users] rails3: in production i get uninitialised constant rspec? In-Reply-To: References: Message-ID: <954033bc-2d9a-4e42-90c5-ca82ad30b345@k13g2000vbq.googlegroups.com> Whoops. Found it! I have a rcov.rake inside my lib/tasks like this: desc "Run all specs with rcov" RSpec::Core::RakeTask.new("test_cov") do |t| t.rcov = true t.rcov_opts = %w{--rails --include views --exclude gems\/,spec \/,features\/,seeds\/} end Now i am looking for a clean way to disable this task in production environment. Any hints? On Sep 13, 9:49?am, nathanvda wrote: > I am trying to deploy my rails3 application in a production > environment. But when i run my first rake task: > > ? ? RAILS_ENV=production rake db:setup > > i always get the following result: > > ? ? rake aborted! > ? ? uninitialized constant RSpec > > and then points to the line in the Rakefile where it says > > ? ? MyApp::Application.load_tasks > > I do not have any lib/tasks referring to rspec; my gemfile does not > refer to any rspec or test gem in production. > Has anybody else encountered this? > > (i have upgraded to beta.22, but encountered it with beta.20 first) > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jko170 at gmail.com Mon Sep 13 04:01:01 2010 From: jko170 at gmail.com (Justin Ko) Date: Mon, 13 Sep 2010 01:01:01 -0700 (PDT) Subject: [rspec-users] rails3: in production i get uninitialised constant rspec? In-Reply-To: <954033bc-2d9a-4e42-90c5-ca82ad30b345@k13g2000vbq.googlegroups.com> References: <954033bc-2d9a-4e42-90c5-ca82ad30b345@k13g2000vbq.googlegroups.com> Message-ID: On Sep 13, 3:58?am, nathanvda wrote: > Whoops. Found it! I have a rcov.rake inside my lib/tasks like this: > > desc ?"Run all specs with rcov" > RSpec::Core::RakeTask.new("test_cov") do |t| > ? t.rcov = true > ? t.rcov_opts = %w{--rails --include views --exclude gems\/,spec > \/,features\/,seeds\/} > end > > Now i am looking for a clean way to disable this task in production > environment. > Any hints? > > On Sep 13, 9:49?am, nathanvda wrote: > > > > > I am trying to deploy my rails3 application in a production > > environment. But when i run my first rake task: > > > ? ? RAILS_ENV=production rake db:setup > > > i always get the following result: > > > ? ? rake aborted! > > ? ? uninitialized constant RSpec > > > and then points to the line in the Rakefile where it says > > > ? ? MyApp::Application.load_tasks > > > I do not have any lib/tasks referring to rspec; my gemfile does not > > refer to any rspec or test gem in production. > > Has anybody else encountered this? > > > (i have upgraded to beta.22, but encountered it with beta.20 first) > > _______________________________________________ > > 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 unless Rails.env.production? # non-production code end From myron.marston at gmail.com Mon Sep 13 10:51:07 2010 From: myron.marston at gmail.com (Myron Marston) Date: Mon, 13 Sep 2010 07:51:07 -0700 (PDT) Subject: [rspec-users] rails3: in production i get uninitialised constant rspec? In-Reply-To: References: <954033bc-2d9a-4e42-90c5-ca82ad30b345@k13g2000vbq.googlegroups.com> Message-ID: <1e560cba-45c8-4e2b-adae-c642229bc9a5@m35g2000prn.googlegroups.com> On Sep 13, 1:01?am, Justin Ko wrote: > On Sep 13, 3:58?am, nathanvda wrote: > > > > > > > Whoops. Found it! I have a rcov.rake inside my lib/tasks like this: > > > desc ?"Run all specs with rcov" > > RSpec::Core::RakeTask.new("test_cov") do |t| > > ? t.rcov = true > > ? t.rcov_opts = %w{--rails --include views --exclude gems\/,spec > > \/,features\/,seeds\/} > > end > > > Now i am looking for a clean way to disable this task in production > > environment. > > Any hints? > > > On Sep 13, 9:49?am, nathanvda wrote: > > > > I am trying to deploy my rails3 application in a production > > > environment. But when i run my first rake task: > > > > ? ? RAILS_ENV=production rake db:setup > > > > i always get the following result: > > > > ? ? rake aborted! > > > ? ? uninitialized constant RSpec > > > > and then points to the line in the Rakefile where it says > > > > ? ? MyApp::Application.load_tasks > > > > I do not have any lib/tasks referring to rspec; my gemfile does not > > > refer to any rspec or test gem in production. > > > Has anybody else encountered this? > > > > (i have upgraded to beta.22, but encountered it with beta.20 first) > > > _______________________________________________ > > > 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 > > unless Rails.env.production? > ? # non-production code > end > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users if defined?(RSpec) desc "Run all specs with rcov" RSpec::Core::RakeTask.new("test_cov") do |t| t.rcov = true t.rcov_opts = %w{--rails --include views --exclude gems\/,spec \/,features\/,seeds\/} end end From jon at blankpad.net Mon Sep 13 13:15:13 2010 From: jon at blankpad.net (Jon Wood) Date: Mon, 13 Sep 2010 18:15:13 +0100 Subject: [rspec-users] [Rails] Unexpected calls to *_before_type_cast in view specs Message-ID: Good evening, I'm having some issues with the view specs on a project newly upgraded from rspec-rails-1.2.x to rspec-rails-1.3.2, and also having had a Rails upgrade from 2.3.5 to 2.3.9 done at the same time. My view specs are now failing with messages like the one at the bottom of this message. I've had a dig around the source, but not been able to find anything that seems particularly useful. Is this an issue that other people have seen, and if so, is anyone able to suggest a solution? Cheers, Jon Wood ActionView::TemplateError in '/judging_lists/edit.html.erb should render' unexpected invocation: #.comments_before_type_cast() satisfied expectations: - allowed any number of times, already invoked 11 times: Time.now(any_parameters) - allowed any number of times, not yet invoked: Time.now(any_parameters) - allowed any number of times, not yet invoked: Time.now(any_parameters) [... etc ...] On line #185 of app/views/judging_lists/edit.html.erb 182: 183:
184:

Judge's Comments

185: <%= f.text_area(:comments) %> 186:
187: 188:
app/views/judging_lists/edit.html.erb:185 app/views/judging_lists/edit.html.erb:137 /Users/jon/.rvm/gems/ruby-1.8.7-p302 at project_name/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action_view/base.rb:27:in `render' /Users/jon/.rvm/gems/ruby-1.8.7-p302 at project_name/gems/rspec-rails-1.3.2/lib/spec/rails/example/view_example_group.rb:170:in `__send__' /Users/jon/.rvm/gems/ruby-1.8.7-p302 at project_name/gems/rspec-rails-1.3.2/lib/spec/rails/example/view_example_group.rb:170:in `render' /spec/views/judging_lists/edit.html.erb_spec.rb:19:in `do_render' /spec/views/judging_lists/edit.html.erb_spec.rb:25 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' /Users/jon/.rvm/rubies/ruby-1.8.7-p302/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 From nicholas.henry at gmail.com Mon Sep 13 17:14:29 2010 From: nicholas.henry at gmail.com (Nicholas Henry) Date: Mon, 13 Sep 2010 14:14:29 -0700 (PDT) Subject: [rspec-users] [BDD] NoMethodError raised when calling #stub with incorrect parameters Message-ID: <03c0bc69-1067-4f6a-914d-f1b5a54f3a21@j2g2000vbo.googlegroups.com> I'm new to RSpec and came across an interesting situation where calling a stubbed method with different parameters from those specified, raises a misleading error. Some code to illustrate: (rspec 1.3.0) describe Person do describe "#greeting" do context "using #stub with correct parameters" do before(:each) do subject.stub(:greeting).with("Nicholas") end specify { lambda{ subject.greeting("Nicholas") }.should_not raise_error(NoMethodError) } end context "using #stub with incorrect parameters" do before(:each) do subject.stub(:greeting).with("incorrect parameter") end specify { lambda{ subject.greeting("Nicholas") }.should raise_error(NoMethodError) } end end end I know this is not a test you would have in reality, but it illustrates the behaviour. I also have come to the realization that you should never specify parameters when using the stub command, you should only use #with on #should_receive. However, when you have mistakenly done this (like the newbie I am), tracking down the issue can be a bit painful due to the misleading exception raised. Should developers be protected against using #with on #stub, a better exception such as Spec::Mocks::MockExpectationError, or am I missing something? I would appreciate hearing you thoughts. Thank you, Nicholas From autiger02 at gmail.com Thu Sep 9 13:46:57 2010 From: autiger02 at gmail.com (Lee Smith) Date: Thu, 9 Sep 2010 10:46:57 -0700 (PDT) Subject: [rspec-users] rspec-rails setup in Rails 3 Message-ID: <1b5572a0-b58d-4460-9290-b9d14c286e8e@q9g2000vbd.googlegroups.com> I'm missing something in my setup of rspec-rails in a rails 3 project. I've included the link to the gist. It seems that it doesn't recognize rails routes for some reason...getting "undefined local variable or method". The spec file I'm running is sitting in spec/integration, if that matters. Thanks for any help. http://gist.github.com/572213 ruby 1.9.2p0 rails 3.0.0 rspec-rails 2.0.0.beta.20 From tyanat.syadan.bekrob at gmail.com Tue Sep 7 23:35:08 2010 From: tyanat.syadan.bekrob at gmail.com (Takumi Tsunokake) Date: Tue, 7 Sep 2010 20:35:08 -0700 (PDT) Subject: [rspec-users] May expect { ... }.to_not be changed to expect { ... }.not_to? Message-ID: <999ec96b-3433-4944-a011-d3805bfd808a@u31g2000pru.googlegroups.com> Hi, I'm Takumi Tsunokake. I think expect { ... }.not_to rails_error is more grammatical and natural than expect { ... }.to_not rails_error Are there any backgrounds and reasons of decision for expect { ... }.to_not, not expect { ... }.not_to? I'm happy if expect { ... }.to_not is changed to expect { ... }.not_to. Best Regards :) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Takumi Tsunokake http://d.hatena.ne.jp/bekkou68/ @bekkou68 From kyle.e.crum at gmail.com Wed Sep 8 08:18:52 2010 From: kyle.e.crum at gmail.com (Kyle) Date: Wed, 8 Sep 2010 05:18:52 -0700 (PDT) Subject: [rspec-users] Rspec tasks with rspec-rails 2.0 Message-ID: <3d723c6c-17f9-4744-a323-a2f8547952b8@x24g2000pro.googlegroups.com> After updating to Rails 3 and Rspec-rails 2.0, the tasks defined in rspec.rake do not work anymore. I instead get this, even when running the rake tasks via 'bundle exec': * You are trying to run an rspec rake task defined in * /Users/bessieandkyle/code/listsite/lib/tasks/rspec.rake, * but rspec can not be found in vendor/gems, vendor/plugins or system gems. Is there a new way to do this with rspec-rails 2.0 or did I just miss something (highly likely). Thanks! From lowellk at gmail.com Thu Sep 9 17:52:02 2010 From: lowellk at gmail.com (Lowell) Date: Thu, 9 Sep 2010 14:52:02 -0700 (PDT) Subject: [rspec-users] In rails 3 and rspec 2, how can I test the layout used by a call to render() ? Message-ID: I'm trying to test that a view was rendered with a given layout. How can I test which layout was used for the call to render() ? The call that I want to test looks like this: render :some_view, :layout => 'some_layout' Thanks! Lowell From nemesisdesign at gmail.com Mon Sep 13 18:30:39 2010 From: nemesisdesign at gmail.com (Michael Xavier) Date: Mon, 13 Sep 2010 15:30:39 -0700 (PDT) Subject: [rspec-users] Incorrect wrong number of arguments exception when stubbing find Message-ID: I'm working with a subclass of ActiveResource and I came across this oddity when trying to stub its find method. Occurring with rspec 1.3.0: The spec code looks like: [1,2].each {|id| Hive::CategoryResource.should_receive(:find).with(id).and_raise(ActiveResource::ResourceNotFound)} Hive::CategoryResource.should_receive(:find).with(3).and_return(gg_parent) -------------------------------------- The code being called looks like return Hive::CategoryResource.find(c.hive_category_id).default_weight -------------------------------------- And the exception looks like: wrong number of arguments (0 for 1) /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ mocks/message_expectation.rb:113:in `initialize' /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ mocks/message_expectation.rb:113:in `exception' /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ mocks/message_expectation.rb:113:in `raise' /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ mocks/message_expectation.rb:113:in `invoke' /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ mocks/proxy.rb:127:in `invoke_expectation' /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ mocks/proxy.rb:111:in `message_received' /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ mocks/proxy.rb:177:in `find' /home/michael/Scripts/admin/app/models/category.rb:392:in `closest_default_weight' /home/michael/Scripts/admin/app/models/category.rb:389:in `each' /home/michael/Scripts/admin/app/models/category.rb:389:in `closest_default_weight' ./spec/models/category_spec.rb:209 -------------------------------------- I was hoping someone could help me figure out what's going on here. It's making an area of my code particularly hard to test From nicolas.braem at gmail.com Mon Sep 13 18:32:31 2010 From: nicolas.braem at gmail.com (nicolas) Date: Mon, 13 Sep 2010 15:32:31 -0700 (PDT) Subject: [rspec-users] passing a block to a stub method Message-ID: It seems that rspec doesn't support passing a block to a stub method. This code fails: def call_build_with_block(o) o.build do puts "hello" end end describe "call_build_with_block" do it "should call build with block" do o = double("object") o.should_receive(:build) do |&b| b.should_not be_nil block_given?.should == true end call_build_with_block(o) end end Anybody? From jko170 at gmail.com Mon Sep 13 22:08:44 2010 From: jko170 at gmail.com (Justin Ko) Date: Mon, 13 Sep 2010 19:08:44 -0700 (PDT) Subject: [rspec-users] rspec-rails setup in Rails 3 In-Reply-To: <1b5572a0-b58d-4460-9290-b9d14c286e8e@q9g2000vbd.googlegroups.com> References: <1b5572a0-b58d-4460-9290-b9d14c286e8e@q9g2000vbd.googlegroups.com> Message-ID: <0bb07338-c106-44ad-a1e0-8349ce056bcc@t7g2000vbj.googlegroups.com> Hello, It looks like you started your integration spec with "context". Try starting it (top level) with "describe". Think of context as "setting the context for what you are describing". Let us know if that fixes it. On Sep 9, 1:46?pm, Lee Smith wrote: > I'm missing something in my setup of rspec-rails in a rails 3 > project. ?I've included the link to the gist. ?It seems that it > doesn't recognize rails routes for some reason...getting "undefined > local variable or method". ?The spec file I'm running is sitting in > spec/integration, if that matters. ?Thanks for any help. > > http://gist.github.com/572213 > > ruby 1.9.2p0 > rails 3.0.0 > rspec-rails 2.0.0.beta.20 > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Sep 13 22:13:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Sep 2010 21:13:45 -0500 Subject: [rspec-users] May expect { ... }.to_not be changed to expect { ... }.not_to? In-Reply-To: <999ec96b-3433-4944-a011-d3805bfd808a@u31g2000pru.googlegroups.com> References: <999ec96b-3433-4944-a011-d3805bfd808a@u31g2000pru.googlegroups.com> Message-ID: On Sep 7, 2010, at 10:35 PM, Takumi Tsunokake wrote: > Hi, I'm Takumi Tsunokake. > > I think > expect { ... }.not_to rails_error > is more grammatical and natural than > expect { ... }.to_not rails_error I think you mean raise_error (I've made the same mistake a few times). I'm pretty sure they're equally valid, grammatically speaking: Expect x not to y Expect x to not y > Are there any backgrounds and reasons of decision for expect > { ... }.to_not, not expect { ... }.not_to? > > I'm happy if expect { ... }.to_not is changed to expect > { ... }.not_to. It's because it aligns better with should[_not]. I think it would be more confusing if we had [not_]to and [should_]not. HTH, David From dchelimsky at gmail.com Mon Sep 13 22:18:18 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Sep 2010 21:18:18 -0500 Subject: [rspec-users] Incorrect wrong number of arguments exception when stubbing find In-Reply-To: References: Message-ID: <8C51A116-9178-47AB-BD2B-447994CE2E58@gmail.com> On Sep 13, 2010, at 5:30 PM, Michael Xavier wrote: > I'm working with a subclass of ActiveResource and I came across this > oddity when trying to stub its find method. Occurring with rspec > 1.3.0: > > The spec code looks like: > > [1,2].each {|id| > Hive::CategoryResource.should_receive(:find).with(id).and_raise(ActiveResource::ResourceNotFound)} ActiveResource::ResourceNotFound.new requires arguments, so you have to pass in an instance instead. http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Mocks/BaseExpectation.html#M000072 Maybe we just need a better error message. HTH, David > Hive::CategoryResource.should_receive(:find).with(3).and_return(gg_parent) > -------------------------------------- > > The code being called looks like > > return Hive::CategoryResource.find(c.hive_category_id).default_weight > > -------------------------------------- > > And the exception looks like: > > wrong number of arguments (0 for 1) > > /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ > mocks/message_expectation.rb:113:in `initialize' > /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ > mocks/message_expectation.rb:113:in `exception' > /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ > mocks/message_expectation.rb:113:in `raise' > /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ > mocks/message_expectation.rb:113:in `invoke' > /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ > mocks/proxy.rb:127:in `invoke_expectation' > /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ > mocks/proxy.rb:111:in `message_received' > /home/michael/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/ > mocks/proxy.rb:177:in `find' > /home/michael/Scripts/admin/app/models/category.rb:392:in > `closest_default_weight' > /home/michael/Scripts/admin/app/models/category.rb:389:in `each' > /home/michael/Scripts/admin/app/models/category.rb:389:in > `closest_default_weight' > ./spec/models/category_spec.rb:209 > > -------------------------------------- > > I was hoping someone could help me figure out what's going on here. > It's making an area of my code particularly hard to test From dchelimsky at gmail.com Mon Sep 13 22:21:22 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Sep 2010 21:21:22 -0500 Subject: [rspec-users] Rspec tasks with rspec-rails 2.0 In-Reply-To: <3d723c6c-17f9-4744-a323-a2f8547952b8@x24g2000pro.googlegroups.com> References: <3d723c6c-17f9-4744-a323-a2f8547952b8@x24g2000pro.googlegroups.com> Message-ID: <8FDEC106-1CA7-4997-8164-09AE194C1B0F@gmail.com> On Sep 8, 2010, at 7:18 AM, Kyle wrote: > After updating to Rails 3 and Rspec-rails 2.0, the tasks defined in > rspec.rake Delete it. rspec-rails-2 keeps the rake tasks in a file in the gem. HTH, David > do not work anymore. I instead get this, even when running > the rake tasks via 'bundle exec': > > * You are trying to run an rspec rake task defined in > * /Users/bessieandkyle/code/listsite/lib/tasks/rspec.rake, > * but rspec can not be found in vendor/gems, vendor/plugins or system > gems. > > Is there a new way to do this with rspec-rails 2.0 or did I just miss > something (highly likely). > > Thanks! From dchelimsky at gmail.com Mon Sep 13 22:23:30 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Sep 2010 21:23:30 -0500 Subject: [rspec-users] In rails 3 and rspec 2, how can I test the layout used by a call to render() ? In-Reply-To: References: Message-ID: On Sep 9, 2010, at 4:52 PM, Lowell wrote: > I'm trying to test that a view was rendered with a given layout. How > can I test which layout was used for the call to render() ? > > The call that I want to test looks like this: > > render :some_view, :layout => 'some_layout' response.should render_template("layouts/some_layout") From dchelimsky at gmail.com Mon Sep 13 22:31:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Sep 2010 21:31:56 -0500 Subject: [rspec-users] passing a block to a stub method In-Reply-To: References: Message-ID: <79CE5E59-772F-4498-89E3-1982F43C6DF1@gmail.com> On Sep 13, 2010, at 5:32 PM, nicolas wrote: > It seems that rspec doesn't support passing a block to a stub method. > This code fails: > > def call_build_with_block(o) > o.build do > puts "hello" > end > end > > > describe "call_build_with_block" do > it "should call build with block" do > o = double("object") > o.should_receive(:build) do |&b| > b.should_not be_nil > block_given?.should == true > end > > call_build_with_block(o) > end > end > > Anybody? Bug. Please file a bug report at http://github.com/rspec/rspec-mocks/issues. Thx, David From jko170 at gmail.com Mon Sep 13 22:38:02 2010 From: jko170 at gmail.com (Justin Ko) Date: Mon, 13 Sep 2010 19:38:02 -0700 (PDT) Subject: [rspec-users] passing a block to a stub method In-Reply-To: References: Message-ID: On Sep 13, 6:32?pm, nicolas wrote: > It seems that rspec doesn't support passing a block to a stub method. > This code fails: > > def call_build_with_block(o) > ? o.build do > ? ? puts "hello" > ? end > end > > describe "call_build_with_block" do > ? it "should call build with block" do > ? ? o = double("object") > ? ? o.should_receive(:build) do |&b| > ? ? ? b.should_not be_nil > ? ? ? block_given?.should == true > ? ? end > > ? ? call_build_with_block(o) > ? end > end > > Anybody? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users What you can use is the "and_yield" method: o.should_receive(:build).and_yield do |eval_context| eval_context.should_not be_nil end Hope that helps. From nicholas.henry at gmail.com Thu Sep 9 14:16:45 2010 From: nicholas.henry at gmail.com (Nicholas Henry) Date: Thu, 9 Sep 2010 11:16:45 -0700 (PDT) Subject: [rspec-users] [BDD] NoMethodError raised when calling #stub with incorrect parameters Message-ID: <22b51aff-2c63-4164-969e-0793373d977d@q2g2000vbk.googlegroups.com> I'm new to RSpec and came across an interesting situation where calling a stubbed method with different parameters from those specified, raises a misleading error. Some code to illustrate: (rspec 1.3.0) describe Person do describe "#greeting" do context "using #stub with correct parameters" do before(:each) do subject.stub(:greeting).with("Nicholas") end specify { lambda{ subject.greeting("Nicholas") }.should_not raise_error(NoMethodError) } end context "using #stub with incorrect parameters" do before(:each) do subject.stub(:greeting).with("incorrect parameter") end specify { lambda{ subject.greeting("Nicholas") }.should raise_error(NoMethodError) } end end end I know this is not a test you would have in reality, but it illustrates the behaviour. I also have come to the realization that you should never specify parameters when using the stub command, you should only use #with on #should_receive. However, when you have mistakenly done this (like the newbie I am), tracking down the issue can be a bit painful due to the misleading exception raised. Should developers be protected against using #with on #stub, a better exception such as Spec::Mocks::MockExpectationError, or am I missing something? I would appreciate hearing you thoughts. Thank you, Nicholas From nicholas.henry at gmail.com Mon Sep 13 09:48:35 2010 From: nicholas.henry at gmail.com (Nicholas Henry) Date: Mon, 13 Sep 2010 06:48:35 -0700 (PDT) Subject: [rspec-users] [BDD] NoMethodError raised when calling #stub with incorrect parameters Message-ID: I'm new to RSpec and came across an interesting situation where calling a stubbed method with different parameters from those specified, raises a misleading error. Some code to illustrate: (rspec 1.3.0) describe Person do describe "#greeting" do context "using #stub with correct parameters" do before(:each) do subject.stub(:greeting).with("Nicholas") end specify { lambda{ subject.greeting("Nicholas") }.should_not raise_error(NoMethodError) } end context "using #stub with incorrect parameters" do before(:each) do subject.stub(:greeting).with("incorrect parameter") end specify { lambda{ subject.greeting("Nicholas") }.should raise_error(NoMethodError) } end end end I know this is not a test you would have in reality, but it illustrates the behaviour. I also have come to the realization that you should never specify parameters when using the stub command, you should only use #with on #should_receive. However, when you have mistakenly done this (like the newbie I am), tracking down the issue can be a bit painful due to the misleading exception raised. Should developers be protected against using #with on #stub, a better exception such as Spec::Mocks::MockExpectationError, or am I missing something? I would appreciate hearing you thoughts. Thank you, Nicholas From brian.takita at gmail.com Tue Sep 14 00:31:05 2010 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 13 Sep 2010 21:31:05 -0700 Subject: [rspec-users] Propagating settings to subtyped ExampleGroups Message-ID: Hey, rspec 2 upgrade question. Rspec 1.x had a class hierarchy. In a Rails project, the ExampleGroup inherited from Test::Unit::TestCase. That allowed me to set use_transactional_fixtures in my own ExampleGroups and rely on inheritance for the settings to propagate. Now it seems like RSpec::Core::ExampleGroup no longer inherits from Test::Unit::TestCase and there is RSpec.configure instead. How do I have the settings in the configuration propagate to subtypes of the ExampleGroup? Thanks, Brian From jko170 at gmail.com Tue Sep 14 01:04:43 2010 From: jko170 at gmail.com (Justin Ko) Date: Mon, 13 Sep 2010 22:04:43 -0700 (PDT) Subject: [rspec-users] Propagating settings to subtyped ExampleGroups In-Reply-To: References: Message-ID: describe 'I want this to be inherited' do before do RSpec.configure {|c| c.use_transactional_fixtures = false } end context 'blah' do I would wrap it in a method if you're doing it often. On Sep 14, 12:31?am, Brian Takita wrote: > Hey, rspec 2 upgrade question. > > Rspec 1.x had a class hierarchy. In a Rails project, the ExampleGroup > inherited from Test::Unit::TestCase. > That allowed me to set use_transactional_fixtures in my own > ExampleGroups and rely on inheritance for the settings to propagate. > > Now it seems like RSpec::Core::ExampleGroup no longer inherits from > Test::Unit::TestCase and there is RSpec.configure instead. > How do I have the settings in the configuration propagate to subtypes > of the ExampleGroup? > > Thanks, > Brian > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Sep 14 09:27:21 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 14 Sep 2010 08:27:21 -0500 Subject: [rspec-users] Propagating settings to subtyped ExampleGroups In-Reply-To: References: Message-ID: Hey Brian - long time. Hope all is well. More below ... On Sep 14, 2010, at 12:04 AM, Justin Ko wrote: > On Sep 14, 12:31 am, Brian Takita wrote: >> Hey, rspec 2 upgrade question. >> >> Rspec 1.x had a class hierarchy. In a Rails project, the ExampleGroup >> inherited from Test::Unit::TestCase. >> That allowed me to set use_transactional_fixtures in my own >> ExampleGroups and rely on inheritance for the settings to propagate. How are you telling rspec to load which example groups? Maybe we can accomplish the same with mixins. >> Now it seems like RSpec::Core::ExampleGroup no longer inherits from >> Test::Unit::TestCase and there is RSpec.configure instead. Not instead - there was always Spec.configure - but yes, I worked with the Rails core team to make it so RSpec didn't need to depend on the Test::Unit or Minitest runners but could still get all the services in rails tests. Now we use metadata set on groups to determine when to mix in what behaviour: module MyExtension ... end RSpec.configure do |c| c.include(MyExtension, :foo => :bar) end describe "something", :foo => :bar do ... end In rspec-rails, that's done implicitly by matching the :type key in the metadata, which gets set before RSpec.configure is processed. You could do something similar if you wanted to make these inclusions work implicitly based on some other criteria like directory path, etc. That all make sense? If not, can you give me a clearer picture of your use case? >> How do I have the settings in the configuration propagate to subtypes >> of the ExampleGroup? > describe 'I want this to be inherited' do > before do > RSpec.configure {|c| c.use_transactional_fixtures = false } > end > > context 'blah' do > > I would wrap it in a method if you're doing it often. From brian.takita at gmail.com Tue Sep 14 12:04:07 2010 From: brian.takita at gmail.com (Brian Takita) Date: Tue, 14 Sep 2010 09:04:07 -0700 Subject: [rspec-users] Propagating settings to subtyped ExampleGroups In-Reply-To: References: Message-ID: On Tue, Sep 14, 2010 at 6:27 AM, David Chelimsky wrote: > Hey Brian - long time. Hope all is well. More below ... Hey David, I've been pretty busy, and things are going well. It seems like things are going well with you :-) > > On Sep 14, 2010, at 12:04 AM, Justin Ko wrote: > >> On Sep 14, 12:31 am, Brian Takita wrote: >>> Hey, rspec 2 upgrade question. >>> >>> Rspec 1.x had a class hierarchy. In a Rails project, the ExampleGroup >>> inherited from Test::Unit::TestCase. >>> That allowed me to set use_transactional_fixtures in my own >>> ExampleGroups and rely on inheritance for the settings to propagate. > > How are you telling rspec to load which example groups? Maybe we can accomplish the same with mixins. I converted the ExampleGroups into mixins, but there are some issues. Basically, I made ExampleGroup classes (with class methods). The class methods also relied on inheritance (to use super). There are complications with the new architecture. I'm trying to figure out if my architecture is "compatible" with RSpec 2.0. > >>> Now it seems like RSpec::Core::ExampleGroup no longer inherits from >>> Test::Unit::TestCase and there is RSpec.configure instead. > > Not instead - there was always Spec.configure - but yes, I worked with the Rails core team to make it so RSpec didn't need to depend on the Test::Unit or Minitest runners but could still get all the services in rails tests. True. I always preferred setting use_transactional_fixtures directly in the ExampleGroup because it is more straightforward (less software needed and less things breaking until now) and worked really well with the inheritance hierarchy. I could override use_transactional_fixtures in subclasses. > > Now we use metadata set on groups to determine when to mix in what behaviour: > > module MyExtension > ?... > end > > RSpec.configure do |c| > ?c.include(MyExtension, :foo => :bar) > end > > describe "something", :foo => :bar do > ?... > end > > In rspec-rails, that's done implicitly by matching the :type key in the metadata, which gets set before RSpec.configure is processed. ?You could do something similar if you wanted to make these inclusions work implicitly based on some other criteria like directory path, etc. > > That all make sense? If not, can you give me a clearer picture of ?your use case? I have different subclasses of ExampleGroup. I use instance and class method overriding. I also call class methods (defined in the parent or current class) in the ExampleGroup definitions. The metadata is interesting. I'm trying to figure out how module inheritance & metadata can be used as a substitute. Correct me if I'm wrong about my following points: If I were to use the metadata, I have to sort of reimplement the class method inheritance (for class methods from Test::Unit such as use_transactional_fixtures) using the metadata. If the class method is originally defined in rspec, I can somehow wrangle module inheritance to properly handle class methods. However, in this case, it's simpler with class inheritance. > >>> How do I have the settings in the configuration propagate to subtypes >>> of the ExampleGroup? >> describe 'I want this to be inherited' do >> ?before do >> ? ?RSpec.configure {|c| c.use_transactional_fixtures = false } >> ?end I'm surprised that would that work. I would think that Fixture loading would be one of the first before blocks and would occur before the configure statement. I suppose if you could somehow prepend the before block to the front of everything, it would work. >> >> ?context 'blah' do >> >> I would wrap it in a method if you're doing it often. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Thank you, Brian From brennon at brennonbortz.com Tue Sep 14 17:41:52 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Tue, 14 Sep 2010 22:41:52 +0100 Subject: [rspec-users] Autotest will run features, but not specs In-Reply-To: References: <5EAD4227-84BA-4276-AFD1-EDC4F164E672@gmail.com> <4A619CFA-5221-4BB0-8AD5-E56B95E12D86@brennonbortz.com> <9E1AF3ED-C464-4037-A3A7-553806CD2CDB@gmail.com> <3E6D070C-266C-4354-AA54-3B9864A58EF5@brennonbortz.com> <5D6BAADD-5D54-47E0-A82D-A16DEF8AD807@brennonbortz.com> <2D455128-FFCD-4616-B3A1-678901E99CC7@gmail.com> Message-ID: <1498A7BA-5529-422C-B68E-A844B14A6347@brennonbortz.com> On 27 Aug 2010, at 15:20, David Chelimsky wrote: > > On Aug 27, 2010, at 8:48 AM, Brennon Bortz wrote: > >> On 27 Aug 2010, at 14:44, David Chelimsky wrote: >> >>> On Aug 27, 2010, at 8:37 AM, Brennon Bortz wrote: >>> >>>> On 27 Aug 2010, at 14:29, Brennon Bortz wrote: >>>> >>>>> On 27 Aug 2010, at 14:06, David Chelimsky wrote: >>>>> >>>>>> On Aug 27, 2010, at 6:47 AM, Brennon Bortz wrote: >>>>>> >>>>>>> Not sure what I must have bumped, but autotest won't run any specs--only features. No errors are given on startup. I've taken "export AUTOFEATURE=true" out of my ./bashrc file--now I just get a blank screen when running autotest. Adding "export RSPEC=true" to .bashrc doesn't change anything either. >>>>>> >>>>>> 1. Get rid of 'Autotest.add_discovery { "rails" }' from ./autotest/discover.rb. >>>>>> 2. Add autotest-rails to the Gemfile. >>>>>> >>>>>> If any of the gems listed in the Gemfile have :path or :git options, you need to run "bundle exec autotest". >>>>>> >>>>>> HTH, >>>>>> DavidStrange...that does work, but now autotest seems caught in an infinite loop. When I run autospec, the specs run, then the features, then the features again...and again...and again...and so on. If I run autotest as follows: "AUTOFEATURE=false autotest", I don't have the problem. Any other ideas? >>>> And now (I haven't touched anything...seriously!), even "AUTOFEATURE=false autotest" gives me an endless loop of spec tests... >>> >>> (I moved your posts to the bottom so we can read them in order. Please post at the bottom or inline.) >>> >>> I've seen this happen when files are generated during a spec run. What's in spec/spec.opts and cucumber.yml? >> >> No spec.opts file, and just the default cucumber.yml file (I believe): >> >> <% >> rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" >> rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" >> std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip" >> %> >> default: <%= std_opts %> features >> wip: --tags @wip:3 --wip features >> rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip > > Unless you're running cucumber with --profile rerun, this shouldn't be a problem. > > Do any of your specs generate files? Also, did you try both "autotest" and "bundle exec autotest" with the same results? Argh...this problem stopped occurring--thought I wouldn't have to deal with it again. Same setup as we've already discussed--just a loop of cucumber features. Specs are run, but only once when a file is changed, and then it's back to the features loop. I've tried both "autotest" and "bundle exec autotest". "autotest" gives me the behaviour I've described. "bundle exec autotest" yields the following error: :29: warning: loading in progress, circular require considered harmful - /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb from :29:in `require' from :29:in `require' from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/setup.rb:1:in `' from :29:in `require' from :29:in `require' from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:2:in `' from :29:in `require' from :29:in `require' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:1136:in `' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `load_plugins' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `each' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `block in load_plugins' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `load' from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/hanna-0.1.12/lib/rubygems_plugin.rb:2:in `' from :29:in `require' from :29:in `require' from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/doc_manager.rb:8:in `' from :29:in `require' from :29:in `require' /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:84: warning: method redefined; discarding old gem /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:81: warning: previous definition of gem was here /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:116: warning: method redefined; discarding old from_gems_in /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/source_index.rb:75: warning: previous definition of from_gems_in was here /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:125: warning: method redefined; discarding old refresh /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:728: warning: previous definition of refresh was here /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:126: warning: method redefined; discarding old bin_path /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:323: warning: previous definition of bin_path was here /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/autotest-4.3.2/lib/autotest.rb:275: warning: (...) interpreted as grouped expression loading autotest/cucumber_rails Error loading Autotest style autotest/cucumber_rails (no such file to load -- autotest/rails). Aborting. Any ideas? Thanks! From lists at ruby-forum.com Wed Sep 15 04:19:20 2010 From: lists at ruby-forum.com (Zhenning Guan) Date: Wed, 15 Sep 2010 10:19:20 +0200 Subject: [rspec-users] variable strange change Message-ID: <0ecf35a478f47755eb14a90b9265be57@ruby-forum.com> class User has_many :mads def mad Mad.find_by_user_id(id) end end class God belongs_to :mad belongs_to :user belongs_to :sender, :class_name => "User", :foreign_key => "sender_id" def strange_change! God.transaction do puts mad.nil? #the first time put is false if mad.nil? puts 'some thing exctue here' #no puts anything mad = you.mad end puts mad.nil? #the second time put is true end end end why the mad will become nil? -- Posted via http://www.ruby-forum.com/. From nesterukd at gmail.com Wed Sep 15 05:36:46 2010 From: nesterukd at gmail.com (nesterukD@gmail.com) Date: Wed, 15 Sep 2010 02:36:46 -0700 (PDT) Subject: [rspec-users] Rspec and rails: Problems while testing libraries in the lib directory Message-ID: I have some classes in the lib directory, and I want to test it. My class which I want to test looks like: class StatAggregation class << self def skills_rate(user_id) user_id = User.find_by_id(user_id) ... end end end I created spec: require File.expand_path(File.dirname(__FILE__) + '/../../ spec_helper') describe StatAggregation do fixtures [ :users ] describe 'skills_rate method' do it 'should work' do @user_id = 1 @user = mock_model(User) User.should_receive(:find_by_id).with(@user_id).and_return(@user) ... StatAggregation.skills_rate(@user_id) end end end It works ok, but it doesn't show where appeared error: 1) ArgumentError in 'PxStatAggregation skills_rate method should work' wrong number of arguments (1 for 0) script/spec:10: Finished in 0.326331 seconds How to get number of line where appeared error "wrong number of arguments (1 for 0)"? From dchelimsky at gmail.com Wed Sep 15 09:20:06 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 15 Sep 2010 08:20:06 -0500 Subject: [rspec-users] Rspec and rails: Problems while testing libraries in the lib directory In-Reply-To: References: Message-ID: On Wed, Sep 15, 2010 at 4:36 AM, nesterukD at gmail.com wrote: > I have some classes in the lib directory, and I want to test it. My > class which I want to test looks like: > > class StatAggregation > ?class << self > ? ?def skills_rate(user_id) > ? ? ?user_id = User.find_by_id(user_id) > ? ? ?... > ? ?end > ?end > end > > I created spec: > > require File.expand_path(File.dirname(__FILE__) + '/../../ > spec_helper') > > describe StatAggregation do > ?fixtures [ > ? ?:users > ?] > > ?describe 'skills_rate method' do > ? ?it 'should work' do > ? ? ?@user_id = 1 > ? ? ?@user = mock_model(User) > > User.should_receive(:find_by_id).with(@user_id).and_return(@user) > ? ? ?... > ? ? ?StatAggregation.skills_rate(@user_id) > ? ?end > ?end > end > > It works ok, but it doesn't show where appeared error: > > 1) > ArgumentError in 'PxStatAggregation skills_rate method should work' > wrong number of arguments (1 for 0) > script/spec:10: > > Finished in 0.326331 seconds > > How to get number of line where appeared error "wrong number of > arguments (1 for 0)"? Use the -h flag on the [r]spec command (rspec for rspec-2, spec for rspec-1) to learn about the command line options: # rspec-1 spec -h # rspec-2 rspec -h In either case you'll see a -b flag to get a full backtrace: # rspec-1 spec spec -b # rspec-2 rspec spec -b HTH, David From dchelimsky at gmail.com Wed Sep 15 09:22:42 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 15 Sep 2010 08:22:42 -0500 Subject: [rspec-users] variable strange change In-Reply-To: <0ecf35a478f47755eb14a90b9265be57@ruby-forum.com> References: <0ecf35a478f47755eb14a90b9265be57@ruby-forum.com> Message-ID: On Wed, Sep 15, 2010 at 3:19 AM, Zhenning Guan wrote: > class User > ?has_many :mads > > ?def mad > ? ?Mad.find_by_user_id(id) > ?end > end > > class God > ?belongs_to :mad > ?belongs_to :user > ?belongs_to :sender, :class_name => "User", :foreign_key => "sender_id" > > ?def strange_change! > ? ?God.transaction do > ? ? ?puts mad.nil? ? ?#the first time put is false > ? ? ?if mad.nil? > ? ? ? ?puts 'some thing exctue here' ? ? ? ? ? #no puts anything > ? ? ? ?mad = you.mad > ? ? ?end > ? ? ?puts mad.nil? ? ?#the second time put is true > ? ?end > ?end > end > > why the mad will become nil? Seems like a Rails question, not an RSpec question. Please post Rails questions to http://groups.google.com/group/rubyonrails-talk. Cheers, David From manchanda.manish at gmail.com Wed Sep 15 10:57:22 2010 From: manchanda.manish at gmail.com (Manish Manchanda) Date: Wed, 15 Sep 2010 20:27:22 +0530 Subject: [rspec-users] specs inside subfolder of lib folder not displaying proper error messages Message-ID: hi im facing this issue in which if i place a failing spec inside a subfolder of my lib folder then along with the error message the file name and the line number is not shown. output as below: 'Test one' FAILED expected: 2, got: 1 (using ==) but if i move the spec directly under lib or any other folder then i see the file name and line number with error message as below 'Test one' FAILED expected: 2, got: 1 (using ==) ./spec/SFA/foo_spec.rb:6: my project structure is somewhat like below project project/app project/app/models project/lib project/lib/extension project/spec project/spec/app project/spec/lib project/spec/lib/extension so if i place the spec file under 'project/spec/lib/extension' or any folder in that level then i do not see the file name and line number along with error msg. please advice regards, manish -------------- next part -------------- An HTML attachment was scrubbed... URL: From manchanda.manish at gmail.com Wed Sep 15 11:24:04 2010 From: manchanda.manish at gmail.com (Manish Manchanda) Date: Wed, 15 Sep 2010 20:54:04 +0530 Subject: [rspec-users] specs inside subfolder of lib folder not displaying proper error messages In-Reply-To: References: Message-ID: and just to add, this is not a rails app -------------- next part -------------- An HTML attachment was scrubbed... URL: From rockrep at yahoo.com Wed Sep 15 14:05:44 2010 From: rockrep at yahoo.com (Michael Kintzer) Date: Wed, 15 Sep 2010 11:05:44 -0700 (PDT) Subject: [rspec-users] [rails] url_for host and protocol not set when full spec suite run Message-ID: <132673.32848.qm@web112020.mail.gq1.yahoo.com> rspec (2.0.0.beta.19) rails (3.0.0) authlogic (2.1.6) bartt-ssl_requirement (1.2.3) RUBYGEMS VERSION: 1.3.7 RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.4.0] Hi, I'm getting different results when running a Rails 3 scaffold generated controller example depending on whether or not I run 'rspec spec' or 'rspec spec/controllers'. The difference occurs when evaluating the dynamic route methods with for '_url', e.g. my_model_url I'm using Authlogic and SslRequirement as well. The issue may be in either of those libraries, but the only difference is how I run the spec suite. I disable the Ssl requirement check in the test.rb environment file. Assume I generated the scaffold code with: "rails g scaffold scaffold" to create a "Scaffold" model. See relevant code here: http://gist.github.com/581130 When I run 'rspec spec/controllers', the example in question passes. I placed debug code in url_for.rb (bartt-ssl_requirement-1.2.3) to parse the options passed to url_for and they include the :host and :protocol parameters, :host => "test.host", :protocol => "http://". When I run 'rspec spec', the example in question fails. The url_for options are missing both the :host and :protocol parameters. If I manully pass those into the my_model_url method, the example will pass. If I use the _path version of the route method, the example passes. The stack trace in the failing case is (path to gems directory omitted): 1) ScaffoldsController POST create with valid params redirects to the created scaffold Failure/Error: response.should redirect_to(scaffold_url(mock_scaffold)) Missing host to link to! Please provide :host parameter or set default_url_options[:host] # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:473:in `url_for_without_non_ssl_host' # .../bartt-ssl_requirement-1.2.3/lib/url_for.rb:44:in `url_for_without_secure_option' # .../gems/bartt-ssl_requirement-1.2.3/lib/url_for.rb:32:in `url_for' # .../actionpack-3.0.0/lib/action_dispatch/routing/url_for.rb:132:in `url_for' # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:195:in `factor_library_url' # ./spec/controllers/scaffolds_controller_spec.rb:70 # .../activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject' So, I'm stumped as to why 'rspec spec' is behaving differently from 'rspec spec/controllers' with respect to generating the appropriate url_for options. Thanks! Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Sep 15 23:51:48 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 15 Sep 2010 22:51:48 -0500 Subject: [rspec-users] [rails] url_for host and protocol not set when full spec suite run In-Reply-To: <132673.32848.qm@web112020.mail.gq1.yahoo.com> References: <132673.32848.qm@web112020.mail.gq1.yahoo.com> Message-ID: <51B2B579-96F6-4FF2-BC35-158265414C15@gmail.com> On Sep 15, 2010, at 1:05 PM, Michael Kintzer wrote: > rspec (2.0.0.beta.19) > rails (3.0.0) > authlogic (2.1.6) > bartt-ssl_requirement (1.2.3) > RUBYGEMS VERSION: 1.3.7 > RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.4.0] > > Hi, > > I'm getting different results when running a Rails 3 scaffold generated controller example depending on whether or not I run 'rspec spec' or 'rspec spec/controllers'. The difference occurs when evaluating the dynamic route methods with for '_url', e.g. my_model_url I'm using Authlogic and SslRequirement as well. The issue may be in either of those libraries, but the only difference is how I run the spec suite. I disable the Ssl requirement check in the test.rb environment file. > > Assume I generated the scaffold code with: "rails g scaffold scaffold" to create a "Scaffold" model. > > See relevant code here: http://gist.github.com/581130 > > When I run 'rspec spec/controllers', the example in question passes. I placed debug code in url_for.rb (bartt-ssl_requirement-1.2.3) to parse the options passed to url_for and they include the :host and :protocol parameters, :host => "test.host", :protocol => "http://". > > When I run 'rspec spec', the example in question fails. The url_for options are missing both the :host and :protocol parameters. If I manully pass those into the my_model_url method, the example will pass. If I use the _path version of the route method, the example passes. > > The stack trace in the failing case is (path to gems directory omitted): > 1) ScaffoldsController POST create with valid params redirects to the created scaffold > Failure/Error: response.should redirect_to(scaffold_url(mock_scaffold)) > Missing host to link to! Please provide :host parameter or set default_url_options[:host] > # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:473:in `url_for_without_non_ssl_host' > # .../bartt-ssl_requirement-1.2.3/lib/url_for.rb:44:in `url_for_without_secure_option' > # .../gems/bartt-ssl_requirement-1.2.3/lib/url_for.rb:32:in `url_for' > # .../actionpack-3.0.0/lib/action_dispatch/routing/url_for.rb:132:in `url_for' > # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:195:in `factor_library_url' > # ./spec/controllers/scaffolds_controller_spec.rb:70 > # .../activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject' > > So, I'm stumped as to why 'rspec spec' is behaving differently from 'rspec spec/controllers' with respect to generating the appropriate url_for options. This sort of problem usually boils down to something interacting with global state - something that is only getting loaded when you run the full suite. To narrow it down, try running subsets of the directories: rspec spec/controllers spec/requests rspec spec/controllers spec/views rspec spec/controllers spec/models etc HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Sep 16 00:17:00 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 15 Sep 2010 23:17:00 -0500 Subject: [rspec-users] Propagating settings to subtyped ExampleGroups In-Reply-To: References: Message-ID: <34A7131D-DF25-4960-99A8-9147424A652A@gmail.com> On Sep 14, 2010, at 11:04 AM, Brian Takita wrote: > On Tue, Sep 14, 2010 at 6:27 AM, David Chelimsky wrote: >> Hey Brian - long time. Hope all is well. More below ... > Hey David, I've been pretty busy, and things are going well. It seems > like things are going well with you :-) >> >> On Sep 14, 2010, at 12:04 AM, Justin Ko wrote: >> >>> On Sep 14, 12:31 am, Brian Takita wrote: >>>> Hey, rspec 2 upgrade question. >>>> >>>> Rspec 1.x had a class hierarchy. In a Rails project, the ExampleGroup >>>> inherited from Test::Unit::TestCase. >>>> That allowed me to set use_transactional_fixtures in my own >>>> ExampleGroups and rely on inheritance for the settings to propagate. >> >> How are you telling rspec to load which example groups? Maybe we can accomplish the same with mixins. > I converted the ExampleGroups into mixins, but there are some issues. > Basically, I made ExampleGroup classes (with class methods). The class > methods also relied on inheritance (to use super). > There are complications with the new architecture. I'm trying to > figure out if my architecture is "compatible" with RSpec 2.0. >> >>>> Now it seems like RSpec::Core::ExampleGroup no longer inherits from >>>> Test::Unit::TestCase and there is RSpec.configure instead. >> >> Not instead - there was always Spec.configure - but yes, I worked with the Rails core team to make it so RSpec didn't need to depend on the Test::Unit or Minitest runners but could still get all the services in rails tests. > True. I always preferred setting use_transactional_fixtures directly > in the ExampleGroup because it is more straightforward (less software > needed and less things breaking until now) and worked really well with > the inheritance hierarchy. > I could override use_transactional_fixtures in subclasses. >> >> Now we use metadata set on groups to determine when to mix in what behaviour: >> >> module MyExtension >> ... >> end >> >> RSpec.configure do |c| >> c.include(MyExtension, :foo => :bar) >> end >> >> describe "something", :foo => :bar do >> ... >> end >> >> In rspec-rails, that's done implicitly by matching the :type key in the metadata, which gets set before RSpec.configure is processed. You could do something similar if you wanted to make these inclusions work implicitly based on some other criteria like directory path, etc. >> >> That all make sense? If not, can you give me a clearer picture of your use case? > I have different subclasses of ExampleGroup. I use instance and class > method overriding. I also call class methods (defined in the parent or > current class) in the ExampleGroup definitions. How does your setup select which of the available ExampleGroup subclasses to instantiate in each case? > The metadata is interesting. I'm trying to figure out how module > inheritance & metadata can be used as a substitute. > > Correct me if I'm wrong about my following points: > If I were to use the metadata, I have to sort of reimplement the class > method inheritance (for class methods from Test::Unit such as > use_transactional_fixtures) using the metadata. > > If the class method is originally defined in rspec, I can somehow > wrangle module inheritance to properly handle class methods. However, > in this case, it's simpler with class inheritance. How would you see this working, given the existing architectural changes? >>>> How do I have the settings in the configuration propagate to subtypes >>>> of the ExampleGroup? >>> describe 'I want this to be inherited' do >>> before do >>> RSpec.configure {|c| c.use_transactional_fixtures = false } >>> end > I'm surprised that would that work. I would think that Fixture loading > would be one of the first before blocks and would occur before the > configure statement. > I suppose if you could somehow prepend the before block to the front > of everything, it would work. >>> >>> context 'blah' do >>> >>> I would wrap it in a method if you're doing it often. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > Thank you, > Brian > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dolzenko at gmail.com Thu Sep 16 01:22:57 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Thu, 16 Sep 2010 09:22:57 +0400 Subject: [rspec-users] variable strange change In-Reply-To: References: <0ecf35a478f47755eb14a90b9265be57@ruby-forum.com> Message-ID: Typical Ruby gotcha: God.transaction do puts mad.nil? # mad is instance method of God and returns BelongsToAssociation here if mad.nil? puts 'some thing exctue here' mad = you.mad # Ruby sees mad local variable definition end puts mad.nil? # mad is unitialized local variable set to nil end On Wed, Sep 15, 2010 at 5:22 PM, David Chelimsky wrote: > On Wed, Sep 15, 2010 at 3:19 AM, Zhenning Guan wrote: >> class User >> ?has_many :mads >> >> ?def mad >> ? ?Mad.find_by_user_id(id) >> ?end >> end >> >> class God >> ?belongs_to :mad >> ?belongs_to :user >> ?belongs_to :sender, :class_name => "User", :foreign_key => "sender_id" >> >> ?def strange_change! >> ? ?God.transaction do >> ? ? ?puts mad.nil? ? ?#the first time put is false >> ? ? ?if mad.nil? >> ? ? ? ?puts 'some thing exctue here' ? ? ? ? ? #no puts anything >> ? ? ? ?mad = you.mad >> ? ? ?end >> ? ? ?puts mad.nil? ? ?#the second time put is true >> ? ?end >> ?end >> end >> >> why the mad will become nil? > > Seems like a Rails question, not an RSpec question. Please post Rails > questions to http://groups.google.com/group/rubyonrails-talk. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rockrep at yahoo.com Thu Sep 16 02:44:15 2010 From: rockrep at yahoo.com (Michael Kintzer) Date: Wed, 15 Sep 2010 23:44:15 -0700 (PDT) Subject: [rspec-users] [rails] url_for host and protocol not set when full spec suite run In-Reply-To: <51B2B579-96F6-4FF2-BC35-158265414C15@gmail.com> References: <132673.32848.qm@web112020.mail.gq1.yahoo.com> <51B2B579-96F6-4FF2-BC35-158265414C15@gmail.com> Message-ID: <794894.70326.qm@web112006.mail.gq1.yahoo.com> From: David Chelimsky To: rspec-users Sent: Wed, September 15, 2010 8:51:48 PM Subject: Re: [rspec-users] [rails] url_for host and protocol not set when full spec suite run On Sep 15, 2010, at 1:05 PM, Michael Kintzer wrote: rspec (2.0.0.beta.19) >rails (3.0.0) >authlogic (2.1.6) >bartt-ssl_requirement (1.2.3) >RUBYGEMS VERSION: 1.3.7 >RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.4.0] > >Hi, > >I'm getting different results when running a Rails 3 scaffold generated >controller example depending on whether or not I run 'rspec spec' or 'rspec >spec/controllers'. The difference occurs when evaluating the dynamic route >methods with for '_url', e.g. my_model_url I'm using Authlogic and >SslRequirement as well. The issue may be in either of those libraries, but the >only difference is how I run the spec suite. I disable the Ssl requirement >check in the test.rb environment file. > >Assume I generated the scaffold code with: "rails g scaffold scaffold" to >create a "Scaffold" model. > >See relevant code here: http://gist.github.com/581130 > >When I run 'rspec spec/controllers', the example in question passes. I placed >debug code in url_for.rb (bartt-ssl_requirement-1.2.3) to parse the options >passed to url_for and they include the :host and :protocol parameters, :host => >"test.host", :protocol => "http://". > >When I run 'rspec spec', the example in question fails. The url_for options >are missing both the :host and :protocol parameters. If I manully pass those >into the my_model_url method, the example will pass. If I use the _path >version of the route method, the example passes. > >The stack trace in the failing case is (path to gems directory omitted): >1) ScaffoldsController POST create with valid params redirects to the created >scaffold > Failure/Error: response.should redirect_to(scaffold_url(mock_scaffold)) > Missing host to link to! Please provide :host parameter or set >default_url_options[:host] > # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:473:in >`url_for_without_non_ssl_host' > # .../bartt-ssl_requirement-1.2.3/lib/url_for.rb:44:in >`url_for_without_secure_option' > # .../gems/bartt-ssl_requirement-1.2.3/lib/url_for.rb:32:in `url_for' > # .../actionpack-3.0.0/lib/action_dispatch/routing/url_for.rb:132:in >`url_for' > # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:195:in >`factor_library_url' > # ./spec/controllers/scaffolds_controller_spec.rb:70 > # .../activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject' > >So, I'm stumped as to why 'rspec spec' is behaving differently from 'rspec >spec/controllers' with respect to generating the appropriate url_for options. > This sort of problem usually boils down to something interacting with global state - something that is only getting loaded when you run the full suite. To narrow it down, try running subsets of the directories: rspec spec/controllers spec/requests rspec spec/controllers spec/views rspec spec/controllers spec/models etc HTH, David ----- David, thanks for the suggestion. One of my model specs was including Rails.application.routes.url_helpers, so it could evaluate route paths (b/c one of my models is doing the same, unusual, but supported). Removing the include fixed the controller spec problem mentioned previously. Of course this broke the model spec that needed url_helpers, but I was able to work around it by hard-coding what the expected route should be. Any idea why including url_helpers in the model spec causes this particular issue? It would be nice if there wasn't a conflict. I haven't traced through it enough to understand why the conflict occurs. Thanks again. Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Sep 16 07:59:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Sep 2010 06:59:26 -0500 Subject: [rspec-users] [rails] url_for host and protocol not set when full spec suite run In-Reply-To: <794894.70326.qm@web112006.mail.gq1.yahoo.com> References: <132673.32848.qm@web112020.mail.gq1.yahoo.com> <51B2B579-96F6-4FF2-BC35-158265414C15@gmail.com> <794894.70326.qm@web112006.mail.gq1.yahoo.com> Message-ID: <03F79724-14E0-4FA2-AD17-9D0CE67CEB8B@gmail.com> On Sep 16, 2010, at 1:44 AM, Michael Kintzer wrote: > From: David Chelimsky > To: rspec-users > Sent: Wed, September 15, 2010 8:51:48 PM > Subject: Re: [rspec-users] [rails] url_for host and protocol not set when full spec suite run > > On Sep 15, 2010, at 1:05 PM, Michael Kintzer wrote: > >> rspec (2.0.0.beta.19) >> rails (3.0.0) >> authlogic (2.1.6) >> bartt-ssl_requirement (1.2.3) >> RUBYGEMS VERSION: 1.3.7 >> RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.4.0] >> >> Hi, >> >> I'm getting different results when running a Rails 3 scaffold generated controller example depending on whether or not I run 'rspec spec' or 'rspec spec/controllers'. The difference occurs when evaluating the dynamic route methods with for '_url', e.g. my_model_url I'm using Authlogic and SslRequirement as well. The issue may be in either of those libraries, but the only difference is how I run the spec suite. I disable the Ssl requirement check in the test.rb environment file. >> >> Assume I generated the scaffold code with: "rails g scaffold scaffold" to create a "Scaffold" model. >> >> See relevant code here: http://gist.github.com/581130 >> >> When I run 'rspec spec/controllers', the example in question passes. I placed debug code in url_for.rb (bartt-ssl_requirement-1.2.3) to parse the options passed to url_for and they include the :host and :protocol parameters, :host => "test.host", :protocol => "http://". >> >> When I run 'rspec spec', the example in question fails. The url_for options are missing both the :host and :protocol parameters. If I manully pass those into the my_model_url method, the example will pass. If I use the _path version of the route method, the example passes. >> >> The stack trace in the failing case is (path to gems directory omitted): >> 1) ScaffoldsController POST create with valid params redirects to the created scaffold >> Failure/Error: response.should redirect_to(scaffold_url(mock_scaffold)) >> Missing host to link to! Please provide :host parameter or set default_url_options[:host] >> # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:473:in `url_for_without_non_ssl_host' >> # .../bartt-ssl_requirement-1.2.3/lib/url_for.rb:44:in `url_for_without_secure_option' >> # .../gems/bartt-ssl_requirement-1.2.3/lib/url_for.rb:32:in `url_for' >> # .../actionpack-3.0.0/lib/action_dispatch/routing/url_for.rb:132:in `url_for' >> # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:195:in `factor_library_url' >> # ./spec/controllers/scaffolds_controller_spec.rb:70 >> # .../activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject' >> >> So, I'm stumped as to why 'rspec spec' is behaving differently from 'rspec spec/controllers' with respect to generating the appropriate url_for options. > > > This sort of problem usually boils down to something interacting with global state - something that is only getting loaded when you run the full suite. To narrow it down, try running subsets of the directories: > > rspec spec/controllers spec/requests > rspec spec/controllers spec/views > rspec spec/controllers spec/models > > etc > > HTH, > David > > ----- > David, thanks for the suggestion. One of my model specs was including Rails.application.routes.url_helpers, so it could evaluate route paths (b/c one of my models is doing the same, unusual, but supported). Removing the include fixed the controller spec problem mentioned previously. Of course this broke the model spec that needed url_helpers, but I was able to work around it by hard-coding what the expected route should be. > > Any idea why including url_helpers in the model spec causes this particular issue? It would be nice if there wasn't a conflict. I haven't traced through it enough to understand why the conflict occurs. Rails.application.routes.url_helpers is a global object, so if the spec is doing anything to change its state that might cause trouble. That's all I can think of. How are you including them? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rockrep at yahoo.com Thu Sep 16 13:34:10 2010 From: rockrep at yahoo.com (Michael Kintzer) Date: Thu, 16 Sep 2010 10:34:10 -0700 (PDT) Subject: [rspec-users] [rails] url_for host and protocol not set when full spec suite run In-Reply-To: <03F79724-14E0-4FA2-AD17-9D0CE67CEB8B@gmail.com> References: <132673.32848.qm@web112020.mail.gq1.yahoo.com> <51B2B579-96F6-4FF2-BC35-158265414C15@gmail.com> <794894.70326.qm@web112006.mail.gq1.yahoo.com> <03F79724-14E0-4FA2-AD17-9D0CE67CEB8B@gmail.com> Message-ID: <174724.27134.qm@web112014.mail.gq1.yahoo.com> From: David Chelimsky To: rspec-users Sent: Thu, September 16, 2010 4:59:26 AM Subject: Re: [rspec-users] [rails] url_for host and protocol not set when full spec suite run On Sep 16, 2010, at 1:44 AM, Michael Kintzer wrote: From: David Chelimsky > >To: rspec-users >Sent: Wed, September 15, 2010 8:51:48 PM >Subject: Re: [rspec-users] [rails] url_for host and protocol not set when full >spec suite run > > >On Sep 15, 2010, at 1:05 PM, Michael Kintzer wrote: > >rspec (2.0.0.beta.19) >>rails (3.0.0) >>authlogic (2.1.6) >>bartt-ssl_requirement (1.2.3) >>RUBYGEMS VERSION: 1.3.7 >>RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.4.0] >> >>Hi, >> >>I'm getting different results when running a Rails 3 scaffold generated >>controller example depending on whether or not I run 'rspec spec' or 'rspec >>spec/controllers'. The difference occurs when evaluating the dynamic route >>methods with for '_url', e.g. my_model_url I'm using Authlogic and >>SslRequirement as well. The issue may be in either of those libraries, but the >>only difference is how I run the spec suite. I disable the Ssl requirement >>check in the test.rb environment file. >> >>Assume I generated the scaffold code with: "rails g scaffold scaffold" to >>create a "Scaffold" model. >> >>See relevant code here: http://gist.github.com/581130 >> >>When I run 'rspec spec/controllers', the example in question passes. I placed >>debug code in url_for.rb (bartt-ssl_requirement-1.2.3) to parse the options >>passed to url_for and they include the :host and :protocol parameters, :host => >>"test.host", :protocol => "http://". >> >>When I run 'rspec spec', the example in question fails. The url_for options >>are missing both the :host and :protocol parameters. If I manully pass those >>into the my_model_url method, the example will pass. If I use the _path >>version of the route method, the example passes. >> >>The stack trace in the failing case is (path to gems directory omitted): >>1) ScaffoldsController POST create with valid params redirects to the created >>scaffold >> Failure/Error: response.should redirect_to(scaffold_url(mock_scaffold)) >> Missing host to link to! Please provide :host parameter or set >>default_url_options[:host] >> # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:473:in >>`url_for_without_non_ssl_host' >> # .../bartt-ssl_requirement-1.2.3/lib/url_for.rb:44:in >>`url_for_without_secure_option' >> # .../gems/bartt-ssl_requirement-1.2.3/lib/url_for.rb:32:in `url_for' >> # .../actionpack-3.0.0/lib/action_dispatch/routing/url_for.rb:132:in >>`url_for' >> # .../actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:195:in >>`factor_library_url' >> # ./spec/controllers/scaffolds_controller_spec.rb:70 >> # .../activesupport-3.0.0/lib/active_support/dependencies.rb:239:in >`inject' >> >>So, I'm stumped as to why 'rspec spec' is behaving differently from 'rspec >>spec/controllers' with respect to generating the appropriate url_for options. >> > > >This sort of problem usually boils down to something interacting with global >state - something that is only getting loaded when you run the full suite. To >narrow it down, try running subsets of the directories: > > >rspec spec/controllers spec/requests >rspec spec/controllers spec/views >rspec spec/controllers spec/models > > >etc > > >HTH, >David > >----- >David, thanks for the suggestion. One of my model specs was including >Rails.application.routes.url_helpers, so it could evaluate route paths (b/c one >of my models is doing the same, unusual, but supported). Removing the include >fixed the controller spec problem mentioned previously. Of course this broke >the model spec that needed url_helpers, but I was able to work around it by >hard-coding what the expected route should be. > >Any idea why including url_helpers in the model spec causes this particular >issue? It would be nice if there wasn't a conflict. I haven't traced through >it enough to understand why the conflict occurs. Rails.application.routes.url_helpers is a global object, so if the spec is doing anything to change its state that might cause trouble. That's all I can think of. How are you including them? --- I was including them with "include Rails.application.routes.url_helpers" which is the Rails 3 recommendation as specified in ActionController::UrlWriter -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed.howland at gmail.com Thu Sep 16 21:24:08 2010 From: ed.howland at gmail.com (Ed Howland) Date: Thu, 16 Sep 2010 21:24:08 -0400 Subject: [rspec-users] Trying to spec all models In-Reply-To: <4B73E6D6.1080802@gmail.com> References: <4B7376D0.3030602@gmail.com> <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> <57c63afe1002102037t66c94bd5h54e4ee4fb464b9f7@mail.gmail.com> <4B73E6D6.1080802@gmail.com> Message-ID: Phillip, any updates on your efforts? I am keenly interested in a Cucumber tags like facility for RSpec Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland On Thu, Feb 11, 2010 at 7:15 AM, Phillip Koebbe wrote: > David Chelimsky wrote: >> >> On Thu, Feb 11, 2010 at 12:13 AM, Mike Sassak ?wrote: >> >>> >>> On Wed, Feb 10, 2010 at 10:17 PM, Phillip Koebbe >>> ?wrote: >>> >>>> >>>> When I do >>>> >>>> script/spec -c -f n ?spec/models/**/*_spec.rb >>>> >>>> I get >>>> >>>> >>>> /Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:283:in >>>> `files_to_load': File or directory not found: spec/models/**/*_spec.rb >>>> (RuntimeError) >>>> >>>> Yet, if I go into irb and do >>>> >>>> Dir.glob('spec/models/**/*_spec.rb') >>>> >>>> I get >>>> >>>> ["spec/models/county_spec.rb", "spec/models/county_user_spec.rb", >>>> "spec/models/message_county_spec.rb", "spec/models/message_spec.rb", >>>> "spec/models/message_user_spec.rb", "spec/models/postman_spec.rb", >>>> "spec/models/user_spec.rb"] >>>> >>>> Does spec not glob? I'm working on a wrapper script and I'd like to be >>>> able >>>> to run all specs of a given type (controller, model, view) by passing a >>>> single switch (-c, -m, -v). It works when I have subdirectories (as I do >>>> with controllers), but it isn't working when I don't (as with models). >>>> The >>>> fact that glob picks up the files properly got me wondering, so I >>>> thought >>>> I'd ask. >>>> >>>> >>> >>> When running script/spec from the CLI the globbing rules will depend >>> on the shell. Try searching Google for "bash globbing" (or whatever >>> shell you're using). But if all you need is to run all the model >>> specs, you could use "rake spec:models". That works well for me. >>> >> >> Or just "script/spec spec/models" >> >> > > Thanks for the replies. It's not as simple as I just want to spec all > models. As I mentioned, I'm writing a wrapper script to automate some things > that I repeatedly find myself doing or wanting to do. I am trying to do a > very simple **/* pattern when I don't pass a pattern as an argument. I don't > really want to have a conditional that says > > rake spec:models unless pattern > > when the rest of my code actually calls script/spec. David's suggestion > might work though. Right now, I do > > file = ARGV.at(0) if ARGV.size > 0 > file = '**/*' unless file > filename_partial> > spec_path = "#{spec_path}/#{file}#{filename_partial}.rb" > > file can be "user", "admin/message", "admin/*", "*/message", or whatever I > need it to be. That's why I'm looking for the easiest way to run all of a > given type. Eventually I'm going to add support for ~, like with Cucumber > tags, except for specs. I did this in a wrapper for Cucumber features and it > is working out well for me. > > I'll keep kicking it around. I'm confident a reasonable solution is not far > off. > > Peace, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cdemyanovich at gmail.com Thu Sep 16 21:28:19 2010 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Thu, 16 Sep 2010 21:28:19 -0400 Subject: [rspec-users] Trying to spec all models In-Reply-To: References: <4B7376D0.3030602@gmail.com> <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> <57c63afe1002102037t66c94bd5h54e4ee4fb464b9f7@mail.gmail.com> <4B73E6D6.1080802@gmail.com> Message-ID: On Thu, Sep 16, 2010 at 9:24 PM, Ed Howland wrote: > Phillip, any updates on your efforts? > > I am keenly interested in a Cucumber tags like facility for RSpec Though I haven't been closely following RSpec 2, I think it's going to have tags much like Cucumber. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Sep 16 21:46:29 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Sep 2010 20:46:29 -0500 Subject: [rspec-users] Trying to spec all models In-Reply-To: References: <4B7376D0.3030602@gmail.com> <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> <57c63afe1002102037t66c94bd5h54e4ee4fb464b9f7@mail.gmail.com> <4B73E6D6.1080802@gmail.com> Message-ID: <5CAF836C-CF3F-46BA-9420-26B0923C33F4@gmail.com> On Sep 16, 2010, at 8:24 PM, Ed Howland wrote: > On Thu, Feb 11, 2010 at 7:15 AM, Phillip Koebbe wrote: >> David Chelimsky wrote: >>> >>> On Thu, Feb 11, 2010 at 12:13 AM, Mike Sassak wrote: >>> >>>> >>>> On Wed, Feb 10, 2010 at 10:17 PM, Phillip Koebbe >>>> wrote: >>>> >>>>> >>>>> When I do >>>>> >>>>> script/spec -c -f n spec/models/**/*_spec.rb >>>>> >>>>> I get >>>>> >>>>> >>>>> /Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:283:in >>>>> `files_to_load': File or directory not found: spec/models/**/*_spec.rb >>>>> (RuntimeError) >>>>> >>>>> Yet, if I go into irb and do >>>>> >>>>> Dir.glob('spec/models/**/*_spec.rb') >>>>> >>>>> I get >>>>> >>>>> ["spec/models/county_spec.rb", "spec/models/county_user_spec.rb", >>>>> "spec/models/message_county_spec.rb", "spec/models/message_spec.rb", >>>>> "spec/models/message_user_spec.rb", "spec/models/postman_spec.rb", >>>>> "spec/models/user_spec.rb"] >>>>> >>>>> Does spec not glob? I'm working on a wrapper script and I'd like to be >>>>> able >>>>> to run all specs of a given type (controller, model, view) by passing a >>>>> single switch (-c, -m, -v). It works when I have subdirectories (as I do >>>>> with controllers), but it isn't working when I don't (as with models). >>>>> The >>>>> fact that glob picks up the files properly got me wondering, so I >>>>> thought >>>>> I'd ask. >>>>> >>>>> >>>> >>>> When running script/spec from the CLI the globbing rules will depend >>>> on the shell. Try searching Google for "bash globbing" (or whatever >>>> shell you're using). But if all you need is to run all the model >>>> specs, you could use "rake spec:models". That works well for me. >>>> >>> >>> Or just "script/spec spec/models" >>> >>> >> >> Thanks for the replies. It's not as simple as I just want to spec all >> models. As I mentioned, I'm writing a wrapper script to automate some things >> that I repeatedly find myself doing or wanting to do. I am trying to do a >> very simple **/* pattern when I don't pass a pattern as an argument. I don't >> really want to have a conditional that says >> >> rake spec:models unless pattern >> >> when the rest of my code actually calls script/spec. David's suggestion >> might work though. Right now, I do >> >> file = ARGV.at(0) if ARGV.size > 0 >> file = '**/*' unless file >> > filename_partial> >> spec_path = "#{spec_path}/#{file}#{filename_partial}.rb" >> >> file can be "user", "admin/message", "admin/*", "*/message", or whatever I >> need it to be. That's why I'm looking for the easiest way to run all of a >> given type. Eventually I'm going to add support for ~, like with Cucumber >> tags, except for specs. I did this in a wrapper for Cucumber features and it >> is working out well for me. >> >> I'll keep kicking it around. I'm confident a reasonable solution is not far >> off. >> >> Peace, >> Phillip > Phillip, any updates on your efforts? > > I am keenly interested in a Cucumber tags like facility for RSpec FYI - there is an open issue on this: http://github.com/rspec/rspec-core/issues#issue/37 I'm planning to add this to 2.1, but likely not before, as I don't view it as crucial to a 2.0 release, but I do view it as something we need to take some time working on to get right. Cheers, David From phillipkoebbe at gmail.com Thu Sep 16 22:01:35 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 16 Sep 2010 21:01:35 -0500 Subject: [rspec-users] Trying to spec all models In-Reply-To: References: <4B7376D0.3030602@gmail.com> <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> <57c63afe1002102037t66c94bd5h54e4ee4fb464b9f7@mail.gmail.com> <4B73E6D6.1080802@gmail.com> Message-ID: <4C92CBFF.1080805@gmail.com> On 2010-09-16 8:24 PM, Ed Howland wrote: > On Thu, Feb 11, 2010 at 7:15 AM, Phillip Koebbe wrote: >> David Chelimsky wrote: >>> On Thu, Feb 11, 2010 at 12:13 AM, Mike Sassak wrote: >>> >>>> On Wed, Feb 10, 2010 at 10:17 PM, Phillip Koebbe >>>> wrote: >>>> >>>>> When I do >>>>> >>>>> script/spec -c -f n spec/models/**/*_spec.rb >>>>> >>>>> I get >>>>> >>>>> >>>>> /Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:283:in >>>>> `files_to_load': File or directory not found: spec/models/**/*_spec.rb >>>>> (RuntimeError) >>>>> >>>>> Yet, if I go into irb and do >>>>> >>>>> Dir.glob('spec/models/**/*_spec.rb') >>>>> >>>>> I get >>>>> >>>>> ["spec/models/county_spec.rb", "spec/models/county_user_spec.rb", >>>>> "spec/models/message_county_spec.rb", "spec/models/message_spec.rb", >>>>> "spec/models/message_user_spec.rb", "spec/models/postman_spec.rb", >>>>> "spec/models/user_spec.rb"] >>>>> >>>>> Does spec not glob? I'm working on a wrapper script and I'd like to be >>>>> able >>>>> to run all specs of a given type (controller, model, view) by passing a >>>>> single switch (-c, -m, -v). It works when I have subdirectories (as I do >>>>> with controllers), but it isn't working when I don't (as with models). >>>>> The >>>>> fact that glob picks up the files properly got me wondering, so I >>>>> thought >>>>> I'd ask. >>>>> >>>>> >>>> When running script/spec from the CLI the globbing rules will depend >>>> on the shell. Try searching Google for "bash globbing" (or whatever >>>> shell you're using). But if all you need is to run all the model >>>> specs, you could use "rake spec:models". That works well for me. >>>> >>> Or just "script/spec spec/models" >>> >>> >> Thanks for the replies. It's not as simple as I just want to spec all >> models. As I mentioned, I'm writing a wrapper script to automate some things >> that I repeatedly find myself doing or wanting to do. I am trying to do a >> very simple **/* pattern when I don't pass a pattern as an argument. I don't >> really want to have a conditional that says >> >> rake spec:models unless pattern >> >> when the rest of my code actually calls script/spec. David's suggestion >> might work though. Right now, I do >> >> file = ARGV.at(0) if ARGV.size> 0 >> file = '**/*' unless file >> > filename_partial> >> spec_path = "#{spec_path}/#{file}#{filename_partial}.rb" >> >> file can be "user", "admin/message", "admin/*", "*/message", or whatever I >> need it to be. That's why I'm looking for the easiest way to run all of a >> given type. Eventually I'm going to add support for ~, like with Cucumber >> tags, except for specs. I did this in a wrapper for Cucumber features and it >> is working out well for me. >> >> I'll keep kicking it around. I'm confident a reasonable solution is not far >> off. >> >> Peace, >> Phillip >> > Phillip, any updates on your efforts? > > I am keenly interested in a Cucumber tags like facility for RSpec > My original message was misleading. I didn't mean to imply that I was working on adding support for tags to RSpec. Rather, when you invoke cucumber on the command line, you can exclude tags by prepending a tilde (~). When I originally posted that question, I was working on the ability to pass in patterns to include or exclude. As a simple example, suppose I wanted to run all admin controller specs except those having to do with messaging, I would use -c admin/* ~message But this hasn't shown itself to be very important after all. In fact, I actually forgot that I had wanted to do it. Peace, Phillip From asimic at gmail.com Fri Sep 17 08:16:25 2010 From: asimic at gmail.com (Aleksandar Simic) Date: Fri, 17 Sep 2010 13:16:25 +0100 Subject: [rspec-users] Rspec-rails 2.0.0.beta.22 + Rails 3 don't generate spec/controllers/ Message-ID: Hello, I've set up rails 3 with rspec-rails 2.0.0.beta.22. When generating a controller, like so: rails generate controller Users new no spec/controllers get generated. However, when I do: rails generate scaffold Users name:string email:string spec/controllers gets created. These are my steps and my environment: http://pastie.org/1163699 Am I doing something obviously wrong? Thanks From dchelimsky at gmail.com Fri Sep 17 09:01:42 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Sep 2010 08:01:42 -0500 Subject: [rspec-users] Rspec-rails 2.0.0.beta.22 + Rails 3 don't generate spec/controllers/ In-Reply-To: References: Message-ID: On Sep 17, 2010, at 7:16 AM, Aleksandar Simic wrote: > Hello, > > I've set up rails 3 with rspec-rails 2.0.0.beta.22. > > When generating a controller, like so: > > rails generate controller Users new > > no spec/controllers get generated. > > However, when I do: > > rails generate scaffold Users name:string email:string > > spec/controllers gets created. > > These are my steps and my environment: > > http://pastie.org/1163699 > > Am I doing something obviously wrong? Nope. Bug. Fixed, but fix not yet released: http://github.com/rspec/rspec-rails/issues/closed#issue/205 From asimic at gmail.com Fri Sep 17 09:14:47 2010 From: asimic at gmail.com (Aleksandar Simic) Date: Fri, 17 Sep 2010 14:14:47 +0100 Subject: [rspec-users] Rspec-rails 2.0.0.beta.22 + Rails 3 don't generate spec/controllers/ In-Reply-To: References: Message-ID: On Fri, Sep 17, 2010 at 2:01 PM, David Chelimsky wrote: > > On Sep 17, 2010, at 7:16 AM, Aleksandar Simic wrote: > >> Hello, >> >> I've set up rails 3 with rspec-rails 2.0.0.beta.22. >> >> When generating a controller, like so: >> >> ? rails generate controller Users new >> >> no spec/controllers get generated. >> >> However, when I do: >> >> ? rails generate scaffold Users name:string email:string >> >> spec/controllers gets created. >> >> These are my steps and my environment: >> >> http://pastie.org/1163699 >> >> Am I doing something obviously wrong? > > Nope. Bug. Fixed, but fix not yet released: > > http://github.com/rspec/rspec-rails/issues/closed#issue/205 Thats good to know. So whats the recommended action: use 2.0.0.beta.21 or wait for 2.0.0.beta.23 to come out? Thanks From dchelimsky at gmail.com Fri Sep 17 09:37:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Sep 2010 08:37:09 -0500 Subject: [rspec-users] Rspec-rails 2.0.0.beta.22 + Rails 3 don't generate spec/controllers/ In-Reply-To: References: Message-ID: <5485DB77-96C1-44D2-92FB-446EC68B5E3E@gmail.com> On Sep 17, 2010, at 8:14 AM, Aleksandar Simic wrote: > On Fri, Sep 17, 2010 at 2:01 PM, David Chelimsky wrote: >> >> On Sep 17, 2010, at 7:16 AM, Aleksandar Simic wrote: >> >>> Hello, >>> >>> I've set up rails 3 with rspec-rails 2.0.0.beta.22. >>> >>> When generating a controller, like so: >>> >>> rails generate controller Users new >>> >>> no spec/controllers get generated. >>> >>> However, when I do: >>> >>> rails generate scaffold Users name:string email:string >>> >>> spec/controllers gets created. >>> >>> These are my steps and my environment: >>> >>> http://pastie.org/1163699 >>> >>> Am I doing something obviously wrong? >> >> Nope. Bug. Fixed, but fix not yet released: >> >> http://github.com/rspec/rspec-rails/issues/closed#issue/205 > > Thats good to know. > > So whats the recommended action: use 2.0.0.beta.21 or wait for 2.0.0.beta.23 to come out? Neither. This only impacts generators, so if I were in your shoes I'd just stick w/ beta.22 and write my controller specs by hand. If you really feel you need the generators, then you could always point your Gemfile to git: gem "rspec-rails", ">= 2.0.0.beta.22", :git => "git://github.com/rspec/rspec-rails.git" Then run "bundle update" and you'll be good to go. From ed.howland at gmail.com Fri Sep 17 10:29:19 2010 From: ed.howland at gmail.com (Ed Howland) Date: Fri, 17 Sep 2010 10:29:19 -0400 Subject: [rspec-users] Trying to spec all models In-Reply-To: <4C92CBFF.1080805@gmail.com> References: <4B7376D0.3030602@gmail.com> <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> <57c63afe1002102037t66c94bd5h54e4ee4fb464b9f7@mail.gmail.com> <4B73E6D6.1080802@gmail.com> <4C92CBFF.1080805@gmail.com> Message-ID: Thanks David and Phillip. Phillip, I was reading about RSpec 2?'s filter capabilities and it seemed that you were working on a wrapper to dynamically adding a configure block when the wrapper was passed an option. David, I see the work in 2.1 for this and it is just what I need. I want to turn off some describe blocks (via some sort of exclusion filter) normally, but optionally turn them on. First, I have to determine if (exclusion) filters applies to 1.3.0. And if they do, then I might try something like this: RSpec.configure do |c| c.exclusion_filter = { :if => lambda {|what| case what when :dont_run ENV['EXCLUDE'] == 'true' end } } end then to invoke: bin/rake spec EXCLUDE=true Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From brennon at brennonbortz.com Fri Sep 17 13:23:47 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Fri, 17 Sep 2010 18:23:47 +0100 Subject: [rspec-users] Autotest will run features, but not specs In-Reply-To: <1498A7BA-5529-422C-B68E-A844B14A6347@brennonbortz.com> References: <5EAD4227-84BA-4276-AFD1-EDC4F164E672@gmail.com> <4A619CFA-5221-4BB0-8AD5-E56B95E12D86@brennonbortz.com> <9E1AF3ED-C464-4037-A3A7-553806CD2CDB@gmail.com> <3E6D070C-266C-4354-AA54-3B9864A58EF5@brennonbortz.com> <5D6BAADD-5D54-47E0-A82D-A16DEF8AD807@brennonbortz.com> <2D455128-FFCD-4616-B3A1-678901E99CC7@gmail.com> <1498A7BA-5529-422C-B68E-A844B14A6347@brennonbortz.com> Message-ID: <3219EF68-D78D-4D46-B8D7-C9714A50D713@brennonbortz.com> On 14 Sep 2010, at 22:41, Brennon Bortz wrote: > On 27 Aug 2010, at 15:20, David Chelimsky wrote: > >> >> On Aug 27, 2010, at 8:48 AM, Brennon Bortz wrote: >> >>> On 27 Aug 2010, at 14:44, David Chelimsky wrote: >>> >>>> On Aug 27, 2010, at 8:37 AM, Brennon Bortz wrote: >>>> >>>>> On 27 Aug 2010, at 14:29, Brennon Bortz wrote: >>>>> >>>>>> On 27 Aug 2010, at 14:06, David Chelimsky wrote: >>>>>> >>>>>>> On Aug 27, 2010, at 6:47 AM, Brennon Bortz wrote: >>>>>>> >>>>>>>> Not sure what I must have bumped, but autotest won't run any specs--only features. No errors are given on startup. I've taken "export AUTOFEATURE=true" out of my ./bashrc file--now I just get a blank screen when running autotest. Adding "export RSPEC=true" to .bashrc doesn't change anything either. >>>>>>> >>>>>>> 1. Get rid of 'Autotest.add_discovery { "rails" }' from ./autotest/discover.rb. >>>>>>> 2. Add autotest-rails to the Gemfile. >>>>>>> >>>>>>> If any of the gems listed in the Gemfile have :path or :git options, you need to run "bundle exec autotest". >>>>>>> >>>>>>> HTH, >>>>>>> DavidStrange...that does work, but now autotest seems caught in an infinite loop. When I run autospec, the specs run, then the features, then the features again...and again...and again...and so on. If I run autotest as follows: "AUTOFEATURE=false autotest", I don't have the problem. Any other ideas? >>>>> And now (I haven't touched anything...seriously!), even "AUTOFEATURE=false autotest" gives me an endless loop of spec tests... >>>> >>>> (I moved your posts to the bottom so we can read them in order. Please post at the bottom or inline.) >>>> >>>> I've seen this happen when files are generated during a spec run. What's in spec/spec.opts and cucumber.yml? >>> >>> No spec.opts file, and just the default cucumber.yml file (I believe): >>> >>> <% >>> rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" >>> rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" >>> std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip" >>> %> >>> default: <%= std_opts %> features >>> wip: --tags @wip:3 --wip features >>> rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip >> >> Unless you're running cucumber with --profile rerun, this shouldn't be a problem. >> >> Do any of your specs generate files? Also, did you try both "autotest" and "bundle exec autotest" with the same results? > > Argh...this problem stopped occurring--thought I wouldn't have to deal with it again. Same setup as we've already discussed--just a loop of cucumber features. Specs are run, but only once when a file is changed, and then it's back to the features loop. I've tried both "autotest" and "bundle exec autotest". "autotest" gives me the behaviour I've described. "bundle exec autotest" yields the following error: > > :29: warning: loading in progress, circular require considered harmful - /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb > from :29:in `require' > from :29:in `require' > from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/setup.rb:1:in `' > from :29:in `require' > from :29:in `require' > from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:2:in `' > from :29:in `require' > from :29:in `require' > from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:1136:in `' > from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `load_plugins' > from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `each' > from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `block in load_plugins' > from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `load' > from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/hanna-0.1.12/lib/rubygems_plugin.rb:2:in `' > from :29:in `require' > from :29:in `require' > from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/doc_manager.rb:8:in `' > from :29:in `require' > from :29:in `require' > /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:84: warning: method redefined; discarding old gem > /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:81: warning: previous definition of gem was here > /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:116: warning: method redefined; discarding old from_gems_in > /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/source_index.rb:75: warning: previous definition of from_gems_in was here > /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:125: warning: method redefined; discarding old refresh > /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:728: warning: previous definition of refresh was here > /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:126: warning: method redefined; discarding old bin_path > /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:323: warning: previous definition of bin_path was here > /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/autotest-4.3.2/lib/autotest.rb:275: warning: (...) interpreted as grouped expression > loading autotest/cucumber_rails > Error loading Autotest style autotest/cucumber_rails (no such file to load -- autotest/rails). Aborting. > > Any ideas? Thanks! Anyone have any ideas? I'm dyin' without autotest here... :( > _ From brian.takita at gmail.com Fri Sep 17 14:52:52 2010 From: brian.takita at gmail.com (Brian Takita) Date: Fri, 17 Sep 2010 11:52:52 -0700 Subject: [rspec-users] Propagating settings to subtyped ExampleGroups In-Reply-To: <34A7131D-DF25-4960-99A8-9147424A652A@gmail.com> References: <34A7131D-DF25-4960-99A8-9147424A652A@gmail.com> Message-ID: On Wed, Sep 15, 2010 at 9:17 PM, David Chelimsky wrote: > > On Sep 14, 2010, at 11:04 AM, Brian Takita wrote: > >> On Tue, Sep 14, 2010 at 6:27 AM, David Chelimsky wrote: >>> Hey Brian - long time. Hope all is well. More below ... >> Hey David, I've been pretty busy, and things are going well. It seems >> like things are going well with you :-) >>> >>> On Sep 14, 2010, at 12:04 AM, Justin Ko wrote: >>> >>>> On Sep 14, 12:31 am, Brian Takita wrote: >>>>> Hey, rspec 2 upgrade question. >>>>> >>>>> Rspec 1.x had a class hierarchy. In a Rails project, the ExampleGroup >>>>> inherited from Test::Unit::TestCase. >>>>> That allowed me to set use_transactional_fixtures in my own >>>>> ExampleGroups and rely on inheritance for the settings to propagate. >>> >>> How are you telling rspec to load which example groups? Maybe we can accomplish the same with mixins. >> I converted the ExampleGroups into mixins, but there are some issues. >> Basically, I made ExampleGroup classes (with class methods). The class >> methods also relied on inheritance (to use super). >> There are complications with the new architecture. I'm trying to >> figure out if my architecture is "compatible" with RSpec 2.0. >>> >>>>> Now it seems like RSpec::Core::ExampleGroup no longer inherits from >>>>> Test::Unit::TestCase and there is RSpec.configure instead. >>> >>> Not instead - there was always Spec.configure - but yes, I worked with the Rails core team to make it so RSpec didn't need to depend on the Test::Unit or Minitest runners but could still get all the services in rails tests. >> True. I always preferred setting use_transactional_fixtures directly >> in the ExampleGroup because it is more straightforward (less software >> needed and less things breaking until now) and worked really well with >> the inheritance hierarchy. >> I could override use_transactional_fixtures in subclasses. >>> >>> Now we use metadata set on groups to determine when to mix in what behaviour: >>> >>> module MyExtension >>> ?... >>> end >>> >>> RSpec.configure do |c| >>> ?c.include(MyExtension, :foo => :bar) >>> end >>> >>> describe "something", :foo => :bar do >>> ?... >>> end >>> >>> In rspec-rails, that's done implicitly by matching the :type key in the metadata, which gets set before RSpec.configure is processed. ?You could do something similar if you wanted to make these inclusions work implicitly based on some other criteria like directory path, etc. >>> >>> That all make sense? If not, can you give me a clearer picture of ?your use case? >> I have different subclasses of ExampleGroup. I use instance and class >> method overriding. I also call class methods (defined in the parent or >> current class) in the ExampleGroup definitions. Cool. Btw, nice job on the redesign. I really like how things are moving toward modules and the metadata. Things look much more modular and extractable than before. > > How does your setup select which of the available ExampleGroup subclasses to instantiate in each case? The ExampleGroup base classes are registered using Spec::Example::ExampleGroupFactory.register. Of course now, it would be done in RSpec.configure. It would be nice to have the state of the boolean stored in the ExampleGroup class (I'm assuming the modules get mixed into ExampleGroup). > >> The metadata is interesting. I'm trying to figure out how module >> inheritance & metadata can be used as a substitute. >> >> Correct me if I'm wrong about my following points: >> If I were to use the metadata, I have to sort of reimplement the class >> method inheritance (for class methods from Test::Unit such as >> use_transactional_fixtures) using the metadata. >> >> If the class method is originally defined in rspec, I can somehow >> wrangle module inheritance to properly handle class methods. However, >> in this case, it's simpler with class inheritance. > > How would you see this working, given the existing architectural changes? If we can get class method propagation (with state preserved and with super) working, this should work. I started experimenting with it, but did not get a working prototype yet. I'm sortof booked for the next couple of days, but I can play around with it a bit this weekend. - Brian > >>>>> How do I have the settings in the configuration propagate to subtypes >>>>> of the ExampleGroup? >>>> describe 'I want this to be inherited' do >>>> ?before do >>>> ? ?RSpec.configure {|c| c.use_transactional_fixtures = false } >>>> ?end >> I'm surprised that would that work. I would think that Fixture loading >> would be one of the first before blocks and would occur before the >> configure statement. >> I suppose if you could somehow prepend the before block to the front >> of everything, it would work. >>>> >>>> ?context 'blah' do >>>> >>>> I would wrap it in a method if you're doing it often. >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> Thank you, >> Brian >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Sep 17 15:11:17 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Sep 2010 15:11:17 -0400 Subject: [rspec-users] Autotest will run features, but not specs In-Reply-To: <3219EF68-D78D-4D46-B8D7-C9714A50D713@brennonbortz.com> References: <5EAD4227-84BA-4276-AFD1-EDC4F164E672@gmail.com> <4A619CFA-5221-4BB0-8AD5-E56B95E12D86@brennonbortz.com> <9E1AF3ED-C464-4037-A3A7-553806CD2CDB@gmail.com> <3E6D070C-266C-4354-AA54-3B9864A58EF5@brennonbortz.com> <5D6BAADD-5D54-47E0-A82D-A16DEF8AD807@brennonbortz.com> <2D455128-FFCD-4616-B3A1-678901E99CC7@gmail.com> <1498A7BA-5529-422C-B68E-A844B14A6347@brennonbortz.com> <3219EF68-D78D-4D46-B8D7-C9714A50D713@brennonbortz.com> Message-ID: On Sep 17, 2010, at 1:23 PM, Brennon Bortz wrote: > On 14 Sep 2010, at 22:41, Brennon Bortz wrote: > >> On 27 Aug 2010, at 15:20, David Chelimsky wrote: >> >>> >>> On Aug 27, 2010, at 8:48 AM, Brennon Bortz wrote: >>> >>>> On 27 Aug 2010, at 14:44, David Chelimsky wrote: >>>> >>>>> On Aug 27, 2010, at 8:37 AM, Brennon Bortz wrote: >>>>> >>>>>> On 27 Aug 2010, at 14:29, Brennon Bortz wrote: >>>>>> >>>>>>> On 27 Aug 2010, at 14:06, David Chelimsky wrote: >>>>>>> >>>>>>>> On Aug 27, 2010, at 6:47 AM, Brennon Bortz wrote: >>>>>>>> >>>>>>>>> Not sure what I must have bumped, but autotest won't run any >>>>>>>>> specs--only features. No errors are given on startup. I've >>>>>>>>> taken "export AUTOFEATURE=true" out of my ./bashrc file--now >>>>>>>>> I just get a blank screen when running autotest. Adding >>>>>>>>> "export RSPEC=true" to .bashrc doesn't change anything either. >>>>>>>> >>>>>>>> 1. Get rid of 'Autotest.add_discovery { "rails" }' from ./ >>>>>>>> autotest/discover.rb. >>>>>>>> 2. Add autotest-rails to the Gemfile. >>>>>>>> >>>>>>>> If any of the gems listed in the Gemfile have :path or :git >>>>>>>> options, you need to run "bundle exec autotest". >>>>>>>> >>>>>>>> HTH, >>>>>>>> DavidStrange...that does work, but now autotest seems caught >>>>>>>> in an infinite loop. When I run autospec, the specs run, >>>>>>>> then the features, then the features again...and again...and >>>>>>>> again...and so on. If I run autotest as follows: >>>>>>>> "AUTOFEATURE=false autotest", I don't have the problem. Any >>>>>>>> other ideas? >>>>>> And now (I haven't touched anything...seriously!), even >>>>>> "AUTOFEATURE=false autotest" gives me an endless loop of spec >>>>>> tests... >>>>> >>>>> (I moved your posts to the bottom so we can read them in order. >>>>> Please post at the bottom or inline.) >>>>> >>>>> I've seen this happen when files are generated during a spec >>>>> run. What's in spec/spec.opts and cucumber.yml? >>>> >>>> No spec.opts file, and just the default cucumber.yml file (I >>>> believe): >>>> >>>> <% >>>> rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" >>>> rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV >>>> ['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV >>>> ['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" >>>> std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} -- >>>> strict --tags ~@wip" >>>> %> >>>> default: <%= std_opts %> features >>>> wip: --tags @wip:3 --wip features >>>> rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict >>>> --tags ~@wip >>> >>> Unless you're running cucumber with --profile rerun, this >>> shouldn't be a problem. >>> >>> Do any of your specs generate files? Also, did you try both >>> "autotest" and "bundle exec autotest" with the same results? >> >> Argh...this problem stopped occurring--thought I wouldn't have to >> deal with it again. Same setup as we've already discussed--just a >> loop of cucumber features. Specs are run, but only once when a >> file is changed, and then it's back to the features loop. I've >> tried both "autotest" and "bundle exec autotest". "autotest" gives >> me the behaviour I've described. "bundle exec autotest" yields the >> following error: >> >> :29: warning: loading in >> progress, circular require considered harmful - /Users/brennon/.rvm/ >> rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb >> from :29:in `require' >> from :29:in `require' >> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/ >> bundler-1.0.0.rc.6/lib/bundler/setup.rb:1:in `' >> from :29:in `require' >> from :29:in `require' >> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/ >> bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:2:in `> (required)>' >> from :29:in `require' >> from :29:in `require' >> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/ >> rubygems.rb:1136:in `' >> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/ >> rubygems.rb:968:in `load_plugins' >> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/ >> rubygems.rb:968:in `each' >> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/ >> rubygems.rb:976:in `block in load_plugins' >> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/ >> rubygems.rb:976:in `load' >> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/ >> hanna-0.1.12/lib/rubygems_plugin.rb:2:in `' >> from :29:in `require' >> from :29:in `require' >> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/ >> rubygems/doc_manager.rb:8:in `' >> from :29:in `require' >> from :29:in `require' >> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc. >> 6/lib/bundler/shared_helpers.rb:84: warning: method redefined; >> discarding old gem >> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc. >> 6/lib/bundler/shared_helpers.rb:81: warning: previous definition of >> gem was here >> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc. >> 6/lib/bundler/shared_helpers.rb:116: warning: method redefined; >> discarding old from_gems_in >> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/ >> source_index.rb:75: warning: previous definition of from_gems_in >> was here >> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc. >> 6/lib/bundler/shared_helpers.rb:125: warning: method redefined; >> discarding old refresh >> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb: >> 728: warning: previous definition of refresh was here >> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc. >> 6/lib/bundler/shared_helpers.rb:126: warning: method redefined; >> discarding old bin_path >> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb: >> 323: warning: previous definition of bin_path was here >> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/autotest-4.3.2/lib/ >> autotest.rb:275: warning: (...) interpreted as grouped expression >> loading autotest/cucumber_rails >> Error loading Autotest style autotest/cucumber_rails (no such file >> to load -- autotest/rails). Aborting. >> >> Any ideas? Thanks! > > Anyone have any ideas? I'm dyin' without autotest here... :( That error is coming from Cucumber. What versions of everything are you working with? From doug at emeryit.com Fri Sep 17 15:48:54 2010 From: doug at emeryit.com (Doug E.) Date: Fri, 17 Sep 2010 12:48:54 -0700 (PDT) Subject: [rspec-users] [Rails] rails view helpers, BDD, and what to mock Message-ID: Hi, I'm trying to understand BDD and proper testing technique. I'm testing a rails view helper method that checks user roles to see if a link should be shown. I'm using rails 2.3.8 and rspec version 1.3.0. My helper looks like this: # welcome_helper.rb module WelcomeHelper def manage_samples_link return nil if current_user.blank? if current_user.role?(:submitter) || current_user.role?(:reviewer) || current_user.role?(:admin) link_to "Manage Samples", manage_samples_path end end end The spec code looks like this: # welcome_helper_spec.rb require 'spec_helper' describe WelcomeHelper do %w{ submitter reviewer admin }.each do |rolename| it "should return manage samples link for user with role #{rolename}" do role = Role.new(:rolename => rolename) user = User.new(:roles => [role]) helper.stub(:current_user).and_return(user) link = %{Manage Samples} helper.manage_samples_link.should == link end end end If the above doesn't format well, here's a gist: https://gist.github.com/afd222a63193bf000ab8 My question is, What should I be testing here? I stubbed current_user, but I haven't mocked the User object and its role? method. While I understand that this is the proper place to test the User#role? method, don't I want to know that this helper is returning the link only for those the admin, submitter, and reviewer users and not for, for instance, 'editors'? If I mock out user and stub it with something like: user.stub!(:role?).and_return(true) Am I really testing anything other than the content of the link? It seems to me that there are two things to test: (1) that I get the right link; and (2) the logic; that is, that the correct users get the link And, it seems that if I don't use a User object, I don't really know whether the logic is correct or, secondarily, if some later change to the User#role? method has broken my helpers, views, etc. Is this correct? I apologize if this is too basic a question, but I'm trying to wrap my head around what rspec tests go where and how to structure them, and leave integration testing to cucumber. Thanks. Doug PS My apologies to the moderators if you've been getting spammed with different versions of this post as I've stumbled about trying to get my account set up. From myron.marston at gmail.com Fri Sep 17 21:16:11 2010 From: myron.marston at gmail.com (Myron Marston) Date: Fri, 17 Sep 2010 18:16:11 -0700 (PDT) Subject: [rspec-users] [Rails] rails view helpers, BDD, and what to mock In-Reply-To: References: Message-ID: On Sep 17, 12:48?pm, "Doug E." wrote: > Hi, > > I'm trying to understand BDD and proper testing technique. I'm testing > a rails view helper method that checks user roles to see if a link > should be shown. I'm using rails 2.3.8 and rspec version 1.3.0. ?My > helper looks like this: > > # welcome_helper.rb > module WelcomeHelper > ?def manage_samples_link > ? return nil if current_user.blank? > ? if current_user.role?(:submitter) || > ? ? ? current_user.role?(:reviewer) || > ? ? ? current_user.role?(:admin) > ? ? link_to "Manage Samples", manage_samples_path > ? end > ?end > end > > The spec code looks like this: > > # welcome_helper_spec.rb > require 'spec_helper' > > describe WelcomeHelper do > ?%w{ submitter reviewer admin }.each do |rolename| > ? it "should return manage samples link for user with role > #{rolename}" do > ? ? role = Role.new(:rolename => rolename) > ? ? user = User.new(:roles => [role]) > ? ? helper.stub(:current_user).and_return(user) > ? ? link = %{Manage Samples} > ? ? helper.manage_samples_link.should == link > ? end > ?end > end > > If the above doesn't format well, here's a gist: > > ?https://gist.github.com/afd222a63193bf000ab8 > > My question is, What should I be testing here? > > I stubbed current_user, but I haven't mocked the User object and its > role? method. While I understand that this is the proper place to test > the User#role? method, don't I want to know that this helper is > returning the link only for those the admin, submitter, and reviewer > users and not for, for instance, 'editors'? > > If I mock out user and stub it with something like: > > ?user.stub!(:role?).and_return(true) > > Am I really testing anything other than the content of the link? > > It seems to me that there are two things to test: > > (1) that I get the right link; and > (2) the logic; that is, that the correct users get the link > > And, it seems that if I don't use a User object, I don't really know > whether the logic is correct or, secondarily, if some later change to > the User#role? method has broken my helpers, views, etc. > > Is this correct? I apologize if this is too basic a question, but I'm > trying to wrap my head around what rspec tests go where and how to > structure them, and leave integration testing to cucumber. > > Thanks. > > Doug > > PS My apologies to the moderators if you've been getting spammed with > different versions of this post as I've stumbled about trying to get > my account set up. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users The presence of 3 clauses in your if statement suggests to me that you have too much business logic in this helper. I'd recommend you move that into an appropriate method on your user model: class User def can_manage_samples? [:submitter, :reviewer, :admin].any? { |r| role?(r) } end end This should not be difficult to test in your user model spec. Now your helper can be greatly simplified: module WelcomeHelper def manage_samples_link link_to "Manage Samples", manage_samples_path if current_user.try(:can_manage_samples?) end end This is far easier to test, and I believe that stubbing #can_manage_samples? is an appropriate way to do so. Your helper test just needs to test 3 cases: 1. No link should be rendered when current_user is nil. 2. No link should be rendered when current_user.can_manage_samples? returns false. 3. The link should be rendered when current_user.can_manage_samples? returns true. Note that you may want to look into something like cancan[1] to help with this (although, I've never used cancan myself). Myron [1] http://github.com/ryanb/cancan From brennon at brennonbortz.com Sat Sep 18 06:20:47 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Sat, 18 Sep 2010 11:20:47 +0100 Subject: [rspec-users] Autotest will run features, but not specs In-Reply-To: References: <5EAD4227-84BA-4276-AFD1-EDC4F164E672@gmail.com> <4A619CFA-5221-4BB0-8AD5-E56B95E12D86@brennonbortz.com> <9E1AF3ED-C464-4037-A3A7-553806CD2CDB@gmail.com> <3E6D070C-266C-4354-AA54-3B9864A58EF5@brennonbortz.com> <5D6BAADD-5D54-47E0-A82D-A16DEF8AD807@brennonbortz.com> <2D455128-FFCD-4616-B3A1-678901E99CC7@gmail.com> <1498A7BA-5529-422C-B68E-A844B14A6347@brennonbortz.com> <3219EF68-D78D-4D46-B8D7-C9714A50D713@brennonbortz.com> Message-ID: <61D9CC57-085D-4720-BCD0-90B0594B5647@brennonbortz.com> On 17 Sep 2010, at 20:11, David Chelimsky wrote: > On Sep 17, 2010, at 1:23 PM, Brennon Bortz wrote: > >> On 14 Sep 2010, at 22:41, Brennon Bortz wrote: >> >>> On 27 Aug 2010, at 15:20, David Chelimsky wrote: >>> >>>> >>>> On Aug 27, 2010, at 8:48 AM, Brennon Bortz wrote: >>>> >>>>> On 27 Aug 2010, at 14:44, David Chelimsky wrote: >>>>> >>>>>> On Aug 27, 2010, at 8:37 AM, Brennon Bortz wrote: >>>>>> >>>>>>> On 27 Aug 2010, at 14:29, Brennon Bortz wrote: >>>>>>> >>>>>>>> On 27 Aug 2010, at 14:06, David Chelimsky wrote: >>>>>>>> >>>>>>>>> On Aug 27, 2010, at 6:47 AM, Brennon Bortz wrote: >>>>>>>>> >>>>>>>>>> Not sure what I must have bumped, but autotest won't run any specs--only features. No errors are given on startup. I've taken "export AUTOFEATURE=true" out of my ./bashrc file--now I just get a blank screen when running autotest. Adding "export RSPEC=true" to .bashrc doesn't change anything either. >>>>>>>>> >>>>>>>>> 1. Get rid of 'Autotest.add_discovery { "rails" }' from ./autotest/discover.rb. >>>>>>>>> 2. Add autotest-rails to the Gemfile. >>>>>>>>> >>>>>>>>> If any of the gems listed in the Gemfile have :path or :git options, you need to run "bundle exec autotest". >>>>>>>>> >>>>>>>>> HTH, >>>>>>>>> DavidStrange...that does work, but now autotest seems caught in an infinite loop. When I run autospec, the specs run, then the features, then the features again...and again...and again...and so on. If I run autotest as follows: "AUTOFEATURE=false autotest", I don't have the problem. Any other ideas? >>>>>>> And now (I haven't touched anything...seriously!), even "AUTOFEATURE=false autotest" gives me an endless loop of spec tests... >>>>>> >>>>>> (I moved your posts to the bottom so we can read them in order. Please post at the bottom or inline.) >>>>>> >>>>>> I've seen this happen when files are generated during a spec run. What's in spec/spec.opts and cucumber.yml? >>>>> >>>>> No spec.opts file, and just the default cucumber.yml file (I believe): >>>>> >>>>> <% >>>>> rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" >>>>> rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" >>>>> std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip" >>>>> %> >>>>> default: <%= std_opts %> features >>>>> wip: --tags @wip:3 --wip features >>>>> rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip >>>> >>>> Unless you're running cucumber with --profile rerun, this shouldn't be a problem. >>>> >>>> Do any of your specs generate files? Also, did you try both "autotest" and "bundle exec autotest" with the same results? >>> >>> Argh...this problem stopped occurring--thought I wouldn't have to deal with it again. Same setup as we've already discussed--just a loop of cucumber features. Specs are run, but only once when a file is changed, and then it's back to the features loop. I've tried both "autotest" and "bundle exec autotest". "autotest" gives me the behaviour I've described. "bundle exec autotest" yields the following error: >>> >>> :29: warning: loading in progress, circular require considered harmful - /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb >>> from :29:in `require' >>> from :29:in `require' >>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/setup.rb:1:in `' >>> from :29:in `require' >>> from :29:in `require' >>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:2:in `' >>> from :29:in `require' >>> from :29:in `require' >>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:1136:in `' >>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `load_plugins' >>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `each' >>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `block in load_plugins' >>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `load' >>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/hanna-0.1.12/lib/rubygems_plugin.rb:2:in `' >>> from :29:in `require' >>> from :29:in `require' >>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/doc_manager.rb:8:in `' >>> from :29:in `require' >>> from :29:in `require' >>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:84: warning: method redefined; discarding old gem >>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:81: warning: previous definition of gem was here >>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:116: warning: method redefined; discarding old from_gems_in >>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/source_index.rb:75: warning: previous definition of from_gems_in was here >>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:125: warning: method redefined; discarding old refresh >>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:728: warning: previous definition of refresh was here >>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:126: warning: method redefined; discarding old bin_path >>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:323: warning: previous definition of bin_path was here >>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/autotest-4.3.2/lib/autotest.rb:275: warning: (...) interpreted as grouped expression >>> loading autotest/cucumber_rails >>> Error loading Autotest style autotest/cucumber_rails (no such file to load -- autotest/rails). Aborting. >>> >>> Any ideas? Thanks! >> >> Anyone have any ideas? I'm dyin' without autotest here... :( > > That error is coming from Cucumber. What versions of everything are you working with? Hi, Dave--thanks for the response. I'm using: * autotest (4.3.2) * autotest-growl (0.2.4) * cucumber (0.8.5) * cucumber-rails (0.3.2) * rspec (2.0.0.beta.20) * rspec-core (2.0.0.beta.20) * rspec-expectations (2.0.0.beta.20) * rspec-mocks (2.0.0.beta.20) * rspec-rails (2.0.0.beta.20) Thanks, again. From babarathotmail at yahoo.com Sat Sep 18 06:33:54 2010 From: babarathotmail at yahoo.com (babar shahzad) Date: Sat, 18 Sep 2010 03:33:54 -0700 (PDT) Subject: [rspec-users] is it Mailing list on github for oauth on twitter Message-ID: <334690.63394.qm@web56606.mail.re3.yahoo.com> Helo dear list members, Can you kindly confirm me that its the correct list I subscribed to. I want help in twitter oauth. I am using abraham williams' library. If something wrong, I will be very thankful if you could write me link of correct list. thanks a lot & sorry for bothering. - Babar -------------- next part -------------- An HTML attachment was scrubbed... URL: From brennon at brennonbortz.com Sat Sep 18 06:51:30 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Sat, 18 Sep 2010 11:51:30 +0100 Subject: [rspec-users] Autotest will run features, but not specs In-Reply-To: <61D9CC57-085D-4720-BCD0-90B0594B5647@brennonbortz.com> References: <5EAD4227-84BA-4276-AFD1-EDC4F164E672@gmail.com> <4A619CFA-5221-4BB0-8AD5-E56B95E12D86@brennonbortz.com> <9E1AF3ED-C464-4037-A3A7-553806CD2CDB@gmail.com> <3E6D070C-266C-4354-AA54-3B9864A58EF5@brennonbortz.com> <5D6BAADD-5D54-47E0-A82D-A16DEF8AD807@brennonbortz.com> <2D455128-FFCD-4616-B3A1-678901E99CC7@gmail.com> <1498A7BA-5529-422C-B68E-A844B14A6347@brennonbortz.com> <3219EF68-D78D-4D46-B8D7-C9714A50D713@brennonbortz.com> <61D9CC57-085D-4720-BCD0-90B0594B5647@brennonbortz.com> Message-ID: <92C8AD7E-432F-4625-8A8B-4829253E5FB7@brennonbortz.com> On 18 Sep 2010, at 11:20, Brennon Bortz wrote: > On 17 Sep 2010, at 20:11, David Chelimsky wrote: > >> On Sep 17, 2010, at 1:23 PM, Brennon Bortz wrote: >> >>> On 14 Sep 2010, at 22:41, Brennon Bortz wrote: >>> >>>> On 27 Aug 2010, at 15:20, David Chelimsky wrote: >>>> >>>>> >>>>> On Aug 27, 2010, at 8:48 AM, Brennon Bortz wrote: >>>>> >>>>>> On 27 Aug 2010, at 14:44, David Chelimsky wrote: >>>>>> >>>>>>> On Aug 27, 2010, at 8:37 AM, Brennon Bortz wrote: >>>>>>> >>>>>>>> On 27 Aug 2010, at 14:29, Brennon Bortz wrote: >>>>>>>> >>>>>>>>> On 27 Aug 2010, at 14:06, David Chelimsky wrote: >>>>>>>>> >>>>>>>>>> On Aug 27, 2010, at 6:47 AM, Brennon Bortz wrote: >>>>>>>>>> >>>>>>>>>>> Not sure what I must have bumped, but autotest won't run any specs--only features. No errors are given on startup. I've taken "export AUTOFEATURE=true" out of my ./bashrc file--now I just get a blank screen when running autotest. Adding "export RSPEC=true" to .bashrc doesn't change anything either. >>>>>>>>>> >>>>>>>>>> 1. Get rid of 'Autotest.add_discovery { "rails" }' from ./autotest/discover.rb. >>>>>>>>>> 2. Add autotest-rails to the Gemfile. >>>>>>>>>> >>>>>>>>>> If any of the gems listed in the Gemfile have :path or :git options, you need to run "bundle exec autotest". >>>>>>>>>> >>>>>>>>>> HTH, >>>>>>>>>> DavidStrange...that does work, but now autotest seems caught in an infinite loop. When I run autospec, the specs run, then the features, then the features again...and again...and again...and so on. If I run autotest as follows: "AUTOFEATURE=false autotest", I don't have the problem. Any other ideas? >>>>>>>> And now (I haven't touched anything...seriously!), even "AUTOFEATURE=false autotest" gives me an endless loop of spec tests... >>>>>>> >>>>>>> (I moved your posts to the bottom so we can read them in order. Please post at the bottom or inline.) >>>>>>> >>>>>>> I've seen this happen when files are generated during a spec run. What's in spec/spec.opts and cucumber.yml? >>>>>> >>>>>> No spec.opts file, and just the default cucumber.yml file (I believe): >>>>>> >>>>>> <% >>>>>> rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" >>>>>> rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" >>>>>> std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip" >>>>>> %> >>>>>> default: <%= std_opts %> features >>>>>> wip: --tags @wip:3 --wip features >>>>>> rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip >>>>> >>>>> Unless you're running cucumber with --profile rerun, this shouldn't be a problem. >>>>> >>>>> Do any of your specs generate files? Also, did you try both "autotest" and "bundle exec autotest" with the same results? >>>> >>>> Argh...this problem stopped occurring--thought I wouldn't have to deal with it again. Same setup as we've already discussed--just a loop of cucumber features. Specs are run, but only once when a file is changed, and then it's back to the features loop. I've tried both "autotest" and "bundle exec autotest". "autotest" gives me the behaviour I've described. "bundle exec autotest" yields the following error: >>>> >>>> :29: warning: loading in progress, circular require considered harmful - /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb >>>> from :29:in `require' >>>> from :29:in `require' >>>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/setup.rb:1:in `' >>>> from :29:in `require' >>>> from :29:in `require' >>>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:2:in `' >>>> from :29:in `require' >>>> from :29:in `require' >>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:1136:in `' >>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `load_plugins' >>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `each' >>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `block in load_plugins' >>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `load' >>>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/hanna-0.1.12/lib/rubygems_plugin.rb:2:in `' >>>> from :29:in `require' >>>> from :29:in `require' >>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/doc_manager.rb:8:in `' >>>> from :29:in `require' >>>> from :29:in `require' >>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:84: warning: method redefined; discarding old gem >>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:81: warning: previous definition of gem was here >>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:116: warning: method redefined; discarding old from_gems_in >>>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/source_index.rb:75: warning: previous definition of from_gems_in was here >>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:125: warning: method redefined; discarding old refresh >>>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:728: warning: previous definition of refresh was here >>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:126: warning: method redefined; discarding old bin_path >>>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:323: warning: previous definition of bin_path was here >>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/autotest-4.3.2/lib/autotest.rb:275: warning: (...) interpreted as grouped expression >>>> loading autotest/cucumber_rails >>>> Error loading Autotest style autotest/cucumber_rails (no such file to load -- autotest/rails). Aborting. >>>> >>>> Any ideas? Thanks! >>> >>> Anyone have any ideas? I'm dyin' without autotest here... :( >> >> That error is coming from Cucumber. What versions of everything are you working with? > > Hi, Dave--thanks for the response. I'm using: > > * autotest (4.3.2) > * autotest-growl (0.2.4) > * cucumber (0.8.5) > * cucumber-rails (0.3.2) > * rspec (2.0.0.beta.20) > * rspec-core (2.0.0.beta.20) > * rspec-expectations (2.0.0.beta.20) > * rspec-mocks (2.0.0.beta.20) > * rspec-rails (2.0.0.beta.20) > > Thanks, again. Turns out that uninstalling ZenTest, autotest (shouldn't there be a conflict between these two?), autotest-rails, autotest-growl, cucumber-rails, and re-"bundle install"ing fixed the problem. No cucumber errors on "bundle exec autotest", and RSpec specs are now picked up when using either "bundle exec autotest", or just plain ol' "autotest". From brennon at brennonbortz.com Sat Sep 18 08:01:30 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Sat, 18 Sep 2010 13:01:30 +0100 Subject: [rspec-users] Testing forms Message-ID: I'm testing a view that renders a form to edit an object. I'd like to test that the form correctly populates the form with the object's attributes' current values. I tried several variations on mock_model and stub_model in order to maintain view/model separation--for instance: require "spec_helper" describe "informational_widget_frameworks/edit.html.erb" do describe "rendered items" do before(:each) do @iwf = mock_model(InformationalWidgetFramework, :heading => "IWF Heading", ).as_null_object assign(:informational_widget_framework, @iwf) render end it "should show 'IWF Heading'" do rendered.should include("IWF Heading") end end end However, when the view is rendered, the value for the text_field bound to @informational_widget_framework.heading is populated with "InformationalWidgetFramework_1025". I've tried changing the example to: it "should show 'IWF Heading'" do @iwf.should_receive(:heading).and_return("IWF Heading") rendered.should include("IWF Heading") end But, this gives the same results. Using stub_model similarly doesn't populate the form fields with anything at all. The only way I can get these examples to pass is by using the following for my before block: before(:each) do @iwf = InformationalWidgetFramework.create( :heading => "IWF Heading", ) assign(:informational_widget_framework, @iwf) render end I'm clearly missing something here...can someone clue me in? Thanks. Brennon Bortz Software Researcher Dundalk Institute of Technology brennon.bortz at casala.ie Ph.D. Researcher & Composer - Sonic Arts Research Centre Queen's University, Belfast brennon at brennonbortz.com / bbortz01 at qub.ac.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Sep 18 10:28:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Sep 2010 09:28:45 -0500 Subject: [rspec-users] is it Mailing list on github for oauth on twitter In-Reply-To: <334690.63394.qm@web56606.mail.re3.yahoo.com> References: <334690.63394.qm@web56606.mail.re3.yahoo.com> Message-ID: On Sep 18, 2010, at 5:33 AM, babar shahzad wrote: > > Helo dear list members, > > Can you kindly confirm me that its the correct list I subscribed to. I want help in twitter oauth. I am using abraham williams' library. If something wrong, I will be very thankful if you could write me link of correct list. This is not the correct list. I don't see any mailing list for this, specifically, but if you go to the github wiki for the library you're using (http://github.com/abraham/twitteroauth/wiki), then you'll see some useful information that might help you in your search. Good luck, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Sep 18 10:29:41 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Sep 2010 09:29:41 -0500 Subject: [rspec-users] Autotest will run features, but not specs In-Reply-To: <92C8AD7E-432F-4625-8A8B-4829253E5FB7@brennonbortz.com> References: <5EAD4227-84BA-4276-AFD1-EDC4F164E672@gmail.com> <4A619CFA-5221-4BB0-8AD5-E56B95E12D86@brennonbortz.com> <9E1AF3ED-C464-4037-A3A7-553806CD2CDB@gmail.com> <3E6D070C-266C-4354-AA54-3B9864A58EF5@brennonbortz.com> <5D6BAADD-5D54-47E0-A82D-A16DEF8AD807@brennonbortz.com> <2D455128-FFCD-4616-B3A1-678901E99CC7@gmail.com> <1498A7BA-5529-422C-B68E-A844B14A6347@brennonbortz.com> <3219EF68-D78D-4D46-B8D7-C9714A50D713@brennonbortz.com> <61D9CC57-085D-4720-BCD0-90B0594B5647@brennonbortz.com> <92C8AD7E-432F-4625-8A8B-4829253E5FB7@brennonbortz.com> Message-ID: <3A43102A-5544-4BBE-8323-93F1EE342DD3@gmail.com> On Sep 18, 2010, at 5:51 AM, Brennon Bortz wrote: > On 18 Sep 2010, at 11:20, Brennon Bortz wrote: > >> On 17 Sep 2010, at 20:11, David Chelimsky wrote: >> >>> On Sep 17, 2010, at 1:23 PM, Brennon Bortz wrote: >>> >>>> On 14 Sep 2010, at 22:41, Brennon Bortz wrote: >>>> >>>>> On 27 Aug 2010, at 15:20, David Chelimsky wrote: >>>>> >>>>>> >>>>>> On Aug 27, 2010, at 8:48 AM, Brennon Bortz wrote: >>>>>> >>>>>>> On 27 Aug 2010, at 14:44, David Chelimsky wrote: >>>>>>> >>>>>>>> On Aug 27, 2010, at 8:37 AM, Brennon Bortz wrote: >>>>>>>> >>>>>>>>> On 27 Aug 2010, at 14:29, Brennon Bortz wrote: >>>>>>>>> >>>>>>>>>> On 27 Aug 2010, at 14:06, David Chelimsky wrote: >>>>>>>>>> >>>>>>>>>>> On Aug 27, 2010, at 6:47 AM, Brennon Bortz wrote: >>>>>>>>>>> >>>>>>>>>>>> Not sure what I must have bumped, but autotest won't run any specs--only features. No errors are given on startup. I've taken "export AUTOFEATURE=true" out of my ./bashrc file--now I just get a blank screen when running autotest. Adding "export RSPEC=true" to .bashrc doesn't change anything either. >>>>>>>>>>> >>>>>>>>>>> 1. Get rid of 'Autotest.add_discovery { "rails" }' from ./autotest/discover.rb. >>>>>>>>>>> 2. Add autotest-rails to the Gemfile. >>>>>>>>>>> >>>>>>>>>>> If any of the gems listed in the Gemfile have :path or :git options, you need to run "bundle exec autotest". >>>>>>>>>>> >>>>>>>>>>> HTH, >>>>>>>>>>> DavidStrange...that does work, but now autotest seems caught in an infinite loop. When I run autospec, the specs run, then the features, then the features again...and again...and again...and so on. If I run autotest as follows: "AUTOFEATURE=false autotest", I don't have the problem. Any other ideas? >>>>>>>>> And now (I haven't touched anything...seriously!), even "AUTOFEATURE=false autotest" gives me an endless loop of spec tests... >>>>>>>> >>>>>>>> (I moved your posts to the bottom so we can read them in order. Please post at the bottom or inline.) >>>>>>>> >>>>>>>> I've seen this happen when files are generated during a spec run. What's in spec/spec.opts and cucumber.yml? >>>>>>> >>>>>>> No spec.opts file, and just the default cucumber.yml file (I believe): >>>>>>> >>>>>>> <% >>>>>>> rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" >>>>>>> rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" >>>>>>> std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip" >>>>>>> %> >>>>>>> default: <%= std_opts %> features >>>>>>> wip: --tags @wip:3 --wip features >>>>>>> rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip >>>>>> >>>>>> Unless you're running cucumber with --profile rerun, this shouldn't be a problem. >>>>>> >>>>>> Do any of your specs generate files? Also, did you try both "autotest" and "bundle exec autotest" with the same results? >>>>> >>>>> Argh...this problem stopped occurring--thought I wouldn't have to deal with it again. Same setup as we've already discussed--just a loop of cucumber features. Specs are run, but only once when a file is changed, and then it's back to the features loop. I've tried both "autotest" and "bundle exec autotest". "autotest" gives me the behaviour I've described. "bundle exec autotest" yields the following error: >>>>> >>>>> :29: warning: loading in progress, circular require considered harmful - /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb >>>>> from :29:in `require' >>>>> from :29:in `require' >>>>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/setup.rb:1:in `' >>>>> from :29:in `require' >>>>> from :29:in `require' >>>>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:2:in `' >>>>> from :29:in `require' >>>>> from :29:in `require' >>>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:1136:in `' >>>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `load_plugins' >>>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:968:in `each' >>>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `block in load_plugins' >>>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:976:in `load' >>>>> from /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/hanna-0.1.12/lib/rubygems_plugin.rb:2:in `' >>>>> from :29:in `require' >>>>> from :29:in `require' >>>>> from /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/doc_manager.rb:8:in `' >>>>> from :29:in `require' >>>>> from :29:in `require' >>>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:84: warning: method redefined; discarding old gem >>>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:81: warning: previous definition of gem was here >>>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:116: warning: method redefined; discarding old from_gems_in >>>>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/source_index.rb:75: warning: previous definition of from_gems_in was here >>>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:125: warning: method redefined; discarding old refresh >>>>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:728: warning: previous definition of refresh was here >>>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at global/gems/bundler-1.0.0.rc.6/lib/bundler/shared_helpers.rb:126: warning: method redefined; discarding old bin_path >>>>> /Users/brennon/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:323: warning: previous definition of bin_path was here >>>>> /Users/brennon/.rvm/gems/ruby-1.9.2-p0 at stan/gems/autotest-4.3.2/lib/autotest.rb:275: warning: (...) interpreted as grouped expression >>>>> loading autotest/cucumber_rails >>>>> Error loading Autotest style autotest/cucumber_rails (no such file to load -- autotest/rails). Aborting. >>>>> >>>>> Any ideas? Thanks! >>>> >>>> Anyone have any ideas? I'm dyin' without autotest here... :( >>> >>> That error is coming from Cucumber. What versions of everything are you working with? >> >> Hi, Dave--thanks for the response. I'm using: >> >> * autotest (4.3.2) >> * autotest-growl (0.2.4) >> * cucumber (0.8.5) >> * cucumber-rails (0.3.2) >> * rspec (2.0.0.beta.20) >> * rspec-core (2.0.0.beta.20) >> * rspec-expectations (2.0.0.beta.20) >> * rspec-mocks (2.0.0.beta.20) >> * rspec-rails (2.0.0.beta.20) >> >> Thanks, again. > > Turns out that uninstalling ZenTest, autotest (shouldn't there be a conflict between these two?), autotest-rails, autotest-growl, cucumber-rails, and re-"bundle install"ing fixed the problem. No cucumber errors on "bundle exec autotest", and RSpec specs are now picked up when using either "bundle exec autotest", or just plain ol' "autotest". Well that must be satisfying and frustrating at the same time :) Glad you got it working. Cheers, David From dchelimsky at gmail.com Sat Sep 18 10:32:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Sep 2010 09:32:05 -0500 Subject: [rspec-users] Testing forms In-Reply-To: References: Message-ID: <75AA24F3-5EFA-4683-A49A-E6D2A2C334DC@gmail.com> On Sep 18, 2010, at 7:01 AM, Brennon Bortz wrote: > I'm testing a view that renders a form to edit an object. I'd like to test that the form correctly populates the form with the object's attributes' current values. I tried several variations on mock_model and stub_model in order to maintain view/model separation--for instance: > > require "spec_helper" > > describe "informational_widget_frameworks/edit.html.erb" do > describe "rendered items" do > before(:each) do > @iwf = mock_model(InformationalWidgetFramework, > :heading => "IWF Heading", > ).as_null_object > assign(:informational_widget_framework, @iwf) > render > end > > it "should show 'IWF Heading'" do > rendered.should include("IWF Heading") > end > end > end > > However, when the view is rendered, the value for the text_field bound to @informational_widget_framework.heading is populated with "InformationalWidgetFramework_1025". I've tried changing the example to: > > it "should show 'IWF Heading'" do > @iwf.should_receive(:heading).and_return("IWF Heading") > rendered.should include("IWF Heading") > end > > But, this gives the same results. Using stub_model similarly doesn't populate the form fields with anything at all. The only way I can get these examples to pass is by using the following for my before block: > > before(:each) do > @iwf = InformationalWidgetFramework.create( > :heading => "IWF Heading", > ) > > assign(:informational_widget_framework, @iwf) > render > end > > I'm clearly missing something here...can someone clue me in? What is the view using to render this field? Also, what versions? There was an as_null_object + rails 3 bug in beta.20 that got fixed in beta.22. From doug at emeryit.com Sat Sep 18 14:52:31 2010 From: doug at emeryit.com (Doug E.) Date: Sat, 18 Sep 2010 11:52:31 -0700 (PDT) Subject: [rspec-users] [Rails] rails view helpers, BDD, and what to mock In-Reply-To: References: Message-ID: On Sep 17, 9:16?pm, Myron Marston wrote: > On Sep 17, 12:48?pm, "Doug E." wrote: > > > > > > > Hi, > > > I'm trying to understand BDD and proper testing technique. I'm testing > > a rails view helper method that checks user roles to see if a link > > should be shown. I'm using rails 2.3.8 and rspec version 1.3.0. ?My > > helper looks like this: > > > # welcome_helper.rb > > module WelcomeHelper > > ?def manage_samples_link > > ? return nil if current_user.blank? > > ? if current_user.role?(:submitter) || > > ? ? ? current_user.role?(:reviewer) || > > ? ? ? current_user.role?(:admin) > > ? ? link_to "Manage Samples", manage_samples_path > > ? end > > ?end > > end > > > The spec code looks like this: > > > # welcome_helper_spec.rb > > require 'spec_helper' > > > describe WelcomeHelper do > > ?%w{ submitter reviewer admin }.each do |rolename| > > ? it "should return manage samples link for user with role > > #{rolename}" do > > ? ? role = Role.new(:rolename => rolename) > > ? ? user = User.new(:roles => [role]) > > ? ? helper.stub(:current_user).and_return(user) > > ? ? link = %{Manage Samples} > > ? ? helper.manage_samples_link.should == link > > ? end > > ?end > > end > > > If the above doesn't format well, here's a gist: > > > ?https://gist.github.com/afd222a63193bf000ab8 > > > My question is, What should I be testing here? > > > I stubbed current_user, but I haven't mocked the User object and its > > role? method. While I understand that this is the proper place to test > > the User#role? method, don't I want to know that this helper is > > returning the link only for those the admin, submitter, and reviewer > > users and not for, for instance, 'editors'? > > > If I mock out user and stub it with something like: > > > ?user.stub!(:role?).and_return(true) > > > Am I really testing anything other than the content of the link? > > > It seems to me that there are two things to test: > > > (1) that I get the right link; and > > (2) the logic; that is, that the correct users get the link > > > And, it seems that if I don't use a User object, I don't really know > > whether the logic is correct or, secondarily, if some later change to > > the User#role? method has broken my helpers, views, etc. > > > Is this correct? I apologize if this is too basic a question, but I'm > > trying to wrap my head around what rspec tests go where and how to > > structure them, and leave integration testing to cucumber. > > > Thanks. > > > Doug > > > PS My apologies to the moderators if you've been getting spammed with > > different versions of this post as I've stumbled about trying to get > > my account set up. > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > The presence of 3 clauses in your if statement suggests to me that you > have too much business logic in this helper. ?I'd recommend you move > that into an appropriate method on your user model: > > class User > ? def can_manage_samples? > ? ? [:submitter, :reviewer, :admin].any? { |r| role?(r) } > ? end > end > > This should not be difficult to test in your user model spec. > > Now your helper can be greatly simplified: > > module WelcomeHelper > ?def manage_samples_link > ? link_to "Manage Samples", manage_samples_path if > current_user.try(:can_manage_samples?) > ?end > end > > This is far easier to test, and I believe that stubbing > #can_manage_samples? is an appropriate way to do so. ?Your helper test > just needs to test 3 cases: > > 1. ?No link should be rendered when current_user is nil. > 2. ?No link should be rendered when current_user.can_manage_samples? > returns false. > 3. ?The link should be rendered when current_user.can_manage_samples? > returns true. > > Note that you may want to look into something like cancan[1] to help > with this (although, I've never used cancan myself). > > Myron > > [1]http://github.com/ryanb/cancan > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Hi Myron, I believe I understand what you're suggesting. My code now looks like this: # app/models/user.rb class User < ActiveRecord::Base has_and_belongs_to_many :roles # stuff cut out for brevity def role?(role) roles.detect { |r| r.rolename == role.to_s } end def can_manage_samples? [ :submitter, :reviewer, :admin ].any? { |r| role? r } end end # app/helpers/welcome_helper.rb module WelcomeHelper def manage_samples_link if current_user.try(:can_manage_samples?) link_to "Manage Samples", manage_samples_path end end end # spec/helpers/welcome_helper_spec.rb require 'spec_helper' describe WelcomeHelper do context "Manage Samples link" do it "should not return manage_samples_link for nil user" do helper.stub(:current_user).and_return(nil) helper.manage_samples_link.should be_nil end it "should not return manage_samples_link for role-less user" do user = mock_model(User) user.stub(:can_manage_samples?).and_return(false) helper.stub(:current_user).and_return(user) helper.manage_samples_link.should be_nil end it "should return manage_samples_link for permitted user" do user = mock_model(User) user.stub(:can_manage_samples?).and_return(true) helper.stub(:current_user).and_return(user) link = %{Manage Samples} helper.manage_samples_link.should == link end end end Here's how I understand this: With a mocked User#can_manage_samples? method, the test focuses not on the User class code, which should be tested at the model level. What this test says is, 'If User#can_manage_samples? is working correctly, then the correct users will see the link. What happens if when the app is in production and I've forgotten writing this test, I'm told that some user who should be authorized to is not seeing this link? The view test will still be passing because I've told the User object to return what I want it to. Is the idea that I should return to my integration tests and move back down through the stack to isolate the problem? It seems to me that the really challenging part of BDD/TDD is learning the boundaries of what's being tested and writing code that is testable. I appreciate your help, very much. As for CanCan, I am in fact using it, and based on this exchange, if I wanted to use CanCan for determining whether to print this link, I would set up the test up in the following way. Since CanCan adds, among other methods, a 'can?' method which is included in the controller and available to helpers and views, I would have the following: # app/helpers/welcome_helper.rb module WelcomeHelper def manage_samples_link link_to "Manage Samples", manage_samples_path if can? :alter, Sample end end # spec/helpers/welcome_helper_spec.rb require 'spec_helper' describe WelcomeHelper do context "Manage Samples link" do it "should not return manage_samples_link for no or unauthorized user" do helper.should_receive(:can?).with(:alter, Sample).and_return(false) helper.manage_samples_link.should be_nil end it "should return manage_samples_link for authorized user" do helper.should_receive(:can?).with(:alter, Sample).and_return(true) link = %{Manage Samples} helper.manage_samples_link.should == link end end end My CanCan Ability implementation handles the case of a nil user, creating an empty User object, as ryanb shows in his examples. The reason I'm using roles and not CanCan for rendering this link and navigating to the management page is off-topic, but it is this: What I want to do is determine whether a user in general can do something more than perform the :read action on a Sample, like :submit, :edit, :delete, and so on. CanCan works at the class or instance level, and while reviewers and admins can do stuff to any Sample, submitters can only do stuff to certain samples, the ones they created. I don't want to hit the database to find out whether a submitter has created any samples. I just want all users who can do stuff to Samples to be able to get to the Manage Samples page. So I would create a general "do stuff to samples" action and give submitters, reviewers, and admins authorization to it. I call it :alter, because :manage is a special CanCan action that maps to any action (e.g., admins `can :manage, User'). But, I decided, in this case I'm just interested in a class of users. If down the line I realize I need something more complex for allowing access to this page, then I can add it. Again, thanks. Doug From myron.marston at gmail.com Sat Sep 18 15:31:15 2010 From: myron.marston at gmail.com (Myron Marston) Date: Sat, 18 Sep 2010 12:31:15 -0700 (PDT) Subject: [rspec-users] [Rails] rails view helpers, BDD, and what to mock In-Reply-To: References: Message-ID: On Sep 18, 11:52?am, "Doug E." wrote: > On Sep 17, 9:16?pm, Myron Marston wrote: > > > > > > > On Sep 17, 12:48?pm, "Doug E." wrote: > > > > Hi, > > > > I'm trying to understand BDD and proper testing technique. I'm testing > > > a rails view helper method that checks user roles to see if a link > > > should be shown. I'm using rails 2.3.8 and rspec version 1.3.0. ?My > > > helper looks like this: > > > > # welcome_helper.rb > > > module WelcomeHelper > > > ?def manage_samples_link > > > ? return nil if current_user.blank? > > > ? if current_user.role?(:submitter) || > > > ? ? ? current_user.role?(:reviewer) || > > > ? ? ? current_user.role?(:admin) > > > ? ? link_to "Manage Samples", manage_samples_path > > > ? end > > > ?end > > > end > > > > The spec code looks like this: > > > > # welcome_helper_spec.rb > > > require 'spec_helper' > > > > describe WelcomeHelper do > > > ?%w{ submitter reviewer admin }.each do |rolename| > > > ? it "should return manage samples link for user with role > > > #{rolename}" do > > > ? ? role = Role.new(:rolename => rolename) > > > ? ? user = User.new(:roles => [role]) > > > ? ? helper.stub(:current_user).and_return(user) > > > ? ? link = %{Manage Samples} > > > ? ? helper.manage_samples_link.should == link > > > ? end > > > ?end > > > end > > > > If the above doesn't format well, here's a gist: > > > > ?https://gist.github.com/afd222a63193bf000ab8 > > > > My question is, What should I be testing here? > > > > I stubbed current_user, but I haven't mocked the User object and its > > > role? method. While I understand that this is the proper place to test > > > the User#role? method, don't I want to know that this helper is > > > returning the link only for those the admin, submitter, and reviewer > > > users and not for, for instance, 'editors'? > > > > If I mock out user and stub it with something like: > > > > ?user.stub!(:role?).and_return(true) > > > > Am I really testing anything other than the content of the link? > > > > It seems to me that there are two things to test: > > > > (1) that I get the right link; and > > > (2) the logic; that is, that the correct users get the link > > > > And, it seems that if I don't use a User object, I don't really know > > > whether the logic is correct or, secondarily, if some later change to > > > the User#role? method has broken my helpers, views, etc. > > > > Is this correct? I apologize if this is too basic a question, but I'm > > > trying to wrap my head around what rspec tests go where and how to > > > structure them, and leave integration testing to cucumber. > > > > Thanks. > > > > Doug > > > > PS My apologies to the moderators if you've been getting spammed with > > > different versions of this post as I've stumbled about trying to get > > > my account set up. > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > The presence of 3 clauses in your if statement suggests to me that you > > have too much business logic in this helper. ?I'd recommend you move > > that into an appropriate method on your user model: > > > class User > > ? def can_manage_samples? > > ? ? [:submitter, :reviewer, :admin].any? { |r| role?(r) } > > ? end > > end > > > This should not be difficult to test in your user model spec. > > > Now your helper can be greatly simplified: > > > module WelcomeHelper > > ?def manage_samples_link > > ? link_to "Manage Samples", manage_samples_path if > > current_user.try(:can_manage_samples?) > > ?end > > end > > > This is far easier to test, and I believe that stubbing > > #can_manage_samples? is an appropriate way to do so. ?Your helper test > > just needs to test 3 cases: > > > 1. ?No link should be rendered when current_user is nil. > > 2. ?No link should be rendered when current_user.can_manage_samples? > > returns false. > > 3. ?The link should be rendered when current_user.can_manage_samples? > > returns true. > > > Note that you may want to look into something like cancan[1] to help > > with this (although, I've never used cancan myself). > > > Myron > > > [1]http://github.com/ryanb/cancan > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > Hi Myron, > > I believe I understand what you're suggesting. My code now looks like > this: > > # app/models/user.rb > ? class User < ActiveRecord::Base > > ? ? has_and_belongs_to_many :roles > > ? ? # stuff cut out for brevity > > ? ? def role?(role) > ? ? ? roles.detect { |r| r.rolename == role.to_s } > ? ? end > > ? ? def can_manage_samples? > ? ? ? [ :submitter, :reviewer, :admin ].any? { |r| role? r } > ? ? end > ? end > > # app/helpers/welcome_helper.rb > ? module WelcomeHelper > ? ? def manage_samples_link > ? ? ? if current_user.try(:can_manage_samples?) > ? ? ? ? link_to "Manage Samples", manage_samples_path > ? ? ? end > ? ? end > ? end > > # spec/helpers/welcome_helper_spec.rb > ? require 'spec_helper' > > ? describe WelcomeHelper do > > ? ? context "Manage Samples link" do > ? ? ? it "should not return manage_samples_link for nil user" do > ? ? ? ? helper.stub(:current_user).and_return(nil) > ? ? ? ? helper.manage_samples_link.should be_nil > ? ? ? end > > ? ? ? it "should not return manage_samples_link for role-less user" do > ? ? ? ? user = mock_model(User) > ? ? ? ? user.stub(:can_manage_samples?).and_return(false) > ? ? ? ? helper.stub(:current_user).and_return(user) > ? ? ? ? helper.manage_samples_link.should be_nil > ? ? ? end > > ? ? ? it "should return manage_samples_link for permitted user" do > ? ? ? ? user = mock_model(User) > ? ? ? ? user.stub(:can_manage_samples?).and_return(true) > ? ? ? ? helper.stub(:current_user).and_return(user) > ? ? ? ? link = %{Manage Samples} > ? ? ? ? helper.manage_samples_link.should == link > ? ? ? end > ? ? end > ? end > > Here's how I understand this: With a mocked User#can_manage_samples? > method, the test focuses not on the User class code, which should be > tested at the model level. What this test says is, 'If > User#can_manage_samples? is working correctly, then the correct users > will see the link. > > What happens if when the app is in production and I've forgotten > writing this test, I'm told that some user who should be authorized to > is not seeing this link? The view test will still be passing because > I've told the User object to return what I want it to. Is the idea > that I should return to my integration tests and move back down > through the stack to isolate the problem? > > It seems to me that the really challenging part of BDD/TDD is learning > the boundaries of what's being tested and writing code that is > testable. I appreciate your help, very much. > > As for CanCan, I am in fact using it, and based on this exchange, if I > wanted to use CanCan for determining whether to print this link, I > would set up the test up in the following way. Since CanCan adds, > among other methods, a 'can?' method which is included in the > controller and available to helpers and views, I would have the > following: > > # app/helpers/welcome_helper.rb > module WelcomeHelper > ? def manage_samples_link > ? ? link_to "Manage Samples", manage_samples_path if can? :alter, > Sample > ? end > end > > # spec/helpers/welcome_helper_spec.rb > require 'spec_helper' > > describe WelcomeHelper do > ? context "Manage Samples link" do > ? ? it "should not return manage_samples_link for no or unauthorized > user" do > ? ? ? helper.should_receive(:can?).with(:alter, > Sample).and_return(false) > ? ? ? helper.manage_samples_link.should be_nil > ? ? end > > ? ? it "should return manage_samples_link for authorized user" do > ? ? ? helper.should_receive(:can?).with(:alter, > Sample).and_return(true) > ? ? ? link = %{Manage Samples} > ? ? ? helper.manage_samples_link.should == link > ? ? end > ? end > end > > My CanCan Ability implementation handles the case of a nil user, > creating an empty User object, as ryanb shows in his examples. > > The reason I'm using roles and not CanCan for rendering this link and > navigating to the management page is off-topic, but it is this: > > What I want to do is determine whether a user in general can do > something more than perform the :read action on a Sample, like > :submit, :edit, :delete, and so on. CanCan works at the class or > instance level, and while reviewers and admins can do stuff to any > Sample, submitters can only do stuff to certain samples, the ones they > created. I don't want to hit the database to find out whether a > submitter has created any samples. I just want all users who can > do stuff to Samples to be able to get to the Manage Samples page. > > So I would create a general "do stuff to samples" action and > give submitters, reviewers, and admins authorization to it. I call it > :alter, because :manage is a special CanCan action that maps to any > action (e.g., admins `can :manage, User'). > > But, I decided, in this case I'm just interested in a class of > users. If down the line I realize I need something more complex for > allowing access to this page, then I can add it. > > Again, thanks. > > Doug > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > What this test says is, 'If User#can_manage_samples? is working > correctly, then the correct users will see the link. That's one way to say it, but I'd rephrase it a bit. The specs are testing the following behavior: only users who are allowed to manage samples get the "manage samples" link. I don't think the helper, or its specs, should have any knowledge of the logic that determines whether or not a user is allowed to manage samples. You've decoupled your helper and its specs from this logic, so that this logic can be implemented and tested separately, and the helper specs won't break if/ when you need to change the logic. Your tests are less brittle now. > What happens if when the app is in production and I've forgotten > writing this test, I'm told that some user who should be authorized to > is not seeing this link? The view test will still be passing because > I've told the User object to return what I want it to. Is the idea > that I should return to my integration tests and move back down > through the stack to isolate the problem? Hopefully you have integration tests, and moving down the stack is one easy way to find the problem. The fact that the helper spec passes, even though the feature doesn't quite work right, doesn't bother me at all--I view the helper spec as being an isolated unit test for the helper. And looking at the helper in isolation, it's still working right. The bug would be in the logic of User#can_manage_samples?, and you would want to update the user spec to have a test for this new case, and update the method appropriately. It's good when a bug causes a test failure, but it's not good when a bug in a single place causes multiple test failures. I strive, as much as possible, to design my code and test suite so that a bug or logic change will cause at most 2 test failures: 1 failure in the appropriate unit test (often a model spec, but it could be a controller, view, helper or some other spec), and 1 failure in an integration test. Having lots of test failures would just slow me down. I don't really have a comment on your CanCan stuff--I haven't used it myself, but I definitely intend to one of these days :). Myron From me at jbrains.ca Sun Sep 19 05:53:10 2010 From: me at jbrains.ca (J. B. Rainsberger) Date: Sun, 19 Sep 2010 06:53:10 -0300 Subject: [rspec-users] [Rails] rails view helpers, BDD, and what to mock In-Reply-To: References: Message-ID: On Fri, Sep 17, 2010 at 16:48, Doug E. wrote: > I'm trying to understand BDD and proper testing technique. I'm testing > a rails view helper method that checks user roles to see if a link > should be shown. I'm using rails 2.3.8 and rspec version 1.3.0. My > helper looks like this: > > # welcome_helper.rb > module WelcomeHelper > def manage_samples_link > return nil if current_user.blank? > if current_user.role?(:submitter) || > current_user.role?(:reviewer) || > current_user.role?(:admin) > link_to "Manage Samples", manage_samples_path > end > end > end > Your helper method depends on the user currently logged in, but hardwires itself to how you have implemented "current user". I'd prefer to make the dependency explicit, not just because that makes checking the behavior easier. module WelcomeHelper def manage_samples_link manage_samples_link_for_user(current_user) end end I think you'll find stubbing the :user parameter here must easier than stubbing Rails' #current_user method. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmymartin at gmail.com Sun Sep 19 08:37:43 2010 From: jimmymartin at gmail.com (James Martin) Date: Sun, 19 Sep 2010 22:37:43 +1000 Subject: [rspec-users] is it Mailing list on github for oauth on twitter In-Reply-To: <334690.63394.qm@web56606.mail.re3.yahoo.com> References: <334690.63394.qm@web56606.mail.re3.yahoo.com> Message-ID: On Sat, Sep 18, 2010 at 8:33 PM, babar shahzad wrote: > > Helo dear list members, > > Can you kindly confirm me that its the correct list I subscribed to. I want > help in twitter oauth. I am using abraham williams' library. If something > wrong, I will be very thankful if you could write me link of correct list. > > thanks a lot & sorry for bothering. > - Babar > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I don't think there's a mailing list specifically for the Abraham library but you might have some luck on the Twitter Developers list: http://groups.google.com/group/twitter-development-talk Thanks, James. -------------- next part -------------- An HTML attachment was scrubbed... URL: From desantis.maurizio at gmail.com Sun Sep 19 05:38:22 2010 From: desantis.maurizio at gmail.com (Maurizio De Santis) Date: Sun, 19 Sep 2010 02:38:22 -0700 (PDT) Subject: [rspec-users] How to use RSpec 2 with Sinatra 1.0 Message-ID: <4e0756c6-4b40-4d83-b01e-98b23d8df937@m16g2000vbs.googlegroups.com> Hello, I am trying to use RSpec 2 with a Sinatra 1.0 application, but I have no idea about whether they are compatible or not. I tried this: in $SINATRA_APP_ROOT/app.rb: require 'sinatra' set :app_file, __FILE__ set :root, File.dirname(__FILE__) set :config_path, File.join(Sinatra::Application.root, 'config') require File.join(Sinatra::Application.config_path, 'config.rb') # Workaround to fix an issue between Sinatra 1.0 and ruby 1.9.2 # Skipped when app is not launched directly enable :run if $0.eql?(__FILE__) get '/' do haml :index end in $SINATRA_APP_ROOT/spec_helper.rb: require 'db_web_console' require 'rack/test' in $SINATRA_APP_ROOT/sinatra_app/sinatra_app_spec.rb: require 'spec_helper' def app @app ||= Sinatra::Application end describe 'Sinatra App' do include Rack::Test::Methods it "says Hello" do get '/' last_response.should be_ok last_response.body.should == 'Hello!' end end But trying rspec spec/ , I get this error: Failures: 1) Sinatra App says ciao Failure/Error: @app ||= Sinatra::Application uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Sinatra # ./spec/db_web_console/db_web_console_spec.rb:4:in `app' # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ test/methods.rb:31:in `build_rack_mock_session' # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ test/methods.rb:27:in `rack_mock_session' # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ test/methods.rb:42:in `build_rack_test_session' # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ test/methods.rb:38:in `rack_test_session' # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ test/methods.rb:46:in `current_session' # ./spec/db_web_console/db_web_console_spec.rb:14:in `block (2 levels) in ' I tried in other ways, but without success... can someone figure out what can be the problem? From babarathotmail at yahoo.com Sat Sep 18 10:31:08 2010 From: babarathotmail at yahoo.com (babar shahzad) Date: Sat, 18 Sep 2010 07:31:08 -0700 (PDT) Subject: [rspec-users] is it Mailing list on github for oauth on twitter In-Reply-To: References: <334690.63394.qm@web56606.mail.re3.yahoo.com> Message-ID: <61755.27228.qm@web56606.mail.re3.yahoo.com> thanX a Lot David :-) Babar Shahzad Chaudary, +358465825630 Deptt of Information Processing Science, University of Oulu, Finland. ________________________________ From: David Chelimsky To: rspec-users Sent: Sat, September 18, 2010 7:28:45 AM Subject: Re: [rspec-users] is it Mailing list on github for oauth on twitter On Sep 18, 2010, at 5:33 AM, babar shahzad wrote: >Helo dear list members, > >Can you kindly confirm me that its the correct list I subscribed to. I want help > >in twitter oauth. I am using abraham williams' library. If something wrong, I >will be very thankful if you could write me link of correct list. > This is not the correct list. I don't see any mailing list for this, specifically, but if you go to the github wiki for the library you're using (http://github.com/abraham/twitteroauth/wiki), then you'll see some useful information that might help you in your search. Good luck, David From lists at ruby-forum.com Sun Sep 19 13:44:02 2010 From: lists at ruby-forum.com (Lord Raiden) Date: Sun, 19 Sep 2010 19:44:02 +0200 Subject: [rspec-users] undefined method `has_selector?' for "":String Message-ID: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> I'm running rails 3.0.0 on ruby 1.9.2p0. I've rspec beta 22 with Capybara 0.3.9. NO WEBRAT. I'm unable to use 'rendered.should have_selector('a') in my view specs. 1) home/_menu.erb should add a link to home first Failure/Error: rendered.should have_selector('a', 'Home') undefined method `has_selector?' for "":String I read in this forum that rspec beta 20 and above should pick Capybara automatically if its included in Gemfile. In my gem file I've this: group :development, :test do gem 'database_cleaner' gem 'cucumber-rails' gem 'cucumber' gem 'rspec-rails', ">= 2.0.0.beta.19" gem 'capybara' gem 'spork' gem 'launchy' # So you can do Then show me the page gem 'machinist', '>= 2.0.0.beta1' end Can anyone please point out what am I missing here? Thanks in advance. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Sep 19 14:16:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 19 Sep 2010 13:16:05 -0500 Subject: [rspec-users] undefined method `has_selector?' for "":String In-Reply-To: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> References: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> Message-ID: <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> On Sep 19, 2010, at 12:44 PM, Lord Raiden wrote: > I'm running rails 3.0.0 on ruby 1.9.2p0. > > I've rspec beta 22 with Capybara 0.3.9. NO WEBRAT. > > I'm unable to use 'rendered.should have_selector('a') in my view specs. > > 1) home/_menu.erb should add a link to home first > Failure/Error: rendered.should have_selector('a', 'Home') > undefined method `has_selector?' for "":String > > I read in this forum that rspec beta 20 and above should pick Capybara > automatically if its included in Gemfile. > > In my gem file I've this: > > group :development, :test do > gem 'database_cleaner' > gem 'cucumber-rails' > gem 'cucumber' > gem 'rspec-rails', ">= 2.0.0.beta.19" > gem 'capybara' > gem 'spork' > gem 'launchy' # So you can do Then show me the page > gem 'machinist', '>= 2.0.0.beta1' > end > > Can anyone please point out what am I missing here? Thanks in advance. Two issues: 1. Capybara matchers do not support arbitrary strings, so they do not work in view specs 2. Even if they did, the capybara matcher would be has_css, not has_selector From dchelimsky at gmail.com Sun Sep 19 14:22:11 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 19 Sep 2010 13:22:11 -0500 Subject: [rspec-users] How to use RSpec 2 with Sinatra 1.0 In-Reply-To: <4e0756c6-4b40-4d83-b01e-98b23d8df937@m16g2000vbs.googlegroups.com> References: <4e0756c6-4b40-4d83-b01e-98b23d8df937@m16g2000vbs.googlegroups.com> Message-ID: On Sep 19, 2010, at 4:38 AM, Maurizio De Santis wrote: > Hello, > > I am trying to use RSpec 2 with a Sinatra 1.0 application, but I have > no idea about whether they are compatible or not. I tried this: > > in $SINATRA_APP_ROOT/app.rb: > > require 'sinatra' > > set :app_file, __FILE__ > set :root, File.dirname(__FILE__) > set :config_path, File.join(Sinatra::Application.root, 'config') > > require File.join(Sinatra::Application.config_path, 'config.rb') > > # Workaround to fix an issue between Sinatra 1.0 and ruby 1.9.2 > # Skipped when app is not launched directly > enable :run if $0.eql?(__FILE__) > > get '/' do > haml :index > end > > in $SINATRA_APP_ROOT/spec_helper.rb: > > require 'db_web_console' > require 'rack/test' > > in $SINATRA_APP_ROOT/sinatra_app/sinatra_app_spec.rb: > > require 'spec_helper' > > def app > @app ||= Sinatra::Application > end > > describe 'Sinatra App' do > > include Rack::Test::Methods > > it "says Hello" do > get '/' > last_response.should be_ok > last_response.body.should == 'Hello!' > end > end > > But trying > > rspec spec/ > > , I get this error: > > > Failures: > 1) Sinatra App says ciao > Failure/Error: @app ||= Sinatra::Application > uninitialized constant > RSpec::Core::ExampleGroup::Nested_1::Sinatra > # ./spec/db_web_console/db_web_console_spec.rb:4:in `app' > # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ > test/methods.rb:31:in `build_rack_mock_session' > # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ > test/methods.rb:27:in `rack_mock_session' > # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ > test/methods.rb:42:in `build_rack_test_session' > # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ > test/methods.rb:38:in `rack_test_session' > # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/ > test/methods.rb:46:in `current_session' > # ./spec/db_web_console/db_web_console_spec.rb:14:in `block (2 > levels) in ' > > > I tried in other ways, but without success... can someone figure out > what can be the problem? There is no specific support for Sinatra, but Rack::Test gives you the tools you need. In this case, the error message is telling you exactly what the problem is. It can't find the constant "Sinatra" that is referenced on line 4 of sinatra_app_spec.rb. Try adding 'require "sinatra"' to spec/spec_helper.rb. HTH, David From myron.marston at gmail.com Sun Sep 19 20:08:50 2010 From: myron.marston at gmail.com (Myron Marston) Date: Sun, 19 Sep 2010 17:08:50 -0700 (PDT) Subject: [rspec-users] Behavior of object.foo(x) when you've stubbed it using object.stub(:foo).with(y) Message-ID: The current behavior of rspec-mocks causes a NoMethodError when you call object.foo(x) after setting up a stub using object.stub(:foo).with(y). Here's an example for when this has caused me a problem: - In a before(:each) block, I've setup a stub: File.stub(:exist?).with("config.yml").and_return(false) - The spec calls some library code that calls File.exist? ("results.yml") - When this is called, a NoMethodError is raised due to the current way rspec-mocks works. David and I have been discussing this over on the issue tracker for rspec-mocks[1]. I originally suggested that the stub should delegate to the original method definition when it is called with a different argument. David brought up that this has the potential to cause problems for people that use stubbing to prevent something destructive form occurring. Previously, object.stub(:foo).with(x) prevented the real definition of foo from ever being called. A NoMethodError would be raised when a different argument is passed, but you have the guarantee that the real, potentially destructive, definition of foo will never be invoked. My suggested change would allow the real definition of foo to be called when a different argument is passed. We're considering adding an explicit way to allow the delegate to the original definition (i.e. maybe another method on the fluent interface that enables this). I'm fine with this route, but I also feel like it's a sub-optimal API. Just based on the naming of the API, I would expect `with` to limit the scope of the stub so that it is only in effect when the arguments match, and the original method definition to get used otherwise. If you want a guarantee that a destructive method is never invoked, you should probably just do object.stub(:foo), and not have a `with`. But going this route does have the potential to cause problems for people due to the existing behavior. It'd be nice to get some feedback from other rspec-users on this. Which way should we go with this? Please comment over on the github issue tracker (linked to below) rather than here, so we keep the discussion all in one place. Thanks, Myron [1] http://github.com/rspec/rspec-mocks/issues/20 From jko170 at gmail.com Sun Sep 19 20:12:21 2010 From: jko170 at gmail.com (Justin Ko) Date: Sun, 19 Sep 2010 17:12:21 -0700 (PDT) Subject: [rspec-users] Behavior of object.foo(x) when you've stubbed it using object.stub(:foo).with(y) In-Reply-To: References: Message-ID: <49e840fa-ca17-4ff9-9b9b-1a914d34fec0@u13g2000vbo.googlegroups.com> On Sep 19, 8:08?pm, Myron Marston wrote: > The current behavior of rspec-mocks causes a NoMethodError when you > call object.foo(x) after setting up a stub using > object.stub(:foo).with(y). ?Here's an example for when this has caused > me a problem: > > - In a before(:each) block, I've setup a stub: > File.stub(:exist?).with("config.yml").and_return(false) > - The spec calls some library code that calls File.exist? > ("results.yml") > - When this is called, a NoMethodError is raised due to the current > way rspec-mocks works. > > David and I have been discussing this over on the issue tracker for > rspec-mocks[1]. ?I originally suggested that the stub should delegate > to the original method definition when it is called with a different > argument. ?David brought up that this has the potential to cause > problems for people that use stubbing to prevent something destructive > form occurring. ?Previously, object.stub(:foo).with(x) prevented the > real definition of foo from ever being called. ?A NoMethodError would > be raised when a different argument is passed, but you have the > guarantee that the real, potentially destructive, definition of foo > will never be invoked. ?My suggested change would allow the real > definition of foo to be called when a different argument is passed. > We're considering adding an explicit way to allow the delegate to the > original definition (i.e. maybe another method on the fluent interface > that enables this). > > I'm fine with this route, but I also feel like it's a sub-optimal > API. ?Just based on the naming of the API, I would expect `with` to > limit the scope of the stub so that it is only in effect when the > arguments match, and the original method definition to get used > otherwise. ?If you want a guarantee that a destructive method is never > invoked, you should probably just do object.stub(:foo), and not have a > `with`. ?But going this route does have the potential to cause > problems for people due to the existing behavior. > > It'd be nice to get some feedback from other rspec-users on this. > Which way should we go with this? ?Please comment over on the github > issue tracker (linked to below) rather than here, so we keep the > discussion all in one place. > > Thanks, > Myron > > [1]http://github.com/rspec/rspec-mocks/issues/20 > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Can we get a tl;dr on this? ;-) j/k From nathanvda at gmail.com Mon Sep 20 03:59:25 2010 From: nathanvda at gmail.com (nathanvda) Date: Mon, 20 Sep 2010 00:59:25 -0700 (PDT) Subject: [rspec-users] using rcov with rspec2 Message-ID: I have using rcov together with rspec2 using the following rake task: desc "Run all specs with rcov" RSpec::Core::RakeTask.new("test_cov") do |t| t.rcov = true t.rcov_opts = %w{--rails --include views --exclude gems\/,spec \/,features\/,seeds\/} end but since the latest beta, this doesn't work anymore. Does anybody have an idea what is going wrong? The error i get is this: `require': no such file to load -- spec_helper (LoadError) From tjtuom at utu.fi Mon Sep 20 06:04:45 2010 From: tjtuom at utu.fi (Toni Tuominen) Date: Mon, 20 Sep 2010 13:04:45 +0300 Subject: [rspec-users] undefined method `has_selector?' for "":String In-Reply-To: <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> References: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> Message-ID: You should use this gem: http://github.com/grimen/rspec_tag_matchers - Toni On Sun, Sep 19, 2010 at 9:16 PM, David Chelimsky wrote: > On Sep 19, 2010, at 12:44 PM, Lord Raiden wrote: > >> I'm running rails 3.0.0 on ruby 1.9.2p0. >> >> I've rspec beta 22 with Capybara 0.3.9. NO WEBRAT. >> >> I'm unable to use 'rendered.should have_selector('a') in my view specs. >> >> ?1) home/_menu.erb should add a link to home first >> ? ? Failure/Error: rendered.should have_selector('a', 'Home') >> ? ? undefined method `has_selector?' for "":String >> >> I read in this forum that rspec beta 20 and above should pick Capybara >> automatically if its included in Gemfile. >> >> In my gem file I've this: >> >> group :development, :test do >> ?gem 'database_cleaner' >> ?gem 'cucumber-rails' >> ?gem 'cucumber' >> ?gem 'rspec-rails', ">= 2.0.0.beta.19" >> ?gem 'capybara' >> ?gem 'spork' >> ?gem 'launchy' ? ?# So you can do Then show me the page >> ?gem 'machinist', '>= 2.0.0.beta1' >> end >> >> Can anyone please point out what am I missing here? Thanks in advance. > > Two issues: > > 1. Capybara matchers do not support arbitrary strings, so they do not work in view specs > 2. Even if they did, the capybara matcher would be has_css, not has_selector > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Sep 20 06:08:09 2010 From: lists at ruby-forum.com (Bruno Cardoso) Date: Mon, 20 Sep 2010 12:08:09 +0200 Subject: [rspec-users] [Problem] Rails 3 + RSpec 2 beta 22 with JRuby 1.5.2 Message-ID: <743745a15263dd1b3b297e8cd7a7de8a@ruby-forum.com> Hi, I created a clean rails 3 project and installed rspec 2 beta 22, created a simple test case and run all my test using "rake spec", i get this error: D:/ruby/rubies/jruby-1.5.2/bin/jruby.bat -S bundle exec rspec "./spec/test_spec.rb" D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1451:in `complete': invalid option: --runner (OptionParser::InvalidOption) from D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1449:in `catch' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1449:in `complete' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1262:in `parse_in_order' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1255:in `catch' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1255:in `parse_in_order' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1249:in `order!' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1340:in `permute!' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/1.8/optparse.rb:1361:in `parse!' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/option_parser.rb:17:in `parse!' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/option_parser.rb:4:in `parse!' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/configuration_options.rb:59:in `parse_env_options' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/configuration_options.rb:48:in `parse_options' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/runner.rb:22:in `run' from D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.22/bin/rspec:3 from D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.22/bin/rspec:19:in `load' from D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 Any idea why this happens? I found no clues about it searching in google, yet. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Sep 20 10:32:56 2010 From: lists at ruby-forum.com (Bruno Cardoso) Date: Mon, 20 Sep 2010 16:32:56 +0200 Subject: [rspec-users] [Problem] Rails 3 + RSpec 2 beta 22 with JRuby 1.5.2 In-Reply-To: <743745a15263dd1b3b297e8cd7a7de8a@ruby-forum.com> References: <743745a15263dd1b3b297e8cd7a7de8a@ruby-forum.com> Message-ID: <6987432bb8fcde1e956ccb35dab9cfdb@ruby-forum.com> An important clue I just found out, this seams to be a problem with Netbeans. If I run "jruby -S rake spec" in the command line everything works OK. I only get the problem by running this rake task from Netbeans. Maybe Netbeans uses the "--runner" option in the background and rspec 2.0 doesn't like it for some reason? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Sep 20 10:53:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Sep 2010 09:53:26 -0500 Subject: [rspec-users] [Problem] Rails 3 + RSpec 2 beta 22 with JRuby 1.5.2 In-Reply-To: <6987432bb8fcde1e956ccb35dab9cfdb@ruby-forum.com> References: <743745a15263dd1b3b297e8cd7a7de8a@ruby-forum.com> <6987432bb8fcde1e956ccb35dab9cfdb@ruby-forum.com> Message-ID: <1FBE3861-4BBA-4E10-BC12-FB91A2EDD6CC@gmail.com> On Sep 20, 2010, at 9:32 AM, Bruno Cardoso wrote: > An important clue I just found out, this seams to be a problem with > Netbeans. If I run "jruby -S rake spec" in the command line everything > works OK. > I only get the problem by running this rake task from Netbeans. Maybe > Netbeans uses the "--runner" option in the background and rspec 2.0 > doesn't like it for some reason? That would make sense. There is no --runner option in rspec-2. Would you kindly post this to http://github.com/rspec/rspec-core/issues? Thx, David From lists at ruby-forum.com Mon Sep 20 11:27:13 2010 From: lists at ruby-forum.com (Bruno Cardoso) Date: Mon, 20 Sep 2010 17:27:13 +0200 Subject: [rspec-users] [Problem] Rails 3 + RSpec 2 beta 22 with JRuby 1.5.2 In-Reply-To: <1FBE3861-4BBA-4E10-BC12-FB91A2EDD6CC@gmail.com> References: <743745a15263dd1b3b297e8cd7a7de8a@ruby-forum.com> <6987432bb8fcde1e956ccb35dab9cfdb@ruby-forum.com> <1FBE3861-4BBA-4E10-BC12-FB91A2EDD6CC@gmail.com> Message-ID: <93026c4ded1ed1ed33534803d5ad8c65@ruby-forum.com> David Chelimsky wrote: > On Sep 20, 2010, at 9:32 AM, Bruno Cardoso wrote: > >> An important clue I just found out, this seams to be a problem with >> Netbeans. If I run "jruby -S rake spec" in the command line everything >> works OK. >> I only get the problem by running this rake task from Netbeans. Maybe >> Netbeans uses the "--runner" option in the background and rspec 2.0 >> doesn't like it for some reason? > > That would make sense. There is no --runner option in rspec-2. Would you > kindly post this to http://github.com/rspec/rspec-core/issues? > > Thx, > David Done: http://github.com/rspec/rspec-core/issues/issue/150 In the old version of rspec, this --runner option existed (http://rspec.info/documentation/tools/spec.html), what was its purpose? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Sep 20 15:07:43 2010 From: lists at ruby-forum.com (Gene Angelo) Date: Mon, 20 Sep 2010 21:07:43 +0200 Subject: [rspec-users] spec for derived classes question Message-ID: <4ea88a1d119c6b9e2e2819fa70c32465@ruby-forum.com> I assume spec tests be repeated for derived classes? Is there such a thing in rspec as deriving specs? -- Posted via http://www.ruby-forum.com/. From amir.nagri at gmail.com Tue Sep 21 05:08:58 2010 From: amir.nagri at gmail.com (Amiruddin Nagri) Date: Tue, 21 Sep 2010 14:38:58 +0530 Subject: [rspec-users] RSpec beta 22 with Rails 3 Message-ID: I am working on a Rails 3 application. Recently bundler got an update for rspec, which upgraded it to 22, (previously we were using beta 20). After the update we are unable to run the old using 'rake spec:rcov', while running with 'rake spec' is running fine. When you do rake spec it does not give any output and finishes the task. something like below : $ rake spec --trace (in /work/rspec22) ** Invoke spec (first_time, not_needed) $ Also, while making the sample app to send it out to the rspec users mailing list, I am not able to run spec:rcov task, can somebody guide if I have forgotten any configuration for rcov. Here is the link to sample app with reproducible behavior which I am getting while running 'rake spec:rcov' => http://github.com/anagri/rspecsample Regards, Amiruddin Nagri, Bangalore, 560008, KA India Y! IM : amir_nagri at yahoo.com GTalk : amir.nagri at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From patmaddox at me.com Tue Sep 21 05:54:52 2010 From: patmaddox at me.com (Pat Maddox) Date: Tue, 21 Sep 2010 02:54:52 -0700 Subject: [rspec-users] spec for derived classes question In-Reply-To: <4ea88a1d119c6b9e2e2819fa70c32465@ruby-forum.com> References: <4ea88a1d119c6b9e2e2819fa70c32465@ruby-forum.com> Message-ID: <13A45787-BC35-4180-A4D0-B85CC8DD4E5C@me.com> search this page for "shared example groups" http://rspec.info/documentation/ On Sep 20, 2010, at 12:07 PM, Gene Angelo wrote: > I assume spec tests be repeated for derived classes? > > Is there such a thing in rspec as deriving specs? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Tue Sep 21 05:57:21 2010 From: lists at ruby-forum.com (Lord Raiden) Date: Tue, 21 Sep 2010 11:57:21 +0200 Subject: [rspec-users] undefined method `has_selector?' for "":String In-Reply-To: <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> References: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> Message-ID: <8370e397f4eb39a9811f9c38e5df38de@ruby-forum.com> David Chelimsky wrote: > Two issues: > > 1. Capybara matchers do not support arbitrary strings, so they do not > work in view specs > 2. Even if they did, the capybara matcher would be has_css, not > has_selector Thanks for quick reply. Sorry about my delay (I was sick and down). I'm not an expert in these tools, so please bear with me. Is there anyway to get Capybara to work with view:specs? May be by doing something Cucumber is doing to get Capybara to work with it. Reason I'm asking is I really want to write few view specs, (outside of cucumber), and I would like not to use Webrat, to keep things clean. It seems the gem Tony pointed out can help, but as I said I would rather not use it if there is any hack which could let me use Capybara for rspec view specs. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Sep 21 07:55:21 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Sep 2010 06:55:21 -0500 Subject: [rspec-users] undefined method `has_selector?' for "":String In-Reply-To: <8370e397f4eb39a9811f9c38e5df38de@ruby-forum.com> References: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> <8370e397f4eb39a9811f9c38e5df38de@ruby-forum.com> Message-ID: <45225D9D-B545-4906-A0B3-E2E490884B9C@gmail.com> On Sep 21, 2010, at 4:57 AM, Lord Raiden wrote: > David Chelimsky wrote: >> Two issues: >> >> 1. Capybara matchers do not support arbitrary strings, so they do not >> work in view specs >> 2. Even if they did, the capybara matcher would be has_css, not >> has_selector > > Thanks for quick reply. Sorry about my delay (I was sick and down). > > I'm not an expert in these tools, so please bear with me. > > Is there anyway to get Capybara to work with view:specs? May be by doing > something Cucumber is doing to get Capybara to work with it. Not now. Capybara is designed to work with a Rack application. View specs are built on Rails' ActionView::TestCase, which is designed to make an isolated call into the rendering framework, and get back a String. They don't know anything about requests or sessions, so the Capybara matchers don't work. I've talked to Jonas about extracting the matchers so they can work with arbitrary Strings. He's interested in the idea, but it won't likely happen for a while due to other priorities. I've added an issue [1], which you are welcome to comment on and follow. > Reason I'm asking is I really want to write few view specs, (outside of > cucumber), and I would like not to use Webrat, to keep things clean. Why would Webrat be any less clean in this case? The matchers are pretty much the same, and that's all you need. Are you using Capybara in controller specs? If not, I'd recommend using Webrat with RSpec and Capybara with Cucumber. HTH, David > It seems the gem Tony pointed out can help, but as I said I would rather > not use it if there is any hack which could let me use Capybara for > rspec view specs. From dchelimsky at gmail.com Tue Sep 21 07:56:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Sep 2010 06:56:36 -0500 Subject: [rspec-users] undefined method `has_selector?' for "":String In-Reply-To: <45225D9D-B545-4906-A0B3-E2E490884B9C@gmail.com> References: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> <8370e397f4eb39a9811f9c38e5df38de@ruby-forum.com> <45225D9D-B545-4906-A0B3-E2E490884B9C@gmail.com> Message-ID: <88780827-A2C8-4F00-9D3C-0CFA3D0E9B4D@gmail.com> On Sep 21, 2010, at 6:55 AM, David Chelimsky wrote: > On Sep 21, 2010, at 4:57 AM, Lord Raiden wrote: > >> David Chelimsky wrote: >>> Two issues: >>> >>> 1. Capybara matchers do not support arbitrary strings, so they do not >>> work in view specs >>> 2. Even if they did, the capybara matcher would be has_css, not >>> has_selector >> >> Thanks for quick reply. Sorry about my delay (I was sick and down). >> >> I'm not an expert in these tools, so please bear with me. >> >> Is there anyway to get Capybara to work with view:specs? May be by doing >> something Cucumber is doing to get Capybara to work with it. > > Not now. Capybara is designed to work with a Rack application. View specs are built on Rails' ActionView::TestCase, which is designed to make an isolated call into the rendering framework, and get back a String. They don't know anything about requests or sessions, so the Capybara matchers don't work. > > I've talked to Jonas about extracting the matchers so they can work with arbitrary Strings. He's interested in the idea, but it won't likely happen for a while due to other priorities. I've added an issue [1], which you are welcome to comment on and follow. > >> Reason I'm asking is I really want to write few view specs, (outside of >> cucumber), and I would like not to use Webrat, to keep things clean. > > Why would Webrat be any less clean in this case? The matchers are pretty much the same, and that's all you need. Are you using Capybara in controller specs? If not, I'd recommend using Webrat with RSpec and Capybara with Cucumber. > > HTH, > David > >> It seems the gem Tony pointed out can help, but as I said I would rather >> not use it if there is any hack which could let me use Capybara for >> rspec view specs. Forgot to include the issue :) http://github.com/jnicklas/capybara/issues#issue/139 From lists at ruby-forum.com Tue Sep 21 08:38:54 2010 From: lists at ruby-forum.com (Gene Angelo) Date: Tue, 21 Sep 2010 14:38:54 +0200 Subject: [rspec-users] spec for derived classes question In-Reply-To: <13A45787-BC35-4180-A4D0-B85CC8DD4E5C@me.com> References: <4ea88a1d119c6b9e2e2819fa70c32465@ruby-forum.com> <13A45787-BC35-4180-A4D0-B85CC8DD4E5C@me.com> Message-ID: <7a8ca4fd62bae5daf11cbb9f8c2c00f2@ruby-forum.com> Pat Maddox wrote: > search this page for "shared example groups" > http://rspec.info/documentation/ thank you, exactly what I was looking for. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Sep 21 08:51:05 2010 From: lists at ruby-forum.com (Gene Angelo) Date: Tue, 21 Sep 2010 14:51:05 +0200 Subject: [rspec-users] How do I test my Module? Message-ID: <0a8fe4e5d7e9a2ea619df3bf29c4b90f@ruby-forum.com> I think I understand basic Class testing, however, how do I test a Module's behavior especially (in my case) where the Module will be used as an extension primarily e.g. object.extend MyModule. -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Tue Sep 21 09:58:17 2010 From: ben at benmabey.com (Ben Mabey) Date: Tue, 21 Sep 2010 07:58:17 -0600 Subject: [rspec-users] How do I test my Module? In-Reply-To: <0a8fe4e5d7e9a2ea619df3bf29c4b90f@ruby-forum.com> References: <0a8fe4e5d7e9a2ea619df3bf29c4b90f@ruby-forum.com> Message-ID: <4C98B9F9.2030605@benmabey.com> On 9/21/10 6:51 AM, Gene Angelo wrote: > I think I understand basic Class testing, however, how do I test a > Module's behavior especially (in my case) where the Module will be used > as an extension primarily e.g. object.extend MyModule. One option is to extend an object in your spec like so: describe MyModule do subject { Object.new.extend(MyModule) } describe "#foo" do it "does blah" do subject.foo.should == "stuff" end end end I often times will use an OpenStuct to help test modules because they allow you to easily set the state. For example: module MyModule def double num * 2 end end require 'ostruct' describe MyModule do def new_object(hash) OpenStruct.new(hash).extend(MyModule) end describe "#double" do it "doubles the num var" do new_object(:num => 2).double.should == 4 end end end HTH, Ben From win at wincent.com Tue Sep 21 09:40:57 2010 From: win at wincent.com (Wincent Colaiuta) Date: Tue, 21 Sep 2010 15:40:57 +0200 Subject: [rspec-users] undefined method `has_selector?' for "":String In-Reply-To: <45225D9D-B545-4906-A0B3-E2E490884B9C@gmail.com> References: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> <8370e397f4eb39a9811f9c38e5df38de@ruby-forum.com> <45225D9D-B545-4906-A0B3-E2E490884B9C@gmail.com> Message-ID: <0C5DE373-45D6-445C-B2F8-C0C0E3F313B6@wincent.com> El 21/09/2010, a las 13:55, David Chelimsky escribi?: > On Sep 21, 2010, at 4:57 AM, Lord Raiden wrote: > >> David Chelimsky wrote: > >> Reason I'm asking is I really want to write few view specs, (outside of >> cucumber), and I would like not to use Webrat, to keep things clean. > > Why would Webrat be any less clean in this case? The matchers are pretty much the same, and that's all you need. Are you using Capybara in controller specs? If not, I'd recommend using Webrat with RSpec and Capybara with Cucumber. I think the issue is that even though they are effectively the same in terms of their capabilities (ie. they both wrap Nokogiri AFAIK), the names of the matchers are slightly different so you end up having to use two different sets of language depending on whether you're writing view specs or acceptance specs. (This is probably less of an issue for Cucumber users because the Cucumber steps are another layer of abstraction over the top of the matchers, but if you're a Steak user, then you're always working directly with the matcher APIs). I'm using Steak + Capybara right now for acceptance specs and Webrat for my view specs, but I'd prefer to be able to use Capybara matchers for everything in order to avoid the duplication of two very similar but slightly different APIs. Cheers, Wincent From lists at ruby-forum.com Tue Sep 21 10:07:58 2010 From: lists at ruby-forum.com (Gene Angelo) Date: Tue, 21 Sep 2010 16:07:58 +0200 Subject: [rspec-users] How do I test my Module? In-Reply-To: <4C98B9F9.2030605@benmabey.com> References: <0a8fe4e5d7e9a2ea619df3bf29c4b90f@ruby-forum.com> <4C98B9F9.2030605@benmabey.com> Message-ID: Ben Mabey wrote: > On 9/21/10 6:51 AM, Gene Angelo wrote: >> I think I understand basic Class testing, however, how do I test a >> Module's behavior especially (in my case) where the Module will be used >> as an extension primarily e.g. object.extend MyModule. > One option is to extend an object in your spec like so: > Perfect. Thank you. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Sep 21 15:24:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Sep 2010 14:24:26 -0500 Subject: [rspec-users] RSpec beta 22 with Rails 3 In-Reply-To: References: Message-ID: On Sep 21, 2010, at 4:08 AM, Amiruddin Nagri wrote: > I am working on a Rails 3 application. Recently bundler got an update for rspec, which upgraded it to 22, (previously we were using beta 20). > > After the update we are unable to run the old using 'rake spec:rcov', while running with 'rake spec' is running fine. > When you do rake spec it does not give any output and finishes the task. something like below : > > $ rake spec --trace > (in /work/rspec22) > ** Invoke spec (first_time, not_needed) > > $ This is a known issue (http://github.com/rspec/rspec-core/issues#issue/152) and will be fixed in the beta.23 release, later this week. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From johnf at distb.net Tue Sep 21 09:45:47 2010 From: johnf at distb.net (John Feminella) Date: Tue, 21 Sep 2010 09:45:47 -0400 Subject: [rspec-users] Conditional before() blocks in spec_helper based on metadata? Message-ID: I have some tests that need to load my application's seed data prior to running, and others that don't. It's a well-defined set of examples: describe "needs seed data", :needs_data => true do ... end What can I put in my Rspec.configure { ... } block so that every test which has ":needs_data => true" will invoke a particular before(:each) { ... } block? Note that I still want every test to run; I just want the :needs_data tests to get some special setup first. ~ jf From bcardoso.home at gmail.com Tue Sep 21 11:58:04 2010 From: bcardoso.home at gmail.com (Bruno Cardoso) Date: Tue, 21 Sep 2010 08:58:04 -0700 (PDT) Subject: [rspec-users] Failure/Error: Unable to find matching line from backtrace can't convert nil into String Message-ID: I'm getting this errors from this spec: http://pastie.org/private/lm9nrqnmhqobs1avf3skgw Failures: 1) Account Account should have a relation belongs to with customer Failure/Error: Unable to find matching line from backtrace can't convert nil into String # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 2) Account Account should have a relation belongs to with account status Failure/Error: Unable to find matching line from backtrace can't convert nil into String # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 3) Account Account should have a has many relation with account managers Failure/Error: Unable to find matching line from backtrace can't convert nil into String # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 4) Account Account should have a has many relation with account relations Failure/Error: Unable to find matching line from backtrace can't convert nil into String # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 5) Account Account should be possible to create an account with only status, b ucket and creation_date Failure/Error: Unable to find matching line from backtrace can't convert nil into String # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 6) Account Account should return an error if bucket is nil Failure/Error: Unable to find matching line from backtrace can't convert nil into String # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 The spec is very simple. This was working with rails2+rspec1.3.... I'm using rails3+rspec2 now. The error message is not very clear. Any idea why this happens? From rodrigo3n at gmail.com Tue Sep 21 17:55:25 2010 From: rodrigo3n at gmail.com (rodrigo3n) Date: Tue, 21 Sep 2010 14:55:25 -0700 (PDT) Subject: [rspec-users] Options for .rspec, or a verbose mode? Message-ID: <2b78c30a-ca95-47c8-b3fc-7f02b5241f38@k13g2000vbq.googlegroups.com> Hello everybody, in my app, (using rspec 2.0.0.beta22) I have my .rspec file with "--colour" in it., I want to know if are there any other options for this file? And I wanna know if is there a verbose mode of running my specs, listing their 'describes' and/or 'its'? Thanks! From craftsmaster at gmail.com Tue Sep 21 20:06:43 2010 From: craftsmaster at gmail.com (simo) Date: Tue, 21 Sep 2010 17:06:43 -0700 (PDT) Subject: [rspec-users] rspec-rails 1.3.2 tests get loaded, but not executed Message-ID: <74656ade-52cd-4b8d-8fe5-959581c45206@u13g2000vbo.googlegroups.com> Hello, Can anyone please help me with the following issue I am running rspec-rails 1.3.2 with rails 2.3.9 on ruby 1.8.7 Unfortunately my tests don't execute at all after i updated these gems although i followed the update insturctions. After some debugging i found that the describes and examples get created, but they never get registered with ExampleGroupFactory.add_example_group and therefore not executed when runner.run is called This seems to be a rspec-rails issue only as i could execute the tests for rspec 1.3.0 the gems i use: *** LOCAL GEMS *** rails (2.3.9) rake (0.8.7) rspec (1.3.0) rspec-rails (1.3.2) ruby-debug-base (0.10.3) ruby-debug-ide (0.4.7) test-unit (2.1.1, 1.2.3) Thank You, Simo From lailsonbm at gmail.com Tue Sep 21 21:00:40 2010 From: lailsonbm at gmail.com (Lailson Bandeira) Date: Tue, 21 Sep 2010 22:00:40 -0300 Subject: [rspec-users] Options for .rspec, or a verbose mode? In-Reply-To: <2b78c30a-ca95-47c8-b3fc-7f02b5241f38@k13g2000vbq.googlegroups.com> References: <2b78c30a-ca95-47c8-b3fc-7f02b5241f38@k13g2000vbq.googlegroups.com> Message-ID: > > And I wanna know if is there a verbose mode of running my specs, listing > their 'describes' and/or 'its'? You can use --format documentation to do this. Is there some place where all the options are documented, folks? (besides the code =P) -- LAILSON BANDEIRA http://lailsonbandeira.com/ On Tue, Sep 21, 2010 at 6:55 PM, rodrigo3n wrote: > Hello everybody, in my app, (using rspec 2.0.0.beta22) I have > my .rspec file with "--colour" in it., I want to know if are there any > other options for this file? And I wanna know if is there a verbose > mode of running my specs, listing their 'describes' and/or 'its'? > > Thanks! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lailsonbm at gmail.com Tue Sep 21 21:02:42 2010 From: lailsonbm at gmail.com (Lailson Bandeira) Date: Tue, 21 Sep 2010 22:02:42 -0300 Subject: [rspec-users] Conditional before() blocks in spec_helper based on metadata? In-Reply-To: References: Message-ID: Look at this example for javascript pages: http://gist.github.com/518636. I think you can do something like that. -- LAILSON BANDEIRA http://lailsonbandeira.com/ On Tue, Sep 21, 2010 at 10:45 AM, John Feminella wrote: > I have some tests that need to load my application's seed data prior > to running, and others that don't. It's a well-defined set of > examples: > > describe "needs seed data", :needs_data => true do > ... > end > > What can I put in my Rspec.configure { ... } block so that every test > which has ":needs_data => true" will invoke a particular before(:each) > { ... } block? Note that I still want every test to run; I just want > the :needs_data tests to get some special setup first. > > ~ jf > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Sep 21 21:05:06 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Sep 2010 20:05:06 -0500 Subject: [rspec-users] Failure/Error: Unable to find matching line from backtrace can't convert nil into String In-Reply-To: References: Message-ID: <985DC091-9B4B-44F2-9E72-C6E914C67572@gmail.com> On Sep 21, 2010, at 10:58 AM, Bruno Cardoso wrote: > I'm getting this errors from this spec: http://pastie.org/private/lm9nrqnmhqobs1avf3skgw > > Failures: > 1) Account Account should have a relation belongs to with customer > Failure/Error: Unable to find matching line from backtrace > can't convert nil into String > # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 > > The spec is very simple. This was working with rails2+rspec1.3.... I'm > using rails3+rspec2 now. The error message is not very clear. > > Any idea why this happens? http://github.com/rspec/rspec-core/issues#issue/146 From dchelimsky at gmail.com Tue Sep 21 21:09:49 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Sep 2010 20:09:49 -0500 Subject: [rspec-users] Options for .rspec, or a verbose mode? In-Reply-To: References: <2b78c30a-ca95-47c8-b3fc-7f02b5241f38@k13g2000vbq.googlegroups.com> Message-ID: <88B2BA90-F495-4F34-AFC4-910082448267@gmail.com> On Sep 21, 2010, at 8:00 PM, Lailson Bandeira wrote: > And I wanna know if is there a verbose mode of running my specs, listing their 'describes' and/or 'its'? > > You can use --format documentation to do this. Is there some place where all the options are documented, folks? (besides the code =P) rspec --help :) > > -- > LAILSON BANDEIRA > http://lailsonbandeira.com/ > > > On Tue, Sep 21, 2010 at 6:55 PM, rodrigo3n wrote: > Hello everybody, in my app, (using rspec 2.0.0.beta22) I have > my .rspec file with "--colour" in it., I want to know if are there any > other options for this file? And I wanna know if is there a verbose > mode of running my specs, listing their 'describes' and/or 'its'? > > Thanks! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lailsonbm at gmail.com Tue Sep 21 21:30:55 2010 From: lailsonbm at gmail.com (Lailson Bandeira) Date: Tue, 21 Sep 2010 22:30:55 -0300 Subject: [rspec-users] Options for .rspec, or a verbose mode? In-Reply-To: <88B2BA90-F495-4F34-AFC4-910082448267@gmail.com> References: <2b78c30a-ca95-47c8-b3fc-7f02b5241f38@k13g2000vbq.googlegroups.com> <88B2BA90-F495-4F34-AFC4-910082448267@gmail.com> Message-ID: Well, it's a very unexpected place to put? help! =D -- LAILSON BANDEIRA http://lailsonbandeira.com/ On Tue, Sep 21, 2010 at 10:09 PM, David Chelimsky wrote: > > On Sep 21, 2010, at 8:00 PM, Lailson Bandeira wrote: > > And I wanna know if is there a verbose mode of running my specs, listing >> their 'describes' and/or 'its'? > > > You can use --format documentation to do this. Is there some place where > all the options are documented, folks? (besides the code =P) > > > rspec --help > > :) > > > -- > LAILSON BANDEIRA > http://lailsonbandeira.com/ > > > On Tue, Sep 21, 2010 at 6:55 PM, rodrigo3n wrote: > >> Hello everybody, in my app, (using rspec 2.0.0.beta22) I have >> my .rspec file with "--colour" in it., I want to know if are there any >> other options for this file? And I wanna know if is there a verbose >> mode of running my specs, listing their 'describes' and/or 'its'? >> >> Thanks! >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Sep 21 23:11:16 2010 From: lists at ruby-forum.com (Lord Raiden) Date: Wed, 22 Sep 2010 05:11:16 +0200 Subject: [rspec-users] undefined method `has_selector?' for "":String In-Reply-To: <0C5DE373-45D6-445C-B2F8-C0C0E3F313B6@wincent.com> References: <71a5b30595610dc5ee7d14664daa1f8b@ruby-forum.com> <788149A8-9587-47EA-AC03-D4A548A65521@gmail.com> <8370e397f4eb39a9811f9c38e5df38de@ruby-forum.com> <45225D9D-B545-4906-A0B3-E2E490884B9C@gmail.com> <0C5DE373-45D6-445C-B2F8-C0C0E3F313B6@wincent.com> Message-ID: > I'd prefer to be able to use Capybara matchers for > everything in order to avoid the duplication of two very similar but > slightly different APIs. > > Cheers, > Wincent Wincent pointed out my exact feelings on the matter (Probably in a better way than I could have.) But I'm willing to follow David's advice if that's the only way for now, and it works without clashes. /Thanks guys. -- Posted via http://www.ruby-forum.com/. From amir.nagri at gmail.com Tue Sep 21 23:46:58 2010 From: amir.nagri at gmail.com (Amiruddin Nagri) Date: Wed, 22 Sep 2010 09:16:58 +0530 Subject: [rspec-users] RSpec beta 22 with Rails 3 In-Reply-To: References: Message-ID: On Wed, Sep 22, 2010 at 12:54 AM, David Chelimsky wrote: > > On Sep 21, 2010, at 4:08 AM, Amiruddin Nagri wrote: > > I am working on a Rails 3 application. Recently bundler got an update for > rspec, which upgraded it to 22, (previously we were using beta 20). > > After the update we are unable to run the old using 'rake spec:rcov', while > running with 'rake spec' is running fine. > When you do rake spec it does not give any output and finishes the task. > something like below : > > $ rake spec --trace > (in /work/rspec22) > ** Invoke spec (first_time, not_needed) > > $ > > > This is a known issue (http://github.com/rspec/rspec-core/issues#issue/152) > and will be fixed in the beta.23 release, later this week. > > David, I am facing two more issues with rspec+rcov - We are using Hudson as our CI environments. I am using rake plugin which allows to execute rake tasks on the CI server. When there are some spec failures in our app the 'rake spec' tasks returns proper exit code which Hudson identifies as a build failure, but when you run 'rake spec:rcov', even when the specs are failing, may be the exit code is such that Hudson is not able to identify the build has failed. - When I run rcov, it also analyses the files in the spec folder for coverage which is giving me wrong coverage statistics. I have tried setting the options to exclude specific folders through rcov.opts, but it doesn't seem to work for a Rails 3 setup (RSpec 2). For my previous project on Rails 2.3.8 (RSpec 1.3) it used to work fine and the spec folders were excluded while doing coverage calculations. Cheers, Amir -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Sep 22 01:41:47 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Sep 2010 00:41:47 -0500 Subject: [rspec-users] RSpec beta 22 with Rails 3 In-Reply-To: References: Message-ID: On Tue, Sep 21, 2010 at 10:46 PM, Amiruddin Nagri wrote: > > On Wed, Sep 22, 2010 at 12:54 AM, David Chelimsky > wrote: >> >> On Sep 21, 2010, at 4:08 AM, Amiruddin Nagri wrote: >> >> I am working on a Rails 3 application. Recently bundler got an update for >> rspec, which upgraded it to 22, (previously we were using beta 20). >> >> After the update we are unable to run the old using 'rake spec:rcov', >> while running with 'rake spec' is running fine. >> When you do rake spec it does not give any output and finishes the task. >> something like below : >> >> $ rake spec --trace >> (in /work/rspec22) >> ** Invoke spec (first_time, not_needed) >> >> $ >> >> This is a known issue >> (http://github.com/rspec/rspec-core/issues#issue/152) and will be fixed in >> the beta.23 release, later this week. > > David, > > I am facing two more issues with rspec+rcov > > We are using Hudson as our CI environments. I am using rake plugin which > allows to execute rake tasks on the CI server. When there are some spec > failures in our app the 'rake spec' tasks returns proper exit code which > Hudson identifies as a build failure, but when you run 'rake spec:rcov', > even when the specs are failing, may be the exit code is such that Hudson is > not able to identify the build has failed. > When I run rcov, it also analyses the files in the spec folder for coverage > which is giving me wrong coverage statistics. I have tried setting the > options to exclude specific folders through rcov.opts, but it doesn't seem > to work for a Rails 3 setup (RSpec 2). For my previous project on Rails > 2.3.8 (RSpec 1.3) it used to work fine and the spec folders were excluded > while doing coverage calculations. Please file these as two separate issues at http://github.com/rspec/rspec-core/issues Thx, David > > Cheers, > Amir > From bcardoso.home at gmail.com Wed Sep 22 05:39:40 2010 From: bcardoso.home at gmail.com (Bruno Cardoso) Date: Wed, 22 Sep 2010 02:39:40 -0700 (PDT) Subject: [rspec-users] Failure/Error: Unable to find matching line from backtrace can't convert nil into String In-Reply-To: <985DC091-9B4B-44F2-9E72-C6E914C67572@gmail.com> References: <985DC091-9B4B-44F2-9E72-C6E914C67572@gmail.com> Message-ID: <815118cc-6e17-4bed-8fa8-6d0e7a29c83a@m1g2000vbh.googlegroups.com> Hi David, Thanks for the reply but that didn't fix my problem. I think this is somehow related to fixtures, at least I only get this problem on the specs that use fixtures and if I remove the fixtures, it works. On Sep 22, 2:05?am, David Chelimsky wrote: > On Sep 21, 2010, at 10:58 AM, Bruno Cardoso wrote: > > > I'm getting this errors from this spec:http://pastie.org/private/lm9nrqnmhqobs1avf3skgw > > > Failures: > > ?1) Account Account should have a relation belongs to with customer > > ? ? Failure/Error: Unable to find matching line from backtrace > > ? ? can't convert nil into String > > ? ? # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 > > > The spec is very simple. This was working with rails2+rspec1.3.... I'm > > using rails3+rspec2 now. The error message is not very clear. > > > Any idea why this happens? > > http://github.com/rspec/rspec-core/issues#issue/146 > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From bcardoso.home at gmail.com Wed Sep 22 07:30:18 2010 From: bcardoso.home at gmail.com (Bruno Cardoso) Date: Wed, 22 Sep 2010 04:30:18 -0700 (PDT) Subject: [rspec-users] Failure/Error: Unable to find matching line from backtrace can't convert nil into String In-Reply-To: <815118cc-6e17-4bed-8fa8-6d0e7a29c83a@m1g2000vbh.googlegroups.com> References: <985DC091-9B4B-44F2-9E72-C6E914C67572@gmail.com> <815118cc-6e17-4bed-8fa8-6d0e7a29c83a@m1g2000vbh.googlegroups.com> Message-ID: TypeError: can't convert nil into String D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ lib/active_record/fixtures.rb:519:in `create_fixtures' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ lib/active_record/fixtures.rb:518:in `map' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ lib/active_record/fixtures.rb:518:in `create_fixtures' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-jdbc- adapter-0.9.7-java/lib/jdbc_adapter/jdbc_mysql.rb:141:in `disable_referential_integrity' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ lib/active_record/fixtures.rb:515:in `create_fixtures' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activesupport-3.0.0/ lib/active_support/benchmarkable.rb:55:in `silence' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ lib/active_record/fixtures.rb:514:in `create_fixtures' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ lib/active_record/fixtures.rb:975:in `load_fixtures' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ lib/active_record/fixtures.rb:950:in `setup_fixtures' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- rails-2.0.0.beta.22/lib/rspec/rails/adapters.rb:11:in `setup' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/hooks.rb:29:in `instance_eval' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/hooks.rb:29:in `run_in' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/hooks.rb:60:in `run_all' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/hooks.rb:60:in `each' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/hooks.rb:60:in `run_all' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/hooks.rb:103:in `run_hook' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example_group.rb:186:in `eval_before_eachs' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example_group.rb:186:in `each' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example_group.rb:186:in `eval_before_eachs' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:128:in `run_before_each' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:51:in `run' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:93:in `call' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:93:in `with_around_hooks' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:49:in `run' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:87:in `call' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:87:in `with_pending_capture' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:86:in `catch' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:86:in `with_pending_capture' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example.rb:48:in `run' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example_group.rb:235:in `run_examples' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example_group.rb:232:in `map' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example_group.rb:232:in `run_examples' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/example_group.rb:216:in `run' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/command_line.rb:43:in `run_examples' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/command_line.rb:43:in `each' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/command_line.rb:43:in `inject' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/command_line.rb:43:in `run_examples' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/command_line.rb:26:in `run' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/reporter.rb:11:in `report' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/command_line.rb:23:in `run' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/runner.rb:36:in `run_in_process' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/lib/rspec/core/runner.rb:27:in `run' D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/bin/rspec:3 D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- core-2.0.0.beta.22/bin/rspec:19:in `load' D:/ruby/rubies/jruby-1.5.2/bin/rspec:19 D:/ruby/rubies/jruby-1.5.2/bin/rspec:1:in `load' -e:1: On Sep 22, 10:39?am, Bruno Cardoso wrote: > Hi David, > > Thanks for the reply but that didn't fix my problem. > > I think this is somehow related to fixtures, at least I only get this > problem on the specs that use fixtures and if I remove the fixtures, > it works. > > On Sep 22, 2:05?am, David Chelimsky wrote: > > > On Sep 21, 2010, at 10:58 AM, Bruno Cardoso wrote: > > > > I'm getting this errors from this spec:http://pastie.org/private/lm9nrqnmhqobs1avf3skgw > > > > Failures: > > > ?1) Account Account should have a relation belongs to with customer > > > ? ? Failure/Error: Unable to find matching line from backtrace > > > ? ? can't convert nil into String > > > ? ? # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 > > > > The spec is very simple. This was working with rails2+rspec1.3.... I'm > > > using rails3+rspec2 now. The error message is not very clear. > > > > Any idea why this happens? > > >http://github.com/rspec/rspec-core/issues#issue/146 > > _______________________________________________ > > 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 bcardoso.home at gmail.com Wed Sep 22 09:53:20 2010 From: bcardoso.home at gmail.com (Bruno Cardoso) Date: Wed, 22 Sep 2010 06:53:20 -0700 (PDT) Subject: [rspec-users] Failure/Error: Unable to find matching line from backtrace can't convert nil into String In-Reply-To: References: <985DC091-9B4B-44F2-9E72-C6E914C67572@gmail.com> <815118cc-6e17-4bed-8fa8-6d0e7a29c83a@m1g2000vbh.googlegroups.com> Message-ID: <752950e1-29d6-4837-83cd-b833f4b530d5@a30g2000vbt.googlegroups.com> Ok... found the problem... had this line in my spec helper commented =| config.fixture_path = "#{::Rails.root}/spec/fixtures" On Sep 22, 12:30?pm, Bruno Cardoso wrote: > TypeError: can't convert nil into String > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ > lib/active_record/fixtures.rb:519:in `create_fixtures' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ > lib/active_record/fixtures.rb:518:in `map' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ > lib/active_record/fixtures.rb:518:in `create_fixtures' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-jdbc- > adapter-0.9.7-java/lib/jdbc_adapter/jdbc_mysql.rb:141:in > `disable_referential_integrity' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ > lib/active_record/fixtures.rb:515:in `create_fixtures' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activesupport-3.0.0/ > lib/active_support/benchmarkable.rb:55:in `silence' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ > lib/active_record/fixtures.rb:514:in `create_fixtures' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ > lib/active_record/fixtures.rb:975:in `load_fixtures' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/activerecord-3.0.0/ > lib/active_record/fixtures.rb:950:in `setup_fixtures' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > rails-2.0.0.beta.22/lib/rspec/rails/adapters.rb:11:in `setup' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/hooks.rb:29:in `instance_eval' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/hooks.rb:29:in `run_in' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/hooks.rb:60:in `run_all' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/hooks.rb:60:in `each' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/hooks.rb:60:in `run_all' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/hooks.rb:103:in `run_hook' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example_group.rb:186:in > `eval_before_eachs' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example_group.rb:186:in `each' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example_group.rb:186:in > `eval_before_eachs' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:128:in `run_before_each' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:51:in `run' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:93:in `call' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:93:in `with_around_hooks' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:49:in `run' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:87:in `call' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:87:in > `with_pending_capture' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:86:in `catch' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:86:in > `with_pending_capture' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example.rb:48:in `run' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example_group.rb:235:in > `run_examples' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example_group.rb:232:in `map' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example_group.rb:232:in > `run_examples' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/example_group.rb:216:in `run' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/command_line.rb:43:in `run_examples' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/command_line.rb:43:in `each' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/command_line.rb:43:in `inject' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/command_line.rb:43:in `run_examples' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/command_line.rb:26:in `run' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/reporter.rb:11:in `report' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/command_line.rb:23:in `run' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/runner.rb:36:in `run_in_process' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/lib/rspec/core/runner.rb:27:in `run' > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/bin/rspec:3 > D:/ruby/rubies/jruby-1.5.2/lib/ruby/gems/1.8/gems/rspec- > core-2.0.0.beta.22/bin/rspec:19:in `load' > D:/ruby/rubies/jruby-1.5.2/bin/rspec:19 > D:/ruby/rubies/jruby-1.5.2/bin/rspec:1:in `load' > -e:1: > > On Sep 22, 10:39?am, Bruno Cardoso wrote: > > > Hi David, > > > Thanks for the reply but that didn't fix my problem. > > > I think this is somehow related to fixtures, at least I only get this > > problem on the specs that use fixtures and if I remove the fixtures, > > it works. > > > On Sep 22, 2:05?am, David Chelimsky wrote: > > > > On Sep 21, 2010, at 10:58 AM, Bruno Cardoso wrote: > > > > > I'm getting this errors from this spec:http://pastie.org/private/lm9nrqnmhqobs1avf3skgw > > > > > Failures: > > > > ?1) Account Account should have a relation belongs to with customer > > > > ? ? Failure/Error: Unable to find matching line from backtrace > > > > ? ? can't convert nil into String > > > > ? ? # D:\ruby\rubies\jruby-1.5.2\bin\rspec:19 > > > > > The spec is very simple. This was working with rails2+rspec1.3.... I'm > > > > using rails3+rspec2 now. The error message is not very clear. > > > > > Any idea why this happens? > > > >http://github.com/rspec/rspec-core/issues#issue/146 > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From joshwhiting at gmail.com Wed Sep 22 22:47:57 2010 From: joshwhiting at gmail.com (Josh Whiting) Date: Wed, 22 Sep 2010 19:47:57 -0700 Subject: [rspec-users] rspec runner setting $KCODE considered harmful? Message-ID: I ran across a problem today in which some code ran fine in regular operation but failed in a test case. I scratched my head and thought "why would running from within the test harness change the behavior of my code?" Clearly it was the Heisenberg uncertainty principle in action! :) I discovered the root cause was that the rspec runner is setting the magical ruby global, $KCODE, to 'u'. However, my application (which is not a rails app) had never specified $KCODE. I was relying on some default behavior of regular expressions under ruby 1.8 (byte-wise character matching semantics) that *change* when $KCODE is set to "u". Specifically, all regular expressions change their default behavior to utf-8 character-wise semantics. A simple example of this phenomenon: http://gist.github.com/592990 I've corrected the issue on my end by adopting the $KCODE='u' semantics in my application, but this led me to a couple comments/questions I thought would be relevant to raise with other rspec-minded folks: - Is it necessary for rspec to set $KCODE or is this a bug? Wouldn't it be better if it didn't twiddle any magical globals that change interpreter-wide behaviors? It reminds me of the bad days of perl when some distant code would unexpectedly change out your line terminator character on you. - It seems like a good idea to call out all the things the rspec environment changes that affect natural runtime behavior of code: twiddling of globals, class monkey patches, etc. It'd be great to get these into a list of publicly documented pitfalls for people to watch out for. Thanks for listening. Rspec has brought huge value to my engineering project and I really appreciate the tool! -Josh -------------- next part -------------- An HTML attachment was scrubbed... URL: From mykhaylo.gavrylyuk at gmail.com Wed Sep 22 15:52:54 2010 From: mykhaylo.gavrylyuk at gmail.com (MG) Date: Wed, 22 Sep 2010 12:52:54 -0700 (PDT) Subject: [rspec-users] Is this a bug? (before(:all) and after(:all) are run for each subcontext) Message-ID: <9692248b-1aac-45db-873a-8a093f37e8c5@n7g2000vbo.googlegroups.com> Rspec version is 1.3.0 Given following spec code: describe "SomeModule" do before(:all) { puts "BEFORE" } after(:all) { puts "AFTER"; puts } context "One" do it "should puts A" do puts "A" end it "should puts B" do puts "B" end end context "Two" do it "should puts C" do puts "C" end it "should puts D" do puts "D" end end end It results in following output: BEFORE C .D .AFTER BEFORE A .B .AFTER From dchelimsky at gmail.com Wed Sep 22 23:46:34 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Sep 2010 22:46:34 -0500 Subject: [rspec-users] Is this a bug? (before(:all) and after(:all) are run for each subcontext) In-Reply-To: <9692248b-1aac-45db-873a-8a093f37e8c5@n7g2000vbo.googlegroups.com> References: <9692248b-1aac-45db-873a-8a093f37e8c5@n7g2000vbo.googlegroups.com> Message-ID: On Sep 22, 2010, at 2:52 PM, MG wrote: > Rspec version is 1.3.0 > > Given following spec code: > > describe "SomeModule" do > before(:all) { puts "BEFORE" } > after(:all) { puts "AFTER"; puts } > > context "One" do > it "should puts A" do puts "A" end > it "should puts B" do puts "B" end > end > > context "Two" do > it "should puts C" do puts "C" end > it "should puts D" do puts "D" end > end > end > > It results in following output: > > BEFORE > C > .D > .AFTER > > BEFORE > A > .B > .AFTER It is a known issue in 1.3, but it will not be fixed in the 1.x series. It does work as you expect in 2.0. Cheers, David From lists at ruby-forum.com Thu Sep 23 06:17:11 2010 From: lists at ruby-forum.com (Dave Green) Date: Thu, 23 Sep 2010 12:17:11 +0200 Subject: [rspec-users] Cucumber Test - not strictly RSpec but testing related Message-ID: I am trying to test a webpage in cucumber that opens a new browser window, I have a feature like ... When I click the "transfer" button Then the user should see the "transfer" page I am having trouble with the second step because it opens in a new browser window, how do you detect this within a step definition? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Sep 23 09:08:38 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 23 Sep 2010 08:08:38 -0500 Subject: [rspec-users] Cucumber Test - not strictly RSpec but testing related In-Reply-To: References: Message-ID: <04044474-C5D8-4882-BB11-3FFF2B282883@gmail.com> On Sep 23, 2010, at 5:17 AM, Dave Green wrote: > I am trying to test a webpage in cucumber that opens a new browser > window, I have a feature like ... > > When I click the "transfer" button > Then the user should see the "transfer" page > > I am having trouble with the second step because it opens in a new > browser window, how do you detect this within a step definition? Cucumber has its own group. Please post this to http://groups.google.com/group/cukes. Cheers, David From dchelimsky at gmail.com Thu Sep 23 09:44:49 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 23 Sep 2010 08:44:49 -0500 Subject: [rspec-users] rspec runner setting $KCODE considered harmful? In-Reply-To: References: Message-ID: <4AF5A26A-8825-4FF0-9D75-2F22B71B960D@gmail.com> On Sep 22, 2010, at 9:47 PM, Josh Whiting wrote: > I ran across a problem today in which some code ran fine in regular operation but failed in a test case. I scratched my head and thought "why would running from within the test harness change the behavior of my code?" Clearly it was the Heisenberg uncertainty principle in action! :) > > I discovered the root cause was that the rspec runner is setting the magical ruby global, $KCODE, to 'u'. However, my application (which is not a rails app) had never specified $KCODE. I was relying on some default behavior of regular expressions under ruby 1.8 (byte-wise character matching semantics) that *change* when $KCODE is set to "u". Specifically, all regular expressions change their default behavior to utf-8 character-wise semantics. A simple example of this phenomenon: http://gist.github.com/592990 > > I've corrected the issue on my end by adopting the $KCODE='u' semantics in my application, but this led me to a couple comments/questions I thought would be relevant to raise with other rspec-minded folks: > > - Is it necessary for rspec to set $KCODE or is this a bug?Wouldn't it be better if it didn't twiddle any magical globals that change interpreter-wide behaviors? It reminds me of the bad days of perl when some distant code would unexpectedly change out your line terminator character on you. > > - It seems like a good idea to call out all the things the rspec environment changes that affect natural runtime behavior of code: twiddling of globals, class monkey patches, etc. It'd be great to get these into a list of publicly documented pitfalls for people to watch out for. > > Thanks for listening. Rspec has brought huge value to my engineering project and I really appreciate the tool! I don't remember the details, but that was added to solve a particular problem back in 2005 or 2006. Changing it in RSpec-1 would break some existing specs with a minor upgrade, so that's a non-option. This does not get set, however, in RSpec-2. I added a note about this to http://github.com/rspec/rspec-core/blob/master/Upgrade.markdown Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From curtis.schofield at gmail.com Thu Sep 23 13:34:12 2010 From: curtis.schofield at gmail.com (Curtis j Schofield) Date: Thu, 23 Sep 2010 10:34:12 -0700 Subject: [rspec-users] [Cross Post] Volunteers and Teachers <3 October 22-23 Rails Outreach for Women Message-ID: [Forgive the Crosspost - this is a community mailout ] What: October 22-23 Rails Outreach for Women URL: http://www.meetup.com/sfruby/calendar/14835957/ Short: Wanted : Rails, BDD/TDD, Cucumber, Ruby Teachers / Volunteer Long: Do you want to share your experience? Have you ever thought " Gee - I'm freaking awesome at X" ? Is X ruby or rails? We want you to come try your chops at volunteering and teaching! Maybe your bored with knowing everything about ruby and your cup is full? Come! Come! Come get humbled by newbies that are interested in learning - find out how rewarding and challenging it is to explain what a variable is - or what a class is - or what a method is. Or maybe you would prefer to work with PHP/Java/Basic/Etc programmers who are curious about what rails is and why people love ruby. You have a choice - Come and learn and teach with us - We want you Jest a little reminder! -- Rails Bridge San Francisco -- make haste slowly \ festina lente ?\ From joshwhiting at gmail.com Thu Sep 23 17:32:59 2010 From: joshwhiting at gmail.com (Josh Whiting) Date: Thu, 23 Sep 2010 14:32:59 -0700 Subject: [rspec-users] rspec runner setting $KCODE considered harmful? In-Reply-To: <4AF5A26A-8825-4FF0-9D75-2F22B71B960D@gmail.com> References: <4AF5A26A-8825-4FF0-9D75-2F22B71B960D@gmail.com> Message-ID: On Thu, Sep 23, 2010 at 6:44 AM, David Chelimsky wrote: > This does not get set, however, in RSpec-2. I added a note about this to > http://github.com/rspec/rspec-core/blob/master/Upgrade.markdown > Great, thanks for the pointer. Agreed changing something like this should probably not be done a point release... Cheers Josh -------------- next part -------------- An HTML attachment was scrubbed... URL: From gditrick at fuse.net Fri Sep 24 14:29:39 2010 From: gditrick at fuse.net (GregD) Date: Fri, 24 Sep 2010 11:29:39 -0700 (PDT) Subject: [rspec-users] Where do a set the description on a should satisfy. Message-ID: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> Hi all, Newbie here and I'm using rspec with jruby to test a java class, but this is more of a rspec question. I have a java HashMap object and want to make sure a key exists. I have this as my test: context :toHashMap do subject { @var_list.toHashMap } it { should satisfy{|a| a.contains_key?(var1) } } it { should satisfy{|a| a.contains_key?(var2) } } it { should satisfy{|a| a.contains_key?(var3) } } end @var_list is set to another java object that has a method toHashMap that returns a HashMap. var1, var2 and var3 are set using let(:var1), etc. If the one of these fails, I get this telling me that I need to supply a description method: >>>>>> 'Java::LibraryLanguage::XmlVariableList when added duplicate variables with different values toHashMap should When you call a matcher in an example without a String, like this: specify { object.should matcher } or this: it { should matcher } RSpec expects the matcher to have a #description method. You should either add a String to the example this matcher is being used in, or give it a description method. Then you won't have to suffer this lengthy warning again. ' FAILED expected {var01=2, var02=this-is-a-string} to satisfy block <<<<<<< I'd like to put 'contain the key ' in place of 'When you call a matcher in an example without a String' Where do I put that string? I thought I could just do: it "should contain the key #{var1}" { should satisify{|a| a.contains_key?(var1) } } But, the loading complains on that. Where can a put a custom description into this code (easily/polite way). Thanks, GregD From dchelimsky at gmail.com Sun Sep 26 18:37:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 26 Sep 2010 17:37:03 -0500 Subject: [rspec-users] Where do a set the description on a should satisfy. In-Reply-To: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> References: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> Message-ID: <4FBA1F2A-57BD-4F22-A0F7-E129ED268947@gmail.com> On Sep 24, 2010, at 1:29 PM, GregD wrote: > Hi all, > > Newbie here and I'm using rspec with jruby to test a java class, but > this is more of a rspec question. > > I have a java HashMap object and want to make sure a key exists. I > have this as my test: > > context :toHashMap do > subject { @var_list.toHashMap } > > it { should satisfy{|a| a.contains_key?(var1) } } > it { should satisfy{|a| a.contains_key?(var2) } } > it { should satisfy{|a| a.contains_key?(var3) } } > end > > @var_list is set to another java object that has a method toHashMap > that returns > a HashMap. var1, var2 and var3 are set using let(:var1), etc. If the > one of > these fails, I get this telling me that I need to supply a description > method: > > 'Java::LibraryLanguage::XmlVariableList when added duplicate variables > with different values toHashMap should When you call a matcher in an > example without a String, like this: > > specify { object.should matcher } > > or this: > > it { should matcher } > > RSpec expects the matcher to have a #description method. You should > either > add a String to the example this matcher is being used in, or give it > a > description method. Then you won't have to suffer this lengthy warning > again. > ' FAILED > expected {var01=2, var02=this-is-a-string} to satisfy block > <<<<<<< > > > I'd like to put 'contain the key ' in place of 'When you call a > matcher in > an example without a String' > > Where do I put that string? I thought I could just do: > > it "should contain the key #{var1}" { should satisify{|a| > a.contains_key?(var1) > } } > > But, the loading complains on that. Where can a put a custom > description into > this code (easily/polite way). Congratulations - you're apparently the first person to ever use the satisfy matcher with an implicit subject, and have uncovered a bug! http://github.com/rspec/rspec-expectations/issues/issue/20 I'd recommend not using that satisfy matcher for this case though, as it's really intended to be more of a last resort, and you can do much better with a custom matcher: RSpec::Matchers.define :contain_key do |key| match do |subject| subject.contains_key?(key) end end Then you can say: context :toHashMap do subject { @var_list.toHashMap } it { should contain_key(var1) } it { should contain_key(var2) } it { should contain_key(var3) } end More info on custom matchers: http://github.com/rspec/rspec-expectations/blob/master/features/matchers/define_matcher.feature HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon Sep 27 01:11:05 2010 From: lists at ruby-forum.com (Senthil kumar Loganathan) Date: Mon, 27 Sep 2010 07:11:05 +0200 Subject: [rspec-users] cucumber generator error in rails 3 Message-ID: I have my Gem file as mentioned in the github gem 'capybara' gem 'database_cleaner' gem 'cucumber-rails' gem 'cucumber' gem 'rspec-rails' gem 'spork' gem 'launchy but when i give rails generate cucumber:install, I am getting the error saying 'Could not find generator cucumber:install.' Did I missed any gems or do I need to do any configurations? -- Posted via http://www.ruby-forum.com/. From brennon at brennonbortz.com Mon Sep 27 04:27:33 2010 From: brennon at brennonbortz.com (Brennon Bortz) Date: Mon, 27 Sep 2010 09:27:33 +0100 Subject: [rspec-users] cucumber generator error in rails 3 In-Reply-To: References: Message-ID: <1285576053.20986.0.camel@tallis> On Mon, 2010-09-27 at 07:11 +0200, Senthil kumar Loganathan wrote: > I have my Gem file as mentioned in the github > gem 'capybara' > gem 'database_cleaner' > gem 'cucumber-rails' > gem 'cucumber' > gem 'rspec-rails' > gem 'spork' > gem 'launchy > > but when i give rails generate cucumber:install, I am getting the error > saying 'Could not find generator cucumber:install.' Did I missed any > gems or do I need to do any configurations? Have you run 'bundle install' yet? From tero at tilus.net Mon Sep 27 03:25:09 2010 From: tero at tilus.net (Tero Tilus) Date: Mon, 27 Sep 2010 10:25:09 +0300 Subject: [rspec-users] cucumber generator error in rails 3 In-Reply-To: References: Message-ID: <1285571418-sup-8691@tilus.net> Senthil kumar Loganathan, 2010-09-27 08:11: > Did I missed any gems or do I need to do any configurations? I had cucumber:install work fine with rails3. Did you remember to `bundle install`? Also you did not seem to have Rails in your Gemfile. Do you have it vendored or? If `rails --version` is different from `script/rails --version` you might want to use the later. My Gemfile looks like this. gem 'rails', '3.0.0' gem 'authlogic', :git => 'http://github.com/binarylogic/authlogic.git' group :production do gem 'mysql2' end group :test do gem 'rspec-rails', '>= 2.0.0.beta.22' gem 'cucumber-rails' gem 'capybara' end group :development do gem 'sqlite3-ruby', :require => 'sqlite3' gem 'ruby-debug' end You can use `bundle list` and `bundle show` to see what you have and where did they come from. `script/rails g` should list the generators you have, including the two Cucumber generators. Bundler basics, see http://gembundler.com/rationale.html -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ From gditrick at fuse.net Mon Sep 27 09:05:11 2010 From: gditrick at fuse.net (GregD) Date: Mon, 27 Sep 2010 06:05:11 -0700 (PDT) Subject: [rspec-users] Where do a set the description on a should satisfy. In-Reply-To: <4FBA1F2A-57BD-4F22-A0F7-E129ED268947@gmail.com> References: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> <4FBA1F2A-57BD-4F22-A0F7-E129ED268947@gmail.com> Message-ID: <45d72eaf-b5b4-480b-be4d-b80af86d0ffe@l20g2000yqm.googlegroups.com> That helped a lot and I see it is a better/more polite 1-liner-way. Do you recommend that these custom matchers probably need to go into a spec helper for standard java classes and included since contains_key? (key) maps to the java HashMap method containsKey(key)? Do I put these in a ruby module to be included? Thanks, GregD (newbie) On Sep 26, 6:37?pm, David Chelimsky wrote: > On Sep 24, 2010, at 1:29 PM, GregD wrote: > > > > > > > Hi all, > > > Newbie here and I'm using rspec with jruby to test a java class, but > > this is more of a rspec question. > > > I have a java HashMap object and want to make sure a key exists. ?I > > have this as my test: > > > ? ?context :toHashMap do > > ? ? ?subject { @var_list.toHashMap } > > > ? ? ?it { should satisfy{|a| a.contains_key?(var1) } } > > ? ? ?it { should satisfy{|a| a.contains_key?(var2) } } > > ? ? ?it { should satisfy{|a| a.contains_key?(var3) } } > > ? ?end > > > @var_list is set to another java object that has a method toHashMap > > that returns > > a HashMap. ?var1, var2 and var3 are set using let(:var1), etc. ?If the > > one of > > these fails, I get this telling me that I need to supply a description > > method: > > > 'Java::LibraryLanguage::XmlVariableList when added duplicate variables > > with different values toHashMap should When you call a matcher in an > > example without a String, like this: > > > specify { object.should matcher } > > > or this: > > > it { should matcher } > > > RSpec expects the matcher to have a #description method. You should > > either > > add a String to the example this matcher is being used in, or give it > > a > > description method. Then you won't have to suffer this lengthy warning > > again. > > ' FAILED > > expected {var01=2, var02=this-is-a-string} to satisfy block > > <<<<<<< > > > I'd like to put 'contain the key ' in place of 'When you call a > > matcher in > > an example without a String' > > > Where do I put that string? ?I thought I could just do: > > > it "should contain the key #{var1}" { should satisify{|a| > > a.contains_key?(var1) > > } } > > > But, the loading complains on that. ?Where can a put a custom > > description into > > this code (easily/polite way). > > Congratulations - you're apparently the first person to ever use the satisfy matcher with an implicit subject, and have uncovered a bug! > > http://github.com/rspec/rspec-expectations/issues/issue/20 > > I'd recommend not using that satisfy matcher for this case though, as it's really intended to be more of a last resort, and you can do much better with a custom matcher: > > ? RSpec::Matchers.define :contain_key do |key| > ? ? match do |subject| > ? ? ? subject.contains_key?(key) > ? ? end > ? end > > Then you can say: > > ? context :toHashMap do > ? ? subject { @var_list.toHashMap } > > ? ? it { should contain_key(var1) } > ? ? it { should contain_key(var2) } > ? ? it { should contain_key(var3) } > ? end > > More info on custom matchers:http://github.com/rspec/rspec-expectations/blob/master/features/match... > > HTH, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Sep 27 09:12:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 27 Sep 2010 08:12:33 -0500 Subject: [rspec-users] Where do a set the description on a should satisfy. In-Reply-To: <45d72eaf-b5b4-480b-be4d-b80af86d0ffe@l20g2000yqm.googlegroups.com> References: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> <4FBA1F2A-57BD-4F22-A0F7-E129ED268947@gmail.com> <45d72eaf-b5b4-480b-be4d-b80af86d0ffe@l20g2000yqm.googlegroups.com> Message-ID: <1ECF67F8-9194-4DDF-A4AA-F5E52532FA3A@gmail.com> On Sep 27, 2010, at 8:05 AM, GregD wrote: > On Sep 26, 6:37 pm, David Chelimsky wrote: >> On Sep 24, 2010, at 1:29 PM, GregD wrote: >>> Hi all, >> >>> Newbie here and I'm using rspec with jruby to test a java class, but >>> this is more of a rspec question. >> >>> I have a java HashMap object and want to make sure a key exists. I >>> have this as my test: >> >>> context :toHashMap do >>> subject { @var_list.toHashMap } >> >>> it { should satisfy{|a| a.contains_key?(var1) } } >>> it { should satisfy{|a| a.contains_key?(var2) } } >>> it { should satisfy{|a| a.contains_key?(var3) } } >>> end >> >>> @var_list is set to another java object that has a method toHashMap >>> that returns >>> a HashMap. var1, var2 and var3 are set using let(:var1), etc. If the >>> one of >>> these fails, I get this telling me that I need to supply a description >>> method: >> >>> 'Java::LibraryLanguage::XmlVariableList when added duplicate variables >>> with different values toHashMap should When you call a matcher in an >>> example without a String, like this: >> >>> specify { object.should matcher } >> >>> or this: >> >>> it { should matcher } >> >>> RSpec expects the matcher to have a #description method. You should >>> either >>> add a String to the example this matcher is being used in, or give it >>> a >>> description method. Then you won't have to suffer this lengthy warning >>> again. >>> ' FAILED >>> expected {var01=2, var02=this-is-a-string} to satisfy block >>> <<<<<<< >> >>> I'd like to put 'contain the key ' in place of 'When you call a >>> matcher in >>> an example without a String' >> >>> Where do I put that string? I thought I could just do: >> >>> it "should contain the key #{var1}" { should satisify{|a| >>> a.contains_key?(var1) >>> } } >> >>> But, the loading complains on that. Where can a put a custom >>> description into >>> this code (easily/polite way). >> >> Congratulations - you're apparently the first person to ever use the satisfy matcher with an implicit subject, and have uncovered a bug! >> >> http://github.com/rspec/rspec-expectations/issues/issue/20 >> >> I'd recommend not using that satisfy matcher for this case though, as it's really intended to be more of a last resort, and you can do much better with a custom matcher: >> >> RSpec::Matchers.define :contain_key do |key| >> match do |subject| >> subject.contains_key?(key) >> end >> end >> >> Then you can say: >> >> context :toHashMap do >> subject { @var_list.toHashMap } >> >> it { should contain_key(var1) } >> it { should contain_key(var2) } >> it { should contain_key(var3) } >> end >> >> More info on custom matchers:http://github.com/rspec/rspec-expectations/blob/master/features/match... >> >> HTH, >> David > That helped a lot and I see it is a better/more polite 1-liner-way. > Do you recommend that these custom matchers probably need to go into a > spec helper for standard java classes and included since contains_key? > (key) maps to the java HashMap method containsKey(key)? Do I put > these in a ruby module to be included? [I moved your responses to the bottom. Please use bottom or inline posting rather than top posting. ] The convention is to have a line like this in spec/spec_helper.rb: Dir["./spec/support/**/*.rb"].each {|f| require f} And then keep matchers and other support files under ./spec/support/ HTH, David From dchelimsky at gmail.com Mon Sep 27 09:14:01 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 27 Sep 2010 08:14:01 -0500 Subject: [rspec-users] Where do a set the description on a should satisfy. In-Reply-To: <1ECF67F8-9194-4DDF-A4AA-F5E52532FA3A@gmail.com> References: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> <4FBA1F2A-57BD-4F22-A0F7-E129ED268947@gmail.com> <45d72eaf-b5b4-480b-be4d-b80af86d0ffe@l20g2000yqm.googlegroups.com> <1ECF67F8-9194-4DDF-A4AA-F5E52532FA3A@gmail.com> Message-ID: <9D279667-5052-4828-8B73-1CF5CC771139@gmail.com> On Sep 27, 2010, at 8:12 AM, David Chelimsky wrote: > > On Sep 27, 2010, at 8:05 AM, GregD wrote: > >> On Sep 26, 6:37 pm, David Chelimsky wrote: >>> On Sep 24, 2010, at 1:29 PM, GregD wrote: >>>> Hi all, >>> >>>> Newbie here and I'm using rspec with jruby to test a java class, but >>>> this is more of a rspec question. >>> >>>> I have a java HashMap object and want to make sure a key exists. I >>>> have this as my test: >>> >>>> context :toHashMap do >>>> subject { @var_list.toHashMap } >>> >>>> it { should satisfy{|a| a.contains_key?(var1) } } >>>> it { should satisfy{|a| a.contains_key?(var2) } } >>>> it { should satisfy{|a| a.contains_key?(var3) } } >>>> end >>> >>>> @var_list is set to another java object that has a method toHashMap >>>> that returns >>>> a HashMap. var1, var2 and var3 are set using let(:var1), etc. If the >>>> one of >>>> these fails, I get this telling me that I need to supply a description >>>> method: >>> >>>> 'Java::LibraryLanguage::XmlVariableList when added duplicate variables >>>> with different values toHashMap should When you call a matcher in an >>>> example without a String, like this: >>> >>>> specify { object.should matcher } >>> >>>> or this: >>> >>>> it { should matcher } >>> >>>> RSpec expects the matcher to have a #description method. You should >>>> either >>>> add a String to the example this matcher is being used in, or give it >>>> a >>>> description method. Then you won't have to suffer this lengthy warning >>>> again. >>>> ' FAILED >>>> expected {var01=2, var02=this-is-a-string} to satisfy block >>>> <<<<<<< >>> >>>> I'd like to put 'contain the key ' in place of 'When you call a >>>> matcher in >>>> an example without a String' >>> >>>> Where do I put that string? I thought I could just do: >>> >>>> it "should contain the key #{var1}" { should satisify{|a| >>>> a.contains_key?(var1) >>>> } } >>> >>>> But, the loading complains on that. Where can a put a custom >>>> description into >>>> this code (easily/polite way). >>> >>> Congratulations - you're apparently the first person to ever use the satisfy matcher with an implicit subject, and have uncovered a bug! >>> >>> http://github.com/rspec/rspec-expectations/issues/issue/20 >>> >>> I'd recommend not using that satisfy matcher for this case though, as it's really intended to be more of a last resort, and you can do much better with a custom matcher: >>> >>> RSpec::Matchers.define :contain_key do |key| >>> match do |subject| >>> subject.contains_key?(key) >>> end >>> end >>> >>> Then you can say: >>> >>> context :toHashMap do >>> subject { @var_list.toHashMap } >>> >>> it { should contain_key(var1) } >>> it { should contain_key(var2) } >>> it { should contain_key(var3) } >>> end >>> >>> More info on custom matchers:http://github.com/rspec/rspec-expectations/blob/master/features/match... >>> >>> HTH, >>> David > >> That helped a lot and I see it is a better/more polite 1-liner-way. >> Do you recommend that these custom matchers probably need to go into a >> spec helper for standard java classes and included since contains_key? >> (key) maps to the java HashMap method containsKey(key)? Do I put >> these in a ruby module to be included? > > [I moved your responses to the bottom. Please use bottom or inline posting rather than top posting. ] > > The convention is to have a line like this in spec/spec_helper.rb: > > Dir["./spec/support/**/*.rb"].each {|f| require f} > > And then keep matchers and other support files under ./spec/support/ re: how to include them: yes, in a module: # in spec/support/custom_matchers.rb module CustomMatchers ... end # in spec/spec_helper.rb RSpec.configure do |c| c.include CustomMatchers end Make sense? From gditrick at fuse.net Mon Sep 27 09:48:51 2010 From: gditrick at fuse.net (Greg Ditrick) Date: Mon, 27 Sep 2010 9:48:51 -0400 Subject: [rspec-users] Where do a set the description on a should satisfy. Message-ID: <28040420.1285595331951.JavaMail.root@wmvirt8> ---- David Chelimsky wrote: > > On Sep 27, 2010, at 8:12 AM, David Chelimsky wrote: > > re: how to include them: yes, in a module: > > # in spec/support/custom_matchers.rb > module CustomMatchers > ... > end > > # in spec/spec_helper.rb > RSpec.configure do |c| > c.include CustomMatchers > end > > Make sense? Yes. Thanks. GregD From gditrick at fuse.net Mon Sep 27 10:23:13 2010 From: gditrick at fuse.net (GregD) Date: Mon, 27 Sep 2010 07:23:13 -0700 (PDT) Subject: [rspec-users] Where do a set the description on a should satisfy. In-Reply-To: <9D279667-5052-4828-8B73-1CF5CC771139@gmail.com> References: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> <4FBA1F2A-57BD-4F22-A0F7-E129ED268947@gmail.com> <45d72eaf-b5b4-480b-be4d-b80af86d0ffe@l20g2000yqm.googlegroups.com> <1ECF67F8-9194-4DDF-A4AA-F5E52532FA3A@gmail.com> <9D279667-5052-4828-8B73-1CF5CC771139@gmail.com> Message-ID: <184c45d1-3af8-40a4-bc3a-66a2f1f9a695@k10g2000yqa.googlegroups.com> On Sep 27, 9:14?am, David Chelimsky wrote: > On Sep 27, 2010, at 8:12 AM, David Chelimsky wrote: > > > > > > > > re: how to include them: yes, in a module: > > # in spec/support/custom_matchers.rb > module CustomMatchers > ? ... > end > > # in spec/spec_helper.rb > RSpec.configure do |c| > ? c.include CustomMatchers > end > Okay, 1 more question and maybe this is more of a convention request. I know in my rails apps that my environment is loaded when running my specs from a rake task or from the spec command. But for a non-rails app, it would be nice to default spec program to load spec_helper if it exists in the spec dir. Like: jruby -S spec spec instead of having to do this to include the spec_helper every time: jruby -S spec -r spec/spec_helper.rb spec Or am I missing something? Or is that just not desirable? I know I can use rake and create a rake task(s), but from the perspective of the command line, it would be nice to not to have to supply the -r option unless you want to include something "outside" of this convention. Regards, GregD From ben at benmabey.com Mon Sep 27 12:38:51 2010 From: ben at benmabey.com (Ben Mabey) Date: Mon, 27 Sep 2010 10:38:51 -0600 Subject: [rspec-users] Where do a set the description on a should satisfy. In-Reply-To: <184c45d1-3af8-40a4-bc3a-66a2f1f9a695@k10g2000yqa.googlegroups.com> References: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> <4FBA1F2A-57BD-4F22-A0F7-E129ED268947@gmail.com> <45d72eaf-b5b4-480b-be4d-b80af86d0ffe@l20g2000yqm.googlegroups.com> <1ECF67F8-9194-4DDF-A4AA-F5E52532FA3A@gmail.com> <9D279667-5052-4828-8B73-1CF5CC771139@gmail.com> <184c45d1-3af8-40a4-bc3a-66a2f1f9a695@k10g2000yqa.googlegroups.com> Message-ID: <4CA0C89B.1060901@benmabey.com> On 9/27/10 8:23 AM, GregD wrote: > > On Sep 27, 9:14 am, David Chelimsky wrote: >> On Sep 27, 2010, at 8:12 AM, David Chelimsky wrote: >> >> >> >> >> >> >> >> re: how to include them: yes, in a module: >> >> # in spec/support/custom_matchers.rb >> module CustomMatchers >> ... >> end >> >> # in spec/spec_helper.rb >> RSpec.configure do |c| >> c.include CustomMatchers >> end >> > Okay, 1 more question and maybe this is more of a convention request. > I know in my rails apps that my environment is loaded when running my > specs from a rake task or from the spec command. But for a non-rails > app, it would be nice to default spec program to load spec_helper if > it exists in the spec dir. Like: > > jruby -S spec spec > > instead of having to do this to include the spec_helper every time: > > jruby -S spec -r spec/spec_helper.rb spec > > Or am I missing something? Or is that just not desirable? I know I > can use rake and create a rake task(s), but from the perspective of > the command line, it would be nice to not to have to supply the -r > option unless you want to include something "outside" of this > convention. > For rails and non-rails apps/libs the convention is to have each *_spec.rb file require the 'spec_helper' at the top of the spec like so: http://github.com/rspec/rspec-core/blob/master/spec/rspec/core_spec.rb#L1 By following this convention you will only have to specify the spec on the command line. HTH, Ben From gditrick at fuse.net Mon Sep 27 12:46:35 2010 From: gditrick at fuse.net (GregD) Date: Mon, 27 Sep 2010 09:46:35 -0700 (PDT) Subject: [rspec-users] Where do a set the description on a should satisfy. In-Reply-To: <4CA0C89B.1060901@benmabey.com> References: <9208649f-8357-452f-a220-f08727075271@f26g2000vbm.googlegroups.com> <4FBA1F2A-57BD-4F22-A0F7-E129ED268947@gmail.com> <45d72eaf-b5b4-480b-be4d-b80af86d0ffe@l20g2000yqm.googlegroups.com> <1ECF67F8-9194-4DDF-A4AA-F5E52532FA3A@gmail.com> <9D279667-5052-4828-8B73-1CF5CC771139@gmail.com> <184c45d1-3af8-40a4-bc3a-66a2f1f9a695@k10g2000yqa.googlegroups.com> <4CA0C89B.1060901@benmabey.com> Message-ID: On Sep 27, 12:38?pm, Ben Mabey wrote: > For rails and non-rails apps/libs the convention is to have each > *_spec.rb file require the 'spec_helper' at the top of the spec like so: > > http://github.com/rspec/rspec-core/blob/master/spec/rspec/core_spec.r... > > By following this convention you will only have to specify the spec on > the command line. > Duh! Thanks. Brain fart on my part. I went and looked back at my rails apps and yes I missed that for these specs. Works like a charm. Sorry for being stupid. GregD From cdechauri at gmail.com Mon Sep 27 16:11:03 2010 From: cdechauri at gmail.com (=?ISO-8859-1?Q?Carmen_D=EDaz_Echauri?=) Date: Mon, 27 Sep 2010 13:11:03 -0700 Subject: [rspec-users] having some issues with factory_girl and bundler... Message-ID: Hi All Need some brilliants minds here :) I'm using Rails 2.3.8 & ruby 1.8 (I know, I know... ) I've move my gems from .gems to Bundler, but I'm having some issues with Factory_girl when I rake spec "uninitialized constant Factory" I'm following the instructions from http://gembundler.com/rails23.html. Basically: - grab all config.gem and place them into Gemfile - bundle install - check Gemfile.lock in my repository .. etc I even tried with a new dummy app from scratch and got the samething... /script/console test Loading test environment (Rails 2.3.8) >> Factory NameError: uninitialized constant Factory from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing' from (irb):1 >> require 'factory_girl' => true >> My Gemfile looks like this source :gemcutter # gem "rails", "2.3.8" gem "memcached-northscale" gem "uuidtools", ">= 1.0.2" gem "json", ">= 1.2.4" gem "nokogiri", ">= 1.4.0" gem "tzinfo", ">=0.3.5" gem "SystemTimer", ">=1.1.3" gem "will_paginate", ">= 2.3.11" gem "taf2-curb", ">=0.3.5.0" gem "pg" gem "hoptoad_notifier" gem "treetop" gem "term-ansicolor" gem "diff-lcs" group :development, :test do gem "factory_girl", :require => 'factory Note: last tried... Placing it outside of the groups, throw the same error... gem "rspec" gem "rspec-rails", ">= 1.3.2" gem "webrat", ">=0.5.3" gem "ruby-debug" end Any ideas? Suggestions? BTW Samething is happening with will_paginate Thanks a lot for your help. You guys rock! -- Carmen -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Mon Sep 27 17:05:10 2010 From: jko170 at gmail.com (Justin Ko) Date: Mon, 27 Sep 2010 14:05:10 -0700 (PDT) Subject: [rspec-users] having some issues with factory_girl and bundler... In-Reply-To: References: Message-ID: On Sep 27, 4:11?pm, Carmen D?az Echauri wrote: > Hi All > > Need some brilliants minds here :) > > I'm using Rails 2.3.8 & ruby 1.8 (I know, I know... ) > I've move my gems from .gems to Bundler, but I'm having some issues with > Factory_girl when I rake spec > "uninitialized constant Factory" > > I'm following the instructions fromhttp://gembundler.com/rails23.html. > Basically: > - grab all config.gem and place them into Gemfile > - bundle install > - check ?Gemfile.lock in my repository .. etc > > ?I even tried with a new dummy app from scratch and got the samething... > /script/console test > Loading test environment (Rails 2.3.8) > > >> Factory > > NameError: uninitialized constant Factory > ? ? from > /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependen cies.rb:443:in > `load_missing_constant' > ? ? from > /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependen cies.rb:80:in > `const_missing' > ? ? from > /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependen cies.rb:92:in > `const_missing' > ? ? from (irb):1 > > >> require 'factory_girl' > => true > > My Gemfile looks like this > > source :gemcutter > # > gem "rails", "2.3.8" > gem "memcached-northscale" > gem "uuidtools", ?">= 1.0.2" > gem "json", ?">= 1.2.4" > gem "nokogiri", ?">= 1.4.0" > gem "tzinfo", ?">=0.3.5" > gem "SystemTimer", ">=1.1.3" > gem "will_paginate", ">= 2.3.11" > gem "taf2-curb", ">=0.3.5.0" > gem "pg" > gem "hoptoad_notifier" > gem "treetop" > gem "term-ansicolor" > gem "diff-lcs" > > group :development, :test do > ? gem "factory_girl", :require => 'factory ?Note: last tried... Placing it > outside of the groups, throw the same error... > ? gem "rspec" > ? gem "rspec-rails", ">= 1.3.2" > ? gem "webrat", ">=0.5.3" > ? gem "ruby-debug" > end > > Any ideas? Suggestions? > BTW Samething is happening with will_paginate > > Thanks a lot for your help. ?You guys rock! > > -- > Carmen > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users Try: gem 'factory_girl_rails' From cdemyanovich at gmail.com Mon Sep 27 18:22:50 2010 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Mon, 27 Sep 2010 18:22:50 -0400 Subject: [rspec-users] having some issues with factory_girl and bundler... In-Reply-To: References: Message-ID: On Mon, Sep 27, 2010 at 5:05 PM, Justin Ko wrote: > > > On Sep 27, 4:11 pm, Carmen D?az Echauri wrote: > > Hi All > > > > Need some brilliants minds here :) > > > > I'm using Rails 2.3.8 & ruby 1.8 (I know, I know... ) > > I've move my gems from .gems to Bundler, but I'm having some issues with > > Factory_girl when I rake spec > > "uninitialized constant Factory" > ... > Try: > > gem 'factory_girl_rails' According to http://github.com/thoughtbot/factory_girl, that's only for Rails 3: "If you want to use factory_girl with Rails 3, see github.com/thoughtbot/factory_girl_rails." I've been working on moving a Rails 2.3.9 app to Bundler 1.0.0 from a custom solution. The app uses factory_girl with rspec and cucumber, and all the specs and cukes run successfully. At the bottom of config/environments/cucumber.rb, I have require 'factory_girl'. I don't have any similar requires in config/environments/test.rb or in spec/spec_helper.rb. Here's the current Gemfile: source "http://rubygems.org" gem "rails", "~> 2.3.9" gem "rake", "~> 0.8.7" gem "haml", "~> 3.0.18" gem "fastercsv", "~> 1.5.3" gem "will_paginate", "~> 2.3.12" gem "rspec", "~> 1.3.0", :group => [:test, :cucumber] gem "rspec-rails", "~> 1.3.2", :group => [:test, :cucumber] gem "capybara", "~> 0.3.8", :group => [:cucumber] gem "cucumber", "~> 0.7.3", :group => [:cucumber] gem "cucumber-rails", "~> 0.3.1", :group => [:cucumber] gem "gherkin", "~> 1.0.30", :group => [:cucumber] gem "database_cleaner", "~> 0.5.0", :group => [:cucumber] gem "dupe", "~> 0.5.1", :group => [:test, :cucumber] gem "factory_girl", "~> 1.2.4", :group => [:test, :cucumber] platforms :jruby do gem "jruby-openssl", "~> 0.7.1" gem "jruby-rack", "~> 1.0.3" gem "warbler", "~> 1.0.1" gem "flying_saucer", "~> 0.8.0" group :db do gem "jdbc-mysql", "~> 5.0.4" gem "activerecord-jdbc-adapter", "~> 0.9.2" gem "activerecord-jdbcmysql-adapter", "~> 0.9.2" end end Note that I'm not using the :require option with gem "factory_girl." Since I don't have any ideas about your specific errors and I have to head out to an appointment, I hope all of this helps. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Mon Sep 27 18:28:24 2010 From: jko170 at gmail.com (Justin Ko) Date: Mon, 27 Sep 2010 15:28:24 -0700 (PDT) Subject: [rspec-users] having some issues with factory_girl and bundler... In-Reply-To: References: Message-ID: <962e0bf2-8573-4a5a-9446-2765dabe882a@x12g2000yqj.googlegroups.com> On Sep 27, 6:22?pm, Craig Demyanovich wrote: > On Mon, Sep 27, 2010 at 5:05 PM, Justin Ko wrote: > > > On Sep 27, 4:11 pm, Carmen D?az Echauri wrote: > > > Hi All > > > > Need some brilliants minds here :) > > > > I'm using Rails 2.3.8 & ruby 1.8 (I know, I know... ) > > > I've move my gems from .gems to Bundler, but I'm having some issues with > > > Factory_girl when I rake spec > > > "uninitialized constant Factory" > > ... > > > Try: > > > gem 'factory_girl_rails' > > According tohttp://github.com/thoughtbot/factory_girl, that's only for > Rails 3: "If you want to use factory_girl with Rails 3, see > github.com/thoughtbot/factory_girl_rails." > > I've been working on moving a Rails 2.3.9 app to Bundler 1.0.0 from a custom > solution. The app uses factory_girl with rspec and cucumber, and all the > specs and cukes run successfully. At the bottom of > config/environments/cucumber.rb, I have require 'factory_girl'. I don't have > any similar requires in config/environments/test.rb or in > spec/spec_helper.rb. > > Here's the current Gemfile: > > source "http://rubygems.org" > > gem "rails", "~> 2.3.9" > > gem "rake", ? ? ? ? ?"~> 0.8.7" > gem "haml", ? ? ? ? ?"~> 3.0.18" > gem "fastercsv", ? ? "~> 1.5.3" > gem "will_paginate", "~> 2.3.12" > > gem "rspec", ? ? ? ? ? ?"~> 1.3.0", ?:group => [:test, :cucumber] > gem "rspec-rails", ? ? ?"~> 1.3.2", ?:group => [:test, :cucumber] > gem "capybara", ? ? ? ? "~> 0.3.8", ?:group => [:cucumber] > gem "cucumber", ? ? ? ? "~> 0.7.3", ?:group => [:cucumber] > gem "cucumber-rails", ? "~> 0.3.1", ?:group => [:cucumber] > gem "gherkin", ? ? ? ? ?"~> 1.0.30", :group => [:cucumber] > gem "database_cleaner", "~> 0.5.0", ?:group => [:cucumber] > gem "dupe", ? ? ? ? ? ? "~> 0.5.1", ?:group => [:test, :cucumber] > gem "factory_girl", ? ? "~> 1.2.4", ?:group => [:test, :cucumber] > > platforms :jruby do > ? gem "jruby-openssl", "~> 0.7.1" > ? gem "jruby-rack", ? ?"~> 1.0.3" > ? gem "warbler", ? ? ? "~> 1.0.1" > ? gem "flying_saucer", "~> 0.8.0" > > ? group :db do > ? ? gem "jdbc-mysql", ? ? ? ? ? ? ? ? ? ? "~> 5.0.4" > ? ? gem "activerecord-jdbc-adapter", ? ? ?"~> 0.9.2" > ? ? gem "activerecord-jdbcmysql-adapter", "~> 0.9.2" > ? end > > end > > Note that I'm not using the :require option with gem "factory_girl." > > Since I don't have any ideas about your specific errors and I have to head > out to an appointment, I hope all of this helps. > > Regards, > Craig > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users My only guess is he is calling Factory somewhere where it is not available. From amir.nagri at gmail.com Wed Sep 29 01:44:13 2010 From: amir.nagri at gmail.com (Amiruddin Nagri) Date: Wed, 29 Sep 2010 11:14:13 +0530 Subject: [rspec-users] route_to to test root route Message-ID: I am working on a Rails 3 application using RSPec 2.beta.20. I am having the following routes in my routes.rb routes.rb ------------ resources :projects root :to => 'projects#index' I am trying to test both the routes. But while testing root route I am getting a failure : it 'should route root to projects#index' do {:get => '/'}.should route_to(:controller => 'projects', :action => 'index') end But the above example is failing since route_to is expecting a route like '/projects'. Is there a way to test root routes which are also configured elsewhere in the routes.rb. Regards, Amiruddin Nagri, Bangalore, 560008, KA India Y! IM : amir_nagri at yahoo.com GTalk : amir.nagri at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From amir.nagri at gmail.com Wed Sep 29 02:42:26 2010 From: amir.nagri at gmail.com (Amiruddin Nagri) Date: Wed, 29 Sep 2010 12:12:26 +0530 Subject: [rspec-users] autotest giving error when having shared example in specs Message-ID: I am having a shared example 'allow authorized actions' for my Rails 3 RSpec 2.beta.20 application. The shared example looks like share_examples_for 'allow authorized actions' do ... end This shared example is in file spec/controllers/support/authorization_shared_example.rb, which I am requiring in spec_helper.rb. I am also using autotest to give me quick feedback. Autotest is generating following command to run rspec /.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/bin/rspec /spec/controllers/support/authorization_shared_example.rb Since autotest is also including support file when running rspec, I am getting following errors with autotest /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/shared_example_group.rb:43:in `ensure_shared_example_group_name_not_taken': Shared example group 'allow authorized actions' already exists (ArgumentError) from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/shared_example_group.rb:6:in `share_examples_for' from /Users/arusarh/work/ece/carbonomist/spec/controllers/support/authorization_shared_example.rb:1:in `' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `block in load' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:227:in `load_dependency' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `block in load_spec_files' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `map' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `load_spec_files' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/command_line.rb:18:in `run' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:46:in `run_in_process' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:37:in `run' from /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:10:in `block in autorun' Any ideas how to not make autotest include shared example files loaded through command line, but only include files with pattern "*_spec.rb", or have anyone else facing same situation. Regards, Amiruddin Nagri, Bangalore, 560008, KA India Y! IM : amir_nagri at yahoo.com GTalk : amir.nagri at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Sep 29 06:50:41 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Sep 2010 05:50:41 -0500 Subject: [rspec-users] route_to to test root route In-Reply-To: References: Message-ID: On Sep 29, 2010, at 12:44 AM, Amiruddin Nagri wrote: > I am working on a Rails 3 application using RSPec 2.beta.20. > > I am having the following routes in my routes.rb > > routes.rb > ------------ > resources :projects > root :to => 'projects#index' > > I am trying to test both the routes. But while testing root route I am getting a failure : > > it 'should route root to projects#index' do > {:get => '/'}.should route_to(:controller => 'projects', :action => 'index') > end > > But the above example is failing since route_to is expecting a route like '/projects'. Is there a way to test root routes which are also configured elsewhere in the routes.rb. route_to delegates to assert_routing, which only passes if both assert_generates and assert_recognizes passes. There was a lengthy thread about this [1] but we never resolved the API deficiency. Obviously we need something before a final rspec-rails-2 release, but in the mean time you can always use the built-in rails assertions. In this case, you'd use: assert_recognizes({:controller => "projects", :action => "index"}, {:method => "get", :path => "/"}) Cheers, David [1] http://groups.google.com/group/rspec/browse_thread/thread/50b46ca3e4bd3a78/2a60d77662a1ec31 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Sep 29 07:56:30 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Sep 2010 06:56:30 -0500 Subject: [rspec-users] Possible improvements to routing spec API In-Reply-To: References: <34C36264-CDA4-4767-9C21-58997B09C279@gmail.com> <9E8FA04F-8027-424B-BBC8-60AC667B79FC@wincent.com> <75BD8DC7-90E0-403F-9E6E-F64BD0D4BEAD@wincent.com> <0B3036BC-EA78-46C8-BF13-DC568A9E7864@wincent.com> <6B6077A7-C771-40E3-AEDE-AD2BA696F703@wincent.com> Message-ID: <62FFD301-E691-456A-92E2-757AC116E5B6@gmail.com> On Aug 17, 2010, at 12:46 PM, Michael Kintzer wrote: > On Jul 7, 11:25 pm, Wincent Colaiuta wrote: >> >> So, when I see this kind of thing, I think _what_ are we trying to achieve in ourroutingspecs and _why_? At least for me, the answers are: >> >> 1. Confirm: To confirm that the routes I've defined actually do what I think they do >> >> 2. Describe: To serve as a complete, explicit, readable specification of the behavior I expect from my routes >> >> And finally: >> >> 3. That the Railsroutingcode actually works as advertised >> >> This last one is a bit dubious, but the truth is the Rails 3 router is a complete re-write and bugs in it and incompatibilities with the old router are being found and squished constantly. An exhaustive set ofroutingspecs can definitely help to uncover undiscovered edge cases. >> >> So, bearing in mind those goals, what I actually need from RSpec in order to achieve them is: >> >> - most importantly, a way of asserting that a user action (eg. HTTP verb + path + params) gets routed to a given controller + action with certain additional parameters (ie. a wrapper for assert_recognizes) >> >> - less importantly, a way of asserting that a set of params (action, controller, additional params) generates a particular path (ie. a wrapper for assert_generates); this is less important for me because in practice close to all (98%) of my URL generation is done with named URL helpers, and I can test those explicitly if I want >> >> - as syntactic sugar, a way of combining the above two assertions into one for those cases where the mapping is perfectly bidirectional (ie. a wrapper for assert_routing). >> >> With these tools I can achieve pretty much everything I need: not only test that user actions end up hitting the right spots in my application, but also specify clearly and explicitly what I expect those mappings to be. >> >> So for me, anything else doesn't really help me achieve my goals. The "have_resource(s)" matcher, for instance, doesn't help me and in fact actually undermines my goal of providing a complete and explicit specification of how my routes work. >> >> The "recognize" and "generate" matchers you suggest obviously are "on target" to help me fulfill my goals. Of these, the "recognize" one is the most important one though. >> >> Of the "match" and "get" matchers you suggest, seeing as they both wrap the same thing (assert_routing), one of them would have to go. I'd probably ditch "match" because it is just a repetition of the router DSL method of the same name, and my goal here isn't just to repeat that DSL in my specs. >> >> In fact, if you look at my most important goal -- asserting that a user action (HTTP verb, path, params) hits a specific end point (controller + action + additional params) -- you'll understand why, in my proposal, all of my specifications start with "get"/"post" etc followed by path, params and then controller/action. It's not just for resonance with other parts of RSpec like where we use "get" etc in controller specs. >> >> But if the goal is just to wrap the 3 Rails assertions as faithfully as possible, then you wind up with a different proposal. What David has posted is probably the closest to this goal. >> >> And if the goal is make the specs map as closely as possible onto the language of config/routes.rb, then you wind up with a different proposal still... (ie. the one you just made). >> >> So, I guess what I'm saying here is I'd like to hear _what_ people are wanting to achieve in theirroutingspecs and _why_; and then to ask what kind of means RSpec should provide to best achieve those goals. >> >> Cheers, >> Wincent > Lots of good proposals here. I would at least like to chime in that I > agree with the goals as set out by Wincent below, and from a > readability standpoint have preferred the API as suggested by > Trevor. > > -Michael Time to resurrect this discussion. Thinking about Wincent's very thoughtful synopsis has lead me to a slightly different line of thinking here. We've always seen route recognition and route generation as opposite sides of the same coin, but I think that's due to how they are presented to us by the Rails testing facilities. The more I think of it, route generation is not really the concern of the router at all. It's a responsibility of controllers (and views, by proxy) to generate a recognizable route from a set of params. What this leads me to is that I'd like to simplify all of this and make route_to only care about the routing side of this equation (i.e. have it delegate to assert_recognizes, rather than assert_routing). The implication of this would be that we'd theoretically lose coverage that routes are generated correctly, but I don't think that actually matters. We still need to assemble the right parameters in our controllers/views to get the routes we want, so those should be specified in relation to the controller or view. i.e. in a view spec: rendered.should have_css("a", :href => projects_path) The fact that the controller can generate that link from {:controller => "projects", :action => "index"} is a matter of Rails working as advertised. Plus, if we wrote that link in a view and it generated an unrecognizable route, the error message we'd get is that no route matches, not that the route could not be generated. To sum up: I'd like to have route_to delegate to assert_recognizes, and leave it at that. That said, I'd be perfectly willing to add some of the sugar that has been proposed in this thread, so we can say: get("/").should route_to("projects#index") I agree that this is more terse, yet very expressive in the context of other facilities we're dealing with. Thoughts? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mulder.patrick at gmail.com Wed Sep 29 15:56:52 2010 From: mulder.patrick at gmail.com (poseid) Date: Wed, 29 Sep 2010 12:56:52 -0700 (PDT) Subject: [rspec-users] "assign" to variable in view seems to give nil object Message-ID: Hello, I am doing my first steps with rspec and did the following observation. I wanted to write a spec for a standard scaffold index view. Now, my view spec looks like: describe "/a_details/index.html.erb" do it "should list all the details of as in an unordered list" do assign[:a_details] = ['test'] render '/a_details/index.html.erb' response.should have_tag("ul") do with_tag("li") do with_tag("div", "Name") with_tag("div", "Details") end end end end Can someone show me a direction and/or has a solution to this ? When I run this I get: 1) ActionView::TemplateError in '/a_details/index.html.erb should list all the details of shoes in an unordered list' You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each On line #15 of app/views/shoe_details/index.html.erb 12: Photo quality 13: 14: 15: <% @a_details.each do |shoe_detail| %> 16: 17: <%=h a_detail.brand %> 18: <%=h a_detail.city_photo %> app/views/a_details/index.html.erb:15 haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:13:in `render_without_mock_proxy' spec/views/a_details/index_spec.rb:8 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' /opt/local/lib/ruby/1.8/timeout.rb:53:in `timeout' From zhiqiang.lei at gmail.com Thu Sep 30 05:02:26 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Thu, 30 Sep 2010 17:02:26 +0800 Subject: [rspec-users] Monitor method invoking from superclass Message-ID: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> Dear All, Class B is a subclass of class A. Could anyone tell me how to monitor if object created from class B receives a super message when its method is invoked. Thanks. Best regards, Lei, Zhi-Qiang From dchelimsky at gmail.com Thu Sep 30 07:59:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Sep 2010 06:59:58 -0500 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> Message-ID: On Sep 30, 2010, at 4:02 AM, Zhi-Qiang Lei wrote: > Dear All, > > Class B is a subclass of class A. Could anyone tell me how to monitor if object created from class B receives a super message when its method is invoked. Thanks. I don't know of a way to do that. What problem are you trying to solve? From dchelimsky at gmail.com Thu Sep 30 08:12:11 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Sep 2010 07:12:11 -0500 Subject: [rspec-users] "assign" to variable in view seems to give nil object In-Reply-To: References: Message-ID: <776B0997-583C-4494-B97B-0AA2C0F647E2@gmail.com> On Sep 29, 2010, at 2:56 PM, poseid wrote: > Hello, > > I am doing my first steps with rspec and did the following observation. > I wanted to write a spec for a standard scaffold index view. > > Now, my view spec looks like: > > describe "/a_details/index.html.erb" do > > it "should list all the details of as in an unordered list" do > assign[:a_details] = ['test'] This looks like Rails-2/RSpec-1. If that's correct, then you want to use "assigns" instead of "assign". HTH, David > render '/a_details/index.html.erb' > > response.should have_tag("ul") do > with_tag("li") do > with_tag("div", "Name") > with_tag("div", "Details") > end > end > end > end > > Can someone show me a direction and/or has a solution to this ? > > When I run this I get: > > > 1) > ActionView::TemplateError in '/a_details/index.html.erb should list > all the details of shoes in an unordered list' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > On line #15 of app/views/shoe_details/index.html.erb > > 12: Photo quality > 13: > 14: > 15: <% @a_details.each do |shoe_detail| %> > 16: > 17: <%=h a_detail.brand %> > 18: <%=h a_detail.city_photo %> > > app/views/a_details/index.html.erb:15 > haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:13:in > `render_without_mock_proxy' > spec/views/a_details/index_spec.rb:8 > 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' > /opt/local/lib/ruby/1.8/timeout.rb:53:in `timeout' From zhiqiang.lei at gmail.com Thu Sep 30 08:45:38 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Thu, 30 Sep 2010 20:45:38 +0800 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> Message-ID: <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> Class A def a #some code end end Class B def a #some code super end end I want to if B is receive 'super' message. Thanks. On Sep 30, 2010, at 7:59 PM, David Chelimsky wrote: > On Sep 30, 2010, at 4:02 AM, Zhi-Qiang Lei wrote: > >> Dear All, >> >> Class B is a subclass of class A. Could anyone tell me how to monitor if object created from class B receives a super message when its method is invoked. Thanks. > > I don't know of a way to do that. What problem are you trying to solve? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Sep 30 09:15:00 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Sep 2010 08:15:00 -0500 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> Message-ID: <4E6A882F-7677-427A-9045-1E3A3CE4FE93@gmail.com> On Sep 30, 2010, at 7:45 AM, Zhi-Qiang Lei wrote: > On Sep 30, 2010, at 7:59 PM, David Chelimsky wrote: > >> On Sep 30, 2010, at 4:02 AM, Zhi-Qiang Lei wrote: >> >>> Dear All, >>> >>> Class B is a subclass of class A. Could anyone tell me how to monitor if object created from class B receives a super message when its method is invoked. Thanks. >> >> I don't know of a way to do that. What problem are you trying to solve? [ I moved your post to the bottom. Please post at the bottom or in-line] > Class A > def a > #some code > end > end > > Class B > def a > #some code > super > end > end > > I want to if B is receive 'super' message. Thanks. I understand what you meant, but I don't understand why you want to do this. What is the bigger problem you are trying to solve? Why do you want to monitor when super gets called? From zhiqiang.lei at gmail.com Thu Sep 30 09:20:24 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Thu, 30 Sep 2010 21:20:24 +0800 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: <4E6A882F-7677-427A-9045-1E3A3CE4FE93@gmail.com> References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> <4E6A882F-7677-427A-9045-1E3A3CE4FE93@gmail.com> Message-ID: <5E9401D1-31B3-485B-8C66-4CF20D38DE13@gmail.com> On Sep 30, 2010, at 9:15 PM, David Chelimsky wrote: > On Sep 30, 2010, at 7:45 AM, Zhi-Qiang Lei wrote: > >> On Sep 30, 2010, at 7:59 PM, David Chelimsky wrote: >> >>> On Sep 30, 2010, at 4:02 AM, Zhi-Qiang Lei wrote: >>> >>>> Dear All, >>>> >>>> Class B is a subclass of class A. Could anyone tell me how to monitor if object created from class B receives a super message when its method is invoked. Thanks. >>> >>> I don't know of a way to do that. What problem are you trying to solve? > > [ I moved your post to the bottom. Please post at the bottom or in-line] > >> Class A >> def a >> #some code >> end >> end >> >> Class B >> def a >> #some code >> super >> end >> end >> >> I want to if B is receive 'super' message. Thanks. > > I understand what you meant, but I don't understand why you want to do this. What is the bigger problem you are trying to solve? Why do you want to monitor when super gets called? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Thank you. Actually what I want is just to write a test case for it, with rspec. From dchelimsky at gmail.com Thu Sep 30 09:45:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Sep 2010 08:45:54 -0500 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: <5E9401D1-31B3-485B-8C66-4CF20D38DE13@gmail.com> References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> <4E6A882F-7677-427A-9045-1E3A3CE4FE93@gmail.com> <5E9401D1-31B3-485B-8C66-4CF20D38DE13@gmail.com> Message-ID: <8661771A-D1B7-44CC-A0F1-061733D44BB7@gmail.com> On Sep 30, 2010, at 8:20 AM, Zhi-Qiang Lei wrote: > On Sep 30, 2010, at 9:15 PM, David Chelimsky wrote: > >> On Sep 30, 2010, at 7:45 AM, Zhi-Qiang Lei wrote: >> >>> On Sep 30, 2010, at 7:59 PM, David Chelimsky wrote: >>> >>>> On Sep 30, 2010, at 4:02 AM, Zhi-Qiang Lei wrote: >>>> >>>>> Dear All, >>>>> >>>>> Class B is a subclass of class A. Could anyone tell me how to monitor if object created from class B receives a super message when its method is invoked. Thanks. >>>> >>>> I don't know of a way to do that. What problem are you trying to solve? >> >> [ I moved your post to the bottom. Please post at the bottom or in-line] >> >>> Class A >>> def a >>> #some code >>> end >>> end >>> >>> Class B >>> def a >>> #some code >>> super >>> end >>> end >>> >>> I want to if B is receive 'super' message. Thanks. >> >> I understand what you meant, but I don't understand why you want to do this. What is the bigger problem you are trying to solve? Why do you want to monitor when super gets called? > > Thank you. Actually what I want is just to write a test case for it, with rspec. You can not. Good luck, David From rick.denatale at gmail.com Thu Sep 30 09:56:28 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 30 Sep 2010 09:56:28 -0400 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: <8661771A-D1B7-44CC-A0F1-061733D44BB7@gmail.com> References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> <4E6A882F-7677-427A-9045-1E3A3CE4FE93@gmail.com> <5E9401D1-31B3-485B-8C66-4CF20D38DE13@gmail.com> <8661771A-D1B7-44CC-A0F1-061733D44BB7@gmail.com> Message-ID: On Thu, Sep 30, 2010 at 9:45 AM, David Chelimsky wrote: > On Sep 30, 2010, at 8:20 AM, Zhi-Qiang Lei wrote: >>>> I want to if B is receive 'super' message. Thanks. >>> >>> I understand what you meant, but I don't understand why you want to do this. What is the bigger problem you are trying to solve? Why do you want to monitor when super gets called? >> >> Thank you. Actually what I want is just to write a test case for it, with rspec. > > You can not. And following up on David's reply, I don't think you should, Lei. What you really should be testing that the observable effects of the call are 'as if' the super call were made. If you could test that the super call was made it would be testing that the implementation were a certain way more than the behavior of the object, and that's the road to writing brittle tests. -- 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 zhiqiang.lei at gmail.com Thu Sep 30 10:36:28 2010 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Thu, 30 Sep 2010 22:36:28 +0800 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> <4E6A882F-7677-427A-9045-1E3A3CE4FE93@gmail.com> <5E9401D1-31B3-485B-8C66-4CF20D38DE13@gmail.com> <8661771A-D1B7-44CC-A0F1-061733D44BB7@gmail.com> Message-ID: <4C2933BD-28A1-4808-9778-720A074F6E40@gmail.com> On Sep 30, 2010, at 9:56 PM, Rick DeNatale wrote: > On Thu, Sep 30, 2010 at 9:45 AM, David Chelimsky wrote: >> On Sep 30, 2010, at 8:20 AM, Zhi-Qiang Lei wrote: > >>>>> I want to if B is receive 'super' message. Thanks. >>>> >>>> I understand what you meant, but I don't understand why you want to do this. What is the bigger problem you are trying to solve? Why do you want to monitor when super gets called? >>> >>> Thank you. Actually what I want is just to write a test case for it, with rspec. >> >> You can not. > > And following up on David's reply, I don't think you should, Lei. > > What you really should be testing that the observable effects of the > call are 'as if' the super call were made. > > If you could test that the super call was made it would be testing > that the implementation were a certain way more than the behavior of > the object, and that's the road to writing brittle tests. > > -- > 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 In my case, there is already a test case for the method in class A, and its feature is complex. So I was trying to test the super call but observable effect for simple. Anyway, thank you both. From rick.denatale at gmail.com Thu Sep 30 11:00:07 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 30 Sep 2010 11:00:07 -0400 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: <4C2933BD-28A1-4808-9778-720A074F6E40@gmail.com> References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> <4E6A882F-7677-427A-9045-1E3A3CE4FE93@gmail.com> <5E9401D1-31B3-485B-8C66-4CF20D38DE13@gmail.com> <8661771A-D1B7-44CC-A0F1-061733D44BB7@gmail.com> <4C2933BD-28A1-4808-9778-720A074F6E40@gmail.com> Message-ID: On Thu, Sep 30, 2010 at 10:36 AM, Zhi-Qiang Lei wrote: > > On Sep 30, 2010, at 9:56 PM, Rick DeNatale wrote: > >> What you really should be testing that the observable effects of the >> call are 'as if' the super call were made. >> >> If you could test that the super call was made it would be testing >> that the implementation were a certain way more than the behavior of >> the object, and that's the road to writing brittle tests. > > In my case, there is already a test case for the method in class A, and its feature is complex. So I was trying to test the super call but observable effect for simple. Anyway, thank you both. That's what shared example groups are for. -- 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 gditrick at fuse.net Thu Sep 30 11:06:36 2010 From: gditrick at fuse.net (GregD) Date: Thu, 30 Sep 2010 08:06:36 -0700 (PDT) Subject: [rspec-users] Can you control $stdout when specs are running? Message-ID: <99e250bd-bcfe-41e2-8fc9-ee16423b3791@28g2000yqm.googlegroups.com> Hi all, I'm testing java classed using rspec and jruby. The java super class is trapping an exception and sending a custom message to stdout along with the original exception meaasage. The original exception is a SAXParseException, if that really matters. Well, my test is to see if the child object class can handle a garbled XML message a certain way. The test passes, but I get the nasty java exception stuff that is being sent to stdout when the tests are running, yuk. I tried closing and opening stdout before and after that particular test and that did not work or I did it wrong. And I'm not sure this is desirable if the test fails. Any ideas on this other than to replace the java with ruby or have the java not to dump to stdout? ;-) Both of which, I can not do. But, I can live with the nastiness of this, if there is no possible way around it. Thanks, GregD From wagner.andrew at gmail.com Thu Sep 30 11:17:07 2010 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Thu, 30 Sep 2010 11:17:07 -0400 Subject: [rspec-users] Monitor method invoking from superclass In-Reply-To: References: <58C4F812-8572-4A27-AD0B-EC7892B90C9E@gmail.com> <7C1E36A6-BDB7-46ED-A3F1-D0B6AA0B57CE@gmail.com> <4E6A882F-7677-427A-9045-1E3A3CE4FE93@gmail.com> <5E9401D1-31B3-485B-8C66-4CF20D38DE13@gmail.com> <8661771A-D1B7-44CC-A0F1-061733D44BB7@gmail.com> <4C2933BD-28A1-4808-9778-720A074F6E40@gmail.com> Message-ID: Rick, could you elaborate on this? I'm curious, how would you use a shared example group here, given his sample code? My first thought was to use ancestors to get the parent class, and re-define the 'a' method there to do something simple and observable, and then test that. Is that evil? On Thu, Sep 30, 2010 at 11:00 AM, Rick DeNatale wrote: > On Thu, Sep 30, 2010 at 10:36 AM, Zhi-Qiang Lei > wrote: > > > > On Sep 30, 2010, at 9:56 PM, Rick DeNatale wrote: > > > > >> What you really should be testing that the observable effects of the > >> call are 'as if' the super call were made. > >> > >> If you could test that the super call was made it would be testing > >> that the implementation were a certain way more than the behavior of > >> the object, and that's the road to writing brittle tests. > > > > > In my case, there is already a test case for the method in class A, and > its feature is complex. So I was trying to test the super call but > observable effect for simple. Anyway, thank you both. > > That's what shared example groups are for. > > > -- > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mulder.patrick at gmail.com Thu Sep 30 17:24:20 2010 From: mulder.patrick at gmail.com (poseid) Date: Thu, 30 Sep 2010 14:24:20 -0700 (PDT) Subject: [rspec-users] "assign" to variable in view seems to give nil object In-Reply-To: <776B0997-583C-4494-B97B-0AA2C0F647E2@gmail.com> References: <776B0997-583C-4494-B97B-0AA2C0F647E2@gmail.com> Message-ID: Thanks, David. You are right, there could be a clash of versions. Now, "assigns" gives: index_spec.rb:6: undefined local variable or method `assigns' for Spec::Rails::Example::ViewExampleGroup::Subclass_1:Class (NameError) from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/ example_group_methods.rb:183:in `module_eval' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/ example_group_methods.rb:183:in `subclass' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/ example_group_methods.rb:55:in `describe' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/ example_group_factory.rb:31:in `create_example_group' Maybe I shall start with another clean rails project? Thanks for your help, Patrick On 30 Sep., 14:12, David Chelimsky wrote: > On Sep 29, 2010, at 2:56 PM, poseid wrote: > > > Hello, > > > I am doing my first steps with rspec and did the following observation. > > I wanted to write a spec for a standard scaffold index view. > > > Now, my view spec looks like: > > > describe "/a_details/index.html.erb" do > > > ?it "should list all the details of as in an unordered list" do > > ? ?assign[:a_details] = ['test'] > > This looks like Rails-2/RSpec-1. If that's correct, then you want to use "assigns" instead of "assign". > > HTH, > David > > > > > ? ?render '/a_details/index.html.erb' > > > ? ?response.should have_tag("ul") do > > ? ? ?with_tag("li") do > > ? ? ? ?with_tag("div", "Name") > > ? ? ? ?with_tag("div", "Details") > > ? ? ?end > > ? ?end > > ?end > > end > > > Can someone show me a direction and/or has a solution to this ? > > > When I run this I get: > > > 1) > > ActionView::TemplateError in '/a_details/index.html.erb should list > > all the details of shoes in an unordered list' > > You have a nil object when you didn't expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.each > > On line #15 of app/views/shoe_details/index.html.erb > > > ? ?12: ? ? Photo quality > > ? ?13: ? > > ? ?14: > > ? ?15: <% @a_details.each do |shoe_detail| %> > > ? ?16: ? > > ? ?17: ? ? <%=h a_detail.brand %> > > ? ?18: ? ? <%=h a_detail.city_photo %> > > > ? ?app/views/a_details/index.html.erb:15 > > ? ?haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:13:in > > `render_without_mock_proxy' > > ? ?spec/views/a_details/index_spec.rb:8 > > ? ?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' > > ? ?/opt/local/lib/ruby/1.8/timeout.rb:53:in `timeout' > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From kai.schlamp at googlemail.com Thu Sep 30 16:50:36 2010 From: kai.schlamp at googlemail.com (turkan) Date: Thu, 30 Sep 2010 13:50:36 -0700 (PDT) Subject: [rspec-users] response.should have_text leads to undefined method `has_text?' Message-ID: One of my controllers directly renders some JSON output that I would like to test with RSpec. For that I use 'response.should have_text("foobar")' in my spec file, but that leads to a Failure/Error: response.should have_text("enim") undefined method `has_text?' for # I read here somewhere that webrat should be in the Gemfile, but that also did not solve the problem. Best regards, Kai