From jarmo.p at gmail.com Wed Jun 1 10:10:21 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 1 Jun 2011 07:10:21 -0700 (PDT) Subject: [rspec-users] how to include module into shared example group in RSpec 2 Message-ID: <0a104f78-3113-45f4-ac50-c12ce473c912@g12g2000yqd.googlegroups.com> Hi! We tried to upgrade our RSpec from 1.3.1 to 2.6 and are having some problems. It seems that shared example group includes modules differently in RSpec 2. Consider the following code: module MyModule def testing end end shared_examples_for "shared" do include MyModule it "works" do testing end end describe "describe" do it_should_behave_like "shared" it "works too" do testing end end When running with RSpec 1.3.1 all specs are passing, but RSpec 2.6 fails with one failure: 1) describe works too Failure/Error: testing NameError: undefined local variable or method `testing' for # # ./spec/blah/blah_spec.rb:18 It seems that the describe block doesn't get the methods included from the module. How to solve that problem? Jarmo From jarmo.p at gmail.com Wed Jun 1 10:14:50 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 1 Jun 2011 07:14:50 -0700 (PDT) Subject: [rspec-users] RSpec 2 not finding specs from subdirectories when trying to run specs from there Message-ID: <799c6803-96a8-4576-b1e8-0c8821d243b2@k16g2000yqm.googlegroups.com> Hi! When having a file structure like this: project -spec -subdir -my_spec.rb and then being in directory "project" and running command `rspec spec` everything works as expected. If running `rspec spec/subdir` to run only specs under spec/subdir then it doesn't work - it finds 0 examples. It works as expected in RSpec 1. What do we do wrong? Jarmo From chabgood at gmail.com Wed Jun 1 10:22:37 2011 From: chabgood at gmail.com (Chris Habgood) Date: Wed, 1 Jun 2011 09:22:37 -0500 Subject: [rspec-users] RSpec 2 not finding specs from subdirectories when trying to run specs from there In-Reply-To: <799c6803-96a8-4576-b1e8-0c8821d243b2@k16g2000yqm.googlegroups.com> References: <799c6803-96a8-4576-b1e8-0c8821d243b2@k16g2000yqm.googlegroups.com> Message-ID: Try this in your spec helper file: Dir[Rails.root.join("spec/factories/**/*.rb")].each {|f| require f} On Wed, Jun 1, 2011 at 09:14, Jarmo Pertman wrote: > Hi! > > When having a file structure like this: > project > -spec > -subdir > -my_spec.rb > > and then being in directory "project" and running command `rspec spec` > everything works as expected. If running `rspec spec/subdir` to run > only specs under spec/subdir then it doesn't work - it finds 0 > examples. It works as expected in RSpec 1. What do we do wrong? > > Jarmo > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- *"In matters of style, swim with the current; in matters of principle, stand like a rock." Thomas Jefferson * -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Jun 1 10:24:24 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Jun 2011 09:24:24 -0500 Subject: [rspec-users] RSpec 2 not finding specs from subdirectories when trying to run specs from there In-Reply-To: <799c6803-96a8-4576-b1e8-0c8821d243b2@k16g2000yqm.googlegroups.com> References: <799c6803-96a8-4576-b1e8-0c8821d243b2@k16g2000yqm.googlegroups.com> Message-ID: <3D8173B3-7D23-4BAE-A00A-01CF5CD21D61@gmail.com> On Jun 1, 2011, at 9:14 AM, Jarmo Pertman wrote: > Hi! > > When having a file structure like this: > project > -spec > -subdir > -my_spec.rb > > and then being in directory "project" and running command `rspec spec` > everything works as expected. If running `rspec spec/subdir` to run > only specs under spec/subdir then it doesn't work - it finds 0 > examples. It works as expected in RSpec 1. What do we do wrong? I run subdirectories quite often and haven't seen this issue. What's in your .rspec and spec/spec_helper.rb files? Also, which version of rspec-2 are you using? From jarmo.p at gmail.com Wed Jun 1 10:37:20 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 1 Jun 2011 07:37:20 -0700 (PDT) Subject: [rspec-users] how to include module into shared example group in RSpec 2 Message-ID: Hi! We tried to upgrade our RSpec from 1.3.1 to 2.6 and are having some problems. It seems that shared example group includes modules differently in RSpec 2. Consider the following code: module MyModule def testing end end shared_examples_for "shared" do include MyModule it "works" do testing end end describe "describe" do it_should_behave_like "shared" it "works too" do testing end end When running with RSpec 1.3.1 all specs are passing, but RSpec 2.6 fails with one failure: 1) describe works too Failure/Error: testing NameError: undefined local variable or method `testing' for # # ./spec/blah/blah_spec.rb:18 It seems that the describe block doesn't get the methods included from the module. How to solve that problem? Jarmo From dchelimsky at gmail.com Wed Jun 1 10:42:28 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Jun 2011 09:42:28 -0500 Subject: [rspec-users] how to include module into shared example group in RSpec 2 In-Reply-To: <0a104f78-3113-45f4-ac50-c12ce473c912@g12g2000yqd.googlegroups.com> References: <0a104f78-3113-45f4-ac50-c12ce473c912@g12g2000yqd.googlegroups.com> Message-ID: On Jun 1, 2011, at 9:10 AM, Jarmo Pertman wrote: > Hi! > > We tried to upgrade our RSpec from 1.3.1 to 2.6 and are having some > problems. It seems that shared example group includes modules > differently in RSpec 2. > > Consider the following code: > module MyModule > def testing > end > end > > shared_examples_for "shared" do > include MyModule > > it "works" do > testing > end > end > > describe "describe" do > it_should_behave_like "shared" > > it "works too" do > testing > end > end > > When running with RSpec 1.3.1 all specs are passing, but RSpec 2.6 > fails with one failure: > 1) describe works too > Failure/Error: testing > NameError: > undefined local variable or method `testing' for > # > # ./spec/blah/blah_spec.rb:18 > > It seems that the describe block doesn't get the methods included from > the module. How to solve that problem? This has been through a bit of churn, but here is the short version: it_should_behave_like creates (and wraps) a nested group, but there is are also two new include_context/include_examples methods. Your choices are: describe "describe" do it_should_behave_like "shared" do it "works too" do testing end end end describe "describe" do include_context "shared" it "works too" do testing end end describe "describe" do include_examples "shared" it "works too" do testing end end From jarmo.p at gmail.com Wed Jun 1 10:57:44 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 1 Jun 2011 07:57:44 -0700 (PDT) Subject: [rspec-users] RSpec 2 not finding specs from subdirectories when trying to run specs from there In-Reply-To: <3D8173B3-7D23-4BAE-A00A-01CF5CD21D61@gmail.com> References: <799c6803-96a8-4576-b1e8-0c8821d243b2@k16g2000yqm.googlegroups.com> <3D8173B3-7D23-4BAE-A00A-01CF5CD21D61@gmail.com> Message-ID: It is indeed related with Windows! C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>rspec spec/subdir . Finished in 0.0045 seconds 1 example, 0 failures C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>rspec spec\subdir No examples found. Finished in 0 seconds 0 examples, 0 failures C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>spec spec\subdir . Finished in 0.040505 seconds 1 example, 0 failures C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>spec spec/subdir . Finished in 0.040505 seconds 1 example, 0 failures It needs path to be specified with unix-slashes... Jarmo On Jun 1, 5:24?pm, David Chelimsky wrote: > On Jun 1, 2011, at 9:14 AM, Jarmo Pertman wrote: > > > Hi! > > > When having a file structure like this: > > project > > ?-spec > > ? ?-subdir > > ? ? ?-my_spec.rb > > > and then being in directory "project" and running command `rspec spec` > > everything works as expected. If running `rspec spec/subdir` to run > > only specs under spec/subdir then it doesn't work - it finds 0 > > examples. It works as expected in RSpec 1. What do we do wrong? > > I run subdirectories quite often and haven't seen this issue. What's in your .rspec and spec/spec_helper.rb files? Also, which version of rspec-2 are you using? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jarmo.p at gmail.com Wed Jun 1 10:52:54 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 1 Jun 2011 07:52:54 -0700 (PDT) Subject: [rspec-users] RSpec 2 not finding specs from subdirectories when trying to run specs from there In-Reply-To: <3D8173B3-7D23-4BAE-A00A-01CF5CD21D61@gmail.com> References: <799c6803-96a8-4576-b1e8-0c8821d243b2@k16g2000yqm.googlegroups.com> <3D8173B3-7D23-4BAE-A00A-01CF5CD21D61@gmail.com> Message-ID: I created a really simple example as shown above and this doesn't work for me - e.g. no spec_helper or .rspec files in use. I'm on Windows, could that be the culprit (it happens on two machines)? Here is some additional output: C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>tree Folder PATH listing Volume serial number is E4DF-948C C:. ????spec ????subdir C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>ls -laR total 0 drwxrwxrwx 1 user group 0 Jun 1 17:01 . drwxrwxrwx 1 user group 0 Jun 1 06:15 .. drwxrwxrwx 1 user group 0 Jun 1 17:47 spec spec=: total 0 drwxrwxrwx 1 user group 0 Jun 1 17:47 . drwxrwxrwx 1 user group 0 Jun 1 17:01 .. drwxrwxrwx 1 user group 0 Jun 1 17:46 subdir spec\subdir=: total 1 drwxrwxrwx 1 user group 0 Jun 1 17:46 . drwxrwxrwx 1 user group 0 Jun 1 17:47 .. -rw-rw-rw- 1 user group 49 Jun 1 17:46 my_spec.rb C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>cat spec\subdir \my_spec.rb describe "my" do it "example" do end end C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>rspec spec . Finished in 0.001 seconds 1 example, 0 failures C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>spec spec . Finished in 0.037002 seconds 1 example, 0 failures C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>rspec spec\subdir No examples found. Finished in 0 seconds 0 examples, 0 failures C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>spec spec . Finished in 0.037003 seconds 1 example, 0 failures C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>gem list | grep rspec rspec (2.6.0, 2.5.0, 2.3.0, 2.1.0, 1.3.1, 1.3.0) rspec-core (2.6.3, 2.5.1, 2.3.1, 2.3.0, 2.2.1, 2.1.0) rspec-expectations (2.6.0, 2.5.0, 2.3.0, 2.2.0, 2.1.0) rspec-mocks (2.6.0, 2.5.0, 2.3.0, 2.2.0, 2.1.0) rspec-rails (2.3.1, 2.1.0) Jarmo On Jun 1, 5:24?pm, David Chelimsky wrote: > On Jun 1, 2011, at 9:14 AM, Jarmo Pertman wrote: > > > Hi! > > > When having a file structure like this: > > project > > ?-spec > > ? ?-subdir > > ? ? ?-my_spec.rb > > > and then being in directory "project" and running command `rspec spec` > > everything works as expected. If running `rspec spec/subdir` to run > > only specs under spec/subdir then it doesn't work - it finds 0 > > examples. It works as expected in RSpec 1. What do we do wrong? > > I run subdirectories quite often and haven't seen this issue. What's in your .rspec and spec/spec_helper.rb files? Also, which version of rspec-2 are you using? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jarmo.p at gmail.com Wed Jun 1 11:05:11 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 1 Jun 2011 08:05:11 -0700 (PDT) Subject: [rspec-users] how to include module into shared example group in RSpec 2 In-Reply-To: References: <0a104f78-3113-45f4-ac50-c12ce473c912@g12g2000yqd.googlegroups.com> Message-ID: <07952665-618b-45bb-9c27-1005d196da3f@g12g2000yqd.googlegroups.com> Thank you :) Where can i see the differences between #it_should_behave_like, #include_context and #include_examples? Jarmo On Jun 1, 5:42?pm, David Chelimsky wrote: > On Jun 1, 2011, at 9:10 AM, Jarmo Pertman wrote: > > > > > > > > > > > Hi! > > > We tried to upgrade our RSpec from 1.3.1 to 2.6 and are having some > > problems. It seems that shared example group includes modules > > differently in RSpec 2. > > > Consider the following code: > > module MyModule > > ?def testing > > ?end > > end > > > shared_examples_for "shared" do > > ?include MyModule > > > ?it "works" do > > ? ?testing > > ?end > > end > > > describe "describe" do > > ?it_should_behave_like "shared" > > > ?it "works too" do > > ? ?testing > > ?end > > end > > > When running with RSpec 1.3.1 all specs are passing, but RSpec 2.6 > > fails with one failure: > > ?1) describe works too > > ? ? Failure/Error: testing > > ? ? NameError: > > ? ? ? undefined local variable or method `testing' for > > # > > ? ? # ./spec/blah/blah_spec.rb:18 > > > It seems that the describe block doesn't get the methods included from > > the module. How to solve that problem? > > This has been through a bit of churn, but here is the short version: > > it_should_behave_like creates (and wraps) a nested group, but there is are also two new include_context/include_examples methods. Your choices are: > > describe "describe" do > ? it_should_behave_like "shared" do > ? ? it "works too" do > ? ? ? testing > ? ? end > ? end > end > > describe "describe" do > ? include_context "shared" > ? it "works too" do > ? ? testing > ? end > end > > describe "describe" do > ? include_examples "shared" > ? it "works too" do > ? ? testing > ? end > end > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Jun 1 11:05:24 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Jun 2011 10:05:24 -0500 Subject: [rspec-users] RSpec 2 not finding specs from subdirectories when trying to run specs from there In-Reply-To: References: <799c6803-96a8-4576-b1e8-0c8821d243b2@k16g2000yqm.googlegroups.com> <3D8173B3-7D23-4BAE-A00A-01CF5CD21D61@gmail.com> Message-ID: <718B8F18-9E56-4348-A6CB-664482AF7360@gmail.com> On Jun 1, 2011, at 9:57 AM, Jarmo Pertman wrote: > It is indeed related with Windows! > > C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>rspec spec/subdir > . > > Finished in 0.0045 seconds > 1 example, 0 failures > > C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>rspec spec\subdir > No examples found. > > > Finished in 0 seconds > 0 examples, 0 failures > > C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>spec spec\subdir > . > > Finished in 0.040505 seconds > > 1 example, 0 failures > > C:\Users\jarmo\Desktop\minu\projects\Ruby\myproject>spec spec/subdir > . > > Finished in 0.040505 seconds > > 1 example, 0 failures > > It needs path to be specified with unix-slashes... Please do me a favor and report this to http://github.com/rspec/rspec-core/issues. Thx > > Jarmo > > On Jun 1, 5:24 pm, David Chelimsky wrote: >> On Jun 1, 2011, at 9:14 AM, Jarmo Pertman wrote: >> >>> Hi! >> >>> When having a file structure like this: >>> project >>> -spec >>> -subdir >>> -my_spec.rb >> >>> and then being in directory "project" and running command `rspec spec` >>> everything works as expected. If running `rspec spec/subdir` to run >>> only specs under spec/subdir then it doesn't work - it finds 0 >>> examples. It works as expected in RSpec 1. What do we do wrong? >> >> I run subdirectories quite often and haven't seen this issue. What's in your .rspec and spec/spec_helper.rb files? Also, which version of rspec-2 are you using? >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Jun 1 11:05:47 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Jun 2011 10:05:47 -0500 Subject: [rspec-users] how to include module into shared example group in RSpec 2 In-Reply-To: <07952665-618b-45bb-9c27-1005d196da3f@g12g2000yqd.googlegroups.com> References: <0a104f78-3113-45f4-ac50-c12ce473c912@g12g2000yqd.googlegroups.com> <07952665-618b-45bb-9c27-1005d196da3f@g12g2000yqd.googlegroups.com> Message-ID: <66C01285-7EDA-4E3E-96A9-F8ADE9855643@gmail.com> On Jun 1, 2011, at 10:05 AM, Jarmo Pertman wrote: > Thank you :) > > Where can i see the differences between #it_should_behave_like, > #include_context and #include_examples? http://relishapp.com/rspec/rspec-core > > Jarmo > > On Jun 1, 5:42 pm, David Chelimsky wrote: >> On Jun 1, 2011, at 9:10 AM, Jarmo Pertman wrote: >> >> >> >> >> >> >> >> >> >>> Hi! >> >>> We tried to upgrade our RSpec from 1.3.1 to 2.6 and are having some >>> problems. It seems that shared example group includes modules >>> differently in RSpec 2. >> >>> Consider the following code: >>> module MyModule >>> def testing >>> end >>> end >> >>> shared_examples_for "shared" do >>> include MyModule >> >>> it "works" do >>> testing >>> end >>> end >> >>> describe "describe" do >>> it_should_behave_like "shared" >> >>> it "works too" do >>> testing >>> end >>> end >> >>> When running with RSpec 1.3.1 all specs are passing, but RSpec 2.6 >>> fails with one failure: >>> 1) describe works too >>> Failure/Error: testing >>> NameError: >>> undefined local variable or method `testing' for >>> # >>> # ./spec/blah/blah_spec.rb:18 >> >>> It seems that the describe block doesn't get the methods included from >>> the module. How to solve that problem? >> >> This has been through a bit of churn, but here is the short version: >> >> it_should_behave_like creates (and wraps) a nested group, but there is are also two new include_context/include_examples methods. Your choices are: >> >> describe "describe" do >> it_should_behave_like "shared" do >> it "works too" do >> testing >> end >> end >> end >> >> describe "describe" do >> include_context "shared" >> it "works too" do >> testing >> end >> end >> >> describe "describe" do >> include_examples "shared" >> it "works too" do >> testing >> end >> end >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jarmo.p at gmail.com Wed Jun 1 12:35:43 2011 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 1 Jun 2011 09:35:43 -0700 (PDT) Subject: [rspec-users] how to include module into shared example group in RSpec 2 In-Reply-To: <66C01285-7EDA-4E3E-96A9-F8ADE9855643@gmail.com> References: <0a104f78-3113-45f4-ac50-c12ce473c912@g12g2000yqd.googlegroups.com> <07952665-618b-45bb-9c27-1005d196da3f@g12g2000yqd.googlegroups.com> <66C01285-7EDA-4E3E-96A9-F8ADE9855643@gmail.com> Message-ID: <469aa145-d0c0-4b64-b1fb-22278c8eb4d6@b1g2000yql.googlegroups.com> Done https://github.com/rspec/rspec-core/issues/396 Jarmo On Jun 1, 6:05?pm, David Chelimsky wrote: > On Jun 1, 2011, at 10:05 AM, Jarmo Pertman wrote: > > > Thank you :) > > > Where can i see the differences between #it_should_behave_like, > > #include_context and #include_examples? > > http://relishapp.com/rspec/rspec-core > > > > > > > > > > > > > Jarmo > > > On Jun 1, 5:42 pm, David Chelimsky wrote: > >> On Jun 1, 2011, at 9:10 AM, Jarmo Pertman wrote: > > >>> Hi! > > >>> We tried to upgrade our RSpec from 1.3.1 to 2.6 and are having some > >>> problems. It seems that shared example group includes modules > >>> differently in RSpec 2. > > >>> Consider the following code: > >>> module MyModule > >>> ?def testing > >>> ?end > >>> end > > >>> shared_examples_for "shared" do > >>> ?include MyModule > > >>> ?it "works" do > >>> ? ?testing > >>> ?end > >>> end > > >>> describe "describe" do > >>> ?it_should_behave_like "shared" > > >>> ?it "works too" do > >>> ? ?testing > >>> ?end > >>> end > > >>> When running with RSpec 1.3.1 all specs are passing, but RSpec 2.6 > >>> fails with one failure: > >>> ?1) describe works too > >>> ? ? Failure/Error: testing > >>> ? ? NameError: > >>> ? ? ? undefined local variable or method `testing' for > >>> # > >>> ? ? # ./spec/blah/blah_spec.rb:18 > > >>> It seems that the describe block doesn't get the methods included from > >>> the module. How to solve that problem? > > >> This has been through a bit of churn, but here is the short version: > > >> it_should_behave_like creates (and wraps) a nested group, but there is are also two new include_context/include_examples methods. Your choices are: > > >> describe "describe" do > >> ? it_should_behave_like "shared" do > >> ? ? it "works too" do > >> ? ? ? testing > >> ? ? end > >> ? end > >> end > > >> describe "describe" do > >> ? include_context "shared" > >> ? it "works too" do > >> ? ? testing > >> ? end > >> end > > >> describe "describe" do > >> ? include_examples "shared" > >> ? it "works too" do > >> ? ? testing > >> ? end > >> end > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From apremdas at gmail.com Fri Jun 3 08:39:29 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Fri, 3 Jun 2011 13:39:29 +0100 Subject: [rspec-users] Migrating cucumber tm_bundle to rspec 2 Message-ID: Hi there, I need some help migrating some code in the cucumber textmate bundle so I can run the specs with rspec2. The following code lives in support/spec/spec_helper.rb and I think its purpose is to load the fixtures. module Spec::Example::ExampleMethods def project_root @project_root ||= File.expand_path(File.join(File.dirname(__FILE__), '../fixtures')) end end Anyhow I can't find an rspec2 equivalent and was hoping someone might be able to help Best attempt so far uses module RSpec::Core::Subject::InstanceMethods but this is pure guesswork and I'm still getting errors, although it could be something unrelated TIA Andrew -- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Jun 3 10:17:09 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Jun 2011 09:17:09 -0500 Subject: [rspec-users] Migrating cucumber tm_bundle to rspec 2 In-Reply-To: References: Message-ID: On Jun 3, 2011, at 7:39 AM, Andrew Premdas wrote: > Hi there, > > I need some help migrating some code in the cucumber textmate bundle so I can run the specs with rspec2. > > The following code lives in support/spec/spec_helper.rb and I think its purpose is to load the fixtures. > > module Spec::Example::ExampleMethods > def project_root > @project_root ||= File.expand_path(File.join(File.dirname(__FILE__), '../fixtures')) > end > end > > Anyhow I can't find an rspec2 equivalent and was hoping someone might be able to help > > Best attempt so far uses module RSpec::Core::Subject::InstanceMethods but this is pure guesswork and I'm still getting errors, although it could be something unrelated Rather than monkey patching RSpec, I'd recommend using its APIs: RSpec.configure do |c| c.include(Module.new do def project_root # ... end end) end Let me know if that works. From apremdas at gmail.com Sat Jun 4 09:11:10 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Sat, 4 Jun 2011 14:11:10 +0100 Subject: [rspec-users] Migrating cucumber tm_bundle to rspec 2 In-Reply-To: References: Message-ID: On 3 June 2011 15:17, David Chelimsky wrote: > On Jun 3, 2011, at 7:39 AM, Andrew Premdas wrote: > > > Hi there, > > > > I need some help migrating some code in the cucumber textmate bundle so I > can run the specs with rspec2. > > > > The following code lives in support/spec/spec_helper.rb and I think its > purpose is to load the fixtures. > > > > module Spec::Example::ExampleMethods > > def project_root > > @project_root ||= File.expand_path(File.join(File.dirname(__FILE__), > '../fixtures')) > > end > > end > > > > Anyhow I can't find an rspec2 equivalent and was hoping someone might be > able to help > > > > Best attempt so far uses module RSpec::Core::Subject::InstanceMethods but > this is pure guesswork and I'm still getting errors, although it could be > something unrelated > > Rather than monkey patching RSpec, I'd recommend using its APIs: > > RSpec.configure do |c| > c.include(Module.new do > def project_root > # ... > end > end) > end > > Let me know if that works. > David, that seems to work fine -- thankyou There is one small problem, I get a deprecation warning ***************************************************************** DEPRECATION WARNING: you are using deprecated behaviour that will be removed from RSpec 3. You have set some configuration options after an example group has already been defined. In RSpec 3, this will not be allowed. All configuration should happen before the first example group is defined. The configuration is happening at: ./support/spec/cucumber/mate/files/../../../spec_helper.rb:12 ***************************************************************** My spec helper is require 'rubygems' require 'rspec/core' ENV['TM_SUPPORT_PATH'] = '/Applications/TextMate.app/Contents/SharedSupport/Support' RSpec.configure do |c| c.include(Module.new do def project_root @project_root ||= File.expand_path(File.join(File.dirname(__FILE__), '../fixtures')) end end) end Should I be putting this code somewhere else? Many thanks Andrew > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffdeville at gmail.com Wed Jun 1 01:37:25 2011 From: jeffdeville at gmail.com (JDeville) Date: Tue, 31 May 2011 22:37:25 -0700 (PDT) Subject: [rspec-users] including a module with ActiveSupport::Concern works in console/site, but not in specs Message-ID: <20072798.7082.1306906645052.JavaMail.geo-discussion-forums@vbjl31> I have a simple module: module Buyer extend ActiveSupport::Concern module ClassMethods def delete_occasion(fb_id, recipient_fb_id, occasion_id) # blah clah end end end I include it like this: class User include Buyer end this works when running the server, and in the console, but my specs yield: undefined method `delete_occasion' for # Is there something different I need to do for rspec here? *Env Details:* 1.9.2, rails 3.07, guard-rspec (0.3.1) rspec (2.6.0) rspec-core (2.6.3) rspec-expectations (2.6.0) rspec-given (1.3.1) rspec-instafail (0.1.7) rspec-mocks (2.6.0) rspec-rails (2.6.1) Thanks all. - jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From thakurne at gmail.com Wed Jun 1 02:11:09 2011 From: thakurne at gmail.com (Neha Thakur) Date: Tue, 31 May 2011 23:11:09 -0700 (PDT) Subject: [rspec-users] Not able to install rspec on Windows XP Message-ID: Hi everyone, I have downloaded and saved the folder in C: \Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1 I am into the folder mentioned below and is trying to install rspec but I am not able to do so...Can someone help me with this.. C:\Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1>gem install spec ERROR: Could not find a valid gem 'spec' (>= 0) in any repository ERROR: Possible alternatives: jspec, mspec, rspec, spec1, spec2 C:\Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1>gem install rspec ERROR: Could not find a valid gem 'rspec' (>= 0) in any repository ERROR: Possible alternatives: rspec From matt.rogish at gmail.com Fri Jun 3 13:20:33 2011 From: matt.rogish at gmail.com (MattR) Date: Fri, 3 Jun 2011 10:20:33 -0700 (PDT) Subject: [rspec-users] rspec1.3.2/rspec-rails1.3.4 and Rake 0.9.1 = lots of deprecation warnings Message-ID: <11143428.367.1307121633706.JavaMail.geo-discussion-forums@vbov2> Hi folks, I've been searching google and I don't think this case has yet been identified. I've got an older, Rails 2.3 app that is using rspec 1.3.x. We upgraded Rake to 0.9.1, and now I get tons of deprecation warnings on lib/tasks/rspec.rake:28: WARNING: Global access to Rake DSL methods is deprecated. Please Include Rake::DSL into classes and modules which use the Rake DSL methods. WARNING: DSL method Spec::Rake::SpecTask#task called at lib/tasks/rspec. rake:28:in `initialize' I tried adding include Rake::DSL in the class that is monkeypatched, but it doesn't work (unknown constant etc.). Any ideas? Thanks!! begin require 'spec/rake/spectask' rescue MissingSourceFile module Spec module Rake class SpecTask # I added it here def initialize(name) -- Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Jun 4 10:20:47 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Jun 2011 09:20:47 -0500 Subject: [rspec-users] Not able to install rspec on Windows XP In-Reply-To: References: Message-ID: On Wed, Jun 1, 2011 at 1:11 AM, Neha Thakur wrote: > Hi everyone, > > I have downloaded and saved the folder in C: > \Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1 > I am into the folder mentioned below and is trying to install rspec > but I am not able to do so...Can someone help me with this.. > > C:\Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1>gem install spec > ERROR: ?Could not find a valid gem 'spec' (>= 0) in any repository > ERROR: ?Possible alternatives: jspec, mspec, rspec, spec1, spec2 > > C:\Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1>gem install rspec > ERROR: ?Could not find a valid gem 'rspec' (>= 0) in any repository > ERROR: ?Possible alternatives: rspec What do you get when you type "gem env"? From dchelimsky at gmail.com Sat Jun 4 10:54:06 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Jun 2011 09:54:06 -0500 Subject: [rspec-users] including a module with ActiveSupport::Concern works in console/site, but not in specs In-Reply-To: <20072798.7082.1306906645052.JavaMail.geo-discussion-forums@vbjl31> References: <20072798.7082.1306906645052.JavaMail.geo-discussion-forums@vbjl31> Message-ID: On Jun 1, 2011, at 12:37 AM, JDeville wrote: > I have a simple module: > > module Buyer > extend ActiveSupport::Concern > > module ClassMethods > def delete_occasion(fb_id, recipient_fb_id, occasion_id) > # blah clah > end > end > end > > I include it like this: > class User > include Buyer > end Where does this ^^ code live? > > this works when running the server, and in the console, but my specs yield: > undefined method `delete_occasion' for # > > Is there something different I need to do for rspec here? > > Env Details: > 1.9.2, rails 3.07, > guard-rspec (0.3.1) > rspec (2.6.0) > rspec-core (2.6.3) > rspec-expectations (2.6.0) > rspec-given (1.3.1) > rspec-instafail (0.1.7) > rspec-mocks (2.6.0) > rspec-rails (2.6.1) > > Thanks all. - jeff What does the spec look like? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Jun 4 11:11:22 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Jun 2011 10:11:22 -0500 Subject: [rspec-users] rspec1.3.2/rspec-rails1.3.4 and Rake 0.9.1 = lots of deprecation warnings In-Reply-To: <11143428.367.1307121633706.JavaMail.geo-discussion-forums@vbov2> References: <11143428.367.1307121633706.JavaMail.geo-discussion-forums@vbov2> Message-ID: On Jun 3, 2011, at 12:20 PM, MattR wrote: > Hi folks, > > I've been searching google and I don't think this case has yet been identified. I've got an older, Rails 2.3 app that is using rspec 1.3.x. We upgraded Rake to 0.9.1, and now I get tons of deprecation warnings on lib/tasks/rspec.rake:28: > > WARNING: Global access to Rake DSL methods is deprecated. Please Include Rake::DSL into classes and modules which use the Rake DSL methods. > WARNING: DSL method Spec::Rake::SpecTask#task called at lib/tasks/rspec.rake:28:in `initialize' > > I tried adding include Rake::DSL in the class that is monkeypatched, but it doesn't work (unknown constant etc.). Any ideas? Thanks!! > > begin > require 'spec/rake/spectask' > rescue MissingSourceFile > module Spec > module Rake > class SpecTask > # I added it here > def initialize(name) > Please report this to the rspec-rails tracker (for 1.x): http://github.com/dchelimsky/rspec-rails/issues. Thx -------------- next part -------------- An HTML attachment was scrubbed... URL: From luislavena at gmail.com Sat Jun 4 11:39:20 2011 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 4 Jun 2011 11:39:20 -0400 Subject: [rspec-users] Not able to install rspec on Windows XP In-Reply-To: References: Message-ID: On Wed, Jun 1, 2011 at 2:11 AM, Neha Thakur wrote: > Hi everyone, > > I have downloaded and saved the folder in C: > \Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1 > I am into the folder mentioned below and is trying to install rspec > but I am not able to do so...Can someone help me with this.. > > C:\Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1>gem install spec > ERROR: ?Could not find a valid gem 'spec' (>= 0) in any repository > ERROR: ?Possible alternatives: jspec, mspec, rspec, spec1, spec2 > > C:\Ruby192\rspec-1.2.9.rc1\rspec-1.2.9.rc1>gem install rspec > ERROR: ?Could not find a valid gem 'rspec' (>= 0) in any repository > ERROR: ?Possible alternatives: rspec Hello, a couple of questions that will help us provide you answers to your problem: 1) What version of Ruby are you using? (execute "ruby -v" in the console to get the answer) 2) Why you manually downloaded the gems? are you behind a proxy? Seems to me that you downloaded *and* extracted the gem contents and are attempting to install them, but at the same time you're receiving errors from RubyGems about it. Can you please attempt the following? Outside any directory of any of the downloaded gems where put, please try: gem install rspec That single command should connect to rubygems.org, download latest information, find the gems, download *and* install them for you. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From ramon.tayag at gmail.com Sat Jun 4 12:59:57 2011 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Sun, 5 Jun 2011 00:59:57 +0800 Subject: [rspec-users] rspec1.3.2/rspec-rails1.3.4 and Rake 0.9.1 = lots of deprecation warnings In-Reply-To: <11143428.367.1307121633706.JavaMail.geo-discussion-forums@vbov2> References: <11143428.367.1307121633706.JavaMail.geo-discussion-forums@vbov2> Message-ID: <-724318333077350258@unknownmsgid> Sounds like it doesn't know how to load rake. Try require 'rake' or something like that on top. Ramon Tayag On Jun 4, 2011, at 22:58, MattR wrote: Hi folks, I've been searching google and I don't think this case has yet been identified. I've got an older, Rails 2.3 app that is using rspec 1.3.x. We upgraded Rake to 0.9.1, and now I get tons of deprecation warnings on lib/tasks/rspec.rake:28: WARNING: Global access to Rake DSL methods is deprecated. Please Include Rake::DSL into classes and modules which use the Rake DSL methods. WARNING: DSL method Spec::Rake::SpecTask#task called at lib/tasks/rspec. rake:28:in `initialize' I tried adding include Rake::DSL in the class that is monkeypatched, but it doesn't work (unknown constant etc.). Any ideas? Thanks!! begin require 'spec/rake/spectask' rescue MissingSourceFile module Spec module Rake class SpecTask # I added it here def initialize(name) -- Matt _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramon.tayag at gmail.com Sat Jun 4 13:11:18 2011 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Sun, 5 Jun 2011 01:11:18 +0800 Subject: [rspec-users] including a module with ActiveSupport::Concern works in console/site, but not in specs In-Reply-To: <20072798.7082.1306906645052.JavaMail.geo-discussion-forums@vbjl31> References: <20072798.7082.1306906645052.JavaMail.geo-discussion-forums@vbjl31> Message-ID: <-6505663999916666771@unknownmsgid> Not sure why it works inconsistently, but I always thought you did the following to include class methods via activesupport::concern: class Buyer extend ActiveSupport::Concern included do # def a_class_method end def an_instance_method ... end Ramon Tayag On Jun 4, 2011, at 22:51, JDeville wrote: I have a simple module: module Buyer extend ActiveSupport::Concern module ClassMethods def delete_occasion(fb_id, recipient_fb_id, occasion_id) # blah clah end end end I include it like this: class User include Buyer end this works when running the server, and in the console, but my specs yield: undefined method `delete_occasion' for # Is there something different I need to do for rspec here? *Env Details:* 1.9.2, rails 3.07, guard-rspec (0.3.1) rspec (2.6.0) rspec-core (2.6.3) rspec-expectations (2.6.0) rspec-given (1.3.1) rspec-instafail (0.1.7) rspec-mocks (2.6.0) rspec-rails (2.6.1) Thanks all. - jeff _______________________________________________ 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 tyson at crowdflower.com Sat Jun 4 15:55:05 2011 From: tyson at crowdflower.com (Tyson Tate) Date: Sat, 4 Jun 2011 12:55:05 -0700 Subject: [rspec-users] Request for comments: Scenario Message-ID: I created a gem a few weeks ago that I think the RSpec community might be interested in: https://github.com/tysontate/scenario (and that I'd love to get feedback on). It supports RSpec 1 and 2. It aims to solve a few of the problems we've had with a large spec suite that's been built over several years: - A veritable forest of global helper methods that often overlap in scope. Some of the method signatures on these methods are horrendous because people have tried to adapt, for example, a single "create_user" method to support too many different scenarios* ? non-approved user, regular user, admin user, and so on. - Expensive setup that doesn't allow granular control over what, exactly, gets set up without adding more options to the helper method or creating another redundant setup method. - (This is the most important one.) Tons of redundant setup code. Throughout many large spec suites, you'll notice a lot of redundant setup code. This redundant code can easily be grouped into a scenario that can more easily be reused throughout your specs. I'd love to hear any feedback you guys might have. The readme should cover most of the bases, but please let me know if you have any questions. The current examples in the readme are a bit trivial and don't really make a strong case for the use of scenarios over mixins, but I'll try to come up with better examples soon. -Tyson * See what I did there? :) -- *CrowdFlower @ *2111 Mission St, Suite 302, San Francisco, CA 94110 -------------- next part -------------- An HTML attachment was scrubbed... URL: From apremdas at gmail.com Sun Jun 5 08:49:28 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Sun, 5 Jun 2011 13:49:28 +0100 Subject: [rspec-users] Request for comments: Scenario In-Reply-To: References: Message-ID: On 4 June 2011 20:55, Tyson Tate wrote: > I created a gem a few weeks ago that I think the RSpec community might be > interested in: https://github.com/tysontate/scenario (and that I'd love to > get feedback on). It supports RSpec 1 and 2. > > It aims to solve a few of the problems we've had with a large spec suite > that's been built over several years: > > - A veritable forest of global helper methods that often overlap in > scope. Some of the method signatures on these methods are horrendous because > people have tried to adapt, for example, a single "create_user" method to > support too many different scenarios* ? non-approved user, regular user, > admin user, and so on. > - Expensive setup that doesn't allow granular control over what, > exactly, gets set up without adding more options to the helper method or > creating another redundant setup method. > - (This is the most important one.) Tons of redundant setup code. > Throughout many large spec suites, you'll notice a lot of redundant setup > code. This redundant code can easily be grouped into a scenario that can > more easily be reused throughout your specs. > > I'd love to hear any feedback you guys might have. The readme should cover > most of the bases, but please let me know if you have any questions. The > current examples in the readme are a bit trivial and don't really make a > strong case for the use of scenarios over mixins, but I'll try to come up > with better examples soon. > > -Tyson > > * See what I did there? :) > > -- > *CrowdFlower @ *2111 Mission St, Suite 302, San > Francisco, CA 94110 > > > This looks very elegant, a couple of points for feedback, having looked at the github page. 1. No installation instructions 2. No specific instructions about how this works with rspec, e.g. do you have to do anything with spec_helper 3. No explanation of where files should be put (in spec folder?) 4. I think the fixtures section could be fleshed out a bit with an example HTH Andrew > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Jun 5 12:20:08 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Jun 2011 11:20:08 -0500 Subject: [rspec-users] Request for comments: Scenario In-Reply-To: References: Message-ID: <838C3949-315F-4A1D-9BF2-8F3CA25C9E02@gmail.com> On Jun 4, 2011, at 2:55 PM, Tyson Tate wrote: > I created a gem a few weeks ago that I think the RSpec community might be interested in: https://github.com/tysontate/scenario (and that I'd love to get feedback on). It supports RSpec 1 and 2. > > It aims to solve a few of the problems we've had with a large spec suite that's been built over several years: > A veritable forest of global helper methods that often overlap in scope. Some of the method signatures on these methods are horrendous because people have tried to adapt, for example, a single "create_user" method to support too many different scenarios* ? non-approved user, regular user, admin user, and so on. > Expensive setup that doesn't allow granular control over what, exactly, gets set up without adding more options to the helper method or creating another redundant setup method. > (This is the most important one.) Tons of redundant setup code. Throughout many large spec suites, you'll notice a lot of redundant setup code. This redundant code can easily be grouped into a scenario that can more easily be reused throughout your specs. > I'd love to hear any feedback you guys might have. The readme should cover most of the bases, but please let me know if you have any questions. The current examples in the readme are a bit trivial and don't really make a strong case for the use of scenarios over mixins, but I'll try to come up with better examples soon. > > -Tyson Hey Tyson, I hate to be the bearer of "you can already do that", but, you can already do that (as of rspec-core-2.6) http://relishapp.com/rspec/rspec-core/dir/example-groups/shared-context https://gist.github.com/1009111 The only difference that I see is the use of the term 'scenario', which could be resolved with a couple of aliases. WDYT? David -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyson at crowdflower.com Sun Jun 5 15:37:41 2011 From: tyson at crowdflower.com (Tyson Tate) Date: Sun, 5 Jun 2011 12:37:41 -0700 Subject: [rspec-users] Request for comments: Scenario In-Reply-To: <838C3949-315F-4A1D-9BF2-8F3CA25C9E02@gmail.com> References: <838C3949-315F-4A1D-9BF2-8F3CA25C9E02@gmail.com> Message-ID: On Sun, Jun 5, 2011 at 9:20 AM, David Chelimsky wrote: > > Hey Tyson, > > I hate to be the bearer of "you can already do that", but, you can already > do that (as of rspec-core-2.6) > > http://relishapp.com/rspec/rspec-core/dir/example-groups/shared-context > https://gist.github.com/1009111 > > The only difference that I see is the use of the term 'scenario', which > could be resolved with a couple of aliases. > > WDYT? > I've no idea how I missed that! I swear I looked through the docs to see if it was something I could already do. In any case, our main spec suite still runs under RSpec 1 (there's a few dependencies keeping us from upgrading), so it's still useful for us. The only other difference I can see is the "setup_for" sugar, but that's something that could easily be added on top of shared_context. I'll dig into that. Thanks for the tip! -Tyson -- *CrowdFlower @ *2111 Mission St, Suite 302, San Francisco, CA 94110 -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Mon Jun 6 17:26:41 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 6 Jun 2011 14:26:41 -0700 (PDT) Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? Message-ID: Hi everyone, I am using rvm, and when I try to do rake spec, I get: "You have already activated rake 0.9.0, but your Gemfile requires rake 0.8.7. Consider using bundle exec." ... Is there a way to get around this so I don't have to do bundle exec rake spec each and every time? Also, I tried throwing 'debugger' into one of my specs and I get: "***** debugger statement ignored, use -d or --debug option to enable debugging" But I am not sure what is asking for the -d or --debug? Is it rake? Is it bundle? Neither rake nor bundle seem to like -d or --debug.. So I am totally confused on this one... Thanks. Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Mon Jun 6 18:49:43 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Jun 2011 17:49:43 -0500 Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: References: Message-ID: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> On Jun 6, 2011, at 4:26 PM, Patrick J. Collins wrote: > Hi everyone, > > I am using rvm, and when I try to do rake spec, I get: > > "You have already activated rake 0.9.0, but your Gemfile requires rake 0.8.7. > Consider using bundle exec." > > ... Is there a way to get around this so I don't have to do bundle exec rake spec each and every time? > > Also, I tried throwing 'debugger' into one of my specs and I get: > > "***** debugger statement ignored, use -d or --debug option to enable debugging" > > But I am not sure what is asking for the -d or --debug? Is it rake? Is it > bundle? Neither rake nor bundle seem to like -d or --debug.. So I am totally > confused on this one... > > Thanks. > > Patrick J. Collins > http://collinatorstudios.com Here's how I deal with this: bundle install --binstubs # installs bin/rake, etc export PATH=./bin:$PATH HTH, David From patrick at collinatorstudios.com Mon Jun 6 19:49:16 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 6 Jun 2011 16:49:16 -0700 (PDT) Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> References: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> Message-ID: > Here's how I deal with this: > > bundle install --binstubs # installs bin/rake, etc > export PATH=./bin:$PATH Great! What about using debugger? rake spec gives me: "***** debugger statement ignored, use -d or --debug option to enable debugging" rake spec -d gives me: "ambiguous option: -d" rake spec --debug gives me no output at all... thanks. Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Mon Jun 6 20:13:58 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Jun 2011 19:13:58 -0500 Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: References: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> Message-ID: <0D20EEE6-77F4-4BDB-922B-B323077F0CC1@gmail.com> On Jun 6, 2011, at 6:49 PM, Patrick J. Collins wrote: >> Here's how I deal with this: >> >> bundle install --binstubs # installs bin/rake, etc >> export PATH=./bin:$PATH > > Great! What about using debugger? > > rake spec gives me: > "***** debugger statement ignored, use -d or --debug option to enable debugging" > > rake spec -d gives me: > "ambiguous option: -d" > > rake spec --debug gives me no output at all... > > thanks. rake doesn't take arguments like that. Try 'rspec spec --debugger'. From patrick at collinatorstudios.com Mon Jun 6 20:53:57 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 6 Jun 2011 17:53:57 -0700 (PDT) Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: <0D20EEE6-77F4-4BDB-922B-B323077F0CC1@gmail.com> References: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> <0D20EEE6-77F4-4BDB-922B-B323077F0CC1@gmail.com> Message-ID: > rake doesn't take arguments like that. Try 'rspec spec --debugger'. Hmm, that gives no output at all.. I just get a bash prompt immediately after entering 'rake spec --debugger' Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Mon Jun 6 21:35:40 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Jun 2011 20:35:40 -0500 Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: References: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> <0D20EEE6-77F4-4BDB-922B-B323077F0CC1@gmail.com> Message-ID: On Jun 6, 2011, at 7:53 PM, Patrick J. Collins wrote: >> rake doesn't take arguments like that. Try 'rspec spec --debugger'. > Hmm, that gives no output at all.. I just get a bash prompt immediately > after entering 'rake spec --debugger' rspec, not rake: rspec spec --debugger From patrick at collinatorstudios.com Mon Jun 6 22:06:43 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 6 Jun 2011 19:06:43 -0700 (PDT) Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: References: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> <0D20EEE6-77F4-4BDB-922B-B323077F0CC1@gmail.com> Message-ID: > rspec, not rake: Oops! I missed that.. So other than this debugger thing, are there any other differences between rake spec and rspec spec? Patrick J. Collins http://collinatorstudios.com From matt at mattwynne.net Tue Jun 7 04:44:58 2011 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 7 Jun 2011 09:44:58 +0100 Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: References: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> <0D20EEE6-77F4-4BDB-922B-B323077F0CC1@gmail.com> Message-ID: On 7 Jun 2011, at 03:06, Patrick J. Collins wrote: >> rspec, not rake: > > Oops! I missed that.. So other than this debugger thing, are there any other > differences between rake spec and rspec spec? Just a bit! They're two completely different commands that run two completely different computer programs. Rake is a tool for running tasks of any nature, which you can invoke with the command `rake`. If you run `rake -T` in your project, you'll see that `rake spec` is just one of many other tasks you can run that do all kinds of things, not just to do with running tests. RSpec is a tool for running BDD-style unit tests, which you can invoke with the command `rspec`. If you run `rspec --help` you'll see all the options you could pass to the rspec command. In the case of `rake spec` the `spec` part is the name of the Rake task which runs your RSpec tests. In the case of `rspec spec` the `spec` part is the folder where you want the `rspec` program to look for tests to run. Does that make more sense now? cheers, Matt -- Freelance programmer & coach Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne From patrick at collinatorstudios.com Tue Jun 7 05:21:24 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 7 Jun 2011 02:21:24 -0700 (PDT) Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: References: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> <0D20EEE6-77F4-4BDB-922B-B323077F0CC1@gmail.com> Message-ID: > Rake is a tool for running tasks of any nature, which you can invoke with the command `rake`. If you run `rake -T` in your project, you'll see that `rake spec` is just one of many other tasks you can run that do all kinds of things, not just to do with running tests. > > RSpec is a tool for running BDD-style unit tests, which you can invoke with the command `rspec`. If you run `rspec --help` you'll see all the options you could pass to the rspec command. Right.. I just was wondering if the entire process of invoking RSpec to run all tests is identical between 'rake spec' and 'spec rspec' Which I am assuming by your answer that it is. Rake spec runs a task that probably just does: 'spec rspec' ? Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Tue Jun 7 06:43:21 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Jun 2011 05:43:21 -0500 Subject: [rspec-users] rake 0.9.0 activated error + debugger not working? In-Reply-To: References: <2C948D4A-2C69-48AA-B49E-5E26C1716715@gmail.com> <0D20EEE6-77F4-4BDB-922B-B323077F0CC1@gmail.com> Message-ID: On Jun 7, 2011, at 4:21 AM, Patrick J. Collins wrote: >> Rake is a tool for running tasks of any nature, which you can invoke with the command `rake`. If you run `rake -T` in your project, you'll see that `rake spec` is just one of many other tasks you can run that do all kinds of things, not just to do with running tests. >> >> RSpec is a tool for running BDD-style unit tests, which you can invoke with the command `rspec`. If you run `rspec --help` you'll see all the options you could pass to the rspec command. > Right.. I just was wondering if the entire process of invoking RSpec to run > all tests is identical between 'rake spec' and 'spec rspec' > > Which I am assuming by your answer that it is. Rake spec runs a task that > probably just does: 'spec rspec' ? While that is the end result, they are still quite different. The 'rake' task loads resources it needs for all rake tasks, and then it shells out to a separate process. In a Rails app, the rake task starts in the development environment (as that is the default) and shells out to the test environment. This means that you take the hit of loading up the Rails environment twice when you run 'rake spec', whereas 'rspec spec' loads it once, and doesn't load up the other things you need for other rake tasks. HTH, David From johnf at bitsbuilder.com Tue Jun 7 11:31:00 2011 From: johnf at bitsbuilder.com (John Feminella) Date: Tue, 7 Jun 2011 11:31:00 -0400 Subject: [rspec-users] Is "it_should_behave_like" a code smell? Message-ID: Consider the following simple Rails app: ==== begin snippet ==== # lib/herpable.rb module Herpable; ...; end # app/models/... class ClassOne; include Herpable; end class ClassTwo; include Herpable; end # ... ==== end snippet ==== What's the better way to write specs for these? Would you put the module into its own shared_example? ==== begin snippet ==== # spec/models/class_one_spec.rb describe ClassOne do it_should_behave_like "Herpable" # ... end ==== end snippet ==== Or would you just test the module directly? ==== begin snippet ==== # spec/lib/herpable_spec.rb describe Herpable do let(:herped) { Class.new { include Herpable } } it "should be derp" do herped.should_be derp end ==== end snippet ==== I started thinking about this because I noticed there seemed to be a lot of specs running in our shared examples. That gave rise to a couple of internal questions: 1.) If you have a bunch of closely related code that always gets tested together, why isn't it already a class or module? 2.) If it is, then why don't you just spec that instead? 3.) If you do, then what's the best way to use shared_examples_for / it_should_behave_like? ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ From dchelimsky at gmail.com Tue Jun 7 12:04:15 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Jun 2011 11:04:15 -0500 Subject: [rspec-users] Is "it_should_behave_like" a code smell? In-Reply-To: References: Message-ID: <526A1CA5-98C0-4E6F-B8D9-B4C4B492EBBB@gmail.com> On Jun 7, 2011, at 10:31 AM, John Feminella wrote: > Consider the following simple Rails app: > > ==== begin snippet ==== > # lib/herpable.rb > module Herpable; ...; end > > # app/models/... > class ClassOne; include Herpable; end > class ClassTwo; include Herpable; end > # ... > ==== end snippet ==== > > What's the better way to write specs for these? Would you put the > module into its own shared_example? > > ==== begin snippet ==== > # spec/models/class_one_spec.rb > describe ClassOne do > it_should_behave_like "Herpable" > # ... > end > ==== end snippet ==== > > Or would you just test the module directly? > > ==== begin snippet ==== > # spec/lib/herpable_spec.rb > describe Herpable do > let(:herped) { Class.new { include Herpable } } > > it "should be derp" do > herped.should_be derp > end > ==== end snippet ==== > > I started thinking about this because I noticed there seemed to be a > lot of specs running in our shared examples. That gave rise to a > couple of internal questions: > > 1.) If you have a bunch of closely related code that always gets > tested together, why isn't it already a class or module? > 2.) If it is, then why don't you just spec that instead? > 3.) If you do, then what's the best way to use shared_examples_for / > it_should_behave_like? There's a section on this in The RSpec Book. Briefly: 1. Host objects can override behavior (intentionally or otherwise), so spec'ing the module outside a host is insufficient. For these cases, I recommend using shared examples. 2. Some modules do stuff (like validate stuff in the host) when they are included. For these cases I recommend spec'ing the module directly. See http://relishapp.com/rspec/rspec-core/dir/example-groups/shared-examples for different approaches. I like "it_behaves_like", or context-specific aliases. HTH, David From apremdas at gmail.com Wed Jun 8 10:51:12 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Wed, 8 Jun 2011 15:51:12 +0100 Subject: [rspec-users] rspec with debug does not pick up .rdebugrc settings Message-ID: Hi there, latest rspec2, running in debug mode, does not seem to pick up settings from project .rdebugrc or home ~/.rdebugrc. Wondering if others experience this and if its anything obvious TIA Andrew -- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From dnelson77 at gmail.com Thu Jun 9 12:03:57 2011 From: dnelson77 at gmail.com (Daniel) Date: Thu, 9 Jun 2011 09:03:57 -0700 (PDT) Subject: [rspec-users] subdomain based namespacing makes RSpec incorrectly state that the route doesn't exist Message-ID: Hello, I'm doing namespace routing based on subdomain, rather than path, so that http://admin.example.com/pages leads to app/controllers/admin/ pages_controller.rb. Cucumber is following this fine, but RSpec is complaining that the requested route doesn't exist even though "rake routes" shows the route. When I add a standard namespace below the "scope :admin" block in my routes.rb file, RSpec does recognize the route, but I don't want path based namespacing. The relevant parts of routes.rb, and the spec file follow below, along with the the RSpec output and the matching line of "rake routes". config/routes.rb: scope :admin, :as => 'admin', :module => 'admin', :conditions => { :subdomain => 'admin' } do resources :pages end spec/controllers/admin/pages_controller_spec.rb: require 'spec_helper' describe Admin::PagesController do describe "GET index" do context "while not signed-in" do it "should redirect to www.example.com" do get :index # also tried get :index, :subdomain => 'admin' response.should redirect_to(root_url(:subdomain => 'www')) end end end end $ rspec spec/controllers/admin/pages_controller_spec.rb No DRb server is running. Running in local process instead ... F Failures: 1) Admin::PagesController GET index while not signed-in should redirect to www.example.com Failure/Error: get :index ActionController::RoutingError: No route matches {:controller=>"admin/pages"} $ rake routes ... admin_pages GET /pages(.:format) {:action=>"index", :controller=>"admin/pages"} ... Thank you for any help you can offer, Daniel From threadhead at gmail.com Thu Jun 9 13:33:01 2011 From: threadhead at gmail.com (Karl) Date: Thu, 9 Jun 2011 10:33:01 -0700 (PDT) Subject: [rspec-users] Stub an AR Model Instance Method Message-ID: <7f221d37-c764-4ff8-b16f-a87aacc94fad@j31g2000yqe.googlegroups.com> Obviously, I'm missing something very simple, can someone please explain how to stub an instance of an AR model method. This does not work: @widget = Widget.first # Widget has an instance method called 'next_seriel_number' @widget.stub(:next_serial_number).and_return(43, nil) I know I could use 'any_instance', and that does work, expect that I need to return multiple values. And 'any_instance' does not work with returning multiple values. This does not work: Widget.any_instance.stub(:next_serial_number).and_return(43, nil) # only returns 43 From me at jbrains.ca Sat Jun 11 21:08:57 2011 From: me at jbrains.ca (J. B. Rainsberger) Date: Sat, 11 Jun 2011 22:08:57 -0300 Subject: [rspec-users] Stub an AR Model Instance Method In-Reply-To: <7f221d37-c764-4ff8-b16f-a87aacc94fad@j31g2000yqe.googlegroups.com> References: <7f221d37-c764-4ff8-b16f-a87aacc94fad@j31g2000yqe.googlegroups.com> Message-ID: On Thu, Jun 9, 2011 at 14:33, Karl wrote: > Obviously, I'm missing something very simple, can someone please > explain how to stub an instance of an AR model method. > > This does not work: > @widget = Widget.first # Widget has an instance method called > 'next_seriel_number' > @widget.stub(:next_serial_number).and_return(43, nil) > > I know I could use 'any_instance', and that does work, expect that I > need to return multiple values. And 'any_instance' does not work with > returning multiple values. > > This does not work: > Widget.any_instance.stub(:next_serial_number).and_return(43, nil) # > only returns 43 Google "rspec mock_model" and off you go. Good luck. -- 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 shlomi at ben-hanna.com Sun Jun 12 03:25:02 2011 From: shlomi at ben-hanna.com (=?UTF-8?B?16nXnNeV157XmSDXpteT15XXpw==?=) Date: Sun, 12 Jun 2011 10:25:02 +0300 Subject: [rspec-users] help with rspec Message-ID: Hi all, My name is Shlomi Zadok - I am an old time PHP (mainly Drupal) developer and I am doing my first application on Ruby on Rails ( I just love it!!) I am trying to test my application with rspec and I am having problems. I have to admit that I rushed with the development and neglected the testing - I have installed rspec & webrat only after finished the prototype, not sure it is related. The error I am getting is: Failure/Error: Unable to find matching line from backtrace NameError: uninitialized constant ActionController::TestCase::Assertions You have encountered that question a lot huh? :) Please find below my configurations: I run Ubuntu 11.04 Rails 3.0.7 ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux] I use Aptana as an IDE My Gemfile: ---- source 'http://rubygems.org' gem 'rails', '3.0.7' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3-ruby', :require => 'sqlite3' # Enable gravatar gem 'gravatar_image_tag', '1.0.0.pre2' # Enable pagination gem 'will_paginate', '3.0.pre2' # Use unicorn as the web server # gem 'unicorn' # Enable jquery gem 'jquery-rails' # Enable tiny_mce # gem 'tiny_mce' # Enable amistad friendship manager gem 'amistad' # Enable authorization manager for user (who can see what) gem 'cancan' # Paperclip to add attachments to files gem "paperclip", "~> 2.3" # Deploy with Capistrano # gem 'capistrano' # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) # gem 'ruby-debug' # gem 'ruby-debug19' # Bundle the extra gems: # gem 'bj' # gem 'nokogiri' # gem 'sqlite3-ruby', :require => 'sqlite3' # gem 'aws-s3', :require => 'aws/s3' # Bundle gems for the local environment. Make sure to # put test-only gems in this group so their generators # and rake tasks are available in development mode: # group :development, :test do # gem 'webrat' # end group :development do gem 'rspec-rails', '2.5.0' end group :test do gem 'rspec', '2.5.0' gem 'webrat', '0.7.1' end ---- I started with a very simple test: spec/controllers/pages_controller_spec.rb (literally copied from http://ruby.railstutorial.org/chapters/static-pages): ---- require 'spec_helper' describe PagesController do describe "GET 'home'" do it "should be successful" do get 'home' response.should be_success end end end ---- Thank you so much for your help. Shlomi -- Shlomi Zadok -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Jun 12 08:27:48 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Jun 2011 07:27:48 -0500 Subject: [rspec-users] help with rspec In-Reply-To: References: Message-ID: On Jun 12, 2011, at 2:25 AM, ????? ???? wrote: > Hi all, > My name is Shlomi Zadok - I am an old time PHP (mainly Drupal) developer and I am doing my first application on Ruby on Rails ( I just love it!!) > I am trying to test my application with rspec and I am having problems. > > I have to admit that I rushed with the development and neglected the testing - I have installed rspec & webrat only after finished the prototype, not sure it is related. > > The error I am getting is: > Failure/Error: Unable to find matching line from backtrace > NameError: > uninitialized constant ActionController::TestCase::Assertions > > You have encountered that question a lot huh? :) > > Please find below my configurations: > > I run Ubuntu 11.04 > Rails 3.0.7 > ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux] > I use Aptana as an IDE > > My Gemfile: > ---- > group :development do > gem 'rspec-rails', '2.5.0' > end > > group :test do > gem 'rspec', '2.5.0' > gem 'webrat', '0.7.1' > end Do this instead: group :development, :test do gem 'rspec-rails', '2.5.0' end group :test do gem 'webrat', '0.7.1' end rspec-rails needs to be in the development env in order to expose the rake tasks and the test environment in order to be loaded when you run the spec suite. It has a dependency on rspec, so you don't need to list rspec explicitly. Webrat only needs to be in the development env. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Jun 12 08:33:07 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Jun 2011 07:33:07 -0500 Subject: [rspec-users] Stub an AR Model Instance Method In-Reply-To: <7f221d37-c764-4ff8-b16f-a87aacc94fad@j31g2000yqe.googlegroups.com> References: <7f221d37-c764-4ff8-b16f-a87aacc94fad@j31g2000yqe.googlegroups.com> Message-ID: <5A232306-43C5-4565-8633-45122A07CADB@gmail.com> On Jun 9, 2011, at 12:33 PM, Karl wrote: > Obviously, I'm missing something very simple, can someone please > explain how to stub an instance of an AR model method. > > This does not work: > @widget = Widget.first # Widget has an instance method called 'next_seriel_number' > @widget.stub(:next_serial_number).and_return(43, nil) "This does not work:" doesn't tell us what the problem is. Please be specific. Are you getting a failure? If so, please show us the complete code for the example, including any before hooks, and the failure message you're getting. From dchelimsky at gmail.com Sun Jun 12 09:41:22 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Jun 2011 08:41:22 -0500 Subject: [rspec-users] subdomain based namespacing makes RSpec incorrectly state that the route doesn't exist In-Reply-To: References: Message-ID: <406B5AB5-5E22-4BA6-A8F4-D1437AC19BB2@gmail.com> On Jun 9, 2011, at 11:03 AM, Daniel wrote: > Hello, > > I'm doing namespace routing based on subdomain, rather than path, so > that http://admin.example.com/pages leads to app/controllers/admin/ > pages_controller.rb. Cucumber is following this fine, but RSpec is > complaining that the requested route doesn't exist even though "rake > routes" shows the route. It's not that Cucumber gets it wrong and RSpec gets it right. Both tools delegate to Rails: cucumber-rails scenarios and rspec-rails request specs to to rails integration tests; rspec-rails controller specs to rails functional tests. If you did this in an rspec-rails request spec using the same declaration you're using in the cuke scenario, it would pass. If you did it in a rails functional test it would fail. More below. > When I add a standard namespace below the > "scope :admin" block in my routes.rb file, RSpec does recognize the > route, but I don't want path based namespacing. > > The relevant parts of routes.rb, and the spec file follow below, along > with the the RSpec output and the matching line of "rake routes". > > config/routes.rb: > > scope :admin, :as => 'admin', :module => 'admin', :conditions => > { :subdomain => 'admin' } do > resources :pages > end The hash key ^^ you're looking for is :constraints, not :conditions. Change that and it will work, even in a controller spec. The fact that it works in a Cucumber scenario is an accident, and likely due to how the request is being declared in the step definition. If it's something like get admin_pages_path, then it's using rails' routing to generate and recognize the path, so it makes sense that it works. Also, the declaration seems overly complex. You can get what I _think_ you're looking for like this: scope :module => :admin, :constraints => { :subdomain => 'admin' } do resources :pages end HTH, David From patrick at collinatorstudios.com Sun Jun 12 12:26:06 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sun, 12 Jun 2011 09:26:06 -0700 (PDT) Subject: [rspec-users] testing framework in 44 lines of ruby Message-ID: Hi everyone, I just came across this post and was wondering if this is on target with how RSpec works under the hood? http://www.skorks.com/2011/02/a-unit-testing-framework-in-44-lines-of-ruby/ Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Sun Jun 12 12:43:00 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Jun 2011 11:43:00 -0500 Subject: [rspec-users] testing framework in 44 lines of ruby In-Reply-To: References: Message-ID: <57A195AE-4EB8-4BDE-BD7D-E8FE660BA370@gmail.com> On Jun 12, 2011, at 11:26 AM, Patrick J. Collins wrote: > Hi everyone, > > I just came across this post and was wondering if this is on target with how > RSpec works under the hood? > > http://www.skorks.com/2011/02/a-unit-testing-framework-in-44-lines-of-ruby/ What do you mean by "on target"? Are you asking if the implementations are the same, or similar? Or are you asking if attest meets the same goals as RSpec? If you're asking about implementation, you can see both implementations on github and judge for yourself: https://github.com/rspec/rspec-core https://github.com/rspec/rspec-expectations https://github.com/rspec/rspec-mocks https://github.com/skorks/attest If you look at the latter, you'll see that the blog post's title is at least a bit misleading. The https://github.com/skorks/attest/blob/master/lib/attest directory has 5 subdirectories and 6 files, one of which (https://github.com/skorks/attest/blob/master/lib/attest/execution_context.rb) is close to 200 lines long. I'll leave it to somebody else to do a more thorough LOC comparison, but you get my drift. Cheers, David From patrick at collinatorstudios.com Sun Jun 12 13:52:09 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Sun, 12 Jun 2011 10:52:09 -0700 (PDT) Subject: [rspec-users] testing framework in 44 lines of ruby In-Reply-To: <57A195AE-4EB8-4BDE-BD7D-E8FE660BA370@gmail.com> References: <57A195AE-4EB8-4BDE-BD7D-E8FE660BA370@gmail.com> Message-ID: > What do you mean by "on target"? Are you asking if the implementations are > the same, or similar? Or are you asking if attest meets the same goals as > RSpec? More specifically, I meant the way he implements describe blocks and the should method... It's difficult for me to tell from glancing through the actual RSpec code.. For example I am confused by the implementation of 'should', since it calls: __should_for_example_group__ But prior to that, it appears that __should_for_example_group__ is an alias for should, which looks to me like it would be recursively calling itself. In that post's example, their definition of should simply returns self as they described "it's just syntactic sugar to make the tests read better", but from looking at RSpec's code, it seems like there's a lot more going on, but I am not quite seeing the big picture... Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Sun Jun 12 14:11:31 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Jun 2011 13:11:31 -0500 Subject: [rspec-users] testing framework in 44 lines of ruby In-Reply-To: References: <57A195AE-4EB8-4BDE-BD7D-E8FE660BA370@gmail.com> Message-ID: <88131E72-1BC9-4EC4-ABC7-16CE4631009F@gmail.com> On Jun 12, 2011, at 12:52 PM, Patrick J. Collins wrote: >> What do you mean by "on target"? Are you asking if the implementations are >> the same, or similar? Or are you asking if attest meets the same goals as >> RSpec? > > More specifically, I meant the way he implements describe blocks and the should > method... > > It's difficult for me to tell from glancing through the actual RSpec code.. > For example I am confused by the implementation of 'should', since it calls: > __should_for_example_group__ > > But prior to that, it appears that __should_for_example_group__ is an alias for > should, which looks to me like it would be recursively calling itself. The code you're looking at is an extension to support one liners like this: it { should do_something } The original definition of should is in https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/expectations/extensions/kernel.rb, which is what adds the 'should' method to every object. > In that post's example, their definition of should simply returns self as they > described "it's just syntactic sugar to make the tests read better", but from > looking at RSpec's code, it seems like there's a lot more going on, but I am > not quite seeing the big picture... RSpec's 'should' actually does something: it accepts a matcher and then tells the matcher to "match" against self. So no, they are not doing the same thing. I'm not really sure what you're trying to evaluate here, but feel free to ask if you have any more specific questions. Cheers, David From patmaddox at me.com Mon Jun 13 14:20:12 2011 From: patmaddox at me.com (Pat Maddox) Date: Mon, 13 Jun 2011 11:20:12 -0700 Subject: [rspec-users] testing framework in 44 lines of ruby In-Reply-To: References: <57A195AE-4EB8-4BDE-BD7D-E8FE660BA370@gmail.com> Message-ID: <043F5520-495C-4B24-84A5-7C4B28C428B0@me.com> On Jun 12, 2011, at 10:52 AM, Patrick J. Collins wrote: >> What do you mean by "on target"? Are you asking if the implementations are >> the same, or similar? Or are you asking if attest meets the same goals as >> RSpec? > > More specifically, I meant the way he implements describe blocks and the should > method... > > It's difficult for me to tell from glancing through the actual RSpec code.. Don't glance at it! Study it :) Pat From sahmed1020 at gmail.com Mon Jun 13 21:29:14 2011 From: sahmed1020 at gmail.com (S Ahmed) Date: Mon, 13 Jun 2011 21:29:14 -0400 Subject: [rspec-users] How to mock when there seems to be a requirement for chained mocked calls? Message-ID: I want to mock the following: MyModel.where(".....").last I tried: MyModel.should_receive(:where).and_return(nil) but this of course doesn't match the expectation since the call to .last was not mapped in the mock code. How can I do this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Jun 13 21:37:59 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Jun 2011 20:37:59 -0500 Subject: [rspec-users] How to mock when there seems to be a requirement for chained mocked calls? In-Reply-To: References: Message-ID: <2FED4C4B-941C-451B-A2B2-DA6AE600885C@gmail.com> On Jun 13, 2011, at 8:29 PM, S Ahmed wrote: "How to mock when there seems to be a requirement for chained mocked calls?" There is no such requirement unless you are imposing it by your own design decisions. > I want to mock the following: > > MyModel.where(".....").last Why do you want to do this? Is this in a model spec? A controller spec? > I tried: > > MyModel.should_receive(:where).and_return(nil) > > but this of course doesn't match the expectation since the call to .last was not mapped in the mock code. > > How can I do this? You _can_ stub (not mock) chains like this: MyModel.stub_chain(:where, :last).and_return(xxx) You can also set chained expectations like this (but I wouldn't recommend it): ar_query = double('ar_query') ar_query.should_receive(:last).and_return(nil) MyModel.stub(:where).and_return(ar_query) HTH, David From sahmed1020 at gmail.com Mon Jun 13 22:44:44 2011 From: sahmed1020 at gmail.com (S Ahmed) Date: Mon, 13 Jun 2011 22:44:44 -0400 Subject: [rspec-users] How to mock when there seems to be a requirement for chained mocked calls? In-Reply-To: <2FED4C4B-941C-451B-A2B2-DA6AE600885C@gmail.com> References: <2FED4C4B-941C-451B-A2B2-DA6AE600885C@gmail.com> Message-ID: This is a method in my Model that I am writing a test for correct. There are allot of if/else clauses in the method, and i want to make sure certain things are called so I want to write expectations for it. Not sure why you don't recommend such a thing? (chained expecations) On Mon, Jun 13, 2011 at 9:37 PM, David Chelimsky wrote: > On Jun 13, 2011, at 8:29 PM, S Ahmed wrote: > > "How to mock when there seems to be a requirement for chained mocked > calls?" > > There is no such requirement unless you are imposing it by your own design > decisions. > > > I want to mock the following: > > > > MyModel.where(".....").last > > Why do you want to do this? Is this in a model spec? A controller spec? > > > I tried: > > > > MyModel.should_receive(:where).and_return(nil) > > > > but this of course doesn't match the expectation since the call to .last > was not mapped in the mock code. > > > > How can I do this? > > You _can_ stub (not mock) chains like this: > > MyModel.stub_chain(:where, :last).and_return(xxx) > > You can also set chained expectations like this (but I wouldn't recommend > it): > > ar_query = double('ar_query') > ar_query.should_receive(:last).and_return(nil) > MyModel.stub(:where).and_return(ar_query) > > HTH, > 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 dchelimsky at gmail.com Mon Jun 13 23:09:37 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Jun 2011 22:09:37 -0500 Subject: [rspec-users] How to mock when there seems to be a requirement for chained mocked calls? In-Reply-To: References: <2FED4C4B-941C-451B-A2B2-DA6AE600885C@gmail.com> Message-ID: <4F469F94-2A5B-426B-90C6-173BDBC7BF52@gmail.com> On Jun 13, 2011, at 9:44 PM, S Ahmed wrote: > On Mon, Jun 13, 2011 at 9:37 PM, David Chelimsky wrote: > On Jun 13, 2011, at 8:29 PM, S Ahmed wrote: > > "How to mock when there seems to be a requirement for chained mocked calls?" > > There is no such requirement unless you are imposing it by your own design decisions. > > > I want to mock the following: > > > > MyModel.where(".....").last > > Why do you want to do this? Is this in a model spec? A controller spec? > > > I tried: > > > > MyModel.should_receive(:where).and_return(nil) > > > > but this of course doesn't match the expectation since the call to .last was not mapped in the mock code. > > > > How can I do this? > > You _can_ stub (not mock) chains like this: > > MyModel.stub_chain(:where, :last).and_return(xxx) > > You can also set chained expectations like this (but I wouldn't recommend it): > > ar_query = double('ar_query') > ar_query.should_receive(:last).and_return(nil) > MyModel.stub(:where).and_return(ar_query) [I moved your post to the bottom] > This is a method in my Model that I am writing a test for correct. > > There are allot of if/else clauses in the method, and i want to make sure certain things are called so I want to write expectations for it. > > Not sure why you don't recommend such a thing? (chained expectations) Because they are brittle. You can specify the externally observable behavior of a model without mocking its internals. This is _not_ the same as setting expectations on model methods called from controllers, in which case we're specifying how one component (the controller) talks to another component (the model). In a model spec, the model _is_ the component being specified. That all make sense? HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From apremdas at gmail.com Tue Jun 14 14:29:52 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 14 Jun 2011 19:29:52 +0100 Subject: [rspec-users] How to mock when there seems to be a requirement for chained mocked calls? In-Reply-To: <4F469F94-2A5B-426B-90C6-173BDBC7BF52@gmail.com> References: <2FED4C4B-941C-451B-A2B2-DA6AE600885C@gmail.com> <4F469F94-2A5B-426B-90C6-173BDBC7BF52@gmail.com> Message-ID: On 14 June 2011 04:09, David Chelimsky wrote: > On Jun 13, 2011, at 9:44 PM, S Ahmed wrote: > > On Mon, Jun 13, 2011 at 9:37 PM, David Chelimsky wrote: > > On Jun 13, 2011, at 8:29 PM, S Ahmed wrote: >> >> "How to mock when there seems to be a requirement for chained mocked >> calls?" >> >> There is no such requirement unless you are imposing it by your own design >> decisions. >> >> > I want to mock the following: >> > >> > MyModel.where(".....").last >> >> Why do you want to do this? Is this in a model spec? A controller spec? >> >> > I tried: >> > >> > MyModel.should_receive(:where).and_return(nil) >> > >> > but this of course doesn't match the expectation since the call to .last >> was not mapped in the mock code. >> > >> > How can I do this? >> >> You _can_ stub (not mock) chains like this: >> >> MyModel.stub_chain(:where, :last).and_return(xxx) >> >> You can also set chained expectations like this (but I wouldn't recommend >> it): >> >> ar_query = double('ar_query') >> ar_query.should_receive(:last).and_return(nil) >> MyModel.stub(:where).and_return(ar_query) >> > > [I moved your post to the bottom] > > This is a method in my Model that I am writing a test for correct. > > There are allot of if/else clauses in the method, and i want to make sure > certain things are called so I want to write expectations for it. > > This method will be hard to test because its not a good method. As its already written you might be better of refactoring first to remove all the if/else clauses. The most if/else clauses a method should have is 1!! A session with the ruby refactoring book is in order :) > Not sure why you don't recommend such a thing? (chained expectations) > > > Because they are brittle. > > You can specify the externally observable behavior of a model without > mocking its internals. This is _not_ the same as setting expectations on > model methods called from controllers, in which case we're specifying how > one component (the controller) talks to another component (the model). In a > model spec, the model _is_ the component being specified. That all make > sense? > > HTH, > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Jun 15 08:29:12 2011 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 15 Jun 2011 13:29:12 +0100 Subject: [rspec-users] Name of current example's file:line in a before block? Message-ID: Hi, I have an idea for a tool I want to build. In a Cucumber Before() block, I can say: Before do |scenario| puts scenario.file_colon_line end That then gives me the information I'd need to run that test case (and only that test case) again. Is there any way (however hacky / brittle) to do something similar in an RSpec before block, or do I need to delve into writing a formatter? cheers, Matt matt at mattwynne.net 07974 430184 From dchelimsky at gmail.com Wed Jun 15 08:47:02 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 15 Jun 2011 07:47:02 -0500 Subject: [rspec-users] Name of current example's file:line in a before block? In-Reply-To: References: Message-ID: <303DB150-6BDD-4E9A-AC79-0CF0A0C234AF@gmail.com> On Jun 15, 2011, at 7:29 AM, Matt Wynne wrote: > Hi, > > I have an idea for a tool I want to build. In a Cucumber Before() block, I can say: > > Before do |scenario| > puts scenario.file_colon_line > end > > That then gives me the information I'd need to run that test case (and only that test case) again. > > Is there any way (however hacky / brittle) to do something similar in an RSpec before block, or do I need to delve into writing a formatter? > > cheers, > Matt before { puts example.location } Cheers, David From matt at mattwynne.net Wed Jun 15 15:50:02 2011 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 15 Jun 2011 20:50:02 +0100 Subject: [rspec-users] Name of current example's file:line in a before block? In-Reply-To: <303DB150-6BDD-4E9A-AC79-0CF0A0C234AF@gmail.com> References: <303DB150-6BDD-4E9A-AC79-0CF0A0C234AF@gmail.com> Message-ID: On 15 Jun 2011, at 13:47, David Chelimsky wrote: > On Jun 15, 2011, at 7:29 AM, Matt Wynne wrote: > >> Hi, >> >> I have an idea for a tool I want to build. In a Cucumber Before() block, I can say: >> >> Before do |scenario| >> puts scenario.file_colon_line >> end >> >> That then gives me the information I'd need to run that test case (and only that test case) again. >> >> Is there any way (however hacky / brittle) to do something similar in an RSpec before block, or do I need to delve into writing a formatter? >> >> cheers, >> Matt > > before { puts example.location } Good answer! Now, for bonus points: when the example is from a set of shared examples, is there an easy way to get the location of the line where the shared examples were included? (i.e. the file:line I'd need to pass to `rspec` in order to actually re-run that example). I can grep, but it would be easier if I could ask RSpec's model. Possible? > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From kai.schlamp at googlemail.com Fri Jun 17 14:03:52 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Fri, 17 Jun 2011 11:03:52 -0700 (PDT) Subject: [rspec-users] RSpec 2.6 + Capybara 1.0 incompatibility Message-ID: <550e4c15-d7f3-47ab-b0d6-dc5dc4eac04e@d14g2000yqb.googlegroups.com> Hi. I use RSpec-Rails 2.6.1 together with Capybara 1.0.0. Whenever I start my integration (request) tests I get the following error: Failure/Error: page.execute_script('$ ("div.editable:first").trigger("mouseover");') Selenium::WebDriver::Error::UnexpectedJavascriptError: $ is not defined It seems that it can't find jQuery in there. Another strange thing is that it doesn't start the browser at all when telling Capybara to use the Selenium driver. Why do I write this here!? Because when I switch back to RSpec 2.5 everything runs fine again. Do I have to re-configure something for RSpec 2.6? Any clue what the cause could be? Regards, Kai From kai.schlamp at googlemail.com Fri Jun 17 15:20:53 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Fri, 17 Jun 2011 12:20:53 -0700 (PDT) Subject: [rspec-users] RSpec 2.6 + Capybara 1.0 incompatibility In-Reply-To: <550e4c15-d7f3-47ab-b0d6-dc5dc4eac04e@d14g2000yqb.googlegroups.com> References: <550e4c15-d7f3-47ab-b0d6-dc5dc4eac04e@d14g2000yqb.googlegroups.com> Message-ID: <9c74c93a-fa28-4098-988b-cd820a74ba6e@u10g2000yqh.googlegroups.com> Here is also the spec helper I use for my integration tests: ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'webrat' require 'capybara/rspec' require "database_cleaner" Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |config| config.filter_run :focus => true config.run_all_when_everything_filtered = true config.filter_run_excluding :exclude => true config.use_transactional_fixtures = false config.mock_with :rspec config.before(:all) do DatabaseCleaner.strategy = :truncation DatabaseCleaner.clean end config.after(:each) do DatabaseCleaner.clean Sunspot.remove_all! end end Webrat.configure do |config| config.mode = :rails end From dchelimsky at gmail.com Fri Jun 17 15:23:37 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Jun 2011 14:23:37 -0500 Subject: [rspec-users] RSpec 2.6 + Capybara 1.0 incompatibility In-Reply-To: <9c74c93a-fa28-4098-988b-cd820a74ba6e@u10g2000yqh.googlegroups.com> References: <550e4c15-d7f3-47ab-b0d6-dc5dc4eac04e@d14g2000yqb.googlegroups.com> <9c74c93a-fa28-4098-988b-cd820a74ba6e@u10g2000yqh.googlegroups.com> Message-ID: On Jun 17, 2011, at 2:20 PM, Kai Schlamp wrote: > Here is also the spec helper I use for my integration tests: > > ENV["RAILS_ENV"] ||= 'test' > require File.expand_path("../../config/environment", __FILE__) > require 'rspec/rails' > require 'webrat' > require 'capybara/rspec' > require "database_cleaner" > > Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} > > RSpec.configure do |config| > config.filter_run :focus => true > config.run_all_when_everything_filtered = true > config.filter_run_excluding :exclude => true > config.use_transactional_fixtures = false > config.mock_with :rspec > > config.before(:all) do > DatabaseCleaner.strategy = :truncation > DatabaseCleaner.clean > end > > config.after(:each) do > DatabaseCleaner.clean > Sunspot.remove_all! > end > end > > Webrat.configure do |config| > config.mode = :rails > end Webrat and Capybara are not compatible, as they each do similar things in different ways. This wasn't a visible issue in rspec-rails-2.5 because capybara was only mixed in to request specs, but 2.6 mixes it into view and helper specs as well. HTH, David From kai.schlamp at googlemail.com Fri Jun 17 17:16:19 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Fri, 17 Jun 2011 14:16:19 -0700 (PDT) Subject: [rspec-users] RSpec 2.6 + Capybara 1.0 incompatibility In-Reply-To: References: <550e4c15-d7f3-47ab-b0d6-dc5dc4eac04e@d14g2000yqb.googlegroups.com> <9c74c93a-fa28-4098-988b-cd820a74ba6e@u10g2000yqh.googlegroups.com> Message-ID: <94244cde-82da-4208-8b21-f7c39de6b81a@h7g2000yqa.googlegroups.com> Thank you, David. After removing the Webrat stuff everything runs perfectly again. Regards, Kai From sahmed1020 at gmail.com Fri Jun 17 19:17:45 2011 From: sahmed1020 at gmail.com (S Ahmed) Date: Fri, 17 Jun 2011 19:17:45 -0400 Subject: [rspec-users] how to mock/stub when there are multiple model objects? Message-ID: I'm a bit confused how to hook into a particular model object instance and mock/stub it? I understand how to hook into a class level method like: User.should_receive(:where).and_return(....) but what if my method looks like: def some_thing user = User.where("...") user2 = User.where("...") user.delete user2.update_attributes(some_attr) end How can I hook into one or both model instances of 'user' and 'user2' at the same time in the same test? Or is it only possible to do it one at a time? -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Fri Jun 17 19:39:29 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 17 Jun 2011 16:39:29 -0700 (PDT) Subject: [rspec-users] how to mock/stub when there are multiple model objects? In-Reply-To: References: Message-ID: > but what if my method looks like: > > ? ?user = User.where("...") > ? ?user2 = User.where("...") User.should_receive(:where).with("...").and_return(...) http://apidock.com/rspec/Spec/Mocks Patrick J. Collins http://collinatorstudios.com From threadhead at gmail.com Sat Jun 18 20:10:26 2011 From: threadhead at gmail.com (Karl) Date: Sat, 18 Jun 2011 17:10:26 -0700 (PDT) Subject: [rspec-users] Stub an AR Model Instance Method In-Reply-To: <5A232306-43C5-4565-8633-45122A07CADB@gmail.com> References: <7f221d37-c764-4ff8-b16f-a87aacc94fad@j31g2000yqe.googlegroups.com> <5A232306-43C5-4565-8633-45122A07CADB@gmail.com> Message-ID: Found my problem... mostly due to my misunderstanding of mocks. Joe's suggestion above led me down the right path. This worked: @account = mock_model(Account) @account.stub!(:next_serial_number).and_return(43, nil) Widget.any_instance.stub(:account).and_return(@account) On Jun 12, 5:33?am, David Chelimsky wrote: > On Jun 9, 2011, at 12:33 PM, Karl wrote: > > > Obviously, I'm missing something very simple, can someone please > > explain how to stub an instance of an AR model method. > > > This does not work: > > @widget = Widget.first # Widget has an instance method called 'next_seriel_number' > > @widget.stub(:next_serial_number).and_return(43, nil) > > "This does not work:" doesn't tell us what the problem is. Please be specific. Are you getting a failure? If so, please show us the complete code for the example, including any before hooks, and the failure message you're getting. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From me at jbrains.ca Sun Jun 19 08:55:02 2011 From: me at jbrains.ca (J. B. Rainsberger) Date: Sun, 19 Jun 2011 09:55:02 -0300 Subject: [rspec-users] Stub an AR Model Instance Method In-Reply-To: References: <7f221d37-c764-4ff8-b16f-a87aacc94fad@j31g2000yqe.googlegroups.com> <5A232306-43C5-4565-8633-45122A07CADB@gmail.com> Message-ID: On Sat, Jun 18, 2011 at 21:10, Karl wrote: > Found my problem... mostly due to my misunderstanding of mocks. Joe's > suggestion above led me down the right path. This worked: > > @account = mock_model(Account) > @account.stub!(:next_serial_number).and_return(43, nil) > Widget.any_instance.stub(:account).and_return(@account) I'm glad you found something that did what you wanted. Now what are you trying to do with it? I've never wanted to stub :next_serial_number before, so I'd like to understand the situation you find yourself in, for when that happens to me. -- 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 ckponnappa at gmail.com Tue Jun 21 08:13:09 2011 From: ckponnappa at gmail.com (Sidu Ponnappa) Date: Tue, 21 Jun 2011 17:43:09 +0530 Subject: [rspec-users] Time out long running tests using Rspec 2 In-Reply-To: References: Message-ID: I'm cross posting a query on timing out tests that came up on our local ruby list: In RSpec1, there was an option "timeout" using which we can fail all > the long running tests i.e. "spec --timeout 2 spec/" will fail those > tests which takes more than 2 seconds to run. It does not seem to be > existing in RSpec2. I saw the "filter_run" option as mentioned here: > http://blog.davidchelimsky.net/2010/06/14/filtering-examples-in-rspec-2/. > Using this I can add "slow" tags to tests. But it is not same as the > "timeout" option. Can someone let me know whats the better approach to > time out slow running tests? Any suggestions would be appreciated. Thanks, Sidu. http://c42.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From jed.schneider at gmail.com Tue Jun 21 16:00:50 2011 From: jed.schneider at gmail.com (Jed Schneider) Date: Tue, 21 Jun 2011 16:00:50 -0400 Subject: [rspec-users] stubbing /mocking ldap within a method Message-ID: given I have the following with the internal assignments to filter and ldap: class Collaborator def self.search_ldap(term) last_name = term.strip.split(/[, ]/).first.downcase filter = Net::LDAP::Filter.eq('surName', last_name) ldap = Net::LDAP.new( :host => 'foo', :port => 636, :base => 'bar', :encryption => :fiz) ldap.search(:filter => filter) end end I would like mock out the LDAP class so i can test the behavior of the method without LDAP. describe Collaborator do it "should search ldap and return last names from the first item of the search phrase" do entry = Net::LDAP::Entry items = {:cn=>["Jim Bob"],:uid=>['bob46'],:mail=>'bob at life.edu'} items.each{|k,v| entry.stub(k) {v} } # how do I get to objects inside this method, something like? assigns(:ldap).stub(:search).and_return(entry) # but that doesnt work Collaborator.search_ldap("Bob").should == [entry] end end -- Jed Schneider -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at jbrains.ca Tue Jun 21 17:56:42 2011 From: me at jbrains.ca (J. B. Rainsberger) Date: Tue, 21 Jun 2011 18:56:42 -0300 Subject: [rspec-users] stubbing /mocking ldap within a method In-Reply-To: References: Message-ID: On Tue, Jun 21, 2011 at 17:00, Jed Schneider wrote: > given I have the following with the internal assignments to filter and ldap: > class Collaborator > ??def self.search_ldap(term) > ?? ?last_name = term.strip.split(/[, ]/).first.downcase > ?? ?filter = Net::LDAP::Filter.eq('surName', last_name) > ?? ?ldap = Net::LDAP.new( :host => 'foo', :port => 636, :base => 'bar', > :encryption => :fiz) > ?? ?ldap.search(:filter => filter) > ??end > end > I would like mock out the LDAP class so i can test the behavior of the > method without LDAP. In this case, I'd invoke the rule "Don't mock types you don't own". What can you trust? LDAP does the right thing. What can you get wrong? Sending the wrong parameters to LDAP. Therefore, check the parameters you send to LDAP. class Collaborator def initialize(ldapGateway = LdapGateway.new) @gateway = ldapGateway end def self.search_ldap(term) last_name = term.strip.split(/[, ]/).first.downcase @gateway.search('surName', last_name, 'foo', 636, 'bar', :fiz) end end class LdapGateway def search(label, value, host, port, base, encryption) filter = Net::LDAP::Filter.eq('surName', last_name) ldap = Net::LDAP.new( :host => 'foo', :port => 636, :base => 'bar', :encryption => :fiz) ldap.search(:filter => filter) end end Judging only by the names, "label" and "value" seem separate from "host"?"encryption". My intuition tells me to move the latter group into constructor parameters. class Collaborator def initialize(ldapGateway) @gateway = ldapGateway end def self.search_ldap(term) last_name = term.strip.split(/[, ]/).first.downcase @gateway.search('surName', last_name) end end class LdapGateway def initialize(host, post, base, encryption) # assign to fields end def search(label, value) filter = Net::LDAP::Filter.eq('surName', last_name) # SMELL Temporal duplication; can we create an LDAP in the constructor? ldap = Net::LDAP.new( :host => @host, :port => @port, :base => @base, :encryption => @encryption) ldap.search(:filter => filter) end end Now the LdapGateway responds to search(label, value), so I don't think Collaborator needs to know that any LDAP is going on. class Collaborator def initialize(term_repository) @term_repository = term_repository end def self.search_ldap(term) last_name = term.strip.split(/[, ]/).first.downcase @term_repository.search('surName', last_name) end end I'm using the mechanical name "Repository" here, because I don't yet understand the role this object plays in the system. class LdapGateway # I'm a TermRepository! Extract a module someday? def initialize(host, post, base, encryption) # assign to fields end def search(label, value) filter = Net::LDAP::Filter.eq('surName', last_name) # SMELL Temporal duplication; can we create an LDAP in the constructor? ldap = Net::LDAP.new( :host => @host, :port => @port, :base => @base, :encryption => @encryption) ldap.search(:filter => filter) end end Now it's easy to check: describe Collaborator do context "when searching" do it "should pass the proper surname to the TermRepository" do termRepository = mock("a TermRepository") termRepository.should_receive(:search).with('surName', 'rainsberger') Collaborator.new(termRepository).search('J. B. Rainsberger') end it "should return the repository's results" do Collaborator.new(stub(:search => ["a", "b", "c"])).search('J. B. Rainsberger').should == ["a", "b", "c"] end end end Does that help you? -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Author, JUnit Recipes Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com From dblockdotorg at gmail.com Wed Jun 22 10:30:03 2011 From: dblockdotorg at gmail.com (dblock) Date: Wed, 22 Jun 2011 07:30:03 -0700 (PDT) Subject: [rspec-users] rspec not returning exit code with --drb w/o spork running Message-ID: I am seeing a problem with running rspec (rspec 2.6.0, rspec-core 2.6.4) with --drb (our default) when spork is not running. It fails to return a non-zero error code. Anyone has any suggestions where I should start looking? Known bug? Thx dB. --- dblock at dblock-magenta:~/source/Gravity/dblock$ rake gravity:test:ci (in /home/dblock/source/Gravity/dblock) No DRb server is running. Running in local process instead ... WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.8 F Failures: 1) artwork/:slug capybara should fail Failure/Error: page.should have_css('blah') expected css "blah" to return something # ./spec/capybara_fail.rb:15:in `block (3 levels) in ' Finished in 13.23 seconds 1 example, 1 failure Failed examples: rspec ./spec/capybara_fail.rb:14 # artwork/:slug capybara should fail rspec spec pid 5522 exit 0 From dblockdotorg at gmail.com Wed Jun 22 10:55:45 2011 From: dblockdotorg at gmail.com (dblock) Date: Wed, 22 Jun 2011 07:55:45 -0700 (PDT) Subject: [rspec-users] rspec not returning exit code with --drb w/o spork running In-Reply-To: References: Message-ID: <39c6bc51-d37f-4564-989c-f17ffe9476a4@l6g2000vbn.googlegroups.com> It seems like the problem is in Ruby, described in https://github.com/jnicklas/capybara/issues/178 But I fail to see how I can workaround that :( Any ideas? From dblockdotorg at gmail.com Wed Jun 22 12:23:55 2011 From: dblockdotorg at gmail.com (dblock) Date: Wed, 22 Jun 2011 09:23:55 -0700 (PDT) Subject: [rspec-users] rspec not returning exit code with --drb w/o spork running In-Reply-To: <39c6bc51-d37f-4564-989c-f17ffe9476a4@l6g2000vbn.googlegroups.com> References: <39c6bc51-d37f-4564-989c-f17ffe9476a4@l6g2000vbn.googlegroups.com> Message-ID: Ok, sorry for the spam. I applied the same change that was done in minitest to rspec and it seems to work. Pull request here: https://github.com/rspec/rspec-core/pull/410. From masterlambaster at gmail.com Wed Jun 22 11:30:22 2011 From: masterlambaster at gmail.com (Master Lambaster) Date: Wed, 22 Jun 2011 08:30:22 -0700 (PDT) Subject: [rspec-users] Formatters extra data Message-ID: <32674d00-a4d0-4a06-9630-cb1c6d37865c@22g2000yqv.googlegroups.com> Hi David, Want to discuss possibilities of giving formatters more information form examples and example groups. I was about to create formatter with some additional info form running spec but came across the problem that all formatters are runned after after -> around hooks were fired and cleanup were made. Though I'd like to have access to this information. The second issue is that the extra_failure_content from HtmlFormatter passes just exception. Passing example will give more freedom of constructing reports with more details. I've made no much investigations on this issues, and sorry in advance if this cases has workaround. From dblockdotorg at gmail.com Wed Jun 22 16:09:17 2011 From: dblockdotorg at gmail.com (dblock) Date: Wed, 22 Jun 2011 13:09:17 -0700 (PDT) Subject: [rspec-users] How do I change www.example.com in rspec tests? Message-ID: It looks like request.host is set to www.example.com, how do I change that? I want to change it for all tests, and it seems that request is only available within the tests themselves (tried to do it in RSpec.configure but that didn't work. From jed.schneider at gmail.com Wed Jun 22 16:33:43 2011 From: jed.schneider at gmail.com (Jed Schneider) Date: Wed, 22 Jun 2011 16:33:43 -0400 Subject: [rspec-users] stubbing /mocking ldap within a method Message-ID: Joe, Here is the solution I decided to go with, for now: describe Collaborator do describe "class_methods" do subject {Collaborator} it { should respond_to(:search_ldap).with(1).argument } it "should format the search term" do subject.prepare_search_term("Bob").should == "bob" end end end describe LdapGateway do subject { LdapGateway.new("surName") } it { should respond_to(:search_for).with(1).argument } it "should set @ldap to an instance of Net::LDAP" do subject.instance_eval('@ldap').should be_kind_of(Net::LDAP) end it "should set the label to the initialzied variable" do subject.instance_eval("@label").should == "surName" end end class LdapGateway def initialize(label) @ldap = Net::LDAP.new(credentials) @label = label end def search_for(term) @ldap.search(:filter => Net::LDAP::Filter.eq(@label, term)) end end class Collaborator < ActiveRecord::Base def self.search_ldap(term) last_name = prepare_search_term(term) @gateway = LdapGateway.new('surName') @gateway.search_for(last_name) # alternatively, maybe # LdapGateway.new('surName').search_for(last_name) end def self.prepare_search_term(term) term.strip.split(/[, ]/).first.downcase end end -- Jed Schneider 706-207-4458 (m) 803-386-7214 jedschneider.posterous.com twitter.com/jedschneider github.com/jedschneider -------------- next part -------------- An HTML attachment was scrubbed... URL: From sahmed1020 at gmail.com Thu Jun 23 16:55:45 2011 From: sahmed1020 at gmail.com (S Ahmed) Date: Thu, 23 Jun 2011 16:55:45 -0400 Subject: [rspec-users] how to mock/stub when there are multiple model objects? In-Reply-To: References: Message-ID: Thanks. I'm trying this now on a Model that is using Mongoid. I have tried: it "should ..." do User.stub(:some_call).and_return(User.new(:name => "blah")) end And when running spec on this file I get: NoMethodError, undefined method "stub" for User:Class I also tried: User.stub!(:some_call).... Does this not work on mongoid objects? On Fri, Jun 17, 2011 at 7:39 PM, Patrick J. Collins < patrick at collinatorstudios.com> wrote: > > but what if my method looks like: > > > > user = User.where("...") > > user2 = User.where("...") > User.should_receive(:where).with("...").and_return(...) > http://apidock.com/rspec/Spec/Mocks > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From johnf at bitsbuilder.com Fri Jun 24 08:17:21 2011 From: johnf at bitsbuilder.com (John Feminella) Date: Fri, 24 Jun 2011 08:17:21 -0400 Subject: [rspec-users] Is there a way to run `let` once per context? Message-ID: hello, I have a monolithic test that looks like this: ====== describe Model do describe "#method" do let!(:expensive) { ... } it "should do a lot of things" do expensive.should be_foo expensive.should be_bar expensive.should be_baz end end end ====== I would like to refactor the large spec into smaller ones: ====== it "should be foo" { expensive.should be_foo } it "should be bar" { expensive.should be_bar } it "should be baz" { expensive.should be_baz } ====== However, doing this slows down the tests a bit, because the `expensive` method requires hitting the database. Suppose that I can guarantee that none of the tests or the methods they call will be modifying the object returned by the `expensive` method. Is there a way to tell RSpec to memoize the `expensive` result across the context, and not just across an individual test run? Alternatively, should I just use before(:all) for this? -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ From dchelimsky at gmail.com Fri Jun 24 08:48:37 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Jun 2011 07:48:37 -0500 Subject: [rspec-users] Is there a way to run `let` once per context? In-Reply-To: References: Message-ID: On Jun 24, 2011, at 7:17 AM, John Feminella wrote: > hello, > > I have a monolithic test that looks like this: > > ====== > describe Model do > describe "#method" do > let!(:expensive) { ... } > > it "should do a lot of things" do > expensive.should be_foo > expensive.should be_bar > expensive.should be_baz > end > end > end > ====== > > I would like to refactor the large spec into smaller ones: > > ====== > it "should be foo" { expensive.should be_foo } > it "should be bar" { expensive.should be_bar } > it "should be baz" { expensive.should be_baz } > ====== > > However, doing this slows down the tests a bit, because the > `expensive` method requires hitting the database. > > Suppose that I can guarantee that none of the tests or the methods > they call will be modifying the object returned by the `expensive` > method. Is there a way to tell RSpec to memoize the `expensive` result > across the context, and not just across an individual test run? > > Alternatively, should I just use before(:all) for this? Just use before(:all). That's what it is designed for, and it tells you that you have stuff to clean up in an after(:all) hook. HTH, David From johnf at bitsbuilder.com Fri Jun 24 09:08:29 2011 From: johnf at bitsbuilder.com (John Feminella) Date: Fri, 24 Jun 2011 09:08:29 -0400 Subject: [rspec-users] Is there a way to run `let` once per context? In-Reply-To: References: Message-ID: >> Alternatively, should I just use before(:all) for this? > > Just use before(:all). That's what it is designed for, and it tells you that you have stuff to clean up in an after(:all) hook. I was about to take your advice, when I discovered another problem: ====== RSpec.configure do |config| config.mock_with :rspec config.before(:each, :geocoding => nil) do Geocoding.stub(:client).and_return(Geocoding::StubGeoClient.new) end end ====== Since the test-specific before-all hook runs first before the global before-each hook, that means that the `expensive` operation now hits an external geocoding service, which makes it take even longer. It also makes tests fail because WebMock is running, and it prohibits network connections you don't explicitly specify. The fact that this is becoming obnoxious suggests that something else is probably bad (e.g. maybe the `expensive` model should be changed to be less expensive to create). I think I'll do that instead of trying to go down this road further. Thanks for your help, David. ~ jf On Fri, Jun 24, 2011 at 08:48, David Chelimsky wrote: > > On Jun 24, 2011, at 7:17 AM, John Feminella wrote: > >> hello, >> >> I have a monolithic test that looks like this: >> >> ====== >> describe Model do >> ?describe "#method" do >> ? ?let!(:expensive) { ... } >> >> ? ?it "should do a lot of things" do >> ? ? ?expensive.should be_foo >> ? ? ?expensive.should be_bar >> ? ? ?expensive.should be_baz >> ? ?end >> ?end >> end >> ====== >> >> I would like to refactor the large spec into smaller ones: >> >> ====== >> ? ?it "should be foo" { expensive.should be_foo } >> ? ?it "should be bar" { expensive.should be_bar } >> ? ?it "should be baz" { expensive.should be_baz } >> ====== >> >> However, doing this slows down the tests a bit, because the >> `expensive` method requires hitting the database. >> >> Suppose that I can guarantee that none of the tests or the methods >> they call will be modifying the object returned by the `expensive` >> method. Is there a way to tell RSpec to memoize the `expensive` result >> across the context, and not just across an individual test run? >> >> Alternatively, should I just use before(:all) for this? > > Just use before(:all). That's what it is designed for, and it tells you that you have stuff to clean up in an after(:all) hook. From dchelimsky at gmail.com Fri Jun 24 09:15:16 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Jun 2011 08:15:16 -0500 Subject: [rspec-users] Is there a way to run `let` once per context? In-Reply-To: References: Message-ID: <00A4022D-910A-4C09-A34D-04B9FF7BC257@gmail.com> On Jun 24, 2011, at 8:08 AM, John Feminella wrote: >>> Alternatively, should I just use before(:all) for this? >> >> Just use before(:all). That's what it is designed for, and it tells you that you have stuff to clean up in an after(:all) hook. > > I was about to take your advice, when I discovered another problem: > > ====== > RSpec.configure do |config| > config.mock_with :rspec > > config.before(:each, :geocoding => nil) do > Geocoding.stub(:client).and_return(Geocoding::StubGeoClient.new) > end > end > ====== > > Since the test-specific before-all hook runs first before the global > before-each hook, that means that the `expensive` operation now hits > an external geocoding service, which makes it take even longer. It > also makes tests fail because WebMock is running, and it prohibits > network connections you don't explicitly specify. You can resolve this using a shared group: http://relishapp.com/rspec/rspec-core/v/2-6/dir/example-groups/shared-examples http://relishapp.com/rspec/rspec-core/v/2-6/dir/example-groups/shared-context > > The fact that this is becoming obnoxious suggests that something else > is probably bad (e.g. maybe the `expensive` model should be changed to > be less expensive to create). That's definitely worth investigating :) > I think I'll do that instead of trying > to go down this road further. Thanks for your help, David. y/w Cheers, David > > ~ jf > > On Fri, Jun 24, 2011 at 08:48, David Chelimsky wrote: >> >> On Jun 24, 2011, at 7:17 AM, John Feminella wrote: >> >>> hello, >>> >>> I have a monolithic test that looks like this: >>> >>> ====== >>> describe Model do >>> describe "#method" do >>> let!(:expensive) { ... } >>> >>> it "should do a lot of things" do >>> expensive.should be_foo >>> expensive.should be_bar >>> expensive.should be_baz >>> end >>> end >>> end >>> ====== >>> >>> I would like to refactor the large spec into smaller ones: >>> >>> ====== >>> it "should be foo" { expensive.should be_foo } >>> it "should be bar" { expensive.should be_bar } >>> it "should be baz" { expensive.should be_baz } >>> ====== >>> >>> However, doing this slows down the tests a bit, because the >>> `expensive` method requires hitting the database. >>> >>> Suppose that I can guarantee that none of the tests or the methods >>> they call will be modifying the object returned by the `expensive` >>> method. Is there a way to tell RSpec to memoize the `expensive` result >>> across the context, and not just across an individual test run? >>> >>> Alternatively, should I just use before(:all) for this? >> >> Just use before(:all). That's what it is designed for, and it tells you that you have stuff to clean up in an after(:all) hook. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From matt at mattwynne.net Fri Jun 24 12:55:07 2011 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 24 Jun 2011 17:55:07 +0100 Subject: [rspec-users] tags and spec_helper Message-ID: <3AD25E8A-35EC-4543-BCE1-09EBF2528D79@mattwynne.net> I've been trying to separate out some fast specs in a Rails app in a Gary Bernhardt style[1], and I experimented with using tags. The problem with using tags is that in order to scan the specs for examples that match the tags, it loads every spec file, most of which require spec_helper, which loads Rails, and so takes 5-6 seconds. Thereby totally defeating the original purpose. One idea I have is to put some if statements into spec_helper to check the tags that were passed to RSpec and only load the rails env if necessary. Is that possible? Has anyone else tried doing anything like this? cheers, Matt matt at mattwynne.net 07974 430184 [1] https://www.destroyallsoftware.com/screencasts/catalog/fast-tests-with-and-without-rails From ivanoats at gmail.com Fri Jun 24 18:21:50 2011 From: ivanoats at gmail.com (ivanoats) Date: Fri, 24 Jun 2011 15:21:50 -0700 (PDT) Subject: [rspec-users] Model Validation fails (correctly) in rails console but not in rspec Message-ID: Hi, I have been really stuck on this problem. My validation for my model fails (like it should) when I'm testing it out in rails console, but my rspec example fails because it validates anyway (which it shouldn't). What am I missing here or where should I start looking? Thanks, Ivan See below: ivan:~/Development/ruby/IvanEnviromanRefinery [git:master+] ? bundle exec rspec ../refinerycms-link/ .............................F. Failures: 1) BlogPost bookmark links must have a link url if it is a link Failure/Error: Factory.build(:post, expected valid? to return false, got true # /Users/ivan/Development/ruby/refinerycms-link/spec/models/ blog_post_spec.rb:197:in `block (3 levels) in ' Finished in 6.56 seconds 31 examples, 1 failure Failed examples: rspec /Users/ivan/Development/ruby/refinerycms-link/spec/models/ blog_post_spec.rb:196 # BlogPost bookmark links must have a link url if it is a link ivan:~/Development/ruby/IvanEnviromanRefinery [git:master+] ? rails console Loading development environment (Rails 3.0.9) ruby-1.9.2-p180 :001 > b = BlogPost.new => # ruby-1.9.2-p180 :002 > b.title=' 2011-06-24 8:34 ' => " 2011-06-24 8:34 " ruby-1.9.2-p180 :003 > b.body='goo' => "goo" ruby-1.9.2-p180 :004 > b.is_link = true => true ruby-1.9.2-p180 :005 > b.valid? => false ruby-1.9.2-p180 :007 > b.save => false ruby-1.9.2-p180 :008 > b.errors => {:link_url=>["must have a link_url if is_link is true"]} ruby-1.9.2-p180 :009 > require 'spec_helper' Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory} describe BlogPost do let(:blog_post ) { Factory :post } ... describe "bookmark links" do it "may have a bookmark link" do Factory.build(:post, :title => "a link", :body => "link text", :is_link => true, :link_url => "http://example.com").should be_valid end it "must have a link url if it is a link" do Factory.build(:post, :title => "a link", :body => "link text", :is_link => true).should_not be_valid end end end From dchelimsky at gmail.com Sat Jun 25 07:06:42 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 25 Jun 2011 06:06:42 -0500 Subject: [rspec-users] Model Validation fails (correctly) in rails console but not in rspec In-Reply-To: References: Message-ID: <1CAFDAB8-2F2A-422D-8A3F-149498ED8CA4@gmail.com> On Jun 24, 2011, at 5:21 PM, ivanoats wrote: > Hi, I have been really stuck on this problem. My validation for my > model fails (like it should) when I'm testing it out in rails console, > but my rspec example fails because it validates anyway (which it > shouldn't). What am I missing here or where should I start looking? > > Thanks, > Ivan > > See below: > > ivan:~/Development/ruby/IvanEnviromanRefinery [git:master+] ? bundle > exec rspec ../refinerycms-link/ > .............................F. > > Failures: > > 1) BlogPost bookmark links must have a link url if it is a link > Failure/Error: Factory.build(:post, > expected valid? to return false, got true > # /Users/ivan/Development/ruby/refinerycms-link/spec/models/ > blog_post_spec.rb:197:in `block (3 levels) in ' > > Finished in 6.56 seconds > 31 examples, 1 failure > > Failed examples: > > rspec /Users/ivan/Development/ruby/refinerycms-link/spec/models/ > blog_post_spec.rb:196 # BlogPost bookmark links must have a link url > if it is a link > ivan:~/Development/ruby/IvanEnviromanRefinery [git:master+] ? rails > console > Loading development environment (Rails 3.0.9) > ruby-1.9.2-p180 :001 > b = BlogPost.new > => # published_at: nil, created_at: nil, updated_at: nil, user_id: nil, > cached_slug: nil, custom_url: nil, link_url: nil, is_link: nil, > custom_teaser: nil> > ruby-1.9.2-p180 :002 > b.title=' 2011-06-24 8:34 ' > => " 2011-06-24 8:34 " > ruby-1.9.2-p180 :003 > b.body='goo' > => "goo" > ruby-1.9.2-p180 :004 > b.is_link = true > => true > ruby-1.9.2-p180 :005 > b.valid? > => false > ruby-1.9.2-p180 :007 > b.save > => false > ruby-1.9.2-p180 :008 > b.errors > => {:link_url=>["must have a link_url if is_link is true"]} > ruby-1.9.2-p180 :009 > > > require 'spec_helper' > Dir[File.expand_path('../../../features/support/factories/*.rb', > __FILE__)].each{|factory| require factory} > > describe BlogPost do > let(:blog_post ) { Factory :post } > > ... > > describe "bookmark links" do > it "may have a bookmark link" do > Factory.build(:post, > :title => "a link", > :body => "link text", > :is_link => true, > :link_url => "http://example.com").should be_valid > end > it "must have a link url if it is a link" do > Factory.build(:post, > :title => "a link", > :body => "link text", > :is_link => true).should_not be_valid > end > end > end I'm guessing the factory is set up to include a link_url. If so, just set :link_url => nil in the second example. If not, I have no idea. HTH, David From dchelimsky at gmail.com Sat Jun 25 09:57:33 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 25 Jun 2011 08:57:33 -0500 Subject: [rspec-users] tags and spec_helper In-Reply-To: <3AD25E8A-35EC-4543-BCE1-09EBF2528D79@mattwynne.net> References: <3AD25E8A-35EC-4543-BCE1-09EBF2528D79@mattwynne.net> Message-ID: On Jun 24, 2011, at 11:55 AM, Matt Wynne wrote: > I've been trying to separate out some fast specs in a Rails app in a Gary Bernhardt style[1], and I experimented with using tags. > > The problem with using tags is that in order to scan the specs for examples that match the tags, it loads every spec file, most of which require spec_helper, which loads Rails, and so takes 5-6 seconds. Thereby totally defeating the original purpose. > > One idea I have is to put some if statements into spec_helper to check the tags that were passed to RSpec and only load the rails env if necessary. Is that possible? What I'm about to tell you is used internally, is not a formal API, and is subject to change without notice. That said, for the moment, you can do this: if !RSpec.configuration.inclusion_filter[:no_rails] # ... load rails end rspec spec --tag no_rails I created https://github.com/rspec/rspec-core/issues/416 to address formalizing an API for this. Comments/suggestions/patches welcome. Cheers, David > Has anyone else tried doing anything like this? > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > [1] https://www.destroyallsoftware.com/screencasts/catalog/fast-tests-with-and-without-rails From dchelimsky at gmail.com Mon Jun 27 06:50:57 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 27 Jun 2011 05:50:57 -0500 Subject: [rspec-users] how to mock/stub when there are multiple model objects? In-Reply-To: References: Message-ID: <87C0DDC2-4507-4856-9834-0449546B58D0@gmail.com> On Jun 23, 2011, at 3:55 PM, S Ahmed wrote: > Thanks. > > I'm trying this now on a Model that is using Mongoid. > > I have tried: > > it "should ..." do > > User.stub(:some_call).and_return(User.new(:name => "blah")) > > end > > And when running spec on this file I get: > > NoMethodError, undefined method "stub" for User:Class > > I also tried: > > User.stub!(:some_call).... > > Does this not work on mongoid objects? It should work on any object (class objects and instance objects), so it sounds like there is a configuration problem. What's in your Gemfile? > > On Fri, Jun 17, 2011 at 7:39 PM, Patrick J. Collins wrote: > > but what if my method looks like: > > > > user = User.where("...") > > user2 = User.where("...") > User.should_receive(:where).with("...").and_return(...) > http://apidock.com/rspec/Spec/Mocks > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From mguterl at gmail.com Mon Jun 27 19:07:55 2011 From: mguterl at gmail.com (Michael Guterl) Date: Mon, 27 Jun 2011 19:07:55 -0400 Subject: [rspec-users] Time out long running tests using Rspec 2 In-Reply-To: References: Message-ID: On Tue, Jun 21, 2011 at 8:13 AM, Sidu Ponnappa wrote: > I'm cross posting a query on timing out tests that came up on our local ruby > list: > >> In RSpec1, there was an option "timeout" using which we can fail all >> the long running tests i.e. "spec --timeout 2 spec/" will fail those >> tests which takes more than 2 seconds to run. It does not seem to be >> existing in RSpec2. I saw the "filter_run" option as mentioned here: >> http://blog.davidchelimsky.net/2010/06/14/filtering-examples-in-rspec-2/. >> Using this I can add "slow" tags to tests. But it is not same as the >> "timeout" option. Can someone let me know whats the better approach to >> time out slow running tests? > > Any suggestions would be appreciated. What about an around_filter? require 'timeout' RSpec.configure do |c| c.around(:each) do |example| Timeout::timeout(2) { example.run } end end http://relishapp.com/rspec/rspec-core/v/2-0/dir/hooks/around-hooks From sahmed1020 at gmail.com Wed Jun 29 13:21:07 2011 From: sahmed1020 at gmail.com (S Ahmed) Date: Wed, 29 Jun 2011 13:21:07 -0400 Subject: [rspec-users] "user" received unexpected message :created_at with (no args) Message-ID: My method looks like: def self.can_do_this(user) return false if user.nil? ( (Time.now >= user.created_at) ? true : false ) end my spec: it "should allow you to do this" do user = stub("user") user.stub(:nil?).and_return(false) user.stub(:created_at).and_return(Time.now) res = User.can_do_this(user) res.should == true end Running the spec I get: Failer/Error: res = User.can_do_this(user) Stub "user" received unexpected message :created_at with (no args) Any ideas? Thanks allot for the help! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Jun 29 14:20:48 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Jun 2011 13:20:48 -0500 Subject: [rspec-users] "user" received unexpected message :created_at with (no args) In-Reply-To: References: Message-ID: <3AAEAF22-25B1-445A-B7B5-98226481672B@gmail.com> On Jun 29, 2011, at 12:21 PM, S Ahmed wrote: > My method looks like: > > def self.can_do_this(user) > return false if user.nil? > ( (Time.now >= user.created_at) ? true : false ) > end > > my spec: > > it "should allow you to do this" do > user = stub("user") > user.stub(:nil?).and_return(false) > user.stub(:created_at).and_return(Time.now) > > res = User.can_do_this(user) > res.should == true > end > > Running the spec I get: > > Failer/Error: res = User.can_do_this(user) > Stub "user" received unexpected message :created_at with (no args) > > Any ideas? I copied what you have as/is and added the User class and example group declarations: class User def self.can_do_this(user) return false if user.nil? ( (Time.now >= user.created_at) ? true : false ) end end describe User do it "should allow you to do this" do user = stub("user") user.stub(:nil?).and_return(false) user.stub(:created_at).and_return(Time.now) res = User.can_do_this(user) res.should == true end end This passes, so either something is different about our environments or there is more going on than you are showing us. Please copy what I wrote above into its own file and run it and let us know if it passes or fails. Off topic, some recommendations about the Ruby in your example: 1. user.stub(:nil?).and_return(false) is unnecessary. It is an object and it will return false to nil?. 2. you can declare a method stub in the declaration of the stub object: user = stub("user", :created_at => Time.now) 3. Asking an object if it is nil is unnecessary noise AND an unnecessary method call. This would be more terse and faster (as the evaluation happens in C in MRI, Java in JRuby, etc): return false unless user 4. A ternary that returns true or false is redundant. These two expressions are functionally equivalent: (Time.now >= user.created_at) ? true : false Time.now >= user.created_at 5. Given #3 and #4, the implementation of can_do_this can be reduced to: user && Time.now >= user.created_at With those recommendations, the whole example can be reduced to: class User def self.can_do_this(user) user && Time.now >= user.created_at end end describe User do it "should allow you to do this" do user = stub("user", :created_at => Time.now) User.can_do_this(user).should be_true end end We could talk about can_do_this wanting a "?" at the end, but my suspicion is that is not the real example you are working from. HTH, David From sahmed1020 at gmail.com Wed Jun 29 15:07:09 2011 From: sahmed1020 at gmail.com (S Ahmed) Date: Wed, 29 Jun 2011 15:07:09 -0400 Subject: [rspec-users] "user" received unexpected message :created_at with (no args) In-Reply-To: <3AAEAF22-25B1-445A-B7B5-98226481672B@gmail.com> References: <3AAEAF22-25B1-445A-B7B5-98226481672B@gmail.com> Message-ID: Your code worked, let me try and figure out why mine isn't working.... Your right it isn't exactly what I have, but pretty much everything is identical except for the naming of the model. On Wed, Jun 29, 2011 at 2:20 PM, David Chelimsky wrote: > On Jun 29, 2011, at 12:21 PM, S Ahmed wrote: > > > My method looks like: > > > > def self.can_do_this(user) > > return false if user.nil? > > ( (Time.now >= user.created_at) ? true : false ) > > end > > > > my spec: > > > > it "should allow you to do this" do > > user = stub("user") > > user.stub(:nil?).and_return(false) > > user.stub(:created_at).and_return(Time.now) > > > > res = User.can_do_this(user) > > res.should == true > > end > > > > Running the spec I get: > > > > Failer/Error: res = User.can_do_this(user) > > Stub "user" received unexpected message :created_at with (no args) > > > > Any ideas? > > I copied what you have as/is and added the User class and example group > declarations: > > class User > def self.can_do_this(user) > return false if user.nil? > ( (Time.now >= user.created_at) ? true : false ) > end > end > > describe User do > it "should allow you to do this" do > user = stub("user") > user.stub(:nil?).and_return(false) > user.stub(:created_at).and_return(Time.now) > > res = User.can_do_this(user) > res.should == true > end > end > > This passes, so either something is different about our environments or > there is more going on than you are showing us. Please copy what I wrote > above into its own file and run it and let us know if it passes or fails. > > Off topic, some recommendations about the Ruby in your example: > > 1. user.stub(:nil?).and_return(false) is unnecessary. It is an object and > it will return false to nil?. > 2. you can declare a method stub in the declaration of the stub object: > > user = stub("user", :created_at => Time.now) > > 3. Asking an object if it is nil is unnecessary noise AND an unnecessary > method call. This would be more terse and faster (as the evaluation happens > in C in MRI, Java in JRuby, etc): > > return false unless user > > 4. A ternary that returns true or false is redundant. These two expressions > are functionally equivalent: > > (Time.now >= user.created_at) ? true : false > Time.now >= user.created_at > > 5. Given #3 and #4, the implementation of can_do_this can be reduced to: > > user && Time.now >= user.created_at > > With those recommendations, the whole example can be reduced to: > > class User > def self.can_do_this(user) > user && Time.now >= user.created_at > end > end > > describe User do > it "should allow you to do this" do > user = stub("user", :created_at => Time.now) > User.can_do_this(user).should be_true > end > end > > We could talk about can_do_this wanting a "?" at the end, but my suspicion > is that is not the real example you are working from. > > HTH, > 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 sahmed1020 at gmail.com Wed Jun 29 15:19:38 2011 From: sahmed1020 at gmail.com (S Ahmed) Date: Wed, 29 Jun 2011 15:19:38 -0400 Subject: [rspec-users] "user" received unexpected message :created_at with (no args) In-Reply-To: References: <3AAEAF22-25B1-445A-B7B5-98226481672B@gmail.com> Message-ID: Ok I got it working, and honestly I have no idea why it is working. There was a test below it which I modified (I had updated_at instead of created_at). I ALMOST feel as if the file was cached and not looking at the right file, but not sure if that is even possible. On Wed, Jun 29, 2011 at 3:07 PM, S Ahmed wrote: > Your code worked, let me try and figure out why mine isn't working.... > > Your right it isn't exactly what I have, but pretty much everything is > identical except for the naming of the model. > > > On Wed, Jun 29, 2011 at 2:20 PM, David Chelimsky wrote: > >> On Jun 29, 2011, at 12:21 PM, S Ahmed wrote: >> >> > My method looks like: >> > >> > def self.can_do_this(user) >> > return false if user.nil? >> > ( (Time.now >= user.created_at) ? true : false ) >> > end >> > >> > my spec: >> > >> > it "should allow you to do this" do >> > user = stub("user") >> > user.stub(:nil?).and_return(false) >> > user.stub(:created_at).and_return(Time.now) >> > >> > res = User.can_do_this(user) >> > res.should == true >> > end >> > >> > Running the spec I get: >> > >> > Failer/Error: res = User.can_do_this(user) >> > Stub "user" received unexpected message :created_at with (no args) >> > >> > Any ideas? >> >> I copied what you have as/is and added the User class and example group >> declarations: >> >> class User >> def self.can_do_this(user) >> return false if user.nil? >> ( (Time.now >= user.created_at) ? true : false ) >> end >> end >> >> describe User do >> it "should allow you to do this" do >> user = stub("user") >> user.stub(:nil?).and_return(false) >> user.stub(:created_at).and_return(Time.now) >> >> res = User.can_do_this(user) >> res.should == true >> end >> end >> >> This passes, so either something is different about our environments or >> there is more going on than you are showing us. Please copy what I wrote >> above into its own file and run it and let us know if it passes or fails. >> >> Off topic, some recommendations about the Ruby in your example: >> >> 1. user.stub(:nil?).and_return(false) is unnecessary. It is an object and >> it will return false to nil?. >> 2. you can declare a method stub in the declaration of the stub object: >> >> user = stub("user", :created_at => Time.now) >> >> 3. Asking an object if it is nil is unnecessary noise AND an unnecessary >> method call. This would be more terse and faster (as the evaluation happens >> in C in MRI, Java in JRuby, etc): >> >> return false unless user >> >> 4. A ternary that returns true or false is redundant. These two >> expressions are functionally equivalent: >> >> (Time.now >= user.created_at) ? true : false >> Time.now >= user.created_at >> >> 5. Given #3 and #4, the implementation of can_do_this can be reduced to: >> >> user && Time.now >= user.created_at >> >> With those recommendations, the whole example can be reduced to: >> >> class User >> def self.can_do_this(user) >> user && Time.now >= user.created_at >> end >> end >> >> describe User do >> it "should allow you to do this" do >> user = stub("user", :created_at => Time.now) >> User.can_do_this(user).should be_true >> end >> end >> >> We could talk about can_do_this wanting a "?" at the end, but my suspicion >> is that is not the real example you are working from. >> >> HTH, >> 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 sahmed1020 at gmail.com Wed Jun 29 15:20:20 2011 From: sahmed1020 at gmail.com (S Ahmed) Date: Wed, 29 Jun 2011 15:20:20 -0400 Subject: [rspec-users] "user" received unexpected message :created_at with (no args) In-Reply-To: References: <3AAEAF22-25B1-445A-B7B5-98226481672B@gmail.com> Message-ID: Oh and I am grateful for your refactoring and explanations, simplies my code and tests (and understanding!) On Wed, Jun 29, 2011 at 3:19 PM, S Ahmed wrote: > Ok I got it working, and honestly I have no idea why it is working. > > There was a test below it which I modified (I had updated_at instead of > created_at). > > I ALMOST feel as if the file was cached and not looking at the right file, > but not sure if that is even possible. > > > On Wed, Jun 29, 2011 at 3:07 PM, S Ahmed wrote: > >> Your code worked, let me try and figure out why mine isn't working.... >> >> Your right it isn't exactly what I have, but pretty much everything is >> identical except for the naming of the model. >> >> >> On Wed, Jun 29, 2011 at 2:20 PM, David Chelimsky wrote: >> >>> On Jun 29, 2011, at 12:21 PM, S Ahmed wrote: >>> >>> > My method looks like: >>> > >>> > def self.can_do_this(user) >>> > return false if user.nil? >>> > ( (Time.now >= user.created_at) ? true : false ) >>> > end >>> > >>> > my spec: >>> > >>> > it "should allow you to do this" do >>> > user = stub("user") >>> > user.stub(:nil?).and_return(false) >>> > user.stub(:created_at).and_return(Time.now) >>> > >>> > res = User.can_do_this(user) >>> > res.should == true >>> > end >>> > >>> > Running the spec I get: >>> > >>> > Failer/Error: res = User.can_do_this(user) >>> > Stub "user" received unexpected message :created_at with (no args) >>> > >>> > Any ideas? >>> >>> I copied what you have as/is and added the User class and example group >>> declarations: >>> >>> class User >>> def self.can_do_this(user) >>> return false if user.nil? >>> ( (Time.now >= user.created_at) ? true : false ) >>> end >>> end >>> >>> describe User do >>> it "should allow you to do this" do >>> user = stub("user") >>> user.stub(:nil?).and_return(false) >>> user.stub(:created_at).and_return(Time.now) >>> >>> res = User.can_do_this(user) >>> res.should == true >>> end >>> end >>> >>> This passes, so either something is different about our environments or >>> there is more going on than you are showing us. Please copy what I wrote >>> above into its own file and run it and let us know if it passes or fails. >>> >>> Off topic, some recommendations about the Ruby in your example: >>> >>> 1. user.stub(:nil?).and_return(false) is unnecessary. It is an object and >>> it will return false to nil?. >>> 2. you can declare a method stub in the declaration of the stub object: >>> >>> user = stub("user", :created_at => Time.now) >>> >>> 3. Asking an object if it is nil is unnecessary noise AND an unnecessary >>> method call. This would be more terse and faster (as the evaluation happens >>> in C in MRI, Java in JRuby, etc): >>> >>> return false unless user >>> >>> 4. A ternary that returns true or false is redundant. These two >>> expressions are functionally equivalent: >>> >>> (Time.now >= user.created_at) ? true : false >>> Time.now >= user.created_at >>> >>> 5. Given #3 and #4, the implementation of can_do_this can be reduced to: >>> >>> user && Time.now >= user.created_at >>> >>> With those recommendations, the whole example can be reduced to: >>> >>> class User >>> def self.can_do_this(user) >>> user && Time.now >= user.created_at >>> end >>> end >>> >>> describe User do >>> it "should allow you to do this" do >>> user = stub("user", :created_at => Time.now) >>> User.can_do_this(user).should be_true >>> end >>> end >>> >>> We could talk about can_do_this wanting a "?" at the end, but my >>> suspicion is that is not the real example you are working from. >>> >>> HTH, >>> 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 alex.katebi at gmail.com Thu Jun 30 19:29:52 2011 From: alex.katebi at gmail.com (Alex Katebi) Date: Thu, 30 Jun 2011 16:29:52 -0700 (PDT) Subject: [rspec-users] Collection membership Error Message-ID: <636275ae-3cf9-4861-9323-01746dd43e8d@r2g2000vbj.googlegroups.com> Using rspec version 2.6.4 I get an error with the Collection membership. Example: [1,2].should include(1) TypeError: wrong argument type Fixnum (expected Module) from (irb):1:in `include' from (irb):1 from /home/akatebi/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `
' RubyGems Environment: - RUBYGEMS VERSION: 1.6.2 - RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [i686-linux] - INSTALLATION DIRECTORY: /home/akatebi/.rvm/gems/ruby-1.9.2- p180 at endpoints - RUBY EXECUTABLE: /home/akatebi/.rvm/rubies/ruby-1.9.2-p180/bin/ ruby - EXECUTABLE DIRECTORY: /home/akatebi/.rvm/gems/ruby-1.9.2- p180 at endpoints/bin - RUBYGEMS PLATFORMS: - ruby - x86-linux - GEM PATHS: - /home/akatebi/.rvm/gems/ruby-1.9.2-p180 at endpoints - /home/akatebi/.rvm/gems/ruby-1.9.2-p180 at global - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://rubygems.org/