From bradleyrobertson at gmail.com Mon Apr 2 02:34:00 2012 From: bradleyrobertson at gmail.com (Bradley) Date: Sun, 1 Apr 2012 19:34:00 -0700 (PDT) Subject: [rspec-users] using shared_context in a global way Message-ID: <29497769.663.1333334040247.JavaMail.geo-discussion-forums@vbyj26> I have some let and before declarations that I want to define for all of my tests. I can't seem to figure out how to do this in a clean way (ie by including a module in my Rspec config). I don't want to have to include_context for each test, I just want to run some before(:all) hooks and provide access to some default variables that example groups could override with their own let declarations. I must be missing something because I can't find anywhere in the docs how I might achieve this. Any help is greatly appreciated. Brad -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Apr 2 11:30:57 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 2 Apr 2012 08:30:57 -0300 Subject: [rspec-users] using shared_context in a global way In-Reply-To: <29497769.663.1333334040247.JavaMail.geo-discussion-forums@vbyj26> References: <29497769.663.1333334040247.JavaMail.geo-discussion-forums@vbyj26> Message-ID: On Sun, Apr 1, 2012 at 11:34 PM, Bradley wrote: > I have some let?and before declarations that I want to define for all of my > tests. ?I can't seem to figure out how to do this in a clean way (ie by > including a module in my Rspec config). ?I don't want to have to > include_context for each test, I just want to run some before(:all) hooks > and provide access to some default variables that example groups could > override with their own let?declarations. > > I must be missing something because I can't find anywhere in the docs how I > might achieve this. ?Any help is greatly appreciated. There is a documented way to declare a module with let and before declarations: http://rubydoc.info/gems/rspec-core/RSpec/Core/SharedContext. There is also a documented way to include a module in every ExampleGroup: http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration#include-instance_method There is, admittedly, no doc that says you can use these two features together. Obviously we can't do that for every pair of features, but perhaps this pair is worth citing specifically. I'll look into doing that for the next release. Cheers, David From zach.dennis at gmail.com Tue Apr 3 00:44:55 2012 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 2 Apr 2012 20:44:55 -0400 Subject: [rspec-users] [OT] Using Git / Pivotal Tracker? Want improved open source tooling around the two? Message-ID: We're taking a survey for Git / Pivotal Tracker integration related to open source tooling. There's been a certain pain point in the tools that are out there or that lack integration (or flexibility to easily add integration). If you're using both would you be kind enough to check out this survey? https://docs.google.com/a/mutuallyhuman.com/spreadsheet/viewform?formkey=dF83bzVYTm1oSmxyNUd4U01KR20wNmc6MQ Thanks, -- @zachdennis http://www.continuousthinking.com http://www.mutuallyhuman.com From dchelimsky at gmail.com Tue Apr 3 19:21:15 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 3 Apr 2012 16:21:15 -0300 Subject: [rspec-users] rspec-expectations-2.9.1 is released! Message-ID: <6582B5C0-297E-42F2-914E-44F57EDB0643@gmail.com> rspec-expectations-2.9.1 is released! This is a bug-fix only release, and is recommended for everybody using rspec-2.9. ### rspec-expectations-2.9.1 / 2012-04-03 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.9.0...2.9.1) Bug fixes * Provide a helpful message if the diff between two objects is empty. * Fix bug diffing single strings with multiline strings. * Fix for error with using custom matchers inside other custom matchers (mirasrael) * Fix using execution context methods in nested DSL matchers (mirasrael) -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Apr 4 10:47:58 2012 From: lists at ruby-forum.com (Lunarose A.) Date: Wed, 04 Apr 2012 12:47:58 +0200 Subject: [rspec-users] The test is failing Whyy? Message-ID: <2ce31be3f95d467a2f22acb518c8c01c@ruby-forum.com> I am actually a newbie in Ruby rails nd Rspec.. So it could be something basic.. Plz helpp This is my rspec test code:: describe "GET new" do it "assigns a new kase as @kase" do get :new assigns(:kase).should be_a_new(Kase) end end Its failing saying: KasesController GET new assigns a new kase as @kase Failure/Error: assigns(:kase).should be_a_new(Kase) expected nil to be a new Kase(id: integer, name: string, description: text, item_loc_id: integer, created_at: datetime, updated_at: datetime, previous_visit_id_cache: integer) # ./spec/controllers/kases_controller_spec.rb:37 -- Posted via http://www.ruby-forum.com/. From cifani.thiago at gmail.com Wed Apr 4 11:44:38 2012 From: cifani.thiago at gmail.com (thiagocifani) Date: Wed, 4 Apr 2012 08:44:38 -0300 Subject: [rspec-users] The test is failing Whyy? In-Reply-To: <2ce31be3f95d467a2f22acb518c8c01c@ruby-forum.com> References: <2ce31be3f95d467a2f22acb518c8c01c@ruby-forum.com> Message-ID: I think that maybe you are declaring your :kase in somewhere, but this assigns need to receive a new object, you could try pass Kase.new instead of :kase. regards 2012/4/4 Lunarose A. > I am actually a newbie in Ruby rails nd Rspec.. So it could be something > basic.. Plz helpp > > > This is my rspec test code:: > > describe "GET new" do > it "assigns a new kase as @kase" do > get :new > assigns(:kase).should be_a_new(Kase) > end > end > > > Its failing saying: > > KasesController GET new assigns a new kase as @kase > Failure/Error: assigns(:kase).should be_a_new(Kase) > expected nil to be a new Kase(id: integer, name: string, > description: text, item_loc_id: integer, created_at: datetime, > updated_at: datetime, previous_visit_id_cache: integer) > # ./spec/controllers/kases_controller_spec.rb:37 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- thiagocifani http://thiagocifani.wordpress.com/ twitter.com/thiagocifani del.icio.us/thiagocifani -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Apr 4 12:58:29 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Apr 2012 09:58:29 -0300 Subject: [rspec-users] The test is failing Whyy? In-Reply-To: <2ce31be3f95d467a2f22acb518c8c01c@ruby-forum.com> References: <2ce31be3f95d467a2f22acb518c8c01c@ruby-forum.com> Message-ID: On Wed, Apr 4, 2012 at 7:47 AM, Lunarose A. wrote: > I am actually a newbie in Ruby rails nd Rspec.. So it could be something > basic.. Plz helpp > > > This is my rspec test code:: > > ?describe "GET new" do > ? ?it "assigns a new kase as @kase" do > ? ? ?get :new > ? ? ?assigns(:kase).should be_a_new(Kase) > ? ?end > ?end > > Its failing saying: > > ? KasesController GET new assigns a new kase as @kase > ? ? Failure/Error: assigns(:kase).should be_a_new(Kase) > ? ? ? expected nil to be a new Kase(id: integer, name: string, > description: text, item_loc_id: integer, created_at: datetime, > updated_at: datetime, previous_visit_id_cache: integer) > ? ? # ./spec/controllers/kases_controller_spec.rb:37 This looks like the controller spec generated when you run `rails generate scaffold ...`. If so, did it fail immediately after generating it? Or did you change something in the controller since you generated it? Would you please post the controller code (at least the :new action)? From lists at ruby-forum.com Wed Apr 4 20:32:28 2012 From: lists at ruby-forum.com (Brad Symons) Date: Wed, 04 Apr 2012 22:32:28 +0200 Subject: [rspec-users] Strange error when running bundle exec rspec spec Message-ID: Hi I have been following the online rails tutorial written by Micheal Hartl, can be found here: http://ruby.railstutorial.org/chapters/beginning#top As I have been going through the chapters, at first the rspec tests were running completely fine. One of the chapters suggests installing blueprint stylesheet, which I did. Somewhere after that, when I write rspec tests and run bundle exec rspec spec, it all broke. The followiung error is displaying in the stack trace, but I have no idea why its pointing to the cucumber steps, and an undefined method 'When'. Im completely lost with this. Any help very much appreciated. I have installed the cucumber gem, and tried a few other things, but as of now, I have no ability to run rspec. :( C:/Users/brad/rails_projects/hartl_tutorial/sample_app/app/assets/stylesheets/joshuaclayton-blueprint-css-9bf9513/features/step_definitions/blueprint_steps.rb:1:in `': undefined method `When' for main:Object (NoMethodError) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:225:in `load_dependency' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:348:in `require_or_load' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:302:in `depend_on' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:214:in `require_dependency' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:417:in `block (2 levels) in eager_load!' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:416:in `each' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:416:in `block in eager_load!' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:414:in `each' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:414:in `eager_load!' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/application/finisher.rb:51:in `block in ' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `instance_exec' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `run' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:55:in `block in run_initializers' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `each' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `run_initializers' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/application.rb:96:in `initialize!' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/railtie/configurable.rb:30:in `method_missing' from C:/Users/brad/rails_projects/hartl_tutorial/sample_app/config/environment.rb:5:in `' from C:/Users/brad/rails_projects/hartl_tutorial/sample_app/spec/spec_helper.rb:3:in `require' from C:/Users/brad/rails_projects/hartl_tutorial/sample_app/spec/spec_helper.rb:3:in `' from C:/Users/brad/rails_projects/hartl_tutorial/sample_app/spec/controllers/pages_controller_spec.rb:1:in `require' from C:/Users/brad/rails_projects/hartl_tutorial/sample_app/spec/controllers/pages_controller_spec.rb:1:in `' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `block in load_spec_files' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `map' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load_spec_files' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:18:in `run' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in `run' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:11:in `block in autorun' C:\Users\brad\rails_projects\hartl_tutorial\sample_app> -- Posted via http://www.ruby-forum.com/. From cnk at ugcs.caltech.edu Wed Apr 4 20:41:46 2012 From: cnk at ugcs.caltech.edu (Cynthia Kiser) Date: Wed, 4 Apr 2012 13:41:46 -0700 Subject: [rspec-users] Strange error when running bundle exec rspec spec In-Reply-To: References: Message-ID: <20120404204146.GA28945@ugcs.caltech.edu> Quoting Brad Symons : > As I have been going through the chapters, at first the rspec tests were > running completely fine. One of the chapters suggests installing > blueprint stylesheet, which I did. > > Somewhere after that, when I write rspec tests and run bundle exec rspec > spec, it all broke. > > The followiung error is displaying in the stack trace, but I have no > idea why its pointing to the cucumber steps, and an undefined method > 'When'. Is the error below happening when you run the rake task or try to run individual specs? e.g. when you run 'rake spec'? or when you run 'spec spec/controllers/some_controller_spec.rb' And why is that path so odd? How did you get feature files INSIDE the app/assets directory? I don't think that is where they belong so I would move them back to C:/Users/brad/rails_projects/hartl_tutorial/sample_app/features/... Or delete them if you still have the original copies of them in the normal place. > C:/Users/brad/rails_projects/hartl_tutorial/sample_app/app/assets/stylesheets/joshuaclayton-blueprint-css-9bf9513/features/step_definitions/blueprint_steps.rb:1:in > `': undefined method `When' for main:Object -- Cynthia N. Kiser cnk at ugcs.caltech.edu From lists at ruby-forum.com Wed Apr 4 22:02:05 2012 From: lists at ruby-forum.com (Brad Symons) Date: Thu, 05 Apr 2012 00:02:05 +0200 Subject: [rspec-users] Simple code dosn't work In-Reply-To: References: Message-ID: I think you have a syntactical error on the line thats throwing the error, you state: > j.even?should be true #throws an error on j == 2, j == 4 should this line not read as: j.even?.should be true -- Posted via http://www.ruby-forum.com/. From curtis at ram9.cc Thu Apr 5 01:50:21 2012 From: curtis at ram9.cc (Curtis Schofield) Date: Wed, 4 Apr 2012 18:50:21 -0700 Subject: [rspec-users] Simple code dosn't work In-Reply-To: References: Message-ID: <34862B8F-B460-4E8E-9C86-40FED7EF9F24@ram9.cc> -- Curtis J Schofield BlazingCloud.net "Creativity can solve anything" - George Lois (source: art & copy) On Apr 4, 2012, at 3:02 PM, Brad Symons wrote: > I think you have a syntactical error on the line thats throwing the > error, you state: > >> j.even?should be true #throws an error on j == 2, j == 4 > > should this line not read as: > > j.even?.should be true It is this : non? > j.even?.should be_true > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From julian at leviston.net Thu Apr 5 01:24:06 2012 From: julian at leviston.net (Julian Leviston) Date: Thu, 5 Apr 2012 11:24:06 +1000 Subject: [rspec-users] Simple code dosn't work In-Reply-To: References: Message-ID: <59315168-7B6F-4E32-A9A1-60D6BA37A86E@leviston.net> On 05/04/2012, at 8:02 AM, Brad Symons wrote: > I think you have a syntactical error on the line thats throwing the > error, you state: > >> j.even?should be true #throws an error on j == 2, j == 4 > > should this line not read as: > > j.even?.should be true lol j.even?.should be_true you mean? From tejasuresh at gmail.com Fri Apr 6 03:43:39 2012 From: tejasuresh at gmail.com (Suresh Babu Madineni) Date: Fri, 6 Apr 2012 09:13:39 +0530 Subject: [rspec-users] Rspec - gem_original_require': no such file to load -- rhom/rhom_db_adapter Message-ID: Hello, Iam trying to use Rspec to test helper methods in my project. When i run the rspec command on my file, the following error note is displayed. C:/RhoStudio/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in *`gem_original_require': no such file to load -- rhom/rhom_db_adapter (LoadError) * from C:/RhoStudio/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from ../MYDIR/MYFILE.rb:1 from C:/RhoStudio/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from C:/RhoStudio/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from E:/Work/Rhodes/Demo/app/test/dbconnector_spec.rb:10 from C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load' from C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files' from C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map' from C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files' from C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run' from C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run' from C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10 from C:/RhoStudio/ruby/bin/rspec:19 The loading problem is displayed only when the file is called using Rspec. When i run my project in Rho Studio, it works fine and the file produces desired results. Unfortunately, iam not able to test my file as RSpec fails to load the rhom/rhom_db_adapter I have installed Rhodes, Rho Studio, Rspec(2.9.0) & Ruby 1.8.7 Is there any specific thing i should take care while using Rhom APIs with Rspec. Any pointers, how i can overcome this error scenario? Thanks, Suresh. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jamescway at gmail.com Thu Apr 5 23:56:03 2012 From: jamescway at gmail.com (James) Date: Thu, 5 Apr 2012 16:56:03 -0700 (PDT) Subject: [rspec-users] Stub conflict? Message-ID: <95fc3263-5295-46fc-8eed-efd0889b358d@to5g2000pbc.googlegroups.com> Hi, I have two stubs in two different specs (one model, one controller). For some reason they are causing some strange conflict with one another. If I comment out the controller stub, the model spec passes. Controller Spec ----------------------------------- require 'spec_helper' describe MyClass::SomeController do it 'should do stuff' do Some::Base.stub!(:mystub) #IF I COMMENT THIS OUT IT PASSES end end I have this line in another model spec ------------------------------------------------------ Some::Thing.should_receive(:mystub).exactly(4).times.and_return nil 'Thing' is a child class of 'Base'. Here is the error: ---------------------------- Failure/Error: Some::Thing.should_receive(:mystub).exactly(4).times.and_return nil ().mystub(any args) expected: 4 times received: 2 times * rspec (2.9.0) * rspec-core (2.9.0) * rspec-expectations (2.9.0) * rspec-mocks (2.9.0) * rspec-rails (2.9.0) rails (3.0.4) ruby 1.8.7 Thanks in advance! James From jamescway at gmail.com Fri Apr 6 00:03:06 2012 From: jamescway at gmail.com (James) Date: Thu, 5 Apr 2012 17:03:06 -0700 (PDT) Subject: [rspec-users] Stub conflict? Message-ID: <1ac6e34f-f2d2-4a5b-b310-0330349133ff@t2g2000pbg.googlegroups.com> Hi, I have two stubs in two different specs (one model, one controller). For some reason they are causing some strange conflict with one another. If I comment out the controller stub, the model spec passes. Controller Spec ----------------------------------- require 'spec_helper' describe MyClass::SomeController do it 'should do stuff' do Some::Base.stub!(:mystub) #IF I COMMENT THIS OUT IT PASSES end end I have this line in another model spec ------------------------------------------------------ Some::Thing.should_receive(:mystub).exactly(4).times.and_return nil 'Thing' is a child class of 'Base'. Here is the error: ---------------------------- Failure/Error: Some::Thing.should_receive(:mystub).exactly(4).times.and_return nil ().mystub(any args) expected: 4 times received: 2 times * rspec (2.9.0) * rspec-core (2.9.0) * rspec-expectations (2.9.0) * rspec-mocks (2.9.0) * rspec-rails (2.9.0) rails (3.0.4) ruby 1.8.7 Thanks in advance! James From alexch at gmail.com Fri Apr 6 17:38:05 2012 From: alexch at gmail.com (Alex Chaffee) Date: Fri, 6 Apr 2012 10:38:05 -0700 (PDT) Subject: [rspec-users] Database custom formatter In-Reply-To: References: <32548201.647.1318950231695.JavaMail.geo-discussion-forums@vbmh5> Message-ID: <553421.529.1333733885746.JavaMail.geo-discussion-forums@pbcwe9> I'm about to start work on a JSON formatter. (I need it for a project where I'm executing RSpec on a server and shipping it down to a JS/HTML client for http://testfirst.org .) Any advice other than "look at lib/rspec/core/formatters/*.rb" before I start? > -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Fri Apr 6 17:21:40 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 6 Apr 2012 10:21:40 -0700 (PDT) Subject: [rspec-users] i've been in activeadmin hell... Message-ID: I am working on a project that uses active_admin, and I found once building out all of the admin resource files, running rspec causes the following error: /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected /Users/patrick/coding/rails/foobar/app/admin/users.rb to define Users (LoadError) from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:192:in `block in const_missing' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:190:in `each' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:190:in `const_missing' from /Users/patrick/coding/rails/foobar/app/controllers/users/confirmations_controller.rb:1:in `' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:359:in `require_or_load' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:313:in `depend_on' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:225:in `require_dependency' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:438:in `each' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:438:in `block in eager_load!' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:436:in `each' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:436:in `eager_load!' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/application/finisher.rb:53:in `block in ' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `instance_exec' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `run' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:55:in `block in run_initializers' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `each' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `run_initializers' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/application.rb:136:in `initialize!' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in `method_missing' from /Users/patrick/coding/rails/foobar/config/environment.rb:5:in `' from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/patrick/coding/rails/foobar/spec/spec_helper.rb:3:in `' from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/patrick/coding/rails/foobar/spec/controllers/locations_controller_spec.rb:1:in `' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run' from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun' ... Changing the filename app/admin/users.rb to app/admin/wtfs.rb makes this error go away... so--- wtfs indeed! incidentally if you are wondering what is this business with confirmations_controller (in the stack trace), that just inherits from Devise: class Users::ConfirmationsController < Devise::ConfirmationsController end Patrick J. Collins http://collinatorstudios.com From jko170 at gmail.com Fri Apr 6 18:17:06 2012 From: jko170 at gmail.com (Justin Ko) Date: Fri, 6 Apr 2012 12:17:06 -0600 Subject: [rspec-users] Stub conflict? In-Reply-To: <1ac6e34f-f2d2-4a5b-b310-0330349133ff@t2g2000pbg.googlegroups.com> References: <1ac6e34f-f2d2-4a5b-b310-0330349133ff@t2g2000pbg.googlegroups.com> Message-ID: <97D2DB40-3FC7-4300-9DAA-72A981A70BE1@gmail.com> On Apr 5, 2012, at 6:03 PM, James wrote: > Hi, > I have two stubs in two different specs (one model, one controller). > For some reason they are causing some strange conflict with one > another. It's not strange at all. Your child classes will inherit the stubs of the parent class. > If I comment out the controller stub, the model spec passes. > > Controller Spec > ----------------------------------- > require 'spec_helper' > describe MyClass::SomeController do > it 'should do stuff' do > Some::Base.stub!(:mystub) #IF I COMMENT THIS OUT IT PASSES > end > end > > > I have this line in another model spec > ------------------------------------------------------ > Some::Thing.should_receive(:mystub).exactly(4).times.and_return > nil > > > 'Thing' is a child class of 'Base'. > > Here is the error: > ---------------------------- > Failure/Error: > Some::Thing.should_receive(:mystub).exactly(4).times.and_return nil > ().mystub(any args) > expected: 4 times > received: 2 times > > > > * rspec (2.9.0) > * rspec-core (2.9.0) > * rspec-expectations (2.9.0) > * rspec-mocks (2.9.0) > * rspec-rails (2.9.0) > rails (3.0.4) > ruby 1.8.7 > > Thanks in advance! > > James > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From samwgoldman at gmail.com Fri Apr 6 18:15:08 2012 From: samwgoldman at gmail.com (Sam Goldman) Date: Fri, 6 Apr 2012 14:15:08 -0400 Subject: [rspec-users] Database custom formatter In-Reply-To: <553421.529.1333733885746.JavaMail.geo-discussion-forums@pbcwe9> References: <32548201.647.1318950231695.JavaMail.geo-discussion-forums@vbmh5> <553421.529.1333733885746.JavaMail.geo-discussion-forums@pbcwe9> Message-ID: I can add another example, that outputs HTML/JSON from a formatter. https://github.com/zipmark/rspec_api_documentation/blob/master/lib/rspec_api_documentation/api_formatter.rb This formatter works in concert with a DSL built on top of RSpec to output HTTP API documentation based on the test examples. The code for this formatter is split up between a number of classes. Of note are ApiFormatter, ApiDocumentation, Example, and Index. HTH, Sam On Fri, Apr 6, 2012 at 1:38 PM, Alex Chaffee wrote: > I'm about to start work on a JSON formatter. (I need it for a project where > I'm executing RSpec on a server and shipping it down to a JS/HTML client for > http://testfirst.org .) Any advice other than "look at > lib/rspec/core/formatters/*.rb" before I start? > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jko170 at gmail.com Fri Apr 6 18:31:04 2012 From: jko170 at gmail.com (Justin Ko) Date: Fri, 6 Apr 2012 12:31:04 -0600 Subject: [rspec-users] Stub conflict? In-Reply-To: <1ac6e34f-f2d2-4a5b-b310-0330349133ff@t2g2000pbg.googlegroups.com> References: <1ac6e34f-f2d2-4a5b-b310-0330349133ff@t2g2000pbg.googlegroups.com> Message-ID: <8366B9A4-7571-4D98-B24D-B32020F8E216@gmail.com> On Apr 5, 2012, at 6:03 PM, James wrote: > Hi, > I have two stubs in two different specs (one model, one controller). > For some reason they are causing some strange conflict with one > another. > If I comment out the controller stub, the model spec passes. > > Controller Spec > ----------------------------------- > require 'spec_helper' > describe MyClass::SomeController do > it 'should do stuff' do > Some::Base.stub!(:mystub) #IF I COMMENT THIS OUT IT PASSES > end > end > > > I have this line in another model spec > ------------------------------------------------------ Oh, and if you want to keep things the way they are, try add this line right before mocking Some::Thing: Some::Thing.rspec_reset > Some::Thing.should_receive(:mystub).exactly(4).times.and_return > nil > > > 'Thing' is a child class of 'Base'. > > Here is the error: > ---------------------------- > Failure/Error: > Some::Thing.should_receive(:mystub).exactly(4).times.and_return nil > ().mystub(any args) > expected: 4 times > received: 2 times > > > > * rspec (2.9.0) > * rspec-core (2.9.0) > * rspec-expectations (2.9.0) > * rspec-mocks (2.9.0) > * rspec-rails (2.9.0) > rails (3.0.4) > ruby 1.8.7 > > Thanks in advance! > > James > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jko170 at gmail.com Fri Apr 6 18:38:41 2012 From: jko170 at gmail.com (Justin Ko) Date: Fri, 6 Apr 2012 12:38:41 -0600 Subject: [rspec-users] i've been in activeadmin hell... In-Reply-To: References: Message-ID: <47756D2B-2527-4C27-B82B-D97644D4DEFE@gmail.com> On Apr 6, 2012, at 11:21 AM, Patrick J. Collins wrote: > I am working on a project that uses active_admin, and I found once > building out all of the admin resource files, running rspec causes the > following error: > > /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected /Users/patrick/coding/rails/foobar/app/admin/users.rb to define Users (LoadError) > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:192:in `block in const_missing' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:190:in `each' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:190:in `const_missing' > from /Users/patrick/coding/rails/foobar/app/controllers/users/confirmations_controller.rb:1:in `' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:359:in `require_or_load' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:313:in `depend_on' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:225:in `require_dependency' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:438:in `each' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:438:in `block in eager_load!' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:436:in `each' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/engine.rb:436:in `eager_load!' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/application/finisher.rb:53:in `block in ' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `instance_exec' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `run' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:55:in `block in run_initializers' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `each' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `run_initializers' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/application.rb:136:in `initialize!' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in `method_missing' > from /Users/patrick/coding/rails/foobar/config/environment.rb:5:in `' > from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' > from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' > from /Users/patrick/coding/rails/foobar/spec/spec_helper.rb:3:in `' > from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' > from /Users/patrick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' > from /Users/patrick/coding/rails/foobar/spec/controllers/locations_controller_spec.rb:1:in `' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run' > from /Users/patrick/.rvm/gems/ruby-1.9.3-p125 at foobar/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun' > > > ... Changing the filename app/admin/users.rb to app/admin/wtfs.rb > > makes this error go away... so--- wtfs indeed! > > incidentally if you are wondering what is this business with > confirmations_controller (in the stack trace), that just inherits from Devise: > > class Users::ConfirmationsController < Devise::ConfirmationsController > end > > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I'm pretty sure this is an issue with how Rails autoloads things, I've run into it a few times. Checkout this post: http://stackoverflow.com/questions/4074830/adding-lib-to-config-autoload-paths-in-rails-3-does-not-autoload-my-module From patrick at collinatorstudios.com Fri Apr 6 19:40:10 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 6 Apr 2012 12:40:10 -0700 (PDT) Subject: [rspec-users] i've been in activeadmin hell... In-Reply-To: <47756D2B-2527-4C27-B82B-D97644D4DEFE@gmail.com> References: <47756D2B-2527-4C27-B82B-D97644D4DEFE@gmail.com> Message-ID: > On Apr 6, 2012, at 11:21 AM, Patrick J. Collins wrote: > > ... Changing the filename app/admin/users.rb to app/admin/wtfs.rb > > > > makes this error go away... so--- wtfs indeed! On Fri, 6 Apr 2012, Justin Ko wrote: > I'm pretty sure this is an issue with how Rails autoloads things, I've run into it a few times. Checkout this post: Well what doesn't make sense to me, is that I would expect having a file called wtfs.rb should give a similar error expecting "Wtfs" to be defined... But it doesn't.. Patrick J. Collins http://collinatorstudios.com From jko170 at gmail.com Fri Apr 6 19:53:21 2012 From: jko170 at gmail.com (Justin Ko) Date: Fri, 6 Apr 2012 13:53:21 -0600 Subject: [rspec-users] i've been in activeadmin hell... In-Reply-To: References: <47756D2B-2527-4C27-B82B-D97644D4DEFE@gmail.com> Message-ID: <81981A08-27D4-4B75-8C41-478386A77709@gmail.com> On Apr 6, 2012, at 1:40 PM, Patrick J. Collins wrote: >> On Apr 6, 2012, at 11:21 AM, Patrick J. Collins wrote: >>> ... Changing the filename app/admin/users.rb to app/admin/wtfs.rb >>> >>> makes this error go away... so--- wtfs indeed! > > On Fri, 6 Apr 2012, Justin Ko wrote: >> I'm pretty sure this is an issue with how Rails autoloads things, I've run into it a few times. Checkout this post: > > Well what doesn't make sense to me, is that I would expect having a file > called wtfs.rb should give a similar error expecting "Wtfs" to be > defined... But it doesn't.. In Ruby, if you define a namespace class without defining the top-level class first, you'll get an error: 1.9.3p125 :001 > class Foo::Bar; end NameError: uninitialized constant Foo from (irb):1 from /Users/justinko/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `
' So as you can see from your backtrace, the error is generating from confirmations_controller.rb, which makes sense because it has "class Users::ConfirmationsController". If you look further up the backtrace, you'll see activesupport trying to handle that error with its `load_missing_constant` method. I assume it "searched" for a file named "users", because the constant was named "Users". WTF doesn't cause an error, because activesupport doesn't look for it. Try renaming your namespace from "Users" to "User", which is a more appropriate name IMO. > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patrick at collinatorstudios.com Fri Apr 6 20:01:45 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Fri, 6 Apr 2012 13:01:45 -0700 (PDT) Subject: [rspec-users] i've been in activeadmin hell... In-Reply-To: <81981A08-27D4-4B75-8C41-478386A77709@gmail.com> References: <47756D2B-2527-4C27-B82B-D97644D4DEFE@gmail.com> <81981A08-27D4-4B75-8C41-478386A77709@gmail.com> Message-ID: On Fri, 6 Apr 2012, Justin Ko wrote: > So as you can see from your backtrace, the error is generating from confirmations_controller.rb, which makes sense because it has "class Users::ConfirmationsController". > > If you look further up the backtrace, you'll see activesupport trying to handle that error with its `load_missing_constant` method. I assume it "searched" for a file named "users", because the constant was named "Users". WTF doesn't cause an error, because activesupport doesn't look for it. Aha.. now it all makes sense... Patrick J. Collins http://collinatorstudios.com From weimar1927 at gmail.com Fri Apr 6 22:18:19 2012 From: weimar1927 at gmail.com (Hillary Hueter) Date: Fri, 6 Apr 2012 15:18:19 -0700 (PDT) Subject: [rspec-users] validating if a cell has any of the options. In-Reply-To: <5D1F243B-B51F-43E1-B8CE-8E011BB258C9@gmail.com> References: <943003.858.1332972660870.JavaMail.geo-discussion-forums@vbuc18> <4759914.2981.1333126378713.JavaMail.geo-discussion-forums@vbdn7> <5D1F243B-B51F-43E1-B8CE-8E011BB258C9@gmail.com> Message-ID: <32730371.713.1333750699220.JavaMail.geo-discussion-forums@vbbfj25> thanks. On Friday, March 30, 2012 5:30:28 PM UTC-7, Justin Ko wrote: > > > On Mar 30, 2012, at 10:52 AM, Hillary Hueter wrote: > > > The example as it exists today: > it "should show all applications" do > I.new do |c| > c.login_flow(:userid => $support, :password => $password) ## Logs in > c.manage_application_page.filter.when_present.flash > c.manage_application_page.filter.when_present.select_value("All") ## > Checks that the dropdown exists and changes it to "Show All Applications" > #Assertion > c.manage_application_page.applications_table.tr.each do | cell | > if ["Active", "Inactive", "Deleted"].include? cell.text() > puts cell.text() > end > end > end > end > > An example of the other tests: > > it "should show all active applications" do ### Checking the > Application Filter "Show All Active Applications" is working properly > Insight.new do |c| > c.login_flow(:userid => $support, :password => $password) ## Logs in > c.manage_application_page.filter.when_present.flash > > c.manage_application_page.filter.when_present.select_value("AllActive") ## > Checks that the dropdown exists and changes it to "Show All Active > Applications" > #Assertion > c.manage_application_page.applications_table.tr.each do |cell| > cell.text.should_not == 'Deleted' > cell.text.should_not == 'Inactive' > end > end > end > > > > > On Thursday, March 29, 2012 4:45:21 AM UTC-7, dchel... at gmail.com wrote: >> >> On Wed, Mar 28, 2012 at 5:11 PM, Hillary Hueter >> wrote: >> > I'm testing the filter on a table. One of the filter options is "Show >> All". >> > So for my other tests I've been looping through the rows and seeing if >> the >> > table cell that contains the status doesn't include text >> (cell.should_not == >> > 'Active'). >> >> Please post one of these examples so we can see precisely what you're >> already doing. >> >> Thx, >> David >> >> > However when the filter is set to all it can include any of the three >> > statuses (Active, Inactive, Deleted). >> > >> > Using any of the rspec matchers how can I validate this? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > If you're trying to verify that a string can be *any* of some things, I > would go with something like this: > > "foo".should match Regexp.union('Active', 'Inactive', 'Deleted') > > That is the same as: > > "foo".should match /Active|Inactive|Deleted/ > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryanachin at gmail.com Fri Apr 6 19:07:26 2012 From: ryanachin at gmail.com (seattlelite) Date: Fri, 6 Apr 2012 12:07:26 -0700 (PDT) Subject: [rspec-users] Autotest and Colors with Rspec Message-ID: <11109257.645.1333739246381.JavaMail.geo-discussion-forums@pbu5> Question 1. I'm using Ruby 1.9.2, Rails 3.0.7 and I have RSpec and Autotest installed, but Autotest is not running my specs - it's running Unit:Test installed. How do I get it to run my Rspecs? I tried this: (a) http://blog.davidchelimsky.net/2010/03/15/rspec-2-and-autotest/ Autotest.add_discovery { "rspec2" } #I also tried "rspec" (b) http://ph7spot.com/musings/getting-started-with-autotest running: bundle exec RSPEC=true autotest # get an error saying to run bundle install (so RSPEC=true gem is installed) Question 2. Can someone please recommend a Rails gem to use to show the red and green colors so it's easier to see pass/fails? Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathanvda at gmail.com Sat Apr 7 07:32:03 2012 From: nathanvda at gmail.com (nathanvda) Date: Sat, 7 Apr 2012 00:32:03 -0700 (PDT) Subject: [rspec-users] before(:all) leaves records in database In-Reply-To: References: Message-ID: <12782303.1766.1333783923313.JavaMail.geo-discussion-forums@vbai14> When using before(:all) to create records in the database, you should use after(:all) to clean that up. Sometimes when you need to setup a lot of data, this can speed your tests a lot. Otherwise avoid it. On Friday, November 25, 2011 3:04:08 PM UTC+1, Zhi-Qiang Lei wrote: > > Hi, > > When I test my Rails controller, I find that records created in > before(:all) remain in database while records created in before(:each) and > let are wiped out after testing. This made me run "rake test:prepare" for > every new test. Is that normal? > > Best regards, > Zhi-Qiang Lei > zhiqiang.lei at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Apr 7 12:59:45 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 7 Apr 2012 09:59:45 -0300 Subject: [rspec-users] Autotest and Colors with Rspec In-Reply-To: <11109257.645.1333739246381.JavaMail.geo-discussion-forums@pbu5> References: <11109257.645.1333739246381.JavaMail.geo-discussion-forums@pbu5> Message-ID: <81A0EB87-A891-4F36-A57C-13D145B65322@gmail.com> On Apr 6, 2012, at 16:07, seattlelite wrote: > Question 1. > I'm using Ruby 1.9.2, Rails 3.0.7 and I have RSpec and Autotest installed, but Autotest is not running my specs - it's running Unit:Test installed. How do I get it to run my Rspecs? > > I tried this: > > (a) http://blog.davidchelimsky.net/2010/03/15/rspec-2-and-autotest/ > > Autotest.add_discovery { "rspec2" } #I also tried "rspec" > > (b) http://ph7spot.com/musings/getting-started-with-autotest > > running: bundle exec RSPEC=true autotest # get an error saying to run bundle install (so RSPEC=true gem is installed) https://www.relishapp.com/rspec/rspec-core/v/2-9/docs/autotest > Question 2. > Can someone please recommend a Rails gem to use to show the red and green colors so it's easier to see pass/fails? Type 'rspec --help'. You don't need another gem. > Thank you! > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sat Apr 7 13:42:30 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 7 Apr 2012 10:42:30 -0300 Subject: [rspec-users] Autotest and Colors with Rspec In-Reply-To: <81A0EB87-A891-4F36-A57C-13D145B65322@gmail.com> References: <11109257.645.1333739246381.JavaMail.geo-discussion-forums@pbu5> <81A0EB87-A891-4F36-A57C-13D145B65322@gmail.com> Message-ID: <8664CCC76D2341B6BF5B554912C24B33@gmail.com> I added basic information to the README: https://github.com/rspec/rspec-core -- David Chelimsky Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Saturday, April 7, 2012 at 9:59 AM, David Chelimsky wrote: > On Apr 6, 2012, at 16:07, seattlelite wrote: > > > Question 1. > > I'm using Ruby 1.9.2, Rails 3.0.7 and I have RSpec and Autotest installed, but Autotest is not running my specs - it's running Unit:Test installed. How do I get it to run my Rspecs? > > > > I tried this: > > > > (a) http://blog.davidchelimsky.net/2010/03/15/rspec-2-and-autotest/ > > > > Autotest.add_discovery { "rspec2" } #I also tried "rspec" > > > > (b) http://ph7spot.com/musings/getting-started-with-autotest > > > > running: bundle exec RSPEC=true autotest # get an error saying to run bundle install (so RSPEC=true gem is installed) > > https://www.relishapp.com/rspec/rspec-core/v/2-9/docs/autotest > > > Question 2. > > Can someone please recommend a Rails gem to use to show the red and green colors so it's easier to see pass/fails? > > > > > Type 'rspec --help'. You don't need another gem. > > > Thank you! > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lbocseg at yahoo.com.br Sat Apr 7 15:30:35 2012 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Sat, 07 Apr 2012 12:30:35 -0300 Subject: [rspec-users] Can't access https://www.relishapp.com/rspec from Chrome Message-ID: <4F805D9B.20209@yahoo.com.br> It seems it has an invalid certificate. From benjamin.lovell at gmail.com Sat Apr 7 16:45:57 2012 From: benjamin.lovell at gmail.com (Ben Lovell) Date: Sat, 7 Apr 2012 17:45:57 +0100 Subject: [rspec-users] Can't access https://www.relishapp.com/rspec from Chrome In-Reply-To: <4F805D9B.20209@yahoo.com.br> References: <4F805D9B.20209@yahoo.com.br> Message-ID: On 7 April 2012 16:30, Rodrigo Rosenfeld Rosas wrote: > It seems it has an invalid certificate. > ______________________________**_________________ > Fine here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Sat Apr 7 20:27:20 2012 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 7 Apr 2012 21:27:20 +0100 Subject: [rspec-users] Can't access https://www.relishapp.com/rspec from Chrome In-Reply-To: <4F805D9B.20209@yahoo.com.br> References: <4F805D9B.20209@yahoo.com.br> Message-ID: <074CC6C8-DC8E-4FFD-AABC-302B0A2E7DE0@mattwynne.net> Hi Rodrigo, On 7 Apr 2012, at 16:30, Rodrigo Rosenfeld Rosas wrote: > It seems it has an invalid certificate. Could you please try this on some other computers to see whether it's a problem with your particular machine? I haven't had any other reports of this issue. If it still persists, please email support at relishapp.com and we can sort it out offline. cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book Founder, http://www.relishapp.com/ Twitter, https://twitter.com/mattwynne -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthauck at gmail.com Mon Apr 9 20:41:33 2012 From: matthauck at gmail.com (Matt Hauck) Date: Mon, 9 Apr 2012 13:41:33 -0700 (PDT) Subject: [rspec-users] Argument Non-Matchers Message-ID: <3261372.240.1334004093328.JavaMail.geo-discussion-forums@yniy14> Is there a way to specify a message expectation on an object to occur _without_ a particular argument? There is a particular function, which in some special circumstance takes a unique argument, but in normal circumstances does not take this unique argument. I want to say something like this: it "should recognize the special state" do obj.set_special_state true obj.should_receive(:my_method).with(/special_state/) obj.my_method end it "should operate fine without the special state" do obj.set_special_state false obj.should_receive(:my_method).without(/special_state/) obj.my_method end This does not appear to be possible to set a "non-expectation" on an argument matcher. Is there a way to do this? Or am I just going about this the wrong way? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Wed Apr 11 03:48:37 2012 From: jko170 at gmail.com (Justin Ko) Date: Tue, 10 Apr 2012 21:48:37 -0600 Subject: [rspec-users] Argument Non-Matchers In-Reply-To: <3261372.240.1334004093328.JavaMail.geo-discussion-forums@yniy14> References: <3261372.240.1334004093328.JavaMail.geo-discussion-forums@yniy14> Message-ID: <0151CDAC-F246-4CB2-B72F-E5D924A6A2D3@gmail.com> On Apr 9, 2012, at 2:41 PM, Matt Hauck wrote: > Is there a way to specify a message expectation on an object to occur _without_ a particular argument? > > There is a particular function, which in some special circumstance takes a unique argument, but in normal circumstances does not take this unique argument. I want to say something like this: > > it "should recognize the special state" do > obj.set_special_state true > obj.should_receive(:my_method).with(/special_state/) > obj.my_method > end > it "should operate fine without the special state" do > obj.set_special_state false > obj.should_receive(:my_method).without(/special_state/) > obj.my_method > end > > This does not appear to be possible to set a "non-expectation" on an argument matcher. Is there a way to do this? Or am I just going about this the wrong way? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Sorry for the late reply. This is what you want: http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers:no_args -------------- next part -------------- An HTML attachment was scrubbed... URL: From mguterl at gmail.com Wed Apr 11 13:08:07 2012 From: mguterl at gmail.com (Michael Guterl) Date: Wed, 11 Apr 2012 09:08:07 -0400 Subject: [rspec-users] SOAP / VCR / General Advice Message-ID: I'm building a ruby wrapper for a SOAP service using savon and I'm running into some issues with testing and I would love some feedback. I have added some tests with the help of VCR, but unfortunately that doesn't feel right given some of the constraints I'm running into. 1. The service provides no test mode or environment. 2. Putting the service into a known state is difficult because some objects are soft deleted. Attempting to save an object with the same unique identifier as a soft deleted object is a unique constraint violation. In order to test saving a new object in the system, an actual new object will need to be created in our production environment every time. 3. It is hard to simulate certain conditions because of #2. Other conditions like session timeouts are also difficult to simulate, because it requires actually sleeping in my spec. Sleeping in the spec is only necessary when not using VCR cassettes, once they are in place the sleep is no longer needed. 4. In the past when using VCR, I would be able to clear my spec/cassettes directory, run the tests again, and refresh what was there. Because of #2 this isn't possible for any tests that persist new objects using the service. The only thing I can come up with is building a clone of the service using sinatra and provide a subset of the functionality I need for testing. I'm fairly certain this will allow me to get around all of the constraints I mentioned and allow me to stub out specific requests to simulate different conditions. Any feedback is greatly appreciated. Best, Michael Guterl From ryan.macy at borderjump.com Tue Apr 10 22:28:33 2012 From: ryan.macy at borderjump.com (Ryan Macy) Date: Tue, 10 Apr 2012 15:28:33 -0700 (PDT) Subject: [rspec-users] Error running RSpec on RVM OSX Lion Message-ID: /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/ffi/ library.rb:121:in `block in ffi_lib': Could not open library '/usr/lib/ liblpcapi_ssl.so': dlopen(/usr/lib/liblpcapi_ssl.so, 5): image not found (LoadError) from /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/ ffi/library.rb:88:in `map' from /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/ ffi/library.rb:88:in `ffi_lib' I've tried searching around for the liblpcapi_ssl library with no luck. From alex at stinky.com Wed Apr 11 16:47:51 2012 From: alex at stinky.com (Alex Chaffee) Date: Wed, 11 Apr 2012 09:47:51 -0700 Subject: [rspec-users] Simple code dosn't work In-Reply-To: <59315168-7B6F-4E32-A9A1-60D6BA37A86E@leviston.net> References: <59315168-7B6F-4E32-A9A1-60D6BA37A86E@leviston.net> Message-ID: >>> j.even?should be true >> j.even?.should be true > j.even?.should be_true Not to ignite a flame war, but this is my biggest problem with RSpec: Unless you're an expert at Ruby syntax already, it's really easy to make punctuation mistakes. And of course, it should be j.should be_even (though following Skitt's Law, I probably got that wrong) - A P.S. In Wrong, it's assert { j.even? } -- Alex Chaffee - alex at stinky.com http://alexchaffee.com http://twitter.com/alexch -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthauck at gmail.com Wed Apr 11 17:18:29 2012 From: matthauck at gmail.com (Matt Hauck) Date: Wed, 11 Apr 2012 10:18:29 -0700 (PDT) Subject: [rspec-users] Argument Non-Matchers In-Reply-To: <0151CDAC-F246-4CB2-B72F-E5D924A6A2D3@gmail.com> References: <3261372.240.1334004093328.JavaMail.geo-discussion-forums@yniy14> <0151CDAC-F246-4CB2-B72F-E5D924A6A2D3@gmail.com> Message-ID: <6957506.3217.1334164709598.JavaMail.geo-discussion-forums@ynbi17> Hmm, that's not exactly what I was thinking of... I don't mean that there should be no arguments at all, but that the arguments should _not_ be of a certain match. On Tuesday, April 10, 2012 8:48:37 PM UTC-7, Justin Ko wrote: > > > On Apr 9, 2012, at 2:41 PM, Matt Hauck wrote: > > Is there a way to specify a message expectation on an object to occur > _without_ a particular argument? > > There is a particular function, which in some special circumstance takes a > unique argument, but in normal circumstances does not take this unique > argument. I want to say something like this: > > it "should recognize the special state" do > > obj.set_special_state true > obj.should_receive(:my_method).with(/special_state/) > obj.my_method > > end > it "should operate fine without the special state" do > > obj.set_special_state false > obj.should_receive(:my_method).without(/special_state/) > obj.my_method > > end > > This does not appear to be possible to set a "non-expectation" on an > argument matcher. Is there a way to do this? Or am I just going about this > the wrong way? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > Sorry for the late reply. This is what you want: > > http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers:no_args > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cnk at ugcs.caltech.edu Wed Apr 11 17:26:18 2012 From: cnk at ugcs.caltech.edu (Cynthia Kiser) Date: Wed, 11 Apr 2012 10:26:18 -0700 Subject: [rspec-users] ***SPAM*** Re: Argument Non-Matchers In-Reply-To: <6957506.3217.1334164709598.JavaMail.geo-discussion-forums@ynbi17> References: <3261372.240.1334004093328.JavaMail.geo-discussion-forums@yniy14> <0151CDAC-F246-4CB2-B72F-E5D924A6A2D3@gmail.com> <6957506.3217.1334164709598.JavaMail.geo-discussion-forums@ynbi17> Message-ID: <20120411172618.GD17673@ugcs.caltech.edu> Quoting Matt Hauck : > Hmm, that's not exactly what I was thinking of... I don't mean that there > should be no arguments at all, but that the arguments should _not_ be of a > certain match. I suspect there isn't a built in matcher to do what you would like. But I suspect you might be about to look at the source code for should_receive and turn around the sense of the match to get what you are looking for. You'll just have to make a custom matcher and include it into your test runner. -- Cynthia N. Kiser cnk at ugcs.caltech.edu From dchelimsky at gmail.com Wed Apr 11 17:31:09 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 11 Apr 2012 12:31:09 -0500 Subject: [rspec-users] Argument Non-Matchers In-Reply-To: <6957506.3217.1334164709598.JavaMail.geo-discussion-forums@ynbi17> References: <3261372.240.1334004093328.JavaMail.geo-discussion-forums@yniy14> <0151CDAC-F246-4CB2-B72F-E5D924A6A2D3@gmail.com> <6957506.3217.1334164709598.JavaMail.geo-discussion-forums@ynbi17> Message-ID: On Wed, Apr 11, 2012 at 12:18 PM, Matt Hauck wrote: > On Tuesday, April 10, 2012 8:48:37 PM UTC-7, Justin Ko wrote: >> >> >> On Apr 9, 2012, at 2:41 PM, Matt Hauck wrote: >> >> Is there a way to specify a message expectation on an object to occur >> _without_ a particular argument? >> >> There is a particular function, which in some special circumstance takes a >> unique argument, but in normal circumstances does not take this unique >> argument. I want to say something like this: >> >> it "should recognize the special state" do >> >> obj.set_special_state true >> obj.should_receive(:my_method).with(/special_state/) >> obj.my_method >> >> end >> it "should operate fine without the special state" do >> >> obj.set_special_state false >> obj.should_receive(:my_method).without(/special_state/) >> obj.my_method >> >> end >> >> This does not appear to be possible to set a "non-expectation"?on an >> argument matcher. Is there a way to do this? Or am I just going about this >> the wrong way? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> Sorry for the late reply. This is what you want: >> >> http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers:no_args > Hmm, that's not exactly what I was thinking of...?I don't mean that there > should be no arguments at all, but that the arguments should _not_ be of a > certain match. > You can do this: obj.should_receive(:my_method) do |arg| arg.should_not match(/special_state/) end HTH, David From dchelimsky at gmail.com Wed Apr 11 20:54:39 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 11 Apr 2012 15:54:39 -0500 Subject: [rspec-users] Error running RSpec on RVM OSX Lion In-Reply-To: References: Message-ID: On Tue, Apr 10, 2012 at 5:28 PM, Ryan Macy wrote: > /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/ffi/ > library.rb:121:in `block in ffi_lib': Could not open library '/usr/lib/ > liblpcapi_ssl.so': dlopen(/usr/lib/liblpcapi_ssl.so, 5): image not > found (LoadError) > ? ? ? ?from /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/ > ffi/library.rb:88:in `map' > ? ? ? ?from /Users/ryanmacy/.rvm/gems/ruby-1.9.2-p318/gems/ffi-1.0.11/lib/ > ffi/library.rb:88:in `ffi_lib' > > > I've tried searching around for the liblpcapi_ssl library with no luck. I'm not familiar with liblpcapi_ssl, but every line in that backtrace references ffi. I'd recommend submitting an issue to https://github.com/ffi/ffi/issues or contacting one of the maintainers (I don't see a mailing list listed in the project README: https://github.com/ffi/ffi). HTH, David From zach.dennis at gmail.com Wed Apr 11 22:39:06 2012 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 11 Apr 2012 18:39:06 -0400 Subject: [rspec-users] Simple code dosn't work In-Reply-To: References: <59315168-7B6F-4E32-A9A1-60D6BA37A86E@leviston.net> Message-ID: On Wed, Apr 11, 2012 at 12:47 PM, Alex Chaffee wrote: >>>> j.even?should be true > >>> j.even?.should be true > >> j.even?.should be_true > > Not to ignite a flame war, but this is my biggest problem with RSpec: Unless > you're an expert at Ruby syntax already, it's really easy to make > punctuation mistakes. If you make syntax errors then you won't get to far with . While it is possible to make syntax errors with RSpec it's also possible to make them outside of RSpec. Your experience may be different than mine, but I don't recall making more typos in RSpec because of its syntax as opposed to making typos in a variety of languages (irregardless of if its a testing framework). But it's entirely possible that my memory is rewriting history. > > And of course, it should be > > j.should be_even > > (though following Skitt's Law, I probably got that wrong) > > ?- A > > P.S. In Wrong, it's > > assert { j.even? } Yep, that's another way of doing it. It's not this little guy that keeps me from test/unit, it's its cousins. Zach > > -- > Alex Chaffee - alex at stinky.com > http://alexchaffee.com > http://twitter.com/alexch > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- -- @zachdennis http://www.continuousthinking.com http://www.mutuallyhuman.com From cnk at ugcs.caltech.edu Thu Apr 12 04:23:46 2012 From: cnk at ugcs.caltech.edu (Cynthia Kiser) Date: Wed, 11 Apr 2012 21:23:46 -0700 Subject: [rspec-users] Simple code dosn't work In-Reply-To: References: <59315168-7B6F-4E32-A9A1-60D6BA37A86E@leviston.net> Message-ID: <20120412042346.GA9906@ugcs.caltech.edu> Quoting Zach Dennis : > On Wed, Apr 11, 2012 at 12:47 PM, Alex Chaffee wrote: > >>>> j.even?should be true > > > >>> j.even?.should be true > > > >> j.even?.should be_true > > > > Not to ignite a flame war, but this is my biggest problem with RSpec: Unless > > you're an expert at Ruby syntax already, it's really easy to make > > punctuation mistakes. > > If you make syntax errors then you won't get to far with > . While it is possible to make syntax errors > with RSpec it's also possible to make them outside of RSpec. True. But I have found the english-like syntax of RSpec harder to remember than the ugly Test::Unit syntax. It is the superiority of RSpec's test organization - and its ubiquity - that made me persist. -- Cynthia N. Kiser cnk at ugcs.caltech.edu From arnaldo.junior at aedu.com Thu Apr 12 17:32:27 2012 From: arnaldo.junior at aedu.com (Arnaldo Junior) Date: Thu, 12 Apr 2012 10:32:27 -0700 (PDT) Subject: [rspec-users] Rspec with Nested Resources Message-ID: <76ae11ab-10ad-4fe0-84e7-cff807c2a833@x17g2000yqj.googlegroups.com> Hi, I have problems to implement the tests with RSpec with nested routes in views, as I implement these tests? Always gives error that it can not find the routes. #config/routes.rb resources :controller1 do resources :controller2 end My test view #spec/views/controller2/index.html.erb_spec.rb require 'spec_helper' describe "controller2/index" do it "renders a list of planos" do render end end And return this error Failure/Error: render ActionView::Template::Error: No route matches {:controller=>"controller2"} Can anybody help-me? Thanks. From jko170 at gmail.com Fri Apr 13 06:24:02 2012 From: jko170 at gmail.com (Justin Ko) Date: Fri, 13 Apr 2012 00:24:02 -0600 Subject: [rspec-users] SOAP / VCR / General Advice In-Reply-To: References: Message-ID: On Apr 11, 2012, at 7:08 AM, Michael Guterl wrote: > I'm building a ruby wrapper for a SOAP service using savon and I'm > running into some issues with testing and I would love some feedback. > I have added some tests with the help of VCR, but unfortunately that > doesn't feel right given some of the constraints I'm running into. > > 1. The service provides no test mode or environment. > 2. Putting the service into a known state is difficult because some > objects are soft deleted. Attempting to save an object with the same > unique identifier as a soft deleted object is a unique constraint > violation. In order to test saving a new object in the system, an > actual new object will need to be created in our production > environment every time. > 3. It is hard to simulate certain conditions because of #2. Other > conditions like session timeouts are also difficult to simulate, > because it requires actually sleeping in my spec. Sleeping in the > spec is only necessary when not using VCR cassettes, once they are in > place the sleep is no longer needed. > 4. In the past when using VCR, I would be able to clear my > spec/cassettes directory, run the tests again, and refresh what was > there. Because of #2 this isn't possible for any tests that persist > new objects using the service. > > The only thing I can come up with is building a clone of the service > using sinatra and provide a subset of the functionality I need for > testing. I'm fairly certain this will allow me to get around all of > the constraints I mentioned and allow me to stub out specific requests > to simulate different conditions. > > Any feedback is greatly appreciated. > > Best, > Michael Guterl > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users They technically have no "sandbox", but could you open another production account for your own personal sandbox? Otherwise you're dealing with some serious limitations. From jko170 at gmail.com Fri Apr 13 07:51:54 2012 From: jko170 at gmail.com (Justin Ko) Date: Fri, 13 Apr 2012 01:51:54 -0600 Subject: [rspec-users] Rspec with Nested Resources In-Reply-To: <76ae11ab-10ad-4fe0-84e7-cff807c2a833@x17g2000yqj.googlegroups.com> References: <76ae11ab-10ad-4fe0-84e7-cff807c2a833@x17g2000yqj.googlegroups.com> Message-ID: <03F902A4-90B3-4BBE-97B5-2E58FA48CDF9@gmail.com> On Apr 12, 2012, at 11:32 AM, Arnaldo Junior wrote: > Hi, I have problems to implement the tests with RSpec with nested > routes in views, as I implement these tests? > Always gives error that it can not find the routes. > > #config/routes.rb > > resources :controller1 do > resources :controller2 > end > > > My test view > > #spec/views/controller2/index.html.erb_spec.rb > > require 'spec_helper' > > describe "controller2/index" do > > it "renders a list of planos" do > render > end > end > > > And return this error > > Failure/Error: render > ActionView::Template::Error: > No route matches {:controller=>"controller2"} > > Can anybody help-me? > Thanks. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Hi, can you open an issue for this? Might be a bug. https://github.com/rspec/rspec-rails/issues From lbocseg at yahoo.com.br Fri Apr 13 19:09:26 2012 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Fri, 13 Apr 2012 16:09:26 -0300 Subject: [rspec-users] Smart mocks for ActiveRecord to speed up tests Message-ID: <4F8879E6.5080102@yahoo.com.br> Hello old friends, I'm getting back to Rails and Ruby programming full time again (Yay!) I've stopped doing Rails programming to work with Grails in 2009 after 2 years working with Rails due to a better job offer. Since then I've changed my job once more, but still on Grails, but I found a critical bug in Grails more than a week ago that didn't seem to get much attention and is affecting the production system I maintain: http://jira.grails.org/browse/GRAILS-8994 As I couldn't work around that bug and I can't see myself reading the Grails source code (a real mess!) I decided to take another approach that would allow me to get back to Rails programming. I created a Devise / Warden strategy to send the cookies to the current system and it will return me the current logged in user. So I can set up Nginx to proxy some requests affected by the Grails bug to this new Rails application. I've finished this action last Monday but when I was about to send all the hard work to the server lots of my directories were suddenly gone when I was using them. I still don't know what happened but I've replaced my hard-drive just in case, but it means I had to do all over again :( Anyway, now I got it back to work but testing a single action (an update/insert one) will take about a full second to run using RSpec and FactoryGirl. I really don't like Grails but they had a great feature for unit testing. They were able to mock their domain class (that is how they call their models) in such a way that they can perform most of the operations you can do on real objects. Of course it have another serious bug that will prevent me to use it in lots of cases: http://jira.grails.org/browse/GRAILS-8854 But the idea is great as it works seamlessly like in a memory database. So, I'd like to be able to keep my tests easy to read but avoid touching the database that much. But my controller spec rely on lots of the setting of ActiveRecord for my models, like maximum calculations in before callbacks, custom foreign keys and depends: :delete_all in some has_many associations. Also I do also need a user object that Devise will accept on its sign_in helper method. Is there any place I could read more about writing faster tests without getting crazy writing so many mocks manually. For example, mocking a Grails domain class in a unit test would be as easy as: @mock(User) class UserTests... Then I'm able to do most operations using the Grails domain class API using the User mock. Is there something like this for Rails and Rspec? Is there some way that I could set up FactoryGirl to use those mocks instead of hitting the database when I want to? Am I going in the wrong direction here? If so, what would be the right direction? Thanks in advance. Glad to be part of the Ruby, Rails and Rspec community full-time again :D Cheers, Rodrigo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Apr 14 13:11:04 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Apr 2012 08:11:04 -0500 Subject: [rspec-users] Smart mocks for ActiveRecord to speed up tests In-Reply-To: <4F8879E6.5080102@yahoo.com.br> References: <4F8879E6.5080102@yahoo.com.br> Message-ID: <9113B01EED7E405EBAB3CFA2784AE4ED@gmail.com> On Friday, April 13, 2012 at 2:09 PM, Rodrigo Rosenfeld Rosas wrote: > Hello old friends, I'm getting back to Rails and Ruby programming full time again (Yay!) > > I've stopped doing Rails programming to work with Grails in 2009 after 2 years working with Rails due to a better job offer. > > Since then I've changed my job once more, but still on Grails, but I found a critical bug in Grails more than a week ago that didn't seem to get much attention and is affecting the production system I maintain: > > http://jira.grails.org/browse/GRAILS-8994 > > As I couldn't work around that bug and I can't see myself reading the Grails source code (a real mess!) I decided to take another approach that would allow me to get back to Rails programming. > > I created a Devise / Warden strategy to send the cookies to the current system and it will return me the current logged in user. So I can set up Nginx to proxy some requests affected by the Grails bug to this new Rails application. > > I've finished this action last Monday but when I was about to send all the hard work to the server lots of my directories were suddenly gone when I was using them. I still don't know what happened but I've replaced my hard-drive just in case, but it means I had to do all over again :( > > Anyway, now I got it back to work but testing a single action (an update/insert one) will take about a full second to run using RSpec and FactoryGirl. > > I really don't like Grails but they had a great feature for unit testing. They were able to mock their domain class (that is how they call their models) in such a way that they can perform most of the operations you can do on real objects. > > Of course it have another serious bug that will prevent me to use it in lots of cases: > > http://jira.grails.org/browse/GRAILS-8854 > > But the idea is great as it works seamlessly like in a memory database. > > So, I'd like to be able to keep my tests easy to read but avoid touching the database that much. > > But my controller spec rely on lots of the setting of ActiveRecord for my models, like maximum calculations in before callbacks, custom foreign keys and depends: :delete_all in some has_many associations. Also I do also need a user object that Devise will accept on its sign_in helper method. > > Is there any place I could read more about writing faster tests without getting crazy writing so many mocks manually. For example, mocking a Grails domain class in a unit test would be as easy as: > > @mock(User) > class UserTests... > > Then I'm able to do most operations using the Grails domain class API using the User mock. > > Is there something like this for Rails and Rspec? Is there some way that I could set up FactoryGirl to use those mocks instead of hitting the database when I want to? > > Am I going in the wrong direction here? If so, what would be the right direction? > > Thanks in advance. > > Glad to be part of the Ruby, Rails and Rspec community full-time again :D > > Cheers, > Rodrigo. You can use mock_model or stub_model to create model instances, or you can use FactoryGirl.build instead of FactoryGirl.create. Only mock_model will actually avoid db calls entirely (the others will still query for column names even if you don't save anything). Those techniques, however, don't help you with finders. You still have to stub any finders with the object generated by any of the aforementioned techniques: thing = mock_model(Thing) Thing.stub(:domain_specific_finder => [thing]) It's not pretty, but it's the best way I know of to get what you're after. I started a lib called stubble a few years back that attempted to address this more holistically (https://github.com/dchelimsky/stubble) but I never released it as a gem because there were just too many different ways to access model data via the ActiveRecord API and they don't all flow through a single part of the codebase that we can override in an extension. HTH, David -- David Chelimsky Sent with Sparrow (http://www.sparrowmailapp.com/?sig) -------------- next part -------------- An HTML attachment was scrubbed... URL: From basv at odd-e.com Sun Apr 15 06:32:49 2012 From: basv at odd-e.com (Bas Vodde) Date: Sun, 15 Apr 2012 14:32:49 +0800 Subject: [rspec-users] RSpec exactly behavior (it doesn't exactly fail) Message-ID: Hiya all, I've got a quick question related to RSpec. I was test-driving some code and ended up in an endless loop. I was surprised by this, but traced it down to the mock not failing on additional calls but only in the end. Let me explain. I was writing code like this: subject.wrapper.should_receive(:window_list).exactly(4).times.and_return { counter = counter + 1 counter >= 4 ? [ "new window" ] : [] } The idea was that it would call the code-block 4 times exactly and then return a new value (and thus stop calling it). As the code to implement wasn't there yet, it led to a recursive call. I had expected RSpec to stop after 4 calls though, as I had instructed the mock that I expected exactly 4 calls. I added a new test in RSpec itself in precision_counts_spec.rb: it "fails when a method is called more than n times, but fails within the method call" do @mock.should_receive(:random_call).exactly(1).times lambda do @mock.random_call @mock.random_call end.should raise_error(RSpec::Mocks::MockExpectationError) end which failed :( (or it failed to fail and therefore failed!) It would be nice if it would fail. Is there any reason for not failing already at this point in time? (I'm using RSpec 2.6-0. I quickly browsed the latest and didn't see this changed) Thanks, Bas From dchelimsky at gmail.com Sun Apr 15 21:48:06 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Apr 2012 16:48:06 -0500 Subject: [rspec-users] RSpec exactly behavior (it doesn't exactly fail) In-Reply-To: References: Message-ID: <9C46EDD2AE184105AD8DFE6DBAB09518@gmail.com> On Sunday, April 15, 2012 at 1:32 AM, Bas Vodde wrote: > > Hiya all, > > I've got a quick question related to RSpec. I was test-driving some code and ended up in an endless loop. I was surprised by this, but traced it down to the mock not failing on additional calls but only in the end. Let me explain. > > I was writing code like this: > > subject.wrapper.should_receive(:window_list).exactly(4).times.and_return { > counter = counter + 1 > counter >= 4 ? [ "new window" ] : [] > } > > The idea was that it would call the code-block 4 times exactly and then return a new value (and thus stop calling it). As the code to implement wasn't there yet, it led to a recursive call. I had expected RSpec to stop after 4 calls though, as I had instructed the mock that I expected exactly 4 calls. > > I added a new test in RSpec itself in precision_counts_spec.rb: > > it "fails when a method is called more than n times, but fails within the method call" do > @mock.should_receive(:random_call).exactly(1).times > lambda do > @mock.random_call > @mock.random_call > end.should raise_error(RSpec::Mocks::MockExpectationError) > end > > which failed :( (or it failed to fail and therefore failed!) > > It would be nice if it would fail. Is there any reason for not failing already at this point in time? > > (I'm using RSpec 2.6-0. I quickly browsed the latest and didn't see this changed) > > Thanks, > > Bas There is no philosophical reason for this to happen, and there are other types of failures that do fail-fast (e.g. obj.should_receive(:bar).with(1,2) fails immediately if it receives :bar with any other args). Please submit this to https://github.com/rspec/rspec-mocks/issues and I'll start looking into a fix. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From mguterl at gmail.com Sun Apr 15 22:04:24 2012 From: mguterl at gmail.com (Michael Guterl) Date: Sun, 15 Apr 2012 18:04:24 -0400 Subject: [rspec-users] SOAP / VCR / General Advice In-Reply-To: References: Message-ID: On Fri, Apr 13, 2012 at 2:24 AM, Justin Ko wrote: > > On Apr 11, 2012, at 7:08 AM, Michael Guterl wrote: > >> I'm building a ruby wrapper for a SOAP service using savon and I'm >> running into some issues with testing and I would love some feedback. >> I have added some tests with the help of VCR, but unfortunately that >> doesn't feel right given some of the constraints I'm running into. >> >> 1. The service provides no test mode or environment. >> 2. Putting the service into a known state is difficult because some >> objects are soft deleted. Attempting to save an object with the same >> unique identifier as a soft deleted object is a unique constraint >> violation. ?In order to test saving a new object in the system, an >> actual new object will need to be created in our production >> environment every time. >> 3. It is hard to simulate certain conditions because of #2. ?Other >> conditions like session timeouts are also difficult to simulate, >> because it requires actually sleeping in my spec. ?Sleeping in the >> spec is only necessary when not using VCR cassettes, once they are in >> place the sleep is no longer needed. >> 4. In the past when using VCR, I would be able to clear my >> spec/cassettes directory, run the tests again, and refresh what was >> there. ?Because of #2 this isn't possible for any tests that persist >> new objects using the service. >> >> The only thing I can come up with is building a clone of the service >> using sinatra and provide a subset of the functionality I need for >> testing. ?I'm fairly certain this will allow me to get around all of >> the constraints I mentioned and allow me to stub out specific requests >> to simulate different conditions. >> >> Any feedback is greatly appreciated. >> >> Best, >> Michael Guterl >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > They technically have no "sandbox", but could you open another production account for your own personal sandbox? Otherwise you're dealing with some serious limitations. > I could, but I'm still dealing with the constraint that records can never be deleted: #2. Also the fact that there is no way to simulate certain conditions is also painful. A good API should have a way for me to simulate an error, no? I'm getting by with little or no tests around this code, but I don't think it will last for long... From jko170 at gmail.com Sun Apr 15 22:47:36 2012 From: jko170 at gmail.com (Justin Ko) Date: Sun, 15 Apr 2012 16:47:36 -0600 Subject: [rspec-users] SOAP / VCR / General Advice In-Reply-To: References: Message-ID: <948E7ECD-CDE9-459D-8BC8-3D7F23CBC0F3@gmail.com> Sent from my iPhone On Apr 15, 2012, at 4:04 PM, Michael Guterl wrote: > On Fri, Apr 13, 2012 at 2:24 AM, Justin Ko wrote: >> >> On Apr 11, 2012, at 7:08 AM, Michael Guterl wrote: >> >>> I'm building a ruby wrapper for a SOAP service using savon and I'm >>> running into some issues with testing and I would love some feedback. >>> I have added some tests with the help of VCR, but unfortunately that >>> doesn't feel right given some of the constraints I'm running into. >>> >>> 1. The service provides no test mode or environment. >>> 2. Putting the service into a known state is difficult because some >>> objects are soft deleted. Attempting to save an object with the same >>> unique identifier as a soft deleted object is a unique constraint >>> violation. In order to test saving a new object in the system, an >>> actual new object will need to be created in our production >>> environment every time. >>> 3. It is hard to simulate certain conditions because of #2. Other >>> conditions like session timeouts are also difficult to simulate, >>> because it requires actually sleeping in my spec. Sleeping in the >>> spec is only necessary when not using VCR cassettes, once they are in >>> place the sleep is no longer needed. >>> 4. In the past when using VCR, I would be able to clear my >>> spec/cassettes directory, run the tests again, and refresh what was >>> there. Because of #2 this isn't possible for any tests that persist >>> new objects using the service. >>> >>> The only thing I can come up with is building a clone of the service >>> using sinatra and provide a subset of the functionality I need for >>> testing. I'm fairly certain this will allow me to get around all of >>> the constraints I mentioned and allow me to stub out specific requests >>> to simulate different conditions. >>> >>> Any feedback is greatly appreciated. >>> >>> Best, >>> Michael Guterl >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> They technically have no "sandbox", but could you open another production account for your own personal sandbox? Otherwise you're dealing with some serious limitations. >> > I could, but I'm still dealing with the constraint that records can > never be deleted: #2. So just pass a unique identifier each time. If the algorithm isn't unique enough, have some retry logic. > Also the fact that there is no way to simulate > certain conditions is also painful. A good API should have a way for > me to simulate an error, no? Correct. I would drop this company if you can. > I'm getting by with little or no tests > around this code, but I don't think it will last for long... > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Apr 16 02:14:01 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Apr 2012 21:14:01 -0500 Subject: [rspec-users] RSpec exactly behavior (it doesn't exactly fail) In-Reply-To: <9C46EDD2AE184105AD8DFE6DBAB09518@gmail.com> References: <9C46EDD2AE184105AD8DFE6DBAB09518@gmail.com> Message-ID: <85460AE2CB82419398FD17CAE64C4F09@gmail.com> Actually I just went ahead and fixed it sans-bug report: https://github.com/rspec/rspec-mocks/commit/fb9c76c2e40b4b25f4dcc5de95f8c60319b6d9c1. It'll be fixed in the next release (2.10). Cheers, David -- David Chelimsky Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Sunday, April 15, 2012 at 4:48 PM, David Chelimsky wrote: > On Sunday, April 15, 2012 at 1:32 AM, Bas Vodde wrote: > > > > Hiya all, > > > > I've got a quick question related to RSpec. I was test-driving some code and ended up in an endless loop. I was surprised by this, but traced it down to the mock not failing on additional calls but only in the end. Let me explain. > > > > I was writing code like this: > > > > subject.wrapper.should_receive(:window_list).exactly(4).times.and_return { > > counter = counter + 1 > > counter >= 4 ? [ "new window" ] : [] > > } > > > > The idea was that it would call the code-block 4 times exactly and then return a new value (and thus stop calling it). As the code to implement wasn't there yet, it led to a recursive call. I had expected RSpec to stop after 4 calls though, as I had instructed the mock that I expected exactly 4 calls. > > > > I added a new test in RSpec itself in precision_counts_spec.rb: > > > > it "fails when a method is called more than n times, but fails within the method call" do > > @mock.should_receive(:random_call).exactly(1).times > > lambda do > > @mock.random_call > > @mock.random_call > > end.should raise_error(RSpec::Mocks::MockExpectationError) > > end > > > > which failed :( (or it failed to fail and therefore failed!) > > > > It would be nice if it would fail. Is there any reason for not failing already at this point in time? > > > > (I'm using RSpec 2.6-0. I quickly browsed the latest and didn't see this changed) > > > > Thanks, > > > > Bas > There is no philosophical reason for this to happen, and there are other types of failures that do fail-fast (e.g. obj.should_receive(:bar).with(1,2) fails immediately if it receives :bar with any other args). > > Please submit this to https://github.com/rspec/rspec-mocks/issues and I'll start looking into a fix. > > Cheers, > David > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lbocseg at yahoo.com.br Mon Apr 16 02:23:03 2012 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Sun, 15 Apr 2012 23:23:03 -0300 Subject: [rspec-users] Smart mocks for ActiveRecord to speed up tests In-Reply-To: <9113B01EED7E405EBAB3CFA2784AE4ED@gmail.com> References: <4F8879E6.5080102@yahoo.com.br> <9113B01EED7E405EBAB3CFA2784AE4ED@gmail.com> Message-ID: <4F8B8287.5030800@yahoo.com.br> Em 14-04-2012 10:11, David Chelimsky escreveu: > On Friday, April 13, 2012 at 2:09 PM, Rodrigo Rosenfeld Rosas wrote: >> Hello old friends, I'm getting back to Rails and Ruby programming >> full time again (Yay!) >> >> I've stopped doing Rails programming to work with Grails in 2009 >> after 2 years working with Rails due to a better job offer. >> >> Since then I've changed my job once more, but still on Grails, but I >> found a critical bug in Grails more than a week ago that didn't seem >> to get much attention and is affecting the production system I maintain: >> >> http://jira.grails.org/browse/GRAILS-8994 >> >> As I couldn't work around that bug and I can't see myself reading the >> Grails source code (a real mess!) I decided to take another approach >> that would allow me to get back to Rails programming. >> >> I created a Devise / Warden strategy to send the cookies to the >> current system and it will return me the current logged in user. So I >> can set up Nginx to proxy some requests affected by the Grails bug to >> this new Rails application. >> >> I've finished this action last Monday but when I was about to send >> all the hard work to the server lots of my directories were suddenly >> gone when I was using them. I still don't know what happened but I've >> replaced my hard-drive just in case, but it means I had to do all >> over again :( >> >> Anyway, now I got it back to work but testing a single action (an >> update/insert one) will take about a full second to run using RSpec >> and FactoryGirl. >> >> I really don't like Grails but they had a great feature for unit >> testing. They were able to mock their domain class (that is how they >> call their models) in such a way that they can perform most of the >> operations you can do on real objects. >> >> Of course it have another serious bug that will prevent me to use it >> in lots of cases: >> >> http://jira.grails.org/browse/GRAILS-8854 >> >> But the idea is great as it works seamlessly like in a memory database. >> >> So, I'd like to be able to keep my tests easy to read but avoid >> touching the database that much. >> >> But my controller spec rely on lots of the setting of ActiveRecord >> for my models, like maximum calculations in before callbacks, custom >> foreign keys and depends: :delete_all in some has_many associations. >> Also I do also need a user object that Devise will accept on its >> sign_in helper method. >> >> Is there any place I could read more about writing faster tests >> without getting crazy writing so many mocks manually. For example, >> mocking a Grails domain class in a unit test would be as easy as: >> >> @mock(User) >> class UserTests... >> >> Then I'm able to do most operations using the Grails domain class API >> using the User mock. >> >> Is there something like this for Rails and Rspec? Is there some way >> that I could set up FactoryGirl to use those mocks instead of hitting >> the database when I want to? >> >> Am I going in the wrong direction here? If so, what would be the >> right direction? >> >> Thanks in advance. >> >> Glad to be part of the Ruby, Rails and Rspec community full-time again :D >> >> Cheers, >> Rodrigo. > You can use mock_model or stub_model to create model instances, or you > can use FactoryGirl.build instead of FactoryGirl.create. Only > mock_model will actually avoid db calls entirely (the others will > still query for column names even if you don't save anything). > > Those techniques, however, don't help you with finders. You still have > to stub any finders with the object generated by any of the > aforementioned techniques: > > thing = mock_model(Thing) > Thing.stub(:domain_specific_finder => [thing]) I'm not sure what you're suggesting. For example, the first part of my controller action looks like this: instance = Model.where(id: params[:id]).first_or_initialize(parent_id: params[:parentId]) The spec starts with something like this: root = FactoryGirl.create :field, label: 'ROOT' post 'action', parentId: root.id In the before/after Model callbacks there will be other kind of finders for the same class. How would you suggest me to change this block to use FactoryGirl.build and mock Model? Also, I couldn't find how to mock 'open' from 'open-uri', so I'm currently mocking my controller's action: controller.should_receive(:clear_fields_cache).exactly(3).times # 1 creation and 2 updates The action is implemented this way: require 'open-uri' ... private def clear_fields_cache open INTEGRATION_BASE_URL + 'clearModelCache', 'Cookie' => authentication_cookie_string # includes JSESSIONID and rememberMe end But maybe it would be a great idea to check for the specific URL and cookie handling and I could do so if I was able to mock the 'open' method from 'open-uri'. Any ideas on how to do that? > It's not pretty, but it's the best way I know of to get what you're > after. I started a lib called stubble a few years back that attempted > to address this more holistically > (https://github.com/dchelimsky/stubble) but I never released it as a > gem because there were just too many different ways to access model > data via the ActiveRecord API and they don't all flow through a single > part of the codebase that we can override in an extension. I agree with you. I've taken a look at the library but as you can see I'm using the new 'where' API and this probably will keep changing each new AR release... Also, in Grails case, the mocked domain classes are maintained alongside with the real classes, so there is little chance of them getting out of sync. But of course the mocks have some limitation, like not being able to deal with custom SQL fragments: http://grails.org/doc/latest/guide/testing.html#unitTestingDomains Other than that there are also some bugs when dealing with association ids. I never thought it would be easy to have something like this for ActiveRecord but once there is a long time since I last often worked with Rails, things might have changed ;) Thank you a lot for your input and glad to be talking to you again :) Cheers, Rodrigo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From basv at odd-e.com Mon Apr 16 02:30:19 2012 From: basv at odd-e.com (Bas Vodde) Date: Mon, 16 Apr 2012 10:30:19 +0800 Subject: [rspec-users] RSpec exactly behavior (it doesn't exactly fail) In-Reply-To: <85460AE2CB82419398FD17CAE64C4F09@gmail.com> References: <9C46EDD2AE184105AD8DFE6DBAB09518@gmail.com> <85460AE2CB82419398FD17CAE64C4F09@gmail.com> Message-ID: <7433274E-6E71-4C14-80E3-AA18E1E4DCA9@odd-e.com> Hiya, Kewl, thanks! (To be honest, I was a bit disapointed as I was thinking of doing it myself and sending it to you :P) Anyways, much appreciated! Bas On 16-Apr-2012, at 10:14 AM, David Chelimsky wrote: > Actually I just went ahead and fixed it sans-bug report: https://github.com/rspec/rspec-mocks/commit/fb9c76c2e40b4b25f4dcc5de95f8c60319b6d9c1. It'll be fixed in the next release (2.10). > > Cheers, > David > > -- > David Chelimsky > Sent with Sparrow > > On Sunday, April 15, 2012 at 4:48 PM, David Chelimsky wrote: > >> On Sunday, April 15, 2012 at 1:32 AM, Bas Vodde wrote: >>> >>> Hiya all, >>> >>> I've got a quick question related to RSpec. I was test-driving some code and ended up in an endless loop. I was surprised by this, but traced it down to the mock not failing on additional calls but only in the end. Let me explain. >>> >>> I was writing code like this: >>> >>> subject.wrapper.should_receive(:window_list).exactly(4).times.and_return { >>> counter = counter + 1 >>> counter >= 4 ? [ "new window" ] : [] >>> } >>> >>> The idea was that it would call the code-block 4 times exactly and then return a new value (and thus stop calling it). As the code to implement wasn't there yet, it led to a recursive call. I had expected RSpec to stop after 4 calls though, as I had instructed the mock that I expected exactly 4 calls. >>> >>> I added a new test in RSpec itself in precision_counts_spec.rb: >>> >>> it "fails when a method is called more than n times, but fails within the method call" do >>> @mock.should_receive(:random_call).exactly(1).times >>> lambda do >>> @mock.random_call >>> @mock.random_call >>> end.should raise_error(RSpec::Mocks::MockExpectationError) >>> end >>> >>> which failed :( (or it failed to fail and therefore failed!) >>> >>> It would be nice if it would fail. Is there any reason for not failing already at this point in time? >>> >>> (I'm using RSpec 2.6-0. I quickly browsed the latest and didn't see this changed) >>> >>> Thanks, >>> >>> Bas >> There is no philosophical reason for this to happen, and there are other types of failures that do fail-fast (e.g. obj.should_receive(:bar).with(1,2) fails immediately if it receives :bar with any other args). >> >> Please submit this to https://github.com/rspec/rspec-mocks/issues and I'll start looking into a fix. >> >> Cheers, >> David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Apr 16 02:34:44 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Apr 2012 21:34:44 -0500 Subject: [rspec-users] RSpec exactly behavior (it doesn't exactly fail) In-Reply-To: <7433274E-6E71-4C14-80E3-AA18E1E4DCA9@odd-e.com> References: <9C46EDD2AE184105AD8DFE6DBAB09518@gmail.com> <85460AE2CB82419398FD17CAE64C4F09@gmail.com> <7433274E-6E71-4C14-80E3-AA18E1E4DCA9@odd-e.com> Message-ID: <4B7860996B184649A77D41198DE1160D@gmail.com> Sorry about that. I don't always jump on things like that, but this one was bugging me and I had the time so I just did it. That doesn't always happen :) I look forward to your future contributions. Cheers, David -- David Chelimsky Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Sunday, April 15, 2012 at 9:30 PM, Bas Vodde wrote: > > Hiya, > > Kewl, thanks! > > (To be honest, I was a bit disapointed as I was thinking of doing it myself and sending it to you :P) > > Anyways, much appreciated! > > Bas > > On 16-Apr-2012, at 10:14 AM, David Chelimsky wrote: > > > Actually I just went ahead and fixed it sans-bug report: https://github.com/rspec/rspec-mocks/commit/fb9c76c2e40b4b25f4dcc5de95f8c60319b6d9c1. It'll be fixed in the next release (2.10). > > > > Cheers, > > David > > > > -- > > David Chelimsky > > Sent with Sparrow > > > > On Sunday, April 15, 2012 at 4:48 PM, David Chelimsky wrote: > > > > > On Sunday, April 15, 2012 at 1:32 AM, Bas Vodde wrote: > > > > > > > > Hiya all, > > > > > > > > I've got a quick question related to RSpec. I was test-driving some code and ended up in an endless loop. I was surprised by this, but traced it down to the mock not failing on additional calls but only in the end. Let me explain. > > > > > > > > I was writing code like this: > > > > > > > > subject.wrapper.should_receive(:window_list).exactly(4).times.and_return { > > > > counter = counter + 1 > > > > counter >= 4 ? [ "new window" ] : [] > > > > } > > > > > > > > The idea was that it would call the code-block 4 times exactly and then return a new value (and thus stop calling it). As the code to implement wasn't there yet, it led to a recursive call. I had expected RSpec to stop after 4 calls though, as I had instructed the mock that I expected exactly 4 calls. > > > > > > > > I added a new test in RSpec itself in precision_counts_spec.rb: > > > > > > > > it "fails when a method is called more than n times, but fails within the method call" do > > > > @mock.should_receive(:random_call).exactly(1).times > > > > lambda do > > > > @mock.random_call > > > > @mock.random_call > > > > end.should raise_error(RSpec::Mocks::MockExpectationError) > > > > end > > > > > > > > which failed :( (or it failed to fail and therefore failed!) > > > > > > > > It would be nice if it would fail. Is there any reason for not failing already at this point in time? > > > > > > > > (I'm using RSpec 2.6-0. I quickly browsed the latest and didn't see this changed) > > > > > > > > Thanks, > > > > > > > > Bas > > > There is no philosophical reason for this to happen, and there are other types of failures that do fail-fast (e.g. obj.should_receive(:bar).with(1,2) fails immediately if it receives :bar with any other args). > > > > > > Please submit this to https://github.com/rspec/rspec-mocks/issues and I'll start looking into a fix. > > > > > > Cheers, > > > David > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org (mailto: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 Apr 16 02:42:19 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Apr 2012 21:42:19 -0500 Subject: [rspec-users] Smart mocks for ActiveRecord to speed up tests In-Reply-To: <4F8B8287.5030800@yahoo.com.br> References: <4F8879E6.5080102@yahoo.com.br> <9113B01EED7E405EBAB3CFA2784AE4ED@gmail.com> <4F8B8287.5030800@yahoo.com.br> Message-ID: <154E9023137C464D82489313FC226FB6@gmail.com> On Sunday, April 15, 2012 at 9:23 PM, Rodrigo Rosenfeld Rosas wrote: > Em 14-04-2012 10:11, David Chelimsky escreveu: > > On Friday, April 13, 2012 at 2:09 PM, Rodrigo Rosenfeld Rosas wrote: > > > Hello old friends, I'm getting back to Rails and Ruby programming full time again (Yay!) > > > > > > I've stopped doing Rails programming to work with Grails in 2009 after 2 years working with Rails due to a better job offer. > > > > > > Since then I've changed my job once more, but still on Grails, but I found a critical bug in Grails more than a week ago that didn't seem to get much attention and is affecting the production system I maintain: > > > > > > http://jira.grails.org/browse/GRAILS-8994 > > > > > > As I couldn't work around that bug and I can't see myself reading the Grails source code (a real mess!) I decided to take another approach that would allow me to get back to Rails programming. > > > > > > I created a Devise / Warden strategy to send the cookies to the current system and it will return me the current logged in user. So I can set up Nginx to proxy some requests affected by the Grails bug to this new Rails application. > > > > > > I've finished this action last Monday but when I was about to send all the hard work to the server lots of my directories were suddenly gone when I was using them. I still don't know what happened but I've replaced my hard-drive just in case, but it means I had to do all over again :( > > > > > > Anyway, now I got it back to work but testing a single action (an update/insert one) will take about a full second to run using RSpec and FactoryGirl. > > > > > > I really don't like Grails but they had a great feature for unit testing. They were able to mock their domain class (that is how they call their models) in such a way that they can perform most of the operations you can do on real objects. > > > > > > Of course it have another serious bug that will prevent me to use it in lots of cases: > > > > > > http://jira.grails.org/browse/GRAILS-8854 > > > > > > But the idea is great as it works seamlessly like in a memory database. > > > > > > So, I'd like to be able to keep my tests easy to read but avoid touching the database that much. > > > > > > But my controller spec rely on lots of the setting of ActiveRecord for my models, like maximum calculations in before callbacks, custom foreign keys and depends: :delete_all in some has_many associations. Also I do also need a user object that Devise will accept on its sign_in helper method. > > > > > > Is there any place I could read more about writing faster tests without getting crazy writing so many mocks manually. For example, mocking a Grails domain class in a unit test would be as easy as: > > > > > > @mock(User) > > > class UserTests... > > > > > > Then I'm able to do most operations using the Grails domain class API using the User mock. > > > > > > Is there something like this for Rails and Rspec? Is there some way that I could set up FactoryGirl to use those mocks instead of hitting the database when I want to? > > > > > > Am I going in the wrong direction here? If so, what would be the right direction? > > > > > > Thanks in advance. > > > > > > Glad to be part of the Ruby, Rails and Rspec community full-time again :D > > > > > > Cheers, > > > Rodrigo. > > You can use mock_model or stub_model to create model instances, or you can use FactoryGirl.build instead of FactoryGirl.create. Only mock_model will actually avoid db calls entirely (the others will still query for column names even if you don't save anything). > > > > Those techniques, however, don't help you with finders. You still have to stub any finders with the object generated by any of the aforementioned techniques: > > > > thing = mock_model(Thing) > > Thing.stub(:domain_specific_finder => [thing]) > > > > > I'm not sure what you're suggesting. For example, the first part of my controller action looks like this: > > instance = Model.where(id: params[:id]).first_or_initialize(parent_id: params[:parentId]) The controller is interacting with an ActiveRecord API on the model instead of a domain-specific-finder. I'd recommend wrapping this in a method on the model and then mocking _that_ method. > The spec starts with something like this: > > root = FactoryGirl.create :field, label: 'ROOT' > post 'action', parentId: root.id > > In the before/after Model callbacks there will be other kind of finders for the same class. Think I'd need to see more of the code to comment on this. > How would you suggest me to change this block to use FactoryGirl.build and mock Model? Use one or the other (they both serve a similar purpose). > Also, I couldn't find how to mock 'open' from 'open-uri', so I'm currently mocking my controller's action: > > controller.should_receive(:clear_fields_cache).exactly(3).times # 1 creation and 2 updates > > The action is implemented this way: > > require 'open-uri' > ... > private > def clear_fields_cache > open INTEGRATION_BASE_URL + 'clearModelCache', > 'Cookie' => authentication_cookie_string # includes JSESSIONID and rememberMe > end > > But maybe it would be a great idea to check for the specific URL and cookie handling and I could do so if I was able to mock the 'open' method from 'open-uri'. Any ideas on how to do that? I use https://github.com/chrisk/fakeweb for this sort of thing. It operates more like a stub than a message expectation. > > It's not pretty, but it's the best way I know of to get what you're after. I started a lib called stubble a few years back that attempted to address this more holistically (https://github.com/dchelimsky/stubble) but I never released it as a gem because there were just too many different ways to access model data via the ActiveRecord API and they don't all flow through a single part of the codebase that we can override in an extension. > > > > I agree with you. I've taken a look at the library but as you can see I'm using the new 'where' API and this probably will keep changing each new AR release... This is exactly why I like to wrap finders in domain-specific methods on the model :) > Also, in Grails case, the mocked domain classes are maintained alongside with the real classes, so there is little chance of them getting out of sync. But of course the mocks have some limitation, like not being able to deal with custom SQL fragments: > > http://grails.org/doc/latest/guide/testing.html#unitTestingDomains > > Other than that there are also some bugs when dealing with association ids. > > I never thought it would be easy to have something like this for ActiveRecord but once there is a long time since I last often worked with Rails, things might have changed ;) > > Thank you a lot for your input and glad to be talking to you again :) > > Cheers, > Rodrigo. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > http://rubyforge.org/mailman/listinfo/rspec-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Mon Apr 16 09:00:11 2012 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 16 Apr 2012 10:00:11 +0100 Subject: [rspec-users] Smart mocks for ActiveRecord to speed up tests In-Reply-To: <154E9023137C464D82489313FC226FB6@gmail.com> References: <4F8879E6.5080102@yahoo.com.br> <9113B01EED7E405EBAB3CFA2784AE4ED@gmail.com> <4F8B8287.5030800@yahoo.com.br> <154E9023137C464D82489313FC226FB6@gmail.com> Message-ID: On 16 Apr 2012, at 03:42, David Chelimsky wrote: > On Sunday, April 15, 2012 at 9:23 PM, Rodrigo Rosenfeld Rosas wrote: >> Em 14-04-2012 10:11, David Chelimsky escreveu: >>> >>> On Friday, April 13, 2012 at 2:09 PM, Rodrigo Rosenfeld Rosas wrote: >>>> Hello old friends, I'm getting back to Rails and Ruby programming full time again (Yay!) >>>> >>>> I've stopped doing Rails programming to work with Grails in 2009 after 2 years working with Rails due to a better job offer. >>>> >>>> Since then I've changed my job once more, but still on Grails, but I found a critical bug in Grails more than a week ago that didn't seem to get much attention and is affecting the production system I maintain: >>>> >>>> http://jira.grails.org/browse/GRAILS-8994 >>>> >>>> As I couldn't work around that bug and I can't see myself reading the Grails source code (a real mess!) I decided to take another approach that would allow me to get back to Rails programming. >>>> >>>> I created a Devise / Warden strategy to send the cookies to the current system and it will return me the current logged in user. So I can set up Nginx to proxy some requests affected by the Grails bug to this new Rails application. >>>> >>>> I've finished this action last Monday but when I was about to send all the hard work to the server lots of my directories were suddenly gone when I was using them. I still don't know what happened but I've replaced my hard-drive just in case, but it means I had to do all over again :( >>>> >>>> Anyway, now I got it back to work but testing a single action (an update/insert one) will take about a full second to run using RSpec and FactoryGirl. >>>> >>>> I really don't like Grails but they had a great feature for unit testing. They were able to mock their domain class (that is how they call their models) in such a way that they can perform most of the operations you can do on real objects. >>>> >>>> Of course it have another serious bug that will prevent me to use it in lots of cases: >>>> >>>> http://jira.grails.org/browse/GRAILS-8854 >>>> >>>> But the idea is great as it works seamlessly like in a memory database. >>>> >>>> So, I'd like to be able to keep my tests easy to read but avoid touching the database that much. >>>> >>>> But my controller spec rely on lots of the setting of ActiveRecord for my models, like maximum calculations in before callbacks, custom foreign keys and depends: :delete_all in some has_many associations. Also I do also need a user object that Devise will accept on its sign_in helper method. >>>> >>>> Is there any place I could read more about writing faster tests without getting crazy writing so many mocks manually. For example, mocking a Grails domain class in a unit test would be as easy as: >>>> >>>> @mock(User) >>>> class UserTests... >>>> >>>> Then I'm able to do most operations using the Grails domain class API using the User mock. >>>> >>>> Is there something like this for Rails and Rspec? Is there some way that I could set up FactoryGirl to use those mocks instead of hitting the database when I want to? >>>> >>>> Am I going in the wrong direction here? If so, what would be the right direction? >>>> >>>> Thanks in advance. >>>> >>>> Glad to be part of the Ruby, Rails and Rspec community full-time again :D >>>> >>>> Cheers, >>>> Rodrigo. >>> You can use mock_model or stub_model to create model instances, or you can use FactoryGirl.build instead of FactoryGirl.create. Only mock_model will actually avoid db calls entirely (the others will still query for column names even if you don't save anything). >>> >>> Those techniques, however, don't help you with finders. You still have to stub any finders with the object generated by any of the aforementioned techniques: >>> >>> thing = mock_model(Thing) >>> Thing.stub(:domain_specific_finder => [thing]) >> >> I'm not sure what you're suggesting. For example, the first part of my controller action looks like this: >> >> instance = Model.where(id: params[:id]).first_or_initialize(parent_id: params[:parentId]) > The controller is interacting with an ActiveRecord API on the model instead of a domain-specific-finder. I'd recommend wrapping this in a method on the model and then mocking _that_ method. >> The spec starts with something like this: >> >> root = FactoryGirl.create :field, label: 'ROOT' >> post 'action', parentId: root.id >> >> In the before/after Model callbacks there will be other kind of finders for the same class. > Think I'd need to see more of the code to comment on this. >> How would you suggest me to change this block to use FactoryGirl.build and mock Model? > Use one or the other (they both serve a similar purpose). >> Also, I couldn't find how to mock 'open' from 'open-uri', so I'm currently mocking my controller's action: >> >> controller.should_receive(:clear_fields_cache).exactly(3).times # 1 creation and 2 updates >> >> The action is implemented this way: >> >> require 'open-uri' >> ... >> private >> def clear_fields_cache >> open INTEGRATION_BASE_URL + 'clearModelCache', >> 'Cookie' => authentication_cookie_string # includes JSESSIONID and rememberMe >> end >> >> But maybe it would be a great idea to check for the specific URL and cookie handling and I could do so if I was able to mock the 'open' method from 'open-uri'. Any ideas on how to do that? > I use https://github.com/chrisk/fakeweb for this sort of thing. It operates more like a stub than a message expectation. >>> It's not pretty, but it's the best way I know of to get what you're after. I started a lib called stubble a few years back that attempted to address this more holistically (https://github.com/dchelimsky/stubble) but I never released it as a gem because there were just too many different ways to access model data via the ActiveRecord API and they don't all flow through a single part of the codebase that we can override in an extension. >> I agree with you. I've taken a look at the library but as you can see I'm using the new 'where' API and this probably will keep changing each new AR release... > This is exactly why I like to wrap finders in domain-specific methods on the model :) >> Also, in Grails case, the mocked domain classes are maintained alongside with the real classes, so there is little chance of them getting out of sync. But of course the mocks have some limitation, like not being able to deal with custom SQL fragments: >> >> http://grails.org/doc/latest/guide/testing.html#unitTestingDomains >> >> Other than that there are also some bugs when dealing with association ids. >> >> I never thought it would be easy to have something like this for ActiveRecord but once there is a long time since I last often worked with Rails, things might have changed ;) >> >> Thank you a lot for your input and glad to be talking to you again :) >> >> Cheers, >> Rodrigo. >> _______________________________________________ >> 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 What David said. There's a great rule of thumb from Steve Freeman and Nat Pryce, who invented mocking. They say: "Don't mock types you don't own" If your Thing inherits from ActiveRecord, you don't own it. That's why it's hard to mock, because the ActiveRecord API is very generic and has nothing to do with your domain. That's also why it's a bad idea to add anything more than skeletal behaviour to it. Instead, I'd suggest you add behaviour to a PORO adapter or wrapper around the ActiveRecord model that makes sense in your domain, and can therefore be easily mocked. cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book Founder, http://www.relishapp.com/ Twitter, https://twitter.com/mattwynne -------------- next part -------------- An HTML attachment was scrubbed... URL: From lbocseg at yahoo.com.br Mon Apr 16 12:27:14 2012 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Mon, 16 Apr 2012 09:27:14 -0300 Subject: [rspec-users] Smart mocks for ActiveRecord to speed up tests In-Reply-To: References: <4F8879E6.5080102@yahoo.com.br> <9113B01EED7E405EBAB3CFA2784AE4ED@gmail.com> <4F8B8287.5030800@yahoo.com.br> <154E9023137C464D82489313FC226FB6@gmail.com> Message-ID: <4F8C1022.8020109@yahoo.com.br> Thank you David and Matt for your comments. Indeed I had considered using FakeWeb but I thought that maybe there could be an easier way just to mock 'open' directly since I guess it would be faster to run. With regards to the work around to overcome the issue with mocking AR so that I could speed up my tests I think that creating helpers in the model that will restrict the use of the AR API sounds like a good balance, but that wouldn't make my specific tests faster. Here is why: my Model class shouldn't be created or updated by any other code in my application. So I'd just have to add a new method to the Model class that would be specific to this action and I'd need to write a "unit" test for this new method. I quoted "unit" because it is actually an integration test as it will touch the database or otherwise I wouldn't be able to upgrade Rails to a new version if I'm mocking some methods from AR and they change in a future version. So I'd need to touch the database anyway and my 9 specs would still take almost a full second to run while this specific controller spec takes about 0.7s (up to 2s depending on my system load). Well, actually, I guess RSpec has changed the way it measure spec runs since I last used it. I'm saying that because it will report me from 0.7 to 2s when I run "rspec path/to/my_controller_spec.rb", but if I run "rspec --profile" it will run the full suite about the same time and this specific controller action will take 0.38s. Anyway, I don't see how I would create hundreds of specs and expect them to run in a few seconds and still have a reliable test suite. I mean, I want to feel safe if I'm upgrading to a newer Rails version even if it changed its AR API. The only real improvements I can see for my tests running fasts without changing anything in the specs is to use something like Hydra so that I could use the full power of my 6-core processor. Does RSpec has a built-in threaded option? I guess not because I don't think it would be much effective on CRuby because it would probably lock on database access (or maybe not, I don't know how the pg driver is implemented). For my particular application I suspect it is not cpu-heavy, but io-expensive instead. So maybe a multi-thread spec runner could improve its performance when running multiple specs. Best, Rodrigo. From lbocseg at yahoo.com.br Mon Apr 16 17:17:30 2012 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Mon, 16 Apr 2012 14:17:30 -0300 Subject: [rspec-users] Smart mocks for ActiveRecord to speed up tests In-Reply-To: <4F8C1022.8020109@yahoo.com.br> References: <4F8879E6.5080102@yahoo.com.br> <9113B01EED7E405EBAB3CFA2784AE4ED@gmail.com> <4F8B8287.5030800@yahoo.com.br> <154E9023137C464D82489313FC226FB6@gmail.com> <4F8C1022.8020109@yahoo.com.br> Message-ID: <4F8C542A.3090302@yahoo.com.br> Em 16-04-2012 09:27, Rodrigo Rosenfeld Rosas escreveu: > Thank you David and Matt for your comments. > > Indeed I had considered using FakeWeb but I thought that maybe there > could be an easier way just to mock 'open' directly since I guess it > would be faster to run. > > With regards to the work around to overcome the issue with mocking AR > so that I could speed up my tests I think that creating helpers in the > model that will restrict the use of the AR API sounds like a good > balance, but that wouldn't make my specific tests faster. > > Here is why: my Model class shouldn't be created or updated by any > other code in my application. So I'd just have to add a new method to > the Model class that would be specific to this action and I'd need to > write a "unit" test for this new method. I quoted "unit" because it is > actually an integration test as it will touch the database or > otherwise I wouldn't be able to upgrade Rails to a new version if I'm > mocking some methods from AR and they change in a future version. > > So I'd need to touch the database anyway and my 9 specs would still > take almost a full second to run while this specific controller spec > takes about 0.7s (up to 2s depending on my system load). > > Well, actually, I guess RSpec has changed the way it measure spec runs > since I last used it. I'm saying that because it will report me from > 0.7 to 2s when I run "rspec path/to/my_controller_spec.rb", but if I > run "rspec --profile" it will run the full suite about the same time > and this specific controller action will take 0.38s. > > Anyway, I don't see how I would create hundreds of specs and expect > them to run in a few seconds and still have a reliable test suite. I > mean, I want to feel safe if I'm upgrading to a newer Rails version > even if it changed its AR API. > > The only real improvements I can see for my tests running fasts > without changing anything in the specs is to use something like Hydra > so that I could use the full power of my 6-core processor. > > Does RSpec has a built-in threaded option? I guess not because I don't > think it would be much effective on CRuby because it would probably > lock on database access (or maybe not, I don't know how the pg driver > is implemented). For my particular application I suspect it is not > cpu-heavy, but io-expensive instead. So maybe a multi-thread spec > runner could improve its performance when running multiple specs. > > Best, > Rodrigo. > After some more investigation I could find out why it is taking so much time for the spec to run. Even for a simple model, calling a single "Model.create! name: 'Model name'" will take almost 100ms. So, here is usually what happens: root = FactoryGirl.create :model # 2 creates: # section = Section.create! name: 'Section' # root = Model.create! section: section, label: 'Label' post 'action', parent_id: root.id # another Model creation in the controller alongside with 2 other creations of a has_many association So, without counting any assertions just for creating all records so far about 400ms were already spent. There will also be about 2 more updates and 2 "delete" statements in this spec and that will complete about 540ms of total spec run time. Another interesting fact is that for measuring this I've mocked the user and controller authentication related methods, but if I actually create the user the time for completing the spec will be about the same, even if in the logs it is reported to spend about 70ms for executing the insert in the user's table. But I don't think it should take so much time for creating/updating those records. See the output of the logging, for example: Completed 200 OK in 83ms (Views: 0.6ms | ActiveRecord: 14.9ms) This is consistent with the individual timing for each query/insert statement including validations. Even so, the first 'post' method call in the spec takes about 100ms. So, my question is, if AR and Views are taking about 16ms what else could be taking about 70ms? This is also hard to profile since PostgreSQL will need more time for the first queries and will be much faster for subsequent ones... This means that running all specs will take much less time than if I run each spec separately and compare to the total time. But I don't really think I'll be able to test this action faster. I need to check for all created records including associations and fields set by the before_validation and removed by after_save so that I can get confidence in the code. And since all of this should only happen through this action, it wouldn't matter if I moved lots of those checks to the "unit" test of my Model as the total time would remain the same. It would only make my specs harder to read with lots of mocks and stubbed methods in my controller spec. I mean, that is ok, I don't aim in having single assertions per unit test. I just need to make sure things won't break in a future refactoring or requirement changes. And of course I'd like my tests to run faster, but my current understanding is that I can't get this test to run faster because it is testing a lot of code. Of course that an in-memory AR adapter could help me speeding up my tests but using mocks here won't give me any confidence on my code base. Usually slow tests are not a problem when I'm working in some controller as I don't need to run the full suite. But when I change some model or library it would be great to run the full suite and I'm a bit worried if that will become super slow some time in the future. But I think I'll start to worry about this when this future becomes present because there is no easy replacement that will allow my specs to run faster. I'll still be able to try Hydra before having to resort to mocks if things get really unsustainable. But thank you very much for your input on the subject. I was just worried if I was doing something fundamentally wrong. Cheers, Rodrigo. From nas35_in at yahoo.com Tue Apr 17 19:30:05 2012 From: nas35_in at yahoo.com (Nasir Jamal) Date: Tue, 17 Apr 2012 12:30:05 -0700 (PDT) Subject: [rspec-users] Access controller object in controller macro Message-ID: <1334691005.24037.YahooMailNeo@web162602.mail.bf1.yahoo.com> Hi We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. 1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. module ControllerMacros ? def imaginary_method_with_example_calls ???? # in actual code different methods call one of the below, this is just an example of things not working ? ? controller.stubs(:method) ??? controller.class.skip_before_filter(:name) ??? session[:user_id] = user.id ??? response.something ? end end But now after upgrading to Rspec 2.6 they do not work and calling controller just returns nil and hence undefined method 'skip_before_filter' for NilClass error. I did google but found nothing regarding this. 2) Changing 'request.request_uri' to 'request.full_path' raises the following error when running rspec NoMethodError: ?????? undefined method `full_path' for # Any help / suggestion would be really helpful. Kind regards, Nas -------------- next part -------------- An HTML attachment was scrubbed... URL: From lucianosantosborges at gmail.com Wed Apr 18 00:50:57 2012 From: lucianosantosborges at gmail.com (Luciano Borges) Date: Tue, 17 Apr 2012 21:50:57 -0300 Subject: [rspec-users] [Newbie's Doubt] Model's Tests Message-ID: I'm studying Rspec and doing some model's tests. I have a table with a field which must have two characters, the field should not be empty and can not be repeated. My doubts is with #. describe State do context "validations" do it "The abbreviation should not be empty" do subject.abbreviation = nil subject.should_not be_valid end *# I can do like example below or I have to break in parts?* it "The abbreviation should have 2 characters" do subject.abbreviation = "BA" subject.should be_valid subject.abbreviation = "B" subject.should_not be_valid subject.abbreviation = "BAA" subject.should_not be_valid end it "The abbreviation can not be repeated" do * # I don't know how to do!* end end end Thanks, Luciano -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian at leviston.net Wed Apr 18 01:01:40 2012 From: julian at leviston.net (Julian Leviston) Date: Wed, 18 Apr 2012 11:01:40 +1000 Subject: [rspec-users] [Newbie's Doubt] Model's Tests In-Reply-To: References: Message-ID: What do you mean repeated? You mean you can't have an abbreviation with two of the same letters? Julian On 18/04/2012, at 10:50 AM, Luciano Borges wrote: > I'm studying Rspec and doing some model's tests. > > I have a table with a field which must have two characters, the field should not be empty and can not be repeated. > > My doubts is with #. > > describe State do > context "validations" do > > it "The abbreviation should not be empty" do > subject.abbreviation = nil > subject.should_not be_valid > end > > # I can do like example below or I have to break in parts? > > it "The abbreviation should have 2 characters" do > subject.abbreviation = "BA" > subject.should be_valid > > subject.abbreviation = "B" > subject.should_not be_valid > > subject.abbreviation = "BAA" > subject.should_not be_valid > end > > it "The abbreviation can not be repeated" do > > # I don't know how to do! > > end > end > end > > Thanks, > Luciano > _______________________________________________ > 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 lucianosantosborges at gmail.com Wed Apr 18 01:11:05 2012 From: lucianosantosborges at gmail.com (Luciano Borges) Date: Tue, 17 Apr 2012 22:11:05 -0300 Subject: [rspec-users] [Newbie's Doubt] Model's Tests In-Reply-To: References: Message-ID: 2012/4/17 Julian Leviston > What do you mean repeated? You mean you can't have an abbreviation with > two of the same letters? > > Julian > Hi Julian, Yes. I cat't have the same abbreviation on the table, I know that I have to put the validation in the model, but, I'd like to test first before change my model. Luciano -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian at leviston.net Wed Apr 18 01:30:50 2012 From: julian at leviston.net (Julian Leviston) Date: Wed, 18 Apr 2012 11:30:50 +1000 Subject: [rspec-users] [Newbie's Doubt] Model's Tests In-Reply-To: References: Message-ID: oh you mean a check for uniqueness. Is this rails? If it is, pretty sure you can do this: item = Item.create(:abbreviation => "ab") duplicate_item = Item.create(:abbreviation => "ab") duplicate_item.new_record?.should_be true or item = Item.new(:abbreviation => "ab") item.should_be valid item.save duplicate_item = Item.new(:abbreviation => "ab") duplicate_item.should_not be_valid On 18/04/2012, at 11:11 AM, Luciano Borges wrote: > 2012/4/17 Julian Leviston > What do you mean repeated? You mean you can't have an abbreviation with two of the same letters? > > Julian > > Hi Julian, > > Yes. I cat't have the same abbreviation on the table, I know that I have to put the validation in the model, but, I'd like to test first before change my model. > > Luciano > _______________________________________________ > 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 lenny at aps.org Wed Apr 18 01:52:14 2012 From: lenny at aps.org (Lenny Marks) Date: Tue, 17 Apr 2012 21:52:14 -0400 Subject: [rspec-users] [Newbie's Doubt] Model's Tests In-Reply-To: References: Message-ID: <12FB4A88-4F4B-4FD1-9886-8873AAA2E9EC@aps.org> Sorry! My posts are very delayed. On Apr 17, 2012, at 8:50 PM, Luciano Borges wrote: > I'm studying Rspec and doing some model's tests. > > I have a table with a field which must have two characters, the field should not be empty and can not be repeated. > > My doubts is with #. > > describe State do > context "validations" do > > it "The abbreviation should not be empty" do > subject.abbreviation = nil > subject.should_not be_valid > end > > # I can do like example below or I have to break in parts? > > it "The abbreviation should have 2 characters" do > subject.abbreviation = "BA" > subject.should be_valid > > subject.abbreviation = "B" > subject.should_not be_valid > > subject.abbreviation = "BAA" > subject.should_not be_valid > end > Hadn't seen your entity was State before. You meant abbreviation must be 2 characters and must be unique within the table. Anyway... my previous post still partially relevant for the example above. > it "The abbreviation can not be repeated" do > > # I don't know how to do! > > end for unique constraints, I use something like below describe 'code' do .... it 'should be unique' do attributes = @valid_attributes.merge(:code => 'foo') AgeLevel.create!(attributes) AgeLevel.new(attributes).should_not be_valid end -lenny > end > end > > Thanks, > Luciano > _______________________________________________ > 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 lenny at aps.org Wed Apr 18 01:33:57 2012 From: lenny at aps.org (Lenny Marks) Date: Tue, 17 Apr 2012 21:33:57 -0400 Subject: [rspec-users] [Newbie's Doubt] Model's Tests In-Reply-To: References: Message-ID: On Apr 17, 2012, at 8:50 PM, Luciano Borges wrote: > I'm studying Rspec and doing some model's tests. > > I have a table with a field which must have two characters, the field should not be empty and can not be repeated. > > My doubts is with #. > > describe State do > context "validations" do > > it "The abbreviation should not be empty" do > subject.abbreviation = nil > subject.should_not be_valid > end > > # I can do like example below or I have to break in parts? > > it "The abbreviation should have 2 characters" do > subject.abbreviation = "BA" > subject.should be_valid > > subject.abbreviation = "B" > subject.should_not be_valid > > subject.abbreviation = "BAA" > subject.should_not be_valid > end > > it "The abbreviation can not be repeated" do > > # I don't know how to do! > > end > end > end With things like the above, I usually want the rule, followed by some examples. I usually approach like below. Its nice to have it all right in the specdoc. describe 'validations' do .... describe 'abbreviation', 'must be two unique characters' do specify 'AB is valid' do subject.abbreviation = 'AB' subject.should be_valid end specify 'A is not valid' do subject.abbreviation = 'A' subject.should_not be_valid end specify 'BAA is not valid' do subject.abbreviation = 'BAA' subject.should_not be_valid end I think it would be overkill for the above, but sometimes if I'm throwing lots of examples at something (e.g. email address validation), I'll use a macro like below. describe 'abbreviation', 'must be two unique characters' do def self.it_is_valid(abbreviation) specify "#{abbreviation} is valid" do subject.abbreviation = abbreviation subject.should be_valid end end ..... it_is_valid('AB') it_is_valid('BA') it_is_not_valid('AA') it_is_not_valid('BAA') ..... -lenny > > Thanks, > Luciano > _______________________________________________ > 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 mcbsystems at gmail.com Wed Apr 18 04:11:07 2012 From: mcbsystems at gmail.com (Mark Berry) Date: Tue, 17 Apr 2012 21:11:07 -0700 Subject: [rspec-users] One error reported recursively if two pages visited by request spec Message-ID: Hi, I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. I've been getting recursive errors, where one error is reported multiple times. It's quite spectacular in a long suite, with the errors overflowing the console buffer. I've whittled down a simple example: require 'spec_helper' describe "public pages" do subject { page } describe "details page" do before do visit root_path end describe "when visiting a second page before example" do before { visit sign_in_path } it { should have_link("Sign in") } end end end The error here is that "sign_in_path" should really be "signin_path". But I get that error five times, and when I run with --format documentation, it looks like RSpec is generating it recursively before it "blows up" with a stack trace (see output below). Obviously this test doesn't really need two before blocks, but sometimes I do want to visit two pages before a test. Am I doing something wrong, or is this a bug? Mark Berry ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Test output: [myproject (tests)]$ rspec spec/requests/test2* --format documentation No DRb server is running. Running in local process instead ... public pages details page when no user is signed in when visiting a second page before example when visiting a second page before example when no user is signed in when visiting a second page before example details page when no user is signed in when visiting a second page before example Failures: 1) public pages details page when no user is signed in when visiting a second page before example Failure/Error: before { visit sign_in_path } NameError: undefined local variable or method `sign_in_path' for # # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in ' 2) public pages details page when no user is signed in when visiting a second page before example Failure/Error: before { visit sign_in_path } NameError: undefined local variable or method `sign_in_path' for # # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in ' 3) public pages details page when no user is signed in when visiting a second page before example Failure/Error: before { visit sign_in_path } NameError: undefined local variable or method `sign_in_path' for # # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in ' 4) public pages details page when no user is signed in when visiting a second page before example Failure/Error: before { visit sign_in_path } NameError: undefined local variable or method `sign_in_path' for # # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in ' 5) public pages details page when no user is signed in when visiting a second page before example Failure/Error: before { visit sign_in_path } NameError: undefined local variable or method `sign_in_path' for # # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in ' Finished in 0.33725 seconds 5 examples, 5 failures Failed examples: rspec ./spec/requests/test2_pages_spec.rb:18 # public pages details page when no user is signed in when visiting a second page before example rspec ./spec/requests/test2_pages_spec.rb:18 # public pages details page when no user is signed in when visiting a second page before example rspec ./spec/requests/test2_pages_spec.rb:18 # public pages details page when no user is signed in when visiting a second page before example rspec ./spec/requests/test2_pages_spec.rb:18 # public pages details page when no user is signed in when visiting a second page before example rspec ./spec/requests/test2_pages_spec.rb:18 # public pages details page when no user is signed in when visiting a second page before example /home/myuser/.rvm/gems/ruby-1.9.3-p0 at myproject/gems/activesupport-3.1.3/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `strip' for nil:NilClass (NoMethodError) from /home/myuser/.rvm/gems/ruby-1.9.3-p0 at myproject/gems/rspec-core-2.9.0/lib/rspec/core/formatters/documentation_formatter.rb:41:in `failure_output' from /home/myuser/.rvm/gems/ruby-1.9.3-p0 at myproject/gems/rspec-core-2.9.0/lib/rspec/core/formatters/documentation_formatter.rb:37:in `example_failed' from /home/myuser/.rvm/gems/ruby-1.9.3-p0 at myproject/gems/rspec-core-2.9.0/lib/rspec/core/reporter.rb:98:in `block in notify' ... From jko170 at gmail.com Wed Apr 18 08:34:36 2012 From: jko170 at gmail.com (Justin Ko) Date: Wed, 18 Apr 2012 02:34:36 -0600 Subject: [rspec-users] Access controller object in controller macro In-Reply-To: <1334691005.24037.YahooMailNeo@web162602.mail.bf1.yahoo.com> References: <1334691005.24037.YahooMailNeo@web162602.mail.bf1.yahoo.com> Message-ID: <518C2743-A8D8-4980-8A64-AD4B8F8082F8@gmail.com> On Apr 17, 2012, at 1:30 PM, Nasir Jamal wrote: > > Hi > > We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. > > 1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. > > module ControllerMacros > def imaginary_method_with_example_calls > # in actual code different methods call one of the below, this is just an example of things not working > controller.stubs(:method) > controller.class.skip_before_filter(:name) > session[:user_id] = user.id > response.something > end > end > > But now after upgrading to Rspec 2.6 they do not work and calling controller just returns nil and hence undefined method 'skip_before_filter' for NilClass error. I did google but found nothing regarding this. > > 2) Changing 'request.request_uri' to 'request.full_path' raises the following error when running rspec > NoMethodError: > undefined method `full_path' for # > > Any help / suggestion would be really helpful. > > Kind regards, > > Nas > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I assume your app directory looks like this? app_root/spec/controllers/my_controller_spec.rb And you are running the specs from the *app_root*? How are you including this module? -------------- next part -------------- An HTML attachment was scrubbed... URL: From nas35_in at yahoo.com Wed Apr 18 08:59:09 2012 From: nas35_in at yahoo.com (Nasir Jamal) Date: Wed, 18 Apr 2012 01:59:09 -0700 (PDT) Subject: [rspec-users] Access controller object in controller macro In-Reply-To: <518C2743-A8D8-4980-8A64-AD4B8F8082F8@gmail.com> References: <1334691005.24037.YahooMailNeo@web162602.mail.bf1.yahoo.com> <518C2743-A8D8-4980-8A64-AD4B8F8082F8@gmail.com> Message-ID: <1334739549.63935.YahooMailNeo@web162601.mail.bf1.yahoo.com> Hi Justin Yes, the specs are in app_root/spec/controllers/ and we running the specs from app_root. We are including the macros like so: RSpec.configure do |config| ??? config.include(ControllerMacros, :type => :controller) end Kind regards, Nas ________________________________ From: Justin Ko To: Nasir Jamal ; rspec-users Sent: Wednesday, 18 April 2012, 9:34 Subject: Re: [rspec-users] Access controller object in controller macro On Apr 17, 2012, at 1:30 PM, Nasir Jamal wrote: >Hi > >We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. > >1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. > >module ControllerMacros >? def imaginary_method_with_example_calls >???? # in actual code different methods call one of the below, this is just an example of things not working >? ? controller.stubs(:method) >??? controller.class.skip_before_filter(:name) >??? session[:user_id] = user.id >??? response.something >? end >end > >But now after upgrading to Rspec 2.6 they do not work and calling controller just returns nil and hence undefined method 'skip_before_filter' for NilClass error. I did google but found nothing regarding this. > >2) Changing 'request.request_uri' to 'request.full_path' raises the following error when running rspec >NoMethodError: >?????? undefined method `full_path' for # > >Any help / suggestion would be really helpful. > >Kind regards, > >Nas >_______________________________________________ >rspec-users mailing list >rspec-users at rubyforge.org >http://rubyforge.org/mailman/listinfo/rspec-users I assume your app directory looks like this? app_root/spec/controllers/my_controller_spec.rb And you are running the specs from the *app_root*? How are you including this module? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Apr 18 12:35:23 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Apr 2012 07:35:23 -0500 Subject: [rspec-users] One error reported recursively if two pages visited by request spec In-Reply-To: References: Message-ID: <494F3FE8582A4B558DD158FEC4A5A0BF@gmail.com> On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote: > Hi, > > I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. > > I've been getting recursive errors, where one error is reported > multiple times. It's quite spectacular in a long suite, with the > errors overflowing the console buffer. I've whittled down a simple > example: > > require 'spec_helper' > describe "public pages" do > subject { page } > describe "details page" do > before do > visit root_path > end > describe "when visiting a second page before example" do > before { visit sign_in_path } > it { should have_link("Sign in") } > end > end > end > > The error here is that "sign_in_path" should really be "signin_path". > But I get that error five times, and when I run with --format > documentation, it looks like RSpec is generating it recursively before > it "blows up" with a stack trace (see output below). > > Obviously this test doesn't really need two before blocks, but > sometimes I do want to visit two pages before a test. > > Am I doing something wrong, or is this a bug? > > Mark Berry > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Test output: > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > No DRb server is running. Running in local process instead ... > > public pages > details page > when no user is signed in > when visiting a second page before example > when visiting a second page before example > when no user is signed in > when visiting a second page before example > details page > when no user is signed in > when visiting a second page before example > > Failures: > > 1) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 2) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 3) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 4) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 5) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > > This is what I would expect. There is nothing "recursive" about this. There is a failure in a before block that runs before every example. It's the same as if you had the same broken code directly in each example. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Apr 18 12:42:24 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Apr 2012 07:42:24 -0500 Subject: [rspec-users] Access controller object in controller macro In-Reply-To: <1334691005.24037.YahooMailNeo@web162602.mail.bf1.yahoo.com> References: <1334691005.24037.YahooMailNeo@web162602.mail.bf1.yahoo.com> Message-ID: On Tuesday, April 17, 2012 at 2:30 PM, Nasir Jamal wrote: > > Hi > > We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. > > 1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. > > module ControllerMacros > def imaginary_method_with_example_calls > # in actual code different methods call one of the below, this is just an example of things not working > controller.stubs(:method) > controller.class.skip_before_filter(:name) > session[:user_id] = user.id > response.something > end > end > > But now after upgrading to Rspec 2.6 they do not work and calling controller just returns nil and hence undefined method 'skip_before_filter' for NilClass error. I did google but found nothing regarding this. Is imaginary_method_with_example_calls called in a config.before hook? If so, the issue is that controller is nil [1]. This has been fixed on master, but not yet released (look for the 2.10 release in the next couple of weeks. > 2) Changing 'request.request_uri' to 'request.full_path' raises the following error when running rspec > NoMethodError: > undefined method `full_path' for # I'd check the rails docs for this one. I'm not immediately familiar w/ what's going on. HTH, David [1] https://github.com/rspec/rspec-rails/issues/391 -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Apr 18 14:06:47 2012 From: lists at ruby-forum.com (Justin Funk) Date: Wed, 18 Apr 2012 16:06:47 +0200 Subject: [rspec-users] Testing parameter passed to controller new method (undefined method 'stringify_keys') Message-ID: <8556bea29a7226f42792119ad4225105@ruby-forum.com> I'm trying to test passing a parameter to the new method of my controller and am coming up with the "undefined method 'stringify_keys'" error when I use this code: get "new", { :company_id => '1' } I have seen other solutions to this issue, but they have all centered around the create method and either using FactoryGirl.attributes_for or making a deeper hash like { :object => { :company_id => 1 } }. I don't think either of these solutions are appropriate. The logic I'm using involves CanCan, where I don't want the user to be able to load up the 'new' page unless they've got a valid company id. If the only way to do what I want really is to use the full object hash, then I need an update for my view test which is validating the new link, currently like so: rendered.should have_selector 'a', :content => 'Add Object', :href => '/menus/new?company_id=' + company.id.to_s I'm using Rails 3.2.3 and rspec 2.9 -- Posted via http://www.ruby-forum.com/. From mcbsystems at gmail.com Wed Apr 18 21:30:00 2012 From: mcbsystems at gmail.com (Mark Berry) Date: Wed, 18 Apr 2012 14:30:00 -0700 Subject: [rspec-users] One error reported recursively if two pages visited by request spec Message-ID: >On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote: >On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote: >> Hi, >> >> I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. >> >> I've been getting recursive errors, where one error is reported >> multiple times. It's quite spectacular in a long suite, with the >> errors overflowing the console buffer. I've whittled down a simple >> example: >> >> require 'spec_helper' >> describe "public pages" do >> subject { page } >> describe "details page" do >> before do >> visit root_path >> end >> describe "when visiting a second page before example" do >> before { visit sign_in_path } >> it { should have_link("Sign in") } >> end >> end >> end >> >> The error here is that "sign_in_path" should really be "signin_path". >> But I get that error five times, and when I run with --format >> documentation, it looks like RSpec is generating it recursively before >> it "blows up" with a stack trace (see output below). >> >> Obviously this test doesn't really need two before blocks, but >> sometimes I do want to visit two pages before a test. >> >> Am I doing something wrong, or is this a bug? >> >> Mark Berry >> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> Test output: >> >> [myproject (tests)]$ rspec spec/requests/test2* --format documentation >> No DRb server is running. Running in local process instead ... >> >> public pages >> details page >> when no user is signed in >> when visiting a second page before example >> when visiting a second page before example >> when no user is signed in >> when visiting a second page before example >> details page >> when no user is signed in >> when visiting a second page before example >> >> Failures: >> >> 1) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> 2) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> 3) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> 4) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> 5) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> >> >This is what I would expect. There is nothing "recursive" about this. There is a failure in >a before block that runs before every example. It's the same as if you had the same >broken code directly in each example. >HTH, >David [Sorry if this starts a new thread. I was attempting to monitor and reply to the group through Google Groups, but apparently that mirror stopped working on April 10, so I'm having to reconstruct this reply.] Thanks for the reply. Although the output says "5 examples, 5 failures," there is only one example, hence my confusion about it failing five times. Also, the "documentation" output lists each describe block (except the first) two to four times. When I fix the error, I get one line per describe, plus one example completed, as expected: [myproject (tests)]$ rspec spec/requests/test2* --format documentation public pages details page when visiting a second page before example should has link "Sign in" Finished in 1.44 seconds 1 example, 0 failures I have since discovered that the problem only occurs when using "--format documentation". Without that, with the error back in place, RSpec only gives me one error, not five: [myproject (tests)]$ rspec spec/requests/test2* F Failures: 1) public pages details page when visiting a second page before example Failure/Error: before { visit sign_in_path } NameError: undefined local variable or method `sign_in_path' for # # ./spec/requests/test2_pages_spec.rb:9:in `block (4 levels) in ' Finished in 1.07 seconds 1 example, 1 failure Failed examples: rspec ./spec/requests/test2_pages_spec.rb:10 # public pages details page when visiting a second page before example Does that clarify the issue? Mark Berry From nas35_in at yahoo.com Wed Apr 18 21:34:18 2012 From: nas35_in at yahoo.com (Nasir Jamal) Date: Wed, 18 Apr 2012 14:34:18 -0700 (PDT) Subject: [rspec-users] rspec-users Digest, Vol 70, Issue 13 In-Reply-To: References: Message-ID: <1334784858.13201.YahooMailNeo@web162605.mail.bf1.yahoo.com> David First issue temporarily sorted by using the 'include' for now until?2.10 comes out. Please ignore the second issue because while doing find and replace I did "full_path" instead of "fullpath". My bad, apologies for that. Kind regards, Nas Date: Wed, 18 Apr 2012 01:59:09 -0700 (PDT) From: Nasir Jamal To: Justin Ko , rspec-users ??? Subject: Re: [rspec-users] Access controller object in controller ??? macro Message-ID: ??? <1334739549.63935.YahooMailNeo at web162601.mail.bf1.yahoo.com> Content-Type: text/plain; charset="iso-8859-1" Date: Wed, 18 Apr 2012 07:42:24 -0500 From: David Chelimsky To: rspec-users Subject: Re: [rspec-users] Access controller object in controller ??? macro Message-ID: Content-Type: text/plain; charset="utf-8" On Tuesday, April 17, 2012 at 2:30 PM, Nasir Jamal wrote: > > Hi > > We have just upgraded our Rails 2.3.11 app to Rails 3.0.0 and Rspec 1.3.2 to 2.6. We are having two problems with rspec currently and any help would be great. > > 1) We have some controller macros where we have been using the controller object, session hash, response, etc. in different methods for e.g. > > module ControllerMacros >? def imaginary_method_with_example_calls >? ? ? # in actual code different methods call one of the below, this is just an example of things not working >? ? controller.stubs(:method) >? ? controller.class.skip_before_filter(:name) >? ? session[:user_id] = user.id >? ? response.something >? end > end > > But now after upgrading to Rspec 2.6 they do not work and calling controller just returns nil and hence undefined method 'skip_before_filter' for NilClass error. I did google but found nothing regarding this. Is imaginary_method_with_example_calls called in a config.before hook? If so, the issue is that controller is nil [1]. This has been fixed on master, but not yet released (look for the 2.10 release in the next couple of weeks. > 2) Changing 'request.request_uri' to 'request.full_path' raises the following error when running rspec > NoMethodError: >? ? ? ? undefined method `full_path' for # I'd check the rails docs for this one. I'm not immediately familiar w/ what's going on. HTH, David [1] https://github.com/rspec/rspec-rails/issues/391 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Thu Apr 19 00:01:32 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 18 Apr 2012 17:01:32 -0700 (PDT) Subject: [rspec-users] how can I get prettier failure messages for integration specs? Message-ID: When an integration test fails, I get a whole mess of garbage that is all in red, very painful to the eyes-- Especially when I quickly just want to see what went wrong-- in this case, all I want to see is ActiveRecord::RecondNotFound-- but instead I see: Failure/Error: page.should have_content "Submit Payment" expected there to be content "Submit Payment" in "Action Controller: Exception caught\n body { background-color: #fff; color: #333; }\n\n body, p, ol, ul, td {\n font-family: helvetica, verdana, arial, sans-serif;\n font-size: 13px;\n line-height: 18px;\n }\n\n pre {\n background-color: #eee;\n padding: 10px;\n font-size: 11px;\n white-space: pre-wrap;\n }\n\n a { color: #000; }\n a:visited { color: #666; }\n a:hover { color: #fff; background-color:#000; }\n \n\n\n ActiveRecord::RecordNotFound\n ... bla bla bla bla bla bla forever. ...... Are there any options to reformat this output? A small improvement would be to actually turn \n into actual new lines... However, an even better option would be to make this automatically launch the browser so that the error page could be read properly. Is this possible? Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Thu Apr 19 02:58:26 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Apr 2012 21:58:26 -0500 Subject: [rspec-users] how can I get prettier failure messages for integration specs? In-Reply-To: References: Message-ID: <8EA5F19F31DE40E591713738A45264D4@gmail.com> On Wednesday, April 18, 2012 at 7:01 PM, Patrick J. Collins wrote: > When an integration test fails, I get a whole mess of garbage that is > all in red, very painful to the eyes-- Especially when I quickly just > want to see what went wrong-- in this case, all I want to see is > ActiveRecord::RecondNotFound-- but instead I see: > > Failure/Error: page.should have_content "Submit Payment" > expected there to be content "Submit Payment" in "Action > Controller: Exception caught\n body { background-color: #fff; color: > #333; }\n\n body, p, ol, ul, td {\n font-family: helvetica, > verdana, arial, sans-serif;\n font-size: 13px;\n > line-height: 18px;\n }\n\n pre {\n background-color: #eee;\n > padding: 10px;\n font-size: 11px;\n white-space: pre-wrap;\n > }\n\n a { color: #000; }\n a:visited { color: #666; }\n a:hover > { color: #fff; background-color:#000; }\n \n\n\n > ActiveRecord::RecordNotFound\n ... bla bla bla bla bla bla forever. > > ...... Are there any options to reformat this output? A small > improvement would be to actually turn \n into actual new lines... > However, an even better option would be to make this automatically > launch the browser so that the error page could be read properly. > > Is this possible? If you're using capybara you could put save_and_open_page in an after hook. You'd still get the console output, but at least you'd see the page in a browser. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Apr 19 03:09:57 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Apr 2012 22:09:57 -0500 Subject: [rspec-users] One error reported recursively if two pages visited by request spec In-Reply-To: References: Message-ID: On Wednesday, April 18, 2012 at 4:30 PM, Mark Berry wrote: > > On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote: > > On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote: > > > Hi, > > > > > > I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. > > > > > > I've been getting recursive errors, where one error is reported > > > multiple times. It's quite spectacular in a long suite, with the > > > errors overflowing the console buffer. I've whittled down a simple > > > example: > > > > > > require 'spec_helper' > > > describe "public pages" do > > > subject { page } > > > describe "details page" do > > > before do > > > visit root_path > > > end > > > describe "when visiting a second page before example" do > > > before { visit sign_in_path } > > > it { should have_link("Sign in") } > > > end > > > end > > > end > > > > > > The error here is that "sign_in_path" should really be "signin_path". > > > But I get that error five times, and when I run with --format > > > documentation, it looks like RSpec is generating it recursively before > > > it "blows up" with a stack trace (see output below). > > > > > > Obviously this test doesn't really need two before blocks, but > > > sometimes I do want to visit two pages before a test. > > > > > > Am I doing something wrong, or is this a bug? > > > > > > Mark Berry > > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > Test output: > > > > > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > > > No DRb server is running. Running in local process instead ... > > > > > > public pages > > > details page > > > when no user is signed in > > > when visiting a second page before example > > > when visiting a second page before example > > > when no user is signed in > > > when visiting a second page before example > > > details page > > > when no user is signed in > > > when visiting a second page before example > > > > > > Failures: > > > > > > 1) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > 2) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > 3) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > 4) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > 5) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > > > > > > This is what I would expect. There is nothing "recursive" about this. There is a failure in > > a before block that runs before every example. It's the same as if you had the same > > broken code directly in each example. > > > > > > HTH, > > David > > > > > [Sorry if this starts a new thread. I was attempting to monitor and > reply to the group through Google Groups, but apparently that mirror > stopped working on April 10, so I'm having to reconstruct this reply.] > > Thanks for the reply. > > Although the output says "5 examples, 5 failures," there is only one > example, hence my confusion about it failing five times. Also, the > "documentation" output lists each describe block (except the first) > two to four times. > > When I fix the error, I get one line per describe, plus one example > completed, as expected: > > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > > public pages > details page > when visiting a second page before example > should has link "Sign in" > > Finished in 1.44 seconds > 1 example, 0 failures > > > I have since discovered that the problem only occurs when using > "--format documentation". Without that, with the error back in place, > RSpec only gives me one error, not five: > > > [myproject (tests)]$ rspec spec/requests/test2* > F > > Failures: > > 1) public pages details page when visiting a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:9:in `block (4 levels) in > ' > > Finished in 1.07 seconds > 1 example, 1 failure > > Failed examples: > > rspec ./spec/requests/test2_pages_spec.rb:10 # public pages details > page when visiting a second page before example > > Does that clarify the issue? Yes. Is the repo public? -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Thu Apr 19 04:30:34 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 18 Apr 2012 21:30:34 -0700 (PDT) Subject: [rspec-users] how can I get prettier failure messages for integration specs? In-Reply-To: <8EA5F19F31DE40E591713738A45264D4@gmail.com> References: <8EA5F19F31DE40E591713738A45264D4@gmail.com> Message-ID: On Wed, 18 Apr 2012, David Chelimsky wrote: > If you're using capybara you could put save_and_open_page in an after hook. You'd still get the console output, but at least you'd see > the page in a browser. Is there a way to make that happen only upon failures during integration tests? Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Thu Apr 19 05:14:46 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 19 Apr 2012 00:14:46 -0500 Subject: [rspec-users] how can I get prettier failure messages for integration specs? In-Reply-To: References: <8EA5F19F31DE40E591713738A45264D4@gmail.com> Message-ID: On Wednesday, April 18, 2012 at 11:30 PM, Patrick J. Collins wrote: > On Wed, 18 Apr 2012, David Chelimsky wrote: > > If you're using capybara you could put save_and_open_page in an after hook. You'd still get the console output, but at least you'd see > > the page in a browser. > > > > > Is there a way to make that happen only upon failures during integration > tests? > > Try this: RSpec.configure do |c| c.after(:each, :type => :request) do save_and_open_page if example.exception end end -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick at collinatorstudios.com Thu Apr 19 06:00:35 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 18 Apr 2012 23:00:35 -0700 (PDT) Subject: [rspec-users] how can I get prettier failure messages for integration specs? In-Reply-To: References: <8EA5F19F31DE40E591713738A45264D4@gmail.com> Message-ID: On Thu, 19 Apr 2012, David Chelimsky wrote: > Try this: > > RSpec.configure do |c| > ? c.after(:each, :type => :request) do > ? ? save_and_open_page if example.exception > ? end > end > > Thank you so much! That works perfectly... Patrick J. Collins http://collinatorstudios.com From patrick at collinatorstudios.com Thu Apr 19 06:33:50 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Wed, 18 Apr 2012 23:33:50 -0700 (PDT) Subject: [rspec-users] how can I stub out external service calls during integration tests? Message-ID: Hi, I realize that integration tests are supposed to be high-level and deal with what the user really sees on their end, but say you have a form that integrates via ajax with a payment service like chargify-- Even though that service may have a "sandbox" environment that you can post to, I would rather not my requests specs go out and actually hit the wire... So, my question is, what is the proper way to stub out something like this? Is it to do something hacky like: page.evaluate_script "$('#form_for_chargify').submit(function() { window.location = '<>'; return false; } Is there a better way to do this? Thanks. Patrick J. Collins http://collinatorstudios.com From mcbsystems at gmail.com Thu Apr 19 15:54:07 2012 From: mcbsystems at gmail.com (Mark Berry) Date: Thu, 19 Apr 2012 08:54:07 -0700 Subject: [rspec-users] One error reported recursively if two pages visited by request spec In-Reply-To: References: Message-ID: On Wed, Apr 18, 2012 at 8:09 PM, David Chelimsky wrote: > On Wednesday, April 18, 2012 at 4:30 PM, Mark Berry wrote: > > On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote: > On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote: > > Hi, > > I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. > > I've been getting recursive errors, where one error is reported > multiple times. It's quite spectacular in a long suite, with the > errors overflowing the console buffer. I've whittled down a simple > example: > > require 'spec_helper' > describe "public pages" do > subject { page } > describe "details page" do > before do > visit root_path > end > describe "when visiting a second page before example" do > before { visit sign_in_path } > it { should have_link("Sign in") } > end > end > end > > The error here is that "sign_in_path" should really be "signin_path". > But I get that error five times, and when I run with --format > documentation, it looks like RSpec is generating it recursively before > it "blows up" with a stack trace (see output below). > > Obviously this test doesn't really need two before blocks, but > sometimes I do want to visit two pages before a test. > > Am I doing something wrong, or is this a bug? > > Mark Berry > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Test output: > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > No DRb server is running. Running in local process instead ... > > public pages > details page > when no user is signed in > when visiting a second page before example > when visiting a second page before example > when no user is signed in > when visiting a second page before example > details page > when no user is signed in > when visiting a second page before example > > Failures: > > 1) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 2) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 3) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 4) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 5) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > > This is what I would expect. There is nothing "recursive" about this. There > is a failure in > a before block that runs before every example. It's the same as if you had > the same > broken code directly in each example. > > > HTH, > David > > > [Sorry if this starts a new thread. I was attempting to monitor and > reply to the group through Google Groups, but apparently that mirror > stopped working on April 10, so I'm having to reconstruct this reply.] > > Thanks for the reply. > > Although the output says "5 examples, 5 failures," there is only one > example, hence my confusion about it failing five times. Also, the > "documentation" output lists each describe block (except the first) > two to four times. > > When I fix the error, I get one line per describe, plus one example > completed, as expected: > > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > > public pages > details page > when visiting a second page before example > should has link "Sign in" > > Finished in 1.44 seconds > 1 example, 0 failures > > > I have since discovered that the problem only occurs when using > "--format documentation". Without that, with the error back in place, > RSpec only gives me one error, not five: > > > [myproject (tests)]$ rspec spec/requests/test2* > F > > Failures: > > 1) public pages details page when visiting a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:9:in `block (4 levels) in > ' > > Finished in 1.07 seconds > 1 example, 1 failure > > Failed examples: > > rspec ./spec/requests/test2_pages_spec.rb:10 # public pages details > page when visiting a second page before example > > Does that clarify the issue? > > Yes. Is the repo public? No, but I think it will duplicate the issue if you drop this into into almost any project with a root_path. spec/requests/test_spec.rb require 'spec_helper' describe "public pages" do subject { page } describe "details page" do before do visit root_path end describe "when visiting a second page before example" do before { visit sign_in_path } it { should have_link("Sign in") } end end end gemfile: gem 'rails', '3.1.3' gem 'devise', '1.5.3' # required to succeed, but not to fail group :test do gem 'rspec-rails', '2.9.0' gem 'capybara', '1.1.2' end Run: rspec spec/requests/test* --format documentation Or try with another failing test. I see the issue with any failing test if I "--format documentation". If it doesn't duplicate, let me know and I'll try to build a public mini project. I've seen mention of another recursion issue traced back to Ruby 1.9; don't know if this is related: http://myronmars.to/n/dev-blog/2011/11/recent-rspec-configuration-warnings-and-errors Mark Berry From lbocseg at yahoo.com.br Thu Apr 19 18:42:40 2012 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Thu, 19 Apr 2012 15:42:40 -0300 Subject: [rspec-users] Smart mocks for ActiveRecord to speed up tests In-Reply-To: <4F8C542A.3090302@yahoo.com.br> References: <4F8879E6.5080102@yahoo.com.br> <9113B01EED7E405EBAB3CFA2784AE4ED@gmail.com> <4F8B8287.5030800@yahoo.com.br> <154E9023137C464D82489313FC226FB6@gmail.com> <4F8C1022.8020109@yahoo.com.br> <4F8C542A.3090302@yahoo.com.br> Message-ID: <4F905CA0.8000201@yahoo.com.br> Just in case someone is curious, I've replaced ActiveRecord models with Sequel ones and my slowest example as reported by "rspec -d" got faster from about 0.5s to 0.2s. That is awesome! :) It seems AR is bloated... As if this wasn't already amazing enough, my models seem much cleaner with Sequel than with AR. Cheers, Rodrigo. Em 16-04-2012 14:17, Rodrigo Rosenfeld Rosas escreveu: > Em 16-04-2012 09:27, Rodrigo Rosenfeld Rosas escreveu: >> Thank you David and Matt for your comments. >> >> Indeed I had considered using FakeWeb but I thought that maybe there >> could be an easier way just to mock 'open' directly since I guess it >> would be faster to run. >> >> With regards to the work around to overcome the issue with mocking AR >> so that I could speed up my tests I think that creating helpers in >> the model that will restrict the use of the AR API sounds like a good >> balance, but that wouldn't make my specific tests faster. >> >> Here is why: my Model class shouldn't be created or updated by any >> other code in my application. So I'd just have to add a new method to >> the Model class that would be specific to this action and I'd need to >> write a "unit" test for this new method. I quoted "unit" because it >> is actually an integration test as it will touch the database or >> otherwise I wouldn't be able to upgrade Rails to a new version if I'm >> mocking some methods from AR and they change in a future version. >> >> So I'd need to touch the database anyway and my 9 specs would still >> take almost a full second to run while this specific controller spec >> takes about 0.7s (up to 2s depending on my system load). >> >> Well, actually, I guess RSpec has changed the way it measure spec >> runs since I last used it. I'm saying that because it will report me >> from 0.7 to 2s when I run "rspec path/to/my_controller_spec.rb", but >> if I run "rspec --profile" it will run the full suite about the same >> time and this specific controller action will take 0.38s. >> >> Anyway, I don't see how I would create hundreds of specs and expect >> them to run in a few seconds and still have a reliable test suite. I >> mean, I want to feel safe if I'm upgrading to a newer Rails version >> even if it changed its AR API. >> >> The only real improvements I can see for my tests running fasts >> without changing anything in the specs is to use something like Hydra >> so that I could use the full power of my 6-core processor. >> >> Does RSpec has a built-in threaded option? I guess not because I >> don't think it would be much effective on CRuby because it would >> probably lock on database access (or maybe not, I don't know how the >> pg driver is implemented). For my particular application I suspect it >> is not cpu-heavy, but io-expensive instead. So maybe a multi-thread >> spec runner could improve its performance when running multiple specs. >> >> Best, >> Rodrigo. >> > > After some more investigation I could find out why it is taking so > much time for the spec to run. Even for a simple model, calling a > single "Model.create! name: 'Model name'" will take almost 100ms. So, > here is usually what happens: > > root = FactoryGirl.create :model # 2 creates: > # section = Section.create! name: 'Section' > # root = Model.create! section: section, label: 'Label' > post 'action', parent_id: root.id # another Model creation in the > controller alongside with 2 other creations of a has_many association > > So, without counting any assertions just for creating all records so > far about 400ms were already spent. There will also be about 2 more > updates and 2 "delete" statements in this spec and that will complete > about 540ms of total spec run time. > > Another interesting fact is that for measuring this I've mocked the > user and controller authentication related methods, but if I actually > create the user the time for completing the spec will be about the > same, even if in the logs it is reported to spend about 70ms for > executing the insert in the user's table. > > But I don't think it should take so much time for creating/updating > those records. See the output of the logging, for example: > > Completed 200 OK in 83ms (Views: 0.6ms | ActiveRecord: 14.9ms) > > This is consistent with the individual timing for each query/insert > statement including validations. Even so, the first 'post' method call > in the spec takes about 100ms. > > So, my question is, if AR and Views are taking about 16ms what else > could be taking about 70ms? > > This is also hard to profile since PostgreSQL will need more time for > the first queries and will be much faster for subsequent ones... This > means that running all specs will take much less time than if I run > each spec separately and compare to the total time. > > But I don't really think I'll be able to test this action faster. I > need to check for all created records including associations and > fields set by the before_validation and removed by after_save so that > I can get confidence in the code. And since all of this should only > happen through this action, it wouldn't matter if I moved lots of > those checks to the "unit" test of my Model as the total time would > remain the same. It would only make my specs harder to read with lots > of mocks and stubbed methods in my controller spec. > > I mean, that is ok, I don't aim in having single assertions per unit > test. I just need to make sure things won't break in a future > refactoring or requirement changes. And of course I'd like my tests to > run faster, but my current understanding is that I can't get this test > to run faster because it is testing a lot of code. Of course that an > in-memory AR adapter could help me speeding up my tests but using > mocks here won't give me any confidence on my code base. > > Usually slow tests are not a problem when I'm working in some > controller as I don't need to run the full suite. But when I change > some model or library it would be great to run the full suite and I'm > a bit worried if that will become super slow some time in the future. > > But I think I'll start to worry about this when this future becomes > present because there is no easy replacement that will allow my specs > to run faster. I'll still be able to try Hydra before having to resort > to mocks if things get really unsustainable. > > But thank you very much for your input on the subject. I was just > worried if I was doing something fundamentally wrong. > > Cheers, > Rodrigo. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mcbsystems at gmail.com Thu Apr 19 22:55:21 2012 From: mcbsystems at gmail.com (Mark Berry) Date: Thu, 19 Apr 2012 15:55:21 -0700 Subject: [rspec-users] One error reported recursively if two pages visited by request spec In-Reply-To: References: Message-ID: On Thu, Apr 19, 2012 at 8:54 AM, Mark Berry wrote: > On Wed, Apr 18, 2012 at 8:09 PM, David Chelimsky wrote: >> On Wednesday, April 18, 2012 at 4:30 PM, Mark Berry wrote: >> >> On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote: >> On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote: >> >> Hi, >> >> I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. >> >> I've been getting recursive errors, where one error is reported >> multiple times. It's quite spectacular in a long suite, with the >> errors overflowing the console buffer. I've whittled down a simple >> example: >> >> require 'spec_helper' >> describe "public pages" do >> subject { page } >> describe "details page" do >> before do >> visit root_path >> end >> describe "when visiting a second page before example" do >> before { visit sign_in_path } >> it { should have_link("Sign in") } >> end >> end >> end >> >> The error here is that "sign_in_path" should really be "signin_path". >> But I get that error five times, and when I run with --format >> documentation, it looks like RSpec is generating it recursively before >> it "blows up" with a stack trace (see output below). >> >> Obviously this test doesn't really need two before blocks, but >> sometimes I do want to visit two pages before a test. >> >> Am I doing something wrong, or is this a bug? >> >> Mark Berry >> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> Test output: >> >> [myproject (tests)]$ rspec spec/requests/test2* --format documentation >> No DRb server is running. Running in local process instead ... >> >> public pages >> details page >> when no user is signed in >> when visiting a second page before example >> when visiting a second page before example >> when no user is signed in >> when visiting a second page before example >> details page >> when no user is signed in >> when visiting a second page before example >> >> Failures: >> >> 1) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> 2) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> 3) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> 4) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> 5) public pages details page when no user is signed in when visiting >> a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in >> ' >> >> >> This is what I would expect. There is nothing "recursive" about this. There >> is a failure in >> a before block that runs before every example. It's the same as if you had >> the same >> broken code directly in each example. >> >> >> HTH, >> David >> >> >> [Sorry if this starts a new thread. I was attempting to monitor and >> reply to the group through Google Groups, but apparently that mirror >> stopped working on April 10, so I'm having to reconstruct this reply.] >> >> Thanks for the reply. >> >> Although the output says "5 examples, 5 failures," there is only one >> example, hence my confusion about it failing five times. Also, the >> "documentation" output lists each describe block (except the first) >> two to four times. >> >> When I fix the error, I get one line per describe, plus one example >> completed, as expected: >> >> >> [myproject (tests)]$ rspec spec/requests/test2* --format documentation >> >> public pages >> details page >> when visiting a second page before example >> should has link "Sign in" >> >> Finished in 1.44 seconds >> 1 example, 0 failures >> >> >> I have since discovered that the problem only occurs when using >> "--format documentation". Without that, with the error back in place, >> RSpec only gives me one error, not five: >> >> >> [myproject (tests)]$ rspec spec/requests/test2* >> F >> >> Failures: >> >> 1) public pages details page when visiting a second page before example >> Failure/Error: before { visit sign_in_path } >> NameError: >> undefined local variable or method `sign_in_path' for >> # >> # ./spec/requests/test2_pages_spec.rb:9:in `block (4 levels) in >> ' >> >> Finished in 1.07 seconds >> 1 example, 1 failure >> >> Failed examples: >> >> rspec ./spec/requests/test2_pages_spec.rb:10 # public pages details >> page when visiting a second page before example >> >> Does that clarify the issue? >> >> Yes. Is the repo public? > > No, but I think it will duplicate the issue if you drop this into into > almost any project with a root_path. > > spec/requests/test_spec.rb > > require 'spec_helper' > describe "public pages" do > ?subject { page } > ?describe "details page" do > ? before do > ? ? visit root_path > ? end > ? describe "when visiting a second page before example" do > ? ? before { visit sign_in_path } > ? ? it { should have_link("Sign in") } > ? end > ?end > end > > gemfile: > > gem 'rails', '3.1.3' > gem 'devise', '1.5.3' # required to succeed, but not to fail > group :test do > ?gem 'rspec-rails', '2.9.0' > ?gem 'capybara', '1.1.2' > end > > Run: > > rspec spec/requests/test* --format documentation > > Or try with another failing test. I see the issue with any failing > test if I "--format documentation". > > If it doesn't duplicate, let me know and I'll try to build a public > mini project. > > I've seen mention of another recursion issue traced back to Ruby 1.9; > don't know if this is related: > > http://myronmars.to/n/dev-blog/2011/11/recent-rspec-configuration-warnings-and-errors > > Mark Berry > Or try with another failing test. I see the issue with any failing > test if I "--format documentation". Let me amend that: I see it on any test with "--format documentation" IF the test fails due to a syntax error. So if "should have_link('foo')" fails because the link is not there, I only get one error. But if I fumble-finger and type "should havelink('foo')", I get the syntax error many times. Mark Berry From lists at ruby-forum.com Sat Apr 21 20:16:05 2012 From: lists at ruby-forum.com (Anil Wadghule) Date: Sat, 21 Apr 2012 22:16:05 +0200 Subject: [rspec-users] Testing an API I'm creating, need test server to be running In-Reply-To: References: <5485ad72-a21d-4f58-95f5-ccc3f4a8a670@i26g2000vbt.googlegroups.com> <19FA37E4-E5B1-4BB4-9EBC-D133429D3E8C@gmail.com> Message-ID: <7a964105e9fc5a46ff55d9102eb35701@ruby-forum.com> How one should test an API which depends on other web services (SOAP etc). e.g. Login to my API internally calls to another webservice API for authentication. Also all the data sent back by my API is actually data retrieved from another web service. Also should we verify the data or just responses are 200 or something else. Any thoughts? Sidu Ponnappa wrote in post #1040936: > Agreed. This is even more a bullet to bite early if your app > orchestrates > over more than one service, or if services talk to other services or > both. > > Testing this kind of setup is pretty difficult and the tests are > typically > very brittle. > > Best, > Sidu. > http://c42.in > http://rubymonk.com > > Sent from my phone -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Apr 22 09:41:40 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 22 Apr 2012 04:41:40 -0500 Subject: [rspec-users] One error reported recursively if two pages visited by request spec In-Reply-To: References: Message-ID: Looks like this is related to https://github.com/rspec/rspec-core/issues/585, which is already fixed in master. If you point your Gemfile to github now you'll see it fixed. 2.10 release coming soon. group :test do gem 'rspec-rails', :git => "git://github.com/rspec/rspec-rails.git" gem 'rspec-core', :git => "git://github.com/rspec/rspec-core.git" gem 'rspec-expectations', :git => "git://github.com/rspec/rspec-expectations.git" gem 'rspec-mocks', :git => "git://github.com/rspec/rspec-mocks.git" gem 'capybara', '1.1.2' end Cheers, David -- David Chelimsky Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Thursday, April 19, 2012 at 5:55 PM, Mark Berry wrote: > On Thu, Apr 19, 2012 at 8:54 AM, Mark Berry wrote: > > On Wed, Apr 18, 2012 at 8:09 PM, David Chelimsky wrote: > > > On Wednesday, April 18, 2012 at 4:30 PM, Mark Berry wrote: > > > > > > On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote: > > > On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote: > > > > > > Hi, > > > > > > I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. > > > > > > I've been getting recursive errors, where one error is reported > > > multiple times. It's quite spectacular in a long suite, with the > > > errors overflowing the console buffer. I've whittled down a simple > > > example: > > > > > > require 'spec_helper' > > > describe "public pages" do > > > subject { page } > > > describe "details page" do > > > before do > > > visit root_path > > > end > > > describe "when visiting a second page before example" do > > > before { visit sign_in_path } > > > it { should have_link("Sign in") } > > > end > > > end > > > end > > > > > > The error here is that "sign_in_path" should really be "signin_path". > > > But I get that error five times, and when I run with --format > > > documentation, it looks like RSpec is generating it recursively before > > > it "blows up" with a stack trace (see output below). > > > > > > Obviously this test doesn't really need two before blocks, but > > > sometimes I do want to visit two pages before a test. > > > > > > Am I doing something wrong, or is this a bug? > > > > > > Mark Berry > > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > Test output: > > > > > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > > > No DRb server is running. Running in local process instead ... > > > > > > public pages > > > details page > > > when no user is signed in > > > when visiting a second page before example > > > when visiting a second page before example > > > when no user is signed in > > > when visiting a second page before example > > > details page > > > when no user is signed in > > > when visiting a second page before example > > > > > > Failures: > > > > > > 1) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > 2) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > 3) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > 4) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > 5) public pages details page when no user is signed in when visiting > > > a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > > > ' > > > > > > > > > This is what I would expect. There is nothing "recursive" about this. There > > > is a failure in > > > a before block that runs before every example. It's the same as if you had > > > the same > > > broken code directly in each example. > > > > > > > > > HTH, > > > David > > > > > > > > > [Sorry if this starts a new thread. I was attempting to monitor and > > > reply to the group through Google Groups, but apparently that mirror > > > stopped working on April 10, so I'm having to reconstruct this reply.] > > > > > > Thanks for the reply. > > > > > > Although the output says "5 examples, 5 failures," there is only one > > > example, hence my confusion about it failing five times. Also, the > > > "documentation" output lists each describe block (except the first) > > > two to four times. > > > > > > When I fix the error, I get one line per describe, plus one example > > > completed, as expected: > > > > > > > > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > > > > > > public pages > > > details page > > > when visiting a second page before example > > > should has link "Sign in" > > > > > > Finished in 1.44 seconds > > > 1 example, 0 failures > > > > > > > > > I have since discovered that the problem only occurs when using > > > "--format documentation". Without that, with the error back in place, > > > RSpec only gives me one error, not five: > > > > > > > > > [myproject (tests)]$ rspec spec/requests/test2* > > > F > > > > > > Failures: > > > > > > 1) public pages details page when visiting a second page before example > > > Failure/Error: before { visit sign_in_path } > > > NameError: > > > undefined local variable or method `sign_in_path' for > > > # > > > # ./spec/requests/test2_pages_spec.rb:9:in `block (4 levels) in > > > ' > > > > > > Finished in 1.07 seconds > > > 1 example, 1 failure > > > > > > Failed examples: > > > > > > rspec ./spec/requests/test2_pages_spec.rb:10 # public pages details > > > page when visiting a second page before example > > > > > > Does that clarify the issue? > > > > > > Yes. Is the repo public? > > > > No, but I think it will duplicate the issue if you drop this into into > > almost any project with a root_path. > > > > spec/requests/test_spec.rb > > > > require 'spec_helper' > > describe "public pages" do > > subject { page } > > describe "details page" do > > before do > > visit root_path > > end > > describe "when visiting a second page before example" do > > before { visit sign_in_path } > > it { should have_link("Sign in") } > > end > > end > > end > > > > gemfile: > > > > gem 'rails', '3.1.3' > > gem 'devise', '1.5.3' # required to succeed, but not to fail > > group :test do > > gem 'rspec-rails', '2.9.0' > > gem 'capybara', '1.1.2' > > end > > > > Run: > > > > rspec spec/requests/test* --format documentation > > > > Or try with another failing test. I see the issue with any failing > > test if I "--format documentation". > > > > If it doesn't duplicate, let me know and I'll try to build a public > > mini project. > > > > I've seen mention of another recursion issue traced back to Ruby 1.9; > > don't know if this is related: > > > > http://myronmars.to/n/dev-blog/2011/11/recent-rspec-configuration-warnings-and-errors > > > > Mark Berry > > > Or try with another failing test. I see the issue with any failing > > test if I "--format documentation". > > > > > Let me amend that: I see it on any test with "--format documentation" > IF the test fails due to a syntax error. > > So if "should have_link('foo')" fails because the link is not there, I > only get one error. > > But if I fumble-finger and type "should havelink('foo')", I get the > syntax error many times. > > Mark Berry > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org (mailto: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 Mon Apr 23 17:26:13 2012 From: sahmed1020 at gmail.com (S Ahmed) Date: Mon, 23 Apr 2012 13:26:13 -0400 Subject: [rspec-users] using rspec in a non-rails environment Message-ID: My folder structure is as follows: /myapp/ /myapp/lib/class1.rb /myapp/rspec/spec_helper.rb /myapp/rspec/lib/class1_spec.rb My spec_helper has: require 'rubygems' require 'rspec' RSpec.configure do |config| end My class1_spec.rb has: require 'spec_helper' require '../../lib/class1' describe Class1 do it "should do something" end How do I require my class1 correct, when I run: rspec spec/lib/class1_spec.rb I am getting: 1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- ../../lib/class1.rb (LoadError) Also, in a non-rails app, what kind of things do you put in the spec_helper normally? any popular config settings that I should know about? thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Apr 23 17:42:57 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 23 Apr 2012 12:42:57 -0500 Subject: [rspec-users] using rspec in a non-rails environment In-Reply-To: References: Message-ID: On Mon, Apr 23, 2012 at 12:26 PM, S Ahmed wrote: > My folder structure is as follows: > > /myapp/ > /myapp/lib/class1.rb > > /myapp/rspec/spec_helper.rb > /myapp/rspec/lib/class1_spec.rb > > My spec_helper has: > > require 'rubygems' ^^ If you've installed rspec as a gem and you're running the rspec command, you don't need to require 'rubygems'. ^^ > require 'rspec' ^^ This should be 'rspec/autorun'. ^^ > > RSpec.configure do |config| > end This ^^ is not necessary unless you're using it > My class1_spec.rb has: > > require 'spec_helper' > require '../../lib/class1' > > describe Class1 do > ? it "should do something" > end > > > How do I require my class1 correct, when I run: > > rspec spec/lib/class1_spec.rb I am getting: > > 1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- > ../../lib/class1.rb (LoadError) RSpec adds 'lib' to the LOAD_PATH, so you can just `require "class1"`, but it's conventional to do this in spec_helper.rb instead. HTH, David > Also, in a non-rails app, what kind of things do you put in the spec_helper > normally? any popular config settings that I should know about? > > thanks! From sahmed1020 at gmail.com Mon Apr 23 18:11:20 2012 From: sahmed1020 at gmail.com (S Ahmed) Date: Mon, 23 Apr 2012 14:11:20 -0400 Subject: [rspec-users] using rspec in a non-rails environment In-Reply-To: References: Message-ID: ok have to lookup what rspec/autorun does as oppose to just 'require "rspec"' thanks, it is now working :) feels good! I've always been tied to rails, seems like I was spoiled and not sure how to do basic things in ruby.... On Mon, Apr 23, 2012 at 1:42 PM, David Chelimsky wrote: > On Mon, Apr 23, 2012 at 12:26 PM, S Ahmed wrote: > > My folder structure is as follows: > > > > /myapp/ > > /myapp/lib/class1.rb > > > > /myapp/rspec/spec_helper.rb > > /myapp/rspec/lib/class1_spec.rb > > > > My spec_helper has: > > > > require 'rubygems' > > ^^ If you've installed rspec as a gem and you're running the rspec > command, you don't need to require 'rubygems'. ^^ > > > require 'rspec' > > ^^ This should be 'rspec/autorun'. ^^ > > > > > RSpec.configure do |config| > > end > > This ^^ is not necessary unless you're using it > > > My class1_spec.rb has: > > > > require 'spec_helper' > > require '../../lib/class1' > > > > describe Class1 do > > it "should do something" > > end > > > > > > How do I require my class1 correct, when I run: > > > > rspec spec/lib/class1_spec.rb I am getting: > > > > 1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file > -- > > ../../lib/class1.rb (LoadError) > > RSpec adds 'lib' to the LOAD_PATH, so you can just `require "class1"`, > but it's conventional to do this in spec_helper.rb instead. > > HTH, > David > > > > Also, in a non-rails app, what kind of things do you put in the > spec_helper > > normally? any popular config settings that I should know about? > > > > thanks! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mcbsystems at gmail.com Mon Apr 23 21:00:49 2012 From: mcbsystems at gmail.com (Mark Berry) Date: Mon, 23 Apr 2012 14:00:49 -0700 Subject: [rspec-users] One error reported recursively if two pages visited by request spec In-Reply-To: References: Message-ID: Yup that fixed it, thanks! Mark Berry On Sun, Apr 22, 2012 at 2:41 AM, David Chelimsky wrote: > Looks like this is related > to?https://github.com/rspec/rspec-core/issues/585, which is already fixed in > master. If you point your Gemfile to github now you'll see it fixed. 2.10 > release coming soon. > > group :test do > ? gem 'rspec-rails', ? ? ? ?:git => "git://github.com/rspec/rspec-rails.git" > ? gem 'rspec-core', ? ? ? ? :git => "git://github.com/rspec/rspec-core.git" > ? gem 'rspec-expectations', :git => > "git://github.com/rspec/rspec-expectations.git" > ? gem 'rspec-mocks', ? ? ? ?:git => "git://github.com/rspec/rspec-mocks.git" > ? gem 'capybara', '1.1.2' > end > > Cheers, > David > > -- > David Chelimsky > Sent with Sparrow > > On Thursday, April 19, 2012 at 5:55 PM, Mark Berry wrote: > > On Thu, Apr 19, 2012 at 8:54 AM, Mark Berry wrote: > > On Wed, Apr 18, 2012 at 8:09 PM, David Chelimsky > wrote: > > On Wednesday, April 18, 2012 at 4:30 PM, Mark Berry wrote: > > On Wed April 18, 2012 at 5:35 AM, David Chelimsky wrote: > On Tuesday, April 17, 2012 at 11:11 PM, Mark Berry wrote: > > Hi, > > I'm using Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0. > > I've been getting recursive errors, where one error is reported > multiple times. It's quite spectacular in a long suite, with the > errors overflowing the console buffer. I've whittled down a simple > example: > > require 'spec_helper' > describe "public pages" do > subject { page } > describe "details page" do > before do > visit root_path > end > describe "when visiting a second page before example" do > before { visit sign_in_path } > it { should have_link("Sign in") } > end > end > end > > The error here is that "sign_in_path" should really be "signin_path". > But I get that error five times, and when I run with --format > documentation, it looks like RSpec is generating it recursively before > it "blows up" with a stack trace (see output below). > > Obviously this test doesn't really need two before blocks, but > sometimes I do want to visit two pages before a test. > > Am I doing something wrong, or is this a bug? > > Mark Berry > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Test output: > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > No DRb server is running. Running in local process instead ... > > public pages > details page > when no user is signed in > when visiting a second page before example > when visiting a second page before example > when no user is signed in > when visiting a second page before example > details page > when no user is signed in > when visiting a second page before example > > Failures: > > 1) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 2) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 3) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 4) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > 5) public pages details page when no user is signed in when visiting > a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:16:in `block (5 levels) in > ' > > > This is what I would expect. There is nothing "recursive" about this. There > is a failure in > a before block that runs before every example. It's the same as if you had > the same > broken code directly in each example. > > > HTH, > David > > > [Sorry if this starts a new thread. I was attempting to monitor and > reply to the group through Google Groups, but apparently that mirror > stopped working on April 10, so I'm having to reconstruct this reply.] > > Thanks for the reply. > > Although the output says "5 examples, 5 failures," there is only one > example, hence my confusion about it failing five times. Also, the > "documentation" output lists each describe block (except the first) > two to four times. > > When I fix the error, I get one line per describe, plus one example > completed, as expected: > > > [myproject (tests)]$ rspec spec/requests/test2* --format documentation > > public pages > details page > when visiting a second page before example > should has link "Sign in" > > Finished in 1.44 seconds > 1 example, 0 failures > > > I have since discovered that the problem only occurs when using > "--format documentation". Without that, with the error back in place, > RSpec only gives me one error, not five: > > > [myproject (tests)]$ rspec spec/requests/test2* > F > > Failures: > > 1) public pages details page when visiting a second page before example > Failure/Error: before { visit sign_in_path } > NameError: > undefined local variable or method `sign_in_path' for > # > # ./spec/requests/test2_pages_spec.rb:9:in `block (4 levels) in > ' > > Finished in 1.07 seconds > 1 example, 1 failure > > Failed examples: > > rspec ./spec/requests/test2_pages_spec.rb:10 # public pages details > page when visiting a second page before example > > Does that clarify the issue? > > Yes. Is the repo public? > > > No, but I think it will duplicate the issue if you drop this into into > almost any project with a root_path. > > spec/requests/test_spec.rb > > require 'spec_helper' > describe "public pages" do > ?subject { page } > ?describe "details page" do > ? before do > ? ? visit root_path > ? end > ? describe "when visiting a second page before example" do > ? ? before { visit sign_in_path } > ? ? it { should have_link("Sign in") } > ? end > ?end > end > > gemfile: > > gem 'rails', '3.1.3' > gem 'devise', '1.5.3' # required to succeed, but not to fail > group :test do > ?gem 'rspec-rails', '2.9.0' > ?gem 'capybara', '1.1.2' > end > > Run: > > rspec spec/requests/test* --format documentation > > Or try with another failing test. I see the issue with any failing > test if I "--format documentation". > > If it doesn't duplicate, let me know and I'll try to build a public > mini project. > > I've seen mention of another recursion issue traced back to Ruby 1.9; > don't know if this is related: > > http://myronmars.to/n/dev-blog/2011/11/recent-rspec-configuration-warnings-and-errors > > Mark Berry > > > Or try with another failing test. I see the issue with any failing > test if I "--format documentation". > > > Let me amend that: I see it on any test with "--format documentation" > IF the test fails due to a syntax error. > > So if "should have_link('foo')" fails because the link is not there, I > only get one error. > > But if I fumble-finger and type "should havelink('foo')", I get the > syntax error many times. > > Mark Berry > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rr.rosas at gmail.com Mon Apr 23 22:39:05 2012 From: rr.rosas at gmail.com (Rodrigo Rosenfeld Rosas) Date: Mon, 23 Apr 2012 19:39:05 -0300 Subject: [rspec-users] How to modify database inside a transaction in before(:all)? Message-ID: <4F95DA09.2050807@gmail.com> I have a set of examples that should run with a specific set of records in the database. Since setting those records is an expensive operation I'd like to perform it just once per context. For example: context 'sample tree' do before(:all) { create_tree_records } example ... end The problem with this is that while before(:each) and the examples will run in a transaction that will be rolled back at the end of each example, that won't happen to the records created/modified by the before(:all) block. It seems my database vendor (PostgreSQL) supports nested transactions (savepoints): http://www.postgresql.org/about/ I should also notice that I'm using Sequel and it seems that transactions are reentrant in Sequel: http://cheat.errtheblog.com/s/sequel/ Database#transaction is re-entrant: DB.transaction do # BEGIN issued only here DB.transaction dataset << {:first_name => 'Inigo', :last_name => 'Montoya'} end end # COMMIT issued only here So, this logic wouldn't work for me. I need a save point in a before(:all), so that I'd restore it on a before(:each). Is there any recommendation to make this work in my specs? Thanks in advance, Rodrigo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Apr 23 23:04:03 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 23 Apr 2012 18:04:03 -0500 Subject: [rspec-users] How to modify database inside a transaction in before(:all)? In-Reply-To: <4F95DA09.2050807@gmail.com> References: <4F95DA09.2050807@gmail.com> Message-ID: On Mon, Apr 23, 2012 at 5:39 PM, Rodrigo Rosenfeld Rosas wrote: > I have a set of examples that should run with a specific set of records in > the database. > > Since setting those records is an expensive operation I'd like to perform it > just once per context. > > For example: > > context 'sample tree' do > ??? before(:all) { create_tree_records } > > ??? example ... > end > > The problem with this is that while before(:each) and the examples will run > in a transaction that will be rolled back at the end of each example, that > won't happen to the records created/modified by the before(:all) block. > > It seems my database vendor (PostgreSQL) supports nested transactions > (savepoints): > > http://www.postgresql.org/about/ > > I should also notice that I'm using Sequel and it seems that transactions > are reentrant in Sequel: > > http://cheat.errtheblog.com/s/sequel/ > > Database#transaction is re-entrant: > > ? DB.transaction do # BEGIN issued only here > ??? DB.transaction > ????? dataset << {:first_name => 'Inigo', :last_name => 'Montoya'} > ??? end > end # COMMIT issued only here > > So, this logic wouldn't work for me. I need a save point in a before(:all), > so that I'd restore it on a before(:each). > > Is there any recommendation to make this work in my specs? Nothing built into RSpec now, but you could disable the Rails transaction management and use DatabaseCleaner on your own. This is currently being discussed in https://github.com/rspec/rspec-rails/issues/496 as well. Feel free to join that convo. Cheers, David > > Thanks in advance, > Rodrigo. From lbocseg at yahoo.com.br Tue Apr 24 02:22:24 2012 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Mon, 23 Apr 2012 23:22:24 -0300 Subject: [rspec-users] How to modify database inside a transaction in before(:all)? In-Reply-To: References: <4F95DA09.2050807@gmail.com> Message-ID: <4F960E60.9050406@yahoo.com.br> Em 23-04-2012 20:04, David Chelimsky escreveu: > On Mon, Apr 23, 2012 at 5:39 PM, Rodrigo Rosenfeld Rosas > wrote: >> I have a set of examples that should run with a specific set of records in >> the database. >> >> Since setting those records is an expensive operation I'd like to perform it >> just once per context. >> >> For example: >> >> context 'sample tree' do >> before(:all) { create_tree_records } >> >> example ... >> end >> >> The problem with this is that while before(:each) and the examples will run >> in a transaction that will be rolled back at the end of each example, that >> won't happen to the records created/modified by the before(:all) block. >> >> It seems my database vendor (PostgreSQL) supports nested transactions >> (savepoints): >> >> http://www.postgresql.org/about/ >> >> I should also notice that I'm using Sequel and it seems that transactions >> are reentrant in Sequel: >> >> http://cheat.errtheblog.com/s/sequel/ >> >> Database#transaction is re-entrant: >> >> DB.transaction do # BEGIN issued only here >> DB.transaction >> dataset<< {:first_name => 'Inigo', :last_name => 'Montoya'} >> end >> end # COMMIT issued only here >> >> So, this logic wouldn't work for me. I need a save point in a before(:all), >> so that I'd restore it on a before(:each). >> >> Is there any recommendation to make this work in my specs? > Nothing built into RSpec now, but you could disable the Rails > transaction management and use DatabaseCleaner on your own. Actually I'm not using the Rails transaction management anymore since I moved all my models to Sequel::Model. I've created a section in my last article on how to setup Sequel, Rails and RSpec. Please check the RSpec section: http://rosenfeld.herokuapp.com/en/articles/2012-04-18-getting-started-with-sequel-in-rails The issue with using DatabaseCleaner is that it doesn't support nested transactions too. And I don't want to use the truncate strategy as there are some tables that shouldn't be cleared. > This is currently being discussed in > https://github.com/rspec/rspec-rails/issues/496 as well. Feel free to > join that convo. I don't know if this is possible to accomplish with all supported databases. Maybe there is a simpler approach for PostgreSQL by using savepoints. I'll make some experiments similar to the approach I've used in my article to create those savepoints. I'd just like to know if there was something already done following this idea, but if there isn't, I guess I'll have to do it myself :( Thank you very much for your (always) fast response :) Cheers, Rodrigo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Apr 25 09:41:01 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 25 Apr 2012 04:41:01 -0500 Subject: [rspec-users] New google groups (help, please) Message-ID: Hi all. Google is in the process of changing the google group format and, unless I'm missing something, seems to have abandoned the mirror functionality this list has relied on for several years now (posting to rspec-users also posts to the google group). If anybody on this list knows how to solve this problem in the google group UI, please let me know. If not, we need to retire/archive either the rspec-users mailing list or the google group. Any thoughts on this? Thanks in advance for your help/advice. Cheers, David From lbocseg at yahoo.com.br Wed Apr 25 10:50:50 2012 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Wed, 25 Apr 2012 07:50:50 -0300 Subject: [rspec-users] New google groups (help, please) In-Reply-To: References: Message-ID: <4F97D70A.1040805@yahoo.com.br> I was just about to suggest you a few days ago to move away from rubyforge and towards Google Groups. Much better interface and I don't think it worths trying to keep a mirror. There is no need for that. Cheers, Rodrigo. Em 25-04-2012 06:41, David Chelimsky escreveu: > Hi all. > > Google is in the process of changing the google group format and, > unless I'm missing something, seems to have abandoned the mirror > functionality this list has relied on for several years now (posting > to rspec-users also posts to the google group). > > If anybody on this list knows how to solve this problem in the google > group UI, please let me know. > > If not, we need to retire/archive either the rspec-users mailing list > or the google group. Any thoughts on this? > > Thanks in advance for your help/advice. > > Cheers, > David > From dchelimsky at gmail.com Fri Apr 27 02:43:18 2012 From: dchelimsky at gmail.com (dchelimsky at gmail.com) Date: Thu, 26 Apr 2012 19:43:18 -0700 (PDT) Subject: [rspec-users] using shared_context in a global way In-Reply-To: <29497769.663.1333334040247.JavaMail.geo-discussion-forums@vbyj26> References: <29497769.663.1333334040247.JavaMail.geo-discussion-forums@vbyj26> Message-ID: <10361880.1617.1335494598633.JavaMail.geo-discussion-forums@ynff7> On Sunday, April 1, 2012 9:34:00 PM UTC-5, Bradley wrote: > > I have some let and before declarations that I want to define for all of > my tests. I can't seem to figure out how to do this in a clean way (ie by > including a module in my Rspec config). I don't want to have to > include_context for each test, I just want to run some before(:all) hooks > and provide access to some default variables that example groups could > override with their own let declarations. > > I must be missing something because I can't find anywhere in the docs how > I might achieve this. Any help is greatly appreciated. > > Brad > Hey Brad, You can set up global `before` hooks using `RSpec.configure` [1] [2]: RSpec.configure {|c| c.before(:all) { do_stuff }} `let` is not supported in `RSpec.configure`, but you _can_ set up a global `let` by including it in a SharedContext module [3] and including that module using `config.before`: module MyLetDeclarations extend RSpec::Core::SharedContext let(:foo) { Foo.new } end RSpec.configure { |c| c.include MyLetDeclarations } If you're going to use that, you may as well put all your global stuff in the same module: module GlobalStuff extend RSpec::Core::SharedContext before(:all) { do_stuff } let(:foo) { Foo.new } end RSpec.configure { |c| c.include MyLetDeclarations } HTH, David [1] http://rubydoc.info/gems/rspec-core/RSpec#configure-class_method [2] http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration [3] http://rubydoc.info/gems/rspec-core/RSpec/Core/SharedContext -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Apr 27 02:46:05 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 26 Apr 2012 21:46:05 -0500 Subject: [rspec-users] This is a test to see if the google mirror is working again Message-ID: This is a test to see if the google mirror is working again. Sorry for the noise. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: