From lists at ruby-forum.com Tue Mar 1 05:27:38 2011 From: lists at ruby-forum.com (Amit Kulkarni) Date: Tue, 01 Mar 2011 11:27:38 +0100 Subject: [rspec-users] Writing Rspec for signup using facebook Message-ID: <74412c8998a5bc28b0deb90f9f6fb20c@ruby-forum.com> Hi, We are using omniauth for signup through Facebook and twitter. Is there any way i can check this by rspec controllers since it contains callbacks n all..so i think we may have to use mock models. If there is any link or documentation please let me know so that i can start implementing. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Mar 1 06:08:09 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Mar 2011 05:08:09 -0600 Subject: [rspec-users] Writing Rspec for signup using facebook In-Reply-To: <74412c8998a5bc28b0deb90f9f6fb20c@ruby-forum.com> References: <74412c8998a5bc28b0deb90f9f6fb20c@ruby-forum.com> Message-ID: <4A791712-E12C-4CAD-96F5-294236575A0D@gmail.com> On Mar 1, 2011, at 4:27 AM, Amit Kulkarni wrote: > Hi, > We are using omniauth for signup through Facebook and twitter. > Is there any way i can check this by rspec controllers since it contains > callbacks n all..so i think we may have to use mock models. > If there is any link or documentation please let me know so that i can > start implementing. omniauth is middleware, so it's work is done before the controller action is invoked. To specify something about how your app uses omniauth you'd probably need to use request specs. What is it that you want to specify? Can you give an example? From dchelimsky at gmail.com Tue Mar 1 08:46:15 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Mar 2011 07:46:15 -0600 Subject: [rspec-users] [ANN] Welcome Chad, Pat, Justin, and Myron! Message-ID: <7DFE5667-9486-40EE-A2F2-C673FB5BB744@gmail.com> I'm very pleased to announce the reformation of a core RSpec development team: Chad Humphries, a.k.a. spicycode, has been involved with RSpec since the 1.0 release, which he helped to usher out the door at RailsConf 2007. He subsequently authored Micronaut [1], a lightweight, RSpec compatible spec runner, which later became the basis for the rspec-core gem. Pat Maddox has been contributing patches and blogging about RSpec and BDD since 2007 as well: most notably the =~ matcher for arrays and the last bit of glue that turned plain text stories in Cucumber's predecessor, the RSpec Story Runner (which succeeded rbehave) into a reality. Justin Ko has been actively contributing patches and participating on the mailing list since last spring, but is probably best known for his creation of http://relishapp.com, which now hosts RSpec 2's documentation. Myron Marston is the author of VCR [2], and has been contributing to RSpec since last summer. He has a keen sense of BDD, and his patches continually impress me with their thoroughness, attention to detail, and understanding of the wider Ruby ecosystem in which RSpec makes its home. Please join me in welcoming Chad, Pat, Justin, and Myron to the RSpec development team. Cheers, David [1] http://github.com/spicycode/micronaut [2] http://github.com/myronmarston/vcr From luke at lukemelia.com Tue Mar 1 09:30:43 2011 From: luke at lukemelia.com (Luke Melia) Date: Tue, 1 Mar 2011 09:30:43 -0500 Subject: [rspec-users] [ANN] Welcome Chad, Pat, Justin, and Myron! In-Reply-To: <7DFE5667-9486-40EE-A2F2-C673FB5BB744@gmail.com> References: <7DFE5667-9486-40EE-A2F2-C673FB5BB744@gmail.com> Message-ID: <04EDBE2C-6E54-4B69-90B6-E962A2DFCC92@lukemelia.com> Congratulations, guys and Thank You! On Mar 1, 2011, at 8:46 AM, David Chelimsky wrote: > I'm very pleased to announce the reformation of a core RSpec development team: > > Chad Humphries, a.k.a. spicycode, has been involved with RSpec since the 1.0 release, which he helped to usher out the door at RailsConf 2007. He subsequently authored Micronaut [1], a lightweight, RSpec compatible spec runner, which later became the basis for the rspec-core gem. > > Pat Maddox has been contributing patches and blogging about RSpec and BDD since 2007 as well: most notably the =~ matcher for arrays and the last bit of glue that turned plain text stories in Cucumber's predecessor, the RSpec Story Runner (which succeeded rbehave) into a reality. > > Justin Ko has been actively contributing patches and participating on the mailing list since last spring, but is probably best known for his creation of http://relishapp.com, which now hosts RSpec 2's documentation. > > Myron Marston is the author of VCR [2], and has been contributing to RSpec since last summer. He has a keen sense of BDD, and his patches continually impress me with their thoroughness, attention to detail, and understanding of the wider Ruby ecosystem in which RSpec makes its home. > > Please join me in welcoming Chad, Pat, Justin, and Myron to the RSpec development team. > > Cheers, > David > > [1] http://github.com/spicycode/micronaut > [2] http://github.com/myronmarston/vcr > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Luke Melia http://www.lukemelia.com/ From timgremore at gmail.com Tue Mar 1 09:49:31 2011 From: timgremore at gmail.com (Tim Gremore) Date: Tue, 1 Mar 2011 08:49:31 -0600 Subject: [rspec-users] [ANN] Welcome Chad, Pat, Justin, and Myron! In-Reply-To: <7DFE5667-9486-40EE-A2F2-C673FB5BB744@gmail.com> References: <7DFE5667-9486-40EE-A2F2-C673FB5BB744@gmail.com> Message-ID: BIG Welcome and thanks to the new RSpec squad! Keep up the outstanding work! On Tue, Mar 1, 2011 at 7:46 AM, David Chelimsky wrote: > I'm very pleased to announce the reformation of a core RSpec development > team: > > Chad Humphries, a.k.a. spicycode, has been involved with RSpec since the > 1.0 release, which he helped to usher out the door at RailsConf 2007. He > subsequently authored Micronaut [1], a lightweight, RSpec compatible spec > runner, which later became the basis for the rspec-core gem. > > Pat Maddox has been contributing patches and blogging about RSpec and BDD > since 2007 as well: most notably the =~ matcher for arrays and the last bit > of glue that turned plain text stories in Cucumber's predecessor, the RSpec > Story Runner (which succeeded rbehave) into a reality. > > Justin Ko has been actively contributing patches and participating on the > mailing list since last spring, but is probably best known for his creation > of http://relishapp.com, which now hosts RSpec 2's documentation. > > Myron Marston is the author of VCR [2], and has been contributing to RSpec > since last summer. He has a keen sense of BDD, and his patches continually > impress me with their thoroughness, attention to detail, and understanding > of the wider Ruby ecosystem in which RSpec makes its home. > > Please join me in welcoming Chad, Pat, Justin, and Myron to the RSpec > development team. > > Cheers, > David > > [1] http://github.com/spicycode/micronaut > [2] http://github.com/myronmarston/vcr > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Tim Gremore 920 471-1716 -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott at railsnewbie.com Tue Mar 1 12:14:31 2011 From: scott at railsnewbie.com (Scott Taylor) Date: Tue, 1 Mar 2011 12:14:31 -0500 Subject: [rspec-users] [ANN] Welcome Chad, Pat, Justin, and Myron! In-Reply-To: <7DFE5667-9486-40EE-A2F2-C673FB5BB744@gmail.com> References: <7DFE5667-9486-40EE-A2F2-C673FB5BB744@gmail.com> Message-ID: Welcome everyone (and double welcome to Pat)! Thanks for your hard work, guys! Cheers, Scott Taylor smtlaissezfaire On Mar 1, 2011, at 8:46 AM, David Chelimsky wrote: > I'm very pleased to announce the reformation of a core RSpec development team: > > Chad Humphries, a.k.a. spicycode, has been involved with RSpec since the 1.0 release, which he helped to usher out the door at RailsConf 2007. He subsequently authored Micronaut [1], a lightweight, RSpec compatible spec runner, which later became the basis for the rspec-core gem. > > Pat Maddox has been contributing patches and blogging about RSpec and BDD since 2007 as well: most notably the =~ matcher for arrays and the last bit of glue that turned plain text stories in Cucumber's predecessor, the RSpec Story Runner (which succeeded rbehave) into a reality. > > Justin Ko has been actively contributing patches and participating on the mailing list since last spring, but is probably best known for his creation of http://relishapp.com, which now hosts RSpec 2's documentation. > > Myron Marston is the author of VCR [2], and has been contributing to RSpec since last summer. He has a keen sense of BDD, and his patches continually impress me with their thoroughness, attention to detail, and understanding of the wider Ruby ecosystem in which RSpec makes its home. > > Please join me in welcoming Chad, Pat, Justin, and Myron to the RSpec development team. > > Cheers, > David > > [1] http://github.com/spicycode/micronaut > [2] http://github.com/myronmarston/vcr > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From cdemyanovich at gmail.com Tue Mar 1 13:26:00 2011 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Tue, 1 Mar 2011 13:26:00 -0500 Subject: [rspec-users] [ANN] Welcome Chad, Pat, Justin, and Myron! In-Reply-To: References: <7DFE5667-9486-40EE-A2F2-C673FB5BB744@gmail.com> Message-ID: Welcome, everyone! Thanks for helping to provide all of us with high-quality, useful tools that help us do what we love. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Mar 2 12:49:40 2011 From: lists at ruby-forum.com (Andrea Reginato) Date: Wed, 02 Mar 2011 18:49:40 +0100 Subject: [rspec-users] calbacks on models Message-ID: <5e2cffe0da89ea02ab33ab71fac87860@ruby-forum.com> Hi, I'm having some strange behavior on callbacks when testing with RSpec2. On my test, when I create a resource using the #create method the callbacks related to #before_create are not called. If I go to the console and I try to type the command Resource.create(client_uri: "http://example.com") all works fine. There are no mocks around, and I can't understand if this is a normal behavior using RSpec, if its due to Mongoid or something else. # resource.rb (model) class Resource include Mongoid::Document before_create :random_code, :create_expiration # resource_rspec.rb (testing suite) let(:resource) { Resource.create(client_uri: "http://example.com") Thanks a lot -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Mar 2 17:34:49 2011 From: lists at ruby-forum.com (Radhesh Kamath) Date: Wed, 02 Mar 2011 23:34:49 +0100 Subject: [rspec-users] Rspec2 for rails 2.3.8? In-Reply-To: <6024D9D7-39CB-4321-B2E9-55CD56E4937A@gmail.com> References: <375b9ed206908ddfdccaa1bea34f0484@ruby-forum.com> <6024D9D7-39CB-4321-B2E9-55CD56E4937A@gmail.com> Message-ID: <672c9ae496faef33dab000bcbd1ceef9@ruby-forum.com> David Chelimsky wrote in post #984311: > On Feb 25, 2011, at 4:19 PM, Radhesh Kamath wrote: > >> I am getting this error with my current setup, which I think, should not >> *** LOCAL GEMS *** >> bouncy-castle-java (1.5.0145.2) >> rack (1.2.1, 1.1.0) >> ruby-debug-base (0.10.3.2) >> # Requires supporting ruby files with custom matchers and macros, etc, >> # in spec/support/ and its subdirectories. >> Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} >> >> RSpec.configure do |config| > > If you're using rspec-rails-1.3.3, this line ^^ should raise an error > since the RSpec constant wasn't introduced until rspec-2.0. > > I'm guessing that the rails app is not correctly configured to use > rspec-rails-1.3.3. > > What's in config/environment.rb? Are you using bundler? If so, what's in > Gemfile? Do not worry about it... I just moved to Rails 3.0.4, because I was facing some other issues with my Rails 2.3.8 application. I am using the following gems now, but I still get an error saying this: Failure/Error: non_uniq_agg.should have(1).error_on(:name) NoMethodError: undefined method `error_on' for # There are failures for errors_on as well, which leads me to think that I am not requiring the proper stuff still. Here's my latest gem list: *** LOCAL GEMS *** abstract (1.0.0) actionmailer (3.0.4) actionpack (3.0.4) activemodel (3.0.4) activerecord (3.0.4) activerecord-jdbc-adapter (1.1.1) activerecord-jdbcmysql-adapter (1.1.1) activeresource (3.0.4) activesupport (3.0.4) acts_as_tree_rails3 (0.1.0) arel (2.0.9) backports (1.18.2) bouncy-castle-java (1.5.0145.2) builder (2.1.2) bundler (1.0.10) columnize (0.3.2) diff-lcs (1.1.2) erubis (2.6.6) facets (2.9.1) glassfish (1.0.3 universal-java, 1.0.2 universal-java) hoe (2.9.1, 2.7.0) i18n (0.4.0) ipaddress (0.7.0) jdbc-mysql (5.1.13) jruby-openssl (0.7.3, 0.7.1) json_pure (1.4.6) macaddr (1.0.0) mail (2.2.15) mime-types (1.16) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.13) rack-test (0.5.7) rails (3.0.4) railties (3.0.4) rake (0.8.7) rspec (2.5.0, 1.3.1) rspec-core (2.5.1) rspec-expectations (2.5.0) rspec-mocks (2.5.0) rspec-rails (2.5.0) ruby-debug (0.10.4) ruby-debug-base (0.10.4 java) rubyforge (2.0.4) sources (0.0.1) SyslogLogger (1.4.0) thor (0.14.6) treetop (1.4.9) tzinfo (0.3.24) uuid (2.3.1) My Ruby version: jruby 1.6.0.RC2 (ruby 1.8.7 patchlevel 330) (2011-02-09 5434c72) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_19) [linux-amd64-java] spec_helper.rb looks like so: ENV["RAILS_ENV"] ||= 'development' require File.expand_path("../../config/environment", __FILE__) # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| # == Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr config.mock_with :rspec # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures #config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. #config.use_transactional_fixtures = true end > >> # Remove this line if you're not using ActiveRecord or ActiveRecord >> >> http://rubyforge.org/mailman/listinfo/rspec-users > Cheers, > David -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Mar 2 17:37:25 2011 From: lists at ruby-forum.com (Radhesh Kamath) Date: Wed, 02 Mar 2011 23:37:25 +0100 Subject: [rspec-users] Rspec2 for rails 2.3.8? In-Reply-To: References: Message-ID: <95172d8b0110c726212450b23318d0e1@ruby-forum.com> P.S.: I looked at this error and used the workaround you have suggested, but it would be nice to use the errors_on, error_on etc. matchers (which is why I moved to Rails 3 in the first place :)) https://rspec.lighthouseapp.com/projects/5645/tickets/962-missing-error_on-method-with-rails-3 -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Mar 2 17:53:41 2011 From: lists at ruby-forum.com (Radhesh Kamath) Date: Wed, 02 Mar 2011 23:53:41 +0100 Subject: [rspec-users] Rspec2 for rails 2.3.8? In-Reply-To: <672c9ae496faef33dab000bcbd1ceef9@ruby-forum.com> References: <375b9ed206908ddfdccaa1bea34f0484@ruby-forum.com> <6024D9D7-39CB-4321-B2E9-55CD56E4937A@gmail.com> <672c9ae496faef33dab000bcbd1ceef9@ruby-forum.com> Message-ID: <6bf8f48c3f6752d900b9efe84aea3d3b@ruby-forum.com> Radhesh Kamath wrote in post #985062: > spec_helper.rb looks like so: > ENV["RAILS_ENV"] ||= 'development' > require File.expand_path("../../config/environment", __FILE__) > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > Sorry about the trouble, folks. It was my mistake. Adding require 'rspec/rails' fixed my problem. Thanks, Radhesh -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Mar 2 23:39:40 2011 From: lists at ruby-forum.com (Tushar Gandhi) Date: Thu, 03 Mar 2011 05:39:40 +0100 Subject: [rspec-users] Cucumber not inserting record in db Message-ID: Hi, I am trying to learn Cucumber. I have followed the tutorial on "http://www.ultrasaurus.com/sarahblog/2008/12/rails-2-day-3-behavior-driven-development/" Everything is working fine but my problem is it is not inserting any record in either development or test database. Can anyone tell me IS it the behaviour of the Cucumber or Am I missing something? Thanks, Tushar -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Mar 3 02:36:29 2011 From: lists at ruby-forum.com (Jiang Guimin) Date: Thu, 03 Mar 2011 08:36:29 +0100 Subject: [rspec-users] How to do controller.stub(:some_method) at request test when using rspec2 Message-ID: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> Hi, I hava a controller class DynamicFlowsController < ApplicationController def create @workflow = Workflow.find_by_id(params[:workflow_id]) table = @workflow.flex_table save_u_and_node(table, @workflow.node_definition) redirect_to "/#{table.name}" end end and I had written some rspec codes describe "save attachment" do before(:each) do workflow, table, form = init_stubs("baoxiaos", 1) definition = workflow.node_definition controller.should_receive(:save_u_and_node).with(table, definition) end it "should be successful" do file = UploadFile.new("a" * 10000, "testfile", "text/plain") post '/workflows/1/baoxiaos', { :attachment => file} response.should be_successful end end When I run the test, unfortunately rspec told me that "controller" is nil, I got a fail test. So, I want to konw how to get the correct "controller" object. Thanks Kayak -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Thu Mar 3 07:04:46 2011 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 3 Mar 2011 12:04:46 +0000 Subject: [rspec-users] Cucumber not inserting record in db In-Reply-To: References: Message-ID: Hi Tushar, On 3 Mar 2011, at 04:39, Tushar Gandhi wrote: > Hi, > I am trying to learn Cucumber. I have followed the tutorial on > "http://www.ultrasaurus.com/sarahblog/2008/12/rails-2-day-3-behavior-driven-development/" > > Everything is working fine but my problem is it is not inserting any > record in either development or test database. > > Can anyone tell me IS it the behaviour of the Cucumber or Am I missing > something? > > Thanks, > Tushar What's probably confused you is that, assuming you're using a Rails app, Cucumber uses Rails' built-in 'transactional fixtures' feature for tests. This means that the test runs inside a transaction which is rolled back at the end of the test, so if you look at the database from outside that process - even during the test run - you won't be able to see the data. Have a look at log/test.log and you should see some SQL statements running. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From dchelimsky at gmail.com Thu Mar 3 09:01:29 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Mar 2011 08:01:29 -0600 Subject: [rspec-users] How to do controller.stub(:some_method) at request test when using rspec2 In-Reply-To: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> References: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> Message-ID: <9A731591-D6EA-4DEE-B08C-A185AF71901F@gmail.com> On Mar 3, 2011, at 1:36 AM, Jiang Guimin wrote: > Hi, > I hava a controller > > class DynamicFlowsController < ApplicationController > > def create > @workflow = Workflow.find_by_id(params[:workflow_id]) > table = @workflow.flex_table > save_u_and_node(table, @workflow.node_definition) > redirect_to "/#{table.name}" > end > > end > > and I had written some rspec codes > > describe "save attachment" do > > before(:each) do > workflow, table, form = init_stubs("baoxiaos", 1) > definition = workflow.node_definition > controller.should_receive(:save_u_and_node).with(table, > definition) > end > > it "should be successful" do > file = UploadFile.new("a" * 10000, "testfile", "text/plain") > post '/workflows/1/baoxiaos', { :attachment => file} > response.should be_successful > end > > end > > When I run the test, unfortunately rspec told me that "controller" is > nil, I got a fail test. > So, I want to konw how to get the correct "controller" object. Please run it again with the --backtrace flag and post the output. From dchelimsky at gmail.com Thu Mar 3 09:11:28 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Mar 2011 08:11:28 -0600 Subject: [rspec-users] calbacks on models In-Reply-To: <5e2cffe0da89ea02ab33ab71fac87860@ruby-forum.com> References: <5e2cffe0da89ea02ab33ab71fac87860@ruby-forum.com> Message-ID: <8E096386-42B1-44C3-AB13-77D3D5182F94@gmail.com> On Mar 2, 2011, at 11:49 AM, Andrea Reginato wrote: > Hi, I'm having some strange behavior on callbacks when testing with > RSpec2. On my test, when I create a resource using the #create method > the callbacks related to #before_create are not called. If I go to the > console and I try to type the command Resource.create(client_uri: > "http://example.com") all works fine. > > There are no mocks around, and I can't understand if this is a normal > behavior using RSpec, if its due to Mongoid or something else. > > # resource.rb (model) > class Resource > include Mongoid::Document > before_create :random_code, :create_expiration > > # resource_rspec.rb (testing suite) > let(:resource) { Resource.create(client_uri: "http://example.com") > > Thanks a lot There's nothing in RSpec that implicitly interrupts the normal life cycle of any model objects. You can do so with stubs, but you have to do it explicitly. Is anybody else on this list having a similar experience? From Rob.aldred at stardotstar.com Thu Mar 3 09:29:15 2011 From: Rob.aldred at stardotstar.com (Rob Aldred) Date: Thu, 3 Mar 2011 14:29:15 +0000 Subject: [rspec-users] How to do controller.stub(:some_method) at request test when using rspec2 In-Reply-To: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> References: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> Message-ID: <5D4E9962-D8F8-4972-9FE0-A3AD4700609A@stardotstar.com> On 3 Mar 2011, at 07:36, Jiang Guimin wrote: > Hi, > I hava a controller > > class DynamicFlowsController < ApplicationController > > def create > @workflow = Workflow.find_by_id(params[:workflow_id]) > table = @workflow.flex_table > save_u_and_node(table, @workflow.node_definition) > redirect_to "/#{table.name}" > end > > end > > and I had written some rspec codes > > describe "save attachment" do > > before(:each) do > workflow, table, form = init_stubs("baoxiaos", 1) > definition = workflow.node_definition > controller.should_receive(:save_u_and_node).with(table, > definition) > end > > it "should be successful" do > file = UploadFile.new("a" * 10000, "testfile", "text/plain") > post '/workflows/1/baoxiaos', { :attachment => file} > response.should be_successful > end > > end > > When I run the test, unfortunately rspec told me that "controller" is > nil, I got a fail test. > So, I want to konw how to get the correct "controller" object. > > Thanks > Kayak > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Are you wanting to stub a method of the controller you are actually testing? I'm pretty sure this is bad practice. From lists at ruby-forum.com Thu Mar 3 12:38:17 2011 From: lists at ruby-forum.com (Jeremy Woertink) Date: Thu, 03 Mar 2011 18:38:17 +0100 Subject: [rspec-users] Callback when tests are done Message-ID: Currently when I run my tests, I run $ rspec spec/ -cf nested Is there a way to have a callback that when this task is done running, I can hook into how many tests failed, or how many passed, and have my own code run right after? Right now I'm just using an at_exit {} and putting some stuff in there, but I don't know how to access the final results as a variable, or if rspec has this built in already. Thanks, ~Jeremy -- Posted via http://www.ruby-forum.com/. From hedgehogshiatus at gmail.com Thu Mar 3 18:08:24 2011 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Fri, 4 Mar 2011 10:08:24 +1100 Subject: [rspec-users] Does RSpec interfere with Pathname#dirname or Pathname#realpath ? Message-ID: Hi, I starting a new project, and have run into behavior I cannot replicate in irb, (i.e. outside of using rspec) when the directory? returns true, so I thought I'd ask here, in case any one has seen this badhavior. ruby-1.9.2-p136 rspec (2.5.0) rspec-core (2.5.1) rspec-expectations (2.5.0) rspec-mocks (2.5.0) When I try to run this spec: require Pathname(__FILE__).ascend { |d| h=d+'spec_helper.rb'; break h if h.file? } describe B3::Bdd do it "should indicate RVM is installed locally" do B3::Bdd::Helpers.rvm_local_install?.should be_true end end The spec helper is: require 'rspec' ; require_relative '../lib/b3' Which describes this code: class B3 module Bdd module Helpers def rvm_local_install? puts ENV['rvm_path'] rvm_path = Pathname.new(ENV['rvm_path'] || '~/.rvm') rvm_path.dirname.realpath.directory? end module_function :rvm_local_install? end end end I get this error: https://gist.github.com/853798 irb version: $ irb ruby-1.9.2-p136 :001 > require 'pathname'; ruby-1.9.2-p136 :002 > Dir.chdir('/home/hedge/Documents/Workspaces/b3/spec/b3/') do ruby-1.9.2-p136 :003 > pn=Pathname.new(ENV['rvm_path'] || '~/.rvm') ruby-1.9.2-p136 :004?> puts pn.dirname.realpath.directory? ruby-1.9.2-p136 :005?> end true => nil ruby-1.9.2-p136 :006 > pn2=Pathname.new(ENV['rvm_path'] || '~/.rvm') => # ruby-1.9.2-p136 :007 > puts pn2.dirname.realpath.directory? true => nil I'd appreciate any comments or insights. -- ????' ??? ??????, ???' ?????? ?? ???? [The fox knows many things, but the hedgehog knows one big thing.] ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) http://wiki.hedgehogshiatus.com From hedgehogshiatus at gmail.com Thu Mar 3 18:37:39 2011 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Fri, 4 Mar 2011 10:37:39 +1100 Subject: [rspec-users] [Solved] Re: Does RSpec interfere with Pathname#dirname or Pathname#realpath ? In-Reply-To: References: Message-ID: On Fri, Mar 4, 2011 at 10:08 AM, Hedge Hog wrote: > Hi, > I starting a new project, and have run into behavior I cannot > replicate in irb, (i.e. outside of using rspec) when the directory? > returns true, so I thought I'd ask here, in case any one has seen this > badhavior. > ruby-1.9.2-p136 > rspec (2.5.0) > rspec-core (2.5.1) > rspec-expectations (2.5.0) > rspec-mocks (2.5.0) > > When I try to run this spec: > > require Pathname(__FILE__).ascend { |d| h=d+'spec_helper.rb'; break h > if h.file? } > describe B3::Bdd do > ?it "should indicate RVM is installed locally" do > ? ?B3::Bdd::Helpers.rvm_local_install?.should be_true > ?end > end > > The spec helper is: require 'rspec' ; require_relative '../lib/b3' > > Which describes this code: > > class B3 > ?module Bdd > ? ?module Helpers > ? ? ?def rvm_local_install? > ? ? ? ?puts ENV['rvm_path'] > ? ? ? ?rvm_path = Pathname.new(ENV['rvm_path'] || '~/.rvm') > ? ? ? ?rvm_path.dirname.realpath.directory? > ? ? ?end > ? ? ?module_function :rvm_local_install? > ? ?end > ?end > end > > > I get this error: > > https://gist.github.com/853798 > > irb version: > > $ irb > ruby-1.9.2-p136 :001 > require 'pathname'; > ruby-1.9.2-p136 :002 > > Dir.chdir('/home/hedge/Documents/Workspaces/b3/spec/b3/') do > ruby-1.9.2-p136 :003 > ? ? pn=Pathname.new(ENV['rvm_path'] || '~/.rvm') > ruby-1.9.2-p136 :004?> ? puts pn.dirname.realpath.directory? > ruby-1.9.2-p136 :005?> ? end > true > ?=> nil > ruby-1.9.2-p136 :006 > pn2=Pathname.new(ENV['rvm_path'] || '~/.rvm') > ?=> # > ruby-1.9.2-p136 :007 > puts pn2.dirname.realpath.directory? > true > ?=> nil > > I'd appreciate any comments or insights. > > -- > ????' ??? ??????, ???' ?????? ?? ???? > [The fox knows many things, but the hedgehog knows one big thing.] > ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) > http://wiki.hedgehogshiatus.com > Actually the cause is that Pathname#realpath does not seem handle ~ very well. Period. File#expand_path handles ~ fine: pn=Pathname.new('~/.rvm') ruby-1.9.2-p136 :020 > pn=Pathname.new('~/.rvm') => # ruby-1.9.2-p136 :021 > puts pn.realpath Errno::ENOENT: No such file or directory - /home/hedge/~ from /home/hedge/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/pathname.rb:446:in `realpath' from /home/hedge/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/pathname.rb:446:in `realpath' from (irb):21 from /home/hedge/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16:in `
' -- ????' ??? ??????, ???' ?????? ?? ???? [The fox knows many things, but the hedgehog knows one big thing.] ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) http://wiki.hedgehogshiatus.com From jason.nah at gmail.com Fri Mar 4 00:44:12 2011 From: jason.nah at gmail.com (Jason Nah) Date: Fri, 4 Mar 2011 16:44:12 +1100 Subject: [rspec-users] Ruby Debugger - not working in rspec? Message-ID: Howdy, I'm trying to get the ruby debugger to breakpoint at a specific line in source. Here's what I did: - Added require "ruby-debug" in spec_helper.rb - Added gem dependency to Gemfile (gem "ruby-debug" - In the spec, added before do breakpoint; 0; end - Ran it with rspec spec/models/myspec.rb -d Here's what I see - spec runs, but the debugger isn't invoked, and nothing pauses/halts for me to inspect. I'm on - MacOSX - ruby-debug 0.10.4 - rspec 2.5.0 - rails 3.0.4 Any ideas? Cheers, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedgehogshiatus at gmail.com Fri Mar 4 00:45:27 2011 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Fri, 4 Mar 2011 16:45:27 +1100 Subject: [rspec-users] How to intercept an instance method from StdLib (1.9.2) Message-ID: Hi, I'm struggling with something that seems to be simple, and I've not had any joy following the RSpec books suggestions (p. 187). I'd like to test that a method raises and error when a file is not found. I've tried adding this in my example just before I call my method, but it never seems to get invoked. Pathname.stub(:exist?).and_return(false) The whole example: it "should raise an error if RVM's install root does not exist" do Pathname.stub(:exist?).and_return(false) lambda{ B3::Bdd::Helpers.rvm_path}.should raise_error(RuntimeError, "File not found:") end Appreciate any tips. -- ????' ??? ??????, ???' ?????? ?? ???? [The fox knows many things, but the hedgehog knows one big thing.] ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) http://wiki.hedgehogshiatus.com From matt at mattwynne.net Fri Mar 4 04:12:08 2011 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 4 Mar 2011 09:12:08 +0000 Subject: [rspec-users] How to intercept an instance method from StdLib (1.9.2) In-Reply-To: References: Message-ID: On 4 Mar 2011, at 05:45, Hedge Hog wrote: > Hi, > I'm struggling with something that seems to be simple, and I've not > had any joy following the RSpec books suggestions (p. 187). > I'd like to test that a method raises and error when a file is not found. > I've tried adding this in my example just before I call my method, but > it never seems to get invoked. > Pathname.stub(:exist?).and_return(false) That's stubbing a class method. exist? is an instance method so you need to stub the specific instance of pathname that's being used in your object-under-test, rather than the Pathname class. > > The whole example: > > it "should raise an error if RVM's install root does not exist" do > Pathname.stub(:exist?).and_return(false) > lambda{ B3::Bdd::Helpers.rvm_path}.should > raise_error(RuntimeError, "File not found:") > end > > Appreciate any tips. > > -- > ????' ??? ??????, ???' ?????? ?? ???? > [The fox knows many things, but the hedgehog knows one big thing.] > Archilochus, Greek poet (c. 680 BC ? c. 645 BC) > http://wiki.hedgehogshiatus.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From dchelimsky at gmail.com Fri Mar 4 05:47:08 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 4 Mar 2011 04:47:08 -0600 Subject: [rspec-users] Ruby Debugger - not working in rspec? In-Reply-To: References: Message-ID: On Mar 3, 2011, at 11:44 PM, Jason Nah wrote: > Howdy, > > I'm trying to get the ruby debugger to breakpoint at a specific line in source. > > Here's what I did: > Added require "ruby-debug" in spec_helper.rb You don't need this ^^. > Added gem dependency to Gemfile (gem "ruby-debug" > In the spec, added before do breakpoint; 0; end Use "debugger" instead of "breakpoint". > Ran it with rspec spec/models/myspec.rb -d This is correct ^^. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.nah at gmail.com Fri Mar 4 06:39:05 2011 From: jason.nah at gmail.com (Jason Nah) Date: Fri, 4 Mar 2011 22:39:05 +1100 Subject: [rspec-users] Ruby Debugger - not working in rspec? In-Reply-To: References: Message-ID: Hi David, I found the problem. I had --drb option on, which caused all sorts of problems with the debugger. It would just skip right through the breakpoint/debugger statements with the --drb option on. Even though spork wasn't running. Removing the option got the debugger back on track. Cheers, Jason On 4 March 2011 21:47, David Chelimsky wrote: > On Mar 3, 2011, at 11:44 PM, Jason Nah wrote: > > Howdy, > > I'm trying to get the ruby debugger to breakpoint at a specific line in > source. > > Here's what I did: > > - Added require "ruby-debug" in spec_helper.rb > > You don't need this ^^. > > > - Added gem dependency to Gemfile (gem "ruby-debug" > - In the spec, added before do breakpoint; 0; end > > Use "debugger" instead of "breakpoint". > > > - Ran it with rspec spec/models/myspec.rb -d > > This is correct ^^. > > HTH, > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zhiqiang.lei at gmail.com Fri Mar 4 08:56:50 2011 From: zhiqiang.lei at gmail.com (Zhi-Qiang Lei) Date: Fri, 4 Mar 2011 21:56:50 +0800 Subject: [rspec-users] How to run example group in transaction Message-ID: <041BFDC9-B1AA-43B5-8F5A-A9A9AAE65218@gmail.com> Dear All, I want to wrap my example group in transaction to avoid record being created. How should I do? My rspec is 2.5.1, and ORM is Sequal. This way does not work for me. Thanks. class RSpec::Core::ExampleGroup def self.run(reporter) DB.transaction { super(reporter); raise(Sequel::Error::Rollback) } end end core_application_spec.rb:9:in `block in run': super: no superclass method `run' for RSpec::Core::ExampleGroup::Nested_1:Class (NoMethodError) Best regards, Zhi-Qiang Lei zhiqiang.lei at gmail.com From lists at ruby-forum.com Fri Mar 4 09:15:52 2011 From: lists at ruby-forum.com (Brian Ledsworth) Date: Fri, 04 Mar 2011 15:15:52 +0100 Subject: [rspec-users] Rails 3.0.1 and rspec-rails assign issue: render doesn't have instance var Message-ID: If you find the exception "undefined method 'model_name' for NilClass:Class" in view specs with Rails 3.0.1 and rspec-rails2, I believe it's a Rails issue. I receive the exception after calling render in my view spec, which indicates the @player instance var does not exist in the view. To troubleshoot, I added the following lines to my spec just below the assign: assign(:player, mock_model("Player").as_new_record) puts "#{_encapsulated_assigns[:player]}" puts "player=#{@player.inspect}" Yielding: Player_# player=nil The Instance var is not there, but rspec-rails has it in the hash used by 'assign'. I switched to Rails 3.0.5 and the issue went away. After going back to 3.0.1, it reoccured. There is some information regarding an assigns issue with Rails 3.0.0 in the RSpec source code. I'm posting this here because I couldn't find anyone else having this issue, so I'm simply sharing incase someone else does, to save them time. As a workaround, I'm skipping mock_model and creating a real AR for now. I've not tried other Rails versions after 3.0.1 besides 3.0.5 require 'spec_helper' class Player < ActiveRecord::Base end describe "players/new.html.erb" do it "displays the signup form" do @player = Player.new # work around puts "#{_encapsulated_assigns[:player]}" puts "player=#{@player.inspect}" render rendered.should contain("Hello") end end Brian -- Posted via http://www.ruby-forum.com/. From wolfmanjm at gmail.com Fri Mar 4 15:03:39 2011 From: wolfmanjm at gmail.com (Jim Morris) Date: Fri, 4 Mar 2011 12:03:39 -0800 (PST) Subject: [rspec-users] How to run example group in transaction In-Reply-To: <041BFDC9-B1AA-43B5-8F5A-A9A9AAE65218@gmail.com> References: <041BFDC9-B1AA-43B5-8F5A-A9A9AAE65218@gmail.com> Message-ID: <8b485919-b390-4758-a6da-2b74457f3898@i35g2000prd.googlegroups.com> In your spec_helper... RSpec.configure do |config| # setup transactional factory for sequel, when running transactional tests config.around(:each, :transactional => true) do |example| Sequel::DATABASES.first.transaction do example.run raise Sequel::Error::Rollback end end end On Mar 4, 5:56?am, Zhi-Qiang Lei wrote: > Dear All, > > I want to wrap my example group in transaction to avoid record being created. How should I do? My rspec is 2.5.1, and ORM is Sequal. This way does not work for me. Thanks. > > class RSpec::Core::ExampleGroup > ? def self.run(reporter) > ? ? DB.transaction { super(reporter); raise(Sequel::Error::Rollback) } > ? end > end > > core_application_spec.rb:9:in `block in run': super: no superclass method `run' for RSpec::Core::ExampleGroup::Nested_1:Class (NoMethodError) > > Best regards, > Zhi-Qiang Lei > zhiqiang.... at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From hedgehogshiatus at gmail.com Sat Mar 5 07:06:31 2011 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Sat, 5 Mar 2011 23:06:31 +1100 Subject: [rspec-users] How to intercept an instance method from StdLib (1.9.2) In-Reply-To: References: Message-ID: On Fri, Mar 4, 2011 at 8:12 PM, Matt Wynne wrote: > > On 4 Mar 2011, at 05:45, Hedge Hog wrote: > >> Hi, >> I'm struggling with something that seems to be simple, and I've not >> had any joy following the RSpec books suggestions (p. 187). >> I'd like to test that a method raises and error when a file is not found. >> I've tried adding this in my example just before I call my method, but >> it never seems to get invoked. >> Pathname.stub(:exist?).and_return(false) > > That's stubbing a class method. > > exist? is an instance method so you need to stub the specific instance of pathname that's being used in your object-under-test, rather than the Pathname class. > Is there a (clean) way to intercept this instance and add the stub/mock to it? What I see in the Rspec books suggests I'd have to force the Pathname instance to the surface, as some method argument. That feels all wrong - to have to change my method's interface just to test a behavior. Appreciate any experience, comments or suggestions people may have. >> >> The whole example: >> >> ? ?it "should raise an error if RVM's install root does not exist" do >> ? ? ? Pathname.stub(:exist?).and_return(false) >> ? ? ? lambda{ B3::Bdd::Helpers.rvm_path}.should >> raise_error(RuntimeError, "File not found:") >> ? ?end >> >> Appreciate any tips. >> >> -- >> ????' ??? ??????, ???' ?????? ?? ???? >> [The fox knows many things, but the hedgehog knows one big thing.] >> ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) >> http://wiki.hedgehogshiatus.com >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- ????' ??? ??????, ???' ?????? ?? ???? [The fox knows many things, but the hedgehog knows one big thing.] ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) http://wiki.hedgehogshiatus.com From matt at mattwynne.net Sat Mar 5 08:27:16 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 5 Mar 2011 13:27:16 +0000 Subject: [rspec-users] How to intercept an instance method from StdLib (1.9.2) In-Reply-To: References: Message-ID: <5B6532D0-A830-4BAF-8836-D81EDF6C0434@mattwynne.net> On 5 Mar 2011, at 12:06, Hedge Hog wrote: > On Fri, Mar 4, 2011 at 8:12 PM, Matt Wynne wrote: >> >> On 4 Mar 2011, at 05:45, Hedge Hog wrote: >> >>> Hi, >>> I'm struggling with something that seems to be simple, and I've not >>> had any joy following the RSpec books suggestions (p. 187). >>> I'd like to test that a method raises and error when a file is not found. >>> I've tried adding this in my example just before I call my method, but >>> it never seems to get invoked. >>> Pathname.stub(:exist?).and_return(false) >> >> That's stubbing a class method. >> >> exist? is an instance method so you need to stub the specific instance of pathname that's being used in your object-under-test, rather than the Pathname class. >> > > Is there a (clean) way to intercept this instance and add the > stub/mock to it? What I see in the Rspec books suggests I'd have to > force the Pathname instance to the surface, as some method argument. > That feels all wrong - to have to change my method's interface just to > test a behavior. > > Appreciate any experience, comments or suggestions people may have. You could try something like this: fake_pathname = double(Pathname, :exist? => false) Pathname.stub(:new).and_return(fake_pathname) This is basically The Ruby Way of doing dependency injection. > >>> >>> The whole example: >>> >>> it "should raise an error if RVM's install root does not exist" do >>> Pathname.stub(:exist?).and_return(false) >>> lambda{ B3::Bdd::Helpers.rvm_path}.should >>> raise_error(RuntimeError, "File not found:") >>> end >>> >>> Appreciate any tips. >>> >>> -- >>> ????' ??? ??????, ???' ?????? ?? ???? >>> [The fox knows many things, but the hedgehog knows one big thing.] >>> Archilochus, Greek poet (c. 680 BC ? c. 645 BC) >>> http://wiki.hedgehogshiatus.com >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> cheers, >> Matt >> >> matt at mattwynne.net >> 07974 430184 >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > ????' ??? ??????, ???' ?????? ?? ???? > [The fox knows many things, but the hedgehog knows one big thing.] > Archilochus, Greek poet (c. 680 BC ? c. 645 BC) > http://wiki.hedgehogshiatus.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From groups at fortuity.com Tue Mar 1 15:59:31 2011 From: groups at fortuity.com (Daniel Kehoe) Date: Tue, 1 Mar 2011 12:59:31 -0800 (PST) Subject: [rspec-users] installing RSpec requires changing generators in config/applicaton.rb? Message-ID: <76c8152c-fa2b-452a-ae40-eade0c4351b2@a21g2000prj.googlegroups.com> All the RSpec installation instructions I've seen (except the RSpec Book) say something like: Set up the RSpec generator by adding the following to config/ applicaton.rb: config.generators do |g| g.test_framework :rspec end Or Create a generator configuration file config/initializers/ generators.rb containing: Rails.application.config.generators do |g| g.test_framework = :rspec end Are either of these necessary? It seems when I leave out this step that running "rails generate controller home index" creates all the necessary files in the rspec directory. Was there a recent improvement that eliminates the need to set up rspec in config.generators? Or am I missing something? I'm using Rails 3.0.5 and rspec-rails 2.5. -- Daniel From lakshmanan at tenmiles.com Tue Mar 1 20:33:10 2011 From: lakshmanan at tenmiles.com (Lakshmanan) Date: Wed, 2 Mar 2011 07:03:10 +0530 Subject: [rspec-users] Rails 3 Upgrade Message-ID: Hi, I am upgrading a rails 2.1.0 app to Rails 3. Before I started my migration, I wrote all the tests cases for my app in Rspec 1.x version. I am doubting whether rspec test cases written in 1.x version will work when my app starts running in Rails3. After I upgrade to rails 3, i want to run my rspec 1.x version tests cases on it to see if I have broken anything during the upgrade. Will RSpec 1.x version work in a Rails 3 application ? Please help. From aselder at mac.com Thu Mar 3 16:43:04 2011 From: aselder at mac.com (Andrew Selder) Date: Thu, 3 Mar 2011 13:43:04 -0800 (PST) Subject: [rspec-users] Possible bug in proxy.rb in Rspec 1.3.1 Message-ID: In the proxy.rb file, Rspec 1.3.1 added a stanza to the it/else stack elsif @target.is_a?(Class) @target.superclass.send(sym, *args, &block) This just seems wrong to me and I'm pretty sure it's causing catastrophic errors in my build. Consider the following example: require 'spec_helper' class Foo def self.singleton @singleton ||= new end # Redirect all missing class methods to the singleton instance for backwards compatible API def self.method_missing(name,*args,&block) self.singleton.send(name,*args,&block) end def bar "abc" end end describe Foo do it "should mock correctly" do Foo.should_receive(:bar).and_return(123) Foo.bar.should == 123 end it "should call successfully after a mock" do Foo.bar.should == "abc" end end The first example creates a message_expectation for the Foo class object, which defines the :bar method on Foo, since as written Foo.respond_to?(:bar) returns false. This method send the name of the method to the __mock_proxy which delegates it to message received. As we move to the second example, the method defined by define_expected_method remains, which sends the message to the mock_proxy's message_received methods. Since there are no expectations defined, we drop to the suspect code. Since the @target of the proxy is Foo, and Foo is a Class, the message tries to get sent to Foo's superclass, namely Object, which doesn't define #bar and blows up. Filed as bug #17 at http://github.com/dchelimsky/rspec/issues/17 From mario.e.aquino at gmail.com Fri Mar 4 22:53:37 2011 From: mario.e.aquino at gmail.com (Mario Aquino) Date: Fri, 4 Mar 2011 19:53:37 -0800 (PST) Subject: [rspec-users] db:test:prepare interfering with rake spec pattern Message-ID: <6e3aa68c-ca84-4dc3-8a24-56c6b7d4c72d@w7g2000pre.googlegroups.com> I have a tricky problem with running rake spec in a Rails 3.0.3 project (using rspec-2.5.0, rspec-rails and rake 0.8.7). It may be that this mailing list is not the correct one to ask for help, but I am hoping that it is. When I run 'rake spec', the spec files for one of the gems my project uses are executed in addition to the spec files for my own project. I want to restrict the spec files that the rake task runs so that only my own project specs are executed because there is a conflict (from factory_girl) that gets triggered by the inclusion of the specs from one of my gem dependencies. I have created a custom rake task that calls the rspec rake task as follows: require 'rake' require 'rspec/core/rake_task' namespace :spec do desc "Run specs without invoking bundler" RSpec::Core::RakeTask.new('nob' => 'db:test:prepare') do |t| t.pattern = ['spec/**/*_spec.rb', 'vendor/engines/proposals/spec/ **/*_spec.rb'] t.skip_bundler = true end end My task declares a dependency on the 'db:test:prepare' task. When the db:test:prepare task runs, somehow the pattern that gets set by my task is ignored and instead specs from one of the gems my project depends on are executed in addition to my own project gems and this is a big problem for me. I would like to trigger the db setup-related activities that normally run before my specs execute. I haven't been able to figure out what is causing the 'pattern' I am declaring to be ignored when db:test:prepare runs, but something is definitely resetting the pattern (when I run my task without the 'db:test:prepare' dependency, only the specs from my project are executed). Any assistance would be appreciated. --Mario From dchelimsky at gmail.com Sat Mar 5 09:45:32 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 5 Mar 2011 08:45:32 -0600 Subject: [rspec-users] installing RSpec requires changing generators in config/applicaton.rb? In-Reply-To: <76c8152c-fa2b-452a-ae40-eade0c4351b2@a21g2000prj.googlegroups.com> References: <76c8152c-fa2b-452a-ae40-eade0c4351b2@a21g2000prj.googlegroups.com> Message-ID: On Mar 1, 2011, at 2:59 PM, Daniel Kehoe wrote: > All the RSpec installation instructions I've seen (except the RSpec > Book) say something like: > > Set up the RSpec generator by adding the following to config/ > applicaton.rb: > config.generators do |g| > g.test_framework :rspec > end > > Or > > Create a generator configuration file config/initializers/ > generators.rb containing: > Rails.application.config.generators do |g| > g.test_framework = :rspec > end > > Are either of these necessary? It seems when I leave out this step > that running > "rails generate controller home index" > creates all the necessary files in the rspec directory. > > Was there a recent improvement that eliminates the need to set up > rspec in config.generators? Or am I missing something? > > I'm using Rails 3.0.5 and rspec-rails 2.5. That hasn't been necessary for a long, long time. Are you seeing this recommendation in rspec's docs? Or in miscellaneous blog posts/wikis/etc? From dchelimsky at gmail.com Sat Mar 5 10:18:29 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 5 Mar 2011 09:18:29 -0600 Subject: [rspec-users] Rails 3 Upgrade In-Reply-To: References: Message-ID: On Mar 1, 2011, at 7:33 PM, Lakshmanan wrote: > Hi, > > I am upgrading a rails 2.1.0 app to Rails 3. Before I started my migration, I wrote all the tests cases for my app in Rspec 1.x version. > > I am doubting whether rspec test cases written in 1.x version will work when my app starts running in Rails3. After I upgrade to rails 3, i want to run my rspec 1.x version tests cases on it to see if I have broken anything during the upgrade. > > Will RSpec 1.x version work in a Rails 3 application ? Please help. Not out of the box, but a lot of what you've done will probably work just fine. Start with the Upgrade information at: http://relishapp.com/rspec/rspec-core http://relishapp.com/rspec/rspec-rails https://github.com/rspec/rspec-rails and feel free to ask questions here if you run into any specific problems. Good luck! From dchelimsky at gmail.com Sat Mar 5 10:21:06 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 5 Mar 2011 09:21:06 -0600 Subject: [rspec-users] db:test:prepare interfering with rake spec pattern In-Reply-To: <6e3aa68c-ca84-4dc3-8a24-56c6b7d4c72d@w7g2000pre.googlegroups.com> References: <6e3aa68c-ca84-4dc3-8a24-56c6b7d4c72d@w7g2000pre.googlegroups.com> Message-ID: <64BEAB1E-A3D9-42D7-8787-270453470DFC@gmail.com> On Mar 4, 2011, at 9:53 PM, Mario Aquino wrote: > I have a tricky problem with running rake spec in a Rails 3.0.3 > project (using rspec-2.5.0, rspec-rails and rake 0.8.7). It may be > that this mailing list is not the correct one to ask for help, but I > am hoping that it is. When I run 'rake spec', the spec files for one > of the gems my project uses are executed in addition to the spec files > for my own project. I want to restrict the spec files that the rake > task runs so that only my own project specs are executed because there > is a conflict (from factory_girl) that gets triggered by the inclusion > of the specs from one of my gem dependencies. > > I have created a custom rake task that calls the rspec rake task as > follows: > > require 'rake' > require 'rspec/core/rake_task' > > namespace :spec do > desc "Run specs without invoking bundler" > RSpec::Core::RakeTask.new('nob' => 'db:test:prepare') do |t| > t.pattern = ['spec/**/*_spec.rb', 'vendor/engines/proposals/spec/**/*_spec.rb'] > t.skip_bundler = true > end > end > > > My task declares a dependency on the 'db:test:prepare' task. When the > db:test:prepare task runs, somehow the pattern that gets set by my > task is ignored What happens if you remove that dependency and run: rake db:test:prepare rake spec:nob > and instead specs from one of the gems my project > depends on are executed in addition to my own project gems and this is > a big problem for me. I would like to trigger the db setup-related > activities that normally run before my specs execute. I haven't been > able to figure out what is causing the 'pattern' I am declaring to be > ignored when db:test:prepare runs, but something is definitely > resetting the pattern (when I run my task without the > 'db:test:prepare' dependency, only the specs from my project are > executed). > > Any assistance would be appreciated. > > --Mario > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From dk at structuralartistry.com Sat Mar 5 11:19:08 2011 From: dk at structuralartistry.com (David Kahn) Date: Sat, 5 Mar 2011 10:19:08 -0600 Subject: [rspec-users] Rails 3 Upgrade In-Reply-To: References: Message-ID: On Tue, Mar 1, 2011 at 7:33 PM, Lakshmanan wrote: > Hi, > > I am upgrading a rails 2.1.0 app to Rails 3. Just a note, you may want to try upgrading first to the latest Rails 2 (is it still 2.3.9?) version. You will still have a lot to do jumping between the latest 2 and 3 but seems that a lot of the support and info out there targets that jump moreso than going from earlier 2 versions. May or may not be a big deal depending on your app. > Before I started my migration, I wrote all the tests cases for my app in > Rspec 1.x version. > > I am doubting whether rspec test cases written in 1.x version will work > when my app starts running in Rails3. After I upgrade to rails 3, i want to > run my rspec 1.x version tests cases on it to see if I have broken anything > during the upgrade. > > Will RSpec 1.x version work in a Rails 3 application ? Please help. > _______________________________________________ > 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 hedgehogshiatus at gmail.com Sun Mar 6 05:30:30 2011 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Sun, 6 Mar 2011 21:30:30 +1100 Subject: [rspec-users] How to intercept an instance method from StdLib (1.9.2) In-Reply-To: <5B6532D0-A830-4BAF-8836-D81EDF6C0434@mattwynne.net> References: <5B6532D0-A830-4BAF-8836-D81EDF6C0434@mattwynne.net> Message-ID: On Sun, Mar 6, 2011 at 12:27 AM, Matt Wynne wrote: > > On 5 Mar 2011, at 12:06, Hedge Hog wrote: > >> On Fri, Mar 4, 2011 at 8:12 PM, Matt Wynne wrote: >>> >>> On 4 Mar 2011, at 05:45, Hedge Hog wrote: >>> >>>> Hi, >>>> I'm struggling with something that seems to be simple, and I've not >>>> had any joy following the RSpec books suggestions (p. 187). >>>> I'd like to test that a method raises and error when a file is not found. >>>> I've tried adding this in my example just before I call my method, but >>>> it never seems to get invoked. >>>> Pathname.stub(:exist?).and_return(false) >>> >>> That's stubbing a class method. >>> >>> exist? is an instance method so you need to stub the specific instance of pathname that's being used in your object-under-test, rather than the Pathname class. >>> >> >> Is there a (clean) way to intercept this instance and add the >> stub/mock to it? ?What I see in the Rspec books suggests I'd have to >> force the Pathname instance to the surface, as some method argument. >> That feels all wrong - to have to change my method's interface just to >> test a behavior. >> >> Appreciate any experience, comments or suggestions people may have. > > You could try something like this: > > ? ?fake_pathname = double(Pathname, :exist? => false) > ? ?Pathname.stub(:new).and_return(fake_pathname) > > This is basically The Ruby Way of doing dependency injection. Thank you Matt. Not sure if I'm going mad but it seems the Rspec book, Ch 14, doesn't cover this use case in much detail. I appreciate it is an introductory book, so this may be out of scope. Alternatively: It may be that, reaching inside a method in this way is a 'test-smell' indicating some bad practice - I'm I being too sensitive? TIA > >> >>>> >>>> The whole example: >>>> >>>> ? ?it "should raise an error if RVM's install root does not exist" do >>>> ? ? ? Pathname.stub(:exist?).and_return(false) >>>> ? ? ? lambda{ B3::Bdd::Helpers.rvm_path}.should >>>> raise_error(RuntimeError, "File not found:") >>>> ? ?end >>>> >>>> Appreciate any tips. >>>> >>>> -- >>>> ????' ??? ??????, ???' ?????? ?? ???? >>>> [The fox knows many things, but the hedgehog knows one big thing.] >>>> ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) >>>> http://wiki.hedgehogshiatus.com >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> cheers, >>> Matt >>> >>> matt at mattwynne.net >>> 07974 430184 >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> -- >> ????' ??? ??????, ???' ?????? ?? ???? >> [The fox knows many things, but the hedgehog knows one big thing.] >> ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) >> http://wiki.hedgehogshiatus.com >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- ????' ??? ??????, ???' ?????? ?? ???? [The fox knows many things, but the hedgehog knows one big thing.] ? Archilochus, Greek poet (c. 680 BC ? c. 645 BC) http://wiki.hedgehogshiatus.com From matt at mattwynne.net Sun Mar 6 05:58:03 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 6 Mar 2011 10:58:03 +0000 Subject: [rspec-users] How to intercept an instance method from StdLib (1.9.2) In-Reply-To: References: <5B6532D0-A830-4BAF-8836-D81EDF6C0434@mattwynne.net> Message-ID: <0ACFDD4D-2BDE-4EBC-AB2C-5EC211896510@mattwynne.net> On 6 Mar 2011, at 10:30, Hedge Hog wrote: > On Sun, Mar 6, 2011 at 12:27 AM, Matt Wynne wrote: >> >> On 5 Mar 2011, at 12:06, Hedge Hog wrote: >> >>> On Fri, Mar 4, 2011 at 8:12 PM, Matt Wynne wrote: >>>> >>>> On 4 Mar 2011, at 05:45, Hedge Hog wrote: >>>> >>>>> Hi, >>>>> I'm struggling with something that seems to be simple, and I've not >>>>> had any joy following the RSpec books suggestions (p. 187). >>>>> I'd like to test that a method raises and error when a file is not found. >>>>> I've tried adding this in my example just before I call my method, but >>>>> it never seems to get invoked. >>>>> Pathname.stub(:exist?).and_return(false) >>>> >>>> That's stubbing a class method. >>>> >>>> exist? is an instance method so you need to stub the specific instance of pathname that's being used in your object-under-test, rather than the Pathname class. >>>> >>> >>> Is there a (clean) way to intercept this instance and add the >>> stub/mock to it? What I see in the Rspec books suggests I'd have to >>> force the Pathname instance to the surface, as some method argument. >>> That feels all wrong - to have to change my method's interface just to >>> test a behavior. >>> >>> Appreciate any experience, comments or suggestions people may have. >> >> You could try something like this: >> >> fake_pathname = double(Pathname, :exist? => false) >> Pathname.stub(:new).and_return(fake_pathname) >> >> This is basically The Ruby Way of doing dependency injection. > > Thank you Matt. Not sure if I'm going mad but it seems the Rspec > book, Ch 14, doesn't cover this use case in much detail. > I appreciate it is an introductory book, so this may be out of scope. > Alternatively: It may be that, reaching inside a method in this way is > a 'test-smell' indicating some bad practice - I'm I being too > sensitive? > > TIA In the Java / C# world, I'd be more used having to do something like this: fake_pathname = double(Pathname, :exist? => false) helper = B3::Bdd::Helpers.new(fake_pathname) or even fake_pathname = double(Pathname, :exist? => false) fake_pathanme_factory = double("PathnameFactory", :new => fake_pathname) helper = B3::Bdd::Helpers.new(fake_pathname_factory) Fortunately, this kind of thing just isn't necessary in Ruby. The risk of doing what I've suggested above is that there are probably other legitimate ways of instantiating a Pathname (I don't know what they are, but I can imagine there could be some) and you might one day want to refactor your tested class to use one of those alternative ways. If you did, your test would break for no good reason, just because you were no longer hitting Pathname.new and so the stubs stopped working. However, .new is pretty idiomatic in Ruby, so you're normally safe. > >> >>> >>>>> >>>>> The whole example: >>>>> >>>>> it "should raise an error if RVM's install root does not exist" do >>>>> Pathname.stub(:exist?).and_return(false) >>>>> lambda{ B3::Bdd::Helpers.rvm_path}.should >>>>> raise_error(RuntimeError, "File not found:") >>>>> end >>>>> >>>>> Appreciate any tips. >>>>> >>>>> -- >>>>> ????' ??? ??????, ???' ?????? ?? ???? >>>>> [The fox knows many things, but the hedgehog knows one big thing.] >>>>> Archilochus, Greek poet (c. 680 BC ? c. 645 BC) >>>>> http://wiki.hedgehogshiatus.com >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> cheers, >>>> Matt >>>> >>>> matt at mattwynne.net >>>> 07974 430184 >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >>> >>> -- >>> ????' ??? ??????, ???' ?????? ?? ???? >>> [The fox knows many things, but the hedgehog knows one big thing.] >>> Archilochus, Greek poet (c. 680 BC ? c. 645 BC) >>> http://wiki.hedgehogshiatus.com >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> cheers, >> Matt >> >> matt at mattwynne.net >> 07974 430184 >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > ????' ??? ??????, ???' ?????? ?? ???? > [The fox knows many things, but the hedgehog knows one big thing.] > Archilochus, Greek poet (c. 680 BC ? c. 645 BC) > http://wiki.hedgehogshiatus.com cheers, Matt matt at mattwynne.net 07974 430184 From dolzenko at gmail.com Sun Mar 6 07:44:38 2011 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Sun, 06 Mar 2011 15:44:38 +0300 Subject: [rspec-users] Rails 3 Upgrade In-Reply-To: References: Message-ID: <4D7381B6.50009@gmail.com> You need to change a few syntax-related things, please check the group archives this thread specifically http://groups.google.com/group/rspec/browse_frm/thread/7e0232e668c679cc (also linked from there http://snyderscribbles.blogspot.com/2011/01/rspec-2-changes-from-rspec-1.html ) On 3/2/2011 4:33 AM, Lakshmanan wrote: > Hi, > > I am upgrading a rails 2.1.0 app to Rails 3. Before I started my migration, I wrote all the tests cases for my app in Rspec 1.x version. > > I am doubting whether rspec test cases written in 1.x version will work when my app starts running in Rails3. After I upgrade to rails 3, i want to run my rspec 1.x version tests cases on it to see if I have broken anything during the upgrade. > > Will RSpec 1.x version work in a Rails 3 application ? Please help. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Mar 7 04:55:36 2011 From: lists at ruby-forum.com (Ashish Kumar) Date: Mon, 07 Mar 2011 10:55:36 +0100 Subject: [rspec-users] [Rails] Can't get controller test working with RSpec 2 and edge Rails 3 In-Reply-To: <244d9712-d604-4ecd-a269-304617cd6359@e5g2000yqn.googlegroups.com> References: <201BD3E3-C65A-48C7-940C-42EEEFE02666@gmail.com> <244d9712-d604-4ecd-a269-304617cd6359@e5g2000yqn.googlegroups.com> Message-ID: <26f30d9a0d7b85168f66214ef0b89c64@ruby-forum.com> dchelimsky at gmail.com wrote in post #921577: > On Jun 25, 9:21?pm, David Chelimsky wrote: >> > require 'spec_helper' >> >> > ? ? undefined method `get' for # @__memoized={}> >> ? include RSpec::Rails::ControllerExampleGroup >> David > FYI: http://github.com/rspec/rspec-rails/issues/99 Just add config.include RSpec::Rails::ControllerExampleGroup in spec_helper.rb -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Mar 8 03:45:18 2011 From: lists at ruby-forum.com (Jiang Guimin) Date: Tue, 08 Mar 2011 09:45:18 +0100 Subject: [rspec-users] How to do controller.stub(:some_method) at request test when using rspec2 In-Reply-To: <5D4E9962-D8F8-4972-9FE0-A3AD4700609A@stardotstar.com> References: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> <5D4E9962-D8F8-4972-9FE0-A3AD4700609A@stardotstar.com> Message-ID: Rob Aldred wrote in post #985198: > On 3 Mar 2011, at 07:36, Jiang Guimin wrote: > >> end >> controller.should_receive(:save_u_and_node).with(table, >> >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > Are you wanting to stub a method of the controller you are actually > testing? > I'm pretty sure this is bad practice. You are right, it's bad practice, i got nightmare because of "save_u_and_node". "save_u_and_node" is a huge code block that was written by my colleagues some months ago, and i need add some features based at "save_u_and_node", but i can't find any spec codes for "save_u_and_node", so i had to stub "save_u_and_node" in controller roughly in order to pass spec. Thanks This forum's email notification featrue seems dosen't work -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Mar 8 04:34:26 2011 From: lists at ruby-forum.com (Jiang Guimin) Date: Tue, 08 Mar 2011 10:34:26 +0100 Subject: [rspec-users] How to do controller.stub(:some_method) at request test when using rspec2 In-Reply-To: <9A731591-D6EA-4DEE-B08C-A185AF71901F@gmail.com> References: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> <9A731591-D6EA-4DEE-B08C-A185AF71901F@gmail.com> Message-ID: David Chelimsky wrote in post #985199: > On Mar 3, 2011, at 1:36 AM, Jiang Guimin wrote: >> end >> controller.should_receive(:save_u_and_node).with(table, >> >> When I run the test, unfortunately rspec told me that "controller" is >> nil, I got a fail test. >> So, I want to konw how to get the correct "controller" object. > > Please run it again with the --backtrace flag and post the output. Ok, I run it again then rspec told me so mush, and I noted the message "An expectation of :save_u_and_node was set on nil", is it said that controller is nil? Why rspec can't get controller in requests test for this spec? No DRb server is running. Running in local process instead ... ..An expectation of :save_u_and_node was set on nil. Called from /home/yang/workspace/trunk/ent_os/spec/requests/workflows/dynamic_flows_spec.rb:57:in `block (3 levels) in '. Use allow_message_expectations_on_nil to disable warnings. F Failures: 1) ???? save attachment should be successful Failure/Error: click_button "??" NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:204:in `transaction' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/implicit_render.rb:4:in `send_action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:151:in `process_action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/rendering.rb:11:in `process_action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/callbacks.rb:18:in `block in process_action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:435:in `_run__33140632__process_action__340421511__callbacks' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/callbacks.rb:17:in `process_action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications.rb:52:in `block in instrument' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications.rb:52:in `instrument' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/instrumentation.rb:29:in `process_action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/rescue.rb:17:in `process_action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:120:in `process' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/rendering.rb:40:in `process' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal.rb:138:in `dispatch' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal.rb:178:in `block in action' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:62:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:62:in `dispatch' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:27:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/route_set.rb:148:in `block in call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:93:in `block in recognize' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:89:in `optimized_each' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:92:in `recognize' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/route_set.rb:139:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:492:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/head.rb:14:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/methodoverride.rb:24:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/params_parser.rb:21:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/flash.rb:182:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/cookies.rb:295:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/query_cache.rb:32:in `block in call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/query_cache.rb:12:in `cache' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/query_cache.rb:31:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/callbacks.rb:46:in `block in call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:415:in `_run_call_callbacks' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/callbacks.rb:44:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/sendfile.rb:107:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/remote_ip.rb:48:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/rack/logger.rb:13:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/runtime.rb:17:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/lock.rb:11:in `block in call' # :10:in `synchronize' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/lock.rb:11:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/static.rb:30:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:168:in `call' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.6/lib/rack/mock_session.rb:30:in `request' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.6/lib/rack/test.rb:209:in `process_request' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.6/lib/rack/test.rb:66:in `post' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/session.rb:278:in `process_request' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/session.rb:119:in `request_page' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/elements/form.rb:20:in `submit' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/elements/field.rb:193:in `click' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/scope.rb:291:in `click_button' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/methods.rb:7:in `click_button' # ./spec/requests/workflows/dynamic_flows_spec.rb:62:in `block (3 levels) in ' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:29:in `instance_eval' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:29:in `run_in' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:60:in `block in run_all' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:60:in `each' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:60:in `run_all' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:106:in `run_hook' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:190:in `block in eval_before_eachs' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:190:in `each' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:190:in `eval_before_eachs' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:136:in `run_before_each' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:48:in `block (2 levels) in run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:98:in `with_around_hooks' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:46:in `block in run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:91:in `block in with_pending_capture' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:90:in `catch' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:90:in `with_pending_capture' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:45:in `run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:261:in `block in run_examples' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:257:in `map' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:257:in `run_examples' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:231:in `run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in `block in run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in `map' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in `run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in `block (2 levels) in run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in `map' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in `block in run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/reporter.rb:12:in `report' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:24:in `run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:55:in `run_in_process' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:44:in `run' # /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:10:in `block in autorun' -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Mar 8 09:10:18 2011 From: lists at ruby-forum.com (Amit Kulkarni) Date: Tue, 08 Mar 2011 15:10:18 +0100 Subject: [rspec-users] problem running rspec test with Webrat Message-ID: <5528a0884c3a57d80e1bdaa972c7b8ae@ruby-forum.com> Hi, I am trying to run rspec testcase using webrat but it is showing me an error as "undefined method `last_response' for #" Following are my configurations: Gemfile: roup :development, :test do gem 'sqlite3-ruby', :require => 'sqlite3' gem "rspec", "=2.4.0" gem "rspec-rails", "2.4.0" #gem "rspec", ">= 2.0.0.beta.16" #gem "rspec-rails", ">= 2.0.0.beta.16" gem 'webrat', '>=0.7.2.beta.6', :git => 'git://github.com/orangewise/webrat.git' gem "autotest" gem "autotest-rails" gem "factory_girl", "=2.0.0.beta1" gem 'capybara' gem "launchy" #gem 'autotest-fsevent' end spec/spec_helper ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/core' require 'rspec/matchers' require 'webrat/core/matchers' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} require 'webrat' require 'webrat/core/matchers' include Webrat::Methods include Webrat::Matchers Webrat.configure do |config| config.mode = :rack end #World(Webrat::Methods) #World(Webrat::Matchers) RSpec.configure do |config| config.include Rack::Test::Methods # == Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr config.mock_with :rspec # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true include Webrat::Methods include Webrat::Matchers end Initially my spec was under spec/models/file_name,after searching i change the path to spec/integratation/file_name but no success Also initially i was using rspec version 2.0.0.beta.16 but after searching i found that for webrat the version required for rspec is 2.40. I also installed that version but no success. Also i want to know since my application is running on rails3,will the change in version of rspec will effect running the specs -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Mar 8 10:36:31 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Mar 2011 09:36:31 -0600 Subject: [rspec-users] problem running rspec test with Webrat In-Reply-To: <5528a0884c3a57d80e1bdaa972c7b8ae@ruby-forum.com> References: <5528a0884c3a57d80e1bdaa972c7b8ae@ruby-forum.com> Message-ID: <38D10901-8978-4F82-8BDD-E0A114C1E627@gmail.com> On Mar 8, 2011, at 8:10 AM, Amit Kulkarni wrote: > Hi, > I am trying to run rspec testcase using webrat but it is showing me an > error as "undefined method `last_response' for #" > > Following are my configurations: > Gemfile: > > roup :development, :test do > gem 'sqlite3-ruby', :require => 'sqlite3' > gem "rspec", "=2.4.0" > gem "rspec-rails", "2.4.0" > #gem "rspec", ">= 2.0.0.beta.16" > #gem "rspec-rails", ">= 2.0.0.beta.16" > gem 'webrat', '>=0.7.2.beta.6', :git => > 'git://github.com/orangewise/webrat.git' > gem "autotest" > gem "autotest-rails" > gem "factory_girl", "=2.0.0.beta1" > gem 'capybara' > gem "launchy" You should use webrat or capybara, but not both. Cheers, David From jcran at 0x0e.org Tue Mar 8 20:08:06 2011 From: jcran at 0x0e.org (Jonathan Cran) Date: Tue, 08 Mar 2011 19:08:06 -0600 Subject: [rspec-users] undefined method `flunk' for # Message-ID: <4D76D2F6.8050109@0x0e.org> I'm running into an issue using ONLY rspec version 1.3.3 (no rails / rspec-rails with this project) where i'm hitting the following error: My code looks like this: describe Win32Meterpreter before :all helper_method end def helper_method ## If a session came back, try to interact with it. if @session @session.load_stdapi else flunk "Couldn't get a session!" end end end And the error: undefined method `flunk' for # I believe this method is contained within the rspec-rails classes and i'm not using those in this case. Is there an alternative to using flunk - Suggestions? jcran -- Jonathan Cran jcran at 0x0e.org 515.890.0070 From jcran at 0x0e.org Tue Mar 8 20:10:31 2011 From: jcran at 0x0e.org (Jonathan Cran) Date: Tue, 08 Mar 2011 19:10:31 -0600 Subject: [rspec-users] undefined method `flunk' for # In-Reply-To: <4D76D2F6.8050109@0x0e.org> References: <4D76D2F6.8050109@0x0e.org> Message-ID: <4D76D387.6090901@0x0e.org> On 03/08/2011 07:08 PM, Jonathan Cran wrote: > I'm running into an issue using ONLY rspec version 1.3.3 (no rails / > rspec-rails with this project) where i'm hitting the following error: > My mistake, that's rspec version 1.3.1. jcran -- Jonathan Cran jcran at 0x0e.org 515.890.0070 From magerison at gmail.com Wed Mar 9 07:30:03 2011 From: magerison at gmail.com (Magnus Erickson) Date: Wed, 9 Mar 2011 13:30:03 +0100 Subject: [rspec-users] Are there any ways to detect spec faults during a run? In-Reply-To: References: Message-ID: Hi, Is there a way to detect if an example has failed? Something like a: "example_failed?" method. In my case I need to dump some information, i.e trace and error log, to be used when analyzing what went wrong in the example. I'm thinking about putting it in a after(:each) {}. BR Magnus -------------- next part -------------- An HTML attachment was scrubbed... URL: From magerison at gmail.com Wed Mar 9 07:32:06 2011 From: magerison at gmail.com (Magnus Erickson) Date: Wed, 9 Mar 2011 13:32:06 +0100 Subject: [rspec-users] Are there any ways to detect spec faults during a run? In-Reply-To: References: Message-ID: Hi, Is there a way to detect if an example has failed? Something like a: "example_failed?" method. In my case I need to dump some information, i.e trace and error log, to be used when analyzing what went wrong in the example. I'm thinking about putting it in a after(:each) {}. BR Magnus -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken.chien at gmail.com Wed Mar 9 17:23:14 2011 From: ken.chien at gmail.com (Ken Chien) Date: Wed, 9 Mar 2011 17:23:14 -0500 Subject: [rspec-users] How to do controller.stub(:some_method) at request test when using rspec2 In-Reply-To: References: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> <9A731591-D6EA-4DEE-B08C-A185AF71901F@gmail.com> Message-ID: You should be able to call: controller.stub(:some_method) My suspicion is what you passed to the describe method. Instead of: describe "save attachment" pass the controller name, without quotes: describe DynamicFlowsController then controller.stub should work, and then you can refactor the dependency on save_u_and_node later. Ken 2011/3/8 Jiang Guimin > David Chelimsky wrote in post #985199: > > On Mar 3, 2011, at 1:36 AM, Jiang Guimin wrote: > >> end > >> controller.should_receive(:save_u_and_node).with(table, > >> > >> When I run the test, unfortunately rspec told me that "controller" is > >> nil, I got a fail test. > >> So, I want to konw how to get the correct "controller" object. > > > > Please run it again with the --backtrace flag and post the output. > > > > Ok, I run it again then rspec told me so mush, and I noted the message > "An expectation of :save_u_and_node was set on nil", is it said that > controller is nil? > Why rspec can't get controller in requests test for this spec? > > No DRb server is running. Running in local process instead ... > ..An expectation of :save_u_and_node was set on nil. Called from > > /home/yang/workspace/trunk/ent_os/spec/requests/workflows/dynamic_flows_spec.rb:57:in > `block (3 levels) in '. Use > allow_message_expectations_on_nil to disable warnings. > F > > Failures: > > 1) ???? save attachment should be successful > Failure/Error: click_button "??" > NoMethodError: > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in > `transaction' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/transactions.rb:204:in > `transaction' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/implicit_render.rb:4:in > `send_action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:151:in > `process_action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/rendering.rb:11:in > `process_action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/callbacks.rb:18:in > `block in process_action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:435:in > `_run__33140632__process_action__340421511__callbacks' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:409:in > `_run_process_action_callbacks' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in > `run_callbacks' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/callbacks.rb:17:in > `process_action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/instrumentation.rb:30:in > `block in process_action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications.rb:52:in > `block in instrument' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications/instrumenter.rb:21:in > `instrument' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/notifications.rb:52:in > `instrument' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/instrumentation.rb:29:in > `process_action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/rescue.rb:17:in > `process_action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:120:in > `process' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/abstract_controller/rendering.rb:40:in > `process' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal.rb:138:in > `dispatch' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal/rack_delegation.rb:14:in > `dispatch' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_controller/metal.rb:178:in > `block in action' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:62:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:62:in > `dispatch' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:27:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/route_set.rb:148:in > `block in call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:93:in > `block in recognize' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:89:in > `optimized_each' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:92:in > `recognize' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-mount-0.6.13/lib/rack/mount/route_set.rb:139:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:492:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/best_standards_support.rb:17:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/head.rb:14:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/methodoverride.rb:24:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/params_parser.rb:21:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/flash.rb:182:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/session/abstract_store.rb:149:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/cookies.rb:295:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/query_cache.rb:32:in > `block in call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/query_cache.rb:28:in > `cache' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/query_cache.rb:12:in > `cache' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/query_cache.rb:31:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/callbacks.rb:46:in > `block in call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:415:in > `_run_call_callbacks' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/callbacks.rb:44:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/sendfile.rb:107:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/remote_ip.rb:48:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/rack/logger.rb:13:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/runtime.rb:17:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.3/lib/active_support/cache/strategy/local_cache.rb:72:in > `call' > # > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/lock.rb:11:in > `block in call' > # :10:in `synchronize' > # > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/lock.rb:11:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/static.rb:30:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.3/lib/rails/application.rb:168:in > `call' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.6/lib/rack/mock_session.rb:30:in > `request' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.6/lib/rack/test.rb:209:in > `process_request' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.6/lib/rack/test.rb:66:in > `post' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/session.rb:278:in > `process_request' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/session.rb:119:in > `request_page' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/elements/form.rb:20:in > `submit' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/elements/field.rb:193:in > `click' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/scope.rb:291:in > `click_button' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/webrat-0.7.3/lib/webrat/core/methods.rb:7:in > `click_button' > # ./spec/requests/workflows/dynamic_flows_spec.rb:62:in `block (3 > levels) in ' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:29:in > `instance_eval' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:29:in > `run_in' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:60:in > `block in run_all' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:60:in > `each' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:60:in > `run_all' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/hooks.rb:106:in > `run_hook' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:190:in > `block in eval_before_eachs' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:190:in > `each' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:190:in > `eval_before_eachs' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:136:in > `run_before_each' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:48:in > `block (2 levels) in run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:98:in > `with_around_hooks' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:46:in > `block in run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:91:in > `block in with_pending_capture' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:90:in > `catch' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:90:in > `with_pending_capture' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example.rb:45:in > `run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:261:in > `block in run_examples' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:257:in > `map' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:257:in > `run_examples' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:231:in > `run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in > `block in run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in > `map' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/example_group.rb:232:in > `run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in > `block (2 levels) in run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in > `map' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:27:in > `block in run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/reporter.rb:12:in > `report' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/command_line.rb:24:in > `run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:55:in > `run_in_process' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:44:in > `run' > # > > /home/yang/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.4.0/lib/rspec/core/runner.rb:10:in > `block in autorun' > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Mar 10 03:35:53 2011 From: lists at ruby-forum.com (Jiang Guimin) Date: Thu, 10 Mar 2011 09:35:53 +0100 Subject: [rspec-users] How to do controller.stub(:some_method) at request test when using rspec2 In-Reply-To: References: <795f41036126f00e07e4231fbbb07aa0@ruby-forum.com> <9A731591-D6EA-4DEE-B08C-A185AF71901F@gmail.com> Message-ID: <35c44bbfb44bd77add8079c889a6c2bb@ruby-forum.com> Kenrick Chien wrote in post #986591: > pass the controller name, without quotes: > describe DynamicFlowsController > > then > controller.stub > > should work, and then you can refactor the dependency on save_u_and_node > later. > > Ken Thanks, it's work now! But I can't get the controller object for integration test. -- Posted via http://www.ruby-forum.com/. From shamaoke at hotmail.com Thu Mar 10 05:32:38 2011 From: shamaoke at hotmail.com (Shamaoke) Date: Thu, 10 Mar 2011 02:32:38 -0800 (PST) Subject: [rspec-users] unless filter Message-ID: <1049473a-e29f-4775-9533-50cbdd7719cf@a21g2000prj.googlegroups.com> Hi. Why doesn't the following filter work? ~~~ # encoding: utf-8 # ./example_spec.rb RSpec.configure do |config| config.filter = { unless: :condition_acceptable } end describe 'some code' do it 'does one', if: :condition_acceptable do end it 'does two', unless: :condition_acceptable do end end ~~~ ~~~ $ rspec example_spec.rb No examples were matched # instead of 'some code does two' ~~~ Thanks. Debian GNU/Linux 5.0.7; Ruby 1.9.2; RSpec 2.5.0. From lists at ruby-forum.com Thu Mar 10 06:52:31 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Thu, 10 Mar 2011 12:52:31 +0100 Subject: [rspec-users] Good tutorial for RSpec With Rails 3 Message-ID: <47244ccef17d2b58df14bacc391d4f53@ruby-forum.com> Hi, I am looking for a good free tutorial which implements RSpec with Rails 3. I have found many tutorials which work for Rails 2.x but leads you into issues when trying the same in Rails 3. Rspec Gem also has updated , coming off the age.. Leading into compatibility issues. I am able to setup RSpec in my app but I can't fix issues I am getting into. Its like i am implementing a customized app without get an overall idea of what changes I would have to carefully incorporate due to usage of the latest Rails ( say 3.0 ) and the latest RSpec gem 2.5. I am also making use of rspec-rails 2.5 gem. Such tutorials( based on earlier versions of Rails and Rspec ) I have seen so far include: http://fr.ivolo.us/posts/rspec-tutorial-part-2-a-simple-test http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/ I am unable to find Part 2 of David's tutorial also. I wonder where I could find that. I also have seen a similar questions on stackoverflow.com like:- Rails: Good Rspec2 example usage? (Also: Cucumber, Pickle, Capybara) The only free tutorial relevant to Rspec with Rails 3 that I could find so far is:- http://ruby.railstutorial.org/ruby-on-rails-tutorial-book I am using ruby 1.9.2 and rails 3.0.3 along with Ubuntu 10.04 . Thanks for any suggestions you can help me with. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Mar 10 08:47:07 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Thu, 10 Mar 2011 14:47:07 +0100 Subject: [rspec-users] Issues implementing Rspec with Rails3 from tutorial Message-ID: Hi, I am a newbie to Rails 3 and Rspec. Kindly excuse my being a novice. I am trying to implement RSpec with Rails 3. I am using Rails 3.0.3 with Ruby 1.9.2 on Ubuntu 10.04 os. I am using rspec 2.5 gem and rspec-rails 2.5 gem. I am referring to the following tutorial:- http://www.railsfire.com/article/rspec-behaviour-driven-development-testing-framework This tutorial is implemented on Rails 2.x with an older version of rspec and rspec-rails. I tried to implement ***exactly the same tutorial*** with my configuration, but I have run into some issues. I am unable to figure out what I must have done wrong. I am sure about one thing that I am not using the `rails_scaffold` generator as used in this tutorial. Instead of using the `rails_scaffold` generator, I made use of the following command `rails g scaffold post title:string body:text` I don't seem to have it(rspec_scaffold) in my list of generators which as part of Rails 3 and the additional ones that will come with Rspec. The error I am getting is :- mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo5$ rake spec (in /home/mohnish/rails_testing/10Mar11/rspec_demo5) rake aborted! You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] (See full trace by running task with --trace) mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo5$ rake spec --trace (in /home/mohnish/rails_testing/10Mar11/rspec_demo5) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:load (first_time) ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge rake aborted! You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:429:in `block (3 levels) in ' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in `call' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in `each' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in `execute' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain' /home/mohnish/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:607:in `block in invoke_prerequisites' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:604:in `each' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:596:in `block in invoke_with_call_chain' /home/mohnish/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:460:in `block (3 levels) in ' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in `call' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in `each' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in `execute' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain' /home/mohnish/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:607:in `block in invoke_prerequisites' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:604:in `each' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:596:in `block in invoke_with_call_chain' /home/mohnish/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/bin/rake:31:in `' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `load' /home/mohnish/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `
' mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo5$ Any suggestions on what I must be doing wrong and how to fix the same. Kindly help. Thank you very much. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Mar 10 08:49:02 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Thu, 10 Mar 2011 14:49:02 +0100 Subject: [rspec-users] How to use rspec_scaffold generator with latest rspec gem. Message-ID: <2117e089d59778382e726a792115d13d@ruby-forum.com> Hi, I am a newbie to Rails 3 and Rspec. Kindly excuse my being a novice. I am trying to use RSpec with Rails 3. I am using rails 3.0.3 and ruby 1.9.2 on ubuntu 10.04 os. I am currently referring to the tutorial on :- http://www.railsfire.com/article/rspec-behaviour-driven-development-testing-framework. This tutorial not only uses old plugins , but old Rails version of 2.x also. I am unable to use the old rspec generator ( rspec_scaffold ) with rspec 2.5 and rspec-rails 2.5 gem. As expected I get the following error as given below. mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo3$ rails g rspec_scaffold post title:string body:text Could not find generator rspec_scaffold. mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo3$ Could you please tell me how should I give to accordingly for it to work for me using the above RoR configuration. Thanks -- Posted via http://www.ruby-forum.com/. From thecatwasnot at gmail.com Thu Mar 10 09:36:26 2011 From: thecatwasnot at gmail.com (Pixel) Date: Thu, 10 Mar 2011 08:36:26 -0600 Subject: [rspec-users] How to use rspec_scaffold generator with latest rspec gem. In-Reply-To: <2117e089d59778382e726a792115d13d@ruby-forum.com> References: <2117e089d59778382e726a792115d13d@ruby-forum.com> Message-ID: On Thu, Mar 10, 2011 at 7:49 AM, Mohnish J. wrote: > I am unable to use the old rspec generator ( rspec_scaffold ) with rspec > 2.5 and rspec-rails 2.5 gem. As expected I get the following error as > given below. > > ? ?mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo3$ rails g > rspec_scaffold post title:string body:text > ? ?Could not find generator rspec_scaffold. > ? ?mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo3$ > > Could you please tell me how should I give to accordingly for it to work > for me using the above RoR configuration. > Hi Mohnish, The rails generator script will produce a list of it's generators if you simply type 'rails g' you can get further assistance by typing 'rails g generator --help' such as 'rails g scaffold --help' I suspect that you are wanting to generate a scaffold with all of the rspec tests as well, because rails 3 went modular you no longer need a special command to get rspec tests, simply by installing the gem and including it in both :development and :test environments in your Gemfile, your scaffold generator will automatically produce rspec tests for you. First check to make sure the rspec:install generator is listed under 'rails g' and that you have run that generator first, then you can 'rails g scaffold' and the model/controller/views and necessary specs will be generated. Rspec 2 docs are a bit of a work in progress at the moment as I understand it but there is much to be gleaned from referencing http://relishapp.com/rspec before you email the list. Specifically the rspec-rails section. Hope that helps, Cole From dchelimsky at gmail.com Thu Mar 10 09:58:33 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Mar 2011 08:58:33 -0600 Subject: [rspec-users] How to use rspec_scaffold generator with latest rspec gem. In-Reply-To: <2117e089d59778382e726a792115d13d@ruby-forum.com> References: <2117e089d59778382e726a792115d13d@ruby-forum.com> Message-ID: On Mar 10, 2011, at 7:49 AM, Mohnish J. wrote: > Hi, > > I am a newbie to Rails 3 and Rspec. Kindly excuse my being a novice. > > I am trying to use RSpec with Rails 3. I am using rails 3.0.3 and ruby > 1.9.2 on ubuntu 10.04 os. > > I am currently referring to the tutorial on :- > http://www.railsfire.com/article/rspec-behaviour-driven-development-testing-framework. > This tutorial not only uses old plugins , but old Rails version of 2.x > also. > > I am unable to use the old rspec generator ( rspec_scaffold ) with rspec > 2.5 and rspec-rails 2.5 gem. As expected I get the following error as > given below. > > mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo3$ rails g > rspec_scaffold post title:string body:text > Could not find generator rspec_scaffold. > mohnish at mohnish-desktop:~/rails_testing/10Mar11/rspec_demo3$ > > Could you please tell me how should I give to accordingly for it to work > for me using the above RoR configuration. rails generate rspec:install rails generate scaffold In Rails 3, once you run the rspec:install generator, the Rails generators delegate out to rspec-rails to generate the spec files. You might also want to check out http://ruby.railstutorial.org/. Cheers, David From jon at jonhoman.com Thu Mar 10 10:24:08 2011 From: jon at jonhoman.com (Jon Homan) Date: Thu, 10 Mar 2011 09:24:08 -0600 Subject: [rspec-users] Good tutorial for RSpec With Rails 3 In-Reply-To: <47244ccef17d2b58df14bacc391d4f53@ruby-forum.com> References: <47244ccef17d2b58df14bacc391d4f53@ruby-forum.com> Message-ID: I recommend getting a copy of The RSpec Book ( http://www.pragprog.com/titles/achbd/the-rspec-book). I read through that when I was fairly new to RSpec and I think it helped ramp up quickly. Jon Homan On Thu, Mar 10, 2011 at 5:52 AM, Mohnish J. wrote: > Hi, > > I am looking for a good free tutorial which implements RSpec with Rails > 3. I have found many tutorials which work for Rails 2.x but leads you > into issues when trying the same in Rails 3. Rspec Gem also has updated > , coming off the age.. Leading into compatibility issues. > > I am able to setup RSpec in my app but I can't fix issues I am getting > into. Its like i am implementing a customized app without get an overall > idea of what changes I would have to carefully incorporate due to usage > of the latest Rails ( say 3.0 ) and the latest RSpec gem 2.5. I am also > making use of rspec-rails 2.5 gem. > > Such tutorials( based on earlier versions of Rails and Rspec ) I have > seen so far include: > > http://fr.ivolo.us/posts/rspec-tutorial-part-2-a-simple-test > > http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/ > > I am unable to find Part 2 of David's tutorial also. I wonder where I > could find that. > > I also have seen a similar questions on stackoverflow.com like:- > > Rails: Good Rspec2 example usage? (Also: Cucumber, Pickle, Capybara) > > The only free tutorial relevant to Rspec with Rails 3 that I could find > so far is:- > > http://ruby.railstutorial.org/ruby-on-rails-tutorial-book > > I am using ruby 1.9.2 and rails 3.0.3 along with Ubuntu 10.04 . > > Thanks for any suggestions you can help me with. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phani.rubyonrails at gmail.com Thu Mar 10 14:00:25 2011 From: phani.rubyonrails at gmail.com (phani kumar) Date: Fri, 11 Mar 2011 00:30:25 +0530 Subject: [rspec-users] Rspec single file Message-ID: Hi Guys, How can run the single spec file without loading the environment. I know ruby spec commands will load the total environment. I want to run the files one by one those are not in same folder and i want to load test environment once for all 10 files. Can we run single file through the Rspec:Core:Runner or some other class? Can you guys please help me? -Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmymartin at gmail.com Thu Mar 10 16:22:11 2011 From: jimmymartin at gmail.com (James Martin) Date: Fri, 11 Mar 2011 08:22:11 +1100 Subject: [rspec-users] Good tutorial for RSpec With Rails 3 In-Reply-To: <47244ccef17d2b58df14bacc391d4f53@ruby-forum.com> References: <47244ccef17d2b58df14bacc391d4f53@ruby-forum.com> Message-ID: I understand you're looking for 'free' tutorials but I would really strongly advise you check out Michael Hartl's http://ruby.railstutorial.org/screencast series. I'm not affiliated with this in any way, but I watched them recently (more for the Rails 3 info than RSpec) and found the use of RSpec and test-first development (not /really/ TDD) to be worth the price alone - there are so many rspec-rails specific gotchas that you just don't even think about when using naked RSpec. The screencast + PDF combination represent excellent value for money (currently $95); which you should easily make back when you deploy your first killer Rails app. :-) HTH James. On Thu, Mar 10, 2011 at 10:52 PM, Mohnish J. wrote: > Hi, > > I am looking for a good free tutorial which implements RSpec with Rails > 3. I have found many tutorials which work for Rails 2.x but leads you > into issues when trying the same in Rails 3. Rspec Gem also has updated > , coming off the age.. Leading into compatibility issues. > > I am able to setup RSpec in my app but I can't fix issues I am getting > into. Its like i am implementing a customized app without get an overall > idea of what changes I would have to carefully incorporate due to usage > of the latest Rails ( say 3.0 ) and the latest RSpec gem 2.5. I am also > making use of rspec-rails 2.5 gem. > > Such tutorials( based on earlier versions of Rails and Rspec ) I have > seen so far include: > > http://fr.ivolo.us/posts/rspec-tutorial-part-2-a-simple-test > > http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/ > > I am unable to find Part 2 of David's tutorial also. I wonder where I > could find that. > > I also have seen a similar questions on stackoverflow.com like:- > > Rails: Good Rspec2 example usage? (Also: Cucumber, Pickle, Capybara) > > The only free tutorial relevant to Rspec with Rails 3 that I could find > so far is:- > > http://ruby.railstutorial.org/ruby-on-rails-tutorial-book > > I am using ruby 1.9.2 and rails 3.0.3 along with Ubuntu 10.04 . > > Thanks for any suggestions you can help me with. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken.chien at gmail.com Thu Mar 10 17:11:46 2011 From: ken.chien at gmail.com (Ken Chien) Date: Thu, 10 Mar 2011 17:11:46 -0500 Subject: [rspec-users] Rspec single file In-Reply-To: References: Message-ID: I assume you're asking in the context of Rails? If so, take a look at Spork[1]. You can choose what you want to load once, and what you want to load before every spec. Ken --- [1] https://github.com/timcharper/spork 2011/3/10 phani kumar > > > Hi Guys, > > How can run the single spec file without loading the environment. > > I know ruby spec commands will load the total environment. > > I want to run the files one by one those are not in same folder and i want > to load test environment once for all 10 files. > > Can we run single file through the Rspec:Core:Runner or some other class? > > Can you guys please help me? > > -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 lists at ruby-forum.com Thu Mar 10 18:06:54 2011 From: lists at ruby-forum.com (Tyrel R.) Date: Fri, 11 Mar 2011 00:06:54 +0100 Subject: [rspec-users] Trying to test flash messaging with rspec Message-ID: <483a7b3300e19dcb9935d2986a50b8f0@ruby-forum.com> Hello every one, So my this rspec test fails: [code] it "should have a welcome message" do post :create, :user => @attr response.flash[:success].should eql("Welcome new user!") end [/code] However when I create a new user the flash message does display just as I had wanted it to. The controller has this in it: [code] def create @user = User.new(params[:user]) if @user.save flash[:success] = "Welcome new user!" redirect_to @user else @title = "Sign up" render 'new' end end def show @user = User.find(params[:id]) @title = @user.userName end end [/code] And the view displays with: [code] <%= flash_helper %> The helper is: def flash_helper f_names = [:success] fl = '' for name in f_names if flash[name] fl = fl + "
#{flash[name]}
" end flash[name] = nil; end return fl.html_safe end [/code] Like I said the flash message works just fine however the test fails any ideas would be greatly appreciated. Hope all is well :) -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Mar 10 20:14:41 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Fri, 11 Mar 2011 02:14:41 +0100 Subject: [rspec-users] How to use rspec_scaffold generator with latest rspec gem. In-Reply-To: References: <2117e089d59778382e726a792115d13d@ruby-forum.com> Message-ID: <3668d3860e12411f61aff7c75bd00838@ruby-forum.com> David Chelimsky wrote in post #986732: > On Mar 10, 2011, at 7:49 AM, Mohnish J. wrote: > >> also. >> Could you please tell me how should I give to accordingly for it to work >> for me using the above RoR configuration. > > rails generate rspec:install > rails generate scaffold > > In Rails 3, once you run the rspec:install generator, the Rails > generators delegate out to rspec-rails to generate the spec files. > > You might also want to check out http://ruby.railstutorial.org/. > > Cheers, > David Hi David, Thank you very much for you reply, I now understand that this isn't needed anymore with Rails 3. I had in another post on the same forum mentioned about one of your blogs:- http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/. I am unable to find Part 2 of your tutorial. Could you please tell me where could I find the same. Thanks again..:) -- Posted via http://www.ruby-forum.com/. From jimmymartin at gmail.com Thu Mar 10 20:27:52 2011 From: jimmymartin at gmail.com (James Martin) Date: Fri, 11 Mar 2011 12:27:52 +1100 Subject: [rspec-users] Trying to test flash messaging with rspec In-Reply-To: <483a7b3300e19dcb9935d2986a50b8f0@ruby-forum.com> References: <483a7b3300e19dcb9935d2986a50b8f0@ruby-forum.com> Message-ID: How about just testing the flash directly, which should be accessible from your test: flash[:success].should =~ /welcome new user/i I've used a case insensitive regex here, which I think captures the intent of your test without being quite so rigid. What do you think? On Fri, Mar 11, 2011 at 10:06 AM, Tyrel R. wrote: > Hello every one, > > So my this rspec test fails: > > [code] > it "should have a welcome message" do > post :create, :user => @attr > response.flash[:success].should eql("Welcome new user!") > end > [/code] > > However when I create a new user the flash message does display just as > I had wanted it to. > > The controller has this in it: > [code] > def create > @user = User.new(params[:user]) > if @user.save > flash[:success] = "Welcome new user!" > redirect_to @user > else > @title = "Sign up" > render 'new' > end > end > > def show > @user = User.find(params[:id]) > @title = @user.userName > end > end > [/code] > > And the view displays with: > [code] > <%= flash_helper %> > > The helper is: > > def flash_helper > f_names = [:success] > fl = '' > > for name in f_names > if flash[name] > fl = fl + "
#{flash[name]}
" > end > flash[name] = nil; > end > return fl.html_safe > end > [/code] > > Like I said the flash message works just fine however the test fails any > ideas would be greatly appreciated. > > Hope all is well :) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Mar 10 21:19:43 2011 From: lists at ruby-forum.com (Tyrel R.) Date: Fri, 11 Mar 2011 03:19:43 +0100 Subject: [rspec-users] Trying to test flash messaging with rspec In-Reply-To: <483a7b3300e19dcb9935d2986a50b8f0@ruby-forum.com> References: <483a7b3300e19dcb9935d2986a50b8f0@ruby-forum.com> Message-ID: <350163c12beab97bcfb29b06b8e419e0@ruby-forum.com> That worked perfectly thank you :) -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Mar 11 00:52:27 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Fri, 11 Mar 2011 06:52:27 +0100 Subject: [rspec-users] How to use rspec_scaffold generator with latest rspec gem. In-Reply-To: References: <2117e089d59778382e726a792115d13d@ruby-forum.com> Message-ID: <762871ec0c4e65e4e1777d275732b00c@ruby-forum.com> Hi Cole, Thanks for the link and yorr reply. Yep , I did want to generate a scaffold with all rspec tests. Pixel wrote in post #986740: > On Thu, Mar 10, 2011 at 7:49 AM, Mohnish J. > wrote: > >> for me using the above RoR configuration. >> > > Hi Mohnish, > > The rails generator script will produce a list of it's generators if > you simply type 'rails g' you can get further assistance by typing > 'rails g generator --help' such as 'rails g scaffold --help' I > suspect that you are wanting to generate a scaffold with all of the > rspec tests as well, because rails 3 went modular you no longer need a > special command to get rspec tests, simply by installing the gem and > including it in both :development and :test environments in your > Gemfile, your scaffold generator will automatically produce rspec > tests for you. First check to make sure the rspec:install generator > is listed under 'rails g' and that you have run that generator first, > then you can 'rails g scaffold' and the model/controller/views and > necessary specs will be generated. > > Rspec 2 docs are a bit of a work in progress at the moment as I > understand it but there is much to be gleaned from referencing > http://relishapp.com/rspec before you email the list. Specifically > the rspec-rails section. > > Hope that helps, > Cole -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Mar 11 00:54:24 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Fri, 11 Mar 2011 06:54:24 +0100 Subject: [rspec-users] Good tutorial for RSpec With Rails 3 In-Reply-To: References: <47244ccef17d2b58df14bacc391d4f53@ruby-forum.com> Message-ID: Hi Jon, Thanks for your recommendation. Jon Homan wrote in post #986735: > I recommend getting a copy of The RSpec Book ( > http://www.pragprog.com/titles/achbd/the-rspec-book). I read through > that > when I was fairly new to RSpec and I think it helped ramp up quickly. > > Jon Homan -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Mar 11 00:55:29 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Fri, 11 Mar 2011 06:55:29 +0100 Subject: [rspec-users] Good tutorial for RSpec With Rails 3 In-Reply-To: References: <47244ccef17d2b58df14bacc391d4f53@ruby-forum.com> Message-ID: Hi James, Thanks for your suggestion. James Martin wrote in post #986783: > I understand you're looking for 'free' tutorials but I would really > strongly > advise you check out Michael Hartl's > http://ruby.railstutorial.org/screencast series. I'm not affiliated > with this in any way, but I watched > them recently (more for the Rails 3 info than RSpec) and found the use > of > RSpec and test-first development (not /really/ TDD) to be worth the > price > alone - there are so many rspec-rails specific gotchas that you just > don't > even think about when using naked RSpec. > > The screencast + PDF combination represent excellent value for money > (currently $95); which you should easily make back when you deploy your > first killer Rails app. :-) > > > HTH > > James. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Mar 11 10:55:00 2011 From: lists at ruby-forum.com (Rails Learner) Date: Fri, 11 Mar 2011 16:55:00 +0100 Subject: [rspec-users] RSpec is missing gems even though they are installed Message-ID: <4f27722144d6f4dbac1abbb8e48d5747@ruby-forum.com> Hi Folks, I am getting an error when trying to run my examples in RSpec: Command: spec spec Error: Missing these required gems: rspec-rails >= 1.2.2 cucumber >= 0.2.2 You're running: ruby 1.8.7.334 at /Users/auser/.rvm/rubies/ruby-1.8.7-p334/bin/ruby rubygems 1.6.2 at /Users/auser/.rvm/gems/ruby-1.8.7-p334, /Users/auser/.rvm/gems/ruby-1.8.7-p334 at global I have installed ruby using RVM. I know that RSpec is looking in wrong location for the gems. It's looking in "/Users/auser/.rvm/gems/ruby-1.8.7-p334 at global" location while the gems exists in "Users/amitp/.rvm/gems/ruby-1.8.7-p334" location. How do I fix this issue? Please help! Thanks a lot!!!! -- Posted via http://www.ruby-forum.com/. From jko170 at gmail.com Fri Mar 11 15:17:45 2011 From: jko170 at gmail.com (Justin Ko) Date: Fri, 11 Mar 2011 12:17:45 -0800 Subject: [rspec-users] unless filter In-Reply-To: <1049473a-e29f-4775-9533-50cbdd7719cf@a21g2000prj.googlegroups.com> References: <1049473a-e29f-4775-9533-50cbdd7719cf@a21g2000prj.googlegroups.com> Message-ID: On Thu, Mar 10, 2011 at 2:32 AM, Shamaoke wrote: > Hi. > > Why doesn't the following filter work? > > ~~~ > # encoding: utf-8 > # ./example_spec.rb > > RSpec.configure do |config| > config.filter = { > unless: :condition_acceptable > } > end > > describe 'some code' do > it 'does one', if: :condition_acceptable do > end > > it 'does two', unless: :condition_acceptable do > end > end > ~~~ > > ~~~ > $ rspec example_spec.rb > No examples were matched # instead of 'some code does two' > ~~~ > > Thanks. > > Debian GNU/Linux 5.0.7; > Ruby 1.9.2; > RSpec 2.5.0. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > If :condition_acceptable evaluates to false, your example will run. If you are looking to "match" key/values, don't use :if or :unless -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at rapleaf.com Fri Mar 11 17:55:47 2011 From: james at rapleaf.com (James OBrien) Date: Fri, 11 Mar 2011 14:55:47 -0800 Subject: [rspec-users] RCov Message-ID: I'm using Rake to run my specs e.g. task :test do Rake::Task['spec'].execute end how can I aspect this to include some sort of coverage report - RCov maybe? Of course, I could just escape to the command line with something like system('rcov rspec ') but I prefer to solve this programaticaly since our spec task has filters set up etc which I don't want to duplicate. any help appreciated. it seems the documentation on the RSpec 1 site http://rspec.info/documentation/tools/rake.html points to a solution that no longer works in RSpec 2 Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Fri Mar 11 19:07:40 2011 From: jko170 at gmail.com (Justin Ko) Date: Fri, 11 Mar 2011 16:07:40 -0800 Subject: [rspec-users] RCov In-Reply-To: References: Message-ID: On Fri, Mar 11, 2011 at 2:55 PM, James OBrien wrote: > I'm using Rake to run my specs e.g. > > task :test do > Rake::Task['spec'].execute > end > > how can I aspect this to include some sort of coverage report - RCov maybe? > > Of course, I could just escape to the command line with something like > system('rcov rspec ') but I prefer to solve this > programaticaly since our spec task has filters set up etc which I don't want > to duplicate. > > any help appreciated. > > it seems the documentation on the RSpec 1 site > http://rspec.info/documentation/tools/rake.html points to a solution that > no longer works in RSpec 2 > > Thanks! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > If you're looking at how to use RCov in your rake tasks, here is an example: https://github.com/rspec/rspec-core/blob/master/Rakefile#L30 If that all looks confusing, I would read up on how Rake works. Hope that helps! -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Sun Mar 6 17:48:29 2011 From: nick at deadorange.com (Nick) Date: Sun, 6 Mar 2011 14:48:29 -0800 (PST) Subject: [rspec-users] render_views and render_to_string Message-ID: <4787929.143.1299451709771.JavaMail.geo-discussion-forums@yqmi17> Hey guys. One of my controller actions uses #render_to_string to send back a JSON response. When I try to spec this, Ruby raises a NoMethodError, saying that #render_to_string doesn't exist in my controller action. Here's the controller action, spec, and output: http://pastie.org/1640962 Any idea what I'm doing wrong? Thanks, Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From diogo.borges.almeida at gmail.com Mon Mar 7 02:30:57 2011 From: diogo.borges.almeida at gmail.com (DBA) Date: Sun, 6 Mar 2011 23:30:57 -0800 (PST) Subject: [rspec-users] undefined method 'get' Message-ID: <05e825ec-3275-425a-acb6-fd6365e6405f@f31g2000pri.googlegroups.com> Hello guys, I was just starting a rails 3.0.5 application with rspec-rails 2.5.0 and ruby 1.9.2-p180 and when I went to describe my controller I ran into this undefined method 'get' error. Here's the spec that is causing the problem (which lives in the folder spec/controllers) require 'spec_helper' describe ArticlesController, :type => :controller do describe "GET index" do get :index response.should be_successful end end And here's the error it throws: spec/controllers/articles_controller_spec.rb:13:in `block (2 levels) in ': undefined method `get' for # (NoMethodError) from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:132:in `module_eval' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:132:in `subclass' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:119:in `describe' from /spec/controllers/articles_controller_spec.rb:12:in `block in ' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:132:in `module_eval' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:132:in `subclass' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:119:in `describe' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/extensions/object.rb:6:in `describe' from /spec/controllers/articles_controller_spec.rb:3:in `' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/configuration.rb:386:in `load' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/configuration.rb:386:in `block in load_spec_files' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/configuration.rb:386:in `map' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/configuration.rb:386:in `load_spec_files' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/command_line.rb:18:in `run' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/runner.rb:55:in `run_in_process' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/runner.rb:46:in `run' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/runner.rb:10:in `block in autorun' What could be causing rspec not to find controller example group methods? Best regards, DBA From magerison at gmail.com Wed Mar 9 07:00:20 2011 From: magerison at gmail.com (Magnus Erickson) Date: Wed, 9 Mar 2011 13:00:20 +0100 Subject: [rspec-users] Are there any ways to detect spec faults during a run? Message-ID: Hi, Is there a way to detect if an example has failed? Something like a: "example_failed?" method. In my case I need to dump some information, i.e trace and error log, to be used when analyzing what went wrong in the example. I'm thinking about putting it in a after(:each) {}. BR Magnus -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Wed Mar 9 22:39:16 2011 From: nick at deadorange.com (Nick) Date: Wed, 9 Mar 2011 19:39:16 -0800 (PST) Subject: [rspec-users] render_views and render_to_string In-Reply-To: <4787929.143.1299451709771.JavaMail.geo-discussion-forums@yqmi17> Message-ID: <9484391.446.1299728356107.JavaMail.geo-discussion-forums@yqgy20> Bump. Any ideas? On Sunday, March 6, 2011 5:48:29 PM UTC-5, Nick wrote: > > Hey guys. One of my controller actions uses #render_to_string to send back > a JSON response. > > When I try to spec this, Ruby raises a NoMethodError, saying that > #render_to_string doesn't exist in my controller action. > > Here's the controller action, spec, and output: > http://pastie.org/1640962 > > Any idea what I'm doing wrong? Thanks, > Nick > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmazur at gmail.com Sun Mar 13 09:46:10 2011 From: mmazur at gmail.com (Mike Mazur) Date: Sun, 13 Mar 2011 21:46:10 +0800 Subject: [rspec-users] undefined method 'get' In-Reply-To: <05e825ec-3275-425a-acb6-fd6365e6405f@f31g2000pri.googlegroups.com> References: <05e825ec-3275-425a-acb6-fd6365e6405f@f31g2000pri.googlegroups.com> Message-ID: Hi, On Mon, Mar 7, 2011 at 15:30, DBA wrote: > I was just starting a rails 3.0.5 application with rspec-rails 2.5.0 > and ruby 1.9.2-p180 and when I went to describe my controller I ran > into this undefined method 'get' error. > > Here's the spec that is causing the problem (which lives in the folder > spec/controllers) > > require 'spec_helper' > > describe ArticlesController, :type => :controller do > ?describe "GET index" do > ? ?get :index > ? ?response.should be_successful > ?end > end Not sure what the problem could be. Does ArticlesController inherit from ActionController::Base (maybe via ApplicationController)? You shouldn't need to specify :type => :controller on the top-level describe like you do. Also, your expectation should be 'response.should be_success'. Mike From dchelimsky at gmail.com Sun Mar 13 09:58:21 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Mar 2011 08:58:21 -0500 Subject: [rspec-users] Are there any ways to detect spec faults during a run? In-Reply-To: References: Message-ID: On Mar 9, 2011, at 6:00 AM, Magnus Erickson wrote: > Hi, > Is there a way to detect if an example has failed? Something like a: "example_failed?" method. > In my case I need to dump some information, i.e trace and error log, to be used when analyzing what > went wrong in the example. I'm thinking about putting it in a after(:each) {}. after(:each) won't work because failures aren't actually reported out until all of the after hooks are processed. Your best bet is a custom formatter. See: http://relishapp.com/rspec/rspec-core/v/2-5/dir/formatters/custom-formatters http://relishapp.com/rspec/rspec-core/v/2-5/dir/command-line/format-option HTH, David From dchelimsky at gmail.com Sun Mar 13 10:00:23 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Mar 2011 09:00:23 -0500 Subject: [rspec-users] undefined method 'get' In-Reply-To: <05e825ec-3275-425a-acb6-fd6365e6405f@f31g2000pri.googlegroups.com> References: <05e825ec-3275-425a-acb6-fd6365e6405f@f31g2000pri.googlegroups.com> Message-ID: <9A87647B-0FD4-46E8-96E2-3B6E668C81EB@gmail.com> On Mar 7, 2011, at 1:30 AM, DBA wrote: > Hello guys, > > I was just starting a rails 3.0.5 application with rspec-rails 2.5.0 > and ruby 1.9.2-p180 and when I went to describe my controller I ran > into this undefined method 'get' error. > > Here's the spec that is causing the problem (which lives in the folder > spec/controllers) > > require 'spec_helper' > > describe ArticlesController, :type => :controller do > describe "GET index" do > get :index > response.should be_successful > end > end The `get` method is available in examples (the block passed to `it` or `specify`), but here it's being called in a group (the block passed to `describe` or context`). Try this instead: describe ArticlesController, :type => :controller do describe "GET index" do it "returns a 200" do get :index response.should be_successful end end end HTH, David From ngw at nofeed.org Sun Mar 13 10:30:34 2011 From: ngw at nofeed.org (Nicholas Wieland) Date: Sun, 13 Mar 2011 15:30:34 +0100 Subject: [rspec-users] Faking FS in specs Message-ID: Hi *, for some reasons I'm not able to fake writing on the FS during specs with carrierwave, someone managed to make it work ? I'm currently trying to use FakeFS, but apparently I'm not even able to run specs after changing spec_helper. The exception it raises is: /Users/ngw/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/pathname.rb:446:in `realpath': undefined method `realpath' for FakeFS::File:Class (NoMethodError) Is it a problem with my version of Ruby ? If it is, how do I test this stuff ? It's very annoying to have the files saved in /public for every autotest I run ... TIA, ngw From dchelimsky at gmail.com Sun Mar 13 10:46:12 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Mar 2011 09:46:12 -0500 Subject: [rspec-users] render_views and render_to_string In-Reply-To: <9484391.446.1299728356107.JavaMail.geo-discussion-forums@yqgy20> References: <4787929.143.1299451709771.JavaMail.geo-discussion-forums@yqmi17> <9484391.446.1299728356107.JavaMail.geo-discussion-forums@yqgy20> Message-ID: I tried something similar and worked fine with or without render_views, so I really have no idea why you're experiencing that. Please file a bug report to https://github.com/rspec/rspec-rails/issues and be sure to include version numbers of Ruby, Rails and RSpec. On Wed, Mar 9, 2011 at 9:39 PM, Nick wrote: > Bump. Any ideas? > > > On Sunday, March 6, 2011 5:48:29 PM UTC-5, Nick wrote: >> >> Hey guys. One of my controller actions uses #render_to_string to send back >> a JSON response. >> >> When I try to spec this, Ruby raises a NoMethodError, saying that >> #render_to_string doesn't exist in my controller action. >> >> Here's the controller action, spec, and output: >> http://pastie.org/1640962 >> >> Any idea what I'm doing wrong? Thanks, >> Nick > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From scott at railsnewbie.com Sun Mar 13 12:28:49 2011 From: scott at railsnewbie.com (Scott Taylor) Date: Sun, 13 Mar 2011 12:28:49 -0400 Subject: [rspec-users] Faking FS in specs In-Reply-To: References: Message-ID: How are you requiring FakeFS? Scott On Mar 13, 2011, at 10:30 AM, Nicholas Wieland wrote: > Hi *, for some reasons I'm not able to fake writing on the FS during specs with carrierwave, someone managed to make it work ? > I'm currently trying to use FakeFS, but apparently I'm not even able to run specs after changing spec_helper. The exception it raises is: > > /Users/ngw/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/pathname.rb:446:in `realpath': undefined method `realpath' for FakeFS::File:Class (NoMethodError) > > Is it a problem with my version of Ruby ? If it is, how do I test this stuff ? It's very annoying to have the files saved in /public for every autotest I run ... > > TIA, > ngw > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ngw at nofeed.org Sun Mar 13 15:37:22 2011 From: ngw at nofeed.org (Nicholas Wieland) Date: Sun, 13 Mar 2011 20:37:22 +0100 Subject: [rspec-users] Faking FS in specs In-Reply-To: References: Message-ID: <14082642-B922-4F7B-8AE7-DD9097EF20FC@nofeed.org> hi Scott, thanks for the answer. https://gist.github.com/868356 I'm not even calling it inside the specs. ngw On Mar 13, 2011, at 5:28 PM, Scott Taylor wrote: > > How are you requiring FakeFS? > > Scott > > On Mar 13, 2011, at 10:30 AM, Nicholas Wieland wrote: > >> Hi *, for some reasons I'm not able to fake writing on the FS during specs with carrierwave, someone managed to make it work ? >> I'm currently trying to use FakeFS, but apparently I'm not even able to run specs after changing spec_helper. The exception it raises is: >> >> /Users/ngw/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/pathname.rb:446:in `realpath': undefined method `realpath' for FakeFS::File:Class (NoMethodError) >> >> Is it a problem with my version of Ruby ? If it is, how do I test this stuff ? It's very annoying to have the files saved in /public for every autotest I run ... >> >> TIA, >> ngw >> _______________________________________________ >> 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 diogo.borges.almeida at gmail.com Sun Mar 13 15:50:26 2011 From: diogo.borges.almeida at gmail.com (DBA) Date: Sun, 13 Mar 2011 12:50:26 -0700 (PDT) Subject: [rspec-users] undefined method 'get' In-Reply-To: <9A87647B-0FD4-46E8-96E2-3B6E668C81EB@gmail.com> References: <05e825ec-3275-425a-acb6-fd6365e6405f@f31g2000pri.googlegroups.com> <9A87647B-0FD4-46E8-96E2-3B6E668C81EB@gmail.com> Message-ID: Indeed. David Chelimsky was kind enough to repair my noob mistake via twitter. What was happening was exactly what he described in his reply. More info at: https://gist.github.com/858446 Thanks, DBA From dchelimsky at gmail.com Sun Mar 13 17:32:36 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Mar 2011 16:32:36 -0500 Subject: [rspec-users] Faking FS in specs In-Reply-To: <14082642-B922-4F7B-8AE7-DD9097EF20FC@nofeed.org> References: <14082642-B922-4F7B-8AE7-DD9097EF20FC@nofeed.org> Message-ID: <634C3450-AA3E-4B22-ADF4-4F11FF24CC83@gmail.com> I think the problem is a missing API in FakeFS: http://rubydoc.info/gems/fakefs/0.3.1/FakeFS/File http://www.ruby-doc.org/core/classes/File.html#M000024 On Mar 13, 2011, at 2:37 PM, Nicholas Wieland wrote: > hi Scott, thanks for the answer. > > https://gist.github.com/868356 > > I'm not even calling it inside the specs. > > ngw > > On Mar 13, 2011, at 5:28 PM, Scott Taylor wrote: > >> >> How are you requiring FakeFS? >> >> Scott >> >> On Mar 13, 2011, at 10:30 AM, Nicholas Wieland wrote: >> >>> Hi *, for some reasons I'm not able to fake writing on the FS during specs with carrierwave, someone managed to make it work ? >>> I'm currently trying to use FakeFS, but apparently I'm not even able to run specs after changing spec_helper. The exception it raises is: >>> >>> /Users/ngw/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/pathname.rb:446:in `realpath': undefined method `realpath' for FakeFS::File:Class (NoMethodError) >>> >>> Is it a problem with my version of Ruby ? If it is, how do I test this stuff ? It's very annoying to have the files saved in /public for every autotest I run ... >>> >>> TIA, >>> ngw >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From groups at inbox.avdi.org Sun Mar 13 18:05:01 2011 From: groups at inbox.avdi.org (Avdi Grimm) Date: Sun, 13 Mar 2011 18:05:01 -0400 Subject: [rspec-users] Faking FS in specs In-Reply-To: References: Message-ID: On Sun, Mar 13, 2011 at 10:30 AM, Nicholas Wieland wrote: > Hi *, for some reasons I'm not able to fake writing on the FS during specs with carrierwave, someone managed to make it work ? > I'm currently trying to use FakeFS, but apparently I'm not even able to run specs after changing spec_helper. The exception it raises is: An alternative you might try is Construct: https://github.com/devver/construct We created it at Devver because we had trouble with libraries like FakeFS. Instead of faking out the FS, it simply gives you tools to set up the needed file structures and then automatically clean them up when the test is done. -- Avdi Grimm http://avdi.org From matt at mattwynne.net Sun Mar 13 18:22:35 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 13 Mar 2011 22:22:35 +0000 Subject: [rspec-users] Faking FS in specs In-Reply-To: References: Message-ID: <010C6F2A-CFB4-4662-9757-4C5556EDED05@mattwynne.net> On 13 Mar 2011, at 22:05, Avdi Grimm wrote: > On Sun, Mar 13, 2011 at 10:30 AM, Nicholas Wieland wrote: >> Hi *, for some reasons I'm not able to fake writing on the FS during specs with carrierwave, someone managed to make it work ? >> I'm currently trying to use FakeFS, but apparently I'm not even able to run specs after changing spec_helper. The exception it raises is: > > An alternative you might try is Construct: https://github.com/devver/construct > > We created it at Devver because we had trouble with libraries like > FakeFS. Instead of faking out the FS, it simply gives you tools to set > up the needed file structures and then automatically clean them up > when the test is done. I wonder if you could similarly use Aruba's library for that in RSpec. It might need some tweaks. > > -- > Avdi Grimm > http://avdi.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From myron.marston at gmail.com Sun Mar 13 20:16:48 2011 From: myron.marston at gmail.com (Myron Marston) Date: Sun, 13 Mar 2011 17:16:48 -0700 (PDT) Subject: [rspec-users] unless filter In-Reply-To: References: <1049473a-e29f-4775-9533-50cbdd7719cf@a21g2000prj.googlegroups.com> Message-ID: On Mar 11, 1:17?pm, Justin Ko wrote: > On Thu, Mar 10, 2011 at 2:32 AM, Shamaoke wrote: > > Hi. > > > Why doesn't the following filter work? > > > ~~~ > > # encoding: utf-8 > > # ./example_spec.rb > > > RSpec.configure do |config| > > ?config.filter = { > > ? ?unless: :condition_acceptable > > ?} > > end > > > describe 'some code' do > > ?it 'does one', if: :condition_acceptable do > > ?end > > > ?it 'does two', unless: :condition_acceptable do > > ?end > > end > > ~~~ > > > ~~~ > > $ rspec example_spec.rb > > No examples were matched # instead of 'some code does two' > > ~~~ > > > Thanks. > > > Debian GNU/Linux 5.0.7; > > Ruby 1.9.2; > > RSpec 2.5.0. > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > If :condition_acceptable evaluates to false, your example will run. If you > are looking to "match" key/values, don't use :if or :unless > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users There are built-in `:if` and `:unless` filters. You probably don't want to override them. They work how you would normally expect. http://relishapp.com/rspec/rspec-core/v/2-5/dir/filtering/implicit-filters HTH, Myron From mmazur at gmail.com Mon Mar 14 01:34:43 2011 From: mmazur at gmail.com (Mike Mazur) Date: Mon, 14 Mar 2011 13:34:43 +0800 Subject: [rspec-users] undefined method 'get' In-Reply-To: <9A87647B-0FD4-46E8-96E2-3B6E668C81EB@gmail.com> References: <05e825ec-3275-425a-acb6-fd6365e6405f@f31g2000pri.googlegroups.com> <9A87647B-0FD4-46E8-96E2-3B6E668C81EB@gmail.com> Message-ID: Hi, On Mar 13, 2011 10:11 PM, "David Chelimsky" wrote: > The `get` method is available in examples (the block passed to `it` or `specify`), but here it's being called in a group (the block passed to `describe` or context`). Yeah, don't know how I missed that! Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott at railsnewbie.com Mon Mar 14 11:46:40 2011 From: scott at railsnewbie.com (Scott Taylor) Date: Mon, 14 Mar 2011 11:46:40 -0400 Subject: [rspec-users] Faking FS in specs In-Reply-To: <634C3450-AA3E-4B22-ADF4-4F11FF24CC83@gmail.com> References: <14082642-B922-4F7B-8AE7-DD9097EF20FC@nofeed.org> <634C3450-AA3E-4B22-ADF4-4F11FF24CC83@gmail.com> Message-ID: <145C169F-552D-4B4E-AEA4-C89AD682CDFC@railsnewbie.com> Agreed with David - it simply hasn't been implemented in FakeFS. I'm actually a maintainer on the project, but don't have any steam to work on it right now. I'd certainly apply patches, though. FakeFS is a project of gradual enhancement, so even a patch that doesn't respect all of the arguments / features of File.realpath is OK. We can always fix it / improve it later. Cheers, Scott On Mar 13, 2011, at 5:32 PM, David Chelimsky wrote: > I think the problem is a missing API in FakeFS: > > http://rubydoc.info/gems/fakefs/0.3.1/FakeFS/File > http://www.ruby-doc.org/core/classes/File.html#M000024 > > On Mar 13, 2011, at 2:37 PM, Nicholas Wieland wrote: > >> hi Scott, thanks for the answer. >> >> https://gist.github.com/868356 >> >> I'm not even calling it inside the specs. >> >> ngw >> >> On Mar 13, 2011, at 5:28 PM, Scott Taylor wrote: >> >>> >>> How are you requiring FakeFS? >>> >>> Scott >>> >>> On Mar 13, 2011, at 10:30 AM, Nicholas Wieland wrote: >>> >>>> Hi *, for some reasons I'm not able to fake writing on the FS during specs with carrierwave, someone managed to make it work ? >>>> I'm currently trying to use FakeFS, but apparently I'm not even able to run specs after changing spec_helper. The exception it raises is: >>>> >>>> /Users/ngw/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/pathname.rb:446:in `realpath': undefined method `realpath' for FakeFS::File:Class (NoMethodError) >>>> >>>> Is it a problem with my version of Ruby ? If it is, how do I test this stuff ? It's very annoying to have the files saved in /public for every autotest I run ... >>>> >>>> TIA, >>>> ngw >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From shamaoke at hotmail.com Tue Mar 15 05:49:30 2011 From: shamaoke at hotmail.com (Shamaoke) Date: Tue, 15 Mar 2011 02:49:30 -0700 (PDT) Subject: [rspec-users] unless filter In-Reply-To: References: <1049473a-e29f-4775-9533-50cbdd7719cf@a21g2000prj.googlegroups.com> Message-ID: <146dc52a-d76d-4acd-8357-89eba17a2da5@y31g2000prd.googlegroups.com> Thanks for the clarification. I was led astray by the example from the RSpec Book where the network dependent code was described*. In that example the default if filter was overriden using the Proc object and it returned true or false depending on the network condition. Now I understand that code could be changed like the following: ~~~ class Network def self.available true # or false depending on the network condition end end describe 'some network dependent code' do it 'does one', :if => Network.available do # works if the network is available only end it 'does two' do end end ~~~ ________ * The RSpec Book, chp. 16, p. 238. On 14 ???, 03:16, Myron Marston wrote: > On Mar 11, 1:17?pm, Justin Ko wrote: > > > > > On Thu, Mar 10, 2011 at 2:32 AM, Shamaoke wrote: > > > Hi. > > > > Why doesn't the following filter work? > > > > ~~~ > > > # encoding: utf-8 > > > # ./example_spec.rb > > > > RSpec.configure do |config| > > > ?config.filter = { > > > ? ?unless: :condition_acceptable > > > ?} > > > end > > > > describe 'some code' do > > > ?it 'does one', if: :condition_acceptable do > > > ?end > > > > ?it 'does two', unless: :condition_acceptable do > > > ?end > > > end > > > ~~~ > > > > ~~~ > > > $ rspec example_spec.rb > > > No examples were matched # instead of 'some code does two' > > > ~~~ > > > > Thanks. > > > > Debian GNU/Linux 5.0.7; > > > Ruby 1.9.2; > > > RSpec 2.5.0. > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.org > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > If :condition_acceptable evaluates to false, your example will run. If you > > are looking to "match" key/values, don't use :if or :unless > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > There are built-in `:if` and `:unless` filters. ?You probably don't > want to override them. ?They work how you would normally expect. > > http://relishapp.com/rspec/rspec-core/v/2-5/dir/filtering/implicit-fi... > > HTH, > Myron > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From magerison at gmail.com Tue Mar 15 06:25:33 2011 From: magerison at gmail.com (Magnus Erickson) Date: Tue, 15 Mar 2011 11:25:33 +0100 Subject: [rspec-users] Are there any ways to detect spec faults during a run? In-Reply-To: References: Message-ID: Thanks for the answer David! It can be done via a custom formatter but then flexibility will be lost as well as visibility. It would really be handy to have this feature. Is there any other way of doing it? Is it possible to patch into RSpec in any way? What about after(:each).failure as a new feature in RSpec? BR Magnus 2011/3/13 David Chelimsky > On Mar 9, 2011, at 6:00 AM, Magnus Erickson wrote: > > > Hi, > > Is there a way to detect if an example has failed? Something like a: > "example_failed?" method. > > In my case I need to dump some information, i.e trace and error log, to > be used when analyzing what > > went wrong in the example. I'm thinking about putting it in a > after(:each) {}. > > after(:each) won't work because failures aren't actually reported out until > all of the after hooks are processed. > > Your best bet is a custom formatter. See: > > > http://relishapp.com/rspec/rspec-core/v/2-5/dir/formatters/custom-formatters > http://relishapp.com/rspec/rspec-core/v/2-5/dir/command-line/format-option > > HTH, > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Mar 15 07:24:38 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Mar 2011 06:24:38 -0500 Subject: [rspec-users] unless filter In-Reply-To: <146dc52a-d76d-4acd-8357-89eba17a2da5@y31g2000prd.googlegroups.com> References: <1049473a-e29f-4775-9533-50cbdd7719cf@a21g2000prj.googlegroups.com> <146dc52a-d76d-4acd-8357-89eba17a2da5@y31g2000prd.googlegroups.com> Message-ID: On Mar 15, 2011, at 4:49 AM, Shamaoke wrote: > On 14 ???, 03:16, Myron Marston wrote: >> On Mar 11, 1:17 pm, Justin Ko wrote: >> >> >> >>> On Thu, Mar 10, 2011 at 2:32 AM, Shamaoke wrote: >>>> Hi. >> >>>> Why doesn't the following filter work? >> >>>> ~~~ >>>> # encoding: utf-8 >>>> # ./example_spec.rb >> >>>> RSpec.configure do |config| >>>> config.filter = { >>>> unless: :condition_acceptable >>>> } >>>> end >> >>>> describe 'some code' do >>>> it 'does one', if: :condition_acceptable do >>>> end >> >>>> it 'does two', unless: :condition_acceptable do >>>> end >>>> end >>>> ~~~ >> >>>> ~~~ >>>> $ rspec example_spec.rb >>>> No examples were matched # instead of 'some code does two' >>>> ~~~ >> >>>> Thanks. >> >>>> Debian GNU/Linux 5.0.7; >>>> Ruby 1.9.2; >>>> RSpec 2.5.0. >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-us... at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >> >>> If :condition_acceptable evaluates to false, your example will run. If you >>> are looking to "match" key/values, don't use :if or :unless >> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> >> There are built-in `:if` and `:unless` filters. You probably don't >> want to override them. They work how you would normally expect. >> >> http://relishapp.com/rspec/rspec-core/v/2-5/dir/filtering/implicit-fi... >> >> HTH, >> Myron > Thanks for the clarification. I was led astray by the example from the > RSpec Book where the network dependent code was described*. In that > example the default if filter was overriden using the Proc object and > it returned true or false depending on the network condition. Now I > understand that code could be changed like the following: > > ~~~ > class Network > def self.available > true # or false depending on the network condition > end > end > > describe 'some network dependent code' do > it 'does one', :if => Network.available do # works if the network is > available only > end > > it 'does two' do > end > end > ~~~ > ________ > * The RSpec Book, chp. 16, p. 238. Unfortunately, :if and :unless were added as special cases after rspec-2.0 and The RSpec Book were released :( Cheers, David From dchelimsky at gmail.com Tue Mar 15 07:32:53 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Mar 2011 06:32:53 -0500 Subject: [rspec-users] Are there any ways to detect spec faults during a run? In-Reply-To: References: Message-ID: <5B1E2307-514D-4842-8324-29B9E9DF727D@gmail.com> On Mar 15, 2011, at 5:25 AM, Magnus Erickson wrote: > > 2011/3/13 David Chelimsky > On Mar 9, 2011, at 6:00 AM, Magnus Erickson wrote: > > > Hi, > > Is there a way to detect if an example has failed? Something like a: "example_failed?" method. > > In my case I need to dump some information, i.e trace and error log, to be used when analyzing what > > went wrong in the example. I'm thinking about putting it in a after(:each) {}. > > after(:each) won't work because failures aren't actually reported out until all of the after hooks are processed. > > Your best bet is a custom formatter. See: > > http://relishapp.com/rspec/rspec-core/v/2-5/dir/formatters/custom-formatters > http://relishapp.com/rspec/rspec-core/v/2-5/dir/command-line/format-option > > HTH, > David > > Thanks for the answer David! > > It can be done via a custom formatter but then flexibility will be lost as well as visibility. > It would really be handy to have this feature. Is there any other way of doing it? Is it possible to > patch into RSpec in any way? What about after(:each).failure as a new feature in RSpec? > > BR > Magnus What do you mean by "flexibility will be lost"? Also, please bottom-post (or inline-post) instead of top-posting [1], especially if that has already been established for the conversation. Cheers, David [1] http://idallen.com/topposting.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From niku at niku.name Tue Mar 15 11:57:33 2011 From: niku at niku.name (niku -E:)) Date: Wed, 16 Mar 2011 00:57:33 +0900 Subject: [rspec-users] How do I use expect{}.to change().from().to() on Array? Message-ID: Hi. I'm using ruby1.9.2 and rspec2.5.1 I want to use "expect{}.to change().from().to()" like this https://gist.github.com/870897 When Int class, it passed. When Ary class, it failed. Why was Ary test failed and How do I pass this test? regards. From dchelimsky at gmail.com Tue Mar 15 12:50:03 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Mar 2011 11:50:03 -0500 Subject: [rspec-users] How do I use expect{}.to change().from().to() on Array? In-Reply-To: References: Message-ID: <18B9E207-F7FE-44FE-984D-EBB191E8E63D@gmail.com> On Mar 15, 2011, at 10:57 AM, niku -E:) wrote: > Hi. > > I'm using ruby1.9.2 and rspec2.5.1 > I want to use "expect{}.to change().from().to()" like this > > https://gist.github.com/870897 > > When Int class, it passed. > When Ary class, it failed. > > Why was Ary test failed and How do I pass this test? subject.ary returns the same object both times, whereas subject.count returns different objects each time. Make sense? From jko170 at gmail.com Tue Mar 15 13:08:16 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 15 Mar 2011 10:08:16 -0700 Subject: [rspec-users] How do I use expect{}.to change().from().to() on Array? In-Reply-To: References: Message-ID: On Tue, Mar 15, 2011 at 8:57 AM, niku -E:) wrote: > Hi. > > I'm using ruby1.9.2 and rspec2.5.1 > I want to use "expect{}.to change().from().to()" like this > > https://gist.github.com/870897 > > When Int class, it passed. > When Ary class, it failed. > > Why was Ary test failed and How do I pass this test? > > regards. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Your Ary @ary variable is initialized as "[]". So of course calling increment on it will change it to "[0]". For your spec to pass, initialize it as "[0]" -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Tue Mar 15 13:41:36 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 15 Mar 2011 10:41:36 -0700 Subject: [rspec-users] How do I use expect{}.to change().from().to() on Array? In-Reply-To: References: Message-ID: On Tue, Mar 15, 2011 at 10:08 AM, Justin Ko wrote: > > > On Tue, Mar 15, 2011 at 8:57 AM, niku -E:) wrote: > >> Hi. >> >> I'm using ruby1.9.2 and rspec2.5.1 >> I want to use "expect{}.to change().from().to()" like this >> >> https://gist.github.com/870897 >> >> When Int class, it passed. >> When Ary class, it failed. >> >> Why was Ary test failed and How do I pass this test? >> >> regards. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > Your Ary @ary variable is initialized as "[]". So of course calling > increment on it will change it to "[0]". For your spec to pass, initialize > it as "[0]" > I'm completely wrong. Didn't read your code properly. Where is the delete link? :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Mar 15 23:26:25 2011 From: lists at ruby-forum.com (Brian Ledsworth) Date: Wed, 16 Mar 2011 04:26:25 +0100 Subject: [rspec-users] Issues implementing Rspec with Rails3 from tutorial In-Reply-To: References: Message-ID: <75e02e22ecf18cc5fdd33539617cd3fb@ruby-forum.com> Mohnish Hard to tell without looking at the state if your rails app or the specs. But, it looks like it might be your Model. Try loading the rails console in test ("rails console test"), and see if you can create and save the model. Also, I assume "rake db:migrate" ran without issue as well? If that's all good, please post your spec. Brian -- Posted via http://www.ruby-forum.com/. From sidwood2 at gmail.com Wed Mar 16 08:15:13 2011 From: sidwood2 at gmail.com (Sid Wood) Date: Wed, 16 Mar 2011 12:15:13 +0000 Subject: [rspec-users] RSpec & DataMapper Open Source Projects? Message-ID: Hi there, Does anyone know of any open source projects that are using RSpec and DataMapper together that I can dissect? Thanks. Sid -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Mar 16 12:53:42 2011 From: lists at ruby-forum.com (Mohnish J.) Date: Wed, 16 Mar 2011 17:53:42 +0100 Subject: [rspec-users] Issues implementing Rspec with Rails3 from tutorial In-Reply-To: <75e02e22ecf18cc5fdd33539617cd3fb@ruby-forum.com> References: <75e02e22ecf18cc5fdd33539617cd3fb@ruby-forum.com> Message-ID: Brian Ledsworth wrote in post #987662: > Mohnish > > Hard to tell without looking at the state if your rails app or the > specs. But, it looks like it might be your Model. Try loading the > rails console in test ("rails console test"), and see if you can create > and save the model. Also, I assume "rake db:migrate" ran without issue > as well? > > If that's all good, please post your spec. > > Brian Hi Brian, I made a fundamental mistake, I realized that I always made use of rake db:create, and rake db:migrate. This would set things for me with Development Environment. For the test enviroment, I had to use rake db:test:prepare or rake db:migrate with appropriate syntax to reflect the migrations in the Test Environment. Thank you for your response and attempt to help.. Its appreciated..:) -- Posted via http://www.ruby-forum.com/. From ericmilford at gmail.com Thu Mar 17 12:58:24 2011 From: ericmilford at gmail.com (ericindc) Date: Thu, 17 Mar 2011 09:58:24 -0700 (PDT) Subject: [rspec-users] Autotest missing specs, not missed in rake spec Message-ID: <339c13cf-c72e-42f8-8479-8af1260514cc@a21g2000prj.googlegroups.com> I've included the output from running my specs with rake spec and autotest. I've restarted autotest several times to no avail. For some reason, autotest is missing the newsroom_blog_post specs. Any idea how to resolve this? I'd like to continue using autotest, but not if specs are going to be missed. Thanks. AUTOFEATURE=true autotest -------------------------------------------------------------------------------- /Users/em/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -rrubygems -S /Users/ em/.rvm/gems/ruby-1.8.7-p302 at backend/gems/rspec-core-2.5.1/bin/rspec -- tty '/Users/em/Development/backend/spec/models/newsroom_spec.rb' '/ Users/em/Development/backend/spec/models/editor_spec.rb' '/Users/em/ Development/backend/spec/controllers/admin/ restricted_controller_spec.rb' '/Users/em/Development/backend/spec/ controllers/admin/base_controller_spec.rb' '/Users/em/Development/ backend/spec/models/newsroom_post_spec.rb' '/Users/em/Development/ backend/spec/models/author_spec.rb' '/Users/em/Development/backend/ spec/controllers/admin/newsrooms_controller_spec.rb' ...................... Finished in 0.82257 seconds 22 examples, 0 failures /Users/em/.rvm/rubies/ruby-1.8.7-p302/bin/ruby /Users/em/.rvm/gems/ ruby-1.8.7-p302 at backend/gems/cucumber-0.10.0/bin/cucumber --format progress --format rerun --out /var/folders/5h/ 5hatSIPsEqCokSxuQQxJJFvNiLY/-Tmp-/autotest- cucumber20110317-37693-147w41x-0 Using the default profile... ......... 2 scenarios (2 passed) 7 steps (7 passed) 0m0.584s rake spec -------------------------------------------------------------------------------- /Users/em/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -S bundle exec rspec ./ spec/controllers/admin/base_controller_spec.rb ./spec/controllers/ admin/newsrooms_controller_spec.rb ./spec/controllers/admin/ restricted_controller_spec.rb ./spec/models/author_spec.rb ./spec/ models/editor_spec.rb ./spec/models/newsroom_blog_post_spec.rb ./spec/ models/newsroom_post_spec.rb ./spec/models/newsroom_spec.rb ............................ Finished in 1.21 seconds 28 examples, 0 failures From ericmilford at gmail.com Thu Mar 17 13:05:05 2011 From: ericmilford at gmail.com (ericindc) Date: Thu, 17 Mar 2011 10:05:05 -0700 (PDT) Subject: [rspec-users] Autotest missing specs, not missed in rake spec In-Reply-To: <339c13cf-c72e-42f8-8479-8af1260514cc@a21g2000prj.googlegroups.com> References: <339c13cf-c72e-42f8-8479-8af1260514cc@a21g2000prj.googlegroups.com> Message-ID: On Mar 17, 12:58?pm, ericindc wrote: > I've included the output from running my specs with rake spec and > autotest. ?I've restarted autotest several times to no avail. ?For > some reason, autotest is missing the newsroom_blog_post specs. ?Any > idea how to resolve this? ?I'd like to continue using autotest, but > not if specs are going to be missed. > > Thanks. > > AUTOFEATURE=true autotest > --------------------------------------------------------------------------- ----- > > /Users/em/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -rrubygems -S /Users/ > em/.rvm/gems/ruby-1.8.7-p302 at backend/gems/rspec-core-2.5.1/bin/rspec -- > tty '/Users/em/Development/backend/spec/models/newsroom_spec.rb' '/ > Users/em/Development/backend/spec/models/editor_spec.rb' '/Users/em/ > Development/backend/spec/controllers/admin/ > restricted_controller_spec.rb' '/Users/em/Development/backend/spec/ > controllers/admin/base_controller_spec.rb' '/Users/em/Development/ > backend/spec/models/newsroom_post_spec.rb' '/Users/em/Development/ > backend/spec/models/author_spec.rb' '/Users/em/Development/backend/ > spec/controllers/admin/newsrooms_controller_spec.rb' > ...................... > > Finished in 0.82257 seconds > 22 examples, 0 failures > > /Users/em/.rvm/rubies/ruby-1.8.7-p302/bin/ruby /Users/em/.rvm/gems/ > ruby-1.8.7-p302 at backend/gems/cucumber-0.10.0/bin/cucumber --format > progress --format rerun --out /var/folders/5h/ > 5hatSIPsEqCokSxuQQxJJFvNiLY/-Tmp-/autotest- > cucumber20110317-37693-147w41x-0 > Using the default profile... > ......... > > 2 scenarios (2 passed) > 7 steps (7 passed) > 0m0.584s > > rake spec > --------------------------------------------------------------------------- ----- > > /Users/em/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -S bundle exec rspec ./ > spec/controllers/admin/base_controller_spec.rb ./spec/controllers/ > admin/newsrooms_controller_spec.rb ./spec/controllers/admin/ > restricted_controller_spec.rb ./spec/models/author_spec.rb ./spec/ > models/editor_spec.rb ./spec/models/newsroom_blog_post_spec.rb ./spec/ > models/newsroom_post_spec.rb ./spec/models/newsroom_spec.rb > ............................ > > Finished in 1.21 seconds > 28 examples, 0 failures > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users I've had this problem before and have double checked some of the possible concerns mention in this thread. http://www.ruby-forum.com/topic/216382 I am running Rails 3.0.5 on OS X with the following RSpec files installed. rspec (2.5.0) rspec-core (2.5.1) rspec-expectations (2.5.0) rspec-mocks (2.5.0) rspec-rails (2.5.0) $ ls -l app/models/ 157 Mar 17 12:44 author.rb 241 Mar 17 11:50 editor.rb 194 Mar 17 11:30 newsroom.rb 540 Mar 17 12:45 newsroom_blog_post.rb 146 Mar 17 12:21 newsroom_post.rb $ ls -l spec/models/ 156 Mar 17 12:44 author_spec.rb 401 Mar 17 11:50 editor_spec.rb 490 Mar 17 12:40 newsroom_blog_post_spec.rb 189 Mar 17 12:20 newsroom_post_spec.rb 150 Mar 17 11:30 newsroom_spec.rb From dk at structuralartistry.com Thu Mar 17 15:54:02 2011 From: dk at structuralartistry.com (David Kahn) Date: Thu, 17 Mar 2011 13:54:02 -0600 Subject: [rspec-users] Testing route with proc --- possible and how? Message-ID: I have this route (Rails 3) which handles redirecting shortened urls: # handles the shortened url lookup match ':hash' => redirect { |params| Sharing.get_url_path_by_short_url(params[:hash]) }, :constraints => { :hash => /[a-zA-Z0-9]{7}/ } It works correctly at the ui. However am having trouble getting a spec working for it. Note that in the UI the user must be logged in to get to the url, but the traffic first hits the directed route and then app controller handles if the user is not logged in. In spec/routing/routing_spec.rb (note that all necessary test data for it to pass is set up and verified): describe "Shorter URL redirect" do it "routes GET 'STU1VWX' to stations/1" do { :get => "/", :hash => "STU1VWX" }.should route_to( :controller => "stations", :action => "show", :params => {:id => 1} ) end end The problem is that I get this error: Failure/Error: { :get => "/", :hash => "STU1VWX" }.should route_to( The recognized options <{"controller"=>"sessions", "action"=>"new"}> did not match <{"controller"=>"stations", "action"=>"show", "params"=>{:id=>1}}>, difference: <{"controller"=>"stations", "action"=>"show", "params"=>{:id=>1}}>. sessions#new is our root url. So I see that by calling :get => '/' the :hash seems to be ignored. I have confirmed this by changing the root url and seen the new root path show in the error above. Note that if I change the test to: { :get => "STU1VWX" }.should route_to( ... or { :get => "/STU1VWX" }.should route_to( ... I get a 'no route matches' exception I have a few conjectures as to that is happening: - The dynamic route is ignored (i.e. the :hash parameter is being ignored). Calling in debugger "Rails.application.routes.recognize_path('STU1VWX')" returns a no route matches exception. - The way routes is being tested that the proc on the route does not get run eventhough the route is seen - I need to handle authentication (this would confuse me a bit as it would seem that on a routes test we should just be testing the output of the router. If anyone can give me some ideas I would appreciate it. Best, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Mar 17 17:25:17 2011 From: lists at ruby-forum.com (Pete Campbell) Date: Thu, 17 Mar 2011 22:25:17 +0100 Subject: [rspec-users] Counter.should_not_receive(:message) not working? Message-ID: I'm trying to test a Rails controller and am having trouble getting SHOULD_NOT_RECEIVE to work on a class method. I can never get Counter.should_not_receive(:xxx) to fail when the message 'xxx' is sent. Controller: def show @counter = Counter.increment if count_me end RSpec: describe 'Show' do it "should INCREMENT only when count-me is true" do Counter.should_receive(:increment) Counter.should_receive(:increment).never Counter.should_not_receive(:increment) get :show, :count_me => 'true' end end Why does this pass? Counter.should_receive(:increment) passes correctly (or fails if COUNT_ME isn't set correctly), but shouldn't the next 2 statements fail? This is in Rails 2.3.11 & MongoDB. Thanks! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Mar 17 17:55:23 2011 From: lists at ruby-forum.com (Pete Campbell) Date: Thu, 17 Mar 2011 22:55:23 +0100 Subject: [rspec-users] Counter.should_not_receive(:message) not working? In-Reply-To: References: Message-ID: <392943a9830bae39562b615e7280ddd5@ruby-forum.com> Even simpler... describe 'Show' do it 'should fail because increment is called' do Counter.should_not_receive(:increment) # Incorrectly passes get :show, :count_me => 'true' end it 'should fail because increment is not called' do Counter.should_receive(:increment) # Correctly fails get :show end end -- Posted via http://www.ruby-forum.com/. From mguterl at gmail.com Thu Mar 17 18:31:57 2011 From: mguterl at gmail.com (Michael Guterl) Date: Thu, 17 Mar 2011 18:31:57 -0400 Subject: [rspec-users] Counter.should_not_receive(:message) not working? In-Reply-To: References: Message-ID: On Thu, Mar 17, 2011 at 5:25 PM, Pete Campbell wrote: > I'm trying to test a Rails controller and am having trouble getting > SHOULD_NOT_RECEIVE to work on a class method. I can never get > Counter.should_not_receive(:xxx) to fail when the message 'xxx' is sent. > > Controller: > def show > ?@counter = Counter.increment if count_me Should this be params[:count_me]? ---^ Best, Michael Guterl From jko170 at gmail.com Thu Mar 17 20:53:05 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 17 Mar 2011 17:53:05 -0700 Subject: [rspec-users] Counter.should_not_receive(:message) not working? In-Reply-To: <392943a9830bae39562b615e7280ddd5@ruby-forum.com> References: <392943a9830bae39562b615e7280ddd5@ruby-forum.com> Message-ID: On Thu, Mar 17, 2011 at 2:55 PM, Pete Campbell wrote: > Even simpler... > > describe 'Show' do > it 'should fail because increment is called' do > Counter.should_not_receive(:increment) # Incorrectly passes > get :show, :count_me => 'true' > end > it 'should fail because increment is not called' do > Counter.should_receive(:increment) # Correctly fails > get :show > end > end > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I would say "count_me" is not returning what you think it is. Try adding "raise count_me.inspect" in the controller action to see if this is the case. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Mar 17 21:07:12 2011 From: lists at ruby-forum.com (Will C.) Date: Fri, 18 Mar 2011 02:07:12 +0100 Subject: [rspec-users] 'spec' command not working Message-ID: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> When I run JSpec, in the command prompt, using the "spec" command, I get this error: 'spec' command not recognized as a command I have the latest versions of JSpec and Ruby installed. How can I use the spec command? Not sure what to put in my PATH environment variables. Thanks! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Mar 17 21:24:34 2011 From: lists at ruby-forum.com (Pete Campbell) Date: Fri, 18 Mar 2011 02:24:34 +0100 Subject: [rspec-users] Counter.should_not_receive(:message) not working? In-Reply-To: References: <392943a9830bae39562b615e7280ddd5@ruby-forum.com> Message-ID: <285910ab9b6602059a37ba62bd55adb3@ruby-forum.com> Justin Ko wrote in post #988060: > I would say "count_me" is not returning what you think it is. Try adding > "raise count_me.inspect" in the controller action to see if this is the > case. Thanks for the feedback. The code snippet isn't the exact code, it is simplified to demonstrate the problem I'm having (or think that I'm having). I know that the count_me values are set correctly when experiencing this problem. I also know when the Counter methods are executed or not (lots of 'puts'!), so I'm sure that the Counter is receiving the message but the .should_not_receive isn't raising an error. I'm probably doing something incorrect w/r/t the way you're supposed to use mocks in RSpec, but so far I haven't found what that is. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Mar 17 23:53:23 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Mar 2011 22:53:23 -0500 Subject: [rspec-users] Counter.should_not_receive(:message) not working? In-Reply-To: <285910ab9b6602059a37ba62bd55adb3@ruby-forum.com> References: <392943a9830bae39562b615e7280ddd5@ruby-forum.com> <285910ab9b6602059a37ba62bd55adb3@ruby-forum.com> Message-ID: <2B198DC1-877F-4C9A-9278-3DE101904955@gmail.com> On Mar 17, 2011, at 8:24 PM, Pete Campbell wrote: > Justin Ko wrote in post #988060: > >> I would say "count_me" is not returning what you think it is. Try adding >> "raise count_me.inspect" in the controller action to see if this is the >> case. > > Thanks for the feedback. The code snippet isn't the exact code, it is > simplified to demonstrate the problem I'm having (or think that I'm > having). I know that the count_me values are set correctly when > experiencing this problem. I also know when the Counter methods are > executed or not (lots of 'puts'!), so I'm sure that the Counter is > receiving the message but the .should_not_receive isn't raising an > error. > > I'm probably doing something incorrect w/r/t the way you're supposed to > use mocks in RSpec, but so far I haven't found what that is. Please post a single, complete example in a gist that we can copy into a file and run so we can see the problem locally. Cheers, David From aslak.hellesoy at gmail.com Fri Mar 18 04:01:26 2011 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Fri, 18 Mar 2011 08:01:26 +0000 Subject: [rspec-users] 'spec' command not working In-Reply-To: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> References: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> Message-ID: <3858489590752513763@unknownmsgid> What's JSpec? Aslak On Mar 18, 2011, at 1:35, "Will C." wrote: > When I run JSpec, in the command prompt, using the "spec" command, I get > this error: > > 'spec' command not recognized as a command > > I have the latest versions of JSpec and Ruby installed. How can I use > the spec command? Not sure what to put in my PATH environment variables. > > Thanks! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dolzenko at gmail.com Fri Mar 18 05:35:37 2011 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Fri, 18 Mar 2011 12:35:37 +0300 Subject: [rspec-users] 'spec' command not working In-Reply-To: <3858489590752513763@unknownmsgid> References: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> <3858489590752513763@unknownmsgid> Message-ID: <4D832769.2040402@gmail.com> If your question is related to "JSpec JavaScript Testing Framework" this is the wrong group to post to, you should post to http://groups.google.com/group/jspec instead On 3/18/2011 11:01 AM, Aslak Helles?y wrote: > What's JSpec? > > Aslak > > On Mar 18, 2011, at 1:35, "Will C." wrote: > >> When I run JSpec, in the command prompt, using the "spec" command, I get >> this error: >> >> 'spec' command not recognized as a command >> >> I have the latest versions of JSpec and Ruby installed. How can I use >> the spec command? Not sure what to put in my PATH environment variables. >> >> Thanks! >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From sidwood2 at gmail.com Fri Mar 18 10:26:10 2011 From: sidwood2 at gmail.com (Sid Wood) Date: Fri, 18 Mar 2011 14:26:10 +0000 Subject: [rspec-users] Controller Spec & DataMapper Chaining Message-ID: Hi there, I'm fairly new to RSpec, and DataMapper and I'm trying to write a controller spec for an index action that will include DM query chaining. Here is a very simplified version of the Controller#index I'm working on def index @widgets = Widget.all(:order => [ :name.asc ]) if params[:alpha] @widgets = @widgets.by_alpha(params[:alpha]) elsif params[:beta] @widgets = @widgets.by_beta(params[:beta]) end end I'm trying to write a spec for this and I'm struggling. It feels like it'll be something uber simple but I'm just not getting it. describe "GET 'index'" do it "should be successful" do get :index response.should be_success end it "assigns all widgets as @widgets" do widgets = [Factory.stub(:widget), Factory.stub(:widget)] Widget.stub(:all) { [widgets] } get :index assigns(:widgets).should == [widgets] end #... end Any assistance would be greatly appreciated. Kind regards, Sid -------------- next part -------------- An HTML attachment was scrubbed... URL: From magerison at gmail.com Fri Mar 18 11:00:18 2011 From: magerison at gmail.com (Magnus Erickson) Date: Fri, 18 Mar 2011 16:00:18 +0100 Subject: [rspec-users] Are there any ways to detect spec faults during a run? In-Reply-To: <5B1E2307-514D-4842-8324-29B9E9DF727D@gmail.com> References: <5B1E2307-514D-4842-8324-29B9E9DF727D@gmail.com> Message-ID: 2011/3/15 David Chelimsky > On Mar 15, 2011, at 5:25 AM, Magnus Erickson wrote: > > > 2011/3/13 David Chelimsky > >> On Mar 9, 2011, at 6:00 AM, Magnus Erickson wrote: >> >> > Hi, >> > Is there a way to detect if an example has failed? Something like a: >> "example_failed?" method. >> > In my case I need to dump some information, i.e trace and error log, to >> be used when analyzing what >> > went wrong in the example. I'm thinking about putting it in a >> after(:each) {}. >> >> after(:each) won't work because failures aren't actually reported out >> until all of the after hooks are processed. >> >> Your best bet is a custom formatter. See: >> >> >> http://relishapp.com/rspec/rspec-core/v/2-5/dir/formatters/custom-formatters >> http://relishapp.com/rspec/rspec-core/v/2-5/dir/command-line/format-option >> >> HTH, >> David >> >> > Thanks for the answer David! > > It can be done via a custom formatter but then flexibility will be lost as > well as visibility. > It would really be handy to have this feature. Is there any other way of > doing it? Is it possible to > patch into RSpec in any way? What about after(:each).failure as a new > feature in RSpec? > > BR > Magnus > > > > What do you mean by "flexibility will be lost"? > > > Also, please bottom-post (or inline-post) instead of top-posting [1], > especially if that has already been established for the conversation. > > > Cheers, > > David > > Hi! If having the option to ask if a fault has occurred in a scenario, the measure to be taken upon detection is visible ie. in the spec file and the action can be tailored depending on whats on test. That's what I mean with flexibility. Cheers Magnus > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Mar 18 11:29:38 2011 From: lists at ruby-forum.com (Paul H.) Date: Fri, 18 Mar 2011 16:29:38 +0100 Subject: [rspec-users] Functional Tests with custom routes Message-ID: Say I have a custom route like this... map.connect 'item/:id/some_action', :controller => 'object', :action => 'change_color', :conditions => {:method => :put} I've been writing my tests like this... describe ObjectController describe "PUT item/:id/some_action" do [...] put :change_color, {:id => 'blue'} [...] end end So the test doesn't actually test the url - "item/blue/some_action", but rather the underlying Controller/Action that implements it. Is there a way to write my tests "in terms of" the url - something like... describe ObjectController describe "PUT item/:id/some_action" do [...] put "item/blue/some_action" [...] end end Or are controller tests simply not the place to do this, and I should do it in Cucumber or something? Cheers -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Mar 18 11:34:01 2011 From: lists at ruby-forum.com (Brian Ledsworth) Date: Fri, 18 Mar 2011 16:34:01 +0100 Subject: [rspec-users] Controller Spec & DataMapper Chaining In-Reply-To: References: Message-ID: Would you post the results of your spec? I'd like to see what you're getting. I'm not familiar with DataMapper, but from an Active Record standpoint, the order clause does not look right. e.g. should be Square.all.order(:name) Try running the spec without the order clause in index (e.g. Widget.all) just to see if that works to rule out the order clause. You might have to do stub chain on Widget for all and then order. Everything else seems fine at quick glance. Brian -- Posted via http://www.ruby-forum.com/. From ken.chien at gmail.com Fri Mar 18 11:46:14 2011 From: ken.chien at gmail.com (Ken Chien) Date: Fri, 18 Mar 2011 11:46:14 -0400 Subject: [rspec-users] Controller Spec & DataMapper Chaining In-Reply-To: References: Message-ID: What problems are you running into? It appears that you should stub out Widget.all before all examples, unless you really want to hit the database. Ken 2011/3/18 Sid Wood > Hi there, > > I'm fairly new to RSpec, and DataMapper and I'm trying to write a > controller spec for an index action that will include DM query chaining. > > Here is a very simplified version of the Controller#index I'm working on > > > def index > @widgets = Widget.all(:order => [ :name.asc ]) > if params[:alpha] > @widgets = @widgets.by_alpha(params[:alpha]) > elsif params[:beta] > @widgets = @widgets.by_beta(params[:beta]) > end > end > > I'm trying to write a spec for this and I'm struggling. It feels like it'll > be something uber simple but I'm just not getting it. > > describe "GET 'index'" do > it "should be successful" do > get :index > response.should be_success > end > > it "assigns all widgets as @widgets" do > widgets = [Factory.stub(:widget), Factory.stub(:widget)] > Widget.stub(:all) { [widgets] } > get :index > assigns(:widgets).should == [widgets] > end > > #... > end > > Any assistance would be greatly appreciated. > > Kind regards, > > Sid > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Mar 18 11:46:43 2011 From: lists at ruby-forum.com (Brian Ledsworth) Date: Fri, 18 Mar 2011 16:46:43 +0100 Subject: [rspec-users] Functional Tests with custom routes In-Reply-To: References: Message-ID: ...not the place to do this, and I should do it in Cucumber or something? Yes! Tthe concept of testing controllers, views and models separately, is related to isolation of concerns. Your controller test is just that, testing the controller, regardless of routing, views, models, etc. You're unit testing, so to speak, just object#change_color. This is why mocks and stubs are created as well, to remove the coupling of the three so you can test each on it's own. Grain of salt disclaimer, I'm not to far down my BDD journey with Rails with RSpec and Cucumber myself.... b -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Mar 18 12:30:40 2011 From: lists at ruby-forum.com (Will C.) Date: Fri, 18 Mar 2011 17:30:40 +0100 Subject: [rspec-users] 'spec' command not working In-Reply-To: <3858489590752513763@unknownmsgid> References: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> <3858489590752513763@unknownmsgid> Message-ID: <07f311294a2af558af5e001654cd0a2b@ruby-forum.com> Aslak Helles??y wrote in post #988109: > What's JSpec? > > Aslak Oh sry I mean RSpec -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Mar 18 12:31:31 2011 From: lists at ruby-forum.com (Will C.) Date: Fri, 18 Mar 2011 17:31:31 +0100 Subject: [rspec-users] 'spec' command not working In-Reply-To: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> References: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> Message-ID: <38997babbabe25a005e06cc4ed70b5f1@ruby-forum.com> Will C. wrote in post #988062: > When I run JSpec, in the command prompt, using the "spec" command, I get > this error: > > 'spec' command not recognized as a command > > I have the latest versions of JSpec and Ruby installed. How can I use > the spec command? Not sure what to put in my PATH environment variables. > > Thanks! I mean Rspec, not Jspec -- Posted via http://www.ruby-forum.com/. From sidwood2 at gmail.com Fri Mar 18 12:37:03 2011 From: sidwood2 at gmail.com (Sid Wood) Date: Fri, 18 Mar 2011 16:37:03 +0000 Subject: [rspec-users] Controller Spec & DataMapper Chaining In-Reply-To: References: Message-ID: Thanks for the replies guys. My problem is writing a test for @widgets = @widgets.by_alpha(params[:alpha]) DataMapper allows you to chain additional criteria on an existing query and doesnt execute that query until in is used in the view. So the above statement gets baked into the previous default query @widgets = Widget.all(:order => [ :name.asc ]). I'd just like to write a test that confirms the controller is in fact calling @widgets.by_alpha(params[:alpha]) when the params[:alpha] is present. Here is the code again so you don't have to scroll to see it def index @widgets = Widget.all(:order => [ :name.asc ]) if params[:alpha] @widgets = @widgets.by_alpha(params[:alpha]) elsif params[:beta] @widgets = @widgets.by_beta(params[:beta]) end end Just to recap, this code is valid and works, I just don't know how to write a test for it. Cheers, Sid -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Fri Mar 18 12:51:46 2011 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 18 Mar 2011 16:51:46 +0000 Subject: [rspec-users] 'spec' command not working In-Reply-To: <38997babbabe25a005e06cc4ed70b5f1@ruby-forum.com> References: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> <38997babbabe25a005e06cc4ed70b5f1@ruby-forum.com> Message-ID: <115FAD3B-34B3-4AA0-BD38-CA48D129E3E8@mattwynne.net> On 18 Mar 2011, at 16:31, Will C. wrote: > Will C. wrote in post #988062: >> When I run JSpec, in the command prompt, using the "spec" command, I get >> this error: >> >> 'spec' command not recognized as a command >> >> I have the latest versions of JSpec and Ruby installed. How can I use >> the spec command? Not sure what to put in my PATH environment variables. >> >> Thanks! > > I mean Rspec, not Jspec It does help if you use the right words for things ;) Since RSpec 2.0, the binary command is now `rspec` rather than `spec`. cheers, Matt matt at mattwynne.net 07974 430184 From ken.chien at gmail.com Fri Mar 18 14:01:33 2011 From: ken.chien at gmail.com (Ken Chien) Date: Fri, 18 Mar 2011 14:01:33 -0400 Subject: [rspec-users] Controller Spec & DataMapper Chaining In-Reply-To: References: Message-ID: When calling get/post/etc, the second optional parameter is a hash representing the "params" hash. So, in order to test the conditional(s) in your controller, you should write: get :index, :alpha => true #test the first conditional In another example, pass in :beta => true like this: get :index, :beta => true HTH, Ken 2011/3/18 Sid Wood > Thanks for the replies guys. > > My problem is writing a test for > > @widgets = @widgets.by_alpha(params[:alpha]) > > DataMapper allows you to chain additional criteria on an existing query and > doesnt execute that query until in is used in the view. So the above > statement gets baked into the previous default query @widgets = > Widget.all(:order => [ :name.asc ]). > > I'd just like to write a test that confirms the controller is in fact > calling @widgets.by_alpha(params[:alpha]) when the params[:alpha] is > present. > > Here is the code again so you don't have to scroll to see it > > > def index > @widgets = Widget.all(:order => [ :name.asc ]) > if params[:alpha] > @widgets = @widgets.by_alpha(params[:alpha]) > elsif params[:beta] > @widgets = @widgets.by_beta(params[:beta]) > end > end > > Just to recap, this code is valid and works, I just don't know how to write > a test for it. > > Cheers, > > Sid > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Mar 18 14:34:14 2011 From: lists at ruby-forum.com (Will C.) Date: Fri, 18 Mar 2011 19:34:14 +0100 Subject: [rspec-users] RSpec Basic Help Needed Message-ID: I'm getting the following error while doing the RSpec example on the bottom of this page: http://rspec.info/ This is the error I am getting no such file to load -- blowing LoadError Both files are on the desktop. Thanks! -- Posted via http://www.ruby-forum.com/. From dk at structuralartistry.com Fri Mar 18 15:10:47 2011 From: dk at structuralartistry.com (David Kahn) Date: Fri, 18 Mar 2011 13:10:47 -0600 Subject: [rspec-users] RSpec Basic Help Needed In-Reply-To: References: Message-ID: On Fri, Mar 18, 2011 at 12:34 PM, Will C. wrote: > I'm getting the following error while doing the RSpec example on the > bottom of this page: http://rspec.info/ > > This is the error I am getting > no such file to load -- blowing LoadError > Do you have the file named right? (I see 'blowing' above but on the ex is bowling) > > Both files are on the desktop. > > Thanks! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Mar 18 15:14:56 2011 From: lists at ruby-forum.com (Will C.) Date: Fri, 18 Mar 2011 20:14:56 +0100 Subject: [rspec-users] 'spec' command not working In-Reply-To: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> References: <0228cceeb2c3ea8fd6a0f316f009128a@ruby-forum.com> Message-ID: <00e66cd3a89524c3e661e77aba6f5083@ruby-forum.com> Will C. wrote in post #988062: > When I run JSpec, in the command prompt, using the "spec" command, I get > this error: > > 'spec' command not recognized as a command > > I have the latest versions of JSpec and Ruby installed. How can I use > the spec command? Not sure what to put in my PATH environment variables. > > Thanks! Solved--- -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Mar 18 15:15:59 2011 From: lists at ruby-forum.com (=?UTF-8?B?RHpzw7M=?= =?UTF-8?B?IFBlbmfFkQ==?=) Date: Fri, 18 Mar 2011 20:15:59 +0100 Subject: [rspec-users] Rails 3 Upgrade In-Reply-To: References: Message-ID: Hey guys! I got a serious issue right after upgraded to rails 3. Rails doesn't render layout, just only if I explicitly add this line to actions at end of actions. render :layout=>"application" If I place layout "application" to the controller doesn't work, but I think it must have to work without anything. Cos That is the default layout. Any idea? thx Dzs -- Posted via http://www.ruby-forum.com/. From rob.westgeest at gmail.com Fri Mar 18 17:57:50 2011 From: rob.westgeest at gmail.com (Rob Westgeest) Date: Fri, 18 Mar 2011 14:57:50 -0700 (PDT) Subject: [rspec-users] RSpec2 collides with Runt but why ? Message-ID: <3fe8f792-bb99-4476-994d-dc9bee5ba7bf@s11g2000yqh.googlegroups.com> Hi, A project of mine is using Runt expressions to match dates. When upgraded my rake tasks to 2.5.1 (from 1.3.0) it get this /usr/bin/ruby1.8 -S rspec spec/delivery_spec.rb spec/reporter_spec.rb spec/mysql_dump_spec.rb spec/string_ext_spec.rb spec/ backup_configuration_spec.rb spec/postgres_dump_spec.rb spec/ system_command_spec.rb spec/archive_spec.rb spec/ configuration_dsl_spec.rb spec/mailer_spec.rb spec/backup_spec.rb spec/ intake/runt_spec.rb spec/intake/date_spec.rb /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ configuration.rb:393: warning: toplevel constant VERSION referenced by Runt::Spec::VERSION /var/lib/gems/1.8/gems/diff-lcs-1.1.2/lib/diff/lcs.rb:16: Diff is not a module (TypeError) from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' from /var/lib/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/ expectations/differ.rb:1 from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' from /var/lib/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/ expectations.rb:9 from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/expecting/ with_rspec.rb:1 from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ configuration.rb:173:in `expectation_frameworks' from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ configuration.rb:380:in `configure_expectation_framework' from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ command_line.rb:20:in `run' from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb: 55:in `run_in_process' from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb: 46:in `run' from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb: 10:in `autorun' from /var/lib/gems/1.8/bin/rspec:19 .... So it seams that Runt::Spec collides with the old Spec namespace checking code (there's no VERSION constant in Runt::Spec) and the Runt::Diff class in collides with the Diff module from diff-lcs. This should not be the case as both Spec and Diff in Runt are namespaced Runt. I don't really understand all the magic going on in RSpec but i believe RSpec is to blame here. Am i right? Cheers Rob From rob.westgeest at gmail.com Fri Mar 18 21:19:00 2011 From: rob.westgeest at gmail.com (Rob Westgeest) Date: Fri, 18 Mar 2011 18:19:00 -0700 (PDT) Subject: [rspec-users] RSpec2 collides with Runt but why ? In-Reply-To: <3fe8f792-bb99-4476-994d-dc9bee5ba7bf@s11g2000yqh.googlegroups.com> References: <3fe8f792-bb99-4476-994d-dc9bee5ba7bf@s11g2000yqh.googlegroups.com> Message-ID: <969ca7ff-9a36-49b7-b883-a800377de1a5@w21g2000yqm.googlegroups.com> I know why now. It was me to blame (of course). Error message about the VERSION constant and the Diff is not a module could be more clear though. There's something strange going on in the Spec module check in core/configuration.rb I narrowed it down to a small example: Given: module MyModule class Spec # my spec implementation end class Diff # my Diff implementation end end When a spec includes the module like so: require 'my_module' include MyModule describe "collisions" do it "collides with Diff class" do 1.should == 1 end end Then rspec spits out the errors: /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ configuration.rb:393: warning: toplevel constant VERSION referenced by MyModule::Spec::VERSION and /var/lib/gems/1.8/gems/diff-lcs-1.1.2/lib/diff/lcs.rb:16: Diff is not a module When an example group includes module like so: require 'my_module' describe "collisions" do include MyModule it "collides with Diff class" do 1.should == 1 end end Then the spec runs without errors When the example group is put in the same module like so: require 'my_module' module MyModule describe "collisions" do it "collides with Diff class" do 1.should == 1 end end end Then the spec runs without errors So yep it was my fault. Sorry for blaming rspec. Apparently it is not a good idea to include a module in the spec file outside of the example groups. What made me put the blame on rspec a few hours looking for clues in rspecs error messages and code. Took me a while to narrow it down to its essence. Cheers Rob On Mar 18, 10:57?pm, Rob Westgeest wrote: > Hi, > > A project of mine is using Runt expressions to match dates. When > upgraded my rake tasks to 2.5.1 (from 1.3.0) it get this > > /usr/bin/ruby1.8 -S rspec spec/delivery_spec.rb spec/reporter_spec.rb > spec/mysql_dump_spec.rb spec/string_ext_spec.rb spec/ > backup_configuration_spec.rb spec/postgres_dump_spec.rb spec/ > system_command_spec.rb spec/archive_spec.rb spec/ > configuration_dsl_spec.rb spec/mailer_spec.rb spec/backup_spec.rb spec/ > intake/runt_spec.rb spec/intake/date_spec.rb > /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ > configuration.rb:393: warning: toplevel constant VERSION referenced by > Runt::Spec::VERSION > /var/lib/gems/1.8/gems/diff-lcs-1.1.2/lib/diff/lcs.rb:16: Diff is not > a module (TypeError) > ? ? ? ? from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > ? ? ? ? from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/ > expectations/differ.rb:1 > ? ? ? ? from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > ? ? ? ? from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/ > expectations.rb:9 > ? ? ? ? from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > ? ? ? ? from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/expecting/ > with_rspec.rb:1 > ? ? ? ? from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > ? ? ? ? from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ > configuration.rb:173:in `expectation_frameworks' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ > configuration.rb:380:in `configure_expectation_framework' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/ > command_line.rb:20:in `run' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb: > 55:in `run_in_process' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb: > 46:in `run' > ? ? ? ? from /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb: > 10:in `autorun' > ? ? ? ? from /var/lib/gems/1.8/bin/rspec:19 > .... > > So it seams that Runt::Spec collides with the old Spec namespace > checking code (there's no VERSION constant in Runt::Spec) and the > Runt::Diff class in collides with the Diff module from diff-lcs. This > should not be the case as both Spec and Diff in Runt are namespaced > Runt. > > I don't really understand all the magic going on in RSpec but i > believe RSpec is to blame here. Am i right? > > Cheers > > Rob > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From rochkind at jhu.edu Tue Mar 15 11:27:51 2011 From: rochkind at jhu.edu (Jonathan Rochkind) Date: Tue, 15 Mar 2011 11:27:51 -0400 Subject: [rspec-users] custom matcher and yielding too block Message-ID: <4D7F8577.2040409@jhu.edu> Using the 'new' way of defining custom matchers explained here: https://github.com/dchelimsky/rspec/wiki/Custom-Matchers I'm having trouble figuring out how to write a custom matcher that yields an object to a block where more matchers can be called on it. For instance, I'd like my actual spec to look something like this: something.should custom_matcher do | x | x.should be_something x.should include(something_or_other) end You get the idea? Can I create a custom matcher that does that? I'm having trouble figuring out how. From srushti at ambekallu.com Fri Mar 18 11:37:42 2011 From: srushti at ambekallu.com (Srushti Ambekallu) Date: Fri, 18 Mar 2011 21:07:42 +0530 Subject: [rspec-users] Post call verification Message-ID: <4D837C46.9050105@gmail.com> Hey all, I would like to be able to be able to have mocks where I can make all the calls and assert that it was called afterwards. This would be especially useful when asserting on a doing-method whose return value is not being considered. e.g. service = mock(ExternalService) ExternalService.stub!(:new).and_return(service) user = User.new user.activate service.should_have_received(:publish_user_activation).with(user) Now this obviously can't replace all assertions done with should_receive, but I know there are at least a few cases where this would come in handy and be more readable. I know while writing tests, I usually write the actual call (in this case the 'post') and then go up a couple of lines to write the should_receive. I think it would be more natural to verify it after the fact rather than before. I seem to remember there was another mocking library which did something quite close to this, but I just can't seem to find it just now. What does everyone think? I could try and implement this myself, but just wanted to see if there was any interest, or any one had a good reason not to include this. Thanks, Srshti -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Mar 19 09:02:21 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 19 Mar 2011 08:02:21 -0500 Subject: [rspec-users] custom matcher and yielding too block In-Reply-To: <4D7F8577.2040409@jhu.edu> References: <4D7F8577.2040409@jhu.edu> Message-ID: On Mar 15, 2011, at 10:27 AM, Jonathan Rochkind wrote: > Using the 'new' way of defining custom matchers explained here: https://github.com/dchelimsky/rspec/wiki/Custom-Matchers > > I'm having trouble figuring out how to write a custom matcher that yields an object to a block where more matchers can be called on it. > > For instance, I'd like my actual spec to look something like this: > > something.should custom_matcher do | x | > x.should be_something > x.should include(something_or_other) > end > > You get the idea? Can I create a custom matcher that does that? I'm having trouble figuring out how. Currently not supported, but I think it should be. Would you mind making a feature request at http://github.com/rspec/rspec-expectations/issues? Thx, David From dchelimsky at gmail.com Sat Mar 19 09:35:27 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 19 Mar 2011 08:35:27 -0500 Subject: [rspec-users] Post call verification In-Reply-To: <4D837C46.9050105@gmail.com> References: <4D837C46.9050105@gmail.com> Message-ID: On Mar 18, 2011, at 10:37 AM, Srushti Ambekallu wrote: > Hey all, > > I would like to be able to be able to have mocks where I can make all the calls and assert that it was called afterwards. This would be especially useful when asserting on a doing-method whose return value is not being considered. > e.g. > service = mock(ExternalService) > ExternalService.stub!(:new).and_return(service) > user = User.new > user.activate > service.should_have_received(:publish_user_activation).with(user) > Now this obviously can't replace all assertions done with should_receive, but I know there are at least a few cases where this would come in handy and be more readable. I know while writing tests, I usually write the actual call (in this case the 'post') and then go up a couple of lines to write the should_receive. I think it would be more natural to verify it after the fact rather than before. I seem to remember there was another mocking library which did something quite close to this, but I just can't seem to find it just now. What does everyone think? I could try and implement this myself, but just wanted to see if there was any interest, or any one had a good reason not to include this. This pattern is called a test spy, and there has been much discussion of it on this list: http://groups.google.com/group/rspec/search?group=rspec&q=test+spies&qt_g=Search+this+group The biggest issue for me is that message expectations often get set with a stub return value: foo.should_receive(:bar).and_return(:baz) foo(:bar) In a world of test spies, this would be: foo.stub(:bar).and_return(:baz) foo(:bar) foo.should_have_received(:bar).with(:bam) This requires more code in the example, and creates an otherwise unnecessary binding between the stub and the expectation. Also, note that the stub doesn't constrain the argument to bar(), but should_have_received() does (in this example). If we were to do that the other way: foo.stub(:bar).with(:baz).and_return(:bam) bar(:something_other_than_baz) foo.should_have_received(:bar) ... should this pass or fail? As rspec-mocks works today, it could only pass if we had an additional stub at the beginning. foo.stub(:bar) foo.stub(:bar).with(:baz).and_return(:bam) bar(:something_other_than_baz) foo.should_have_received(:bar) ... because calling bar(:anything_other_than_baz) would not work due to the with() constraint. If we agree it should fail, then that's pretty confusing as well, since foo did actually receive bar() and the only way to understand to failure is to look back at the stub with the with() constraint. I could go on but I think this makes the point. We don't have test spies in RSpec yet because a) I don't personally find them valuable and b) they introduce more problems than they solve. That said, if anyone cares to write an external library to support this, I'd gladly work with you to make sure RSpec provides you the extension points you need. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From lille.penguini at gmail.com Sat Mar 19 10:12:10 2011 From: lille.penguini at gmail.com (Lille) Date: Sat, 19 Mar 2011 07:12:10 -0700 (PDT) Subject: [rspec-users] [rspec-rails] warning about polymorphism on child objects Message-ID: <82c12e42-2edc-43d8-86b0-a8ed3e5a1ed5@r4g2000prm.googlegroups.com> Hi, I just ran into kind of an issue with child models in a one-to-one relationship who are also in a polymorphic association, i.e., their foreign key is kept by another model, e.g., 'Comment'. So, the path for a child might be "human_parents/1/child", while the path to the polymorphic association would be "human_parents/1/child/ comments". (Imagine that there are many kinds of parents, all capable of only one child, e.g., "kangaroo_parents/1/child".) The problem, I've found, is that a relatively efficient approach to controlling the Comment model, i.e., having a CommentController, is not fully testable under rspec-rails, bc the routes are unique within the CommentController spec file only by their params. So, when I do say 'get :new, :human_parent_id=>2' I can't further specify the action on the child, e.g., 'get new comment for the child'. >From a rspec-rails testing perspective, then, this should make you prefer to distribute the comment controller actions among the child controllers and not, as is often proposed, in a single controller. If anyone has any thoughts on how I can in fact, run around this problem and keep my CommentController, please write. Lille From matt at mattwynne.net Sat Mar 19 11:53:09 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 19 Mar 2011 15:53:09 +0000 Subject: [rspec-users] Post call verification In-Reply-To: References: <4D837C46.9050105@gmail.com> Message-ID: On 19 Mar 2011, at 13:35, David Chelimsky wrote: > On Mar 18, 2011, at 10:37 AM, Srushti Ambekallu wrote: > >> Hey all, >> >> I would like to be able to be able to have mocks where I can make all the calls and assert that it was called afterwards. This would be especially useful when asserting on a doing-method whose return value is not being considered. >> e.g. >> service = mock(ExternalService) >> ExternalService.stub!(:new).and_return(service) >> user = User.new >> user.activate >> service.should_have_received(:publish_user_activation).with(user) >> Now this obviously can't replace all assertions done with should_receive, but I know there are at least a few cases where this would come in handy and be more readable. I know while writing tests, I usually write the actual call (in this case the 'post') and then go up a couple of lines to write the should_receive. I think it would be more natural to verify it after the fact rather than before. I seem to remember there was another mocking library which did something quite close to this, but I just can't seem to find it just now. What does everyone think? I could try and implement this myself, but just wanted to see if there was any interest, or any one had a good reason not to include this. > > This pattern is called a test spy, and there has been much discussion of it on this list: > > http://groups.google.com/group/rspec/search?group=rspec&q=test+spies&qt_g=Search+this+group > > The biggest issue for me is that message expectations often get set with a stub return value: > > foo.should_receive(:bar).and_return(:baz) > foo(:bar) > > In a world of test spies, this would be: > > foo.stub(:bar).and_return(:baz) > foo(:bar) > foo.should_have_received(:bar).with(:bam) > > This requires more code in the example, and creates an otherwise unnecessary binding between the stub and the expectation. Also, note that the stub doesn't constrain the argument to bar(), but should_have_received() does (in this example). If we were to do that the other way: > > foo.stub(:bar).with(:baz).and_return(:bam) > bar(:something_other_than_baz) > foo.should_have_received(:bar) > > ... should this pass or fail? As rspec-mocks works today, it could only pass if we had an additional stub at the beginning. > > foo.stub(:bar) > foo.stub(:bar).with(:baz).and_return(:bam) > bar(:something_other_than_baz) > foo.should_have_received(:bar) > > ... because calling bar(:anything_other_than_baz) would not work due to the with() constraint. > > If we agree it should fail, then that's pretty confusing as well, since foo did actually receive bar() and the only way to understand to failure is to look back at the stub with the with() constraint. > > I could go on but I think this makes the point. We don't have test spies in RSpec yet because a) I don't personally find them valuable and b) they introduce more problems than they solve. > > That said, if anyone cares to write an external library to support this, I'd gladly work with you to make sure RSpec provides you the extension points you need. > > Cheers, > David It's also worth pointing out that can quite easily write your own test spy for the odd occasion when it seems necessary: class FakeExternalService attr_reader :who_was_published def publish_user_activation(user) @who_was_published = user end end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 -------------- next part -------------- An HTML attachment was scrubbed... URL: From sidwood2 at gmail.com Sat Mar 19 13:49:00 2011 From: sidwood2 at gmail.com (Sid Wood) Date: Sat, 19 Mar 2011 17:49:00 +0000 Subject: [rspec-users] Controller Spec & DataMapper Chaining In-Reply-To: References: Message-ID: Thanks Ken, but when I said I was new to RSpec I didn't mean I was THAT new! ;o) I think people aren't grasping the DataMapper chaining that is at the root of my testing confusion. I managed to come up with a solution that I've outlined here http://pastie.org/1690040 Basically, I mocked out a couple DataMapper::Collections and nested them. I'd love to hear if anyone would have tackled this issue differently. On 18 March 2011 18:01, Ken Chien wrote: > When calling get/post/etc, the second optional parameter is a hash > representing the "params" hash. > > So, in order to test the conditional(s) in your controller, you should > write: > get :index, :alpha => true #test the first conditional > > In another example, pass in :beta => true like this: > get :index, :beta => true > > HTH, > Ken > > > 2011/3/18 Sid Wood > >> Thanks for the replies guys. >> >> My problem is writing a test for >> >> @widgets = @widgets.by_alpha(params[:alpha]) >> >> DataMapper allows you to chain additional criteria on an existing query >> and doesnt execute that query until in is used in the view. So the above >> statement gets baked into the previous default query @widgets = >> Widget.all(:order => [ :name.asc ]). >> >> I'd just like to write a test that confirms the controller is in fact >> calling @widgets.by_alpha(params[:alpha]) when the params[:alpha] is >> present. >> >> Here is the code again so you don't have to scroll to see it >> >> >> def index >> @widgets = Widget.all(:order => [ :name.asc ]) >> if params[:alpha] >> @widgets = @widgets.by_alpha(params[:alpha]) >> elsif params[:beta] >> @widgets = @widgets.by_beta(params[:beta]) >> end >> end >> >> Just to recap, this code is valid and works, I just don't know how to >> write a test for it. >> >> Cheers, >> >> Sid >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Sat Mar 19 18:11:11 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 19 Mar 2011 22:11:11 +0000 Subject: [rspec-users] Controller Spec & DataMapper Chaining In-Reply-To: References: Message-ID: On 19 Mar 2011, at 17:49, Sid Wood wrote: > Thanks Ken, but when I said I was new to RSpec I didn't mean I was THAT new! ;o) > > I think people aren't grasping the DataMapper chaining that is at the root of my testing confusion. I managed to come up with a solution that I've outlined here http://pastie.org/1690040 > > Basically, I mocked out a couple DataMapper::Collections and nested them. I'd love to hear if anyone would have tackled this issue differently. Yes, I would have listened to the tests here, and heard that the interface to my model was awkward. I would either override Widget#all, or create a new method on the Widget that simply takes the params hash (or the three specific params new, name and materials) and figures out what to fetch from the database and returns it. You have data access concerns leaking out into your controller, which is why the interface is awkward to mock. > > > On 18 March 2011 18:01, Ken Chien wrote: > When calling get/post/etc, the second optional parameter is a hash representing the "params" hash. > > So, in order to test the conditional(s) in your controller, you should write: > get :index, :alpha => true #test the first conditional > > In another example, pass in :beta => true like this: > get :index, :beta => true > > HTH, > Ken > > > 2011/3/18 Sid Wood > Thanks for the replies guys. > > My problem is writing a test for > > @widgets = @widgets.by_alpha(params[:alpha]) > > DataMapper allows you to chain additional criteria on an existing query and doesnt execute that query until in is used in the view. So the above statement gets baked into the previous default query @widgets = Widget.all(:order => [ :name.asc ]). > > I'd just like to write a test that confirms the controller is in fact calling @widgets.by_alpha(params[:alpha]) when the params[:alpha] is present. > > Here is the code again so you don't have to scroll to see it > > > def index > @widgets = Widget.all(:order => [ :name.asc ]) > if params[:alpha] > @widgets = @widgets.by_alpha(params[:alpha]) > elsif params[:beta] > @widgets = @widgets.by_beta(params[:beta]) > end > end > > Just to recap, this code is valid and works, I just don't know how to write a test for it. > > Cheers, > > Sid > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Mar 19 19:22:32 2011 From: lists at ruby-forum.com (Phil Thompson) Date: Sun, 20 Mar 2011 00:22:32 +0100 Subject: [rspec-users] experimenting with stub in irb with RSpec2 In-Reply-To: References: Message-ID: <00ebdee2f3b265d067196ceb80cc64ac@ruby-forum.com> An update: This is now achieved with: require 'rspec/mocks/standalone' -- Posted via http://www.ruby-forum.com/. From sidwood2 at gmail.com Sun Mar 20 03:56:02 2011 From: sidwood2 at gmail.com (Sid Wood) Date: Sun, 20 Mar 2011 07:56:02 +0000 Subject: [rspec-users] Controller Spec & DataMapper Chaining In-Reply-To: References: Message-ID: Thats great advice and now that you've pointed it out it seems so obvious. Thanks Matt. See you at Cukeup! Sid On 19 March 2011 22:11, Matt Wynne wrote: > > On 19 Mar 2011, at 17:49, Sid Wood wrote: > > Thanks Ken, but when I said I was new to RSpec I didn't mean I was THAT > new! ;o) > > I think people aren't grasping the DataMapper chaining that is at the root > of my testing confusion. I managed to come up with a solution that I've > outlined here http://pastie.org/1690040 > > Basically, I mocked out a couple DataMapper::Collections and nested them. > I'd love to hear if anyone would have tackled this issue differently. > > > Yes, I would have listened to the tests here, and heard that the interface > to my model was awkward. > > I would either override Widget#all, or create a new method on the Widget > that simply takes the params hash (or the three specific params new, name > and materials) and figures out what to fetch from the database and returns > it. You have data access concerns leaking out into your controller, which is > why the interface is awkward to mock. > > > > On 18 March 2011 18:01, Ken Chien wrote: > >> When calling get/post/etc, the second optional parameter is a hash >> representing the "params" hash. >> >> So, in order to test the conditional(s) in your controller, you should >> write: >> get :index, :alpha => true #test the first conditional >> >> In another example, pass in :beta => true like this: >> get :index, :beta => true >> >> HTH, >> Ken >> >> >> 2011/3/18 Sid Wood >> >>> Thanks for the replies guys. >>> >>> My problem is writing a test for >>> >>> @widgets = @widgets.by_alpha(params[:alpha]) >>> >>> DataMapper allows you to chain additional criteria on an existing query >>> and doesnt execute that query until in is used in the view. So the above >>> statement gets baked into the previous default query @widgets = >>> Widget.all(:order => [ :name.asc ]). >>> >>> I'd just like to write a test that confirms the controller is in fact >>> calling @widgets.by_alpha(params[:alpha]) when the params[:alpha] is >>> present. >>> >>> Here is the code again so you don't have to scroll to see it >>> >>> >>> def index >>> @widgets = Widget.all(:order => [ :name.asc ]) >>> if params[:alpha] >>> @widgets = @widgets.by_alpha(params[:alpha]) >>> elsif params[:beta] >>> @widgets = @widgets.by_beta(params[:beta]) >>> end >>> end >>> >>> Just to recap, this code is valid and works, I just don't know how to >>> write a test for it. >>> >>> Cheers, >>> >>> Sid >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > cheers, > Matt > > matt at mattwynne.net > 07974 430184 > > > _______________________________________________ > 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 lille.penguini at gmail.com Sun Mar 20 11:02:15 2011 From: lille.penguini at gmail.com (Lille) Date: Sun, 20 Mar 2011 08:02:15 -0700 (PDT) Subject: [rspec-users] [rspec-rails] warning about polymorphism on child objects In-Reply-To: <82c12e42-2edc-43d8-86b0-a8ed3e5a1ed5@r4g2000prm.googlegroups.com> References: <82c12e42-2edc-43d8-86b0-a8ed3e5a1ed5@r4g2000prm.googlegroups.com> Message-ID: <296fcdd6-d0d8-4285-b259-453d44adc7c6@j35g2000prb.googlegroups.com> ...I couldn't handle this lingering difficulty, so I just put the CommentController into a module and mixed it in. Thus, no longer soliciting comments on previous problem. Yet, I think the warning still maybe useful re Rails and comments modeling. Lille On Mar 19, 10:12?am, Lille wrote: > Hi, > > I just ran into kind of an issue with child models in a one-to-one > relationship who are also in a polymorphic association, i.e., their > foreign key is kept by another model, e.g., 'Comment'. > > So, the path for a child might be "human_parents/1/child", while the > path to the polymorphic association would be "human_parents/1/child/ > comments". (Imagine that there are many kinds of parents, all capable > of only one child, e.g., "kangaroo_parents/1/child".) > > The problem, I've found, is that a relatively efficient approach to > controlling the Comment model, i.e., having a CommentController, is > not fully testable under rspec-rails, bc the routes are unique within > the CommentController spec file only by their params. So, when I do > say 'get :new, :human_parent_id=>2' I can't further specify the action > on the child, e.g., 'get new comment for the child'. > > >From a rspec-rails testing perspective, then, this should make you > > prefer to distribute the comment controller actions among the child > controllers and not, as is often proposed, in a single controller. > > If anyone has any thoughts on how I can in fact, run around this > problem and keep my CommentController, please write. > > Lille > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From niku at niku.name Sun Mar 20 21:41:18 2011 From: niku at niku.name (niku -E:)) Date: Mon, 21 Mar 2011 10:41:18 +0900 Subject: [rspec-users] How do I use expect{}.to change().from().to() on Array? In-Reply-To: References: Message-ID: I understand that "expect{}.to change()" can't test "destructive method". So, I should write test like that. correct? require 'rspec' class Ary attr_reader :ary def initialize @count = 0 @ary = [] increment end def increment @ary << @count @count += 1 end end describe Ary, "#ary" do subject{ Ary.new } it "should increment the ary" do # expect { subject.increment }.to change(subject, :ary).from([]).to([0]) subject.ary.should == [0] subject.increment subject.ary.should == [0,1] end end On Wed, Mar 16, 2011 at 2:41 AM, Justin Ko wrote: > > > On Tue, Mar 15, 2011 at 10:08 AM, Justin Ko wrote: >> >> >> On Tue, Mar 15, 2011 at 8:57 AM, niku -E:) wrote: >>> >>> Hi. >>> >>> I'm using ruby1.9.2 and rspec2.5.1 >>> I want to use "expect{}.to change().from().to()" like this >>> >>> https://gist.github.com/870897 >>> >>> When Int class, it passed. >>> When Ary class, it failed. >>> >>> Why was Ary test failed and How do I pass this test? >>> >>> regards. >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> Your Ary @ary variable is initialized as "[]". So of course calling >> increment on it will change it to "[0]". For your spec to pass, initialize >> it as "[0]" > > I'm completely wrong. Didn't read your code properly. Where is the delete > link? :) From niku at niku.name Sun Mar 20 21:54:50 2011 From: niku at niku.name (niku -E:)) Date: Mon, 21 Mar 2011 10:54:50 +0900 Subject: [rspec-users] How do I use expect{}.to change().from().to() on Array? In-Reply-To: References: Message-ID: Sorry. Test comment is incorrect. This is intentional test. require 'rspec' class Ary attr_reader :ary def initialize @count = 0 @ary = [] increment end def increment @ary << @count @count += 1 end end describe Ary, "#ary" do subject{ Ary.new } it "should increment the ary" do # expect { subject.increment }.to change(subject, :ary).from([0]).to([0,1]) subject.ary.should == [0] subject.increment subject.ary.should == [0,1] end end On Mon, Mar 21, 2011 at 10:41 AM, niku -E:) wrote: > I understand that "expect{}.to change()" can't test "destructive method". > So, I should write test like that. correct? > > require 'rspec' > > class Ary > ?attr_reader :ary > ?def initialize > ? ?@count = 0 > ? ?@ary = [] > ? ?increment > ?end > ?def increment > ? ?@ary << @count > ? ?@count += 1 > ?end > end > > describe Ary, "#ary" do > ?subject{ Ary.new } > ?it "should increment the ary" do > ? ?# expect { subject.increment }.to change(subject, :ary).from([]).to([0]) > ? ?subject.ary.should == [0] > ? ?subject.increment > ? ?subject.ary.should == [0,1] > ?end > end > > On Wed, Mar 16, 2011 at 2:41 AM, Justin Ko wrote: >> >> >> On Tue, Mar 15, 2011 at 10:08 AM, Justin Ko wrote: >>> >>> >>> On Tue, Mar 15, 2011 at 8:57 AM, niku -E:) wrote: >>>> >>>> Hi. >>>> >>>> I'm using ruby1.9.2 and rspec2.5.1 >>>> I want to use "expect{}.to change().from().to()" like this >>>> >>>> https://gist.github.com/870897 >>>> >>>> When Int class, it passed. >>>> When Ary class, it failed. >>>> >>>> Why was Ary test failed and How do I pass this test? >>>> >>>> regards. >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> Your Ary @ary variable is initialized as "[]". So of course calling >>> increment on it will change it to "[0]". For your spec to pass, initialize >>> it as "[0]" >> >> I'm completely wrong. Didn't read your code properly. Where is the delete >> link? :) > From kai.schlamp at googlemail.com Mon Mar 21 06:41:35 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Mon, 21 Mar 2011 03:41:35 -0700 (PDT) Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec Message-ID: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> My ApplicationController exposes a method (e.g. sort_direction) to the view templates by using helper_method :sort_direction. I then use this method in another method (e.g. sort_link) in a view helper (application_helper.rb). When testing the sort_link method with RSpec (in application_helper_spec.rb) I have to stub sort_direction as the test seems to run completely independent from the controllers (and thereby by to the view templates exposed methods). Unfortunately I could not find out how to stub that sort_direction method of the controller. I always get "undefined method". Here is what I tried so far (inside application_helper_spec.rb): helper.stub(:sort_direction) controller.stub(:sort_direction) view.stub(:sort_direction) self.stub(:sort_direction) Here the error I get: NoMethodError: undefined method `sort_direction' for # References: Message-ID: On 16 March 2011 12:15, Sid Wood wrote: > Does anyone know of any open source projects that are using RSpec and > DataMapper together that I can dissect? A project I work on, One Click Orgs, was using Merb + DataMapper with RSpec and Machinist. We've since migrated to Rails with ActiveRecord, but if you checkout our v0.5.x branch: https://github.com/oneclickorgs/one-click-orgs/tree/v0.5.x then you'll get the old Merb app. I wouldn't say it's the most thoroughly or expertly spec'd piece of code out there, but perhaps it's a start? Chris From dchelimsky at gmail.com Mon Mar 21 07:36:22 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 21 Mar 2011 06:36:22 -0500 Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> Message-ID: On Mar 21, 2011, at 5:41 AM, Kai Schlamp wrote: > My ApplicationController exposes a method (e.g. sort_direction) to the > view templates by using > helper_method :sort_direction. > I then use this method in another method (e.g. sort_link) in a view > helper (application_helper.rb). > > When testing the sort_link method with RSpec (in > application_helper_spec.rb) I have to stub sort_direction as the test > seems to run completely independent from the controllers (and thereby > by to the view templates exposed methods). > > Unfortunately I could not find out how to stub that sort_direction > method of the controller. I always get "undefined method". > > Here is what I tried so far (inside application_helper_spec.rb): > > helper.stub(:sort_direction) This ^^ should work. > controller.stub(:sort_direction) > view.stub(:sort_direction) > self.stub(:sort_direction) > > Here the error I get: > > NoMethodError: > undefined method `sort_direction' for > # References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> Message-ID: On 21 Mar 2011, at 10:41, Kai Schlamp wrote: > My ApplicationController exposes a method (e.g. sort_direction) to the > view templates by using > helper_method :sort_direction. > I then use this method in another method (e.g. sort_link) in a view > helper (application_helper.rb). > > When testing the sort_link method with RSpec (in > application_helper_spec.rb) I have to stub sort_direction as the test > seems to run completely independent from the controllers (and thereby > by to the view templates exposed methods). > > Unfortunately I could not find out how to stub that sort_direction > method of the controller. I always get "undefined method". > > Here is what I tried so far (inside application_helper_spec.rb): > > helper.stub(:sort_direction) > controller.stub(:sort_direction) > view.stub(:sort_direction) > self.stub(:sort_direction) > > Here the error I get: > > NoMethodError: > undefined method `sort_direction' for > # > There is already some older blog post about that topic (http:// > jakescruggs.blogspot.com/2007/03/mockingstubbing-partials-and- > helper.html), but it seems that this is not valid anymore for Rails 3 > as there is no @controller.template. > > How do I stub that method? > > Kai > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From kai.schlamp at googlemail.com Mon Mar 21 09:40:51 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Mon, 21 Mar 2011 06:40:51 -0700 (PDT) Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> Message-ID: > This error ^^ suggests that sort_direction is being called on the example itself rather than the helper object. Please post the spec so we can see what's going on. Sure ... describe ApplicationHelper do describe "order link" do it "should create html link" do # things I tried view.stub(:check_param) helper.stub(:check_param) controller.stub(:check_param) self.stub(:check_param) order_link(:name) end end end Here is how check_param is called from within the helper: module ApplicationHelper def order_link(column, title = nil) fetch_param(:order) end end and in application controller: ... helper_method :fetch_param def fetch_param(name) ... end ... From dchelimsky at gmail.com Mon Mar 21 10:08:47 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 21 Mar 2011 09:08:47 -0500 Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> Message-ID: <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> On Mar 21, 2011, at 8:40 AM, Kai Schlamp wrote: >> This error ^^ suggests that sort_direction is being called on the example itself rather than the helper object. Please post the spec so we can see what's going on. > > Sure ... > > describe ApplicationHelper do > describe "order link" do > it "should create html link" do > # things I tried > view.stub(:check_param) > helper.stub(:check_param) > controller.stub(:check_param) > self.stub(:check_param) > > order_link(:name) > end > end > end > > Here is how check_param is called from within the helper: > > module ApplicationHelper > def order_link(column, title = nil) > fetch_param(:order) Change this ^^ to this: helper.fetch_param(:order) The problem is that ActionView::TestCase::Behavior, which helper specs rely on, include the module being spec'd right in the spec, so you have access to those methods directly. RSpec expresses an opinion that the object should be wrapped instead by providing a helper object that includes the module being spec'd, but does not remove the module methods from the scope of the spec. HTH, David > end > end > > and in application controller: > > ... > helper_method :fetch_param > > def fetch_param(name) > ... > end > ... > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From kai.schlamp at googlemail.com Mon Mar 21 12:15:03 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Mon, 21 Mar 2011 09:15:03 -0700 (PDT) Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> Message-ID: Ok, the tests now runs fine, but unfortunately the site itself doesn't work anymore. When the view gets rendered I get the following error: undefined local variable or method `helper' for #<#: 0xb665532c> > > module ApplicationHelper > > ?def order_link(column, title = nil) > > ? ?fetch_param(:order) > > Change this ^^ to this: > > ? helper.fetch_param(:order) From kai.schlamp at googlemail.com Mon Mar 21 12:19:09 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Mon, 21 Mar 2011 09:19:09 -0700 (PDT) Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> Message-ID: > Change this ^^ to this: > > ? helper.fetch_param(:order) I was wrong the test fails also with the same error message: Failure/Error: order_link(:name) NoMethodError: undefined method `fetch_param' for #<#: 0xb63be118> From kai.schlamp at googlemail.com Mon Mar 21 13:09:59 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Mon, 21 Mar 2011 10:09:59 -0700 (PDT) Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> Message-ID: > From this error message, it looks like you can just def it inside your describe block. Thanks Matt, that seems to work. From dchelimsky at gmail.com Mon Mar 21 13:14:16 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 21 Mar 2011 12:14:16 -0500 Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> Message-ID: <62FCF2C2-F26D-4C54-98F5-182BC54B6C84@gmail.com> On Mar 21, 2011, at 11:19 AM, Kai Schlamp wrote: >> Change this ^^ to this: >> >> helper.fetch_param(:order) > > I was wrong the test fails also with the same error message: > > Failure/Error: order_link(:name) > NoMethodError: > undefined method `fetch_param' for #<#: > 0xb63be118> That's not the same error message you posted earlier: NoMethodError: undefined method `sort_direction' for # References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> Message-ID: <93C4EA5C-5BE3-425A-A0AC-4131D9B191D0@gmail.com> On Mar 21, 2011, at 11:15 AM, Kai Schlamp wrote: >>> module ApplicationHelper >>> def order_link(column, title = nil) >>> fetch_param(:order) >> >> Change this ^^ to this: >> >> helper.fetch_param(:order) > Ok, the tests now runs fine, but unfortunately the site itself doesn't > work anymore. > When the view gets rendered I get the following error: > > undefined local variable or method `helper' for #<#: > 0xb665532c> What's the full backtrace? From kai.schlamp at googlemail.com Mon Mar 21 13:52:14 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Mon, 21 Mar 2011 10:52:14 -0700 (PDT) Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: <62FCF2C2-F26D-4C54-98F5-182BC54B6C84@gmail.com> References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> <62FCF2C2-F26D-4C54-98F5-182BC54B6C84@gmail.com> Message-ID: <90c94ca6-6fe4-4a4d-89ab-2f27300b3b75@p16g2000vbi.googlegroups.com> > > Failure/Error: order_link(:name) > > ? ? NoMethodError: > > ? ? ? undefined method `fetch_param' for #<#: > > 0xb63be118> > > That's not the same error message you posted earlier: > > NoMethodError: > ? ? ? undefined method `sort_direction' for > #" error shows up when using helper.check_param in the order_link method as you suggested. The "# This ^^ message tells us that sort_direction is not implemented on the example. The new message (above) tells us that fetch_param is not implemented on the helper object, which means one of two things: > > 1) fetch_param is not implemented as an instance method in the ApplicationHelper module. This would be just a matter of implementing it. It should be. It works when viewing that template in the browser. > 2) ApplicationHelper is not included in the helper object. It should be included if the spec file is in spec/helpers. Is it? order_link is known and that is a method of ApplicationHelper, so I guess it is included. From lists at ruby-forum.com Mon Mar 21 14:04:44 2011 From: lists at ruby-forum.com (Jared M.) Date: Mon, 21 Mar 2011 19:04:44 +0100 Subject: [rspec-users] rake spec loads development environment In-Reply-To: <1c51d85b1455b71e6461316a77073874@ruby-forum.com> References: <1c51d85b1455b71e6461316a77073874@ruby-forum.com> Message-ID: This thread has been dead for awhile, but I'm having the same issue. I don't have a bash variable set. I'm also having this issue with Cucumber. It always runs in development mode. If I put "p Rails.env" in spec_helper.rb:8 (after spec_helper already declares ENV["RAILS_ENV"] ||= "test") and run "rake spec" it outputs "development" every time. If I run "spec spec/*/**" it outputs "test" like it should. My setup: Rails 2.3.9 Rake 0.8.7 Bundler 1.0.10 Rspec-rails 1.3.3 Rspec 1.3.1 -- Posted via http://www.ruby-forum.com/. From kai.schlamp at googlemail.com Mon Mar 21 14:12:49 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Mon, 21 Mar 2011 11:12:49 -0700 (PDT) Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: <93C4EA5C-5BE3-425A-A0AC-4131D9B191D0@gmail.com> References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> <93C4EA5C-5BE3-425A-A0AC-4131D9B191D0@gmail.com> Message-ID: <3d00b86c-95fc-444f-a82f-19b9d7aa81d7@s3g2000vbf.googlegroups.com> > > undefined local variable or method `helper' for #<#: > > 0xb665532c> > > What's the full backtrace? 1) ApplicationHelper order link should create html link Failure/Error: order_link(:name) NoMethodError: undefined method `fetch_param' for #<#: 0xb64a1ef4> # ./app/helpers/application_helper.rb:43:in `order_link' # ./spec/helpers/application_helper_spec.rb:22 # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example.rb:49:in `instance_eval' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example.rb:49:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example.rb:106:in `with_around_hooks' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example.rb:46:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example.rb:99:in `with_pending_capture' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example.rb:98:in `catch' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example.rb:98:in `with_pending_capture' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example.rb:45:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:262:in `run_examples' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:258:in `map' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:258:in `run_examples' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:232:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:233:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:233:in `map' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:233:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/command_line.rb:27:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/command_line.rb:27:in `map' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/command_line.rb:27:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/reporter.rb:12:in `report' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/command_line.rb:24:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/runner.rb:55:in `run_in_process' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/runner.rb:46:in `run' # /home/kai/.rvm/gems/ruby-1.8.7-p330/gems/rspec-core-2.5.1/lib/ rspec/core/runner.rb:10:in `autorun' # /home/kai/.rvm/gems/ruby-1.8.7-p330/bin/rspec:19 From dchelimsky at gmail.com Mon Mar 21 14:52:48 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 21 Mar 2011 13:52:48 -0500 Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: <90c94ca6-6fe4-4a4d-89ab-2f27300b3b75@p16g2000vbi.googlegroups.com> References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> <62FCF2C2-F26D-4C54-98F5-182BC54B6C84@gmail.com> <90c94ca6-6fe4-4a4d-89ab-2f27300b3b75@p16g2000vbi.googlegroups.com> Message-ID: <78293CE4-3197-4B87-B25E-DC586660600C@gmail.com> On Mar 21, 2011, at 12:52 PM, Kai Schlamp wrote: >>> Failure/Error: order_link(:name) >>> NoMethodError: >>> undefined method `fetch_param' for #<#: >>> 0xb63be118> >> >> That's not the same error message you posted earlier: >> >> NoMethodError: >> undefined method `sort_direction' for >> # > The "#<#" error shows up when using > helper.check_param in the order_link method as you suggested. That's not what I meant to suggest. In the spec, the method being spec'd should be invoked through the helper: it "does something" do helper.method_being_specified end I did not mean to reference a helper object inside the implementation. Make sense? > The > "# check_param (without "helper."). > >> This ^^ message tells us that sort_direction is not implemented on the example. The new message (above) tells us that fetch_param is not implemented on the helper object, which means one of two things: >> >> 1) fetch_param is not implemented as an instance method in the ApplicationHelper module. This would be just a matter of implementing it. > > It should be. It works when viewing that template in the browser. > >> 2) ApplicationHelper is not included in the helper object. It should be included if the spec file is in spec/helpers. Is it? > > order_link is known and that is a method of ApplicationHelper, so I > guess it is included. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From kai.schlamp at googlemail.com Mon Mar 21 17:10:12 2011 From: kai.schlamp at googlemail.com (Kai Schlamp) Date: Mon, 21 Mar 2011 14:10:12 -0700 (PDT) Subject: [rspec-users] Stub a controllers helper_method in a view template helper spec In-Reply-To: <78293CE4-3197-4B87-B25E-DC586660600C@gmail.com> References: <022bb5e0-d663-4cdb-8f20-16ce4660e0bf@p16g2000vbi.googlegroups.com> <3DFE6DC7-1EC4-4088-BC16-EA847B127A55@gmail.com> <62FCF2C2-F26D-4C54-98F5-182BC54B6C84@gmail.com> <90c94ca6-6fe4-4a4d-89ab-2f27300b3b75@p16g2000vbi.googlegroups.com> <78293CE4-3197-4B87-B25E-DC586660600C@gmail.com> Message-ID: <36132402-f078-4731-aee4-1b0aad2d2a30@v16g2000vbq.googlegroups.com> > In the spec, the method being spec'd should be invoked through the helper: > > ? it "does something" do > ? ? helper.method_being_specified > ? end > > I did not mean to reference a helper object inside the implementation. > > Make sense? Ah, now I got it ... you meant the template helper method (helpers here and there and everywhere ;-)). This works fine now: it "should work" do helper.stub(:fetch_param) helper.order_link(:name) end Thanks a lot for your time and help, David. From tom at therye.org Tue Mar 22 05:13:42 2011 From: tom at therye.org (Tom Stuart) Date: Tue, 22 Mar 2011 09:13:42 +0000 Subject: [rspec-users] Post call verification In-Reply-To: References: <4D837C46.9050105@gmail.com> Message-ID: <394D5AA5-B20F-4304-8BEF-DF140EFF0549@therye.org> On 19 Mar 2011, at 13:35, David Chelimsky wrote: > On Mar 18, 2011, at 10:37 AM, Srushti Ambekallu wrote: > >> Hey all, >> >> I would like to be able to be able to have mocks where I can make all the calls and assert that it was called afterwards. This would be especially useful when asserting on a doing-method whose return value is not being considered. >> e.g. >> service = mock(ExternalService) >> ExternalService.stub!(:new).and_return(service) >> user = User.new >> user.activate >> service.should_have_received(:publish_user_activation).with(user) >> Now this obviously can't replace all assertions done with should_receive, but I know there are at least a few cases where this would come in handy and be more readable. I know while writing tests, I usually write the actual call (in this case the 'post') and then go up a couple of lines to write the should_receive. I think it would be more natural to verify it after the fact rather than before. I seem to remember there was another mocking library which did something quite close to this, but I just can't seem to find it just now. What does everyone think? I could try and implement this myself, but just wanted to see if there was any interest, or any one had a good reason not to include this. > > This pattern is called a test spy, and there has been much discussion of it on this list: > > http://groups.google.com/group/rspec/search?group=rspec&q=test+spies&qt_g=Search+this+group > > The biggest issue for me is that message expectations often get set with a stub return value: > > foo.should_receive(:bar).and_return(:baz) > foo(:bar) > > In a world of test spies, this would be: > > foo.stub(:bar).and_return(:baz) > foo(:bar) > foo.should_have_received(:bar).with(:bam) > > This requires more code in the example, and creates an otherwise unnecessary binding between the stub and the expectation. Also, note that the stub doesn't constrain the argument to bar(), but should_have_received() does (in this example). If we were to do that the other way: > > foo.stub(:bar).with(:baz).and_return(:bam) > bar(:something_other_than_baz) > foo.should_have_received(:bar) > > ... should this pass or fail? As rspec-mocks works today, it could only pass if we had an additional stub at the beginning. > > foo.stub(:bar) > foo.stub(:bar).with(:baz).and_return(:bam) > bar(:something_other_than_baz) > foo.should_have_received(:bar) > > ... because calling bar(:anything_other_than_baz) would not work due to the with() constraint. > > If we agree it should fail, then that's pretty confusing as well, since foo did actually receive bar() and the only way to understand to failure is to look back at the stub with the with() constraint. > > I could go on but I think this makes the point. We don't have test spies in RSpec yet because a) I don't personally find them valuable and b) they introduce more problems than they solve. > > That said, if anyone cares to write an external library to support this, I'd gladly work with you to make sure RSpec provides you the extension points you need. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users This is a long-running discussion and I suspect it comes down to personal preference in the end more than anything else. However, I have done some work to get a basic test spy library working with rspec which tries to avoid unnecessary stubbing to allow assertion on method calls (i.e. you only need to set up a stub as well when you need to manipulate the return value). It's in its infant stages and needs some TLC (in particular, its factory method 'spy' is in the global namespace, when it could and should be dealt with more elegantly), but it may be of some use for test spy fanatics... https://github.com/mortice/matahari Cheers, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Mar 22 07:52:02 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Mar 2011 06:52:02 -0500 Subject: [rspec-users] Post call verification In-Reply-To: <394D5AA5-B20F-4304-8BEF-DF140EFF0549@therye.org> References: <4D837C46.9050105@gmail.com> <394D5AA5-B20F-4304-8BEF-DF140EFF0549@therye.org> Message-ID: <3237C672-2BB7-446C-9AE5-E25447CE25C8@gmail.com> On Mar 22, 2011, at 4:13 AM, Tom Stuart wrote: > On 19 Mar 2011, at 13:35, David Chelimsky wrote: > >> On Mar 18, 2011, at 10:37 AM, Srushti Ambekallu wrote: >> >>> Hey all, >>> >>> I would like to be able to be able to have mocks where I can make all the calls and assert that it was called afterwards. This would be especially useful when asserting on a doing-method whose return value is not being considered. >>> e.g. >>> service = mock(ExternalService) >>> ExternalService.stub!(:new).and_return(service) >>> user = User.new >>> user.activate >>> service.should_have_received(:publish_user_activation).with(user) >>> Now this obviously can't replace all assertions done with should_receive, but I know there are at least a few cases where this would come in handy and be more readable. I know while writing tests, I usually write the actual call (in this case the 'post') and then go up a couple of lines to write the should_receive. I think it would be more natural to verify it after the fact rather than before. I seem to remember there was another mocking library which did something quite close to this, but I just can't seem to find it just now. What does everyone think? I could try and implement this myself, but just wanted to see if there was any interest, or any one had a good reason not to include this. >> >> This pattern is called a test spy, and there has been much discussion of it on this list: >> >> http://groups.google.com/group/rspec/search?group=rspec&q=test+spies&qt_g=Search+this+group >> >> The biggest issue for me is that message expectations often get set with a stub return value: >> >> foo.should_receive(:bar).and_return(:baz) >> foo(:bar) >> >> In a world of test spies, this would be: >> >> foo.stub(:bar).and_return(:baz) >> foo(:bar) >> foo.should_have_received(:bar).with(:bam) >> >> This requires more code in the example, and creates an otherwise unnecessary binding between the stub and the expectation. Also, note that the stub doesn't constrain the argument to bar(), but should_have_received() does (in this example). If we were to do that the other way: >> >> foo.stub(:bar).with(:baz).and_return(:bam) >> bar(:something_other_than_baz) >> foo.should_have_received(:bar) >> >> ... should this pass or fail? As rspec-mocks works today, it could only pass if we had an additional stub at the beginning. >> >> foo.stub(:bar) >> foo.stub(:bar).with(:baz).and_return(:bam) >> bar(:something_other_than_baz) >> foo.should_have_received(:bar) >> >> ... because calling bar(:anything_other_than_baz) would not work due to the with() constraint. >> >> If we agree it should fail, then that's pretty confusing as well, since foo did actually receive bar() and the only way to understand to failure is to look back at the stub with the with() constraint. >> >> I could go on but I think this makes the point. We don't have test spies in RSpec yet because a) I don't personally find them valuable and b) they introduce more problems than they solve. >> >> That said, if anyone cares to write an external library to support this, I'd gladly work with you to make sure RSpec provides you the extension points you need. >> >> Cheers, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > This is a long-running discussion and I suspect it comes down to personal preference in the end more than anything else. However, I have done some work to get a basic test spy library working with rspec which tries to avoid unnecessary stubbing to allow assertion on method calls (i.e. you only need to set up a stub as well when you need to manipulate the return value). It's in its infant stages and needs some TLC (in particular, its factory method 'spy' is in the global namespace, when it could and should be dealt with more elegantly), but it may be of some use for test spy fanatics... https://github.com/mortice/matahari Thanks, Tom. Let me know if there is anything you need in RSpec to make it easy to plug this in. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From thibaut.barrere at gmail.com Tue Mar 22 08:50:57 2011 From: thibaut.barrere at gmail.com (=?ISO-8859-1?Q?Thibaut_Barr=E8re?=) Date: Tue, 22 Mar 2011 05:50:57 -0700 (PDT) Subject: [rspec-users] How to test a Rails 3 metal controller? Message-ID: <044ce36f-f765-48a0-a145-f539e01ea2ec@j35g2000prb.googlegroups.com> Hi! I could not find an easy solution to this question: how can I properly test an Rails controller action? We were trying to run the following test: get :show, :id => 'hello' response.should redirect_to("http://www.google.com") But we got: undefined method `formats=' for # After reading a couple of blog posts, we tried this work-around: class LinksController include ActionController::UrlFor include ActionController::Testing include Rails.application.routes.url_helpers include AbstractController::ViewPaths end It works only partially, we're now stuck with the limits of our monkey- patching and get the following error: undefined method `protected_instance_variables' for LinksController:Class Well - is there a clean way to test our a Rails metal with RSpec? Thanks for your support! -- Thibaut From dchelimsky at gmail.com Tue Mar 22 09:36:49 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Mar 2011 08:36:49 -0500 Subject: [rspec-users] How to test a Rails 3 metal controller? In-Reply-To: <044ce36f-f765-48a0-a145-f539e01ea2ec@j35g2000prb.googlegroups.com> References: <044ce36f-f765-48a0-a145-f539e01ea2ec@j35g2000prb.googlegroups.com> Message-ID: On Mar 22, 2011, at 7:50 AM, Thibaut Barr?re wrote: > Hi! > > I could not find an easy solution to this question: how can I properly > test an Rails controller action? > > We were trying to run the following test: > > get :show, :id => 'hello' > response.should redirect_to("http://www.google.com") > > But we got: > > undefined method `formats=' for # > > After reading a couple of blog posts, we tried this work-around: > > class LinksController > include ActionController::UrlFor > include ActionController::Testing > include Rails.application.routes.url_helpers > include AbstractController::ViewPaths > end > > It works only partially, we're now stuck with the limits of our monkey- > patching and get the following error: > > undefined method `protected_instance_variables' for > LinksController:Class > > Well - is there a clean way to test our a Rails metal with RSpec? Use a request spec (in spec/requests) instead of a controller spec. > > Thanks for your support! > > -- Thibaut > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From bewang.tech at gmail.com Tue Mar 22 17:37:42 2011 From: bewang.tech at gmail.com (Benyi Wang) Date: Tue, 22 Mar 2011 14:37:42 -0700 Subject: [rspec-users] Is it possible to run rspec continuously? Message-ID: When I run rspec in Rails, it seems that a ruby process is created and loaded with rails components due to the statement require 'spec_helper'. This usually takes a while to run even a single spec. Does a tool for rspec like rails console exist so that you can run specs continuously without loading everything each time? autotest actually starts a new process each time when there is a change, and I can still feel the obvious delay. Any idea? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From katrina.owen at gmail.com Tue Mar 22 17:59:49 2011 From: katrina.owen at gmail.com (Katrina Owen) Date: Tue, 22 Mar 2011 22:59:49 +0100 Subject: [rspec-users] Is it possible to run rspec continuously? In-Reply-To: References: Message-ID: Hi there, Check out Spork. Spork will fire up a distributed ruby process that your tests can run in. You'll need to restart spork any time environment files change (check out guard for this, though), but that's minor considering the increase in speed that you can see. Katrina On Tue, Mar 22, 2011 at 10:37 PM, Benyi Wang wrote: > When I run rspec in Rails, it seems that a ruby process is created and > loaded with rails components due to the statement require 'spec_helper'. > This usually takes a while to run even a single spec. Does a tool for rspec > like rails console exist so that you can run specs continuously without > loading everything each time? > autotest actually starts a new process each time when there is a change, and > I can still feel the obvious delay. > Any idea? > Thanks. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jko170 at gmail.com Tue Mar 22 18:02:37 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 22 Mar 2011 15:02:37 -0700 Subject: [rspec-users] Is it possible to run rspec continuously? In-Reply-To: References: Message-ID: On Tue, Mar 22, 2011 at 2:37 PM, Benyi Wang wrote: > When I run rspec in Rails, it seems that a ruby process is created and > loaded with rails components due to the statement require 'spec_helper'. > This usually takes a while to run even a single spec. Does a tool for rspec > like rails console exist so that you can run specs continuously without > loading everything each time? > > autotest actually starts a new process each time when there is a change, > and I can still feel the obvious delay. > > Any idea? > > Thanks. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Take a look at Spork: http://chrismdp.github.com/2010/11/getting-spork-working-now-on-rails-3-rspec-2-and-cucumber/ https://github.com/timcharper/spork -------------- next part -------------- An HTML attachment was scrubbed... URL: From adam.sroka at gmail.com Tue Mar 22 19:28:20 2011 From: adam.sroka at gmail.com (Adam Sroka) Date: Tue, 22 Mar 2011 16:28:20 -0700 Subject: [rspec-users] Is it possible to run rspec continuously? In-Reply-To: References: Message-ID: Check out this book: http://www.pragprog.com/titles/rcctr/continuous-testing-with-ruby It is about to be published and is available as a beta PDF. They cover several tools and both why and how to use them. On Mar 22, 2011 2:57 PM, "Benyi Wang" wrote: > When I run rspec in Rails, it seems that a ruby process is created and > loaded with rails components due to the statement require 'spec_helper'. > This usually takes a while to run even a single spec. Does a tool for rspec > like rails console exist so that you can run specs continuously without > loading everything each time? > > autotest actually starts a new process each time when there is a change, and > I can still feel the obvious delay. > > Any idea? > > Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Mar 22 21:50:36 2011 From: lists at ruby-forum.com (Radhesh Kamath) Date: Wed, 23 Mar 2011 02:50:36 +0100 Subject: [rspec-users] Testing routes with a prefix Message-ID: <56848fc4cd4589ba63b2e93883a82dad@ruby-forum.com> Hi experts, I am trying to test routing in my application, where all routes are enclosed in a namespace like so: scope 'v1' do resource :blah end collection do something end end end Is there a clean way to set 'v1' somewhere and just write my routing tests like so: describe 'routing for blah' do it 'should invoke show when it receives /xyz' do { :get => '/blah/xyz'}.should route_to(...) end end i.e., I do not want to say { :get => 'v1/blah/xyz'}.should route_to(...) Thanks, Radhesh -- Posted via http://www.ruby-forum.com/. From akleak at gmail.com Sun Mar 20 22:22:19 2011 From: akleak at gmail.com (andyl) Date: Sun, 20 Mar 2011 19:22:19 -0700 (PDT) Subject: [rspec-users] Stubs and Object Constructor Message-ID: <16776870.976.1300674139911.JavaMail.geo-discussion-forums@prfx21> I'm having trouble using stubs to intercept method calls in the object constructor. Here's some code with a failing example: class Test2 attr_accessor :msg def initialize @msg = sayhi end def sayhi "hi" end end describe Test2, "stubbing methods used during object construction" do it "should assign the stub value to the instance variable" do Test2.stub!(:sayhi).and_return("bye") Test2.new.msg.should == "bye" end end (full test-case at https://gist.github.com/878911) What should I do to make this work?!? Thanks, Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: From akleak at gmail.com Sun Mar 20 22:25:04 2011 From: akleak at gmail.com (andyl) Date: Sun, 20 Mar 2011 19:25:04 -0700 (PDT) Subject: [rspec-users] Stubs and Object Constructor In-Reply-To: <16776870.976.1300674139911.JavaMail.geo-discussion-forums@prfx21> Message-ID: <20101601.542.1300674304601.JavaMail.geo-discussion-forums@prfx36> PS: I'm using rspec/rspec-mocks 2.5, Ubuntu 10.10, Ruby 1.8.7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From akleak at gmail.com Mon Mar 21 00:38:20 2011 From: akleak at gmail.com (andyl) Date: Sun, 20 Mar 2011 21:38:20 -0700 (PDT) Subject: [rspec-users] Stubs and Object Constructor In-Reply-To: <20101601.542.1300674304601.JavaMail.geo-discussion-forums@prfx36> Message-ID: <10144642.11.1300682300354.JavaMail.geo-discussion-forums@prcm18> OK - I got this working using mocha and the 'any_instance' method. A gist with working examples is here: https://gist.github.com/879029 It looks like rspec mocks had an 'any_instance' method, but it was removed because it promoted 'bad practice'. I'm curious to understand how 'any_instance' promotes bad practice. I found it useful in my situation, to stub out slow network code that crushed my test performance. - Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: From bhellman1 at gmail.com Sat Mar 19 17:32:46 2011 From: bhellman1 at gmail.com (Mobyye) Date: Sat, 19 Mar 2011 14:32:46 -0700 (PDT) Subject: [rspec-users] RSPEC how to post to a controller? What's wrong with this? Message-ID: <663648.120.1300570366528.JavaMail.geo-discussion-forums@preo10> I'm trying to post to my controller in RSPEC by doing: it "should store create an IncomingMail record" do lambda { post :create, :from => 'xx', :to => 'xx', :cc => 'xx', :subject => 'xx', :message_text => 'xx', :message_html => 'xx' }.should change(IncomingMail, :count).by(1) end I do have this in my rake routes: POST /incoming_mails(.:format) {:controller=>"incoming_mails", :action=>"create"} I checked the logs. While the test above is hitting the controller, it is never going inside the method def create. Any ideas why? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnimety at gmail.com Sat Mar 19 20:35:26 2011 From: jnimety at gmail.com (jnimety) Date: Sat, 19 Mar 2011 17:35:26 -0700 (PDT) Subject: [rspec-users] Model validation failing in rspec for unknown reason In-Reply-To: <33d229e7b24d46b44de4ff60719f529c@ruby-forum.com> References: <5eb72198e716f44fecf484f4ecf2864e@ruby-forum.com> <15439656.426.1297191880337.JavaMail.geo-discussion-forums@yqeq15> <33d229e7b24d46b44de4ff60719f529c@ruby-forum.com> Message-ID: I just ran into this. I had added a bit of code to allow reload Factories in the rails console. This was causing the Factories to reload on every request, resetting my factory sequences, causing the validation errors. Hope this helps. On Feb 8, 3:17?pm, The Ultimation wrote: > Nick Hoffman wrote in post #980380: > > > On Tuesday, February 8, 2011 12:25:30 PM UTC-5, The Ultimation wrote: > > >> Hi, i'm getting the following error when running a spec on my controller > >> for my Equipment model. > > >> ? ? it "edit action should render edit template" do > >> ? ? ? get :edit, :id => Factory(:equipment) > > > Shouldn't you pass an ID to the "id" key, rather than a model instance? > > I've tried every method of passing the id in, still same error :/ > > -- > Posted viahttp://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jko170 at gmail.com Wed Mar 23 02:23:47 2011 From: jko170 at gmail.com (Justin Ko) Date: Tue, 22 Mar 2011 23:23:47 -0700 Subject: [rspec-users] RSPEC how to post to a controller? What's wrong with this? In-Reply-To: <663648.120.1300570366528.JavaMail.geo-discussion-forums@preo10> References: <663648.120.1300570366528.JavaMail.geo-discussion-forums@preo10> Message-ID: On Sat, Mar 19, 2011 at 2:32 PM, Mobyye wrote: > I'm trying to post to my controller in RSPEC by doing: > > it "should store create an IncomingMail record" do > > lambda { > post :create, > :from => 'xx', > :to => 'xx', > :cc => 'xx', > :subject => 'xx', > :message_text => 'xx', > :message_html => 'xx' > }.should change(IncomingMail, :count).by(1) > > end > > > I do have this in my rake routes: POST /incoming_mails(.:format) > {:controller=>"incoming_mails", :action=>"create"} > > I checked the logs. While the test above is hitting the controller, it is > never going inside the method def create. Any ideas why? > > Thanks > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > So you checked the log and you see a sql insert statement? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Wed Mar 23 03:04:27 2011 From: jko170 at gmail.com (Justin Ko) Date: Wed, 23 Mar 2011 00:04:27 -0700 Subject: [rspec-users] Testing routes with a prefix In-Reply-To: <56848fc4cd4589ba63b2e93883a82dad@ruby-forum.com> References: <56848fc4cd4589ba63b2e93883a82dad@ruby-forum.com> Message-ID: On Tue, Mar 22, 2011 at 6:50 PM, Radhesh Kamath wrote: > Hi experts, > > I am trying to test routing in my application, where all routes are > enclosed in a namespace like so: > > scope 'v1' do > resource :blah end > collection do > something > end > end > end > > Is there a clean way to set 'v1' somewhere and just write my routing > tests like so: > > describe 'routing for blah' do > it 'should invoke show when it receives /xyz' do > { :get => '/blah/xyz'}.should route_to(...) > end > end > > i.e., I do not want to say > { :get => 'v1/blah/xyz'}.should route_to(...) > > Thanks, > Radhesh > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You're mapping absolute strings (URL's) to your routes. Any string manipulation would dilute the spec. In my opinion, this is not a case of keeping things DRY. -------------- next part -------------- An HTML attachment was scrubbed... URL: From patmaddox at me.com Wed Mar 23 06:25:00 2011 From: patmaddox at me.com (Pat Maddox) Date: Wed, 23 Mar 2011 03:25:00 -0700 Subject: [rspec-users] Stubs and Object Constructor In-Reply-To: <10144642.11.1300682300354.JavaMail.geo-discussion-forums@prcm18> References: <10144642.11.1300682300354.JavaMail.geo-discussion-forums@prcm18> Message-ID: On Mar 20, 2011, at 9:38 PM, andyl wrote: > OK - I got this working using mocha and the 'any_instance' method. > > A gist with working examples is here: https://gist.github.com/879029 > > It looks like rspec mocks had an 'any_instance' method, but it was removed because it promoted 'bad practice'. > > I'm curious to understand how 'any_instance' promotes bad practice. I found it useful in my situation, to stub out slow network code that crushed my test performance. > > - Andy A class in Ruby is an object. When you call Test2.stub(:sayhi), you are defining a stub method on the object that is the Test2 class. This class object manufactures instances, whose methods are the instance methods defined by Test2. So basically you were defining the stub on a completely different object than you thought you were. To answer your question, any_instance was rejected for a long time because it does not align with the RSpec team's opinion of making dependencies explicit. That said, any_instance will make it into an upcoming release. Not because it's a good idea ;) but because so many people have clamored for it and frequently use mocha primarily for that feature. Pat From patmaddox at me.com Wed Mar 23 06:26:59 2011 From: patmaddox at me.com (Pat Maddox) Date: Wed, 23 Mar 2011 03:26:59 -0700 Subject: [rspec-users] Testing routes with a prefix In-Reply-To: <56848fc4cd4589ba63b2e93883a82dad@ruby-forum.com> References: <56848fc4cd4589ba63b2e93883a82dad@ruby-forum.com> Message-ID: On Mar 22, 2011, at 6:50 PM, Radhesh Kamath wrote: > Hi experts, > > I am trying to test routing in my application, where all routes are > enclosed in a namespace like so: > > scope 'v1' do > resource :blah end > collection do > something > end > end > end > > Is there a clean way to set 'v1' somewhere and just write my routing > tests like so: > > describe 'routing for blah' do > it 'should invoke show when it receives /xyz' do > { :get => '/blah/xyz'}.should route_to(...) > end > end > > i.e., I do not want to say > { :get => 'v1/blah/xyz'}.should route_to(...) I don't understand. The path '/blah/xyz' does not route to (...), so why would you write an example saying that it does? Pat From patmaddox at me.com Wed Mar 23 06:29:05 2011 From: patmaddox at me.com (Pat Maddox) Date: Wed, 23 Mar 2011 03:29:05 -0700 Subject: [rspec-users] RSPEC how to post to a controller? What's wrong with this? In-Reply-To: <663648.120.1300570366528.JavaMail.geo-discussion-forums@preo10> References: <663648.120.1300570366528.JavaMail.geo-discussion-forums@preo10> Message-ID: On Mar 19, 2011, at 2:32 PM, Mobyye wrote: > I'm trying to post to my controller in RSPEC by doing: > > it "should store create an IncomingMail record" do > > lambda { > post :create, > :from => 'xx', > :to => 'xx', > :cc => 'xx', > :subject => 'xx', > :message_text => 'xx', > :message_html => 'xx' > }.should change(IncomingMail, :count).by(1) > > end > > > I do have this in my rake routes: POST /incoming_mails(.:format) {:controller=>"incoming_mails", :action=>"create"} > > I checked the logs. While the test above is hitting the controller, it is never going inside the method def create. Any ideas why? > > Thanks Off the top of my head I can think of 198723 possibilities. To help expedite the narrowing down process, please provide: 1. Complete example code 2. Complete controller code 3. Complete rspec output 4. Complete log output Pat -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Mar 23 06:34:24 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Mar 2011 05:34:24 -0500 Subject: [rspec-users] Stubs and Object Constructor In-Reply-To: <10144642.11.1300682300354.JavaMail.geo-discussion-forums@prcm18> References: <10144642.11.1300682300354.JavaMail.geo-discussion-forums@prcm18> Message-ID: <8C40B74C-A620-49A6-93E2-F00EEDC09EF4@gmail.com> On Mar 20, 2011, at 11:38 PM, andyl wrote: > OK - I got this working using mocha and the 'any_instance' method. > > A gist with working examples is here: https://gist.github.com/879029 > > It looks like rspec mocks had an 'any_instance' method, but it was removed because it promoted 'bad practice'. It was never released, and was removed because the patch was incomplete in retrospect. There is an open issue on this right now, with a patch in progress that I hope to include in the next release, assuming it is ready when that release is ready to go. > I'm curious to understand how 'any_instance' promotes bad practice. I found it useful in my situation, to stub out slow network code that crushed my test performance. In general, we want test code to be as narrow and precise as possible. This means we should control which objects we are dealing with at any moment. any_instance is a bandaid for a situation in which the design makes it difficult to get a handle on a specific instance. If we're actually doing TDD this should never happen, but sometimes we use frameworks like ActiveRecord, which provides two different objects in this scenario: widget = Factory(:widget) found_widget = Widget.find(widget.id) These two objects ^^ have the same attributes, but are not the same object. This means that stubbing methods on widget does not have any impact on found_widget. In this case, any_instance saves the day, but it leaves open some holes in tests. Consider: order = Factory(:order) Order.any_instance.should_receive(:confirm) put :confirm, :order_id => order.id If the examples and code change over time such that there are more than one order at play and the wrong one receives confirm(), this example will still pass. FYI - ActiveRecord will soon have an identity map, which means that this code will work: order = Factory(:order) order.should_receive(:confirm) put :confirm, :order_id => order.id This is a much better situation as it is very precise. HTH, David From mguterl at gmail.com Wed Mar 23 09:03:59 2011 From: mguterl at gmail.com (Michael Guterl) Date: Wed, 23 Mar 2011 09:03:59 -0400 Subject: [rspec-users] current example Message-ID: Is it possible to retrieve the example that is currently running? From dchelimsky at gmail.com Wed Mar 23 09:56:15 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Mar 2011 08:56:15 -0500 Subject: [rspec-users] current example In-Reply-To: References: Message-ID: <25AFE17C-F25B-44CB-A10A-C9241406987B@gmail.com> On Mar 23, 2011, at 8:03 AM, Michael Guterl wrote: > Is it possible to retrieve the example that is currently running? describe "an example" do it "knows itself as example" do example.description.should eq("knows itself as example") end end From micah at 8thlight.com Wed Mar 23 09:59:37 2011 From: micah at 8thlight.com (Micah Martin) Date: Wed, 23 Mar 2011 08:59:37 -0500 Subject: [rspec-users] rspec-users Digest, Vol 57, Issue 22 In-Reply-To: References: Message-ID: <1EB3BE1B-395F-4222-971E-626748B2EE80@8thlight.com> On Mar 23, 2011, at 12:22 AM, rspec-users-request at rubyforge.org wrote: > Send rspec-users mailing list submissions to > rspec-users at rubyforge.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://rubyforge.org/mailman/listinfo/rspec-users > or, via email, send a message with subject or body 'help' to > rspec-users-request at rubyforge.org > > You can reach the person managing the list at > rspec-users-owner at rubyforge.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of rspec-users digest..." > > > Today's Topics: > > 1. How to test a Rails 3 metal controller? (Thibaut Barr?re) > 2. Re: How to test a Rails 3 metal controller? (David Chelimsky) > 3. Is it possible to run rspec continuously? (Benyi Wang) > 4. Re: Is it possible to run rspec continuously? (Katrina Owen) > 5. Re: Is it possible to run rspec continuously? (Justin Ko) > 6. Re: Is it possible to run rspec continuously? (Adam Sroka) > 7. Testing routes with a prefix (Radhesh Kamath) > 8. Stubs and Object Constructor (andyl) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 22 Mar 2011 05:50:57 -0700 (PDT) > From: Thibaut Barr?re > To: rspec-users at rubyforge.org > Subject: [rspec-users] How to test a Rails 3 metal controller? > Message-ID: > <044ce36f-f765-48a0-a145-f539e01ea2ec at j35g2000prb.googlegroups.com> > Content-Type: text/plain; charset=ISO-8859-1 > > Hi! > > I could not find an easy solution to this question: how can I properly > test an Rails controller action? > > We were trying to run the following test: > > get :show, :id => 'hello' > response.should redirect_to("http://www.google.com") > > But we got: > > undefined method `formats=' for # > > After reading a couple of blog posts, we tried this work-around: > > class LinksController > include ActionController::UrlFor > include ActionController::Testing > include Rails.application.routes.url_helpers > include AbstractController::ViewPaths > end > > It works only partially, we're now stuck with the limits of our monkey- > patching and get the following error: > > undefined method `protected_instance_variables' for > LinksController:Class > > Well - is there a clean way to test our a Rails metal with RSpec? > > Thanks for your support! > > -- Thibaut > > > ------------------------------ > > Message: 2 > Date: Tue, 22 Mar 2011 08:36:49 -0500 > From: David Chelimsky > To: rspec-users > Subject: Re: [rspec-users] How to test a Rails 3 metal controller? > Message-ID: > Content-Type: text/plain; charset=utf-8 > > On Mar 22, 2011, at 7:50 AM, Thibaut Barr?re wrote: > >> Hi! >> >> I could not find an easy solution to this question: how can I properly >> test an Rails controller action? >> >> We were trying to run the following test: >> >> get :show, :id => 'hello' >> response.should redirect_to("http://www.google.com") >> >> But we got: >> >> undefined method `formats=' for # >> >> After reading a couple of blog posts, we tried this work-around: >> >> class LinksController >> include ActionController::UrlFor >> include ActionController::Testing >> include Rails.application.routes.url_helpers >> include AbstractController::ViewPaths >> end >> >> It works only partially, we're now stuck with the limits of our monkey- >> patching and get the following error: >> >> undefined method `protected_instance_variables' for >> LinksController:Class >> >> Well - is there a clean way to test our a Rails metal with RSpec? > > Use a request spec (in spec/requests) instead of a controller spec. >> >> Thanks for your support! >> >> -- Thibaut >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > ------------------------------ > > Message: 3 > Date: Tue, 22 Mar 2011 14:37:42 -0700 > From: Benyi Wang > To: rspec-users at rubyforge.org > Subject: [rspec-users] Is it possible to run rspec continuously? > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > When I run rspec in Rails, it seems that a ruby process is created and > loaded with rails components due to the statement require 'spec_helper'. > This usually takes a while to run even a single spec. Does a tool for rspec > like rails console exist so that you can run specs continuously without > loading everything each time? > > autotest actually starts a new process each time when there is a change, and > I can still feel the obvious delay. > > Any idea? > > Thanks. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > Message: 4 > Date: Tue, 22 Mar 2011 22:59:49 +0100 > From: Katrina Owen > To: rspec-users > Subject: Re: [rspec-users] Is it possible to run rspec continuously? > Message-ID: > > Content-Type: text/plain; charset=UTF-8 > > Hi there, > > Check out Spork. Spork will fire up a distributed ruby process that > your tests can run in. > > You'll need to restart spork any time environment files change (check > out guard for this, though), but that's minor considering the increase > in speed that you can see. > > Katrina > > On Tue, Mar 22, 2011 at 10:37 PM, Benyi Wang wrote: >> When I run rspec in Rails, it seems that a ruby process is created and >> loaded with rails components due to the statement require 'spec_helper'. >> This usually takes a while to run even a single spec. Does a tool for rspec >> like rails console exist so that you can run specs continuously without >> loading everything each time? >> autotest actually starts a new process each time when there is a change, and >> I can still feel the obvious delay. >> Any idea? >> Thanks. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > ------------------------------ > > Message: 5 > Date: Tue, 22 Mar 2011 15:02:37 -0700 > From: Justin Ko > To: rspec-users > Subject: Re: [rspec-users] Is it possible to run rspec continuously? > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > On Tue, Mar 22, 2011 at 2:37 PM, Benyi Wang wrote: > >> When I run rspec in Rails, it seems that a ruby process is created and >> loaded with rails components due to the statement require 'spec_helper'. >> This usually takes a while to run even a single spec. Does a tool for rspec >> like rails console exist so that you can run specs continuously without >> loading everything each time? >> >> autotest actually starts a new process each time when there is a change, >> and I can still feel the obvious delay. >> >> Any idea? >> >> Thanks. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > Take a look at Spork: > > http://chrismdp.github.com/2010/11/getting-spork-working-now-on-rails-3-rspec-2-and-cucumber/ > https://github.com/timcharper/spork > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > Message: 6 > Date: Tue, 22 Mar 2011 16:28:20 -0700 > From: Adam Sroka > To: rspec-users > Subject: Re: [rspec-users] Is it possible to run rspec continuously? > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > Check out this book: > http://www.pragprog.com/titles/rcctr/continuous-testing-with-ruby > > It is about to be published and is available as a beta PDF. They cover > several tools and both why and how to use them. > On Mar 22, 2011 2:57 PM, "Benyi Wang" wrote: >> When I run rspec in Rails, it seems that a ruby process is created and >> loaded with rails components due to the statement require 'spec_helper'. >> This usually takes a while to run even a single spec. Does a tool for > rspec >> like rails console exist so that you can run specs continuously without >> loading everything each time? >> >> autotest actually starts a new process each time when there is a change, > and >> I can still feel the obvious delay. >> >> Any idea? >> >> Thanks. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > Message: 7 > Date: Wed, 23 Mar 2011 02:50:36 +0100 > From: Radhesh Kamath > To: rspec-users at rubyforge.org > Subject: [rspec-users] Testing routes with a prefix > Message-ID: <56848fc4cd4589ba63b2e93883a82dad at ruby-forum.com> > Content-Type: text/plain; charset=UTF-8 > > Hi experts, > > I am trying to test routing in my application, where all routes are > enclosed in a namespace like so: > > scope 'v1' do > resource :blah end > collection do > something > end > end > end > > Is there a clean way to set 'v1' somewhere and just write my routing > tests like so: > > describe 'routing for blah' do > it 'should invoke show when it receives /xyz' do > { :get => '/blah/xyz'}.should route_to(...) > end > end > > i.e., I do not want to say > { :get => 'v1/blah/xyz'}.should route_to(...) > > Thanks, > Radhesh > > -- > Posted via http://www.ruby-forum.com/. > > > ------------------------------ > > Message: 8 > Date: Sun, 20 Mar 2011 19:22:19 -0700 (PDT) > From: andyl > To: rspec at googlegroups.com > Subject: [rspec-users] Stubs and Object Constructor > Message-ID: > <16776870.976.1300674139911.JavaMail.geo-discussion-forums at prfx21> > Content-Type: text/plain; charset="utf-8" > > I'm having trouble using stubs to intercept method calls in the object > constructor. Here's some code with a failing example: > > class Test2 > attr_accessor :msg > def initialize > @msg = sayhi > end > def sayhi > "hi" > end > end > > describe Test2, "stubbing methods used during object construction" do > it "should assign the stub value to the instance variable" do > Test2.stub!(:sayhi).and_return("bye") > Test2.new.msg.should == "bye" > end > end > > (full test-case at https://gist.github.com/878911) > > What should I do to make this work?!? > > Thanks, Andy > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > End of rspec-users Digest, Vol 57, Issue 22 > ******************************************* From joevandyk at gmail.com Wed Mar 23 11:00:25 2011 From: joevandyk at gmail.com (Joe Van Dyk) Date: Wed, 23 Mar 2011 08:00:25 -0700 Subject: [rspec-users] RSPEC how to post to a controller? What's wrong with this? In-Reply-To: <663648.120.1300570366528.JavaMail.geo-discussion-forums@preo10> References: <663648.120.1300570366528.JavaMail.geo-discussion-forums@preo10> Message-ID: <4671467764090633235@unknownmsgid> Before_filters preventing it? On Mar 22, 2011, at 11:06 PM, Mobyye wrote: I'm trying to post to my controller in RSPEC by doing: it "should store create an IncomingMail record" do lambda { post :create, :from => 'xx', :to => 'xx', :cc => 'xx', :subject => 'xx', :message_text => 'xx', :message_html => 'xx' }.should change(IncomingMail, :count).by(1) end I do have this in my rake routes: POST /incoming_mails(.:format) {:controller=>"incoming_mails", :action=>"create"} I checked the logs. While the test above is hitting the controller, it is never going inside the method def create. Any ideas why? 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 lists at ruby-forum.com Wed Mar 23 13:16:53 2011 From: lists at ruby-forum.com (Radhesh Kamath) Date: Wed, 23 Mar 2011 18:16:53 +0100 Subject: [rspec-users] Testing routes with a prefix In-Reply-To: References: <56848fc4cd4589ba63b2e93883a82dad@ruby-forum.com> Message-ID: Justin Ko wrote in post #988825: > On Tue, Mar 22, 2011 at 6:50 PM, Radhesh Kamath > wrote: > >> end >> >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > You're mapping absolute strings (URL's) to your routes. Any string > manipulation would dilute the spec. In my opinion, this is not a case of > keeping things DRY. It's clear that you have understood my intent: keep things DRY by specifying the prefix once, and write tests as though the prefix is implicitly specified. But what do you mean by 'dilute the spec'? Do you think it might make the spec brittle? Pat: I just want to keep things DRY by specifying the 'v1' prefix once, so the example would be 'v1/...', only 'v1' would be implicitly set in some way. Best, Radhesh -- Posted via http://www.ruby-forum.com/. From jko170 at gmail.com Wed Mar 23 13:43:34 2011 From: jko170 at gmail.com (Justin Ko) Date: Wed, 23 Mar 2011 10:43:34 -0700 Subject: [rspec-users] Testing routes with a prefix In-Reply-To: References: <56848fc4cd4589ba63b2e93883a82dad@ruby-forum.com> Message-ID: On Wed, Mar 23, 2011 at 10:16 AM, Radhesh Kamath wrote: > Justin Ko wrote in post #988825: > > On Tue, Mar 22, 2011 at 6:50 PM, Radhesh Kamath > > wrote: > > > >> end > >> > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > > > You're mapping absolute strings (URL's) to your routes. Any string > > manipulation would dilute the spec. In my opinion, this is not a case of > > keeping things DRY. > > It's clear that you have understood my intent: keep things DRY by > specifying the prefix once, and write tests as though the prefix is > implicitly specified. > > But what do you mean by 'dilute the spec'? > Do you think it might make the spec brittle? > Routes are basically constants. By breaking this constant up (the string) in your spec, the value drops (because of clarity), in my opinion. > > Pat: > > I just want to keep things DRY by specifying the 'v1' prefix once, so > the example would be 'v1/...', only 'v1' would be implicitly set in some > way. > > Best, > Radhesh > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Mar 23 14:12:30 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Mar 2011 13:12:30 -0500 Subject: [rspec-users] Testing routes with a prefix In-Reply-To: References: <56848fc4cd4589ba63b2e93883a82dad@ruby-forum.com> Message-ID: On Wed, Mar 23, 2011 at 12:16 PM, Radhesh Kamath wrote: > Justin Ko wrote in post #988825: >> On Tue, Mar 22, 2011 at 6:50 PM, Radhesh Kamath >> wrote: >> >>> ?end >>> >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> You're mapping absolute strings (URL's) to your routes. Any string >> manipulation would dilute the spec. In my opinion, this is not a case of >> keeping things DRY. > > It's clear that you have understood my intent: keep things DRY by > specifying the prefix once, and write tests as though the prefix is > implicitly specified. > > But what do you mean by 'dilute the spec'? It makes it hard to read. You have a new concept to understand: all the routes being specified are not the routes being specified. > Do you think it might make the spec brittle? > > Pat: > > I just want to keep things DRY by specifying the 'v1' prefix once, so > the example would be 'v1/...', only 'v1' would be implicitly set in some > way. What you propose would introduce an abstraction that will make it harder to understand failures in order to save a few duplicate keystrokes. This is _not_ what DRY is about. See http://www.artima.com/intv/dry.html for some background on that. Cheers, David From srshti at gmail.com Wed Mar 23 14:41:01 2011 From: srshti at gmail.com (Srushti) Date: Thu, 24 Mar 2011 00:11:01 +0530 Subject: [rspec-users] Post call verification Message-ID: If anyone is interested, I wrote a quick little gem to add spies to rspec-mocks. Basically, it adds a method called spy which internally returns a mock.as_null_object, and a matcher for "have_received(:method)" & "have_received(:method).with(args)". David, my understanding of your point (or at least, part of it) is that you'd rather use mocks since they fail on the method calls that have never been set up. The way I see it, if I want something to fail I'd rather make it explicit. I'd rather explicitly state that "object.should_not have_received(:wrong_method)" so that the test is perfectly clear, than want to use a standard mock which would fail . This is the same reason I imagine we have "lambda {a_call}.should_not raise_error". We don't really need that since the test fails because of an exception nonetheless. Of course, mocks would also work as a general check against calls to other methods. The last time I used something like this (when using RhinoMocks working on a .net project) if you had to have a return (that your production code would use) you would set up the expectation before hand with a :should_receive. You would only use the :have_received matcher on calls that you didn't need to set an expectation on. Even though this might be seem to be a little consistent, with a little of this and a little of that, it worked out quite well on us, with the added benefit of not needing stubs on methods where the return value doesn't matter and you saving a little bit of noise in your tests. Nonetheless, here's the gem: http://rubygems.org/gems/stirlitz Thanks, Srushti On 22 March 2011 17:22, wrote: > > Date: Tue, 22 Mar 2011 06:52:02 -0500 > From: David Chelimsky > To: rspec-users > Subject: Re: [rspec-users] Post call verification > Message-ID: <3237C672-2BB7-446C-9AE5-E25447CE25C8 at gmail.com> > Content-Type: text/plain; charset="us-ascii" > > On Mar 22, 2011, at 4:13 AM, Tom Stuart wrote: > > > On 19 Mar 2011, at 13:35, David Chelimsky wrote: > > > >> On Mar 18, 2011, at 10:37 AM, Srushti Ambekallu wrote: > >> > >>> Hey all, > >>> > >>> I would like to be able to be able to have mocks where I can make all > the calls and assert that it was called afterwards. This would be especially > useful when asserting on a doing-method whose return value is not being > considered. > >>> e.g. > >>> service = mock(ExternalService) > >>> ExternalService.stub!(:new).and_return(service) > >>> user = User.new > >>> user.activate > >>> service.should_have_received(:publish_user_activation).with(user) > >>> Now this obviously can't replace all assertions done with > should_receive, but I know there are at least a few cases where this would > come in handy and be more readable. I know while writing tests, I usually > write the actual call (in this case the 'post') and then go up a couple of > lines to write the should_receive. I think it would be more natural to > verify it after the fact rather than before. I seem to remember there was > another mocking library which did something quite close to this, but I > just can't seem to find it just now. What does everyone think? I could try > and implement this myself, but just wanted to see if there was any interest, > or any one had a good reason not to include this. > >> > >> This pattern is called a test spy, and there has been much discussion of > it on this list: > >> > >> > http://groups.google.com/group/rspec/search?group=rspec&q=test+spies&qt_g=Search+this+group > >> > >> The biggest issue for me is that message expectations often get set with > a stub return value: > >> > >> foo.should_receive(:bar).and_return(:baz) > >> foo(:bar) > >> > >> In a world of test spies, this would be: > >> > >> foo.stub(:bar).and_return(:baz) > >> foo(:bar) > >> foo.should_have_received(:bar).with(:bam) > >> > >> This requires more code in the example, and creates an otherwise > unnecessary binding between the stub and the expectation. Also, note that > the stub doesn't constrain the argument to bar(), but should_have_received() > does (in this example). If we were to do that the other way: > >> > >> foo.stub(:bar).with(:baz).and_return(:bam) > >> bar(:something_other_than_baz) > >> foo.should_have_received(:bar) > >> > >> ... should this pass or fail? As rspec-mocks works today, it could only > pass if we had an additional stub at the beginning. > >> > >> foo.stub(:bar) > >> foo.stub(:bar).with(:baz).and_return(:bam) > >> bar(:something_other_than_baz) > >> foo.should_have_received(:bar) > >> > >> ... because calling bar(:anything_other_than_baz) would not work due to > the with() constraint. > >> > >> If we agree it should fail, then that's pretty confusing as well, since > foo did actually receive bar() and the only way to understand to failure is > to look back at the stub with the with() constraint. > >> > >> I could go on but I think this makes the point. We don't have test spies > in RSpec yet because a) I don't personally find them valuable and b) they > introduce more problems than they solve. > >> > >> That said, if anyone cares to write an external library to support this, > I'd gladly work with you to make sure RSpec provides you the extension > points you need. > >> > >> Cheers, > >> David > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > This is a long-running discussion and I suspect it comes down to personal > preference in the end more than anything else. However, I have done some > work to get a basic test spy library working with rspec which tries to avoid > unnecessary stubbing to allow assertion on method calls (i.e. you only need > to set up a stub as well when you need to manipulate the return value). It's > in its infant stages and needs some TLC (in particular, its factory method > 'spy' is in the global namespace, when it could and should be dealt with > more elegantly), but it may be of some use for test spy fanatics... > https://github.com/mortice/matahari > > Thanks, Tom. Let me know if there is anything you need in RSpec to make it > easy to plug this in. > > Cheers, > David > > ******************************************* > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Mar 23 14:59:39 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Mar 2011 13:59:39 -0500 Subject: [rspec-users] Post call verification In-Reply-To: References: Message-ID: <3B85B2AC-3D5C-4E78-9C53-DFDCA7D9752F@gmail.com> [moved your post to the bottom for consistency with this thread] On Mar 23, 2011, at 1:41 PM, Srushti wrote: > On 22 March 2011 17:22, wrote: > > Date: Tue, 22 Mar 2011 06:52:02 -0500 > From: David Chelimsky > To: rspec-users > Subject: Re: [rspec-users] Post call verification > Message-ID: <3237C672-2BB7-446C-9AE5-E25447CE25C8 at gmail.com> > Content-Type: text/plain; charset="us-ascii" > > On Mar 22, 2011, at 4:13 AM, Tom Stuart wrote: > > > On 19 Mar 2011, at 13:35, David Chelimsky wrote: > > > >> On Mar 18, 2011, at 10:37 AM, Srushti Ambekallu wrote: > >> > >>> Hey all, > >>> > >>> I would like to be able to be able to have mocks where I can make all the calls and assert that it was called afterwards. This would be especially useful when asserting on a doing-method whose return value is not being considered. > >>> e.g. > >>> service = mock(ExternalService) > >>> ExternalService.stub!(:new).and_return(service) > >>> user = User.new > >>> user.activate > >>> service.should_have_received(:publish_user_activation).with(user) > >>> Now this obviously can't replace all assertions done with should_receive, but I know there are at least a few cases where this would come in handy and be more readable. I know while writing tests, I usually write the actual call (in this case the 'post') and then go up a couple of lines to write the should_receive. I think it would be more natural to verify it after the fact rather than before. I seem to remember there was another mocking library which did something quite close to this, but I just can't seem to find it just now. What does everyone think? I could try and implement this myself, but just wanted to see if there was any interest, or any one had a good reason not to include this. > >> > >> This pattern is called a test spy, and there has been much discussion of it on this list: > >> > >> http://groups.google.com/group/rspec/search?group=rspec&q=test+spies&qt_g=Search+this+group > >> > >> The biggest issue for me is that message expectations often get set with a stub return value: > >> > >> foo.should_receive(:bar).and_return(:baz) > >> foo(:bar) > >> > >> In a world of test spies, this would be: > >> > >> foo.stub(:bar).and_return(:baz) > >> foo(:bar) > >> foo.should_have_received(:bar).with(:bam) > >> > >> This requires more code in the example, and creates an otherwise unnecessary binding between the stub and the expectation. Also, note that the stub doesn't constrain the argument to bar(), but should_have_received() does (in this example). If we were to do that the other way: > >> > >> foo.stub(:bar).with(:baz).and_return(:bam) > >> bar(:something_other_than_baz) > >> foo.should_have_received(:bar) > >> > >> ... should this pass or fail? As rspec-mocks works today, it could only pass if we had an additional stub at the beginning. > >> > >> foo.stub(:bar) > >> foo.stub(:bar).with(:baz).and_return(:bam) > >> bar(:something_other_than_baz) > >> foo.should_have_received(:bar) > >> > >> ... because calling bar(:anything_other_than_baz) would not work due to the with() constraint. > >> > >> If we agree it should fail, then that's pretty confusing as well, since foo did actually receive bar() and the only way to understand to failure is to look back at the stub with the with() constraint. > >> > >> I could go on but I think this makes the point. We don't have test spies in RSpec yet because a) I don't personally find them valuable and b) they introduce more problems than they solve. > >> > >> That said, if anyone cares to write an external library to support this, I'd gladly work with you to make sure RSpec provides you the extension points you need. > >> > >> Cheers, > >> David > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > This is a long-running discussion and I suspect it comes down to personal preference in the end more than anything else. However, I have done some work to get a basic test spy library working with rspec which tries to avoid unnecessary stubbing to allow assertion on method calls (i.e. you only need to set up a stub as well when you need to manipulate the return value). It's in its infant stages and needs some TLC (in particular, its factory method 'spy' is in the global namespace, when it could and should be dealt with more elegantly), but it may be of some use for test spy fanatics... https://github.com/mortice/matahari > > Thanks, Tom. Let me know if there is anything you need in RSpec to make it easy to plug this in. > > If anyone is interested, I wrote a quick little gem to add spies to rspec-mocks. Basically, it adds a method called spy which internally returns a mock.as_null_object, and a matcher for "have_received(:method)" & "have_received(:method).with(args)". > David, my understanding of your point (or at least, part of it) is that you'd rather use mocks since they fail on the method calls that have never been set up. That's not what I said. Please re-read my examples above - they are about the cases where a stubbed return value matters for the code to run, which happens much more often than it would if we all followed Tell, Don't Ask (but we don't so much). > The way I see it, if I want something to fail I'd rather make it explicit. I'd rather explicitly state that "object.should_not have_received(:wrong_method)" so that the test is perfectly clear, than want to use a standard mock which would fail . This is the same reason I imagine we have "lambda {a_call}.should_not raise_error". We don't really need that since the test fails because of an exception nonetheless. Of course, mocks would also work as a general check against calls to other methods. > The last time I used something like this (when using RhinoMocks working on a .net project) if you had to have a return (that your production code would use) you would set up the expectation before hand with a :should_receive. You would only use the :have_received matcher on calls that you didn't need to set an expectation on. Even though this might be seem to be a little consistent, with a little of this and a little of that, it worked out quite well on us, with the added benefit of not needing stubs on methods where the return value doesn't matter and you saving a little bit of noise in your tests. > Nonetheless, here's the gem: http://rubygems.org/gems/stirlitz > Thanks, > Srushti > -------------- next part -------------- An HTML attachment was scrubbed... URL: From srushti at ambekallu.com Wed Mar 23 15:54:47 2011 From: srushti at ambekallu.com (Srushti Ambekallu) Date: Thu, 24 Mar 2011 01:24:47 +0530 Subject: [rspec-users] Post call verification In-Reply-To: <3B85B2AC-3D5C-4E78-9C53-DFDCA7D9752F@gmail.com> References: <3B85B2AC-3D5C-4E78-9C53-DFDCA7D9752F@gmail.com> Message-ID: <4D8A5007.4010802@gmail.com> On 24/03/11 12:29 AM, David Chelimsky wrote: > [moved your post to the bottom for consistency with this thread] > > On Mar 23, 2011, at 1:41 PM, Srushti wrote: > >> On 22 March 2011 17:22, > > wrote: >> >> >> Date: Tue, 22 Mar 2011 06:52:02 -0500 >> From: David Chelimsky > > >> To: rspec-users > > >> Subject: Re: [rspec-users] Post call verification >> Message-ID: <3237C672-2BB7-446C-9AE5-E25447CE25C8 at gmail.com >> > >> Content-Type: text/plain; charset="us-ascii" >> >> On Mar 22, 2011, at 4:13 AM, Tom Stuart wrote: >> >> > On 19 Mar 2011, at 13:35, David Chelimsky wrote: >> > >> >> On Mar 18, 2011, at 10:37 AM, Srushti Ambekallu wrote: >> >> >> >>> Hey all, >> >>> >> >>> I would like to be able to be able to have mocks where I can >> make all the calls and assert that it was called afterwards. This >> would be especially useful when asserting on a doing-method whose >> return value is not being considered. >> >>> e.g. >> >>> service = mock(ExternalService) >> >>> ExternalService.stub!(:new).and_return(service) >> >>> user = User.new >> >>> user.activate >> >>> service.should_have_received(:publish_user_activation).with(user) >> >>> Now this obviously can't replace all assertions done with >> should_receive, but I know there are at least a few cases where >> this would come in handy and be more readable. I know while >> writing tests, I usually write the actual call (in this case the >> 'post') and then go up a couple of lines to write the >> should_receive. I think it would be more natural to verify it >> after the fact rather than before. I seem to remember there was >> another mocking library which did something quite close to >> this, but I just can't seem to find it just now. What does >> everyone think? I could try and implement this myself, but just >> wanted to see if there was any interest, or any one had a good >> reason not to include this. >> >> >> >> This pattern is called a test spy, and there has been much >> discussion of it on this list: >> >> >> >> >> http://groups.google.com/group/rspec/search?group=rspec&q=test+spies&qt_g=Search+this+group >> >> >> >> >> The biggest issue for me is that message expectations often >> get set with a stub return value: >> >> >> >> foo.should_receive(:bar).and_return(:baz) >> >> foo(:bar) >> >> >> >> In a world of test spies, this would be: >> >> >> >> foo.stub(:bar).and_return(:baz) >> >> foo(:bar) >> >> foo.should_have_received(:bar).with(:bam) >> >> >> >> This requires more code in the example, and creates an >> otherwise unnecessary binding between the stub and the >> expectation. Also, note that the stub doesn't constrain the >> argument to bar(), but should_have_received() does (in this >> example). If we were to do that the other way: >> >> >> >> foo.stub(:bar).with(:baz).and_return(:bam) >> >> bar(:something_other_than_baz) >> >> foo.should_have_received(:bar) >> >> >> >> ... should this pass or fail? As rspec-mocks works today, it >> could only pass if we had an additional stub at the beginning. >> >> >> >> foo.stub(:bar) >> >> foo.stub(:bar).with(:baz).and_return(:bam) >> >> bar(:something_other_than_baz) >> >> foo.should_have_received(:bar) >> >> >> >> ... because calling bar(:anything_other_than_baz) would not >> work due to the with() constraint. >> >> >> >> If we agree it should fail, then that's pretty confusing as >> well, since foo did actually receive bar() and the only way to >> understand to failure is to look back at the stub with the with() >> constraint. >> >> >> >> I could go on but I think this makes the point. We don't have >> test spies in RSpec yet because a) I don't personally find them >> valuable and b) they introduce more problems than they solve. >> >> >> >> That said, if anyone cares to write an external library to >> support this, I'd gladly work with you to make sure RSpec >> provides you the extension points you need. >> >> >> >> Cheers, >> >> David >> >> _______________________________________________ >> >> rspec-users mailing list >> >> rspec-users at rubyforge.org >> >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >> > This is a long-running discussion and I suspect it comes down >> to personal preference in the end more than anything else. >> However, I have done some work to get a basic test spy library >> working with rspec which tries to avoid unnecessary stubbing to >> allow assertion on method calls (i.e. you only need to set up a >> stub as well when you need to manipulate the return value). It's >> in its infant stages and needs some TLC (in particular, its >> factory method 'spy' is in the global namespace, when it could >> and should be dealt with more elegantly), but it may be of some >> use for test spy fanatics... https://github.com/mortice/matahari >> >> Thanks, Tom. Let me know if there is anything you need in RSpec >> to make it easy to plug this in. >> > > >> If anyone is interested, I wrote a quick little gem to add spies to >> rspec-mocks. Basically, it adds a method called spy which internally >> returns a mock.as_null_object, and a matcher for >> "have_received(:method)" & "have_received(:method).with(args)". >> David, my understanding of your point (or at least, part of it) is >> that you'd rather use mocks since they fail on the method calls that >> have never been set up. > > That's not what I said. Please re-read my examples above - they are > about the cases where a stubbed return value matters for the code to > run, which happens much more often than it would if we all followed > Tell, Don't Ask (but we don't so much). > >> The way I see it, if I want something to fail I'd rather make it >> explicit. I'd rather explicitly state that "object.should_not >> have_received(:wrong_method)" so that the test is perfectly clear, >> than want to use a standard mock which would fail . This is the same >> reason I imagine we have "lambda {a_call}.should_not raise_error". We >> don't really need that since the test fails because of an exception >> nonetheless. Of course, mocks would also work as a general check >> against calls to other methods. >> The last time I used something like this (when using RhinoMocks >> working on a .net project) if you had to have a return (that your >> production code would use) you would set up the expectation before >> hand with a :should_receive. You would only use the :have_received >> matcher on calls that you didn't need to set an expectation on. Even >> though this might be seem to be a little consistent, with a little of >> this and a little of that, it worked out quite well on us, with the >> added benefit of not needing stubs on methods where the return value >> doesn't matter and you saving a little bit of noise in your tests. >> Nonetheless, here's the gem: http://rubygems.org/gems/stirlitz >> Thanks, >> Srushti >> > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I guess you're right, and I take back that point. I haven't used test spies in a while, so I might get back to you on this in a while (I'm going to start using it whenever I can now), but I guess it's a matter of how often you depend on a return value. Your experience seems to be, most of the time, or at least often enough that it doesn't make sense to add test spies. You're probably right, but I'll give it a go nonetheless. There have been at least a few times that I've wished I had access to test spies. These might have been rare occurrences and not enough to justify polluting the api with a different type of asserting on calls. On the other hand, I might have just gotten used to working with rspec-mocks over time to stop looking for those types of usages (which I used to see enough of when working in other languages & mocking frameworks). Regardless, I'll report back in a while fighting for inclusion again, or admitting everything's fine the way it is. Thanks, Srushti -------------- next part -------------- An HTML attachment was scrubbed... URL: From apeel3 at gmail.com Wed Mar 23 21:01:59 2011 From: apeel3 at gmail.com (Art Peel) Date: Wed, 23 Mar 2011 18:01:59 -0700 Subject: [rspec-users] problem running tests of helpers Message-ID: I'm in the process of upgrading from ruby 1.8.7 to ruby-1.9.2-p18 and from rails 2.3.8 to rails 2.3.9 and my tests of helpers have stopped working, for example script/spec spec/helpers/application_helper_spec.rb (Full sample shown below.) The output is below. The problem occurs in helper_example_group.rb when trying @controller.request = @request I have not been able to figure out why @controller is nil. A minimal rails project that reproduces the problem is available at https://github.com/whenceforth/Helper-Test-Fail-Project I'm using bundler. script/spec --version rspec 1.3.1 which ruby /Users/art/.rvm/rubies/ruby-1.9.2-p180/bin/ruby Thanks in advance for any pointers. Art # begin Gemfile source :rubygems gem 'mysql', '2.8.1' gem 'rails', '2.3.11' gem 'rspec', '1.3.1' gem 'rspec-rails', '1.3.3' gem 'test-unit', '1.2.3' # end Gemfile art-imac-3:Helper-Test-Fail-Project art$ script/spec --backtrace spec/helpers/application_helper_spec.rb F 1) NoMethodError in 'ApplicationHelper#app_echo should echo' undefined method `request=' for nil:NilClass /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/activesupport-2.3.11/lib/active_support/whiny_nil.rb:52:in `method_missing' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-rails-1.3.3/lib/spec/rails/example/helper_example_group.rb:113:in `block in ' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_methods.rb:74:in `instance_eval' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_methods.rb:74:in `block in eval_each_fail_fast' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_methods.rb:74:in `each' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_methods.rb:74:in `eval_each_fail_fast' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_group_hierarchy.rb:17:in `run_before_each' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_methods.rb:107:in `run_before_each' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_methods.rb:128:in `before_each_example' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_methods.rb:39:in `block in execute' /Users/art/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:44:in `timeout' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_methods.rb:37:in `execute' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb:219:in `block in run_examples' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb:217:in `each' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb:217:in `run_examples' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/example/example_group_methods.rb:103:in `run' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/runner/example_group_runner.rb:23:in `block in run' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/runner/example_group_runner.rb:22:in `each' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/runner/example_group_runner.rb:22:in `run' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/runner/options.rb:153:in `run_examples' /Users/art/.rvm/gems/ruby-1.9.2-p180 at loyal3/gems/rspec-1.3.1/lib/spec/runner/command_line.rb:9:in `run' script/spec:5:in `
' Finished in 0.02259 seconds 1 example, 1 failure -------------- next part -------------- An HTML attachment was scrubbed... URL: From akleak at gmail.com Wed Mar 23 23:44:21 2011 From: akleak at gmail.com (andyl) Date: Wed, 23 Mar 2011 20:44:21 -0700 (PDT) Subject: [rspec-users] Stubs and Object Constructor In-Reply-To: <8C40B74C-A620-49A6-93E2-F00EEDC09EF4@gmail.com> Message-ID: <23619265.327.1300938261592.JavaMail.geo-discussion-forums@preo10> Pat and David - Thanks for taking the time to explain this. Look forward to seeing any_instance in rspec/mocks. And I will try to use it as little as possible! ;-) - Andy -------------- next part -------------- An HTML attachment was scrubbed... URL: From thibaut.barrere at gmail.com Thu Mar 24 05:39:48 2011 From: thibaut.barrere at gmail.com (=?ISO-8859-1?Q?Thibaut_Barr=E8re?=) Date: Thu, 24 Mar 2011 10:39:48 +0100 Subject: [rspec-users] How to test a Rails 3 metal controller? In-Reply-To: References: <044ce36f-f765-48a0-a145-f539e01ea2ec@j35g2000prb.googlegroups.com> Message-ID: Hello David, > Use a request spec (in spec/requests) instead of a controller spec. Thanks, it worked perfectly! I only encountered a "stack level too deep" error, which was solved by upgrading rspec from 2.0.1 to 2.5.0, if it helps someone. Thanks again! -- Thibaut From mbklein at gmail.com Thu Mar 24 12:59:17 2011 From: mbklein at gmail.com (Michael B. Klein) Date: Thu, 24 Mar 2011 09:59:17 -0700 Subject: [rspec-users] [module announcement] Equivalency testing for XML In-Reply-To: References: Message-ID: Hello all, I recently released a gem that assists in testing XML nodes for equivalency, and thought it might be of interest to the RSpec community. It can normalize whitespace (or not), ignore element order (or not), compare namespaces based on URI (not prefix), and more. Plus -- and possibly best of all -- it has baked-in RSpec (1.2.4+, 2.x) integration via custom matchers. It's similar in aim to XmlUnit for Java[1], but with a far narrower scope. Documentation: http://rdoc.info/github/mbklein/equivalent-xml/master/frames Source: http://github.com/mbklein/equivalent-xml RubyGems: http://rubygems.org/gems/equivalent-xml Or, of course, simply gem install equivalent-xml I welcome any feedback, suggestions, patches, pull requests, additional test cases, etc. Thanks! Michael [1] http://xmlunit.sourceforge.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From amkirwan at gmail.com Thu Mar 24 13:22:30 2011 From: amkirwan at gmail.com (amkirwan) Date: Thu, 24 Mar 2011 10:22:30 -0700 (PDT) Subject: [rspec-users] stubbing mongoid::criteria in view code Message-ID: <8db7b069-042d-41c5-980c-dfdb5c319025@z3g2000prz.googlegroups.com> I'm try to stub the following in my view code but keep running into problems with unexpected messages. I've tried stubbing and mocking in many combinations but can't find away past this. Here is the code below I am trying to spec ... - if page.parent_id.nil? %td - else %td= Page.criteria.id(page.parent_id).first.title ... I receive this error Mock "MongoidCriteria_1004" received unexpected message :title with (no args) when I do the following Page.stub_chain(:criteria, :id).and_return(mock_model("MongoidCriteria", :first => mock_model("Page", :title => "foobar"))) I've tried every combination I can think of but can't figure out how to stub this. From jko170 at gmail.com Thu Mar 24 15:26:12 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 24 Mar 2011 12:26:12 -0700 Subject: [rspec-users] stubbing mongoid::criteria in view code In-Reply-To: <8db7b069-042d-41c5-980c-dfdb5c319025@z3g2000prz.googlegroups.com> References: <8db7b069-042d-41c5-980c-dfdb5c319025@z3g2000prz.googlegroups.com> Message-ID: On Thu, Mar 24, 2011 at 10:22 AM, amkirwan wrote: > I'm try to stub the following in my view code but keep running into > problems with unexpected messages. I've tried stubbing and mocking in > many combinations but can't find away past this. Here is the code > below I am trying to spec > > ... > - if page.parent_id.nil? > %td > - else > %td= Page.criteria.id(page.parent_id).first.title > ... > > I receive this error Mock "MongoidCriteria_1004" received unexpected > message :title with (no args) when I do the following > > Page.stub_chain(:criteria, :id).and_return(mock_model("MongoidCriteria", > :first > => mock_model("Page", :title => "foobar"))) > > I've tried every combination I can think of but can't figure out how > to stub this. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Try this: Page.stub_chain('criteria.id.first.title').and_return('the title') -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmymartin at gmail.com Fri Mar 25 00:58:50 2011 From: jimmymartin at gmail.com (James Martin) Date: Fri, 25 Mar 2011 15:58:50 +1100 Subject: [rspec-users] [module announcement] Equivalency testing for XML In-Reply-To: References: Message-ID: On Fri, Mar 25, 2011 at 3:59 AM, Michael B. Klein wrote: > Hello all, > > I recently released a gem that assists in testing XML nodes > for equivalency, and thought it might be of interest to the RSpec community. > It can normalize whitespace (or not), ignore element order (or not), compare > namespaces based on URI (not prefix), and more. Plus -- and possibly best of > all -- it has baked-in RSpec (1.2.4+, 2.x) integration via custom matchers. > > It's similar in aim to XmlUnit for Java[1], but with a far narrower scope. > > Documentation: > http://rdoc.info/github/mbklein/equivalent-xml/master/frames > Source: http://github.com/mbklein/equivalent-xml > RubyGems: http://rubygems.org/gems/equivalent-xml > > Or, of course, simply gem install equivalent-xml > > I welcome any feedback, suggestions, patches, pull requests, additional > test cases, etc. > > Thanks! > > Michael > > [1] http://xmlunit.sourceforge.net/ > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Nice! Shame it wasn't available a few months ago when I rolled my own! :-) Will take a look through the specs and my own version and if there's any gaps I'll send you a pull request. Cheers, James. -------------- next part -------------- An HTML attachment was scrubbed... URL: From amkirwan at gmail.com Fri Mar 25 11:18:28 2011 From: amkirwan at gmail.com (amkirwan) Date: Fri, 25 Mar 2011 08:18:28 -0700 (PDT) Subject: [rspec-users] stubbing mongoid::criteria in view code In-Reply-To: Message-ID: <4370921.222.1301066308303.JavaMail.geo-discussion-forums@yqdn5> no unfortunately that does not work either. I receive the error: undefined method `title' for # -------------- next part -------------- An HTML attachment was scrubbed... URL: From niku at niku.name Fri Mar 25 19:43:51 2011 From: niku at niku.name (niku -E:)) Date: Sat, 26 Mar 2011 08:43:51 +0900 Subject: [rspec-users] How do I use expect{}.to change().from().to() on Array? In-Reply-To: References: Message-ID: finally, I solved this code. require 'rspec' class Ary attr_reader :ary def initialize @count = 0 @ary = [] increment end def increment @ary << @count @count += 1 end end describe Ary, "#ary" do subject{ Ary.new } it "should increment the ary" do # expect { subject.increment }.to change(subject, :ary).from([0]).to([0,1]) # fail expect { subject.increment }.to change{ subject.ary.clone }.from([0]).to([0,1]) end it "should increment the ary by [1]" do expect { subject.increment }.to change{ subject.ary.clone }.by([1]) end end On Mon, Mar 21, 2011 at 10:54 AM, niku -E:) wrote: > Sorry. Test comment is incorrect. > This is intentional test. > > require 'rspec' > > class Ary > ?attr_reader :ary > ?def initialize > ? ?@count = 0 > ? ?@ary = [] > ? ?increment > ?end > ?def increment > ? ?@ary << @count > ? ?@count += 1 > ?end > end > > describe Ary, "#ary" do > ?subject{ Ary.new } > ?it "should increment the ary" do > ? ?# expect { subject.increment }.to change(subject, :ary).from([0]).to([0,1]) > ? ?subject.ary.should == [0] > ? ?subject.increment > ? ?subject.ary.should == [0,1] > ?end > end > > On Mon, Mar 21, 2011 at 10:41 AM, niku -E:) wrote: >> I understand that "expect{}.to change()" can't test "destructive method". >> So, I should write test like that. correct? >> >> require 'rspec' >> >> class Ary >> ?attr_reader :ary >> ?def initialize >> ? ?@count = 0 >> ? ?@ary = [] >> ? ?increment >> ?end >> ?def increment >> ? ?@ary << @count >> ? ?@count += 1 >> ?end >> end >> >> describe Ary, "#ary" do >> ?subject{ Ary.new } >> ?it "should increment the ary" do >> ? ?# expect { subject.increment }.to change(subject, :ary).from([]).to([0]) >> ? ?subject.ary.should == [0] >> ? ?subject.increment >> ? ?subject.ary.should == [0,1] >> ?end >> end >> >> On Wed, Mar 16, 2011 at 2:41 AM, Justin Ko wrote: >>> >>> >>> On Tue, Mar 15, 2011 at 10:08 AM, Justin Ko wrote: >>>> >>>> >>>> On Tue, Mar 15, 2011 at 8:57 AM, niku -E:) wrote: >>>>> >>>>> Hi. >>>>> >>>>> I'm using ruby1.9.2 and rspec2.5.1 >>>>> I want to use "expect{}.to change().from().to()" like this >>>>> >>>>> https://gist.github.com/870897 >>>>> >>>>> When Int class, it passed. >>>>> When Ary class, it failed. >>>>> >>>>> Why was Ary test failed and How do I pass this test? >>>>> >>>>> regards. >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> Your Ary @ary variable is initialized as "[]". So of course calling >>>> increment on it will change it to "[0]". For your spec to pass, initialize >>>> it as "[0]" >>> >>> I'm completely wrong. Didn't read your code properly. Where is the delete >>> link? :) >> > From mbklein at gmail.com Sat Mar 26 02:11:49 2011 From: mbklein at gmail.com (Michael B. Klein) Date: Fri, 25 Mar 2011 23:11:49 -0700 Subject: [rspec-users] stubbing mongoid::criteria in view code In-Reply-To: <4370921.222.1301066308303.JavaMail.geo-discussion-forums@yqdn5> References: <4370921.222.1301066308303.JavaMail.geo-discussion-forums@yqdn5> Message-ID: What happens if you Page.stub_chain(:criteria, :id).and_return([mock_model("Page", :title => "foobar")]) (i.e., replace the mocked MongoidCriteria with a single-element Array containing the mocked Page) On Fri, Mar 25, 2011 at 8:18 AM, amkirwan wrote: > no unfortunately that does not work either. I receive the error: undefined > method `title' for # > _______________________________________________ > 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 huw.nichols at gmail.com Sat Mar 26 15:36:02 2011 From: huw.nichols at gmail.com (Huw Nichols) Date: Sat, 26 Mar 2011 12:36:02 -0700 (PDT) Subject: [rspec-users] calbacks on models In-Reply-To: <8E096386-42B1-44C3-AB13-77D3D5182F94@gmail.com> Message-ID: <11094318.414.1301168162773.JavaMail.geo-discussion-forums@yqmi40> Hi, Just been looking for answers to this very question: I have a User model (using devise) and the same problem. Both the before_create and after_create callbacks fail to run from within Rspec2 I can even put invalid code in the callbacks and it is not detected until I switch to dev and run through the browser - then it all works as expected. rails 3.0.5 and sqlite rspec (2.5.0) rspec-core (2.5.1) rspec-expectations (2.5.0) rspec-mocks (2.5.0) rspec-rails (2.5.0) Has anyone had any thoughts on this as yet ? Thanks H -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Sat Mar 26 17:41:33 2011 From: jko170 at gmail.com (Justin Ko) Date: Sat, 26 Mar 2011 14:41:33 -0700 Subject: [rspec-users] calbacks on models In-Reply-To: <11094318.414.1301168162773.JavaMail.geo-discussion-forums@yqmi40> References: <11094318.414.1301168162773.JavaMail.geo-discussion-forums@yqmi40> Message-ID: <06FE1C60-4C9A-4B3E-A3B5-64082776AD31@gmail.com> On Mar 26, 2011, at 12:36 PM, Huw Nichols wrote: > Hi, > > Just been looking for answers to this very question: > > I have a User model (using devise) and the same problem. > > Both the before_create and after_create callbacks fail to run from within Rspec2 > > I can even put invalid code in the callbacks and it is not detected until I switch to dev and run through the browser - then it all works as expected. > > rails 3.0.5 and sqlite > rspec (2.5.0) > rspec-core (2.5.1) > rspec-expectations (2.5.0) > rspec-mocks (2.5.0) > rspec-rails (2.5.0) > > Has anyone had any thoughts on this as yet ? > > Thanks > > H > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Got code? From huw.nichols at gmail.com Sat Mar 26 21:18:37 2011 From: huw.nichols at gmail.com (Huw Nichols) Date: Sat, 26 Mar 2011 18:18:37 -0700 (PDT) Subject: [rspec-users] calbacks on models In-Reply-To: <06FE1C60-4C9A-4B3E-A3B5-64082776AD31@gmail.com> Message-ID: <21078934.145.1301188717708.JavaMail.geo-discussion-forums@yqkq14> OK, found the problem and it's not rspec - my bad... Turns out that my spork config using guard etc. does not reload model files as it should - looking into that next Reloading spork (or killing it and running native) and all tests work as expected. Sorry for time waste H -------------- next part -------------- An HTML attachment was scrubbed... URL: From lbocseg at yahoo.com.br Sat Mar 26 22:43:21 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Sat, 26 Mar 2011 23:43:21 -0300 Subject: [rspec-users] given-when-then-and syntax support in Rspec Message-ID: <4D8EA449.9030904@yahoo.com.br> Hi David and fellows, I know this subject has already been discussed here and there are already some attempts to support the given-when-then-and syntax in Rspec, like the links below: https://gist.github.com/206969 https://github.com/jimweirich/rspec-given First, I don't understand the reason to adopt the capital method names Given/When/Then/And instead of given/when/then/and. Then, I don't think we can call this some real support for that syntax because "example" is not meant to be executed in any special order in Rspec nor it can be defined that any additional "then/and" should be aborted if a prior expectation wasn't met. And both solutions seem to work by simple aliasing "example" and "describe". I never used Cucumber because I find that working with it is cumbersome for most cases. I've been working mostly with Grails on my daily job for about 2 years now since I moved to my current job. I wanted something like Rspec for Groovy and Grails and while searching for some alternative, I found EasyB: http://www.easyb.org/ Actually I liked the story syntax they provide as well as the reports and I found it would be useful for Rspec to incorporate that style too: http://www.easyb.org/howtos.html What do you think? Best regards! Rodrigo. From dchelimsky at gmail.com Sun Mar 27 05:55:21 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Mar 2011 04:55:21 -0500 Subject: [rspec-users] given-when-then-and syntax support in Rspec In-Reply-To: <4D8EA449.9030904@yahoo.com.br> References: <4D8EA449.9030904@yahoo.com.br> Message-ID: <85261967-2F44-488F-987E-44FE563840DB@gmail.com> On Mar 26, 2011, at 9:43 PM, Rodrigo Rosenfeld Rosas wrote: > Hi David and fellows, > > I know this subject has already been discussed here and there are already some attempts to support the given-when-then-and syntax in Rspec, like the links below: > > https://gist.github.com/206969 > https://github.com/jimweirich/rspec-given > > First, I don't understand the reason to adopt the capital method names Given/When/Then/And instead of given/when/then/and. 'when', 'then', and 'and' are all Ruby keywords. You can define them as methods, but unpleasant things happen. > Then, I don't think we can call this some real support for that syntax because "example" is not meant to be executed in any special order in Rspec nor it can be defined that any additional "then/and" should be aborted if a prior expectation wasn't met. And both solutions seem to work by simple aliasing "example" and "describe". > > I never used Cucumber because I find that working with it is cumbersome for most cases. > > I've been working mostly with Grails on my daily job for about 2 years now since I moved to my current job. I wanted something like Rspec for Groovy and Grails and while searching for some alternative, I found EasyB: > > http://www.easyb.org/ > > Actually I liked the story syntax they provide as well as the reports and I found it would be useful for Rspec to incorporate that style too: > > http://www.easyb.org/howtos.html > > What do you think? Adding first class support for feature/scenario/given/when/then would be a fundamental change to rspec-core, requiring much more than simply exposing new syntax. We'd need new formatters, new ways to define shared code, new command line options, etc, etc. I think this would require too much work, and make the libraries more complicated to use and maintain. I like the direction that rspec-given takes us: an extension library on top of RSpec. As you point out, it could be made more valuable by adding rich concepts like "steps" that are different from "examples", but I think that could be done within the context of rspec-given (or any other extension), and I'd gladly consider adding new extension points that would make that job easier. Cheers, David > Best regards! > > Rodrigo. From thecatwasnot at gmail.com Sun Mar 27 08:56:54 2011 From: thecatwasnot at gmail.com (Pixel) Date: Sun, 27 Mar 2011 07:56:54 -0500 Subject: [rspec-users] calbacks on models In-Reply-To: <21078934.145.1301188717708.JavaMail.geo-discussion-forums@yqkq14> References: <06FE1C60-4C9A-4B3E-A3B5-64082776AD31@gmail.com> <21078934.145.1301188717708.JavaMail.geo-discussion-forums@yqkq14> Message-ID: On Sat, Mar 26, 2011 at 8:18 PM, Huw Nichols wrote: > OK, found the problem and it's not rspec - my bad... > Turns out that my spork config using guard etc. does not reload model files > as it should - looking into that next > Reloading spork (or killing it and running native) and all tests work as > expected. > Sorry for time waste > H I've seen this same problem with a very similar setup. I believe it's got to do with the way devise loads up the user model when routes are loaded, so basically it's a problem between spork and devise. (I use guard as well, but I don't think it is related.) I tried: https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu With no luck. You might want to take it to the spork mailing list. From matt at mattwynne.net Sun Mar 27 09:32:55 2011 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 27 Mar 2011 14:32:55 +0100 Subject: [rspec-users] given-when-then-and syntax support in Rspec In-Reply-To: <4D8EA449.9030904@yahoo.com.br> References: <4D8EA449.9030904@yahoo.com.br> Message-ID: <682CCC88-A70F-4CF8-BC87-3CF37AC99D38@mattwynne.net> On 27 Mar 2011, at 03:43, Rodrigo Rosenfeld Rosas wrote: > Hi David and fellows, > > I know this subject has already been discussed here and there are already some attempts to support the given-when-then-and syntax in Rspec, like the links below: > > https://gist.github.com/206969 > https://github.com/jimweirich/rspec-given > > First, I don't understand the reason to adopt the capital method names Given/When/Then/And instead of given/when/then/and. Then, I don't think we can call this some real support for that syntax because "example" is not meant to be executed in any special order in Rspec nor it can be defined that any additional "then/and" should be aborted if a prior expectation wasn't met. And both solutions seem to work by simple aliasing "example" and "describe". > > I never used Cucumber because I find that working with it is cumbersome for most cases. > > I've been working mostly with Grails on my daily job for about 2 years now since I moved to my current job. I wanted something like Rspec for Groovy and Grails and while searching for some alternative, I found EasyB: > > http://www.easyb.org/ > > Actually I liked the story syntax they provide as well as the reports and I found it would be useful for Rspec to incorporate that style too: > > http://www.easyb.org/howtos.html > > What do you think? Why not just use Cucumber? > > Best regards! > > Rodrigo. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt matt at mattwynne.net 07974 430184 From huw at newbeatsmedia.com Sun Mar 27 12:06:43 2011 From: huw at newbeatsmedia.com (Huw) Date: Sun, 27 Mar 2011 17:06:43 +0100 Subject: [rspec-users] calbacks on models In-Reply-To: References: <06FE1C60-4C9A-4B3E-A3B5-64082776AD31@gmail.com> <21078934.145.1301188717708.JavaMail.geo-discussion-forums@yqkq14> Message-ID: On Sun, Mar 27, 2011 at 1:56 PM, Pixel wrote: > On Sat, Mar 26, 2011 at 8:18 PM, Huw Nichols > wrote: > > OK, found the problem and it's not rspec - my bad... > > Turns out that my spork config using guard etc. does not reload model > files > > as it should - looking into that next > > Reloading spork (or killing it and running native) and all tests work as > > expected. > > Sorry for time waste > > H > > > I've seen this same problem with a very similar setup. I believe it's > got to do with the way devise loads up the user model when routes are > loaded, so basically it's a problem between spork and devise. (I use > guard as well, but I don't think it is related.) > > I tried: > https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu > With no luck. You might want to take it to the spork mailing list. > > Have a look at the very latest spork (0.9.0.rc4) on github - I can't recall where I saw it mentioned yesterday but the combo of that devise fix you linked to and upgrading spork seems to be working for me now.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lbocseg at yahoo.com.br Sun Mar 27 18:12:24 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Sun, 27 Mar 2011 19:12:24 -0300 Subject: [rspec-users] given-when-then-and syntax support in Rspec In-Reply-To: <85261967-2F44-488F-987E-44FE563840DB@gmail.com> References: <4D8EA449.9030904@yahoo.com.br> <85261967-2F44-488F-987E-44FE563840DB@gmail.com> Message-ID: <4D8FB648.1070604@yahoo.com.br> Em 27-03-2011 06:55, David Chelimsky escreveu: > On Mar 26, 2011, at 9:43 PM, Rodrigo Rosenfeld Rosas wrote: > >> Hi David and fellows, >> >> I know this subject has already been discussed here and there are already some attempts to support the given-when-then-and syntax in Rspec, like the links below: >> >> https://gist.github.com/206969 >> https://github.com/jimweirich/rspec-given >> >> First, I don't understand the reason to adopt the capital method names Given/When/Then/And instead of given/when/then/and. > 'when', 'then', and 'and' are all Ruby keywords. You can define them as methods, but unpleasant things happen. Right! Of course there was a reason! How didn't I think about this before?! :) >> Then, I don't think we can call this some real support for that syntax because "example" is not meant to be executed in any special order in Rspec nor it can be defined that any additional "then/and" should be aborted if a prior expectation wasn't met. And both solutions seem to work by simple aliasing "example" and "describe". >> >> I never used Cucumber because I find that working with it is cumbersome for most cases. >> >> I've been working mostly with Grails on my daily job for about 2 years now since I moved to my current job. I wanted something like Rspec for Groovy and Grails and while searching for some alternative, I found EasyB: >> >> http://www.easyb.org/ >> >> Actually I liked the story syntax they provide as well as the reports and I found it would be useful for Rspec to incorporate that style too: >> >> http://www.easyb.org/howtos.html >> >> What do you think? > Adding first class support for feature/scenario/given/when/then would be a fundamental change to rspec-core, requiring much more than simply exposing new syntax. We'd need new formatters, new ways to define shared code, new command line options, etc, etc. I think this would require too much work, and make the libraries more complicated to use and maintain. I really don't intend to replace current Rspec syntax. I like it too. I just proposed to add these new syntax because I feel it is very useful, both for avoiding several expectations by example when you need something sequential and for generating good reports for some use cases. I said that because I don't agree that the library would be more complicated to use, although it would certainly add more maintainance work. It would just add some new syntax if the user wants it. For instance, we could do like EasyB does. Suggest creating .spec and .story files. Each one of them would use one of the approaches. That way, it wouldn't make it more complicate to use. But I agree that maintainance would be harder, but on the other hand the user experience could improve a lot for some users. > I like the direction that rspec-given takes us: an extension library on top of RSpec. As you point out, it could be made more valuable by adding rich concepts like "steps" that are different from "examples", but I think that could be done within the context of rspec-given (or any other extension), and I'd gladly consider adding new extension points that would make that job easier. Right, that's awesome and I agree with you. But as it happens with rspec-rails, I think that rspec-given could be some official module to Rspec to show users that Rspec is commited to support this syntax too. The documentation could be integrated as well as it also happens to rspec-rails. How do you see this possibility? Best regards, Rodrigo. From lbocseg at yahoo.com.br Sun Mar 27 18:16:51 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Sun, 27 Mar 2011 19:16:51 -0300 Subject: [rspec-users] given-when-then-and syntax support in Rspec In-Reply-To: <682CCC88-A70F-4CF8-BC87-3CF37AC99D38@mattwynne.net> References: <4D8EA449.9030904@yahoo.com.br> <682CCC88-A70F-4CF8-BC87-3CF37AC99D38@mattwynne.net> Message-ID: <4D8FB753.9020202@yahoo.com.br> Em 27-03-2011 10:32, Matt Wynne escreveu: > On 27 Mar 2011, at 03:43, Rodrigo Rosenfeld Rosas wrote: > >> Hi David and fellows, >> >> I know this subject has already been discussed here and there are already some attempts to support the given-when-then-and syntax in Rspec, like the links below: >> >> https://gist.github.com/206969 >> https://github.com/jimweirich/rspec-given >> >> First, I don't understand the reason to adopt the capital method names Given/When/Then/And instead of given/when/then/and. Then, I don't think we can call this some real support for that syntax because "example" is not meant to be executed in any special order in Rspec nor it can be defined that any additional "then/and" should be aborted if a prior expectation wasn't met. And both solutions seem to work by simple aliasing "example" and "describe". >> >> I never used Cucumber because I find that working with it is cumbersome for most cases. >> >> I've been working mostly with Grails on my daily job for about 2 years now since I moved to my current job. I wanted something like Rspec for Groovy and Grails and while searching for some alternative, I found EasyB: >> >> http://www.easyb.org/ >> >> Actually I liked the story syntax they provide as well as the reports and I found it would be useful for Rspec to incorporate that style too: >> >> http://www.easyb.org/howtos.html >> >> What do you think? > Why not just use Cucumber? I'll repeat myself: "I never used Cucumber because I find that working with it is cumbersome for most cases". That is really the reason :) I don't feel the need for the extra work. I just want to use directly the syntax in the test code. Writing step definitions besides the feature text seems too much work to me, while I would like to do both at once, even if I don't get some english-only (or any other language) specification. Regards, Rodrigo From aslak.hellesoy at gmail.com Sun Mar 27 18:57:08 2011 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 27 Mar 2011 23:57:08 +0100 Subject: [rspec-users] given-when-then-and syntax support in Rspec In-Reply-To: <4D8FB753.9020202@yahoo.com.br> References: <4D8EA449.9030904@yahoo.com.br> <682CCC88-A70F-4CF8-BC87-3CF37AC99D38@mattwynne.net> <4D8FB753.9020202@yahoo.com.br> Message-ID: On Sun, Mar 27, 2011 at 11:16 PM, Rodrigo Rosenfeld Rosas wrote: > Em 27-03-2011 10:32, Matt Wynne escreveu: >> >> On 27 Mar 2011, at 03:43, Rodrigo Rosenfeld Rosas wrote: >> >>> Hi David and fellows, >>> >>> I know this subject has already been discussed here and there are already >>> some attempts to support the given-when-then-and syntax in Rspec, like the >>> links below: >>> >>> https://gist.github.com/206969 >>> https://github.com/jimweirich/rspec-given >>> >>> First, I don't understand the reason to adopt the capital method names >>> Given/When/Then/And instead of given/when/then/and. Then, I don't think we >>> can call this some real support for that syntax because "example" is not >>> meant to be executed in any special order in Rspec nor it can be defined >>> that any additional "then/and" should be aborted if a prior expectation >>> wasn't met. And both solutions seem to work by simple aliasing "example" and >>> "describe". >>> >>> I never used Cucumber because I find that working with it is cumbersome >>> for most cases. >>> >>> I've been working mostly with Grails on my daily job for about 2 years >>> now since I moved to my current job. I wanted something like Rspec for >>> Groovy and Grails and while searching for some alternative, I found EasyB: >>> >>> http://www.easyb.org/ >>> >>> Actually I liked the story syntax they provide as well as the reports and >>> I found it would be useful for Rspec to incorporate that style too: >>> >>> http://www.easyb.org/howtos.html >>> >>> What do you think? >> >> Why not just use Cucumber? > > I'll repeat myself: "I never used Cucumber because I find that working with > it is cumbersome for most cases". > Have you tried Steak? https://github.com/cavalle/steak Aslak > That is really the reason :) I don't feel the need for the extra work. I > just want to use directly the syntax in the test code. Writing step > definitions besides the feature text seems too much work to me, while I > would like to do both at once, even if I don't get some english-only (or any > other language) specification. > > Regards, > > Rodrigo > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Mar 28 00:10:54 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Mar 2011 23:10:54 -0500 Subject: [rspec-users] given-when-then-and syntax support in Rspec In-Reply-To: <4D8FB648.1070604@yahoo.com.br> References: <4D8EA449.9030904@yahoo.com.br> <85261967-2F44-488F-987E-44FE563840DB@gmail.com> <4D8FB648.1070604@yahoo.com.br> Message-ID: <3E504EEA-EFCC-415C-9EC1-734313FD9292@gmail.com> On Mar 27, 2011, at 5:12 PM, Rodrigo Rosenfeld Rosas wrote: > Em 27-03-2011 06:55, David Chelimsky escreveu: >> On Mar 26, 2011, at 9:43 PM, Rodrigo Rosenfeld Rosas wrote: >> >>> Hi David and fellows, >>> >>> I know this subject has already been discussed here and there are already some attempts to support the given-when-then-and syntax in Rspec, like the links below: >>> >>> https://gist.github.com/206969 >>> https://github.com/jimweirich/rspec-given >>> >>> First, I don't understand the reason to adopt the capital method names Given/When/Then/And instead of given/when/then/and. >> 'when', 'then', and 'and' are all Ruby keywords. You can define them as methods, but unpleasant things happen. > > Right! Of course there was a reason! How didn't I think about this before?! :) > >>> Then, I don't think we can call this some real support for that syntax because "example" is not meant to be executed in any special order in Rspec nor it can be defined that any additional "then/and" should be aborted if a prior expectation wasn't met. And both solutions seem to work by simple aliasing "example" and "describe". >>> >>> I never used Cucumber because I find that working with it is cumbersome for most cases. >>> >>> I've been working mostly with Grails on my daily job for about 2 years now since I moved to my current job. I wanted something like Rspec for Groovy and Grails and while searching for some alternative, I found EasyB: >>> >>> http://www.easyb.org/ >>> >>> Actually I liked the story syntax they provide as well as the reports and I found it would be useful for Rspec to incorporate that style too: >>> >>> http://www.easyb.org/howtos.html >>> >>> What do you think? >> Adding first class support for feature/scenario/given/when/then would be a fundamental change to rspec-core, requiring much more than simply exposing new syntax. We'd need new formatters, new ways to define shared code, new command line options, etc, etc. I think this would require too much work, and make the libraries more complicated to use and maintain. > > I really don't intend to replace current Rspec syntax. I like it too. I just proposed to add these new syntax because I feel it is very useful, both for avoiding several expectations by example when you need something sequential and for generating good reports for some use cases. > > I said that because I don't agree that the library would be more complicated to use Then we disagree. > although it would certainly add more maintainance work. It would just add some new syntax if the user wants it. For instance, we could do like EasyB does. Suggest creating .spec and .story files. Each one of them would use one of the approaches. That way, it wouldn't make it more complicate to use. But I agree that maintainance would be harder, but on the other hand the user experience could improve a lot for some users. > >> I like the direction that rspec-given takes us: an extension library on top of RSpec. As you point out, it could be made more valuable by adding rich concepts like "steps" that are different from "examples", but I think that could be done within the context of rspec-given (or any other extension), and I'd gladly consider adding new extension points that would make that job easier. > > Right, that's awesome and I agree with you. But as it happens with rspec-rails, I think that rspec-given could be some official module to Rspec to show users that Rspec is commited to support this syntax too. Except that RSpec is _not_ committed to supporting this syntax. > The documentation could be integrated as well as it also happens to rspec-rails. > > How do you see this possibility? I appreciate your enthusiasm for this, and encourage you to write an extension library that provides what you're looking for, but I don't envision this getting merged into RSpec proper for the foreseeable future. Cheers, David From lbocseg at yahoo.com.br Mon Mar 28 19:37:52 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Mon, 28 Mar 2011 20:37:52 -0300 Subject: [rspec-users] given-when-then-and syntax support in Rspec In-Reply-To: <3E504EEA-EFCC-415C-9EC1-734313FD9292@gmail.com> References: <4D8EA449.9030904@yahoo.com.br> <85261967-2F44-488F-987E-44FE563840DB@gmail.com> <4D8FB648.1070604@yahoo.com.br> <3E504EEA-EFCC-415C-9EC1-734313FD9292@gmail.com> Message-ID: <4D911BD0.6090103@yahoo.com.br> Em 28-03-2011 01:10, David Chelimsky escreveu: > On Mar 27, 2011, at 5:12 PM, Rodrigo Rosenfeld Rosas wrote: > >> Em 27-03-2011 06:55, David Chelimsky escreveu: >>> On Mar 26, 2011, at 9:43 PM, Rodrigo Rosenfeld Rosas wrote: >>> >>>> Hi David and fellows, >>>> >>>> I know this subject has already been discussed here and there are already some attempts to support the given-when-then-and syntax in Rspec, like the links below: >>>> >>>> https://gist.github.com/206969 >>>> https://github.com/jimweirich/rspec-given >>>> >>>> First, I don't understand the reason to adopt the capital method names Given/When/Then/And instead of given/when/then/and. >>> 'when', 'then', and 'and' are all Ruby keywords. You can define them as methods, but unpleasant things happen. >> Right! Of course there was a reason! How didn't I think about this before?! :) >> >>>> Then, I don't think we can call this some real support for that syntax because "example" is not meant to be executed in any special order in Rspec nor it can be defined that any additional "then/and" should be aborted if a prior expectation wasn't met. And both solutions seem to work by simple aliasing "example" and "describe". >>>> >>>> I never used Cucumber because I find that working with it is cumbersome for most cases. >>>> >>>> I've been working mostly with Grails on my daily job for about 2 years now since I moved to my current job. I wanted something like Rspec for Groovy and Grails and while searching for some alternative, I found EasyB: >>>> >>>> http://www.easyb.org/ >>>> >>>> Actually I liked the story syntax they provide as well as the reports and I found it would be useful for Rspec to incorporate that style too: >>>> >>>> http://www.easyb.org/howtos.html >>>> >>>> What do you think? >>> Adding first class support for feature/scenario/given/when/then would be a fundamental change to rspec-core, requiring much more than simply exposing new syntax. We'd need new formatters, new ways to define shared code, new command line options, etc, etc. I think this would require too much work, and make the libraries more complicated to use and maintain. >> I really don't intend to replace current Rspec syntax. I like it too. I just proposed to add these new syntax because I feel it is very useful, both for avoiding several expectations by example when you need something sequential and for generating good reports for some use cases. >> >> I said that because I don't agree that the library would be more complicated to use > Then we disagree. > >> although it would certainly add more maintainance work. It would just add some new syntax if the user wants it. For instance, we could do like EasyB does. Suggest creating .spec and .story files. Each one of them would use one of the approaches. That way, it wouldn't make it more complicate to use. But I agree that maintainance would be harder, but on the other hand the user experience could improve a lot for some users. >> >>> I like the direction that rspec-given takes us: an extension library on top of RSpec. As you point out, it could be made more valuable by adding rich concepts like "steps" that are different from "examples", but I think that could be done within the context of rspec-given (or any other extension), and I'd gladly consider adding new extension points that would make that job easier. >> Right, that's awesome and I agree with you. But as it happens with rspec-rails, I think that rspec-given could be some official module to Rspec to show users that Rspec is commited to support this syntax too. > Except that RSpec is _not_ committed to supporting this syntax. > >> The documentation could be integrated as well as it also happens to rspec-rails. >> >> How do you see this possibility? > I appreciate your enthusiasm for this, and encourage you to write an extension library that provides what you're looking for, but I don't envision this getting merged into RSpec proper for the foreseeable future. Ok, thank you for your feedback :) Rodrigo. From mike at sowbug.com Mon Mar 28 22:29:04 2011 From: mike at sowbug.com (Mike Tsao) Date: Mon, 28 Mar 2011 19:29:04 -0700 Subject: [rspec-users] Can't put shared example group in its own file In-Reply-To: References: Message-ID: Any ideas? All I'd like to do is have two specs in different files use the same shared example group. I saw a similar thread about autotest, but I am not using that. [Sorry for the double post on Google Groups; didn't realize at the time it was a read-only group.] $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] $ rails -v Rails 3.0.5 $ rails new shared $ cd shared/ $ echo "gem 'rspec-rails', '~> 2.5'" >> Gemfile $ bundle --without production $ rails generate rspec:install $ rails generate scaffold foo $ rake db:migrate $ mkdir spec/support $ nano spec/support/stuff_spec.rb -- spec/support/stuff_spec.rb shared_examples_for "bar" do end $ rake spec (in /tmp/shared) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S bundle exec rspec ./spec/controllers/foos_controller_spec.rb ./spec/helpers/foos_helper_spec.rb ./spec/models/foo_spec.rb ./spec/requests/foos_spec.rb ./spec/routing/foos_routing_spec.rb ./spec/support/stuff_spec.rb ./spec/views/foos/edit.html.erb_spec.rb ./spec/views/foos/index.html.erb_spec.rb ./spec/views/foos/new.html.erb_spec.rb ./spec/views/foos/show.html.erb_spec.rb /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:45:in `ensure_shared_example_group_name_not_taken': Shared example group 'bar' already exists (ArgumentError) ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:6:in `shared_examples_for' ? ? ? ?from /private/tmp/shared/spec/support/stuff_spec.rb:1 ? ? ? ?from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:227:in `load_dependency' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run' ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `autorun' ? ? ? ?from /Library/Ruby/Gems/1.8/bin/rspec:19 rake aborted! From dchelimsky at gmail.com Tue Mar 29 00:44:42 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Mar 2011 23:44:42 -0500 Subject: [rspec-users] Can't put shared example group in its own file In-Reply-To: References: Message-ID: On Mar 28, 2011, at 9:29 PM, Mike Tsao wrote: > Any ideas? All I'd like to do is have two specs in different files use > the same shared example group. I saw a similar thread about autotest, > but I am not using that. [Sorry for the double post on Google Groups; > didn't realize at the time it was a read-only group.] > > $ ruby -v > ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] > $ rails -v > Rails 3.0.5 > $ rails new shared > $ cd shared/ > $ echo "gem 'rspec-rails', '~> 2.5'" >> Gemfile > $ bundle --without production > $ rails generate rspec:install > $ rails generate scaffold foo > $ rake db:migrate > $ mkdir spec/support > $ nano spec/support/stuff_spec.rb Don't name this file ^^ ending with _spec.rb - that is the default pattern that RSpec looks for specs in, so it's getting loaded as a spec. Name it something like shared_examples_for_stuff.rb. HTH, David > > -- spec/support/stuff_spec.rb > shared_examples_for "bar" do > end > > $ rake spec > (in /tmp/shared) > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S > bundle exec rspec ./spec/controllers/foos_controller_spec.rb > ./spec/helpers/foos_helper_spec.rb ./spec/models/foo_spec.rb > ./spec/requests/foos_spec.rb ./spec/routing/foos_routing_spec.rb > ./spec/support/stuff_spec.rb ./spec/views/foos/edit.html.erb_spec.rb > ./spec/views/foos/index.html.erb_spec.rb > ./spec/views/foos/new.html.erb_spec.rb > ./spec/views/foos/show.html.erb_spec.rb > /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:45:in > `ensure_shared_example_group_name_not_taken': Shared example group > 'bar' already exists (ArgumentError) > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:6:in > `shared_examples_for' > from /private/tmp/shared/spec/support/stuff_spec.rb:1 > from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in > `load' > from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in > `load' > from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:227:in > `load_dependency' > from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in > `load' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in > `load_spec_files' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in > `map' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in > `load_spec_files' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in > `run' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in > `run_in_process' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in > `run' > from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in > `autorun' > from /Library/Ruby/Gems/1.8/bin/rspec:19 > rake aborted! From amkirwan at gmail.com Tue Mar 29 16:14:07 2011 From: amkirwan at gmail.com (amkirwan) Date: Tue, 29 Mar 2011 13:14:07 -0700 (PDT) Subject: [rspec-users] stubbing mongoid::criteria in view code In-Reply-To: References: <4370921.222.1301066308303.JavaMail.geo-discussion-forums@yqdn5> Message-ID: <3c617a49-5e3e-4793-9ad2-171d6342b7f2@w7g2000pre.googlegroups.com> that did it thanks. On Mar 26, 2:11?am, "Michael B. Klein" wrote: > What happens if you > > Page.stub_chain(:criteria, :id).and_return([mock_model("Page", :title => > "foobar")]) > > (i.e., replace the mocked MongoidCriteria with a single-element Array > containing the mocked Page) > > > > On Fri, Mar 25, 2011 at 8:18 AM, amkirwan wrote: > > no unfortunately that does not work either. I receive the error: undefined > > method `title' for # > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From amkirwan at gmail.com Wed Mar 30 12:04:57 2011 From: amkirwan at gmail.com (amkirwan) Date: Wed, 30 Mar 2011 09:04:57 -0700 (PDT) Subject: [rspec-users] Anonymous Subclass of ActionController::Base Message-ID: <6953ec72-5d39-4a55-854d-35558ccc9a45@cu4g2000vbb.googlegroups.com> I'm trying to spec a subclass of ActionController::Base using an anonymous subclass but I am running into errors but I am receiving a uninitialized constant StubResource Here is my base class class Admin::BaseController < ApplicationController before_filter :etherweb_site load_and_authorize_resource layout "admin/admin" protected def etherweb_site end end Spec: require File.expand_path(File.dirname(__FILE__) + '/../../ spec_helper') describe "Admin::BaseController" do let(:current_user) { logged_in(:role? => true) } controller(Admin::BaseController) do def index render :nothing => true end end before(:each) do cas_faker(current_user.username) end describe "cms_site before_filter" do it "should receive before_filter cms_site" do controller.should_receive(:etherweb_site) get :index end end end From peter.boling at gmail.com Wed Mar 30 12:28:47 2011 From: peter.boling at gmail.com (Peter Boling) Date: Wed, 30 Mar 2011 12:28:47 -0400 Subject: [rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs? Message-ID: Sorry if multiple postings of this show up. I had to RTFM a few times before I figured out how to post correctly. I use VCR to record interactions, and when the recordings change filenames, and directory structure, over time, as the test suite evolves, the old recordings, no longer used, are rarely pruned. I would like to have the ability to run rspec with an option to check for unused VCR recordings, and another to both check and delete unused recordings. I need a way to know if the full spec suite is being run. I think this can be determined with some fancy testing on ARGV. I can get the full list of recordings like this (or similar): FileList["spec/fixtures/vcr/**/*.yml"].reject{|file|File.directory?(file)} And then prune the list as each recording is used by the spec suite, afterwards having a list of the recordings that should be deleted. I need a hook that will run after the complete spec suite is run, before exiting the process, while still in the context of the thread, and the variable containing my list of files to delete is still accessible. Failing that I can write the list to a file, and hook in the deletion in the rake spec task. The downside of this is I currently run the test suite with `bundle exec rspec spec`, and don't really use the `rake spec` task. Aside: It would involve some (lots?) of work to get `rake spec` working in this project. Currently when I run `rake spec` there is no output at all. It appears to load the rails env, and do nothing. Any one have an idea about that? -- |7eter H. l3oling -------------- next part -------------- An HTML attachment was scrubbed... URL: From curtis.schofield at gmail.com Wed Mar 30 12:31:31 2011 From: curtis.schofield at gmail.com (Curtis j Schofield) Date: Wed, 30 Mar 2011 09:31:31 -0700 Subject: [rspec-users] Test Design Question #1 Message-ID: I have an model in rails with an after_create that generates another object (for the purpose of making an audit trail). In the unit test - i want to verify this behavior. This behaviour - in other tests is breaking some exceptions around (include) - since the creation of the new audit trail is leaking into this other unit test. In the controller test this behavior doesn't matter - in the integration test i do want this behavior. What am i doing wrong here? -- make haste slowly \ festina lente ?\ - mobile ?+1_415_632_6001 curtis.schofield at gmail.com http://robotarmyma.de From curtis.schofield at gmail.com Wed Mar 30 12:34:38 2011 From: curtis.schofield at gmail.com (Curtis j Schofield) Date: Wed, 30 Mar 2011 09:34:38 -0700 Subject: [rspec-users] Test Design Question #2 Message-ID: I am designing a test around a class that interacts with TCPSocket - I have used a mock and have asserted as minimal an interface as I can - centered around the IO methods. Should i be using a stub instead and stub on open and read - instead of mock with open, read , close and so forth. Is there a good pattern for testing TCP servers in a unit-oriented way? I could make a micro server in the test - but that seems to be not what i really want. Thank you -- make haste slowly \ festina lente ?\ - mobile ?+1_415_632_6001 curtis.schofield at gmail.com http://robotarmyma.de From peter.boling at gmail.com Wed Mar 30 13:59:33 2011 From: peter.boling at gmail.com (Peter Boling) Date: Wed, 30 Mar 2011 10:59:33 -0700 (PDT) Subject: [rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs? In-Reply-To: References: Message-ID: Update: I have fixed rake spec. Someone else on the team had removed the gem dependency from the development group in the Gemfile. Once added back rake spec worked fine. From patmaddox at me.com Thu Mar 31 03:52:25 2011 From: patmaddox at me.com (Pat Maddox) Date: Thu, 31 Mar 2011 00:52:25 -0700 Subject: [rspec-users] Test Design Question #1 In-Reply-To: References: Message-ID: What do you mean that it's "leaking" into the other test? If you have transactions turned on, then any records inserted into the db will be removed for the next test. My guess is that other tests just don't set up the required data...which is a problem with ActiveRecord callbacks and observers. In that case, you'll want to use a test data builder like fixjour or Factory Girl, so you only have to set up the data in one place. Another approach is to move your after_create code into an observer and use my no_peeping_toms gem which disables observers in tests (and makes you explicitly enable them, either all of them or individually). This way you can test your callbacks in the unit tests for that behavior, and disable them everywhere else. Cheers brother, Pat On Mar 30, 2011, at 9:31 AM, Curtis j Schofield wrote: > I have an model in rails with an after_create that generates another > object (for the purpose of making an audit trail). > > In the unit test - i want to verify this behavior. > > This behaviour - in other tests is breaking some exceptions around > (include) - since the creation of the new audit trail > is leaking into this other unit test. > > In the controller test this behavior doesn't matter - in the > integration test i do want this behavior. > > What am i doing wrong here? > > > -- > make haste slowly \ > festina lente \ > - > mobile +1_415_632_6001 > curtis.schofield at gmail.com > http://robotarmyma.de > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patmaddox at me.com Thu Mar 31 03:53:42 2011 From: patmaddox at me.com (Pat Maddox) Date: Thu, 31 Mar 2011 00:53:42 -0700 Subject: [rspec-users] Test Design Question #2 In-Reply-To: References: Message-ID: <47349CB0-E374-4663-B6EE-50D475DECF00@me.com> Use mocks to define your interface, not to define TCPSocket directly. I would suggest running a TCP server just to test your wrapping object. Pat On Mar 30, 2011, at 9:34 AM, Curtis j Schofield wrote: > I am designing a test around a class that interacts with TCPSocket - I > have used a mock and have asserted as minimal an interface as I can - > centered around the IO methods. > > Should i be using a stub instead and stub on open and read - instead > of mock with open, read , close and so forth. > > Is there a good pattern for testing TCP servers in a unit-oriented way? > > I could make a micro server in the test - but that seems to be not > what i really want. > > > Thank you > > > -- > make haste slowly \ > festina lente \ > - > mobile +1_415_632_6001 > curtis.schofield at gmail.com > http://robotarmyma.de > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From peter.boling at gmail.com Thu Mar 31 09:14:25 2011 From: peter.boling at gmail.com (Peter Boling) Date: Thu, 31 Mar 2011 06:14:25 -0700 (PDT) Subject: [rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs? In-Reply-To: References: Message-ID: <0f4a380c-78d0-400f-9b34-18d2d05c1f0b@n10g2000yqf.googlegroups.com> Some additional data: rspec 2.5.1 rspec-rails 2.5.1 rails 3.0.4 ruby 1.9.2p0 rake 0.8.7 I have gotten all of this working now with the exception of a way to hook some code to be run after finishing all specs while still in the same thread. When I run Rake::Task["spec"].invoke within another rake task the list of VCR cassettes that have been 'touched' by the tests is not retained after the invoke method executes. I've tried storing it in a class instance variable @@file_list, as well as a global ruby var $file_list, with no dice. I think the only option to persist the list of file is now to write the file list to a yaml, and then pull it back out. :( From peter.boling at gmail.com Thu Mar 31 14:16:09 2011 From: peter.boling at gmail.com (Peter Boling) Date: Thu, 31 Mar 2011 11:16:09 -0700 (PDT) Subject: [rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs? In-Reply-To: <0f4a380c-78d0-400f-9b34-18d2d05c1f0b@n10g2000yqf.googlegroups.com> Message-ID: <10526280.482.1301595369219.JavaMail.geo-discussion-forums@vbxv23> I have implemented a full solution. Had to persist the list of unused VCR cassettes to the file system. Cheers! It would be still be cool if there was an after hook on rspec, as there is on capistrano! -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Thu Mar 31 14:27:44 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 31 Mar 2011 11:27:44 -0700 Subject: [rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs? In-Reply-To: <10526280.482.1301595369219.JavaMail.geo-discussion-forums@vbxv23> References: <0f4a380c-78d0-400f-9b34-18d2d05c1f0b@n10g2000yqf.googlegroups.com> <10526280.482.1301595369219.JavaMail.geo-discussion-forums@vbxv23> Message-ID: On Thu, Mar 31, 2011 at 11:16 AM, Peter Boling wrote: > I have implemented a full solution. Had to persist the list of unused VCR > cassettes to the file system. > Cheers! > It would be still be cool if there was an after hook on rspec, as there is > on capistrano! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > http://relishapp.com/rspec/rspec-core/v/2-5/dir/hooks/before-and-after-hooks -------------- next part -------------- An HTML attachment was scrubbed... URL: From yk.danabalan at gmail.com Wed Mar 23 14:05:59 2011 From: yk.danabalan at gmail.com (Yuvan) Date: Wed, 23 Mar 2011 11:05:59 -0700 (PDT) Subject: [rspec-users] Rake generate - not generating spec files In-Reply-To: References: Message-ID: I had a similar problem, then I noticed that I didn't include gem 'rspec-rails' in my development environment like what David mentioned above. That fixed the problem I had. I'm running the following stack: - rails 3.0.3 - - rake (0.8.7) - rspec 2.5.0 - rspec-rails 2.5.0 On Feb 23, 10:46?am, Pixel wrote: > On Tue, Feb 22, 2011 at 8:35 PM, Jason Nah wrote: > > Howdy, > > I'm running the following stack: > > > rails 3.0.4 > > rake (0.8.7) > > rspec 2.5.0 > > rspec-rails 2.5.0 > > > I created the rails app, and I didn't tell rails to exclude the default Test > > mechanisms. > > I installed it using > > rails generate rspec:install > > When I type > > rake g model User > > I've got a similar stack to yours. ?I've always run 'rails g model > User' (note rails not rake) but if I try 'rake g' it spits out an > error, so if you're running the rails script instead, I could be > wrong. > > > I get this: > > ?? ? ?invoke ?active_record > > ?? ? ?create ? ?db/migrate/20110223022101_create_users.rb > > ?? ? ?create ? ?app/models/user.rb > > ?? ? ?invoke ? ?test_unit > > ?? ? ?create ? ? ?test/unit/user_test.rb > > ?? ? ?create ? ? ?test/fixtures/users.yml > > No specs. > > When I type > > rake -T > > I don't see any spec targets. > > When I run rake spec, nothing happens. > > Is rspec-rails in both your :test and :development groups in your > Gemfile? ?It needs to be in :development to provide the rake tasks and > generators. ?See David's blog [1] for more info. > > > Is there something I've missed? > > Cheers, > > Jason > > -Cole > > [1]http://blog.davidchelimsky.net/tag/generators/ > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From mbklein at stanford.edu Wed Mar 23 14:51:22 2011 From: mbklein at stanford.edu (Michael B. Klein) Date: Wed, 23 Mar 2011 11:51:22 -0700 Subject: [rspec-users] [module announcement] Equivalency testing for XML Message-ID: Hello all, I recently released a gem that assists in testing XML nodes for equivalency, and thought it might be of interest to the RSpec community. It can normalize whitespace (or not), ignore element order (or not), compare namespaces based on URI (not prefix), and more. Plus -- and possibly best of all -- it has baked-in RSpec (1.2.4+, 2.x) integration via custom matchers. It's similar in aim to XmlUnit for Java[1], but with a far narrower scope. Documentation: http://rdoc.info/github/mbklein/equivalent-xml/master/frames Source:?http://github.com/mbklein/equivalent-xml RubyGems: http://rubygems.org/gems/equivalent-xml Or, of course, simply gem install equivalent-xml I welcome any feedback, suggestions, patches, pull requests, additional test cases, etc. Thanks! Michael B. Klein Digitization Workflow Engineer Stanford University Libraries & Academic Information Services [1] http://xmlunit.sourceforge.net/ From apnea.diving.deep at gmail.com Thu Mar 24 17:58:28 2011 From: apnea.diving.deep at gmail.com (apneadiving) Date: Thu, 24 Mar 2011 14:58:28 -0700 (PDT) Subject: [rspec-users] Rack application timed out during boot Message-ID: <715a6371-2447-4c90-b588-6ee4baff7f53@r3g2000yqh.googlegroups.com> Hi, I'm using Rspec + Capybara in Rails3. My integration tests went well today until I couldn't even access a page with simple requests such as: visit root_path With error: Rack application timed out during boot Any idea of what's going on? From mike at sowbug.com Sun Mar 27 23:04:23 2011 From: mike at sowbug.com (Mike T) Date: Sun, 27 Mar 2011 20:04:23 -0700 (PDT) Subject: [rspec-users] Can't put shared example group in its own file Message-ID: <491888.303.1301281463700.JavaMail.geo-discussion-forums@prmp17> Any ideas? All I'd like to do is have two specs in different files use the same shared example group. I saw a similar thread about autotest, but I am not using that. $ uname -a Darwin mbp.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386 $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] $ rails -v Rails 3.0.5 $ rails new shared $ cd shared/ $ echo "gem 'rspec-rails', '~> 2.5'" >> Gemfile $ bundle --without production $ rails generate rspec:install $ rails generate scaffold foo $ rake db:migrate $ mkdir spec/support $ nano spec/support/stuff_spec.rb -- spec/support/stuff_spec.rb *shared_examples_for "bar" do* *end* $ rake spec (in /tmp/shared) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S bundle exec rspec ./spec/controllers/foos_controller_spec.rb ./spec/helpers/foos_helper_spec.rb ./spec/models/foo_spec.rb ./spec/requests/foos_spec.rb ./spec/routing/foos_routing_spec.rb ./spec/support/stuff_spec.rb ./spec/views/foos/edit.html.erb_spec.rb ./spec/views/foos/index.html.erb_spec.rb ./spec/views/foos/new.html.erb_spec.rb ./spec/views/foos/show.html.erb_spec.rb /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/*shared_example_group.rb:45:in `ensure_shared_example_group_name_not_taken': Shared example group 'bar' already exists (ArgumentError)* from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:6:in `shared_examples_for' from /private/tmp/shared/spec/support/stuff_spec.rb:1 from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:227:in `load_dependency' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `autorun' from /Library/Ruby/Gems/1.8/bin/rspec:19 rake aborted! -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at sowbug.com Sun Mar 27 23:18:30 2011 From: mike at sowbug.com (Mike Tsao) Date: Sun, 27 Mar 2011 20:18:30 -0700 Subject: [rspec-users] Can't put shared example group in its own file Message-ID: Any ideas? All I'd like to do is have two specs in different files use the same shared example group. I saw a similar thread about autotest, but I am not using that. [Sorry for the double post on Google Groups; didn't realize at the time it was a read-only group.] $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] $ rails -v Rails 3.0.5 $ rails new shared $ cd shared/ $ echo "gem 'rspec-rails', '~> 2.5'" >> Gemfile $ bundle --without production $ rails generate rspec:install $ rails generate scaffold foo $ rake db:migrate $ mkdir spec/support $ nano spec/support/stuff_spec.rb -- spec/support/stuff_spec.rb shared_examples_for "bar" do end $ rake spec (in /tmp/shared) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S bundle exec rspec ./spec/controllers/foos_controller_spec.rb ./spec/helpers/foos_helper_spec.rb ./spec/models/foo_spec.rb ./spec/requests/foos_spec.rb ./spec/routing/foos_routing_spec.rb ./spec/support/stuff_spec.rb ./spec/views/foos/edit.html.erb_spec.rb ./spec/views/foos/index.html.erb_spec.rb ./spec/views/foos/new.html.erb_spec.rb ./spec/views/foos/show.html.erb_spec.rb /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:45:in `ensure_shared_example_group_name_not_taken': Shared example group 'bar' already exists (ArgumentError) from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:6:in `shared_examples_for' from /private/tmp/shared/spec/support/stuff_spec.rb:1 from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:227:in `load_dependency' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in `load' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `autorun' from /Library/Ruby/Gems/1.8/bin/rspec:19 rake aborted! From corbish at gmail.com Mon Mar 28 10:59:05 2011 From: corbish at gmail.com (Stuart Corbishley) Date: Mon, 28 Mar 2011 07:59:05 -0700 (PDT) Subject: [rspec-users] Bundler and Setting up RSpec Message-ID: Hi there, Does RSpec acknowledge bundler, and use the groups? Also is there any good example of what is required for a function spec rake task... I've had issues trying to create my own. require 'rubygems' require 'bundler' Bundler.setup(:default, :test) begin require 'rspec/core/rake_task' desc "Run the specs under spec/" RSpec::Rake::SpecTask.new rescue NameError, LoadError => e puts e end I get this back: no such file to load -- rake/tasklib I had a similar issue with another project written by someone else. I get the feeling I'm using the RSpec 1.x ways or something of the sort. Any advice? From scott at thisbythem.com Mon Mar 28 16:53:35 2011 From: scott at thisbythem.com (snelson) Date: Mon, 28 Mar 2011 13:53:35 -0700 (PDT) Subject: [rspec-users] Autotest Parallel Support Message-ID: <5f7a4de8-0f72-4dba-a563-e31abae9c6e5@o21g2000prh.googlegroups.com> I have a commit to add support for the -p (parallel) option to autotest, which is a feature provided by @grosser's autotest fork. The discussion is here: https://github.com/grosser/autotest/issues/#issue/13 The commit is here: https://github.com/thisbythem/rspec-core/commit/de074af8ab19e432b3c7b3c54fdf97494187e4aa Being that this adds a feature only supported by a forked version of autotest, I wanted to get some feedback as to wether or not this could even go into rspec-core. If not, then we'll explore other options. Thanks! From khalebpr at gmail.com Mon Mar 28 21:04:00 2011 From: khalebpr at gmail.com (Carlos Torres) Date: Mon, 28 Mar 2011 21:04:00 -0400 Subject: [rspec-users] Error running rspec on Debian Message-ID: I'm new to Rails and I was planning on trying out RSpec. When I try to execute the rspec command on Debian v6.0.1, I get the output below: k4ru050 at DebianBox:~/Desktop/rails_projects/sample_app/spec$ bundle exec rspec spec/controllers /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load': no such file to load -- /home/k4ru050/Desktop/rails_projects/sample_app/spec/spec/controllers (LoadError) from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files' from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map' from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files' from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run' from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process' from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run' from /home/k4ru050/.rvm/gems/ruby-1.9.2-p180 at rails3tutorial/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun' The versions I'm using are: Rails v3.0.5, Ruby v1.9.2 installed via rvm. Any suggestions on how to find a workaround for this issue? Thanks, Carlos -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.boling at gmail.com Wed Mar 30 11:03:56 2011 From: peter.boling at gmail.com (Peter Boling) Date: Wed, 30 Mar 2011 08:03:56 -0700 (PDT) Subject: [rspec-users] spec_helper aware of full test suite being run? After hook to run code after running all specs? Message-ID: I use VCR to record interactions, and when the recordings change filenames, and directory structure, over time, as the test suite evolves, the old recordings, no longer used, are rarely pruned. I would like to have the ability to run rspec with an option to check for unused VCR recordings, and another to both check and delete unused recordings. I need a way to know if the full spec suite is being run. I think this can be determined with some fancy testing on ARGV. I can get the full list of recordings like this (or similar): FileList["spec/fixtures/vcr/**/*.yml"].reject{|file|File.directory? (file)} And then prune the list as each recording is used by the spec suite, afterwards having a list of the recordings that should be deleted. I need a hook that will run after the complete spec suite is run, before exiting the process, while still in the context of the thread, and the variable containing my list of files to delete is still accessible. Failing that I can write the list to a file, and hook in the deletion in the rake spec task. The downside of this is we currently run our test suite with `bundle exec rspec spec`, and don't really use the rake spec task. It would involve other work to get rake spec working in this project. From peter.boling at gmail.com Wed Mar 30 11:59:21 2011 From: peter.boling at gmail.com (Peter Boling) Date: Wed, 30 Mar 2011 11:59:21 -0400 Subject: [rspec-users] spec_helper aware of full test suite being run? After hook to run code after running all specs? Message-ID: I use VCR to record interactions, and when the recordings change filenames, and directory structure, over time, as the test suite evolves, the old recordings, no longer used, are rarely pruned. I would like to have the ability to run rspec with an option to check for unused VCR recordings, and another to both check and delete unused recordings. I need a way to know if the full spec suite is being run. I think this can be determined with some fancy testing on ARGV. I can get the full list of recordings like this (or similar): FileList["spec/fixtures/vcr/**/*.yml"].reject{|file|File.directory?(file)} And then prune the list as each recording is used by the spec suite, afterwards having a list of the recordings that should be deleted. I need a hook that will run after the complete spec suite is run, before exiting the process, while still in the context of the thread, and the variable containing my list of files to delete is still accessible. Failing that I can write the list to a file, and hook in the deletion in the rake spec task. The downside of this is I currently run the test suite with `bundle exec rspec spec`, and don't really use the `rake spec` task. Aside: It would involve some (lots?) of work to get `rake spec` working in this project. Currently when I run `rake spec` there is no output at all. It appears to load the rails env, and do nothing. Any one have an idea about that? -- |7eter H. l3oling -------------- next part -------------- An HTML attachment was scrubbed... URL: