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