From pergesu at gmail.com Mon Jan 1 03:47:53 2007 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 1 Jan 2007 01:47:53 -0700 Subject: [rspec-users] Validations based on associations Message-ID: <810a540e0701010047o49fa5f04ucac203b68aecb08e@mail.gmail.com> My model is very simple, it's mostly just a join table that represents which tournaments a user has registered for. class Registration < ActiveRecord::Base belongs_to :user belongs_to :tournament validates_presence_of :user_id, :tournament_id validates_uniqueness_of :user_id, :scope => :tournament_id end the validates_uniqueness checks to make sure there's no record that has the same user_id and tournament_id. Is there a relatively easy way to specify this behavior? The only way that I know is to do something like context "A Registration with a User and Tournament" do setup do @user = User.new @user.save false @tournament = Tournament.new @tournament.save false @reg = Registration.new(:user => @user, :tournament => @tournament) end specify "should be valid" do @reg.should_be_valid end specify "should not be valid if a registration with the same details already exists" do @reg.save Registration.new(:user => @user, :tournament => @tournament).should_not_be_valid end end Well actually that's obviously pretty easy :) Is it bad that I'm tied to the implementations of User and Tournament at all? ActiveRecord dictates that, so I guess it's not a problem to have that in my spec at all. Anyway this is just the spec I came up with and I'm wondering if anyone else has a better idea. Pat From pergesu at gmail.com Mon Jan 1 03:49:03 2007 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 1 Jan 2007 01:49:03 -0700 Subject: [rspec-users] Validations based on associations In-Reply-To: <810a540e0701010047o49fa5f04ucac203b68aecb08e@mail.gmail.com> References: <810a540e0701010047o49fa5f04ucac203b68aecb08e@mail.gmail.com> Message-ID: <810a540e0701010049j755b0304m4d3b8a495f8ac5f9@mail.gmail.com> oh, I forgot to say that the @user.save(false) means that the user object gets saved but skips validation. That's a quick way of not having to create a completely valid user object that may become out of date as you change the User model. and happy new year everyone! Pat From pergesu at gmail.com Mon Jan 1 04:05:02 2007 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 1 Jan 2007 02:05:02 -0700 Subject: [rspec-users] Another "how do I spec this?" Message-ID: <810a540e0701010105sb5610e2t1c3c7d94da67fe54@mail.gmail.com> I wanted to add a convenience method on my User class to see if he was already signed up for a tournament. Here's my spec context "A User signed up for one tournament" do setup do @t1 = Tournament.new @t1.save false @t2 = Tournament.new @t2.save false @user = User.new @user.save false @user.registrations << Registration.new(:tournament => @t1) end specify "should be signed up for that tournament" do @user.should_be_signed_up_for @t1 end specify "should not be signed up for another tournament" do @user.should_not_be_signed_up_for @t2 end end class User < ActiveRecord::Base has_many :registrations def signed_up_for?(tournament) !registrations.find_by_tournament_id(tournament).nil? end end Are there any potential improvements, or is that the best way to spec it? Pat From dchelimsky at gmail.com Mon Jan 1 08:33:57 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Jan 2007 08:33:57 -0500 Subject: [rspec-users] Validations based on associations In-Reply-To: <810a540e0701010049j755b0304m4d3b8a495f8ac5f9@mail.gmail.com> References: <810a540e0701010047o49fa5f04ucac203b68aecb08e@mail.gmail.com> <810a540e0701010049j755b0304m4d3b8a495f8ac5f9@mail.gmail.com> Message-ID: <57c63afe0701010533m4d9bc67ei7b244ab58a1d7de3@mail.gmail.com> On 1/1/07, Pat Maddox wrote: > oh, I forgot to say that the @user.save(false) means that the user > object gets saved but skips validation. That's a quick way of not > having to create a completely valid user object that may become out of > date as you change the User model. That's the kind of stuff you should be blogging! Very useful tip. Thanks Pat. > > and happy new year everyone! You too! David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jan 1 09:07:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Jan 2007 09:07:18 -0500 Subject: [rspec-users] Validations based on associations In-Reply-To: <810a540e0701010047o49fa5f04ucac203b68aecb08e@mail.gmail.com> References: <810a540e0701010047o49fa5f04ucac203b68aecb08e@mail.gmail.com> Message-ID: <57c63afe0701010607m3bcab306k761a8a3156b1e0ec@mail.gmail.com> On 1/1/07, Pat Maddox wrote: > My model is very simple, it's mostly just a join table that represents > which tournaments a user has registered for. > > class Registration < ActiveRecord::Base > belongs_to :user > belongs_to :tournament > > validates_presence_of :user_id, :tournament_id > validates_uniqueness_of :user_id, :scope => :tournament_id > end > > the validates_uniqueness checks to make sure there's no record that > has the same user_id and tournament_id. > > Is there a relatively easy way to specify this behavior? The only way > that I know is to do something like > > context "A Registration with a User and Tournament" do > setup do > @user = User.new > @user.save false > @tournament = Tournament.new > @tournament.save false > @reg = Registration.new(:user => @user, :tournament => @tournament) > end > > specify "should be valid" do > @reg.should_be_valid > end > > specify "should not be valid if a registration with the same details > already exists" do > @reg.save > Registration.new(:user => @user, :tournament => > @tournament).should_not_be_valid > end > end Geez, ActiveRecord models are SUCH a violation of SRP! I realize that this is the rails way, and that there are great productivity benefits we glean from AR, but having a model that validates both at both the instance level (validates_presence_of) and the class level (validates_uniqueness_of) is a pain in the ass. It's confusing because both sorts of validations look the same, but they are really fundamentally different. Ranting aside, there are a couple of different ways you can view this. To be the most clear, I'd probably spec the class level validations separately from instance level validations. The uniqueness spec might look like this: context "The Registration model class" do setup do @user1 = User.new @user2 = User.new @tournament = Tournament.new [@user1, @user2, @tournament].each {|model| model.save(false)} end specify "should permit registrations with different users" do Registration.create(:user => @user1, :tournament => @tournament) Registration.new(:user => @user2, :tournament => @tournament).should_be_valid end specify "should deny multiple registrations with the same user" do Registration.create(:user => @user1, :tournament => @tournament) Registration.new(:user => @user1, :tournament => @tournament).should_not_be_valid end end WDYT? > > Well actually that's obviously pretty easy :) Is it bad that I'm tied > to the implementations of User and Tournament at all? ActiveRecord > dictates that, so I guess it's not a problem to have that in my spec > at all. > > Anyway this is just the spec I came up with and I'm wondering if > anyone else has a better idea. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jan 1 09:16:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 1 Jan 2007 09:16:05 -0500 Subject: [rspec-users] Another "how do I spec this?" In-Reply-To: <810a540e0701010105sb5610e2t1c3c7d94da67fe54@mail.gmail.com> References: <810a540e0701010105sb5610e2t1c3c7d94da67fe54@mail.gmail.com> Message-ID: <57c63afe0701010616x15c2e61rca9a2459d0ddd548@mail.gmail.com> On 1/1/07, Pat Maddox wrote: > I wanted to add a convenience method on my User class to see if he was > already signed up for a tournament. Here's my spec > > context "A User signed up for one tournament" do > setup do > @t1 = Tournament.new > @t1.save false > @t2 = Tournament.new > @t2.save false > @user = User.new > @user.save false > @user.registrations << Registration.new(:tournament => @t1) > end > > specify "should be signed up for that tournament" do > @user.should_be_signed_up_for @t1 > end > > specify "should not be signed up for another tournament" do > @user.should_not_be_signed_up_for @t2 > end > end > > class User < ActiveRecord::Base > has_many :registrations > > def signed_up_for?(tournament) > !registrations.find_by_tournament_id(tournament).nil? > end > end > > Are there any potential improvements, or is that the best way to spec it? Couple of thoughts. Creating new unvalidated models seems to be something useful, so... module ModelSpecUtils def unvalidated_model(klass) model = klass.new model.save(false) model end end Also, this line: @user.registrations << Registration.new(:tournament => @t1) is breaking encapsulation a bit. Given that and the utility module above, I might end up w/ something like this: context "A User signed up for one tournament" do include ModelSpecUtils setup do @tournament1 = unvalidated_model(Tournament) @tournament2 = unvalidated_model(Tournament) @user = unvalidated_model(User) @user.register_for(@tournament1) end specify "should be signed up for that tournament" do @user.should_be_signed_up_for @tournament1 end specify "should not be signed up for another tournament" do @user.should_not_be_signed_up_for @tournament2 end end David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lastobelus at mac.com Mon Jan 1 21:46:47 2007 From: lastobelus at mac.com (Michael Johnston) Date: Mon, 1 Jan 2007 18:46:47 -0800 Subject: [rspec-users] rspec_autotest no longer re-runs tests with rspec 0.7.5 In-Reply-To: <4232AA34-F6EC-42BE-A6D9-044F05D29149@mac.com> References: <4FF77DF8-CDB3-466D-AC16-925BB4842491@mac.com> <4232AA34-F6EC-42BE-A6D9-044F05D29149@mac.com> Message-ID: <2E2973DA-BE37-4849-B277-1BF6F479F906@mac.com> Ok I just took the time to figure this out. It should have been obvious to me: turning on redgreen breaks the regex in "handle_results" which should create an array of failed tests because the color codes that are added to the result string. I discovered it was also mildly broken without color, because the second term in the regex needs to be made non greedy, or it matches everything after the first error. But because of the way this is used, I don't think this would make much (any) difference to the functioning of autotest. Anyway, so here is the diff with the regex for handle_results function of rspec_autotest that works with redgreen turned on (and with spec command changed to use the rails_spec_server): Index: lib/rspec_autotest.rb =================================================================== --- lib/rspec_autotest.rb (revision 45) +++ lib/rspec_autotest.rb (working copy) @@ -26,7 +26,7 @@ attr_accessor :spec_command def initialize # :nodoc: - @spec_command = "spec --diff unified" + @spec_command = "script/rails_spec -C --diff unified" super @exceptions = %r%^\./(?:coverage|db|doc|log|public|script|vendor)% end @@ -76,7 +76,7 @@ end def handle_results(results) - failed = results.scan(/^\d+\)\n(?:.*?Error in )?'([^']*?)'(?: FAILED)?\n(.*)\n\n/m) + failed = results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^']*?)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m) @files_to_test = consolidate_failures failed unless @files_to_test.empty? then hook :red On 30-Dec-06, at 4:46 AM, Michael Johnston wrote: > That is what I meant. In my setup, it is NOT rerunning the whole > suite after I fix a failing spec. > > After a cursory look at autotest.rb in ZenTest, I haven't figured > out why it is broken. But I think I will try to figure that out > today, because autotest seems kind of pointless without that > behaviour. > > It probably has nothing to do with rspec or rspec_autotest; I > realized that my version of ZenTest is new too, 3.4.3 instead of > 3.4.1. > > Cheers, > Michael > On 21-Dec-06, at 11:13 AM, Nick Sieger wrote: > >> On 12/21/06, Michael Johnston wrote: >> Has anyone else encountered this problem? >> >> What I mean is, rspec_autotest runs all specs, then waits. When you >> change a spec, it reruns that spec. However, if that spec now passes, >> it should run the whole suite again, so you can see the next one to >> work on. It no longer does this. This renders it somewhat useless. >> >> Does anyone have autotest working with rspec 0.7.5, or does anyone >> have any idea of what may be causing this issue or how to go about >> fixing it? >> >> Are you sure this is caused by the 0.7.5 upgrade? I've seen >> similar behavior but I'm still on 0.7.3. Here's the response >> comment I posted to yours: >> >> I think this is expected behavior for autotest ? I've already >> noticed this and assumed it was standard behavior. The only time >> autotest reruns the whole suite is after I've just fixed a failing >> test or spec. Is it possible that's what you're observing? >> >> Feel free to take any further discussion off-list, thanks. >> >> /Nick >> _______________________________________________ >> 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: http://rubyforge.org/pipermail/rspec-users/attachments/20070101/f0575b74/attachment.html From yrashk at gmail.com Mon Jan 1 22:19:23 2007 From: yrashk at gmail.com (Yurii Rashkovskii) Date: Tue, 2 Jan 2007 05:19:23 +0200 Subject: [rspec-users] acts_as_authenticated plugin rspecs Message-ID: Hello, Just thought it could be interesting for some of you. I've written rspecs for acts_as_authenticated plugin. http://rashkovskii.com/articles/2007/01/01/rspec-on-rails- acts_as_authenticated I'm not sure they are 100% ok, but they seem to be :) Thank you, Yurii. From nicksieger at gmail.com Tue Jan 2 11:03:52 2007 From: nicksieger at gmail.com (Nick Sieger) Date: Tue, 2 Jan 2007 10:03:52 -0600 Subject: [rspec-users] rspec_autotest no longer re-runs tests with rspec 0.7.5 In-Reply-To: <2E2973DA-BE37-4849-B277-1BF6F479F906@mac.com> References: <4FF77DF8-CDB3-466D-AC16-925BB4842491@mac.com> <4232AA34-F6EC-42BE-A6D9-044F05D29149@mac.com> <2E2973DA-BE37-4849-B277-1BF6F479F906@mac.com> Message-ID: On 1/1/07, Michael Johnston wrote: > > Ok I just took the time to figure this out. It should have been obvious to > me: turning on redgreen breaks the regex in "handle_results" which should > create an array of failed tests because the color codes that are added to > the result string. > I discovered it was also mildly broken without color, because the second > term in the regex needs to be made non greedy, or it matches everything > after the first error. But because of the way this is used, I don't think > this would make much (any) difference to the functioning of autotest. > > Anyway, so here is the diff with the regex for handle_results function of > rspec_autotest that works with redgreen turned on (and with spec command > changed to use the rails_spec_server): > > Index: lib/rspec_autotest.rb > =================================================================== > --- lib/rspec_autotest.rb (revision 45) > +++ lib/rspec_autotest.rb (working copy) > @@ -26,7 +26,7 @@ > attr_accessor :spec_command > def initialize # :nodoc: > - @spec_command = "spec --diff unified" > + @spec_command = "script/rails_spec -C --diff unified" > super > @exceptions = %r%^\./(?:coverage|db|doc|log|public|script|vendor)% > end > @@ -76,7 +76,7 @@ > end > def handle_results(results) > - failed = results.scan(/^\d+\)\n(?:.*?Error in )?'([^']*?)'(?: > FAILED)?\n(.*)\n\n/m) > + failed = results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in > )?'([^']*?)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m) > @files_to_test = consolidate_failures failed > unless @files_to_test.empty? then > hook :red > Thanks Michael, I committed a slightly modified version of the regex. I didn't commit the change to @spec_command because you can easily customize this for yourself by putting a hook in your ~/.autotest: Autotest.add_hook :initialize do |at| if at.respond_to? :spec_command at.spec_command = "script/rails_spec -C --diff unified" end end Cheers, /Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070102/1e08b634/attachment.html From cwdinfo at gmail.com Wed Jan 3 11:57:44 2007 From: cwdinfo at gmail.com (s.ross) Date: Wed, 3 Jan 2007 08:57:44 -0800 Subject: [rspec-users] 0.7.5 Doesn't Let My Tests Run Message-ID: <9EB5B084-7D7E-4765-B36E-FEC9E52ACCD5@gmail.com> The tests are all running on 0.7.4. In installed 0.7.5 as follows: - sudo gem install rspec - script/plugin install svn://rubyforge.org/var/svn/rspec/tags/ REL_0_7_5_/vendor/rspec_on_rails/vendor/plugins/rspec - script/generate rspec ZenTest (3.4.1) is also installed. Here is what happens when I run the same tests that ran on 0.7.4. (By the way, Rails is build 5065). Any help is appreciated. $ rake spec (in /Users/minime/rails/voodoo_work) /opt/local/bin/ruby -I"/opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/ lib" "/opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/bin/spec" "spec/ models/cart_spec.rb" /Users/minime/rails/voodoo_work/config/../vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:349:in `const_missing': uninitialized constant Spec::RailsPlugin::ResponseBody::TagExpectations (NameError) from /Users/minime/rails/voodoo_work/vendor/plugins/vendor/ plugins/rspec/lib/spec/rails_plugin/response_body.rb:4 from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `gem_original_require' from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `require' from /Users/minime/rails/voodoo_work/config/../vendor/rails/ activerecord/lib/../../activesupport/lib/active_support/ dependencies.rb:364:in `require' from /Users/minime/rails/voodoo_work/config/../vendor/ plugins/vendor/plugins/rspec/lib/rspec_on_rails.rb:16 from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `gem_original_require' from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `require' from /Users/minime/rails/voodoo_work/config/../vendor/rails/ activerecord/lib/../../activesupport/lib/active_support/ dependencies.rb:364:in `require' from ./spec/models/../spec_helper.rb:3 from ./spec/models/cart_spec.rb:1:in `require' from ./spec/models/cart_spec.rb:1 from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/command_line.rb:21:in `load' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/command_line.rb:21:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/command_line.rb:15:in `each' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/command_line.rb:15:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/bin/spec:4 From listaccount at e-tobi.net Thu Jan 4 18:03:36 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Fri, 05 Jan 2007 00:03:36 +0100 Subject: [rspec-users] Common setup code and naming specifications Message-ID: <459D87C8.1010300@e-tobi.net> Hello! I have a lot of contexts for testing Rails controllers, that must do something like 'session[:logged_in] = true' in their setup. How can this be refactored? In unit tests I would simply create a LoggedInControllerTest base class, that all my functional tests would derive from. And another small question: In my controller specifications I often have to decide whether to write: specify "should provide the first ten items in @items and three pages in @pages when passing no :page parameter to the :list action" or specify "should provide the first ten items and three pages when not selecting a specific page" So the decision is, whether to explicitly name parameters, return values and actions or to use a more abstract phrase. How do you handle this? Sorry, might be a stupid question, but I'm, still trying to get the right "feeling" for BDD-style testing. bye, Tobias From dchelimsky at gmail.com Thu Jan 4 18:12:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Jan 2007 18:12:18 -0500 Subject: [rspec-users] Common setup code and naming specifications In-Reply-To: <459D87C8.1010300@e-tobi.net> References: <459D87C8.1010300@e-tobi.net> Message-ID: <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> On 1/4/07, Tobias Grimm wrote: > Hello! > > I have a lot of contexts for testing Rails controllers, that must do > something like 'session[:logged_in] = true' in their setup. How can this > be refactored? In unit tests I would simply create a > LoggedInControllerTest base class, that all my functional tests would > derive from. module MyHelpers def set_logged_in session[:logged_in] = true end end context "..." do include MyHelpers setup do set_logged_in end end > > And another small question: > > In my controller specifications I often have to decide whether to write: > > specify "should provide the first ten items in @items and three pages in > @pages when passing no :page parameter to the :list action" > > or > > specify "should provide the first ten items and three pages when not > selecting a specific page" Definitely the latter. These names should be how the customer would talk about requirements, not how developers would - UNLESS you're writing a framework for developers and developers ARE your customers. David > So the decision is, whether to explicitly name parameters, return values > and actions or to use a more abstract phrase. How do you handle this? > Sorry, might be a stupid question, but I'm, still trying to get the > right "feeling" for BDD-style testing. > > bye, > > Tobias > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bob.cotton at rallydev.com Thu Jan 4 18:34:14 2007 From: bob.cotton at rallydev.com (Bob Cotton) Date: Thu, 04 Jan 2007 16:34:14 -0700 Subject: [rspec-users] Common setup code and naming specifications In-Reply-To: <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> (David Chelimsky's message of "Thu, 4 Jan 2007 18:12:18 -0500") References: <459D87C8.1010300@e-tobi.net> <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> Message-ID: "David Chelimsky" writes: > On 1/4/07, Tobias Grimm wrote: >> Hello! >> >> I have a lot of contexts for testing Rails controllers, that must do >> something like 'session[:logged_in] = true' in their setup. How can this >> be refactored? In unit tests I would simply create a >> LoggedInControllerTest base class, that all my functional tests would >> derive from. > > module MyHelpers > def set_logged_in > session[:logged_in] = true > end > end > > context "..." do > include MyHelpers > setup do > set_logged_in > end > end > What about: module LoggedIn def setup session[:logged_in] = true end end context "..." do include LoggedIn end A little less typing, and just as clear. -Bob >> >> And another small question: >> >> In my controller specifications I often have to decide whether to write: >> >> specify "should provide the first ten items in @items and three pages in >> @pages when passing no :page parameter to the :list action" >> >> or >> >> specify "should provide the first ten items and three pages when not >> selecting a specific page" > > Definitely the latter. These names should be how the customer would > talk about requirements, not how developers would - UNLESS you're > writing a framework for developers and developers ARE your customers. > > David > >> So the decision is, whether to explicitly name parameters, return values >> and actions or to use a more abstract phrase. How do you handle this? >> Sorry, might be a stupid question, but I'm, still trying to get the >> right "feeling" for BDD-style testing. >> >> bye, >> >> Tobias >> >> _______________________________________________ >> 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 -- Bob Cotton Test Architect -- Rally Software -- rallydev.com http://www.testarchitecture.com/blog From listaccount at e-tobi.net Thu Jan 4 19:15:38 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Fri, 05 Jan 2007 01:15:38 +0100 Subject: [rspec-users] Common setup code and naming specifications In-Reply-To: <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> References: <459D87C8.1010300@e-tobi.net> <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> Message-ID: <459D98AA.3050003@e-tobi.net> Thanks for your fast response! David Chelimsky wrote: > context "..." do > include MyHelpers > setup do > set_logged_in > end > end > Ok, but this still requires me to call set_logged_in in 99% of my controller contexts. I can live with it, but it tastes like evil duplication. >> specify "should provide the first ten items in @items and three pages in >> @pages when passing no :page parameter to the :list action" >> >> specify "should provide the first ten items and three pages when not >> selecting a specific page" >> > > Definitely the latter. These names should be how the customer would > talk about requirements, not how developers would - UNLESS you're > writing a framework for developers and developers ARE your customers. > Fine - sounds reasonable! But sometimes it's hard to see, whether you are working on a framework or not. If I'm at a controller, it's not only the customer who uses it in some way, it's also the view. And the view needs to call :list and pass :page and expects to get @items and @pages. The second of the two specifications above tells nothing about how the view should interact with the controller. Tobias From bryan at osesm.com Thu Jan 4 19:16:18 2007 From: bryan at osesm.com (Bryan Liles) Date: Thu, 4 Jan 2007 19:16:18 -0500 Subject: [rspec-users] Common setup code and naming specifications In-Reply-To: References: <459D87C8.1010300@e-tobi.net> <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> Message-ID: On Jan 4, 2007, at 6:34 PM, Bob Cotton wrote: > > What about: > > module LoggedIn > def setup > session[:logged_in] = true > end > end > > context "..." do > include LoggedIn > end > With this method, don't you lose access to setup? Seems like a lot to lose just to gain a a login mixin. From bryan at osesm.com Thu Jan 4 21:05:39 2007 From: bryan at osesm.com (Bryan Liles) Date: Thu, 4 Jan 2007 21:05:39 -0500 Subject: [rspec-users] RSpec 0.7.5 with Rails and rcov Message-ID: I seem to be missing something because I am at a loss on how to get rcov, RSpec, and Rails working together. Would someone mind dropping some hints? From dchelimsky at gmail.com Thu Jan 4 22:05:02 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Jan 2007 22:05:02 -0500 Subject: [rspec-users] Common setup code and naming specifications In-Reply-To: <459D98AA.3050003@e-tobi.net> References: <459D87C8.1010300@e-tobi.net> <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> <459D98AA.3050003@e-tobi.net> Message-ID: <57c63afe0701041905sd54b02ew48492c89b3205d11@mail.gmail.com> On 1/4/07, Tobias Grimm wrote: > Thanks for your fast response! > > David Chelimsky wrote: > > context "..." do > > include MyHelpers > > setup do > > set_logged_in > > end > > end > > > > Ok, but this still requires me to call set_logged_in in 99% of my > controller contexts. I can live with it, but it tastes like evil > duplication. Ah, the DRY battle cry. There is a difference between duplication of code and duplicated calls to a no-arg method. While typing the call to set_logged_in may require a few extra strokes, the meaning of it will never change in different contexts. So the risks associated w/ code duplication are mitigated. In fact, the real risk is that you might change its one and only meaning, in which case you'd have to look at each case and decide if the new meaning makes sense. That problem wouldn't go away if you could subclass contexts. In fact, it would be more sinister because the behaviour is implicit. At least if you look at set_logged_in in each context you have some sense of what it means. There is also a difference between duplication in code and duplication in tests. Jay Fields put it very well when he put it this way: test are inherently procedural. The risk of duplication in code is that when you have to change it in one place you'll miss the other place. That risk doesn't really apply to this situation. Alternatively, you could figure out a way to subclass contexts and not be able to look at a given context and understand why the user keeps on ending up logged in. My only slightly solicited 2 cents. > > >> specify "should provide the first ten items in @items and three pages in > >> @pages when passing no :page parameter to the :list action" > >> > >> specify "should provide the first ten items and three pages when not > >> selecting a specific page" > >> > > > > Definitely the latter. These names should be how the customer would > > talk about requirements, not how developers would - UNLESS you're > > writing a framework for developers and developers ARE your customers. > > > > Fine - sounds reasonable! But sometimes it's hard to see, whether you > are working on a framework or not. If I'm at a controller, it's not only > the customer who uses it in some way, it's also the view. And the view > needs to call :list and pass :page and expects to get @items and @pages. > The second of the two specifications above tells nothing about how the > view should interact with the controller. Excellent point. There's no simple answer for this. Your best bet is to keep throwing examples at us and we can discuss them more explicitly. Cheers, David > Tobias > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bob.cotton at rallydev.com Thu Jan 4 22:42:48 2007 From: bob.cotton at rallydev.com (Bob Cotton) Date: Thu, 04 Jan 2007 20:42:48 -0700 Subject: [rspec-users] Common setup code and naming specifications In-Reply-To: (Bryan Liles's message of "Thu, 4 Jan 2007 19:16:18 -0500") References: <459D87C8.1010300@e-tobi.net> <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> Message-ID: Bryan Liles writes: > On Jan 4, 2007, at 6:34 PM, Bob Cotton wrote: > >> >> What about: >> >> module LoggedIn >> def setup >> session[:logged_in] = true >> end >> end >> >> context "..." do >> include LoggedIn >> end >> > > With this method, don't you lose access to setup? Seems like a lot > to lose just to gain a a login mixin. Sorry, LoggedIn should have been a class: class One def setup puts "in setup one" end end context "context with inherit" do inherit One setup do puts "in context setup" end specify "some specify" do puts "in specify" end end $ spec foo_spec..rb in setup one in context setup in specify . I do agree with David, that some duplication in test code is ok. It would be easy to get the LoggedIn class buried up the inheritance hierarchy where it can't be seen. But if it's the only superclass of the context, and it's visible, and it named correctly, this will save you some typing. -Bob -- Bob Cotton Test Architect -- Rally Software -- rallydev.com http://www.testarchitecture.com/blog From dchelimsky at gmail.com Thu Jan 4 22:50:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Jan 2007 22:50:01 -0500 Subject: [rspec-users] Common setup code and naming specifications In-Reply-To: References: <459D87C8.1010300@e-tobi.net> <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> Message-ID: <57c63afe0701041950r693df98n4edbadda42837567@mail.gmail.com> On 1/4/07, Bob Cotton wrote: > Bryan Liles writes: > > > On Jan 4, 2007, at 6:34 PM, Bob Cotton wrote: > > > >> > >> What about: > >> > >> module LoggedIn > >> def setup > >> session[:logged_in] = true > >> end > >> end > >> > >> context "..." do > >> include LoggedIn > >> end > >> > > > > With this method, don't you lose access to setup? Seems like a lot > > to lose just to gain a a login mixin. > > Sorry, LoggedIn should have been a class: > > class One > def setup > puts "in setup one" > end > end > > context "context with inherit" do > inherit One > > setup do > puts "in context setup" > end > > specify "some specify" do > puts "in specify" > end > end > > $ spec foo_spec..rb > > in setup one > in context setup > in specify > . > > > I do agree with David, that some duplication in test code is ok. It > would be easy to get the LoggedIn class buried up the inheritance > hierarchy where it can't be seen. > > But if it's the only superclass of the context, and it's visible, and > it named correctly, this will save you some typing. Great idea - but unfortunately we already use "inherit" in all of the rails contexts. That's ultimately how we're able to tap into Test::Unit::TestCase to take advantage of fixture loading, etc. > > -Bob > > -- > Bob Cotton > Test Architect -- Rally Software -- rallydev.com > http://www.testarchitecture.com/blog > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Thu Jan 4 23:22:22 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 4 Jan 2007 21:22:22 -0700 Subject: [rspec-users] Validations based on associations In-Reply-To: <57c63afe0701010607m3bcab306k761a8a3156b1e0ec@mail.gmail.com> References: <810a540e0701010047o49fa5f04ucac203b68aecb08e@mail.gmail.com> <57c63afe0701010607m3bcab306k761a8a3156b1e0ec@mail.gmail.com> Message-ID: <810a540e0701042022r4cc726e7p842e595e76c934a@mail.gmail.com> On 1/1/07, David Chelimsky wrote: > On 1/1/07, Pat Maddox wrote: > > My model is very simple, it's mostly just a join table that represents > > which tournaments a user has registered for. > > > > class Registration < ActiveRecord::Base > > belongs_to :user > > belongs_to :tournament > > > > validates_presence_of :user_id, :tournament_id > > validates_uniqueness_of :user_id, :scope => :tournament_id > > end > > > > the validates_uniqueness checks to make sure there's no record that > > has the same user_id and tournament_id. > > > > Is there a relatively easy way to specify this behavior? The only way > > that I know is to do something like > > > > context "A Registration with a User and Tournament" do > > setup do > > @user = User.new > > @user.save false > > @tournament = Tournament.new > > @tournament.save false > > @reg = Registration.new(:user => @user, :tournament => @tournament) > > end > > > > specify "should be valid" do > > @reg.should_be_valid > > end > > > > specify "should not be valid if a registration with the same details > > already exists" do > > @reg.save > > Registration.new(:user => @user, :tournament => > > @tournament).should_not_be_valid > > end > > end > > Geez, ActiveRecord models are SUCH a violation of SRP! I realize that > this is the rails way, and that there are great productivity benefits > we glean from AR, but having a model that validates both at both the > instance level (validates_presence_of) and the class level > (validates_uniqueness_of) is a pain in the ass. It's confusing because > both sorts of validations look the same, but they are really > fundamentally different. > > Ranting aside, there are a couple of different ways you can view this. > To be the most clear, I'd probably spec the class level validations > separately from instance level validations. The uniqueness spec might > look like this: > > context "The Registration model class" do > setup do > @user1 = User.new > @user2 = User.new > @tournament = Tournament.new > > [@user1, @user2, @tournament].each {|model| model.save(false)} > end > > specify "should permit registrations with different users" do > Registration.create(:user => @user1, :tournament => @tournament) > Registration.new(:user => @user2, :tournament => > @tournament).should_be_valid > end > > specify "should deny multiple registrations with the same user" do > Registration.create(:user => @user1, :tournament => @tournament) > Registration.new(:user => @user1, :tournament => > @tournament).should_not_be_valid > end > end > > WDYT? That makes a lot of sense. I'm finding that, as productive as I am with Rails, RSpec is helping me find a lot of deficiencies in the Rails philosophy, but far more importantly in my own thinking. I've learned that I have to pay a LOT more attention than I have been when coding...and I consider myself a mindful programmer to begin with. I know it sounds obvious that you have to pay attention, but it can be tough in practice. Anyway I'm loving RSpec, if only because I'm asking more design questions than I was before. Whenever a spec is awkward to write or implement, it's time to investigate further. Thanks a lot for the input. Pat From pergesu at gmail.com Thu Jan 4 23:47:30 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 4 Jan 2007 21:47:30 -0700 Subject: [rspec-users] Another "how do I spec this?" In-Reply-To: <57c63afe0701010616x15c2e61rca9a2459d0ddd548@mail.gmail.com> References: <810a540e0701010105sb5610e2t1c3c7d94da67fe54@mail.gmail.com> <57c63afe0701010616x15c2e61rca9a2459d0ddd548@mail.gmail.com> Message-ID: <810a540e0701042047w1fea7004u339877997f6abe99@mail.gmail.com> On 1/1/07, David Chelimsky wrote: > On 1/1/07, Pat Maddox wrote: > > I wanted to add a convenience method on my User class to see if he was > > already signed up for a tournament. Here's my spec > > > > context "A User signed up for one tournament" do > > setup do > > @t1 = Tournament.new > > @t1.save false > > @t2 = Tournament.new > > @t2.save false > > @user = User.new > > @user.save false > > @user.registrations << Registration.new(:tournament => @t1) > > end > > > > specify "should be signed up for that tournament" do > > @user.should_be_signed_up_for @t1 > > end > > > > specify "should not be signed up for another tournament" do > > @user.should_not_be_signed_up_for @t2 > > end > > end > > > > class User < ActiveRecord::Base > > has_many :registrations > > > > def signed_up_for?(tournament) > > !registrations.find_by_tournament_id(tournament).nil? > > end > > end > > > > Are there any potential improvements, or is that the best way to spec it? > > Couple of thoughts. Creating new unvalidated models seems to be > something useful, so... > > module ModelSpecUtils > def unvalidated_model(klass) > model = klass.new > model.save(false) > model > end > end > > Also, this line: > > @user.registrations << Registration.new(:tournament => @t1) > > is breaking encapsulation a bit. Given that and the utility module > above, I might end up w/ something like this: > > context "A User signed up for one tournament" do > include ModelSpecUtils > > setup do > @tournament1 = unvalidated_model(Tournament) > @tournament2 = unvalidated_model(Tournament) > @user = unvalidated_model(User) > @user.register_for(@tournament1) > end > > specify "should be signed up for that tournament" do > @user.should_be_signed_up_for @tournament1 > end > > specify "should not be signed up for another tournament" do > @user.should_not_be_signed_up_for @tournament2 > end > end > > David My original spec is bad, because it doesn't show how the Registration model is being used. Right now in my controller I'm just doing @registration = Registration.new :tournament => @tournament, :user => current_user and then saving it. It's probably not good then that I'm doing user.registrations<< in the spec. I know that breaks encapsulation, but I'm not doing it in my app. Either way though the specs should match the use. This brings up a more interesting question (to me at least. It could be pointless to some). I've got User and Tournament models, and have the Registration relationship. What's the best way to create the Registration? Creating User#register_for has a couple upsides 1. Clients only need to know about two classes, user and tournament. 2. It reads really well. this_user.register_for(some_tourney) is very clear a. It's "opinionated." Having an explicit method at least promotes a single creation mechanism (it gets a letter because I'm not sure if it's that important) #2 is the biggest benefit, in my opinion, and it should be obvious why it's good. #1 though is interesting to me, because while you want to couple clients to as few classes as possible, here you lose/diminish the value of a richer model. When you create a relationship model like this, presumably there are some interesting attributes other than the simple relationship. In my case, there's nothing else interesting (yet). I use the join model because it's more flexible and no more conceptually difficult than using HABTM. I prefer the explicit relationship. But maybe I need to signify that the relationship doesn't have interesting attributes by abstracting it away behind the #register_for method. So here's my hypothesis: when there are no interesting attributes to the relationship, create a simple method that hides the join class. When there are interesting attributes, create the relationship object explicitly. Of course you can never stick to simple rules like that, but hopefully it's enough for you to give me another OOP lesson :) Pat From dchelimsky at gmail.com Fri Jan 5 00:06:12 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jan 2007 00:06:12 -0500 Subject: [rspec-users] Another "how do I spec this?" In-Reply-To: <810a540e0701042047w1fea7004u339877997f6abe99@mail.gmail.com> References: <810a540e0701010105sb5610e2t1c3c7d94da67fe54@mail.gmail.com> <57c63afe0701010616x15c2e61rca9a2459d0ddd548@mail.gmail.com> <810a540e0701042047w1fea7004u339877997f6abe99@mail.gmail.com> Message-ID: <57c63afe0701042106r18646bd4uadff72a9de583eee@mail.gmail.com> On 1/4/07, Pat Maddox wrote: > On 1/1/07, David Chelimsky wrote: > > On 1/1/07, Pat Maddox wrote: > > > I wanted to add a convenience method on my User class to see if he was > > > already signed up for a tournament. Here's my spec > > > > > > context "A User signed up for one tournament" do > > > setup do > > > @t1 = Tournament.new > > > @t1.save false > > > @t2 = Tournament.new > > > @t2.save false > > > @user = User.new > > > @user.save false > > > @user.registrations << Registration.new(:tournament => @t1) > > > end > > > > > > specify "should be signed up for that tournament" do > > > @user.should_be_signed_up_for @t1 > > > end > > > > > > specify "should not be signed up for another tournament" do > > > @user.should_not_be_signed_up_for @t2 > > > end > > > end > > > > > > class User < ActiveRecord::Base > > > has_many :registrations > > > > > > def signed_up_for?(tournament) > > > !registrations.find_by_tournament_id(tournament).nil? > > > end > > > end > > > > > > Are there any potential improvements, or is that the best way to spec it? > > > > Couple of thoughts. Creating new unvalidated models seems to be > > something useful, so... > > > > module ModelSpecUtils > > def unvalidated_model(klass) > > model = klass.new > > model.save(false) > > model > > end > > end > > > > Also, this line: > > > > @user.registrations << Registration.new(:tournament => @t1) > > > > is breaking encapsulation a bit. Given that and the utility module > > above, I might end up w/ something like this: > > > > context "A User signed up for one tournament" do > > include ModelSpecUtils > > > > setup do > > @tournament1 = unvalidated_model(Tournament) > > @tournament2 = unvalidated_model(Tournament) > > @user = unvalidated_model(User) > > @user.register_for(@tournament1) > > end > > > > specify "should be signed up for that tournament" do > > @user.should_be_signed_up_for @tournament1 > > end > > > > specify "should not be signed up for another tournament" do > > @user.should_not_be_signed_up_for @tournament2 > > end > > end > > > > David > > My original spec is bad, because it doesn't show how the Registration > model is being used. Right now in my controller I'm just doing > @registration = Registration.new :tournament => @tournament, :user => > current_user > > and then saving it. It's probably not good then that I'm doing > user.registrations<< in the spec. I know that breaks encapsulation, > but I'm not doing it in my app. Either way though the specs should > match the use. > > This brings up a more interesting question (to me at least. It could > be pointless to some). I've got User and Tournament models, and have > the Registration relationship. What's the best way to create the > Registration? > > Creating User#register_for has a couple upsides > 1. Clients only need to know about two classes, user and tournament. > 2. It reads really well. this_user.register_for(some_tourney) is very clear > a. It's "opinionated." Having an explicit method at least promotes a > single creation mechanism (it gets a letter because I'm not sure if > it's that important) > > #2 is the biggest benefit, in my opinion, and it should be obvious why > it's good. > > #1 though is interesting to me, because while you want to couple > clients to as few classes as possible, here you lose/diminish the > value of a richer model. When you create a relationship model like > this, presumably there are some interesting attributes other than the > simple relationship. > > In my case, there's nothing else interesting (yet). I use the join > model because it's more flexible and no more conceptually difficult > than using HABTM. I prefer the explicit relationship. But maybe I > need to signify that the relationship doesn't have interesting > attributes by abstracting it away behind the #register_for method. > > So here's my hypothesis: when there are no interesting attributes to > the relationship, create a simple method that hides the join class. > When there are interesting attributes, create the relationship object > explicitly. That probably makes sense a lot of the time, though I can imagine a case where there are interesting attributes in the join but it *still* makes things most clear to do it through the user. Here's one: @guest = Guest.new(:smoker => false) @hotel = Hotel.new @hotel.should_receive(:reserve_room).with(:start_date => Time.new, :nights => 3, :smoking_preference => "non-smoking') @guest.reserve_room_at(@hotel) In this case, the guest is responsible to let the hotel know that she's interested in a non-smoking room rather than the controller being responsible for asking the guest her preference and passing that on to the hotel. > > Of course you can never stick to simple rules like that, but hopefully > it's enough for you to give me another OOP lesson :) You're too kind. > > Pat David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jan 5 00:10:02 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jan 2007 00:10:02 -0500 Subject: [rspec-users] Validations based on associations In-Reply-To: <810a540e0701042022r4cc726e7p842e595e76c934a@mail.gmail.com> References: <810a540e0701010047o49fa5f04ucac203b68aecb08e@mail.gmail.com> <57c63afe0701010607m3bcab306k761a8a3156b1e0ec@mail.gmail.com> <810a540e0701042022r4cc726e7p842e595e76c934a@mail.gmail.com> Message-ID: <57c63afe0701042110l5e4ffd88o80730cb0dbb7b483@mail.gmail.com> On 1/4/07, Pat Maddox wrote: > On 1/1/07, David Chelimsky wrote: > > On 1/1/07, Pat Maddox wrote: > > > My model is very simple, it's mostly just a join table that represents > > > which tournaments a user has registered for. > > > > > > class Registration < ActiveRecord::Base > > > belongs_to :user > > > belongs_to :tournament > > > > > > validates_presence_of :user_id, :tournament_id > > > validates_uniqueness_of :user_id, :scope => :tournament_id > > > end > > > > > > the validates_uniqueness checks to make sure there's no record that > > > has the same user_id and tournament_id. > > > > > > Is there a relatively easy way to specify this behavior? The only way > > > that I know is to do something like > > > > > > context "A Registration with a User and Tournament" do > > > setup do > > > @user = User.new > > > @user.save false > > > @tournament = Tournament.new > > > @tournament.save false > > > @reg = Registration.new(:user => @user, :tournament => @tournament) > > > end > > > > > > specify "should be valid" do > > > @reg.should_be_valid > > > end > > > > > > specify "should not be valid if a registration with the same details > > > already exists" do > > > @reg.save > > > Registration.new(:user => @user, :tournament => > > > @tournament).should_not_be_valid > > > end > > > end > > > > Geez, ActiveRecord models are SUCH a violation of SRP! I realize that > > this is the rails way, and that there are great productivity benefits > > we glean from AR, but having a model that validates both at both the > > instance level (validates_presence_of) and the class level > > (validates_uniqueness_of) is a pain in the ass. It's confusing because > > both sorts of validations look the same, but they are really > > fundamentally different. > > > > Ranting aside, there are a couple of different ways you can view this. > > To be the most clear, I'd probably spec the class level validations > > separately from instance level validations. The uniqueness spec might > > look like this: > > > > context "The Registration model class" do > > setup do > > @user1 = User.new > > @user2 = User.new > > @tournament = Tournament.new > > > > [@user1, @user2, @tournament].each {|model| model.save(false)} > > end > > > > specify "should permit registrations with different users" do > > Registration.create(:user => @user1, :tournament => @tournament) > > Registration.new(:user => @user2, :tournament => > > @tournament).should_be_valid > > end > > > > specify "should deny multiple registrations with the same user" do > > Registration.create(:user => @user1, :tournament => @tournament) > > Registration.new(:user => @user1, :tournament => > > @tournament).should_not_be_valid > > end > > end > > > > WDYT? > > That makes a lot of sense. I'm finding that, as productive as I am > with Rails, RSpec is helping me find a lot of deficiencies in the > Rails philosophy, but far more importantly in my own thinking. > > I've learned that I have to pay a LOT more attention than I have been > when coding...and I consider myself a mindful programmer to begin > with. I know it sounds obvious that you have to pay attention, but it > can be tough in practice. It's REALLY tough in practice. But that's what separates the geniuses from the rest of us. In programming and in any other craft. I was just discussing this with a jazz singer in my family - how there are some people who just live in the zone. The rest of us can only aspire to that by continuing to practice and pay attention when we do. Hopefully, eventually, you don't have to pay attention and good stuff just happens as a matter of course. > Anyway I'm loving RSpec, if only because I'm asking more design > questions than I was before. Whenever a spec is awkward to write or > implement, it's time to investigate further. Can I quote you on that? > > Thanks a lot for the input. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From listaccount at e-tobi.net Fri Jan 5 04:25:29 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Fri, 05 Jan 2007 10:25:29 +0100 Subject: [rspec-users] Common setup code and naming specifications In-Reply-To: <57c63afe0701041905sd54b02ew48492c89b3205d11@mail.gmail.com> References: <459D87C8.1010300@e-tobi.net> <57c63afe0701041512t6740ff1ax898dffd75753d5f@mail.gmail.com> <459D98AA.3050003@e-tobi.net> <57c63afe0701041905sd54b02ew48492c89b3205d11@mail.gmail.com> Message-ID: <459E1989.5030306@e-tobi.net> David Chelimsky wrote: > Ah, the DRY battle cry. > Yeeehaaa! :) > There is a difference between duplication of code and duplicated calls > to a no-arg method. While typing the call to set_logged_in may require > a few extra strokes, You're right. At least in this particular case there would be no gain in having something like a logged_in_context-"base class". It wouldn't save very much keystrokes and it doesn't communicate better than putting set_logged_in in the setup. If there's common setup code, it should be refactored into a helper module and included in the context. > are inherently procedural. The risk of duplication in code is that > when you have to change it in one place you'll miss the other place. > That risk doesn't really apply to this situation. > The only thing I'm constantly missing is putting the logged in code in the setup, when creating a new context. But a subclassing approach probably wouldn't make this any better. Maybe I just shouldn't code at one o'clock in the night :-) >> Excellent point. There's no simple answer for this. Your best bet is >> to keep throwing examples at us and we can discuss them more >> explicitly. >> >From another point of view, one might also see it this way: Not putting implementation details into the specification title gives you more freedom to implement it along the way. In this sense I would describe the anatomy of a specification as: specify "" do <body> <usage> <verification> </body> end The <title> should be a hint on what functionality / behaviour is specified. <body> describes the details and typically consists of a <usage> part and a <verification> part. The customer does only look at the title. The developer, who e.g. implements the view, looks mainly at the <usage> part. This can also look like: setup do <usage> end specify "<title>" do <verification> end Maybe this can be seen as a pair of different languages in a translation. <title> is a phrase in the human customer language, <body> is the translation in the developer language. Mmmm... thats still not the right analogy. It's more like a dictionary where <title> is a term in one language and <usage>/<verification> is the definition in another language. Ok, before I get too philosophical about this, I'll rather go ahead and write some code to see where this gets me :-) Regarding the examples - what I'm currently working on is open source anyway. I'll put it into a public SVN repository these days, so if anyone is interested he can take a look at it. bye, Tobias From jonathan.tron.mailings at gmail.com Fri Jan 5 04:47:58 2007 From: jonathan.tron.mailings at gmail.com (Jonathan Tron) Date: Fri, 5 Jan 2007 10:47:58 +0100 Subject: [rspec-users] RSpec 0.7.5 with Rails and rcov In-Reply-To: <CAD71583-F29B-4AE1-9F36-87D489A8D270@osesm.com> References: <CAD71583-F29B-4AE1-9F36-87D489A8D270@osesm.com> Message-ID: <E96C0CFF-9E38-44DA-80B0-C99CC065AA6C@gmail.com> Le 5 janv. 07 ? 03:05, Bryan Liles a ?crit : > I seem to be missing something because I am at a loss on how to get > rcov, RSpec, and Rails working together. Would someone mind dropping > some hints? I don't know what you want to achieve, but if your goal is to generate some reports here's what I added to lib/tasks/ rspec_additions.rake : namespace :spec do desc "Spec with rspec/rcov reports" Spec::Rake::SpecTask.new('reports') do |t| t.spec_files = FileList['spec/**/*.rb'] t.spec_opts = ["--format", "html", "--diff"] t.out = 'doc/rspec.html' t.rcov = true t.rcov_dir = 'doc/coverage' # Optional : # Prevent rcov to generate report on specs, environment.rb and boot.rb # t.rcov_opts = ['--exclude', 'spec,config\/environment.rb,config\/ boot.rb'] t.fail_on_error = false t.failure_message = "The specs failed. Check for the problem at http://projects.tron.name/flash007/rspec.html" end end Run it with rake : spec:reports It will generate rspec.html report in doc/rspec.html and rcov report in doc/coverage/. Jonathan -- Tron Jonathan http://jonathan.tron.name From aslak.hellesoy at gmail.com Fri Jan 5 06:01:32 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 5 Jan 2007 12:01:32 +0100 Subject: [rspec-users] RSpec 0.7.5 with Rails and rcov In-Reply-To: <E96C0CFF-9E38-44DA-80B0-C99CC065AA6C@gmail.com> References: <CAD71583-F29B-4AE1-9F36-87D489A8D270@osesm.com> <E96C0CFF-9E38-44DA-80B0-C99CC065AA6C@gmail.com> Message-ID: <8d961d900701050301j59b40e15pfd89748297cef5a5@mail.gmail.com> In the next release (or rspec+spec/rails on trunk) you'll also be able to leave the built-in spec:* tasks by editing a spec/spec.opts file. On 1/5/07, Jonathan Tron <jonathan.tron.mailings at gmail.com> wrote: > Le 5 janv. 07 ? 03:05, Bryan Liles a ?crit : > > > I seem to be missing something because I am at a loss on how to get > > rcov, RSpec, and Rails working together. Would someone mind dropping > > some hints? > > I don't know what you want to achieve, but if your goal is to > generate some reports here's what I added to lib/tasks/ > rspec_additions.rake : > > namespace :spec do > desc "Spec with rspec/rcov reports" > Spec::Rake::SpecTask.new('reports') do |t| > t.spec_files = FileList['spec/**/*.rb'] > t.spec_opts = ["--format", "html", "--diff"] > t.out = 'doc/rspec.html' > t.rcov = true > t.rcov_dir = 'doc/coverage' > > # Optional : > # Prevent rcov to generate report on specs, environment.rb and boot.rb > # t.rcov_opts = ['--exclude', 'spec,config\/environment.rb,config\/ > boot.rb'] > > t.fail_on_error = false > t.failure_message = "The specs failed. Check for the problem at > http://projects.tron.name/flash007/rspec.html" > end > end > > Run it with rake : spec:reports > It will generate rspec.html report in doc/rspec.html and rcov report > in doc/coverage/. > > Jonathan > -- > Tron Jonathan > http://jonathan.tron.name > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mlangenberg at gmail.com Fri Jan 5 09:09:08 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Fri, 5 Jan 2007 15:09:08 +0100 Subject: [rspec-users] Using RESTful routes in controller tests Message-ID: <27c0ac6d0701050609p26603001j7127b1ffe663606e@mail.gmail.com> Why can't I use the RESTful route helpers in my specs? In my controller I'm doing a redirect: redirect_to list_path(:id => @item.list_id) Now when I write: controller.should_redirect_to list_path(:id => 2) I'm getting the following error: NoMethodError in 'POST on /lists/2/items should redirect to index on succesful POST' You have a nil object when you didn't expect it! The error occurred while evaluating nil.rewrite (eval):19:in `list_path' ./spec/controllers/items_controller_spec.rb:36: Finished in 0.114317 seconds Writing "controller.should_redirect_to :controller => 'lists', :action => 'show', :id => 2" works though. Am I forgetting something? From aslak.hellesoy at gmail.com Fri Jan 5 16:15:38 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 5 Jan 2007 22:15:38 +0100 Subject: [rspec-users] Using RESTful routes in controller tests In-Reply-To: <27c0ac6d0701050609p26603001j7127b1ffe663606e@mail.gmail.com> References: <27c0ac6d0701050609p26603001j7127b1ffe663606e@mail.gmail.com> Message-ID: <8d961d900701051315y1d93404q69623fa4b9485d68@mail.gmail.com> Sounds like a bug/missing feature. Please submit a feature request at Rubyforge, with a failing spec if you can. On 1/5/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > Why can't I use the RESTful route helpers in my specs? > In my controller I'm doing a redirect: redirect_to list_path(:id => > @item.list_id) > Now when I write: controller.should_redirect_to list_path(:id => 2) > I'm getting the following error: > > NoMethodError in 'POST on /lists/2/items should redirect to index on > succesful POST' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.rewrite > (eval):19:in `list_path' > ./spec/controllers/items_controller_spec.rb:36: > > Finished in 0.114317 seconds > > Writing "controller.should_redirect_to :controller => 'lists', :action > => 'show', :id => 2" works though. > > Am I forgetting something? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Fri Jan 5 16:30:33 2007 From: cwdinfo at gmail.com (s.ross) Date: Fri, 5 Jan 2007 13:30:33 -0800 Subject: [rspec-users] How To Spec Controllers with Finders Message-ID: <A2A16278-54DF-43A5-A587-90F0230C02EB@gmail.com> Given this code (which renders rjs), I'm faced with the fixture- driven way of spec-ing or mocking. How the heck to you mock this so the code at line (2) and (4) work right? I'm still struggling with mocks but it seems like this can be done. Forgive the naivety of this question. 1. def change_quantity 2. @line_item = LineItem.find_by_id(params[:id]) 3. unless @line_item.nil? 4. @line_item.update_attribute(:quantity, params[:quantity]) 5. @extension_id = "extension#{params[:id]}" 6. end 7. end Thanks From court3nay at gmail.com Fri Jan 5 17:14:09 2007 From: court3nay at gmail.com (Courtenay) Date: Fri, 5 Jan 2007 14:14:09 -0800 Subject: [rspec-users] How To Spec Controllers with Finders In-Reply-To: <A2A16278-54DF-43A5-A587-90F0230C02EB@gmail.com> References: <A2A16278-54DF-43A5-A587-90F0230C02EB@gmail.com> Message-ID: <4b430c8f0701051414yd6e5a3r48551df4b818e739@mail.gmail.com> try this: @line_item = mock("line_item") LineItem.should_receive(:find_by_id).with(3).and_return(@line_item) @line_item.should_receive(:update_attribute).with(:quantity, 1) get :change_quantity, :id => 3, :quantity => 1 On 1/5/07, s.ross <cwdinfo at gmail.com> wrote: > Given this code (which renders rjs), I'm faced with the fixture- > driven way of spec-ing or mocking. How the heck to you mock this so > the code at line (2) and (4) work right? I'm still struggling with > mocks but it seems like this can be done. Forgive the naivety of this > question. > > 1. def change_quantity > 2. @line_item = LineItem.find_by_id(params[:id]) > 3. unless @line_item.nil? > 4. @line_item.update_attribute(:quantity, params[:quantity]) > 5. @extension_id = "extension#{params[:id]}" > 6. end > 7. end > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brian.takita at gmail.com Fri Jan 5 20:39:26 2007 From: brian.takita at gmail.com (Brian Takita) Date: Fri, 5 Jan 2007 17:39:26 -0800 Subject: [rspec-users] spec command and windows Message-ID: <1d7ddd110701051739j7285b552r7a785afca6b0bb0@mail.gmail.com> Hello, Today I ran into some frustration with spec and windows. We have a series of plugins that have either test suites and/or spec suites. To avoid environment collisions, we have a "master" test suite that spawns new process for all of the test suites and spec suites. Every works great on posix. Unfortunately on windows, spec was not found. The only way I figured to ensure we get to spec in a platform independent way is to call: success = true dir = File.dirname(__FILE__) spec_cmd = (RUBY_PLATFORM =~ /[^r]win/) ? 'C:\\ruby\\bin\\spec.cmd' : 'spec' success &&= system("#{spec_cmd} --format specdoc --diff unified #{dir}/project_dir/spec_suite.rb") # ... exit success Lame! Does somebody out there have a better solution? Could rspec be run from ruby instead? Thank you, Brian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070105/6f6a5e28/attachment.html From waynev at gmail.com Fri Jan 5 22:55:06 2007 From: waynev at gmail.com (Wayne Vucenic) Date: Fri, 5 Jan 2007 19:55:06 -0800 Subject: [rspec-users] spec command and windows In-Reply-To: <1d7ddd110701051739j7285b552r7a785afca6b0bb0@mail.gmail.com> References: <1d7ddd110701051739j7285b552r7a785afca6b0bb0@mail.gmail.com> Message-ID: <88c9ce410701051955y6b0079bav9c7b7537a00e7504@mail.gmail.com> Hi Brian, It looks like c:\ruby\bin isn't in your PATH environment variable on Windows. (I've had problems with the OneClickInstaller not adding this directory to the PATH). If this is true, adding it to PATH should solve your problem. > Could rspec be run from ruby instead? This is similar to a question I was going to ask on this list. I'm trying to figure out how to run a xyz_spec.rb file from within my IDE, rather than having to use spec on the command line. Can anyone tell me how to do this? Thanks, Wayne --- Wayne Vucenic No Bugs Software Ruby, C#, and Erlang Agile Contract Programming in Silicon Valley From dchelimsky at gmail.com Fri Jan 5 23:04:21 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Jan 2007 23:04:21 -0500 Subject: [rspec-users] spec command and windows In-Reply-To: <88c9ce410701051955y6b0079bav9c7b7537a00e7504@mail.gmail.com> References: <1d7ddd110701051739j7285b552r7a785afca6b0bb0@mail.gmail.com> <88c9ce410701051955y6b0079bav9c7b7537a00e7504@mail.gmail.com> Message-ID: <57c63afe0701052004x39000224m9562f766069a9ddc@mail.gmail.com> On 1/5/07, Wayne Vucenic <waynev at gmail.com> wrote: > Hi Brian, > > It looks like c:\ruby\bin isn't in your PATH environment variable on > Windows. (I've had problems with the OneClickInstaller not adding > this directory to the PATH). If this is true, adding it to PATH > should solve your problem. > > > Could rspec be run from ruby instead? > > This is similar to a question I was going to ask on this list. I'm > trying to figure out how to run a xyz_spec.rb file from within my IDE, > rather than having to use spec on the command line. Can anyone tell > me how to do this? Just require 'spec' in the file or a file it includes and go: ruby path/to/the/file.rb OR (if you MUST) ruby path\to\the\file.rb Cheers, David > > Thanks, > > Wayne > > --- > > Wayne Vucenic > No Bugs Software > Ruby, C#, and Erlang Agile Contract Programming in Silicon Valley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From waynev at gmail.com Sat Jan 6 00:30:39 2007 From: waynev at gmail.com (Wayne Vucenic) Date: Fri, 5 Jan 2007 21:30:39 -0800 Subject: [rspec-users] spec command and windows In-Reply-To: <57c63afe0701052004x39000224m9562f766069a9ddc@mail.gmail.com> References: <1d7ddd110701051739j7285b552r7a785afca6b0bb0@mail.gmail.com> <88c9ce410701051955y6b0079bav9c7b7537a00e7504@mail.gmail.com> <57c63afe0701052004x39000224m9562f766069a9ddc@mail.gmail.com> Message-ID: <88c9ce410701052130u63cf2557oe4afa7d762fd9d07@mail.gmail.com> Hi David, Thanks for your amazingly prompt reply! On 1/5/07, David Chelimsky <dchelimsky at gmail.com> wrote: > Just require 'spec' in the file or a file it includes and go: > > ruby path/to/the/file.rb > > OR (if you MUST) > > ruby path\to\the\file.rb Works like a charm! Now is there any way to get the same output as with "-f s" ? And I completely agree with you on / rather than \ in file paths. The use of \ was one of the most annoying things MS-DOS and then Windows ever did. When I switched from programming on the Mac to Windows NT 3.51 I was glad that all the Win32 APIs accepted either \ or / in paths, so I always preferred /. Thanks, Wayne From cwdinfo at gmail.com Sat Jan 6 01:35:22 2007 From: cwdinfo at gmail.com (s.ross) Date: Fri, 5 Jan 2007 22:35:22 -0800 Subject: [rspec-users] How To Spec Controllers with Finders In-Reply-To: <4b430c8f0701051414yd6e5a3r48551df4b818e739@mail.gmail.com> References: <A2A16278-54DF-43A5-A587-90F0230C02EB@gmail.com> <4b430c8f0701051414yd6e5a3r48551df4b818e739@mail.gmail.com> Message-ID: <CD863B29-C7D1-4B35-8880-E171E327F456@gmail.com> What I came up with was: context "The cart controller" do controller_name "carts" integrate_views setup do @cart = mock("cart") @cart.stub!(:new_record).and_return(false) @cart.stub!(:new).and_return(@cart) @cart.stub!(:total_price).and_return(35.00) @cart.stub!(:total_quantity).and_return(1) @cart.stub!(:empty?).and_return(false) @line_item = mock("line_item") LineItem.stub!(:find_by_id).and_return(@line_item) @line_item.should_receive(:update_attribute).with(:quantity, "1").and_return(true) @line_item.stub!(:extension).and_return(25.00) end specify "should allow change of quantity" do post :change_quantity, {:id => 1, :quantity => 1} response.should_be_success assigns[:extension_id].should == "extension1" assigns[:line_item].should_be(@line_item) controller.should_render_rjs :replace_html, 'cartstatus', "(1 item, $35.00)" end end but somehow it seems a bit brittle. This is really what should happen if a user changes quantity, but the mocks seem like they won't flex or bend easily for further reuse. Any thoughts on this? On Jan 5, 2007, at 2:14 PM, Courtenay wrote: > try this: > > > @line_item = mock("line_item") > LineItem.should_receive(:find_by_id).with(3).and_return(@line_item) > @line_item.should_receive(:update_attribute).with(:quantity, 1) > > get :change_quantity, :id => 3, :quantity => 1 > > > On 1/5/07, s.ross <cwdinfo at gmail.com> wrote: >> Given this code (which renders rjs), I'm faced with the fixture- >> driven way of spec-ing or mocking. How the heck to you mock this so >> the code at line (2) and (4) work right? I'm still struggling with >> mocks but it seems like this can be done. Forgive the naivety of this >> question. >> >> 1. def change_quantity >> 2. @line_item = LineItem.find_by_id(params[:id]) >> 3. unless @line_item.nil? >> 4. @line_item.update_attribute(:quantity, params[:quantity]) >> 5. @extension_id = "extension#{params[:id]}" >> 6. end >> 7. end >> >> 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 From dchelimsky at gmail.com Sat Jan 6 08:20:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 6 Jan 2007 08:20:51 -0500 Subject: [rspec-users] How To Spec Controllers with Finders In-Reply-To: <CD863B29-C7D1-4B35-8880-E171E327F456@gmail.com> References: <A2A16278-54DF-43A5-A587-90F0230C02EB@gmail.com> <4b430c8f0701051414yd6e5a3r48551df4b818e739@mail.gmail.com> <CD863B29-C7D1-4B35-8880-E171E327F456@gmail.com> Message-ID: <57c63afe0701060520h50c2a556jbfc8f1856cc78cb4@mail.gmail.com> On 1/6/07, s.ross <cwdinfo at gmail.com> wrote: > What I came up with was: > > context "The cart controller" do > controller_name "carts" > integrate_views > > setup do > @cart = mock("cart") > @cart.stub!(:new_record).and_return(false) > @cart.stub!(:new).and_return(@cart) > @cart.stub!(:total_price).and_return(35.00) > @cart.stub!(:total_quantity).and_return(1) > @cart.stub!(:empty?).and_return(false) > > @line_item = mock("line_item") > LineItem.stub!(:find_by_id).and_return(@line_item) > @line_item.should_receive(:update_attribute).with(:quantity, > "1").and_return(true) I try to avoid using should_receive in setup, so I'd do this here: @line_item.stub!(:update_attribute).and_return(true) and then override the method stub w/ a mock expectation in the specify block. The idea is that you put all of the stuff in setup that must be there for the code to execute, and put the details in the specs that are interesting for that spec. > @line_item.stub!(:extension).and_return(25.00) > end > > specify "should allow change of quantity" do > post :change_quantity, {:id => 1, :quantity => 1} > response.should_be_success > assigns[:extension_id].should == "extension1" > assigns[:line_item].should_be(@line_item) > controller.should_render_rjs :replace_html, 'cartstatus', > "(1 item, $35.00)" > end > end > > but somehow it seems a bit brittle. This is really what should happen > if a user changes quantity, but the mocks seem like they won't flex > or bend easily for further reuse. Any thoughts on this? Within this context they absolutely will flex or bend by overriding the method stubs (functioning as defaults) w/ mock expectations. Also, I might approach this differently. The behaviour here that you want to spec is that when changing quantity some things should happen. So.... context "Given a request to change quantity, the CartController should" do controller_name "carts" integrate_views setup do @cart = mock("cart") @cart.stub!(:new_record).and_return(false) @cart.stub!(:total_price).and_return(35.00) @cart.stub!(:total_quantity).and_return(1) @cart.stub!(:empty?).and_return(false) Cart.stub!(:new).and_return(@cart) @line_item = mock("line_item") @line_item.stub!(:update_attribute).and_return(true) @line_item.stub!(:extension).and_return(25.00) LineItem.stub!(:find_by_id).and_return(@line_item) post :change_quantity, {:id => 1, :quantity => 1} end specify "respond w/ success" do response.should_be_success end specify "assign exension_id" do assigns[:extension_id].should == "extension1" end specify "assign line_item" do assigns[:line_item].should_be(@line_item) end specify "update the html (using rjs)" do controller.should_render_rjs :replace_html, 'cartstatus', "(1 item, $35.00)" end end This would then read: Given a request to change quantity, the CartController should - respond w/ success - assign exension_id - assign line_item - update the html (using rjs) If you're concerned about reuse of the stubs, you can do this: module Stubs def new_stub_cart cart = mock("cart") cart.stub!(:new_record).and_return(false) cart.stub!(:total_price).and_return(0.0) cart.stub!(:total_quantity).and_return(0) cart.stub!(:empty?).and_return(false) cart end def new_stub_line_item line_item = mock("line_item") line_item.stub!(:update_attribute).and_return(true) line_item.stub!(:extension).and_return(0) line_item end def stub_cart @stub_cart ||= new_stub_cart end def stub_line_item @stub_line_item ||= new_stub_line_item end end context "Given a request to change quantity, the CartController should" do include Stubs controller_name "carts" integrate_views setup do Cart.stub!(:new).and_return(stub_cart) LineItem.stub!(:find_by_id).and_return(stub_line_item) end ... end Now any new spec that requires specific values can use stub_cart.should_receive(:total_price).and_return(25.00), for example. > > On Jan 5, 2007, at 2:14 PM, Courtenay wrote: > > > try this: > > > > > > @line_item = mock("line_item") > > LineItem.should_receive(:find_by_id).with(3).and_return(@line_item) > > @line_item.should_receive(:update_attribute).with(:quantity, 1) > > > > get :change_quantity, :id => 3, :quantity => 1 > > > > > > On 1/5/07, s.ross <cwdinfo at gmail.com> wrote: > >> Given this code (which renders rjs), I'm faced with the fixture- > >> driven way of spec-ing or mocking. How the heck to you mock this so > >> the code at line (2) and (4) work right? I'm still struggling with > >> mocks but it seems like this can be done. Forgive the naivety of this > >> question. > >> > >> 1. def change_quantity > >> 2. @line_item = LineItem.find_by_id(params[:id]) > >> 3. unless @line_item.nil? > >> 4. @line_item.update_attribute(:quantity, params[:quantity]) > >> 5. @extension_id = "extension#{params[:id]}" > >> 6. end > >> 7. end > >> > >> Thanks > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bkeepers at gmail.com Sat Jan 6 10:28:24 2007 From: bkeepers at gmail.com (Brandon Keepers) Date: Sat, 6 Jan 2007 10:28:24 -0500 Subject: [rspec-users] Using RESTful routes in controller tests In-Reply-To: <8d961d900701051315y1d93404q69623fa4b9485d68@mail.gmail.com> References: <27c0ac6d0701050609p26603001j7127b1ffe663606e@mail.gmail.com> <8d961d900701051315y1d93404q69623fa4b9485d68@mail.gmail.com> Message-ID: <6D1F570C-3C74-44C2-9660-818A4E25AB27@gmail.com> There already is one: https://rubyforge.org/tracker/index.php? func=detail&aid=6541&group_id=797&atid=3149 Brandon On Jan 5, 2007, at 4:15 PM, aslak hellesoy wrote: > Sounds like a bug/missing feature. Please submit a feature request at > Rubyforge, with a failing spec if you can. > > On 1/5/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: >> Why can't I use the RESTful route helpers in my specs? >> In my controller I'm doing a redirect: redirect_to list_path(:id => >> @item.list_id) >> Now when I write: controller.should_redirect_to list_path(:id => 2) >> I'm getting the following error: >> >> NoMethodError in 'POST on /lists/2/items should redirect to index on >> succesful POST' >> You have a nil object when you didn't expect it! >> The error occurred while evaluating nil.rewrite >> (eval):19:in `list_path' >> ./spec/controllers/items_controller_spec.rb:36: >> >> Finished in 0.114317 seconds >> >> Writing "controller.should_redirect_to :controller => >> 'lists', :action >> => 'show', :id => 2" works though. >> >> Am I forgetting something? >> _______________________________________________ >> 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 cwdinfo at gmail.com Sat Jan 6 12:09:10 2007 From: cwdinfo at gmail.com (s.ross) Date: Sat, 6 Jan 2007 09:09:10 -0800 Subject: [rspec-users] How To Spec Controllers with Finders In-Reply-To: <57c63afe0701060520h50c2a556jbfc8f1856cc78cb4@mail.gmail.com> References: <A2A16278-54DF-43A5-A587-90F0230C02EB@gmail.com> <4b430c8f0701051414yd6e5a3r48551df4b818e739@mail.gmail.com> <CD863B29-C7D1-4B35-8880-E171E327F456@gmail.com> <57c63afe0701060520h50c2a556jbfc8f1856cc78cb4@mail.gmail.com> Message-ID: <AB5C8957-FE12-4A3B-890B-F78A38F5B303@gmail.com> Wow! Thanks. I'll look at this to see how it works for me. Steve On Jan 6, 2007, at 5:20 AM, David Chelimsky wrote: > On 1/6/07, s.ross <cwdinfo at gmail.com> wrote: >> What I came up with was: >> >> context "The cart controller" do >> controller_name "carts" >> integrate_views >> >> setup do >> @cart = mock("cart") >> @cart.stub!(:new_record).and_return(false) >> @cart.stub!(:new).and_return(@cart) >> @cart.stub!(:total_price).and_return(35.00) >> @cart.stub!(:total_quantity).and_return(1) >> @cart.stub!(:empty?).and_return(false) >> >> @line_item = mock("line_item") >> LineItem.stub!(:find_by_id).and_return(@line_item) >> @line_item.should_receive(:update_attribute).with(:quantity, >> "1").and_return(true) > > I try to avoid using should_receive in setup, so I'd do this here: > > @line_item.stub!(:update_attribute).and_return(true) > > and then override the method stub w/ a mock expectation in the specify > block. The idea is that you put all of the stuff in setup that must be > there for the code to execute, and put the details in the specs that > are interesting for that spec. > >> @line_item.stub!(:extension).and_return(25.00) >> end >> >> specify "should allow change of quantity" do >> post :change_quantity, {:id => 1, :quantity => 1} >> response.should_be_success >> assigns[:extension_id].should == "extension1" >> assigns[:line_item].should_be(@line_item) >> controller.should_render_rjs :replace_html, 'cartstatus', >> "(1 item, $35.00)" >> end >> end >> >> but somehow it seems a bit brittle. This is really what should happen >> if a user changes quantity, but the mocks seem like they won't flex >> or bend easily for further reuse. Any thoughts on this? > > Within this context they absolutely will flex or bend by overriding > the method stubs (functioning as defaults) w/ mock expectations. > > Also, I might approach this differently. The behaviour here that you > want to spec is that when changing quantity some things should happen. > So.... > > context "Given a request to change quantity, the CartController > should" do > controller_name "carts" > integrate_views > > setup do > @cart = mock("cart") > @cart.stub!(:new_record).and_return(false) > @cart.stub!(:total_price).and_return(35.00) > @cart.stub!(:total_quantity).and_return(1) > @cart.stub!(:empty?).and_return(false) > Cart.stub!(:new).and_return(@cart) > > @line_item = mock("line_item") > @line_item.stub!(:update_attribute).and_return(true) > @line_item.stub!(:extension).and_return(25.00) > LineItem.stub!(:find_by_id).and_return(@line_item) > > post :change_quantity, {:id => 1, :quantity => 1} > end > > specify "respond w/ success" do > response.should_be_success > end > > specify "assign exension_id" do > assigns[:extension_id].should == "extension1" > end > > specify "assign line_item" do > assigns[:line_item].should_be(@line_item) > end > > specify "update the html (using rjs)" do > controller.should_render_rjs :replace_html, > 'cartstatus', > "(1 item, $35.00)" > end > end > > This would then read: > > Given a request to change quantity, the CartController should > - respond w/ success > - assign exension_id > - assign line_item > - update the html (using rjs) > > If you're concerned about reuse of the stubs, you can do this: > > module Stubs > def new_stub_cart > cart = mock("cart") > cart.stub!(:new_record).and_return(false) > cart.stub!(:total_price).and_return(0.0) > cart.stub!(:total_quantity).and_return(0) > cart.stub!(:empty?).and_return(false) > cart > end > > def new_stub_line_item > line_item = mock("line_item") > line_item.stub!(:update_attribute).and_return(true) > line_item.stub!(:extension).and_return(0) > line_item > end > > def stub_cart > @stub_cart ||= new_stub_cart > end > > def stub_line_item > @stub_line_item ||= new_stub_line_item > end > end > > context "Given a request to change quantity, the CartController > should" do > include Stubs > controller_name "carts" > integrate_views > > setup do > Cart.stub!(:new).and_return(stub_cart) > LineItem.stub!(:find_by_id).and_return(stub_line_item) > end > ... > end > > Now any new spec that requires specific values can use > stub_cart.should_receive(:total_price).and_return(25.00), for example. > > >> >> On Jan 5, 2007, at 2:14 PM, Courtenay wrote: >> >>> try this: >>> >>> >>> @line_item = mock("line_item") >>> LineItem.should_receive(:find_by_id).with(3).and_return(@line_item) >>> @line_item.should_receive(:update_attribute).with(:quantity, 1) >>> >>> get :change_quantity, :id => 3, :quantity => 1 >>> >>> >>> On 1/5/07, s.ross <cwdinfo at gmail.com> wrote: >>>> Given this code (which renders rjs), I'm faced with the fixture- >>>> driven way of spec-ing or mocking. How the heck to you mock this so >>>> the code at line (2) and (4) work right? I'm still struggling with >>>> mocks but it seems like this can be done. Forgive the naivety of >>>> this >>>> question. >>>> >>>> 1. def change_quantity >>>> 2. @line_item = LineItem.find_by_id(params[:id]) >>>> 3. unless @line_item.nil? >>>> 4. @line_item.update_attribute(:quantity, params[:quantity]) >>>> 5. @extension_id = "extension#{params[:id]}" >>>> 6. end >>>> 7. end >>>> >>>> Thanks >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From waynev at gmail.com Sat Jan 6 15:19:49 2007 From: waynev at gmail.com (Wayne Vucenic) Date: Sat, 6 Jan 2007 12:19:49 -0800 Subject: [rspec-users] spec command and windows In-Reply-To: <88c9ce410701052130u63cf2557oe4afa7d762fd9d07@mail.gmail.com> References: <1d7ddd110701051739j7285b552r7a785afca6b0bb0@mail.gmail.com> <88c9ce410701051955y6b0079bav9c7b7537a00e7504@mail.gmail.com> <57c63afe0701052004x39000224m9562f766069a9ddc@mail.gmail.com> <88c9ce410701052130u63cf2557oe4afa7d762fd9d07@mail.gmail.com> Message-ID: <88c9ce410701061219q78466c0kdfc841b92dcc7080@mail.gmail.com> > Now is there any way to get the same output as with "-f s" ? I took a look at the source, and answered my own question: require 'spec' ARGV.unshift("-f", "s") Not the most elegant approach, but it seems to work so far. Wayne From jchris at mfdz.com Mon Jan 8 00:55:01 2007 From: jchris at mfdz.com (Chris Anderson) Date: Sun, 7 Jan 2007 21:55:01 -0800 Subject: [rspec-users] thoughts on mocks and specs Message-ID: <e282921e0701072155t468a49e2wd6ae5cdb734a8c2d@mail.gmail.com> I spent the last couple of days getting my sea legs with Rails and RSpec. I'd been waiting til things seemed calmer before jumping in, and I'm overall very happy with my experience so far. My only real annoyance so far has been forgetting to call "do_post" or "do_create" from my specify blocks. My mocks don't get the calls they want, and it usually isn't until I've mucked around in my application code for a bit that I realize the real problem. Wouldn't it be nice to be able to define a callback that gets run after every specify block? Maybe it would look like this: context "A leaner syntaxed context" do setup do @obj = mock('obj') end body do @obj.whatever end specify "should run the body block after every specification" do @obj.should_receive(:whatever) end end I know sometimes one might want to put some verification code after the body. In that case, you could allow an explicit call to body from within the specify block, which would preclude it from being called again at the end. It seems to me that this feature isn't just a fight for DRY, but also encourages good spec design. Situations diverse enough to need separate body code could use different contexts anyway. If there is a call for this feature, I'd be happy to make a go at patching it into RSpec. Reactions? -- Chris Anderson http://jchris.mfdz.com From pergesu at gmail.com Mon Jan 8 01:19:50 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 7 Jan 2007 23:19:50 -0700 Subject: [rspec-users] thoughts on mocks and specs In-Reply-To: <e282921e0701072155t468a49e2wd6ae5cdb734a8c2d@mail.gmail.com> References: <e282921e0701072155t468a49e2wd6ae5cdb734a8c2d@mail.gmail.com> Message-ID: <810a540e0701072219t2d4c6b65n94d18741f20d99ae@mail.gmail.com> On 1/7/07, Chris Anderson <jchris at mfdz.com> wrote: > I spent the last couple of days getting my sea legs with Rails and > RSpec. I'd been waiting til things seemed calmer before jumping in, > and I'm overall very happy with my experience so far. > > My only real annoyance so far has been forgetting to call "do_post" or > "do_create" from my specify blocks. My mocks don't get the calls they > want, and it usually isn't until I've mucked around in my application > code for a bit that I realize the real problem. > > Wouldn't it be nice to be able to define a callback that gets run > after every specify block? Maybe it would look like this: > > context "A leaner syntaxed context" do > > setup do > @obj = mock('obj') > end > > body do > @obj.whatever > end > > specify "should run the body block after every specification" do > @obj.should_receive(:whatever) > end > > end > > I know sometimes one might want to put some verification code after > the body. In that case, you could allow an explicit call to body from > within the specify block, which would preclude it from being called > again at the end. > > It seems to me that this feature isn't just a fight for DRY, but also > encourages good spec design. Situations diverse enough to need > separate body code could use different contexts anyway. > > If there is a call for this feature, I'd be happy to make a go at > patching it into RSpec. > > Reactions? > > -- > Chris Anderson > http://jchris.mfdz.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You can do that using teardown. Pat From pergesu at gmail.com Mon Jan 8 06:19:18 2007 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 8 Jan 2007 04:19:18 -0700 Subject: [rspec-users] Controller actions do a bunch of javascript stuff...can I use spec that? Message-ID: <810a540e0701080319n50286a5fu2ff78497ce7802a7@mail.gmail.com> I've got a form that isn't doing a regular POST...what actually happens is that when onClick gets called, a bunch of javascript stuff happens. It changes the form's action to be a different URL. Then it polls for progress on another server, and when it's 100% reverts back to the initial URL. I know that sounds really ugly (and I agree it is), but that's the way it has to be at this point. Working with a "legacy" system. Is there any way I can spec that behavior with rspec? I sort of assume not, since it's highly dependent on JS...probably need to use jsunit for that instead. Still I've love to hear any ideas, as well as how I could move more of the behavior into Ruby instead of JS. Pat From dchelimsky at gmail.com Mon Jan 8 08:40:23 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Jan 2007 08:40:23 -0500 Subject: [rspec-users] Controller actions do a bunch of javascript stuff...can I use spec that? In-Reply-To: <810a540e0701080319n50286a5fu2ff78497ce7802a7@mail.gmail.com> References: <810a540e0701080319n50286a5fu2ff78497ce7802a7@mail.gmail.com> Message-ID: <57c63afe0701080540p4acf2f3csff8126e646caab4c@mail.gmail.com> On 1/8/07, Pat Maddox <pergesu at gmail.com> wrote: > I've got a form that isn't doing a regular POST...what actually > happens is that when onClick gets called, a bunch of javascript stuff > happens. It changes the form's action to be a different URL. Then it > polls for progress on another server, and when it's 100% reverts back > to the initial URL. > > I know that sounds really ugly (and I agree it is), but that's the way > it has to be at this point. Working with a "legacy" system. Is there > any way I can spec that behavior with rspec? I sort of assume not, > since it's highly dependent on JS...probably need to use jsunit for > that instead. Still I've love to hear any ideas, as well as how I > could move more of the behavior into Ruby instead of JS. I would test stuff like that in the browser using selenium or watir. There are existing hooks, like Selenium Remote Control, that allow you to drive these browser-based testing frameworks from ruby files. We're adding more integrated hooks into rspec for the next release as well. As for pushing the behaviour down to ruby, I can imagine a couple of options. One would be to have the onClick remote-link to an action that replaces the form tag and introduces a new javascript block that remote-links back to another action. The second action responds by polling for progress on the new server and updating the page w/ the same remote link (calling itself again) until the server responds 100%, at which point the second action restores the form tag. Another approach might be to have the onClick remote-link to an action that sets a variable in the session like session[:server_update_complete] = false, invokes the server update, starts polling for completion, and then sets session[:server_update_complete] = true when it gets back 100%. The form action would never change on the page, but the action would be written to check for that session variable and redirect to the appropriate action. I'm sure both of these have pitfalls that I'm not thinking of. Just a couple of ideas to bat around. Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jan 8 10:02:12 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Jan 2007 10:02:12 -0500 Subject: [rspec-users] thoughts on mocks and specs In-Reply-To: <810a540e0701072219t2d4c6b65n94d18741f20d99ae@mail.gmail.com> References: <e282921e0701072155t468a49e2wd6ae5cdb734a8c2d@mail.gmail.com> <810a540e0701072219t2d4c6b65n94d18741f20d99ae@mail.gmail.com> Message-ID: <57c63afe0701080702m7466b62ew6c728f60f0153c16@mail.gmail.com> On 1/8/07, Pat Maddox <pergesu at gmail.com> wrote: > On 1/7/07, Chris Anderson <jchris at mfdz.com> wrote: > > I spent the last couple of days getting my sea legs with Rails and > > RSpec. I'd been waiting til things seemed calmer before jumping in, > > and I'm overall very happy with my experience so far. > > > > My only real annoyance so far has been forgetting to call "do_post" or > > "do_create" from my specify blocks. My mocks don't get the calls they > > want, and it usually isn't until I've mucked around in my application > > code for a bit that I realize the real problem. > > > > Wouldn't it be nice to be able to define a callback that gets run > > after every specify block? Maybe it would look like this: > > > > context "A leaner syntaxed context" do > > > > setup do > > @obj = mock('obj') > > end > > > > body do > > @obj.whatever > > end > > > > specify "should run the body block after every specification" do > > @obj.should_receive(:whatever) > > end > > > > end > > > > I know sometimes one might want to put some verification code after > > the body. In that case, you could allow an explicit call to body from > > within the specify block, which would preclude it from being called > > again at the end. > > > > It seems to me that this feature isn't just a fight for DRY, but also > > encourages good spec design. Situations diverse enough to need > > separate body code could use different contexts anyway. > > > > If there is a call for this feature, I'd be happy to make a go at > > patching it into RSpec. > > > > Reactions? > > > > -- > > Chris Anderson > > http://jchris.mfdz.com > > You can do that using teardown. You could, yes, but that means that part of your spec is in teardown. To me, setup and teardown are for setting up and tearing down an environment in which you'll execute the specs. Each spec should tell it's whole story. You shouldn't have to look at setup or teardown to understand what is being specified, though you may need to look there to understand failures. Also, sometimes the do_blah needs to come after the expectations (when you're using mocks), and sometimes before, so we need some way to say "execute the request before OR after each specify block". Seems to me we're opening up a can of worms here. Simpler to just put it in the spec block. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dylanegan at gmail.com Tue Jan 9 05:37:10 2007 From: dylanegan at gmail.com (Dylan Egan) Date: Tue, 9 Jan 2007 21:37:10 +1100 Subject: [rspec-users] rcov seg fault Message-ID: <cbbc1640701090237v7b733007t995ec11312614648@mail.gmail.com> Hi Trying to get rcov going (has been working), but with the following context and specs it fails. context '/account POST with invalid attendee' do controller_name :account setup do Attendee.stub!(:create!).and_raise(ActiveRecord::RecordInvalid.new( Attendee.new)) end specify 'should raise on create' do Attendee.should_receive(:create!).with({ 'name' => 'Attendee' }).and_raise(ActiveRecord::RecordInvalid.new(Attendee.new)) post :create, :attendee => { :name => 'Attendee' } end specify 'should render new' do controller.should_render :action => 'new' post :create end end All I get is /usr/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/mocks/error_generator.rb:53: [BUG] Segmentation fault I tried variations on the specs and setup, but it fails when only running the should render new spec and everything else commented out. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070109/039ad785/attachment.html From jonathan.tron.mailings at gmail.com Tue Jan 9 05:58:18 2007 From: jonathan.tron.mailings at gmail.com (Jonathan Tron) Date: Tue, 9 Jan 2007 11:58:18 +0100 Subject: [rspec-users] rcov seg fault In-Reply-To: <cbbc1640701090237v7b733007t995ec11312614648@mail.gmail.com> References: <cbbc1640701090237v7b733007t995ec11312614648@mail.gmail.com> Message-ID: <514DD5CA-2A2D-484E-824F-F2AF3F2B06C1@gmail.com> Le 9 janv. 07 ? 11:37, Dylan Egan a ?crit : > Hi > > Trying to get rcov going (has been working), but with the following > context and specs it fails. ... > All I get is /usr/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/mocks/ > error_generator.rb:53: [BUG] Segmentation fault I get the same error but only on my MacbookPro and only when using mock_model (cf: http://www.dzone.com/rsslinks/ making_a_mockery_of_activerecord.html). The same code running on a debian server (ruby 1.8.5-4, rspec 0.7.5, rcov 0.7.0.1, Rails 1.2RC) don't produce the error... But I get failed specs I did not get on my MacbookPro (I'm using Cerberus for CI) Really weird... Jonathan -- Tron Jonathan http://jonathan.tron.name From dchelimsky at gmail.com Tue Jan 9 09:36:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 9 Jan 2007 08:36:33 -0600 Subject: [rspec-users] rcov seg fault In-Reply-To: <514DD5CA-2A2D-484E-824F-F2AF3F2B06C1@gmail.com> References: <cbbc1640701090237v7b733007t995ec11312614648@mail.gmail.com> <514DD5CA-2A2D-484E-824F-F2AF3F2B06C1@gmail.com> Message-ID: <57c63afe0701090636p50166481oa069ad6b17a7da2@mail.gmail.com> On 1/9/07, Jonathan Tron <jonathan.tron.mailings at gmail.com> wrote: > Le 9 janv. 07 ? 11:37, Dylan Egan a ?crit : > > > Hi > > > > Trying to get rcov going (has been working), but with the following > > context and specs it fails. > ... > > All I get is /usr/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/mocks/ > > error_generator.rb:53: [BUG] Segmentation fault > > I get the same error but only on my MacbookPro and only when using > mock_model (cf: http://www.dzone.com/rsslinks/ > making_a_mockery_of_activerecord.html). > The same code running on a debian server (ruby 1.8.5-4, rspec 0.7.5, > rcov 0.7.0.1, Rails 1.2RC) don't produce the error... But I get > failed specs I did not get on my MacbookPro (I'm using Cerberus for CI) > > Really weird... I was having similar problems on an MBP when I was using sqlite and rails. Since I started always using mysql, no problem. What was really weird was that I could get rid of the error by simply adding a few blank lines to any file that was involved in the spec run. VERY weird. > > Jonathan > -- > Tron Jonathan > http://jonathan.tron.name > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan.tron.mailings at gmail.com Tue Jan 9 09:52:27 2007 From: jonathan.tron.mailings at gmail.com (Jonathan Tron) Date: Tue, 9 Jan 2007 15:52:27 +0100 Subject: [rspec-users] rcov seg fault In-Reply-To: <57c63afe0701090636p50166481oa069ad6b17a7da2@mail.gmail.com> References: <cbbc1640701090237v7b733007t995ec11312614648@mail.gmail.com> <514DD5CA-2A2D-484E-824F-F2AF3F2B06C1@gmail.com> <57c63afe0701090636p50166481oa069ad6b17a7da2@mail.gmail.com> Message-ID: <69119765-D7BC-496A-AC08-F081E217D98F@gmail.com> Le 9 janv. 07 ? 15:36, David Chelimsky a ?crit : > I was having similar problems on an MBP when I was using sqlite and > rails. Since I started always using mysql, no problem. > > What was really weird was that I could get rid of the error by simply > adding a few blank lines to any file that was involved in the spec > run. VERY weird. That's exactly what I did after replying, I switched to MySQL (then to PostgreSQL ;) ) and all errors vanished. Besides these errors, the true (compared to sqlite's one) foreign key implementation of both Mysql/PostgreSQL forced me to refactor my spec on vanilla model separating more appropriatly what should be tested with and without fixtures loaded and what should hit the db and what should not :)... (mock with randomly generated id is BAD!!!!! when your db check for foreign keys infringement). Jonathan -- Tron Jonathan http://jonathan.tron.name From jonathan at home.tron.name Tue Jan 9 06:51:02 2007 From: jonathan at home.tron.name (Jonathan Tron) Date: Tue, 9 Jan 2007 12:51:02 +0100 Subject: [rspec-users] rcov seg fault In-Reply-To: <514DD5CA-2A2D-484E-824F-F2AF3F2B06C1@gmail.com> References: <cbbc1640701090237v7b733007t995ec11312614648@mail.gmail.com> <514DD5CA-2A2D-484E-824F-F2AF3F2B06C1@gmail.com> Message-ID: <B9F5E91C-904D-41AC-8FD0-C5B10227695B@home.tron.name> Le 9 janv. 07 ? 11:58, Jonathan Tron a ?crit : > Le 9 janv. 07 ? 11:37, Dylan Egan a ?crit : > >> Hi >> >> Trying to get rcov going (has been working), but with the following >> context and specs it fails. > ... >> All I get is /usr/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/mocks/ >> error_generator.rb:53: [BUG] Segmentation fault > > I get the same error but only on my MacbookPro and only when using > mock_model (cf: http://www.dzone.com/rsslinks/ > making_a_mockery_of_activerecord.html). > The same code running on a debian server (ruby 1.8.5-4, rspec 0.7.5, > rcov 0.7.0.1, Rails 1.2RC) don't produce the error... But I get > failed specs I did not get on my MacbookPro (I'm using Cerberus for > CI) I just find the problem with different rspec results between my two configuration... I use sqlite3 as test database and for a reason I ignore, the rake task db:test:prepare seems to cause ActiveRecord to pre-populate some of my models with quotes (''). My specs on presence_of validations then just failed. If I do a db:migrate / db:test:clone_structure and then run specs the errors vanished... Jonathan -- Tron Jonathan http://jonathan.tron.name From brian at yamabe.net Tue Jan 9 15:48:01 2007 From: brian at yamabe.net (Brian Yamabe) Date: Tue, 9 Jan 2007 12:48:01 -0800 Subject: [rspec-users] spec not running in TextMate Message-ID: <FBE2CCBA-875D-4AC5-9A6E-234F2BB3E0E8@yamabe.net> I tried running a spec with command-r in TextMate and got: /Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/ lib/spec_mate.rb:1:in `require': No such file to load -- rubygems (LoadError) from /Library/Application Support/TextMate/Bundles/ RSpec.tmbundle/Support/lib/spec_mate.rb:1 from /tmp/ temp_textmate.GplhPr:3:in `require' from /tmp/temp_textmate.GplhPr:3 The spec runs fine from the command line. Any ideas? Thanks, Brian From dylanegan at gmail.com Tue Jan 9 18:07:48 2007 From: dylanegan at gmail.com (Dylan Egan) Date: Wed, 10 Jan 2007 10:07:48 +1100 Subject: [rspec-users] rcov seg fault In-Reply-To: <B9F5E91C-904D-41AC-8FD0-C5B10227695B@home.tron.name> References: <cbbc1640701090237v7b733007t995ec11312614648@mail.gmail.com> <514DD5CA-2A2D-484E-824F-F2AF3F2B06C1@gmail.com> <B9F5E91C-904D-41AC-8FD0-C5B10227695B@home.tron.name> Message-ID: <cbbc1640701091507p4e392209kf59eddcd3b6ee20e@mail.gmail.com> Tried both suggestions. I moved from sqlite to postgresql. I also added some blank lines to the spec file, but without any luck. Will try and get it working somehow. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070110/52a9d0d2/attachment.html From cwdinfo at gmail.com Tue Jan 9 18:59:24 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 9 Jan 2007 15:59:24 -0800 Subject: [rspec-users] Date Approximation in Specs Message-ID: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> The floating-point expectations allow for an error tolerance. Is there any similar facility for dates? For example, say I have a custom class that handles date/time spans and I want to spec it: context "A DateRange span" do specify "should know when a week ago is :)" do d = DateRange.new d.last_week.should_be_close_to(1.week.ago, 24*60*60) end end The idea of should_be_close_to is to provide a tolerance. My class only is required to be accurate to the same day, and I want to express that in terms of "close_to" uncertainty. Is there a great baked-in way I'm missing? I have code to do this in Test::Unit that I could port over if need be but I'd rather not if something better already exists. Thanks, Steve From dchelimsky at gmail.com Tue Jan 9 19:45:08 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 9 Jan 2007 18:45:08 -0600 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> Message-ID: <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> On 1/9/07, s.ross <cwdinfo at gmail.com> wrote: > The floating-point expectations allow for an error tolerance. Is > there any similar facility for dates? For example, say I have a > custom class that handles date/time spans and I want to spec it: > > context "A DateRange span" do > specify "should know when a week ago is :)" do > d = DateRange.new > d.last_week.should_be_close_to(1.week.ago, 24*60*60) > end > end > > The idea of should_be_close_to is to provide a tolerance. My class > only is required to be accurate to the same day, and I want to > express that in terms of "close_to" uncertainty. Is there a great > baked-in way I'm missing? > > I have code to do this in Test::Unit that I could port over if need > be but I'd rather not if something better already exists. Doesn't exist yet. Feel free to add a feature request: http://rubyforge.org/tracker/?group_id=797 > Thanks, > > Steve > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Jan 9 23:26:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 9 Jan 2007 22:26:42 -0600 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> Message-ID: <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> On 1/9/07, David Chelimsky <dchelimsky at gmail.com> wrote: > On 1/9/07, s.ross <cwdinfo at gmail.com> wrote: > > The floating-point expectations allow for an error tolerance. Is > > there any similar facility for dates? For example, say I have a > > custom class that handles date/time spans and I want to spec it: > > > > context "A DateRange span" do > > specify "should know when a week ago is :)" do > > d = DateRange.new > > d.last_week.should_be_close_to(1.week.ago, 24*60*60) > > end > > end > > > > The idea of should_be_close_to is to provide a tolerance. My class > > only is required to be accurate to the same day, and I want to > > express that in terms of "close_to" uncertainty. Is there a great > > baked-in way I'm missing? > > > > I have code to do this in Test::Unit that I could port over if need > > be but I'd rather not if something better already exists. > > Doesn't exist yet. Feel free to add a feature request: > > http://rubyforge.org/tracker/?group_id=797 Hey Steve - I just committed a small enhancement to rspec core that is intended to pave the way for custom expectations. Are you working w/ 0.7.5 or the trunk? If you're working w/ trunk, grab the latest trunk and do this: module DateExpectations class BeCloseTo def initialize(target_date, tolerance) @target_date = target_date @tolerance = tolerance end def met_by?(target) #return true if target is a date #that meets the expectation end def failure_message #return an appropriate failure message end end def should_be_close_to(target_date, tolerance) return BeCloseTo.new(target_date, tolerance) end end context "My package" do include DateExpectations specify "should be delivered no later than 2 days after my order" do delivery_date.should be_close_to("1/9/2007", :days => 2) end end This is only experimental today, but will very likely become the entry way for custom expectations. Let me know how it works out for you. Cheers, David > > > Thanks, > > > > Steve > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From bhelmkamp at gmail.com Wed Jan 10 01:47:12 2007 From: bhelmkamp at gmail.com (Bryan Helmkamp) Date: Wed, 10 Jan 2007 01:47:12 -0500 Subject: [rspec-users] spec not running in TextMate In-Reply-To: <FBE2CCBA-875D-4AC5-9A6E-234F2BB3E0E8@yamabe.net> References: <FBE2CCBA-875D-4AC5-9A6E-234F2BB3E0E8@yamabe.net> Message-ID: <c0b8beca0701092247k641dcbb4j6583c7547e4855bb@mail.gmail.com> I don't have any help to offer, but I can confirm that I'm experiencing this issue right now, as well as some other people I have spoken with. -Bryan On 1/9/07, Brian Yamabe <brian at yamabe.net> wrote: > I tried running a spec with command-r in TextMate and got: > > /Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/ > lib/spec_mate.rb:1:in `require': No such file to load -- rubygems > (LoadError) from /Library/Application Support/TextMate/Bundles/ > RSpec.tmbundle/Support/lib/spec_mate.rb:1 from /tmp/ > temp_textmate.GplhPr:3:in `require' from /tmp/temp_textmate.GplhPr:3 > > The spec runs fine from the command line. > > Any ideas? > > Thanks, > Brian > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Wed Jan 10 02:26:42 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 9 Jan 2007 23:26:42 -0800 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> Message-ID: <9C454716-9EB6-472C-BCED-B1F1CE94E932@gmail.com> I'm running 0.7.5. I guess I should learn how to install rspec from svn, huh? Basically, each time I change my version of rspec, I have to dive into 5 or 6 projects to update their Rails plugins and so on... Any shortcuts you use when doing this? Thanks for doing this so quickly! Steve On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > On 1/9/07, David Chelimsky <dchelimsky at gmail.com> wrote: >> On 1/9/07, s.ross <cwdinfo at gmail.com> wrote: >>> The floating-point expectations allow for an error tolerance. Is >>> there any similar facility for dates? For example, say I have a >>> custom class that handles date/time spans and I want to spec it: >>> >>> context "A DateRange span" do >>> specify "should know when a week ago is :)" do >>> d = DateRange.new >>> d.last_week.should_be_close_to(1.week.ago, 24*60*60) >>> end >>> end >>> >>> The idea of should_be_close_to is to provide a tolerance. My class >>> only is required to be accurate to the same day, and I want to >>> express that in terms of "close_to" uncertainty. Is there a great >>> baked-in way I'm missing? >>> >>> I have code to do this in Test::Unit that I could port over if need >>> be but I'd rather not if something better already exists. >> >> Doesn't exist yet. Feel free to add a feature request: >> >> http://rubyforge.org/tracker/?group_id=797 > > Hey Steve - I just committed a small enhancement to rspec core that is > intended to pave the way for custom expectations. Are you working w/ > 0.7.5 or the trunk? If you're working w/ trunk, grab the latest trunk > and do this: > > module DateExpectations > class BeCloseTo > def initialize(target_date, tolerance) > @target_date = target_date > @tolerance = tolerance > end > > def met_by?(target) > #return true if target is a date > #that meets the expectation > end > > def failure_message > #return an appropriate failure message > end > end > > def should_be_close_to(target_date, tolerance) > return BeCloseTo.new(target_date, tolerance) > end > end > > context "My package" do > include DateExpectations > specify "should be delivered no later than 2 days after my order" do > delivery_date.should be_close_to("1/9/2007", :days => 2) > end > end > > This is only experimental today, but will very likely become the entry > way for custom expectations. Let me know how it works out for you. > > Cheers, > David > >> >>> Thanks, >>> >>> Steve >>> _______________________________________________ >>> 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 jonathan.tron.mailings at gmail.com Wed Jan 10 03:25:01 2007 From: jonathan.tron.mailings at gmail.com (Jonathan Tron) Date: Wed, 10 Jan 2007 09:25:01 +0100 Subject: [rspec-users] rcov seg fault In-Reply-To: <cbbc1640701091507p4e392209kf59eddcd3b6ee20e@mail.gmail.com> References: <cbbc1640701090237v7b733007t995ec11312614648@mail.gmail.com> <514DD5CA-2A2D-484E-824F-F2AF3F2B06C1@gmail.com> <B9F5E91C-904D-41AC-8FD0-C5B10227695B@home.tron.name> <cbbc1640701091507p4e392209kf59eddcd3b6ee20e@mail.gmail.com> Message-ID: <A0C78B0A-B1C5-4308-B5AD-30A39DCA3546@gmail.com> Le 10 janv. 07 ? 00:07, Dylan Egan a ?crit : > Tried both suggestions. I moved from sqlite to postgresql. > > I also added some blank lines to the spec file, but without any luck. > > Will try and get it working somehow. Sorry about the confusion, mysql/postgresql solutions was related to the fact that some specs doesn't work on sqlite3 when used in a different system. My problem of seg fault when using rcov and mock_model remains unsolved (on my MacbookPro), I think it's a bug in ruby or rcov but I don't really have time to track it down. Jonathan -- Tron Jonathan http://jonathan.tron.name From aslak.hellesoy at gmail.com Wed Jan 10 04:49:15 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 10 Jan 2007 10:49:15 +0100 Subject: [rspec-users] spec not running in TextMate In-Reply-To: <c0b8beca0701092247k641dcbb4j6583c7547e4855bb@mail.gmail.com> References: <FBE2CCBA-875D-4AC5-9A6E-234F2BB3E0E8@yamabe.net> <c0b8beca0701092247k641dcbb4j6583c7547e4855bb@mail.gmail.com> Message-ID: <8d961d900701100149k1bcd48d1q7de9791cd0bb9c72@mail.gmail.com> Sounds like TM is running a Ruby interpreter that doesn't have Rubygems installed. Tell TM to run a different Ruby - it's documented somewhere, but I don't remember where. Aslak On 1/10/07, Bryan Helmkamp <bhelmkamp at gmail.com> wrote: > I don't have any help to offer, but I can confirm that I'm > experiencing this issue right now, as well as some other people I have > spoken with. > > -Bryan > > On 1/9/07, Brian Yamabe <brian at yamabe.net> wrote: > > I tried running a spec with command-r in TextMate and got: > > > > /Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/ > > lib/spec_mate.rb:1:in `require': No such file to load -- rubygems > > (LoadError) from /Library/Application Support/TextMate/Bundles/ > > RSpec.tmbundle/Support/lib/spec_mate.rb:1 from /tmp/ > > temp_textmate.GplhPr:3:in `require' from /tmp/temp_textmate.GplhPr:3 > > > > The spec runs fine from the command line. > > > > Any ideas? > > > > Thanks, > > Brian > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brian at yamabe.net Wed Jan 10 07:21:12 2007 From: brian at yamabe.net (Brian Yamabe) Date: Wed, 10 Jan 2007 04:21:12 -0800 Subject: [rspec-users] spec not running in TextMate In-Reply-To: <8d961d900701100149k1bcd48d1q7de9791cd0bb9c72@mail.gmail.com> References: <FBE2CCBA-875D-4AC5-9A6E-234F2BB3E0E8@yamabe.net> <c0b8beca0701092247k641dcbb4j6583c7547e4855bb@mail.gmail.com> <8d961d900701100149k1bcd48d1q7de9791cd0bb9c72@mail.gmail.com> Message-ID: <DA7394F9-999B-489E-8732-545E21BDD093@yamabe.net> I do have TM_RUBY set to the same Ruby interpreter as the one I use from the terminal. ---Brian On Jan 10, 2007, at 1:49 AM, aslak hellesoy wrote: > Sounds like TM is running a Ruby interpreter that doesn't have > Rubygems installed. > > Tell TM to run a different Ruby - it's documented somewhere, but I > don't remember where. > > Aslak > > On 1/10/07, Bryan Helmkamp <bhelmkamp at gmail.com> wrote: >> I don't have any help to offer, but I can confirm that I'm >> experiencing this issue right now, as well as some other people I >> have >> spoken with. >> >> -Bryan >> >> On 1/9/07, Brian Yamabe <brian at yamabe.net> wrote: >>> I tried running a spec with command-r in TextMate and got: >>> >>> /Library/Application Support/TextMate/Bundles/RSpec.tmbundle/ >>> Support/ >>> lib/spec_mate.rb:1:in `require': No such file to load -- rubygems >>> (LoadError) from /Library/Application Support/TextMate/Bundles/ >>> RSpec.tmbundle/Support/lib/spec_mate.rb:1 from /tmp/ >>> temp_textmate.GplhPr:3:in `require' from /tmp/temp_textmate.GplhPr:3 >>> >>> The spec runs fine from the command line. >>> >>> Any ideas? >>> >>> Thanks, >>> Brian >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Wed Jan 10 10:00:54 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 10 Jan 2007 16:00:54 +0100 Subject: [rspec-users] spec not running in TextMate In-Reply-To: <DA7394F9-999B-489E-8732-545E21BDD093@yamabe.net> References: <FBE2CCBA-875D-4AC5-9A6E-234F2BB3E0E8@yamabe.net> <c0b8beca0701092247k641dcbb4j6583c7547e4855bb@mail.gmail.com> <8d961d900701100149k1bcd48d1q7de9791cd0bb9c72@mail.gmail.com> <DA7394F9-999B-489E-8732-545E21BDD093@yamabe.net> Message-ID: <8d961d900701100700j30c674e7pf216ad9e42039eb@mail.gmail.com> Let's narrow it down a little to see if this is a problem with the bundle or your environment. Try this: 1) Create a file called foo.rb 2) Add one line to it: require 'rubygems' 3) Open it in TextMate 4) Run it from TextMate (Cmd-R - Run) Do you get the same error? If so, your environment is bad. Aslak On 1/10/07, Brian Yamabe <brian at yamabe.net> wrote: > I do have TM_RUBY set to the same Ruby interpreter as the one I use > from the terminal. > > ---Brian > > On Jan 10, 2007, at 1:49 AM, aslak hellesoy wrote: > > > Sounds like TM is running a Ruby interpreter that doesn't have > > Rubygems installed. > > > > Tell TM to run a different Ruby - it's documented somewhere, but I > > don't remember where. > > > > Aslak > > > > On 1/10/07, Bryan Helmkamp <bhelmkamp at gmail.com> wrote: > >> I don't have any help to offer, but I can confirm that I'm > >> experiencing this issue right now, as well as some other people I > >> have > >> spoken with. > >> > >> -Bryan > >> > >> On 1/9/07, Brian Yamabe <brian at yamabe.net> wrote: > >>> I tried running a spec with command-r in TextMate and got: > >>> > >>> /Library/Application Support/TextMate/Bundles/RSpec.tmbundle/ > >>> Support/ > >>> lib/spec_mate.rb:1:in `require': No such file to load -- rubygems > >>> (LoadError) from /Library/Application Support/TextMate/Bundles/ > >>> RSpec.tmbundle/Support/lib/spec_mate.rb:1 from /tmp/ > >>> temp_textmate.GplhPr:3:in `require' from /tmp/temp_textmate.GplhPr:3 > >>> > >>> The spec runs fine from the command line. > >>> > >>> Any ideas? > >>> > >>> Thanks, > >>> Brian > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > 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 brian at yamabe.net Wed Jan 10 10:56:11 2007 From: brian at yamabe.net (Brian Yamabe) Date: Wed, 10 Jan 2007 07:56:11 -0800 Subject: [rspec-users] spec not running in TextMate In-Reply-To: <8d961d900701100700j30c674e7pf216ad9e42039eb@mail.gmail.com> References: <FBE2CCBA-875D-4AC5-9A6E-234F2BB3E0E8@yamabe.net> <c0b8beca0701092247k641dcbb4j6583c7547e4855bb@mail.gmail.com> <8d961d900701100149k1bcd48d1q7de9791cd0bb9c72@mail.gmail.com> <DA7394F9-999B-489E-8732-545E21BDD093@yamabe.net> <8d961d900701100700j30c674e7pf216ad9e42039eb@mail.gmail.com> Message-ID: <647AD79E-646B-4075-8259-DE2A6FC54C6E@yamabe.net> Tried it and it worked without a problem, so it looks like a bundle problem. I don't know much about bundles, but I'd be happy to work with someone who has suggestions for how to fix this. Thank, Aslak. You and David do a great job on this list. ---Brian On Jan 10, 2007, at 7:00 AM, aslak hellesoy wrote: > Let's narrow it down a little to see if this is a problem with the > bundle or your environment. > > Try this: > > 1) Create a file called foo.rb > 2) Add one line to it: require 'rubygems' > 3) Open it in TextMate > 4) Run it from TextMate (Cmd-R - Run) > > Do you get the same error? If so, your environment is bad. > > Aslak > > On 1/10/07, Brian Yamabe <brian at yamabe.net> wrote: >> I do have TM_RUBY set to the same Ruby interpreter as the one I use >> from the terminal. >> >> ---Brian >> >> On Jan 10, 2007, at 1:49 AM, aslak hellesoy wrote: >> >>> Sounds like TM is running a Ruby interpreter that doesn't have >>> Rubygems installed. >>> >>> Tell TM to run a different Ruby - it's documented somewhere, but I >>> don't remember where. >>> >>> Aslak >>> >>> On 1/10/07, Bryan Helmkamp <bhelmkamp at gmail.com> wrote: >>>> I don't have any help to offer, but I can confirm that I'm >>>> experiencing this issue right now, as well as some other people I >>>> have >>>> spoken with. >>>> >>>> -Bryan >>>> >>>> On 1/9/07, Brian Yamabe <brian at yamabe.net> wrote: >>>>> I tried running a spec with command-r in TextMate and got: >>>>> >>>>> /Library/Application Support/TextMate/Bundles/RSpec.tmbundle/ >>>>> Support/ >>>>> lib/spec_mate.rb:1:in `require': No such file to load -- rubygems >>>>> (LoadError) from /Library/Application Support/TextMate/Bundles/ >>>>> RSpec.tmbundle/Support/lib/spec_mate.rb:1 from /tmp/ >>>>> temp_textmate.GplhPr:3:in `require' from /tmp/ >>>>> temp_textmate.GplhPr:3 >>>>> >>>>> The spec runs fine from the command line. >>>>> >>>>> Any ideas? >>>>> >>>>> Thanks, >>>>> Brian >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From cwdinfo at gmail.com Wed Jan 10 14:01:57 2007 From: cwdinfo at gmail.com (s.ross) Date: Wed, 10 Jan 2007 11:01:57 -0800 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> Message-ID: <EBC7915C-3B7F-498F-BA8C-DFC333DB1F2C@gmail.com> I upgraded to trunk and changed the code as follows: module DateExpectations HOUR_TOLERANCE = 60 * 60 DAY_TOLERANCE = HOUR_TOLERANCE * 24 WEEK_TOLERANCE = DAY_TOLERANCE * 7 class BeCloseTo def initialize(target_date, tolerance) @target_date = Time.parse(target_date) @tolerance = tolerance end def met_by?(target) compare_date = target - @target_date adjustment = @tolerance.inject do |item| case item when :days adjustment += DAY_TOLERANCE when :weeks adjustment += WEEK_TOLERANCE end end return true if compare_date.abs < adjustment end def failure_message return "#{@target_date} does not fall within tolerance." # s/ b better end end def should_be_close_to(target_date, tolerance) return BeCloseTo.new(target_date, tolerance) end end context "My package" do include DateExpectations specify "should be delivered no later than 2 days after my order" do 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- line 40 end end The result is: 1) NoMethodError in 'My package should be delivered no later than 2 days after my order' undefined method `close_to?' for Tue Jan 09 10:59:31 -0800 2007:Time ./spec/helpers/date_range_spec.rb:40: Any thoughts as to why? (Note: You had written the expectation in your sample as: "should<space>be_close_to" -- was that intentional?). Steve On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > module DateExpectations > class BeCloseTo > def initialize(target_date, tolerance) > @target_date = target_date > @tolerance = tolerance > end > > def met_by?(target) > #return true if target is a date > #that meets the expectation > end > > def failure_message > #return an appropriate failure message > end > end > > def should_be_close_to(target_date, tolerance) > return BeCloseTo.new(target_date, tolerance) > end > end > > context "My package" do > include DateExpectations > specify "should be delivered no later than 2 days after my order" do > delivery_date.should be_close_to("1/9/2007", :days => 2) > end > end From rob at muhlestein.net Wed Jan 10 13:31:24 2007 From: rob at muhlestein.net (Rob Muhlestein) Date: Wed, 10 Jan 2007 13:31:24 -0500 Subject: [rspec-users] foo_spec.rb -> foo.rspec (proposed RSpec file name convention) Message-ID: <1168453884.4245.53.camel@dads> Is it too late to suggest some filename conventions for example rspec files--especially when bundling with gems? I see spec_foo.rb and foo_spec.rb around. Also found some foo_ex.rb around. Would having a foo.rspec be worth talking about? Or is the convention more or less to have 'spec' in the file name? I have to confess the only real motivation I have at the moment is syntax highlighting without adding RSpec DSL tags to ruby.vim (which I went ahead and did anyway.) If acceptable as a published convention, we could then recommend to editor projects. Here's one link suggesting how to incorporate RSpec into rake and gems: http://townx.org/running_rspec_as_a_rake_task Personally I'd like so see this convention distilled enough to be mentioned in the pickax "Creating Your Own Gems - Package Layout" section (not to mention an entire additional section dedicated to BDD to go with or replace the old asserts stuff). Loving RSpec. You actually get work done while writing that spec doc any PHB can understand, even if the application isn't written in Ruby. Looking forward to using RSpec from JRuby to apply BDD to the legacy Java stuff. Regards, -- Rob Muhlestein http://rob.muhlestein.net From shane.duan at gmail.com Wed Jan 10 14:14:41 2007 From: shane.duan at gmail.com (Shane Duan) Date: Wed, 10 Jan 2007 11:14:41 -0800 Subject: [rspec-users] foo_spec.rb -> foo.rspec (proposed RSpec file name convention) In-Reply-To: <1168453884.4245.53.camel@dads> References: <1168453884.4245.53.camel@dads> Message-ID: <bd7896da0701101114t43285a49kb4b7d1a3f751bd24@mail.gmail.com> Coming up with new extension involves buy-ins from all the editors (intelliJ, eclipse, vi, emacs), and major operation systems. So I really doubt it will take off. Having the naming convention feels like a good way to go. As for the link provided, you just meant the naming convention, right? I learned to write it just following rspec's document. Worked out great for me, especially the rcov and rspec HTML report. On 1/10/07, Rob Muhlestein <rob at muhlestein.net> wrote: > Is it too late to suggest some filename conventions for example rspec > files--especially when bundling with gems? > > I see spec_foo.rb and foo_spec.rb around. Also found some foo_ex.rb > around. Would having a foo.rspec be worth talking about? Or is the > convention more or less to have 'spec' in the file name? > > I have to confess the only real motivation I have at the moment is > syntax highlighting without adding RSpec DSL tags to ruby.vim (which I > went ahead and did anyway.) If acceptable as a published convention, we > could then recommend to editor projects. > > Here's one link suggesting how to incorporate RSpec into rake and gems: > > http://townx.org/running_rspec_as_a_rake_task > > Personally I'd like so see this convention distilled enough to be > mentioned in the pickax "Creating Your Own Gems - Package Layout" > section (not to mention an entire additional section dedicated to > BDD to go with or replace the old asserts stuff). > > Loving RSpec. You actually get work done while writing that spec doc any > PHB can understand, even if the application isn't written in Ruby. > Looking forward to using RSpec from JRuby to apply BDD to the legacy > Java stuff. > > Regards, > > -- > Rob Muhlestein > http://rob.muhlestein.net > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Shane http://www.shaneduan.com From pergesu at gmail.com Wed Jan 10 14:16:52 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 10 Jan 2007 12:16:52 -0700 Subject: [rspec-users] foo_spec.rb -> foo.rspec (proposed RSpec file name convention) In-Reply-To: <1168453884.4245.53.camel@dads> References: <1168453884.4245.53.camel@dads> Message-ID: <810a540e0701101116t289a4302p2a6a70ea3415bf33@mail.gmail.com> On 1/10/07, Rob Muhlestein <rob at muhlestein.net> wrote: > Is it too late to suggest some filename conventions for example rspec > files--especially when bundling with gems? > > I see spec_foo.rb and foo_spec.rb around. Also found some foo_ex.rb > around. Would having a foo.rspec be worth talking about? Or is the > convention more or less to have 'spec' in the file name? I like foo_spec.rb Pat From bryan at osesm.com Wed Jan 10 14:18:58 2007 From: bryan at osesm.com (Bryan Liles) Date: Wed, 10 Jan 2007 14:18:58 -0500 Subject: [rspec-users] foo_spec.rb -> foo.rspec (proposed RSpec file name convention) In-Reply-To: <1168453884.4245.53.camel@dads> References: <1168453884.4245.53.camel@dads> Message-ID: <15D6D9AD-CEBD-43C3-A754-E79538E77D1F@osesm.com> On Jan 10, 2007, at 1:31 PM, Rob Muhlestein wrote: > Is it too late to suggest some filename conventions for example rspec > files--especially when bundling with gems? > > I see spec_foo.rb and foo_spec.rb around. Also found some foo_ex.rb > around. Would having a foo.rspec be worth talking about? Or is the > convention more or less to have 'spec' in the file name? > I would vote against this (even if my vote even mattered). I like to think of my rspecs of ruby that actually verifies my code is doing what I think it is doing. From dchelimsky at gmail.com Wed Jan 10 14:22:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Jan 2007 13:22:01 -0600 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <EBC7915C-3B7F-498F-BA8C-DFC333DB1F2C@gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> <EBC7915C-3B7F-498F-BA8C-DFC333DB1F2C@gmail.com> Message-ID: <57c63afe0701101122t281a11ebr4b542a885081accf@mail.gmail.com> On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: > I upgraded to trunk and changed the code as follows: > > module DateExpectations > HOUR_TOLERANCE = 60 * 60 > DAY_TOLERANCE = HOUR_TOLERANCE * 24 > WEEK_TOLERANCE = DAY_TOLERANCE * 7 > > class BeCloseTo > def initialize(target_date, tolerance) > @target_date = Time.parse(target_date) > @tolerance = tolerance > end > > def met_by?(target) > compare_date = target - @target_date > adjustment = @tolerance.inject do |item| > case item > when :days > adjustment += DAY_TOLERANCE > when :weeks > adjustment += WEEK_TOLERANCE > end > end > return true if compare_date.abs < adjustment > end > > def failure_message > return "#{@target_date} does not fall within tolerance." # s/ > b better > end > end > > def should_be_close_to(target_date, tolerance) > return BeCloseTo.new(target_date, tolerance) > end > end > > context "My package" do > include DateExpectations > specify "should be delivered no later than 2 days after my order" do > 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- line 40 > end > end > > The result is: > > 1) > NoMethodError in 'My package should be delivered no later than 2 days > after my order' > undefined method `close_to?' for Tue Jan 09 10:59:31 -0800 2007:Time > ./spec/helpers/date_range_spec.rb:40: > > > Any thoughts as to why? (Note: You had written the expectation in > your sample as: > "should<space>be_close_to" -- was that intentional?). Yes!!!! That's the whole point. ;) should be_close_to and your method should be named be_close_to Let me know how it works out. Thanks for giving this a shot - you're the guinea pig! David > > Steve > > > On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > > > module DateExpectations > > class BeCloseTo > > def initialize(target_date, tolerance) > > @target_date = target_date > > @tolerance = tolerance > > end > > > > def met_by?(target) > > #return true if target is a date > > #that meets the expectation > > end > > > > def failure_message > > #return an appropriate failure message > > end > > end > > > > def should_be_close_to(target_date, tolerance) > > return BeCloseTo.new(target_date, tolerance) > > end > > end > > > > context "My package" do > > include DateExpectations > > specify "should be delivered no later than 2 days after my order" do > > delivery_date.should be_close_to("1/9/2007", :days => 2) > > end > > end > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From shane.duan at gmail.com Wed Jan 10 14:26:21 2007 From: shane.duan at gmail.com (Shane Duan) Date: Wed, 10 Jan 2007 11:26:21 -0800 Subject: [rspec-users] foo_spec.rb -> foo.rspec (proposed RSpec file name convention) In-Reply-To: <810a540e0701101116t289a4302p2a6a70ea3415bf33@mail.gmail.com> References: <1168453884.4245.53.camel@dads> <810a540e0701101116t289a4302p2a6a70ea3415bf33@mail.gmail.com> Message-ID: <bd7896da0701101126m3b7d32e5h7964333ee3a1e3b3@mail.gmail.com> The history from the Java world has shown that there will never be one standard. People choose different naming for different preferences. I even have 'tc_' prefix in the project because I never bothered the trouble after I converted them from ruby unit. On 1/10/07, Pat Maddox <pergesu at gmail.com> wrote: > On 1/10/07, Rob Muhlestein <rob at muhlestein.net> wrote: > > Is it too late to suggest some filename conventions for example rspec > > files--especially when bundling with gems? > > > > I see spec_foo.rb and foo_spec.rb around. Also found some foo_ex.rb > > around. Would having a foo.rspec be worth talking about? Or is the > > convention more or less to have 'spec' in the file name? > > I like foo_spec.rb > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Shane http://www.shaneduan.com From dchelimsky at gmail.com Wed Jan 10 14:28:55 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Jan 2007 13:28:55 -0600 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <57c63afe0701101122t281a11ebr4b542a885081accf@mail.gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> <EBC7915C-3B7F-498F-BA8C-DFC333DB1F2C@gmail.com> <57c63afe0701101122t281a11ebr4b542a885081accf@mail.gmail.com> Message-ID: <57c63afe0701101128t6f81d2f9y2896c928c5e6d6e1@mail.gmail.com> On 1/10/07, David Chelimsky <dchelimsky at gmail.com> wrote: > On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: > > I upgraded to trunk and changed the code as follows: > > > > module DateExpectations > > HOUR_TOLERANCE = 60 * 60 > > DAY_TOLERANCE = HOUR_TOLERANCE * 24 > > WEEK_TOLERANCE = DAY_TOLERANCE * 7 > > > > class BeCloseTo > > def initialize(target_date, tolerance) > > @target_date = Time.parse(target_date) > > @tolerance = tolerance > > end > > > > def met_by?(target) > > compare_date = target - @target_date > > adjustment = @tolerance.inject do |item| > > case item > > when :days > > adjustment += DAY_TOLERANCE > > when :weeks > > adjustment += WEEK_TOLERANCE > > end > > end > > return true if compare_date.abs < adjustment > > end > > > > def failure_message > > return "#{@target_date} does not fall within tolerance." # s/ > > b better > > end > > end > > > > def should_be_close_to(target_date, tolerance) > > return BeCloseTo.new(target_date, tolerance) > > end > > end > > > > context "My package" do > > include DateExpectations > > specify "should be delivered no later than 2 days after my order" do > > 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- line 40 > > end > > end > > > > The result is: > > > > 1) > > NoMethodError in 'My package should be delivered no later than 2 days > > after my order' > > undefined method `close_to?' for Tue Jan 09 10:59:31 -0800 2007:Time > > ./spec/helpers/date_range_spec.rb:40: > > > > > > Any thoughts as to why? (Note: You had written the expectation in > > your sample as: > > "should<space>be_close_to" -- was that intentional?). > > Yes!!!! That's the whole point. ;) I should clarify that a bit. The idea is to decouple expectations from Object so that we can more easily write, maintain and extend them while simultaneously minimizing the risk of other frameworks (like rails) screwing w/ our use of method missing. If you look at the initialize method in should.rb, it now takes an optional expectation argument. If it gets one, it processes it. What you are writing is an expectation that gets passed to should, which then passes the target to the expectation for verification. Make sense? David > > should be_close_to > > and your method should be named be_close_to > > Let me know how it works out. > > Thanks for giving this a shot - you're the guinea pig! > > David > > > > > Steve > > > > > > On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > > > > > module DateExpectations > > > class BeCloseTo > > > def initialize(target_date, tolerance) > > > @target_date = target_date > > > @tolerance = tolerance > > > end > > > > > > def met_by?(target) > > > #return true if target is a date > > > #that meets the expectation > > > end > > > > > > def failure_message > > > #return an appropriate failure message > > > end > > > end > > > > > > def should_be_close_to(target_date, tolerance) > > > return BeCloseTo.new(target_date, tolerance) > > > end > > > end > > > > > > context "My package" do > > > include DateExpectations > > > specify "should be delivered no later than 2 days after my order" do > > > delivery_date.should be_close_to("1/9/2007", :days => 2) > > > end > > > end > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From dchelimsky at gmail.com Wed Jan 10 14:40:27 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 10 Jan 2007 13:40:27 -0600 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <57c63afe0701101128t6f81d2f9y2896c928c5e6d6e1@mail.gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> <EBC7915C-3B7F-498F-BA8C-DFC333DB1F2C@gmail.com> <57c63afe0701101122t281a11ebr4b542a885081accf@mail.gmail.com> <57c63afe0701101128t6f81d2f9y2896c928c5e6d6e1@mail.gmail.com> Message-ID: <57c63afe0701101140i72e41457v7ed86b6e1d24f2c8@mail.gmail.com> On 1/10/07, David Chelimsky <dchelimsky at gmail.com> wrote: > On 1/10/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: > > > I upgraded to trunk and changed the code as follows: > > > > > > module DateExpectations > > > HOUR_TOLERANCE = 60 * 60 > > > DAY_TOLERANCE = HOUR_TOLERANCE * 24 > > > WEEK_TOLERANCE = DAY_TOLERANCE * 7 > > > > > > class BeCloseTo > > > def initialize(target_date, tolerance) > > > @target_date = Time.parse(target_date) > > > @tolerance = tolerance > > > end > > > > > > def met_by?(target) > > > compare_date = target - @target_date > > > adjustment = @tolerance.inject do |item| > > > case item > > > when :days > > > adjustment += DAY_TOLERANCE > > > when :weeks > > > adjustment += WEEK_TOLERANCE > > > end > > > end > > > return true if compare_date.abs < adjustment > > > end > > > > > > def failure_message > > > return "#{@target_date} does not fall within tolerance." # s/ > > > b better > > > end > > > end > > > > > > def should_be_close_to(target_date, tolerance) > > > return BeCloseTo.new(target_date, tolerance) > > > end > > > end > > > > > > context "My package" do > > > include DateExpectations > > > specify "should be delivered no later than 2 days after my order" do > > > 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- line 40 > > > end > > > end > > > > > > The result is: > > > > > > 1) > > > NoMethodError in 'My package should be delivered no later than 2 days > > > after my order' > > > undefined method `close_to?' for Tue Jan 09 10:59:31 -0800 2007:Time > > > ./spec/helpers/date_range_spec.rb:40: > > > > > > > > > Any thoughts as to why? (Note: You had written the expectation in > > > your sample as: > > > "should<space>be_close_to" -- was that intentional?). > > > > Yes!!!! That's the whole point. ;) > > I should clarify that a bit. The idea is to decouple expectations from > Object so that we can more easily write, maintain and extend them > while simultaneously minimizing the risk of other frameworks (like > rails) screwing w/ our use of method missing. > > If you look at the initialize method in should.rb, it now takes an > optional expectation argument. If it gets one, it processes it. What > you are writing is an expectation that gets passed to should, which > then passes the target to the expectation for verification. > > Make sense? I blogged about this here: http://blog.davidchelimsky.net/articles/2007/01/10/rspec-should-use_a_little_less_magic Comments welcome and appreciated. Thanks, David > > David > > > > > should be_close_to > > > > and your method should be named be_close_to > > > > Let me know how it works out. > > > > Thanks for giving this a shot - you're the guinea pig! > > > > David > > > > > > > > Steve > > > > > > > > > On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > > > > > > > module DateExpectations > > > > class BeCloseTo > > > > def initialize(target_date, tolerance) > > > > @target_date = target_date > > > > @tolerance = tolerance > > > > end > > > > > > > > def met_by?(target) > > > > #return true if target is a date > > > > #that meets the expectation > > > > end > > > > > > > > def failure_message > > > > #return an appropriate failure message > > > > end > > > > end > > > > > > > > def should_be_close_to(target_date, tolerance) > > > > return BeCloseTo.new(target_date, tolerance) > > > > end > > > > end > > > > > > > > context "My package" do > > > > include DateExpectations > > > > specify "should be delivered no later than 2 days after my order" do > > > > delivery_date.should be_close_to("1/9/2007", :days => 2) > > > > end > > > > end > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > From rob at muhlestein.net Wed Jan 10 15:44:53 2007 From: rob at muhlestein.net (Rob Muhlestein) Date: Wed, 10 Jan 2007 15:44:53 -0500 Subject: [rspec-users] foo_spec.rb -> foo.rspec (proposed RSpec file name convention) In-Reply-To: <bd7896da0701101126m3b7d32e5h7964333ee3a1e3b3@mail.gmail.com> References: <1168453884.4245.53.camel@dads> <810a540e0701101116t289a4302p2a6a70ea3415bf33@mail.gmail.com> <bd7896da0701101126m3b7d32e5h7964333ee3a1e3b3@mail.gmail.com> Message-ID: <1168461893.4245.64.camel@dads> On Wed, 2007-01-10 at 11:26 -0800, Shane Duan wrote: > On 1/10/07, Pat Maddox <pergesu at gmail.com> wrote: > > On 1/10/07, Rob Muhlestein <rob at muhlestein.net> wrote: > > > Is it too late to suggest some filename conventions for example rspec > > > files--especially when bundling with gems? > > > > > > I see spec_foo.rb and foo_spec.rb around. Also found some foo_ex.rb > > > around. Would having a foo.rspec be worth talking about? Or is the > > > convention more or less to have 'spec' in the file name? > > > > I like foo_spec.rb > [... corrected top-posting ...] > The history from the Java world has shown that there will never be one > standard. People choose different naming for different preferences. > I even have 'tc_' prefix in the project because I never bothered the > trouble after I converted them from ruby unit. Agreed, but convention is different than standard. Perl users starting using .t for their test scripts and it stuck. After a full reread of the http://rspec.rubyforge.org site (a good one I might add) it is very clear the intent is to use foo_spec.rb and from under the 'spec/' directory in rails. It makes sense, then, that for gems these should go in 'spec/' next to 'lib/' for example although I'm sure we'll find specs in 'test/' for many years to come. I'll go ahead and submit a patch to ruby-vim adding the rspec DSL tags (context, setup, etc). Is there even one other vim user on this list that understands my point? Thanks -- Rob Muhlestein http://rob.muhlestein.net From rob at muhlestein.net Wed Jan 10 15:56:19 2007 From: rob at muhlestein.net (Rob Muhlestein) Date: Wed, 10 Jan 2007 15:56:19 -0500 Subject: [rspec-users] foo_spec.rb -> foo.rspec (proposed RSpec file name convention) In-Reply-To: <bd7896da0701101114t43285a49kb4b7d1a3f751bd24@mail.gmail.com> References: <1168453884.4245.53.camel@dads> <bd7896da0701101114t43285a49kb4b7d1a3f751bd24@mail.gmail.com> Message-ID: <1168462579.4245.75.camel@dads> On Wed, 2007-01-10 at 11:14 -0800, Shane Duan wrote: > As for the link provided, you just meant the naming convention, right? > I learned to write it just following rspec's document. Worked out > great for me, especially the rcov and rspec HTML report. The only part I was missing was that you can replace use of the 'spec' command with the following to make your spec a standalone ruby script: require 'rubygems' require_gem 'rspec' Obviously this is needed to define the 'context', 'setup', and the rest of the RSpec DSL. This can be derived from cracking open the 'spec' command, but is not immediately obvious to newbies, which I still consider myself to be. By the way, this isn't mentioned anywhere on the http://rspec.rubyforge.org web site and was not immediately obvious to me. This might be for a very good reason that I just don't see yet, but if not, I'd like to humble suggest a note go into the example or tutorial to cover it. -- Rob Muhlestein http://rob.muhlestein.net From rob at muhlestein.net Wed Jan 10 16:15:35 2007 From: rob at muhlestein.net (Rob Muhlestein) Date: Wed, 10 Jan 2007 16:15:35 -0500 Subject: [rspec-users] foo_spec.rb -> foo.rspec (proposed RSpec file name convention) In-Reply-To: <1168461893.4245.64.camel@dads> References: <1168453884.4245.53.camel@dads> <810a540e0701101116t289a4302p2a6a70ea3415bf33@mail.gmail.com> <bd7896da0701101126m3b7d32e5h7964333ee3a1e3b3@mail.gmail.com> <1168461893.4245.64.camel@dads> Message-ID: <1168463735.4245.83.camel@dads> On Wed, 2007-01-10 at 15:44 -0500, Rob Muhlestein wrote: > I'll go ahead and submit a patch to ruby-vim adding the rspec DSL tags > (context, setup, etc). Here are all the keywords from the RSpec DSL that I can gather from the website: context context_setup setup specify context_teardown teardown Am I missing any? I've got them and few others (require_gem) I'm going to submit as a ruby.vim patch to ruby-vim. Perhaps updates to the other editors might be nice as well. -- Rob Muhlestein http://rob.muhlestein.net From cwdinfo at gmail.com Thu Jan 11 02:18:11 2007 From: cwdinfo at gmail.com (s.ross) Date: Wed, 10 Jan 2007 23:18:11 -0800 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <57c63afe0701101122t281a11ebr4b542a885081accf@mail.gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> <EBC7915C-3B7F-498F-BA8C-DFC333DB1F2C@gmail.com> <57c63afe0701101122t281a11ebr4b542a885081accf@mail.gmail.com> Message-ID: <BFEBA93D-76A8-4D9D-BA4B-1BD3FA385984@gmail.com> My net connection's gone spotty over the last couple of days, but I wanted to follow up and tell you that your new code works great. Here's just a proof of concept implementation (complete with hard coding!): module DateExpectations HOUR_TOLERANCE = 60 * 60 DAY_TOLERANCE = HOUR_TOLERANCE * 24 WEEK_TOLERANCE = DAY_TOLERANCE * 7 class BeCloseTo def initialize(target_date, tolerance) @target_date = Time.parse(target_date) @tolerance = tolerance end def met_by?(target) @compare_date = target compare_span = target - @target_date adjustment = 0 @tolerance.each do |key, amount| case key when :hours adjustment += HOUR_TOLERANCE * amount when :days adjustment += DAY_TOLERANCE * amount when :weeks adjustment += WEEK_TOLERANCE * amount end end return true if compare_span.abs < adjustment end def failure_message return "#{@target_date} does not fall within tolerance (# {@tolerance.collect{|k,v| "#{k.to_s} => #{v}"}.join(", ")}) from # {@compare_date}." end end def be_close_to(target_date, tolerance) return BeCloseTo.new(target_date, tolerance) end end context "The DateRange helper" do include DateExpectations specify "should be able to approximate within two days" do 1.day.ago.should be_close_to("1/9/2007", :days => 2) end end On Jan 10, 2007, at 11:22 AM, David Chelimsky wrote: > On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: >> I upgraded to trunk and changed the code as follows: >> >> module DateExpectations >> HOUR_TOLERANCE = 60 * 60 >> DAY_TOLERANCE = HOUR_TOLERANCE * 24 >> WEEK_TOLERANCE = DAY_TOLERANCE * 7 >> >> class BeCloseTo >> def initialize(target_date, tolerance) >> @target_date = Time.parse(target_date) >> @tolerance = tolerance >> end >> >> def met_by?(target) >> compare_date = target - @target_date >> adjustment = @tolerance.inject do |item| >> case item >> when :days >> adjustment += DAY_TOLERANCE >> when :weeks >> adjustment += WEEK_TOLERANCE >> end >> end >> return true if compare_date.abs < adjustment >> end >> >> def failure_message >> return "#{@target_date} does not fall within tolerance." # s/ >> b better >> end >> end >> >> def should_be_close_to(target_date, tolerance) >> return BeCloseTo.new(target_date, tolerance) >> end >> end >> >> context "My package" do >> include DateExpectations >> specify "should be delivered no later than 2 days after my >> order" do >> 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- >> line 40 >> end >> end >> >> The result is: >> >> 1) >> NoMethodError in 'My package should be delivered no later than 2 days >> after my order' >> undefined method `close_to?' for Tue Jan 09 10:59:31 -0800 2007:Time >> ./spec/helpers/date_range_spec.rb:40: >> >> >> Any thoughts as to why? (Note: You had written the expectation in >> your sample as: >> "should<space>be_close_to" -- was that intentional?). > > Yes!!!! That's the whole point. ;) > > should be_close_to > > and your method should be named be_close_to > > Let me know how it works out. > > Thanks for giving this a shot - you're the guinea pig! > > David > >> >> Steve >> >> >> On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: >> >>> module DateExpectations >>> class BeCloseTo >>> def initialize(target_date, tolerance) >>> @target_date = target_date >>> @tolerance = tolerance >>> end >>> >>> def met_by?(target) >>> #return true if target is a date >>> #that meets the expectation >>> end >>> >>> def failure_message >>> #return an appropriate failure message >>> end >>> end >>> >>> def should_be_close_to(target_date, tolerance) >>> return BeCloseTo.new(target_date, tolerance) >>> end >>> end >>> >>> context "My package" do >>> include DateExpectations >>> specify "should be delivered no later than 2 days after my >>> order" do >>> delivery_date.should be_close_to("1/9/2007", :days => 2) >>> end >>> end >> >> _______________________________________________ >> 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 aslak.hellesoy at gmail.com Thu Jan 11 02:55:09 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 11 Jan 2007 08:55:09 +0100 Subject: [rspec-users] spec not running in TextMate In-Reply-To: <647AD79E-646B-4075-8259-DE2A6FC54C6E@yamabe.net> References: <FBE2CCBA-875D-4AC5-9A6E-234F2BB3E0E8@yamabe.net> <c0b8beca0701092247k641dcbb4j6583c7547e4855bb@mail.gmail.com> <8d961d900701100149k1bcd48d1q7de9791cd0bb9c72@mail.gmail.com> <DA7394F9-999B-489E-8732-545E21BDD093@yamabe.net> <8d961d900701100700j30c674e7pf216ad9e42039eb@mail.gmail.com> <647AD79E-646B-4075-8259-DE2A6FC54C6E@yamabe.net> Message-ID: <8d961d900701102355w5f75bee9t102e89677ad54056@mail.gmail.com> Please submit a bug report at Rubyforge for this. I'm currently without Internet at home so it will take a while before I get to it. On 1/10/07, Brian Yamabe <brian at yamabe.net> wrote: > Tried it and it worked without a problem, so it looks like a bundle > problem. > I don't know much about bundles, but I'd be happy to work with someone > who has suggestions for how to fix this. > > Thank, Aslak. You and David do a great job on this list. > > ---Brian > > On Jan 10, 2007, at 7:00 AM, aslak hellesoy wrote: > > > Let's narrow it down a little to see if this is a problem with the > > bundle or your environment. > > > > Try this: > > > > 1) Create a file called foo.rb > > 2) Add one line to it: require 'rubygems' > > 3) Open it in TextMate > > 4) Run it from TextMate (Cmd-R - Run) > > > > Do you get the same error? If so, your environment is bad. > > > > Aslak > > > > On 1/10/07, Brian Yamabe <brian at yamabe.net> wrote: > >> I do have TM_RUBY set to the same Ruby interpreter as the one I use > >> from the terminal. > >> > >> ---Brian > >> > >> On Jan 10, 2007, at 1:49 AM, aslak hellesoy wrote: > >> > >>> Sounds like TM is running a Ruby interpreter that doesn't have > >>> Rubygems installed. > >>> > >>> Tell TM to run a different Ruby - it's documented somewhere, but I > >>> don't remember where. > >>> > >>> Aslak > >>> > >>> On 1/10/07, Bryan Helmkamp <bhelmkamp at gmail.com> wrote: > >>>> I don't have any help to offer, but I can confirm that I'm > >>>> experiencing this issue right now, as well as some other people I > >>>> have > >>>> spoken with. > >>>> > >>>> -Bryan > >>>> > >>>> On 1/9/07, Brian Yamabe <brian at yamabe.net> wrote: > >>>>> I tried running a spec with command-r in TextMate and got: > >>>>> > >>>>> /Library/Application Support/TextMate/Bundles/RSpec.tmbundle/ > >>>>> Support/ > >>>>> lib/spec_mate.rb:1:in `require': No such file to load -- rubygems > >>>>> (LoadError) from /Library/Application Support/TextMate/Bundles/ > >>>>> RSpec.tmbundle/Support/lib/spec_mate.rb:1 from /tmp/ > >>>>> temp_textmate.GplhPr:3:in `require' from /tmp/ > >>>>> temp_textmate.GplhPr:3 > >>>>> > >>>>> The spec runs fine from the command line. > >>>>> > >>>>> Any ideas? > >>>>> > >>>>> Thanks, > >>>>> Brian > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-users at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>> > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jan 11 10:44:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Jan 2007 09:44:50 -0600 Subject: [rspec-users] Date Approximation in Specs In-Reply-To: <BFEBA93D-76A8-4D9D-BA4B-1BD3FA385984@gmail.com> References: <9B13D352-1F62-4433-83BC-68A1682EB05A@gmail.com> <57c63afe0701091645i41c3f2dehaa3bacd4ebbb3b13@mail.gmail.com> <57c63afe0701092026y45b5f66fjeadb5b109b85448a@mail.gmail.com> <EBC7915C-3B7F-498F-BA8C-DFC333DB1F2C@gmail.com> <57c63afe0701101122t281a11ebr4b542a885081accf@mail.gmail.com> <BFEBA93D-76A8-4D9D-BA4B-1BD3FA385984@gmail.com> Message-ID: <57c63afe0701110744o79892a9ck787ba999689b328d@mail.gmail.com> On 1/11/07, s.ross <cwdinfo at gmail.com> wrote: > My net connection's gone spotty over the last couple of days, but I > wanted to follow up and tell you that your new code works great. > Here's just a proof of concept implementation (complete with hard > coding!): > > module DateExpectations > HOUR_TOLERANCE = 60 * 60 > DAY_TOLERANCE = HOUR_TOLERANCE * 24 > WEEK_TOLERANCE = DAY_TOLERANCE * 7 > > class BeCloseTo > def initialize(target_date, tolerance) > @target_date = Time.parse(target_date) > @tolerance = tolerance > end > > def met_by?(target) > @compare_date = target > compare_span = target - @target_date > adjustment = 0 > @tolerance.each do |key, amount| > case key > when :hours > adjustment += HOUR_TOLERANCE * amount > when :days > adjustment += DAY_TOLERANCE * amount > when :weeks > adjustment += WEEK_TOLERANCE * amount > end > end > return true if compare_span.abs < adjustment > end > > def failure_message > return "#{@target_date} does not fall within tolerance (# > {@tolerance.collect{|k,v| "#{k.to_s} => #{v}"}.join(", ")}) from # > {@compare_date}." > end > end > > def be_close_to(target_date, tolerance) > return BeCloseTo.new(target_date, tolerance) > end > end > > context "The DateRange helper" do > include DateExpectations > specify "should be able to approximate within two days" do > 1.day.ago.should be_close_to("1/9/2007", :days => 2) > end > end Great to hear it's working for you. I just committed support for negative expectations as well. You just need to supply a negative_failure_message in addition to failure_message. Then you can say (given your extension): 3.days.ago.should_not be_close_to("1/10/2007", :days => 2) I am totally psyched about this. In addition to opening the door to custom expectations it seems to be leading towards a leaner implementation in rspec. Cheers, David > > > On Jan 10, 2007, at 11:22 AM, David Chelimsky wrote: > > > On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: > >> I upgraded to trunk and changed the code as follows: > >> > >> module DateExpectations > >> HOUR_TOLERANCE = 60 * 60 > >> DAY_TOLERANCE = HOUR_TOLERANCE * 24 > >> WEEK_TOLERANCE = DAY_TOLERANCE * 7 > >> > >> class BeCloseTo > >> def initialize(target_date, tolerance) > >> @target_date = Time.parse(target_date) > >> @tolerance = tolerance > >> end > >> > >> def met_by?(target) > >> compare_date = target - @target_date > >> adjustment = @tolerance.inject do |item| > >> case item > >> when :days > >> adjustment += DAY_TOLERANCE > >> when :weeks > >> adjustment += WEEK_TOLERANCE > >> end > >> end > >> return true if compare_date.abs < adjustment > >> end > >> > >> def failure_message > >> return "#{@target_date} does not fall within tolerance." # s/ > >> b better > >> end > >> end > >> > >> def should_be_close_to(target_date, tolerance) > >> return BeCloseTo.new(target_date, tolerance) > >> end > >> end > >> > >> context "My package" do > >> include DateExpectations > >> specify "should be delivered no later than 2 days after my > >> order" do > >> 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- > >> line 40 > >> end > >> end > >> > >> The result is: > >> > >> 1) > >> NoMethodError in 'My package should be delivered no later than 2 days > >> after my order' > >> undefined method `close_to?' for Tue Jan 09 10:59:31 -0800 2007:Time > >> ./spec/helpers/date_range_spec.rb:40: > >> > >> > >> Any thoughts as to why? (Note: You had written the expectation in > >> your sample as: > >> "should<space>be_close_to" -- was that intentional?). > > > > Yes!!!! That's the whole point. ;) > > > > should be_close_to > > > > and your method should be named be_close_to > > > > Let me know how it works out. > > > > Thanks for giving this a shot - you're the guinea pig! > > > > David > > > >> > >> Steve > >> > >> > >> On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > >> > >>> module DateExpectations > >>> class BeCloseTo > >>> def initialize(target_date, tolerance) > >>> @target_date = target_date > >>> @tolerance = tolerance > >>> end > >>> > >>> def met_by?(target) > >>> #return true if target is a date > >>> #that meets the expectation > >>> end > >>> > >>> def failure_message > >>> #return an appropriate failure message > >>> end > >>> end > >>> > >>> def should_be_close_to(target_date, tolerance) > >>> return BeCloseTo.new(target_date, tolerance) > >>> end > >>> end > >>> > >>> context "My package" do > >>> include DateExpectations > >>> specify "should be delivered no later than 2 days after my > >>> order" do > >>> delivery_date.should be_close_to("1/9/2007", :days => 2) > >>> end > >>> end > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ed.howland at gmail.com Thu Jan 11 19:32:34 2007 From: ed.howland at gmail.com (Ed Howland) Date: Thu, 11 Jan 2007 18:32:34 -0600 Subject: [rspec-users] After upgrade to 0.7.5, specs are now using the development, not the test DB Message-ID: <3df642dd0701111632p1ef98f0exaf9d4e94192722f0@mail.gmail.com> Hi, After I upgraded RSpec from 0.7.4 to 0.7.5, first the gem, then the Rails plugin, I noticed that when I ran my spec/models, the fixtures were overwriting the data in the development environment DB, not the test one. The test environment was being used prior to the upgrade. I am using SQLite3 and an in-memory db for the test environment. Any help would be appreciated. Thanks Ed -- Ed Howland http://greenprogrammer.blogspot.com From listaccount at e-tobi.net Thu Jan 11 19:46:15 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Fri, 12 Jan 2007 01:46:15 +0100 Subject: [rspec-users] First steps with RSpec on Rails Message-ID: <45A6DA57.9060704@e-tobi.net> Hi! If anyone is interested, these are my first tiny steps with RSpec on Rails: https://www.heise.de:444/svn/ctvdr/ctvdrwebadmin/trunk/ The "ctvdrwebadmin" application should become a web administration tool for a Debian based distribution that is specialized to VDR [1] - the Linux video disc recoder by Klaus Schmidinger. It shall provide an interface for the installation / uninstallation of software packages, configuration handling and several status information. It doesn't use a database - instead it reads data from the file system or grabs it from the OS and other external tools. For now this is still in the "proof of concept" phase, giving me the opportunity to play around with Rails and RSpec. "ctvdrwebadmin" is tightly coupled to Debian and has a German-only UI, so most of you probably won't be able to run it. But the interesting part is the source code, especially the specifications - all English of course. Any suggestions for improvements are welcome! I still have a problem with finding the "right" phrases for specifications, so especially on this topic any feedback is welcome. The most interesting part of the application in it's current state probably is the channel editor. One of the use cases of the channel editor is, that it should be possible to rearrange the order of channels. With plain old http get/post this quickly becomes a usability nightmare, so I decided to throw in some Ajax/JavaScript to implement a nice drag 'n drop UI for rearranging the list of channels. With sortable_element() and Rails this was much easier than I initially thought. It just became a little bit more tricky, when I realized, that with 1000 channels the Javascripts became damn slow. And several hundred channels (TV and radio) are not unusual when you use DVB-S. So I needed to paginate the list of channels. This required a little bit more Ajax. And because I now needed a way to move a channel from the last page to the first, I decided to introduce a clipboard where the user can temporarily store channels when switching between pages. So finally I had this: Two lists where the user can drag 'n drop channels within and between the lists. The clipboard list is static, the channel list is paginated. Each time the user moves a channel, an Ajax request triggers the rearrangement in the underlying controller. And these are the specifications for this controller: https://www.heise.de:444/svn/ctvdr/ctvdrwebadmin/branches/snapshot_for_rspec_ml/spec/controllers/channel_list_spec.rb Some of the things that still puzzle me there: spec "should result in an empty clipboard when pulling the last channel to the order list" - when a channel is moved from the clipboard to the list, two Ajax requests are triggered. One that passes the new list of items in the clipboard and one with the items in the channel list. For this specification I'm only interested in the request from the clipboard. The question is, if I then can skip the request from the channel list? In a real use of the application both events always occur together, when dragging between the two lists. Or should I just rename the specification to "should result in an empty clipboard when removing the last channel from it" and skip the request from the channel list? (But what if I had a bug in the code that handles the requests from the channel list?) What about the contexts? Should I split them into more contexts? Or should I merge some? The first two contexts only have one specification. They could easily be merged, but the setup of the second context is a little bit more complex which is not needed to perform the specification in the first context. So far I think that doing it the RSpec-way gave me a little bit more freedom to evolve the implementation and the overall design than doing it with "plain old" unit tests. But on the other hand I have the feeling, that the specifications don't test the code as deeply as unit test would have done. But that's only a vague feeling at the moment. bye, Tobias PS: David - I followed your suggestion and moved the "logged-in"-code to a set_logged_in method, which I simply put into spec_helper.rb, so I don't need to explicitly include a helper module. Thanks! [1]: http://www.cadsoft.de/vdr/ From dchelimsky at gmail.com Thu Jan 11 22:57:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Jan 2007 21:57:53 -0600 Subject: [rspec-users] After upgrade to 0.7.5, specs are now using the development, not the test DB In-Reply-To: <3df642dd0701111632p1ef98f0exaf9d4e94192722f0@mail.gmail.com> References: <3df642dd0701111632p1ef98f0exaf9d4e94192722f0@mail.gmail.com> Message-ID: <57c63afe0701111957w7e53e8e5w441e0d45ec529799@mail.gmail.com> Add this to the top of spec_helper.rb: ENV["RAILS_ENV"] = "test" This will not be a problem in the next release. David On 1/11/07, Ed Howland <ed.howland at gmail.com> wrote: > Hi, > > After I upgraded RSpec from 0.7.4 to 0.7.5, first the gem, then the > Rails plugin, I noticed that when I ran my spec/models, the fixtures > were overwriting the data in the development environment DB, not the > test one. The test environment was being used prior to the upgrade. > > I am using SQLite3 and an in-memory db for the test environment. > > Any help would be appreciated. > > Thanks > Ed > -- > Ed Howland > http://greenprogrammer.blogspot.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ed.howland at gmail.com Fri Jan 12 09:23:03 2007 From: ed.howland at gmail.com (Ed Howland) Date: Fri, 12 Jan 2007 08:23:03 -0600 Subject: [rspec-users] After upgrade to 0.7.5, specs are now using the development, not the test DB In-Reply-To: <57c63afe0701111957w7e53e8e5w441e0d45ec529799@mail.gmail.com> References: <3df642dd0701111632p1ef98f0exaf9d4e94192722f0@mail.gmail.com> <57c63afe0701111957w7e53e8e5w441e0d45ec529799@mail.gmail.com> Message-ID: <3df642dd0701120623s246def36n24c49a0a61f543fa@mail.gmail.com> On 1/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: > Add this to the top of spec_helper.rb: > > ENV["RAILS_ENV"] = "test" > > This will not be a problem in the next release. > > David Thanks, that did the trick. Ed From brian at yamabe.net Fri Jan 12 11:20:23 2007 From: brian at yamabe.net (Brian Yamabe) Date: Fri, 12 Jan 2007 08:20:23 -0800 Subject: [rspec-users] Integration Testing - Wait, Watir, or Selenium Message-ID: <E9396A4C-B66E-45A4-816A-09098C04327B@yamabe.net> I'm evaluating what to use for integration testing: SafariWatir - integrates nicely with RSpec - doesn't work with Ajax because of Safari event firing issues Selenium - Works with Ajax - doesn't integrate with RSpec What is the best guess timeframe for RSpec integration testing? Will it be able to test Ajax application in the early iterations? Thanks, Brian Yamabe From shane.duan at gmail.com Fri Jan 12 11:34:26 2007 From: shane.duan at gmail.com (Shane Duan) Date: Fri, 12 Jan 2007 08:34:26 -0800 Subject: [rspec-users] Integration Testing - Wait, Watir, or Selenium In-Reply-To: <E9396A4C-B66E-45A4-816A-09098C04327B@yamabe.net> References: <E9396A4C-B66E-45A4-816A-09098C04327B@yamabe.net> Message-ID: <bd7896da0701120834u7e61066cp460d2c5992e70265@mail.gmail.com> Hi, What did you mean by Selenium integration with rspec? You can install the selenium gem. Then you can control the start/stop of selenium server and use the driver to drive the browser, http://selenium.rubyforge.org Cheers Shane On 1/12/07, Brian Yamabe <brian at yamabe.net> wrote: > I'm evaluating what to use for integration testing: > > SafariWatir > - integrates nicely with RSpec > - doesn't work with Ajax because of Safari event firing issues > > Selenium > - Works with Ajax > - doesn't integrate with RSpec > > What is the best guess timeframe for RSpec integration testing? > Will it be able to test Ajax application in the early iterations? > > Thanks, > Brian Yamabe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Shane http://www.shaneduan.com From aslak.hellesoy at gmail.com Fri Jan 12 11:38:10 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 12 Jan 2007 17:38:10 +0100 Subject: [rspec-users] Integration Testing - Wait, Watir, or Selenium In-Reply-To: <E9396A4C-B66E-45A4-816A-09098C04327B@yamabe.net> References: <E9396A4C-B66E-45A4-816A-09098C04327B@yamabe.net> Message-ID: <8d961d900701120838s49b6bc18vec3a4bd095c48208@mail.gmail.com> Rspec and selemnium (via selenium-rc) do indeed play nicely together. See the spec-ui directory in svn trunk. On 1/12/07, Brian Yamabe <brian at yamabe.net> wrote: > I'm evaluating what to use for integration testing: > > SafariWatir > - integrates nicely with RSpec > - doesn't work with Ajax because of Safari event firing issues > > Selenium > - Works with Ajax > - doesn't integrate with RSpec > > What is the best guess timeframe for RSpec integration testing? > Will it be able to test Ajax application in the early iterations? > > Thanks, > Brian Yamabe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brian at yamabe.net Fri Jan 12 12:05:42 2007 From: brian at yamabe.net (Brian Yamabe) Date: Fri, 12 Jan 2007 09:05:42 -0800 Subject: [rspec-users] Integration Testing - Wait, Watir, or Selenium In-Reply-To: <bd7896da0701120834u7e61066cp460d2c5992e70265@mail.gmail.com> References: <E9396A4C-B66E-45A4-816A-09098C04327B@yamabe.net> <bd7896da0701120834u7e61066cp460d2c5992e70265@mail.gmail.com> Message-ID: <01C57737-1697-4297-9D52-1C43548C7308@yamabe.net> Thanks for both the replies. I saw Selenium on Rails, but missed the Selenium gem. ---Brian On Jan 12, 2007, at 8:34 AM, Shane Duan wrote: > Hi, > > What did you mean by Selenium integration with rspec? > > You can install the selenium gem. Then you can control the start/stop > of selenium server and use the driver to drive the browser, > > http://selenium.rubyforge.org > > Cheers > Shane > > On 1/12/07, Brian Yamabe <brian at yamabe.net> wrote: >> I'm evaluating what to use for integration testing: >> >> SafariWatir >> - integrates nicely with RSpec >> - doesn't work with Ajax because of Safari event firing issues >> >> Selenium >> - Works with Ajax >> - doesn't integrate with RSpec >> >> What is the best guess timeframe for RSpec integration testing? >> Will it be able to test Ajax application in the early iterations? >> >> Thanks, >> Brian Yamabe >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > Shane > http://www.shaneduan.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From shane.duan at gmail.com Fri Jan 12 14:16:16 2007 From: shane.duan at gmail.com (Shane Duan) Date: Fri, 12 Jan 2007 11:16:16 -0800 Subject: [rspec-users] Integration Testing - Wait, Watir, or Selenium In-Reply-To: <01C57737-1697-4297-9D52-1C43548C7308@yamabe.net> References: <E9396A4C-B66E-45A4-816A-09098C04327B@yamabe.net> <bd7896da0701120834u7e61066cp460d2c5992e70265@mail.gmail.com> <01C57737-1697-4297-9D52-1C43548C7308@yamabe.net> Message-ID: <bd7896da0701121116l510af351vf9470269714a65f1@mail.gmail.com> Selenium on rails uses the original selenium HTML driver and provides API for generating the HTML Selenium Ruby bundles the selenium server and the Selenium ruby RC as well as providing additional API for domain based web testing (http://selenium.rubyforge.org/doc/domain-based-web-testing.html) I have contacted them to see if two projects can work together in some way. Cheers Shane On 1/12/07, Brian Yamabe <brian at yamabe.net> wrote: > Thanks for both the replies. I saw Selenium on Rails, but missed the > Selenium gem. > > ---Brian > > On Jan 12, 2007, at 8:34 AM, Shane Duan wrote: > > > Hi, > > > > What did you mean by Selenium integration with rspec? > > > > You can install the selenium gem. Then you can control the start/stop > > of selenium server and use the driver to drive the browser, > > > > http://selenium.rubyforge.org > > > > Cheers > > Shane > > > > On 1/12/07, Brian Yamabe <brian at yamabe.net> wrote: > >> I'm evaluating what to use for integration testing: > >> > >> SafariWatir > >> - integrates nicely with RSpec > >> - doesn't work with Ajax because of Safari event firing issues > >> > >> Selenium > >> - Works with Ajax > >> - doesn't integrate with RSpec > >> > >> What is the best guess timeframe for RSpec integration testing? > >> Will it be able to test Ajax application in the early iterations? > >> > >> Thanks, > >> Brian Yamabe > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > > > -- > > Shane > > http://www.shaneduan.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 > -- Shane http://www.shaneduan.com From work at ashleymoran.me.uk Fri Jan 12 14:36:34 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 12 Jan 2007 19:36:34 +0000 Subject: [rspec-users] Integration Testing - Wait, Watir, or Selenium In-Reply-To: <bd7896da0701121116l510af351vf9470269714a65f1@mail.gmail.com> References: <E9396A4C-B66E-45A4-816A-09098C04327B@yamabe.net> <bd7896da0701120834u7e61066cp460d2c5992e70265@mail.gmail.com> <01C57737-1697-4297-9D52-1C43548C7308@yamabe.net> <bd7896da0701121116l510af351vf9470269714a65f1@mail.gmail.com> Message-ID: <AA7CCEBA-FA69-452E-BDB4-F3059C3E09F1@ashleymoran.me.uk> On Jan 12, 2007, at 7:16 pm, Shane Duan wrote: >>>> SafariWatir >>>> - integrates nicely with RSpec >>>> - doesn't work with Ajax because of Safari event firing issues I e-mailed the author about this and he fixed it over Christmas. Try version 0.2.1, it works for me. Ashley From brian at yamabe.net Fri Jan 12 18:00:14 2007 From: brian at yamabe.net (Brian Yamabe) Date: Fri, 12 Jan 2007 15:00:14 -0800 Subject: [rspec-users] spec_ui problems Message-ID: <ADAB7E40-D308-4AF5-B220-11FDDD052D93@yamabe.net> While looking into spec_ui, I decided to run the examples. The watir example works a little, but always chokes on the 'better than fudge' spec (failure output below). Also, is there any command to pause the "browser"? If my connection slows, the test gets out of whack. The selenium example fails right away (output below). I do have the 0.9.0 selenium-rc server running. I executed rake from inside each of the specific example directories. Thanks for any help. ---Brian Yamabe watir failure ---------- /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/expectations/ sugar.rb:13:in `call': undefined local variable or method `current_spec_number' for #<Spec::Ui::WebappFormatter:0x10083d0> (NameError) from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ expectations/sugar.rb:13:in `_method_missing' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ expectations/sugar.rb:9:in `method_missing' from /Users/byamabe/Desktop/spec_ui/lib/spec/ui/formatter.rb: 5:in `extra_failure_content' from /Users/byamabe/Desktop/spec_ui/lib/spec/ui/formatter.rb: 11:in `extra_failure_content' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/formatter/html_formatter.rb:57:in `spec_failed' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/reporter.rb:78:in `spec_failed' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/reporter.rb:27:in `spec_finished' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/specification.rb:37:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/context.rb:57:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/context.rb:54:in `each' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/context.rb:54:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/context_runner.rb:23:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/context_runner.rb:22:in `each' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/context_runner.rb:22:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/command_line.rb:26:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/bin/spec:4 rake aborted! selenium failure ---------- /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- ./spec/selenium (LoadError) from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `require' from ./spec/spec_helper.rb:7 from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/option_parser.rb:107:in `require' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/option_parser.rb:107:in `parse' from /opt/local/lib/ruby/1.8/optparse.rb:1218:in `call' from /opt/local/lib/ruby/1.8/optparse.rb:1218:in `order!' from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `catch' from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `order!' from /opt/local/lib/ruby/1.8/optparse.rb:1279:in `permute!' from /opt/local/lib/ruby/1.8/optparse.rb:1300:in `parse!' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/option_parser.rb:141:in `parse' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/option_parser.rb:13:in `create_context_runner' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ runner/command_line.rb:12:in `run' from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/bin/spec:4 From cwdinfo at gmail.com Sat Jan 13 14:18:38 2007 From: cwdinfo at gmail.com (s.ross) Date: Sat, 13 Jan 2007 11:18:38 -0800 Subject: [rspec-users] svn reorganized? Message-ID: <A7D88DAB-7C1E-45BF-B247-4AC03A17CF54@gmail.com> It appears the repository has been rearranged when compared to the documentation. For the Rails plugin, the correct script/plugin install now seems to be: script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/ rspec_on_rails Is this correct? From dchelimsky at gmail.com Sat Jan 13 14:51:54 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 13 Jan 2007 13:51:54 -0600 Subject: [rspec-users] svn reorganized? In-Reply-To: <A7D88DAB-7C1E-45BF-B247-4AC03A17CF54@gmail.com> References: <A7D88DAB-7C1E-45BF-B247-4AC03A17CF54@gmail.com> Message-ID: <57c63afe0701131151h66016f6cpd14024e1fb1a16b3@mail.gmail.com> Where are you seeing the wrong doc? I'm looking at this: http://rspec.rubyforge.org/documentation/rails/install.html and I see the correct path for tagged versions (0.7.5 and later) svn://rubyforge.org/var/svn/rspec/tags/REL_X_Y_Z/rspec_on_rails/vendor/plugins/rspec_on_rails and the current trunk: svn://rubyforge.org/var/svn/rspec/trunk/rspec_on_rails/vendor/plugins/rspec_on_rails Is there another page that you are seeing the wrong information? Thanks David On 1/13/07, s.ross <cwdinfo at gmail.com> wrote: > It appears the repository has been rearranged when compared to the > documentation. For the Rails plugin, the correct script/plugin > install now seems to be: > > script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/ > rspec_on_rails > > Is this correct? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Sat Jan 13 16:03:42 2007 From: cwdinfo at gmail.com (s.ross) Date: Sat, 13 Jan 2007 13:03:42 -0800 Subject: [rspec-users] svn reorganized? In-Reply-To: <57c63afe0701131151h66016f6cpd14024e1fb1a16b3@mail.gmail.com> References: <A7D88DAB-7C1E-45BF-B247-4AC03A17CF54@gmail.com> <57c63afe0701131151h66016f6cpd14024e1fb1a16b3@mail.gmail.com> Message-ID: <FFE75306-53A1-49BB-94D7-2CE9DEF50EB1@gmail.com> When installing from trunk, the location (apparently) is: svn://rubyforge.org/var/svn/rspec/trunk/rspec_on_rails This page (http://rspec.rubyforge.org/tools/rails.html) mentions trunk as being: script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/vendor/ rspec_on_rails/vendor/plugins/rspec It is tagged as being for rSpec 0.6.3 This page (http://rspec.rubyforge.org/documentation/rails/index.html) mentions trunk as being: script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/ rspec_on_rails/vendor/plugins/rspec_on_rails The point is that the former is wrong with respect to trunk and (IMO) should be revised to point to the 0.7.5 and later trunk installation. Steve On Jan 13, 2007, at 11:51 AM, David Chelimsky wrote: > Where are you seeing the wrong doc? I'm looking at this: > > http://rspec.rubyforge.org/documentation/rails/install.html > > and I see the correct path for tagged versions (0.7.5 and later) > > svn://rubyforge.org/var/svn/rspec/tags/REL_X_Y_Z/rspec_on_rails/ > vendor/plugins/rspec_on_rails > > and the current trunk: > > svn://rubyforge.org/var/svn/rspec/trunk/rspec_on_rails/vendor/ > plugins/rspec_on_rails > > Is there another page that you are seeing the wrong information? > > Thanks > David > > On 1/13/07, s.ross <cwdinfo at gmail.com> wrote: >> It appears the repository has been rearranged when compared to the >> documentation. For the Rails plugin, the correct script/plugin >> install now seems to be: >> >> script/plugin install svn://rubyforge.org/var/svn/rspec/trunk/ >> rspec_on_rails >> >> Is this correct? >> _______________________________________________ >> 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 richard at infoarts.info Sat Jan 13 21:51:09 2007 From: richard at infoarts.info (Richard Sandilands) Date: Sun, 14 Jan 2007 13:51:09 +1100 Subject: [rspec-users] rspec and set_table_name? Message-ID: <3961F8F2-D53C-4F3F-A116-49D4CB8AAA09@infoarts.info> Hi there I have a Value class in my Rails app; however 'values' is a reserved word in MySQL so in my value.rb file, I've declared set_table_name as 'vals'. However, in setting up my specs for this model, I'm hitting errors that seem to be resulting from rspec not seeing the set_table_name declaration in my model file. For instance, rspec is throwing a MySQL error as it is attempting to delete records from a table named 'values' which of course does not exist - the table is 'vals' but the model is Value. Is this an issue with rspec? If so, is there a way around this? I want to keep using rspec and am prepared to rename my class so as to not need the set_table_name declaration but want to be clear that this is the source of the problem. Any clues would be appreciated. Richard From matt at iseekgolf.com Sun Jan 14 02:40:49 2007 From: matt at iseekgolf.com (Matt Allen) Date: Sun, 14 Jan 2007 18:40:49 +1100 Subject: [rspec-users] rspec and set_table_name? In-Reply-To: <3961F8F2-D53C-4F3F-A116-49D4CB8AAA09@infoarts.info> References: <3961F8F2-D53C-4F3F-A116-49D4CB8AAA09@infoarts.info> Message-ID: <45A9DE81.2010508@iseekgolf.com> Hi Richard; I use set_table_name too. Here is my set-up. product.rb class Product < ActiveRecord::Base set_table_name "cart_products" end product_spec.rb context "A product with fixtures loaded" do set_fixture_class :cart_products => 'Product' fixtures :cart_products end Your fixtures should be the same name as you table, so in my case cart_products. HTH, Matta Richard Sandilands did write the following on 14/01/2007 1:51 PM: > Hi there > > I have a Value class in my Rails app; however 'values' is a reserved > word in MySQL so in my value.rb file, I've declared set_table_name as > 'vals'. > > However, in setting up my specs for this model, I'm hitting errors > that seem to be resulting from rspec not seeing the set_table_name > declaration in my model file. > > For instance, rspec is throwing a MySQL error as it is attempting to > delete records from a table named 'values' which of course does not > exist - the table is 'vals' but the model is Value. > > Is this an issue with rspec? If so, is there a way around this? I > want to keep using rspec and am prepared to rename my class so as to > not need the set_table_name declaration but want to be clear that > this is the source of the problem. > > Any clues would be appreciated. > > Richard > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > . > -- Matt Allen iseekgolf.com 1300 663 813 From richard at infoarts.info Sun Jan 14 15:27:37 2007 From: richard at infoarts.info (Richard Sandilands) Date: Mon, 15 Jan 2007 07:27:37 +1100 Subject: [rspec-users] rspec and set_table_name? In-Reply-To: <45A9DE81.2010508@iseekgolf.com> References: <3961F8F2-D53C-4F3F-A116-49D4CB8AAA09@infoarts.info> <45A9DE81.2010508@iseekgolf.com> Message-ID: <0C4AD1BF-75C2-4204-B39E-30B3017C2049@infoarts.info> On 14/01/2007, at 6:40 PM, Matt Allen wrote: > set_fixture_class :cart_products => 'Product' Ah, that's the missing piece there. It's all working nicely now - thanks for your help. -- Richard From eastmedianyc at gmail.com Mon Jan 15 00:04:56 2007 From: eastmedianyc at gmail.com (Matt Pelletier) Date: Mon, 15 Jan 2007 00:04:56 -0500 Subject: [rspec-users] RSpec 0.7.5 with Rails and rcov Message-ID: <96af85420701142104u640e0ceav875ae4fabd0bd4b3@mail.gmail.com> > Le 5 janv. 07 ? 03:05, Bryan Liles a ?crit : > > > I seem to be missing something because I am at a loss on how to get > > rcov, RSpec, and Rails working together. Would someone mind dropping > > some hints? > > I don't know what you want to achieve, but if your goal is to > generate some reports here's what I added to lib/tasks/ > rspec_additions.rake : > > namespace :spec do > desc "Spec with rspec/rcov reports" > Spec::Rake::SpecTask.new('reports') do |t| > t.spec_files = FileList['spec/**/*.rb'] > t.spec_opts = ["--format", "html", "--diff"] > t.out = 'doc/rspec.html' > t.rcov = true > t.rcov_dir = 'doc/coverage' > > # Optional : > # Prevent rcov to generate report on specs, environment.rb and boot.rb > # t.rcov_opts = ['--exclude', 'spec,config\/environment.rb,config\/ > boot.rb'] > > t.fail_on_error = false > t.failure_message = "The specs failed. Check for the problem at > http://projects.tron.name/flash007/rspec.html" > end > end > > Run it with rake : spec:reports > It will generate rspec.html report in doc/rspec.html and rcov report > in doc/coverage/. This results in a bus error in OSX 10.4.8 (I had a similar task that did the same thing): <snip path>/config/../vendor/rails/activerecord/lib/active_record/associations/has_many_association.rb:13: [BUG] Bus Error ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1] I'm running Rails 1.2 in vendor/rails Anyone else getting this? Any idea why? Thanks. Matt > > Jonathan > -- > Tron Jonathan > http://jonathan.tron.name > From jchris at mfdz.com Mon Jan 15 04:29:50 2007 From: jchris at mfdz.com (Chris Anderson) Date: Mon, 15 Jan 2007 01:29:50 -0800 Subject: [rspec-users] heckle and rspec on rails Message-ID: <e282921e0701150129m924b4e3rbcc30589bf7bfd4c@mail.gmail.com> Now that I'm developing a big suite of specs, I really want to run Heckle and see how well I've done. Using r1359, when I run: spec spec/models/metadata_report_spec.rb --heckle MetadataReport the result is just to run the specs once and then exit, as though I hadn't mentioned Heckle. I started looking though rspec to figure out why, but it's late, so I should sleep instead. I guess the question is, has anyone had luck using Heckle with Rails? I've got it working for regular ruby specs, and it's a lot of fun (although I do hit infinite loops sometimes). Thanks! -- Chris Anderson http://jchris.mfdz.com From cwdinfo at gmail.com Mon Jan 15 18:55:28 2007 From: cwdinfo at gmail.com (s.ross) Date: Mon, 15 Jan 2007 15:55:28 -0800 Subject: [rspec-users] RSpec 0.7.5 with Rails and rcov In-Reply-To: <96af85420701142104u640e0ceav875ae4fabd0bd4b3@mail.gmail.com> References: <96af85420701142104u640e0ceav875ae4fabd0bd4b3@mail.gmail.com> Message-ID: <3FCA8364-BDAA-4C26-9EF4-F38F7A5A004E@gmail.com> I'm running the same system configuration as you, except my Rails install is 5623. The bus error does not occur on my system when running this task. Note: I'm running trunk rSpec. What version of rSpec did you say you were running? --steve On Jan 14, 2007, at 9:04 PM, Matt Pelletier wrote: >> Le 5 janv. 07 ? 03:05, Bryan Liles a ?crit : >> >>> I seem to be missing something because I am at a loss on how to get >>> rcov, RSpec, and Rails working together. Would someone mind >>> dropping >>> some hints? >> >> I don't know what you want to achieve, but if your goal is to >> generate some reports here's what I added to lib/tasks/ >> rspec_additions.rake : >> >> namespace :spec do >> desc "Spec with rspec/rcov reports" >> Spec::Rake::SpecTask.new('reports') do |t| >> t.spec_files = FileList['spec/**/*.rb'] >> t.spec_opts = ["--format", "html", "--diff"] >> t.out = 'doc/rspec.html' >> t.rcov = true >> t.rcov_dir = 'doc/coverage' >> >> # Optional : >> # Prevent rcov to generate report on specs, environment.rb and >> boot.rb >> # t.rcov_opts = ['--exclude', 'spec,config\/ >> environment.rb,config\/ >> boot.rb'] >> >> t.fail_on_error = false >> t.failure_message = "The specs failed. Check for the problem at >> http://projects.tron.name/flash007/rspec.html" >> end >> end >> >> Run it with rake : spec:reports >> It will generate rspec.html report in doc/rspec.html and rcov report >> in doc/coverage/. > > This results in a bus error in OSX 10.4.8 (I had a similar task that > did the same thing): > > <snip path>/config/../vendor/rails/activerecord/lib/active_record/ > associations/has_many_association.rb:13: > [BUG] Bus Error > ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1] > > I'm running Rails 1.2 in vendor/rails > > Anyone else getting this? Any idea why? Thanks. > > Matt > >> >> Jonathan >> -- >> Tron Jonathan >> http://jonathan.tron.name >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jonathan.tron.mailings at gmail.com Tue Jan 16 03:35:42 2007 From: jonathan.tron.mailings at gmail.com (Jonathan Tron) Date: Tue, 16 Jan 2007 09:35:42 +0100 Subject: [rspec-users] RSpec 0.7.5 with Rails and rcov In-Reply-To: <3FCA8364-BDAA-4C26-9EF4-F38F7A5A004E@gmail.com> References: <96af85420701142104u640e0ceav875ae4fabd0bd4b3@mail.gmail.com> <3FCA8364-BDAA-4C26-9EF4-F38F7A5A004E@gmail.com> Message-ID: <C0F836EB-F4D3-4FFF-B7C4-D3601A3EA8A5@gmail.com> Le 16 janv. 07 ? 00:55, s.ross a ?crit : > I'm running the same system configuration as you, except my Rails > install is 5623. The bus error does not occur on my system when > running this task. Note: I'm running trunk rSpec. What version of > rSpec did you say you were running? As I said on a different thread, I had the problem of "Bus Error" too, but only when I'm using mock_model from (http://metaclass.org/ 2006/12/22/making-a-mockery-of-activerecord). I run specs on two different config and only the local one segfault. My local config is : MacOS X.4.8 / Ruby 1.8.5 (from MacPorts) / Rails edge 1.2-branch / RSpec 0.7.5 (gem) / RspecOnRails 0.7.5 (from trunk at 1331) / rcov 0.7.0.1 (gem) My remote config is : Debian Testing / Ruby 1.8.5-4 / Rails edge 1.2- branch / RSpec 0.7.5 (gem) / RspecOnRails 0.7.5 (from trunk at 1331) / rcov 0.7.0.1 (gem) Jonathan -- Tron Jonathan http://jonathan.tron.name From aslak.hellesoy at gmail.com Tue Jan 16 04:41:23 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 16 Jan 2007 10:41:23 +0100 Subject: [rspec-users] RSpec 0.7.5 with Rails and rcov In-Reply-To: <C0F836EB-F4D3-4FFF-B7C4-D3601A3EA8A5@gmail.com> References: <96af85420701142104u640e0ceav875ae4fabd0bd4b3@mail.gmail.com> <3FCA8364-BDAA-4C26-9EF4-F38F7A5A004E@gmail.com> <C0F836EB-F4D3-4FFF-B7C4-D3601A3EA8A5@gmail.com> Message-ID: <8d961d900701160141v6747f6bfq9ddba4acaad4fd04@mail.gmail.com> Is anyone telling Mauricio about this? We're not going to fix it - bus error is a ruby/rcov problem Aslak On 1/16/07, Jonathan Tron <jonathan.tron.mailings at gmail.com> wrote: > Le 16 janv. 07 ? 00:55, s.ross a ?crit : > > > I'm running the same system configuration as you, except my Rails > > install is 5623. The bus error does not occur on my system when > > running this task. Note: I'm running trunk rSpec. What version of > > rSpec did you say you were running? > > As I said on a different thread, I had the problem of "Bus Error" > too, but only when I'm using mock_model from (http://metaclass.org/ > 2006/12/22/making-a-mockery-of-activerecord). I run specs on two > different config and only the local one segfault. > > My local config is : MacOS X.4.8 / Ruby 1.8.5 (from MacPorts) / Rails > edge 1.2-branch / RSpec 0.7.5 (gem) / RspecOnRails 0.7.5 (from > trunk at 1331) / rcov 0.7.0.1 (gem) > My remote config is : Debian Testing / Ruby 1.8.5-4 / Rails edge 1.2- > branch / RSpec 0.7.5 (gem) / RspecOnRails 0.7.5 (from trunk at 1331) / > rcov 0.7.0.1 (gem) > > > Jonathan > -- > Tron Jonathan > http://jonathan.tron.name > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Tue Jan 16 08:02:43 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 16 Jan 2007 13:02:43 +0000 Subject: [rspec-users] Links in view specs Message-ID: <79EAA51F-6DEF-49F5-85BF-F62DA9BD4883@ashleymoran.me.uk> Hi I have this simple view (used by the Gap controller): <h1>Gap#index</h1> <%= link_to "Get a GAP quote", :action => "get_quote" %> And this spec: context "A rendered gap/index" do setup do render 'gap/index' end specify "should have a link to the get_quote page" do response.should_have_tag 'a', :attributes => { :href => /\/gap \/get_quote/ } end end But is fails because it actually links like this: <a href="/view_spec/get_quote"> not <a href="/gap/get_quote"> What's the cleanest way to test links without integrating it into the controller? For now I'm doing... response.should_have_tag 'a', :attributes => { :href => /\/ get_quote$/ } Sorry if this is a FAQ, can't see any posts on the list about it. Ta Ashley From dchelimsky at gmail.com Tue Jan 16 08:21:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Jan 2007 07:21:51 -0600 Subject: [rspec-users] Links in view specs In-Reply-To: <79EAA51F-6DEF-49F5-85BF-F62DA9BD4883@ashleymoran.me.uk> References: <79EAA51F-6DEF-49F5-85BF-F62DA9BD4883@ashleymoran.me.uk> Message-ID: <57c63afe0701160521j4c2ac5den77870f6948050f78@mail.gmail.com> On 1/16/07, Ashley Moran <work at ashleymoran.me.uk> wrote: > Hi > > I have this simple view (used by the Gap controller): > > <h1>Gap#index</h1> > <%= link_to "Get a GAP quote", :action => "get_quote" %> > > And this spec: > > context "A rendered gap/index" do > setup do > render 'gap/index' > end > > specify "should have a link to the get_quote page" do > response.should_have_tag 'a', :attributes => { :href => /\/gap > \/get_quote/ } > end > end > > But is fails because it actually links like this: > <a href="/view_spec/get_quote"> > not > <a href="/gap/get_quote"> > > What's the cleanest way to test links without integrating it into the > controller? For now I'm doing... > response.should_have_tag 'a', :attributes => { :href => /\/ > get_quote$/ } > > Sorry if this is a FAQ, can't see any posts on the list about it. Try checking the tracker at ruby forge too. This is a known bug: http://rubyforge.org/tracker/index.php?func=detail&aid=7795&group_id=797&atid=3149 Cheers, David > > Ta > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Tue Jan 16 09:02:55 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 16 Jan 2007 14:02:55 +0000 Subject: [rspec-users] Links in view specs In-Reply-To: <57c63afe0701160521j4c2ac5den77870f6948050f78@mail.gmail.com> References: <79EAA51F-6DEF-49F5-85BF-F62DA9BD4883@ashleymoran.me.uk> <57c63afe0701160521j4c2ac5den77870f6948050f78@mail.gmail.com> Message-ID: <F0D043B6-4E63-4052-8826-22639851D72C@ashleymoran.me.uk> On 16 Jan 2007, at 13:21, David Chelimsky wrote: > Try checking the tracker at ruby forge too. This is a known bug: > > http://rubyforge.org/tracker/index.php? > func=detail&aid=7795&group_id=797&atid=3149 > > Cheers, > David Thanks David I'll just keep it half-specced for now From work at ashleymoran.me.uk Tue Jan 16 11:51:11 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 16 Jan 2007 16:51:11 +0000 Subject: [rspec-users] Specifying the contents of a date selector Message-ID: <817850A8-00B6-4EB8-8347-0B8B8EE0E771@ashleymoran.me.uk> Another n00b question (can you tell I don't normally write view code yet???)... I'm using the date_select form helper to give me three select popups, (day, month, year). I want to specify that these exist and are set to today's date I've tried this: response.should_have 'form > p > select [name="gap_quick_quote_parameters[purchase_date(3i)]"] > option', :attributes => { :value => '16', :selected => 'selected' }, :content => '16' But it fails, saying: Invalid selector: "] > option Is this a limitation of the CSS selector? I can't think of a way of phrasing the spec without trying to select children of the select elements. I want to avoid specifying that SOME select popup on the page has a value equal to today's day, month, or year. Ashley From dchelimsky at gmail.com Tue Jan 16 12:27:57 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Jan 2007 11:27:57 -0600 Subject: [rspec-users] Specifying the contents of a date selector In-Reply-To: <817850A8-00B6-4EB8-8347-0B8B8EE0E771@ashleymoran.me.uk> References: <817850A8-00B6-4EB8-8347-0B8B8EE0E771@ashleymoran.me.uk> Message-ID: <57c63afe0701160927j6a407f7eu87c89ce3eaf698d6@mail.gmail.com> On 1/16/07, Ashley Moran <work at ashleymoran.me.uk> wrote: > Another n00b question (can you tell I don't normally write view code > yet???)... > > I'm using the date_select form helper to give me three select popups, > (day, month, year). I want to specify that these exist and are set > to today's date > > I've tried this: > > response.should_have 'form > p > select > [name="gap_quick_quote_parameters[purchase_date(3i)]"] > option', > :attributes => { :value => '16', :selected > => 'selected' }, > :content => '16' > > But it fails, saying: > > Invalid selector: "] > option > > Is this a limitation of the CSS selector? I can't think of a way of > phrasing the spec without trying to select children of the select > elements. I want to avoid specifying that SOME select popup on the > page has a value equal to today's day, month, or year. The syntax you are using invokes a preliminary port of assert_select that is not officially supported yet. That said, take a look at the tests for the selector. All the examples that use double quotes have them escaped: "form>p>select[name=\"gap_quick_quote_parameters[purchase_date(3i)]\"]>option" I'm guessing you could also do this: "form>p>select[name='gap_quick_quote_parameters[purchase_date(3i)]']>option" or even this: "form>p>select[name=gap_quick_quote_parameters[purchase_date(3i)]]>option" Let us know what works, if any of those suggestions. Cheers, David > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Tue Jan 16 12:52:04 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 16 Jan 2007 17:52:04 +0000 Subject: [rspec-users] Specifying the contents of a date selector In-Reply-To: <57c63afe0701160927j6a407f7eu87c89ce3eaf698d6@mail.gmail.com> References: <817850A8-00B6-4EB8-8347-0B8B8EE0E771@ashleymoran.me.uk> <57c63afe0701160927j6a407f7eu87c89ce3eaf698d6@mail.gmail.com> Message-ID: <A48AEB18-F30D-40AF-95A8-DC1F233D0CF7@ashleymoran.me.uk> On 16 Jan 2007, at 17:27, David Chelimsky wrote: > "form>p>select[name='gap_quick_quote_parameters[purchase_date(3i)]'] > >option" Hi David Thanks for the pointer - that works fine. I found this out playing around with it: This fails (this is the original one I posted): response.should_have "'orm > p > select [name="gap_quick_quote_parameters[purchase_date(3i)]"] > option' This succeeds (obviously the penultimate ]-character is interpreted as closing the *first* [-character): response.should_have 'form > p > select [name^="gap_quick_quote_parameters[purchase_date(3i)"] > option' So apparently, using double quotes inside the CSS selector breaks bracket matching. I wouldn't like to guess why it does that. Anyway it's working now so I'm happy. Cheers Ashley PS I edited those code lines by hand in case they contains errors From aslak.hellesoy at gmail.com Wed Jan 17 05:14:24 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 17 Jan 2007 11:14:24 +0100 Subject: [rspec-users] spec_ui problems In-Reply-To: <ADAB7E40-D308-4AF5-B220-11FDDD052D93@yamabe.net> References: <ADAB7E40-D308-4AF5-B220-11FDDD052D93@yamabe.net> Message-ID: <8d961d900701170214v47e229dj438bdea6a4065c@mail.gmail.com> On 1/13/07, Brian Yamabe <brian at yamabe.net> wrote: > While looking into spec_ui, I decided to run the examples. > > The watir example works a little, but always chokes on the 'better > than fudge' spec (failure output below). Also, is there any command > to pause the "browser"? If my connection slows, the test gets out of > whack. > For now, you have to build and install the RSpec gem from svn trunk to make spec_ui work. You can sprinkle some sleeps in your code (or monkey-patch Watir) to pause things. HTH, Aslak > The selenium example fails right away (output below). I do have the > 0.9.0 selenium-rc server running. > > I executed rake from inside each of the specific example directories. > > Thanks for any help. > > ---Brian Yamabe > > watir failure > ---------- > /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/expectations/ > sugar.rb:13:in `call': undefined local variable or method > `current_spec_number' for #<Spec::Ui::WebappFormatter:0x10083d0> > (NameError) > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > expectations/sugar.rb:13:in `_method_missing' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > expectations/sugar.rb:9:in `method_missing' > from /Users/byamabe/Desktop/spec_ui/lib/spec/ui/formatter.rb: > 5:in `extra_failure_content' > from /Users/byamabe/Desktop/spec_ui/lib/spec/ui/formatter.rb: > 11:in `extra_failure_content' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/formatter/html_formatter.rb:57:in `spec_failed' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/reporter.rb:78:in `spec_failed' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/reporter.rb:27:in `spec_finished' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/specification.rb:37:in `run' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/context.rb:57:in `run' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/context.rb:54:in `each' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/context.rb:54:in `run' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/context_runner.rb:23:in `run' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/context_runner.rb:22:in `each' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/context_runner.rb:22:in `run' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/command_line.rb:26:in `run' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/bin/spec:4 > rake aborted! > > selenium failure > ---------- > /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require': no such file to load -- ./spec/selenium > (LoadError) > from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ > custom_require.rb:27:in `require' > from ./spec/spec_helper.rb:7 > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/option_parser.rb:107:in `require' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/option_parser.rb:107:in `parse' > from /opt/local/lib/ruby/1.8/optparse.rb:1218:in `call' > from /opt/local/lib/ruby/1.8/optparse.rb:1218:in `order!' > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `catch' > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `order!' > from /opt/local/lib/ruby/1.8/optparse.rb:1279:in `permute!' > from /opt/local/lib/ruby/1.8/optparse.rb:1300:in `parse!' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/option_parser.rb:141:in `parse' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/option_parser.rb:13:in `create_context_runner' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > runner/command_line.rb:12:in `run' > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/bin/spec:4 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aschur1 at telus.net Wed Jan 17 19:26:17 2007 From: aschur1 at telus.net (aschur1 at telus.net) Date: Wed, 17 Jan 2007 16:26:17 -0800 Subject: [rspec-users] spec_ui problems In-Reply-To: <8d961d900701170214v47e229dj438bdea6a4065c@mail.gmail.com> References: <ADAB7E40-D308-4AF5-B220-11FDDD052D93@yamabe.net> <8d961d900701170214v47e229dj438bdea6a4065c@mail.gmail.com> Message-ID: <1169079977.45aebea9ad702@webmail.telus.net> See patch #7685 to fix the undefined local variable message http://rubyforge.org/tracker/index.php?func=detail&aid=7685&group_id=797&atid=3151 Alvin. Quoting aslak hellesoy <aslak.hellesoy at gmail.com>: > On 1/13/07, Brian Yamabe <brian at yamabe.net> wrote: > > While looking into spec_ui, I decided to run the examples. > > > > The watir example works a little, but always chokes on the 'better > > than fudge' spec (failure output below). Also, is there any command > > to pause the "browser"? If my connection slows, the test gets out of > > whack. > > > > For now, you have to build and install the RSpec gem from svn trunk to > make spec_ui work. > You can sprinkle some sleeps in your code (or monkey-patch Watir) to > pause things. > > HTH, > Aslak > > > The selenium example fails right away (output below). I do have the > > 0.9.0 selenium-rc server running. > > > > I executed rake from inside each of the specific example directories. > > > > Thanks for any help. > > > > ---Brian Yamabe > > > > watir failure > > ---------- > > /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/expectations/ > > sugar.rb:13:in `call': undefined local variable or method > > `current_spec_number' for #<Spec::Ui::WebappFormatter:0x10083d0> > > (NameError) > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > expectations/sugar.rb:13:in `_method_missing' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > expectations/sugar.rb:9:in `method_missing' > > from /Users/byamabe/Desktop/spec_ui/lib/spec/ui/formatter.rb: > > 5:in `extra_failure_content' > > from /Users/byamabe/Desktop/spec_ui/lib/spec/ui/formatter.rb: > > 11:in `extra_failure_content' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/formatter/html_formatter.rb:57:in `spec_failed' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/reporter.rb:78:in `spec_failed' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/reporter.rb:27:in `spec_finished' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/specification.rb:37:in `run' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/context.rb:57:in `run' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/context.rb:54:in `each' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/context.rb:54:in `run' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/context_runner.rb:23:in `run' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/context_runner.rb:22:in `each' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/context_runner.rb:22:in `run' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/command_line.rb:26:in `run' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/bin/spec:4 > > rake aborted! > > > > selenium failure > > ---------- > > /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > > `gem_original_require': no such file to load -- ./spec/selenium > > (LoadError) > > from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ > > custom_require.rb:27:in `require' > > from ./spec/spec_helper.rb:7 > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/option_parser.rb:107:in `require' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/option_parser.rb:107:in `parse' > > from /opt/local/lib/ruby/1.8/optparse.rb:1218:in `call' > > from /opt/local/lib/ruby/1.8/optparse.rb:1218:in `order!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `catch' > > from /opt/local/lib/ruby/1.8/optparse.rb:1205:in `order!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1279:in `permute!' > > from /opt/local/lib/ruby/1.8/optparse.rb:1300:in `parse!' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/option_parser.rb:141:in `parse' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/option_parser.rb:13:in `create_context_runner' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/lib/spec/ > > runner/command_line.rb:12:in `run' > > from /opt/local/lib/ruby/gems/1.8/gems/rspec-0.7.5/bin/spec:4 > > _______________________________________________ > > 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 jaydonnell at yahoo.com Wed Jan 17 20:02:41 2007 From: jaydonnell at yahoo.com (Jay Donnell) Date: Wed, 17 Jan 2007 17:02:41 -0800 (PST) Subject: [rspec-users] problems testing a rails controller Message-ID: <545907.19730.qm@web56014.mail.re3.yahoo.com> I'm trying to test a rails controller, but my mock isn't working. Everything looks right to me. Can someone take a look at it and see if I'm missing something obvious http://pastie.caboo.se/33883 Domain.should_receive(:find_domain).once.and_return(domain) That line in the spec is failing but I don't see why. If I comment out that line the test passes so it is running the controller method as far as I can tell. Thanks, Jay ____________________________________________________________________________________ Looking for earth-friendly autos? Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center. http://autos.yahoo.com/green_center/ From work at ashleymoran.me.uk Thu Jan 18 08:57:29 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 18 Jan 2007 13:57:29 +0000 Subject: [rspec-users] Best way to specify an HTML element inside another Message-ID: <C2A316EA-303A-4225-8974-6A73A25407CA@ashleymoran.me.uk> Hi I know should_have is preliminary but I can't resist using it... I have a form that contains a date select (Rails-generated). I want to specify that the default value for each popup menu is correct The best I can manage is this: response.should_have "form > p > select[name='quote_parameters [purchase_date(3i)]'] > option[selected='selected']", :text => '16' I really want to specify two attributes for the <option> tag, like option[selected='selected',value='16'] - is there any syntax that allows this? Ashley From listaccount at e-tobi.net Thu Jan 18 04:43:42 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Thu, 18 Jan 2007 10:43:42 +0100 Subject: [rspec-users] problems testing a rails controller In-Reply-To: <545907.19730.qm@web56014.mail.re3.yahoo.com> References: <545907.19730.qm@web56014.mail.re3.yahoo.com> Message-ID: <45AF414E.40107@e-tobi.net> Jay Donnell wrote: > someone take a look at it and see if I'm missing > something obvious > > post 'search.rjs' Mmm... You're posting to the action 'search.rjs', but what you want to test is the action 'search' bye, Tobias From bryan at osesm.com Thu Jan 18 13:57:39 2007 From: bryan at osesm.com (Bryan Liles) Date: Thu, 18 Jan 2007 13:57:39 -0500 Subject: [rspec-users] What do you think of this controller spec? In-Reply-To: <810a540e0612260908k55c67a79wf281c58fa9fb7ce2@mail.gmail.com> References: <810a540e0612241253gd5b327ex706cb07e3ccacc6e@mail.gmail.com> <57c63afe0612250834nf735f0cge4cb2346a03e1057@mail.gmail.com> <810a540e0612260908k55c67a79wf281c58fa9fb7ce2@mail.gmail.com> Message-ID: <0FEDF8E5-9065-40E2-80BB-A26B6D033EBE@osesm.com> On Dec 26, 2006, at 12:08 PM, Pat Maddox wrote: > On 12/25/06, David Chelimsky <dchelimsky at gmail.com> wrote: >> On 12/24/06, Pat Maddox <pergesu at gmail.com> wrote: >>> Here's a controller spec I wrote, it's for a very simple RESTful >>> controller (well, aren't all RESTful controllers simple? :) >>> >>> I've created a couple spec helper methods to refactor some of the >>> common code...for example, require_login_and_correct_user creates >>> two >>> specifications: one for when the user isn't logged in, and one when >>> the user is logged in but requests someone else's book. do_request >>> automatically calls do_get/post/put/delete depending on what's >>> implemented. > > Here's the code with the incorporated changes: > spec_helper.rb: http://pastie.caboo.se/29577 > books_controller_spec.rb: http://pastie.caboo.se/29578 > I'm trying to follow your example, but the include command isn't extending what ever class my context runs in. From pergesu at gmail.com Thu Jan 18 14:51:33 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 18 Jan 2007 12:51:33 -0700 Subject: [rspec-users] What do you think of this controller spec? In-Reply-To: <0FEDF8E5-9065-40E2-80BB-A26B6D033EBE@osesm.com> References: <810a540e0612241253gd5b327ex706cb07e3ccacc6e@mail.gmail.com> <57c63afe0612250834nf735f0cge4cb2346a03e1057@mail.gmail.com> <810a540e0612260908k55c67a79wf281c58fa9fb7ce2@mail.gmail.com> <0FEDF8E5-9065-40E2-80BB-A26B6D033EBE@osesm.com> Message-ID: <810a540e0701181151s5eceb5c2j71f3155b729400fe@mail.gmail.com> On 1/18/07, Bryan Liles <bryan at osesm.com> wrote: > > On Dec 26, 2006, at 12:08 PM, Pat Maddox wrote: > > > On 12/25/06, David Chelimsky <dchelimsky at gmail.com> wrote: > >> On 12/24/06, Pat Maddox <pergesu at gmail.com> wrote: > >>> Here's a controller spec I wrote, it's for a very simple RESTful > >>> controller (well, aren't all RESTful controllers simple? :) > >>> > >>> I've created a couple spec helper methods to refactor some of the > >>> common code...for example, require_login_and_correct_user creates > >>> two > >>> specifications: one for when the user isn't logged in, and one when > >>> the user is logged in but requests someone else's book. do_request > >>> automatically calls do_get/post/put/delete depending on what's > >>> implemented. > > > > Here's the code with the incorporated changes: > > spec_helper.rb: http://pastie.caboo.se/29577 > > books_controller_spec.rb: http://pastie.caboo.se/29578 > > > > I'm trying to follow your example, but the include command isn't > extending what ever class my context runs in. See http://rubyforge.org/tracker/index.php?func=detail&aid=7461&group_id=797&atid=3151 From cwdinfo at gmail.com Thu Jan 18 16:44:38 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 18 Jan 2007 13:44:38 -0800 Subject: [rspec-users] spec'ing models with observers that send mail Message-ID: <AFD1AF18-FC30-4A70-B567-7F6FB789F353@gmail.com> I'm spec'ing a model with an observer that sends mail. Mailers behave similarly to controllers, so to make the whole thing work, I believe something like integrate_views has to be available. Has anyone dealt with observers and ActionMailer? Thanks From jaydonnell at yahoo.com Thu Jan 18 17:51:30 2007 From: jaydonnell at yahoo.com (Jay Donnell) Date: Thu, 18 Jan 2007 14:51:30 -0800 (PST) Subject: [rspec-users] problems testing a rails controller Message-ID: <245009.71018.qm@web56007.mail.re3.yahoo.com> "Mmm... You're posting to the action 'search.rjs', but what you want to test is the action 'search'" My understanding is that the new restful stuff in edge rails (i.e. the respond_to) method will use the extension to determine which output type to use. This code runs fine outside of the tests and I am using urls with extensions. What is the usual way to test various respond_to output types from rspec? ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com From dchelimsky at gmail.com Thu Jan 18 18:09:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Jan 2007 17:09:53 -0600 Subject: [rspec-users] problems testing a rails controller In-Reply-To: <245009.71018.qm@web56007.mail.re3.yahoo.com> References: <245009.71018.qm@web56007.mail.re3.yahoo.com> Message-ID: <57c63afe0701181509y42d88a72o54d9acd1d6108b16@mail.gmail.com> On 1/18/07, Jay Donnell <jaydonnell at yahoo.com> wrote: > "Mmm... You're posting to the action 'search.rjs', but > what you want to > test is the action 'search'" > > My understanding is that the new restful stuff in edge > rails (i.e. the respond_to) method will use the > extension to determine which output type to use. This > code runs fine outside of the tests and I am using > urls with extensions. > > What is the usual way to test various respond_to > output types from rspec? This bit looks odd: respond_to do |format| format.js { render :action => "search.rjs" } end I think you'd want to either render :template => 'seach.rjs' or just say format.js (and the rjs template would be rendered implicitly, no?) > > > > ____________________________________________________________________________________ > Do you Yahoo!? > Everyone is raving about the all-new Yahoo! Mail beta. > http://new.mail.yahoo.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jaydonnell at yahoo.com Thu Jan 18 20:48:04 2007 From: jaydonnell at yahoo.com (Jay Donnell) Date: Thu, 18 Jan 2007 17:48:04 -0800 (PST) Subject: [rspec-users] problems testing a rails controller In-Reply-To: <57c63afe0701181509y42d88a72o54d9acd1d6108b16@mail.gmail.com> Message-ID: <917599.16539.qm@web56009.mail.re3.yahoo.com> I'll try it without render :action as soon as I get a chance. I don't know why that would be a problem though. --- David Chelimsky <dchelimsky at gmail.com> wrote: > On 1/18/07, Jay Donnell <jaydonnell at yahoo.com> > wrote: > > "Mmm... You're posting to the action 'search.rjs', > but > > what you want to > > test is the action 'search'" > > > > My understanding is that the new restful stuff in > edge > > rails (i.e. the respond_to) method will use the > > extension to determine which output type to use. > This > > code runs fine outside of the tests and I am using > > urls with extensions. > > > > What is the usual way to test various respond_to > > output types from rspec? > > This bit looks odd: > > respond_to do |format| > format.js { render :action => "search.rjs" } > end > > I think you'd want to either render :template => > 'seach.rjs' or just > say format.js (and the rjs template would be > rendered implicitly, no?) > > > > > > > > > > ____________________________________________________________________________________ > > Do you Yahoo!? > > Everyone is raving about the all-new Yahoo! Mail > beta. > > http://new.mail.yahoo.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 > ____________________________________________________________________________________ Yahoo! Music Unlimited Access over 1 million songs. http://music.yahoo.com/unlimited From dchelimsky at gmail.com Thu Jan 18 21:23:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Jan 2007 20:23:13 -0600 Subject: [rspec-users] [ANN] RSpec 0.7.5.1 Message-ID: <57c63afe0701181823ub9b7d1bq63d85f6627ffc3d4@mail.gmail.com> Announcing the release of RSpec 0.7.5.1. This release fixes a bug that prevents you from installing RSpec with rubygems 0.9.1. It does not include any other fixes, so we do not recommend that you upgrade to this if you are already using 0.7.5. Thank you, The RSpec Development Team From jenny at likemindedgroup.com Thu Jan 18 19:03:14 2007 From: jenny at likemindedgroup.com (jenny lawrence) Date: Fri, 19 Jan 2007 00:03:14 -0000 Subject: [rspec-users] Error when following online tutorial Message-ID: <20070119000958.895F552422C8@rubyforge.org> Hi I'm following the tutorial from the website. I've got to the end, but I've been getting this failure: 'A stack with one item should return top when you send it top FAILED "one item" should equal "one item" ./stack_spec.rb:28: ./stack_spec.rb:27:in 'instance_eval' 3 specs 1 failure I do not understand this. Surely "one item" does equal "one item". I'm a beginner and I'm just trying to copy exactly what it says on the tin. What is going on? Can anyone help? Thanks Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070119/56e826c4/attachment.html From dchelimsky at gmail.com Thu Jan 18 22:12:57 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Jan 2007 21:12:57 -0600 Subject: [rspec-users] Error when following online tutorial In-Reply-To: <20070119000958.895F552422C8@rubyforge.org> References: <20070119000958.895F552422C8@rubyforge.org> Message-ID: <57c63afe0701181912i397f1fcby429dfc63de5bfab5@mail.gmail.com> On 1/18/07, jenny lawrence <jenny at likemindedgroup.com> wrote: > > > > > Hi > > > > I'm following the tutorial from the website. > > > > I've got to the end, but I've been getting this failure: > > > > 'A stack with one item should return top when you send it top FAILED > > "one item" should equal "one item" > > ./stack_spec.rb:28: > > ./stack_spec.rb:27:in 'instance_eval' > > > > 3 specs 1 failure > > > > I do not understand this. Surely "one item" does equal "one item". I'm a > beginner and I'm just trying to copy exactly what it says on the tin. What > is going on? Sorry Jenny - I haven't updated the tutorial since we made some changes to rspec syntax. The deal is that ruby evaluates actual.equal?(expected) using object identity. Even though "one item" and "one item" look the same, they are actually different objects in ruby. Instead, you want to use either: @stack.top.should_eql "one item" OR @stack.top.should == "one item" Check out http://rspec.rubyforge.org/documentation/expectations.html for more information. I'll update the tutorial soon. Cheers, David > > > > Can anyone help? > > > > Thanks > > > > Jason > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From brian at yamabe.net Thu Jan 18 22:18:29 2007 From: brian at yamabe.net (Brian Yamabe) Date: Thu, 18 Jan 2007 19:18:29 -0800 Subject: [rspec-users] rake spec:views Message-ID: <2A173275-C63D-4F05-B92A-FCEB774E9D39@yamabe.net> rake spec:views does not run the specs in my views folder. I can run them with spec <path>. Is there something I missed? ---Brian Yamabe From dchelimsky at gmail.com Thu Jan 18 22:34:04 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 18 Jan 2007 21:34:04 -0600 Subject: [rspec-users] rake spec:views In-Reply-To: <2A173275-C63D-4F05-B92A-FCEB774E9D39@yamabe.net> References: <2A173275-C63D-4F05-B92A-FCEB774E9D39@yamabe.net> Message-ID: <57c63afe0701181934hc5b3c72x994dae5ec92f2e73@mail.gmail.com> The files need be below spec/views/ and need be named ending in _spec.rb. Is that the case? On 1/18/07, Brian Yamabe <brian at yamabe.net> wrote: > rake spec:views does not run the specs in my views folder. I can run > them with spec <path>. Is there something I missed? > > ---Brian Yamabe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From brian at yamabe.net Thu Jan 18 22:41:19 2007 From: brian at yamabe.net (Brian Yamabe) Date: Thu, 18 Jan 2007 19:41:19 -0800 Subject: [rspec-users] rake spec:views In-Reply-To: <57c63afe0701181934hc5b3c72x994dae5ec92f2e73@mail.gmail.com> References: <2A173275-C63D-4F05-B92A-FCEB774E9D39@yamabe.net> <57c63afe0701181934hc5b3c72x994dae5ec92f2e73@mail.gmail.com> Message-ID: <0A05D175-3DBE-47B2-AA36-FF4B414E2AA8@yamabe.net> Thanks, can't believe I didn't notice the _spec. part. ---Brian Yamabe On Jan 18, 2007, at 7:34 PM, David Chelimsky wrote: > The files need be below spec/views/ and need be named ending in > _spec.rb. Is that the case? > > On 1/18/07, Brian Yamabe <brian at yamabe.net> wrote: >> rake spec:views does not run the specs in my views folder. I can run >> them with spec <path>. Is there something I missed? >> >> ---Brian Yamabe >> _______________________________________________ >> 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 jonathan.tron.mailings at gmail.com Fri Jan 19 04:09:50 2007 From: jonathan.tron.mailings at gmail.com (Jonathan Tron) Date: Fri, 19 Jan 2007 10:09:50 +0100 Subject: [rspec-users] spec'ing models with observers that send mail In-Reply-To: <AFD1AF18-FC30-4A70-B567-7F6FB789F353@gmail.com> References: <AFD1AF18-FC30-4A70-B567-7F6FB789F353@gmail.com> Message-ID: <C5388C0C-46B7-4D20-8D5C-B4E267F89E9A@gmail.com> Le 18 janv. 07 ? 22:44, s.ross a ?crit : > I'm spec'ing a model with an observer that sends mail. Mailers behave > similarly to controllers, so to make the whole thing work, I believe > something like integrate_views has to be available. Has anyone dealt > with observers and ActionMailer? I did it to add specs to restful_authentication plugin, it uses an observer to send mail on signup/activation. For the observer, I choosed to get it by calling UserObserver.instance and then spec from that with a mock User object. (cf: http://jonathan.tron.name/files/user_observer_spec.v2.rb) For the mailer, I choosed to spec based on the different mailer actions and what UserNotifier.create_my_action returns. (cf: http:// jonathan.tron.name/files/user_notifier_spec.v2.rb) I'm not sure it's the right way to go, especially for the mailer part, so feel free to correct my mistakes. Jonathan -- Tron Jonathan http://jonathan.tron.name From pergesu at gmail.com Fri Jan 19 05:05:01 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 19 Jan 2007 03:05:01 -0700 Subject: [rspec-users] Something cool I learned about rspec today Message-ID: <810a540e0701190205n17a24de5p632b0a2fef8a2c5@mail.gmail.com> I found an awesome feature today. When you're setting expectations, you can actually pattern match the parameters to methods. Here's my discussion and example: http://evang.eli.st/blog/2007/1/19/parameter-matching-in-rspec Pat From work at ashleymoran.me.uk Fri Jan 19 05:37:05 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 19 Jan 2007 10:37:05 +0000 Subject: [rspec-users] Something cool I learned about rspec today In-Reply-To: <810a540e0701190205n17a24de5p632b0a2fef8a2c5@mail.gmail.com> References: <810a540e0701190205n17a24de5p632b0a2fef8a2c5@mail.gmail.com> Message-ID: <DE1E163E-07D0-4F8C-A55B-3BC4F120E0A3@ashleymoran.me.uk> On 19 Jan 2007, at 10:05, Pat Maddox wrote: > I found an awesome feature today. When you're setting expectations, > you can actually pattern match the parameters to methods. Here's my > discussion and example: > http://evang.eli.st/blog/2007/1/19/parameter-matching-in-rspec Just out of curiosity, what would happen if you needed to pass a regex as a message argument? Ashley From aslak.hellesoy at gmail.com Fri Jan 19 05:39:40 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 19 Jan 2007 11:39:40 +0100 Subject: [rspec-users] Something cool I learned about rspec today In-Reply-To: <810a540e0701190205n17a24de5p632b0a2fef8a2c5@mail.gmail.com> References: <810a540e0701190205n17a24de5p632b0a2fef8a2c5@mail.gmail.com> Message-ID: <8d961d900701190239k119b25b2pcbf56cfec3cbc740@mail.gmail.com> On 1/19/07, Pat Maddox <pergesu at gmail.com> wrote: > I found an awesome feature today. When you're setting expectations, > you can actually pattern match the parameters to methods. Here's my > discussion and example: > http://evang.eli.st/blog/2007/1/19/parameter-matching-in-rspec > Nice writeup Pat! > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Fri Jan 19 05:44:57 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 19 Jan 2007 11:44:57 +0100 Subject: [rspec-users] Something cool I learned about rspec today In-Reply-To: <DE1E163E-07D0-4F8C-A55B-3BC4F120E0A3@ashleymoran.me.uk> References: <810a540e0701190205n17a24de5p632b0a2fef8a2c5@mail.gmail.com> <DE1E163E-07D0-4F8C-A55B-3BC4F120E0A3@ashleymoran.me.uk> Message-ID: <8d961d900701190244l2ebee4f5vbdfd1213e4fe94a0@mail.gmail.com> On 1/19/07, Ashley Moran <work at ashleymoran.me.uk> wrote: > > On 19 Jan 2007, at 10:05, Pat Maddox wrote: > > > I found an awesome feature today. When you're setting expectations, > > you can actually pattern match the parameters to methods. Here's my > > discussion and example: > > http://evang.eli.st/blog/2007/1/19/parameter-matching-in-rspec > > Just out of curiosity, what would happen if you needed to pass a > regex as a message argument? > Your mock expectation would look the same, and you'd have to call the method with an eql regexp to make it pass. -Like the example in the docs illustrates. Aslak > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From justnothing at tiscali.co.uk Fri Jan 19 07:07:16 2007 From: justnothing at tiscali.co.uk (David Green) Date: Fri, 19 Jan 2007 12:07:16 -0000 Subject: [rspec-users] problems updating to 0.7.5.1 Message-ID: <000501c73bc2$5d6828f0$8801a8c0@DCQ95K1J> Hi all I've upgraded the rails plugin from 0.7.5 to 0.7.5.1 (plugin/remove rspec_on_rails followed by : ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/REL_0_7_5_1/rspec_on_rails/vendor/plugins/rspec_on_rails I've also updated the rspec gem and removed the older version. I'm running rubygems 0.9.1 on a windows box however, when I try to run a spec (which was running fine under the old setup) I get the error message below. here are the steps I took to update: - ruby scipt/plugin/remove rspec_on_rails - ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/REL_0_7_5_1/rspec_on_rails/vendor/plugins/rspec_on_rails - ruby script/generate rspec (Y to over-write) - gem update rspec - gem uninstall rspec -v 0.7.5 - manually downloaded and installed rubygems 0.9.1. as per the instructions in this thread: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/d7bc67cb9c7372d3/cb9af3d48cd63863 needless to say I'm a little stumped now and would appreciate some help thanks david error message: M:\devel\wd\phoss>drbspec spec/models/photo_spec.rb (druby://localhost:8989) M:/devel/wd/phoss/vendor/plugins/rspec_on_rails/lib/spe c/rails/version.rb:14: (RuntimeError) ############################################################################ Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 0.7.5.1 (r1395) RSpec on Rails : r1394 Make sure your RSpec on Rails plugin is compatible with your RSpec gem. See http://rspec.rubyforge.org/documentation/rails/install.html for details. ############################################################################ from (druby://localhost:8989) c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu stom_require.rb:27:in `gem_original_require' from (druby://localhost:8989) c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu stom_require.rb:27:in `require' from (druby://localhost:8989) c:/ruby/lib/ruby/gems/1.8/gems/activesuppo rt-1.3.1/lib/active_support/dependencies.rb:147:in `require' from (druby://localhost:8989) M:/devel/wd/phoss/config/../vendor/plugins /rspec_on_rails/lib/spec/rails.rb:15 from (druby://localhost:8989) c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu stom_require.rb:27:in `gem_original_require' from (druby://localhost:8989) c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu stom_require.rb:27:in `require' from (druby://localhost:8989) c:/ruby/lib/ruby/gems/1.8/gems/activesuppo rt-1.3.1/lib/active_support/dependencies.rb:147:in `require' from (druby://localhost:8989) ./spec/models/../spec_helper.rb:5 ... 10 levels... from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.7.5.1/lib/spec/runner/drb_co mmand_line.rb:13:in `run' from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.7.5.1/bin/drbspec:3 from c:/ruby/bin/drbspec:16:in `load' from c:/ruby/bin/drbspec:16 From dchelimsky at gmail.com Fri Jan 19 08:07:17 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 19 Jan 2007 07:07:17 -0600 Subject: [rspec-users] problems updating to 0.7.5.1 In-Reply-To: <000501c73bc2$5d6828f0$8801a8c0@DCQ95K1J> References: <000501c73bc2$5d6828f0$8801a8c0@DCQ95K1J> Message-ID: <57c63afe0701190507k41a60035ob3df3aeed7f106a2@mail.gmail.com> Working on this now. I'll follow up shortly.... On 1/19/07, David Green <justnothing at tiscali.co.uk> wrote: > Hi all > > I've upgraded the rails plugin from 0.7.5 to 0.7.5.1 (plugin/remove > rspec_on_rails followed by : > ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/REL_0_7_5_1/rspec_on_rails/vendor/plugins/rspec_on_rails > I've also updated the rspec gem and removed the older version. I'm running > rubygems 0.9.1 on a windows box > > however, when I try to run a spec (which was running fine under the old > setup) I get the error message below. > > here are the steps I took to update: > > - ruby scipt/plugin/remove rspec_on_rails > - ruby script/plugin install > svn://rubyforge.org/var/svn/rspec/tags/REL_0_7_5_1/rspec_on_rails/vendor/plugins/rspec_on_rails > - ruby script/generate rspec (Y to over-write) > > - gem update rspec > - gem uninstall rspec -v 0.7.5 > > - manually downloaded and installed rubygems 0.9.1. as per the instructions > in this thread: > http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/d7bc67cb9c7372d3/cb9af3d48cd63863 > > needless to say I'm a little stumped now and would appreciate some help > thanks > > david > > error message: > > M:\devel\wd\phoss>drbspec spec/models/photo_spec.rb > (druby://localhost:8989) > M:/devel/wd/phoss/vendor/plugins/rspec_on_rails/lib/spe > c/rails/version.rb:14: (RuntimeError) > ############################################################################ > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > RSpec : 0.7.5.1 (r1395) > RSpec on Rails : r1394 > > Make sure your RSpec on Rails plugin is compatible with your RSpec gem. > See http://rspec.rubyforge.org/documentation/rails/install.html for details. > ############################################################################ > from (druby://localhost:8989) > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu > stom_require.rb:27:in `gem_original_require' > from (druby://localhost:8989) > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu > stom_require.rb:27:in `require' > from (druby://localhost:8989) > c:/ruby/lib/ruby/gems/1.8/gems/activesuppo > rt-1.3.1/lib/active_support/dependencies.rb:147:in `require' > from (druby://localhost:8989) > M:/devel/wd/phoss/config/../vendor/plugins > /rspec_on_rails/lib/spec/rails.rb:15 > from (druby://localhost:8989) > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu > stom_require.rb:27:in `gem_original_require' > from (druby://localhost:8989) > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu > stom_require.rb:27:in `require' > from (druby://localhost:8989) > c:/ruby/lib/ruby/gems/1.8/gems/activesuppo > rt-1.3.1/lib/active_support/dependencies.rb:147:in `require' > from (druby://localhost:8989) ./spec/models/../spec_helper.rb:5 > ... 10 levels... > from > c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.7.5.1/lib/spec/runner/drb_co > mmand_line.rb:13:in `run' > from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.7.5.1/bin/drbspec:3 > from c:/ruby/bin/drbspec:16:in `load' > from c:/ruby/bin/drbspec:16 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jan 19 08:47:17 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 19 Jan 2007 07:47:17 -0600 Subject: [rspec-users] problems updating to 0.7.5.1 In-Reply-To: <57c63afe0701190507k41a60035ob3df3aeed7f106a2@mail.gmail.com> References: <000501c73bc2$5d6828f0$8801a8c0@DCQ95K1J> <57c63afe0701190507k41a60035ob3df3aeed7f106a2@mail.gmail.com> Message-ID: <57c63afe0701190547u303b835o8fcb93ac9b8209c6@mail.gmail.com> OK. This is fixed now. For those who are interested.... I'm not quite sure how it happened, but when I did the release the gem and and the tag ended up w/ different revision numbers. We've got code in the plugin that enforces a rule that the rspec and rspec_on_rails revision numbers must match. I went ahead and hard-coded the revision number in the plugin to match that of the gem. All should be working correctly now. Thanks for your patience. Cheers, David On 1/19/07, David Chelimsky <dchelimsky at gmail.com> wrote: > Working on this now. I'll follow up shortly.... > > On 1/19/07, David Green <justnothing at tiscali.co.uk> wrote: > > Hi all > > > > I've upgraded the rails plugin from 0.7.5 to 0.7.5.1 (plugin/remove > > rspec_on_rails followed by : > > ruby script/plugin install > > svn://rubyforge.org/var/svn/rspec/tags/REL_0_7_5_1/rspec_on_rails/vendor/plugins/rspec_on_rails > > I've also updated the rspec gem and removed the older version. I'm running > > rubygems 0.9.1 on a windows box > > > > however, when I try to run a spec (which was running fine under the old > > setup) I get the error message below. > > > > here are the steps I took to update: > > > > - ruby scipt/plugin/remove rspec_on_rails > > - ruby script/plugin install > > svn://rubyforge.org/var/svn/rspec/tags/REL_0_7_5_1/rspec_on_rails/vendor/plugins/rspec_on_rails > > - ruby script/generate rspec (Y to over-write) > > > > - gem update rspec > > - gem uninstall rspec -v 0.7.5 > > > > - manually downloaded and installed rubygems 0.9.1. as per the instructions > > in this thread: > > http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/d7bc67cb9c7372d3/cb9af3d48cd63863 > > > > needless to say I'm a little stumped now and would appreciate some help > > thanks > > > > david > > > > error message: > > > > M:\devel\wd\phoss>drbspec spec/models/photo_spec.rb > > (druby://localhost:8989) > > M:/devel/wd/phoss/vendor/plugins/rspec_on_rails/lib/spe > > c/rails/version.rb:14: (RuntimeError) > > ############################################################################ > > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > > > RSpec : 0.7.5.1 (r1395) > > RSpec on Rails : r1394 > > > > Make sure your RSpec on Rails plugin is compatible with your RSpec gem. > > See http://rspec.rubyforge.org/documentation/rails/install.html for details. > > ############################################################################ > > from (druby://localhost:8989) > > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu > > stom_require.rb:27:in `gem_original_require' > > from (druby://localhost:8989) > > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu > > stom_require.rb:27:in `require' > > from (druby://localhost:8989) > > c:/ruby/lib/ruby/gems/1.8/gems/activesuppo > > rt-1.3.1/lib/active_support/dependencies.rb:147:in `require' > > from (druby://localhost:8989) > > M:/devel/wd/phoss/config/../vendor/plugins > > /rspec_on_rails/lib/spec/rails.rb:15 > > from (druby://localhost:8989) > > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu > > stom_require.rb:27:in `gem_original_require' > > from (druby://localhost:8989) > > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/cu > > stom_require.rb:27:in `require' > > from (druby://localhost:8989) > > c:/ruby/lib/ruby/gems/1.8/gems/activesuppo > > rt-1.3.1/lib/active_support/dependencies.rb:147:in `require' > > from (druby://localhost:8989) ./spec/models/../spec_helper.rb:5 > > ... 10 levels... > > from > > c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.7.5.1/lib/spec/runner/drb_co > > mmand_line.rb:13:in `run' > > from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.7.5.1/bin/drbspec:3 > > from c:/ruby/bin/drbspec:16:in `load' > > from c:/ruby/bin/drbspec:16 > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From justnothing at tiscali.co.uk Fri Jan 19 10:30:29 2007 From: justnothing at tiscali.co.uk (David Green) Date: Fri, 19 Jan 2007 15:30:29 -0000 Subject: [rspec-users] problems updating to 0.7.5.1 Message-ID: <000f01c73bde$c1e53130$8801a8c0@DCQ95K1J> > OK. This is fixed now. thanks david! I appreciate you fixing it so quickly. From lists-rspec at shopwatch.org Fri Jan 19 22:51:05 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Fri, 19 Jan 2007 22:51:05 -0500 Subject: [rspec-users] heckle and rspec on rails In-Reply-To: <e282921e0701150129m924b4e3rbcc30589bf7bfd4c@mail.gmail.com> References: <e282921e0701150129m924b4e3rbcc30589bf7bfd4c@mail.gmail.com> Message-ID: <45B191A9.8070209@rubyforge.org> Chris Anderson wrote: > I guess the question is, has anyone had luck using Heckle with Rails? > I've got it working for regular ruby specs, and it's a lot of fun > (although I do hit infinite loops sometimes). If I heckle an ActiveRecord model, I get all sorts of noise about the various methods ActiveRecord adds. However, if I heckle a regular old class I wrote, I get the results you're seeing - single run, no heckling. Not sure what to go look at from here. Jay Levitt From lists-rspec at shopwatch.org Sat Jan 20 11:02:36 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sat, 20 Jan 2007 11:02:36 -0500 Subject: [rspec-users] heckle and rspec on rails In-Reply-To: <45B191A9.8070209@rubyforge.org> References: <e282921e0701150129m924b4e3rbcc30589bf7bfd4c@mail.gmail.com> <45B191A9.8070209@rubyforge.org> Message-ID: <45B23D1C.3050908@rubyforge.org> Jay Levitt wrote: > If I heckle an ActiveRecord model, I get all sorts of noise about the > various methods ActiveRecord adds. However, if I heckle a regular old > class I wrote, I get the results you're seeing - single run, no > heckling. Not sure what to go look at from here. No, ignore that - I was mistyping my own class name! When I heckle the class, it works as expected. Jay From listaccount at e-tobi.net Sat Jan 20 20:25:00 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Sun, 21 Jan 2007 02:25:00 +0100 Subject: [rspec-users] A Thread / Mock question Message-ID: <45B2C0EC.1030609@e-tobi.net> Hi! What I'm trying at the moment is to build specifications for some background thread code. What I want is a class Task and a class TaskRunner. The TaskRunner should run a task in a background thread. It should also indicate the status of the running task when calling the running? method. That's basically, what I came up with so far: class TaskRunner def initialize @is_running = false end def running? return @is_running end def execute(task) @is_running = true Thread.new do task.run @is_running = false end end end class SampleTask def run end end context "The TaskRunner" do setup do Thread.stub!(:new).and_return do |block| block.call end @runner = TaskRunner.new end specify "should be running when a task is executed" do task = SampleTask.new task.should_receive(:run) do @runner.should_be_running end @runner.execute(task) end specify "should not be running after the task has been executed" do @runner.execute(SampleTask.new) @runner.should_not_be_running end end I don't want to have real threads in the specs, so I mocked the Thread class to just execute the passed block within the main thread. In the first specification I also mock the run method of the task to check within that method, if the TaskRunner correctly indicates it's running status. So far this works, but maybe there is a better solution. Any suggestions? Is there a way to use the above mocking of Thread.new and pass a parameter to the block executed by the thread, like this?: def execute(task) @is_running = true Thread.new(task) do |task_to_execute| task_to_execute.run @is_running = false end end How can RSpec mock Thread.new in this case? Maybe I should introduce some kind of ThreadFactory that creates instances of TestableThread for the specifications. bye, Tobias From francois.beausoleil at gmail.com Sat Jan 20 23:45:17 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Sat, 20 Jan 2007 23:45:17 -0500 Subject: [rspec-users] Collection proxies need to be stubbed ? Message-ID: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> Hi all ! I just started writing specs on a new project. I would just like to validate that this is the way you would write it. I know about mocks, stubs and expectations. I don't think this is a problem for me. My question really boils down to: def index @projects = current_user.projects.active end My spec needs to return the proxy, no ? Here's my code: context "A logged in user visiting the index action" do controller_name :dashboard setup do @user = mock("user") controller.stub!(:current_user).and_return(@user) @user.should_receive(:projects).and_return(projects_proxy = Object.new) projects_proxy.should_receive(:active).and_return([:a, :b]) get :index end specify "should have a list of projects available" do assigns[:projects].should == [:a, :b] end specify "should render the index view" do controller.should_render :template => "dashboard/index" end specify "should be a successful call" do response.should_be_success end end Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From listaccount at e-tobi.net Sun Jan 21 06:25:30 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Sun, 21 Jan 2007 12:25:30 +0100 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> Message-ID: <45B34DAA.7040004@e-tobi.net> Hi! Francois Beausoleil wrote: > My question really boils down to: > > def index > @projects = current_user.projects.active > end > > My spec needs to return the proxy, no ? Here's my code: > >From a RSpec-newbie's point of view: Looks like current_user is a method of the controller, that selects the user from the request params, right? Mocking this means, current_user() will not be covered by the specs. Normally I avoid mocking/stubbing members of a class under test or private and protected members of any class. You could instead mock the User class directly to return the User mock. But why not use fixtures and let it run with real data instead of mocking the database away? bye, Tobias From dchelimsky at gmail.com Sun Jan 21 06:37:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 05:37:59 -0600 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> Message-ID: <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> On 1/20/07, Francois Beausoleil <francois.beausoleil at gmail.com> wrote: > Hi all ! > > I just started writing specs on a new project. I would just like to > validate that this is the way you would write it. I know about mocks, > stubs and expectations. I don't think this is a problem for me. > > My question really boils down to: > > def index > @projects = current_user.projects.active > end > > My spec needs to return the proxy, no ? Here's my code: > > context "A logged in user visiting the index action" do > controller_name :dashboard > > setup do > @user = mock("user") > controller.stub!(:current_user).and_return(@user) > > @user.should_receive(:projects).and_return(projects_proxy = Object.new) > projects_proxy.should_receive(:active).and_return([:a, :b]) > get :index > end > > specify "should have a list of projects available" do > assigns[:projects].should == [:a, :b] > end > > specify "should render the index view" do > controller.should_render :template => "dashboard/index" > end > > specify "should be a successful call" do > response.should_be_success > end > end I would approach this quite differently. The first difference being I would have started with a spec, letting the spec help me to discover the interface that I want on User. context "A logged in user visiting the index action" do controller_name :dashboard setup do @user = mock("user") controller.stub!(:current_user).and_return(@user) @user.should_receive(:active_projects).and_return([:a, :b]) get :index end specify "should have a list of projects available" do assigns[:projects].should == [:a, :b] end specify "should render the index view" do response.should_render :template => "dashboard/index" end specify "should be a successful call" do response.should_be_success end end This would lead me to this implementation ... def index @projects = current_user.active_projects end ... which would, in turn, lead me to spec out a method named active_projects on User. The other thing that I've been doing lately is making an effort to separate out the noise (in setup) from the interesting bits in each specification. I do that by using stub! in setup and should_receive in specify, using should_receive to override stub! when appropriate. This leads to a more verbose spec, but it makes each specify block complete (so you don't have to look back at setup). context "A logged in user visiting the index action" do controller_name :dashboard setup do @user = mock("user") @user.stub!(:active_projects).and_return([]) controller.stub!(:current_user).and_return(@user) end specify "should have a list of projects available" do #given @user.should_receive(:active_projects).and_return([:a, :b]) #when get :index #then assigns[:projects].should == [:a, :b] end specify "should render the index view" do #given - nothing unusual #when get :index #then response.should_be_success response.should_render :template => "dashboard/index" end end Here I've identified in each spec the Given/When/Then with comments. Note that I abhor comments like this in production code, but I've come to view specs as different from code. The result is that each spec is easy to read and understand in isolation. You don't have to look up at setup to understand a problem. Note also that I've used two expectations in one spec. For me, having a separate spec for should_be_success is not that meaningful when we're spec'ing the template. From a developer standpoint it might be helpful to have the statement there when trying to understand a problem, but from the outside we know it was successful if the right template shows up, no? A little more than 2 cents. Hope this is all helpful. Cheers, David > > Thanks ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > http://piston.rubyforge.org/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Jan 21 06:46:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 05:46:13 -0600 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <45B34DAA.7040004@e-tobi.net> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> Message-ID: <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> On 1/21/07, Tobias Grimm <listaccount at e-tobi.net> wrote: > Hi! > > Francois Beausoleil wrote: > > My question really boils down to: > > > > def index > > @projects = current_user.projects.active > > end > > > > My spec needs to return the proxy, no ? Here's my code: > > > >From a RSpec-newbie's point of view: > > Looks like current_user is a method of the controller, that selects the > user from the request params, right? Mocking this means, current_user() > will not be covered by the specs. Normally I avoid mocking/stubbing > members of a class under test or private and protected members of any > class. You could instead mock the User class directly to return the User > mock. If the current_user is actually coming from request params I agree w/ this. If it's a user stored in the session, I don't agree that it should come from the User class. I would probably stick the mock user in the session though, rather than stub the method. > But why not use fixtures and let it run with real data instead of > mocking the database away? Because specs run faster when you don't rely on the database. You're going to be spec'ing all the same stuff in your model specs, so why hit the database more than you need to? Cheers, David > > bye, > > Tobias > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From listaccount at e-tobi.net Sun Jan 21 07:24:07 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Sun, 21 Jan 2007 13:24:07 +0100 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> Message-ID: <45B35B67.2070402@e-tobi.net> David Chelimsky wrote: > this. If it's a user stored in the session, I don't agree that it > should come from the User class. I would probably stick the mock user > in the session though, rather than stub the method. > Agreed - if it's in the session, this should be the preferred way. > Because specs run faster when you don't rely on the database. You're > going to be spec'ing all the same stuff in your model specs, so why > hit the database more than you need to? > I don't have any experience with RSpec/Rails using a database - my current Rails project is DB-less :-) But on a recent C# project (with NUnit) I've chosen to just use a database in my tests. It wasn't even an in-memory database (embedded Firebird) but it was still fast enough with several hundred tests hitting the database. Rails with SQLite in memory should even be faster. So speed isn't really much of an issue in my experience. But you're right that stubbing database access should be preferred. Sometimes it's just easier to put complex data into a fixture and retrieve it from the database. Maybe that's a design smell - I'll keep this in mind when I run into this situation the next time. Tobias From dchelimsky at gmail.com Sun Jan 21 07:36:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 06:36:01 -0600 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <45B35B67.2070402@e-tobi.net> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> <45B35B67.2070402@e-tobi.net> Message-ID: <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> On 1/21/07, Tobias Grimm <listaccount at e-tobi.net> wrote: > David Chelimsky wrote: > > this. If it's a user stored in the session, I don't agree that it > > should come from the User class. I would probably stick the mock user > > in the session though, rather than stub the method. > > > > Agreed - if it's in the session, this should be the preferred way. > > > Because specs run faster when you don't rely on the database. You're > > going to be spec'ing all the same stuff in your model specs, so why > > hit the database more than you need to? > > > > I don't have any experience with RSpec/Rails using a database - my > current Rails project is DB-less :-) But on a recent C# project (with > NUnit) I've chosen to just use a database in my tests. It wasn't even an > in-memory database (embedded Firebird) but it was still fast enough with > several hundred tests hitting the database. What's fast enough? When doing BDD or TDD, the goal is to run the specs (tests) as often as possible, after every little change. I run my specs dozens (if not hundreds) of times a day, so a difference of a few seconds adds up to a big difference. >Rails with SQLite in memory > should even be faster. So speed isn't really much of an issue in my > experience. > > But you're right that stubbing database access should be preferred. > Sometimes it's just easier to put complex data into a fixture and > retrieve it from the database. Maybe that's a design smell - I'll keep > this in mind when I run into this situation the next time. > > > Tobias > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From listaccount at e-tobi.net Sun Jan 21 07:58:42 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Sun, 21 Jan 2007 13:58:42 +0100 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> Message-ID: <45B36382.2030503@e-tobi.net> David Chelimsky wrote: > What's fast enough? > It's fast enough, if it doesn't break my "flow" - which most likely is slower than your's :-) Tobias From francois.beausoleil at gmail.com Sun Jan 21 15:42:56 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Sun, 21 Jan 2007 15:42:56 -0500 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> Message-ID: <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> Hello David, all, 2007/1/21, David Chelimsky <dchelimsky at gmail.com>: > On 1/20/07, Francois Beausoleil <francois.beausoleil at gmail.com> wrote: > > def index > > @projects = current_user.projects.active > > end > > I would approach this quite differently. The first difference being I > would have started with a spec, letting the spec help me to discover > the interface that I want on User. > > def index > @projects = current_user.active_projects > end > > ... which would, in turn, lead me to spec out a method named > active_projects on User. I agree with you, David, but Rails has this nice facility for allowing developers to add methods on collection proxies. The end goal is that I get only active / inactive projects, right ? Whatever implementation floats the boat is good. Adding #active_projects on User leads to a kind of namespace pollution, no ? Really, who knows what projects are active ? The Project class, or the User ? has_many :projects do def active find(:all, :conditions => ['active = 1']) end end has_many :projects def active_projects end We're going off-topic here, but these are good design questions anyway. Thank you for enlightning me ! Bye ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From francois.beausoleil at gmail.com Sun Jan 21 15:44:38 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Sun, 21 Jan 2007 15:44:38 -0500 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> Message-ID: <41d5fadf0701211244t71ba8ceci495a73aaa0ed4f15@mail.gmail.com> Shoot! Message went away too fast. has_many :projects def active_projects self.projects.find(:all, :conditions => ['active = 1']) end Or another alternative: class Project def self.active with_scope(:find => ['active = 1']) do yield end end end In the end, it boils down to preferences, no ? Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From lists-rspec at shopwatch.org Sun Jan 21 15:46:23 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 21 Jan 2007 15:46:23 -0500 Subject: [rspec-users] More on collection proxies In-Reply-To: <45B36382.2030503@e-tobi.net> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> Message-ID: <45B3D11F.90703@rubyforge.org> I've got a question similar to Francois's. I'm writing a to-do-like application, where each Task has a number of Events, consisting of event.date and event.status. I want to see how long it's been since the Task was last completed. So: context "A task completed once on 2001-01-02" do setup do @task = Task.new mock_event = Struct.new(:date, :status) @task.stub!(:events).and_return( [mock_event.new(Date.parse("2001-01-02"), "completed")]) end specify "was completed 0 days ago on 2001-01-02" do @task.completed_days_ago(Date.parse("2001-01-02")).should_eql 0 end end task.rb looks like: def cache_completions @completions = {} events.each do |event| @completions[event.date] = event.status end end def completed_days_ago(todays_date) cache_completions unless @completions date = todays_date while date > todays_date - 7 do return (todays_date - date).to_i if @completions[date] == "completed" date = date - 1 end "never" end This smells a bit. I could separate part of completed_days_ago into last_completed_on(date), but no matter how I slice it I still end up mocking Task.cells for some routine. Suggestions? Jay From cwdinfo at gmail.com Sun Jan 21 15:52:09 2007 From: cwdinfo at gmail.com (s.ross) Date: Sun, 21 Jan 2007 12:52:09 -0800 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> Message-ID: <A09E1267-DD7F-4693-B57A-D267EAB3048F@gmail.com> Do partial mocks solve your problem? http://rspec.rubyforge.org/documentation/mocks/partial_mocks.html I run into a lot of these issues when spec'ing, and it seems writing mocks that cover as many cases as I expect AR to cough up can be difficult. Others might have different experiences. I found partial mocks intriguing, although I've not yet explored them. Hope I'm not barking up the wrong tree. --steve On Jan 21, 2007, at 12:42 PM, Francois Beausoleil wrote: > Hello David, all, > > 2007/1/21, David Chelimsky <dchelimsky at gmail.com>: >> On 1/20/07, Francois Beausoleil <francois.beausoleil at gmail.com> >> wrote: >>> def index >>> @projects = current_user.projects.active >>> end >> >> I would approach this quite differently. The first difference being I >> would have started with a spec, letting the spec help me to discover >> the interface that I want on User. >> >> def index >> @projects = current_user.active_projects >> end >> >> ... which would, in turn, lead me to spec out a method named >> active_projects on User. > > I agree with you, David, but Rails has this nice facility for allowing > developers to add methods on collection proxies. The end goal is that > I get only active / inactive projects, right ? Whatever > implementation floats the boat is good. > > Adding #active_projects on User leads to a kind of namespace > pollution, no ? Really, who knows what projects are active ? The > Project class, or the User ? > > has_many :projects do > def active > find(:all, :conditions => ['active = 1']) > end > end > > has_many :projects > def active_projects > > end > > We're going off-topic here, but these are good design questions > anyway. > > Thank you for enlightning me ! > > Bye ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > http://piston.rubyforge.org/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists-rspec at shopwatch.org Sun Jan 21 15:53:43 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 21 Jan 2007 15:53:43 -0500 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> Message-ID: <45B3D2D7.5050400@rubyforge.org> Francois Beausoleil wrote: > > Adding #active_projects on User leads to a kind of namespace > pollution, no ? Really, who knows what projects are active ? The > Project class, or the User ? This seems to be a basic conflict between "Tell, don't ask" and domain-driven design. DDD, as I understand it, says the Project class should encapsulate all knowledge about projects; TDA says we shouldn't ask for the project proxy. Yes? Jay From dchelimsky at gmail.com Sun Jan 21 16:59:27 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 15:59:27 -0600 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> Message-ID: <57c63afe0701211359l1238f200v3dde8cf7ad447fc3@mail.gmail.com> On 1/21/07, Francois Beausoleil <francois.beausoleil at gmail.com> wrote: > Hello David, all, > > 2007/1/21, David Chelimsky <dchelimsky at gmail.com>: > > On 1/20/07, Francois Beausoleil <francois.beausoleil at gmail.com> wrote: > > > def index > > > @projects = current_user.projects.active > > > end > > > > I would approach this quite differently. The first difference being I > > would have started with a spec, letting the spec help me to discover > > the interface that I want on User. > > > > def index > > @projects = current_user.active_projects > > end > > > > ... which would, in turn, lead me to spec out a method named > > active_projects on User. > > I agree with you, David, but Rails has this nice facility for allowing > developers to add methods on collection proxies. The end goal is that > I get only active / inactive projects, right ? Whatever > implementation floats the boat is good. > > Adding #active_projects on User leads to a kind of namespace > pollution, no ? Really, who knows what projects are active ? The > Project class, or the User ? > > has_many :projects do > def active > find(:all, :conditions => ['active = 1']) > end > end > > has_many :projects > def active_projects > > end > > We're going off-topic here, but these are good design questions anyway. RSpec is ALL ABOUT design, so these questions are certainly on topic (in my view). > > Thank you for enlightning me ! > > Bye ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > http://piston.rubyforge.org/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From brian at yamabe.net Sun Jan 21 17:02:01 2007 From: brian at yamabe.net (Brian Yamabe) Date: Sun, 21 Jan 2007 14:02:01 -0800 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <45B3D2D7.5050400@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> Message-ID: <40DABC99-130D-48D8-946B-B82F9FD28D8F@yamabe.net> Sorry for continuing the divergence, but the design thoughts are very interesting. Couldn't DDD and TDA be satisfied by: Project.find_active_projects_for_user(:current_user) ---Brian Yamabe On Jan 21, 2007, at 12:53 PM, Jay Levitt wrote: > Francois Beausoleil wrote: > >> >> Adding #active_projects on User leads to a kind of namespace >> pollution, no ? Really, who knows what projects are active ? The >> Project class, or the User ? > > This seems to be a basic conflict between "Tell, don't ask" and > domain-driven design. DDD, as I understand it, says the Project class > should encapsulate all knowledge about projects; TDA says we shouldn't > ask for the project proxy. Yes? > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Jan 21 17:14:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 16:14:37 -0600 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <45B3D2D7.5050400@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> Message-ID: <57c63afe0701211414t189c0df1md288cce6885c0a56@mail.gmail.com> On 1/21/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > Francois Beausoleil wrote: > > > > > Adding #active_projects on User leads to a kind of namespace > > pollution, no ? Really, who knows what projects are active ? The > > Project class, or the User ? > > This seems to be a basic conflict between "Tell, don't ask" and > domain-driven design. DDD, as I understand it, says the Project class > should encapsulate all knowledge about projects; TDA says we shouldn't > ask for the project proxy. Yes? TDA says we shouldn't even ask the User for its Projects. It's the Law of Demeter that says we shouldn't ask the User for it's Projects and THEN ask the Projects whether they are active. Just because rails makes it easy doesn't make it a good design choice. It really depends on context. If your app is never going to change requirements, then the problems associated with violations of OO design principles don't really matter. They are all about writing maintainable software. I'm serious here - I don't mean to patronize. There are times when the application you're writing will have simple requirements and a short potential life-span. In those cases, the costs of heeding to design principles might outweigh the benefits of a flexible design. That said, imagine that somewhere down the line the requirements change such that User knows its Projects through some middle man, like a ProjectManager. Now you'd have to change all the places in the code that say "user.projects.active" would have to change to "user.project_manager.projects.active". Of course at that point you could change #projects to delegate to project_manager.projects, so clients of User wouldn't have to change, but you see the point. So I'd prefer to not advertise how the User keeps its Projects. But that's me. 2 cents worth. > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jan 21 17:23:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 16:23:51 -0600 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <40DABC99-130D-48D8-946B-B82F9FD28D8F@yamabe.net> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> <40DABC99-130D-48D8-946B-B82F9FD28D8F@yamabe.net> Message-ID: <57c63afe0701211423r5fde1438ib5ca73505391647d@mail.gmail.com> On 1/21/07, Brian Yamabe <brian at yamabe.net> wrote: > Sorry for continuing the divergence, but the design thoughts are very > interesting. > > Couldn't DDD and TDA be satisfied by: > Project.find_active_projects_for_user(:current_user) How would that be implemented? def self.find_active_projects_for_user(user) return user.projects.active_projects end This bi-directional dependency seems problematic to me. I realize that rails makes it easy to do these, but again, just because its easy doesn't make it a good decision. This is one of those questions that can be enlightened by client need. Do clients of Projects ask for their users? Do clients of User ask for its Projects? If both answers are yes, then maybe the bi-directional deal makes sense. If only one is needed, then only one should be implemented. OK. I'll shut up now. Go Bears! David > ---Brian Yamabe > > On Jan 21, 2007, at 12:53 PM, Jay Levitt wrote: > > > Francois Beausoleil wrote: > > > >> > >> Adding #active_projects on User leads to a kind of namespace > >> pollution, no ? Really, who knows what projects are active ? The > >> Project class, or the User ? > > > > This seems to be a basic conflict between "Tell, don't ask" and > > domain-driven design. DDD, as I understand it, says the Project class > > should encapsulate all knowledge about projects; TDA says we shouldn't > > ask for the project proxy. Yes? > > > > Jay > > > > _______________________________________________ > > 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 Sun Jan 21 17:28:44 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 16:28:44 -0600 Subject: [rspec-users] More on collection proxies In-Reply-To: <45B3D11F.90703@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> Message-ID: <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> On 1/21/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > I've got a question similar to Francois's. I'm writing a to-do-like > application, where each Task has a number of Events, consisting of > event.date and event.status. I want to see how long it's been since the > Task was last completed. So: > > context "A task completed once on 2001-01-02" do > setup do > @task = Task.new > mock_event = Struct.new(:date, :status) > @task.stub!(:events).and_return( > [mock_event.new(Date.parse("2001-01-02"), "completed")]) > end > > specify "was completed 0 days ago on 2001-01-02" do > @task.completed_days_ago(Date.parse("2001-01-02")).should_eql 0 > end > end > > task.rb looks like: > > def cache_completions > @completions = {} > events.each do |event| > @completions[event.date] = event.status > end > end > > def completed_days_ago(todays_date) > cache_completions unless @completions > date = todays_date > while date > todays_date - 7 do > return (todays_date - date).to_i if @completions[date] == "completed" > date = date - 1 > end > > "never" > end > > > This smells a bit. I could separate part of completed_days_ago into > last_completed_on(date), but no matter how I slice it I still end up > mocking Task.cells for some routine. Suggestions? Ah, how I love these questions. Thanks Jay! So first of all, lets think about what we REALLY want the interface to Task to be. What you have there is: @task.completed_days_ago(date) In your description, you say "how long it's been since the Task was last completed". That leads me to a method name like this: @task.days_since_completed(date) The next question is, why are we passing in the date? We want to how many days have passed since it was completed, not how many days between completion and some arbitrary date. Now this gets tricky because the method becomes more testable if you can supply the date, but supplying the date doesn't "feel" right in the context of "days_since_completed". >From here, I see a couple of ways to go. One would be to stub Time.new (or local, or whatever method you wish to use to generate current time) and leave the method with no argument: context "A task completed once on 2001-02-03" do setup do event_stub = Struct.new(:date, :status).new(Time.parse("2001-02-03"), "completed") Time.stub!(:new).and_return(Time.parse("2001-02-03")) @task = Task.new @task.stub!(:events).and_return([event_stub]) end specify "was completed 0 days ago on 2001-02-03" do @task.days_since_completed.should_eql 0 end end Another would be to change the meaning of the method to something like: @task.days_from_completion_date_to(date) No perfect answer here. Just food for thought. Cheers, David > > Jay > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists-rspec at shopwatch.org Sun Jan 21 18:09:18 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 21 Jan 2007 18:09:18 -0500 Subject: [rspec-users] More on collection proxies In-Reply-To: <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> Message-ID: <45B3F29E.1080009@rubyforge.org> David Chelimsky wrote: > On 1/21/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: >> I've got a question similar to Francois's. I'm writing a to-do-like >> application, where each Task has a number of Events, consisting of >> event.date and event.status. I want to see how long it's been since the >> Task was last completed. So: [snip] >> This smells a bit. I could separate part of completed_days_ago into >> last_completed_on(date), but no matter how I slice it I still end up >> mocking Task.cells for some routine. Suggestions? > > The next question is, why are we passing in the date? We want to how > many days have passed since it was completed, not how many days > between completion and some arbitrary date. Actually, we want the latter - but of course you couldn't tell that from my method name! The tasks are repeating, and this app fills in a spreadsheet-like series of cells, one per day, with various colors, depending on how often you're completing a task. So we actually need to check the task's status on any given day. [..] > event_stub = Struct.new(:date, > :status).new(Time.parse("2001-02-03"), "completed") > @task.stub!(:events).and_return([event_stub]) [..] You don't mind stubbing the association proxy as a struct? That was my real question; it seems to lead down a messy road of trying to stub every ActiveRecord method. On the one hand, it seems like BDD says I should stub or mock any object other than the one under test. On the other, since I'm still in the models realm, maybe it's okay to use fixtures to represent the model relations. Or maybe there's a third way. Jay From lists-rspec at shopwatch.org Sun Jan 21 18:13:46 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 21 Jan 2007 18:13:46 -0500 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <57c63afe0701211414t189c0df1md288cce6885c0a56@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> <57c63afe0701211414t189c0df1md288cce6885c0a56@mail.gmail.com> Message-ID: <45B3F3AA.1080606@rubyforge.org> David Chelimsky wrote: > TDA says we shouldn't even ask the User for its Projects. It's the Law > of Demeter that says we shouldn't ask the User for it's Projects and > THEN ask the Projects whether they are active. Oops, my bad, then! So is it my misunderstanding of domain-driven design - especially the AGGREGATE pattern - or is TDA diametrically opposed to DDD here? Can we get Alec Sharp and Eric Evans in a boxing ring? Jay From brian at yamabe.net Sun Jan 21 18:32:20 2007 From: brian at yamabe.net (Brian Yamabe) Date: Sun, 21 Jan 2007 15:32:20 -0800 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <57c63afe0701211423r5fde1438ib5ca73505391647d@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> <40DABC99-130D-48D8-946B-B82F9FD28D8F@yamabe.net> <57c63afe0701211423r5fde1438ib5ca73505391647d@mail.gmail.com> Message-ID: <9DB465C9-119C-4577-8896-EDA12E744709@yamabe.net> David, thanks for making me think. If the bi-directional dependency is needed, would it be cleaned up with a "has_many :through" (An Assignment class as an example)? > def self.find_active_projects_for_user(user) > return user.projects.active_projects > end > > This bi-directional dependency seems problematic to me. I realize that > rails makes it easy to do these, but again, just because its easy > doesn't make it a good decision. > > This is one of those questions that can be enlightened by client need. > Do clients of Projects ask for their users? Do clients of User ask for > its Projects? If both answers are yes, then maybe the bi-directional > deal makes sense. If only one is needed, then only one should be > implemented. > > OK. I'll shut up now. Go Bears! > > David > > >> ---Brian Yamabe >> >> On Jan 21, 2007, at 12:53 PM, Jay Levitt wrote: >> >>> Francois Beausoleil wrote: >>> >>>> >>>> Adding #active_projects on User leads to a kind of namespace >>>> pollution, no ? Really, who knows what projects are active ? The >>>> Project class, or the User ? >>> >>> This seems to be a basic conflict between "Tell, don't ask" and >>> domain-driven design. DDD, as I understand it, says the Project >>> class >>> should encapsulate all knowledge about projects; TDA says we >>> shouldn't >>> ask for the project proxy. Yes? >>> >>> Jay >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Jan 21 18:51:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 17:51:19 -0600 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <45B3F3AA.1080606@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> <57c63afe0701211414t189c0df1md288cce6885c0a56@mail.gmail.com> <45B3F3AA.1080606@rubyforge.org> Message-ID: <57c63afe0701211551x783afc8am640c389785a55e81@mail.gmail.com> On 1/21/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > David Chelimsky wrote: > > TDA says we shouldn't even ask the User for its Projects. It's the Law > > of Demeter that says we shouldn't ask the User for it's Projects and > > THEN ask the Projects whether they are active. > > Oops, my bad, then! So is it my misunderstanding of domain-driven > design - especially the AGGREGATE pattern - or is TDA diametrically > opposed to DDD here? Can we get Alec Sharp and Eric Evans in a boxing ring? No - I think that's right. My read is that aggregate looks like the antithesis of LoD, BUT, there is an important distinction to be made. In DDD, the goal is ubiquitous language built around the business domain. If the business domain says that there are Leagues that have Conferences that have Teams that have Players, then those relationships are very unlikely to change, and therefore minimize the risks assoicated with LoD violations. The real problem w/ LoD is when you see stuff like: player = team.jersey_number_to_player_map[17] as opposed to player = team.find_player_by_jersey_number[17] Even though it's not obvious, the first is an LoD violation. Here are the same statements in java: player = team.getJerseyNumberToPlayerMap().get("17") as opposed to player = team.findPlayerByJerseyNumber("17") The fact that team stores players in a map is none of anybody's business. The fact that it stores players is arguably a domain concept that makes sense. Make sense? David > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jan 21 18:58:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Jan 2007 17:58:16 -0600 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <9DB465C9-119C-4577-8896-EDA12E744709@yamabe.net> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> <40DABC99-130D-48D8-946B-B82F9FD28D8F@yamabe.net> <57c63afe0701211423r5fde1438ib5ca73505391647d@mail.gmail.com> <9DB465C9-119C-4577-8896-EDA12E744709@yamabe.net> Message-ID: <57c63afe0701211558t2127490bw2f5146a4821ca5c1@mail.gmail.com> On 1/21/07, Brian Yamabe <brian at yamabe.net> wrote: > David, thanks for making me think. Back atcha. > If the bi-directional dependency > is needed, would it be cleaned up with a "has_many :through" (An > Assignment class as an example)? That happens to work in a lot of cases because rails supports it. But bear in mind that :through relationships weren't supported in 1.0. They came later because the problem of a particular type of relationship came up enough to do something about it in the framework. I'm sure that sooner or later you're going to come up w/ a model that isn't supported directly by rails, and then you need to think about all this stuff. <soapbox> Also, while this may be far from most people's minds, letting all of this AR goodness seep out past your model classes binds your application to AR. There are other persistence frameworks, like OG, that are promising. If you decided to give on a try, you'd have a much easier time if you encapsulate all of that goodness inside your models and expose methods that are framework neutral. Not saying that you shouldn't exploit AR goodness. Just that localizing the exploitation makes things more flexible in the long run. </soapbox> > > > def self.find_active_projects_for_user(user) > > return user.projects.active_projects > > end > > > > This bi-directional dependency seems problematic to me. I realize that > > rails makes it easy to do these, but again, just because its easy > > doesn't make it a good decision. > > > > This is one of those questions that can be enlightened by client need. > > Do clients of Projects ask for their users? Do clients of User ask for > > its Projects? If both answers are yes, then maybe the bi-directional > > deal makes sense. If only one is needed, then only one should be > > implemented. > > > > OK. I'll shut up now. Go Bears! > > > > David > > > > > >> ---Brian Yamabe > >> > >> On Jan 21, 2007, at 12:53 PM, Jay Levitt wrote: > >> > >>> Francois Beausoleil wrote: > >>> > >>>> > >>>> Adding #active_projects on User leads to a kind of namespace > >>>> pollution, no ? Really, who knows what projects are active ? The > >>>> Project class, or the User ? > >>> > >>> This seems to be a basic conflict between "Tell, don't ask" and > >>> domain-driven design. DDD, as I understand it, says the Project > >>> class > >>> should encapsulate all knowledge about projects; TDA says we > >>> shouldn't > >>> ask for the project proxy. Yes? > >>> > >>> Jay > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists-rspec at shopwatch.org Sun Jan 21 19:00:43 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 21 Jan 2007 19:00:43 -0500 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <57c63afe0701211551x783afc8am640c389785a55e81@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> <57c63afe0701211414t189c0df1md288cce6885c0a56@mail.gmail.com> <45B3F3AA.1080606@rubyforge.org> <57c63afe0701211551x783afc8am640c389785a55e81@mail.gmail.com> Message-ID: <45B3FEAB.9060201@rubyforge.org> David Chelimsky wrote: > The fact that team stores players in a map is none of anybody's > business. The fact that it stores players is arguably a domain concept > that makes sense. Great distinction... thanks. Jay From francois.beausoleil at gmail.com Mon Jan 22 09:46:36 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Mon, 22 Jan 2007 09:46:36 -0500 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <57c63afe0701211558t2127490bw2f5146a4821ca5c1@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> <40DABC99-130D-48D8-946B-B82F9FD28D8F@yamabe.net> <57c63afe0701211423r5fde1438ib5ca73505391647d@mail.gmail.com> <9DB465C9-119C-4577-8896-EDA12E744709@yamabe.net> <57c63afe0701211558t2127490bw2f5146a4821ca5c1@mail.gmail.com> Message-ID: <41d5fadf0701220646y119fcf73wf7ffd72307ba1e22@mail.gmail.com> Hi all, 2007/1/21, David Chelimsky <dchelimsky at gmail.com>: > <soapbox> > Also, while this may be far from most people's minds, letting all of > this AR goodness seep out past your model classes binds your > application to AR. There are other persistence frameworks, like OG, > that are promising. If you decided to give on a try, you'd have a much > easier time if you encapsulate all of that goodness inside your models > and expose methods that are framework neutral. > > Not saying that you shouldn't exploit AR goodness. Just that > localizing the exploitation makes things more flexible in the long > run. > </soapbox> So in essence, you are arguing for current_user.active_projects instead of anything else, right :) In my application, projects exist only in relationship to users. And users access projects through a Role. That wasn't relevant in the initial discussions, so I didn't speak about it. Thanks all ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From brian at yamabe.net Mon Jan 22 10:58:44 2007 From: brian at yamabe.net (Brian Yamabe) Date: Mon, 22 Jan 2007 07:58:44 -0800 Subject: [rspec-users] Collection proxies need to be stubbed ? In-Reply-To: <57c63afe0701211558t2127490bw2f5146a4821ca5c1@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701210337h27416165sebb7fa9f23743a50@mail.gmail.com> <41d5fadf0701211242n68928cedq36329b5f23c112d6@mail.gmail.com> <45B3D2D7.5050400@rubyforge.org> <40DABC99-130D-48D8-946B-B82F9FD28D8F@yamabe.net> <57c63afe0701211423r5fde1438ib5ca73505391647d@mail.gmail.com> <9DB465C9-119C-4577-8896-EDA12E744709@yamabe.net> <57c63afe0701211558t2127490bw2f5146a4821ca5c1@mail.gmail.com> Message-ID: <ADB43E3C-61CF-44F1-8897-012E54A8677E@yamabe.net> > I'm sure that sooner or later you're going to come up w/ a model that > isn't supported directly by rails, and then you need to think about > all this stuff. > > <soapbox> > Also, while this may be far from most people's minds, letting all of > this AR goodness seep out past your model classes binds your > application to AR. There are other persistence frameworks, like OG, > that are promising. If you decided to give on a try, you'd have a much > easier time if you encapsulate all of that goodness inside your models > and expose methods that are framework neutral. > > Not saying that you shouldn't exploit AR goodness. Just that > localizing the exploitation makes things more flexible in the long > run. > </soapbox> Even before I got your <soapbox/> I was thinking about what to do if this weren't using Rails. I still like the notion of an intermediary; a class that manages the relationship between Users and Projects. This would minimize any coupling between the User and Project classes and allow for a richer set of relationships to be tracked (inactive project members, inactive user projects, etc.). The intermediary class could either exploit the "AR goodness" or not. I could hear someone crying, "YAGNI," but the decoupling of User and Project is the main concern. The flexibility comes almost as a side effect. ---Brian Yamabe From francois.beausoleil at gmail.com Mon Jan 22 11:25:26 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Mon, 22 Jan 2007 11:25:26 -0500 Subject: [rspec-users] Observed models cause failures with DRBSpec ? Message-ID: <41d5fadf0701220825v266a97c5l4a02c99cbefb34b8@mail.gmail.com> Hi all ! I don't believe I am the only one using model observers, right ? Well, here's a nice one: $ drbspec spec . Finished in 0.125322 seconds 1 specification, 0 failures $ drbspec spec F 1) 'A user with an inactive and an active project should be able to return active projects only' FAILED [] should == [#<Spec::Mocks::Mock:0xb75590bc @name="active", @options={}>] ./spec/models/user_spec.rb:11: script/rails_spec_server:17:in `run' script/rails_spec_server:38: Finished in 0.024455 seconds 1 specification, 1 failure # spec/models/user_spec.rb require File.dirname(__FILE__) + "/../spec_helper" context "A user with an inactive and an active project" do setup do @user = User.new end specify "should be able to return active projects only" do @active = mock("active") Project.stub!(:active).and_return([@active]) @user.active_projects.should == [@active] end end # app/models/user.rb class User < ActiveRecord::Base has_many :projects, :foreign_key => "owner_id", :order => "projects.title" def active_projects(force=false) @active_projects = nil if force @active_projects ||= self.projects.active end end The observer is loaded in config/environment.rb like this: Rails::Initializer.run do |config| config.active_record.observers = :user_observer end There's nothing very interesting about this, except that if I comment the user observer in the configuration, I can run drbspec spec multiple times in a row without failures. If I add the observer, I can run drbspec without failures once, then I get failures like the one above for ever after. Can anyone confirm / deny this behavior ? Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From aslak.hellesoy at gmail.com Mon Jan 22 11:45:23 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 22 Jan 2007 17:45:23 +0100 Subject: [rspec-users] Observed models cause failures with DRBSpec ? In-Reply-To: <41d5fadf0701220825v266a97c5l4a02c99cbefb34b8@mail.gmail.com> References: <41d5fadf0701220825v266a97c5l4a02c99cbefb34b8@mail.gmail.com> Message-ID: <8d961d900701220845i7a6bc9e8v4516e12c87b37679@mail.gmail.com> On 1/22/07, Francois Beausoleil <francois.beausoleil at gmail.com> wrote: > Hi all ! > > I don't believe I am the only one using model observers, right ? > Well, here's a nice one: > > $ drbspec spec > > . > > Finished in 0.125322 seconds > > 1 specification, 0 failures > $ drbspec spec > > F > > 1) > 'A user with an inactive and an active project should be able to > return active projects only' FAILED > [] should == [#<Spec::Mocks::Mock:0xb75590bc @name="active", @options={}>] > ./spec/models/user_spec.rb:11: > script/rails_spec_server:17:in `run' > script/rails_spec_server:38: > > Finished in 0.024455 seconds > > 1 specification, 1 failure > > > > # spec/models/user_spec.rb > require File.dirname(__FILE__) + "/../spec_helper" > > context "A user with an inactive and an active project" do > setup do > @user = User.new > end > > specify "should be able to return active projects only" do > @active = mock("active") > Project.stub!(:active).and_return([@active]) > @user.active_projects.should == [@active] > end > end > > > # app/models/user.rb > class User < ActiveRecord::Base > has_many :projects, :foreign_key => "owner_id", :order => "projects.title" > > def active_projects(force=false) > @active_projects = nil if force > @active_projects ||= self.projects.active > end > end > > The observer is loaded in config/environment.rb like this: > Rails::Initializer.run do |config| > config.active_record.observers = :user_observer > end > > There's nothing very interesting about this, except that if I comment > the user observer in the configuration, I can run drbspec spec > multiple times in a row without failures. If I add the observer, I > can run drbspec without failures once, then I get failures like the > one above for ever after. > > Can anyone confirm / deny this behavior ? > I haven't tried to reproduce this, but it sounds like rails_spec_server is not reinitialising the rails environment properly. Essentially, we're trying to make rails_spec_server behave the same way as Rails in development mode - reload everything on each HTTP request. Take a peek inside rails_spec_server - perhaps we're not doing this correctly? If it works with Rails in development mode (can you check that please), it should work with rails_spec_server too. If you can confirm that reloading happens ok in dev mode (hitting with your browser), but not with rails_spec_server, then please submit a bug report, along with useful versions/revision numbers etc. By the way, drbspec will be replaced with spec --drb in the next RSpec release. Not much help, but maybe a nudge in the right direction for more debugging. Aslak > Thanks ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > http://piston.rubyforge.org/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Tue Jan 23 21:24:51 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 23 Jan 2007 19:24:51 -0700 Subject: [rspec-users] A spec where interaction-based testing breaks down... (at least for now) Message-ID: <810a540e0701231824w35211fd1sf75aaacbda9d4c4f@mail.gmail.com> Here are the specs: context "Finding all the stylesheets available to a company" do setup do @mock_company = mock("company") @mock_company.stub!(:to_param).and_return "1" Stylesheet.stub!(:find) end def do_find Stylesheet.find_available_to @mock_company end specify "should convert the company into a parameter" do @mock_company.should_receive(:to_param).and_return "1" do_find end specify "should find stylesheets belonging to only the company or to nobody" do Stylesheet.should_receive(:find).with(:all, :conditions => ["company_id IS NULL OR company_id=?", "1"]) do_find end end And here's the code: class Stylesheet < ActiveRecord::Base def self.find_available_to(company) find :all, :conditions => ["company_id IS NULL OR company_id=?", company.to_param] end end You can see that the implementation is duplicated. In fact, I wrote the implementation in the spec and then basically just copied it over. That bugs me. The obvious way to fix it would be to create a couple stylesheet entries in the database, run the query, and see if it matches the expected results. The only benefit of the current approach (that I can see) is that the behavior is explicit. If you've just got the results, you have to mentally link them to the query. Anyway I'm just sort of stuck on this one. I think there's a much better way that is evading me. Pat From dchelimsky at gmail.com Wed Jan 24 01:26:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 24 Jan 2007 00:26:19 -0600 Subject: [rspec-users] More on collection proxies In-Reply-To: <45B3F29E.1080009@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> Message-ID: <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> On 1/21/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > David Chelimsky wrote: > > On 1/21/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > >> I've got a question similar to Francois's. I'm writing a to-do-like > >> application, where each Task has a number of Events, consisting of > >> event.date and event.status. I want to see how long it's been since the > >> Task was last completed. So: > > [snip] > > >> This smells a bit. I could separate part of completed_days_ago into > >> last_completed_on(date), but no matter how I slice it I still end up > >> mocking Task.cells for some routine. Suggestions? > > > > The next question is, why are we passing in the date? We want to how > > many days have passed since it was completed, not how many days > > between completion and some arbitrary date. > > Actually, we want the latter - but of course you couldn't tell that from > my method name! The tasks are repeating, and this app fills in a > spreadsheet-like series of cells, one per day, with various colors, > depending on how often you're completing a task. So we actually need to > check the task's status on any given day. > > [..] > > event_stub = Struct.new(:date, > > :status).new(Time.parse("2001-02-03"), "completed") > > @task.stub!(:events).and_return([event_stub]) > [..] > > You don't mind stubbing the association proxy as a struct? That was my > real question; it seems to lead down a messy road of trying to stub > every ActiveRecord method. On the one hand, it seems like BDD says I > should stub or mock any object other than the one under test. On the > other, since I'm still in the models realm, maybe it's okay to use > fixtures to represent the model relations. Or maybe there's a third way. I'm kind of on the fence on this topic. I've been of the mindset that since models are so tightly bound to AR that it's more trouble than its worth to try and break that dependency. Because I mock models in all of my controller and view specs, I'm only hitting the db for the things that are interesting about models. Recently, I read a post from Jay Fields where he talks about what amounts to mocking out the loading of a file. So if you want to spec that User should validate presence of email, you do this: User.should_receive(:validates_presence_of).with(:email) load "${RAILS_ROOT}/app/models/user.rb" Odd, huh? It wouldn't be if the API for AR was like this: @model_registry.should_receive(:validate_presence_of).with(User, :email) User.register(@model_registry) Essentially, loading the file IS the entry point to the AR API. Interesting point of view, no? I like two things about this: clear specs fast specs I can write all my validation specs in two lines each. No models to create. No database to connect to. Pretty awesome. So, no, I don't mind mocking the proxy in model specs, though I would always try to avoid that seeping out to the controllers and views. That helpful? Cheers, David > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists-rspec at shopwatch.org Wed Jan 24 08:45:55 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Wed, 24 Jan 2007 08:45:55 -0500 Subject: [rspec-users] More on collection proxies In-Reply-To: <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> Message-ID: <45B76313.4000305@rubyforge.org> David Chelimsky wrote: > I'm kind of on the fence on this topic. I've been of the mindset that > since models are so tightly bound to AR that it's more trouble than > its worth to try and break that dependency. Because I mock models in > all of my controller and view specs, I'm only hitting the db for the > things that are interesting about models. I think I'm of the same mind; I just wanted to make sure I wasn't taking the easy way out. I was thinking... a great addition to rSpec someday - though a major project in its own right - might be a pre-stubbed version of ActiveRecord with fixtures. Then again, that might be just as complex as the real AR, and maybe the solution is to just use an in-memory database when testing. > > Recently, I read a post from Jay Fields where he talks about what > amounts to mocking out the loading of a file. So if you want to spec > that User should validate presence of email, you do this: > > User.should_receive(:validates_presence_of).with(:email) > load "${RAILS_ROOT}/app/models/user.rb" > > Odd, huh? It wouldn't be if the API for AR was like this: > > @model_registry.should_receive(:validate_presence_of).with(User, :email) > User.register(@model_registry) > > Essentially, loading the file IS the entry point to the AR API. > Interesting point of view, no? Wow - I never thought of it like that. I think (as a new convert to mocks) that type of mock is a little too specific and un-DRY for my taste, though; it feels like specifying that "line 6 of method foo should be an if statement". There's double-entry bookkeeping, and then there's keeping two sets of books. > So, no, I don't mind mocking the proxy in model specs, though I would > always try to avoid that seeping out to the controllers and views. > > That helpful? Very! From lists-rspec at shopwatch.org Wed Jan 24 09:08:10 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Wed, 24 Jan 2007 09:08:10 -0500 Subject: [rspec-users] More on collection proxies In-Reply-To: <45B76313.4000305@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B34DAA.7040004@e-tobi.net> <57c63afe0701210346v69792d9bgdca54afef008efc6@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> Message-ID: <45B7684A.7030404@rubyforge.org> Jay Levitt wrote: > David Chelimsky wrote: >> User.should_receive(:validates_presence_of).with(:email) > Wow - I never thought of it like that. I think (as a new convert to > mocks) that type of mock is a little too specific and un-DRY for my > taste, though; it feels like specifying that "line 6 of method foo > should be an if statement". There's double-entry bookkeeping, and then > there's keeping two sets of books. While I'm out on this limb, I'm gonna say that, given the way Rails validations are structured, it's better to use state-based testing than interaction-based testing! validates_presence_of is a bad example, because the two methods are practically interchangeable. But consider a validation that uses a regex to verify a legal IP address. Do you want your specs to repeat the regex, or do you want to test various legal and illegal IP-address strings and see what breaks? To me, it's the second one that's actually testing the behavior of the application. Jay From dchelimsky at gmail.com Wed Jan 24 10:15:07 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 24 Jan 2007 09:15:07 -0600 Subject: [rspec-users] More on collection proxies In-Reply-To: <45B7684A.7030404@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> <45B7684A.7030404@rubyforge.org> Message-ID: <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> On 1/24/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > Jay Levitt wrote: > > David Chelimsky wrote: > >> User.should_receive(:validates_presence_of).with(:email) > > Wow - I never thought of it like that. I think (as a new convert to > > mocks) that type of mock is a little too specific and un-DRY for my > > taste, though; it feels like specifying that "line 6 of method foo > > should be an if statement". There's double-entry bookkeeping, and then > > there's keeping two sets of books. > > While I'm out on this limb, I'm gonna say that, given the way Rails > validations are structured, it's better to use state-based testing than > interaction-based testing! > > validates_presence_of is a bad example, because the two methods are > practically interchangeable. But consider a validation that uses a > regex to verify a legal IP address. Do you want your specs to repeat > the regex, or do you want to test various legal and illegal IP-address > strings and see what breaks? To me, it's the second one that's actually > testing the behavior of the application. Another view would be that the Regexp is a separate component that you'd want to test separately from the use of that component. So the test that your model validates_format_of using a Regexp uses the right one and then have other tests just for that Regexp. WDYT? > > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists-rspec at shopwatch.org Wed Jan 24 10:54:18 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Wed, 24 Jan 2007 10:54:18 -0500 Subject: [rspec-users] More on collection proxies In-Reply-To: <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> <45B7684A.7030404@rubyforge.org> <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> Message-ID: <45B7812A.1090506@rubyforge.org> David Chelimsky wrote: > On 1/24/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: >> validates_presence_of is a bad example, because the two methods are >> practically interchangeable. But consider a validation that uses a >> regex to verify a legal IP address. Do you want your specs to repeat >> the regex, or do you want to test various legal and illegal IP-address >> strings and see what breaks? To me, it's the second one that's actually >> testing the behavior of the application. > > Another view would be that the Regexp is a separate component that > you'd want to test separately from the use of that component. So the > test that your model validates_format_of using a Regexp uses the right > one and then have other tests just for that Regexp. > > WDYT? Hmm.. I can see your argument, but I'm not convinced. Perhaps more experience will convince me :) Jay From dchelimsky at gmail.com Wed Jan 24 11:08:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 24 Jan 2007 10:08:52 -0600 Subject: [rspec-users] More on collection proxies In-Reply-To: <45B7812A.1090506@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> <45B7684A.7030404@rubyforge.org> <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> <45B7812A.1090506@rubyforge.org> Message-ID: <57c63afe0701240808q16fa0d3h59b48970ae6a559a@mail.gmail.com> On 1/24/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > David Chelimsky wrote: > > On 1/24/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > >> validates_presence_of is a bad example, because the two methods are > >> practically interchangeable. But consider a validation that uses a > >> regex to verify a legal IP address. Do you want your specs to repeat > >> the regex, or do you want to test various legal and illegal IP-address > >> strings and see what breaks? To me, it's the second one that's actually > >> testing the behavior of the application. > > > > Another view would be that the Regexp is a separate component that > > you'd want to test separately from the use of that component. So the > > test that your model validates_format_of using a Regexp uses the right > > one and then have other tests just for that Regexp. > > > > WDYT? > > Hmm.. I can see your argument, but I'm not convinced. Perhaps more > experience will convince me :) FWIW, I'm not convinced either. It was just an idea for the purpose of discussion. > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jodi at nnovation.ca Wed Jan 24 14:39:54 2007 From: jodi at nnovation.ca (Jodi Showers) Date: Wed, 24 Jan 2007 14:39:54 -0500 Subject: [rspec-users] hello! first post + context_setup Message-ID: <86659E25-EEAE-4B94-8FE7-9C126B004B86@nNovation.ca> Greetings all. I'm looking over a 'greenfield' pasture, and enjoying the TDD(BDD) process of creation. I'm currently rspec'ing a finite state machine (acts_as_state_machine). As such, I need to persist the model through 'specifies' within the context - from top to bottom. I have bumped into a couple of probs: 1. context_setup to define the doesn't permit access to fixtures. "You have a nil object when you didn't expect it!" 2. transactions are defined around each specify? For this reason my specifies are very repetitive, encompassing all state movement for all previous contexts. 3. since 2 seems to be the case, it probably doesn't matter - but is execution order guaranteed for specifiy's ? Thanx to the core team and contributors for rspec. The "diameter of my smile" is wide. Cheers, Jodi General Partner The nNovation Group inc. www.nnovation.ca/blog -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070124/f3e7c934/attachment.html From dchelimsky at gmail.com Wed Jan 24 15:03:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 24 Jan 2007 14:03:26 -0600 Subject: [rspec-users] hello! first post + context_setup In-Reply-To: <86659E25-EEAE-4B94-8FE7-9C126B004B86@nNovation.ca> References: <86659E25-EEAE-4B94-8FE7-9C126B004B86@nNovation.ca> Message-ID: <57c63afe0701241203n668a22e9ud82c8163eab3a532@mail.gmail.com> On 1/24/07, Jodi Showers <jodi at nnovation.ca> wrote: > > Greetings all. > I'm looking over a 'greenfield' pasture, and enjoying the TDD(BDD) process > of creation. > Consider yourself lucky!!! > I'm currently rspec'ing a finite state machine (acts_as_state_machine). As > such, I need to persist the model through 'specifies' within the context - > from top to bottom. > > I have bumped into a couple of probs: > 1. context_setup to define the doesn't permit access to fixtures. "You > have a nil object when you didn't expect it!" > Please submit a bug on this to the tracker: http://rubyforge.org/tracker/?group_id=797 2. transactions are defined around each specify? For this reason my > specifies are very repetitive, encompassing all state movement for all > previous contexts. > 3. since 2 seems to be the case, it probably doesn't matter - but > is execution order guaranteed for specifiy's ? > Order is not guaranteed as in a commitment from the RSpec team to keep it that way. We believe that each specify block should be completely independent from the next, so order should not be related. That said, the specify method generates a Specification object which is added to a Ruby Array held by the Context object (which is generated by the context method). Given that implementation, the specs will run in order. And it is HIGHLY unlikely that this would ever change. Depending on that, however, is a risk that you would have to understand and choose to take. Thinking about the particular problem at hand, imagine that we solved the transaction problem and allowed you to declare the entire context to be wrapped in a single transaction and guaranteed order. Now if spec 1 fails, you can't really trust the outcome of spec 2 (because it depends on state leftover from spec 1). This seems to me to be no different than having a single specify block that takes you through all the states. In fact, it strikes me as worse than the single spec block because you can't trust the other outcomes. So I'd recommend just writing one spec block. Thanx to the core team and contributors for rspec. The "diameter of my > smile" is wide. > Thanks for the feedback. David Cheers, > Jodi > General Partner > The nNovation Group inc. > www.nnovation.ca/blog > [image: ranting o the technology and business of software]<http://feeds.feedburner.com/on-innovation> > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070124/fd12f76e/attachment.html From aslak.hellesoy at gmail.com Wed Jan 24 16:47:49 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 24 Jan 2007 22:47:49 +0100 Subject: [rspec-users] A spec where interaction-based testing breaks down... (at least for now) In-Reply-To: <810a540e0701231824w35211fd1sf75aaacbda9d4c4f@mail.gmail.com> References: <810a540e0701231824w35211fd1sf75aaacbda9d4c4f@mail.gmail.com> Message-ID: <8d961d900701241347m79ed0a89waa59b1de77df8973@mail.gmail.com> On 1/24/07, Pat Maddox <pergesu at gmail.com> wrote: > Here are the specs: > context "Finding all the stylesheets available to a company" do > setup do > @mock_company = mock("company") > @mock_company.stub!(:to_param).and_return "1" > Stylesheet.stub!(:find) > end > > def do_find > Stylesheet.find_available_to @mock_company > end > > specify "should convert the company into a parameter" do > @mock_company.should_receive(:to_param).and_return "1" > do_find > end > > specify "should find stylesheets belonging to only the company or to > nobody" do > Stylesheet.should_receive(:find).with(:all, :conditions => > ["company_id IS NULL OR company_id=?", "1"]) > do_find > end > end > > And here's the code: > class Stylesheet < ActiveRecord::Base > def self.find_available_to(company) > find :all, :conditions => ["company_id IS NULL OR company_id=?", > company.to_param] > end > end > > You can see that the implementation is duplicated. In fact, I wrote > the implementation in the spec and then basically just copied it over. > > That bugs me. > > The obvious way to fix it would be to create a couple stylesheet > entries in the database, run the query, and see if it matches the > expected results. > > The only benefit of the current approach (that I can see) is that the > behavior is explicit. If you've just got the results, you have to > mentally link them to the query. > > Anyway I'm just sort of stuck on this one. I think there's a much > better way that is evading me. > I wouldn't use mocks for model specs. I'd test it against the real database. Aslak > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From listaccount at e-tobi.net Wed Jan 24 19:03:02 2007 From: listaccount at e-tobi.net (Tobias Grimm) Date: Thu, 25 Jan 2007 01:03:02 +0100 Subject: [rspec-users] mocking methods that receive blocks In-Reply-To: <45B2C0EC.1030609@e-tobi.net> References: <45B2C0EC.1030609@e-tobi.net> Message-ID: <45B7F3B6.80608@e-tobi.net> Hi! Maybe my last (but real life) example was too boring - what about this one? see end of mail or http://pastie.caboo.se/35443 So basically what I want to do, is mock a method that receives parameters and a block, but I still need to execute the passed block in order to test that it does what it is expected to do. With a different design, I could avoid this problem. Instead of passing blocks around I could e.g. use some kind of Strategy class. I was just wondering if this can be done somehow with RSpec's mocking capabilities. If not, maybe RSpec can be extended to make it possible. bye, Tobias Sorry, I hold no degree in Trek physics !!! :-) class Antimatter def stabilize end end class TransWarpEngine def TransWarpEngine.initiate(antimatter) create_quantum_singularity yield antimatter end end class BorgCube def travel_with_light_speed(antimatter) TransWarpEngine.initiate(antimatter) do |antimatter| antimatter.stabilize end end end context "The Borg Cube, when travelling with light speed" do setup do @borg_cube = BorgCube.new end specify "should initiate the TransWarpEngine with the given antimatter" do antimatter = mock(Antimatter) TransWarpEngine.should_receive(:initiate).with(antimatter) @borg_cube.travel_with_light_speed(antimatter) end specify "should tell the TransWarpEngine, that the antimatter should be stabilized" do antimatter = mock(Antimatter) antimatter.should_receive(:stabilize) # # Put in here the part, that I don't know how to do :-) # I must mock or stub TransWarpEngine.initiate(), because I can't risk # to create a quantum singularity when running RSpec. # But i also must test, that my little BorgCube receives the correct # instructions to stabilize the antimatter, otherwise my customer won't # be very happy, when she tries out the BorgCube the first time and it # simply detonates because of unstabilized antimatter. # @borg_cube.travel_with_light_speed(antimatter) end end From jodi at nnovation.ca Wed Jan 24 20:52:28 2007 From: jodi at nnovation.ca (Jodi Showers) Date: Wed, 24 Jan 2007 20:52:28 -0500 Subject: [rspec-users] hello! first post + context_setup In-Reply-To: <57c63afe0701241203n668a22e9ud82c8163eab3a532@mail.gmail.com> References: <86659E25-EEAE-4B94-8FE7-9C126B004B86@nNovation.ca> <57c63afe0701241203n668a22e9ud82c8163eab3a532@mail.gmail.com> Message-ID: <A52446E0-F3CD-4176-8022-2193A7012844@nNovation.ca> On 24-Jan-07, at 3:03 PM, David Chelimsky wrote: > I have bumped into a couple of probs: > 1. context_setup to define the doesn't permit access to fixtures. > "You have a nil object when you didn't expect it!" > > Please submit a bug on this to the tracker: > > http://rubyforge.org/tracker/?group_id=797 > > 2. transactions are defined around each specify? For this > reason my specifies are very repetitive, encompassing all state > movement for all previous contexts. > 3. since 2 seems to be the case, it probably doesn't matter > - but is execution order guaranteed for specifiy's ? > > Order is not guaranteed as in a commitment from the RSpec team to > keep it that way. We believe that each specify block should be > completely independent from the next, so order should not be related. > > That said, the specify method generates a Specification object > which is added to a Ruby Array held by the Context object (which is > generated by the context method). Given that implementation, the > specs will run in order. And it is HIGHLY unlikely that this would > ever change. Depending on that, however, is a risk that you would > have to understand and choose to take. > > Thinking about the particular problem at hand, imagine that we > solved the transaction problem and allowed you to declare the > entire context to be wrapped in a single transaction and guaranteed > order. Now if spec 1 fails, you can't really trust the outcome of > spec 2 (because it depends on state leftover from spec 1). This > seems to me to be no different than having a single specify block > that takes you through all the states. In fact, it strikes me as > worse than the single spec block because you can't trust the other > outcomes. > > So I'd recommend just writing one spec block. > I'm in agreement David. I'm facing a bunch of code duplication (that doesn't feel safe), so I'd perhaps I'll work out a means to iterate over the events and expected states. I'll file that bug tomorrow. Jodi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070124/19b46816/attachment-0001.html From listaccount at e-tobi.net Thu Jan 25 06:36:16 2007 From: listaccount at e-tobi.net (Tobi) Date: Thu, 25 Jan 2007 12:36:16 +0100 Subject: [rspec-users] mocking methods that receive blocks - back to mocking Thread again Message-ID: <45B89630.7000701@e-tobi.net> Hi again, my last example wasn't good either. It really makes only sense in the context of using Thread. I finally came up with this code, that should now test all important aspects of running a task in a background thread (to keep it simple, I left out the exception handling). see http://pastie.caboo.se/35559 or end of mail. It seems, TaskRunner is now very well covered by the specs - if you find a way to break TaskRunner without breaking the specs, please let me know. Unfortunately the specifications seem to be a little bit hard to read now. Any suggestions for improvements? bye, Tobias class TaskRunner def initialize @is_running = false end def running? return @is_running end def execute(task) @is_running = true Thread.new(task) do |myTask| myTask.run @is_running = false end end end context "The TaskRunner" do setup do @runner = TaskRunner.new @task = mock('SampleTask') @task.stub!(:run) Thread.stub!(:new) end specify "should not run a task in the main thread" do @task.should_not_receive(:run) @runner.execute(@task) end specify "should run a task in a new thread" do Thread.should_receive(:new).with(@task).and_yield(@task) @task.should_receive(:run) @runner.execute(@task) end specify "should be running while a task is beeing executed" do Thread.should_receive(:new).with(@task).and_yield(@task) @task.should_receive(:run) do @runner.should_be_running end @runner.execute(@task) end specify "should not be running after the task has been executed" do Thread.should_receive(:new).with(@task).and_return do |task, block| block.call(task) @runner.should_not_be_running end @runner.execute(@task) end end From papipo at gmail.com Thu Jan 25 08:30:02 2007 From: papipo at gmail.com (=?ISO-8859-1?Q?Rodrigo_Alvarez_Fern=E1ndez?=) Date: Thu, 25 Jan 2007 14:30:02 +0100 Subject: [rspec-users] Testing RJS select method Message-ID: <6d2bdda0701250530p5838e132mbf38afc9c6a5a113@mail.gmail.com> Hi How can I test this kind of RJS code? page.select '#id .class'.each do |element| element.removeClassName('whatever') end I know that should_have_rjs admits a block, but i don't know exactly which is its purpose. And I can test that the "select" part is beign called, but I don't know hot to test the "removeClassName" part. Thanks in advance. From yrashk at gmail.com Thu Jan 25 12:52:04 2007 From: yrashk at gmail.com (Yurii Rashkovskii) Date: Thu, 25 Jan 2007 19:52:04 +0200 Subject: [rspec-users] specify_negatively Message-ID: <9A9FE63F-3735-4595-9B7C-B20F1F4ECB93@gmail.com> Hello, I have played a bit on a negative specification idea: http://rashkovskii.com/articles/2007/1/25/rspec-specify_negatively What do you think about it? Yurii Rashkovskii Technology Director Railsware.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070125/12c4f473/attachment.html From martin.emde at gmail.com Thu Jan 25 15:02:42 2007 From: martin.emde at gmail.com (Martin Emde) Date: Thu, 25 Jan 2007 13:02:42 -0700 Subject: [rspec-users] A spec where interaction-based testing breaks down... (at least for now) In-Reply-To: <8d961d900701241347m79ed0a89waa59b1de77df8973@mail.gmail.com> References: <810a540e0701231824w35211fd1sf75aaacbda9d4c4f@mail.gmail.com> <8d961d900701241347m79ed0a89waa59b1de77df8973@mail.gmail.com> Message-ID: <145359ad0701251202w4f6a67fbuee039cf61e347914@mail.gmail.com> On 1/24/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote: > > On 1/24/07, Pat Maddox <pergesu at gmail.com> wrote: > > Here are the specs: > > context "Finding all the stylesheets available to a company" do > > setup do > > @mock_company = mock("company") > > @mock_company.stub!(:to_param).and_return "1" > > Stylesheet.stub!(:find) > > end > > > > def do_find > > Stylesheet.find_available_to @mock_company > > end > > > > specify "should convert the company into a parameter" do > > @mock_company.should_receive(:to_param).and_return "1" > > do_find > > end > > > > specify "should find stylesheets belonging to only the company or to > > nobody" do > > Stylesheet.should_receive(:find).with(:all, :conditions => > > ["company_id IS NULL OR company_id=?", "1"]) > > do_find > > end > > end > > > > And here's the code: > > class Stylesheet < ActiveRecord::Base > > def self.find_available_to(company) > > find :all, :conditions => ["company_id IS NULL OR company_id=?", > > company.to_param] > > end > > end > > > > You can see that the implementation is duplicated. In fact, I wrote > > the implementation in the spec and then basically just copied it over. > > > > That bugs me. > > > > The obvious way to fix it would be to create a couple stylesheet > > entries in the database, run the query, and see if it matches the > > expected results. > > > > The only benefit of the current approach (that I can see) is that the > > behavior is explicit. If you've just got the results, you have to > > mentally link them to the query. > > > > Anyway I'm just sort of stuck on this one. I think there's a much > > better way that is evading me. > > > > I wouldn't use mocks for model specs. I'd test it against the real > database. > > Aslak In addition to actually finding real records from the database for the Stylesheet model (don't stub find), I would also suggest that to_param is not the right method to use in this case. You're stating that company_id should equal the url formatted string for a company (which it is typical to overload to handle things like 10-name_of_company). Clearly your database naming says company.id so it's safer to just use company.id. -Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070125/32558d34/attachment.html From lists-rspec at shopwatch.org Fri Jan 26 15:04:07 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Fri, 26 Jan 2007 15:04:07 -0500 Subject: [rspec-users] More on collection proxies In-Reply-To: <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B35B67.2070402@e-tobi.net> <57c63afe0701210436v28002fcds4dd6aa945171b8b4@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> <45B7684A.7030404@rubyforge.org> <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> Message-ID: <45BA5EB7.9010508@rubyforge.org> David Chelimsky wrote: >> Jay Levitt wrote: >> >> validates_presence_of is a bad example, because the two methods are >> practically interchangeable. But consider a validation that uses a >> regex to verify a legal IP address. Do you want your specs to repeat >> the regex, or do you want to test various legal and illegal IP-address >> strings and see what breaks? To me, it's the second one that's actually >> testing the behavior of the application. > > Another view would be that the Regexp is a separate component that > you'd want to test separately from the use of that component. So the > test that your model validates_format_of using a Regexp uses the right > one and then have other tests just for that Regexp. I'd counter that the Regexp is essentially a private method that shouldn't be tested. It's never directly used by the outside world; only the validation is. Jay From mlangenberg at gmail.com Sat Jan 27 06:59:36 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Sat, 27 Jan 2007 12:59:36 +0100 Subject: [rspec-users] More on collection proxies In-Reply-To: <45BA5EB7.9010508@rubyforge.org> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B36382.2030503@e-tobi.net> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> <45B7684A.7030404@rubyforge.org> <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> <45BA5EB7.9010508@rubyforge.org> Message-ID: <27c0ac6d0701270359t5e57d9bh258d208e4bbc7664@mail.gmail.com> Why shouldn't private methods be tested? I use Object#send all the time to test private methods, otherwise I've got the idea the step to implement the spec is too big, for example look at the specs of my SMSer project (http://pastie.caboo.se/36044). On 1/26/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > David Chelimsky wrote: > >> Jay Levitt wrote: > >> > >> validates_presence_of is a bad example, because the two methods are > >> practically interchangeable. But consider a validation that uses a > >> regex to verify a legal IP address. Do you want your specs to repeat > >> the regex, or do you want to test various legal and illegal IP-address > >> strings and see what breaks? To me, it's the second one that's actually > >> testing the behavior of the application. > > > > Another view would be that the Regexp is a separate component that > > you'd want to test separately from the use of that component. So the > > test that your model validates_format_of using a Regexp uses the right > > one and then have other tests just for that Regexp. > > I'd counter that the Regexp is essentially a private method that > shouldn't be tested. It's never directly used by the outside world; > only the validation is. > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Jan 27 10:03:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 27 Jan 2007 09:03:18 -0600 Subject: [rspec-users] More on collection proxies In-Reply-To: <27c0ac6d0701270359t5e57d9bh258d208e4bbc7664@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B3D11F.90703@rubyforge.org> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> <45B7684A.7030404@rubyforge.org> <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> <45BA5EB7.9010508@rubyforge.org> <27c0ac6d0701270359t5e57d9bh258d208e4bbc7664@mail.gmail.com> Message-ID: <57c63afe0701270703q58b8af68n9c33f8856a122ff@mail.gmail.com> On 1/27/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > Why shouldn't private methods be tested? I use Object#send all the > time to test private methods, otherwise I've got the idea the step to > implement the spec is too big, for example look at the specs of my > SMSer project (http://pastie.caboo.se/36044). There is a school of thought that suggests that if you need to test privates that you're probably doing too much in the one class and you should consider breaking things out. Admittedly, this school of thought comes from static languages in which you have to go through crazy and error prone hoops in order to test privates. Since Ruby makes it so simple, it seems less harmful and risky. It should, however, be at least a red flag about your design. It should make you ask "why am I testing privates?". The questions I have are: What is the impact of extracting the error code? Does doing so change some other behaviour? Isn't it enough to spec "should raise an exception if the webservice returned an error"? Getting back to my earlier statement about breaking things out, you *could* (and I likely would) choose to make a new class SmsResponse that gets initialized with the xml response text and exposes :code and :message. Then you could eliminate the last two specs in your example and have a separate spec just for this new class: http://pastie.caboo.se/36071 The cost of this is an extra class. The benefit is good separation of concerns (parsing XML vs processing a logical response). Similarly, the product of :create_post_data must go somewhere, right? What effect does that have on behavior? If it simply gets stored, then you can mock out the storage to make sure it gets stored correctly. If it changes the behaviour of the SMSer, then you can have examples that show the different behaviours. All of this said, these principles exist because people have experienced pain from doing things. You may be absolutely fine w/ what you have. The risk that you run is that business rules about SMSer and the XML schema for the response change independently, and then you have two reasons to change the same class (violation of the Single Responsibility Principle), making it more prone to ripple effects. An other thing to consider is whether there are other parts of your system that have to parse the same XML. If that is the case, then its definitely to your benefit to break out an SmsResponse class. WDYT? David > > On 1/26/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > > David Chelimsky wrote: > > >> Jay Levitt wrote: > > >> > > >> validates_presence_of is a bad example, because the two methods are > > >> practically interchangeable. But consider a validation that uses a > > >> regex to verify a legal IP address. Do you want your specs to repeat > > >> the regex, or do you want to test various legal and illegal IP-address > > >> strings and see what breaks? To me, it's the second one that's actually > > >> testing the behavior of the application. > > > > > > Another view would be that the Regexp is a separate component that > > > you'd want to test separately from the use of that component. So the > > > test that your model validates_format_of using a Regexp uses the right > > > one and then have other tests just for that Regexp. > > > > I'd counter that the Regexp is essentially a private method that > > shouldn't be tested. It's never directly used by the outside world; > > only the validation is. > > > > Jay > > > > _______________________________________________ > > 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 cwdinfo at gmail.com Sat Jan 27 14:29:23 2007 From: cwdinfo at gmail.com (s.ross) Date: Sat, 27 Jan 2007 11:29:23 -0800 Subject: [rspec-users] should expectation syntax has changed Message-ID: <3EEEBBD1-B8EB-4BA4-8714-496052E39873@gmail.com> This is just a note in case anyone else is using the (I believe experimental) custom expectations. The custom expectation I had written used the custom 'met_by?' function, which now appears to have been replaced by the 'matches?' function to determine whether the expectation is met. Steve From dchelimsky at gmail.com Sat Jan 27 14:55:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 27 Jan 2007 13:55:19 -0600 Subject: [rspec-users] should expectation syntax has changed In-Reply-To: <3EEEBBD1-B8EB-4BA4-8714-496052E39873@gmail.com> References: <3EEEBBD1-B8EB-4BA4-8714-496052E39873@gmail.com> Message-ID: <57c63afe0701271155x4152e139t32d5891274b639e0@mail.gmail.com> To be clear, this ONLY applies to those of you using trunk and experimenting with an un-released feature supporting custom expectations. To those of you who are, it is now pretty much how it will be released, so if you use #matches?, failure_message and negative_failure_message you should be OK. Cheers, David On 1/27/07, s.ross <cwdinfo at gmail.com> wrote: > This is just a note in case anyone else is using the (I believe > experimental) custom expectations. > > The custom expectation I had written used the custom 'met_by?' > function, which now appears to have been replaced by the 'matches?' > function to determine whether the expectation is met. > > Steve > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From listaccount at e-tobi.net Sun Jan 28 19:58:00 2007 From: listaccount at e-tobi.net (Tobi) Date: Mon, 29 Jan 2007 01:58:00 +0100 Subject: [rspec-users] Bug in should_not_be - What else to use? Message-ID: <45BD4698.5000909@e-tobi.net> Hi! I just stumbled over a possible bug in 0.7.5.1: `1.should_not_be == 1` does not fail. I took a look into the code and figured out, that this is caused by Not.be() using :no_arg instead of :___no_arg. The expected argument of the method be() in Not is passed from should_not_be() with :___no_arg. Not.be() is marked with "Gone for 0.9", so I assume that "should_not_be ==" shouldn't be used at all, right? So what else to use, when testing of "==" is required? 1.should_not == 1 ...gives a "not so nice" failure message: "1 should not == 1 nil" - this would read nicer as "1 should not be == 1" Where is the "nil" in the failure message coming from anyway? I digged a little bit deeper into the sources and figured that out too: In the Not class, instead of passing the not expected value as the second argument to default_message, it gets appended to the message text, so the missing argument will then be added by default_message() as nil. I've already added a bug report. bye, Tobias From jchris at mfdz.com Sun Jan 28 20:47:41 2007 From: jchris at mfdz.com (Chris Anderson) Date: Sun, 28 Jan 2007 17:47:41 -0800 Subject: [rspec-users] Rails trunk breakages Message-ID: <e282921e0701281747o17445311s38e06112dcaef927@mail.gmail.com> Anyone else having an issue with route-generation in specs breaking as of Rails trunk r6062? When I run my specs at r6061, they all pass, and in 6062 I get a trace like this every time my controller generates a route: TypeError in 'Requesting /artists/1 using PUT should redirect to the artist' can't convert Fixnum into String (eval):19:in `artist_url' /Users/jchris/ruby/rails/grabbit/config/../app/controllers/artists_controller.rb:59:in `update' /Users/jchris/ruby/rails/grabbit/config/../app/controllers/artists_controller.rb:56:in `update' ./spec/controllers/artists_controller_spec.rb:267:in `do_update' ./spec/controllers/artists_controller_spec.rb:287: For now I'm just using Rails r6061, but I wonder if people using a new version of RSpec are not having trouble. For reference, I'm using RSpec and RSpec on Rails from trunk as of revision 1359. (Even more reference. I just took a five minute break and upgraded to RSpec 0.8.0 (r1440) and am having the same problem. Parallel Test::Unit tests aren't showing any signs of breakage. I've put this in the tracker, as well. http://rubyforge.org/tracker/?func=detail&aid=8238&group_id=797&atid=3149 Best, Chris -- Chris Anderson http://jchris.mfdz.com From dchelimsky at gmail.com Sun Jan 28 21:33:07 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 28 Jan 2007 20:33:07 -0600 Subject: [rspec-users] Bug in should_not_be - What else to use? In-Reply-To: <45BD4698.5000909@e-tobi.net> References: <45BD4698.5000909@e-tobi.net> Message-ID: <57c63afe0701281833t1f191696x77ee553b3a356cd3@mail.gmail.com> On 1/28/07, Tobi <listaccount at e-tobi.net> wrote: > Hi! > > I just stumbled over a possible bug in 0.7.5.1: > > `1.should_not_be == 1` does not fail. Try should_not == 1 > > I took a look into the code and figured out, that this is caused by > Not.be() using :no_arg instead of :___no_arg. The expected argument of > the method be() in Not is passed from should_not_be() with :___no_arg. > > Not.be() is marked with "Gone for 0.9", so I assume that "should_not_be > ==" shouldn't be used at all, right? So what else to use, when testing > of "==" is required? > > 1.should_not == 1 > > ...gives a "not so nice" failure message: "1 should not == 1 nil" - this > would read nicer as "1 should not be == 1" > > Where is the "nil" in the failure message coming from anyway? I digged a > little bit deeper into the sources and figured that out too: > > In the Not class, instead of passing the not expected value as the > second argument to default_message, it gets appended to the message text, > so the missing argument will then be added by default_message() as nil. > I've already added a bug report. > > bye, > > Tobias > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From francois.beausoleil at gmail.com Sun Jan 28 22:12:30 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Sun, 28 Jan 2007 22:12:30 -0500 Subject: [rspec-users] Cryptic error message when no controller_name Message-ID: <41d5fadf0701281912u2fd2e98bk868ef5f73b0c541e@mail.gmail.com> Hi ! In the following spec: context "A project owner" do specify "can assign roles to other users" do # ... end end I get the following cryptic error message: 1) NoMethodError in 'A project owner can assign roles to other users' undefined method `session=' for #<Object:0xb741bed4> /home/francois/src/smrty2/vendor/plugins/rspec_on_rails/lib/spec/rails/context/controller.rb:134:in `setup_extra' /home/francois/src/smrty2/vendor/plugins/rspec_on_rails/lib/spec/rails/functional_eval_context.rb:22:in `setup' /home/francois/src/smrty2/vendor/plugins/rspec_on_rails/lib/spec/rails/context/controller.rb:151:in `setup' Line 134 of controller.rb is: @controller.session = session We are probably only missing a check to ensure that @controller is somehow defined. Failing that should simply say "You forgot to define controller_name in your controller spec". This is on 0.7.5.1. Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From dchelimsky at gmail.com Sun Jan 28 22:15:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 28 Jan 2007 21:15:16 -0600 Subject: [rspec-users] Cryptic error message when no controller_name In-Reply-To: <41d5fadf0701281912u2fd2e98bk868ef5f73b0c541e@mail.gmail.com> References: <41d5fadf0701281912u2fd2e98bk868ef5f73b0c541e@mail.gmail.com> Message-ID: <57c63afe0701281915g12fdc81bybc30aa1b0862663a@mail.gmail.com> Please put this in the tracker: http://rubyforge.org/tracker/?group_id=797 Thanks, David On 1/28/07, Francois Beausoleil <francois.beausoleil at gmail.com> wrote: > Hi ! > > In the following spec: > > context "A project owner" do > specify "can assign roles to other users" do > # ... > end > end > > I get the following cryptic error message: > > 1) > NoMethodError in 'A project owner can assign roles to other users' > undefined method `session=' for #<Object:0xb741bed4> > /home/francois/src/smrty2/vendor/plugins/rspec_on_rails/lib/spec/rails/context/controller.rb:134:in > `setup_extra' > /home/francois/src/smrty2/vendor/plugins/rspec_on_rails/lib/spec/rails/functional_eval_context.rb:22:in > `setup' > /home/francois/src/smrty2/vendor/plugins/rspec_on_rails/lib/spec/rails/context/controller.rb:151:in > `setup' > > Line 134 of controller.rb is: > > @controller.session = session > > We are probably only missing a check to ensure that @controller is > somehow defined. Failing that should simply say "You forgot to define > controller_name in your controller spec". > > This is on 0.7.5.1. > > Thanks ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > http://piston.rubyforge.org/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From francois.beausoleil at gmail.com Sun Jan 28 22:27:11 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Sun, 28 Jan 2007 22:27:11 -0500 Subject: [rspec-users] Cryptic error message when no controller_name In-Reply-To: <57c63afe0701281915g12fdc81bybc30aa1b0862663a@mail.gmail.com> References: <41d5fadf0701281912u2fd2e98bk868ef5f73b0c541e@mail.gmail.com> <57c63afe0701281915g12fdc81bybc30aa1b0862663a@mail.gmail.com> Message-ID: <41d5fadf0701281927p1d8230cbkc3f85b31e3aba235@mail.gmail.com> Hi ! 2007/1/28, David Chelimsky <dchelimsky at gmail.com>: > Please put this in the tracker: > http://rubyforge.org/tracker/?group_id=797 Yes, of course. I'm so sorry not to have done that right at first. Here's the link: http://rubyforge.org/tracker/index.php?func=detail&aid=8240&group_id=797&atid=3149 Bye ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From francois.beausoleil at gmail.com Mon Jan 29 00:12:23 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Mon, 29 Jan 2007 00:12:23 -0500 Subject: [rspec-users] mock.with(Hash) expects an Array ? Message-ID: <41d5fadf0701282112hf4ad5dctf97d1dcfebd5fd52@mail.gmail.com> Hi all, I looked at the open issues on the bug tracker, but couldn't find anything related to this. I also searched the archives. And I can't believe someone didn't hit on this before. Here's my spec: context "A project owner" do controller_name :roles setup do controller.stub!(:current_user).and_return(@user = mock("user")) controller.stub!(:current_project).and_return(@project = mock("project")) @user.stub!(:role_on).and_return(Role.owner) end specify "can change the role of a user" do @project.should_receive(:roles).and_return(roles_proxy = mock("roles proxy")) roles_proxy.should_receive(:find).with("17").and_return(role = mock("role")) role.should_receive(:update_attributes!).with(:name => Role.developer).and_return(true) role.stub!(:name).and_return(Role.developer) post :update, :project_id => 41, :id => 17, :role => {:name => Role.developer} response.body.should == Role.developer end end And the failure: 'A project owner can change the role of a user' FAILED Mock 'role' expected :update_attributes! with ([:name, "developer"]) but received it with ({"name"=>"developer"}) (eval):3:in `update_attributes!' /home/francois/src/smrty2/config/../app/controllers/roles_controller.rb:11:in `update' ./spec/controllers/roles_spec.rb:35: Looks like the call to #with changed the Hash to an Array. Can anyone else confirm this ? This is on 0.7.5.1. Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From listaccount at e-tobi.net Mon Jan 29 04:41:01 2007 From: listaccount at e-tobi.net (Tobi) Date: Mon, 29 Jan 2007 10:41:01 +0100 Subject: [rspec-users] Bug in should_not_be - What else to use? In-Reply-To: <57c63afe0701281833t1f191696x77ee553b3a356cd3@mail.gmail.com> References: <45BD4698.5000909@e-tobi.net> <57c63afe0701281833t1f191696x77ee553b3a356cd3@mail.gmail.com> Message-ID: <45BDC12D.6000503@e-tobi.net> David Chelimsky wrote: > Try should_not == 1 > Ok. It just gives me a not so nice to read failure message: "1 should not == 1" compared to "1 should not be == 1" Maybe the "Gone for 0.9"-methods should print a deprecation warning in one of the next releases. Tobias From justnothing at tiscali.co.uk Mon Jan 29 04:30:13 2007 From: justnothing at tiscali.co.uk (David Green) Date: Mon, 29 Jan 2007 01:30:13 -0800 (PST) Subject: [rspec-users] rspec and cookies Message-ID: <8686339.post@talk.nabble.com> Hello can anyone tell me how to test cookies using rspec? specifically, I'd like to be able to set a cookie before a get/post request and also to test the cookies which have been set by a get/post request I know I can use cookies[:name] = 'value' to set a cookie but how would I set expiry information on such a cookie? when i try to pass a hash {:value => 'value', :expires => 3.days.from_now} the entire hash becomes the value of cookies[:name] thanks david -- View this message in context: http://www.nabble.com/rspec-and-cookies-tf3134883.html#a8686339 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Mon Jan 29 07:31:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 29 Jan 2007 06:31:36 -0600 Subject: [rspec-users] Bug in should_not_be - What else to use? In-Reply-To: <45BDC12D.6000503@e-tobi.net> References: <45BD4698.5000909@e-tobi.net> <57c63afe0701281833t1f191696x77ee553b3a356cd3@mail.gmail.com> <45BDC12D.6000503@e-tobi.net> Message-ID: <57c63afe0701290431o45ab86d4g93a21f6b3032d417@mail.gmail.com> On 1/29/07, Tobi <listaccount at e-tobi.net> wrote: > David Chelimsky wrote: > > Try should_not == 1 > > > > Ok. It just gives me a not so nice to read failure message: > > "1 should not == 1" compared to "1 should not be == 1" > > Maybe the "Gone for 0.9"-methods should print a deprecation warning in > one of the next releases. Already in the plan. It won't print warnings in 0.8.0, but it will be shortly thereafter, and well before the deprecated methods are removed. > > Tobias > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From francois.beausoleil at gmail.com Mon Jan 29 15:03:40 2007 From: francois.beausoleil at gmail.com (Francois Beausoleil) Date: Mon, 29 Jan 2007 15:03:40 -0500 Subject: [rspec-users] rspec and cookies In-Reply-To: <8686339.post@talk.nabble.com> References: <8686339.post@talk.nabble.com> Message-ID: <41d5fadf0701291203y6b4fb291l234a32000594ede2@mail.gmail.com> Hello David, 2007/1/29, David Green <justnothing at tiscali.co.uk>: > I know I can use cookies[:name] = 'value' to set a cookie but how would I > set expiry information on such a cookie? when i try to pass a hash {:value > => 'value', :expires => 3.days.from_now} the entire hash becomes the value > of cookies[:name] When the cookie comes back through the browser, it never has any expiration or options. The browser handles that information. That's why you can't set those options on the requesting side. When responding, however... that's another story. Hope that helps ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From deepak.jois at gmail.com Tue Jan 30 03:45:13 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Tue, 30 Jan 2007 16:45:13 +0800 Subject: [rspec-users] errors while testing resource controller using rpec Message-ID: <24dc07380701300045x6aa80fbx3fbd2bad9855a5e3@mail.gmail.com> I am testing a resource called venue in this piece of code (generated using script/rspec_resource) ==================== context "Requesting /venues using POST" do controller_name :venues setup do @mock_venue = mock('Venue') @mock_venue.stub!(:save).and_return(true) @mock_venue.stub!(:to_param).and_return(1) Venue.stub!(:new).and_return(@mock_venue) end def do_post post :create, :venue => {:name => 'Venue'} end specify "should create a new venue" do Venue.should_receive(:new).with({'name' => 'Venue'}).and_return(@mock_venue) do_post end end ========================== and the test fails as =============== TypeError in 'Requesting /venues using POST should create a new venue' can't convert Fixnum into String (eval):19:in `venue_url' /home/deepak/personalcode/worlds/config/../app/controllers/venues_controller.rb:43:in `create' /home/deepak/personalcode/worlds/config/../app/controllers/venues_controller.rb:40:in `create' ./spec/controllers/venues_controller_spec.rb:242:in `do_post' ./spec/controllers/venues_controller_spec.rb:247: ================ the relevant portion of the controller code is ================ # POST /venues # POST /venues.xml def create @venue = Venue.new(params[:venue]) respond_to do |format| if @venue.save flash[:notice] = 'Venue was successfully created.' format.html { redirect_to venue_url(@venue) } format.xml { head :created, :location => venue_url(@venue) } else format.html { render :action => "new" } format.xml { render :xml => @venue.errors.to_xml } end end end ============== however, If I change the mock stub to return a string, the spec passes fine. @mock_venue.stub!(:to_param).and_return("1") # note the string There is something happening in the generated code venue_url which I am not aware of, which is causing the test to fail on the mock object. Is this a bug in the generated code.. or am I doing something wrong? Thanks Deepak From deepak.jois at gmail.com Tue Jan 30 03:47:38 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Tue, 30 Jan 2007 16:47:38 +0800 Subject: [rspec-users] errors while testing resource controller using rpec In-Reply-To: <24dc07380701300045x6aa80fbx3fbd2bad9855a5e3@mail.gmail.com> References: <24dc07380701300045x6aa80fbx3fbd2bad9855a5e3@mail.gmail.com> Message-ID: <24dc07380701300047g6a3cc02cv491bec66fc08ad96@mail.gmail.com> On 1/30/07, Deepak Jois <deepak.jois at gmail.com> wrote: > > however, If I change the mock stub to return a string, the spec passes fine. > > @mock_venue.stub!(:to_param).and_return("1") # note the string > > There is something happening in the generated code venue_url which I > am not aware of, which is causing the test to fail on the mock object. According to http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001033 the to_param method sends a stringified ID. Hence this should be a bug. Thanks Deepak From dchelimsky at gmail.com Tue Jan 30 06:04:35 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Jan 2007 05:04:35 -0600 Subject: [rspec-users] errors while testing resource controller using rpec In-Reply-To: <24dc07380701300047g6a3cc02cv491bec66fc08ad96@mail.gmail.com> References: <24dc07380701300045x6aa80fbx3fbd2bad9855a5e3@mail.gmail.com> <24dc07380701300047g6a3cc02cv491bec66fc08ad96@mail.gmail.com> Message-ID: <57c63afe0701300304h687fbb1cg3cd34db2c2f6caf@mail.gmail.com> On 1/30/07, Deepak Jois <deepak.jois at gmail.com> wrote: > On 1/30/07, Deepak Jois <deepak.jois at gmail.com> wrote: > > > > however, If I change the mock stub to return a string, the spec passes fine. > > > > @mock_venue.stub!(:to_param).and_return("1") # note the string > > > > There is something happening in the generated code venue_url which I > > am not aware of, which is causing the test to fail on the mock object. > > According to http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001033 > > the to_param method sends a stringified ID. Hence this should be a bug. Hence you should report this to the rspec tracker: http://rspec.rubyforge.org/contribute.html http://rubyforge.org/mail/?group_id=797 Cheers, David > > Thanks > Deepak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From deepak.jois at gmail.com Tue Jan 30 06:20:48 2007 From: deepak.jois at gmail.com (Deepak Jois) Date: Tue, 30 Jan 2007 19:20:48 +0800 Subject: [rspec-users] errors while testing resource controller using rpec In-Reply-To: <57c63afe0701300304h687fbb1cg3cd34db2c2f6caf@mail.gmail.com> References: <24dc07380701300045x6aa80fbx3fbd2bad9855a5e3@mail.gmail.com> <24dc07380701300047g6a3cc02cv491bec66fc08ad96@mail.gmail.com> <57c63afe0701300304h687fbb1cg3cd34db2c2f6caf@mail.gmail.com> Message-ID: <24dc07380701300320le73cfb6r40cb89e3914dbf77@mail.gmail.com> On 1/30/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > Hence you should report this to the rspec tracker: > > http://rspec.rubyforge.org/contribute.html > http://rubyforge.org/mail/?group_id=797 > > Cheers, > David > And thus arises my meta-question :).. Since I am quote new to this, I dont know how to submit a patch for this with a spec As far as I can see, it is a VERY trivial patch which involves adding quotes around a number in the generator templates. Should I just go ahead and do that? Or is there a spec that I can actually write for such a trivial patch, Thanks Deepak From dchelimsky at gmail.com Tue Jan 30 06:33:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Jan 2007 05:33:26 -0600 Subject: [rspec-users] errors while testing resource controller using rpec In-Reply-To: <24dc07380701300320le73cfb6r40cb89e3914dbf77@mail.gmail.com> References: <24dc07380701300045x6aa80fbx3fbd2bad9855a5e3@mail.gmail.com> <24dc07380701300047g6a3cc02cv491bec66fc08ad96@mail.gmail.com> <57c63afe0701300304h687fbb1cg3cd34db2c2f6caf@mail.gmail.com> <24dc07380701300320le73cfb6r40cb89e3914dbf77@mail.gmail.com> Message-ID: <57c63afe0701300333u634b1f73m17b8337023cd011a@mail.gmail.com> On 1/30/07, Deepak Jois <deepak.jois at gmail.com> wrote: > On 1/30/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > Hence you should report this to the rspec tracker: > > > > http://rspec.rubyforge.org/contribute.html > > http://rubyforge.org/mail/?group_id=797 > > > > Cheers, > > David > > > > And thus arises my meta-question :).. Since I am quote new to this, I > dont know how to submit a patch for this with a spec > > As far as I can see, it is a VERY trivial patch which involves adding > quotes around a number in the generator templates. Should I just go > ahead and do that? Or is there a spec that I can actually write for > such a trivial patch, I'll put up better instructions re: patches in the next release of the docs. In the mean time, since you've diagnosed the problem what you've reported above would be just fine. Something along the lines of "mocking :to_param should return a Fixnum" as the title and then describe the situation. Go ahead and stick that in the Bugs tracker (rather than a patch). Cheers, David > > Thanks > Deepak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tils-rspec at tils.net Tue Jan 30 06:06:57 2007 From: tils-rspec at tils.net (Tilmann Singer) Date: Tue, 30 Jan 2007 12:06:57 +0100 Subject: [rspec-users] Emacs spec parsing? Message-ID: <20070130110657.GD25504@tils.net> Hi, Did anyone with better emacs lisp knowledge than me already come up with a function like spec-at-point which finds the specify and context declaration for the current cursor position and returns a string which can be used to be passed to the --spec option of the spec runner? Damn that would be useful ... I am currently using a function that runs spec --line with the current line number, the problem with this is however that 1.) the specification string is not shown again on the commandline if the spec passed, and 2.) the line number may change when editing the file, and re-running the previous spec commandline (with the very nice emacs command recompile) may hit a different spot. tia, Til From jchris at mfdz.com Tue Jan 30 12:24:59 2007 From: jchris at mfdz.com (Chris Anderson) Date: Tue, 30 Jan 2007 09:24:59 -0800 Subject: [rspec-users] errors while testing resource controller using rpec In-Reply-To: <57c63afe0701300333u634b1f73m17b8337023cd011a@mail.gmail.com> References: <24dc07380701300045x6aa80fbx3fbd2bad9855a5e3@mail.gmail.com> <24dc07380701300047g6a3cc02cv491bec66fc08ad96@mail.gmail.com> <57c63afe0701300304h687fbb1cg3cd34db2c2f6caf@mail.gmail.com> <24dc07380701300320le73cfb6r40cb89e3914dbf77@mail.gmail.com> <57c63afe0701300333u634b1f73m17b8337023cd011a@mail.gmail.com> Message-ID: <e282921e0701300924y76286f5ekf0ab7230453612b1@mail.gmail.com> I filed a ticket on this issue the other night. I didn't realize that to_param ought to return a string, so the bug does seem to be with the generated specs. But it is interesting to note that the issue does not affect Rails prior to rev 6062. I've invalidated my old ticket and submitted a patch that fixes the issue. Here it is: http://rubyforge.org/tracker/?func=detail&aid=8316&group_id=797&atid=3151 On 1/30/07, David Chelimsky <dchelimsky at gmail.com> wrote: > On 1/30/07, Deepak Jois <deepak.jois at gmail.com> wrote: > > On 1/30/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > Hence you should report this to the rspec tracker: > > > > > > http://rspec.rubyforge.org/contribute.html > > > http://rubyforge.org/mail/?group_id=797 > > > > > > Cheers, > > > David > > > > > > > And thus arises my meta-question :).. Since I am quote new to this, I > > dont know how to submit a patch for this with a spec > > > > As far as I can see, it is a VERY trivial patch which involves adding > > quotes around a number in the generator templates. Should I just go > > ahead and do that? Or is there a spec that I can actually write for > > such a trivial patch, > > I'll put up better instructions re: patches in the next release of the docs. > > In the mean time, since you've diagnosed the problem what you've > reported above would be just fine. Something along the lines of > "mocking :to_param should return a Fixnum" as the title and then > describe the situation. Go ahead and stick that in the Bugs tracker > (rather than a patch). > > Cheers, > David > > > > > Thanks > > Deepak > > _______________________________________________ > > 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 > -- Chris Anderson http://jchris.mfdz.com From jchris at mfdz.com Tue Jan 30 17:36:57 2007 From: jchris at mfdz.com (Chris Anderson) Date: Tue, 30 Jan 2007 14:36:57 -0800 Subject: [rspec-users] nil object in mocks Message-ID: <e282921e0701301436w4c102121yab19ad819e60e88@mail.gmail.com> RSpecrs, I've been running into some trouble lately when passing mock objects into rich views. Either I have to obscure my specs by stubbing every method the view would call on my object, or I have to resort to trickery like stubbing ActionController#render, which is also less than ideal. The solution I've some up with is a variant on the :null_object option that can be passed to the mock factory. Null objects return themselves from any unstubbed method call. The option I've added changes that return value to nil, which doesn't play so well with method chaining, but does work nicely in most views. The question for you all is: what should the syntax look like? We've considered a couple of options but found them lacking. They are m = mock('returns nil', :nil_object => true) m = mock('returns nil', :null_object => :returns_nil) Hopefully someone on the list can come up with something more compelling. Another idea that just came to me (funny how lunch break has that effect): m = mock('returns nil', :default => nil) could be useful like this also m = mock('returns 5', :default => 5) and if you allow the default value to be a lambda that takes the mock as an argument, you can make :null_object a special case: m = mock('returns self', :default => lambda{|m| m}) but now I'm just getting silly. -- Chris Anderson http://jchris.mfdz.com From snessnet at gmail.com Tue Jan 30 22:27:36 2007 From: snessnet at gmail.com (sness) Date: Tue, 30 Jan 2007 19:27:36 -0800 Subject: [rspec-users] rspec + CakePHP Message-ID: <7f7f86440701301927s2363a006u87a88c2141d95d85@mail.gmail.com> Hi, I am in a situation where I am going to have to rewrite a working Ruby on Rails application in CakePHP with PHP5. I have a whole bunch of specs written with rspec, and I was wondering if it would be possible to somehow use these specs to test the Models and Controllers that I am rewriting in CakePHP. I am going to be basically just exactly duplicating the Rails application, with identical class and method names in PHP. I know this is perverse, but is it possible? Thanks, sness. From cwdinfo at gmail.com Tue Jan 30 23:39:25 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 30 Jan 2007 20:39:25 -0800 Subject: [rspec-users] rspec + CakePHP In-Reply-To: <7f7f86440701301927s2363a006u87a88c2141d95d85@mail.gmail.com> References: <7f7f86440701301927s2363a006u87a88c2141d95d85@mail.gmail.com> Message-ID: <2C9E17A6-09C0-410E-9E95-D4DF80AF4206@gmail.com> I'll take a shot at answering this. rSpec doesn't passively observe the code under test, it actively interrogates it. So rSpec, which is written in Ruby will not be mappable into the PHP space. Consider this example: assigns[:person].first_name.should == 'bob' Here's a snippet of controller spec that is reaching into the controller and checking out the contents of @person. See why it won't work? Have a look at this: http://www.sitepoint.com/forums/showthread.php?t=439480 Still want to work in PHP? Maybe? On Jan 30, 2007, at 7:27 PM, sness wrote: > Hi, > > I am in a situation where I am going to have to rewrite a working Ruby > on Rails application in CakePHP with PHP5. I have a whole bunch of > specs written with rspec, and I was wondering if it would be possible > to somehow use these specs to test the Models and Controllers that I > am rewriting in CakePHP. I am going to be basically just exactly > duplicating the Rails application, with identical class and method > names in PHP. > > I know this is perverse, but is it possible? > > Thanks, > sness. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mlangenberg at gmail.com Wed Jan 31 03:20:22 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Wed, 31 Jan 2007 09:20:22 +0100 Subject: [rspec-users] rspec + CakePHP In-Reply-To: <2C9E17A6-09C0-410E-9E95-D4DF80AF4206@gmail.com> References: <7f7f86440701301927s2363a006u87a88c2141d95d85@mail.gmail.com> <2C9E17A6-09C0-410E-9E95-D4DF80AF4206@gmail.com> Message-ID: <27c0ac6d0701310020w3fe64911r7cdd8679f5ff0c70@mail.gmail.com> Why actually doing a rewrite of a RoR application? Performance? I bet there are other solutions. On 1/31/07, s.ross <cwdinfo at gmail.com> wrote: > I'll take a shot at answering this. rSpec doesn't passively observe > the code under test, it actively interrogates it. So rSpec, which is > written in Ruby will not be mappable into the PHP space. Consider > this example: > > assigns[:person].first_name.should == 'bob' > > Here's a snippet of controller spec that is reaching into the > controller and checking out the contents of @person. See why it won't > work? > > Have a look at this: > > http://www.sitepoint.com/forums/showthread.php?t=439480 > > Still want to work in PHP? > > Maybe? > > > On Jan 30, 2007, at 7:27 PM, sness wrote: > > > Hi, > > > > I am in a situation where I am going to have to rewrite a working Ruby > > on Rails application in CakePHP with PHP5. I have a whole bunch of > > specs written with rspec, and I was wondering if it would be possible > > to somehow use these specs to test the Models and Controllers that I > > am rewriting in CakePHP. I am going to be basically just exactly > > duplicating the Rails application, with identical class and method > > names in PHP. > > > > I know this is perverse, but is it possible? > > > > Thanks, > > sness. > > _______________________________________________ > > 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 mlangenberg at gmail.com Wed Jan 31 04:20:21 2007 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Wed, 31 Jan 2007 10:20:21 +0100 Subject: [rspec-users] More on collection proxies In-Reply-To: <57c63afe0701270703q58b8af68n9c33f8856a122ff@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <57c63afe0701211428w263a3bebr4c84d454fd31db0b@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> <45B7684A.7030404@rubyforge.org> <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> <45BA5EB7.9010508@rubyforge.org> <27c0ac6d0701270359t5e57d9bh258d208e4bbc7664@mail.gmail.com> <57c63afe0701270703q58b8af68n9c33f8856a122ff@mail.gmail.com> Message-ID: <27c0ac6d0701310120s2147c930o6441ef60efb752ea@mail.gmail.com> David, thanks for your reply. I've made some changes to my specs and code, but I'm still not really sure where I should move the private 'create_post_data' method, should there be a seperate class for that method to? Same question for the 'send_http_post_request' method, although I think it's a good idea to put that method in a different class / context, allowing me to write a sample webservice to assert the http post. This is currently my spec and code: http://pastie.caboo.se/36900 - Matthijs On 1/27/07, David Chelimsky <dchelimsky at gmail.com> wrote: > On 1/27/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > Why shouldn't private methods be tested? I use Object#send all the > > time to test private methods, otherwise I've got the idea the step to > > implement the spec is too big, for example look at the specs of my > > SMSer project (http://pastie.caboo.se/36044). > > There is a school of thought that suggests that if you need to test > privates that you're probably doing too much in the one class and you > should consider breaking things out. Admittedly, this school of > thought comes from static languages in which you have to go through > crazy and error prone hoops in order to test privates. Since Ruby > makes it so simple, it seems less harmful and risky. > > It should, however, be at least a red flag about your design. It > should make you ask "why am I testing privates?". > > The questions I have are: > > What is the impact of extracting the error code? > Does doing so change some other behaviour? > Isn't it enough to spec "should raise an exception if the webservice > returned an error"? > > Getting back to my earlier statement about breaking things out, you > *could* (and I likely would) choose to make a new class SmsResponse > that gets initialized with the xml response text and exposes :code and > :message. Then you could eliminate the last two specs in your example > and have a separate spec just for this new class: > http://pastie.caboo.se/36071 > > The cost of this is an extra class. The benefit is good separation of > concerns (parsing XML vs processing a logical response). > > Similarly, the product of :create_post_data must go somewhere, right? > What effect does that have on behavior? If it simply gets stored, then > you can mock out the storage to make sure it gets stored correctly. If > it changes the behaviour of the SMSer, then you can have examples that > show the different behaviours. > > All of this said, these principles exist because people have > experienced pain from doing things. You may be absolutely fine w/ what > you have. The risk that you run is that business rules about SMSer and > the XML schema for the response change independently, and then you > have two reasons to change the same class (violation of the Single > Responsibility Principle), making it more prone to ripple effects. > > An other thing to consider is whether there are other parts of your > system that have to parse the same XML. If that is the case, then its > definitely to your benefit to break out an SmsResponse class. > > WDYT? > > David > > > > > > > > On 1/26/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > > > David Chelimsky wrote: > > > >> Jay Levitt wrote: > > > >> > > > >> validates_presence_of is a bad example, because the two methods are > > > >> practically interchangeable. But consider a validation that uses a > > > >> regex to verify a legal IP address. Do you want your specs to repeat > > > >> the regex, or do you want to test various legal and illegal IP-address > > > >> strings and see what breaks? To me, it's the second one that's actually > > > >> testing the behavior of the application. > > > > > > > > Another view would be that the Regexp is a separate component that > > > > you'd want to test separately from the use of that component. So the > > > > test that your model validates_format_of using a Regexp uses the right > > > > one and then have other tests just for that Regexp. > > > > > > I'd counter that the Regexp is essentially a private method that > > > shouldn't be tested. It's never directly used by the outside world; > > > only the validation is. > > > > > > Jay > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jan 31 08:07:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 31 Jan 2007 07:07:26 -0600 Subject: [rspec-users] More on collection proxies In-Reply-To: <27c0ac6d0701310120s2147c930o6441ef60efb752ea@mail.gmail.com> References: <41d5fadf0701202045y208bdca0ub06dba767ad770c1@mail.gmail.com> <45B3F29E.1080009@rubyforge.org> <57c63afe0701232226u30653b12g6dad4e18a719ce9c@mail.gmail.com> <45B76313.4000305@rubyforge.org> <45B7684A.7030404@rubyforge.org> <57c63afe0701240715t47a30e3cs625624565dc6f583@mail.gmail.com> <45BA5EB7.9010508@rubyforge.org> <27c0ac6d0701270359t5e57d9bh258d208e4bbc7664@mail.gmail.com> <57c63afe0701270703q58b8af68n9c33f8856a122ff@mail.gmail.com> <27c0ac6d0701310120s2147c930o6441ef60efb752ea@mail.gmail.com> Message-ID: <57c63afe0701310507o494bac2cw14bad21dcac8a0c2@mail.gmail.com> On 1/31/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > David, thanks for your reply. I've made some changes to my specs and > code, but I'm still not really sure where I should move the private > 'create_post_data' method, should there be a seperate class for that > method to? > Same question for the 'send_http_post_request' method, although I > think it's a good idea to put that method in a different class / > context, allowing me to write a sample webservice to assert the http > post. > This is currently my spec and code: http://pastie.caboo.se/36900 This line is the perfect place to introduce a new class: @sms_response = SMSResponse.new(send_http_post_request(SERVICE_URI, create_post_data(dutch_mobile, msg))) How about this: @sms_response = SMSRequest.new(dutch_mobile, msg).post(SERVICE_URI) and then moving the creation of the SMSResponse to the SMSRequest? This applies TDA and separates things nicely. WDYT? > > - Matthijs > > On 1/27/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 1/27/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > Why shouldn't private methods be tested? I use Object#send all the > > > time to test private methods, otherwise I've got the idea the step to > > > implement the spec is too big, for example look at the specs of my > > > SMSer project (http://pastie.caboo.se/36044). > > > > There is a school of thought that suggests that if you need to test > > privates that you're probably doing too much in the one class and you > > should consider breaking things out. Admittedly, this school of > > thought comes from static languages in which you have to go through > > crazy and error prone hoops in order to test privates. Since Ruby > > makes it so simple, it seems less harmful and risky. > > > > It should, however, be at least a red flag about your design. It > > should make you ask "why am I testing privates?". > > > > The questions I have are: > > > > What is the impact of extracting the error code? > > Does doing so change some other behaviour? > > Isn't it enough to spec "should raise an exception if the webservice > > returned an error"? > > > > Getting back to my earlier statement about breaking things out, you > > *could* (and I likely would) choose to make a new class SmsResponse > > that gets initialized with the xml response text and exposes :code and > > :message. Then you could eliminate the last two specs in your example > > and have a separate spec just for this new class: > > http://pastie.caboo.se/36071 > > > > The cost of this is an extra class. The benefit is good separation of > > concerns (parsing XML vs processing a logical response). > > > > Similarly, the product of :create_post_data must go somewhere, right? > > What effect does that have on behavior? If it simply gets stored, then > > you can mock out the storage to make sure it gets stored correctly. If > > it changes the behaviour of the SMSer, then you can have examples that > > show the different behaviours. > > > > All of this said, these principles exist because people have > > experienced pain from doing things. You may be absolutely fine w/ what > > you have. The risk that you run is that business rules about SMSer and > > the XML schema for the response change independently, and then you > > have two reasons to change the same class (violation of the Single > > Responsibility Principle), making it more prone to ripple effects. > > > > An other thing to consider is whether there are other parts of your > > system that have to parse the same XML. If that is the case, then its > > definitely to your benefit to break out an SmsResponse class. > > > > WDYT? > > > > David > > > > > > > > > > > > > > On 1/26/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: > > > > David Chelimsky wrote: > > > > >> Jay Levitt wrote: > > > > >> > > > > >> validates_presence_of is a bad example, because the two methods are > > > > >> practically interchangeable. But consider a validation that uses a > > > > >> regex to verify a legal IP address. Do you want your specs to repeat > > > > >> the regex, or do you want to test various legal and illegal IP-address > > > > >> strings and see what breaks? To me, it's the second one that's actually > > > > >> testing the behavior of the application. > > > > > > > > > > Another view would be that the Regexp is a separate component that > > > > > you'd want to test separately from the use of that component. So the > > > > > test that your model validates_format_of using a Regexp uses the right > > > > > one and then have other tests just for that Regexp. > > > > > > > > I'd counter that the Regexp is essentially a private method that > > > > shouldn't be tested. It's never directly used by the outside world; > > > > only the validation is. > > > > > > > > Jay > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >