From bluesman.alex at gmail.com Mon Nov 1 06:55:59 2010 From: bluesman.alex at gmail.com (Alexey Ilyichev) Date: Mon, 1 Nov 2010 13:55:59 +0300 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: David, I got your point, however I find behavior in version 1.3.1 inconsistent. In my opinion, if I stub a method with a certain parameter value, and then call with another value, it should either delegate to original method, return nil, or throw an exception. I'd be happy with either of these. But what it actually does is delegating to the original method in the superclass, which doesn't make sense to me at all. This is what my spec results to if I comment out the fix in code: 1) 'stubbing with arguments should call derived class method_missing when args differ from what is stubbed and the method is missing' FAILED expected: "*b_method_missing*", got: "*a_method_missing*" (using ==) Diff: @@ -1,2 +1,2 @@ -*b_method_missing* +*a_method_missing* /home/alex/rspec/spec/spec/mocks/stubbing_with_arguments_spec.rb:26: 2) 'stubbing with arguments should call present method when it is defined in derived class and args differ from what is stubbed' FAILED expected: "*b_present_method*", got: "*a_method_missing*" (using ==) Diff: @@ -1,2 +1,2 @@ -*b_present_method* +*a_method_missing* /home/alex/rspec/spec/spec/mocks/stubbing_with_arguments_spec.rb:36: (see http://github.com/alexz77/rspec/blob/master/spec/spec/mocks/stubbing_with_arguments_spec.rbfor the spec code) And also, it behaved differently in 1.2.9. My original problem arisen after updating to 1.3.1 On Sun, Oct 31, 2010 at 3:14 PM, dchelimsky at gmail.com wrote: > > > On Oct 28, 7:40 am, Alexey Ilyichev wrote: > > I have made 2 examples for this and I can't figure out how to make both > > pass. Take a look please: > > > > require 'spec_helper' > > > > describe "Mock" do > > class A > > def self.method_missing(name, *args, &block) > > '*a_method_missing*' > > end > > > > def self.present_method(arg) > > '*present_method*' > > end > > end > > > > class B < A > > def self.method_missing(name, *args, &block) > > '*b_method_missing*' > > end > > end > > > > it 'should call derived class method_missing when args differ from what > is > > stubbed' do > > B.stub!(:missing_method).with(1).and_return '*stub*' > > B.missing_method(2).should == '*b_method_missing*' > > end > > > > it 'should call present_method when it is defined in parent class and > args > > differ from what is stubbed' do > > B.stub!(:present_method).with(1).and_return '*stub*' > > B.present_method(2).should == '*present_method*' > > end > > end > > > > ---------- Forwarded message ---------- > > From: Alexey Ilyichev > > Date: Thu, Oct 28, 2010 at 12:44 PM > > Subject: Issue with AR::Base descendants with certain argument > > To: rspec-us... at rubyforge.org > > > > Hi! > > > > I am trying to upgrade rspec-rails to 1.3.3, and one of my specs fails. > > > > In before :each I stub finder method like this: > > Payment.stub!(:find_by_id).with(@payment.id.to_s).and_return @payment > > Payment class is derived from AR::Base > > > > And then in one of the examples I call Payment.find_by_id((@payment.id + > > 1).to_s), and I am expecting it to return null, as it used to with 1.2.9 > > version, however it leads to an exception in active_record/base.rb. > > Analyzing the stack trace I figured that in line 115 of mock/proxy.rb > method > > find_by_id is called for ActiveRecord::Base, which is not correct. > > > > I'm not familiar with rspec internals, so I don't have an idea on where > in > > code the actual problem is. So any help would be greatly appreciated. > > The expected behaviour is that when you stub or mock a method on a > real object (we call this partial stubbing/mocking), the framework > takes over that method for the duration of the example. So the > expectation that when the wrong args are received the call is > delegated to the original object is incorrect, and making this change > would introduce potential problems for other users who count on this > behaviour. > > There is a request to add an explicit way to call to the original in > rspec-mocks-2's issue tracker: > http://github.com/rspec/rspec-mocks/issues#issue/23. > > 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 u.alberton at gmail.com Mon Nov 1 07:44:29 2010 From: u.alberton at gmail.com (Bira) Date: Mon, 1 Nov 2010 09:44:29 -0200 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: On Mon, Nov 1, 2010 at 8:55 AM, Alexey Ilyichev wrote: > David, I got your point, however I find behavior in version 1.3.1 > inconsistent. In my opinion, if I stub a method with a certain parameter > value, and then call with another value, it should either delegate to > original method, return nil, or throw an exception. I'd be happy with either > of these. But what it actually does is delegating to the original method in > the superclass, which doesn't make sense to me at all. <...> > And also, it behaved differently in 1.2.9. My original problem arisen after > updating to 1.3.1 > I have a similar problem here at work. We use a variant of the rails-settings plugin, which stores configuration settings in a DB table and relies heavily on a class-level method_missing to fetch them. So, for example, you could call Settings.welcome_message and expect to get a string back. Our specs stub specific methods from this class often, to test how the application behaves given different values for them. The stubs work properly the first time, but afterwards they somehow go missing. On 1.3.0, this caused the actual method to be called, which is incorrect, but went unnoticed as the specs still passed. On 1.3.1, due to commit 2753b492e00078c92f9fe3b9e879ea83e3536753, the "missing" stub method is now actually called on the superclass, rather than on the class itself. So we get lots of failures of the "undefined method welcome_message for ActiveRecord::Base". I tried to reproduce this on rspec alone, but there things seemed to work perfectly. So it looks like rspec-rails plays a part on this as well. I'll see if I can reproduce it there. -- Bira http://compexplicita.wordpress.com http://compexplicita.tumblr.com From dchelimsky at gmail.com Mon Nov 1 08:21:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Nov 2010 10:21:57 -0200 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: On Mon, Nov 1, 2010 at 8:55 AM, Alexey Ilyichev wrote: > David, I got your point, however I find behavior in version 1.3.1 > inconsistent. In my opinion, if I stub a method with a certain parameter > value, and then call with another value, it should either delegate to > original method, return nil, or throw an exception. In RSpec-2 it raises an informative error, so I think this is what we should do in RSpec-1. Would you like to submit a patch to make it do that? > I'd be happy with either > of these. But what it actually does is delegating to the original method in > the superclass, which doesn't make sense to me at all. This is what my spec > results to if I comment out the fix in code: > > 1) > 'stubbing with arguments should call derived class method_missing when args > differ from what is stubbed and the method is missing' FAILED > expected: "*b_method_missing*", > ???? got: "*a_method_missing*" (using ==) > > ?Diff: > @@ -1,2 +1,2 @@ > -*b_method_missing* > +*a_method_missing* > > /home/alex/rspec/spec/spec/mocks/stubbing_with_arguments_spec.rb:26: > > 2) > 'stubbing with arguments should call present method when it is defined in > derived class and args differ from what is stubbed' FAILED > expected: "*b_present_method*", > ???? got: "*a_method_missing*" (using ==) > > ?Diff: > @@ -1,2 +1,2 @@ > -*b_present_method* > +*a_method_missing* > > /home/alex/rspec/spec/spec/mocks/stubbing_with_arguments_spec.rb:36: > > (see > http://github.com/alexz77/rspec/blob/master/spec/spec/mocks/stubbing_with_arguments_spec.rb > for the spec code) > And also, it behaved differently in 1.2.9. My original problem arisen after > updating to 1.3.1 > > On Sun, Oct 31, 2010 at 3:14 PM, dchelimsky at gmail.com > wrote: >> >> >> On Oct 28, 7:40?am, Alexey Ilyichev wrote: >> > I have made 2 examples for this and I can't figure out how to make both >> > pass. Take a look please: >> > >> > require 'spec_helper' >> > >> > describe "Mock" do >> > ? class A >> > ? ? def self.method_missing(name, *args, &block) >> > ? ? ? '*a_method_missing*' >> > ? ? end >> > >> > ? ? def self.present_method(arg) >> > ? ? ? '*present_method*' >> > ? ? end >> > ? end >> > >> > ? class B < A >> > ? ? def self.method_missing(name, *args, &block) >> > ? ? ? '*b_method_missing*' >> > ? ? end >> > ? end >> > >> > ? it 'should call derived class method_missing when args differ from >> > what is >> > stubbed' do >> > ? ? B.stub!(:missing_method).with(1).and_return '*stub*' >> > ? ? B.missing_method(2).should == '*b_method_missing*' >> > ? end >> > >> > ? it 'should call present_method when it is defined in parent class and >> > args >> > differ from what is stubbed' do >> > ? ? B.stub!(:present_method).with(1).and_return '*stub*' >> > ? ? B.present_method(2).should == '*present_method*' >> > ? end >> > end >> > >> > ---------- Forwarded message ---------- >> > From: Alexey Ilyichev >> > Date: Thu, Oct 28, 2010 at 12:44 PM >> > Subject: Issue with AR::Base descendants with certain argument >> > To: rspec-us... at rubyforge.org >> > >> > Hi! >> > >> > I am trying to upgrade rspec-rails to 1.3.3, and one of my specs fails. >> > >> > In before :each I stub finder method like this: >> > Payment.stub!(:find_by_id).with(@payment.id.to_s).and_return @payment >> > Payment class is derived from AR::Base >> > >> > And then in one of the examples I call Payment.find_by_id((@payment.id + >> > 1).to_s), and I am expecting it to return null, as it used to with 1.2.9 >> > version, however it leads to an exception in active_record/base.rb. >> > Analyzing the stack trace I figured that in line 115 of mock/proxy.rb >> > method >> > find_by_id is called for ActiveRecord::Base, which is not correct. >> > >> > I'm not familiar with rspec internals, so I don't have an idea on where >> > in >> > code the actual problem is. So any help would be greatly appreciated. >> >> The expected behaviour is that when you stub or mock a method on a >> real object (we call this partial stubbing/mocking), the framework >> takes over that method for the duration of the example. So the >> expectation that when the wrong args are received the call is >> delegated to the original object is incorrect, and making this change >> would introduce potential problems for other users who count on this >> behaviour. >> >> There is a request to add an explicit way to call to the original in >> rspec-mocks-2's issue tracker: >> http://github.com/rspec/rspec-mocks/issues#issue/23. >> >> HTH, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Nov 1 08:32:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Nov 2010 10:32:53 -0200 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: On Mon, Nov 1, 2010 at 9:44 AM, Bira wrote: > On Mon, Nov 1, 2010 at 8:55 AM, Alexey Ilyichev wrote: >> David, I got your point, however I find behavior in version 1.3.1 >> inconsistent. In my opinion, if I stub a method with a certain parameter >> value, and then call with another value, it should either delegate to >> original method, return nil, or throw an exception. I'd be happy with either >> of these. But what it actually does is delegating to the original method in >> the superclass, which doesn't make sense to me at all. > > <...> > >> And also, it behaved differently in 1.2.9. My original problem arisen after >> updating to 1.3.1 >> > > I have a similar problem here at work. We use a variant of the > rails-settings plugin, which stores configuration settings in a DB > table and relies heavily on a class-level method_missing to fetch > them. So, for example, you could call Settings.welcome_message and > expect to get a string back. > > Our specs stub specific methods from this class often, to test how the > application behaves given different values for them. The stubs work > properly the first time, but afterwards they somehow go missing. Can you post a real example of this complete with spec, implementation, and failure message? Thx > On > 1.3.0, this caused the actual method to be called, which is incorrect, > but went unnoticed as the specs still passed. > > On 1.3.1, due to commit 2753b492e00078c92f9fe3b9e879ea83e3536753, the > "missing" stub method is now actually called on the superclass, rather > than on the class itself. So we get lots of failures of the "undefined > method welcome_message for ActiveRecord::Base". > > I tried to reproduce this on rspec alone, but there things seemed to > work perfectly. So it looks like rspec-rails plays a part on this as > well. I'll see if I can reproduce it there. > > > -- > Bira > http://compexplicita.wordpress.com > http://compexplicita.tumblr.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Nov 1 09:03:35 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Nov 2010 11:03:35 -0200 Subject: [rspec-users] How do I figure out which (wrong) file rspec is loading? In-Reply-To: <38fb2488-9f95-4840-b540-ca9a518b4c0b@l8g2000yql.googlegroups.com> References: <38fb2488-9f95-4840-b540-ca9a518b4c0b@l8g2000yql.googlegroups.com> Message-ID: <78515F1F-9CFF-42B1-B728-5ECDA84B7D5E@gmail.com> On Oct 31, 2010, at 11:14 PM, Curious Yogurt wrote: > I'm using Rails 3.0.1, RSpec-Rails 2.0.1 and Webrat 0.7.1. I have the > following test: > > describe PagesController do > describe "GET 'main'" do > it "should have the right title" do > get 'main' > response.should have_selector("title", :content => "My title") > end > end > end > > The HTML of pages#main checks out: it contains My Title. When I run > rspec, it gives me a failure on this test, and says it expects to find > the tag in the following line: > > www.w3.org/TR/REC-html40/loose.dtd"> > > Since this is not the file stored at pages#main, I take it that rspec > is, for some reason, loading the wrong page. How do I solve this? Or, > failing a general solution, how can I get rspec to tell me which page > it is trying to load, so that I can try to figure out why it is going > to this other page? Thanks. Controller specs don't render views unless you tell them to explicitly. Please see: http://relishapp.com/rspec/rspec-rails/v/2-0/dir/controller-specs/do-not-render-views http://relishapp.com/rspec/rspec-rails/v/2-0/dir/controller-specs/render-views HTH, David From u.alberton at gmail.com Mon Nov 1 09:25:07 2010 From: u.alberton at gmail.com (Bira) Date: Mon, 1 Nov 2010 11:25:07 -0200 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: On Mon, Nov 1, 2010 at 10:32 AM, David Chelimsky wrote: > > Can you post a real example of this complete with spec, > implementation, and failure message? > > Thx I'm trying :)! So far it's been hard to isolate. Looks like many of the failures I get in my application actually happen "far away" from the original stub statement. So we stub the class method on one point of the spec file, and then on a subsequent unrelated context it gets called by some observer code. Due to the changes from 2753b492e, the message gets dispatched to ActiveRecord::Base instead of Settings. I'll try to reproduce this within rspec-rails' own specs. -- Bira http://compexplicita.wordpress.com http://compexplicita.tumblr.com From dolzenko at gmail.com Mon Nov 1 10:03:47 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Mon, 1 Nov 2010 17:03:47 +0300 Subject: [rspec-users] How do I figure out which (wrong) file rspec is loading? In-Reply-To: <38fb2488-9f95-4840-b540-ca9a518b4c0b@l8g2000yql.googlegroups.com> References: <38fb2488-9f95-4840-b540-ca9a518b4c0b@l8g2000yql.googlegroups.com> Message-ID: Use `response.should render_template("main")` to set assertion on template that should be rendered for an action. If it fails it will print you the list of templates that got actually rendered. Also I guess you should show us your PagesController#main action, seems like what you get there is an empty response rendered with default views/layout/application.html.erb layout. On Mon, Nov 1, 2010 at 4:14 AM, Curious Yogurt wrote: > I'm using Rails 3.0.1, RSpec-Rails 2.0.1 and Webrat 0.7.1. I have the > following test: > > describe PagesController do > ?describe "GET 'main'" do > ? ?it "should have the right title" do > ? ? ?get 'main' > ? ? ?response.should have_selector("title", :content => "My title") > ? ?end > ?end > end > > The HTML of pages#main checks out: it contains My Title. When I run > rspec, it gives me a failure on this test, and says it expects to find > the tag in the following line: > > www.w3.org/TR/REC-html40/loose.dtd"> > > Since this is not the file stored at pages#main, I take it that rspec > is, for some reason, loading the wrong page. How do I solve this? Or, > failing a general solution, how can I get rspec to tell me which page > it is trying to load, so that I can try to figure out why it is going > to this other page? Thanks. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From u.alberton at gmail.com Mon Nov 1 11:02:32 2010 From: u.alberton at gmail.com (Bira) Date: Mon, 1 Nov 2010 13:02:32 -0200 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: On Mon, Nov 1, 2010 at 10:32 AM, David Chelimsky wrote: > Can you post a real example of this complete with spec, > implementation, and failure message? > > Thx This is the closest I could get with my limited knowledge of RSpec's and RSpec-rails's internals. I tried to replicate a bit of rails-settings' "fancy footwork" with method_missing, and I use a before(:all) block here to simulate what happens in my app, where a stub happens within a normal before block in one point and causes a similar failure 700 lines later. require 'spec_helper' describe "stubbing a class method" do class Settings < ActiveRecord::Base @@defaults = { "foo" => "a", "bar" => "b" } def self.method_missing(sym, *args) super rescue NoMethodError @@defaults[sym.to_s] end end before(:all) do Settings.stub!(:foo).and_return("c") end specify "works when the stub is invoked for the first time" do Settings.foo.should == "c" Settings.bar.should == "b" end specify "should not raise an error after the first time" do lambda { Settings.foo.should == "a"}.should_not raise_exception end end Running this along with RSpec-rails' other specs gives me the following failure: 1) 'stubbing a class method should not raise an error after the first time' FAILED expected no Exception, got # ./spec/spec/rails/mocks/bug_report_xxx_spec.rb:30: I'm not sure if the correct behavior would be to call the actual implementation of Settings.foo, or to give a different error message. Currently, it tries to call ActiveRecord::Base.foo . Not using a before(:all) block prevents the failure, but as I said it's only here as a "shorthand" for the complex specs I have on my app. Actually declaring a .foo class method on Settings also makes it pass, so method_missing seems to be part of the problem. On my app's specs, I found out that calling "unstub!" explicitly on an after block makes some specs pass as well. -- Bira http://compexplicita.wordpress.com http://compexplicita.tumblr.com From starempireelite at gmail.com Mon Nov 1 11:57:35 2010 From: starempireelite at gmail.com (Curious Yogurt) Date: Mon, 1 Nov 2010 08:57:35 -0700 (PDT) Subject: [rspec-users] How do I figure out which (wrong) file rspec is loading? In-Reply-To: References: <38fb2488-9f95-4840-b540-ca9a518b4c0b@l8g2000yql.googlegroups.com> Message-ID: <5767eefd-f304-45cd-a620-9461e0ed6f5d@u10g2000yqk.googlegroups.com> I solved the problem, though I didn't track down the cause. It turns out that by tearing our rspec and reinstalling it, things started to work correctly. I'm thinking it might have been some sort of version conflict. Thanks so much for the suggestions. On Nov 1, 7:03?am, Evgeniy Dolzhenko wrote: > Use `response.should render_template("main")` to set assertion on > template that should be rendered for an action. > If it fails it will print you the list of templates that got actually rendered. > > Also I guess you should show us your PagesController#main action, > seems like what you get there is an empty response rendered with > default views/layout/application.html.erb layout. > > On Mon, Nov 1, 2010 at 4:14 AM, Curious Yogurt > > > > > > > > wrote: > > I'm using Rails 3.0.1, RSpec-Rails 2.0.1 and Webrat 0.7.1. I have the > > following test: > > > describe PagesController do > > ?describe "GET 'main'" do > > ? ?it "should have the right title" do > > ? ? ?get 'main' > > ? ? ?response.should have_selector("title", :content => "My title") > > ? ?end > > ?end > > end > > > The HTML of pages#main checks out: it contains My Title. When I run > > rspec, it gives me a failure on this test, and says it expects to find > > the tag in the following line: > > > >www.w3.org/TR/REC-html40/loose.dtd"> > > > Since this is not the file stored at pages#main, I take it that rspec > > is, for some reason, loading the wrong page. How do I solve this? Or, > > failing a general solution, how can I get rspec to tell me which page > > it is trying to load, so that I can try to figure out why it is going > > to this other page? Thanks. > > _______________________________________________ > > 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 bluesman.alex at gmail.com Mon Nov 1 14:47:18 2010 From: bluesman.alex at gmail.com (Alexey Ilyichev) Date: Mon, 1 Nov 2010 21:47:18 +0300 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: > In RSpec-2 it raises an informative error, so I think this is what we > should do in RSpec-1. Would you like to submit a patch to make it do > that? > > Sure. Attaching a patch. Also submitted a pull request on github - whatever. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: patch.diff Type: text/x-patch Size: 3377 bytes Desc: not available URL: From dchelimsky at gmail.com Mon Nov 1 15:33:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Nov 2010 17:33:12 -0200 Subject: [rspec-users] Fwd: Issue with AR::Base descendants with certain argument In-Reply-To: References: Message-ID: <10CD4702-59A7-46D9-A9C2-E46C68C9B0AD@gmail.com> On Nov 1, 2010, at 4:47 PM, Alexey Ilyichev wrote: > > In RSpec-2 it raises an informative error, so I think this is what we > should do in RSpec-1. Would you like to submit a patch to make it do > that? > > > Sure. Attaching a patch. Also submitted a pull request on github - whatever. > _______________________________________________ Already received and merged the pull request. Thanks for the contribution! Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From iain at somethingelectronic.com Mon Nov 1 20:36:38 2010 From: iain at somethingelectronic.com (Iain E. Davis) Date: Mon, 1 Nov 2010 19:36:38 -0500 Subject: [rspec-users] Testing attr_accessible (and/or attr_protected) Message-ID: I've been puzzling over how to test that attr_accessible has been set for the correct columns; but the tests I've come up with so far seem to fail to fail when I expect. I came across this old message from this list: http://www.mail-archive.com/rspec-users at rubyforge.org/msg01570.html Which seemed like a plausible example, but my attempt (modeled on the example) doesn't work: describe Article, 'protected attributes' do it 'should deny mass-assignment to the user_id' do lambda { article.update_attributes(:person_id => @person.id) }.should raise_error end end The lambda doesn't raise an error, even though the attr_accessible doesn't include person_id. Where am I stumbling here? Is it my beginner's knowledge of rails, or beginner's knowledge of Ruby? Thanks, Iain From bluesman.alex at gmail.com Tue Nov 2 02:33:18 2010 From: bluesman.alex at gmail.com (Alexey Ilyichev) Date: Tue, 2 Nov 2010 09:33:18 +0300 Subject: [rspec-users] Testing attr_accessible (and/or attr_protected) In-Reply-To: References: Message-ID: An attempt to assign protected attributes leads to the warning in your log and not doing actual assignment. You can test it like this: describe Article, 'protected attributes' do it 'should deny mass-assignment to the user_id' do RAILS_DEFAULT_LOGGER.should_receive(:warn) # I ain't sure if it is actually a warning, and I would just skip this check article.update_attributes(:person_id => @person.id) article.person_id.should == nil # or whatever it is before update call end end On Tue, Nov 2, 2010 at 3:36 AM, Iain E. Davis wrote: > I've been puzzling over how to test that attr_accessible has been set > for the correct columns; but the tests I've come up with so far seem > to fail to fail when I expect. I came across this old message from > this list: > > http://www.mail-archive.com/rspec-users at rubyforge.org/msg01570.html > > Which seemed like a plausible example, but my attempt (modeled on the > example) doesn't work: > > describe Article, 'protected attributes' do > it 'should deny mass-assignment to the user_id' do > lambda { article.update_attributes(:person_id => @person.id) > }.should raise_error > end > end > > The lambda doesn't raise an error, even though the attr_accessible > doesn't include person_id. > > Where am I stumbling here? Is it my beginner's knowledge of rails, or > beginner's knowledge of Ruby? > > Thanks, > > Iain > _______________________________________________ > 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 dolzenko at gmail.com Tue Nov 2 03:13:47 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Tue, 2 Nov 2010 10:13:47 +0300 Subject: [rspec-users] Testing attr_accessible (and/or attr_protected) In-Reply-To: References: Message-ID: update_attributes [1] doesn't raise any exception when you try to assign the attribute which is protected with `attr_accessible/attr_protected` machinery (only warning in log is printed). So your options are: 1. perform update_attributes for an attribute and then assert that the attribute didn't change 2. go a bit "meta" and implement something like Shoulda allow_mass_assignment_of matcher [2] [1] http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-i-attributes%3D [2] http://github.com/thoughtbot/shoulda/blob/master/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb On Tue, Nov 2, 2010 at 3:36 AM, Iain E. Davis wrote: > I've been puzzling over how to test that attr_accessible has been set > for the correct columns; but the tests I've come up with so far seem > to fail to fail when I expect. I came across this old message from > this list: > > http://www.mail-archive.com/rspec-users at rubyforge.org/msg01570.html > > Which seemed like a plausible example, but my attempt (modeled on the > example) doesn't work: > > describe Article, 'protected attributes' do > ? ? it 'should deny mass-assignment to the user_id' do > ? ? ? lambda { article.update_attributes(:person_id => ?@person.id) > }.should raise_error > ? ? end > end > > The lambda doesn't raise an error, even though the attr_accessible > doesn't include person_id. > > Where am I stumbling here? Is it my beginner's knowledge of rails, or > beginner's knowledge of Ruby? > > Thanks, > > Iain > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From win at wincent.com Tue Nov 2 03:20:07 2010 From: win at wincent.com (Wincent Colaiuta) Date: Tue, 2 Nov 2010 08:20:07 +0100 Subject: [rspec-users] Testing attr_accessible (and/or attr_protected) In-Reply-To: References: Message-ID: On 02/11/2010, at 01:36, Iain E. Davis wrote: > I've been puzzling over how to test that attr_accessible has been set > for the correct columns; but the tests I've come up with so far seem > to fail to fail when I expect. I came across this old message from > this list: > > http://www.mail-archive.com/rspec-users at rubyforge.org/msg01570.html > > Which seemed like a plausible example, but my attempt (modeled on the > example) doesn't work: > > describe Article, 'protected attributes' do > it 'should deny mass-assignment to the user_id' do > lambda { article.update_attributes(:person_id => @person.id) > }.should raise_error > end > end > > The lambda doesn't raise an error, even though the attr_accessible > doesn't include person_id. > > Where am I stumbling here? Is it my beginner's knowledge of rails, or > beginner's knowledge of Ruby? I'm the author of that message you linked to from three years ago. Things have changed quite a bit since then. Right now, I check for this stuff using a custom matcher: http://gist.github.com/659344 Which can be used like this: article.should_not allow_mass_assignment_of(:person_id => @person.id) Or: article.should allow_mass_assignment_of(:person_id => @person.id) I'm not the only one to have written custom matchers like this though; if you Google (for "rspec custom matcher rails" or "rspec macro rails") you'll probably find a bunch for doing this, and for other stuff (like testing validations, associations etc). Cheers, Wincent From iain at somethingelectronic.com Tue Nov 2 10:39:02 2010 From: iain at somethingelectronic.com (Iain E. Davis) Date: Tue, 2 Nov 2010 09:39:02 -0500 Subject: [rspec-users] Testing attr_accessible (and/or attr_protected) In-Reply-To: References: Message-ID: I failed to mention I'm using Rails 2.3.8 and Rspec-1.3.x. I should have said that right away. On Tue, Nov 2, 2010 at 01:33, Alexey Ilyichev wrote: > An attempt to assign protected attributes leads to the warning in your log Hmm... Maybe I should actually look at the log once in a while... > ??? article.update_attributes(:person_id => ?@person.id) > ??? article.person_id.should == nil # or whatever it is before update call On Tue, Nov 2, 2010 at 02:13, Evgeniy Dolzhenko wrote: > 1. perform update_attributes for an attribute and then assert that the attribute didn't change Buh. I wish I had thought of that. Seems rather obvious now...I confess I was expecting something esoteric and thus didn't stop to think if there was a simple solution. :) To me, checking whether the attribute changed is more straight-forward than implementing a custom matcher, at least at my current level of experience (novice) with rails and rspec. I suppose I need to be careful that the attribute change was rejected for some other reason (bad data, for example). But that's true of any example/test. On Tue, Nov 2, 2010 at 02:20, Wincent Colaiuta wrote: > I'm the author of that message you linked to from three years ago. Things have changed quite > a bit since then. I suspected so! I guess I should have clued in when I didn't find anything about raising an error in the docs for update_attribute. Oh! In the same vein, when looking at the docs/source for update_attribute, I formed the expectation that update_attribute(s) would return false if it failed. My new guess is that it returns false if it fails to save the model...irregardless of whether the attribute changes? Thank you Alexey, Evgeniy, and Wincent! Iain From rick.denatale at gmail.com Tue Nov 2 11:31:32 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 2 Nov 2010 11:31:32 -0400 Subject: [rspec-users] Testing attr_accessible (and/or attr_protected) In-Reply-To: References: Message-ID: On Tue, Nov 2, 2010 at 10:39 AM, Iain E. Davis wrote: > I failed to mention I'm using Rails 2.3.8 and Rspec-1.3.x. I should > have said that right away. > > On Tue, Nov 2, 2010 at 01:33, Alexey Ilyichev wrote: >> An attempt to assign protected attributes leads to the warning in your log > Hmm... Maybe I should actually look at the log once in a while... > >> ??? article.update_attributes(:person_id => ?@person.id) >> ??? article.person_id.should == nil # or whatever it is before update call > > On Tue, Nov 2, 2010 at 02:13, Evgeniy Dolzhenko wrote: >> 1. perform update_attributes for an attribute and then assert that the attribute didn't change > > Buh. I wish I had thought of that. Seems rather obvious now...I > confess I was expecting something esoteric and thus didn't stop to > think if there was a simple solution. :) > > To me, checking whether the attribute changed is more straight-forward > than implementing a custom matcher, at least at my current level of > experience (novice) with rails and rspec. > > I suppose I need to be careful that the attribute change was rejected > for some other reason (bad data, for example). But that's true of any > example/test. Note that Evgeniy's two suggestions: 1. perform update_attributes for an attribute and then assert that the attribute didn't change 2. go a bit "meta" and implement something like Shoulda allow_mass_assignment_of matcher Represent two different philosophies. The first, feels to me more like you are specifying/testing the behavior of ActiveRecord rather than your own code. It indirectly tests whether or not attr_accessible/attr_protected is in effect by observing the effect on one of the methods which are effected by those 'declarative' methods. In general I prefer to concentrate on specifying/testing the code I write. The second approach is more compatible with that philosophy. I trust that ActiveRecord correctly implements protected attributes, what I want to prove is that my code is using them. This is independent of whether or not a custom matcher is used. For example Wincent's implementation of the matcher takes the first approach, while the shoulda macro instead examines whether or not the model has an attribute set as accessible directly. Now the shoulda approach is dependent a bit on the implementation in activerecord, which is a reason to look for such plugins before trying to write them yourself, an open-source plugin has more eyes on it and will probably adapt to any changes before you run into them yourself. And as Wincent points out, you don't usually need to do such plumbing yourself, there are lots of RSpec compatible matchers (including the Shoulda matchers) freely available. -- Rick DeNatale Help fund my talk at Ruby Conf 2010:http://pledgie.com/campaigns/13677 Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From dolzenko at gmail.com Tue Nov 2 11:49:40 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Tue, 2 Nov 2010 18:49:40 +0300 Subject: [rspec-users] Testing attr_accessible (and/or attr_protected) In-Reply-To: References: Message-ID: > I suppose I need to be careful that the attribute change was rejected > for some other reason (bad data, for example). But that's true of any > example/test. Good catch, that's why I think the Shoulda approach makes sense (since otherwise you're duplicating the Rails test suite which is supposed to specify/exercise that functionality already) From iain at somethingelectronic.com Tue Nov 2 12:55:51 2010 From: iain at somethingelectronic.com (Iain E. Davis) Date: Tue, 2 Nov 2010 11:55:51 -0500 Subject: [rspec-users] Testing attr_accessible (and/or attr_protected) In-Reply-To: References: Message-ID: > To me, checking whether the attribute changed is more straight-forward > than implementing a custom matcher, at least at my current level of > experience (novice) with rails and rspec. Okay, so that didn't last very long. Suddenly, I was swimming in very repetitive code in my _spec files...I could feel my eyes closing from the ennui... In light of that experience and the excellent points that Rick made, I think I'll go hunt down a custom matcher that checks that I actually set the planned attr_accessible, rather than doing it the way I just did it! I'll start by looking at the link to Shoulda's matcher, kindly provided by Evgeniy earlier. It works the other way, but the repetition was driving me crazy, and as Rick says: > It indirectly tests whether or not attr_accessible/attr_protected is in effect by observing the effect on > one of the methods which are effected by those 'declarative' methods. I agree...I was at some level sort of aware of that but didn't know enough (yet) to overcome it. :) >?The second approach is more compatible with that philosophy. I trust that ActiveRecord correctly > implements protected attributes, what I want to prove is that my code is using them. Exactly. The way I've begun to think is "...if I add a line[1] of code to do X, will my test flag a failure if that line is not there?". That way I'm writing tests that insure that the code _I've_ (or my team has) written is correct, and not testing Rails/Authlogic/Rspec/etc. themselves. :) Thanks again! Iain [1] "Line" is a bit misleading, since I could leave off a _portion_ of a line in the case of attr_accessible and similar pieces. From lists at ruby-forum.com Tue Nov 2 14:54:33 2010 From: lists at ruby-forum.com (Mack T.) Date: Tue, 02 Nov 2010 19:54:33 +0100 Subject: [rspec-users] Rspec-2 around/before(:all) hooks Message-ID: <6d8c531b003abdb23751edf98e20dd76@ruby-forum.com> Rspec-2 around/before(:all) hooks I'm trying to create several model instances before all of our tests are run. I'm having trouble defining the behavior in my Rspec.configure block. I've tried before(:all) and around(:all), but to no avail. before(:all) successfully creates the models, but it appears that everything in the block passed is rolled back before the test runs: # spec_helper.rb config.before(:all) do @person = Person.create(:name => 'not here!') end # person_spec.rb describe Person it do p Person.where(:short_name => 'not here!').first #=> nil p @person #=> @person.reload #=> Error: Couldn't find Person with ID=1050608284 end end It seems that around(:all) is not supported, either. Is that correct? This code in the block passed to configure results in a nil.<< error: # spec_helper.rb config.around(:all) do puts "hai" yield puts "bai" end I'm running rspec-2.0.1 and rails-3.0.0. Is there a preferred way to do this that I'm missing? Thanks in advance! -- Posted via http://www.ruby-forum.com/. From node.js99 at gmail.com Tue Nov 2 21:55:18 2010 From: node.js99 at gmail.com (Nadal) Date: Tue, 2 Nov 2010 18:55:18 -0700 (PDT) Subject: [rspec-users] Not sure why let is not doing the same thing as traditional test Message-ID: Here is my test which passes. before do @page = Factory(:page) @note = Factory(:note, :page => @page, :title => 'super cool') end it 'has size 1' do @page.notes.size.should == 1 end I read rspec book and wanted to use let. Here is my implementation. And it fails let(:page) { Factory(:page) } let(:note) { Factory(:note, :page => page, :title => 'super cool') } it 'has size 1' do page.notes.size.should == 1 end In the log I noticed that when I switched to using let then no note record is being created. Here is relevant gem file group :development, :test do gem 'mongrel' gem 'capistrano', ">= 2.5.19" gem 'capistrano-ext' gem "factory_girl_rails" gem "database_cleaner" gem "shoulda" gem "rspec-rails", ">= 2.0.1" gem "cucumber-rails", ">= 0.3.2" gem "capybara", "= 0.4.0" gem "launchy" gem "redgreen" gem "faker" gem "mongrel" end Is let lazy? It seems since I am not using note the record is not being created. The book said that output is memoized. Nothing more than that. From jko170 at gmail.com Tue Nov 2 22:13:18 2010 From: jko170 at gmail.com (Justin Ko) Date: Tue, 2 Nov 2010 19:13:18 -0700 (PDT) Subject: [rspec-users] Not sure why let is not doing the same thing as traditional test In-Reply-To: References: Message-ID: <5af132fd-77e7-49c2-a2ff-5ff1cc3d2946@v16g2000yqn.googlegroups.com> I'm under the weather so I won't be able to give you a thorough answer. #let - The block is executed when you call it. #let! - The block is "wrapped" in a before(:each) filter. So, you want to use #let! On Nov 2, 7:55?pm, Nadal wrote: > Here is my test which passes. > > ? ?before do > ? ? ? ? @page = Factory(:page) > ? ? ? ? @note = Factory(:note, :page => @page, :title => 'super cool') > ? ? ? end > ? ? ? it 'has size 1' do > ? ? ? ? @page.notes.size.should == 1 > ? ? ? end > > I read rspec book and wanted to use let. Here is my implementation. > And it fails > > ? ? ?let(:page) { Factory(:page) } > ? ? ? let(:note) { Factory(:note, :page => page, :title => 'super > cool') } > ? ? ? it 'has size 1' do > ? ? ? ? page.notes.size.should == 1 > ? ? ? end > > In the log I noticed that when I switched to using let then no note > record is being created. > > Here is relevant gem file > > group :development, :test do > ? gem 'mongrel' > ? gem 'capistrano', ">= 2.5.19" > ? gem 'capistrano-ext' > > ? gem "factory_girl_rails" > > ? gem "database_cleaner" > ? gem "shoulda" > > ? gem "rspec-rails", ">= 2.0.1" > ? gem "cucumber-rails", ">= 0.3.2" > ? gem "capybara", "= 0.4.0" > ? gem "launchy" > ? gem "redgreen" > ? gem "faker" > ? gem "mongrel" > end > > Is let lazy? It seems since I am not using note the record is not > being created. > > The book said that output is memoized. Nothing more than that. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From akleak at gmail.com Tue Nov 2 23:59:48 2010 From: akleak at gmail.com (Arco) Date: Tue, 2 Nov 2010 20:59:48 -0700 (PDT) Subject: [rspec-users] Hiding Test-Unit Generators ?? Message-ID: <2790a010-77e3-4c31-aaab-4213f436f588@r29g2000yqj.googlegroups.com> Just curious if this was ever fixed?? On Jul 13, 2010, at 8:49 PM, Arco wrote: > In a recent blog post, David wrote: > Because RSpec is the test framework of record, Rails doesn?t know to > hide the test_unit generators. If you want to hide them, just add this > to one of your config files: > Rails::Generators.hide_namespace("test_unit") > Where exactly should this statement go?? I tried a number of > alternatives and wasn't able to make it work. Turns out this doesn't work as expected. I filed http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5111 and am told it will be addressed in Rails proper. I'll update the blog post when I have more solid information. Sorry for the confusion. Cheers, David From dchelimsky at gmail.com Wed Nov 3 00:37:35 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 2 Nov 2010 23:37:35 -0500 Subject: [rspec-users] Rspec-2 around/before(:all) hooks In-Reply-To: <6d8c531b003abdb23751edf98e20dd76@ruby-forum.com> References: <6d8c531b003abdb23751edf98e20dd76@ruby-forum.com> Message-ID: <8EA256ED-C542-40C4-B84A-F36279C37138@gmail.com> On Nov 2, 2010, at 1:54 PM, Mack T. wrote: > Rspec-2 around/before(:all) hooks > > I'm trying to create several model instances before all of our tests are > run. I'm having trouble defining the behavior in my Rspec.configure > block. I've tried before(:all) and around(:all), but to no avail. > > before(:all) successfully creates the models, but it appears that > everything in the block passed is rolled back before the test runs: > > # spec_helper.rb > config.before(:all) do > @person = Person.create(:name => 'not here!') > end > > # person_spec.rb > describe Person > it do > p Person.where(:short_name => 'not here!').first #=> nil > p @person #=> > @person.reload #=> Error: Couldn't find Person with ID=1050608284 > end > end > > It seems that around(:all) is not supported, either. Is that correct? > This code in the block passed to configure results in a nil.<< error: > > # spec_helper.rb > config.around(:all) do > puts "hai" > yield > puts "bai" > end > > I'm running rspec-2.0.1 and rails-3.0.0. Is there a preferred way to do > this that I'm missing? Thanks in advance! A few things: 1. I can't reproduce what you're describing. I get the same person object for all three lines in the example (adding a 'p' to the last line). Not sure why that would be. 2. around(:all) is not supported (needs a better error message), but before(:all) should work. 3. What you're trying to do is a bit unusual. By default, each example is run in a transaction which is rolled back at the end of the example. This keeps all of the examples isolated from each other, which is a very desirable outcome. If you use before(:all), the created object will remain in the database, so it's up to you to clean it up yourself instead of relying on ActiveRecord to do it for you. Also, before(:all) (or before(:each)) in the configure block in spec_helper adds that to every example group. i.e. it's the same as declaring that block in each group. If you're looking to do this once per run, use before(:suite). HTH, David From tjtuom at utu.fi Wed Nov 3 02:08:40 2010 From: tjtuom at utu.fi (Toni Tuominen) Date: Wed, 3 Nov 2010 08:08:40 +0200 Subject: [rspec-users] Rake task for focused examples Message-ID: Hi, Is it possible to make a rake task to run examples with a certain filter on? In this case I want to run rake spec:focused and run only the examples with :focus => true. - Toni From node.js99 at gmail.com Wed Nov 3 04:52:51 2010 From: node.js99 at gmail.com (Nadal) Date: Wed, 3 Nov 2010 01:52:51 -0700 (PDT) Subject: [rspec-users] Not sure why let is not doing the same thing as traditional test In-Reply-To: <5af132fd-77e7-49c2-a2ff-5ff1cc3d2946@v16g2000yqn.googlegroups.com> References: <5af132fd-77e7-49c2-a2ff-5ff1cc3d2946@v16g2000yqn.googlegroups.com> Message-ID: That worked. Thanks a lot. Wish you speedy recovery Justin. take care. On Nov 2, 10:13?pm, Justin Ko wrote: > I'm under the weather so I won't be able to give you a thorough > answer. > > #let - The block is executed when you call it. > #let! - The block is "wrapped" in a before(:each) filter. > > So, you want to use #let! > > On Nov 2, 7:55?pm, Nadal wrote: > > > > > > > > > Here is my test which passes. > > > ? ?before do > > ? ? ? ? @page = Factory(:page) > > ? ? ? ? @note = Factory(:note, :page => @page, :title => 'super cool') > > ? ? ? end > > ? ? ? it 'has size 1' do > > ? ? ? ? @page.notes.size.should == 1 > > ? ? ? end > > > I read rspec book and wanted to use let. Here is my implementation. > > And it fails > > > ? ? ?let(:page) { Factory(:page) } > > ? ? ? let(:note) { Factory(:note, :page => page, :title => 'super > > cool') } > > ? ? ? it 'has size 1' do > > ? ? ? ? page.notes.size.should == 1 > > ? ? ? end > > > In the log I noticed that when I switched to using let then no note > > record is being created. > > > Here is relevant gem file > > > group :development, :test do > > ? gem 'mongrel' > > ? gem 'capistrano', ">= 2.5.19" > > ? gem 'capistrano-ext' > > > ? gem "factory_girl_rails" > > > ? gem "database_cleaner" > > ? gem "shoulda" > > > ? gem "rspec-rails", ">= 2.0.1" > > ? gem "cucumber-rails", ">= 0.3.2" > > ? gem "capybara", "= 0.4.0" > > ? gem "launchy" > > ? gem "redgreen" > > ? gem "faker" > > ? gem "mongrel" > > end > > > Is let lazy? It seems since I am not using note the record is not > > being created. > > > The book said that output is memoized. Nothing more than that. > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Nov 3 08:27:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Nov 2010 07:27:58 -0500 Subject: [rspec-users] Hiding Test-Unit Generators ?? In-Reply-To: <2790a010-77e3-4c31-aaab-4213f436f588@r29g2000yqj.googlegroups.com> References: <2790a010-77e3-4c31-aaab-4213f436f588@r29g2000yqj.googlegroups.com> Message-ID: On Nov 2, 2010, at 10:59 PM, Arco wrote: > Just curious if this was ever fixed?? The rails ticket (linked below) says it is still open. If you want to stay informed about it, just go to the ticket and click "Watch Ticket". You'll get an email any time it is updated. Cheers, David > On Jul 13, 2010, at 8:49 PM, Arco wrote: > >> In a recent blog post, David wrote: > >> Because RSpec is the test framework of record, Rails doesn?t know to >> hide the test_unit generators. If you want to hide them, just add this >> to one of your config files: > >> Rails::Generators.hide_namespace("test_unit") > >> Where exactly should this statement go?? I tried a number of >> alternatives and wasn't able to make it work. > > Turns out this doesn't work as expected. I filed > http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5111 > and am told it will be addressed in Rails proper. > > I'll update the blog post when I have more solid information. > > Sorry for the confusion. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Nov 3 08:40:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Nov 2010 07:40:12 -0500 Subject: [rspec-users] Rake task for focused examples In-Reply-To: References: Message-ID: On Nov 3, 2010, at 1:08 AM, Toni Tuominen wrote: > Hi, > > Is it possible to make a rake task to run examples with a certain > filter on? In this case I want to run rake spec:focused and run only > the examples with :focus => true. Not yet. Right now (2.0.1) the only way to define filters is in an RSpec.configure block. I do it like the first example on http://relishapp.com/rspec/rspec-core/v/2-0/dir/filtering/run-all-when-everything-filtered. If there are any examples or groups with ":focus => true", only those get run. If there are not, then everything gets run. There is an open issue/pull request to add command line support for "tags" similar to that in Cucumber. So if you have: describe "foo", :fast => true do it("does something"){ ... } end Then you can do this on the command line: rspec spec --tags fast I'm planning to include this in the next minor release (2.1.0). Once that's in place you can set up rake tasks like this: RSpec::Core::RakeTask.new(:fast) do |t| t.rspec_options = "--tags fast" end Take a look at the pull request (https://github.com/rspec/rspec-core/pull/205) to see all the options that will be available once this in place. It's going to be pretty powerful. Cheers, David From dchelimsky at gmail.com Wed Nov 3 08:40:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Nov 2010 07:40:12 -0500 Subject: [rspec-users] Rake task for focused examples In-Reply-To: References: Message-ID: On Nov 3, 2010, at 1:08 AM, Toni Tuominen wrote: > Hi, > > Is it possible to make a rake task to run examples with a certain > filter on? In this case I want to run rake spec:focused and run only > the examples with :focus => true. Not yet. Right now (2.0.1) the only way to define filters is in an RSpec.configure block. I do it like the first example on http://relishapp.com/rspec/rspec-core/v/2-0/dir/filtering/run-all-when-everything-filtered. If there are any examples or groups with ":focus => true", only those get run. If there are not, then everything gets run. There is an open issue/pull request to add command line support for "tags" similar to that in Cucumber. So if you have: describe "foo", :fast => true do it("does something"){ ... } end Then you can do this on the command line: rspec spec --tags fast I'm planning to include this in the next minor release (2.1.0). Once that's in place you can set up rake tasks like this: RSpec::Core::RakeTask.new(:fast) do |t| t.rspec_options = "--tags fast" end Take a look at the pull request (https://github.com/rspec/rspec-core/pull/205) to see all the options that will be available once this in place. It's going to be pretty powerful. Cheers, David From tjtuom at utu.fi Wed Nov 3 10:12:46 2010 From: tjtuom at utu.fi (Toni Tuominen) Date: Wed, 3 Nov 2010 16:12:46 +0200 Subject: [rspec-users] Rake task for focused examples In-Reply-To: References: Message-ID: Ok, thanks. That functionality is enough for me for now at least. - Toni On Wed, Nov 3, 2010 at 2:40 PM, David Chelimsky wrote: > On Nov 3, 2010, at 1:08 AM, Toni Tuominen wrote: > >> Hi, >> >> Is it possible to make a rake task to run examples with a certain >> filter on? In this case I want to run rake spec:focused and run only >> the examples with :focus => true. > > Not yet. Right now (2.0.1) the only way to define filters is in an RSpec.configure block. I do it like the first example on http://relishapp.com/rspec/rspec-core/v/2-0/dir/filtering/run-all-when-everything-filtered. If there are any examples or groups with ":focus => true", only those get run. If there are not, then everything gets run. > > There is an open issue/pull request to add command line support for "tags" similar to that in Cucumber. So if you have: > > ?describe "foo", :fast => true do > ? ?it("does something"){ ... } > ?end > > Then you can do this on the command line: > > ?rspec spec --tags fast > > I'm planning to include this in the next minor release (2.1.0). Once that's in place you can set up rake tasks like this: > > ?RSpec::Core::RakeTask.new(:fast) do |t| > ? ?t.rspec_options = "--tags fast" > ?end > > Take a look at the pull request (https://github.com/rspec/rspec-core/pull/205) to see all the options that will be available once this in place. It's going to be pretty powerful. > > Cheers, > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lailsonbm at gmail.com Wed Nov 3 10:28:35 2010 From: lailsonbm at gmail.com (Lailson Bandeira) Date: Wed, 3 Nov 2010 11:28:35 -0300 Subject: [rspec-users] Rake task for focused examples In-Reply-To: References: Message-ID: Humm, I did not know about the run_all_when_everything_filtered option. It's very useful for me? -- LAILSON BANDEIRA http://lailsonbandeira.com/ On Wed, Nov 3, 2010 at 11:12 AM, Toni Tuominen wrote: > Ok, thanks. That functionality is enough for me for now at least. > > - Toni > > On Wed, Nov 3, 2010 at 2:40 PM, David Chelimsky > wrote: > > On Nov 3, 2010, at 1:08 AM, Toni Tuominen wrote: > > > >> Hi, > >> > >> Is it possible to make a rake task to run examples with a certain > >> filter on? In this case I want to run rake spec:focused and run only > >> the examples with :focus => true. > > > > Not yet. Right now (2.0.1) the only way to define filters is in an > RSpec.configure block. I do it like the first example on > http://relishapp.com/rspec/rspec-core/v/2-0/dir/filtering/run-all-when-everything-filtered. > If there are any examples or groups with ":focus => true", only those get > run. If there are not, then everything gets run. > > > > There is an open issue/pull request to add command line support for > "tags" similar to that in Cucumber. So if you have: > > > > describe "foo", :fast => true do > > it("does something"){ ... } > > end > > > > Then you can do this on the command line: > > > > rspec spec --tags fast > > > > I'm planning to include this in the next minor release (2.1.0). Once > that's in place you can set up rake tasks like this: > > > > RSpec::Core::RakeTask.new(:fast) do |t| > > t.rspec_options = "--tags fast" > > end > > > > Take a look at the pull request ( > https://github.com/rspec/rspec-core/pull/205) to see all the options that > will be available once this in place. It's going to be pretty powerful. > > > > Cheers, > > David > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Nov 3 13:04:08 2010 From: lists at ruby-forum.com (Jon Kruger) Date: Wed, 03 Nov 2010 18:04:08 +0100 Subject: [rspec-users] Cucumber - before scenario outline, but just one time Message-ID: <4b8a086ebd2781848814c821f6c737e0@ruby-forum.com> If I have a Background section and a Scenario Outline, the Background runs once before each example in the scenario outline. Is there a hook that before the Scenario Outline, but not before each example? Jon -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Nov 3 14:01:27 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Nov 2010 13:01:27 -0500 Subject: [rspec-users] Cucumber - before scenario outline, but just one time In-Reply-To: <4b8a086ebd2781848814c821f6c737e0@ruby-forum.com> References: <4b8a086ebd2781848814c821f6c737e0@ruby-forum.com> Message-ID: On Nov 3, 2010, at 12:04 PM, Jon Kruger wrote: > If I have a Background section and a Scenario Outline, the Background > runs once before each example in the scenario outline. Is there a hook > that before the Scenario Outline, but not before each example? Please post Cucumber questions to the Cucumber google group: http://groups.google.com/group/cukes. Cheers, David From lists at ruby-forum.com Wed Nov 3 14:07:25 2010 From: lists at ruby-forum.com (Mack T.) Date: Wed, 03 Nov 2010 19:07:25 +0100 Subject: [rspec-users] Rspec-2 around/before(:all) hooks In-Reply-To: <6d8c531b003abdb23751edf98e20dd76@ruby-forum.com> References: <6d8c531b003abdb23751edf98e20dd76@ruby-forum.com> Message-ID: <869cf9f1d45f1ff96cb36f6ca38e498e@ruby-forum.com> I should have mentioned this before, but I'm using fixtures in these specs. When I took all of the fixtures out, I get the same before(:all) behavior that you got. With them in, it seems whatever happens in the before(:all) is rolled back before any examples run. Can you reproduce that behavior with fixtures included? What I'm really trying to accomplish here is faster examples that don't have to repeatedly build the same model relationships. Doubles won't work, since I want to make sure models save to the database correctly and most relationships have foreign key constraints. It would be great to establish a known setup of models that all examples can assume exists. I realize that I'll have to manually undo whatever changes I do in the before block, but that's a price I'm willing to pay. Examples should remain isolated if the database is restored to the same state it was when they started. before(:suite) is looking promising. The instance variables aren't available as they are in before(:all), but that's simple to work around. Thank you so much for your help! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 3 14:22:40 2010 From: lists at ruby-forum.com (Mack T.) Date: Wed, 03 Nov 2010 19:22:40 +0100 Subject: [rspec-users] Rspec-2 around/before(:all) hooks In-Reply-To: <6d8c531b003abdb23751edf98e20dd76@ruby-forum.com> References: <6d8c531b003abdb23751edf98e20dd76@ruby-forum.com> Message-ID: <7de9b6d877069aa466e11bb151421610@ruby-forum.com> Any ideas on how to create models in the before(:suite) block in a transaction, then not commit that transaction and roll it back in the after(:suite) block? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 3 15:57:32 2010 From: lists at ruby-forum.com (Jon Kruger) Date: Wed, 03 Nov 2010 20:57:32 +0100 Subject: [rspec-users] Cucumber - before scenario outline, but just one time In-Reply-To: <4b8a086ebd2781848814c821f6c737e0@ruby-forum.com> References: <4b8a086ebd2781848814c821f6c737e0@ruby-forum.com> Message-ID: <4d06cd233b7daefafa5a61ebc0fd16e5@ruby-forum.com> Didn't know there was one. I'll do that, thanks. -- Posted via http://www.ruby-forum.com/. From rhett at detailedbalance.net Wed Nov 3 18:49:38 2010 From: rhett at detailedbalance.net (Rhett Sutphin) Date: Wed, 3 Nov 2010 17:49:38 -0500 Subject: [rspec-users] Constant resolution fails in describes inside of modules using rspec 2 on ruby 1.9.1 Message-ID: Hi, I've converted a couple of my smaller libraries' spec suites to rspec 2 with no trouble. (I'm enjoying the new version -- thanks to all involved.) I'm trying to convert one a larger suite now and I've run into two problems on ruby 1.9.1 (but not 1.8.7) related to constant resolution in describes inside of modules. One of the problems haven't been able to reproduce in a simple test case, but the other one I have. Here's the reproducible one: # ---- baz_spec.rb module Foo module Quux class Baz def name "noise" end end end end module Foo::Quux describe Baz do it "has a name" do Baz.new.name.should == 'noise' end end end # ---- This spec passes on rspec 2.0.1 and 1.3.0 on Ruby 1.8.7: ---- $ ruby -v ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0] $ spec _1.3.0_ baz_spec.rb . Finished in 0.002011 seconds 1 example, 0 failures $ rspec _2.0.1_ baz_spec.rb . Finished in 0.00077 seconds 1 example, 0 failures ---- It also passes on rspec 1.3.0 on Ruby 1.9.1. On rspec 2.0.1, it fails: ---- $ ruby -v ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.3.0] $ spec _1.3.0_ baz_spec.rb . Finished in 0.020187 seconds 1 example, 0 failures $ rspec _2.0.1_ baz_spec.rb F Failures: 1) Foo::Quux::Baz has a name Failure/Error: Baz.new.name.should == 'noise' uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Baz # ./baz_spec.rb:14:in `block (2 levels) in ' Finished in 0.00159 seconds 1 example, 1 failure ---- Is this a bug or expected behavior in rspec 2? I'll file an issue if it's a bug -- this would be against rspec-core, correct? Thanks, Rhett From jko170 at gmail.com Wed Nov 3 19:59:15 2010 From: jko170 at gmail.com (Justin Ko) Date: Wed, 3 Nov 2010 16:59:15 -0700 (PDT) Subject: [rspec-users] Constant resolution fails in describes inside of modules using rspec 2 on ruby 1.9.1 In-Reply-To: References: Message-ID: Use ruby 1.9.2 - sorry on my iphone On Nov 3, 4:49?pm, Rhett Sutphin wrote: > Hi, > > I've converted a couple of my smaller libraries' spec suites to rspec 2 with no trouble. ?(I'm enjoying the new version -- thanks to all involved.) ?I'm trying to convert one a larger suite now and I've run into two problems on ruby 1.9.1 (but not 1.8.7) related to constant resolution in describes inside of modules. ?One of the problems haven't been able to reproduce in a simple test case, but the other one I have. ?Here's the reproducible one: > > # ---- baz_spec.rb > > module Foo > ?module Quux > ? ?class Baz > ? ? ?def name > ? ? ? ?"noise" > ? ? ?end > ? ?end > ?end > end > > module Foo::Quux > ?describe Baz do > ? ?it "has a name" do > ? ? ?Baz.new.name.should == 'noise' > ? ?end > ?end > end > > # ---- > > This spec passes on rspec 2.0.1 and 1.3.0 on Ruby 1.8.7: > > ---- > $ ruby -v > ruby1.8.7(2010-08-16 patchlevel 302) [i686-darwin10.4.0] > $ spec _1.3.0_ baz_spec.rb > . > > Finished in0.002011seconds > > 1 example, 0 failures > $ rspec _2.0.1_ baz_spec.rb > . > > Finished in 0.00077 seconds > 1 example, 0 failures > ---- > > It also passes on rspec 1.3.0 on Ruby 1.9.1. ?On rspec 2.0.1, it fails: > > ---- > $ ruby -v > ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.3.0] > $ spec _1.3.0_ baz_spec.rb > . > > Finished in0.020187seconds > > 1 example, 0 failures > $ rspec _2.0.1_ baz_spec.rb > F > > Failures: > ?1) Foo::Quux::Baz has a name > ? ? Failure/Error: Baz.new.name.should == 'noise' > ? ? uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Baz > ? ? # ./baz_spec.rb:14:in `block (2 levels) in ' > > Finished in 0.00159 seconds > 1 example, 1 failure > ---- > > Is this a bug or expected behavior in rspec 2? ?I'll file an issue if it's a bug -- this would be against rspec-core, correct? > > Thanks, > Rhett > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From myron.marston at gmail.com Thu Nov 4 13:29:15 2010 From: myron.marston at gmail.com (Myron Marston) Date: Thu, 4 Nov 2010 10:29:15 -0700 (PDT) Subject: [rspec-users] Constant resolution fails in describes inside of modules using rspec 2 on ruby 1.9.1 In-Reply-To: References: Message-ID: <3cdd0b97-4bfc-46e6-836d-9a65b72a36af@g28g2000pra.googlegroups.com> You can reorganize it a bit in a way that will work on 1.8.7, 1.9.1 and 1.9.2: module Foo module Quux class Baz def name "noise" end end end end describe Foo::Quux::Baz do it "has a name" do described_class.new.name.should == 'noise' end end From jarmo.p at gmail.com Thu Nov 4 15:21:58 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Thu, 4 Nov 2010 12:21:58 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 Message-ID: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> Hello! I'm trying to migrate my scripts from RSpec 1.3.0 to 2.0.1 having some issues so far. 1) I don't like is that ".rspec" has to be in the working directory and cannot be anymore in "spec". Okay, i can issue "mv spec/ spec.opts .rspec" in my projects, but why isn't it supported? 2) If there is somewhere "require 'spec'" in existing specs or spec_helper or anywhere then test will not be run and this will be shown instead: Finished in 0 seconds 0 examples, 0 failures It is also possible to reproduce it like this from command line: rspec -rspec blah_spec.rb 3) Why does html formatter snippet show always failing line as: raise(RSpec::Expectations::ExpectationNotMetError.new(message)) in 1.x it would show the failing line in the spec file instead... is this a bug? 4) In 1.x i modified ExampleGroup's description in my html formatter to have some additional information in it like timestamp. I did it in example_group_started where the passed variable example_group was an instance of the ExampleGroup. In 2.x this is just a class name. How can i accomplish the similar functionality? 5) I don't understand how to use multiple formatters together. In RSpec 1.x it is possible to use multiple formatters like this: spec --format nested --format html:output/blah.html In RSpec 2.x it seems to me that only the last --format is used. The command below: rspec -f html -f d blah_spec.rb Uses only nested formatter. In RSpec 1.x you had to specify the file path like this: rspec -f html:path_to_output But it seems that in 2.x you have to use --out for that which overrides all the output of course. And on top of if there is everywhere used a term "formatter" in RSpec::Core::Configuration, but "formatters" (in plural) in RSpec::Core::Reporter. It's constructor also allows to pass multiple formatters into it. I'd like to use two formatters together - documentation and html. Documentation would be helpful for faster feedback and for an indication of end of the testrun on the command line, but (custom) html formatter would include more information for better troubleshooting. I managed to do that currently by little monkey-patching and manual coding: module RSpec module Core class Configuration def reporter=(reporter) @reporter = reporter end public :built_in_formatter end end end and in spec_helper or somewhere: config = RSpec.configuration config.color_enabled = true documentation_formatter = config.built_in_formatter(:documentation).new(config.output) @@html_formatter = MyHtmlFormatter.new("blah/index.html") # it takes file path as a string due to archival and file in use needs config.reporter = RSpec::Core::Reporter.new(documentation_formatter, @@html_formatter) Is there some easier/more normal way to do this? Does this mean that RSpec 2 is meant to be used with only 1 formatter simultaneously? From jarmo.p at gmail.com Thu Nov 4 15:52:46 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Thu, 4 Nov 2010 12:52:46 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> Message-ID: <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> On Nov 4, 9:21?pm, Jarmo Pertman wrote: > 3) Why does html formatter snippet show always failing line as: > ? raise(RSpec::Expectations::ExpectationNotMetError.new(message)) > > in 1.x it would show the failing line in the spec file instead... is > this a bug? I cannot reproduce this problem currently with standard html formatter although i don't do anything with snippet extractor in my custom html formatter. I need to investigate why the problem happens now and then. Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net From jarmo.p at gmail.com Thu Nov 4 16:37:33 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Thu, 4 Nov 2010 13:37:33 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> Message-ID: <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> There seems to be also a problem when using RCov raketask - it doesn't seem to load RSpec. Consider the following project structure: # Rakefile require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| end RSpec::Core::RakeTask.new(:rcov) do |spec| spec.rcov = true end # lib/my_lib.rb class MyLib end # spec/my_lib_spec.rb require "lib/my_lib" describe "should work" do it "doesn't" do MyLib.new.should be end end Now, when executing `rake spec` everything works - RSpec itself gets loaded automatically. When executing `rake rcov` on the other hand then this will be the output: C:\Users\jarmo\Desktop\minu\projects\Ruby\blah>rake rcov (in C:/Users/jarmo/Desktop/minu/projects/Ruby/blah) c:/ruby/bin/ruby.exe -S rcov -Ispec "./spec/my_lib_spec.rb" ./spec/my_lib_spec.rb:1: undefined method `describe' for main:Object (NoMethodError) from c:/ruby/lib/ruby/gems/1.8/gems/rcov-0.9.8/bin/rcov:511:in `load' from c:/ruby/lib/ruby/gems/1.8/gems/rcov-0.9.8/bin/rcov:511 from c:/ruby/bin/rcov:19:in `load' from c:/ruby/bin/rcov:19 rake aborted! ruby -S rcov -Ispec "./spec/my_lib_spec.rb" failed It will pass of course if i'll add `require "rspec"` to somewhere. Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net From jarmo.p at gmail.com Thu Nov 4 17:28:12 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Thu, 4 Nov 2010 14:28:12 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> Message-ID: On Nov 4, 9:52?pm, Jarmo Pertman wrote: > I cannot reproduce this problem currently with standard html formatter > although i don't do anything with snippet extractor in my custom html > formatter. I need to investigate why the problem happens now and then. I've managed to reproduce it again and always like this: # some_spec.rb describe "something" do it "doesn't work" do true.should be_false end end C:\Users\jarmo\Desktop\minu\projects\Ruby\blah2>rspec some_spec.rb -f html -o out.html And this is the output: http://dl.dropbox.com/u/2731643/misc/out.html with -b the whole stacktrace is as following: c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/ expectations/fail_with.rb:29:in `fail_with' c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/ expectations/handler.rb:21:in `handle_matcher' c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/ expectations/extensions/kernel.rb:27:in `should' ./some_spec.rb:3 c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:47:in `instance_eval' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:47:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:86:in `call' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:86:in `with_around_hooks' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:44:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:80:in `call' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:80:in `with_pending_capture' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:79:in `catch' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:79:in `with_pending_capture' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example.rb:43:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example_group.rb:260:in `run_examples' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example_group.rb:256:in `map' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example_group.rb:256:in `run_examples' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ example_group.rb:230:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ command_line.rb:26:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ command_line.rb:26:in `map' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ command_line.rb:26:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ reporter.rb:11:in `report' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ command_line.rb:23:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ runner.rb:55:in `run_in_process' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ runner.rb:46:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ runner.rb:10:in `autorun' c:/Ruby/bin/rspec:19 Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net From jarmo.p at gmail.com Thu Nov 4 19:14:35 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Thu, 4 Nov 2010 16:14:35 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> Message-ID: <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> It also fails with RCov very strangely when including module in RSpec.configure block like this: # spec/my_lib_spec.rb require "rspec" describe "should work" do it "with rcov also" do MyLib.should be my_method.should == "works" end end # lib/my_lib.rb require "rspec" module MyLib def my_method "works" end end RSpec.configure do |config| config.include(MyLib) end # .rspec -r lib/my_lib and Rakefile is the same as before. When using `rake spec` then example passes, but with `rake rcov` i see this: C:\Users\jarmo\Desktop\minu\projects\Ruby\blah>rake rcov (in C:/Users/jarmo/Desktop/minu/projects/Ruby/blah) c:/ruby/bin/ruby.exe -S rcov -Ispec "./spec/my_lib_spec.rb" F Failures: 1) should work with rcov also Failure/Error: my_method.should == "works" undefined local variable or method `my_method' for # # ./spec/my_lib_spec.rb:6 Finished in 0.014 seconds 1 example, 1 failure rake aborted! ruby -S rcov -Ispec "./spec/my_lib_spec.rb" failed (See full trace by running task with --trace) When i put a breakpoint into example block then with `rake spec` i can see that module is included, but not with `rake rcov` although my_lib.rb is loaded because the first expectation succeeds as seen above. With `rake spec`: (rdb:1) l [3, 12] in C:/Users/jarmo/Desktop/minu/projects/Ruby/blah/spec/ my_lib_spec.rb 3 describe "should work" do 4 it "with rcov also" do 5 MyLib.should be 6 require "ruby-debug" 7 debugger => 8 my_method.should == "works" 9 end 10 end (rdb:1) self.class.included_modules [MyLib, RSpec::Matchers, RSpec::Core::MockFrameworkAdapter, RSpec::Core::Pending, RSpec::Core::Let::InstanceMethods, RSpec::Core::Let, RSpec::Core::Subject, RSpec::Core::Extensions::InstanceEvalWithArgs, RSpec::Mocks::Methods, PP::ObjectMixin, RSpec::Core::SharedExampleGroup, RSpec::Core::ObjectExtensions, Kernel] With `rake rcov`: (rdb:1) self.class.included_modules [RSpec::Matchers, RSpec::Core::MockFrameworkAdapter, RSpec::Core::Pending, RSpec::Core::Let::InstanceMethods, RSpec::Core::Let, RSpec::Core::Subject, RSpec::Core::Extensions::InstanceEvalWithArgs, RSpec::Mocks::Methods, PP::ObjectMixin, RSpec::Core::SharedExampleGroup, RSpec::Core::ObjectExtensions, Kernel] So, for some reason the module is not included when running with RCov. By the way all the specs were working before with 1.3.0. Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net On Nov 4, 10:37?pm, Jarmo Pertman wrote: > There seems to be also a problem when using RCov raketask - it doesn't > seem to load RSpec. From jarmo.p at gmail.com Thu Nov 4 20:18:15 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Thu, 4 Nov 2010 17:18:15 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> Message-ID: Upgrade to RSpec 2.x has been more painful than i expected. A lot more painful. Subject#subject behavior with "self" is also broken! This fails in RSpec 2 with stack overflow: describe "something" do subject { self } it "is ok?" do should be_ok end def ok? true end end It is passing in RSpec 1.3. See the original discussion of that feature that i myself suggested/needed http://groups.google.com/group/rspec/browse_thread/thread/89d6dd78b8f76df7/21109b78fc61a0e6 It also seems to me that the #subject specs provided with the patch for 1.x have been deleted also during some refactoring or something. At least i couldn't find the specs testing that explicit functionality from rspec-core. They still exist at 1.x repo though https://github.com/dchelimsky/rspec/blob/master/spec/spec/example/example_methods_spec.rb I'm really sorry if some of the problems in this thread are already fixed in master, but i couldn't see any open bugs relating to any of the problems described here. Waiting for some solutions-explanations how to solve most of the problems hopefully. Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net From dchelimsky at gmail.com Thu Nov 4 23:11:32 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Nov 2010 22:11:32 -0500 Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> Message-ID: On Nov 4, 2010, at 7:18 PM, Jarmo Pertman wrote: > Upgrade to RSpec 2.x has been more painful than i expected. A lot more > painful. > > Subject#subject behavior with "self" is also broken! > > This fails in RSpec 2 with stack overflow: > describe "something" do > subject { self } > > it "is ok?" do > should be_ok > end > > def ok? > true > end > end > > It is passing in RSpec 1.3. See the original discussion of that > feature that i myself suggested/needed > http://groups.google.com/group/rspec/browse_thread/thread/89d6dd78b8f76df7/21109b78fc61a0e6 > > It also seems to me that the #subject specs provided with the patch > for 1.x have been deleted also during some refactoring or something. > At least i couldn't find the specs testing that explicit functionality > from rspec-core. They still exist at 1.x repo though > https://github.com/dchelimsky/rspec/blob/master/spec/spec/example/example_methods_spec.rb > > I'm really sorry if some of the problems in this thread are already > fixed in master, but i couldn't see any open bugs relating to any of > the problems described here. > > Waiting for some solutions-explanations how to solve most of the > problems hopefully. Hey Jarmo, Sorry for all the trouble, and thanks for all of the feedback. I'm completely consumed with getting last minute things together for The RSpec Book to go to the printer (yay), and preparing for my talk next week at RubyConf, so I'm not quite sure when I'll be able to review/respond. Hopefully sometime over the weekend, but no guarantees. In the meantime, be sure to search the closed issues on github (unfortunately, they don't show up if you search the open issues), and please feel free to open new issues for the problems you are experiencing. Cheers, David From r-sutphin at northwestern.edu Wed Nov 3 18:39:28 2010 From: r-sutphin at northwestern.edu (Rhett Sutphin) Date: Wed, 3 Nov 2010 17:39:28 -0500 Subject: [rspec-users] Apparent regression in rspec 2 on ruby 1.9: constant resolution fails in describes in nested modules Message-ID: <7444C203-768E-404C-82AD-895044A75532@northwestern.edu> Hi, I've converted a couple of my smaller libraries' spec suites to rspec 2 with no trouble. (I'm enjoying the new version -- thanks to all involved.) I'm trying to convert one a larger suite now and I've run into two problems on ruby 1.9.1 (but not 1.8.7) related to constant resolution in describes inside of modules. One of the problems haven't been able to reproduce in a simple test case, but the other one I have. Here's the reproducible one: # ---- baz_spec.rb module Foo module Quux class Baz def name "noise" end end end end module Foo::Quux describe Baz do it "has a name" do Baz.new.name.should == 'noise' end end end # ---- This spec passes on rspec 2.0.1 and 1.3.0 on Ruby 1.8.7: ---- $ ruby -v ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0] $ spec _1.3.0_ baz_spec.rb . Finished in 0.002011 seconds 1 example, 0 failures $ rspec _2.0.1_ baz_spec.rb . Finished in 0.00077 seconds 1 example, 0 failures ---- It also passes on rspec 1.3.0 on Ruby 1.9.1. On rspec 2.0.1, it fails: ---- $ ruby -v ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.3.0] $ spec _1.3.0_ baz_spec.rb . Finished in 0.020187 seconds 1 example, 0 failures $ rspec _2.0.1_ baz_spec.rb F Failures: 1) Foo::Quux::Baz has a name Failure/Error: Baz.new.name.should == 'noise' uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Baz # ./baz_spec.rb:14:in `block (2 levels) in ' Finished in 0.00159 seconds 1 example, 1 failure ---- Is this a bug or expected behavior in rspec 2? I'll file an issue if it's a bug -- this would be against rspec-core, correct? Thanks, Rhett From nicholas.wieland at gmail.com Fri Nov 5 03:54:30 2010 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Fri, 5 Nov 2010 00:54:30 -0700 Subject: [rspec-users] Autotest not even starting Message-ID: <18E64D1D-93A5-4646-BF49-6C63B6840C05@gmail.com> Hi *, I'm trying to implement the Warden middleware, but apparently warden is making autotest crash. Here is the backtrace: https://gist.github.com/657378/a2c8fc15a179331d23f9015a6aba75a0a635121f Specs and features run as normal. This is what is in strategies.rb: https://gist.github.com/663795 Someone has any idea what's happening here ? ngw From dchelimsky at gmail.com Fri Nov 5 07:52:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Nov 2010 06:52:26 -0500 Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> Message-ID: <7BC2E7F2-2984-45C6-BCBD-C87CD7B42D57@gmail.com> On Nov 4, 2010, at 2:21 PM, Jarmo Pertman wrote: > Hello! Hello! > I'm trying to migrate my scripts from RSpec 1.3.0 to 2.0.1 having some > issues so far. > > 1) I don't like is that ".rspec" has to be in the working directory > and cannot be anymore in "spec". Okay, i can issue "mv spec/ > spec.opts .rspec" in my projects, but why isn't it supported? It's more common across other libraries to put "dot files" in your home and/or project root directories. > 2) If there is somewhere "require 'spec'" in existing specs or > spec_helper or anywhere then test will not be run and this will be > shown instead: > Finished in 0 seconds > 0 examples, 0 failures > > It is also possible to reproduce it like this from command line: > rspec -rspec blah_spec.rb Sounds like a new bug. Please report to http://github.com/rspec/rspec-core/issues. > 3) Why does html formatter snippet show always failing line as: > raise(RSpec::Expectations::ExpectationNotMetError.new(message)) > > in 1.x it would show the failing line in the spec file instead... is > this a bug? Yes. Please report to http://github.com/rspec/rspec-core/issues. > 4) In 1.x i modified ExampleGroup's description in my html formatter > to have some additional information in it like timestamp. I did it in > example_group_started where the passed variable example_group was an > instance of the ExampleGroup. In 2.x this is just a class name. How > can i accomplish the similar functionality? You can write a custom subclass of the HtmlFormatter and add whatever you like. > 5) I don't understand how to use multiple formatters together. You can't yet. rspec-core-2 was built from Micronaut, so a lot of the functionality had to be rebuilt. This is one feature I didn't forward port from rspec-1 because I didn't see the value in it for the complexity. RSpec-2 has been in the works for over a year now and you're the first person to ask about this, so it's obviously not a widely used feature, and I'm trying to keep unused features out. Feel free to report this to http://github.com/rspec/rspec-core/issues and we can discuss it further in the issue. > In > RSpec 1.x it is possible to use multiple formatters like this: > spec --format nested --format html:output/blah.html > > In RSpec 2.x it seems to me that only the last --format is used. The > command below: > rspec -f html -f d blah_spec.rb > > Uses only nested formatter. In RSpec 1.x you had to specify the file > path like this: > rspec -f html:path_to_output > > But it seems that in 2.x you have to use --out for that which > overrides all the output of course. And on top of if there is > everywhere used a term "formatter" in RSpec::Core::Configuration, but > "formatters" (in plural) in RSpec::Core::Reporter. It's constructor > also allows to pass multiple formatters into it. > > I'd like to use two formatters together - documentation and html. > Documentation would be helpful for faster feedback and for an > indication of end of the testrun on the command line, but (custom) > html formatter would include more information for better > troubleshooting. > > I managed to do that currently by little monkey-patching and manual > coding: > module RSpec > module Core > class Configuration > def reporter=(reporter) > @reporter = reporter > end > > public :built_in_formatter > end > end > end > > and in spec_helper or somewhere: > config = RSpec.configuration > config.color_enabled = true > documentation_formatter = > config.built_in_formatter(:documentation).new(config.output) > @@html_formatter = MyHtmlFormatter.new("blah/index.html") # it takes > file path as a string due to archival and file in use needs > config.reporter = RSpec::Core::Reporter.new(documentation_formatter, > @@html_formatter) > > Is there some easier/more normal way to do this? > > Does this mean that RSpec 2 is meant to be used with only 1 formatter > simultaneously? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Nov 5 07:53:19 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Nov 2010 06:53:19 -0500 Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> Message-ID: On Nov 4, 2010, at 4:28 PM, Jarmo Pertman wrote: > On Nov 4, 9:52 pm, Jarmo Pertman wrote: >> I cannot reproduce this problem currently with standard html formatter >> although i don't do anything with snippet extractor in my custom html >> formatter. I need to investigate why the problem happens now and then. > > I've managed to reproduce it again and always like this: > > # some_spec.rb > describe "something" do > it "doesn't work" do > true.should be_false > end > end > > C:\Users\jarmo\Desktop\minu\projects\Ruby\blah2>rspec some_spec.rb -f > html -o out.html > > And this is the output: > http://dl.dropbox.com/u/2731643/misc/out.html > > with -b the whole stacktrace is as following: > c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/ > expectations/fail_with.rb:29:in `fail_with' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/ > expectations/handler.rb:21:in `handle_matcher' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.1/lib/rspec/ > expectations/extensions/kernel.rb:27:in `should' > ./some_spec.rb:3 > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:47:in `instance_eval' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:47:in `run' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:86:in `call' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:86:in `with_around_hooks' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:44:in `run' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:80:in `call' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:80:in `with_pending_capture' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:79:in `catch' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:79:in `with_pending_capture' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example.rb:43:in `run' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example_group.rb:260:in `run_examples' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example_group.rb:256:in `map' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example_group.rb:256:in `run_examples' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > example_group.rb:230:in `run' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > command_line.rb:26:in `run' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > command_line.rb:26:in `map' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > command_line.rb:26:in `run' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > reporter.rb:11:in `report' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > command_line.rb:23:in `run' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > runner.rb:55:in `run_in_process' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > runner.rb:46:in `run' > c:/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/lib/rspec/core/ > runner.rb:10:in `autorun' > c:/Ruby/bin/rspec:19 Please report this to http://github.com/rspec/rspec-core/issues. From dchelimsky at gmail.com Fri Nov 5 07:59:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Nov 2010 06:59:12 -0500 Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> Message-ID: On Nov 4, 2010, at 3:37 PM, Jarmo Pertman wrote: > There seems to be also a problem when using RCov raketask - it doesn't > seem to load RSpec. > > Consider the following project structure: > > # Rakefile > require 'rspec/core/rake_task' > RSpec::Core::RakeTask.new(:spec) do |spec| > end > > RSpec::Core::RakeTask.new(:rcov) do |spec| > spec.rcov = true > end > > # lib/my_lib.rb > class MyLib > end > > # spec/my_lib_spec.rb > require "lib/my_lib" > > describe "should work" do > it "doesn't" do > MyLib.new.should be > end > end > > Now, when executing `rake spec` everything works - RSpec itself gets > loaded automatically. When executing `rake rcov` on the other hand > then this will be the output: > > C:\Users\jarmo\Desktop\minu\projects\Ruby\blah>rake rcov > (in C:/Users/jarmo/Desktop/minu/projects/Ruby/blah) > c:/ruby/bin/ruby.exe -S rcov -Ispec "./spec/my_lib_spec.rb" > ./spec/my_lib_spec.rb:1: undefined method `describe' for main:Object > (NoMethodError) > from c:/ruby/lib/ruby/gems/1.8/gems/rcov-0.9.8/bin/rcov:511:in > `load' > from c:/ruby/lib/ruby/gems/1.8/gems/rcov-0.9.8/bin/rcov:511 > from c:/ruby/bin/rcov:19:in `load' > from c:/ruby/bin/rcov:19 > rake aborted! > ruby -S rcov -Ispec "./spec/my_lib_spec.rb" failed > > It will pass of course if i'll add `require "rspec"` to somewhere. Bug. Please report this to http://github.com/rspec/rspec-core/issues. From jarmo.p at gmail.com Fri Nov 5 08:02:31 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Fri, 5 Nov 2010 05:02:31 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> Message-ID: I'd wait for some preliminary answers from you or anyone else from core before opening up any new issues. The main blockers for me to start using RSpec 2 are currently the subject {self} and html formatter snippet problems. Hopefully you'll find some time to answer to my provided feedback. Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net On Nov 5, 5:11?am, David Chelimsky wrote: > Hey Jarmo, > > Sorry for all the trouble, and thanks for all of the feedback. I'm completely consumed with getting last minute things together for The RSpec Book to go to the printer (yay), and preparing for my talk next week at RubyConf, so I'm not quite sure when I'll be able to review/respond. Hopefully sometime over the weekend, but no guarantees. > > In the meantime, be sure to search the closed issues on github (unfortunately, they don't show up if you search the open issues), and please feel free to open new issues for the problems you are experiencing. > > Cheers, > David From dchelimsky at gmail.com Fri Nov 5 08:10:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Nov 2010 07:10:57 -0500 Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> Message-ID: <6E4CAE8E-068A-4707-B1CA-AAE4D70B5206@gmail.com> On Nov 4, 2010, at 7:18 PM, Jarmo Pertman wrote: > Upgrade to RSpec 2.x has been more painful than i expected. A lot more > painful. > > Subject#subject behavior with "self" is also broken! > > This fails in RSpec 2 with stack overflow: > describe "something" do > subject { self } > > it "is ok?" do > should be_ok > end > > def ok? > true > end > end > > It is passing in RSpec 1.3. See the original discussion of that > feature that i myself suggested/needed > http://groups.google.com/group/rspec/browse_thread/thread/89d6dd78b8f76df7/21109b78fc61a0e6 > > It also seems to me that the #subject specs provided with the patch > for 1.x have been deleted also during some refactoring or something. rspec-core-2 was a complete rewrite, so it's not that specs or code were deleted, just not all were forward ported. > At least i couldn't find the specs testing that explicit functionality > from rspec-core. They still exist at 1.x repo though > https://github.com/dchelimsky/rspec/blob/master/spec/spec/example/example_methods_spec.rb These were largely about a module re-opening issue. I added a github issue for that: https://github.com/rspec/rspec-core/issues/issue/210 but I'm not sure it solves your need. If you don't think it will, please report this one as well to https://github.com/rspec/rspec-core/issues. > I'm really sorry if some of the problems in this thread are already > fixed in master, but i couldn't see any open bugs relating to any of > the problems described here. I don't think any of these issues have been reported. Most of the problems you're encountering have to do with unconventional use, which is why they haven't come up before. Thanks again for all the feedback. Cheers, David > Waiting for some solutions-explanations how to solve most of the > problems hopefully. From dchelimsky at gmail.com Fri Nov 5 08:13:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Nov 2010 07:13:36 -0500 Subject: [rspec-users] Apparent regression in rspec 2 on ruby 1.9: constant resolution fails in describes in nested modules In-Reply-To: <7444C203-768E-404C-82AD-895044A75532@northwestern.edu> References: <7444C203-768E-404C-82AD-895044A75532@northwestern.edu> Message-ID: <5791EBDC-7813-412F-A3C0-1CB8E605E797@gmail.com> On Nov 3, 2010, at 5:39 PM, Rhett Sutphin wrote: > Hi, > > I've converted a couple of my smaller libraries' spec suites to rspec 2 with no trouble. (I'm enjoying the new version -- thanks to all involved.) I'm trying to convert one a larger suite now and I've run into two problems on ruby 1.9.1 (but not 1.8.7) related to constant resolution in describes inside of modules. One of the problems haven't been able to reproduce in a simple test case, but the other one I have. Here's the reproducible one: > > # ---- baz_spec.rb > > module Foo > module Quux > class Baz > def name > "noise" > end > end > end > end > > module Foo::Quux > describe Baz do > it "has a name" do > Baz.new.name.should == 'noise' > end > end > end > > # ---- > > This spec passes on rspec 2.0.1 and 1.3.0 on Ruby 1.8.7: > > ---- > $ ruby -v > ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0] > $ spec _1.3.0_ baz_spec.rb > . > > Finished in 0.002011 seconds > > 1 example, 0 failures > $ rspec _2.0.1_ baz_spec.rb > . > > Finished in 0.00077 seconds > 1 example, 0 failures > ---- > > It also passes on rspec 1.3.0 on Ruby 1.9.1. On rspec 2.0.1, it fails: > > ---- > $ ruby -v > ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.3.0] > $ spec _1.3.0_ baz_spec.rb > . > > Finished in 0.020187 seconds > > 1 example, 0 failures > $ rspec _2.0.1_ baz_spec.rb > F > > Failures: > 1) Foo::Quux::Baz has a name > Failure/Error: Baz.new.name.should == 'noise' > uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Baz > # ./baz_spec.rb:14:in `block (2 levels) in ' > > Finished in 0.00159 seconds > 1 example, 1 failure > ---- > > Is this a bug or expected behavior in rspec 2? I'll file an issue if it's a bug -- this would be against rspec-core, correct? Same issue just came up on this list yesterday: http://groups.google.com/group/rspec/browse_thread/thread/60cfab923dbf007a From rhett at detailedbalance.net Fri Nov 5 10:19:11 2010 From: rhett at detailedbalance.net (Rhett Sutphin) Date: Fri, 5 Nov 2010 09:19:11 -0500 Subject: [rspec-users] Apparent regression in rspec 2 on ruby 1.9: constant resolution fails in describes in nested modules In-Reply-To: <5791EBDC-7813-412F-A3C0-1CB8E605E797@gmail.com> References: <7444C203-768E-404C-82AD-895044A75532@northwestern.edu> <5791EBDC-7813-412F-A3C0-1CB8E605E797@gmail.com> Message-ID: Hi, On Nov 5, 2010, at 7:13 AM, David Chelimsky wrote: > On Nov 3, 2010, at 5:39 PM, Rhett Sutphin wrote: > >> Hi, >> >> I've converted a couple of my smaller libraries' spec suites to rspec 2 with no trouble. (I'm enjoying the new version -- thanks to all involved.) I'm trying to convert one a larger suite now and I've run into two problems on ruby 1.9.1 (but not 1.8.7) related to constant resolution in describes inside of modules. One of the problems haven't been able to reproduce in a simple test case, but the other one I have. Here's the reproducible one: >> [details snipped] >> >> Is this a bug or expected behavior in rspec 2? I'll file an issue if it's a bug -- this would be against rspec-core, correct? > > Same issue just came up on this list yesterday: http://groups.google.com/group/rspec/browse_thread/thread/60cfab923dbf007a Yeah, those were both me -- I sent the first one from the wrong address. Sorry about the noise. To summarize what I've learned for someone who comes across this later: 1.9.1 has some bugs regarding scoping. While rspec 1.3.x worked around these bugs in some fashion, rspec 2 will not. (Since 1.9.1 is a superseded revision of the experimental version of ruby, this seems reasonable to me.) I filed an issue[1] requesting that the non-support of 1.9.1 be noted in the upgrade guide. Myron Marston helpfully pointed out a workaround for the minimal example I posted -- my actual specs are more complex, but I'm sure there are similar workarounds. For the particular gem I'm working on (an internal one) dropping support for 1.9.1 in favor of 1.9.2 is a fine option, so I'm doing that instead. [1]: https://github.com/rspec/rspec-core/issues/209 Thanks for the help, Rhett > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Nov 5 11:06:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Nov 2010 10:06:03 -0500 Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> Message-ID: <83C9E343-05D6-4F47-9D53-97E37482A376@gmail.com> On Nov 5, 2010, at 7:02 AM, Jarmo Pertman wrote: > I'd wait for some preliminary answers from you or anyone else from > core before opening up any new issues. The main blockers for me to > start using RSpec 2 are currently the subject {self} and html > formatter snippet problems. > > Hopefully you'll find some time to answer to my provided feedback. I'd really prefer you just submit the issues to http://github.com/rspec/rspec-core/issues. Keeps the conversation about each issue separate and ensures they each stay on the radar and get addressed, even if not immediately. Thanks, David > > Jarmo Pertman > ----- > IT does really matter - http://www.itreallymatters.net > > On Nov 5, 5:11 am, David Chelimsky wrote: >> Hey Jarmo, >> >> Sorry for all the trouble, and thanks for all of the feedback. I'm completely consumed with getting last minute things together for The RSpec Book to go to the printer (yay), and preparing for my talk next week at RubyConf, so I'm not quite sure when I'll be able to review/respond. Hopefully sometime over the weekend, but no guarantees. >> >> In the meantime, be sure to search the closed issues on github (unfortunately, they don't show up if you search the open issues), and please feel free to open new issues for the problems you are experiencing. >> >> Cheers, >> David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Fri Nov 5 13:19:57 2010 From: lists at ruby-forum.com (Tau Christiansen) Date: Fri, 05 Nov 2010 18:19:57 +0100 Subject: [rspec-users] rspec: command not found Message-ID: I am new to ROR. Trying to going through tutorial, but couldn't run rspec (command not found). Everything was installed as directed. Search the hold drive, found spec file and spec.bat in the following directories ./usr/lib/ruby/lib/ruby/gems/1.8/bin/rspec ./usr/lib/ruby/lib/ruby/gems/1.8/bin/rspec.bat ./usr/lib/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/bin/rspec abstract (1.0.0) actionmailer (3.0.1) actionpack (3.0.1) activemodel (3.0.1) activerecord (3.0.1) activeresource (3.0.1) activesupport (3.0.1) arel (1.0.1) autotest (4.4.2, 4.3.2) autotest-growl (0.2.6) autotest-notification (2.3.1) autotest-rails-pure (4.1.0) builder (2.1.2) bundler (1.0.3) configuration (1.1.0) diff-lcs (1.1.2) erubis (2.6.6) heroku (1.12.1) i18n (0.4.2) json_pure (1.4.6) launchy (0.3.7) mail (2.2.9) mime-types (1.16) mysql (2.8.1 x86-mingw32) nokogiri (1.4.3.1 x86-mingw32) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.13) rack-test (0.5.6) rails (3.0.1) railties (3.0.1) rake (0.8.7) rest-client (1.6.1) rspec (2.0.1) rspec-core (2.0.1) rspec-expectations (2.0.1) rspec-mocks (2.0.1) rspec-rails (2.0.1) sequel (3.15.0) sinatra (1.0) sys-uname (0.8.4 x86-mingw32) taps (0.3.13) thor (0.14.4, 0.14.3) treetop (1.4.8) tzinfo (0.3.23) webrat (0.7.1) zentest-without-autotest (4.4.0) -- Posted via http://www.ruby-forum.com/. From katrina.owen at gmail.com Fri Nov 5 14:19:53 2010 From: katrina.owen at gmail.com (Katrina Owen) Date: Fri, 5 Nov 2010 19:19:53 +0100 Subject: [rspec-users] rspec: command not found In-Reply-To: References: Message-ID: On Fri, Nov 5, 2010 at 6:19 PM, Tau Christiansen wrote: > I am new to ROR. ?Trying to going through tutorial, but couldn't run > rspec (command not found). ?Everything was installed as directed. > Search the hold drive, found spec file and spec.bat in the following > directories Did you call rails generate rspec:install from the root of your project? From jarmo.p at gmail.com Fri Nov 5 15:24:08 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Fri, 5 Nov 2010 12:24:08 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <83C9E343-05D6-4F47-9D53-97E37482A376@gmail.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> <83C9E343-05D6-4F47-9D53-97E37482A376@gmail.com> Message-ID: <8e213fcc-b921-44f2-a1f0-06762d333bf7@26g2000yqv.googlegroups.com> I didn't refresh my browser before writing that reply thus didn't see that you had already answered. Going to create those issues soon. Thanks for your feedback! Jarmo On Nov 5, 5:06?pm, David Chelimsky wrote: > On Nov 5, 2010, at 7:02 AM, Jarmo Pertman wrote: > > > I'd wait for some preliminary answers from you or anyone else from > > core before opening up any new issues. The main blockers for me to > > start using RSpec 2 are currently the subject {self} and html > > formatter snippet problems. > > > Hopefully you'll find some time to answer to my provided feedback. > > I'd really prefer you just submit the issues tohttp://github.com/rspec/rspec-core/issues. Keeps the conversation about each issue separate and ensures they each stay on the radar and get addressed, even if not immediately. > > Thanks, > David > > > > > > > > > > > > > Jarmo Pertman > > ----- > > IT does really matter -http://www.itreallymatters.net > > > On Nov 5, 5:11 am, David Chelimsky wrote: > >> Hey Jarmo, > > >> Sorry for all the trouble, and thanks for all of the feedback. I'm completely consumed with getting last minute things together for The RSpec Book to go to the printer (yay), and preparing for my talk next week at RubyConf, so I'm not quite sure when I'll be able to review/respond. Hopefully sometime over the weekend, but no guarantees. > > >> In the meantime, be sure to search the closed issues on github (unfortunately, they don't show up if you search the open issues), and please feel free to open new issues for the problems you are experiencing. > > >> Cheers, > >> David > > _______________________________________________ > > 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 jarmo.p at gmail.com Fri Nov 5 16:29:55 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Fri, 5 Nov 2010 13:29:55 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <7BC2E7F2-2984-45C6-BCBD-C87CD7B42D57@gmail.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <7BC2E7F2-2984-45C6-BCBD-C87CD7B42D57@gmail.com> Message-ID: <3adbe31d-19b2-4e1c-b86a-42d69de02e28@j25g2000yqa.googlegroups.com> On Nov 5, 1:52?pm, David Chelimsky wrote: > > 4) In 1.x i modified ExampleGroup's description in my html formatter > > to have some additional information in it like timestamp. I did it in > > example_group_started where the passed variable example_group was an > > instance of the ExampleGroup. In 2.x this is just a class name. How > > can i accomplish the similar functionality? > > You can write a custom subclass of the HtmlFormatter and add whatever you like. Since i don't consider this as an issue to be reported at GitHub rather than a new way to do things then i just want to know how should i do this. I understand that i can write a custom subclass of the HtmlFormatter and do there whatever i like. This is the actual case - i already have an subclass of HtmlFormatter, but the problem is that super class is acting differently than it was in 1.x. In HtmlFormatter#example_group_started a parameter called example_group was an actual instance of the current ExampleGroup in 1.x thus i were able to modify it's description so it would have additional information in my custom html formatter report. In 2.x the parameter example_group is not anymore an instance of an ExampleGroup, but just a class constant for runtime ExampleGroup class, thus there's nothing useful to do with that parameter anymore. How should/could i modify the description now? I'm afraid that in HtmlFormatter#example_started where i could access the ExampleGroup from the Example instance it's already too late since ExampleGroup description might be already flushed to the report. Haven't tried that yet though. Hopefully you understand my concern better now. Jarmo Pertman From jarmo.p at gmail.com Fri Nov 5 16:33:49 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Fri, 5 Nov 2010 13:33:49 -0700 (PDT) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <83C9E343-05D6-4F47-9D53-97E37482A376@gmail.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <152371fa-3c02-45a9-89ee-a566074003a8@e14g2000yqe.googlegroups.com> <619c875f-70d4-48b7-af1e-19b67b1aa228@s4g2000yql.googlegroups.com> <3d48c0f9-daea-4eb5-a047-c9924d9a74f0@32g2000yqz.googlegroups.com> <83C9E343-05D6-4F47-9D53-97E37482A376@gmail.com> Message-ID: I've created the issues. I'm copying them to here also to give an overview of the outcome of this thread. 1) 0 examples will be run if requiring "spec" https://github.com/rspec/rspec-core/issues/issue/212 2) add possibility to use multiple formatters at the same time https://github.com/rspec/rspec-core/issues/issue/213 3) using HtmlFormatter shows RSpec's internal snippet in the report https://github.com/rspec/rspec-core/issues/issue/214 4) RCov RakeTask doesn't load RSpec https://github.com/rspec/rspec-core/issues/issue/215 5) using RCov RakeTask doesn't include modules into example groups with RSpec.configure https://github.com/rspec/rspec-core/issues/issue/216 6) Subject#subject {self} causes stack overflow: https://github.com/rspec/rspec-core/issues/issue/217 Jarmo Pertman ----- IT does really matter - http://www.itreallymatters.net On Nov 5, 5:06?pm, David Chelimsky wrote: > I'd really prefer you just submit the issues tohttp://github.com/rspec/rspec-core/issues. Keeps the conversation about each issue separate and ensures they each stay on the radar and get addressed, even if not immediately. > > Thanks, > David From chs at proactive.cc Fri Nov 5 16:39:03 2010 From: chs at proactive.cc (Christoph Schiessl) Date: Fri, 5 Nov 2010 21:39:03 +0100 Subject: [rspec-users] Calling let(:something) from before blocks? Message-ID: Hello! I find myself repeating the same `let(:something)` statements over and over again in different view examples. Therefore, I wonder if it's possible to define these globally in the spec_helper.rb file. I came up with the following approach: # spec/spec_helper.rb RSpec.configure do |config| # ... config.before(:each, :type => :view) do let(:something) { "available for **all** view examples" } end # ... end However, this doesn't work because `let` isn't defined in that context: Failure/Error: Unable to find matching line from backtrace undefined method `let' for # Some kind of workaround to make this work would be really nice. Is this usage of `let` supported at all? Thx & best regards, Christoph PS: I'm using rspec 2.0.1, rails 3.0.1 and ruby 1.8.7. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Nov 5 17:47:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Nov 2010 16:47:36 -0500 Subject: [rspec-users] Calling let(:something) from before blocks? In-Reply-To: References: Message-ID: <469CB903-7929-4998-9A26-AF1FFBEA305E@gmail.com> On Nov 5, 2010, at 3:39 PM, Christoph Schiessl wrote: > Hello! > > I find myself repeating the same `let(:something)` statements over and over again in different view examples. Therefore, I wonder if it's possible to define these globally in the spec_helper.rb file. I came up with the following approach: > > # spec/spec_helper.rb > RSpec.configure do |config| > # ... > config.before(:each, :type => :view) do > let(:something) { "available for **all** view examples" } > end > # ... > end > > However, this doesn't work because `let` isn't defined in that context: > > Failure/Error: Unable to find matching line from backtrace > undefined method `let' for # > > Some kind of workaround to make this work would be really nice. Is this usage of `let` supported at all? Not as of yet. Not sure if I'd like to add it or not, but please file a feature request: http://github.com/rspec/rspec-core/issues. Thx, David > > Thx & best regards, > Christoph > > PS: I'm using rspec 2.0.1, rails 3.0.1 and ruby 1.8.7. > _______________________________________________ > 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 chs at proactive.cc Fri Nov 5 15:12:13 2010 From: chs at proactive.cc (Christoph Schiessl) Date: Fri, 5 Nov 2010 20:12:13 +0100 Subject: [rspec-users] Calling let(:something) from before blocks? Message-ID: <10EA2E91-17E1-4BA3-BBDB-16063CA3FF08@proactive.cc> Hello! I find myself repeating the same `let(:something)` statements over and over again in different view examples. Therefore, I wonder if it's possible to define these globally in the spec_helper.rb file. I came up with the following approach: # spec/spec_helper.rb RSpec.configure do |config| # ... config.before(:each, :type => :view) do let(:something) { "available for **all** view examples" } end # ... end However, this doesn't work because `let` isn't defined in that context: Failure/Error: Unable to find matching line from backtrace undefined method `let' for # Some kind of workaround to make this work would be really nice. Is this usage of `let` supported at all? Thx & best regards, Christoph PS: I'm using rspec 2.0.1, rails 3.0.1 and ruby 1.8.7. From scott at railsnewbie.com Sat Nov 6 18:04:50 2010 From: scott at railsnewbie.com (Scott Taylor) Date: Sat, 6 Nov 2010 18:04:50 -0400 Subject: [rspec-users] Custom File List for Rails 3 Spec Task Message-ID: <0956F165-32D2-4045-9BDD-E9B878AE1422@railsnewbie.com> I have some javascript specs (using the jspec javascript framework) in my rails 3 project, living in the spec/javascript directory. How can I exclude the ruby files in the jspec project from being run when I run "rake spec"? RSpec::Core::RakeTask used to take a file list (which was usually generated with a glob pattern and an explicit call to Dir.glob). Now it only takes a glob pattern: http://rdoc.info/github/rspec/rspec-core/master/RSpec/Core/RakeTask#pattern-instance_method So how am I supposed to express the following in one glob pattern? Dir.glob("spec/**/*_spec.rb") - Dir.glob("spec/javascript/**/*_spec.rb") Or is there a better way that I'm missing entirely, Best, Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Nov 6 19:16:41 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 6 Nov 2010 18:16:41 -0500 Subject: [rspec-users] Custom File List for Rails 3 Spec Task In-Reply-To: <0956F165-32D2-4045-9BDD-E9B878AE1422@railsnewbie.com> References: <0956F165-32D2-4045-9BDD-E9B878AE1422@railsnewbie.com> Message-ID: On Nov 6, 2010, at 5:04 PM, Scott Taylor wrote: > I have some javascript specs (using the jspec javascript framework) in my rails 3 project, living in the spec/javascript directory. How can I exclude the ruby files in the jspec project from being run when I run "rake spec"? > > RSpec::Core::RakeTask used to take a file list (which was usually generated with a glob pattern and an explicit call to Dir.glob). Now it only takes a glob pattern: > > http://rdoc.info/github/rspec/rspec-core/master/RSpec/Core/RakeTask#pattern-instance_method > > So how am I supposed to express the following in one glob pattern? > > Dir.glob("spec/**/*_spec.rb") - Dir.glob("spec/javascript/**/*_spec.rb") > > Or is there a better way that I'm missing entirely, Hey Scott, Something like: "spec/{models,views,controllers,helpers,requests}/**/*_spec.rb" You'd have to include any dirs I left out (if you have any others) in the curly brackets. Do you think that's sufficient? Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedgehogshiatus at gmail.com Sat Nov 6 20:10:08 2010 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Sun, 7 Nov 2010 11:10:08 +1100 Subject: [rspec-users] How best to intercept one method in the midst of a chain Message-ID: Hi Group, I'm back to Rspec after some time away, and was a little curious about why the following example does not return the value zero. ??https://gist.github.com/665226 I have tried @repo.status.__send__{type.to_sym}.size and got the same result, and I suspected the send was maybe bypassing rspec doubles/stubs, so I used the eval and got the same result. That said, I have used stub_chain to get this to pass, but would appreciate any insight into what I've done wrong. The side effect of stub_chain is that it seems to clobber the contents of .status, so I have to create a new @repo instance, which just feels wrong when I'm actually trying to stub the method 'type'. In fact since, in the gist, I use should_receive I expected that this would break the example altogether. Rather it is as if the method 'type' is unaffected. This post left me with the impression that 'type' should be overridden after the use of should_receive (in the way status is after using the stub_chain), but I've obviously misunderstood: http://groups.google.com/group/rspec/browse_thread/thread/a38932d19fffee49/915d609d3a0d2862?lnk=gst&q=stub+method+chain#915d609d3a0d2862 Appreciate any insights Best wishes -- ????' ??? ??????, ???' ?????? ?? ???? [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 Sat Nov 6 20:54:16 2010 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Sun, 7 Nov 2010 11:54:16 +1100 Subject: [rspec-users] Hooks before a scenario but not the background: possible or bad practice Message-ID: Hi, I'd like to activate FakeFS for some scenarios, which I tag @fakefs, however it seems Before('@fakefs') runs before the background of the feature - unfortunately this clobbers Grit, and I can't Grit::Repo.new(...) in the backbround. Is it currently possible to get a hook to run before a scenario, but not the Background of the feature? Or am I mistaken in making a distinction between a scenario and the background of a feature? Best wishes -- ????' ??? ??????, ???' ?????? ?? ???? [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 dchelimsky at gmail.com Sun Nov 7 06:49:01 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Nov 2010 05:49:01 -0600 Subject: [rspec-users] How best to intercept one method in the midst of a chain In-Reply-To: References: Message-ID: On Nov 6, 2010, at 7:10 PM, Hedge Hog wrote: > Hi Group, > I'm back to Rspec after some time away, and was a little curious about > why the following example does not return the value zero. > > ??https://gist.github.com/665226 > > I have tried @repo.status.__send__{type.to_sym}.size and got the same > result, and I suspected the send was maybe bypassing rspec > doubles/stubs, so I used the eval and got the same result. > > That said, I have used stub_chain to get this to pass, but would > appreciate any insight into what I've done wrong. > The side effect of stub_chain is that it seems to clobber the contents > of .status, so I have to create a new @repo instance, which just feels > wrong when I'm actually trying to stub the method 'type'. > > In fact since, in the gist, I use should_receive I expected that this > would break the example altogether. Rather it is as if the method > 'type' is unaffected. > This post left me with the impression that 'type' should be overridden > after the use of should_receive (in the way status is after using the > stub_chain), but I've obviously misunderstood: > http://groups.google.com/group/rspec/browse_thread/thread/a38932d19fffee49/915d609d3a0d2862?lnk=gst&q=stub+method+chain#915d609d3a0d2862 I have some thoughts for you, but this is really a Cucumber question (even though you're using rspec-mocks in the context of Cucumber). Are you aware there is a separate Cucumber list? http://groups.google.com/group/cukes I'd recommend moving this conversation there, at which point I'll be glad to respond. Cheers, David > > Appreciate any insights > Best wishes > > -- > ????' ??? ??????, ???' ?????? ?? ???? > [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 From dchelimsky at gmail.com Sun Nov 7 06:49:29 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Nov 2010 05:49:29 -0600 Subject: [rspec-users] Hooks before a scenario but not the background: possible or bad practice In-Reply-To: References: Message-ID: <80329122-3FC5-49F1-A5DC-24667378096A@gmail.com> On Nov 6, 2010, at 7:54 PM, Hedge Hog wrote: > Hi, > I'd like to activate FakeFS for some scenarios, which I tag @fakefs, > however it seems Before('@fakefs') runs before the background of the > feature - unfortunately this clobbers Grit, and I can't > Grit::Repo.new(...) in the backbround. > Is it currently possible to get a hook to run before a scenario, but > not the Background of the feature? > > Or am I mistaken in making a distinction between a scenario and the > background of a feature? Please post this to the Cucumber list: http://groups.google.com/group/cukes. Cheers, David > > Best wishes > > -- > ????' ??? ??????, ???' ?????? ?? ???? > [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 From lardawge at gmail.com Sat Nov 6 22:15:25 2010 From: lardawge at gmail.com (lardawge) Date: Sat, 6 Nov 2010 19:15:25 -0700 (PDT) Subject: [rspec-users] WillPaginate::Collection not detectible in assigns? Message-ID: I am transitioning a Rails 2 app to Rails 3, Rspec 2 and have several controller where I test collect.should be_an_instance_of(WillPaginate::Collection). The spec fails with "expected [object] to be an instance of WillPaginate::Collection". The class of the object in the controller is WillPaginate::Collection. What am I missing? Why is assigns not returning the actual object? Controller collection class is WillPaginate::Collection. Spec collection class is an Array. Thanks, ~Larry From dchelimsky at gmail.com Sun Nov 7 08:56:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Nov 2010 07:56:58 -0600 Subject: [rspec-users] WillPaginate::Collection not detectible in assigns? In-Reply-To: References: Message-ID: <4D99B85E-233B-4A99-8847-51E957586914@gmail.com> On Nov 6, 2010, at 9:15 PM, lardawge wrote: > I am transitioning a Rails 2 app to Rails 3, Rspec 2 and have several > controller where I test collect.should > be_an_instance_of(WillPaginate::Collection). The spec fails with > "expected [object] to be an instance of WillPaginate::Collection". The > class of the object in the controller is WillPaginate::Collection. > What am I missing? Why is assigns not returning the actual object? > Controller collection class is WillPaginate::Collection. Spec > collection class is an Array. Please post the failing example and the full failure message (i.e. run with --backtrace so we can see the full backtrace). > Thanks, > ~Larry From dchelimsky at gmail.com Sun Nov 7 12:36:48 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Nov 2010 11:36:48 -0600 Subject: [rspec-users] rspec-2.1 is released! Message-ID: <40FF70FD-75C6-4ABA-BEC0-9D4B81DB9F2B@gmail.com> ### rspec-core-2.1.0 / 2010-11-07 [Cucumber features](http://relishapp.com/rspec/rspec-core/v/2-1) [RDoc](http://rdoc.info/gems/rspec-core/2.1.0/frames) # will be generated by 2010-11-08 [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.1...v2.1.0) * Enhancments * Add skip_bundler option to rake task to tell rake task to ignore the presence of a Gemfile (jfelchner) * Add gemfile option to rake task to tell rake task what Gemfile to look for (defaults to 'Gemfile') * Allow passing caller trace into Metadata to support extensions (Glenn Vanderburg) * Add deprecation warning for Spec::Runner.configure to aid upgrade from RSpec-1 * Add deprecated Spec::Rake::SpecTask to aid upgrade from RSpec-1 * Add 'autospec' command with helpful message to aid upgrade from RSpec-1 * Add support for filtering with tags on CLI (Lailson Bandeira) * Add a helpful message about RUBYOPT when require fails in bin/rspec (slyphon) * Add "-Ilib" to the default rcov options (Tianyi Cui) * Make the expectation framework configurable (default rspec, of course) (Justin Ko) * Add 'pending' to be conditional (Myron Marston) * Add explicit support for :if and :unless as metadata keys for conditional run of examples (Myron Marston) * Add --fail-fast command line option (Jeff Kreeftmeijer) * Bug fixes * Eliminate stack overflow with "subject { self }" * Require 'rspec/core' in the Raketask (ensures it required when running rcov) ### rspec-expectations-2.1.0 / 2010-11-07 [Cucumber features](http://relishapp.com/rspec/rspec-expectations/v/2-1) [RDoc](http://rdoc.info/gems/rspec-expectations/2.1.0/frames) # will be generated by 2010-11-08 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.1...v2.1.0) * Enhancements * be_within(delta).of(expected) matcher (Myron Marston) * Lots of new Cucumber features (Myron Marston) * Raise error if you try "should != expected" on Ruby-1.9 (Myron Marston) * Improved failure messages from throw_symbol (Myron Marston) * Bug fixes * Eliminate hard dependency on RSpec::Core (Myron Marston) * have_matcher - use pluralize only when ActiveSupport inflections are indeed defined (Josep M Bach) * throw_symbol matcher no longer swallows exceptions (Myron Marston) * fix matcher chaining to avoid name collisions (Myron Marston) ### rspec-mocks-2.1.0 / 2010-11-07 [Cucumber features](http://relishapp.com/rspec/rspec-mocks/v/2-1) [RDoc](http://rdoc.info/gems/rspec-mocks/2.1.0/frames) # will be generated by 2010-11-08 [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.1...v2.1.0) * Bug fixes * Fix serialization of stubbed object (Josep M Bach) ### rspec-rails-2.1.0 / 2010-11-07 [Cucumber features](http://relishapp.com/rspec/rspec-rails/v/2-1) [RDoc](http://rdoc.info/gems/rspec-rails/2.1.0/frames) # will be generated by 2010-11-08 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.0.1...v2.1.0) * Enhancements * Move errors_on to ActiveModel to support other AM-compliant ORMs * Bug fixes * Check for presence of ActiveRecord instead of checking Rails config (gets rspec out of the way of multiple ORMs in the same app) From hedgehogshiatus at gmail.com Sun Nov 7 13:53:21 2010 From: hedgehogshiatus at gmail.com (Hedge Hog) Date: Mon, 8 Nov 2010 05:53:21 +1100 Subject: [rspec-users] Hooks before a scenario but not the background: possible or bad practice In-Reply-To: <80329122-3FC5-49F1-A5DC-24667378096A@gmail.com> References: <80329122-3FC5-49F1-A5DC-24667378096A@gmail.com> Message-ID: On Sun, Nov 7, 2010 at 10:49 PM, David Chelimsky wrote: > On Nov 6, 2010, at 7:54 PM, Hedge Hog wrote: > >> Hi, >> I'd like to activate FakeFS for some scenarios, which I tag @fakefs, >> however it seems Before('@fakefs') runs before the background of the >> feature - unfortunately this clobbers Grit, and I can't >> Grit::Repo.new(...) in the backbround. >> Is it currently possible to get a hook to run before a scenario, but >> not the Background of the feature? >> >> Or am I mistaken in making a distinction between a scenario and the >> background of a feature? > > Please post this to the Cucumber list: http://groups.google.com/group/cukes. > Apologies for using the wrong list and that this was due to something in the Before hook failing - so I won't resurrect this on the cukes list. Things work as expected when driven by a suitable operator :) > Cheers, > David > >> >> Best wishes >> >> -- >> ????' ??? ??????, ???' ?????? ?? ???? >> [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 > > _______________________________________________ > 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 scott at railsnewbie.com Mon Nov 8 00:52:53 2010 From: scott at railsnewbie.com (Scott Taylor) Date: Mon, 8 Nov 2010 00:52:53 -0500 Subject: [rspec-users] Custom File List for Rails 3 Spec Task In-Reply-To: References: <0956F165-32D2-4045-9BDD-E9B878AE1422@railsnewbie.com> Message-ID: Thanks David. I didn't realize Dir.glob was so capable. Here's what I ended up coming up with. Notice that I had to remove the rspec task as it was previously defined (by rspec itself): https://gist.github.com/667421 Cheers, Scott On Nov 6, 2010, at 7:16 PM, David Chelimsky wrote: > On Nov 6, 2010, at 5:04 PM, Scott Taylor wrote: > >> I have some javascript specs (using the jspec javascript framework) in my rails 3 project, living in the spec/javascript directory. How can I exclude the ruby files in the jspec project from being run when I run "rake spec"? >> >> RSpec::Core::RakeTask used to take a file list (which was usually generated with a glob pattern and an explicit call to Dir.glob). Now it only takes a glob pattern: >> >> http://rdoc.info/github/rspec/rspec-core/master/RSpec/Core/RakeTask#pattern-instance_method >> >> So how am I supposed to express the following in one glob pattern? >> >> Dir.glob("spec/**/*_spec.rb") - Dir.glob("spec/javascript/**/*_spec.rb") >> >> Or is there a better way that I'm missing entirely, > > Hey Scott, > > Something like: "spec/{models,views,controllers,helpers,requests}/**/*_spec.rb" > > You'd have to include any dirs I left out (if you have any others) in the curly brackets. Do you think that's sufficient? > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lardawge at gmail.com Mon Nov 8 12:26:33 2010 From: lardawge at gmail.com (lardawge) Date: Mon, 8 Nov 2010 09:26:33 -0800 (PST) Subject: [rspec-users] WillPaginate::Collection not detectible in assigns? In-Reply-To: <4D99B85E-233B-4A99-8847-51E957586914@gmail.com> References: <4D99B85E-233B-4A99-8847-51E957586914@gmail.com> Message-ID: <56b5a794-f730-49c9-ae86-1113ccc5bdd1@w30g2000prj.googlegroups.com> I created a sample app that this was repeatable in and would be happy to put it up on github... here is the gist of it: https://gist.github.com/667961 On Nov 7, 5:56?am, David Chelimsky wrote: > On Nov 6, 2010, at 9:15 PM, lardawge wrote: > > > I am transitioning a Rails 2 app to Rails 3, Rspec 2 and have several > > controller where I test collect.should > > be_an_instance_of(WillPaginate::Collection). The spec fails with > > "expected [object] to be an instance of WillPaginate::Collection". The > > class of the object in the controller is WillPaginate::Collection. > > What am I missing? Why is assigns not returning the actual object? > > Controller collection class is WillPaginate::Collection. Spec > > collection class is an Array. > > Please post the failing example and the full failure message (i.e. run with --backtrace so we can see the full backtrace). > > > Thanks, > > ~Larry > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lardawge at gmail.com Mon Nov 8 12:40:58 2010 From: lardawge at gmail.com (lardawge) Date: Mon, 8 Nov 2010 09:40:58 -0800 (PST) Subject: [rspec-users] WillPaginate::Collection not detectible in assigns? In-Reply-To: <4D99B85E-233B-4A99-8847-51E957586914@gmail.com> References: <4D99B85E-233B-4A99-8847-51E957586914@gmail.com> Message-ID: Ok, here is the entire example app: https://github.com/lardawge/will_paginate_failing_spec On Nov 7, 5:56?am, David Chelimsky wrote: > On Nov 6, 2010, at 9:15 PM, lardawge wrote: > > > I am transitioning a Rails 2 app to Rails 3, Rspec 2 and have several > > controller where I test collect.should > > be_an_instance_of(WillPaginate::Collection). The spec fails with > > "expected [object] to be an instance of WillPaginate::Collection". The > > class of the object in the controller is WillPaginate::Collection. > > What am I missing? Why is assigns not returning the actual object? > > Controller collection class is WillPaginate::Collection. Spec > > collection class is an Array. > > Please post the failing example and the full failure message (i.e. run with --backtrace so we can see the full backtrace). > > > Thanks, > > ~Larry > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Nov 8 13:40:56 2010 From: lists at ruby-forum.com (Dean Richardson) Date: Mon, 08 Nov 2010 19:40:56 +0100 Subject: [rspec-users] "rspec can not be found in vendor/gems, vendor/plugins or system gems" error Message-ID: I'm trying to follow the instructions in the beta version of "The RSpec Book" to get "BDD in Rails" going. Here are some relevant details: Rails version: 2.3.5 Local gems: rspec (2.1.0) rspec-core (2.1.0) rspec-expectations (2.1.0) rspec-mocks (2.1.0) rspec-rails (1.3.2) I started by installing rspec-rails 1.3.2, then cucumber-rails 0.3.2, then database_cleaner and webrat. I then tried to run rake spec and got the "rspec can not be found" error message. Taking this message literally, I then ran "gem install rspec" and was able to install the rspec-2.1.0 gem. But when I ran rake spec again, I got the same error message as before. Should I have installed an earlier version of the rspec gem? Thanks, Dean Richardson -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Nov 8 13:47:05 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Nov 2010 12:47:05 -0600 Subject: [rspec-users] "rspec can not be found in vendor/gems, vendor/plugins or system gems" error In-Reply-To: References: Message-ID: <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com> On Nov 8, 2010, at 12:40 PM, Dean Richardson wrote: > I'm trying to follow the instructions in the beta version of "The RSpec > Book" to get "BDD in Rails" going. Here are some relevant details: > > Rails version: 2.3.5 > > Local gems: > rspec (2.1.0) > rspec-core (2.1.0) > rspec-expectations (2.1.0) > rspec-mocks (2.1.0) > rspec-rails (1.3.2) > > I started by installing rspec-rails 1.3.2, then cucumber-rails 0.3.2, > then database_cleaner and webrat. I then tried to run rake spec and got > the "rspec can not be found" error message. Taking this message > literally, I then ran "gem install rspec" and was able to install the > rspec-2.1.0 gem. > > But when I ran rake spec again, I got the same error message as before. > Should I have installed an earlier version of the rspec gem? Did you get the most recent update to the beta book? If not, go log into your PragProg account and get it. There's a section in the preface that lists all the versions you need, including Rails-3 (not rails-2.3.5) and RSpec-2. HTH, David > Thanks, > > Dean Richardson From dchelimsky at gmail.com Mon Nov 8 14:24:32 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Nov 2010 13:24:32 -0600 Subject: [rspec-users] WillPaginate::Collection not detectible in assigns? In-Reply-To: <56b5a794-f730-49c9-ae86-1113ccc5bdd1@w30g2000prj.googlegroups.com> References: <4D99B85E-233B-4A99-8847-51E957586914@gmail.com> <56b5a794-f730-49c9-ae86-1113ccc5bdd1@w30g2000prj.googlegroups.com> Message-ID: Let's stick w/ the github issue. No need to do this on two paths. Thx On Nov 8, 2010, at 11:26 AM, lardawge wrote: > I created a sample app that this was repeatable in and would be happy > to put it up on github... here is the gist of it: > > https://gist.github.com/667961 > > On Nov 7, 5:56 am, David Chelimsky wrote: >> On Nov 6, 2010, at 9:15 PM, lardawge wrote: >> >>> I am transitioning a Rails 2 app to Rails 3, Rspec 2 and have several >>> controller where I test collect.should >>> be_an_instance_of(WillPaginate::Collection). The spec fails with >>> "expected [object] to be an instance of WillPaginate::Collection". The >>> class of the object in the controller is WillPaginate::Collection. >>> What am I missing? Why is assigns not returning the actual object? >>> Controller collection class is WillPaginate::Collection. Spec >>> collection class is an Array. >> >> Please post the failing example and the full failure message (i.e. run with --backtrace so we can see the full backtrace). >> >>> Thanks, >>> ~Larry >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lardawge at gmail.com Mon Nov 8 16:52:30 2010 From: lardawge at gmail.com (lardawge) Date: Mon, 8 Nov 2010 13:52:30 -0800 (PST) Subject: [rspec-users] WillPaginate::Collection not detectible in assigns? In-Reply-To: References: <4D99B85E-233B-4A99-8847-51E957586914@gmail.com> <56b5a794-f730-49c9-ae86-1113ccc5bdd1@w30g2000prj.googlegroups.com> Message-ID: Agreed. I switched to github when I realized there was a delay posting here... These came in through after that. On Nov 8, 11:24?am, David Chelimsky wrote: > Let's stick w/ the github issue. No need to do this on two paths. > > Thx > > On Nov 8, 2010, at 11:26 AM, lardawge wrote: > > > > > > > I created a sample app that this was repeatable in and would be happy > > to put it up on github... here is the gist of it: > > >https://gist.github.com/667961 > > > On Nov 7, 5:56 am, David Chelimsky wrote: > >> On Nov 6, 2010, at 9:15 PM, lardawge wrote: > > >>> I am transitioning a Rails 2 app to Rails 3, Rspec 2 and have several > >>> controller where I test collect.should > >>> be_an_instance_of(WillPaginate::Collection). The spec fails with > >>> "expected [object] to be an instance of WillPaginate::Collection". The > >>> class of the object in the controller is WillPaginate::Collection. > >>> What am I missing? Why is assigns not returning the actual object? > >>> Controller collection class is WillPaginate::Collection. Spec > >>> collection class is an Array. > > >> Please post the failing example and the full failure message (i.e. run with --backtrace so we can see the full backtrace). > > >>> Thanks, > >>> ~Larry > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From restagner at gmail.com Mon Nov 8 19:12:55 2010 From: restagner at gmail.com (Robert Stagner) Date: Mon, 8 Nov 2010 16:12:55 -0800 Subject: [rspec-users] How to setup rspec to be included on the PATH Message-ID: I've recently installed a copy of rspec (2.0.0) on my Linux distribution (Ubuntu 9.10). All went well. However, when I attempt to access cucumber from the shell, like so $ rspec --help I receive the following: No command 'rspec' found I know there is a simple solution to this, likely dealing with the PATH environment variable. Any help in pointing me to a solution where I can get rspec setup on my PATH would be most appreciated. I used the following command taken from the RSpec book to install rspec sudo gem intall rspec --version 2.0.0 Thanks. -- Regards, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon Nov 8 19:35:09 2010 From: lists at ruby-forum.com (Chong kee Tan) Date: Tue, 09 Nov 2010 01:35:09 +0100 Subject: [rspec-users] uploads with webrat in stories In-Reply-To: <2CC8290E-BED9-49E7-8A15-7A4793B3B0BB@parkerhill.com> References: <2CC8290E-BED9-49E7-8A15-7A4793B3B0BB@parkerhill.com> Message-ID: <7c570d22d3247e883f6a2b6bd43478df@ruby-forum.com> In case there are other people trying to do the same thing, webrat's implementation of attach_file has changed somewhat. See this URL for the current method to attach a file in your multipart form: http://gitrdoc.com/rdoc/brynary/webrat/273e8c541a82ddacf91f4f68ab6166c16ffdc9c5/classes/Webrat/Scope.html To summarize, syntax is attach_file (field_locator, path, content_type = nil) There is no need to call File.join or File.open, just specify the relative path. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Nov 8 20:23:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Nov 2010 19:23:54 -0600 Subject: [rspec-users] How to setup rspec to be included on the PATH In-Reply-To: References: Message-ID: On Nov 8, 2010, at 6:12 PM, Robert Stagner wrote: > I've recently installed a copy of rspec (2.0.0) on my Linux distribution (Ubuntu 9.10). All went well. However, when I attempt to access cucumber from the shell, like so You mean "attempt to access rspec," right? > $ rspec --help > > I receive the following: > > No command 'rspec' found > > I know there is a simple solution to this, likely dealing with the PATH environment variable. Any help in pointing me to a solution where I can get rspec setup on my PATH would be most appreciated. > Please run "gem env" and look at the section of the output that starts with "GEM PATHS" and make sure that all of the paths listed there (there may only be one) are included in your PATH. HTH, David > I used the following command taken from the RSpec book to install rspec > > sudo gem intall rspec --version 2.0.0 > > Thanks. > > > -- > Regards, > Robert > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Tue Nov 9 07:38:58 2010 From: lists at ruby-forum.com (Dean Richardson) Date: Tue, 09 Nov 2010 13:38:58 +0100 Subject: [rspec-users] "rspec can not be found in vendor/gems, vendor/plugins or system gems" error In-Reply-To: <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com> References: , <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com> Message-ID: <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com> David Chelimsky wrote in post #960173: > On Nov 8, 2010, at 12:40 PM, Dean Richardson wrote: > >> rspec-rails (1.3.2) >> >> I started by installing rspec-rails 1.3.2, then cucumber-rails 0.3.2, >> then database_cleaner and webrat. I then tried to run rake spec and got >> the "rspec can not be found" error message. Taking this message >> literally, I then ran "gem install rspec" and was able to install the >> rspec-2.1.0 gem. >> >> But when I ran rake spec again, I got the same error message as before. >> Should I have installed an earlier version of the rspec gem? > > Did you get the most recent update to the beta book? If not, go log into > your PragProg account and get it. There's a section in the preface that > lists all the versions you need, including Rails-3 (not rails-2.3.5) and > RSpec-2. > > HTH, > David David: Thanks for prompting me to get the update of the book. So, if I'm not quite ready to make the leap to Rails 3, am I out of luck trying to use RSpec and Cucumber? Is there any intermediate strategy you can suggest? --Dean -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Nov 9 08:21:00 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 9 Nov 2010 07:21:00 -0600 Subject: [rspec-users] "rspec can not be found in vendor/gems, vendor/plugins or system gems" error In-Reply-To: <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com> References: , <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com> <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com> Message-ID: <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com> On Nov 9, 2010, at 6:38 AM, Dean Richardson wrote: > David Chelimsky wrote in post #960173: >> On Nov 8, 2010, at 12:40 PM, Dean Richardson wrote: >> >>> rspec-rails (1.3.2) >>> >>> I started by installing rspec-rails 1.3.2, then cucumber-rails 0.3.2, >>> then database_cleaner and webrat. I then tried to run rake spec and got >>> the "rspec can not be found" error message. Taking this message >>> literally, I then ran "gem install rspec" and was able to install the >>> rspec-2.1.0 gem. >>> >>> But when I ran rake spec again, I got the same error message as before. >>> Should I have installed an earlier version of the rspec gem? >> >> Did you get the most recent update to the beta book? If not, go log into >> your PragProg account and get it. There's a section in the preface that >> lists all the versions you need, including Rails-3 (not rails-2.3.5) and >> RSpec-2. >> >> HTH, >> David > > David: > > Thanks for prompting me to get the update of the book. So, if I'm not > quite ready to make the leap to Rails 3, am I out of luck trying to use > RSpec and Cucumber? Is there any intermediate strategy you can suggest? rspec-1.3 works fine with rails-2.3, and there are notes about how to set this up in the "BDD in Rails" chapter. The RSpec Book is more of a workflow/strategy/process book than a recipe/syntax book. The latter is present, but not the focus. I'd recommend using the versions in the book (listed in the preface) to go through the exercises so you can learn how to use these tools effectively, and then comb the interwebs for information about whatever syntactic differences might be missing from the book. You can also write to this list if you have questions about the differences between versions. HTH, David > > --Dean > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From restagner at gmail.com Tue Nov 9 11:06:43 2010 From: restagner at gmail.com (Robert Stagner) Date: Tue, 9 Nov 2010 08:06:43 -0800 Subject: [rspec-users] How to setup rspec to be included on the PATH In-Reply-To: References: Message-ID: Yes, I meant rspec. My apologies for the typo. I'm running into the same problem with cucumber and inadvertently confused the two. I've gone ahead and added 3 additional values to my PATH environment variable. My PATH variable now looks like /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/rstagner/firefox:/var/lib/gems/1.8:/home/rstagner/.gem/ruby/1.8:/var/lib/gems/1.8/bin In addition to adding the "GEM PATHS" variables to my PATH environment, I've also included the "EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin" setting, which seemed to do the trick. Thanks for the information!!! Regards, Robert On Mon, Nov 8, 2010 at 5:23 PM, David Chelimsky wrote: > > On Nov 8, 2010, at 6:12 PM, Robert Stagner wrote: > > I've recently installed a copy of rspec (2.0.0) on my Linux distribution > (Ubuntu 9.10). All went well. However, when I attempt to access cucumber > from the shell, like so > > > > You mean "attempt to access rspec," right? > > $ rspec --help > > I receive the following: > > No command 'rspec' found > > I know there is a simple solution to this, likely dealing with the PATH > environment variable. Any help in pointing me to a solution where I can get > rspec setup on my PATH would be most appreciated. > > Please run "gem env" and look at the section of the output that starts with > "GEM PATHS" and make sure that all of the paths listed there (there may only > be one) are included in your PATH. > > HTH, > David > > I used the following command taken from the RSpec book to install rspec > > sudo gem intall rspec --version 2.0.0 > > Thanks. > > -- > Regards, > Robert > > _______________________________________________ > 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 > -- Regards, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From dlidstrom at gmail.com Tue Nov 9 13:14:29 2010 From: dlidstrom at gmail.com (=?ISO-8859-1?Q?Daniel_Lidstr=F6m?=) Date: Tue, 9 Nov 2010 10:14:29 -0800 (PST) Subject: [rspec-users] How to specify current directory for specs? Message-ID: <95709c81-8cef-4fe3-b315-6bca65629303@r4g2000prj.googlegroups.com> Hello, I'd like to know if it's possible to specify what directory to use as the current directory when executing the specifications. My specs are in spec/ and I have some data in spec/data that I want to read from one of the specs: spec/book_spec.rb require 'book' describe Book do it "should read version" do book = Book.new "data/JA_s12.book" # This should open the file book.version.should == 1 end end Of course I can prepend spec/ to the path above, but I'd rather not. I have created a rake task for running my specifications: desc "Run all specs in the spec directory" RSpec::Core::RakeTask.new('spec') do |t| t.rspec_opts = %w[--color] end Can I specify the spec/ directory as the current directory when running this task? What is the expert recommendation? Is the data for my specs malplaced, you think? Thanks in advance! Daniel From zach.dennis at gmail.com Tue Nov 9 18:12:35 2010 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 9 Nov 2010 18:12:35 -0500 Subject: [rspec-users] How to specify current directory for specs? In-Reply-To: <95709c81-8cef-4fe3-b315-6bca65629303@r4g2000prj.googlegroups.com> References: <95709c81-8cef-4fe3-b315-6bca65629303@r4g2000prj.googlegroups.com> Message-ID: On Tue, Nov 9, 2010 at 1:14 PM, Daniel Lidstr?m wrote: > Hello, > > I'd like to know if it's possible to specify what directory to use as > the current directory when executing the specifications. My specs are > in spec/ and I have some data in spec/data that I want to read from > one of the specs: > > spec/book_spec.rb > > require 'book' > You can do this by ensuring the spec/ directory is at the front of your load path, ie: $LOAD_PATH.unshift 'spec' or $:.unshift 'spec' This will make it so when Ruby tries to require "book.rb" it looks in the spec directory first. I wouldn't recommend this for loading spec helpers as it will take precedent over application code and you may run into strange issues. > describe Book do > it "should read version" do > book = Book.new "data/JA_s12.book" # This should open the file > book.version.should == 1 > end > end > > Of course I can prepend spec/ to the path above, but I'd rather not. I > have created a rake task for running my specifications: > > > desc "Run all specs in the spec directory" > RSpec::Core::RakeTask.new('spec') do |t| > t.rspec_opts = %w[--color] > end > > Can I specify the spec/ directory as the current directory when > running this task? What is the expert recommendation? Is the data for > my specs malplaced, you think? > Two things come to mind as how I might approach this: use spec_helper to always load seed-data, or use a different mechanism to load your seed data. (well there's a third, leave the require more verbose) The first would be to open up spec_helper.rb and have it always load seed data when rspec runs: Dir["#{File.dirname(__FILE__)}/data/**/*.rb"].each {|f| require f} The second would be to create a custom method so in your spec you would say: seed_data 'book' And then you can have seed_data know about the full path to require the data, ie: def seed_data(name) require "spec/data/#{name}" end As much as I like removing unnecessary requires in specs I prefer verbosity over magic -- anything that gives the code reader more clarity as to what's necessary for a particular example group. A third option might be to make this work for both your rake task and when running specs individually: require File.join(Rails.root, "spec/data/book") Hope this helps, Zach Thanks in advance! > > Daniel > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) -------------- next part -------------- An HTML attachment was scrubbed... URL: From todd.sedano at sv.cmu.edu Tue Nov 9 21:21:29 2010 From: todd.sedano at sv.cmu.edu (Todd Sedano) Date: Tue, 9 Nov 2010 18:21:29 -0800 Subject: [rspec-users] no output from rspec -- fixed Message-ID: Resend from 10/29/2010 due to bounce back. This is in reference to an email sent to the group on On Oct 18, 2010, at 1:24 AM. Short version: The solution was indeed to downgrade to test-unit 1.2.3 gem 'test-unit', '1.2.3' Longer version: I went through my github repository and found a version of my gemfile that worked with rspec. I then carefully compared the two versions and by process of elimination figured out what went wrong. My earlier Gemfile did not specify test-unit. Ironically, I had seen this solution posted on the internet and am convinced that I tried test-unit 1.2.3 on several occasions, but either I was doing something wrong, or bundler was confused, or somehow test-unit 2.x.x was sneaking in even when I was explicitly calling 1.2.3 -- I'm happy to have specs running again! > At one point, I had rspec working with my system and I've must have changed > the configuration because now I don't see anything in the output using rspec > 1.3. > Just to be clear, I see nothing when I type > spec spec > rake spec > bundle exec spec spec > bundle exec rake spec > (or any of the above with a specific spec file.) > > > I didn't see a debug option to see what is going wrong. > I'm using bundler. (Gemfile http://gist.github.com/631809). I've tried > uninstalling rspec 1.3 and rspec 2.0 (et al) My specs are in my rails > directory (ie project/spec) I'm on leopard (10.5.8) Just to be safe, I blew > out the bundler directories ( rm -rf ~/.bundle/ ~/.gem/ .bundle/ > vendor/cache/ Gemfile.lock) and the ~/.rvm directory > > Ironically, everything works nicely on my build machine. > I'm eagerly waiting for my move to Rails 3, this just isn't a good time for > me yet > I just tried creating a new project using the same Gemfile and it looks like > it is working in a vanilla rails project. I'm not sure where to begin to see > what my current project is doing to create this problem. > Any thoughts? > > Thanks! > Todd > Ps. I'm assuming that I can't use rspec 2.0.0 and rspec-rails-1.3 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jarmo.p at gmail.com Wed Nov 10 08:54:15 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 10 Nov 2010 05:54:15 -0800 (PST) Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> Message-ID: <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> I didn't get any replies about that problem so far but i just managed to find out how to make it work manually. The problem is that the bundle exec is not working like this on Windows: bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby But works like this: bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby.exe I don't understand who makes that decision what should be executed via bundler - is it RSpec? Rails? Bundler itself? Anyway, maybe someone knows what makes up that exec command so i can open up an issue at correct place. Jarmo On Oct 24, 9:20?pm, Jarmo Pertman wrote: > No ideas, what might cause that problem? Could it be a Windows-only- > issue? > > Jarmo > > On Oct 22, 3:46?pm,JarmoPertman wrote: > > > > > > > > > Hello! > > > I'm trying to run autotest under Windows when using Rails 3.0.1 and > > RSpec 2.0.1. It's not working so far. This is what happens: > > C:\Users\jarmo\Desktop\minu\projects\Ruby\sample_app>autotest > > loading autotest/rails_rspec2 > > style: RailsRspec2 > > bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby -S C:/bin/pik/Ruby-187- > > p302/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/bin/rspec --autotest 'C:/ > > Users/jarmo > > /Desktop/minu/projects/Ruby/sample_app/spec/controllers/ > > pages_controller_spec.rb' > > bundler: command not found: C:\bin\pik\Ruby-187-p302\bin\ruby > > Install missing gem binaries with `bundle install` > > > ... and then i have to interrupt it manually. > > > I have installed gems autotest and autotest-rails-pure. Anything else > > i have to do to get it running? > > >Jarmo > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Nov 10 09:06:55 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Nov 2010 08:06:55 -0600 Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> Message-ID: On Nov 10, 2010, at 7:54 AM, Jarmo Pertman wrote: > I didn't get any replies about that problem so far but i just managed > to find out how to make it work manually. What manual change did you make? > The problem is that the bundle exec is not working like this on > Windows: > bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby > > But works like this: > bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby.exe > > I don't understand who makes that decision what should be executed via > bundler - is it RSpec? Rails? Bundler itself? As of rspec-2.0, rspec prefixes the command with "bundle exec " if there is a Gemfile, but delegates to Autotest's definition of the ruby executable itself. There is already an issue open in rspec-core to have an opt-out for "bundle exec ", but that wouldn't change which ruby executable is used. Cheers, David > Anyway, maybe someone knows what makes up that exec command so i can > open up an issue at correct place. > > Jarmo > > On Oct 24, 9:20 pm, Jarmo Pertman wrote: >> No ideas, what might cause that problem? Could it be a Windows-only- >> issue? >> >> Jarmo >> >> On Oct 22, 3:46 pm,JarmoPertman wrote: >> >> >> >> >> >> >> >>> Hello! >> >>> I'm trying to run autotest under Windows when using Rails 3.0.1 and >>> RSpec 2.0.1. It's not working so far. This is what happens: >>> C:\Users\jarmo\Desktop\minu\projects\Ruby\sample_app>autotest >>> loading autotest/rails_rspec2 >>> style: RailsRspec2 >>> bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby -S C:/bin/pik/Ruby-187- >>> p302/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/bin/rspec --autotest 'C:/ >>> Users/jarmo >>> /Desktop/minu/projects/Ruby/sample_app/spec/controllers/ >>> pages_controller_spec.rb' >>> bundler: command not found: C:\bin\pik\Ruby-187-p302\bin\ruby >>> Install missing gem binaries with `bundle install` >> >>> ... and then i have to interrupt it manually. >> >>> I have installed gems autotest and autotest-rails-pure. Anything else >>> i have to do to get it running? >> >>> Jarmo >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jarmo.p at gmail.com Wed Nov 10 09:54:20 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 10 Nov 2010 06:54:20 -0800 (PST) Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> Message-ID: <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> On Nov 10, 4:06?pm, David Chelimsky wrote: > On Nov 10, 2010, at 7:54 AM,JarmoPertmanwrote: > > > I didn't get any replies about that problem so far but i just managed > > to find out how to make it work manually. > > What manual change did you make? > > > The problem is that the bundle exec is not working like this on > > Windows: > > bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby > > > But works like this: > > bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby.exe Sorry that i didn't bring it out more - i replaced bin\ruby with bin \ruby.exe and was able to run that bundle exec from the command line manually. So if the path to Ruby is constructed by RSpec then it is bug in RSpec's otherwise it could be somewhere else. Maybe even in bundler, which could just add that missing ".exe" by itself... That's why i'm asking. Jarmo From jarmo.p at gmail.com Wed Nov 10 10:21:50 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 10 Nov 2010 07:21:50 -0800 (PST) Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> Message-ID: Ok, the path is coming from autotest.rb in autotest gem. But i think that the bug is in Bundler instead: C:\Users\jarmo\Desktop\minu\projects\Ruby\sample_app>bundle exec c: \Ruby\bin\ruby --version bundler: command not found: c:\Ruby\bin\ruby Install missing gem binaries with `bundle install` C:\Users\jarmo\Desktop\minu\projects\Ruby\sample_app>bundle exec c: \Ruby\bin\ruby.exe --version ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32] Thank you for the tip, David! Jarmo On Nov 10, 4:54?pm, Jarmo Pertman wrote: > On Nov 10, 4:06?pm, David Chelimsky wrote: > > > On Nov 10, 2010, at 7:54 AM,JarmoPertmanwrote: > > > > I didn't get any replies about that problem so far but i just managed > > > to find out how to make it work manually. > > > What manual change did you make? > > > > The problem is that the bundle exec is not working like this on > > > Windows: > > > bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby > > > > But works like this: > > > bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby.exe > > Sorry that i didn't bring it out more - i replaced bin\ruby with bin > \ruby.exe and was able to run that bundle exec from the command line > manually. So if the path to Ruby is constructed by RSpec then it is > bug in RSpec's otherwise it could be somewhere else. Maybe even in > bundler, which could just add that missing ".exe" by itself... That's > why i'm asking. > > Jarmo > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Nov 10 10:23:21 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Nov 2010 09:23:21 -0600 Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> Message-ID: <38BEAD72-B174-4631-BA01-94C5EA7659DE@gmail.com> On Nov 10, 2010, at 8:54 AM, Jarmo Pertman wrote: > On Nov 10, 4:06 pm, David Chelimsky wrote: >> On Nov 10, 2010, at 7:54 AM,JarmoPertmanwrote: >> >>> I didn't get any replies about that problem so far but i just managed >>> to find out how to make it work manually. >> >> What manual change did you make? >> >>> The problem is that the bundle exec is not working like this on >>> Windows: >>> bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby >> >>> But works like this: >>> bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby.exe > > Sorry that i didn't bring it out more - i replaced bin\ruby with bin > \ruby.exe and was able to run that bundle exec from the command line > manually. So if the path to Ruby is constructed by RSpec then it is > bug in RSpec's otherwise it could be somewhere else. Maybe even in > bundler, which could just add that missing ".exe" by itself... That's > why i'm asking. RSpec subclasses Autotest (https://github.com/rspec/rspec-core/blob/master/lib/autotest/rspec2.rb#L5), generates the command, and delegates the ruby executable to Autotest (https://github.com/rspec/rspec-core/blob/master/lib/autotest/rspec2.rb#L44). So it is Autotest that is deciding what ruby command to use. Cheers, David From justin at malonekreativ.com Mon Nov 8 11:10:00 2010 From: justin at malonekreativ.com (Justin Malone) Date: Mon, 8 Nov 2010 08:10:00 -0800 Subject: [rspec-users] [Rails] `parse!': invalid option: --autotest (OptionParser::InvalidOption) Message-ID: Well, here it is. I am learning Rails and rSpec at the same time courtesy of Michael Hartl's tutorial. All was going good when this happened. rspec is woking on my other projects so I have no idea what I did wrong. I tryed removing files one by one from 'spec' directory to see if one of the files was jacked up but I either get nothing or this same thing. Please help if you know what I did wrong. ---------------------------------------------- When i run $ autotest, here is what I get back: bundle exec /usr/local/bin/ruby -S /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/bin/rspec --autotest '/Users/justin/Projects/hno/spec/controllers/pages_controller_spec.rb' '/Users/justin/Projects/hno/spec/controllers/sessions_controller_spec.rb' '/Users/justin/Projects/hno/spec/controllers/users_controller_spec.rb' '/Users/justin/Projects/hno/spec/models/user_spec.rb' '/Users/justin/Projects/hno/spec/requests/layout_links_spec.rb' '/Users/justin/Projects/hno/spec/requests/users_spec.rb' /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/option_parser.rb:17:in `parse!': invalid option: --autotest (OptionParser::InvalidOption) from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/option_parser.rb:4:in `parse!' from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/configuration_options.rb:64:in `parse_command_line_options' from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/configuration_options.rb:46:in `parse_options' from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/runner.rb:32:in `run' from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/runner.rb:10:in `block in autorun' ---------------------------------------------- Thanks in advance, Justin Malone -------------- next part -------------- An HTML attachment was scrubbed... URL: From yingkityuen at gmail.com Mon Nov 8 12:39:22 2010 From: yingkityuen at gmail.com (ykyuen) Date: Mon, 8 Nov 2010 09:39:22 -0800 (PST) Subject: [rspec-users] rspec and autotest integration problem Message-ID: <30163015.post@talk.nabble.com> Hi all, i am new to ruby and rails and i am following the tutorial in http://railstutorial.org/chapters/static-pages#sec:autotest railstutorial.org to setup the rspec and autotest in my Ubuntu 10.04 i have the following gems installed rspec (2.0.1) rspec-core (2.0.1) rspec-expectations (2.0.1) rspec-mocks (2.0.1) rspec-rails (2.0.1) test-unit (2.1.1) redgreen (1.2.2) ZenTest (4.4.0) autotest-rails-pure (4.1.0) autotest (4.4.2) i also have libnotify-bin installed in my Ubuntu 10.04. as well as adding ?require ?test/unit/ui/console/testrunner?? in my .autotest file. i have tested the notify-send command and it works well and i run the test case with ?rspec spec? without any problem. but when i run autotest. there is not popup in my ubuntu gnome. and when i quit the autotest by ^C^C. the following error is shown. ykyuen at ykyuen-laptop:~/Documents/RailsApplications/sample_app$ autotest loading autotest/rails # Waiting since 2010-11-05 00:05:52 ^CInterrupt a second time to quit ^C/home/ykyuen/.rvm/gems/ruby-1.9.2-p0/gems/test-unit-2.1.1/lib/test/unit/ui/console/testrunner.rb:29:in `initialize?: wrong number of arguments (3 for 2) (ArgumentError) from /home/ykyuen/.rvm/gems/ruby-1.9.2-p0/gems/redgreen-1.2.2/lib/redgreen.rb:17:in `initialize? from /home/ykyuen/.rvm/gems/ruby-1.9.2-p0/gems/test-unit-2.1.1/lib/test/unit/ui/testrunnerutilities.rb:24:in `new? from /home/ykyuen/.rvm/gems/ruby-1.9.2-p0/gems/test-unit-2.1.1/lib/test/unit/ui/testrunnerutilities.rb:24:in `run? from /home/ykyuen/.rvm/gems/ruby-1.9.2-p0/gems/test-unit-2.1.1/lib/test/unit/autorunner.rb:307:in `run? from /home/ykyuen/.rvm/gems/ruby-1.9.2-p0/gems/test-unit-2.1.1/lib/test/unit/autorunner.rb:52:in `run? ... and this is my .autotest. #!/bin/ruby require 'test/unit/ui/console/testrunner' require 'redgreen' #require 'test_notifier/runner/autotest' require 'autotest/timestamp' module Autotest::GnomeNotify def self.notify title, msg, img system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000" end Autotest.add_hook :ran_command do |at| image_root = "~/.autotest_images" results = [at.results].flatten.join("\n") results.gsub!(/\\e\[\d+m/,'') output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spending?|)/) full_sentence, green, failures, garbage, pending = $~.to_a.map(&:to_i) if output if failures > 0 notify "FAIL", "#{output}", "#{image_root}/fail.png" elsif pending > 0 notify "Pending", "#{output}", "#{image_root}/pending.png" else notify "Pass", "#{output}", "#{image_root}/pass.png" end end end end Have i missed anything? Thanks. -- View this message in context: http://old.nabble.com/rspec-and-autotest-integration-problem-tp30163015p30163015.html Sent from the rspec-users mailing list archive at Nabble.com. From jdelstrother at gmail.com Tue Nov 9 19:18:47 2010 From: jdelstrother at gmail.com (Jonathan del Strother) Date: Tue, 9 Nov 2010 16:18:47 -0800 (PST) Subject: [rspec-users] rspec-rails - expected helper_method behaviour in view specs Message-ID: <62854d23-f948-4693-bb33-d0ec6d5d9eb4@y23g2000yqd.googlegroups.com> Heya, Say I had the following app controller : class ApplicationController:view) ? In addition, rspec-rails1 used to mix all helpers into the view template, right? rspec-rails2 mixes in only the ApplicationHelper and the helper for the current spec, but this seems a strange choice when Rails includes all helpers by default. Any thoughts? -Jonathan From chad.ostrowski at gmail.com Wed Nov 10 06:44:22 2010 From: chad.ostrowski at gmail.com (Chad Ostrowski) Date: Wed, 10 Nov 2010 06:44:22 -0500 Subject: [rspec-users] undefined method `contain' for # Message-ID: Here's my Gemfile: group :development, :test do > gem 'rspec-rails', '2.0.0' > gem 'cucumber-rails', '0.3.2' > gem 'capybara', '0.4.0.rc' > end and here's my spec: describe "welcome/index.html.haml" do > it "displays 'Problem Child' in the header" do > render > rendered.should contain("Problem Child") > end > end This results in the error given in the subject: Failures: > 1) welcome/index.html.haml displays 'Problem Child' in the header > Failure/Error: rendered.should contain("Problem Child") > undefined method `contain' for > # Does the "contain" matcher come with Webrat? Is that why the RSpec book seems to be lying to me? I'm trying to get the feel of RSpec and I love the idea of speccing views. I've been approximately following along with The RSpec Book. I'm using Capybara instead of Webrat because Webrat wasn't playing well with Rails 3 (I forget the details). Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Nov 10 11:03:24 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Nov 2010 10:03:24 -0600 Subject: [rspec-users] undefined method `contain' for # In-Reply-To: References: Message-ID: <32B9C5FB-EDF0-4B1B-AC6D-889953E8FE1B@gmail.com> On Nov 10, 2010, at 5:44 AM, Chad Ostrowski wrote: > Here's my Gemfile: > > group :development, :test do > gem 'rspec-rails', '2.0.0' > gem 'cucumber-rails', '0.3.2' > gem 'capybara', '0.4.0.rc' > end > > and here's my spec: > > describe "welcome/index.html.haml" do > it "displays 'Problem Child' in the header" do > render > rendered.should contain("Problem Child") > end > end > > This results in the error given in the subject: > > Failures: > 1) welcome/index.html.haml displays 'Problem Child' in the header > Failure/Error: rendered.should contain("Problem Child") > undefined method `contain' for # > > Does the "contain" matcher come with Webrat? Is that why the RSpec book seems to be lying to me? I'm trying to get the feel of RSpec and I love the idea of speccing views. I've been approximately following along with The RSpec Book. I'm using Capybara instead of Webrat because Webrat wasn't playing well with Rails 3 (I forget the details). The book says "these examples use Webrat" and you choose Capybara (a perfectly good option, but not for the examples in the book). Not sure who is lying to you, but it is not the book :) Webrat works fine for all of the examples in the book. I'd recommend using it to go through the book to get the feel for the process. Also, Capybara's matchers are not available in view specs or helper specs (see https://github.com/rspec/rspec-rails/issues/closed#issue/242). HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Nov 10 11:05:53 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Nov 2010 10:05:53 -0600 Subject: [rspec-users] [Rails] `parse!': invalid option: --autotest (OptionParser::InvalidOption) In-Reply-To: References: Message-ID: On Nov 8, 2010, at 10:10 AM, Justin Malone wrote: > Well, here it is. I am learning Rails and rSpec at the same time courtesy of Michael Hartl's tutorial. All was going good when this happened. rspec is woking on my other projects so I have no idea what I did wrong. I tryed removing files one by one from 'spec' directory to see if one of the files was jacked up but I either get nothing or this same thing. Please help if you know what I did wrong. > > ---------------------------------------------- > > When i run $ autotest, here is what I get back: > > bundle exec /usr/local/bin/ruby -S /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/bin/rspec --autotest '/Users/justin/Projects/hno/spec/controllers/pages_controller_spec.rb' '/Users/justin/Projects/hno/spec/controllers/sessions_controller_spec.rb' '/Users/justin/Projects/hno/spec/controllers/users_controller_spec.rb' '/Users/justin/Projects/hno/spec/models/user_spec.rb' '/Users/justin/Projects/hno/spec/requests/layout_links_spec.rb' '/Users/justin/Projects/hno/spec/requests/users_spec.rb' > /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/option_parser.rb:17:in `parse!': invalid option: --autotest (OptionParser::InvalidOption) > from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/option_parser.rb:4:in `parse!' > from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/configuration_options.rb:64:in `parse_command_line_options' > from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/configuration_options.rb:46:in `parse_options' > from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/runner.rb:32:in `run' > from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.18/lib/rspec/core/runner.rb:10:in `block in autorun' Looks like you've got rspec-core-2.0.1 and rspec-core-2.0.0.beta.18. I'd recommend uninstalling the beta. HTH, David From jarmo.p at gmail.com Wed Nov 10 12:32:24 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 10 Nov 2010 09:32:24 -0800 (PST) Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: <38BEAD72-B174-4631-BA01-94C5EA7659DE@gmail.com> References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> <38BEAD72-B174-4631-BA01-94C5EA7659DE@gmail.com> Message-ID: <9a46d66f-c44d-40e9-9275-bb8ce1961f13@a37g2000yqi.googlegroups.com> Yup, understood and opened an issue in Bundler since it seems to be the culprit in the end: https://github.com/carlhuda/bundler/issues/issue/832 Just FYI if there's any other Windows/RSpec2/Autotest/Bundler user :) Jarmo On Nov 10, 5:23?pm, David Chelimsky wrote: > On Nov 10, 2010, at 8:54 AM,JarmoPertmanwrote: > > > > > > > > > > > On Nov 10, 4:06 pm, David Chelimsky wrote: > >> On Nov 10, 2010, at 7:54 AM,JarmoPertmanwrote: > > >>> I didn't get any replies about that problem so far but i just managed > >>> to find out how to make it work manually. > > >> What manual change did you make? > > >>> The problem is that the bundle exec is not working like this on > >>> Windows: > >>> bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby > > >>> But works like this: > >>> bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby.exe > > > Sorry that i didn't bring it out more - i replaced bin\ruby with bin > > \ruby.exe and was able to run that bundle exec from the command line > > manually. So if the path to Ruby is constructed by RSpec then it is > > bug in RSpec's otherwise it could be somewhere else. Maybe even in > > bundler, which could just add that missing ".exe" by itself... That's > > why i'm asking. > > RSpec subclasses Autotest (https://github.com/rspec/rspec-core/blob/master/lib/autotest/rspec2.r...), generates the command, and delegates the ruby executable to Autotest (https://github.com/rspec/rspec-core/blob/master/lib/autotest/rspec2.r...). So it is Autotest that is deciding what ruby command to use. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Nov 10 13:43:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Nov 2010 12:43:10 -0600 Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: <9a46d66f-c44d-40e9-9275-bb8ce1961f13@a37g2000yqi.googlegroups.com> References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> <38BEAD72-B174-4631-BA01-94C5EA7659DE@gmail.com> <9a46d66f-c44d-40e9-9275-bb8ce1961f13@a37g2000yqi.googlegroups.com> Message-ID: On Nov 10, 2010, at 11:32 AM, Jarmo Pertman wrote: > Yup, understood and opened an issue in Bundler since it seems to be > the culprit in the end: > https://github.com/carlhuda/bundler/issues/issue/832 > > Just FYI if there's any other Windows/RSpec2/Autotest/Bundler user :) Nope. Think you're the only one :) Thanks for following up on this. Cheers, David > > Jarmo > > On Nov 10, 5:23 pm, David Chelimsky wrote: >> On Nov 10, 2010, at 8:54 AM,JarmoPertmanwrote: >> >> >> >> >> >> >> >> >> >>> On Nov 10, 4:06 pm, David Chelimsky wrote: >>>> On Nov 10, 2010, at 7:54 AM,JarmoPertmanwrote: >> >>>>> I didn't get any replies about that problem so far but i just managed >>>>> to find out how to make it work manually. >> >>>> What manual change did you make? >> >>>>> The problem is that the bundle exec is not working like this on >>>>> Windows: >>>>> bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby >> >>>>> But works like this: >>>>> bundle exec C:\bin\pik\Ruby-187-p302\bin\ruby.exe >> >>> Sorry that i didn't bring it out more - i replaced bin\ruby with bin >>> \ruby.exe and was able to run that bundle exec from the command line >>> manually. So if the path to Ruby is constructed by RSpec then it is >>> bug in RSpec's otherwise it could be somewhere else. Maybe even in >>> bundler, which could just add that missing ".exe" by itself... That's >>> why i'm asking. >> >> RSpec subclasses Autotest (https://github.com/rspec/rspec-core/blob/master/lib/autotest/rspec2.r...), generates the command, and delegates the ruby executable to Autotest (https://github.com/rspec/rspec-core/blob/master/lib/autotest/rspec2.r...). So it is Autotest that is deciding what ruby command to use. >> >> Cheers, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From luislavena at gmail.com Wed Nov 10 14:56:27 2010 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 10 Nov 2010 16:56:27 -0300 Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> <38BEAD72-B174-4631-BA01-94C5EA7659DE@gmail.com> <9a46d66f-c44d-40e9-9275-bb8ce1961f13@a37g2000yqi.googlegroups.com> Message-ID: On Wed, Nov 10, 2010 at 3:43 PM, David Chelimsky wrote: > On Nov 10, 2010, at 11:32 AM, Jarmo Pertman wrote: > >> Yup, understood and opened an issue in Bundler since it seems to be >> the culprit in the end: >> https://github.com/carlhuda/bundler/issues/issue/832 >> >> Just FYI if there's any other Windows/RSpec2/Autotest/Bundler user :) > > Nope. Think you're the only one :) > If you strip down the Bundler part, I'm under the same environment too :P While I can complain about Bundler doing weird things on Windows I decided to stop using it and switched to Isolate and invoke commands with "rake isolate:sh[autotest]" As for autotest coloring issues, for the ones wondering, we (RubyInstaller) are working on permanent ANSI coloring solutions for those Windows users. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From jarmo.p at gmail.com Wed Nov 10 15:48:48 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 10 Nov 2010 12:48:48 -0800 (PST) Subject: [rspec-users] Upgrade problems/questions regarding RSpec 1.3.0 to 2.0.1 In-Reply-To: <3adbe31d-19b2-4e1c-b86a-42d69de02e28@j25g2000yqa.googlegroups.com> References: <67467f45-dddd-42d0-84ff-92fe9aef74b8@g13g2000yqj.googlegroups.com> <7BC2E7F2-2984-45C6-BCBD-C87CD7B42D57@gmail.com> <3adbe31d-19b2-4e1c-b86a-42d69de02e28@j25g2000yqa.googlegroups.com> Message-ID: <798c269f-04fc-4ed6-a554-15598b02d6a5@g25g2000yqn.googlegroups.com> Still no pointers about the small problem below? On Nov 5, 10:29?pm, Jarmo Pertman wrote: > On Nov 5, 1:52?pm, David Chelimsky wrote: > > > > 4) In 1.x i modified ExampleGroup's description in my html formatter > > > to have some additional information in it like timestamp. I did it in > > > example_group_started where the passed variable example_group was an > > > instance of the ExampleGroup. In 2.x this is just a class name. How > > > can i accomplish the similar functionality? > > > You can write a custom subclass of the HtmlFormatter and add whatever you like. > > Since i don't consider this as an issue to be reported at GitHub > rather than a new way to do things then i just want to know how should > i do this. I understand that i can write a custom subclass of the > HtmlFormatter and do there whatever i like. This is the actual case - > i already have an subclass of HtmlFormatter, but the problem is that > super class is acting differently than it was in 1.x. > > In HtmlFormatter#example_group_started a parameter called > example_group was an actual instance of the current ExampleGroup in > 1.x thus i were able to modify it's description so it would have > additional information in my custom html formatter report. In 2.x the > parameter example_group is not anymore an instance of an ExampleGroup, > but just a class constant for runtime ExampleGroup class, thus there's > nothing useful to do with that parameter anymore. How should/could i > modify the description now? I'm afraid that in > HtmlFormatter#example_started where i could access the ExampleGroup > from the Example instance it's already too late since ExampleGroup > description might be already flushed to the report. Haven't tried that > yet though. > > Hopefully you understand my concern better now. > > Jarmo Pertman From dlidstrom at gmail.com Wed Nov 10 15:59:02 2010 From: dlidstrom at gmail.com (=?ISO-8859-1?Q?Daniel_Lidstr=F6m?=) Date: Wed, 10 Nov 2010 12:59:02 -0800 (PST) Subject: [rspec-users] How to specify current directory for specs? In-Reply-To: References: <95709c81-8cef-4fe3-b315-6bca65629303@r4g2000prj.googlegroups.com> Message-ID: <8edfd65d-e2a9-4589-8ea0-db54bc9c7697@32g2000yqz.googlegroups.com> Hi Zach, thanks for your detailed answer. I think I need some clarifications: I am not using Rails, I have a regular ruby project. When I say I need to read a file, I am talking about a binary file with Othello positions, not a spec helper. It is not a file I can 'require-in'. Sorry for the confusion. Daniel From jarmo.p at gmail.com Wed Nov 10 16:29:03 2010 From: jarmo.p at gmail.com (Jarmo Pertman) Date: Wed, 10 Nov 2010 13:29:03 -0800 (PST) Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> <38BEAD72-B174-4631-BA01-94C5EA7659DE@gmail.com> <9a46d66f-c44d-40e9-9275-bb8ce1961f13@a37g2000yqi.googlegroups.com> Message-ID: On Nov 10, 9:56?pm, Luis Lavena wrote: > If you strip down the Bundler part, I'm under the same environment too :P > > While I can complain about Bundler doing weird things on Windows I > decided to stop using it and switched to Isolate and invoke commands > with "rake isolate:sh[autotest]" I'm still staying with it in hope of it getting better and trying to give my feedback about it. Hopefully it doesn't do weird things on Windows at some point. > As for autotest coloring issues, for the ones wondering, we > (RubyInstaller) are working on permanent ANSI coloring solutions for > those Windows users. Thanks! I didn't even bother about writing about that since the coloring issues are happening quite often here and there. At least RSpec seems to work nowadays with that correctly. Can you share some more (even technical) information about these solutions? Maybe through some other channel if this might get too offtopic in here... Jarmo > > -- > Luis Lavena > AREA 17 > - > Perfection in design is achieved not when there is nothing more to add, > but rather when there is nothing more to take away. > Antoine de Saint-Exup?ry > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From rhett at detailedbalance.net Wed Nov 10 16:50:17 2010 From: rhett at detailedbalance.net (Rhett Sutphin) Date: Wed, 10 Nov 2010 15:50:17 -0600 Subject: [rspec-users] How to specify current directory for specs? In-Reply-To: <8edfd65d-e2a9-4589-8ea0-db54bc9c7697@32g2000yqz.googlegroups.com> References: <95709c81-8cef-4fe3-b315-6bca65629303@r4g2000prj.googlegroups.com> <8edfd65d-e2a9-4589-8ea0-db54bc9c7697@32g2000yqz.googlegroups.com> Message-ID: <00A6980B-DC48-4149-A139-218473901337@detailedbalance.net> Hi Daniel, On Nov 10, 2010, at 2:59 PM, Daniel Lidstr?m wrote: > Hi Zach, > > thanks for your detailed answer. I think I need some clarifications: I > am not using Rails, I have a regular ruby project. When I say I need > to read a file, I am talking about a binary file with Othello > positions, not a spec helper. It is not a file I can 'require-in'. You can change the working directory for the process using FileUtils.cd. If you want to change the directory for all your specs, you could do something like: # In spec/spec_helper.rb require 'fileutils' # ... RSpec.configure do |config| config.before FileUtils.cd File.dirname(__FILE__) end end You could do the same thing for particular specs if that works better with what you want. Just adjust the path. As an alternative, you might also consider having a helper like this: # again, in spec/spec_helper.rb def spec_path(path) File.expand_path("../spec", __FILE__) end which you would use like so: book = Book.new spec_path("data/JA_s12.book") This has the benefit of being more explicit / less surprising to other developers (including your future self), since the relative path for spec execution is usually the project root. Rhett > Sorry for the confusion. > > Daniel > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From luislavena at gmail.com Wed Nov 10 18:55:06 2010 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 10 Nov 2010 20:55:06 -0300 Subject: [rspec-users] autotest not working on Windows with rails3 and rspec2? In-Reply-To: References: <3177090c-9511-4573-84a6-3f76e887b90d@e14g2000yqe.googlegroups.com> <3bce1ce4-0b2f-4ed9-a35b-83d1937b484a@l32g2000yqc.googlegroups.com> <63c0988c-508e-44bb-b2d2-e1ad4c63fb11@t35g2000yqj.googlegroups.com> <38BEAD72-B174-4631-BA01-94C5EA7659DE@gmail.com> <9a46d66f-c44d-40e9-9275-bb8ce1961f13@a37g2000yqi.googlegroups.com> Message-ID: On Wed, Nov 10, 2010 at 6:29 PM, Jarmo Pertman wrote: > > Can you share some more (even technical) information about these > solutions? Maybe through some other channel if this might get too > offtopic in here... > Search ANSICON and win32console on Rubyinstaller group: http://groups.google.com/group/rubyinstaller/browse_thread/thread/2d2a62db7281509a/ http://groups.google.com/group/rubyinstaller/browse_thread/thread/be67b409e483db20# First was the proposal and the first case of problems. The second was a full investigation and the offer of a bounty to get it fixed. Any question or problems you have running Ruby on Windows (RubyInstaller by preference), please don't hesitate to ask in RubyInstaller group. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From dolzenko at gmail.com Thu Nov 11 02:23:41 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Thu, 11 Nov 2010 10:23:41 +0300 Subject: [rspec-users] rspec-rails - expected helper_method behaviour in view specs In-Reply-To: <62854d23-f948-4693-bb33-d0ec6d5d9eb4@y23g2000yqd.googlegroups.com> References: <62854d23-f948-4693-bb33-d0ec6d5d9eb4@y23g2000yqd.googlegroups.com> Message-ID: Not sure why helper_method doesn't work, but just `helper` definetely works for us https://github.com/rails/rails/blob/master/actionpack/lib/abstract_controller/helpers.rb#L96 (supports various ways to specify desired helper). +1 on question about Rails including all helpers vs. RSpec doing it the Rails 2 way On Wed, Nov 10, 2010 at 3:18 AM, Jonathan del Strother wrote: > Heya, > > Say I had the following app controller : > class ApplicationController ?def logged_in? > ? ?true > ?end > ?helper_method :logged_in? > end > > Under a rspec-rails1 view-spec, a view template would be able to call > logged_in?. ?It seems this behaviour has gone away in rspec-rails2. > Was this behaviour intentional? ?What's the recommended alternative - > mixing in a helper to stub out all these methods with > config.include(HelperMethodsStubber, :type=>:view) ?? > > > In addition, rspec-rails1 used to mix all helpers into the view > template, right? ? rspec-rails2 mixes in only the ApplicationHelper > and the helper for the current spec, but this seems a strange choice > when Rails includes all helpers by default. > > Any thoughts? > > -Jonathan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Nov 11 07:49:06 2010 From: lists at ruby-forum.com (Dean Richardson) Date: Thu, 11 Nov 2010 13:49:06 +0100 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com> References: , <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com>, <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com>, <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com> Message-ID: <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com> David: Thanks for your help. I've followed the set-up instructions in the "BDD in Rails" chapter successfully up to the "rake db:test:prepare" step. At that point, I get the following error: rake aborted! no such file to load -- sqlite3 I've attached a document containing my "gem list" output showing the presence of the sqlite3-ruby gem and other associated dependencies. The document also gives the content of my database.yml file for reference. I'm using mysql for my development and production databases. When I try to switch my test database to mysql too, by editing the "test:" section of database.yml, I get the following error: rake aborted! Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Both of these errors are widely-discussed on message boards, stack overflow, etc., but none of the fixes I've found so far there seem to help. Any suggestions for how to make either test database approach (sqlite3 or mysql) work would be greatly appreciated. Thanks again for your help, Dean Richardson David Chelimsky wrote in post #960323: > On Nov 9, 2010, at 6:38 AM, Dean Richardson wrote: > >>>> >> >> David: >> >> Thanks for prompting me to get the update of the book. So, if I'm not >> quite ready to make the leap to Rails 3, am I out of luck trying to use >> RSpec and Cucumber? Is there any intermediate strategy you can suggest? > > rspec-1.3 works fine with rails-2.3, and there are notes about how to > set this up in the "BDD in Rails" chapter. > > The RSpec Book is more of a workflow/strategy/process book than a > recipe/syntax book. The latter is present, but not the focus. I'd > recommend using the versions in the book (listed in the preface) to go > through the exercises so you can learn how to use these tools > effectively, and then comb the interwebs for information about whatever > syntactic differences might be missing from the book. You can also write > to this list if you have questions about the differences between > versions. > > HTH, > David Attachments: http://www.ruby-forum.com/attachment/5341/rake_db_test_prepare_problem.rtf -- Posted via http://www.ruby-forum.com/. From nellboy at gmail.com Thu Nov 11 07:54:58 2010 From: nellboy at gmail.com (Paul Nelligan) Date: Thu, 11 Nov 2010 12:54:58 +0000 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com> References: <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com> <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com> <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com> <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com> Message-ID: Hi Dean it seems that you have sqlite3-ruby installed, but not sqlite3 installed ... 'gem install sqlite3' might fix it ? cheers Paul On Thu, Nov 11, 2010 at 12:49 PM, Dean Richardson wrote: > David: > > Thanks for your help. I've followed the set-up instructions in the "BDD > in Rails" chapter successfully up to the "rake db:test:prepare" step. At > that point, I get the following error: > > rake aborted! > no such file to load -- sqlite3 > > I've attached a document containing my "gem list" output showing the > presence of the sqlite3-ruby gem and other associated dependencies. The > document also gives the content of my database.yml file for reference. > I'm using mysql for my development and production databases. > > When I try to switch my test database to mysql too, by editing the > "test:" section of database.yml, I get the following error: > > rake aborted! > Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) > > Both of these errors are widely-discussed on message boards, stack > overflow, etc., but none of the fixes I've found so far there seem to > help. > > Any suggestions for how to make either test database approach (sqlite3 > or mysql) work would be greatly appreciated. > > Thanks again for your help, > > Dean Richardson > > > > > > > > David Chelimsky wrote in post #960323: > > On Nov 9, 2010, at 6:38 AM, Dean Richardson wrote: > > > >>>> > >> > >> David: > >> > >> Thanks for prompting me to get the update of the book. So, if I'm not > >> quite ready to make the leap to Rails 3, am I out of luck trying to use > >> RSpec and Cucumber? Is there any intermediate strategy you can suggest? > > > > rspec-1.3 works fine with rails-2.3, and there are notes about how to > > set this up in the "BDD in Rails" chapter. > > > > The RSpec Book is more of a workflow/strategy/process book than a > > recipe/syntax book. The latter is present, but not the focus. I'd > > recommend using the versions in the book (listed in the preface) to go > > through the exercises so you can learn how to use these tools > > effectively, and then comb the interwebs for information about whatever > > syntactic differences might be missing from the book. You can also write > > to this list if you have questions about the differences between > > versions. > > > > HTH, > > David > > Attachments: > http://www.ruby-forum.com/attachment/5341/rake_db_test_prepare_problem.rtf > > > -- > 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 Nov 11 08:53:19 2010 From: lists at ruby-forum.com (Dean Richardson) Date: Thu, 11 Nov 2010 14:53:19 +0100 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: References: , <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com>, <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com>, <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com>, <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com>, Message-ID: <6b880e826ec2aea449954dfda5a52b1c@ruby-forum.com> Paul: Thanks for taking the time to respond... that sounds like an attractively simple solution. When I go to try it, though, I'm told that the sqlite3 gem requires at least Ruby 1.9.1, and I'm still working with 1.8.7. Also, I'm already running a bunch of applications on this machine (MBP) that use sqlite3 successfully. Is there a version of sqlite3 that might help eliminate the error but which doesn't require Ruby 1.9.1? Or is the upgrade path the only one that's likely to work for me? Again, thanks for your help... --Dean Paul Nelligan wrote in post #960723: > Hi Dean > > it seems that you have sqlite3-ruby installed, but not sqlite3 installed > ... > 'gem install sqlite3' might fix it ? > > cheers > > Paul -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Nov 11 09:12:02 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Nov 2010 08:12:02 -0600 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: <6b880e826ec2aea449954dfda5a52b1c@ruby-forum.com> References: , <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com>, <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com>, <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com>, <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com>, <6b880e826ec2aea449954dfda5a52b1c@ruby-forum.com> Message-ID: <537B05AE-32F6-4F8F-8C0B-A63E90190DA0@gmail.com> On Nov 11, 2010, at 7:53 AM, Dean Richardson wrote: > Paul: > > Thanks for taking the time to respond... that sounds like an > attractively simple solution. When I go to try it, though, I'm told that > the sqlite3 gem requires at least Ruby 1.9.1, and I'm still working with > 1.8.7. Also, I'm already running a bunch of applications on this machine > (MBP) that use sqlite3 successfully. > > Is there a version of sqlite3 that might help eliminate the error but > which doesn't require Ruby 1.9.1? Or is the upgrade path the only one > that's likely to work for me? > > Again, thanks for your help... You need the sqlite3 library (not the sqlite3 gem) and the sqlite3-ruby gem. HTH, David > > --Dean > > Paul Nelligan wrote in post #960723: >> Hi Dean >> >> it seems that you have sqlite3-ruby installed, but not sqlite3 installed >> ... >> 'gem install sqlite3' might fix it ? >> >> cheers >> >> Paul > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From luislavena at gmail.com Thu Nov 11 09:35:55 2010 From: luislavena at gmail.com (Luis Lavena) Date: Thu, 11 Nov 2010 11:35:55 -0300 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com> References: <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com> <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com> <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com> <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com> Message-ID: On Thu, Nov 11, 2010 at 9:49 AM, Dean Richardson wrote: > David: > > Thanks for your help. I've followed the set-up instructions in the "BDD > in Rails" chapter successfully up to the "rake db:test:prepare" step. At > that point, I get the following error: > > rake aborted! > no such file to load -- sqlite3 > > I've attached a document containing my "gem list" output showing the > presence of the sqlite3-ruby gem and other associated dependencies. The > document also gives the content of my database.yml file for reference. > I'm using mysql for my development and production databases. > > When I try to switch my test database to mysql too, by editing the > "test:" section of database.yml, I get the following error: > > rake aborted! > Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) > > Both of these errors are widely-discussed on message boards, stack > overflow, etc., but none of the fixes I've found so far there seem to > help. > > Any suggestions for how to make either test database approach (sqlite3 > or mysql) work would be greatly appreciated. > Hello, To better understand what is going on with sqlite3 adapter will require more details. As for the mysql error, in your database.yml, just copy your configuration from development section and rename the database to your test one. Ensure the socket line is not there, as is the one affecting your mysql execution. HTH, -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From lists at ruby-forum.com Thu Nov 11 09:40:27 2010 From: lists at ruby-forum.com (Dean Richardson) Date: Thu, 11 Nov 2010 15:40:27 +0100 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: References: , <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com>, <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com>, <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com>, <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com>, Message-ID: <8d2bd0a597ac2befc77a4a781cef8878@ruby-forum.com> Hi Luis: Thanks for the rapid response. I'll work on your MySQL fix... in the meantime, what further details can I provide regarding the sqlite3 adapter issue? --Dean Luis Lavena wrote in post #960735: > On Thu, Nov 11, 2010 at 9:49 AM, Dean Richardson > wrote: >> presence of the sqlite3-ruby gem and other associated dependencies. The >> overflow, etc., but none of the fixes I've found so far there seem to >> help. >> >> Any suggestions for how to make either test database approach (sqlite3 >> or mysql) work would be greatly appreciated. >> > > Hello, > > To better understand what is going on with sqlite3 adapter will > require more details. > > As for the mysql error, in your database.yml, just copy your > configuration from development section and rename the database to your > test one. > > Ensure the socket line is not there, as is the one affecting your > mysql execution. > > HTH, > -- > Luis Lavena > AREA 17 > - > Perfection in design is achieved not when there is nothing more to add, > but rather when there is nothing more to take away. > Antoine de Saint-Exupry -- Posted via http://www.ruby-forum.com/. From luislavena at gmail.com Thu Nov 11 10:29:27 2010 From: luislavena at gmail.com (Luis Lavena) Date: Thu, 11 Nov 2010 12:29:27 -0300 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: <8d2bd0a597ac2befc77a4a781cef8878@ruby-forum.com> References: <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com> <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com> <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com> <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com> <8d2bd0a597ac2befc77a4a781cef8878@ruby-forum.com> Message-ID: On Thu, Nov 11, 2010 at 11:40 AM, Dean Richardson wrote: > Hi Luis: > > Thanks for the rapid response. I'll work on your MySQL fix... in the > meantime, what further details can I provide regarding the sqlite3 > adapter issue? > If you can create a simple new rails application it will use sqlite3 by default, try to execute rake db:migrate and db:test:prepare there and see if the error is reproducible. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From lists at ruby-forum.com Thu Nov 11 10:48:08 2010 From: lists at ruby-forum.com (Dean Richardson) Date: Thu, 11 Nov 2010 16:48:08 +0100 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: References: , <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com>, <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com>, <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com>, <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com>, , <8d2bd0a597ac2befc77a4a781cef8878@ruby-forum.com>, Message-ID: Luis: This was really helpful advice. I went ahead and simply created the "showtime" rails app using the guidelines under section 19.3 of The RSpec Book: No problems whatsoever with rake db:test:prepare. This should have been obvious to me because I just went through that chapter a few weeks back. I then went into the config directory for showtime and changed the database.yml file... so that the development and test sections looked like they do in my genlighten app. I repeated rake db:test:prepare, and it still worked fine. Of course, when I went through Michael Hartl's Rails Tutorial book several months ago, I was able to use rspec and rake db:test:prepare there successfully, in another directory on my same machine, so it shouldn't surprise me that a "clean" app works. Unfortunately, however, I'm afraid I'm still clueless as to what's so different about the genlighten app's configuration/setup that it fails to find sqlite3 (if that's even what's really going on...) --Dean BTW, your suggested fix to the "test:" section in my database.yml file for using mysql on my test database worked flawlessly. Thanks! Luis Lavena wrote in post #960752: > On Thu, Nov 11, 2010 at 11:40 AM, Dean Richardson > wrote: >> Hi Luis: >> >> Thanks for the rapid response. I'll work on your MySQL fix... in the >> meantime, what further details can I provide regarding the sqlite3 >> adapter issue? >> > > If you can create a simple new rails application it will use sqlite3 > by default, try to execute rake db:migrate and db:test:prepare there > and see if the error is reproducible. > -- > Luis Lavena > AREA 17 > - > Perfection in design is achieved not when there is nothing more to add, > but rather when there is nothing more to take away. > Antoine de Saint-Exupry -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Nov 11 14:32:33 2010 From: lists at ruby-forum.com (Dean Richardson) Date: Thu, 11 Nov 2010 20:32:33 +0100 Subject: [rspec-users] "no such file to load -- sqlite3" error In-Reply-To: References: , <440A368C-D703-4162-A8CC-02A68EABFA83@gmail.com>, <34b4c47cfef3bfa3a6e557b033384a70@ruby-forum.com>, <42D9CBB6-AAFF-43CE-AE95-AF821E47DCFB@gmail.com>, <8e8588660cbf817cd7065b114571f7cc@ruby-forum.com>, Message-ID: Luis: Since your suggested change to database.yml got rake db:test:prepare to work when using mysql for the test database, I went ahead and tried to rake spec and rake cucumber for my app. "rake spec" produced the same error that originally led to this thread: rake aborted! *************************************************************************** * You are trying to run an rspec rake task defined in * /Users/Lowell/rails_projects/genlighten_dr/lib/tasks/rspec.rake, * but rspec can not be found in vendor/gems, vendor/plugins or system gems. *************************************************************************** Fortunately, however entering 'spec spec/' works fine (i.e., produces no output and a command prompt, since my app currently has no tests.) I worry that I have some gems in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby /gems/1.8/gems (rails 2.3.5, for instance, but not rspec or cucumber) and lots of other gems in /Library/Ruby/Gems/1.8/gems (another copy of rails 2.3.5, plus rspec and components, cucumber and components, and a ton of other stuff) and that the rake task is confused about where to look. Any suggestions on whether that might be the issue and if so, how to address it? Thanks once more... Dean Luis Lavena wrote in post #960735: > On Thu, Nov 11, 2010 at 9:49 AM, Dean Richardson > wrote: >> presence of the sqlite3-ruby gem and other associated dependencies. The >> overflow, etc., but none of the fixes I've found so far there seem to >> help. >> >> Any suggestions for how to make either test database approach (sqlite3 >> or mysql) work would be greatly appreciated. >> > > Hello, > > To better understand what is going on with sqlite3 adapter will > require more details. > > As for the mysql error, in your database.yml, just copy your > configuration from development section and rename the database to your > test one. > > Ensure the socket line is not there, as is the one affecting your > mysql execution. > > HTH, > -- > Luis Lavena > AREA 17 > - > Perfection in design is achieved not when there is nothing more to add, > but rather when there is nothing more to take away. > Antoine de Saint-Exupry -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Nov 12 04:56:06 2010 From: lists at ruby-forum.com (Arun Sharma) Date: Fri, 12 Nov 2010 10:56:06 +0100 Subject: [rspec-users] In spec/controller file not taking controller property Message-ID: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> I am working on Rspec for Controller testing.I am initial leve of rspec.I have a problem that in Spec/controller directory rspec file is not taking controller property as (instance varibale,flash notice) My controller code is as follow class PortalNewsController < ApplicationController def index redirect_to root_path end def show @portal_news = PortalNews.find(params[:id]) respond_to do |format| format.html {render :action => 'show', :layout => false}# show.html.erb format.xml { render :xml => @portal_news } end end # GET /portal_news/new # GET /portal_news/new.xml def new @portal_news = PortalNews.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @portal_news } end end # GET /portal_news/1/edit def edit @portal_news = PortalNews.find(params[:id]) end # POST /portal_news # POST /portal_news.xml def create @portal_news = PortalNews.new(params[:portal_news]) puts "arundjfhdjfh" respond_to do |format| if @portal_news.save flash[:notice] = 'PortalNews was successfully created.' format.html { redirect_to root_path } format.xml { render :xml => @portal_news, :status => :created, :location => @portal_news } else format.html { render :action => "new" } format.xml { render :xml => @portal_news.errors, :status => :unprocessable_entity } end end end # PUT /portal_news/1 # PUT /portal_news/1.xml def update @portal_news = PortalNews.find(params[:id]) respond_to do |format| if @portal_news.update_attributes(params[:portal_news]) flash[:notice] = 'PortalNews was successfully updated.' format.html { redirect_to root_path } format.xml { head :ok } else flash[:notice] = 'PortalNews was not successfully updated.' format.html { render :action => "edit" } format.xml { render :xml => @portal_news.errors, :status => :unprocessable_entity } end end end # DELETE /portal_news/1 # DELETE /portal_news/1.xml def destroy @portal_news = PortalNews.find(params[:id]) @portal_news.destroy respond_to do |format| format.html { redirect_to root_path } format.xml { head :ok } end end private # Check for superadmin def is_superadmin? if !current_user.is_superadmin flash[:error] = "Permission denied." redirect_to root_path end end end And my rspec file code is rspec/controllers/portal_news_controller_spec.rb require File.dirname(__FILE__) +'/../spec_helper' describe PortalNewsController do integrate_views :true controller_name :portal_news it "should_be_redirect_to_root_path" do get :index response.should redirect_to('/login') end it "should_show " do PortalNews.any_instance.stubs(:find).returns(@portal_news) PortalNews.any_instance.stubs(:show).returns(true) get :show, :id=>1 response.should render_template('show') end it "should_redirect_to_root_with_successfull_notice" do post :create,:heading=>nil assigns[:portal_news].errors.on(:heading).should_not be_nil flash[:error].should_not be_nil end it "should_re-render_new_template_on_failed_save" do PortalNews.any_instance.stubs(:valid?).returns(false) post :create assigns[:portal_news].should be_new_record flash[:notice].should be_nil response.should render_template('http://test.host/portal_news/new') end it"should_pass_the_param_value" do post :create,:portal_news => {:user_id => 11} assigns[:portal_news].user_id.should =11 end it "should_be update_on_valid_attributes" do PortalNews.any_instance.stubs(:find).returns(@portal_news) PortalNews.any_instance.stubs(:update_attributes).with(@portal_news).returns(true) put :update, :id =>23 response.should redirect_to('/login') flash[:notice].should_not be_nil end it "should_be update_on_invalid_attributes" do PortalNews.any_instance.stubs(:find).returns(@portal_news) PortalNews.any_instance.stubs(:update_attributes).with(@portal_news).returns(false) put :update, :id =>23 response.should redirect_to('/login') flash[:notice].should_not be_nil end it "should_check_variable" do put :update,:id =>{:user_id =>11} assigns[:id].user_id.should =11 end end And i am geeting error as follow 1 NoMethodError in 'PortalNewsController should_redirect_to_root_with_successfull_notice' 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.errors 2 NoMethodError in 'PortalNewsController should_re-render_new_template_on_failed_save' 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.new_record? ----- Please post solution of this problem 3 NoMethodError in 'PortalNewsController should_pass_the_param_value' undefined method `user_id' for nil:NilClass -- Posted via http://www.ruby-forum.com/. From dlidstrom at gmail.com Fri Nov 12 05:48:13 2010 From: dlidstrom at gmail.com (=?ISO-8859-1?Q?Daniel_Lidstr=F6m?=) Date: Fri, 12 Nov 2010 02:48:13 -0800 (PST) Subject: [rspec-users] How to specify current directory for specs? In-Reply-To: <00A6980B-DC48-4149-A139-218473901337@detailedbalance.net> References: <95709c81-8cef-4fe3-b315-6bca65629303@r4g2000prj.googlegroups.com> <8edfd65d-e2a9-4589-8ea0-db54bc9c7697@32g2000yqz.googlegroups.com> <00A6980B-DC48-4149-A139-218473901337@detailedbalance.net> Message-ID: On 10 Nov, 22:50, Rhett Sutphin wrote: > Hi Daniel, > [...] > As an alternative, you might also consider having a helper like this: > > # again, in spec/spec_helper.rb > def spec_path(path) > ? File.expand_path("../spec", __FILE__) > end > > which you would use like so: > > book = Book.new spec_path("data/JA_s12.book") > > This has the benefit of being more explicit / less surprising to other developers (including your future self), since the relative path for spec execution is usually the project root. Hi Rhett, the above alternative looks very promising to me. Thanks for the suggestion! Daniel From lists at ruby-forum.com Fri Nov 12 06:13:33 2010 From: lists at ruby-forum.com (Arun Sharma) Date: Fri, 12 Nov 2010 12:13:33 +0100 Subject: [rspec-users] In spec/controller file not taking controller property In-Reply-To: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> References: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> Message-ID: <5c5d60d9bda6907f9475eaaa7b3b17d3@ruby-forum.com> I am waiting for reply -- Posted via http://www.ruby-forum.com/. From ole.morten.amundsen at gmail.com Fri Nov 12 08:23:59 2010 From: ole.morten.amundsen at gmail.com (Ole Morten Amundsen) Date: Fri, 12 Nov 2010 14:23:59 +0100 Subject: [rspec-users] pending tests fail when I switch to mock_with :mocha Message-ID: First of all, please direct me into how better to search existing threads in this mailing list. Ok to my rspec 2.0.1 mocha 0.9.8 issue: given a controller test before do subject.expects(:authenticate).once end it "should bla bla" do pending "PENDING, shouldn't fail?" end with config.mock_with :rspec it's ok: pending, but with config.mock_with :mocha if fails! It expected the authenticate to be called. What do I have to do to make it compatible? Reason for using mocha, is A: I'm used to it B: I don't know rspec mocks too well, but it notice that these mocks live across tests, breaking unrelated model specs. cheers! oma -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Nov 12 08:47:28 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 12 Nov 2010 07:47:28 -0600 Subject: [rspec-users] In spec/controller file not taking controller property In-Reply-To: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> References: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> Message-ID: On Nov 12, 2010, at 3:56 AM, Arun Sharma wrote: > I am working on Rspec for Controller testing.I am initial leve of > rspec.I have a problem that in Spec/controller directory rspec file is > not taking controller property as (instance varibale,flash notice) > My controller code is as follow > > class PortalNewsController < ApplicationController > # POST /portal_news > # POST /portal_news.xml > def create > @portal_news = PortalNews.new(params[:portal_news]) > puts "arundjfhdjfh" > respond_to do |format| > if @portal_news.save > flash[:notice] = 'PortalNews was successfully created.' > format.html { redirect_to root_path } > format.xml { render :xml => @portal_news, :status => :created, :location => @portal_news } > else > format.html { render :action => "new" } > format.xml { render :xml => @portal_news.errors, :status => :unprocessable_entity } > end > end > end > private > > # Check for superadmin > def is_superadmin? > if !current_user.is_superadmin > flash[:error] = "Permission denied." > redirect_to root_path > end > end Where is this ^^ method invoked? I don't see any direct references to it, or a before_filter. > end > > And my rspec file code is > rspec/controllers/portal_news_controller_spec.rb This ^^ should be "spec/controllers/...", not "rspec/controllers/...." > require File.dirname(__FILE__) +'/../spec_helper' If you're on rspec-1.3 or greater, this ^^ can be shortened to require "spec_helper" > describe PortalNewsController do > integrate_views :true > controller_name :portal_news You don't need this ^^ line (RSpec already knows the controller from "describe PortalNewsController"). > it "should_redirect_to_root_with_successfull_notice" do > post :create,:heading=>nil > assigns[:portal_news].errors.on(:heading).should_not be_nil > flash[:error].should_not be_nil > end > > it "should_re-render_new_template_on_failed_save" do > PortalNews.any_instance.stubs(:valid?).returns(false) > post :create > assigns[:portal_news].should be_new_record > flash[:notice].should be_nil > response.should render_template('http://test.host/portal_news/new') > end > > it"should_pass_the_param_value" do > post :create,:portal_news => {:user_id => 11} > assigns[:portal_news].user_id.should =11 > end > end > > And i am geeting error as follow > > 1 NoMethodError in 'PortalNewsController > should_redirect_to_root_with_successfull_notice' > 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.errors > > 2 NoMethodError in 'PortalNewsController > should_re-render_new_template_on_failed_save' > 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.new_record? > > 3 NoMethodError in 'PortalNewsController should_pass_the_param_value' > undefined method `user_id' for nil:NilClass > > ----- > Please post solution of this problem All three errors are related to the create action, and all three suggest that we never get to the first line of the create action which assigns the new PortalNews to @portal_news. Any chance the is_super_admin? method is in a before_filter in ApplicationController? That's the only thing I see in the code you posted that would lead to these errors. Everything else seems like it should work. HTH, David From dchelimsky at gmail.com Fri Nov 12 09:11:27 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 12 Nov 2010 08:11:27 -0600 Subject: [rspec-users] pending tests fail when I switch to mock_with :mocha In-Reply-To: References: Message-ID: <801C94CD-7D4D-41DC-A95D-FC426606F5F4@gmail.com> On Nov 12, 2010, at 7:23 AM, Ole Morten Amundsen wrote: > First of all, please direct me into how better to search existing threads in this mailing list. Not sure what you tried already, but: http://groups.google.com/group/rspec http://old.nabble.com/forum/Search.jtp?query=rspec-users+rspec+mocha And if all else fails http://www.google.com/search?q=rspec-users+rspec+mocha > Ok to my rspec 2.0.1 mocha 0.9.8 issue: > > given a controller test > before do > subject.expects(:authenticate).once > end > > it "should bla bla" do > pending "PENDING, shouldn't fail?" > end > > with > config.mock_with :rspec > it's ok: pending, but with > config.mock_with :mocha > if fails! > > It expected the authenticate to be called. What do I have to do to make it compatible? > > Reason for using mocha, is > A: I'm used to it > B: I don't know rspec mocks too well, but it notice that these mocks live across tests, breaking unrelated model specs. In the future, please be sure to say what versions of rails and ruby you're using as well. My best guess is that this is a rails-3 app (because rspec-2 doesn't work with rails-2 yet), and the mocha gem is configured in the Gemfile. Unless it says ":require => false", mocha will be loaded regardless of which framework you tell RSpec to use. Assuming this is all correct (or some other mechanism is being used to configure/load the mocha gem), here's the deal: When you declare an example as pending _inside the example_, RSpec doesn't know the example is pending until it runs the example, so its before blocks are run. Because the mocha gem is loaded, the "expects" method is added to all objects whether the configured framework is :rspec or :mocha, so the before block is not raising an error when the configured mock framework is :rspec, but then the mocha expectations are never verified. This is why it's passing when configured with :rspec. The fact that it's failing when configured with :mocha is expected, since the before block is being run. My recommendation has always been to avoid message expectations (expects in mocha, should_receive in rspec) should never be used in before blocks, and this is one of many reasons why. That said, if you want to declare a method pending and ensure that the before blocks are not executed, then use either of these alternatives: pending "should bla bla" do .. end it "should bla bla", :pending => true do .. end Both of these let RSpec know the example is pending before it is run, so RSpec doesn't run the before blocks in these cases. HTH, David > > cheers! > oma From lists at ruby-forum.com Fri Nov 12 10:23:04 2010 From: lists at ruby-forum.com (Ruben C.) Date: Fri, 12 Nov 2010 16:23:04 +0100 Subject: [rspec-users] Rspec 2, Rails 3 and Webrat In-Reply-To: <340C2B8D-0D65-48D5-957C-E44C2EAD7D39@gmail.com> References: <4C11A0E2.5090509@yahoo.com.br>, <59A897EC-0FDF-4256-A60C-C79032059CCE@gmail.com>, <4C1272B0.6080701@yahoo.com.br>, , <4C12FC40.90602@yahoo.com.br>, <340C2B8D-0D65-48D5-957C-E44C2EAD7D39@gmail.com> Message-ID: <2e46091ff46c4b751991857fbdffb2d4@ruby-forum.com> I did this with webrat 0.7.2, rails 3.0.1, test-unit 2.1.1: require "webrat" require 'webrat/core/matchers' include Webrat::Methods Webrat.configure do |config| config.mode = :rack end and for now I can run tests like this: test "testing_webrat_visit" do visit 'home/index' end maybe some methods from webrat won't work, but I haven't found them yet. -- Posted via http://www.ruby-forum.com/. From vertebrate at gmail.com Fri Nov 12 12:42:02 2010 From: vertebrate at gmail.com (Steve) Date: Fri, 12 Nov 2010 09:42:02 -0800 (PST) Subject: [rspec-users] How do I include routing path helpers? Message-ID: I'm writing some Steak acceptance tests in Rspec2 for my Rails3 app and I can't access various route helpers(members_path, new_member_path, etc...) in my specs, and can't figure out how to include them. I'm sure it's probably a simple config setting. Does anyone know what I need to do? Thanks, Steve From lists at ruby-forum.com Fri Nov 12 14:57:44 2010 From: lists at ruby-forum.com (Seung ho C.) Date: Fri, 12 Nov 2010 20:57:44 +0100 Subject: [rspec-users] rake spec loads development environment In-Reply-To: <3c30da400905132207p534a87c1x36c8d4eb51698b6f@mail.gmail.com> References: <1c51d85b1455b71e6461316a77073874@ruby-forum.com>, <1F25F8BD-8DF1-4713-90A3-36A7677CD256@parkerhill.com>, , <1DF992C3-CC79-485A-9D56-4DCD70F77CBB@parkerhill.com>, , <3c30da400905132207p534a87c1x36c8d4eb51698b6f@mail.gmail.com> Message-ID: Mark Wilden wrote in post #816031: > On Tue, Aug 19, 2008 at 2:35 PM, Jonathan Linowes > wrote: > >> >> rake spec RAILS_ENV=production >> >> that way the db:test:prepare uses the production db rather than the >> development one > > > I know this thread is long dead but ... you must be joking. > > ///ark I went though same experience today with my recently setup ruby 1.9, rails 3.0, and rspec 2. "$ rake spec" loaded development environment, hitting development db and pumping logs at log/development.log. This caused lot of confusion in my testing (As I run spec within RubyMine at the same time). I found that there is "RAILS_ENV=development" in my bash environment. Once I remove that, everything works as expected. rspec loads test environment, test db, and logging at log/test.log. One thing I noticed is when I have RAILS_ENV=development, even if I tried "$ rake spec RAILS_ENV=test", it actually hit development environment. I thought argument override shell env setting. Am I wrong or is it rspec issue? -- Posted via http://www.ruby-forum.com/. From dolzenko at gmail.com Fri Nov 12 15:56:30 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Fri, 12 Nov 2010 23:56:30 +0300 Subject: [rspec-users] How do I include routing path helpers? In-Reply-To: References: Message-ID: Not sure on how to do that with Steak but you must be looking to include Rails.application.routes.url_helpers somewhere, with vanilla RSpec it would be describes 'included helpers' do include Rails.application.routes.url_helpers ... end On Fri, Nov 12, 2010 at 8:42 PM, Steve wrote: > I'm writing some Steak acceptance tests in Rspec2 for my Rails3 app > and I can't access various route helpers(members_path, > new_member_path, etc...) in my specs, and can't figure out how to > include them. I'm sure it's probably a simple config setting. Does > anyone know what I need to do? > > Thanks, > Steve > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Sat Nov 13 00:11:00 2010 From: lists at ruby-forum.com (Arun Sharma) Date: Sat, 13 Nov 2010 06:11:00 +0100 Subject: [rspec-users] In spec/controller file not taking controller property In-Reply-To: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> References: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> Message-ID: <9d81258d50b9ccb4a4b3e070abb833f1@ruby-forum.com> thanks for reply >--- > i commented all lines of code which you mentioned but still this code is not working.Same code is working in other dummy application. > I have installed rails 2.3.5 and rspec 2.1.0 and rspec-rails 2.1.0 and I also installed plugin >---- git://github.com/dchelimsky/rspec-rails.git -r 'refs/tags/1.2.9' and git://github.com/dchelimsky/rspec.git -r 'refs/tags/1.2.9' >----- Please post the solution. I am waiting for reply -- Posted via http://www.ruby-forum.com/. From vertebrate at gmail.com Sat Nov 13 00:26:10 2010 From: vertebrate at gmail.com (Steve) Date: Fri, 12 Nov 2010 21:26:10 -0800 (PST) Subject: [rspec-users] How do I include routing path helpers? In-Reply-To: References: Message-ID: <2f84c7ee-2ad2-4c26-8028-0e375c1958ff@o11g2000prf.googlegroups.com> I went with: config.include Rails.application.routes.url_helpers, :type => :acceptance but knowing what exactly to include was the important part. I still have a nil error when url_for tries to call host_with_port on the request object, but I think that has to do with my using subdomains with capybara. So now I'm off to figure that out. Thanks, Steve On Nov 12, 2:56?pm, Evgeniy Dolzhenko wrote: > Not sure on how to do that with Steak but you must be looking to > include Rails.application.routes.url_helpers > somewhere, with vanilla RSpec it would be > > describes 'included helpers' do > ? include Rails.application.routes.url_helpers > ? ... > end From lists at ruby-forum.com Sat Nov 13 01:59:22 2010 From: lists at ruby-forum.com (Arun Sharma) Date: Sat, 13 Nov 2010 07:59:22 +0100 Subject: [rspec-users] In spec/controller file not taking controller property Message-ID: > My rspec file is not taking controller property. > In controller instance variable defined as : @portal_news=PortalNews.new > In rspec file my code is get :create,:portal_news=>{:user_id=>101} assigns[:portal_news].user_id.should=101 > I getting error is NoMethodError in 'PortalNewsController should_check_variable' undefined method `user_id' for nil:NilClass > please post the solution.I am waiting for reply -- Posted via http://www.ruby-forum.com/. From vertebrate at gmail.com Fri Nov 12 20:01:19 2010 From: vertebrate at gmail.com (Steve) Date: Fri, 12 Nov 2010 17:01:19 -0800 (PST) Subject: [rspec-users] How do I include routing path helpers? In-Reply-To: References: Message-ID: <3def0d80-a538-461b-99b0-e30cefb72457@j12g2000prm.googlegroups.com> Thanks, that did it. I still have a nil error when trying to call host_with_port on the request object inside url_for, but I think that is related to my app having subdomains, and trying to use those with capybara. On Nov 12, 2:56?pm, Evgeniy Dolzhenko wrote: > Not sure on how to do that with Steak but you must be looking to > include Rails.application.routes.url_helpers > somewhere, with vanilla RSpec it would be > > describes 'included helpers' do > ? include Rails.application.routes.url_helpers > ? ... > end > From dchelimsky at gmail.com Sat Nov 13 02:14:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 13 Nov 2010 01:14:45 -0600 Subject: [rspec-users] In spec/controller file not taking controller property In-Reply-To: <9d81258d50b9ccb4a4b3e070abb833f1@ruby-forum.com> References: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> <9d81258d50b9ccb4a4b3e070abb833f1@ruby-forum.com> Message-ID: On Nov 12, 2010, at 11:11 PM, Arun Sharma wrote: > thanks for reply >> --- > >> i commented all lines of code which you mentioned but still this code is not > working.Same code is working in other dummy application. > >> I have installed rails 2.3.5 and rspec 2.1.0 and rspec-rails 2.1.0 and I also > installed plugin There's your problem. RSpec-2 does not support Rails-2. Try using rspec-rails-1.3.3 and configuring gems (rather than plugins). HTH, David > >> ---- > git://github.com/dchelimsky/rspec-rails.git -r 'refs/tags/1.2.9' > > and > > git://github.com/dchelimsky/rspec.git -r 'refs/tags/1.2.9' > >> ----- > > Please post the solution. > > I am waiting for reply > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Sat Nov 13 03:34:47 2010 From: lists at ruby-forum.com (Arun Sharma) Date: Sat, 13 Nov 2010 09:34:47 +0100 Subject: [rspec-users] In spec/controller file not taking controller property In-Reply-To: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> References: <9b530efd079db46f25ac938a5d3c43e8@ruby-forum.com> Message-ID: <8d5295926733017790b813f3cfcbf28d@ruby-forum.com> > thanks for reply > now this is working -- Posted via http://www.ruby-forum.com/. From dolzenko at gmail.com Sat Nov 13 06:53:52 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Sat, 13 Nov 2010 14:53:52 +0300 Subject: [rspec-users] How do I include routing path helpers? In-Reply-To: <3def0d80-a538-461b-99b0-e30cefb72457@j12g2000prm.googlegroups.com> References: <3def0d80-a538-461b-99b0-e30cefb72457@j12g2000prm.googlegroups.com> Message-ID: Hm, make sure you have something like MySuperApp::Application.configure do routes.default_url_options = { :host => "test.host", :protocol => 'https' } end in your config\environments\test.rb On Sat, Nov 13, 2010 at 4:01 AM, Steve wrote: > Thanks, that did it. I still have a nil error when trying to call > host_with_port on the request object inside url_for, but I think that > is related to my app having subdomains, and trying to use those with > capybara. > > On Nov 12, 2:56?pm, Evgeniy Dolzhenko wrote: >> Not sure on how to do that with Steak but you must be looking to >> include Rails.application.routes.url_helpers >> somewhere, with vanilla RSpec it would be >> >> describes 'included helpers' do >> ? include Rails.application.routes.url_helpers >> ? ... >> end >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Sat Nov 13 07:50:43 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 13 Nov 2010 12:50:43 +0000 Subject: [rspec-users] Possible subject/its bug? Message-ID: Hi I recently did a coding kata and ran into some strange behaviour. The code is here[1], the weirdness under the comment "Doesn't work... RSpec bug?". Basically, all the `subject` / `its(:sequence)` examples seem to work, except the one split into the two contexts. In this case `its(:sequence)` produces an empty array. Anyone got any idea what's going on? Cheers Ash [1] https://github.com/ashleymoran/xpman_even_fib/blob/ashleymoran-seb-201011112025/spec/euler_fib_spec.rb -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From ole.morten.amundsen at gmail.com Sat Nov 13 10:59:38 2010 From: ole.morten.amundsen at gmail.com (oma) Date: Sat, 13 Nov 2010 07:59:38 -0800 (PST) Subject: [rspec-users] pending tests fail when I switch to mock_with :mocha In-Reply-To: <801C94CD-7D4D-41DC-A95D-FC426606F5F4@gmail.com> References: <801C94CD-7D4D-41DC-A95D-FC426606F5F4@gmail.com> Message-ID: On Nov 12, 3:11?pm, David Chelimsky wrote: > On Nov 12, 2010, at 7:23 AM, Ole Morten Amundsen wrote: > > > First of all, please direct me into how better to search existing threads in this mailing list. > > Not sure what you tried already, but: Thanks, I didn't know about the google group. I used this http://rubyforge.org/pipermail/rspec-users/ > > ?http://groups.google.com/group/rspec > ?http://old.nabble.com/forum/Search.jtp?query=rspec-users+rspec+mocha > > And if all else fails > > ?http://www.google.com/search?q=rspec-users+rspec+mocha > > > > > > > > > > > Ok to my rspec 2.0.1 mocha 0.9.8 issue: > > > given a controller test > > ?before do > > ? ? subject.expects(:authenticate).once > > ? end > > > ? it "should bla bla" do > > ? ?pending "PENDING, shouldn't fail?" > > end > > > with > > ? ?config.mock_with :rspec > > it's ok: pending, but with > > ? ?config.mock_with :mocha > > if fails! > > > It expected the authenticate to be called. What do I have to do to make it compatible? > > > Reason for using mocha, is > > A: I'm used to it > > B: I don't know rspec mocks too well, but it notice that these mocks live across tests, breaking unrelated model specs. > > In the future, please be sure to say what versions of rails and ruby you're using as well. > > My best guess is that this is a rails-3 app (because rspec-2 doesn't work with rails-2 yet), and the mocha gem is configured in the Gemfile. Unless it says ":require => false", mocha will be loaded regardless of which framework you tell RSpec to use. Assuming this is all correct (or some other mechanism is being used to configure/load the mocha gem), here's the deal: > > When you declare an example as pending _inside the example_, RSpec doesn't know the example is pending until it runs the example, so its before blocks are run. Because the mocha gem is loaded, the "expects" method is added to all objects whether the configured framework is :rspec or :mocha, so the before block is not raising an error when the configured mock framework is :rspec, but then the mocha expectations are never verified. This is why it's passing when configured with :rspec. > > The fact that it's failing when configured with :mocha is expected, since the before block is being run. > > My recommendation has always been to avoid message expectations (expects in mocha, should_receive in rspec) should never be used in before blocks, and this is one of many reasons why. That said, if you want to declare a method pending and ensure that the before blocks are not executed, then use either of these alternatives: > > pending "should bla bla" do > ? .. > end > > it "should bla bla", :pending => true do > ? .. > end > > Both of these let RSpec know the example is pending before it is run, so RSpec doesn't run the before blocks in these cases. Great answer! You rock David. I've tested both suggestions and they work perfectly. I guess I should stub, not mock, the authenticate method as I test this authentication (controller before_filter) in other tests. Thanks for the feedback. -oma > > HTH, > David > > > > > cheers! > > oma > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From vertebrate at gmail.com Sat Nov 13 11:54:47 2010 From: vertebrate at gmail.com (Steve) Date: Sat, 13 Nov 2010 08:54:47 -0800 (PST) Subject: [rspec-users] How do I include routing path helpers? In-Reply-To: References: <3def0d80-a538-461b-99b0-e30cefb72457@j12g2000prm.googlegroups.com> Message-ID: That didn't seem to change anything. I'll have to keep playing with it, but if you have any other thoughts I'm all for it. On Nov 13, 5:53?am, Evgeniy Dolzhenko wrote: > Hm, make sure you have something like > > MySuperApp::Application.configure do > ? routes.default_url_options = { :host => "test.host", :protocol => 'https' } > end > > in your config\environments\test.rb > > > > On Sat, Nov 13, 2010 at 4:01 AM, Steve wrote: > > Thanks, that did it. I still have a nil error when trying to call > > host_with_port on the request object inside url_for, but I think that > > is related to my app having subdomains, and trying to use those with > > capybara. > > > On Nov 12, 2:56?pm, Evgeniy Dolzhenko wrote: > >> Not sure on how to do that with Steak but you must be looking to > >> include Rails.application.routes.url_helpers > >> somewhere, with vanilla RSpec it would be > > >> describes 'included helpers' do > >> ? include Rails.application.routes.url_helpers > >> ? ... > >> end > > > _______________________________________________ > > 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 dolzenko at gmail.com Sat Nov 13 15:31:42 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Sat, 13 Nov 2010 23:31:42 +0300 Subject: [rspec-users] How do I include routing path helpers? In-Reply-To: References: <3def0d80-a538-461b-99b0-e30cefb72457@j12g2000prm.googlegroups.com> Message-ID: We're into some horrible throw-it-and-see-if-it-works loop now, but I can tell you here is what I use in my `before` blocks to test the subdomain routing in controller specs: request.env.merge!('HTTP_HOST' => 'hi5.test.host') On Sat, Nov 13, 2010 at 7:54 PM, Steve wrote: > That didn't seem to change anything. I'll have to keep playing with > it, but if you have any other thoughts I'm all for it. > > On Nov 13, 5:53?am, Evgeniy Dolzhenko wrote: >> Hm, make sure you have something like >> >> MySuperApp::Application.configure do >> ? routes.default_url_options = { :host => "test.host", :protocol => 'https' } >> end >> >> in your config\environments\test.rb >> >> >> >> On Sat, Nov 13, 2010 at 4:01 AM, Steve wrote: >> > Thanks, that did it. I still have a nil error when trying to call >> > host_with_port on the request object inside url_for, but I think that >> > is related to my app having subdomains, and trying to use those with >> > capybara. >> >> > On Nov 12, 2:56?pm, Evgeniy Dolzhenko wrote: >> >> Not sure on how to do that with Steak but you must be looking to >> >> include Rails.application.routes.url_helpers >> >> somewhere, with vanilla RSpec it would be >> >> >> describes 'included helpers' do >> >> ? include Rails.application.routes.url_helpers >> >> ? ... >> >> end >> >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-us... at rubyforge.org >> >http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Sat Nov 13 15:36:52 2010 From: lists at ruby-forum.com (Dean Richardson) Date: Sat, 13 Nov 2010 21:36:52 +0100 Subject: [rspec-users] rake cucumber gives "database configuration does not specify adapter" error Message-ID: <390db1bc50767852d7d765edd4db85d5@ruby-forum.com> I'm still working on getting the basic Rails 2 configuration for RSpec and Cucumber from the RSpec book up and running. I've installed the various gems as follows: $ [sudo] gem install rspec-rails --version 1.3.3 $ [sudo] gem install cucumber-rails --version 0.3.2 $ [sudo] gem install database_cleaner --version 0.5.0 $ [sudo] gem install webrat --version 0.7.1 I'm running Rails 2.3.5 rather than 2.3.10. I didn't install Selenium yet. I've had problems getting RSpec to see my installation of sqlite3/sqlite3-ruby, so I'm currently going with MySQL for development *AND* test databases. $ rake spec is currently generating the error message "rspec can not be found in vendor/gems, vendor/plugins or system gems" but entering $ spec spec/ works fine so far, though I don't have any examples to run yet. My main concern at the moment is getting Cucumber to run. When I enter $ rake cucumber I get the error message bundle exec /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I "/Library/Ruby/Gems/1.8/gems/cucumber-0.8.5/lib:lib" "/Library/Ruby/Gems/1.8/gems/cucumber-0.8.5/bin/cucumber" --profile default Using the default profile... database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified) ... followed by rake aborted! Command failed with status (1): [bundle exec /System/Library/Frameworks/Rub...] Any suggestions on what I should try next? Thanks! Dean Richardson -- Posted via http://www.ruby-forum.com/. From vertebrate at gmail.com Sun Nov 14 02:30:51 2010 From: vertebrate at gmail.com (Steve) Date: Sat, 13 Nov 2010 23:30:51 -0800 (PST) Subject: [rspec-users] How do I include routing path helpers? In-Reply-To: References: <3def0d80-a538-461b-99b0-e30cefb72457@j12g2000prm.googlegroups.com> Message-ID: <4fdde3b7-3158-4358-a4ac-b5206b63991f@k11g2000vbf.googlegroups.com> We are indeed. There is no request var available in Capybara. I think that is supposed to be taken care of by Capybara.default_host which I have set, but still no dice. I see exciting times ahead trying to get this working. On Nov 13, 2:31?pm, Evgeniy Dolzhenko wrote: > We're into some horrible throw-it-and-see-if-it-works loop now, but I > can tell you > here is what I use in my `before` blocks to test the subdomain routing > in controller specs: > > request.env.merge!('HTTP_HOST' => 'hi5.test.host') > From vertebrate at gmail.com Sun Nov 14 02:49:11 2010 From: vertebrate at gmail.com (Steve) Date: Sat, 13 Nov 2010 23:49:11 -0800 (PST) Subject: [rspec-users] How do I include routing path helpers? In-Reply-To: References: <3def0d80-a538-461b-99b0-e30cefb72457@j12g2000prm.googlegroups.com> Message-ID: <5d4d6b14-99e3-4a0f-8186-2e1508f18e07@j33g2000vbb.googlegroups.com> The issue is actually before getting to anything Capybara related. It's coming from my call to member_path @member in my spec to determine the route path to use. Looking at it this way the error makes more sense. Not sure how much fudging I would need to do to simulate there being a request there for the routing helpers to work off of. On Nov 13, 2:31?pm, Evgeniy Dolzhenko wrote: > We're into some horrible throw-it-and-see-if-it-works loop now, but I > can tell you > here is what I use in my `before` blocks to test the subdomain routing > in controller specs: > > request.env.merge!('HTTP_HOST' => 'hi5.test.host') > From tjtuom at utu.fi Mon Nov 15 00:55:11 2010 From: tjtuom at utu.fi (Toni Tuominen) Date: Mon, 15 Nov 2010 07:55:11 +0200 Subject: [rspec-users] debugging calls with message expectations Message-ID: I'd like to know how to debug callers with message expectations. I have a message expectation that should be called only once but for some reason is called 13 times and I'd like to know where it's called from. I've made the expectation return the value with a block and made it print the call stack but it only prints one stack, not 13 stacks as I would have thought. Why is that? The relevant code is here: https://gist.github.com/026a6c696e2199a46455. I am using rails 3.0.1 and rspec 2.0.1. - Toni From lists at ruby-forum.com Mon Nov 15 09:05:57 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Mon, 15 Nov 2010 15:05:57 +0100 Subject: [rspec-users] Rspec not testing my callback Message-ID: <6248faacf299a375ef68782245e58d50@ruby-forum.com> Hello everyone, I have a "before_save" at the top of my model, and it is being used correctly. However, when testing with RSpec/Rcov, my callback method is not being tested. Is there something specific I need to be doing? Thank you, Andrew Davis NASA - KSC -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Nov 15 09:09:15 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Nov 2010 08:09:15 -0600 Subject: [rspec-users] debugging calls with message expectations In-Reply-To: References: Message-ID: On Sun, Nov 14, 2010 at 11:55 PM, Toni Tuominen wrote: > I'd like to know how to debug callers with message expectations. I > have a message expectation that should be called only once but for > some reason is called 13 times and I'd like to know where it's called > from. I've made the expectation return the value with a block and made > it print the call stack but it only prints one stack, not 13 stacks as > I would have thought. Why is that? > > The relevant code is here: https://gist.github.com/026a6c696e2199a46455. > I am using rails 3.0.1 and rspec 2.0.1. For what you're doing it would be far simpler to say it this way: Course.stub(:find) { puts caller.join("\n"); course } That, or what you have, should expose the caller, so the problem is probably that something else is different in the spec than it is when you run the app. Could be the stuff you're stubbing like the stub_chain in the before block or the fact that you're using a mock_model for Signup. HTH, David > > - Toni > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Nov 15 09:39:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Nov 2010 08:39:54 -0600 Subject: [rspec-users] Rspec not testing my callback In-Reply-To: <6248faacf299a375ef68782245e58d50@ruby-forum.com> References: <6248faacf299a375ef68782245e58d50@ruby-forum.com> Message-ID: On Mon, Nov 15, 2010 at 8:05 AM, Andrew Davis wrote: > Hello everyone, > > I have a "before_save" at the top of my model, and it is being used > correctly. However, when testing with RSpec/Rcov, my callback method is > not being tested. Is there something specific I need to be doing? Can't tell what you're doing at all if you don't post some code. Please do so. Need to see the spec that's not doing what you think it should be doing, the implementation of the action invoked by that spec, and the before filter. Cheers, David From lists at ruby-forum.com Mon Nov 15 10:03:50 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Mon, 15 Nov 2010 16:03:50 +0100 Subject: [rspec-users] Rspec not testing my callback In-Reply-To: <6248faacf299a375ef68782245e58d50@ruby-forum.com> References: <6248faacf299a375ef68782245e58d50@ruby-forum.com> Message-ID: <7060654ab9824cdcd047dd217af0446e@ruby-forum.com> Okay, I didn't think you needed to see any code since it seems general. And I meant "after_save" not "before_save". I guess it's kind of complicated since I have a lot of associations, but hopefully this will help you. My model class TaskOrder < ActiveRecord::Base after_update :save_product_groups def save_product_groups product_groups.each do |p| p.save(false) end end end One of my tests it "should update the task order's product group attributes" do @pg1 = Factory(:product_group, :weight => 30, :branch_id => 1) @pg2 = Factory(:product_group, :weight => 20, :branch_id => 2) @pg3 = Factory(:product_group, :weight => 50, :branch_id => 3) update_task_order_instance = TaskOrder.new(@attr.merge(:product_groups => [ @pg1, @pg2, @pg3 ])) p1 = update_task_order_instance.product_groups.first p2 = update_task_order_instance.product_groups.second p3 = update_task_order_instance.product_groups.last @pg_hash = { "#{p1.id}" => {"weight" => 40}, "#{p2.id}" => {"weight" => 50}, "#{p3.id}" => {"weight" => 10} } update_task_order_instance.existing_product_group_attributes = @pg_hash update_task_order_instance.save update_task_order_instance.product_groups.first.weight.should == 40 update_task_order_instance.product_groups.second.weight.should == 50 update_task_order_instance.product_groups.last.weight.should == 10 update_task_order_instance.product_groups.count.should == 3 end As you can see, there is a line in the test that calls a save method. I've set breakpoints on the development server and observed that it DOES use the "save_product_groups" as it should be, but for some reason it's just not being covered in my rcov. Let me know if you need anything else. Please note that I'm still somewhat new to Rails. Thank you, Andrew Davis NASA - KSC -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Nov 15 11:14:02 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Nov 2010 10:14:02 -0600 Subject: [rspec-users] Rspec not testing my callback In-Reply-To: <7060654ab9824cdcd047dd217af0446e@ruby-forum.com> References: <6248faacf299a375ef68782245e58d50@ruby-forum.com> <7060654ab9824cdcd047dd217af0446e@ruby-forum.com> Message-ID: On Nov 15, 2010, at 9:03 AM, Andrew Davis wrote: > Okay, I didn't think you needed to see any code since it seems general. Even if it's hypothetical, it's always better to post code so we have context for a conversation. The general answer to "RSpec is not testing my filters" is "you're doing it wrong." Posting code gives us something to work with. > And I meant "after_save" not "before_save". > > I guess it's kind of complicated since I have a lot of associations, but > hopefully this will help you. > > My model > class TaskOrder < ActiveRecord::Base > after_update :save_product_groups > > def save_product_groups > product_groups.each do |p| > p.save(false) > end > end > end > > > One of my tests > it "should update the task order's product group attributes" do > @pg1 = Factory(:product_group, :weight => 30, :branch_id => 1) > @pg2 = Factory(:product_group, :weight => 20, :branch_id => 2) > @pg3 = Factory(:product_group, :weight => 50, :branch_id => 3) > update_task_order_instance = > TaskOrder.new(@attr.merge(:product_groups => [ > @pg1, > @pg2, > @pg3 > ])) This ^^ instantiates a new object but does not save it to the database, so the "save" below creates the new record, therefore the "after_update" filter is not called. You might want that to be "after_save" instead, but you'd have to think about the other implications of that in the context of your app. If you don't, then change this line, above, to TaskOrder.create and the save, below, will update the record in the db and fire the after_update callback. HTH, David > > p1 = update_task_order_instance.product_groups.first > p2 = update_task_order_instance.product_groups.second > p3 = update_task_order_instance.product_groups.last > > @pg_hash = { > "#{p1.id}" => {"weight" => 40}, > "#{p2.id}" => {"weight" => 50}, > "#{p3.id}" => {"weight" => 10} > } > > update_task_order_instance.existing_product_group_attributes = > @pg_hash > > update_task_order_instance.save > update_task_order_instance.product_groups.first.weight.should == 40 > update_task_order_instance.product_groups.second.weight.should == 50 > update_task_order_instance.product_groups.last.weight.should == 10 > update_task_order_instance.product_groups.count.should == 3 > end > > > As you can see, there is a line in the test that calls a save method. > I've set breakpoints on the development server and observed that it DOES > use the "save_product_groups" as it should be, but for some reason it's > just not being covered in my rcov. > > Let me know if you need anything else. Please note that I'm still > somewhat new to Rails. > > Thank you, > > Andrew Davis > NASA - KSC > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Nov 15 11:57:45 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Mon, 15 Nov 2010 17:57:45 +0100 Subject: [rspec-users] Rspec not testing my callback In-Reply-To: <6248faacf299a375ef68782245e58d50@ruby-forum.com> References: <6248faacf299a375ef68782245e58d50@ruby-forum.com> Message-ID: Thank you David for your prompt response. I completely understand what you're getting at regarding the posting of code as well. I think you may have solved my problem, I'll give it a go later today. I appreciate it! Thanks, Andrew Davis NASA - KSC -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Nov 15 12:06:38 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Mon, 15 Nov 2010 18:06:38 +0100 Subject: [rspec-users] Rspec not testing my callback In-Reply-To: <6248faacf299a375ef68782245e58d50@ruby-forum.com> References: <6248faacf299a375ef68782245e58d50@ruby-forum.com> Message-ID: <7cf2614a19dfe4ad586595d1c2dc9d77@ruby-forum.com> Worked like a charm. Thanks again Mr. Chelimsky -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Nov 15 15:13:12 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Mon, 15 Nov 2010 21:13:12 +0100 Subject: [rspec-users] RSpec not testing ".sum" Message-ID: <4491d68b7c85508f64f153f7c9c882b1@ruby-forum.com> Hello all, I'm on the final stretch of testing my model, and I've realized that one simple line isn't being tested. I was hoping to get some insight on what I can do to accomplish this. The line that isn't being covered by Rcov is the ".sum". See code here: Test: http://pastie.org/private/djdqtmatp58acas3ysszq Model: http://pastie.org/private/kphng5jjnfn2imz52nceq So each Task Order has some crazy associations, but in the end, it's summing the collection of criterion rollup scores. The test passes, but the ".sum" isn't being covered. Might I be missing something? rcov (0.9.9) rspec (1.3.0) rspec-rails (1.3.2) rails (2.3.8) ruby (1.8.7) Thanks in advance, Andrew Davis -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Nov 15 15:19:09 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Mon, 15 Nov 2010 21:19:09 +0100 Subject: [rspec-users] RSpec not testing ".sum" In-Reply-To: <4491d68b7c85508f64f153f7c9c882b1@ruby-forum.com> References: <4491d68b7c85508f64f153f7c9c882b1@ruby-forum.com> Message-ID: Scratch this. It has been noted that rcov has a hard time distinguishing what the last line is. If I put all of the code in that model on one line, it works great. Thanks! Andrew Davis -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Nov 15 16:13:31 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Nov 2010 15:13:31 -0600 Subject: [rspec-users] RSpec not testing ".sum" In-Reply-To: <4491d68b7c85508f64f153f7c9c882b1@ruby-forum.com> References: <4491d68b7c85508f64f153f7c9c882b1@ruby-forum.com> Message-ID: On Nov 15, 2010, at 2:13 PM, Andrew Davis wrote: > Hello all, > > I'm on the final stretch of testing my model, and I've realized that one > simple line isn't being tested. I was hoping to get some insight on what > I can do to accomplish this. The line that isn't being covered by Rcov > is the ".sum". See code here: > > Test: > http://pastie.org/private/djdqtmatp58acas3ysszq > > Model: > http://pastie.org/private/kphng5jjnfn2imz52nceq > > So each Task Order has some crazy associations, but in the end, it's > summing the collection of criterion rollup scores. The test passes, but > the ".sum" isn't being covered. Might I be missing something? > > rcov (0.9.9) > rspec (1.3.0) > rspec-rails (1.3.2) > rails (2.3.8) > ruby (1.8.7) > > Thanks in advance, Rcov is not 100% reliable this way. If you were to remove the ".sum" from the line it is one, I'd bet you see failures. Turn that into a one liner and you should be fine. Cheers, David > Andrew Davis From martin.hawkins at gmail.com Mon Nov 15 17:36:50 2010 From: martin.hawkins at gmail.com (Martin Hawkins) Date: Mon, 15 Nov 2010 22:36:50 +0000 Subject: [rspec-users] Problem testing Authlogic UserSession Message-ID: I've posted this to the Authlogic group but things seem a little quiet, so perhaps someone here can help: 'm testing Authlogic 2.1.6, running under Rails 3.0.1., using rspec 2.1.0 I have the following: user.rb class User < ActiveRecord::Base acts_as_authentic do |config| config.login_field :email config.ignore_blank_passwords false config.disable_perishable_token_maintenance true end end user_session.rb class UserSession < Authlogic::Session::Base end user_sessions_controller_spec.rb require 'spec_helper' def user_session_create @user = Factory.create(:user) @user_session = UserSession.create(:email => @user.email, :password => @user.password) end describe UserSessionsController do before(:each) do :activate_authlogic end describe "create a user session" do it "creates a user session using the user credentials" do user_session_create @user_session.email.should == @user.email end end describe "find a user session" do it "locates the user session" do user_session_create us = UserSession.find us.email.should == @user.email end end end I have the correct lines in spec_helper.rb ( require "authlogic/test_case" and include Authlogic::TestCase) The create a user session test is ok but the find a user session test is failing with Failures: 1) UserSessionsController find a user session locates the user session Failure/Error: us.email.should == @user.email expected: "ron2.weasley2 at hogworts.com", got: nil (using ==) When I try this using console, I get the following ruby-1.8.7-p302 > require "authlogic/test_case" => true ruby-1.8.7-p302 > include Authlogic::TestCase => Object ruby-1.8.7-p302 >ron = User.first ruby-1.8.7-p302 > activate_authlogic => #"text/html"}> ruby-1.8.7-p302 > us = UserSession.new(:email => ron.email, :password => ron.password) => #"", :email=>"ron1.weasley1 at hogworts.com"}> ruby-1.8.7-p302 > us.save NoMethodError: undefined method `remote_ip' for nil:NilClass from /Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/ activesupport-3.0.1/lib/active_support/whiny_nil.rb:48:in `method_missing' from /Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/ authlogic-2.1.6/lib/authlogic/session/magic_columns.rb:61:in `update_info' from /Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/ activesupport-3.0.1/lib/active_support/callbacks.rb:414:in `_run_before_save_callbacks' from /Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/ activesupport-3.0.1/lib/active_support/callbacks.rb:93:in `send' from /Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/ activesupport-3.0.1/lib/active_support/callbacks.rb:93:in `run_callbacks' from /Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/ authlogic-2.1.6/lib/authlogic/session/callbacks.rb:83:in `before_save' from /Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/ authlogic-2.1.6/lib/authlogic/session/existence.rb:68:in `save' from (irb):9 I'm at a bit of a loss to explain this - any help very welcome! -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.havens at gmail.com Mon Nov 15 17:51:34 2010 From: peter.havens at gmail.com (Peter Havens) Date: Mon, 15 Nov 2010 14:51:34 -0800 (PST) Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. Message-ID: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> I'm having problems getting rspec-rails 2 request specs to work with webrat. Any help would be appreciated. Here's my setup: ruby 1.9.2p0 rails 3.0.1 rspec-rails 2.1.0 webrat 0.7.2 Here's the error I'm getting: $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb F Failures: 1) Failure/Error: Unable to find matching line from backtrace stack level too deep # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 Finished in 0.49825 seconds 1 example, 1 failure Here are snippets of my files: # spec/spec_helper.rb # # The following is based on some tips from a cucumber-rails ticket: require "webrat" require "webrat/core/matchers" include Rack::Test::Methods include Webrat::Methods include Webrat::Matchers Webrat.configure do |config| config.mode = :rack config.open_error_files = false end # spec/requests/_spec.rb require "spec_helper" describe "" do it "" do visit _path # The following works when uncommented: # # get _path # assert_template '/' end end Thanks, Pete From dchelimsky at gmail.com Mon Nov 15 18:36:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 15 Nov 2010 17:36:57 -0600 Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> Message-ID: On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: > I'm having problems getting rspec-rails 2 request specs to work with > webrat. Any help would be appreciated. Here's my setup: > > ruby 1.9.2p0 > rails 3.0.1 > rspec-rails 2.1.0 > webrat 0.7.2 > > Here's the error I'm getting: > > $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb > F > > Failures: > 1) > Failure/Error: Unable to find matching line from backtrace > stack level too deep > # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 > > Finished in 0.49825 seconds > 1 example, 1 failure > > Here are snippets of my files: > > # spec/spec_helper.rb > # > # The following is based on some tips from a cucumber-rails ticket: > require "webrat" > require "webrat/core/matchers" > > include Rack::Test::Methods > include Webrat::Methods > include Webrat::Matchers > > Webrat.configure do |config| > config.mode = :rack > config.open_error_files = false > end > > # spec/requests/_spec.rb > require "spec_helper" > > describe "" do > it "" do > visit _path > > # The following works when uncommented: > # > # get _path > # assert_template '/' > end > end This is actually a webrat issue, but it is reported to rspec-rails and webrat: https://github.com/rspec/rspec-rails/issues/140 https://webrat.lighthouseapp.com/projects/10503/tickets/398 https://webrat.lighthouseapp.com/projects/10503/tickets/400 > > Thanks, > Pete > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Nov 15 19:43:16 2010 From: lists at ruby-forum.com (Sarah Allen) Date: Tue, 16 Nov 2010 01:43:16 +0100 Subject: [rspec-users] experimenting with stub in irb with RSpec2 Message-ID: In class, to give people a feel for how stubs work, I used to do this with rspec 1.x: sarah:~$ gem list rspec *** LOCAL GEMS *** rspec (1.3.0) rspec-rails (1.3.2) sarah:~$ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] sarah:~$ irb >> require 'spec' => true >> require 'spec/mocks' => true >> Time.stub!(:now).and_return(10,20) => # >> Time.now => 10 >> Time.now => 20 >> Time.now => 20 >> I can't figure out how to do that in RSpec 2. Here's what I've tried: sarah:~$ gem list rspec *** LOCAL GEMS *** rspec (2.0.1, 2.0.0, 2.0.0.beta.22) rspec-core (2.0.1, 2.0.0, 2.0.0.beta.22) rspec-expectations (2.0.1, 2.0.0, 2.0.0.beta.22) rspec-mocks (2.0.1, 2.0.0, 2.0.0.beta.22) rspec-rails (2.0.1, 2.0.0, 2.0.0.beta.22) sarah:~$ ruby -v ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0] sarah:~$ irb ruby-1.8.7-p302 > require 'rspec' => true ruby-1.8.7-p302 > require 'rspec/mocks' => false ruby-1.8.7-p302 > require 'rspec-mocks' LoadError: no such file to load -- rspec-mocks from /Users/sarah/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /Users/sarah/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from (irb):4 ruby-1.8.7-p302 > Time.stub!(:now).and_return(10,20) NoMethodError: undefined method `stub!' for Time:Class from (irb):5 Can anyone give me a hint? Thanks in advance, Sarah http://www.ultrasaurus.com http://blazingcloud.net -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Nov 15 23:31:37 2010 From: lists at ruby-forum.com (Sai Babu) Date: Tue, 16 Nov 2010 05:31:37 +0100 Subject: [rspec-users] why should_receive behaves differently Message-ID: <25e02f998f540efdd19d453108c8467c@ruby-forum.com> Hi friends in my rspec_controller 1]@user.articles.should_receive(:find_by_id).with('1').and_return(@article) get :show,:id => 1 in above example 1 if i mention get :show, :id => 1 below the schould_receive it is working fine but 2]get :show,:id => 1 @user.articles.should_receive(:find_by_id).with('1').and_return(@article) if i mention in the above way it is raising error! Why ? What is the reason? Could any one explain please ? Thanks in advance? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Nov 16 01:08:55 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Nov 2010 00:08:55 -0600 Subject: [rspec-users] experimenting with stub in irb with RSpec2 In-Reply-To: References: Message-ID: On Nov 15, 2010, at 6:43 PM, Sarah Allen wrote: > In class, to give people a feel for how stubs work, I used to do this > with rspec 1.x: > > sarah:~$ gem list rspec > > *** LOCAL GEMS *** > > rspec (1.3.0) > rspec-rails (1.3.2) > sarah:~$ ruby -v > ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] > sarah:~$ irb >>> require 'spec' > => true >>> require 'spec/mocks' > => true >>> Time.stub!(:now).and_return(10,20) > => > # >>> Time.now > => 10 >>> Time.now > => 20 >>> Time.now > => 20 >>> > > I can't figure out how to do that in RSpec 2. Here's what I've tried: Here's how you have to do it right now: require 'rspec/mocks' require 'rspec/mocks/extensions/object' Time.stub(:now).and_return(10,20) Time.now Time.now Time.now The reason you have to require 'rspec/mocks/extensions/object' is to make sure that requiring 'rspec/mocks' doesn't automatically add stub and should_receive to every object. That's so rspec-mocks can be used outside RSpec, and is a requirement of this feature: http://relishapp.com/rspec/rspec-mocks/v/2-1/dir/outside-rspec/configure-any-test-framework-to-use-rspec-mocks I'm pretty sure nobody is using this feature, and may be willing to reconsider, but I need to think about it. For now, go ahead and require 'rspec/mocks/extensions/object' and at least you can do the demo you're trying to do. Cheers, David > > > sarah:~$ gem list rspec > > *** LOCAL GEMS *** > > rspec (2.0.1, 2.0.0, 2.0.0.beta.22) > rspec-core (2.0.1, 2.0.0, 2.0.0.beta.22) > rspec-expectations (2.0.1, 2.0.0, 2.0.0.beta.22) > rspec-mocks (2.0.1, 2.0.0, 2.0.0.beta.22) > rspec-rails (2.0.1, 2.0.0, 2.0.0.beta.22) > sarah:~$ ruby -v > ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0] > sarah:~$ irb > ruby-1.8.7-p302 > require 'rspec' > => true > ruby-1.8.7-p302 > require 'rspec/mocks' > => false > ruby-1.8.7-p302 > require 'rspec-mocks' > LoadError: no such file to load -- rspec-mocks > from > /Users/sarah/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > from > /Users/sarah/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in > `require' > from (irb):4 > ruby-1.8.7-p302 > Time.stub!(:now).and_return(10,20) > NoMethodError: undefined method `stub!' for Time:Class > from (irb):5 > > > Can anyone give me a hint? > > Thanks in advance, > > Sarah > http://www.ultrasaurus.com > http://blazingcloud.net > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Nov 16 01:12:04 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Nov 2010 00:12:04 -0600 Subject: [rspec-users] why should_receive behaves differently In-Reply-To: <25e02f998f540efdd19d453108c8467c@ruby-forum.com> References: <25e02f998f540efdd19d453108c8467c@ruby-forum.com> Message-ID: <8C1BE1E0-C38A-4C48-A73C-D73E19D8668B@gmail.com> On Nov 15, 2010, at 10:31 PM, Sai Babu wrote: > Hi friends > > in my rspec_controller > > 1]@user.articles.should_receive(:find_by_id).with('1').and_return(@article) > > get :show,:id => 1 > > in above example 1 if i mention get :show, :id => 1 below the > schould_receive > it is working fine > > but > 2]get :show,:id => 1 > @user.articles.should_receive(:find_by_id).with('1').and_return(@article) > > if i mention in the above way it is raising error! > > Why ? > What is the reason? > Could any one explain please ? > Thanks in advance? When you say "foo.should_receive(:bar)" you're saying "foo should receive bar sometime between now and the end of this example. The first example, the "get" is doing something that causes @user.articles to receive :find_by_id, but in the second example that's already happened before you set the expectation and does not happen again, so you get a failure message. HTH, David From lists at ruby-forum.com Tue Nov 16 03:44:11 2010 From: lists at ruby-forum.com (Sai Babu) Date: Tue, 16 Nov 2010 09:44:11 +0100 Subject: [rspec-users] why should_receive behaves differently In-Reply-To: <8C1BE1E0-C38A-4C48-A73C-D73E19D8668B@gmail.com> References: <25e02f998f540efdd19d453108c8467c@ruby-forum.com>, <8C1BE1E0-C38A-4C48-A73C-D73E19D8668B@gmail.com> Message-ID: <11a849b496789485fec407e23e105c8b@ruby-forum.com> Oh! i understood now Thanks for good explanation David Chelimsky wrote in post #961764: > On Nov 15, 2010, at 10:31 PM, Sai Babu wrote: > >> it is working fine >> Thanks in advance? > When you say "foo.should_receive(:bar)" you're saying "foo should > receive bar sometime between now and the end of this example. The first > example, the "get" is doing something that causes @user.articles to > receive :find_by_id, but in the second example that's already happened > before you set the expectation and does not happen again, so you get a > failure message. > > HTH, > David -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 16 09:44:21 2010 From: lists at ruby-forum.com (Sarah Allen) Date: Tue, 16 Nov 2010 15:44:21 +0100 Subject: [rspec-users] experimenting with stub in irb with RSpec2 In-Reply-To: References: , Message-ID: <1141b36d12bae127b8fe61c67fc86f17@ruby-forum.com> > For now, go ahead and require > 'rspec/mocks/extensions/object' and at least you can do the demo you're > trying to do. Yay! This works for me and I'm excited to be able to show it in my class today. Thanks so much for your quick response! Sarah -- Posted via http://www.ruby-forum.com/. From wagner.andrew at gmail.com Tue Nov 16 13:07:17 2010 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Tue, 16 Nov 2010 13:07:17 -0500 Subject: [rspec-users] Shared contexts Message-ID: Suppose we have this class: class MarbleMachine def insert color # process marble of color 'color' end def press button # process a push of the given button end def output # compute a result end end Let's presume here that the machine takes any number of marbles in any of 8 different colors, and that it has a few different buttons that can be pressed. The output is highly dependent on what actions you take, in what order. Obviously, a bit of a silly example, but easier than explaining a complex, highly data-driven application. Ok, now let's think about writing some specs. We're really not interested in trying to specify every possible scenario. But there are a few scenarios that we know are important. For example, we know that the customer is very interested in what happens in the state the machine is in after the sequence: [:blue_marble, :medium_button, :black_marble, :orange_marble] What happens if you insert two green marbles after this? What happens if you insert a yellow marble and press the big purple button? etc. In addition, the customer is also very interested in what happens if you push the red button when the machine is in a variety of states. What I'm trying to get at, here, is that I want to share some complex contexts across specs while not varying the action I'm specifying. I also want to vary the action I'm specifying in a number of different contexts (which is more along the lines of shared examples). I don't really want to think about it in terms of the state that exists, because that's not useful from the customer's standpoint. To be sure that things are set up correctly, we need to be able to say what happened, not just what the state is. So, how would you organize your specs in a scenario like this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From kai.schlamp at googlemail.com Tue Nov 16 13:43:30 2010 From: kai.schlamp at googlemail.com (turkan) Date: Tue, 16 Nov 2010 10:43:30 -0800 (PST) Subject: [rspec-users] should_receive(:render).with(some_option) not working Message-ID: Hello. As some former posts already mentioned there is some difficulty to test the render method when also checking for arguments: http://jdfrens.blogspot.com/2010/08/upgrading-to-rails-3-and-rspec-2-part_20.html http://rails-bestpractices.com/questions/17-test-the-render-method-in-a-controller-with-rspec http://groups.google.com/group/rspec/browse_thread/thread/a458272b4f35110c/71d60bbd20d77b9e?lnk=gst&q=render#71d60bbd20d77b9e Is there an official issue report to drag that problem? Is there a workaround? Best regards, Kai From kenny.ortmann at gmail.com Tue Nov 16 14:47:41 2010 From: kenny.ortmann at gmail.com (Kenneth Ortmann) Date: Tue, 16 Nov 2010 13:47:41 -0600 Subject: [rspec-users] rspec troubles Message-ID: https://github.com/yairgo/rspec_question I have a repository up here with a basic rails app and 3 classes with one spec file. If you run the spec you will see test failures that I would expect to pass. Anyone want to explain what I am doing wrong? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdarby at dynamix-ltd.com Tue Nov 16 09:16:18 2010 From: mdarby at dynamix-ltd.com (Matt Darby) Date: Tue, 16 Nov 2010 06:16:18 -0800 (PST) Subject: [rspec-users] view.should render_template best practices? Message-ID: I've been looking for the definitive answer for months now, and the RSpec book doesn't touch on it at all: How do we now handle stubbing out rendering of partials in view specs in RSpec2? I have a large (35K+ lines of views and related specs) that I'm trying to upgrade to Rails3/RSpec2. My views use partials pretty extensively and this issue is a huge blocker for me. before do view.should render_template("event_list", :locals => {:calendar => @calendar}) end causes all my related specs fail with: expecting <"event_list"> but rendering with <"">. Expected block to return true value. Any advice? From dolzenko at gmail.com Wed Nov 17 02:01:04 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Wed, 17 Nov 2010 10:01:04 +0300 Subject: [rspec-users] view.should render_template best practices? In-Reply-To: References: Message-ID: render_template matcher is to be used after the view is rendered. In your case something like view.stub!(:render).with(:partial => "event_list", :locals => {:calendar => @calendar}) should do the trick On Tuesday, November 16, 2010, Matt Darby wrote: > I've been looking for the definitive answer for months now, and the > RSpec book doesn't touch on it at all: > > How do we now handle stubbing out rendering of partials in view specs > in RSpec2? > > I have a large (35K+ lines of views and related specs) that I'm trying > to upgrade to Rails3/RSpec2. My views use partials pretty extensively > and this issue is a huge blocker for me. > > > before do > ?view.should render_template("event_list", :locals => {:calendar => > @calendar}) > end > > causes all my related specs fail with: > > expecting <"event_list"> but rendering with <"">. > Expected block to return true value. > > > Any advice? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From kai.schlamp at googlemail.com Wed Nov 17 02:11:57 2010 From: kai.schlamp at googlemail.com (turkan) Date: Tue, 16 Nov 2010 23:11:57 -0800 (PST) Subject: [rspec-users] How to use request helpers outside of controller specs? Message-ID: <13ca66d1-8a3f-4798-80b8-a26fc20b09af@z19g2000yqb.googlegroups.com> I asked this questions on some other places before, but have found no solution yet. I'd like to include the request helper (from ActionDispatch::Integration::RequestHelpers, like post and xhr methods) also in some specs outside of my controller specs. The problem is that these request helpers are only included in spec/ controller and when a controller is described. What do I have to include/require in those specs? Best regards, Kai From dolzenko at gmail.com Wed Nov 17 03:15:38 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Wed, 17 Nov 2010 11:15:38 +0300 Subject: [rspec-users] view.should render_template best practices? In-Reply-To: References: Message-ID: I'm sorry for introducing the confusion, but `view.stub!(:render)` won't work, I should've read the list more attention http://groups.google.com/group/rspec/browse_thread/thread/1590942f2827f55 On Wed, Nov 17, 2010 at 10:01 AM, Evgeniy Dolzhenko wrote: > render_template matcher is to be used after the view is rendered. > In your case something like > ?view.stub!(:render).with(:partial => "event_list", :locals => > {:calendar => @calendar}) > ?should do the trick > > On Tuesday, November 16, 2010, Matt Darby wrote: >> I've been looking for the definitive answer for months now, and the >> RSpec book doesn't touch on it at all: >> >> How do we now handle stubbing out rendering of partials in view specs >> in RSpec2? >> >> I have a large (35K+ lines of views and related specs) that I'm trying >> to upgrade to Rails3/RSpec2. My views use partials pretty extensively >> and this issue is a huge blocker for me. >> >> >> before do >> ??view.should render_template("event_list", :locals => {:calendar => >> @calendar}) >> end >> >> causes all my related specs fail with: >> >> expecting <"event_list"> but rendering with <"">. >> Expected block to return true value. >> >> >> Any advice? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From kai.schlamp at googlemail.com Wed Nov 17 04:06:48 2010 From: kai.schlamp at googlemail.com (medihack) Date: Wed, 17 Nov 2010 01:06:48 -0800 (PST) Subject: [rspec-users] How to use request helpers outside of controller specs? In-Reply-To: <13ca66d1-8a3f-4798-80b8-a26fc20b09af@z19g2000yqb.googlegroups.com> References: <13ca66d1-8a3f-4798-80b8-a26fc20b09af@z19g2000yqb.googlegroups.com> Message-ID: <53f77af0-db8a-4470-b84a-fde58ecc7008@p1g2000yqm.googlegroups.com> I just solved the problem by including the below code in my acceptance helper. If you are not Steak then just simply put it in spec helper or require it from somewhere else. post and xhr methods are now available in that spec regardless in what spec it is or in what directory you are. The code is derived from RSpec::Rails::RequestExampleGroup
RSpec::Core::ExampleGroup.class_eval do
  include ActiveSupport::Concern
  include ActionDispatch::Integration::Runner
  include RSpec::Rails::BrowserSimulators

  def app
    ::Rails.application
  end

  def last_response
    response
  end
end
From dchelimsky at gmail.com Wed Nov 17 05:35:52 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Nov 2010 04:35:52 -0600 Subject: [rspec-users] How to use request helpers outside of controller specs? In-Reply-To: <53f77af0-db8a-4470-b84a-fde58ecc7008@p1g2000yqm.googlegroups.com> References: <13ca66d1-8a3f-4798-80b8-a26fc20b09af@z19g2000yqb.googlegroups.com> <53f77af0-db8a-4470-b84a-fde58ecc7008@p1g2000yqm.googlegroups.com> Message-ID: <774B5358-6B2B-480E-A5B3-210E475C0852@gmail.com> On Nov 17, 2010, at 3:06 AM, medihack wrote: > I just solved the problem by including the below code in my acceptance > helper. If you are not Steak then just simply put it in spec helper or > require it from somewhere else. post and xhr methods are now available > in that spec regardless in what spec it is or in what directory you > are. > > The code is derived from RSpec::Rails::RequestExampleGroup > >
> RSpec::Core::ExampleGroup.class_eval do
>  include ActiveSupport::Concern
>  include ActionDispatch::Integration::Runner
>  include RSpec::Rails::BrowserSimulators
> 
>  def app
>    ::Rails.application
>  end
> 
>  def last_response
>    response
>  end
> end
> 
Can I ask why you want this outside controller and/or request specs? From dchelimsky at gmail.com Wed Nov 17 06:37:07 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Nov 2010 05:37:07 -0600 Subject: [rspec-users] view.should render_template best practices? In-Reply-To: References: Message-ID: On Nov 16, 2010, at 8:16 AM, Matt Darby wrote: > I've been looking for the definitive answer for months now, and the > RSpec book doesn't touch on it at all: > > How do we now handle stubbing out rendering of partials in view specs > in RSpec2? > > I have a large (35K+ lines of views and related specs) that I'm trying > to upgrade to Rails3/RSpec2. My views use partials pretty extensively > and this issue is a huge blocker for me. > > before do > view.should render_template("event_list", :locals => {:calendar => > @calendar}) > end > > causes all my related specs fail with: > > expecting <"event_list"> but rendering with <"">. > Expected block to return true value. > > > Any advice? In rspec-2/rails-3, view.should render_template("event_list") is no longer a message expectation (pre-action), but rather delegates to Rails' assert_template method, so it needs to come _after_ the action. It should work exactly as you have it above, just after the action. This is documented in the rspec-rails README (https://github.com/rspec/rspec-rails - see sections on View Specs and Matchers), though not with an upgrade note pointing out that it changed. I'll make that addition shortly. As for stubbing the template, so that it is not actually rendered, RSpec doesn't offer a way to do this in view specs and I don't think Rails does either. I added an issue for this (https://github.com/rspec/rspec-rails/issues/issue/263), and hopefully we'll be able to resolve it soon. In the mean time, the examples will need to supply any data needed by the template being spec'd _and_ any of the partials. Side note: I urge you not to put message expectations (pre "When") or state-based expectations (post "When") in before/after blocks. It makes examples difficult to understand, and results in specifying the same things in every example in a group. Rather, have one example that specifies each individual thing. In this case: it "renders the event_list with @calendar" do render view.should render_template( "event_list", :locals => {:calendar => @calendar} ) end HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Nov 17 09:07:50 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Nov 2010 08:07:50 -0600 Subject: [rspec-users] view.should render_template best practices? In-Reply-To: References: Message-ID: On Nov 17, 2010, at 5:37 AM, David Chelimsky wrote: > On Nov 16, 2010, at 8:16 AM, Matt Darby wrote: > >> I've been looking for the definitive answer for months now, and the >> RSpec book doesn't touch on it at all: >> >> How do we now handle stubbing out rendering of partials in view specs >> in RSpec2? >> >> I have a large (35K+ lines of views and related specs) that I'm trying >> to upgrade to Rails3/RSpec2. My views use partials pretty extensively >> and this issue is a huge blocker for me. >> >> before do >> view.should render_template("event_list", :locals => {:calendar => >> @calendar}) >> end >> >> causes all my related specs fail with: >> >> expecting <"event_list"> but rendering with <"">. >> Expected block to return true value. >> >> >> Any advice? > > In rspec-2/rails-3, view.should render_template("event_list") is no longer a message expectation (pre-action), but rather delegates to Rails' assert_template method, so it needs to come _after_ the action. It should work exactly as you have it above, just after the action. > > This is documented in the rspec-rails README (https://github.com/rspec/rspec-rails - see sections on View Specs and Matchers), though not with an upgrade note pointing out that it changed. I'll make that addition shortly. > > As for stubbing the template, so that it is not actually rendered, RSpec doesn't offer a way to do this in view specs and I don't think Rails does either. I added an issue for this (https://github.com/rspec/rspec-rails/issues/issue/263), and hopefully we'll be able to resolve it soon. In the mean time, the examples will need to supply any data needed by the template being spec'd _and_ any of the partials. > > Side note: I urge you not to put message expectations (pre "When") or state-based expectations (post "When") in before/after blocks. It makes examples difficult to understand, and results in specifying the same things in every example in a group. Rather, have one example that specifies each individual thing. In this case: > > it "renders the event_list with @calendar" do > render > view.should render_template( > "event_list", > :locals => {:calendar => @calendar} > ) > end FYI - it looks like you can do the following before the action, but you'd be using an internal method of Rails which is not guaranteed to work the same way in the future: view.should_receive(:_render_partial).with( :partial => "event_list", :locals => { :calendar => @calendar } ) Do not use this unless you are willing to absorb the risk that it could change in a future Rails release without any warning. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wagner.andrew at gmail.com Wed Nov 17 09:43:40 2010 From: wagner.andrew at gmail.com (Andrew Wagner) Date: Wed, 17 Nov 2010 09:43:40 -0500 Subject: [rspec-users] Shared contexts In-Reply-To: References: Message-ID: OK, in the face of chirping crickets, let me try to be a little more concrete. Here is a start at trying to spec out some behavior for our fabled MarbleMachine: https://gist.github.com/703446 I'd love to get some suggestions for improving how this is organized. Specifically, there are a few different, but related, contexts like the ones I've put in shared examples. Ideally, I'd like to figure out how to make these contexts composable in some way, because the actions they're comprised of are composable. On Tue, Nov 16, 2010 at 1:07 PM, Andrew Wagner wrote: > Suppose we have this class: > > class MarbleMachine > def insert color > # process marble of color 'color' > end > > def press button > # process a push of the given button > end > > def output > # compute a result > end > end > > Let's presume here that the machine takes any number of marbles in any of 8 > different colors, and that it has a few different buttons that can be > pressed. The output is highly dependent on what actions you take, in what > order. Obviously, a bit of a silly example, but easier than explaining a > complex, highly data-driven application. > > Ok, now let's think about writing some specs. We're really not interested > in trying to specify every possible scenario. But there are a few scenarios > that we know are important. For example, we know that the customer is very > interested in what happens in the state the machine is in after the > sequence: > > [:blue_marble, :medium_button, :black_marble, :orange_marble] > > What happens if you insert two green marbles after this? What happens if > you insert a yellow marble and press the big purple button? etc. > > In addition, the customer is also very interested in what happens if you > push the red button when the machine is in a variety of states. > > What I'm trying to get at, here, is that I want to share some complex > contexts across specs while not varying the action I'm specifying. I also > want to vary the action I'm specifying in a number of different contexts > (which is more along the lines of shared examples). I don't really want to > think about it in terms of the state that exists, because that's not useful > from the customer's standpoint. To be sure that things are set up correctly, > we need to be able to say what happened, not just what the state is. > > So, how would you organize your specs in a scenario like this? > -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at imaj.es Wed Nov 17 11:40:29 2010 From: james at imaj.es (James Cox) Date: Wed, 17 Nov 2010 11:40:29 -0500 Subject: [rspec-users] Rspec not loading .rspec file Message-ID: Hey, For some reason i can't seem to make rake spec or bin/rspec load the contents of the current working directory's .rspec, nor my ~/.rspec. Is there some kind of incantation required to make this work? Thanks, James -- James Cox, Consultant, Raconteur, Photographer, Entrepreneur t: +1 347 433 0567? e: james at imaj.es w: http://imaj.es/ talk: http://twitter.com/imajes photos: http://flickr.com/imajes From kai.schlamp at googlemail.com Wed Nov 17 14:36:49 2010 From: kai.schlamp at googlemail.com (medihack) Date: Wed, 17 Nov 2010 11:36:49 -0800 (PST) Subject: [rspec-users] How to use request helpers outside of controller specs? In-Reply-To: <774B5358-6B2B-480E-A5B3-210E475C0852@gmail.com> References: <13ca66d1-8a3f-4798-80b8-a26fc20b09af@z19g2000yqb.googlegroups.com> <53f77af0-db8a-4470-b84a-fde58ecc7008@p1g2000yqm.googlegroups.com> <774B5358-6B2B-480E-A5B3-210E475C0852@gmail.com> Message-ID: > Can I ask why you want this outside controller and/or request specs? Of course. I'd like to test some web services and XMLHttpRequests with Steak. For that I need the post and xhr methods of the request helpers. Steak uses an acceptance folder where the request helpers are not available. I wonder a bit as a Steak spec itself tries to use the get method in one example, but also fails (was there a change in RSpec lately and Steak is not up-to-date?). From lists at ruby-forum.com Wed Nov 17 15:16:36 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Wed, 17 Nov 2010 21:16:36 +0100 Subject: [rspec-users] Testing Controller 'show' action Message-ID: Hello, I'm still pretty new to Rails, and I've used rspec on all of my models with success. Now I'm working on the controllers, but I'm having difficulty. Everything I try is giving me a response of false, and I was hoping to get some insight from this community. All code can be viewed in this pastie: http://pastie.org/private/rn7vhzvmamn9tuytuuqq Please let me know if you need anything else! Thanks in advance! Andrew Davis -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Nov 18 08:19:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Nov 2010 07:19:26 -0600 Subject: [rspec-users] Testing Controller 'show' action In-Reply-To: References: Message-ID: On Nov 17, 2010, at 2:16 PM, Andrew Davis wrote: > Hello, I'm still pretty new to Rails, and I've used rspec on all of my > models with success. Welcome! > Now I'm working on the controllers, but I'm having > difficulty. Everything I try is giving me a response of false, Please post backtraces when you have failures. "response of false" could mean too many different things. > and I was > hoping to get some insight from this community. > > All code can be viewed in this pastie: > http://pastie.org/private/rn7vhzvmamn9tuytuuqq Not sure if it's related, but I notice this line in the pastie: TaskOrder.stub!(:find, @task_order.id).and_return(@task_order) This is incorrect usage of stub. If you're trying to constraint the stub to the id, you have to use the "with" method, which would also need something to account for the hash with :include => "criteria": TaskOrder.stub!(:find).with(@task_order.id, anything).and_return(@task_order) The "anything" method is an argument matcher that will match against anything passed in. If you want to be specific about the hash as well, you could do this: TaskOrder.stub(:find).with(@task_order.id, "include" => "criteria").and_return(@task_order) But I'd recommend against this level of detail and stick to either "anything" or perhaps defining a named scope or a wrapper method for including the criteria: TaskOrder.stub_chain("with_criteria.find").with(@task_order.id).and_return(@task_order) TaskOrder.stub(:find_with_criteria).with(@task_order.id).and_return(@task_order) I don't really like the name "find_with_criteria" but hopefully you'll come up with something better :) HTH, David > > Please let me know if you need anything else! > > Thanks in advance! > Andrew Davis From lists at ruby-forum.com Thu Nov 18 09:38:22 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Thu, 18 Nov 2010 15:38:22 +0100 Subject: [rspec-users] Testing Controller 'show' action In-Reply-To: References: Message-ID: <039fb8f148252c94e1cc9cbc4d42ae88@ruby-forum.com> Thank you very much for your response. I'll give it a go this afternoon! Now, you mentioned, "Please post backtraces when you have failures." Do you mean a section of the test.log? Because RSpec only informed that that it expected true but was false. Or is there a condition I need to pass to get a backtrace, that sounds extremely helpful! Thanks again for your thorough response! Thank you, Andrew Davis -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Nov 18 10:21:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Nov 2010 09:21:43 -0600 Subject: [rspec-users] Testing Controller 'show' action In-Reply-To: <039fb8f148252c94e1cc9cbc4d42ae88@ruby-forum.com> References: <039fb8f148252c94e1cc9cbc4d42ae88@ruby-forum.com> Message-ID: On Nov 18, 2010, at 8:38 AM, Andrew Davis wrote: > Thank you very much for your response. I'll give it a go this afternoon! > > Now, you mentioned, "Please post backtraces when you have failures." > > Do you mean a section of the test.log? Because RSpec only informed that > that it expected true but was false. Or is there a condition I need to > pass to get a backtrace, that sounds extremely helpful! At the very least copy the failure message verbatim rather than describing it. You said "false responses", which sounds like the response object was false. Now you say "expected true but it was false" but I think the actual message would be "expected true, got false". Precision is important to make it easier for those who want to help to do so. If you run "rspec spec --backtrace" you'll get the full backtrace, and you can copy that into the email or https://gist.github.com/ or https://gist.github.com/. Run "rspec --help" to see all of the command line options. Cheers, David > > Thanks again for your thorough response! > > Thank you, > Andrew Davis > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Nov 18 12:21:26 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Thu, 18 Nov 2010 18:21:26 +0100 Subject: [rspec-users] Testing user_controller update action Message-ID: Hello everyone, I'm trying to test the update action in my user controller, but unfortunately having troubles. You can find all of my code and relevant code here: http://pastie.org/private/odzbqvcoe8kdnh97ocaxia You can find the exact RSpec error here: http://pastie.org/private/pnpr3dgst1m50ixt4jufiq In the first, I have the development.log to show the working log, on my local server. That's what I see when I update a user via the application. The test log is the log when running the spec. Please let me know if anyone can think of anything that can point me in the right direction, or inform me of something I may be doing wrong. Thanks! Andrew Davis -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Nov 18 13:40:41 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Thu, 18 Nov 2010 19:40:41 +0100 Subject: [rspec-users] Testing user_controller update action In-Reply-To: References: Message-ID: Okay... Problem temporarily solved. Turns out it has to do with my before filter. I have: before_filter :authenticate_user! before_filter :set_conditions in the application controller. And: before_filter :authorize At the top of the users_controller. For some reason it works with those commented out. But still not at the final solution yet. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Nov 18 14:20:59 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Thu, 18 Nov 2010 20:20:59 +0100 Subject: [rspec-users] Testing user_controller update action In-Reply-To: References: Message-ID: <61c5f94a13b916c96091e18f37b511d4@ruby-forum.com> To post a solution to my problem: describe "PUT 'update'" do before(:each) do User.should_receive(:find).with(:first, {:conditions=>{:id=>@user.id}}).and_return(@user) User.should_receive(:find).with(@user).and_return(@user) end . . . The first line is for the authentication. -- Posted via http://www.ruby-forum.com/. From doug at emeryit.com Sat Nov 20 20:43:12 2010 From: doug at emeryit.com (Doug E.) Date: Sat, 20 Nov 2010 17:43:12 -0800 (PST) Subject: [rspec-users] specs pass individually, but fail using autotest Message-ID: <9c03549c-1b11-4ff3-a1b8-3f2079c74bd4@t35g2000yqj.googlegroups.com> Hi, I'm trying to run autotest and I'm using ryanb's nifty authentication with Rails 3 and Rpec 2. When I run autotest, the user model spec fails all its validation tests with the "error_on" matcher. If I run the spec by itself, it passes. If I'm running autotest and make a trivial change to the spec and save it, so that autotest runs just the user spec by itself, it passes. All the other tests in the spec pass. If I hit Ctrl-C to rerun the tests, these tests will fail again. Only the ones of the form "new_user(:password => 'bad').should have(1).error_on(:password)" fail. Below is the output from autotest, including the initial run, and second run after I make a trivial change to the spec. Thanks. Doug >>>>>>>>>> Failures: 1) User should require username Failure/Error: new_user(:username => '').should have(1).error_on(:username) expected 1 error on :username, got 0 # ./spec/models/user_spec.rb:21:in `block (2 levels) in ' 2) User should require password Failure/Error: new_user(:password => '').should have(1).error_on(:password) expected 1 error on :password, got 0 # ./spec/models/user_spec.rb:25:in `block (2 levels) in ' 3) User should require well formed email Failure/Error: new_user(:email => 'foo at bar@example.com').should have(1).error_on(:email) expected 1 error on :email, got 0 # ./spec/models/user_spec.rb:29:in `block (2 levels) in ' 4) User should validate uniqueness of email Failure/Error: new_user(:email => 'bar at example.com').should have(1).error_on(:email) expected 1 error on :email, got 0 # ./spec/models/user_spec.rb:34:in `block (2 levels) in ' 5) User should validate uniqueness of username Failure/Error: new_user(:username => 'uniquename').should have(1).error_on(:username) expected 1 error on :username, got 0 # ./spec/models/user_spec.rb:39:in `block (2 levels) in ' 6) User should not allow odd characters in username Failure/Error: new_user(:username => 'odd ^&(@)').should have(1).error_on(:username) expected 1 error on :username, got 0 # ./spec/models/user_spec.rb:43:in `block (2 levels) in ' 7) User should validate password is longer than 3 characters Failure/Error: new_user(:password => 'bad').should have(1).error_on(:password) expected 1 error on :password, got 0 # ./spec/models/user_spec.rb:47:in `block (2 levels) in ' 8) User should require matching password confirmation Failure/Error: new_user(:password_confirmation => 'nonmatching').should have(1).error_on(:password) expected 1 error on :password, got 0 # ./spec/models/user_spec.rb:51:in `block (2 levels) in ' Finished in 3.46 seconds 111 examples, 8 failures, 4 pending bundle exec /Users/doug/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S /Users/ doug/.rvm/gems/ruby-1.9.2-p0 at class-proto/gems/rspec-core-2.0.1/bin/ rspec --autotest '/Users/doug/dev/hg/class-proto/spec/models/ user_spec.rb' ...Trivial change ........... Finished in 1.17 seconds 14 examples, 0 failures From doug at emeryit.com Sat Nov 20 21:49:36 2010 From: doug at emeryit.com (Doug E.) Date: Sat, 20 Nov 2010 18:49:36 -0800 (PST) Subject: [rspec-users] specs pass individually, but fail using autotest In-Reply-To: <9c03549c-1b11-4ff3-a1b8-3f2079c74bd4@t35g2000yqj.googlegroups.com> References: <9c03549c-1b11-4ff3-a1b8-3f2079c74bd4@t35g2000yqj.googlegroups.com> Message-ID: On Nov 20, 8:43?pm, "Doug E." wrote: > Hi, > I'm trying to run autotest and I'm using ryanb's nifty authentication > with Rails 3 and Rpec 2. When I run autotest, the user model spec > fails all its validation tests with the "error_on" matcher. > > If I run the spec by itself, it passes. If I'm running autotest and > make a trivial change to the spec and save it, so that autotest ?runs > just the user spec by itself, it passes. All the other tests in the > spec pass. If I hit Ctrl-C to rerun the tests, these tests will fail > again. > > Only the ones of the form "new_user(:password => 'bad').should > have(1).error_on(:password)" fail. > > Below is the output from autotest, including the initial run, and > second run after I make a trivial change to the spec. > > Thanks. > Doug > > > > Failures: > ? 1) User should require username > ? ? ?Failure/Error: new_user(:username => '').should > have(1).error_on(:username) > ? ? ?expected 1 error on :username, got 0 > ? ? ?# ./spec/models/user_spec.rb:21:in `block (2 levels) in (required)>' > > ? 2) User should require password > ? ? ?Failure/Error: new_user(:password => '').should > have(1).error_on(:password) > ? ? ?expected 1 error on :password, got 0 > ? ? ?# ./spec/models/user_spec.rb:25:in `block (2 levels) in (required)>' > > ? 3) User should require well formed email > ? ? ?Failure/Error: new_user(:email => 'foo at b...@example.com').should > have(1).error_on(:email) > ? ? ?expected 1 error on :email, got 0 > ? ? ?# ./spec/models/user_spec.rb:29:in `block (2 levels) in (required)>' > > ? 4) User should validate uniqueness of email > ? ? ?Failure/Error: new_user(:email => '... at example.com').should > have(1).error_on(:email) > ? ? ?expected 1 error on :email, got 0 > ? ? ?# ./spec/models/user_spec.rb:34:in `block (2 levels) in (required)>' > > ? 5) User should validate uniqueness of username > ? ? ?Failure/Error: new_user(:username => 'uniquename').should > have(1).error_on(:username) > ? ? ?expected 1 error on :username, got 0 > ? ? ?# ./spec/models/user_spec.rb:39:in `block (2 levels) in (required)>' > > ? 6) User should not allow odd characters in username > ? ? ?Failure/Error: new_user(:username => 'odd ^&(@)').should > have(1).error_on(:username) > ? ? ?expected 1 error on :username, got 0 > ? ? ?# ./spec/models/user_spec.rb:43:in `block (2 levels) in (required)>' > > ? 7) User should validate password is longer than 3 characters > ? ? ?Failure/Error: new_user(:password => 'bad').should > have(1).error_on(:password) > ? ? ?expected 1 error on :password, got 0 > ? ? ?# ./spec/models/user_spec.rb:47:in `block (2 levels) in (required)>' > > ? 8) User should require matching password confirmation > ? ? ?Failure/Error: new_user(:password_confirmation => > 'nonmatching').should have(1).error_on(:password) > ? ? ?expected 1 error on :password, got 0 > ? ? ?# ./spec/models/user_spec.rb:51:in `block (2 levels) in (required)>' > > Finished in 3.46 seconds > 111 examples, 8 failures, 4 pending > bundle exec /Users/doug/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S /Users/ > doug/.rvm/gems/ruby-1.9.2-p0 at class-proto/gems/rspec-core-2.0.1/bin/ > rspec --autotest '/Users/doug/dev/hg/class-proto/spec/models/ > user_spec.rb' > ...Trivial change > ........... > > Finished in 1.17 seconds > 14 examples, 0 failures > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users I'll add that this behavior only occurs with the model User. I set up some similar tests for other classes (named Sample and SampleClassification). These do not have the same problem. Their validation tests pass during batch and single test runs. I created a new User model from scratch with a single validates_presence_of call, and got the same unexpected behavior: in single spec runs they pass, and in batch runs they fail. Doug From doug at emeryit.com Sat Nov 20 22:49:11 2010 From: doug at emeryit.com (Doug E.) Date: Sat, 20 Nov 2010 19:49:11 -0800 (PST) Subject: [rspec-users] specs pass individually, but fail using autotest In-Reply-To: References: <9c03549c-1b11-4ff3-a1b8-3f2079c74bd4@t35g2000yqj.googlegroups.com> Message-ID: <913f2fbe-a736-47e1-9def-af00ba71c287@y23g2000yqd.googlegroups.com> Problem discovered, but not solved. It isn't an rspec problem. It's caused by nifty-authentication's use of Mocha's any_instance. users_controller_spec.rb's last test calls: User.any_instance.stubs(:valid?).and_returns(true) This is fine if the tests are run singly, but with autotest the call in the controller spec still affects *every* subsequent User instance, and so it's impossible later in the same autotest batch to test the validity of later user objects. They just return true. An aside: It seems that mocha should make it possible to undo the effect of any_instance.stubs(:sym). On Nov 20, 9:49?pm, "Doug E." wrote: > On Nov 20, 8:43?pm, "Doug E." wrote: > > > > > > > > > > > Hi, > > I'm trying to run autotest and I'm using ryanb's nifty authentication > > with Rails 3 and Rpec 2. When I run autotest, the user model spec > > fails all its validation tests with the "error_on" matcher. > > > If I run the spec by itself, it passes. If I'm running autotest and > > make a trivial change to the spec and save it, so that autotest ?runs > > just the user spec by itself, it passes. All the other tests in the > > spec pass. If I hit Ctrl-C to rerun the tests, these tests will fail > > again. > > > Only the ones of the form "new_user(:password => 'bad').should > > have(1).error_on(:password)" fail. > > > Below is the output from autotest, including the initial run, and > > second run after I make a trivial change to the spec. > > > Thanks. > > Doug > > > Failures: > > ? 1) User should require username > > ? ? ?Failure/Error: new_user(:username => '').should > > have(1).error_on(:username) > > ? ? ?expected 1 error on :username, got 0 > > ? ? ?# ./spec/models/user_spec.rb:21:in `block (2 levels) in > (required)>' > > > ? 2) User should require password > > ? ? ?Failure/Error: new_user(:password => '').should > > have(1).error_on(:password) > > ? ? ?expected 1 error on :password, got 0 > > ? ? ?# ./spec/models/user_spec.rb:25:in `block (2 levels) in > (required)>' > > > ? 3) User should require well formed email > > ? ? ?Failure/Error: new_user(:email => 'foo at b...@example.com').should > > have(1).error_on(:email) > > ? ? ?expected 1 error on :email, got 0 > > ? ? ?# ./spec/models/user_spec.rb:29:in `block (2 levels) in > (required)>' > > > ? 4) User should validate uniqueness of email > > ? ? ?Failure/Error: new_user(:email => '... at example.com').should > > have(1).error_on(:email) > > ? ? ?expected 1 error on :email, got 0 > > ? ? ?# ./spec/models/user_spec.rb:34:in `block (2 levels) in > (required)>' > > > ? 5) User should validate uniqueness of username > > ? ? ?Failure/Error: new_user(:username => 'uniquename').should > > have(1).error_on(:username) > > ? ? ?expected 1 error on :username, got 0 > > ? ? ?# ./spec/models/user_spec.rb:39:in `block (2 levels) in > (required)>' > > > ? 6) User should not allow odd characters in username > > ? ? ?Failure/Error: new_user(:username => 'odd ^&(@)').should > > have(1).error_on(:username) > > ? ? ?expected 1 error on :username, got 0 > > ? ? ?# ./spec/models/user_spec.rb:43:in `block (2 levels) in > (required)>' > > > ? 7) User should validate password is longer than 3 characters > > ? ? ?Failure/Error: new_user(:password => 'bad').should > > have(1).error_on(:password) > > ? ? ?expected 1 error on :password, got 0 > > ? ? ?# ./spec/models/user_spec.rb:47:in `block (2 levels) in > (required)>' > > > ? 8) User should require matching password confirmation > > ? ? ?Failure/Error: new_user(:password_confirmation => > > 'nonmatching').should have(1).error_on(:password) > > ? ? ?expected 1 error on :password, got 0 > > ? ? ?# ./spec/models/user_spec.rb:51:in `block (2 levels) in > (required)>' > > > Finished in 3.46 seconds > > 111 examples, 8 failures, 4 pending > > bundle exec /Users/doug/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S /Users/ > > doug/.rvm/gems/ruby-1.9.2-p0 at class-proto/gems/rspec-core-2.0.1/bin/ > > rspec --autotest '/Users/doug/dev/hg/class-proto/spec/models/ > > user_spec.rb' > > ...Trivial change > > ........... > > > Finished in 1.17 seconds > > 14 examples, 0 failures > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > I'll add that this behavior only occurs with the model User. I set up > some similar tests for other classes (named Sample and > SampleClassification). These do not have the same problem. Their > validation tests pass during batch and single test runs. > > I created a new User model from scratch with a single > validates_presence_of call, and got the same unexpected behavior: in > single spec runs they pass, and in batch runs they fail. > > Doug > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From nick at deadorange.com Sat Nov 20 23:12:17 2010 From: nick at deadorange.com (Nick Hoffman) Date: Sat, 20 Nov 2010 23:12:17 -0500 Subject: [rspec-users] Specs for controllers and rescue_from Message-ID: Hey guys. My ApplicationController rescues Mongoid::Errors::DocumentNotFound errors like this: class ApplicationController < ActionController::Base rescue_from Mongoid::Errors::DocumentNotFound, :with => :resource_not_found protected def resource_not_found(error) flash[:alert] = t('errors.resource_not_found') redirect_to root_url end end Obviously, I need specs for this. However, I can't figure out how this should be specced. Should I create a shared example group that expects the flash-alert and redirect, and use it in every controller action that could potentially raise this error? This seems right, but will be verbose. Or, in each controller that could raise this error, should I create one example group that raises this error and expects the flash-alert and redirect? This seems right because the rescuing behaviour exists within the controller rather than each action. However, it ignores the possibility of an action rescuing the error. Should I create a dummy controller with an action that raises this error, and spec that? This would be akin to speccing ApplicationController, though indirectly. This method was my first inclination, but fails to provide specs for the other controllers that inherit the rescuing behaviour. How would you spec this? I'm all ears! Nick From phillipkoebbe at gmail.com Sun Nov 21 06:40:21 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 21 Nov 2010 05:40:21 -0600 Subject: [rspec-users] Specs for controllers and rescue_from In-Reply-To: References: Message-ID: <4CE90525.4030800@gmail.com> I had a similar problem in the past (with RSpec 1.x). I tend to create what I call a BaseController in each namespace specifically for shared behavior. The best example of this is class Admin::BaseController < ApplicationController before_filter :require_logged_in before_filter :require_admin protected def require_admin redirect_to error_path(403) unless current_user.is_administrator end end [:require_logged_in is defined in ApplicationController because it is also used by User::BaseController.] More comments inline. On 2010-11-20 10:12 PM, Nick Hoffman wrote: > Hey guys. My ApplicationController rescues > Mongoid::Errors::DocumentNotFound errors like this: > > class ApplicationController< ActionController::Base > rescue_from Mongoid::Errors::DocumentNotFound, > :with => :resource_not_found > > protected > > def resource_not_found(error) > flash[:alert] = t('errors.resource_not_found') > redirect_to root_url > end > end > > Obviously, I need specs for this. However, I can't figure out how this > should be specced. > > Should I create a shared example group that expects the flash-alert > and redirect, and use it in every controller action that could > potentially raise this error? This seems right, but will be verbose. > I started to go this route as it seemed most appropriate to spec a controller's behavior in that controller, but since the behavior was going to be the same in all such controllers, a shared example made perfect sense. I was happily specing against the index action of such controllers, until I came to one that didn't have an index action. Instead of putting in one just to be able to test, I tried figuring out how to use an arbitrary action in the shared example. But that became too complicated very quickly. There very well might be a way to do this, but I was unable to get to it. > Or, in each controller that could raise this error, should I create > one example group that raises this error and expects the flash-alert > and redirect? This seems right because the rescuing behaviour exists > within the controller rather than each action. However, it ignores the > possibility of an action rescuing the error. > Could you not also spec it in actions that you see as possible sources of the exception? This approach would certainly be most verbose, but maybe you should start here and see what pattern develops that could lead you down the proper path of refactoring. > Should I create a dummy controller with an action that raises this > error, and spec that? This would be akin to speccing > ApplicationController, though indirectly. This method was my first > inclination, but fails to provide specs for the other controllers that > inherit the rescuing behaviour. > Ultimately, I went this direction. I more or less applied the logic that I would with a plugin: if the plugin is well tested and I trust it, do I really need to test it wherever it is used? Here is what I ended up with: require 'controller_helper' describe Admin::BaseController do should_descend_from ApplicationController should_have_before_filter :require_logged_in should_have_before_filter :require_admin end class Admin::BogusController < Admin::BaseController def index render :nothing => true end end ActionController::Routing::Routes.draw do |map| map.namespace :admin do |admin| admin.resources :bogus end end describe Admin::BogusController do context 'when the user is not logged in' do before(:each) { get :index } it 'should redirect to login path' do response.should redirect_to(login_path) end end context 'when accessed by administrative users' do before :each do setup_admin get :index end it 'should not redirect to error path 403' do response.should_not redirect_to(error_path(403)) end should_succeed end context 'when accessed by non-administrative users' do before :each do setup_user get :index end it 'should redirect to error path 403' do response.should redirect_to(error_path(403)) end end end I'm not sure if this is what I'd do today, but this did solve my problem before. My preference would have been the shared examples, but I don't want my tests to be too complicated. Peace, Phillip From dchelimsky at gmail.com Sun Nov 21 17:02:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Nov 2010 16:02:57 -0600 Subject: [rspec-users] Specs for controllers and rescue_from In-Reply-To: References: Message-ID: <8EF89EDE-AED8-4839-9AE6-D07EFA0CC311@gmail.com> On Nov 20, 2010, at 10:12 PM, Nick Hoffman wrote: > Hey guys. My ApplicationController rescues > Mongoid::Errors::DocumentNotFound errors like this: > > class ApplicationController < ActionController::Base > rescue_from Mongoid::Errors::DocumentNotFound, > :with => :resource_not_found > > protected > > def resource_not_found(error) > flash[:alert] = t('errors.resource_not_found') > redirect_to root_url > end > end > > Obviously, I need specs for this. However, I can't figure out how this > should be specced. > > Should I create a shared example group that expects the flash-alert > and redirect, and use it in every controller action that could > potentially raise this error? This seems right, but will be verbose. > > Or, in each controller that could raise this error, should I create > one example group that raises this error and expects the flash-alert > and redirect? This seems right because the rescuing behaviour exists > within the controller rather than each action. However, it ignores the > possibility of an action rescuing the error. > > Should I create a dummy controller with an action that raises this > error, and spec that? This would be akin to speccing > ApplicationController, though indirectly. This method was my first > inclination, but fails to provide specs for the other controllers that > inherit the rescuing behaviour. > > How would you spec this? I'm all ears! http://relishapp.com/rspec/rspec-rails/v/2-1/dir/controller-specs/anonymous-controller -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Nov 22 00:02:08 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Nov 2010 23:02:08 -0600 Subject: [rspec-users] specs pass individually, but fail using autotest In-Reply-To: <913f2fbe-a736-47e1-9def-af00ba71c287@y23g2000yqd.googlegroups.com> References: <9c03549c-1b11-4ff3-a1b8-3f2079c74bd4@t35g2000yqj.googlegroups.com> <913f2fbe-a736-47e1-9def-af00ba71c287@y23g2000yqd.googlegroups.com> Message-ID: <838A4A9E-5161-4C29-A17E-108F408A2A17@gmail.com> On Nov 20, 2010, at 9:49 PM, Doug E. wrote: > Problem discovered, but not solved. It isn't an rspec problem. It's > caused by nifty-authentication's use of Mocha's any_instance. > users_controller_spec.rb's last test calls: > > User.any_instance.stubs(:valid?).and_returns(true) > > This is fine if the tests are run singly, but with autotest the call > in the controller spec still affects *every* subsequent User instance, > and so it's impossible later in the same autotest batch to test the > validity of later user objects. They just return true. > > An aside: It seems that mocha should make it possible to undo the > effect of any_instance.stubs(:sym). AFAIK, this should happen automatically, assuming your suite is configured to use mocha. Do you have config.mock_with(:mocha) (usually in 'spec/spec_helper.rb')? > > On Nov 20, 9:49 pm, "Doug E." wrote: >> On Nov 20, 8:43 pm, "Doug E." wrote: >> >> >> >> >> >> >> >> >> >>> Hi, >>> I'm trying to run autotest and I'm using ryanb's nifty authentication >>> with Rails 3 and Rpec 2. When I run autotest, the user model spec >>> fails all its validation tests with the "error_on" matcher. >> >>> If I run the spec by itself, it passes. If I'm running autotest and >>> make a trivial change to the spec and save it, so that autotest runs >>> just the user spec by itself, it passes. All the other tests in the >>> spec pass. If I hit Ctrl-C to rerun the tests, these tests will fail >>> again. >> >>> Only the ones of the form "new_user(:password => 'bad').should >>> have(1).error_on(:password)" fail. >> >>> Below is the output from autotest, including the initial run, and >>> second run after I make a trivial change to the spec. >> >>> Thanks. >>> Doug >> >>> Failures: >>> 1) User should require username >>> Failure/Error: new_user(:username => '').should >>> have(1).error_on(:username) >>> expected 1 error on :username, got 0 >>> # ./spec/models/user_spec.rb:21:in `block (2 levels) in >> (required)>' >> >>> 2) User should require password >>> Failure/Error: new_user(:password => '').should >>> have(1).error_on(:password) >>> expected 1 error on :password, got 0 >>> # ./spec/models/user_spec.rb:25:in `block (2 levels) in >> (required)>' >> >>> 3) User should require well formed email >>> Failure/Error: new_user(:email => 'foo at b...@example.com').should >>> have(1).error_on(:email) >>> expected 1 error on :email, got 0 >>> # ./spec/models/user_spec.rb:29:in `block (2 levels) in >> (required)>' >> >>> 4) User should validate uniqueness of email >>> Failure/Error: new_user(:email => '... at example.com').should >>> have(1).error_on(:email) >>> expected 1 error on :email, got 0 >>> # ./spec/models/user_spec.rb:34:in `block (2 levels) in >> (required)>' >> >>> 5) User should validate uniqueness of username >>> Failure/Error: new_user(:username => 'uniquename').should >>> have(1).error_on(:username) >>> expected 1 error on :username, got 0 >>> # ./spec/models/user_spec.rb:39:in `block (2 levels) in >> (required)>' >> >>> 6) User should not allow odd characters in username >>> Failure/Error: new_user(:username => 'odd ^&(@)').should >>> have(1).error_on(:username) >>> expected 1 error on :username, got 0 >>> # ./spec/models/user_spec.rb:43:in `block (2 levels) in >> (required)>' >> >>> 7) User should validate password is longer than 3 characters >>> Failure/Error: new_user(:password => 'bad').should >>> have(1).error_on(:password) >>> expected 1 error on :password, got 0 >>> # ./spec/models/user_spec.rb:47:in `block (2 levels) in >> (required)>' >> >>> 8) User should require matching password confirmation >>> Failure/Error: new_user(:password_confirmation => >>> 'nonmatching').should have(1).error_on(:password) >>> expected 1 error on :password, got 0 >>> # ./spec/models/user_spec.rb:51:in `block (2 levels) in >> (required)>' >> >>> Finished in 3.46 seconds >>> 111 examples, 8 failures, 4 pending >>> bundle exec /Users/doug/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S /Users/ >>> doug/.rvm/gems/ruby-1.9.2-p0 at class-proto/gems/rspec-core-2.0.1/bin/ >>> rspec --autotest '/Users/doug/dev/hg/class-proto/spec/models/ >>> user_spec.rb' >>> ...Trivial change >>> ........... >> >>> Finished in 1.17 seconds >>> 14 examples, 0 failures >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> >> I'll add that this behavior only occurs with the model User. I set up >> some similar tests for other classes (named Sample and >> SampleClassification). These do not have the same problem. Their >> validation tests pass during batch and single test runs. >> >> I created a new User model from scratch with a single >> validates_presence_of call, and got the same unexpected behavior: in >> single spec runs they pass, and in batch runs they fail. >> >> Doug >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From somaraju at gmail.com Mon Nov 22 07:24:03 2010 From: somaraju at gmail.com (Raghunandan Somaraju) Date: Mon, 22 Nov 2010 17:54:03 +0530 Subject: [rspec-users] How to mock a logged in user Message-ID: <4CEA60E3.6000804@gmail.com> I need to update something for a logged in user. My controller code for the action is: def som_action @_current_user.save_choice(params) end My application_controller.rb contains the following: class ApplicationController < ActionController::Base before_filter :current_user def current_user @_current_user ||= session[:current_user_id] && User.find(session[:current_user_id]) end end In my controller spec, I am trying something like this: let(:user) { mock_model("User", :id => 1001) } let(:item) { mock_model("Item", :id => 1010) } before(:each) do controller.stub!(:current_user).and_return(user) end describe "POST create" do context "when the user chooses an item" do it 'creates a item_choice' do ItemChoice.should_receive(:new). with("requester_id" => user.id, "item_id" => item.id). and_return(item_choice) post :create, :item_choice => { "item_id" => item.id } response.should redirect_to(home_path) end end end I get nil object error when I run this spec, as there is no @_current_user set. How do I stub such that there is a user with an id to do this? raghu From lists at ruby-forum.com Mon Nov 22 09:00:16 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Mon, 22 Nov 2010 15:00:16 +0100 Subject: [rspec-users] Testing update, flash[:error] Message-ID: <50ac5194a3a0dfcf6ddc355fc3292f4e@ruby-forum.com> Hello everyone, I'm trying to write a failure test for updating a model, but the flash[:error] seems to be causing a problem. All code can be found here: http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw I've also tried using regular expressions, instead of: flash[:error].should == "Name can't be blank" I've tried: flash[:error].should =~ /Name can't be blank/i Thank you in advance!! Andrew Davis -- Posted via http://www.ruby-forum.com/. From nellboy at gmail.com Mon Nov 22 10:04:46 2010 From: nellboy at gmail.com (Paul Nelligan) Date: Mon, 22 Nov 2010 15:04:46 +0000 Subject: [rspec-users] Testing update, flash[:error] In-Reply-To: <50ac5194a3a0dfcf6ddc355fc3292f4e@ruby-forum.com> References: <50ac5194a3a0dfcf6ddc355fc3292f4e@ruby-forum.com> Message-ID: Hi Andrew I suspect that flash[:error] is not a valid identifier, and therefore is returning a nil value. Hope this is of use to you. Paul On Mon, Nov 22, 2010 at 2:00 PM, Andrew Davis wrote: > Hello everyone, > > I'm trying to write a failure test for updating a model, but the > flash[:error] seems to be causing a problem. > > All code can be found here: > http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw > > I've also tried using regular expressions, instead of: > > flash[:error].should == "Name can't be blank" > > I've tried: > > flash[:error].should =~ /Name can't be blank/i > > Thank you in advance!! > Andrew Davis > > -- > 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 doug at emeryit.com Mon Nov 22 11:31:59 2010 From: doug at emeryit.com (Doug E.) Date: Mon, 22 Nov 2010 08:31:59 -0800 (PST) Subject: [rspec-users] specs pass individually, but fail using autotest In-Reply-To: <838A4A9E-5161-4C29-A17E-108F408A2A17@gmail.com> References: <9c03549c-1b11-4ff3-a1b8-3f2079c74bd4@t35g2000yqj.googlegroups.com> <913f2fbe-a736-47e1-9def-af00ba71c287@y23g2000yqd.googlegroups.com> <838A4A9E-5161-4C29-A17E-108F408A2A17@gmail.com> Message-ID: On Nov 22, 12:02?am, David Chelimsky wrote: > On Nov 20, 2010, at 9:49 PM, Doug E. wrote: > > > Problem discovered, but not solved. It isn't an rspec problem. It's > > caused by nifty-authentication's use of Mocha's any_instance. > > users_controller_spec.rb's last test calls: > > > ? ?User.any_instance.stubs(:valid?).and_returns(true) > > > This is fine if the tests are run singly, but with autotest the call > > in the controller spec still affects *every* subsequent User instance, > > and so it's impossible later in the same autotest batch to test the > > validity of later user objects. They just return true. > > > An aside: It seems that mocha should make it possible to undo the > > effect of any_instance.stubs(:sym). > > AFAIK, this should happen automatically, assuming your suite is configured to use mocha. Do you have config.mock_with(:mocha) (usually in 'spec/spec_helper.rb')? > Thanks, David. I rewrote the tests to use rspec mocks. All the other tests already use them. I'm learning rspec 2, and am trying to stick strictly with rspec tests and mocks. In this application, I've replaced the mocha based specs created by the nifty scaffold generator with rspec scaffold specs. Rspec, of course, doesn't have a generator parallel to the nifty authentication generator, so I left those tests in place, not knowing that the two would not play nice together. Now that I understand what's happened, I've removed mocha and rewritten mocha-based specs. Doug > > > > On Nov 20, 9:49 pm, "Doug E." wrote: > >> On Nov 20, 8:43 pm, "Doug E." wrote: > > >>> Hi, > >>> I'm trying to run autotest and I'm using ryanb's nifty authentication > >>> with Rails 3 and Rpec 2. When I run autotest, the user model spec > >>> fails all its validation tests with the "error_on" matcher. > > >>> If I run the spec by itself, it passes. If I'm running autotest and > >>> make a trivial change to the spec and save it, so that autotest ?runs > >>> just the user spec by itself, it passes. All the other tests in the > >>> spec pass. If I hit Ctrl-C to rerun the tests, these tests will fail > >>> again. > > >>> Only the ones of the form "new_user(:password => 'bad').should > >>> have(1).error_on(:password)" fail. > > >>> Below is the output from autotest, including the initial run, and > >>> second run after I make a trivial change to the spec. > > >>> Thanks. > >>> Doug > > >>> Failures: > >>> ? 1) User should require username > >>> ? ? ?Failure/Error: new_user(:username => '').should > >>> have(1).error_on(:username) > >>> ? ? ?expected 1 error on :username, got 0 > >>> ? ? ?# ./spec/models/user_spec.rb:21:in `block (2 levels) in >>> (required)>' > > >>> ? 2) User should require password > >>> ? ? ?Failure/Error: new_user(:password => '').should > >>> have(1).error_on(:password) > >>> ? ? ?expected 1 error on :password, got 0 > >>> ? ? ?# ./spec/models/user_spec.rb:25:in `block (2 levels) in >>> (required)>' > > >>> ? 3) User should require well formed email > >>> ? ? ?Failure/Error: new_user(:email => 'foo at b...@example.com').should > >>> have(1).error_on(:email) > >>> ? ? ?expected 1 error on :email, got 0 > >>> ? ? ?# ./spec/models/user_spec.rb:29:in `block (2 levels) in >>> (required)>' > > >>> ? 4) User should validate uniqueness of email > >>> ? ? ?Failure/Error: new_user(:email => '... at example.com').should > >>> have(1).error_on(:email) > >>> ? ? ?expected 1 error on :email, got 0 > >>> ? ? ?# ./spec/models/user_spec.rb:34:in `block (2 levels) in >>> (required)>' > > >>> ? 5) User should validate uniqueness of username > >>> ? ? ?Failure/Error: new_user(:username => 'uniquename').should > >>> have(1).error_on(:username) > >>> ? ? ?expected 1 error on :username, got 0 > >>> ? ? ?# ./spec/models/user_spec.rb:39:in `block (2 levels) in >>> (required)>' > > >>> ? 6) User should not allow odd characters in username > >>> ? ? ?Failure/Error: new_user(:username => 'odd ^&(@)').should > >>> have(1).error_on(:username) > >>> ? ? ?expected 1 error on :username, got 0 > >>> ? ? ?# ./spec/models/user_spec.rb:43:in `block (2 levels) in >>> (required)>' > > >>> ? 7) User should validate password is longer than 3 characters > >>> ? ? ?Failure/Error: new_user(:password => 'bad').should > >>> have(1).error_on(:password) > >>> ? ? ?expected 1 error on :password, got 0 > >>> ? ? ?# ./spec/models/user_spec.rb:47:in `block (2 levels) in >>> (required)>' > > >>> ? 8) User should require matching password confirmation > >>> ? ? ?Failure/Error: new_user(:password_confirmation => > >>> 'nonmatching').should have(1).error_on(:password) > >>> ? ? ?expected 1 error on :password, got 0 > >>> ? ? ?# ./spec/models/user_spec.rb:51:in `block (2 levels) in >>> (required)>' > > >>> Finished in 3.46 seconds > >>> 111 examples, 8 failures, 4 pending > >>> bundle exec /Users/doug/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S /Users/ > >>> doug/.rvm/gems/ruby-1.9.2-p0 at class-proto/gems/rspec-core-2.0.1/bin/ > >>> rspec --autotest '/Users/doug/dev/hg/class-proto/spec/models/ > >>> user_spec.rb' > >>> ...Trivial change > >>> ........... > > >>> Finished in 1.17 seconds > >>> 14 examples, 0 failures > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > >> I'll add that this behavior only occurs with the model User. I set up > >> some similar tests for other classes (named Sample and > >> SampleClassification). These do not have the same problem. Their > >> validation tests pass during batch and single test runs. > > >> I created a new User model from scratch with a single > >> validates_presence_of call, and got the same unexpected behavior: in > >> single spec runs they pass, and in batch runs they fail. > > >> Doug > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lesliefreeman3 at gmail.com Mon Nov 22 15:42:17 2010 From: lesliefreeman3 at gmail.com (LesFreeman) Date: Mon, 22 Nov 2010 12:42:17 -0800 (PST) Subject: [rspec-users] autotest giving error when having shared example in specs In-Reply-To: References: Message-ID: <35f1161a-a48b-4cfa-bffc-701e13625a12@fl7g2000vbb.googlegroups.com> I too am having this error On Sep 28, 10:42?pm, Amiruddin Nagri wrote: > I am having a shared example 'allow authorized actions' for my Rails 3 RSpec > 2.beta.20 application. The shared example looks like > > share_examples_for 'allow authorized actions' do > ? ... > end > > This shared example is in file > spec/controllers/support/authorization_shared_example.rb, which I am > requiring in spec_helper.rb. I am also using autotest to give me quick > feedback. Autotest is generating following command to run rspec > > ruby>/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/bin/rspec to rails root>/spec/controllers/support/authorization_shared_example.rb > > > Since autotest is also including support file when running rspec, I am > getting following errors with autotest > > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/shared_example_group.rb:43:in > `ensure_shared_example_group_name_not_taken': Shared example group 'allow > authorized actions' already exists (ArgumentError) > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/shared_example_group.rb:6:in > `share_examples_for' > ? ? from > /Users/arusarh/work/ece/carbonomist/spec/controllers/support/authorization_ shared_example.rb:1:in > `' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in > `load' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in > `block in load' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:227:in > `load_dependency' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in > `load' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in > `block in load_spec_files' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in > `map' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in > `load_spec_files' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/command_line.rb:18:in > `run' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:46:in > `run_in_process' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:37:in > `run' > ? ? from > /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:10:in > `block in autorun' > > Any ideas how to not make autotest include shared example files loaded > through command line, but only include files with pattern "*_spec.rb", or > have anyone else facing same situation. > > Regards, > Amiruddin Nagri, > Bangalore, 560008, KA > India > > Y! IM : amir_na... at yahoo.com > GTalk : amir.na... at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From robert.dober at gmail.com Mon Nov 22 16:02:30 2010 From: robert.dober at gmail.com (Robert Dober) Date: Mon, 22 Nov 2010 22:02:30 +0100 Subject: [rspec-users] How to mock a logged in user In-Reply-To: <4CEA60E3.6000804@gmail.com> References: <4CEA60E3.6000804@gmail.com> Message-ID: On Mon, Nov 22, 2010 at 1:24 PM, Raghunandan Somaraju wrote: > I need to update something for a logged in user. My controller code for the > action is: > > def som_action > ?@_current_user.save_choice(params) > end you are stubbing current_user, not @_current_user, thus this will fail. Maybe it would be more idiomatic to change this to def some_action current_user.save_choice( params ) end this should solve your setup problem too. > > My application_controller.rb contains the following: > > class ApplicationController < ActionController::Base > ?before_filter :current_user > > ?def current_user > ? ?@_current_user ||= session[:current_user_id] && > ? ? ?User.find(session[:current_user_id]) > ?end > end > > In my controller spec, I am trying something like this: > > ?let(:user) { mock_model("User", :id => 1001) } > ?let(:item) { mock_model("Item", :id => 1010) } > > ?before(:each) do > ? ?controller.stub!(:current_user).and_return(user) > ?end > > ?describe "POST create" do > ? ?context "when the user chooses an item" do > ? ? ?it 'creates a item_choice' do > ? ? ? ?ItemChoice.should_receive(:new). > ? ? ? ? ?with("requester_id" => user.id, "item_id" => item.id). > ? ? ? ? ?and_return(item_choice) Maybe i missed something here, but where does item_choice come from, should that not be item? > ? ? ? ?post :create, :item_choice => { "item_id" => item.id } > ? ? ? ?response.should redirect_to(home_path) > ? ? ?end > ? ?end > ?end > > > I get nil object error when I run this spec, as there is no @_current_user > set. How do I stub such that there is a user with an id to do this? > HTH Cheers Robert -- The 1,000,000th fibonacci number contains '42' 2039 times; that is almost 30 occurrences more than expected (208988 digits). N.B. The 42nd fibonacci number does not contain '1000000' that is almost the expected 3.0e-06 times. From robert.dober at gmail.com Mon Nov 22 16:55:03 2010 From: robert.dober at gmail.com (Robert Dober) Date: Mon, 22 Nov 2010 22:55:03 +0100 Subject: [rspec-users] Testing update, flash[:error] In-Reply-To: References: <50ac5194a3a0dfcf6ddc355fc3292f4e@ruby-forum.com> Message-ID: On Mon, Nov 22, 2010 at 4:04 PM, Paul Nelligan wrote: > Hi Andrew > I suspect that flash[:error] is not a valid identifier, ?and therefore is > returning a nil value. > Hope this is of use to you. > Paul > > On Mon, Nov 22, 2010 at 2:00 PM, Andrew Davis wrote: >> >> Hello everyone, >> >> I'm trying to write a failure test for updating a model, but the >> flash[:error] seems to be causing a problem. >> >> All code can be found here: >> http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw >> >> I've also tried using regular expressions, instead of: >> >> flash[:error].should == "Name can't be blank" >> >> I've tried: >> >> flash[:error].should =~ /Name can't be blank/i As Paul pointed out correctly flash[:error] == nil, thus your spec works quite correctly. All you have to do now is to set flash[:error] appropriately, in your case I guess that this should be done by means of ActiveRecord/ActiveModel validations. Are you sure that you have the necessary validation in your Task model? HTH Robert -- The 1,000,000th fibonacci number contains '42' 2039 times; that is almost 30 occurrences more than expected (208988 digits). N.B. The 42nd fibonacci number does not contain '1000000' that is almost the expected 3.0e-06 times. From nellboy at gmail.com Mon Nov 22 17:26:11 2010 From: nellboy at gmail.com (Paul Nelligan) Date: Mon, 22 Nov 2010 22:26:11 +0000 Subject: [rspec-users] Testing update, flash[:error] In-Reply-To: References: <50ac5194a3a0dfcf6ddc355fc3292f4e@ruby-forum.com> Message-ID: the question you need to ask is: is flash[:error] a variable within the scope that you're working ? ... I suspect that it's not, although I could be wrong. with that in mind, does anyone know of a way of determining which variables are accessible via rspec on each (MVC) layer ?, Is it a simple case of 'what's accessible in the controller is accessible in the controller spec' (for example) ?, or is it more complicated ? cheers On Mon, Nov 22, 2010 at 9:55 PM, Robert Dober wrote: > On Mon, Nov 22, 2010 at 4:04 PM, Paul Nelligan wrote: > > Hi Andrew > > I suspect that flash[:error] is not a valid identifier, and therefore is > > returning a nil value. > > Hope this is of use to you. > > Paul > > > > On Mon, Nov 22, 2010 at 2:00 PM, Andrew Davis > wrote: > >> > >> Hello everyone, > >> > >> I'm trying to write a failure test for updating a model, but the > >> flash[:error] seems to be causing a problem. > >> > >> All code can be found here: > >> http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw > >> > >> I've also tried using regular expressions, instead of: > >> > >> flash[:error].should == "Name can't be blank" > >> > >> I've tried: > >> > >> flash[:error].should =~ /Name can't be blank/i > > As Paul pointed out correctly flash[:error] == nil, thus your spec > works quite correctly. All you have to do now is to set flash[:error] > appropriately, in your case I guess that this should be done by means > of ActiveRecord/ActiveModel validations. > Are you sure that you have the necessary validation in your Task model? > > HTH > Robert > > -- > The 1,000,000th fibonacci number contains '42' 2039 times; that is > almost 30 occurrences more than expected (208988 digits). > N.B. The 42nd fibonacci number does not contain '1000000' that is > almost the expected 3.0e-06 times. > _______________________________________________ > 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 robert.dober at gmail.com Mon Nov 22 18:23:08 2010 From: robert.dober at gmail.com (Robert Dober) Date: Tue, 23 Nov 2010 00:23:08 +0100 Subject: [rspec-users] Testing update, flash[:error] In-Reply-To: References: <50ac5194a3a0dfcf6ddc355fc3292f4e@ruby-forum.com> Message-ID: On Mon, Nov 22, 2010 at 11:26 PM, Paul Nelligan wrote: > the question you need to ask is: is flash[:error] a variable within the > scope that you're working ? ... I suspect that it's not, although I could be > wrong. > with that in mind, ?does anyone know of a way of determining which variables > are accessible via rspec on each (MVC) layer ?, ?Is it a simple case of > 'what's accessible in the controller is accessible in the controller spec' > (for example) ?, ?or is it more complicated ? > cheers > On Mon, Nov 22, 2010 at 9:55 PM, Robert Dober > wrote: Paul, it was a little bit tricky to answer this because of the top post, most of us are not used to that. So please if you can, do rather bottom post or inline post. That said, I am not sure what you mean by flash[:error] being a variable? As the trace shows flash[:error] is nil, from this alone, we can follow that flash points to an object which responds to the #[] message. In our case it replies to [:error] with nil. However in the given context we *know* that flash is a Hash representing well, the flash. I am not an expert to tell you where in the rspec setup this is mocked, but this should not be the problem in our case. That said I would be happy to learn more about that mechanism. Cheers R. From somaraju at gmail.com Tue Nov 23 07:04:12 2010 From: somaraju at gmail.com (Raghu Somaraju) Date: Tue, 23 Nov 2010 04:04:12 -0800 (PST) Subject: [rspec-users] How to mock a logged in user In-Reply-To: References: <4CEA60E3.6000804@gmail.com> Message-ID: <30283795.post@talk.nabble.com> Thank you Robert. That works. I should have used the "current_user" instead of @_current_user in the first place. But, if I do want to use @_current_user, how do I pass on that instance variable to the controller from spec? Ignore the item_choice. It is a remnant of a piece that I edited off to simplify the question and concentrate on what I wanted. raghu Robert Dober wrote: > > On Mon, Nov 22, 2010 at 1:24 PM, Raghunandan Somaraju > wrote: >> I need to update something for a logged in user. My controller code for >> the >> action is: >> >> def som_action >> ?@_current_user.save_choice(params) >> end > you are stubbing current_user, not @_current_user, thus this will > fail. Maybe it would be more idiomatic to change this to > > def some_action > current_user.save_choice( params ) > end > > this should solve your setup problem too. >> >> My application_controller.rb contains the following: >> >> class ApplicationController < ActionController::Base >> ?before_filter :current_user >> >> ?def current_user >> ? ?@_current_user ||= session[:current_user_id] && >> ? ? ?User.find(session[:current_user_id]) >> ?end >> end >> >> In my controller spec, I am trying something like this: >> >> ?let(:user) { mock_model("User", :id => 1001) } >> ?let(:item) { mock_model("Item", :id => 1010) } >> >> ?before(:each) do >> ? ?controller.stub!(:current_user).and_return(user) >> ?end >> >> ?describe "POST create" do >> ? ?context "when the user chooses an item" do >> ? ? ?it 'creates a item_choice' do >> ? ? ? ?ItemChoice.should_receive(:new). >> ? ? ? ? ?with("requester_id" => user.id, "item_id" => item.id). >> ? ? ? ? ?and_return(item_choice) > Maybe i missed something here, but where does item_choice come from, > should that not be item? >> ? ? ? ?post :create, :item_choice => { "item_id" => item.id } >> ? ? ? ?response.should redirect_to(home_path) >> ? ? ?end >> ? ?end >> ?end >> >> >> I get nil object error when I run this spec, as there is no >> @_current_user >> set. How do I stub such that there is a user with an id to do this? >> > HTH > Cheers > Robert > > -- > The 1,000,000th fibonacci number contains '42' 2039 times; that is > almost 30 occurrences more than expected (208988 digits). > N.B. The 42nd fibonacci number does not contain '1000000' that is > almost the expected 3.0e-06 times. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://old.nabble.com/How-to-mock-a-logged-in-user-tp30278143p30283795.html Sent from the rspec-users mailing list archive at Nabble.com. From robert.dober at gmail.com Tue Nov 23 10:14:43 2010 From: robert.dober at gmail.com (Robert Dober) Date: Tue, 23 Nov 2010 16:14:43 +0100 Subject: [rspec-users] How to mock a logged in user In-Reply-To: <30283795.post@talk.nabble.com> References: <4CEA60E3.6000804@gmail.com> <30283795.post@talk.nabble.com> Message-ID: On Tue, Nov 23, 2010 at 1:04 PM, Raghu Somaraju wrote: > > Thank you Robert. That works. I should have used the "current_user" instead > of @_current_user in the first place. > > But, if I do want to use @_current_user, how do I pass on that instance > variable to the controller from spec? Short answer: Do not do it: Mocking is here to simulate behavior and ivars are here to implement state. (caching state in our case) Long answer: Although I believe that the above said is often true there must be exceptions, I adapted a relish test to show you how it works: https://gist.github.com/711904 Cheers Robert From rickcr at gmail.com Tue Nov 23 15:19:36 2010 From: rickcr at gmail.com (Rick R) Date: Tue, 23 Nov 2010 15:19:36 -0500 Subject: [rspec-users] Newbie questions - Best practice for loading local db data and model tests? (factory_girl , debugging ?) Message-ID: I'm pretty much a newbie with Rails and RSpec. I'm trying to follow best practices as I start to work on my own Rails side project. I'm using: rspec 2.1.0 / Rails 3.0.1 / ruby 1.9.2 1) Currently I have a Rake task that I run that populates the local sqlite db by using Rails models directly. Is this an ok approach to load simple local data so your app is in a state for using it while developing? eg 10.times do |x| u = User.new(...) u.save! 2) Is there a way I can just have my rspec tests run off the local sqlite db populated from my rake task? or is this a bad practice? I currently have messed around some using factory_girl factories and I can generate everything using the factories and use them in my rspec model tests, but this seems like I'm doing double the work - I'm loading things in my rake file and then again similar things are loaded with my factories? - maybe the solution is to leverage the factory_girl factories to also populate my local db with a rake task? What is the preferred approach for setting this kind of stuff up so your application has local data for working with and also for testing your models? 3) Is there any way to use log/put statements to help in debugging within an rspec test so that I can run a single test and see what's going on directly in the console? (I'm finding it difficult to find a lot of this documentation in one place. If all of the above kind of questions are easily covered in David's pragmatic rspec book, then I'll just go get the electronic version.) Thanks, -- Rick R -------------- next part -------------- An HTML attachment was scrubbed... URL: From rtlechow at gmail.com Tue Nov 23 19:08:23 2010 From: rtlechow at gmail.com (R.T.) Date: Tue, 23 Nov 2010 19:08:23 -0500 Subject: [rspec-users] Newbie questions - Best practice for loading local db data and model tests? (factory_girl , debugging ?) In-Reply-To: References: Message-ID: 1. Rails provides db/seeds.rb and the "db:seed" rake task specifically for this. See: http://railscasts.com/episodes/179-seed-data 2. Yep, this is bad and will lead to slow, brittle specs. The RSpec Book talks about the importance of isolation and all that Good Stuff. 3. The Rails logger is available to you: http://guides.rubyonrails.org/debugging_rails_applications.html#the-logger? Keep in mind, you could just set an expectation on whatever you wanted to "log", and see what happens to it in the spec output. On Tue, Nov 23, 2010 at 3:19 PM, Rick R wrote: > I'm pretty much a newbie with Rails and RSpec. I'm trying to follow best > practices as I start to work on my own Rails side project. > > I'm using: rspec 2.1.0 / Rails 3.0.1 / ruby 1.9.2 > > 1) Currently I have a Rake task that I run that populates the local sqlite > db by using Rails models directly. Is this an ok approach to load simple > local data so your app is in a state for using it while developing? eg > 10.times do |x| > u = User.new(...) > u.save! > > 2) Is there a way I can just have my rspec tests run off the local sqlite > db populated from my rake task? or is this a bad practice? I currently have > messed around some using factory_girl factories and I can generate > everything using the factories and use them in my rspec model tests, but > this seems like I'm doing double the work - I'm loading things in my rake > file and then again similar things are loaded with my factories? - maybe the > solution is to leverage the factory_girl factories to also populate my local > db with a rake task? > What is the preferred approach for setting this kind of stuff up so your > application has local data for working with and also for testing your > models? > > 3) Is there any way to use log/put statements to help in debugging within > an rspec test so that I can run a single test and see what's going on > directly in the console? > > (I'm finding it difficult to find a lot of this documentation in one place. > If all of the above kind of questions are easily covered in David's > pragmatic rspec book, then I'll just go get the electronic version.) > > Thanks, > > -- > Rick R > > _______________________________________________ > 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 kai.schlamp at googlemail.com Tue Nov 23 20:12:46 2010 From: kai.schlamp at googlemail.com (medihack) Date: Tue, 23 Nov 2010 17:12:46 -0800 (PST) Subject: [rspec-users] stub_chain together with should_receive Message-ID: <3dab104d-448f-42d0-9e0c-a56795533d49@l8g2000yqh.googlegroups.com> Hello. I am trying to test if in a method calling chain one of the methods get a specific parameter. In the below code for example MyModel must receive the parameter 0 for the method "offset". Unfortunately the code below does not work. It seems it is not possible to mix should_receive and stub_chain. How could I solve this? MyModel.should_receive(:offset).with(0).stub_chain(:tag_counts, :offset, :limit, :order).and_return([]) # does not work! Regards, Kai From lists at ruby-forum.com Wed Nov 24 02:07:05 2010 From: lists at ruby-forum.com (Arun Sharma) Date: Wed, 24 Nov 2010 08:07:05 +0100 Subject: [rspec-users] Spec::Mocks::MockExpectationError Message-ID: <136909e8f90826c12da48225879f09d1@ruby-forum.com> hii I am initial level of rspec.I am getting a error nil class. My Controller code is as follows class UsersController < ApplicationController before_filter :have_hard_drive? # # filter check for authorized user to access current server before_filter :authorized_user_to_server? # # Will check that the cpanel id is belongs to current server or not before_filter :is_cpanel_belongs_to_current_server? def automatic_partitions @prev_values = Cpanel.find(:all,:conditions => ["harddrive_id = ? and server_id =?",HARDDRIVE_SLOTS[params[:harddrive_id].to_i],params[:server_id]]) @prev_values.each do |value| value.destroy end @ignored_harddisk = IgnoredHarddrive.find(:first,:conditions => ["server_id = ? and harddrive_id = ?",params[:server_id],HARDDRIVE_SLOTS[params[:harddrive_id].to_i]]) if @ignored_harddisk @ignored_harddisk.destroy end end end and My Spec code is require 'spec_helper' describe CpanelsController do describe "role_as_superadmin" do before(:each) do user=User.authenticate('superadmin','carmatec') user.is_superadmin session[:user_id]=user.id controller.stub(:have_hard_drive?) controller.stub(:is_cpanel_belongs_to_current_server?) controller.stub(:authorized_user_to_server?) end it "should_test_automatic_partions" do @prev_values=mock_model(Cpanel) Cpanel.should_receive(:find).and_return(@prev_values) @ignored_harddisk=mock_model(IgnoredHarddrive) IgnoredHarddrive.should_receive(:find).and_return(@ignored_harddisk) get :automatic_partitions,{:harddrive_id=>'sda',:server_id=>1938} assigns[:prev_values].should=='' end end and I am getting an error Spec::Mocks::MockExpectationError in 'CpanelsController should_test_automatic_partions' expected :find with (any args) once, but received it 0 times please anyone post the solution -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Nov 24 08:19:58 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Wed, 24 Nov 2010 14:19:58 +0100 Subject: [rspec-users] NestedIterator Assistance Message-ID: <7e83b6f17c1dceba8c92a7b28d7a2dee@ruby-forum.com> Hello everyone, Metric_fu is informing me of some nested iterators, and I was hoping to gather some advice on how to refactor this method to make it more correct. Hopefully this will assist me in refactoring many other methods! Code is here: http://pastie.org/private/kqp1kk2uk81rs8s6atag Any thoughts on this? Thank you in advance! Andrew Davis -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Nov 24 08:38:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 24 Nov 2010 07:38:46 -0600 Subject: [rspec-users] stub_chain together with should_receive In-Reply-To: <3dab104d-448f-42d0-9e0c-a56795533d49@l8g2000yqh.googlegroups.com> References: <3dab104d-448f-42d0-9e0c-a56795533d49@l8g2000yqh.googlegroups.com> Message-ID: On Nov 23, 2010, at 7:12 PM, medihack wrote: > Hello. > > I am trying to test if in a method calling chain one of the methods > get a specific parameter. In the below code for example MyModel must > receive the parameter 0 for the method "offset". Unfortunately the > code below does not work. It seems it is not possible to mix > should_receive and stub_chain. How could I solve this? > > MyModel.should_receive(:offset).with(0).stub_chain(:tag_counts, :offset, :limit, :order).and_return([]) > # does not work! As you're finding out, chains like this are hard to test. That, and the fact that writing code before tests significantly increases the likelihood that the code will be hard to test. There is no easy way to do what you're trying to do with this code. You'd have to create a series of test doubles, like this: offset_return_value = double offset_return_value.stub_chain("limit.order") { [] } tag_counts_return_value = double tag_counts_return_value.should_receive(:offset).with(0).and_return(offset_return_value) MyModel.stub(:tag_counts) { tag_counts_return_value } The problem with this sort of structure, besides it being hard to read, is that you can't change anything about the implementation of the method that is invoking this chain without changing this example and likely many others. I'd recommend wrapping that chain in a method and specifying how that method behaves when a 0 makes its way to the offset method vs how it behaves otherwise. HTH, David > > Regards, > Kai > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cheers, David From dchelimsky at gmail.com Wed Nov 24 08:50:32 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 24 Nov 2010 07:50:32 -0600 Subject: [rspec-users] Spec::Mocks::MockExpectationError In-Reply-To: <136909e8f90826c12da48225879f09d1@ruby-forum.com> References: <136909e8f90826c12da48225879f09d1@ruby-forum.com> Message-ID: <63D0C3A5-8EF0-454B-8FDF-960DED24A9DD@gmail.com> On Nov 24, 2010, at 1:07 AM, Arun Sharma wrote: > hii > > I am initial level of rspec. I am getting a error nil class. > > My Controller code is as follows > > class UsersController < ApplicationController > before_filter :have_hard_drive? > # # filter check for authorized user to access current server > before_filter :authorized_user_to_server? > # # Will check that the cpanel id is belongs to current server or not > before_filter :is_cpanel_belongs_to_current_server? > def automatic_partitions > @prev_values = Cpanel.find(:all,:conditions => ["harddrive_id = ? > and server_id > =?",HARDDRIVE_SLOTS[params[:harddrive_id].to_i],params[:server_id]]) > @prev_values.each do |value| > value.destroy > end > @ignored_harddisk = IgnoredHarddrive.find(:first,:conditions => > ["server_id = ? and harddrive_id = > ?",params[:server_id],HARDDRIVE_SLOTS[params[:harddrive_id].to_i]]) > if @ignored_harddisk > @ignored_harddisk.destroy > end > end > end > > and My Spec code is > > require 'spec_helper' > describe CpanelsController do > > describe "role_as_superadmin" do > before(:each) do > user=User.authenticate('superadmin','carmatec') > user.is_superadmin > session[:user_id]=user.id > controller.stub(:have_hard_drive?) > controller.stub(:is_cpanel_belongs_to_current_server?) > controller.stub(:authorized_user_to_server?) > > end > it "should_test_automatic_partions" do > > @prev_values=mock_model(Cpanel) > Cpanel.should_receive(:find).and_return(@prev_values) > @ignored_harddisk=mock_model(IgnoredHarddrive) > IgnoredHarddrive.should_receive(:find).and_return(@ignored_harddisk) > > get :automatic_partitions,{:harddrive_id=>'sda',:server_id=>1938} > assigns[:prev_values].should=='' > > end > end > > and I am getting an error > > Spec::Mocks::MockExpectationError in 'CpanelsController > should_test_automatic_partions' > file_system: string, size: string, grow: string, bad_sector: string, > raid_level: string, raid_device: string, harddrive_id: string) (class)> > expected :find with (any args) once, but received it 0 times > > please anyone post the solution My guess is one of the before filters is preventing the automatic_partitions action from being invoked. Cheers, David From lists at ruby-forum.com Wed Nov 24 09:53:28 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Wed, 24 Nov 2010 15:53:28 +0100 Subject: [rspec-users] NestedIterator Assistance In-Reply-To: <7e83b6f17c1dceba8c92a7b28d7a2dee@ruby-forum.com> References: <7e83b6f17c1dceba8c92a7b28d7a2dee@ruby-forum.com> Message-ID: Oops, it appears I've posted this in the wrong forum. I apologize. -- Posted via http://www.ruby-forum.com/. From robert.dober at gmail.com Wed Nov 24 16:39:32 2010 From: robert.dober at gmail.com (Robert Dober) Date: Wed, 24 Nov 2010 22:39:32 +0100 Subject: [rspec-users] Puzzled about the rspec tests generated by Rails3 Message-ID: Hi all I am puzzled about the rspec tests that are generated by Rails3 scaffolding. I am however not sure if this is the correct place to discuss this issue. It might be that a rails ML/chat is better suited for that kind of discussion. It just depends on who is responsible for that code. Somehow I am too stupid to find that out, so please bare with me if I produced only noise here. Cheers Robert -- The 1,000,000th fibonacci number contains '42' 2039 times; that is almost 30 occurrences more than expected (208988 digits). N.B. The 42nd fibonacci number does not contain '1000000' that is almost the expected 3.0e-06 times. From dchelimsky at gmail.com Wed Nov 24 16:52:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 24 Nov 2010 15:52:58 -0600 Subject: [rspec-users] Puzzled about the rspec tests generated by Rails3 In-Reply-To: References: Message-ID: <4CE33B51-21F6-4A6D-B753-841A602AEC05@gmail.com> On Nov 24, 2010, at 3:39 PM, Robert Dober wrote: > Hi all > > I am puzzled about the rspec tests that are generated by Rails3 > scaffolding. I am however not sure if this is the correct place to > discuss this issue. > It might be that a rails ML/chat is better suited for that kind of > discussion. It just depends on who is responsible for that code. > Somehow I am too stupid to find that out, so please bare with me if I > produced only noise here. When you run the scaffold generator, rspec-rails is responsible to generate the specs. So this is the right place. Cheers, David > Cheers > Robert From nick at deadorange.com Wed Nov 24 22:51:43 2010 From: nick at deadorange.com (Nick) Date: Wed, 24 Nov 2010 19:51:43 -0800 (PST) Subject: [rspec-users] Specs for controllers and rescue_from In-Reply-To: <8EF89EDE-AED8-4839-9AE6-D07EFA0CC311@gmail.com> References: <8EF89EDE-AED8-4839-9AE6-D07EFA0CC311@gmail.com> Message-ID: <7e145727-c648-466d-a4b4-60c36854dd07@k13g2000vbq.googlegroups.com> On Nov 21, 5:02?pm, David Chelimsky wrote: > http://relishapp.com/rspec/rspec-rails/v/2-1/dir/controller-specs/ano... Fantastic. Thanks, David! From somaraju at gmail.com Wed Nov 24 23:26:52 2010 From: somaraju at gmail.com (Raghu Somaraju) Date: Wed, 24 Nov 2010 20:26:52 -0800 (PST) Subject: [rspec-users] How to mock a logged in user In-Reply-To: References: <4CEA60E3.6000804@gmail.com> <30283795.post@talk.nabble.com> Message-ID: <30300615.post@talk.nabble.com> Robert Dober wrote: > > On Tue, Nov 23, 2010 at 1:04 PM, Raghu Somaraju > wrote: >> >> Thank you Robert. That works. I should have used the "current_user" >> instead >> of @_current_user in the first place. >> >> But, if I do want to use @_current_user, how do I pass on that instance >> variable to the controller from spec? > > Short answer: Do not do it: Mocking is here to simulate behavior and > ivars are here to implement state. (caching state in our case) > > Long answer: Although I believe that the above said is often true > there must be exceptions, I adapted a relish test to show you how it > works: > https://gist.github.com/711904 > > Cheers > Robert > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Thank you once again Robert, for answering my question. I understand the reasoning. I realized it when you gave the solution to my original problem of this thread. But, out of curiosity wanted to know if it was possible. raghu -- View this message in context: http://old.nabble.com/How-to-mock-a-logged-in-user-tp30278143p30300615.html Sent from the rspec-users mailing list archive at Nabble.com. From pub at kaorukobo.net Thu Nov 25 00:09:00 2010 From: pub at kaorukobo.net (=?ISO-2022-JP?B?GyRCR3IwZiEhNzAbKEI=?=) Date: Thu, 25 Nov 2010 14:09:00 +0900 Subject: [rspec-users] Question: Define custom matcher like raise_error, by Matchers.define Message-ID: <54C8E659-5959-4FE9-8BF2-24C52FD9D10B@kaorukobo.net> I have a question about the custom matcher using Matcher#define. My intention is given by the following code: ======================================================================== Spec::Matchers.define :be_done do match do |block| block.call true end failure_message_for_should do "be_done failed." end end describe "The expectation failure in block called from the custom matcher" do example "should be reported." do lambda { lambda { 1.should == 2 }.should be_done }.should_not raise_error(/be_done failed/) # should 'expected: 2, got: 1 (using ==)' end end ======================================================================== I want to define the custom matcher that it calls the block given as the actual value, like raise_error. But if the expectation in the given block failed, it is not reported, but it reports the custom matcher's failure. Is there some misuse about Matchers.define in my code? Best Regards. -- Kaoru Kobo From lists at ruby-forum.com Thu Nov 25 01:10:50 2010 From: lists at ruby-forum.com (Arun Sharma) Date: Thu, 25 Nov 2010 07:10:50 +0100 Subject: [rspec-users] Spec::Mocks::MockExpectationError In-Reply-To: <136909e8f90826c12da48225879f09d1@ruby-forum.com> References: <136909e8f90826c12da48225879f09d1@ruby-forum.com> Message-ID: <88ac3dbb146a5bcd92327740ebd71e4a@ruby-forum.com> thanks for reply my other methods in spec file it is working properly(index,edit,update...) but here it creates a probelm.bascially except CRUD opertion it is not working. get :automatic_partitions,{:harddrive_id=>'sda',:server_id=>1938} assigns[:prev_values].should=='' i simply want to ask that is this right way to call a action and pass the value?? please post the reply as soon as.I am waiting for reply -- Posted via http://www.ruby-forum.com/. From robert.dober at gmail.com Thu Nov 25 03:57:40 2010 From: robert.dober at gmail.com (Robert Dober) Date: Thu, 25 Nov 2010 09:57:40 +0100 Subject: [rspec-users] Puzzled about the rspec tests generated by Rails3 In-Reply-To: <4CE33B51-21F6-4A6D-B753-841A602AEC05@gmail.com> References: <4CE33B51-21F6-4A6D-B753-841A602AEC05@gmail.com> Message-ID: On Wed, Nov 24, 2010 at 10:52 PM, David Chelimsky wrote: > On Nov 24, 2010, at 3:39 PM, Robert Dober wrote: > >> Hi all >> >> I am puzzled about the rspec tests that are generated by Rails3 >> scaffolding. I am however not sure if this is the correct place to >> discuss this issue. >> It might be that a rails ML/chat is better suited for that kind of >> discussion. It just depends on who is responsible for that code. >> Somehow I am too stupid to find that out, so please bare with me if I >> produced only noise here. > > When you run the scaffold generator, rspec-rails is responsible to generate the specs. So this is the right place. It is terrible how biased one can be, by learning it comes from you I looked at the code with new confidence and pretty much seem to understand it now. Sorry for the noise and thank you Cheers Robert > > Cheers, > David > >> Cheers >> Robert > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- The 1,000,000th fibonacci number contains '42' 2039 times; that is almost 30 occurrences more than expected (208988 digits). N.B. The 42nd fibonacci number does not contain '1000000' that is almost the expected 3.0e-06 times. From dchelimsky at gmail.com Thu Nov 25 07:04:27 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Nov 2010 06:04:27 -0600 Subject: [rspec-users] Question: Define custom matcher like raise_error, by Matchers.define In-Reply-To: <54C8E659-5959-4FE9-8BF2-24C52FD9D10B@kaorukobo.net> References: <54C8E659-5959-4FE9-8BF2-24C52FD9D10B@kaorukobo.net> Message-ID: <67A5656C-63DA-42CB-9847-17E1A5A956DE@gmail.com> On Nov 24, 2010, at 11:09 PM, ???? wrote: > I have a question about the custom matcher using Matcher#define. > > My intention is given by the following code: > > ======================================================================== > Spec::Matchers.define :be_done do > match do |block| > block.call > true > end This should work: match do |block| begin block.call true rescue false end end Or, if you prefer one liners: match do |block| (block.call; true) rescue false end HTH, David > > failure_message_for_should do > "be_done failed." > end > end > > describe "The expectation failure in block called from the custom matcher" do > example "should be reported." do > lambda { > lambda { > 1.should == 2 > }.should be_done > }.should_not raise_error(/be_done failed/) # should 'expected: 2, got: 1 (using ==)' > end > end > ======================================================================== > > I want to define the custom matcher that it calls the block given as the actual value, like raise_error. > But if the expectation in the given block failed, > it is not reported, but it reports the custom matcher's failure. > > Is there some misuse about Matchers.define in my code? > > Best Regards. > -- > Kaoru Kobo > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Nov 25 07:12:02 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Nov 2010 06:12:02 -0600 Subject: [rspec-users] Spec::Mocks::MockExpectationError In-Reply-To: <88ac3dbb146a5bcd92327740ebd71e4a@ruby-forum.com> References: <136909e8f90826c12da48225879f09d1@ruby-forum.com> <88ac3dbb146a5bcd92327740ebd71e4a@ruby-forum.com> Message-ID: On Thu, Nov 25, 2010 at 12:10 AM, Arun Sharma wrote: > thanks for reply > > my other methods in spec file it is working > properly(index,edit,update...) > > but here it creates a probelm.bascially except CRUD opertion it is not > working. > > ?get :automatic_partitions,{:harddrive_id=>'sda',:server_id=>1938} > ? ? ? ? assigns[:prev_values].should=='' > > i simply want to ask that is this right way to call a action and pass > the value?? > > please post the reply as soon as.I am waiting for reply That seems like it should work, and the very first statement of the controller action meets the expectation that is failing: # spec Cpanel.should_receive(:find).and_return(@prev_values) # controller @prev_values = Cpanel.find(:all, :conditions => [ "harddrive_id = ? and server_id = ?", HARDDRIVE_SLOTS[params[:harddrive_id].to_i], params[:server_id] ]) I see the filters are stubbed in the before block. Try changing those stubs to return true: controller.stub(:have_hard_drive?) { true } controller.stub(:is_cpanel_belongs_to_current_server?) { true } controller.stub(:authorized_user_to_server?) { true } HTH, David From jack.kinsella at gmail.com Wed Nov 17 13:49:32 2010 From: jack.kinsella at gmail.com (Jack Kinsella) Date: Wed, 17 Nov 2010 10:49:32 -0800 (PST) Subject: [rspec-users] How To Mock A Chain (specifically ActionMailerModel.method.deliver) Message-ID: <86e1ee0e-0b53-40c3-aa5a-c543a5ddff35@r29g2000yqj.googlegroups.com> Hi, In Rails 3 you deliver a mail message with the ActionMailerModel.method.deliver syntax (e.g. Notifier.welcome_message.deliver). How do you test that this method is called in Rspec. I'm looking for an equivalent to "stub_chain" which has expectations. I'm testing that messages are sent on certain events in the object life cycle (e.g. that an email is sent when an Award is created). I know it's possible to abstract welcome_message.deliver into a single method call, but this seems overly inconvenient for such a simple case. Anyone any ideas on how to solve this problem? Kind Regards, Jack Kinsella From me at installero.com Thu Nov 18 12:52:57 2010 From: me at installero.com (Vadim A. Venediktov) Date: Thu, 18 Nov 2010 20:52:57 +0300 Subject: [rspec-users] Rspec: rendering a certain template with a certain layout is needed Message-ID: Hello! I was trying render my view with a custom layout: render :template => "cards/show.html.erb", :layout => 'application' And caught an error: Failure/Error: render :text => 'Text', :layout => 'application' Missing template /application with {:handlers=>[:rhtml, :rxml, :erb, :rjs, :builder], :locale=>[:ru, :ru], :formats=>[:html]} in view paths "/home/install/webdev/pkl/app/views", "/home/install/webdev/pkl/.bundle/ruby/1.8/gems/devise-1.1.3/app/views" After searching for a while I ran against this thread: http://forums.pragprog.com/forums/95/topics/3952 I wonder what should I do if I have controller/action specific translations in my layout, like this: <% @title = t("#{controller.controller_name}.#{controller.action_name}.title") if @title.blank? %> BTW, do you find it reasonable? I'm using this variable two times in my layout, and I want to check whether my page is translated properly, so I write a macros with a spec: it "should be translated" do render rendered.should_not have_selector('span', :class => 'translation_missing') end but it does not render layout, so everything is fine even if I don't have my title: 'Title' set in i18n yml files. I have a spec to test my layout, but is knows nothing about controller, so it can't test @title's translated properly niether. I know, that I can do something like <%= yield :title %> in my layout and test content for title in every view spec, but this causes me to set :content_for 'title' in every view template, which does not sound great. What could you advise for this tricky situation? From spocksplanet at gmail.com Sat Nov 20 20:07:56 2010 From: spocksplanet at gmail.com (Volkan Unsal) Date: Sat, 20 Nov 2010 17:07:56 -0800 (PST) Subject: [rspec-users] How do I generate specs for existing controllers? Message-ID: <1b58db94-c584-4a6e-b567-9ad8fc19dd21@v20g2000yqb.googlegroups.com> I want to generate boilerplate code for existing controller, models and views. Is there a command or a gem that lets me do that? From justin.maccarthy at gmail.com Tue Nov 23 01:26:13 2010 From: justin.maccarthy at gmail.com (macarthy) Date: Mon, 22 Nov 2010 22:26:13 -0800 (PST) Subject: [rspec-users] Lastest versions for 2.3.10? Message-ID: <26242d9b-606b-49a4-9000-87268cfb3920@a30g2000vbt.googlegroups.com> Can someone tell me what the latest versions for rspec / cucumber for a rails 2.3.10 project? Currently I get this error $: script/generate rspec Couldn't find 'rspec' generator My enviroment.rb : config.gem 'rspec-rails', :lib => false, :version => '1.3.3' config.gem 'cucumber-rails', :lib => false, :version => '0.3.2' config.gem 'database_cleaner', :lib => false, :version => '0.5.0' config.gem 'webrat', :lib => false, :version => '0.7.1' Rake gems /projects/understanding/valtest > rake gems (in /Users/macarthy/projects/understanding/valtest) - [I] rspec-rails = 1.3.3 - [I] rspec = 1.3.1 - [R] rack >= 1.0.0 - [I] cucumber-rails = 0.3.2 - [I] cucumber >= 0.8.0 - [I] gherkin ~> 2.2.9 - [R] json ~> 1.4.6 - [I] term-ansicolor ~> 1.0.5 - [I] term-ansicolor ~> 1.0.5 - [R] builder ~> 2.1.2 - [I] diff-lcs ~> 1.1.2 - [R] json ~> 1.4.6 - [I] database_cleaner = 0.5.0 - [I] webrat = 0.7.1 - [I] nokogiri >= 1.2.0 - [R] rack >= 1.0 - [I] rack-test >= 0.5.3 - [R] rack >= 1.0 I = Installed F = Frozen R = Framework (loaded before rails starts) From jrbruce at gmail.com Tue Nov 23 21:12:12 2010 From: jrbruce at gmail.com (jrbruce) Date: Tue, 23 Nov 2010 18:12:12 -0800 (PST) Subject: [rspec-users] rspec2, rails 3, subdomain constraints Message-ID: I'm trying to constrain access to admin routes in my application to either www or canonical. I need the custom constraint in root_domain.rb (RootDomain) to handle the canonical part. Since the subdomains will represent accounts, I don't want /admin available on any of the subdomains. Here is a gist showing exactly how my code and tests are setup: https://gist.github.com/712968 In the first test, I expect /admin not to be routable on a generic subdomain (this test currently doesn't pass). However, when I check in a browser, I receive a not routable error. If I remove the custom constraint and use, for example, the :subdomain => "www" constraint, the test does pass. I've tested both the custom constraint and the subdomain constraint in my browser and both restrict access as expected. Is this an issue with rspec and how it handles constraints or am I doing something wrong? From rsalsa at gmail.com Wed Nov 24 00:32:03 2010 From: rsalsa at gmail.com (Rick) Date: Tue, 23 Nov 2010 21:32:03 -0800 (PST) Subject: [rspec-users] be_valid method undefined on model spec Message-ID: <44f575cc-e068-4077-b0e5-72dca9b43099@p7g2000prb.googlegroups.com> Hi all, I'm using rspec-rails and have a simple model spec which fails with the following trace: undefined local variable or method `be_valid' for # (NameError) Full trace: https://gist.github.com/713164 The spec is simple: require 'spec_helper' describe Deal do describe "it should not allow start dates in the past" do Deal.new.should be_valid end end That above fails. I'm running rspec 2.1.0. Any ideas what could be wrong? I'm searched the list and unfortunately haven't found anything similar. Is it that rspec-rails isn't being loaded correctly? All my controller specs work just fine. Thanks! From dchelimsky at gmail.com Thu Nov 25 07:19:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Nov 2010 06:19:10 -0600 Subject: [rspec-users] be_valid method undefined on model spec In-Reply-To: <44f575cc-e068-4077-b0e5-72dca9b43099@p7g2000prb.googlegroups.com> References: <44f575cc-e068-4077-b0e5-72dca9b43099@p7g2000prb.googlegroups.com> Message-ID: On Tue, Nov 23, 2010 at 11:32 PM, Rick wrote: > Hi all, > > I'm using rspec-rails and have a simple model spec which fails with > the following trace: > > undefined local variable or method `be_valid' for # 0x00000102c6e820> (NameError) > > Full trace: https://gist.github.com/713164 > > The spec is simple: > > require 'spec_helper' > > describe Deal do > > ?describe "it should not allow start dates in the past" do This ^^ creates an example group, but the next line should be in an example. Change the line ^^ above to: it "should not allow start dates in the past" do That will create an example (as opposed to a group). HTH, David > ? ?Deal.new.should be_valid > ?end > > end > > > That above fails. I'm running rspec 2.1.0. Any ideas what could be > wrong? I'm searched the list and unfortunately haven't found anything > similar. Is it that rspec-rails isn't being loaded correctly? All my > controller specs work just fine. > > Thanks! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Nov 25 07:22:21 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Nov 2010 06:22:21 -0600 Subject: [rspec-users] How To Mock A Chain (specifically ActionMailerModel.method.deliver) In-Reply-To: <86e1ee0e-0b53-40c3-aa5a-c543a5ddff35@r29g2000yqj.googlegroups.com> References: <86e1ee0e-0b53-40c3-aa5a-c543a5ddff35@r29g2000yqj.googlegroups.com> Message-ID: On Wed, Nov 17, 2010 at 12:49 PM, Jack Kinsella wrote: > Hi, > > In Rails 3 you deliver a mail message with the > ActionMailerModel.method.deliver syntax (e.g. > Notifier.welcome_message.deliver). How do you test that this method is > called in Rspec. I'm looking for an equivalent to "stub_chain" which > has expectations. I'm testing that messages are sent on certain events > in the object life cycle (e.g. that an email is sent when an Award is > created). > > I know it's possible to abstract welcome_message.deliver into a single > method call, but this seems overly inconvenient for such a simple > case. > > Anyone any ideas on how to solve this problem? See this thread: http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2390b0# Cheers, David > > Kind Regards, > > Jack Kinsella From dolzenko at gmail.com Thu Nov 25 08:03:09 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Thu, 25 Nov 2010 16:03:09 +0300 Subject: [rspec-users] rspec2, rails 3, subdomain constraints In-Reply-To: References: Message-ID: https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_recognizes-does-not-support-constraints anyone? On Wed, Nov 24, 2010 at 5:12 AM, jrbruce wrote: > I'm trying to constrain access to admin routes in my application to > either www or canonical. I need the custom constraint in > root_domain.rb (RootDomain) to handle the canonical part. Since the > subdomains will represent accounts, I don't want /admin available on > any of the subdomains. > > Here is a gist showing exactly how my code and tests are setup: > > https://gist.github.com/712968 > > In the first test, I expect /admin not to be routable on a generic > subdomain (this test currently doesn't pass). However, when I check in > a browser, I receive a not routable error. > > If I remove the custom constraint and use, for example, the :subdomain > => "www" constraint, the test does pass. I've tested both the custom > constraint and the subdomain constraint in my browser and both > restrict access as expected. > > Is this an issue with rspec and how it handles constraints or am I > doing something wrong? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dolzenko at gmail.com Thu Nov 25 08:06:23 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Thu, 25 Nov 2010 16:06:23 +0300 Subject: [rspec-users] How do I generate specs for existing controllers? In-Reply-To: <1b58db94-c584-4a6e-b567-9ad8fc19dd21@v20g2000yqb.googlegroups.com> References: <1b58db94-c584-4a6e-b567-9ad8fc19dd21@v20g2000yqb.googlegroups.com> Message-ID: Unfortunately no that I know of, though it shouldn't be very hard to write a script for that which will rely on running corresponding generators with `-s, [--skip]` options which makes the generator skip already existing files. On Sun, Nov 21, 2010 at 4:07 AM, Volkan Unsal wrote: > I want to generate boilerplate code for existing controller, models > and views. Is there a command or a gem that lets me do that? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dolzenko at gmail.com Thu Nov 25 08:24:03 2010 From: dolzenko at gmail.com (Evgeniy Dolzhenko) Date: Thu, 25 Nov 2010 16:24:03 +0300 Subject: [rspec-users] Rspec: rendering a certain template with a certain layout is needed In-Reply-To: References: Message-ID: Speaking of `controller.controller_name`: inside of the view spec controller is an instance of TestController and `controller.controller_name` and `controller.action_name` won't return you anything useful. Though RSpec tries to help us here a little bit by inferring `controller.controller_path` and `request.path_parameters` [1]. That's what I ended up using instead of `action_name` in my views. [1] https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/view_example_group.rb#L151 On Thu, Nov 18, 2010 at 8:52 PM, Vadim A. Venediktov wrote: > Hello! > > I was trying render my view with a custom layout: > > render :template => "cards/show.html.erb", :layout => 'application' > > And caught an error: > > ?Failure/Error: render :text => 'Text', :layout => 'application' > ?Missing template /application with {:handlers=>[:rhtml, :rxml, :erb, > :rjs, :builder], :locale=>[:ru, :ru], :formats=>[:html]} in view paths > "/home/install/webdev/pkl/app/views", > "/home/install/webdev/pkl/.bundle/ruby/1.8/gems/devise-1.1.3/app/views" > > After searching for a while I ran against this thread: > http://forums.pragprog.com/forums/95/topics/3952 > > I wonder what should I do if I have controller/action specific > translations in my layout, like this: > > <% @title = t("#{controller.controller_name}.#{controller.action_name}.title") > if @title.blank? %> > > BTW, do you find it reasonable? I'm using this variable two times in > my layout, and I want to check whether my page is translated properly, > so I write a macros with a spec: > > it "should be translated" do > ?render > ?rendered.should_not have_selector('span', :class => 'translation_missing') > end > > but it does not render layout, so everything is fine even if I don't > have my title: 'Title' set in i18n yml files. > > I have a spec to test my layout, but is knows nothing about > controller, so it can't test @title's translated properly niether. > > I know, that I can do something like <%= yield :title %> in my layout > and test content for title in every view spec, but this causes me to > set :content_for 'title' in every view template, which does not sound > great. What could you advise for this tricky situation? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Nov 25 09:20:24 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Nov 2010 08:20:24 -0600 Subject: [rspec-users] How do I generate specs for existing controllers? In-Reply-To: <1b58db94-c584-4a6e-b567-9ad8fc19dd21@v20g2000yqb.googlegroups.com> References: <1b58db94-c584-4a6e-b567-9ad8fc19dd21@v20g2000yqb.googlegroups.com> Message-ID: <73D6642D-B8B5-499C-8797-0377321F7FBB@gmail.com> On Nov 20, 2010, at 7:07 PM, Volkan Unsal wrote: > I want to generate boilerplate code for existing controller, models > and views. Is there a command or a gem that lets me do that? You can't see them because rails hides them, but: rails generate rspec:model rails generate rspec:view rails generate rspec:controller Each of these generates only the spec. HTH, David From jonathan at parkerhill.com Thu Nov 25 09:33:51 2010 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 25 Nov 2010 09:33:51 -0500 Subject: [rspec-users] How do I generate specs for existing controllers? In-Reply-To: <73D6642D-B8B5-499C-8797-0377321F7FBB@gmail.com> References: <1b58db94-c584-4a6e-b567-9ad8fc19dd21@v20g2000yqb.googlegroups.com> <73D6642D-B8B5-499C-8797-0377321F7FBB@gmail.com> Message-ID: rails hides them? why? On Nov 25, 2010, at 9:20 AM, David Chelimsky wrote: > On Nov 20, 2010, at 7:07 PM, Volkan Unsal wrote: > >> I want to generate boilerplate code for existing controller, models >> and views. Is there a command or a gem that lets me do that? > > You can't see them because rails hides them, but: > > rails generate rspec:model > rails generate rspec:view > rails generate rspec:controller > > Each of these generates only the spec. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From kai.schlamp at googlemail.com Thu Nov 25 10:44:58 2010 From: kai.schlamp at googlemail.com (medihack) Date: Thu, 25 Nov 2010 07:44:58 -0800 (PST) Subject: [rspec-users] stub_chain together with should_receive Message-ID: <36c56d0d-8697-46ab-b85f-670fc54d635d@g25g2000yqn.googlegroups.com> Hello. I am trying to test if in a method calling chain one of the methods get a specific parameter. In the below code for example MyModel must receive the parameter 0 for the method `offset`. Unfortunately the code below does not work. It seems it is not possible to mix should_receive and stub_chain. How could I solve this? I am using RSpec 2. does not work: MyModel.should_receive(:offset).with(0).stub_chain(:tag_counts, :offset, :limit, :order).and_return([]) also does succeed (expectation is never called): MyModel.stub_chain(:tag_counts, :offset, :limit, :where, :order).and_return([]) MyModel.should_receive(:offset).with(0) { MyModel } does succeed, but is IMHO quite unhandy (you can't stub_chain in a before filter): MyModel.stub(:tag_counts) { MyModel } MyModel.should_receive(:offset).with(0) { MyModel } MyModel.stub_chain(:limit, :where, :order).and_return([]) From dchelimsky at gmail.com Thu Nov 25 12:17:34 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Nov 2010 11:17:34 -0600 Subject: [rspec-users] How do I generate specs for existing controllers? In-Reply-To: References: <1b58db94-c584-4a6e-b567-9ad8fc19dd21@v20g2000yqb.googlegroups.com> <73D6642D-B8B5-499C-8797-0377321F7FBB@gmail.com> Message-ID: On Nov 25, 2010, at 8:33 AM, Jonathan Linowes wrote: > On Nov 25, 2010, at 9:20 AM, David Chelimsky wrote: > >> On Nov 20, 2010, at 7:07 PM, Volkan Unsal wrote: >> >>> I want to generate boilerplate code for existing controller, models >>> and views. Is there a command or a gem that lets me do that? >> >> You can't see them because rails hides them, but: > rails hides them? > > why? Rails 3 agnosticism. Intent is that when you register rspec as "the test framework" that the Rails generators ("rails generate model", etc) seamlessly delegate the test-generation to rspec. It's not really designed with generating tests after the fact in mind. >> rails generate rspec:model >> rails generate rspec:view >> rails generate rspec:controller >> >> Each of these generates only the spec. >> >> HTH, >> David >> _______________________________________________ >> 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 lists at ruby-forum.com Thu Nov 25 12:44:56 2010 From: lists at ruby-forum.com (James Palmer) Date: Thu, 25 Nov 2010 18:44:56 +0100 Subject: [rspec-users] no such file to load - spec/test/unit Message-ID: Under the older version of rspec, I'm able to run my script successfully by running "spec randomperform.rb" I've now installed the newest rspec, and it does not work for me. If I run the command: rspec randomperform.rb I get the following error: ----- :29:in `require': no such file to load -- spec/test/unit (LoadError) from :29:in `require' from C:/watir-tests/craftfree/randomperform.rb:3:in `' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core /configuration.rb:334:in `load' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core /configuration.rb:334:in `block in load_spec_files' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core /configuration.rb:334:in `map' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core /configuration.rb:334:in `load_spec_files' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core /command_line.rb:18:in `run' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core /runner.rb:55:in `run_in_process' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core /runner.rb:46:in `run' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core /runner.rb:10:in `block in autorun' -------- Anyone know what is wrong? What am I missing? Sorry if this is a "newb" question, as I'm still fairly new at Ruby and its various gems. Thanks, James -- Posted via http://www.ruby-forum.com/. From pedrobrasileiro at gmail.com Thu Nov 25 13:31:37 2010 From: pedrobrasileiro at gmail.com (Pedro Brasileiro) Date: Thu, 25 Nov 2010 15:31:37 -0300 Subject: [rspec-users] be_valid method undefined on model spec In-Reply-To: References: <44f575cc-e068-4077-b0e5-72dca9b43099@p7g2000prb.googlegroups.com> Message-ID: Try Deal.new.should be_valid? On Thu, Nov 25, 2010 at 9:19 AM, David Chelimsky wrote: > On Tue, Nov 23, 2010 at 11:32 PM, Rick wrote: > > Hi all, > > > > I'm using rspec-rails and have a simple model spec which fails with > > the following trace: > > > > undefined local variable or method `be_valid' for # > 0x00000102c6e820> (NameError) > > > > Full trace: https://gist.github.com/713164 > > > > The spec is simple: > > > > require 'spec_helper' > > > > describe Deal do > > > > describe "it should not allow start dates in the past" do > > This ^^ creates an example group, but the next line should be in an > example. Change the line ^^ above to: > > it "should not allow start dates in the past" do > > That will create an example (as opposed to a group). > > HTH, > David > > > Deal.new.should be_valid > > end > > > > end > > > > > > That above fails. I'm running rspec 2.1.0. Any ideas what could be > > wrong? I'm searched the list and unfortunately haven't found anything > > similar. Is it that rspec-rails isn't being loaded correctly? All my > > controller specs work just fine. > > > > Thanks! > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Pedro Brasileiro Cardoso Junior http://www.pedrobrasileiro.com.br www.twitter.com/pedrobrasileiro -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Nov 25 14:23:20 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Nov 2010 13:23:20 -0600 Subject: [rspec-users] be_valid method undefined on model spec In-Reply-To: References: <44f575cc-e068-4077-b0e5-72dca9b43099@p7g2000prb.googlegroups.com> Message-ID: On Nov 25, 2010, at 12:31 PM, Pedro Brasileiro wrote: > Try Deal.new.should be_valid? No, don't. That doesn't work, and what I wrote below does :) Cheers, David > > On Thu, Nov 25, 2010 at 9:19 AM, David Chelimsky wrote: > On Tue, Nov 23, 2010 at 11:32 PM, Rick wrote: > > Hi all, > > > > I'm using rspec-rails and have a simple model spec which fails with > > the following trace: > > > > undefined local variable or method `be_valid' for # > 0x00000102c6e820> (NameError) > > > > Full trace: https://gist.github.com/713164 > > > > The spec is simple: > > > > require 'spec_helper' > > > > describe Deal do > > > > describe "it should not allow start dates in the past" do > > This ^^ creates an example group, but the next line should be in an > example. Change the line ^^ above to: > > it "should not allow start dates in the past" do > > That will create an example (as opposed to a group). > > HTH, > David > > > Deal.new.should be_valid > > end > > > > end > > > > > > That above fails. I'm running rspec 2.1.0. Any ideas what could be > > wrong? I'm searched the list and unfortunately haven't found anything > > similar. Is it that rspec-rails isn't being loaded correctly? All my > > controller specs work just fine. > > > > Thanks! > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Pedro Brasileiro Cardoso Junior > http://www.pedrobrasileiro.com.br > www.twitter.com/pedrobrasileiro > > _______________________________________________ > 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 Thu Nov 25 14:30:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Nov 2010 13:30:43 -0600 Subject: [rspec-users] Lastest versions for 2.3.10? In-Reply-To: <26242d9b-606b-49a4-9000-87268cfb3920@a30g2000vbt.googlegroups.com> References: <26242d9b-606b-49a4-9000-87268cfb3920@a30g2000vbt.googlegroups.com> Message-ID: <5B492B15-B23B-47F1-8206-893F5DDF8417@gmail.com> On Nov 23, 2010, at 12:26 AM, macarthy wrote: > Can someone tell me what the latest versions for rspec / cucumber for > a rails 2.3.10 project? > > Currently I get this error > > $: script/generate rspec > Couldn't find 'rspec' generator > > My enviroment.rb : > > config.gem 'rspec-rails', :lib => false, :version => > '1.3.3' Not sure about cucumber, but 1.3.3 is the right version for rspec-rails. As for the generators, I'll look into it, but I don't know that there's anything rspec can actually do to fix this problem, which happens when rspec-rails-2.x and rspec-rails-1.x are installed in the same environment. If you uninstall rspec-rails-2 you should see the generators. What I'm doing is keeping the environments for each of my apps separate using bundler or RVM. HTH, David > config.gem 'cucumber-rails', :lib => false, :version => '0.3.2' > config.gem 'database_cleaner', :lib => false, :version => '0.5.0' > config.gem 'webrat', :lib => false, :version => '0.7.1' > > Rake gems > > /projects/understanding/valtest > rake gems > (in /Users/macarthy/projects/understanding/valtest) > - [I] rspec-rails = 1.3.3 > - [I] rspec = 1.3.1 > - [R] rack >= 1.0.0 > - [I] cucumber-rails = 0.3.2 > - [I] cucumber >= 0.8.0 > - [I] gherkin ~> 2.2.9 > - [R] json ~> 1.4.6 > - [I] term-ansicolor ~> 1.0.5 > - [I] term-ansicolor ~> 1.0.5 > - [R] builder ~> 2.1.2 > - [I] diff-lcs ~> 1.1.2 > - [R] json ~> 1.4.6 > - [I] database_cleaner = 0.5.0 > - [I] webrat = 0.7.1 > - [I] nokogiri >= 1.2.0 > - [R] rack >= 1.0 > - [I] rack-test >= 0.5.3 > - [R] rack >= 1.0 > > I = Installed > F = Frozen > R = Framework (loaded before rails starts) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pub at kaorukobo.net Thu Nov 25 19:30:22 2010 From: pub at kaorukobo.net (Kaoru Kobo) Date: Fri, 26 Nov 2010 09:30:22 +0900 Subject: [rspec-users] Question: Define custom matcher like raise_error, by Matchers.define In-Reply-To: <67A5656C-63DA-42CB-9847-17E1A5A956DE@gmail.com> References: <54C8E659-5959-4FE9-8BF2-24C52FD9D10B@kaorukobo.net> <67A5656C-63DA-42CB-9847-17E1A5A956DE@gmail.com> Message-ID: <523CC9ED-C5CF-4A4F-8727-7395BBE234E9@kaorukobo.net> Thanks, David. > > This should work: > ... > match do |block| > (block.call; true) rescue false > end I tried that, but the spec still fails... 1) 'The expectation failure in block called from the custom matcher should be reported.' FAILED expected no Exception with message matching /be_done failed/, got # ./spec/custom_matcher_spec.rb:21: I expect that it fails with message 'expected: 2, got: 1 (using ==)'. Best Regards. -- Kaoru Kobo From pub at kaorukobo.net Thu Nov 25 20:16:33 2010 From: pub at kaorukobo.net (Kaoru Kobo) Date: Fri, 26 Nov 2010 10:16:33 +0900 Subject: [rspec-users] Question: Define custom matcher like raise_error, by Matchers.define In-Reply-To: <523CC9ED-C5CF-4A4F-8727-7395BBE234E9@kaorukobo.net> References: <54C8E659-5959-4FE9-8BF2-24C52FD9D10B@kaorukobo.net> <67A5656C-63DA-42CB-9847-17E1A5A956DE@gmail.com> <523CC9ED-C5CF-4A4F-8727-7395BBE234E9@kaorukobo.net> Message-ID: Then I found this page: ?Upgrade to 1.3.0 - Matcher DSL" Upgrade.rdoc at master from dchelimsky's rspec - GitHub http://github.com/dchelimsky/rspec/blob/master/Upgrade.rdoc and, I found the tentative solution: (Is there the better way?) ======================================================================== Spec::Matchers.define :be_done do - match do |block| + # Do not turn any exceptions to false. + match_unless_raises(Class.new(Exception)) do |block| block.call true end ======================================================================== Best Regards. -- Kaoru Kobo From kai.schlamp at googlemail.com Fri Nov 26 03:24:11 2010 From: kai.schlamp at googlemail.com (medihack) Date: Fri, 26 Nov 2010 00:24:11 -0800 (PST) Subject: [rspec-users] stub_chain together with should_receive In-Reply-To: <36c56d0d-8697-46ab-b85f-670fc54d635d@g25g2000yqn.googlegroups.com> References: <36c56d0d-8697-46ab-b85f-670fc54d635d@g25g2000yqn.googlegroups.com> Message-ID: David, sorry for double posting (it seems I am working too much and forgetting about what I already asked) ... and thanks for your answer. How about a bit more convenient way for future releases. Something like: MyModel.stub_chain(:tag_counts, { :offset => 0 }, :limit, :order).and_return([]) it could also work for multi parameters: MyModel.stub_chain(:tag_counts, { :my_method => [:param1, :param2, param3] }, :limit, :order).and_return([]) What do you think? From dchelimsky at gmail.com Fri Nov 26 06:26:03 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 26 Nov 2010 05:26:03 -0600 Subject: [rspec-users] stub_chain together with should_receive In-Reply-To: References: <36c56d0d-8697-46ab-b85f-670fc54d635d@g25g2000yqn.googlegroups.com> Message-ID: <674627F8-9517-4AE9-BE35-FED0A4DD4445@gmail.com> On Nov 26, 2010, at 2:24 AM, medihack wrote: > David, sorry for double posting (it seems I am working too much and > forgetting about what I already asked) ... and thanks for your answer. > How about a bit more convenient way for future releases. Something > like: > MyModel.stub_chain(:tag_counts, { :offset => > 0 }, :limit, :order).and_return([]) > it could also work for multi parameters: > MyModel.stub_chain(:tag_counts, { :my_method => [:param1, :param2, > param3] }, :limit, :order).and_return([]) > What do you think? I would be opposed to this feature. There is an old guideline in TDD that suggests that you should listen to your tests because when they hurt there is usually a design problem. Tests are clients of the code under test, and if the test hurts, then so do all of the other clients in the codebase. Shortcuts like this quickly become an excuse for poor designs. I want it to stay painful because it _should hurt_ to do this. I understand that chains like this are common in Rails apps thanks to good ideas like composable finders (which generally do not violate Demeter), but I don't think the parallel chains should appear in client code or in specs. e.g. if this is a controller spec, the model should expose a single method that wraps this, and if it's the model spec, the spec should just call the method that wraps the chain with different inputs and and specify the expected outcomes. Even if I were in favor of the concept, the example above is confusing because it is a stub that becomes a message expectation. Constrained stubs like this (e.g. double.stub(:method).with(:arg).and_return(value)) are confusing enough as it is because they don't look like message expectations, but they act sort of like them. I've considered deprecating "with" on stubs and pushing toward an inline fake implementation instead: account.stub(:withdraw) do |*args| if args.first == Money.new(200, :USD) # do something else # do something else end end RSpec already supports this, and it makes the intent of the spec much more clear and localized than: account.stub(:withdraw).with(Money.new(200, :USD)).and_return(TransactionResult.new) In this case, if account receives withdraw() with anything other than Money.new(200, :USD), the outcome needs to be defined elsewhere in the spec, and these things quickly become spread out and difficult to understand. That's my 2?, but feel free to try to convince me otherwise :) Cheers, David From jtanium at gmail.com Sat Nov 27 17:15:32 2010 From: jtanium at gmail.com (Jason Edwards) Date: Sat, 27 Nov 2010 15:15:32 -0700 Subject: [rspec-users] [Sinatra] "tried to create Proc object without a block" In-Reply-To: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> References: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> Message-ID: I figured that problem out... Another gem needed to be installed: rack-test Jason On Sat, Nov 27, 2010 at 11:11 AM, jtanium wrote: > Hello all, > > I'm a long time Ruby and Rails user, but new to RSpec; I've been using > Shoulda instead. > > I picked up the book "Service-Oriented Design with Ruby and > Rails" (http://amzn.to/9sgx99) which uses RSpec throughout. Despite > being published only a few months ago, it's already out of date. > > Here's the gist with the relevant files: https://gist.github.com/718122 > (you can see where I commented out a few lines trying to get it to > work). > > I'm guessing the book was written using RSpec 1, and some older > (unknown) version of Rack. I've got Rack-1.2.1 and RSpec-2.1.0 > installed. > > This is what I get when I run "rspec spec": > > ?1) service should return a user by name > ? ? Failure/Error: get '/api/v1/users/jason' > ? ? tried to create Proc object without a block > ? ? # (__DELEGATE__):2:in `send' > ? ? # (__DELEGATE__):2:in `get' > ? ? # ./spec/service_spec.rb:23 > > I'm guessing the spec just needs a minor tweak or two to start > working, but I have no idea what that would be. > > Thanks for any help you can provide, > > Jason From lille.penguini at gmail.com Sat Nov 27 22:33:58 2010 From: lille.penguini at gmail.com (Lille) Date: Sat, 27 Nov 2010 19:33:58 -0800 (PST) Subject: [rspec-users] for web apps, when to use webrat, when to spec controllers? Message-ID: <09d2058a-3363-48bf-a0c2-29f0746b60e1@n10g2000yqd.googlegroups.com> Hi, I'm trying to better understand when to use the integration testing approach a la, say, Webrat, and when to rely on spec'ing my (Rails) controllers (MVC pattern). Let me give the current example that has brought me to indecision over which to use. Attributes of a child object depend on changes in the parent. When the child is thus changed, the web app user is to be informed with a message in the edit view for the child. There are several messages that can be displayed together or separately, depending on the circumstances. What's the deal here? Does the fact that this involves another model -- the parent -- mean this is an integration test? Lille From kai.schlamp at googlemail.com Sun Nov 28 03:06:20 2010 From: kai.schlamp at googlemail.com (medihack) Date: Sun, 28 Nov 2010 00:06:20 -0800 (PST) Subject: [rspec-users] stub_chain together with should_receive In-Reply-To: <674627F8-9517-4AE9-BE35-FED0A4DD4445@gmail.com> References: <36c56d0d-8697-46ab-b85f-670fc54d635d@g25g2000yqn.googlegroups.com> <674627F8-9517-4AE9-BE35-FED0A4DD4445@gmail.com> Message-ID: > That's my 2?, but feel free to try to convince me otherwise :) Ok, I'll give my best ... how about a dollar? ;-) > I understand that chains like this are common in Rails apps thanks to good ideas like composable finders (which generally do not violate Demeter), but I don't think the parallel chains should appear in client code or in specs. e.g. if this is a controller spec, the model should expose a single method that wraps this, and if it's the model spec, the spec should just call the method that wraps the chain with different inputs and and specify the expected outcomes. I dislike the idea to extract a single line of chained method calls into its own method, just because it is easier to test then. It is not used anywhere else and the method it is in is not very large either (those would be reasons to extract that code in its own method). By the way, it is part of the model. I would agree if it were part of the controller. > Even if I were in favor of the concept, the example above is confusing because it is a stub that becomes a message expectation. I absolutely agree. I also thought about that when I read my post for a second time. How about: MyModel.should_receive_chain(...) From jtanium at gmail.com Sat Nov 27 13:11:53 2010 From: jtanium at gmail.com (jtanium) Date: Sat, 27 Nov 2010 10:11:53 -0800 (PST) Subject: [rspec-users] [Sinatra] "tried to create Proc object without a block" Message-ID: <6b17ccd8-241c-4ea6-9010-a5f441894bec@r31g2000prg.googlegroups.com> Hello all, I'm a long time Ruby and Rails user, but new to RSpec; I've been using Shoulda instead. I picked up the book "Service-Oriented Design with Ruby and Rails" (http://amzn.to/9sgx99) which uses RSpec throughout. Despite being published only a few months ago, it's already out of date. Here's the gist with the relevant files: https://gist.github.com/718122 (you can see where I commented out a few lines trying to get it to work). I'm guessing the book was written using RSpec 1, and some older (unknown) version of Rack. I've got Rack-1.2.1 and RSpec-2.1.0 installed. This is what I get when I run "rspec spec": 1) service should return a user by name Failure/Error: get '/api/v1/users/jason' tried to create Proc object without a block # (__DELEGATE__):2:in `send' # (__DELEGATE__):2:in `get' # ./spec/service_spec.rb:23 I'm guessing the spec just needs a minor tweak or two to start working, but I have no idea what that would be. Thanks for any help you can provide, Jason From dchelimsky at gmail.com Sun Nov 28 15:01:08 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 28 Nov 2010 14:01:08 -0600 Subject: [rspec-users] stub_chain together with should_receive In-Reply-To: References: <36c56d0d-8697-46ab-b85f-670fc54d635d@g25g2000yqn.googlegroups.com> <674627F8-9517-4AE9-BE35-FED0A4DD4445@gmail.com> Message-ID: On Nov 28, 2010, at 2:06 AM, medihack wrote: >> That's my 2?, but feel free to try to convince me otherwise :) > > Ok, I'll give my best ... how about a dollar? ;-) > >> I understand that chains like this are common in Rails apps thanks to good ideas like composable finders (which generally do not violate Demeter), but I don't think the parallel chains should appear in client code or in specs. e.g. if this is a controller spec, the model should expose a single method that wraps this, and if it's the model spec, the spec should just call the method that wraps the chain with different inputs and and specify the expected outcomes. > > I dislike the idea to extract a single line of chained method calls > into its own method, just because it is easier to test then. We have a fundamental philosophical disagreement here. I see testability as having inherent value, "just because it is easier to test" is a good enough reason to consider a change. > It is not > used anywhere else and the method it is in is not very large either > (those would be reasons to extract that code in its own method). I'm confused about where it _is_ being used? What code actually calls this chain? > By > the way, it is part of the model. I would agree if it were part of the > controller. > >> Even if I were in favor of the concept, the example above is confusing because it is a stub that becomes a message expectation. > > I absolutely agree. I also thought about that when I read my post for > a second time. How about: MyModel.should_receive_chain(...) Need to ponder that. Will follow up with some thoughts. From dchelimsky at gmail.com Sun Nov 28 16:20:24 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 28 Nov 2010 15:20:24 -0600 Subject: [rspec-users] no such file to load - spec/test/unit In-Reply-To: References: Message-ID: <93208473-7E25-4AEA-9D17-B4F18BD85CB8@gmail.com> On Nov 25, 2010, at 11:44 AM, James Palmer wrote: > Under the older version of rspec, I'm able to run my script successfully > by running "spec randomperform.rb" > > I've now installed the newest rspec, and it does not work for me. If I > run the command: > > rspec randomperform.rb > > I get the following error: > > ----- > :29:in `require': no such file to > load -- > spec/test/unit (LoadError) > from :29:in `require' > from C:/watir-tests/craftfree/randomperform.rb:3:in ` (required)>' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core > /configuration.rb:334:in `load' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core > /configuration.rb:334:in `block in load_spec_files' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core > /configuration.rb:334:in `map' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core > /configuration.rb:334:in `load_spec_files' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core > /command_line.rb:18:in `run' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core > /runner.rb:55:in `run_in_process' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core > /runner.rb:46:in `run' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.1.0/lib/rspec/core > /runner.rb:10:in `block in autorun' > -------- > > Anyone know what is wrong? What am I missing? Sorry if this is a > "newb" question, as I'm still fairly new at Ruby and its various gems. > > Thanks, > James rspec-2 does not interoperate with the test/unit runner anymore, so spec/test/unit was removed. What is it you're trying to do? From dchelimsky at gmail.com Sun Nov 28 16:23:12 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 28 Nov 2010 15:23:12 -0600 Subject: [rspec-users] Question: Define custom matcher like raise_error, by Matchers.define In-Reply-To: References: <54C8E659-5959-4FE9-8BF2-24C52FD9D10B@kaorukobo.net> <67A5656C-63DA-42CB-9847-17E1A5A956DE@gmail.com> <523CC9ED-C5CF-4A4F-8727-7395BBE234E9@kaorukobo.net> Message-ID: <64B77E6C-B9D7-4A1D-AC74-71FB19C0280D@gmail.com> On Nov 25, 2010, at 7:16 PM, Kaoru Kobo wrote: > Then I found this page: > > ?Upgrade to 1.3.0 - Matcher DSL" > Upgrade.rdoc at master from dchelimsky's rspec - GitHub > http://github.com/dchelimsky/rspec/blob/master/Upgrade.rdoc > > > and, I found the tentative solution: > (Is there the better way?) Actually, match_unless_raises is probably the best solution for your issue. > > ======================================================================== > Spec::Matchers.define :be_done do > - match do |block| > + # Do not turn any exceptions to false. > + match_unless_raises(Class.new(Exception)) do |block| > block.call > true > end > ======================================================================== > > Best Regards. > -- > Kaoru Kobo From dchelimsky at gmail.com Sun Nov 28 17:35:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 28 Nov 2010 16:35:56 -0600 Subject: [rspec-users] rspec-2.2 is released! Message-ID: ### rspec-core-2.2.0 [full changelog](http://github.com/rspec/rspec-core/compare/v2.1.0...master) * Deprecations/changes * --debug/-d on command line is deprecated and now has no effect * win32console is now ignored; Windows users must use ANSICON for color support (Bosko Ivanisevic) * Enhancements * Raise exception with helpful message when rspec-1 is loaded alongside rspec-2 (Justin Ko) * debugger statements _just work_ as long as ruby-debug is installed * otherwise you get warned, but not fired * Expose example.metadata in around hooks * Performance improvments (see [Upgrade.markdown](https://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)) * Bug fixes * Make sure --fail-fast makes it across drb * Pass -Ilib:spec to rcov ### rspec-mocks-2.2.0 [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.1.0...v2.2.0) * Enhancements * Added "rspec/mocks/standalone" for exploring the rspec-mocks in irb. * Bug fix * Eliminate warning on splat args without parens (Gioele Barabucci) * Fix bug where obj.should_receive(:foo).with(stub.as_null_object) would pass with a false positive. ### rspec-rails-2.2.0 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.1.0...master) * Enhancements * Added stub_template in view specs * Bug fixes * Properly include helpers in views (Jonathan del Strother) * Fix bug in which method missing led to a stack overflow * Fix stack overflow in request specs with open_session * Fix stack overflow in any spec when method_missing was invoked * Add gem dependency on rails ~> 3.0.0 (ensures bundler won't install rspec-rails-2 with rails-2 apps). From jonathan at parkerhill.com Sun Nov 28 20:28:23 2010 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sun, 28 Nov 2010 20:28:23 -0500 Subject: [rspec-users] rspec-2.2 is released! In-Reply-To: References: Message-ID: <84D4F263-177D-432B-81A3-ADDD04D2C142@parkerhill.com> David, it's been a while since I said Thank You, so I just want to say Thank You for everything you do for rspec. :) --linoj On Nov 28, 2010, at 5:35 PM, David Chelimsky wrote: > ### rspec-core-2.2.0 > > [full changelog](http://github.com/rspec/rspec-core/compare/v2.1.0...master) > > * Deprecations/changes > * --debug/-d on command line is deprecated and now has no effect > * win32console is now ignored; Windows users must use ANSICON for color support > (Bosko Ivanisevic) > > * Enhancements > * Raise exception with helpful message when rspec-1 is loaded alongside > rspec-2 (Justin Ko) > * debugger statements _just work_ as long as ruby-debug is installed > * otherwise you get warned, but not fired > * Expose example.metadata in around hooks > * Performance improvments (see [Upgrade.markdown](https://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)) > > * Bug fixes > * Make sure --fail-fast makes it across drb > * Pass -Ilib:spec to rcov > > ### rspec-mocks-2.2.0 > > [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.1.0...v2.2.0) > > * Enhancements > * Added "rspec/mocks/standalone" for exploring the rspec-mocks in irb. > > * Bug fix > * Eliminate warning on splat args without parens (Gioele Barabucci) > * Fix bug where obj.should_receive(:foo).with(stub.as_null_object) would > pass with a false positive. > > ### rspec-rails-2.2.0 > > [full changelog](http://github.com/rspec/rspec-rails/compare/v2.1.0...master) > > * Enhancements > * Added stub_template in view specs > > * Bug fixes > * Properly include helpers in views (Jonathan del Strother) > * Fix bug in which method missing led to a stack overflow > * Fix stack overflow in request specs with open_session > * Fix stack overflow in any spec when method_missing was invoked > * Add gem dependency on rails ~> 3.0.0 (ensures bundler won't install > rspec-rails-2 with rails-2 apps). > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- jonathan linowes parkerhill technology group llc jonathan at parkerhill.com office: 603-838-2884 tech blog: http://vaporbase.com personal tumblog: http://jon.linow.es facebook: http://facebook.com/jon.linowes twitter: @linojon From pub at kaorukobo.net Sun Nov 28 23:32:59 2010 From: pub at kaorukobo.net (Kaoru Kobo) Date: Mon, 29 Nov 2010 13:32:59 +0900 Subject: [rspec-users] Question: Define custom matcher like raise_error, by Matchers.define In-Reply-To: <64B77E6C-B9D7-4A1D-AC74-71FB19C0280D@gmail.com> References: <54C8E659-5959-4FE9-8BF2-24C52FD9D10B@kaorukobo.net> <67A5656C-63DA-42CB-9847-17E1A5A956DE@gmail.com> <523CC9ED-C5CF-4A4F-8727-7395BBE234E9@kaorukobo.net> <64B77E6C-B9D7-4A1D-AC74-71FB19C0280D@gmail.com> Message-ID: <549B73C0-31F7-4962-9D2B-10AD953200CA@kaorukobo.net> David Thanks! > > Actually, match_unless_raises is probably the best solution for your > issue. >> >> Then I found this page: >> >> ?Upgrade to 1.3.0 - Matcher DSL" >> Upgrade.rdoc at master from dchelimsky's rspec - GitHub >> http://github.com/dchelimsky/rspec/blob/master/Upgrade.rdoc >> >> and, I found the tentative solution: >> (Is there the better way?) From wolfmanjm at gmail.com Mon Nov 29 05:51:34 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Mon, 29 Nov 2010 02:51:34 -0800 (PST) Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> Message-ID: <3fc4eeb7-181c-422a-95b3-3b58157e709a@n2g2000pre.googlegroups.com> I don't get the stack level too deep but I do get undefined method `last_response' for # Which was supposed to be fixed ages ago. So did one fix break another? I have webrat using :rack config rspec 2.2.0, rspec-rails 2.2.0, webrat 0.7.2, rails 3.0.3 It looks to me like the webrat rack adapter is calling @session.last_response which is a rack/test call and should work, Should I report this on the webrat page or rspec??? On Nov 15, 3:36?pm, David Chelimsky wrote: > On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: > > > > > I'm having problems getting rspec-rails 2 request specs to work with > >webrat. Any help would be appreciated. Here's my setup: > > > ruby 1.9.2p0 > > rails 3.0.1 > > rspec-rails 2.1.0 > >webrat0.7.2 > > > Here's the error I'm getting: > > > $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb > > F > > > Failures: > > ?1) > > ? ? Failure/Error: Unable to find matching line from backtrace > > ? ? stack level too deep > > ? ? # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 > > > Finished in 0.49825 seconds > > 1 example, 1 failure > > > Here are snippets of my files: > > > # spec/spec_helper.rb > > # > > # The following is based on ?some tips from a cucumber-rails ticket: > > require "webrat" > > require "webrat/core/matchers" > > > include Rack::Test::Methods > > includeWebrat::Methods > > includeWebrat::Matchers > > >Webrat.configure do |config| > > ?config.mode = :rack > > ?config.open_error_files = false > > end > > > # spec/requests/_spec.rb > > require "spec_helper" > > > describe "" do > > ?it "" do > > ? ?visit _path > > > ? ?# The following works when uncommented: > > ? ?# > > ? ?# get _path > > ? ?# assert_template '/' > > ?end > > end > > This is actually awebratissue, but it is reported to rspec-rails andwebrat: > > https://github.com/rspec/rspec-rails/issues/140https://webrat.lighthouseapp.com/projects/10503/tickets/398https://webrat.lighthouseapp.com/projects/10503/tickets/400 > > > > > Thanks, > > Pete > > _______________________________________________ > > 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 wolfmanjm at gmail.com Mon Nov 29 05:58:28 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Mon, 29 Nov 2010 02:58:28 -0800 (PST) Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> Message-ID: Ok adding include Rack::Test::Methods to my spec_helper changed the error to Failure/Error: visit "/" No response yet. Request a page first. # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' # ./spec/requests/basics_spec.rb:5 So someone is not including the rack test stuff, however still don;t know why it is failing On Nov 15, 3:36?pm, David Chelimsky wrote: > On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: > > > > > I'm having problems getting rspec-rails 2 request specs to work with > >webrat. Any help would be appreciated. Here's my setup: > > > ruby 1.9.2p0 > > rails 3.0.1 > > rspec-rails 2.1.0 > >webrat0.7.2 > > > Here's the error I'm getting: > > > $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb > > F > > > Failures: > > ?1) > > ? ? Failure/Error: Unable to find matching line from backtrace > > ? ? stack level too deep > > ? ? # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 > > > Finished in 0.49825 seconds > > 1 example, 1 failure > > > Here are snippets of my files: > > > # spec/spec_helper.rb > > # > > # The following is based on ?some tips from a cucumber-rails ticket: > > require "webrat" > > require "webrat/core/matchers" > > > include Rack::Test::Methods > > includeWebrat::Methods > > includeWebrat::Matchers > > >Webrat.configure do |config| > > ?config.mode = :rack > > ?config.open_error_files = false > > end > > > # spec/requests/_spec.rb > > require "spec_helper" > > > describe "" do > > ?it "" do > > ? ?visit _path > > > ? ?# The following works when uncommented: > > ? ?# > > ? ?# get _path > > ? ?# assert_template '/' > > ?end > > end > > This is actually awebratissue, but it is reported to rspec-rails andwebrat: > > https://github.com/rspec/rspec-rails/issues/140https://webrat.lighthouseapp.com/projects/10503/tickets/398https://webrat.lighthouseapp.com/projects/10503/tickets/400 > > > > > Thanks, > > Pete > > _______________________________________________ > > 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 cremes.devlist at mac.com Mon Nov 29 09:04:53 2010 From: cremes.devlist at mac.com (Chuck Remes) Date: Mon, 29 Nov 2010 08:04:53 -0600 Subject: [rspec-users] rspec-2.2 is released! In-Reply-To: References: Message-ID: On Nov 28, 2010, at 4:35 PM, David Chelimsky wrote: > ### rspec-core-2.2.0 > > > * Performance improvments (see [Upgrade.markdown](https://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)) Wow, the perf improvements are *much* appreciated! My test suite (MRI 1.9.2p0) with 3300 examples went from 7.4s under 2.1.0 to 3.2s with 2.2.1. Most excellent! cr From lists at ruby-forum.com Mon Nov 29 10:14:27 2010 From: lists at ruby-forum.com (James Palmer) Date: Mon, 29 Nov 2010 16:14:27 +0100 Subject: [rspec-users] no such file to load - spec/test/unit In-Reply-To: References: Message-ID: <79a791e970aec9a156bb150540f36b2c@ruby-forum.com> Thanks David, I actually had a "require" statement in my code for Test Unit that shouldn't have been there - the problem appears to not have been rspec related at all. Thanks! James -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Nov 29 10:18:11 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 29 Nov 2010 09:18:11 -0600 Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> Message-ID: On Nov 29, 2010, at 4:58 AM, Jim Morris wrote: > Ok adding > > include Rack::Test::Methods > > to my spec_helper changed the error to > > Failure/Error: visit "/" > No response yet. Request a page first. > # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- > test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' > # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' > # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' > # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' > # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' > # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' > # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' > # ./spec/requests/basics_spec.rb:5 > > So someone is not including the rack test stuff, however still don;t > know why it is failing I'd get rid of all of that stuff from spec_helper. It was guidance from a cucumber-rails issue, not an rspec issue, and is unnecessary with rspec. I'd just re-generate it with "script/rails generate rspec:install" HTH, David > > On Nov 15, 3:36 pm, David Chelimsky wrote: >> On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: >> >> >> >>> I'm having problems getting rspec-rails 2 request specs to work with >>> webrat. Any help would be appreciated. Here's my setup: >> >>> ruby 1.9.2p0 >>> rails 3.0.1 >>> rspec-rails 2.1.0 >>> webrat0.7.2 >> >>> Here's the error I'm getting: >> >>> $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb >>> F >> >>> Failures: >>> 1) >>> Failure/Error: Unable to find matching line from backtrace >>> stack level too deep >>> # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 >> >>> Finished in 0.49825 seconds >>> 1 example, 1 failure >> >>> Here are snippets of my files: >> >>> # spec/spec_helper.rb >>> # >>> # The following is based on some tips from a cucumber-rails ticket: >>> require "webrat" >>> require "webrat/core/matchers" >> >>> include Rack::Test::Methods >>> includeWebrat::Methods >>> includeWebrat::Matchers >> >>> Webrat.configure do |config| >>> config.mode = :rack >>> config.open_error_files = false >>> end >> >>> # spec/requests/_spec.rb >>> require "spec_helper" >> >>> describe "" do >>> it "" do >>> visit _path >> >>> # The following works when uncommented: >>> # >>> # get _path >>> # assert_template '/' >>> end >>> end >> >> This is actually awebratissue, but it is reported to rspec-rails andwebrat: >> >> https://github.com/rspec/rspec-rails/issues/140https://webrat.lighthouseapp.com/projects/10503/tickets/398https://webrat.lighthouseapp.com/projects/10503/tickets/400 >> >> >> >>> Thanks, >>> Pete >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Nov 29 10:27:23 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 29 Nov 2010 09:27:23 -0600 Subject: [rspec-users] rspec-2.2 is released! In-Reply-To: References: Message-ID: <8B7F0C81-8836-4FD9-853A-7EEEB0C53709@gmail.com> On Nov 29, 2010, at 8:04 AM, Chuck Remes wrote: > > On Nov 28, 2010, at 4:35 PM, David Chelimsky wrote: > >> ### rspec-core-2.2.0 >> >> >> * Performance improvments (see [Upgrade.markdown](https://github.com/rspec/rspec-core/blob/master/Upgrade.markdown)) > > Wow, the perf improvements are *much* appreciated! > > My test suite (MRI 1.9.2p0) with 3300 examples went from 7.4s under 2.1.0 to 3.2s with 2.2.1. Most excellent! Glad to hear it. My benchmarks were based on an essentially empty spec suite (so no overhead from the implementation code). Hearing that with a real app we're still getting 1k examples per second makes me very happy :) I'm assuming, however, this is not a Rails app, correct? From jack.kinsella at gmail.com Mon Nov 29 11:52:56 2010 From: jack.kinsella at gmail.com (Jack Kinsella) Date: Mon, 29 Nov 2010 08:52:56 -0800 (PST) Subject: [rspec-users] How To Mock A Chain (specifically ActionMailerModel.method.deliver) In-Reply-To: References: <86e1ee0e-0b53-40c3-aa5a-c543a5ddff35@r29g2000yqj.googlegroups.com> Message-ID: <3c954e8c-6fe2-441d-bc01-bdef23afea8d@e10g2000yqh.googlegroups.com> Cheers, very insightful. I liked your point about ease of testing having an inherent value. On Nov 25, 12:22?pm, David Chelimsky wrote: > On Wed, Nov 17, 2010 at 12:49 PM, Jack Kinsella wrote: > > Hi, > > > In Rails 3 you deliver a mail message with the > > ActionMailerModel.method.deliver syntax (e.g. > > Notifier.welcome_message.deliver). How do you test that this method is > > called in Rspec. I'm looking for an equivalent to "stub_chain" which > > has expectations. I'm testing that messages are sent on certain events > > in the object life cycle (e.g. that an email is sent when an Award is > > created). > > > I know it's possible to abstract welcome_message.deliver into a single > > method call, but this seems overly inconvenient for such a simple > > case. > > > Anyone any ideas on how to solve this problem? > > See this thread:http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2... > > Cheers, > David > > > > > Kind Regards, > > > Jack Kinsella > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Nov 29 14:19:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 29 Nov 2010 13:19:57 -0600 Subject: [rspec-users] rspec-core-2.2.1 is released! Message-ID: <3040FC15-1DFC-44E4-AAC9-2C73A3AB4E7E@gmail.com> ### rspec-core-2.2.1 / 2010-11-28 [full changelog](http://github.com/rspec/rspec-core/compare/v2.2.0...master) * Bug fixes * alias_method instead of override Kernel#method_missing (John Wilger) * changed --autotest to --tty in generated command (MIKAMI Yoshiyuki) * revert change to debugger (had introduced conflict with Rails) * also restored --debugger/-debug option From wolfmanjm at gmail.com Mon Nov 29 16:32:31 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Mon, 29 Nov 2010 13:32:31 -0800 (PST) Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> Message-ID: <25761de9-1f35-4e82-abd4-7213532784bb@p7g2000prb.googlegroups.com> BGTW the spec is very simple... require 'spec_helper' describe "Logins" do describe "GET /login" do it "should be able to login" do get "/login" p response.body end end end the undefined method `last_response' for # comes from the p response.body On Nov 29, 7:18?am, David Chelimsky wrote: > On Nov 29, 2010, at 4:58 AM, Jim Morris wrote: > > > > > Ok adding > > > include Rack::Test::Methods > > > to my spec_helper changed the error to > > > ? ?Failure/Error: visit "/" > > ? ? No response yet. Request a page first. > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- > > test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' > > ? ? # ./spec/requests/basics_spec.rb:5 > > > So someone is not including the rack test stuff, however still don;t > > know why it is failing > > I'd get rid of all of that stuff from spec_helper. It was guidance from a cucumber-rails issue, not an rspec issue, and is unnecessary with rspec. I'd just re-generate it with "script/rails generate rspec:install" > > HTH, > David > > > > > > > On Nov 15, 3:36 pm, David Chelimsky wrote: > >> On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: > > >>> I'm having problems getting rspec-rails 2 request specs to work with > >>> webrat. Any help would be appreciated. Here's my setup: > > >>> ruby 1.9.2p0 > >>> rails 3.0.1 > >>> rspec-rails 2.1.0 > >>> webrat0.7.2 > > >>> Here's the error I'm getting: > > >>> $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb > >>> F > > >>> Failures: > >>> ?1) > >>> ? ? Failure/Error: Unable to find matching line from backtrace > >>> ? ? stack level too deep > >>> ? ? # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 > > >>> Finished in 0.49825 seconds > >>> 1 example, 1 failure > > >>> Here are snippets of my files: > > >>> # spec/spec_helper.rb > >>> # > >>> # The following is based on ?some tips from a cucumber-rails ticket: > >>> require "webrat" > >>> require "webrat/core/matchers" > > >>> include Rack::Test::Methods > >>> includeWebrat::Methods > >>> includeWebrat::Matchers > > >>> Webrat.configure do |config| > >>> ?config.mode = :rack > >>> ?config.open_error_files = false > >>> end > > >>> # spec/requests/_spec.rb > >>> require "spec_helper" > > >>> describe "" do > >>> ?it "" do > >>> ? ?visit _path > > >>> ? ?# The following works when uncommented: > >>> ? ?# > >>> ? ?# get _path > >>> ? ?# assert_template '/' > >>> ?end > >>> end > > >> This is actually awebratissue, but it is reported to rspec-rails andwebrat: > > >>https://github.com/rspec/rspec-rails/issues/140https://webrat.lightho... > > >>> Thanks, > >>> Pete > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-us... at rubyforge.org > >>>http://rubyforge.org/mailman/listinfo/rspec-users > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-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 wolfmanjm at gmail.com Mon Nov 29 16:28:07 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Mon, 29 Nov 2010 13:28:07 -0800 (PST) Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> Message-ID: Sorry I may have been unclear.... When using the default spec_helper as generated from a fresh script/rails generate rspec:install I get the error... undefined method `last_response' for # This means something is not seeing the Rack Test stuff. The second error is got when I add include Rack::Test::Methods It now sees last_response but doesn't get a respnose from visit (That may be a different errror). So bottom line is using the latest rails/rspec/webrat does not work out of the box. On Nov 29, 7:18?am, David Chelimsky wrote: > On Nov 29, 2010, at 4:58 AM, Jim Morris wrote: > > > > > Ok adding > > > include Rack::Test::Methods > > > to my spec_helper changed the error to > > > ? ?Failure/Error: visit "/" > > ? ? No response yet. Request a page first. > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- > > test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' > > ? ? # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > > webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' > > ? ? # ./spec/requests/basics_spec.rb:5 > > > So someone is not including the rack test stuff, however still don;t > > know why it is failing > > I'd get rid of all of that stuff from spec_helper. It was guidance from a cucumber-rails issue, not an rspec issue, and is unnecessary with rspec. I'd just re-generate it with "script/rails generate rspec:install" > > HTH, > David > > > > > > > On Nov 15, 3:36 pm, David Chelimsky wrote: > >> On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: > > >>> I'm having problems getting rspec-rails 2 request specs to work with > >>> webrat. Any help would be appreciated. Here's my setup: > > >>> ruby 1.9.2p0 > >>> rails 3.0.1 > >>> rspec-rails 2.1.0 > >>> webrat0.7.2 > > >>> Here's the error I'm getting: > > >>> $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb > >>> F > > >>> Failures: > >>> ?1) > >>> ? ? Failure/Error: Unable to find matching line from backtrace > >>> ? ? stack level too deep > >>> ? ? # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 > > >>> Finished in 0.49825 seconds > >>> 1 example, 1 failure > > >>> Here are snippets of my files: > > >>> # spec/spec_helper.rb > >>> # > >>> # The following is based on ?some tips from a cucumber-rails ticket: > >>> require "webrat" > >>> require "webrat/core/matchers" > > >>> include Rack::Test::Methods > >>> includeWebrat::Methods > >>> includeWebrat::Matchers > > >>> Webrat.configure do |config| > >>> ?config.mode = :rack > >>> ?config.open_error_files = false > >>> end > > >>> # spec/requests/_spec.rb > >>> require "spec_helper" > > >>> describe "" do > >>> ?it "" do > >>> ? ?visit _path > > >>> ? ?# The following works when uncommented: > >>> ? ?# > >>> ? ?# get _path > >>> ? ?# assert_template '/' > >>> ?end > >>> end > > >> This is actually awebratissue, but it is reported to rspec-rails andwebrat: > > >>https://github.com/rspec/rspec-rails/issues/140https://webrat.lightho... > > >>> Thanks, > >>> Pete > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-us... at rubyforge.org > >>>http://rubyforge.org/mailman/listinfo/rspec-users > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-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 jrbruce at gmail.com Mon Nov 29 17:37:06 2010 From: jrbruce at gmail.com (John Bruce) Date: Mon, 29 Nov 2010 14:37:06 -0800 Subject: [rspec-users] [TDD] [Rails] - Rspec test for application_helper.rb fails when trying to access application_controller method. Message-ID: In a method named logo in my application helper, I reference an application controller method (current_account) that has been marked as a helper method with the following syntax: helper_method :current_account When I test out the setup in the browser (without rspec), rails is happy with this setup. However, when I run the spec, the spec won't pass and gives me the following error: Failures: 1) ApplicationHelper#logo image tag should point to logo.png Failure/Error: helper.logo.should =~ /logo.png/i undefined local variable or method `current_account' for # # ./app/helpers/application_helper.rb:13:in `logo' # ./spec/helpers/application_helper_spec.rb:21 Current Versions: Rspec Version 2.1.0 Rails Version 3.0.1 I've created a gist that shows how my code is setup, and how the helper is calling the controller method: https://gist.github.com/720757 Does anyone know why this setup works fine outside of rspec (when I test in the browser), but won't work within rspec? Is there an object / instance variable that I need to mock, or a setting that I need to change in order for the helper spec to know about the controller methods that have been marked as helper methods? John Bruce -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Nov 29 17:44:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 29 Nov 2010 16:44:54 -0600 Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> Message-ID: <877C79A4-D07C-48B6-AF91-503122CA0785@gmail.com> On Nov 29, 2010, at 3:28 PM, Jim Morris wrote: > Sorry I may have been unclear.... > > When using the default spec_helper as generated from a fresh > script/rails generate rspec:install > I get the error... > > undefined method `last_response' for > # > > This means something is not seeing the Rack Test stuff. > > The second error is got when I add > > include Rack::Test::Methods > > It now sees last_response but doesn't get a respnose from visit (That > may be a different errror). > > So bottom line is using the latest rails/rspec/webrat does not work > out of the box. It does for me, so something is different between our configurations. Do you have webrat in the Gemfile? Is this a controller spec? If so is it in the spec/controllers directory? > > On Nov 29, 7:18 am, David Chelimsky wrote: >> On Nov 29, 2010, at 4:58 AM, Jim Morris wrote: >> >> >> >>> Ok adding >> >>> include Rack::Test::Methods >> >>> to my spec_helper changed the error to >> >>> Failure/Error: visit "/" >>> No response yet. Request a page first. >>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- >>> test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' >>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>> webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' >>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>> webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' >>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>> webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' >>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>> webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' >>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>> webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' >>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>> webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' >>> # ./spec/requests/basics_spec.rb:5 >> >>> So someone is not including the rack test stuff, however still don;t >>> know why it is failing >> >> I'd get rid of all of that stuff from spec_helper. It was guidance from a cucumber-rails issue, not an rspec issue, and is unnecessary with rspec. I'd just re-generate it with "script/rails generate rspec:install" >> >> HTH, >> David >> >> >> >> >> >>> On Nov 15, 3:36 pm, David Chelimsky wrote: >>>> On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: >> >>>>> I'm having problems getting rspec-rails 2 request specs to work with >>>>> webrat. Any help would be appreciated. Here's my setup: >> >>>>> ruby 1.9.2p0 >>>>> rails 3.0.1 >>>>> rspec-rails 2.1.0 >>>>> webrat0.7.2 >> >>>>> Here's the error I'm getting: >> >>>>> $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb >>>>> F >> >>>>> Failures: >>>>> 1) >>>>> Failure/Error: Unable to find matching line from backtrace >>>>> stack level too deep >>>>> # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 >> >>>>> Finished in 0.49825 seconds >>>>> 1 example, 1 failure >> >>>>> Here are snippets of my files: >> >>>>> # spec/spec_helper.rb >>>>> # >>>>> # The following is based on some tips from a cucumber-rails ticket: >>>>> require "webrat" >>>>> require "webrat/core/matchers" >> >>>>> include Rack::Test::Methods >>>>> includeWebrat::Methods >>>>> includeWebrat::Matchers >> >>>>> Webrat.configure do |config| >>>>> config.mode = :rack >>>>> config.open_error_files = false >>>>> end >> >>>>> # spec/requests/_spec.rb >>>>> require "spec_helper" >> >>>>> describe "" do >>>>> it "" do >>>>> visit _path >> >>>>> # The following works when uncommented: >>>>> # >>>>> # get _path >>>>> # assert_template '/' >>>>> end >>>>> end >> >>>> This is actually awebratissue, but it is reported to rspec-rails andwebrat: >> >>>> https://github.com/rspec/rspec-rails/issues/140https://webrat.lightho... >> >>>>> Thanks, >>>>> Pete >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-us... at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Nov 29 17:45:36 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 29 Nov 2010 16:45:36 -0600 Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: <877C79A4-D07C-48B6-AF91-503122CA0785@gmail.com> References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> <877C79A4-D07C-48B6-AF91-503122CA0785@gmail.com> Message-ID: <2183E0A5-56B1-4BC5-AF27-4B597218F18D@gmail.com> On Nov 29, 2010, at 4:44 PM, David Chelimsky wrote: > > On Nov 29, 2010, at 3:28 PM, Jim Morris wrote: > >> Sorry I may have been unclear.... >> >> When using the default spec_helper as generated from a fresh >> script/rails generate rspec:install >> I get the error... >> >> undefined method `last_response' for >> # >> >> This means something is not seeing the Rack Test stuff. >> >> The second error is got when I add >> >> include Rack::Test::Methods >> >> It now sees last_response but doesn't get a respnose from visit (That >> may be a different errror). >> >> So bottom line is using the latest rails/rspec/webrat does not work >> out of the box. > > It does for me, so something is different between our configurations. > > Do you have webrat in the Gemfile? > Is this a controller spec? If so is it in the spec/controllers directory? Also, what version of rspec-rails are we talking about? > >> >> On Nov 29, 7:18 am, David Chelimsky wrote: >>> On Nov 29, 2010, at 4:58 AM, Jim Morris wrote: >>> >>> >>> >>>> Ok adding >>> >>>> include Rack::Test::Methods >>> >>>> to my spec_helper changed the error to >>> >>>> Failure/Error: visit "/" >>>> No response yet. Request a page first. >>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- >>>> test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' >>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>> webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' >>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>> webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' >>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>> webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' >>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>> webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' >>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>> webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' >>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>> webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' >>>> # ./spec/requests/basics_spec.rb:5 >>> >>>> So someone is not including the rack test stuff, however still don;t >>>> know why it is failing >>> >>> I'd get rid of all of that stuff from spec_helper. It was guidance from a cucumber-rails issue, not an rspec issue, and is unnecessary with rspec. I'd just re-generate it with "script/rails generate rspec:install" >>> >>> HTH, >>> David >>> >>> >>> >>> >>> >>>> On Nov 15, 3:36 pm, David Chelimsky wrote: >>>>> On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: >>> >>>>>> I'm having problems getting rspec-rails 2 request specs to work with >>>>>> webrat. Any help would be appreciated. Here's my setup: >>> >>>>>> ruby 1.9.2p0 >>>>>> rails 3.0.1 >>>>>> rspec-rails 2.1.0 >>>>>> webrat0.7.2 >>> >>>>>> Here's the error I'm getting: >>> >>>>>> $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb >>>>>> F >>> >>>>>> Failures: >>>>>> 1) >>>>>> Failure/Error: Unable to find matching line from backtrace >>>>>> stack level too deep >>>>>> # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 >>> >>>>>> Finished in 0.49825 seconds >>>>>> 1 example, 1 failure >>> >>>>>> Here are snippets of my files: >>> >>>>>> # spec/spec_helper.rb >>>>>> # >>>>>> # The following is based on some tips from a cucumber-rails ticket: >>>>>> require "webrat" >>>>>> require "webrat/core/matchers" >>> >>>>>> include Rack::Test::Methods >>>>>> includeWebrat::Methods >>>>>> includeWebrat::Matchers >>> >>>>>> Webrat.configure do |config| >>>>>> config.mode = :rack >>>>>> config.open_error_files = false >>>>>> end >>> >>>>>> # spec/requests/_spec.rb >>>>>> require "spec_helper" >>> >>>>>> describe "" do >>>>>> it "" do >>>>>> visit _path >>> >>>>>> # The following works when uncommented: >>>>>> # >>>>>> # get _path >>>>>> # assert_template '/' >>>>>> end >>>>>> end >>> >>>>> This is actually awebratissue, but it is reported to rspec-rails andwebrat: >>> >>>>> https://github.com/rspec/rspec-rails/issues/140https://webrat.lightho... >>> >>>>>> Thanks, >>>>>> Pete >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-us... at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-us... at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > From jrbruce at gmail.com Mon Nov 29 17:56:34 2010 From: jrbruce at gmail.com (jrbruce) Date: Mon, 29 Nov 2010 14:56:34 -0800 (PST) Subject: [rspec-users] rspec2, rails 3, subdomain constraints In-Reply-To: References: Message-ID: <4a3018f3-c4cc-42f8-a9cf-ef72ad5b35db@k14g2000pre.googlegroups.com> On Nov 25, 5:03?am, Evgeniy Dolzhenko wrote: > https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_rec... > anyone? > > I appreciate the reply. Given that these routing constraints are core to my application do you have any suggestions as to how to test this in the meantime? It makes me uneasy to have them sitting there completely untested as this point. John > > > On Wed, Nov 24, 2010 at 5:12 AM, jrbruce wrote: > > I'm trying to constrain access to admin routes in my application to > > either www or canonical. I need the custom constraint in > > root_domain.rb (RootDomain) to handle the canonical part. Since the > > subdomains will represent accounts, I don't want /admin available on > > any of the subdomains. > > > Here is a gist showing exactly how my code and tests are setup: > > >https://gist.github.com/712968 > > > In the first test, I expect /admin not to be routable on a generic > > subdomain (this test currently doesn't pass). However, when I check in > > a browser, I receive a not routable error. > > > If I remove the custom constraint and use, for example, the :subdomain > > => "www" constraint, the test does pass. I've tested both the custom > > constraint and the subdomain constraint in my browser and both > > restrict access as expected. > > > Is this an issue with rspec and how it handles constraints or am I > > doing something wrong? > > _______________________________________________ > > 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 wolfmanjm at gmail.com Mon Nov 29 21:05:47 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Mon, 29 Nov 2010 18:05:47 -0800 (PST) Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: <2183E0A5-56B1-4BC5-AF27-4B597218F18D@gmail.com> References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> <877C79A4-D07C-48B6-AF91-503122CA0785@gmail.com> <2183E0A5-56B1-4BC5-AF27-4B597218F18D@gmail.com> Message-ID: <704c2777-746b-4d82-b772-71929bb3ddd3@fl7g2000vbb.googlegroups.com> Hi David, I am using the current versions of everything rspec rspec (2.2.0,) rspec-core (2.2.1) rspec-expectations (2.2.0) rspec-mocks (2.2.0,) rspec-rails (2.2.0) webrat (0.7.2) rails(3.0.3) webrat is in Gemfile... group :test, :development do gem 'webrat' gem 'rspec-rails' end My spec is meant to be an integration test and as such is in spec/ requests I have a pretty simple setup, the full source is here... https://github.com/wolfmanjm/wolfmanblog_rails Thanks for the help, its odd so many people are having issues with webrat, should I cross post to their group or is this an rspec/webrat/ rails3 issue? On Nov 29, 2:45?pm, David Chelimsky wrote: > On Nov 29, 2010, at 4:44 PM, David Chelimsky wrote: > > > > > > > On Nov 29, 2010, at 3:28 PM, Jim Morris wrote: > > >> Sorry I may have been unclear.... > > >> When using the default spec_helper as generated from a fresh > >> script/rails generate rspec:install > >> I get the error... > > >> undefined method `last_response' for > >> # > > >> This means something is not seeing the Rack Test stuff. > > >> The second error is got when I add > > >> include Rack::Test::Methods > > >> It now sees last_response but doesn't get a respnose from visit (That > >> may be a different errror). > > >> So bottom line is using the latest rails/rspec/webrat does not work > >> out of the box. > > > It does for me, so something is different between our configurations. > > > Do you have webrat in the Gemfile? > > Is this a controller spec? If so is it in the spec/controllers directory? > > Also, what version of rspec-rails are we talking about? > > > > > > >> On Nov 29, 7:18 am, David Chelimsky wrote: > >>> On Nov 29, 2010, at 4:58 AM, Jim Morris wrote: > > >>>> Ok adding > > >>>> include Rack::Test::Methods > > >>>> to my spec_helper changed the error to > > >>>> ? Failure/Error: visit "/" > >>>> ? ?No response yet. Request a page first. > >>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- > >>>> test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' > >>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>> webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' > >>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>> webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' > >>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>> webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' > >>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>> webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' > >>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>> webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' > >>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>> webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' > >>>> ? ?# ./spec/requests/basics_spec.rb:5 > > >>>> So someone is not including the rack test stuff, however still don;t > >>>> know why it is failing > > >>> I'd get rid of all of that stuff from spec_helper. It was guidance from a cucumber-rails issue, not an rspec issue, and is unnecessary with rspec. I'd just re-generate it with "script/rails generate rspec:install" > > >>> HTH, > >>> David > > >>>> On Nov 15, 3:36 pm, David Chelimsky wrote: > >>>>> On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: > > >>>>>> I'm having problems getting rspec-rails 2 request specs to work with > >>>>>> webrat. Any help would be appreciated. Here's my setup: > > >>>>>> ruby 1.9.2p0 > >>>>>> rails 3.0.1 > >>>>>> rspec-rails 2.1.0 > >>>>>> webrat0.7.2 > > >>>>>> Here's the error I'm getting: > > >>>>>> $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb > >>>>>> F > > >>>>>> Failures: > >>>>>> 1) > >>>>>> ? ?Failure/Error: Unable to find matching line from backtrace > >>>>>> ? ?stack level too deep > >>>>>> ? ?# /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 > > >>>>>> Finished in 0.49825 seconds > >>>>>> 1 example, 1 failure > > >>>>>> Here are snippets of my files: > > >>>>>> # spec/spec_helper.rb > >>>>>> # > >>>>>> # The following is based on ?some tips from a cucumber-rails ticket: > >>>>>> require "webrat" > >>>>>> require "webrat/core/matchers" > > >>>>>> include Rack::Test::Methods > >>>>>> includeWebrat::Methods > >>>>>> includeWebrat::Matchers > > >>>>>> Webrat.configure do |config| > >>>>>> config.mode = :rack > >>>>>> config.open_error_files = false > >>>>>> end > > >>>>>> # spec/requests/_spec.rb > >>>>>> require "spec_helper" > > >>>>>> describe "" do > >>>>>> it "" do > >>>>>> ? visit _path > > >>>>>> ? # The following works when uncommented: > >>>>>> ? # > >>>>>> ? # get _path > >>>>>> ? # assert_template '/' > >>>>>> end > >>>>>> end > > >>>>> This is actually awebratissue, but it is reported to rspec-rails andwebrat: > > >>>>>https://github.com/rspec/rspec-rails/issues/140https://webrat.lightho... > > >>>>>> Thanks, > >>>>>> Pete > >>>>>> _______________________________________________ > >>>>>> rspec-users mailing list > >>>>>> rspec-us... at rubyforge.org > >>>>>>http://rubyforge.org/mailman/listinfo/rspec-users > > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-us... at rubyforge.org > >>>>http://rubyforge.org/mailman/listinfo/rspec-users > > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-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 lists at ruby-forum.com Tue Nov 30 09:27:17 2010 From: lists at ruby-forum.com (Andrew Davis) Date: Tue, 30 Nov 2010 15:27:17 +0100 Subject: [rspec-users] ActionController::RoutingError Assistance Message-ID: Hello everyone, I can't seem to figure out what I'm doing wrong on this test. I'm trying to delete one of my models, criterion. All code can be found here, please let me know if you need anything else! The rspec message is also in there. http://pastie.org/private/uaoexi6tmmsplsr3oj1a8w Thank you! Andrew Davis -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Nov 30 09:34:51 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Nov 2010 08:34:51 -0600 Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: <704c2777-746b-4d82-b772-71929bb3ddd3@fl7g2000vbb.googlegroups.com> References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> <877C79A4-D07C-48B6-AF91-503122CA0785@gmail.com> <2183E0A5-56B1-4BC5-AF27-4B597218F18D@gmail.com> <704c2777-746b-4d82-b772-71929bb3ddd3@fl7g2000vbb.googlegroups.com> Message-ID: <634C9D72-D1EA-43B1-995E-23EB9F08EB54@gmail.com> On Nov 29, 2010, at 8:05 PM, Jim Morris wrote: > Hi David, > > I am using the current versions of everything rspec > rspec (2.2.0,) > rspec-core (2.2.1) > rspec-expectations (2.2.0) > rspec-mocks (2.2.0,) > rspec-rails (2.2.0) > webrat (0.7.2) > rails(3.0.3) > > webrat is in Gemfile... > > group :test, :development do > gem 'webrat' > gem 'rspec-rails' > end > > My spec is meant to be an integration test and as such is in spec/ > requests > > I have a pretty simple setup, the full source is here... > > https://github.com/wolfmanjm/wolfmanblog_rails > > > Thanks for the help, its odd so many people are having issues with > webrat, should I cross post to their group or is this an rspec/webrat/ > rails3 issue? I'm not sure where the issue is yet (most likely rspec), but I was able to see it by cloning your repo and running the specs. I was able to get things to work by moving "include Rack::Test::Methods" into the configure block: RSpec.configure do |config| config.include Rack::Test::Methods ... end You should _not_, however, have to do any such thing, so I'll look into it and if I can address this in rspec-rails I will and have a bug-fix release out soon. Thanks! David > > On Nov 29, 2:45 pm, David Chelimsky wrote: >> On Nov 29, 2010, at 4:44 PM, David Chelimsky wrote: >> >> >> >> >> >>> On Nov 29, 2010, at 3:28 PM, Jim Morris wrote: >> >>>> Sorry I may have been unclear.... >> >>>> When using the default spec_helper as generated from a fresh >>>> script/rails generate rspec:install >>>> I get the error... >> >>>> undefined method `last_response' for >>>> # >> >>>> This means something is not seeing the Rack Test stuff. >> >>>> The second error is got when I add >> >>>> include Rack::Test::Methods >> >>>> It now sees last_response but doesn't get a respnose from visit (That >>>> may be a different errror). >> >>>> So bottom line is using the latest rails/rspec/webrat does not work >>>> out of the box. >> >>> It does for me, so something is different between our configurations. >> >>> Do you have webrat in the Gemfile? >>> Is this a controller spec? If so is it in the spec/controllers directory? >> >> Also, what version of rspec-rails are we talking about? >> >> >> >> >> >>>> On Nov 29, 7:18 am, David Chelimsky wrote: >>>>> On Nov 29, 2010, at 4:58 AM, Jim Morris wrote: >> >>>>>> Ok adding >> >>>>>> include Rack::Test::Methods >> >>>>>> to my spec_helper changed the error to >> >>>>>> Failure/Error: visit "/" >>>>>> No response yet. Request a page first. >>>>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- >>>>>> test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' >>>>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>>>> webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' >>>>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>>>> webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' >>>>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>>>> webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' >>>>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>>>> webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' >>>>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>>>> webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' >>>>>> # /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ >>>>>> webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' >>>>>> # ./spec/requests/basics_spec.rb:5 >> >>>>>> So someone is not including the rack test stuff, however still don;t >>>>>> know why it is failing >> >>>>> I'd get rid of all of that stuff from spec_helper. It was guidance from a cucumber-rails issue, not an rspec issue, and is unnecessary with rspec. I'd just re-generate it with "script/rails generate rspec:install" >> >>>>> HTH, >>>>> David >> >>>>>> On Nov 15, 3:36 pm, David Chelimsky wrote: >>>>>>> On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: >> >>>>>>>> I'm having problems getting rspec-rails 2 request specs to work with >>>>>>>> webrat. Any help would be appreciated. Here's my setup: >> >>>>>>>> ruby 1.9.2p0 >>>>>>>> rails 3.0.1 >>>>>>>> rspec-rails 2.1.0 >>>>>>>> webrat0.7.2 >> >>>>>>>> Here's the error I'm getting: >> >>>>>>>> $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb >>>>>>>> F >> >>>>>>>> Failures: >>>>>>>> 1) >>>>>>>> Failure/Error: Unable to find matching line from backtrace >>>>>>>> stack level too deep >>>>>>>> # /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 >> >>>>>>>> Finished in 0.49825 seconds >>>>>>>> 1 example, 1 failure >> >>>>>>>> Here are snippets of my files: >> >>>>>>>> # spec/spec_helper.rb >>>>>>>> # >>>>>>>> # The following is based on some tips from a cucumber-rails ticket: >>>>>>>> require "webrat" >>>>>>>> require "webrat/core/matchers" >> >>>>>>>> include Rack::Test::Methods >>>>>>>> includeWebrat::Methods >>>>>>>> includeWebrat::Matchers >> >>>>>>>> Webrat.configure do |config| >>>>>>>> config.mode = :rack >>>>>>>> config.open_error_files = false >>>>>>>> end >> >>>>>>>> # spec/requests/_spec.rb >>>>>>>> require "spec_helper" >> >>>>>>>> describe "" do >>>>>>>> it "" do >>>>>>>> visit _path >> >>>>>>>> # The following works when uncommented: >>>>>>>> # >>>>>>>> # get _path >>>>>>>> # assert_template '/' >>>>>>>> end >>>>>>>> end >> >>>>>>> This is actually awebratissue, but it is reported to rspec-rails andwebrat: >> >>>>>>> https://github.com/rspec/rspec-rails/issues/140https://webrat.lightho... >> >>>>>>>> Thanks, >>>>>>>> Pete >>>>>>>> _______________________________________________ >>>>>>>> rspec-users mailing list >>>>>>>> rspec-us... at rubyforge.org >>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-us... at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-us... at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Tue Nov 30 11:09:13 2010 From: lists at ruby-forum.com (Jo Liss) Date: Tue, 30 Nov 2010 17:09:13 +0100 Subject: [rspec-users] RSpec interacting with Test::Unit: weird "is already defined" error Message-ID: <453856f595e5cc805e978e8b6a5e19aa@ruby-forum.com> Hey everyone, (I'm a newbie, so if I'm doing something wrong, please let me know! ^^) I'm getting weird errors when I mix RSpec and Test::Unit tests. Here is how to reproduce it with Rails 3: Run "rails new railsapp". Add "gem 'rspec'" to the Gemfile, and create test/unit/demo_test.rb with the following code: require 'test_helper' class FirstTest < ActiveSupport::TestCase test 'something' do assert_equal 42, 42 end end class SecondTest < ActiveSupport::TestCase test 'something' do assert_equal 42, 42 end end Run "bundle install; rake db:migrate; rake test". The two tests pass. Now add the following code to the end of test/unit/demo_test.rb: describe 'this is an rspec test' do end Run "rake test" again, and it fails with the following errors message: (in /home/jo/tmp/railsapp) /var/lib/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/testing/declarative.rb:28:in `test': test_something is already defined in FirstTest (RuntimeError) from /home/jo/tmp/railsapp/test/unit/demo_test.rb:4:in `' from /home/jo/tmp/railsapp/test/unit/demo_test.rb:3:in `' from /var/lib/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:235:in `load' from /var/lib/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:235:in `block in load' from /var/lib/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:227:in `load_dependency' from /var/lib/gems/1.9.1/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:235:in `load' from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files' from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map' from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files' from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run' from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process' from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run' from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun' Errors running test:units! I googled for the error message and came up with http://osdir.com/ml/RubyonRails:Core/2009-12/msg00084.html , which tells me that since "FirstTest" and "SecondTest" have different class names, there shouldn't be a problem. Am I doing something wrong? I'm not even sure whether this is a Test::Unit or RSpec problem, but since RSpec seems to trigger it, I figured I'd post here... Thanks, Jo -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Nov 30 11:28:16 2010 From: lists at ruby-forum.com (Jo Liss) Date: Tue, 30 Nov 2010 17:28:16 +0100 Subject: [rspec-users] RSpec interacting with Test::Unit: weird "is already defined" error In-Reply-To: <453856f595e5cc805e978e8b6a5e19aa@ruby-forum.com> References: <453856f595e5cc805e978e8b6a5e19aa@ruby-forum.com> Message-ID: <3b6dbd60cdc02ab73d279bc7ea7b5e59@ruby-forum.com> One more thing: If instead of "test 'something'" I write "def test_something", like so: require 'test_helper' class FirstTest < ActiveSupport::TestCase def test_something assert_equal 42, 84 end end class SecondTest < ActiveSupport::TestCase def test_something assert_equal 42, 84 end end describe 'this is an rspec test' do end ... then adding the last two lines causes the two test_something tests to not be picked up at all (so zero tests are run). Strange, isn't it? Jo -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Nov 30 13:21:42 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Nov 2010 12:21:42 -0600 Subject: [rspec-users] RSpec interacting with Test::Unit: weird "is already defined" error In-Reply-To: <3b6dbd60cdc02ab73d279bc7ea7b5e59@ruby-forum.com> References: <453856f595e5cc805e978e8b6a5e19aa@ruby-forum.com> <3b6dbd60cdc02ab73d279bc7ea7b5e59@ruby-forum.com> Message-ID: On Nov 30, 2010, at 10:28 AM, Jo Liss wrote: > One more thing: If instead of "test 'something'" I write "def > test_something", like so: > > require 'test_helper' > class FirstTest < ActiveSupport::TestCase > def test_something > assert_equal 42, 84 > end > end > class SecondTest < ActiveSupport::TestCase > def test_something > assert_equal 42, 84 > end > end > describe 'this is an rspec test' do > end > > ... then adding the last two lines causes the two test_something tests > to not be picked up at all (so zero tests are run). > > Strange, isn't it? Hey Jo - welcome to the RSpec list. RSpec and Test::Unit each have their own runners which work differently, so what you're experiencing is not surprising. Are you just exploring at this point? Or is there a problem you're trying to solve by intermingling them? I'd recommend keeping specs under the spec directory and run them separately from Test::Unit tests. From joliss42 at gmail.com Tue Nov 30 15:11:37 2010 From: joliss42 at gmail.com (Jo Liss) Date: Tue, 30 Nov 2010 21:11:37 +0100 Subject: [rspec-users] RSpec interacting with Test::Unit: weird "is already defined" error In-Reply-To: References: <453856f595e5cc805e978e8b6a5e19aa@ruby-forum.com> <3b6dbd60cdc02ab73d279bc7ea7b5e59@ruby-forum.com> Message-ID: On Tue, Nov 30, 2010 at 7:21 PM, David Chelimsky wrote: > Or is there a problem you're trying to solve by intermingling them? > > I'd recommend keeping specs under the spec directory and run them separately from Test::Unit tests. Ah, I see -- thanks for the quick reply! So, I'm really trying to write test code, not specs. There are a bunch of existing Test::Unit tests. But since I'm using rspec/expectations's "should" assertions in my test code already (as described on http://relishapp.com/rspec/rspec-expectations/v/2-0/dir/test-frameworks/test-unit-integration ), I figured I might use RSpec instead of Test::Unit to structure my tests, as RSpec has this awesome nesting feature. But from your reply I take it that trying to squeeze my test code into RSpec (even if I migrated all my Test::Unit tests to RSpec tests) is going to result in ugly code and unhappiness? Jo From dchelimsky at gmail.com Tue Nov 30 15:39:29 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Nov 2010 14:39:29 -0600 Subject: [rspec-users] RSpec interacting with Test::Unit: weird "is already defined" error In-Reply-To: References: <453856f595e5cc805e978e8b6a5e19aa@ruby-forum.com> <3b6dbd60cdc02ab73d279bc7ea7b5e59@ruby-forum.com> Message-ID: <4DB47755-13AD-432E-9C5E-1D422B29C11D@gmail.com> On Nov 30, 2010, at 2:11 PM, Jo Liss wrote: > On Tue, Nov 30, 2010 at 7:21 PM, David Chelimsky wrote: >> Or is there a problem you're trying to solve by intermingling them? >> >> I'd recommend keeping specs under the spec directory and run them separately from Test::Unit tests. > > Ah, I see -- thanks for the quick reply! > > So, I'm really trying to write test code, not specs. There are a > bunch of existing Test::Unit tests. But since I'm using > rspec/expectations's "should" assertions in my test code already (as > described on http://relishapp.com/rspec/rspec-expectations/v/2-0/dir/test-frameworks/test-unit-integration That page only applies to rspec-expectations (should + matchers), not rspec-core, which provides the structure. > ), I figured I might use RSpec instead of Test::Unit to structure my > tests, as RSpec has this awesome nesting feature. Yes, it does, which is why I like to use rspec for the whole thing :) > But from your reply I take it that trying to squeeze my test code into > RSpec (even if I migrated all my Test::Unit tests to RSpec tests) is > going to result in ugly code and unhappiness? Not necessarily. Depends on how you go about it. Also depends on what environment you're already in. There is a project called rspec-unit that can help you migrate from test/unit to rspec gradually, but it doesn't always work well if you're using test/unit extensions that hack into test/unit internals. Might want to take a look at it, however: https://github.com/glv/rspec-unit Cheers, David > > Jo From wolfmanjm at gmail.com Tue Nov 30 16:00:53 2010 From: wolfmanjm at gmail.com (Jim Morris) Date: Tue, 30 Nov 2010 13:00:53 -0800 (PST) Subject: [rspec-users] Trouble making rspec-rails 2 work with webrat. In-Reply-To: <634C9D72-D1EA-43B1-995E-23EB9F08EB54@gmail.com> References: <2b3d260d-1431-494c-a003-89489f443425@c39g2000yqi.googlegroups.com> <877C79A4-D07C-48B6-AF91-503122CA0785@gmail.com> <2183E0A5-56B1-4BC5-AF27-4B597218F18D@gmail.com> <704c2777-746b-4d82-b772-71929bb3ddd3@fl7g2000vbb.googlegroups.com> <634C9D72-D1EA-43B1-995E-23EB9F08EB54@gmail.com> Message-ID: cool that did fix it. thanks On Nov 30, 6:34?am, David Chelimsky wrote: > On Nov 29, 2010, at 8:05 PM, Jim Morris wrote: > > > > > Hi David, > > > I am using the current versions of everything rspec > > rspec (2.2.0,) > > rspec-core (2.2.1) > > rspec-expectations (2.2.0) > > rspec-mocks (2.2.0,) > > rspec-rails (2.2.0) > > webrat (0.7.2) > > rails(3.0.3) > > > webrat is in Gemfile... > > > group :test, :development do > > ?gem 'webrat' > > ?gem 'rspec-rails' > > end > > > My spec is meant to be an integration test and as such is in spec/ > > requests > > > I have a pretty simple setup, the full source is here... > > >https://github.com/wolfmanjm/wolfmanblog_rails > > > Thanks for the help, its odd so many people are having issues with > > webrat, should I cross post to their group or is this an rspec/webrat/ > > rails3 issue? > > I'm not sure where the issue is yet (most likely rspec), but I was able to see it by cloning your repo and running the specs. > > I was able to get things to work by moving "include Rack::Test::Methods" into the configure block: > > RSpec.configure do |config| > ? config.include Rack::Test::Methods > ? ... > end > > You should _not_, however, have to do any such thing, so I'll look into it and if I can address this in rspec-rails I will and have a bug-fix release out soon. > > Thanks! > > David > > > > > > > On Nov 29, 2:45 pm, David Chelimsky wrote: > >> On Nov 29, 2010, at 4:44 PM, David Chelimsky wrote: > > >>> On Nov 29, 2010, at 3:28 PM, Jim Morris wrote: > > >>>> Sorry I may have been unclear.... > > >>>> When using the default spec_helper as generated from a fresh > >>>> script/rails generate rspec:install > >>>> I get the error... > > >>>> undefined method `last_response' for > >>>> # > > >>>> This means something is not seeing the Rack Test stuff. > > >>>> The second error is got when I add > > >>>> include Rack::Test::Methods > > >>>> It now sees last_response but doesn't get a respnose from visit (That > >>>> may be a different errror). > > >>>> So bottom line is using the latest rails/rspec/webrat does not work > >>>> out of the box. > > >>> It does for me, so something is different between our configurations. > > >>> Do you have webrat in the Gemfile? > >>> Is this a controller spec? If so is it in the spec/controllers directory? > > >> Also, what version of rspec-rails are we talking about? > > >>>> On Nov 29, 7:18 am, David Chelimsky wrote: > >>>>> On Nov 29, 2010, at 4:58 AM, Jim Morris wrote: > > >>>>>> Ok adding > > >>>>>> include Rack::Test::Methods > > >>>>>> to my spec_helper changed the error to > > >>>>>> ? Failure/Error: visit "/" > >>>>>> ? ?No response yet. Request a page first. > >>>>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rack- > >>>>>> test-0.5.6/lib/rack/mock_session.rb:51:in `last_response' > >>>>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>>>> webrat-0.7.2/lib/webrat/adapters/rack.rb:26:in `response' > >>>>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>>>> webrat-0.7.2/lib/webrat/adapters/rack.rb:14:in `response_body' > >>>>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>>>> webrat-0.7.2/lib/webrat/core/session.rb:176:in `exception_caught?' > >>>>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>>>> webrat-0.7.2/lib/webrat/core/session.rb:121:in `request_page' > >>>>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>>>> webrat-0.7.2/lib/webrat/core/session.rb:217:in `visit' > >>>>>> ? ?# /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ > >>>>>> webrat-0.7.2/lib/webrat/core/methods.rb:7:in `visit' > >>>>>> ? ?# ./spec/requests/basics_spec.rb:5 > > >>>>>> So someone is not including the rack test stuff, however still don;t > >>>>>> know why it is failing > > >>>>> I'd get rid of all of that stuff from spec_helper. It was guidance from a cucumber-rails issue, not an rspec issue, and is unnecessary with rspec. I'd just re-generate it with "script/rails generate rspec:install" > > >>>>> HTH, > >>>>> David > > >>>>>> On Nov 15, 3:36 pm, David Chelimsky wrote: > >>>>>>> On Nov 15, 2010, at 4:51 PM, Peter Havens wrote: > > >>>>>>>> I'm having problems getting rspec-rails 2 request specs to work with > >>>>>>>> webrat. Any help would be appreciated. Here's my setup: > > >>>>>>>> ruby 1.9.2p0 > >>>>>>>> rails 3.0.1 > >>>>>>>> rspec-rails 2.1.0 > >>>>>>>> webrat0.7.2 > > >>>>>>>> Here's the error I'm getting: > > >>>>>>>> $ rspec --backtrace spec/requests/ssl_certificate_requests_spec.rb > >>>>>>>> F > > >>>>>>>> Failures: > >>>>>>>> 1) > >>>>>>>> ? ?Failure/Error: Unable to find matching line from backtrace > >>>>>>>> ? ?stack level too deep > >>>>>>>> ? ?# /opt/local/lib/ruby1.9/1.9.1/forwardable.rb:185 > > >>>>>>>> Finished in 0.49825 seconds > >>>>>>>> 1 example, 1 failure > > >>>>>>>> Here are snippets of my files: > > >>>>>>>> # spec/spec_helper.rb > >>>>>>>> # > >>>>>>>> # The following is based on ?some tips from a cucumber-rails ticket: > >>>>>>>> require "webrat" > >>>>>>>> require "webrat/core/matchers" > > >>>>>>>> include Rack::Test::Methods > >>>>>>>> includeWebrat::Methods > >>>>>>>> includeWebrat::Matchers > > >>>>>>>> Webrat.configure do |config| > >>>>>>>> config.mode = :rack > >>>>>>>> config.open_error_files = false > >>>>>>>> end > > >>>>>>>> # spec/requests/_spec.rb > >>>>>>>> require "spec_helper" > > >>>>>>>> describe "" do > >>>>>>>> it "" do > >>>>>>>> ? visit _path > > >>>>>>>> ? # The following works when uncommented: > >>>>>>>> ? # > >>>>>>>> ? # get _path > >>>>>>>> ? # assert_template '/' > >>>>>>>> end > >>>>>>>> end > > >>>>>>> This is actually awebratissue, but it is reported to rspec-rails andwebrat: > > >>>>>>>https://github.com/rspec/rspec-rails/issues/140https://webrat.lightho... > > >>>>>>>> Thanks, > >>>>>>>> Pete > >>>>>>>> _______________________________________________ > >>>>>>>> rspec-users mailing list > >>>>>>>> rspec-us... at rubyforge.org > >>>>>>>>http://rubyforge.org/mailman/listinfo/rspec-users > > >>>>>>> _______________________________________________ > >>>>>>> rspec-users mailing list > >>>>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > >>>>>> _______________________________________________ > >>>>>> rspec-users mailing list > >>>>>> rspec-us... at rubyforge.org > >>>>>>http://rubyforge.org/mailman/listinfo/rspec-users > > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-us... at rubyforge.org > >>>>http://rubyforge.org/mailman/listinfo/rspec-users > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-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 joliss42 at gmail.com Tue Nov 30 16:35:59 2010 From: joliss42 at gmail.com (Jo Liss) Date: Tue, 30 Nov 2010 22:35:59 +0100 Subject: [rspec-users] RSpec interacting with Test::Unit: weird "is already defined" error In-Reply-To: <4DB47755-13AD-432E-9C5E-1D422B29C11D@gmail.com> References: <453856f595e5cc805e978e8b6a5e19aa@ruby-forum.com> <3b6dbd60cdc02ab73d279bc7ea7b5e59@ruby-forum.com> <4DB47755-13AD-432E-9C5E-1D422B29C11D@gmail.com> Message-ID: On Tue, Nov 30, 2010 at 9:39 PM, David Chelimsky wrote: > Yes, it does, which is why I like to use rspec for the whole thing :) I see... In that case I think I'll go ahead and try migrating all my tests to RSpec. And this ... > https://github.com/glv/rspec-unit ... will definitely help on the way. :) Thanks for the pointer! Jo From itsterry at gmail.com Tue Nov 30 19:13:25 2010 From: itsterry at gmail.com (itsterry) Date: Tue, 30 Nov 2010 16:13:25 -0800 (PST) Subject: [rspec-users] Rspec2 - Absolutely brilliant! (at breaking stuff) - Is there a downgrade path ? Message-ID: <9b5d915c-88b8-4802-b380-d6656b32134f@f20g2000vbc.googlegroups.com> Just installed Rspec2 and noticed an immediate improvement in speed: it broke all 899 passing tests on an important project in a matter of seconds. Sadly, I don't have the time to work my way through the multitude upgrade errors (it's not just one error repeated), so I tried to remove rspec2 and the new rspec-rails and downgrade to the previous version. It didn't work, and I'm still getting the following message when I autospec: ************************************************************ REMOVAL NOTICE: you are using behaviour that has been removed from rspec-2. * The 'autospec' command is no longer supported. * Please use 'autotest' insted. This message will be removed from a future version of rspec. ************************************************************ Running autotest rather than autospec gives the following: Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. I'm proud to be a good little BDD developer: I just don't need an upgrade to give me headaches right now, so.... Does anyone have any idea how to get back to a previous Rspec version so I can work properly again? (Not saying Rspec2 isn't fantastic. I'm sure it is. I'll try to make it work again over the Xmas break, when I have lots of hours free) From raldred at gmail.com Tue Nov 30 19:39:20 2010 From: raldred at gmail.com (Rob Aldred) Date: Wed, 1 Dec 2010 00:39:20 +0000 Subject: [rspec-users] Rspec2 - Absolutely brilliant! (at breaking stuff) - Is there a downgrade path ? In-Reply-To: <9b5d915c-88b8-4802-b380-d6656b32134f@f20g2000vbc.googlegroups.com> References: <9b5d915c-88b8-4802-b380-d6656b32134f@f20g2000vbc.googlegroups.com> Message-ID: maybe just being stupid here but surely your using git or some sort of scm? stash your progress with rspec 2 in another branch then reset your current branch.. $ git reset --hard On 1 December 2010 00:13, itsterry wrote: > Just installed Rspec2 and noticed an immediate improvement in speed: > it broke all 899 passing tests on an important project in a matter of > seconds. > > Sadly, I don't have the time to work my way through the multitude > upgrade errors (it's not just one error repeated), so I tried to > remove rspec2 and the new rspec-rails and downgrade to the previous > version. > > It didn't work, and I'm still getting the following message when I > autospec: > > ************************************************************ > REMOVAL NOTICE: you are using behaviour that has been > removed from rspec-2. > > * The 'autospec' command is no longer supported. > * Please use 'autotest' insted. > > This message will be removed from a future version of rspec. > ************************************************************ > > Running autotest rather than autospec gives the following: > > Autotest style autotest/rails_rspec2 doesn't seem to exist. Aborting. > > > I'm proud to be a good little BDD developer: I just don't need an > upgrade to give me headaches right now, so.... > > Does anyone have any idea how to get back to a previous Rspec version > so I can work properly again? > > > (Not saying Rspec2 isn't fantastic. I'm sure it is. I'll try to make > it work again over the Xmas break, when I have lots of hours free) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jed.schneider at gmail.com Tue Nov 30 23:43:50 2010 From: jed.schneider at gmail.com (Jed Schneider) Date: Tue, 30 Nov 2010 23:43:50 -0500 Subject: [rspec-users] RSpec interacting with Test::Unit: weird "is already defined" error Message-ID: <338696F1-EA23-4002-A18A-479C132B021A@gmail.com> Jo, You may look at shoulda if you want to continue to use test unit but want some of the feel of rspec. Good luck Jed Sent from my iPad From elitwin at rocketmail.com Mon Nov 29 14:32:35 2010 From: elitwin at rocketmail.com (E. Litwin) Date: Mon, 29 Nov 2010 11:32:35 -0800 (PST) Subject: [rspec-users] Routes are not recognized in request specs after upgrading to 2.2 Message-ID: I'm getting undefined local variable or method `users_path' (as an example) my request spec tests after upgrading to 2.2.0 from 2.1.0. I haven't really changed these tests from the generated code but am curious as to why they are failing now. require 'spec_helper' describe "Users" do describe "GET /users" do it "works! (now write some real specs)" do get users_path end end end I followed the upgrade steps to regenerate spec_helper.rb (it was identical), so I'm not sure what I am missing. From elitwin at rocketmail.com Mon Nov 29 15:24:07 2010 From: elitwin at rocketmail.com (E. Litwin) Date: Mon, 29 Nov 2010 12:24:07 -0800 (PST) Subject: [rspec-users] Routes are not recognized in request specs after upgrading to 2.2 Message-ID: <377a1fd1-7135-41cc-a4eb-3cc77b6e5bce@p7g2000prb.googlegroups.com> I'm getting undefined local variable or method `users_path' (as an example) my request spec tests after upgrading to 2.2.0 from 2.1.0. I haven't really changed these tests from the generated code but am curious as to why they are failing now. require 'spec_helper' describe "Users" do describe "GET /users" do it "works! (now write some real specs)" do get users_path end end end I followed the upgrade steps to regenerate spec_helper.rb (it was identical), so I'm not sure what I am missing. From info at cardeo.ca Sun Nov 28 23:45:41 2010 From: info at cardeo.ca (cardeo) Date: Sun, 28 Nov 2010 20:45:41 -0800 (PST) Subject: [rspec-users] rspec: command not found In-Reply-To: References: Message-ID: <30327731.post@talk.nabble.com> I'm having a similar problem. Marnen Laibow-Koser-2 wrote: > > I am new to ROR. Trying to going through tutorial, but couldn't run > rspec (command not found). Everything was installed as directed. > Search the hold drive, found spec file and spec.bat in the following > directories > > ./usr/lib/ruby/lib/ruby/gems/1.8/bin/rspec > ./usr/lib/ruby/lib/ruby/gems/1.8/bin/rspec.bat > > ./usr/lib/ruby/lib/ruby/gems/1.8/gems/rspec-core-2.0.1/bin/rspec > > abstract (1.0.0) > actionmailer (3.0.1) > actionpack (3.0.1) > activemodel (3.0.1) > activerecord (3.0.1) > activeresource (3.0.1) > activesupport (3.0.1) > arel (1.0.1) > autotest (4.4.2, 4.3.2) > autotest-growl (0.2.6) > autotest-notification (2.3.1) > autotest-rails-pure (4.1.0) > builder (2.1.2) > bundler (1.0.3) > configuration (1.1.0) > diff-lcs (1.1.2) > erubis (2.6.6) > heroku (1.12.1) > i18n (0.4.2) > json_pure (1.4.6) > launchy (0.3.7) > mail (2.2.9) > mime-types (1.16) > mysql (2.8.1 x86-mingw32) > nokogiri (1.4.3.1 x86-mingw32) > polyglot (0.3.1) > rack (1.2.1) > rack-mount (0.6.13) > rack-test (0.5.6) > rails (3.0.1) > railties (3.0.1) > rake (0.8.7) > rest-client (1.6.1) > rspec (2.0.1) > rspec-core (2.0.1) > rspec-expectations (2.0.1) > rspec-mocks (2.0.1) > rspec-rails (2.0.1) > sequel (3.15.0) > sinatra (1.0) > sys-uname (0.8.4 x86-mingw32) > taps (0.3.13) > thor (0.14.4, 0.14.3) > treetop (1.4.8) > tzinfo (0.3.23) > webrat (0.7.1) > zentest-without-autotest (4.4.0) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://old.nabble.com/rspec%3A-command-not-found-tp30143653p30327731.html Sent from the rspec-users mailing list archive at Nabble.com. From raldred at gmail.com Tue Nov 30 07:10:15 2010 From: raldred at gmail.com (Rob Aldred) Date: Tue, 30 Nov 2010 04:10:15 -0800 (PST) Subject: [rspec-users] Testing html email content with have_selector rspec2 rails3 fails Message-ID: Previously on rails 2.x I have been able to test the content of my html actionmailer emails. In rspec 1.x: @mailer = OrderMailer.create_receipt(@order) @mailer.body.should have_tag('.order_number') @mailer.body.should have_tag('.billing_address') @mailer.body.should have_tag('.delivery_address') I have changed to rspec 2.x style @mailer = OrderMailer.receipt(@order) @body = @mailer.encoded @body.should have_tag('.order_number') @body.should have_tag('.billing_address') @body.should have_tag('.delivery_address') It fails. I suspect theres something else that have_tag was doing that have_selector is not? Am I doing something wrong? Is there a better way to tests the content of my emails? Maybe I should never have tested email content this way, is it more a job for cucumber? Look forward to your responses. Thanks Rob From bradleyrobertson at gmail.com Tue Nov 30 12:31:42 2010 From: bradleyrobertson at gmail.com (Bradley) Date: Tue, 30 Nov 2010 09:31:42 -0800 (PST) Subject: [rspec-users] Getting color to work with jruby Message-ID: <9613e4be-f05e-4aa1-af99-75a5b941d25c@z17g2000prz.googlegroups.com> I'm having issues getting color to work when I'm running my tests. I'm writing a gem and using RSpec 2.1.0. I'm using JRuby-1.5.3 installed by RVM on OSX10.6 I have a rake task defined like so: Rspec::Core::RakeTask.new(:spec) do |spec| spec.pattern = "spec/**/*_spec.rb" spec.rspec_opts = ['--color', '--format documentation'] end when I run `rake spec` I can see those opts being passed in: > /Users/bradrobertson/.rvm/rubies/jruby-1.5.3/bin/jruby -S bundle exec rspec --color --format documentation "spec/modesl/some_mode.rb" ... # other files but I get no color :( I also just realized that running it with MRI 1.9.2 does give me color, so maybe this belongs in the JRuby forum... but for now, does anyone know of something needed to get JRuby to output color? From iparips at gmail.com Tue Nov 30 23:48:54 2010 From: iparips at gmail.com (Ilya P.) Date: Tue, 30 Nov 2010 20:48:54 -0800 (PST) Subject: [rspec-users] [rspec-rails] Configuring which ExampleGroup gets instantiated Message-ID: <7df43337-0a69-4fb8-8c46-e7010a8bac6c@i25g2000prd.googlegroups.com> Hi all, I've spent a fair bit of time googling but couldn't find the answer to this question. Any insight would be greatly appreciated. Basically I'm specking my ActionMailer instance & I would like to use ControllerExampleGroup's method assigns(). How can I specify which type of ExampleGroup rspec instantiates when I call describe() in my spec? My understanding is rspec-rails determines which type of ExampleGroup to instantiate based on the directories that the specs are in. For example it instantiates a ModelExampleGroup for specs in models/, or ControllerExampleGroup for specs in controllers/. Is there a way to specify the type of example group that gets instantiated regardless of the directory the specs are in? I recall that at some point in past I could supply a :type =>:controller parameter to describe() method. I tried doing that for my mailer spec but the example group I got was still RSpec::Core::ExampleGroup. Here is what I am using: ruby 1.9 rails 3.0.1 rspec 2.0.1 rspec-rails 2.0.1 Thanks a lot, Ilya.