From brian.takita at gmail.com Sat Aug 1 00:41:45 2009 From: brian.takita at gmail.com (Brian Takita) Date: Fri, 31 Jul 2009 21:41:45 -0700 Subject: [rspec-users] Rspec api ideas, inspired by Cucumber In-Reply-To: <57c63afe0907310436paf00d0ex80bd60e7c07b502f@mail.gmail.com> References: <1d7ddd110907310011u146314c3k3be016b63f37786c@mail.gmail.com> <57c63afe0907310436paf00d0ex80bd60e7c07b502f@mail.gmail.com> Message-ID: <1d7ddd110907312141y52a5ac1cx6317bb5b574054a0@mail.gmail.com> On Fri, Jul 31, 2009 at 4:36 AM, David Chelimsky wrote: > On Fri, Jul 31, 2009 at 2:11 AM, Brian Takita wrote: >> I think I would like to stick primarily with Rspec, because I like >> working close to the code and being able to easily refactor things. >> I do like Cucumber's ability to easily define sequences of actions and >> custom plain text actions. >> >> Here are some api ideas I have to make those things better in rspec. >> http://gist.github.com/159123 >> >> WDYT? > > Very cool ideas. I'm not sure whether I'd want them in rspec proper, > but I do think that rspec should let you easily plug ideas like this > into its example lifecycle management. That idea has been brewing for > a while as part of rspec-2.0, but rspec-2.0 is back-burnered until > after the book is off to print - I need to stay focused. > > What you're proposing looks a lot like rbehave, which was the > precursor to Story Runner, and then Cucumber. Story Runner introduced > plain text scenarios, but still let you work in Ruby (like rbehave) if > you chose to. In rbehave, your example would look like > http://gist.github.com/159174 > > FIT's DoFixture does the same sort of alternating part of the method > with arguments. So you can write table rows like this: > > | can have | any | number of | arguments | between text | > > .. which get converted to method calls like this (pardon the camel case): > > canHaveNumberOfBetweenText('any','arguments') > > This actually dates back to smalltalk, which lets you make method > calls with something akin to keyword arguments like this: > > message canHave: 'any'; numberOf: 'arguments' These sort of apis almost always mirror the problem at hand more closely. > > It's more fluid than rbehave's name/arg structure, in which all of the > args have to be at the end, and I think its a powerful idea. The > lambda in the middle is a bit disconcerting. Maybe that bit would look > nicer in Ruby 1.9 :) I actually use lambdas quite a bit in my macro invocations because the code inside needs to be executed in the context of the Example. I like the idea of using L as the lambda method. I think its a convention that is worth having. > > Other thoughts? I'm very much in support of a strong and simple core object model in which a nice DSLish api can be built on top of. I think this would open up innovation in making good api's, since each implementer would not need to develop so much infrastructure. It would also be cool to bring the Cucumber and rspec world closer together. > > Cheers, > David Cheers, Brian > >> >> - 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 sfeley at gmail.com Sat Aug 1 14:10:17 2009 From: sfeley at gmail.com (Stephen Eley) Date: Sat, 1 Aug 2009 14:10:17 -0400 Subject: [rspec-users] Rspec api ideas, inspired by Cucumber In-Reply-To: <57c63afe0907310436paf00d0ex80bd60e7c07b502f@mail.gmail.com> References: <1d7ddd110907310011u146314c3k3be016b63f37786c@mail.gmail.com> <57c63afe0907310436paf00d0ex80bd60e7c07b502f@mail.gmail.com> Message-ID: <1fb4df0908011110y3b6451d7lee474e99f2b0b8b4@mail.gmail.com> On Fri, Jul 31, 2009 at 7:36 AM, David Chelimsky wrote: > > Other thoughts? Here's one I've been meaning to bring up for a while: porting Cucumber's FIT-like table functionality to RSpec. I don't use scenario outlines very much in Cucumber. I much prefer factories and keeping one clear narration per major execution path. To me, the real value of something like outline tables is to test edge cases: inputs x and y should produce output z, which can be either success or a distinct sort of failure. But testing edge cases in Cucumber feels a bit kludgy to me. I don't like having to look for flash messages to tell me what succeeded or failed. I would much rather test these cases at a finer-grained level in RSpec. Using the exact same table format as a set of values for an RSpec example group to iterate over makes all kinds of sense. That would be this year's Christmas wish for me. >8-> -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From gad.nut at gmail.com Mon Aug 3 05:00:07 2009 From: gad.nut at gmail.com (Railsmaniac) Date: Mon, 3 Aug 2009 02:00:07 -0700 (PDT) Subject: [rspec-users] Troubles building rspec gem locally: Message-ID: Can't build gem with rake gem command. Here's what i've got: nat-laptop:rspec railsmaniac$ rake gem (in /Users/railsmaniac/Projects/rspec) rake aborted! Don't know how to build task 'features/heckle/heckle.feature' (See full trace by running task with --trace) nat-laptop:rspec railsmaniac$ rake, rspec, heckle and cucumber are all installed as gems. What do i do wrong? From gad.nut at gmail.com Mon Aug 3 04:59:02 2009 From: gad.nut at gmail.com (Railsmaniac) Date: Mon, 3 Aug 2009 01:59:02 -0700 (PDT) Subject: [rspec-users] Troubles building rspec gem locally: Message-ID: <7366374a-9e30-49fa-b04d-1a1b6f42913a@a13g2000yqc.googlegroups.com> Can't build gem with rake gem command. Here's what i've got: nat-laptop:rspec railsmaniac$ rake gem (in /Users/railsmaniac/Projects/rspec) rake aborted! Don't know how to build task 'features/heckle/heckle.feature' (See full trace by running task with --trace) nat-laptop:rspec railsmaniac$ rake, rspec, heckle and cucumber are all installed as gems. What do i do wrong? From dchelimsky at gmail.com Mon Aug 3 05:54:16 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Aug 2009 04:54:16 -0500 Subject: [rspec-users] Troubles building rspec gem locally: In-Reply-To: <7366374a-9e30-49fa-b04d-1a1b6f42913a@a13g2000yqc.googlegroups.com> References: <7366374a-9e30-49fa-b04d-1a1b6f42913a@a13g2000yqc.googlegroups.com> Message-ID: <57c63afe0908030254t6edec28fk1f1e4de92dd12a27@mail.gmail.com> On Mon, Aug 3, 2009 at 3:59 AM, Railsmaniac wrote: > Can't build gem with rake gem command. Here's what i've got: > > nat-laptop:rspec railsmaniac$ rake gem > (in /Users/railsmaniac/Projects/rspec) > rake aborted! > Don't know how to build task 'features/heckle/heckle.feature' > > (See full trace by running task with --trace) > nat-laptop:rspec railsmaniac$ > > rake, rspec, heckle and cucumber are all installed as gems. > What do i do wrong? I had moved a couple of files around and forgot to update the manifest. I just pushed the fix. Try pulling and building again please. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From celoserpa at gmail.com Mon Aug 3 17:00:38 2009 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Mon, 3 Aug 2009 16:00:38 -0500 Subject: [rspec-users] Loading webrat when installed as a plugin Message-ID: <1e5bcefd0908031400x7d99b942pe2d668b40a0aedfa@mail.gmail.com> Hello list, When installing Webrat as a plugin, do I need to change the "require 'webrat'" to point to the absolute directory in which webrat is installed in the vendor/plugins folder or is there any implicit logic in the require that I am missing? I didn't find anything in the rSpec book about this (see In chapter 20, page 276, the book shows the "plugin approach" of bundling the libraries). Thanks, Marcelo. From gad.nut at gmail.com Tue Aug 4 05:02:23 2009 From: gad.nut at gmail.com (Railsmaniac) Date: Tue, 4 Aug 2009 02:02:23 -0700 (PDT) Subject: [rspec-users] Troubles building rspec gem locally: In-Reply-To: <57c63afe0908030254t6edec28fk1f1e4de92dd12a27@mail.gmail.com> References: <7366374a-9e30-49fa-b04d-1a1b6f42913a@a13g2000yqc.googlegroups.com> <57c63afe0908030254t6edec28fk1f1e4de92dd12a27@mail.gmail.com> Message-ID: <80b5d0a7-1979-4be4-a175-4ca15c469375@k1g2000yqf.googlegroups.com> It builds successfully. Will also test it on ruby 1.9. On Aug 3, 1:54?pm, David Chelimsky wrote: > On Mon, Aug 3, 2009 at 3:59 AM, Railsmaniac wrote: > > Can't build gem with rake gem command. Here's what i've got: > > > nat-laptop:rspec railsmaniac$ rake gem > > (in /Users/railsmaniac/Projects/rspec) > > rake aborted! > > Don't know how to build task 'features/heckle/heckle.feature' > > > (See full trace by running task with --trace) > > nat-laptop:rspec railsmaniac$ > > > rake, rspec, heckle and cucumber are all installed as gems. > > What do i do wrong? > > I had moved a couple of files around and forgot to update the > manifest. I just pushed the fix. Try pulling and building again > please. > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From brian at kendog.freeserve.co.uk Tue Aug 4 05:47:49 2009 From: brian at kendog.freeserve.co.uk (kendog) Date: Tue, 4 Aug 2009 02:47:49 -0700 (PDT) Subject: [rspec-users] A passing test that I expected be a fail - any suggestions please? Message-ID: <3adfa6b0-39f4-4815-a675-ec4ec0247dcc@e27g2000yqm.googlegroups.com> Just started to learn the basics of rspec. Before doing anything serious I wanted to get to know the set-up and commands to run tests. I'm pretty sure that is all OK now with respect to gems and my test environment. It will run the tests but it seems to get the wrong answer. I have a controller with a single action 'index'. I wanted to observe a failing test so I created a super-simple test as follows: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe Test4Controller do describe "responding to show" do it "show should be successful" do get :show response.should be_success end end end There is NO action called 'show' in my controller but the test passes successfully. On running the app the response code is 404 not 200. Could anyone please explain what's happening. From dchelimsky at gmail.com Tue Aug 4 09:13:07 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Aug 2009 08:13:07 -0500 Subject: [rspec-users] Loading webrat when installed as a plugin In-Reply-To: <1e5bcefd0908031400x7d99b942pe2d668b40a0aedfa@mail.gmail.com> References: <1e5bcefd0908031400x7d99b942pe2d668b40a0aedfa@mail.gmail.com> Message-ID: <57c63afe0908040613t58414066s490ffe07529d3997@mail.gmail.com> On Mon, Aug 3, 2009 at 4:00 PM, Marcelo de Moraes Serpa wrote: > Hello list, > > When installing Webrat as a plugin, do I need to change the "require > 'webrat'" to point to the absolute directory in which webrat is > installed in the vendor/plugins folder or is there any implicit logic > in the require that I am missing? Rails handles this for you implicitly. Are you having a problem? > I didn't find anything in the rSpec > book about this (see In chapter 20, page 276, the book shows the > "plugin approach" of bundling the libraries). > > Thanks, > > Marcelo. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Aug 4 09:17:54 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Aug 2009 08:17:54 -0500 Subject: [rspec-users] A passing test that I expected be a fail - any suggestions please? In-Reply-To: <3adfa6b0-39f4-4815-a675-ec4ec0247dcc@e27g2000yqm.googlegroups.com> References: <3adfa6b0-39f4-4815-a675-ec4ec0247dcc@e27g2000yqm.googlegroups.com> Message-ID: <57c63afe0908040617g683fe295t7c80c1ae60a682fe@mail.gmail.com> On Tue, Aug 4, 2009 at 4:47 AM, kendog wrote: > Just started to learn the basics of rspec. > Before doing anything serious I wanted to get to know the set-up and > commands to run tests. > I'm pretty sure that is all OK now with respect to gems and my test > environment. It will run the tests but it seems to get the wrong > answer. > > I have a controller with ?a single action 'index'. > > I wanted to observe a failing test so I created a super-simple test as > follows: > > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > > describe Test4Controller do > > describe "responding to show" do integrate_views > ?it "show should be successful" do > ? ? ?get :show > ? ? ?response.should be_success > ? ?end > ?end > end > > There is NO action called 'show' in my controller but the test passes > successfully. On running the app the response code is 404 not 200. > Could anyone please explain what's happening. You've hit a bug in rspec-rails when running in the default isolation mode. https://rspec.lighthouseapp.com/projects/5645/tickets/860-rspec-rails-swallows-missing-action This will be fixed for the next release, but in the mean time you'll get the expected behaviour if you add integrate_views at the top of the example group, as shown above. HTH, David From mds at half-deserted.net Tue Aug 4 12:32:18 2009 From: mds at half-deserted.net (Michele Stuart) Date: Tue, 4 Aug 2009 12:32:18 -0400 Subject: [rspec-users] render_template with a non-standard view name Message-ID: Hi, all. I am perplexed. The problem I'm having seems to be related to rendering a "non-standard" view. In our controllers, the 'new' and 'edit' actions share a template, as shown here. Controller: def new @location = Location.new respond_to do |format| format.html { render :template => 'locations/locations' } format.xml { render :xml => @location } end end def edit @location = Location.find(params[:id]) render :template => 'locations/locations' end def create @location = Location.new(params[:location]) respond_to do |format| if @location.save flash[:notice] = 'Location was successfully created.' format.html { redirect_to(@location) } format.xml { render :xml => @location, :status => :created, :location => @location } else format.html { render :action => "new" } format.xml { render :xml => @location.errors, :status => :unprocessable_entity } end end end def update @location = Location.find(params[:id]) respond_to do |format| if @location.update_attributes(params[:location]) flash[:notice] = 'Location was successfully updated.' format.html { redirect_to(@location) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @location.errors, :status => :unprocessable_entity } end end end In the controller spec, the 'new' and 'edit' actions work fine, but when I try to get the response back for the 'update' and 'create' actions, I get a failure. This works: it "should render new template" do get :new response.should render_template('locations/locations') end This fails: describe "with failed save" do def do_post @location.should_receive(:save).and_return(false) post :create, :location => {} end it "should re-render 'new'" do do_post response.should render_template('locations/locations') end end Error: 'LocationsController handling POST /cms/locations with failed save should re-render 'new'' FAILED expected "locations/locations", got "locations/new" ./spec/controllers/locations_controller_spec.rb:320: Any advice is appreciated. Thank you. - Michele From dchelimsky at gmail.com Tue Aug 4 12:34:32 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Aug 2009 11:34:32 -0500 Subject: [rspec-users] stubbing association methods in controller spec In-Reply-To: <1e82ef7d-557d-47d1-864f-b4a8aff90cad@y28g2000prd.googlegroups.com> References: <1e82ef7d-557d-47d1-864f-b4a8aff90cad@y28g2000prd.googlegroups.com> Message-ID: <57c63afe0908040934j1a5c755cp156052f1ff7c7535@mail.gmail.com> On Thu, Jul 30, 2009 at 6:13 PM, norm wrote: > I have two models: > ?Student has_many=>:grad_surveys > ? ?and > ?GradSurvey belongs_to=>:student > > I am testing the GradSurveysController#update method with > > ?it "should only allow update if the correct token is presented" do > ? ?@params = {:id=>"1", :token=>"ab56e1b47", :survey=>{}} > ? ?@mock_grad_survey = mock_model(GradSurvey) > ? ?GradSurvey.should_receive(:accepts_as_authorized).with(@params > [:id], at params[:token]).and_return(@mock_grad_survey) > ? ?put :update, @params > ? ?response.should render_template(:update) > ?end > > Inside the GradSurvey#accepts_as_authorized method is called the > GradSurvey#student method. The test above fails with the message: > ? ? ? ? Mock 'GradSurvey_1034' received unexpected message :student > with (no args) > > However I can make the test pass by adding the :student method to the > @mock_grad_survey object, so > ? ? ?@mock_grad_survey = mock_model(GradSurvey, :student=>mock_model > (Student)) > > Why is it necessary for me to explicitly add the #student method to > the mock GradSurvey model, it seems to me that it should come for free > as part of the defined association, no? What am I not understanding > here? > > thanks in advance for any light you are able to shed mock_model creates a test double - it's not a real GradSurvey. Try using stub_model instead: @grad_survey = stub_model(GradSurvey) This uses a real model instance that is modified to not talk to the database. HTH, David From dchelimsky at gmail.com Tue Aug 4 12:37:12 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Aug 2009 11:37:12 -0500 Subject: [rspec-users] render_template with a non-standard view name In-Reply-To: References: Message-ID: <57c63afe0908040937k7ef193eena34eb917c54f5655@mail.gmail.com> On Tue, Aug 4, 2009 at 11:32 AM, Michele Stuart wrote: > Hi, all. > > I am perplexed. The problem I'm having seems to be related to > rendering a "non-standard" view. In our controllers, the 'new' and > 'edit' actions share a template, as shown here. > > Controller: > > ?def new > ? ?@location = Location.new > > ? ?respond_to do |format| > ? ? ?format.html { render :template => 'locations/locations' } > ? ? ?format.xml ?{ render :xml => @location } > ? ?end > ?end > > ?def edit > ? ?@location = Location.find(params[:id]) > ? ?render :template => 'locations/locations' > ?end > > ?def create > ? ?@location = Location.new(params[:location]) > > ? ?respond_to do |format| > ? ? ?if @location.save > ? ? ? ?flash[:notice] = 'Location was successfully created.' > ? ? ? ?format.html { redirect_to(@location) } > ? ? ? ?format.xml ?{ render :xml => @location, :status => :created, > :location => @location } > ? ? ?else > ? ? ? ?format.html { render :action => "new" } > ? ? ? ?format.xml ?{ render :xml => @location.errors, :status => > :unprocessable_entity } > ? ? ?end > ? ?end > ?end > > ?def update > ? ?@location = Location.find(params[:id]) > > ? ?respond_to do |format| > ? ? ?if @location.update_attributes(params[:location]) > ? ? ? ?flash[:notice] = 'Location was successfully updated.' > ? ? ? ?format.html { redirect_to(@location) } > ? ? ? ?format.xml ?{ head :ok } > ? ? ?else > ? ? ? ?format.html { render :action => "edit" } > ? ? ? ?format.xml ?{ render :xml => @location.errors, :status => > :unprocessable_entity } > ? ? ?end > ? end > end > > In the controller spec, the 'new' and 'edit' actions work fine, but > when I try to get the response back for the 'update' and 'create' > actions, I get a failure. > > This works: > > ? ?it "should render new template" do > ? ? ?get :new > ? ? ?response.should render_template('locations/locations') > ? ?end > > This fails: > > ? ?describe "with failed save" do > > ? ? ?def do_post > ? ? ? ?@location.should_receive(:save).and_return(false) > ? ? ? ?post :create, :location => {} > ? ? ?end > > ? ? ?it "should re-render 'new'" do > ? ? ? ?do_post > ? ? ? ?response.should render_template('locations/locations') > ? ? ?end > > ? ?end > > > Error: > > 'LocationsController handling POST /cms/locations with failed save > should re-render 'new'' FAILED > expected "locations/locations", got "locations/new" > ./spec/controllers/locations_controller_spec.rb:320: > > > > Any advice is appreciated. Thank you. This is a bug. Please report it to http://rspec.lighthouseapp.com. You may be able to get this to pass in integration mode (add integrate_views to the top of the example group), but I'm not sure about that. Cheers, David > > - Michele > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mds at half-deserted.net Tue Aug 4 13:09:48 2009 From: mds at half-deserted.net (Michele Stuart) Date: Tue, 4 Aug 2009 13:09:48 -0400 Subject: [rspec-users] render_template with a non-standard view name In-Reply-To: <57c63afe0908040937k7ef193eena34eb917c54f5655@mail.gmail.com> References: <57c63afe0908040937k7ef193eena34eb917c54f5655@mail.gmail.com> Message-ID: Hi. No joy with integrate_views either, although the error does change. I discovered that the old new and and edit templates still existed. So, with integrate_views and with the new.html.erb file on the filesystem, we get this. 'LocationsController handling POST /cms/locations with failed save should re-render 'new'' FAILED expected "locations/locations", got "/Users/mstuart2/Sites/cms/trunk/app/views/locations/new.html.erb" ./spec/controllers/locations_controller_spec.rb:333: With integrate_views, but deleting the new.html.erb file, we get this. TypeError in 'LocationsController handling POST /cms/locations with failed save should re-render 'new'' can't dup FalseClass Is this something I should report as well, or is this all known already? Thank you! On Tue, Aug 4, 2009 at 12:37 PM, David Chelimsky wrote: > On Tue, Aug 4, 2009 at 11:32 AM, Michele Stuart wrote: >> Hi, all. >> >> I am perplexed. The problem I'm having seems to be related to >> rendering a "non-standard" view. In our controllers, the 'new' and >> 'edit' actions share a template, as shown here. >> >> Controller: >> >> ?def new >> ? ?@location = Location.new >> >> ? ?respond_to do |format| >> ? ? ?format.html { render :template => 'locations/locations' } >> ? ? ?format.xml ?{ render :xml => @location } >> ? ?end >> ?end >> >> ?def edit >> ? ?@location = Location.find(params[:id]) >> ? ?render :template => 'locations/locations' >> ?end >> >> ?def create >> ? ?@location = Location.new(params[:location]) >> >> ? ?respond_to do |format| >> ? ? ?if @location.save >> ? ? ? ?flash[:notice] = 'Location was successfully created.' >> ? ? ? ?format.html { redirect_to(@location) } >> ? ? ? ?format.xml ?{ render :xml => @location, :status => :created, >> :location => @location } >> ? ? ?else >> ? ? ? ?format.html { render :action => "new" } >> ? ? ? ?format.xml ?{ render :xml => @location.errors, :status => >> :unprocessable_entity } >> ? ? ?end >> ? ?end >> ?end >> >> ?def update >> ? ?@location = Location.find(params[:id]) >> >> ? ?respond_to do |format| >> ? ? ?if @location.update_attributes(params[:location]) >> ? ? ? ?flash[:notice] = 'Location was successfully updated.' >> ? ? ? ?format.html { redirect_to(@location) } >> ? ? ? ?format.xml ?{ head :ok } >> ? ? ?else >> ? ? ? ?format.html { render :action => "edit" } >> ? ? ? ?format.xml ?{ render :xml => @location.errors, :status => >> :unprocessable_entity } >> ? ? ?end >> ? end >> end >> >> In the controller spec, the 'new' and 'edit' actions work fine, but >> when I try to get the response back for the 'update' and 'create' >> actions, I get a failure. >> >> This works: >> >> ? ?it "should render new template" do >> ? ? ?get :new >> ? ? ?response.should render_template('locations/locations') >> ? ?end >> >> This fails: >> >> ? ?describe "with failed save" do >> >> ? ? ?def do_post >> ? ? ? ?@location.should_receive(:save).and_return(false) >> ? ? ? ?post :create, :location => {} >> ? ? ?end >> >> ? ? ?it "should re-render 'new'" do >> ? ? ? ?do_post >> ? ? ? ?response.should render_template('locations/locations') >> ? ? ?end >> >> ? ?end >> >> >> Error: >> >> 'LocationsController handling POST /cms/locations with failed save >> should re-render 'new'' FAILED >> expected "locations/locations", got "locations/new" >> ./spec/controllers/locations_controller_spec.rb:320: >> >> >> >> Any advice is appreciated. Thank you. > > This is a bug. Please report it to http://rspec.lighthouseapp.com. > > You may be able to get this to pass in integration mode (add > integrate_views to the top of the example group), but I'm not sure > about that. > > Cheers, > David > >> >> - Michele >> _______________________________________________ >> 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 codehacker at comcast.net Tue Aug 4 13:44:57 2009 From: codehacker at comcast.net (norm) Date: Tue, 4 Aug 2009 10:44:57 -0700 (PDT) Subject: [rspec-users] stubbing association methods in controller spec In-Reply-To: <57c63afe0908040934j1a5c755cp156052f1ff7c7535@mail.gmail.com> References: <1e82ef7d-557d-47d1-864f-b4a8aff90cad@y28g2000prd.googlegroups.com> <57c63afe0908040934j1a5c755cp156052f1ff7c7535@mail.gmail.com> Message-ID: that worked! thanks David, your help is much appreciated From celoserpa at gmail.com Tue Aug 4 17:09:13 2009 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Tue, 4 Aug 2009 16:09:13 -0500 Subject: [rspec-users] Loading webrat when installed as a plugin In-Reply-To: <57c63afe0908040613t58414066s490ffe07529d3997@mail.gmail.com> References: <1e5bcefd0908031400x7d99b942pe2d668b40a0aedfa@mail.gmail.com> <57c63afe0908040613t58414066s490ffe07529d3997@mail.gmail.com> Message-ID: <1e5bcefd0908041409y27a49e16s7f566fface5ea330@mail.gmail.com> David, thanks for the reply! > Rails handles this for you implicitly. Are you having a problem? Yes. I don't have Cucumber, rspec, rspec-rails nor webrat installed as gems system-wide. I only have them as plugins in the app. When I try to run a sample feature with script/cucumber, I get the following output: >$ script/cucumber vendor/plugins/cucumber/examples/selenium >no such file to load -- spec/expectations >Failed to load vendor/plugins/cucumber/examples/selenium/features/support/env.rb (LoadError) >/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' >/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `polyglot_original_require' >/usr/lib/ruby/gems/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54:in `require' >./vendor/plugins/cucumber/examples/selenium/features/support/env.rb:1 >/>usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' >/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `polyglot_original_require' >/usr/lib/ruby/gems/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54:in `require' >/home/marcelo/projetos/creative-allies-dev/trunk/ruby/vendor/plugins/cucumber/bin/../lib/cucumber/cli/main.rb:99:in `require_files' >/home/marcelo/projetos/creative-allies-dev/trunk/ruby/vendor/plugins/cucumber/bin/../lib/cucumber/cli/main.rb:108:in `each_lib' >/home/marcelo/projetos/creative-allies-dev/trunk/ruby/vendor/plugins/cucumber/bin/../lib/cucumber/cli/main.rb:106:in `each' >/home/marcelo/projetos/creative-allies-dev/trunk/ruby/vendor/plugins/cucumber/bin/../lib/cucumber/cli/main.rb:106:in `each_lib' >/home/marcelo/projetos/creative-allies-dev/trunk/ruby/vendor/plugins/cucumber/bin/../lib/cucumber/cli/main.rb:99:in `require_files' >/home/marcelo/projetos/creative-allies-dev/trunk/ruby/vendor/plugins/cucumber/bin/../lib/cucumber/cli/main.rb:53:in `execute!' >/home/marcelo/projetos/creative-allies-dev/trunk/ruby/vendor/plugins/cucumber/bin/../lib/cucumber/cli/main.rb:26:in `execute' >/home/marcelo/projetos/creative-allies-dev/trunk/ruby/vendor/plugins/cucumber/bin/cucumber:9 >script/cucumber:3:in `load' >script/cucumber:3 I mean, having these libraries self-contained in the app is the whole idea of installing them as plugins. However, script/cucumber is still trying to find system-wide gems. Any ideas? Thanks, Marcelo. On Tue, Aug 4, 2009 at 8:13 AM, David Chelimsky wrote: > On Mon, Aug 3, 2009 at 4:00 PM, Marcelo de Moraes > Serpa wrote: >> Hello list, >> >> When installing Webrat as a plugin, do I need to change the "require >> 'webrat'" to point to the absolute directory in which webrat is >> installed in the vendor/plugins folder or is there any implicit logic >> in the require that I am missing? > > Rails handles this for you implicitly. Are you having a problem? > >> I didn't find anything in the rSpec >> book about this (see In chapter 20, page 276, the book shows the >> "plugin approach" of bundling the libraries). >> >> Thanks, >> >> Marcelo. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Aug 6 07:48:43 2009 From: lists at ruby-forum.com (Gerard Leijdekkers) Date: Thu, 6 Aug 2009 13:48:43 +0200 Subject: [rspec-users] concerned_with, and maybe require_dependency issues only In-Reply-To: References: Message-ID: <0b302e7772cb1edc6681c4e00f5966e6@ruby-forum.com> We are having the same issue. It works fine when config.cache_classes is on. but when its turned off stuff breaks. The extra files are no longer parsed. concerned_with seems to have an issue with eager loading. Right now we're looking at alternatives. -- Posted via http://www.ruby-forum.com/. From sfalvo at ning.com Thu Aug 6 16:56:51 2009 From: sfalvo at ning.com (Sam Falvo) Date: Thu, 06 Aug 2009 13:56:51 -0700 Subject: [rspec-users] Rspec anomalous behavior Message-ID: I hope nobody takes this message too curtly -- I'm just trying to be as brief, and yet as informative, as possible, as per the guidelines on the RSpec contact website. Can anyone assist? Thanks! ### Problem: Potential bug in RSpec. nil#should always passes the test. It should succeed if, and only if, its boolean expression is true, as it would for any other expression. To reproduce, please find multiplexed in this message the following components: * phased_version_spec.rb file contents * phased_version.rb file contents * RSpec version * Command executed to reproduce the error * Generated output. * Expectations. * Gem listing. ### In file phased_version_spec.rb: #!/usr/bin/env spec require 'phased_version' module M describe M::PhasedVersion, "freshly created" do before(:each) do @v = M::PhasedVersion.new end it "should parse a phase" do @v.parse_string("6.16.7-pre") (@v.phase).should.eql? "pre" # HUH? # (@v.phase = nil) implies ((@v.phase).should.eql? "pre") = (nil.should.eql? "pre") implies (this should fail the test!) end end end ### In file phased_version.rb: #!/usr/bin/env ruby module M class PhasedVersion def parse_string aString @str = aString end attr_reader :phase def initialize @str = nil @phase = nil end end End ### RSpec Version: 1.2.7 ### Command: spec phased_version_spec.rb ### No errors generated; indeed, this is the problem! ### Output: . Finished in 0.010082 seconds 1 example, 0 failures ### Expected: F (diagnostic here) Finished in ... Seconds 1 example, 1 failures ### gem listing *** LOCAL GEMS *** actionmailer (1.3.6) actionpack (1.13.6) actionwebservice (1.2.6) activerecord (1.15.6) activesupport (1.4.4) acts_as_ferret (0.4.1) capistrano (2.0.0) cgi_multipart_eof_fix (2.5.0) daemons (1.0.9) dnssd (0.6.0) fastthread (1.0.1) fcgi (0.8.7) ferret (0.11.4) gem_plugin (0.2.3) highline (1.2.9) hpricot (0.6) libxml-ruby (0.9.5, 0.3.8.4) mongrel (1.1.4) needle (1.3.0) net-sftp (1.1.0) net-ssh (1.1.2) rails (1.2.6) rake (0.8.7, 0.7.3) RedCloth (3.0.4) rspec (1.2.7) ruby-openid (1.1.4) ruby-yadis (0.3.4) rubyforge (1.0.3) rubygems-update (1.3.4) rubynode (0.1.3) sqlite3-ruby (1.2.1) systemu (1.2.0) term-ansicolor (1.0.3) termios (0.9.4) From dchelimsky at gmail.com Thu Aug 6 17:34:54 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Aug 2009 16:34:54 -0500 Subject: [rspec-users] Rspec anomalous behavior In-Reply-To: References: Message-ID: <57c63afe0908061434x54a2b9e2q5182983eaa209b07@mail.gmail.com> On Thu, Aug 6, 2009 at 3:56 PM, Sam Falvo wrote: > I hope nobody takes this message too curtly -- I'm just trying to be as > brief, and yet as informative, as possible, as per the guidelines on the > RSpec contact website. > > Can anyone assist? ?Thanks! > > ### Problem: > > Potential bug in RSpec. ?nil#should always passes the test. ?It should > succeed if, and only if, its boolean expression is true, as it would for any > other expression. > > To reproduce, please find multiplexed in this message the following > components: > > * phased_version_spec.rb file contents > * phased_version.rb file contents > * RSpec version > * Command executed to reproduce the error > * Generated output. > * Expectations. > * Gem listing. > > > ### In file phased_version_spec.rb: > > #!/usr/bin/env spec > > require 'phased_version' > > module M > ? ?describe M::PhasedVersion, "freshly created" do > ? ? ? ?before(:each) do > ? ? ? ? ? ?@v = M::PhasedVersion.new > ? ? ? ?end > > ? ? ? ?it "should parse a phase" do > ? ? ? ? ? ?@v.parse_string("6.16.7-pre") > ? ? ? ? ? ?(@v.phase).should.eql? "pre" This needs to read: (@v.phase).should eql("pre") What you have does not set any expectation, therefore there is nothing to fail. HTH, David > ? ? ? ? ? ?# HUH? > ? ? ? ? ? ?# (@v.phase = nil) implies ((@v.phase).should.eql? "pre") = > (nil.should.eql? "pre") implies (this should fail the test!) > ? ? ? ?end > ? ?end > end > > ### In file phased_version.rb: > > #!/usr/bin/env ruby > > module M > ? ?class PhasedVersion > ? ? ? ?def parse_string aString > ? ? ? ? ? ?@str = aString > ? ? ? ?end > > ? ? ? ?attr_reader :phase > > ? ? ? ?def initialize > ? ? ? ? ? ?@str = nil > ? ? ? ? ? ?@phase = nil > ? ? ? ?end > ? ?end > End > > ### RSpec Version: 1.2.7 > > ### Command: spec phased_version_spec.rb > > ### No errors generated; indeed, this is the problem! > > ### Output: > . > > Finished in 0.010082 seconds > > 1 example, 0 failures > > > ### Expected: > F > (diagnostic here) > > Finished in ... Seconds > 1 example, 1 failures > > > ### gem listing > *** LOCAL GEMS *** > > actionmailer (1.3.6) > actionpack (1.13.6) > actionwebservice (1.2.6) > activerecord (1.15.6) > activesupport (1.4.4) > acts_as_ferret (0.4.1) > capistrano (2.0.0) > cgi_multipart_eof_fix (2.5.0) > daemons (1.0.9) > dnssd (0.6.0) > fastthread (1.0.1) > fcgi (0.8.7) > ferret (0.11.4) > gem_plugin (0.2.3) > highline (1.2.9) > hpricot (0.6) > libxml-ruby (0.9.5, 0.3.8.4) > mongrel (1.1.4) > needle (1.3.0) > net-sftp (1.1.0) > net-ssh (1.1.2) > rails (1.2.6) > rake (0.8.7, 0.7.3) > RedCloth (3.0.4) > rspec (1.2.7) > ruby-openid (1.1.4) > ruby-yadis (0.3.4) > rubyforge (1.0.3) > rubygems-update (1.3.4) > rubynode (0.1.3) > sqlite3-ruby (1.2.1) > systemu (1.2.0) > term-ansicolor (1.0.3) > termios (0.9.4) > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nick at deadorange.com Fri Aug 7 09:55:28 2009 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 7 Aug 2009 09:55:28 -0400 Subject: [rspec-users] RSpec with Sinatra Message-ID: <16827fa20908070655y439afef5q94bb35ed60c8b71@mail.gmail.com> Hey guys. I'm building an app in Sinatra, and am having some trouble writing a controller spec. It seems that #get isn't known: NoMethodError in 'server shows the index page' undefined method `get' for # I've pasted the spec, spec_helper, etc here, in case it's of any help: http://pastie.org/574643 Thanks! Nick From nick at deadorange.com Fri Aug 7 11:22:04 2009 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 7 Aug 2009 11:22:04 -0400 Subject: [rspec-users] RSpec with Sinatra In-Reply-To: <16827fa20908070655y439afef5q94bb35ed60c8b71@mail.gmail.com> References: <16827fa20908070655y439afef5q94bb35ed60c8b71@mail.gmail.com> Message-ID: <16827fa20908070822n4a4dbde3oaaf7b8df6bef085e@mail.gmail.com> On Fri, Aug 7, 2009 at 9:55 AM, Nick Hoffman wrote: > Hey guys. I'm building an app in Sinatra, and am having some trouble > writing a controller spec. It seems that #get isn't known: > > NoMethodError in 'server shows the index page' > undefined method `get' for # > > I've pasted the spec, spec_helper, etc here, in case it's of any help: > http://pastie.org/574643 > > Thanks! > Nick It turns out that the solution was more Sinatra-oriented. In case others have this same question, I added require 'rack/test' to the beginning of my spec, and then added include Rack::Test::Methods to the beginning of the describe-block for the Sinatra app. Cheers, Nick From balint.erdi at gmail.com Mon Aug 10 04:39:54 2009 From: balint.erdi at gmail.com (Balint Erdi) Date: Mon, 10 Aug 2009 01:39:54 -0700 (PDT) Subject: [rspec-users] [rspec-rails] rspec-rails forcing test environment? In-Reply-To: <57c63afe0907310536o174ca777pb9732fb4e19ead7c@mail.gmail.com> References: <57c63afe0907310536o174ca777pb9732fb4e19ead7c@mail.gmail.com> Message-ID: <38828ecb-90d5-460c-a68a-a516f63f83b3@m20g2000vbp.googlegroups.com> > > > Rails::Initializer.run do |config| > > ?(...) > > ?config.gem "rspec", :version => ">= 1.2.8", :lib => 'spec' > > ?config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => 'spec/ > > Use lib => false to keep rails from automatically loading rspec and/or > rspec-rails > > This should also be in config/environments/test.rb > > HTH, > David > Ok, I now have the following lines in my environment.rb: config.gem "rspec", :version => ">= 1.2.6", :lib => false config.gem "rspec-rails", :version => ">= 1.2.6", :lib => false And these in my environments/test.rb: config.gem "rspec", :lib => 'spec' config.gem "rspec-rails", :lib => 'spec/rails' Indeed, that solves the original problem of forcing the test environment when running the server. I refrained from specifying the version in the test.rb file since that would be a violation of DRY. I am not 100% satisfied since I still have to define the gems in two places, but this is now a minor issue and I don't see an easy way to fix it. Thank you for your help, David. B?lint From dchelimsky at gmail.com Mon Aug 10 08:16:25 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 10 Aug 2009 08:16:25 -0400 Subject: [rspec-users] [rspec-rails] rspec-rails forcing test environment? In-Reply-To: <38828ecb-90d5-460c-a68a-a516f63f83b3@m20g2000vbp.googlegroups.com> References: <57c63afe0907310536o174ca777pb9732fb4e19ead7c@mail.gmail.com> <38828ecb-90d5-460c-a68a-a516f63f83b3@m20g2000vbp.googlegroups.com> Message-ID: <57c63afe0908100516r235d476cqb6e95f2950e4c5a9@mail.gmail.com> On Mon, Aug 10, 2009 at 4:39 AM, Balint Erdi wrote: > > > >> >> > Rails::Initializer.run do |config| >> > ?(...) >> > ?config.gem "rspec", :version => ">= 1.2.8", :lib => 'spec' >> > ?config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => 'spec/ >> >> Use lib => false to keep rails from automatically loading rspec and/or >> rspec-rails >> >> This should also be in config/environments/test.rb >> >> HTH, >> David >> > > Ok, I now have the following lines in my environment.rb: > > ?config.gem "rspec", :version => ">= 1.2.6", :lib => false > ?config.gem "rspec-rails", :version => ">= 1.2.6", :lib => false > > And these in my environments/test.rb: > > ?config.gem "rspec", :lib => 'spec' > ?config.gem "rspec-rails", :lib => 'spec/rails' > > Indeed, that solves the original problem of forcing the test > environment when running the server. I refrained from specifying the > version in the test.rb file since that would be a violation of DRY. I > am not 100% satisfied since I still have to define the gems in two > places, but this is now a minor issue and I don't see an easy way to > fix it. Why are you duplicating it in environment.rb? You shouldn't have to have it in both places. In all of my rails apps I _only_ have it in environments/test.rb: config.gem "rspec", :version => ">= 1.2.8", :lib => false config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => false > > Thank you for your help, David. > B?lint From sfeley at gmail.com Mon Aug 10 10:11:14 2009 From: sfeley at gmail.com (Stephen Eley) Date: Mon, 10 Aug 2009 10:11:14 -0400 Subject: [rspec-users] [rspec-rails] rspec-rails forcing test environment? In-Reply-To: References: Message-ID: <1fb4df0908100711n4d585032x36b21fc8d59efc87@mail.gmail.com> On Fri, Jul 31, 2009 at 4:57 AM, Balint Erdi wrote: > > One possible workaround is to put the rspec and rspec-rails lines into > the environment file for the test env. (test.rb), but that seems to > defeat the goal of having all dependencies in one place so that it is > clear and gem-related rake tasks can be conveniently run. (I am using > rails 2.3.2, rspec 1.2.8, rspec-rails 1.2.7.1) Actually, I think it's pretty sensible. That's where I have mine. This is an environment-specific dependency. If you're never going to run in a test environment on a particular server, you don't need RSpec and there's no reason for the gem tasks to install it. (If you will, then the deployment is just a matter of setting the environment variable first: "RAILS_ENV=test rake gems:install") -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From johnjkle at gmail.com Tue Aug 11 08:51:58 2009 From: johnjkle at gmail.com (John Kolokotronis) Date: Tue, 11 Aug 2009 05:51:58 -0700 (PDT) Subject: [rspec-users] How do you get example full description in Rspec 1.2.x? Message-ID: <37f6ec3b-fc2b-46e0-a8b5-8a71d919fb66@a13g2000yqc.googlegroups.com> Hi All, I've been using Rspec 1.1.8 for some time now and even though I am not sure I'm doing this the best way possible, it allowed to get a full description block of a nested example but Rspec 1.2.8 does not seem to have the method I was using (__full_description). My example groups would look like this: describe "My test suite" do after(:each) puts self.__full description end describe "00001: My first test" do it "should do something" do # some code goes here end end end With Rspec 1.1.8 (or lower), the __full_description method will give me something like "My test suite 00001: My first test should do something" which is exactly what I want. However, with Rspec 1.2.8, there is no such method. If I use self.description, I only get what is in the it block, as expected. How can I access a full description string of a nested example like __full_description used to do? Can I also access an example description in the after(:each) block without referring to the self object? Thanks in advance. Regards, John From dchelimsky at gmail.com Tue Aug 11 10:04:39 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Aug 2009 10:04:39 -0400 Subject: [rspec-users] How do you get example full description in Rspec 1.2.x? In-Reply-To: <37f6ec3b-fc2b-46e0-a8b5-8a71d919fb66@a13g2000yqc.googlegroups.com> References: <37f6ec3b-fc2b-46e0-a8b5-8a71d919fb66@a13g2000yqc.googlegroups.com> Message-ID: <57c63afe0908110704r4cd7d28cu64ce4151d456fb55@mail.gmail.com> On Tue, Aug 11, 2009 at 8:51 AM, John Kolokotronis wrote: > Hi All, > > I've been using Rspec 1.1.8 for some time now and even though I am not > sure I'm doing this the best way possible, it allowed to get a full > description block of a nested example but Rspec 1.2.8 does not seem to > have the method I was using (__full_description). By convention, anything prefixed with a "_" is not part of the public API and subject to change. > My example groups > would look like this: > > describe "My test suite" do > ?after(:each) > ? ?puts self.__full description > ?end > > ?describe "00001: My first test" do > ? ?it "should do something" do > ? ? ?# some code goes here > ? ?end > ?end > end > > With Rspec 1.1.8 (or lower), the __full_description method will give > me something like "My test suite 00001: My first test should do > something" which is exactly what I want. > > However, with Rspec 1.2.8, there is no such method. If I use > self.description, I only get what is in the it block, as expected. > > How can I access a full description string of a nested example like > __full_description used to do? Can I also access an example > description in the after(:each) block without referring to the self > object? Thanks in advance. There is no full_description method right now, but it's dead simple: def full_description "#{self.class.description} #{description}" end Feel free to file a ticket for this at http://rspec.lighthouseapp.com Cheers, David > Regards, > > John > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From timcharper at gmail.com Wed Aug 12 00:09:18 2009 From: timcharper at gmail.com (Tim Harper) Date: Tue, 11 Aug 2009 22:09:18 -0600 Subject: [rspec-users] any idea why spec_server gets 'cannot remove Object' error? In-Reply-To: <24629257.post@talk.nabble.com> References: <7df13a180210246a40d87100c25a9e7d@ruby-forum.com> <57c63afe0906230719t211872abm67200c5aa1d22d5c@mail.gmail.com> <24629257.post@talk.nabble.com> Message-ID: On Thu, Jul 23, 2009 at 10:13 AM, nbenes wrote: > > > > Tim Harper wrote: > > > >> Have you heard of anyone that has rspec/spork/cucumber etc running under > >> cygwin, colinux, andLinux, or Ulteo Virtual Desktop. Do any of them > >> allow for fork? > > > > yes, yes, yes, don't know > > > > cygwin is slow, I would avoid it. andLinux is a ubuntu-KDE > > distribution that uses colinux. I use andLinux at home, and it's > > simply awesome. > > > > Tim > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > Hey Tim, I was trying to get Spork to work on Cygwin (Yes...Cygwin is slow, > hence the desire to get everything going on a DRb). > > I installed the Spork gem and setup the files for spec/cucumber just like > it > said to. However whenever I try to use it with either one it doesn't work. > Spork starts up just fine, but then when I run: > > script/spec spec --drb > > It fails out on me. I also tried doing it with autospec (and the proper > changes to the spec_helper file), but same result. > > $ spork > Using RSpec > Preloading Rails environment > Loading Spork.prefork block... > Spork is ready and listening on 8989! > 3 [main] ruby 5696 C:\cygwin\bin\ruby.exe: *** fatal error - unable to > remap C:\cygwin\bin\cyggcrypt-11.dll to same address as parent(0x5390000) > != > 0x54A0000 > 15 [main] ruby 3344 child_info::sync: wait failed, pid 5696, Win32 > error 183 > 204 [main] ruby 3344 fork: child 5696 - died waiting for dll loading, > errno 11 > > > That's the error I get. The 3 [main] ruby etc. line shows up when I > attempt > to run my specs through it in another terminal. The next two lines (15 and > 204) show up about 5 minutes later if letting it idle. Any idea on what > it's doing or how I can solve this? > > I have rspec 1.2.8 > ruby 1.8.7 > rails 2.3.2 > > Supposedly cygwin will support the forking so something tells me this is > another issue entirely. Any ideas? I'm really sorry. I have no idea why it's doing that. I set up a friend with AndLinux on his winders machine. He was using the E editor, and then running spork and autospec under AndLinux, using the kde terminal. It was a pretty sweet setup and was fast. You might look into it. Tim -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Wed Aug 12 13:47:57 2009 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 12 Aug 2009 18:47:57 +0100 Subject: [rspec-users] [Cucumber:999] specify a port for DRB In-Reply-To: References: Message-ID: <30DBE98A-94BC-41AC-B2B3-D85FF8E0B863@mattwynne.net> Good man for picking this up. I vote for opts, FWIW. Environment variables are useful if they need to be trickled down to child processes, but otherwise I think they're a bit evil - hidden dependencies and all that. On 12 Aug 2009, at 18:26, Chris Flipse wrote: > Pardon the crosspost, but this applies to both > > So, at work, I'm one of several people developing on the same multi- > user unix system. I/we would like to be able to use the drb server, > but at the moment rspec,cucumber and spork assume a single well > known port number for drb. That doesn't work well on a multi-user > system. > > My itch, and I'm starting to look through the codebases to scratch > it. I'm planning on patches for spork and cucumber as well. > > There are two ways I can see to implement this, just wanted to see > what people thought about it. The first is through an environment > variable, and the second is through adding command line switches. > > adding the switches to the command lines seems like it will be more > invasive, and it would require people to remember to specify the > port on any manual invocations. Also need to pass the right port in > to your spork invocations. On the other hand, it's more consistant > with the way the rest of the options are specified, and could be set > in an indivudual user's cucumber.yml or spec.opts, mitigating the > command line issue (though, frequently, I don't use my spec.opts file) > > setting an environment variable, say RSPEC_DRB or CUCUMBER_DRB would > be much less invasive, since the main codebases specify their global > drb ports through a constant anyway. It'd be fairly easy to have > them check for an environment variable before accepting the > default. I'd just have to add the ability to specify a specific > port to spork. Downside is that it's not as consistant with the > rest of the configuration. Upside from a user perspective is that > it's completely fire-and-forget; just set an env variable in > your .profile, and you're done worrying about it... > > > Thoughts? > > -- > // anything worth taking seriously is worth making fun of > // http://blog.devcaffeine.com/ > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "Cukes" group. > To post to this group, send email to cukes at googlegroups.com > To unsubscribe from this group, send email to cukes+unsubscribe at googlegroups.com > For more options, visit this group at http://groups.google.com/group/cukes?hl=en > -~----------~----~----~----~------~----~------~--~--- > cheers, Matt Wynne http://mattwynne.net +447974 430184 From ben at benmabey.com Wed Aug 12 22:50:18 2009 From: ben at benmabey.com (Ben Mabey) Date: Wed, 12 Aug 2009 20:50:18 -0600 Subject: [rspec-users] specify a port for DRB In-Reply-To: References: Message-ID: <4A837F6A.5050705@benmabey.com> Chris Flipse wrote: > Pardon the crosspost, but this applies to both > > So, at work, I'm one of several people developing on the same > multi-user unix system. I/we would like to be able to use the drb > server, but at the moment rspec,cucumber and spork assume a single > well known port number for drb. That doesn't work well on a > multi-user system. > > My itch, and I'm starting to look through the codebases to scratch > it. I'm planning on patches for spork and cucumber as well. > > There are two ways I can see to implement this, just wanted to see > what people thought about it. The first is through an environment > variable, and the second is through adding command line switches. > > adding the switches to the command lines seems like it will be more > invasive, and it would require people to remember to specify the port > on any manual invocations. Also need to pass the right port in to > your spork invocations. On the other hand, it's more consistant with > the way the rest of the options are specified, and could be set in an > indivudual user's cucumber.yml or spec.opts, mitigating the command > line issue (though, frequently, I don't use my spec.opts file) > > setting an environment variable, say RSPEC_DRB or CUCUMBER_DRB would > be much less invasive, since the main codebases specify their global > drb ports through a constant anyway. It'd be fairly easy to have them > check for an environment variable before accepting the default. I'd > just have to add the ability to specify a specific port to spork. > Downside is that it's not as consistant with the rest of the > configuration. Upside from a user perspective is that it's completely > fire-and-forget; just set an env variable in your .profile, and you're > done worrying about it... > > > Thoughts? > I can see where you are coming from and understand the tradeoffs... It would be nice just to set an ENV var and have both cucumber and spork operate on it. It does feel a little dirty though and could result in confusion if they were ever misspecified. It is also harder to document the use of constants, whereas the the options already have a convention. For the sake of consistently I would rather see them be specified using options. Does anyone else have a preference or argument for using env vars? BTW, thanks for doing this. :) -Ben From matt at mattwynne.net Thu Aug 13 05:54:36 2009 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 13 Aug 2009 10:54:36 +0100 Subject: [rspec-users] Autospec w/ rcov : how to ? In-Reply-To: <670a00380908130101n310e733fqf21859d92e8e459c@mail.gmail.com> References: <670a00380908130101n310e733fqf21859d92e8e459c@mail.gmail.com> Message-ID: <4E109FFA-F69D-4526-893A-978B7A8E1553@mattwynne.net> On 13 Aug 2009, at 09:01, Peter Fitzgibbons wrote: > Hello All, > > I would like to know how to include rcov in my autospec cycle? My > team is starting coverage work and this will be useful to us. > > Could anyone give an example of how to set this up ? I might be wrong, but I think this is going to be difficult to integrate into autospec. Why not set up a lightweight CI server like integrity or cruisecontrol.rb on your local machine, point it at your (local) git repo, and then commit every time you want to get coverage feedback? > > Thanks, > > Peter Fitzgibbons > (847) 687-7646 > Email: peter.fitzgibbons at gmail.com > IM GTalk: peter.fitzgibbons > IM AOL: peter.fitzgibbons at gmail.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt Wynne http://mattwynne.net +447974 430184 From johnjkle at gmail.com Thu Aug 13 10:07:59 2009 From: johnjkle at gmail.com (John Kolokotronis) Date: Thu, 13 Aug 2009 07:07:59 -0700 (PDT) Subject: [rspec-users] How do you get example full description in Rspec 1.2.x? In-Reply-To: <57c63afe0908110704r4cd7d28cu64ce4151d456fb55@mail.gmail.com> References: <37f6ec3b-fc2b-46e0-a8b5-8a71d919fb66@a13g2000yqc.googlegroups.com> <57c63afe0908110704r4cd7d28cu64ce4151d456fb55@mail.gmail.com> Message-ID: Thanks David, I didn't realize it was so easy to add the method back in (class.description never occurred to me) so including it in my spec_helper file sorts my problem for now and I can use Rspec 1.2.8. I've logged a ticket as requested: https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/873-rspec-12x-does-not-contain-__full_description-method Thanks again for the quick reply. Regards, John From rob.aldred at setfiremedia.com Fri Aug 14 07:04:51 2009 From: rob.aldred at setfiremedia.com (Rob Aldred) Date: Fri, 14 Aug 2009 12:04:51 +0100 Subject: [rspec-users] Fixtures not loading when running full test suite Message-ID: Hi, I've been trying to work this out for a while, im convinced its some local db configuration specific to my machine. When running `rake spec` 14 of my test fail all of them in the user_spec generated by restful auth. The error for all the failing tests is: ActiveRecord::RecordNotFound Couldn't find User with ID=1 Iv put some debugger lines and at the start of some of the tests it would appear that the users fixture is not being loaded when running the full suite If I run the specific test with the spec binary `spec spec/modes/user_spec.rb` all the fixtures are loaded and pass as expected. Further more, the error is only apparent when using mysql for the test db... When I use sqlite for the test db the tests pass when running the whole suite and the specific test... Weird... I'd like to know if anyone else has experienced this and if anyone has any pointers as to why the fixtures are not loaded when using mysql as the test db. Many thanks Rob -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott at railsnewbie.com Fri Aug 14 12:18:02 2009 From: scott at railsnewbie.com (Scott Taylor) Date: Fri, 14 Aug 2009 12:18:02 -0400 Subject: [rspec-users] Fixtures not loading when running full test suite In-Reply-To: References: Message-ID: <47023F21-FA8F-417D-A99A-B22433526C7A@railsnewbie.com> On Aug 14, 2009, at 7:04 AM, Rob Aldred wrote: > Hi, I've been trying to work this out for a while, im convinced its > some local db configuration specific to my machine. > > When running `rake spec` 14 of my test fail all of them in the > user_spec generated by restful auth. > The error for all the failing tests is: > > ActiveRecord::RecordNotFound > Couldn't find User with ID=1 > > Iv put some debugger lines and at the start of some of the tests it > would appear that the users fixture is not being loaded when running > the full suite > If I run the specific test with the spec binary `spec spec/modes/ > user_spec.rb` all the fixtures are loaded and pass as expected. > > Further more, the error is only apparent when using mysql for the > test db... > When I use sqlite for the test db the tests pass when running the > whole suite and the specific test... > > Weird... I'd like to know if anyone else has experienced this and if > anyone has any pointers as to why the fixtures are not loaded when > using mysql as the test db. Gist a copy of your spec_helper.rb I'd also run rake db:test:prepare and inspect the test database - making sure the fixtures are getting loaded properly. Just to note - running ./script/spec won't recreate the test database. You might also want to inspect that your fixtures are valid with a project like this (some code I've poached): http://github.com/smtlaissezfaire/validate_fixtures/tree/master Scott > > Many thanks > Rob > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From sfeley at gmail.com Fri Aug 14 12:52:32 2009 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 14 Aug 2009 12:52:32 -0400 Subject: [rspec-users] Cookies... In-Reply-To: <4A85762F.3020400@haskinferguson.net> References: <4A85762F.3020400@haskinferguson.net> Message-ID: <1fb4df0908140952g295ee7b5l463d855fdcc1d22b@mail.gmail.com> On Fri, Aug 14, 2009 at 10:35 AM, Denis Haskin wrote: > > (in application_helper_spec.rb) > ??? it "should return false and set the cookie to true if it is not set" do > ????? cookies[:fp_skip_hp_video].should == nil > ????? skip_hp_video.should == false > ????? cookies[:fp_skip_hp_video].should include({:value => true}) > ??? end Theory: I don't know the RSpec internals well enough to say for sure, but the fact that you're testing cookies[] twice in one example looks weird to me. If the cookies[] RSpec helper is memoizing a shallow copy of the real cookies object the first time you access it, then your second call to it isn't going to reflect any changes. I'd suggest splitting this out into multiple examples. Test the initial cookie state, test the result of your method call, and then test the final cookie state (which implies calling the method again in that example, but not testing it.) I can't guarantee it'd solve your problem, but it's worth trying. This is more a matter of style than necessity, but I personally try not to have more than one "should" or expectation per example. It makes for more verbose testing, but also clearer testing. As a fringe benefit, it also reinforces a coding style where side effects of methods are kept to a minimum, and where blocks of code do Just One Thing to the fullest practical extent. (I.e., clearer and more maintainable code.) >8-> -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From chamnapchhorn at gmail.com Sat Aug 15 05:35:40 2009 From: chamnapchhorn at gmail.com (Chamnap) Date: Sat, 15 Aug 2009 02:35:40 -0700 (PDT) Subject: [rspec-users] How to mock http accept header? Message-ID: I tried several hours to mock. What I want is basically to send "http accept" let's say "application/json" and want rails to send data back in json. Therefore, i need to mock that headers to do a test. I think I mocked that header already, but rails still sends me back in xml. Anyone could help me? From dchelimsky at gmail.com Sat Aug 15 09:49:52 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 15 Aug 2009 09:49:52 -0400 Subject: [rspec-users] How to mock http accept header? In-Reply-To: References: Message-ID: <57c63afe0908150649m5e990231n293cbc5fd7792aaf@mail.gmail.com> On Sat, Aug 15, 2009 at 5:35 AM, Chamnap wrote: > I tried several hours to mock. What I want is basically to send "http > accept" let's say "application/json" and want rails to send data back > in json. Therefore, i need to mock that headers to do a test. I think > I mocked that header already, but rails still sends me back in xml. > Anyone could help me? I think you mean stub (mocking means setting an expectation that a message is received - sounds like you're just trying to set a value for the controller to access). Assuming you're using a rails version using rack (can't remember when that was introduced - 2.1?), you can do this: it "should return json" do request.env['ACCEPT'] = "application/json" get whatever_the_path_is ... end HTH, David From programmer2188 at gmail.com Sun Aug 16 01:59:15 2009 From: programmer2188 at gmail.com (Brandon Olivares) Date: Sun, 16 Aug 2009 01:59:15 -0400 Subject: [rspec-users] have matcher failing Message-ID: <000701ca1e36$b0aee680$120cb380$@com> Hi, I'm trying to make a very simple console game, and have been using RSpec. However, the 'have' matcher is failing for some reason. I have a class named Game, which has a collection named Teams, defined as a read-only attribute. However, the following specification is failing: it { should have(1).teams } The code is here: http://gist.github.com/168572 It is the very last specification in the code that is failing. I'm running RSpec 1.2.8. Here's the output: $ spec spec/ ...F 1) 'Game before it is started when a team is added should have 1 teams' FAILED expected 1 teams, got 0 /home/Brandon/projects/baseball/spec/game_spec.rb:20: Finished in 0.05 seconds 4 examples, 1 failure When I manually call @game.teams.count, it returns 1, and the following spec succeeds: it "should have 1 team" do @game.teams.count.should == 1 end Thanks, Brandon From programmer2188 at gmail.com Sun Aug 16 02:46:48 2009 From: programmer2188 at gmail.com (Brandon Olivares) Date: Sun, 16 Aug 2009 02:46:48 -0400 Subject: [rspec-users] have matcher failing Message-ID: <000801ca1e3d$5cd82d30$16888790$@com> Hi, I'm really sorry, never mind on the matcher. I guess I remembered incorrectly how to set the subject. Is: Subject { @game } The best way to set it? Brandon -- www.creatorspiritus.com Blog and forum discussing living a Christ-centered life Follow me on Twitter: http://twitter.com/devbanana Follow creatorspiritus.com on Twitter: http://twitter.com/creatorspiritus From dchelimsky at gmail.com Sun Aug 16 09:43:12 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Aug 2009 09:43:12 -0400 Subject: [rspec-users] have matcher failing In-Reply-To: <000801ca1e3d$5cd82d30$16888790$@com> References: <000801ca1e3d$5cd82d30$16888790$@com> Message-ID: <57c63afe0908160643j1b9eb489n63737a68dda4b6c9@mail.gmail.com> On Sun, Aug 16, 2009 at 2:46 AM, Brandon Olivares wrote: > Hi, > > I'm really sorry, never mind on the matcher. I guess I remembered > incorrectly how to set the subject. > > Is: > > Subject { @game } It's with a lowercase 's': subject { @game } But if you call the subject method without a block you get an instance of Game (because that's passed to describe()). Check out http://gist.github.com/168629 HTH, David > > The best way to set it? > > Brandon > > -- > www.creatorspiritus.com > Blog and forum discussing living a Christ-centered life > Follow me on Twitter: http://twitter.com/devbanana > Follow creatorspiritus.com on Twitter: http://twitter.com/creatorspiritus > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Aug 16 09:50:40 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Aug 2009 09:50:40 -0400 Subject: [rspec-users] Is this the correct add_mapping? In-Reply-To: <670a00380908140613u659bfa46j783e3963cdacc244@mail.gmail.com> References: <670a00380908140613u659bfa46j783e3963cdacc244@mail.gmail.com> Message-ID: <57c63afe0908160650q28c10850vc755fb66796b290@mail.gmail.com> On Fri, Aug 14, 2009 at 9:13 AM, Peter Fitzgibbons wrote: > Hello All, > > a-la cucumber: > Feature: Spec runs Integrations > ? Scenario: When code changes, Integration specs run > ??? Given a rails app with controllers, models, view, helpers > ??? And a spec under spec/integration > ??? When code changes in app > ??? Then specs under spec/integration are run. > > So, in .autospec > > > Autotest.add_hook :initialize do |at| > ? at.add_mapping(%r%^app/(.*)\.rb$%) { > ??? at.files_matching %r%^spec/integration/.*_spec\.rb$% > ? } > > ? at.find_directories << 'spec/integration' > end > > This is my best guess.? Could somone show me the .autospec that correclty > accomplishes the story above? There is no .autospec. Try .autotest :) The autospec command just sets an env variable and then calls autotest - after that it's all autotest. Cheers, David > I'm feeling dense right now, so feel free to point out the painfully > obvious, even including which page in RSpec book spells out my density. > > Thanks all! > > Peter Fitzgibbons > (847) 687-7646 > Email: peter.fitzgibbons at gmail.com > IM GTalk: peter.fitzgibbons > IM AOL: peter.fitzgibbons at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From chamnapchhorn at gmail.com Sun Aug 16 21:01:28 2009 From: chamnapchhorn at gmail.com (Chamnap) Date: Sun, 16 Aug 2009 18:01:28 -0700 (PDT) Subject: [rspec-users] How to mock http accept header? In-Reply-To: <57c63afe0908150649m5e990231n293cbc5fd7792aaf@mail.gmail.com> References: <57c63afe0908150649m5e990231n293cbc5fd7792aaf@mail.gmail.com> Message-ID: I did the same thing as you did, but it doesn't work. The respond_to method still responses back in "application/xml". Any idea? On Aug 15, 8:49?pm, David Chelimsky wrote: > On Sat, Aug 15, 2009 at 5:35 AM, Chamnap wrote: > > I tried several hours to mock. What I want is basically to send "http > > accept" let's say "application/json" and want rails to send data back > > in json. Therefore, i need to mock that headers to do a test. I think > > I mocked that header already, but rails still sends me back in xml. > > Anyone could help me? > > I think you mean stub (mocking means setting an expectation that a > message is received - sounds like you're just trying to set a value > for the controller to access). > > Assuming you're using a rails version using rack (can't remember when > that was introduced - 2.1?), you can do this: > > it "should return json" do > ? request.env['ACCEPT'] = "application/json" > ? get whatever_the_path_is > ? ... > end > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From sfeley at gmail.com Sun Aug 16 22:19:42 2009 From: sfeley at gmail.com (Stephen Eley) Date: Sun, 16 Aug 2009 22:19:42 -0400 Subject: [rspec-users] How to mock http accept header? In-Reply-To: References: <57c63afe0908150649m5e990231n293cbc5fd7792aaf@mail.gmail.com> Message-ID: <1fb4df0908161919i73050ed3p9232c64d1e67ec61@mail.gmail.com> On Sun, Aug 16, 2009 at 9:01 PM, Chamnap wrote: > I did the same thing as you did, but it doesn't work. ?The respond_to > method still responses back in "application/xml". Any idea? It sounds like you're pretty sure your code is correct and your tests are broken. Does the application work outside of the RSpec tests? Can you hit it with, say, 'curl' with the json Accept header and determine if it does the right thing? If it does, then yes,your tests are broken. If the application _itself_ is returning XML, then the tests are working correctly: they're reporting a failing test condition when your application is indeed failing. >8-> Fix the code in that case, not the test. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From chamnapchhorn at gmail.com Sun Aug 16 23:04:50 2009 From: chamnapchhorn at gmail.com (Chamnap) Date: Sun, 16 Aug 2009 20:04:50 -0700 (PDT) Subject: [rspec-users] How to mock http accept header? In-Reply-To: <1fb4df0908161919i73050ed3p9232c64d1e67ec61@mail.gmail.com> References: <57c63afe0908150649m5e990231n293cbc5fd7792aaf@mail.gmail.com> <1fb4df0908161919i73050ed3p9232c64d1e67ec61@mail.gmail.com> Message-ID: <3f003b17-887b-472f-85b3-06c3e1d4decd@26g2000yqk.googlegroups.com> On Aug 17, 9:19?am, Stephen Eley wrote: > It sounds like you're pretty sure your code is correct and your tests > are broken. ?Does the application work outside of the RSpec tests? > Can you hit it with, say, 'curl' with the json Accept header and > determine if it does the right thing? Well, I can say, I trust respond_to method in rails. It actually works outside of RSpec tests. Maybe Rails uses some other objects that needs to be stubbed or mocked. I tried to dig the respond_to method code, but I feel I am going further too much. Chamnap From dchelimsky at gmail.com Sun Aug 16 23:24:53 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Aug 2009 22:24:53 -0500 Subject: [rspec-users] How to mock http accept header? In-Reply-To: References: <57c63afe0908150649m5e990231n293cbc5fd7792aaf@mail.gmail.com> Message-ID: <65F793EC-8306-4AE8-96E7-2E78260948DB@gmail.com> On Aug 16, 2009, at 8:01 PM, Chamnap wrote: > I did the same thing as you did, but it doesn't work. The respond_to > method still responses back in "application/xml". Any idea? Did you spell it ACCEPT ( all caps )? > > On Aug 15, 8:49 pm, David Chelimsky wrote: >> On Sat, Aug 15, 2009 at 5:35 AM, Chamnap >> wrote: >>> I tried several hours to mock. What I want is basically to send >>> "http >>> accept" let's say "application/json" and want rails to send data >>> back >>> in json. Therefore, i need to mock that headers to do a test. I >>> think >>> I mocked that header already, but rails still sends me back in xml. >>> Anyone could help me? >> >> I think you mean stub (mocking means setting an expectation that a >> message is received - sounds like you're just trying to set a value >> for the controller to access). >> >> Assuming you're using a rails version using rack (can't remember when >> that was introduced - 2.1?), you can do this: >> >> it "should return json" do >> request.env['ACCEPT'] = "application/json" >> get whatever_the_path_is >> ... >> end >> >> HTH, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/ >> rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From chamnapchhorn at gmail.com Sun Aug 16 23:26:20 2009 From: chamnapchhorn at gmail.com (Chamnap) Date: Sun, 16 Aug 2009 20:26:20 -0700 (PDT) Subject: [rspec-users] How to mock http accept header? In-Reply-To: <3f003b17-887b-472f-85b3-06c3e1d4decd@26g2000yqk.googlegroups.com> References: <57c63afe0908150649m5e990231n293cbc5fd7792aaf@mail.gmail.com> <1fb4df0908161919i73050ed3p9232c64d1e67ec61@mail.gmail.com> <3f003b17-887b-472f-85b3-06c3e1d4decd@26g2000yqk.googlegroups.com> Message-ID: Alright, thanks for your help guys. I found the problem. I debugged the code and I found the right header "HTTP_ACCEPT" in its request object. Rails uses this header to response back. Thanks Chamnap From maciej.blizinski at gmail.com Tue Aug 18 10:03:49 2009 From: maciej.blizinski at gmail.com (=?ISO-8859-2?Q?Maciej_Blizi=F1ski?=) Date: Tue, 18 Aug 2009 07:03:49 -0700 (PDT) Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources Message-ID: Hello rspec, I'm working on a Solaris rspec package (for OpenCSW). I pulled the current git sources as described at http://wiki.github.com/dchelimsky/rspec in the "Build and install the rspec gem from source" section. After 'rake gem' I'm getting: /export/home/maciej/src/rspec/Rakefile:92: warning: ambiguous first argument; put parentheses or even spaces rake aborted! undefined method `gem' for main:Object /export/home/maciej/src/rspec/Rakefile:2 (See full trace by running task with --trace) (in /export/home/maciej/src/rspec) Does it mean that the gem target is missing from the Rakefile, or am I doing something wrong? More information: $ rake --version rake, version 0.8.7 Last git commit: 3cb2913a43c172b629d19bd32ba54e8cbb25e754 Maciej From dchelimsky at gmail.com Tue Aug 18 11:06:03 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Aug 2009 10:06:03 -0500 Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources In-Reply-To: References: Message-ID: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> 2009/8/18 Maciej Blizi?ski : > Hello rspec, > > I'm working on a Solaris rspec package (for OpenCSW). I pulled the > current git sources as described at http://wiki.github.com/dchelimsky/rspec > in the "Build and install the rspec gem from source" section. After > 'rake gem' I'm getting: > > /export/home/maciej/src/rspec/Rakefile:92: warning: ambiguous first > argument; put parentheses or even spaces > rake aborted! > undefined method `gem' for main:Object > /export/home/maciej/src/rspec/Rakefile:2 > (See full trace by running task with --trace) > (in /export/home/maciej/src/rspec) > > Does it mean that the gem target is missing from the Rakefile, or am I > doing something wrong? > > More information: > > $ rake --version > rake, version 0.8.7 What Ruby and Rubygems versions:? $ ruby --version $ gem --version > > Last git commit: > 3cb2913a43c172b629d19bd32ba54e8cbb25e754 > > Maciej > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From maciej.blizinski at gmail.com Tue Aug 18 11:16:08 2009 From: maciej.blizinski at gmail.com (=?UTF-8?Q?Maciej_Blizi=C5=84ski?=) Date: Tue, 18 Aug 2009 16:16:08 +0100 Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources In-Reply-To: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> References: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> Message-ID: On Tue, Aug 18, 2009 at 4:06 PM, David Chelimsky wrote: >> More information: >> >> $ rake --version >> rake, version 0.8.7 > > What Ruby and Rubygems versions:? > > $ ruby --version > $ gem --version $ ruby --version ruby 1.8.7 (2009-06-12 patchlevel 174) [i386-solaris2.8] $ gem --version 0.9.2 From dchelimsky at gmail.com Tue Aug 18 11:20:19 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Aug 2009 10:20:19 -0500 Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources In-Reply-To: References: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> Message-ID: <57c63afe0908180820g6bc33bf5h14bc09ab4873959d@mail.gmail.com> 2009/8/18 Maciej Blizi?ski : > On Tue, Aug 18, 2009 at 4:06 PM, David Chelimsky wrote: >>> More information: >>> >>> $ rake --version >>> rake, version 0.8.7 >> >> What Ruby and Rubygems versions:? >> >> $ ruby --version >> $ gem --version > > $ ruby --version > ruby 1.8.7 (2009-06-12 patchlevel 174) [i386-solaris2.8] > $ gem --version > 0.9.2 That is a very old version of rubygems (2007-02-05) which probably doesn't support the gem method yet (just guessing). I'm using 1.3.4 (though it looks like there is a 1.3.5 version I missed). I'd recommend upgrading. Cheers, David From orengolan at gmail.com Tue Aug 18 11:47:39 2009 From: orengolan at gmail.com (oren) Date: Tue, 18 Aug 2009 08:47:39 -0700 (PDT) Subject: [rspec-users] rake and cucumber fails with ruby-1.9.1-p243 and polyglot 0.2.7 Message-ID: <4eccc084-88e9-4420-8c23-9795ffd2763c@g10g2000yqh.googlegroups.com> rake and cucumber fails with ruby-1.9.1-p243 and polyglot 0.2.7. (btw, when commenting the require method (polyglot.rb:56) it's passing) rake spec /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/polyglot-0.2.7/lib/ polyglot.rb:44:in `load': Failed to load /home/oren/misc/borderstylo/ code/silica1.9/app/models/mailer using extensions rb, treetop, tt (MissingSourceFile) from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/polyglot-0.2.7/lib/ polyglot.rb:60:in `rescue in require' from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/polyglot-0.2.7/lib/ polyglot.rb:57:in `require' cucumber features Using the default profile... Failed to load features/support/env.rb using extensions rb, treetop, tt Failed to load features/support/env.rb (MissingSourceFile) /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/polyglot-0.2.7/lib/ polyglot.rb:44:in `load' Any hints would be great, Thanks From dchelimsky at gmail.com Tue Aug 18 12:00:44 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Aug 2009 11:00:44 -0500 Subject: [rspec-users] rake and cucumber fails with ruby-1.9.1-p243 and polyglot 0.2.7 In-Reply-To: <4eccc084-88e9-4420-8c23-9795ffd2763c@g10g2000yqh.googlegroups.com> References: <4eccc084-88e9-4420-8c23-9795ffd2763c@g10g2000yqh.googlegroups.com> Message-ID: <57c63afe0908180900u3e96ab27h5b5f31cbaf278634@mail.gmail.com> On Tue, Aug 18, 2009 at 10:47 AM, oren wrote: > rake and cucumber fails with ?ruby-1.9.1-p243 and polyglot 0.2.7. > (btw, when commenting the require method (polyglot.rb:56) it's > passing) > > rake spec > > /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/polyglot-0.2.7/lib/ > polyglot.rb:44:in `load': Failed to load /home/oren/misc/borderstylo/ > code/silica1.9/app/models/mailer using extensions rb, treetop, tt > (MissingSourceFile) > from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/polyglot-0.2.7/lib/ > polyglot.rb:60:in `rescue in require' > from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/polyglot-0.2.7/lib/ > polyglot.rb:57:in `require' > > cucumber features > > Using the default profile... > Failed to load features/support/env.rb using extensions rb, treetop, > tt > Failed to load features/support/env.rb (MissingSourceFile) > /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/polyglot-0.2.7/lib/ > polyglot.rb:44:in `load' > > > Any hints would be great, > Thanks Cucumber has its own list now. Please submit cucumber questions to http://groups.google.com/group/cukes. Cheers, David From orengolan at gmail.com Tue Aug 18 12:09:30 2009 From: orengolan at gmail.com (oren) Date: Tue, 18 Aug 2009 09:09:30 -0700 (PDT) Subject: [rspec-users] rake and cucumber fails with ruby-1.9.1-p243 and polyglot 0.2.7 In-Reply-To: <57c63afe0908180900u3e96ab27h5b5f31cbaf278634@mail.gmail.com> References: <4eccc084-88e9-4420-8c23-9795ffd2763c@g10g2000yqh.googlegroups.com> <57c63afe0908180900u3e96ab27h5b5f31cbaf278634@mail.gmail.com> Message-ID: <28f63e14-27e0-41cb-9ef1-26a44b3659fb@d15g2000prc.googlegroups.com> I guess it was fixed in 0.2.8 - http://groups.google.com/group/cukes/browse_thread/thread/4497bae018d49e4f/88afe4037eb338e2?lnk=gst&q=polyglot#88afe4037eb338e2 From maciej.blizinski at gmail.com Tue Aug 18 13:34:41 2009 From: maciej.blizinski at gmail.com (=?UTF-8?Q?Maciej_Blizi=C5=84ski?=) Date: Tue, 18 Aug 2009 18:34:41 +0100 Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources In-Reply-To: <57c63afe0908180820g6bc33bf5h14bc09ab4873959d@mail.gmail.com> References: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> <57c63afe0908180820g6bc33bf5h14bc09ab4873959d@mail.gmail.com> Message-ID: On Tue, Aug 18, 2009 at 4:20 PM, David Chelimsky wrote: > That is a very old version of rubygems (2007-02-05) which probably > doesn't support the gem method yet (just guessing). I'm using 1.3.4 > (though it looks like there is a 1.3.5 version I missed). I'd > recommend upgrading. I've upgraded rubygems: maciej at solaris /export/home/maciej/src/rspec $ rake --version rake, version 0.8.7 maciej at solaris /export/home/maciej/src/rspec $ gem --version 1.3.5 maciej at solaris /export/home/maciej/src/rspec $ rake gem (in /export/home/maciej/src/rspec) /export/home/maciej/src/rspec/Rakefile:92: warning: ambiguous first argument; put parentheses or even spaces rake aborted! undefined method `gem' for main:Object /export/home/maciej/src/rspec/Rakefile:2 (See full trace by running task with --trace) I've re-run it with --trace: maciej at solaris /export/home/maciej/src/rspec $ rake --trace gem (in /export/home/maciej/src/rspec) /export/home/maciej/src/rspec/Rakefile:92: warning: ambiguous first argument; put parentheses or even spaces rake aborted! undefined method `gem' for main:Object /export/home/maciej/src/rspec/Rakefile:2 /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2383:in `load' /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2383:in `raw_load_rakefile' /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2017:in `load_rakefile' /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2068:in `standard_exception_handling' /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2016:in `load_rakefile' /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2000:in `run' /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2068:in `standard_exception_handling' /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:1998:in `run' /opt/csw/bin/rake:32 Any ideas? Maciej From dchelimsky at gmail.com Tue Aug 18 13:54:44 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Aug 2009 12:54:44 -0500 Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources In-Reply-To: References: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> <57c63afe0908180820g6bc33bf5h14bc09ab4873959d@mail.gmail.com> Message-ID: <57c63afe0908181054j7662b011nb0d45c0a8154e5b3@mail.gmail.com> 2009/8/18 Maciej Blizi?ski : > On Tue, Aug 18, 2009 at 4:20 PM, David Chelimsky wrote: >> That is a very old version of rubygems (2007-02-05) which probably >> doesn't support the gem method yet (just guessing). I'm using 1.3.4 >> (though it looks like there is a 1.3.5 version I missed). I'd >> recommend upgrading. > > I've upgraded rubygems: > > maciej at solaris /export/home/maciej/src/rspec $ rake --version > rake, version 0.8.7 > maciej at solaris /export/home/maciej/src/rspec $ gem --version > 1.3.5 > maciej at solaris /export/home/maciej/src/rspec $ rake gem > (in /export/home/maciej/src/rspec) > /export/home/maciej/src/rspec/Rakefile:92: warning: ambiguous first > argument; put parentheses or even spaces > rake aborted! > undefined method `gem' for main:Object > /export/home/maciej/src/rspec/Rakefile:2 > (See full trace by running task with --trace) > > I've re-run it with --trace: > > maciej at solaris /export/home/maciej/src/rspec $ rake ?--trace gem > (in /export/home/maciej/src/rspec) > /export/home/maciej/src/rspec/Rakefile:92: warning: ambiguous first > argument; put parentheses or even spaces > rake aborted! > undefined method `gem' for main:Object > /export/home/maciej/src/rspec/Rakefile:2 > /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2383:in `load' > /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2383:in `raw_load_rakefile' > /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2017:in `load_rakefile' > /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2068:in `standard_exception_handling' > /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2016:in `load_rakefile' > /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2000:in `run' > /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:2068:in `standard_exception_handling' > /opt/csw/lib/ruby/site_ruby/1.8/rake.rb:1998:in `run' > /opt/csw/bin/rake:32 > > Any ideas? Ugy - sorry to put you through that to land in the same spot. I really don't have any ideas. I did run into an unrelated problem (manifest was out of date) and just pushed the fix for that. I'm able to build the gem using Ruby 1.8.7 with no warnings or errors. Anybody else here familiar w/ Solaris/Ruby idiosyncrasies? > > Maciej > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From paul.mylchreest at mac.com Tue Aug 18 13:19:32 2009 From: paul.mylchreest at mac.com (Paul Mylchreest) Date: Tue, 18 Aug 2009 13:19:32 -0400 Subject: [rspec-users] question about throw_symbol Message-ID: <5FE46680-D456-4FAC-BE13-11D602F373BA@mac.com> Given rspec 1.2.8 ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] And the following spec: def over_limit?(a) catch(:over_limit) do a.each do |x| throw(:over_limit) if x > 10 end end end describe "when over limit" do it "should throw symbol :over_limit" do lambda{ over_limit?([0, 5, 11]) }.should throw_symbol(:over_limit) end end One would expect this to pass, however this is the result: when over limit - should throw symbol :over_limit (FAILED - 1) 1) 'when over limit should throw symbol :over_limit' FAILED expected :over_limit but nothing was thrown ./spec/rspec_tests/rutabaga_spec.rb:125: When the catch is removed, it works. Can anyone reproduce this behavior? thanks Paul Mylchreest paul.mylchreest at mac.com From dchelimsky at gmail.com Tue Aug 18 14:34:20 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Aug 2009 13:34:20 -0500 Subject: [rspec-users] question about throw_symbol In-Reply-To: <5FE46680-D456-4FAC-BE13-11D602F373BA@mac.com> References: <5FE46680-D456-4FAC-BE13-11D602F373BA@mac.com> Message-ID: <57c63afe0908181134r56ea29f9iefe74776d20f9603@mail.gmail.com> On Tue, Aug 18, 2009 at 12:19 PM, Paul Mylchreest wrote: > Given > ?rspec 1.2.8 > ?ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] > > And the following spec: > > ?def over_limit?(a) > ? ?catch(:over_limit) do > ? ? ?a.each do |x| > ? ? ? ?throw(:over_limit) if x > 10 > ? ? ?end > ? ?end > ?end > > ?describe "when over limit" do > ? ?it "should throw symbol :over_limit" do > ? ? ?lambda{ > ? ? ? ?over_limit?([0, 5, 11]) > ? ? ?}.should throw_symbol(:over_limit) > ? ?end > ?end > > One would expect this to pass, however this is the result: > > ?when over limit > ?- should throw symbol :over_limit (FAILED - 1) > > ?1) > ?'when over limit should throw symbol :over_limit' FAILED > ?expected :over_limit but nothing was thrown > ?./spec/rspec_tests/rutabaga_spec.rb:125: > > When the catch is removed, it works. That's correct. The catch in over_limit() catches the throw, so it does not bubble out of the method. > > Can anyone reproduce this behavior? > > thanks > > Paul Mylchreest > paul.mylchreest at mac.com > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From paul.mylchreest at mac.com Tue Aug 18 15:16:33 2009 From: paul.mylchreest at mac.com (Paul Mylchreest) Date: Tue, 18 Aug 2009 15:16:33 -0400 Subject: [rspec-users] question about throw_symbol In-Reply-To: <57c63afe0908181134r56ea29f9iefe74776d20f9603@mail.gmail.com> References: <5FE46680-D456-4FAC-BE13-11D602F373BA@mac.com> <57c63afe0908181134r56ea29f9iefe74776d20f9603@mail.gmail.com> Message-ID: <0CBC802F-04B4-415A-BECD-A8D5052C54EC@mac.com> Thanks David, So, taking from your book, on page 212: =begin def working_too_hard? catch :working_too_hard do weeks.each do |week| people.each do |person| throw :working_too_hard, true if person.hours_for(week) > 50 end end end end To set an expectation that a symbol is thrown, we wrap up the code in a proc and set the expectation on the proc: lambda { team.working_too_hard? }.should throw_symbol(:working_too_hard) =end I guess that is a typo, correct? On 2009-Aug-18, at 14:34 , David Chelimsky wrote: > On Tue, Aug 18, 2009 at 12:19 PM, Paul > Mylchreest wrote: >> Given >> rspec 1.2.8 >> ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] >> >> And the following spec: >> >> def over_limit?(a) >> catch(:over_limit) do >> a.each do |x| >> throw(:over_limit) if x > 10 >> end >> end >> end >> >> describe "when over limit" do >> it "should throw symbol :over_limit" do >> lambda{ >> over_limit?([0, 5, 11]) >> }.should throw_symbol(:over_limit) >> end >> end >> >> One would expect this to pass, however this is the result: >> >> when over limit >> - should throw symbol :over_limit (FAILED - 1) >> >> 1) >> 'when over limit should throw symbol :over_limit' FAILED >> expected :over_limit but nothing was thrown >> ./spec/rspec_tests/rutabaga_spec.rb:125: >> >> When the catch is removed, it works. > > That's correct. The catch in over_limit() catches the throw, so it > does not bubble out of the method. > >> >> Can anyone reproduce this behavior? >> >> thanks >> >> Paul Mylchreest >> paul.mylchreest at mac.com >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Paul Mylchreest paul.mylchreest at mac.com From tom at experthuman.com Tue Aug 18 15:46:37 2009 From: tom at experthuman.com (Tom Stuart) Date: Tue, 18 Aug 2009 20:46:37 +0100 Subject: [rspec-users] question about throw_symbol In-Reply-To: <0CBC802F-04B4-415A-BECD-A8D5052C54EC@mac.com> References: <5FE46680-D456-4FAC-BE13-11D602F373BA@mac.com> <57c63afe0908181134r56ea29f9iefe74776d20f9603@mail.gmail.com> <0CBC802F-04B4-415A-BECD-A8D5052C54EC@mac.com> Message-ID: <15F70580-3E8A-45CD-BCC2-1DF44C6AAD20@experthuman.com> On 18 Aug 2009, at 20:16, Paul Mylchreest wrote: > So, taking from your book, on page 212: [...] > I guess that is a typo, correct? As an aside, I don't understand this section of the book ("Expecting a Throw") at all. The original version of the loop already "short circuits" (with return) without using throw/catch. What does "as soon as working_too_hard == true" mean? And yes, it's weird to be setting a throw_symbol expectation on a call to a method which is catching that throw. Cheers, -Tom From maciej.blizinski at gmail.com Wed Aug 19 08:15:19 2009 From: maciej.blizinski at gmail.com (=?UTF-8?Q?Maciej_Blizi=C5=84ski?=) Date: Wed, 19 Aug 2009 13:15:19 +0100 Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources In-Reply-To: <57c63afe0908181054j7662b011nb0d45c0a8154e5b3@mail.gmail.com> References: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> <57c63afe0908180820g6bc33bf5h14bc09ab4873959d@mail.gmail.com> <57c63afe0908181054j7662b011nb0d45c0a8154e5b3@mail.gmail.com> Message-ID: On Tue, Aug 18, 2009 at 6:54 PM, David Chelimsky wrote: > I really don't have any ideas. I did run into an unrelated problem > (manifest was out of date) and just pushed the fix for that. I'm able > to build the gem using Ruby 1.8.7 with no warnings or errors. > > Anybody else here familiar w/ Solaris/Ruby idiosyncrasies? I checked it under Ubuntu Hardy: $ rake --version rake, version 0.8.1 $ gem --version 1.1.1 $ git clone git://github.com/dchelimsky/rspec.git $ cd rspec $ rake gem (in /home/maciej/src/rspec) rake aborted! undefined method `gem' for main:Object /home/maciej/src/rspec/Rakefile:2 (See full trace by running task with --trace) The same symptoms... it could due to gem version 1.1.1, though. Okay, testing with a newer version, on a different Linux box: maciej at fennel ~/src $ git clone git://github.com/dchelimsky/rspec.git Initialized empty Git repository in /home/maciej/src/rspec/.git/ remote: Counting objects: 56169, done. remote: Compressing objects: 100% (12694/12694), done. remote: Total 56169 (delta 41074), reused 55651 (delta 40664) Receiving objects: 100% (56169/56169), 7.05 MiB | 1360 KiB/s, done. Resolving deltas: 100% (41074/41074), done. maciej at fennel ~/src $ cd rspec maciej at fennel ~/src/rspec $ rake gem (in /home/maciej/src/rspec) rake aborted! Could not find RubyGem hoe (>= 2.0.0) /home/maciej/src/rspec/Rakefile:2 (See full trace by running task with --trace) maciej at fennel ~/src/rspec $ rake --version rake, version 0.8.7 maciej at fennel ~/src/rspec $ gem --version 1.3.1 So, the same symptoms, tested on Ubuntu Hardy, Gentoo and Solaris 10. It's weird that you can't reproduce the issue. Perhaps try with a fresh system? I install: ruby, rubygems, rake, git. Then the above sequence. Maciej From dchelimsky at gmail.com Wed Aug 19 08:24:04 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Aug 2009 07:24:04 -0500 Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources In-Reply-To: References: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> <57c63afe0908180820g6bc33bf5h14bc09ab4873959d@mail.gmail.com> <57c63afe0908181054j7662b011nb0d45c0a8154e5b3@mail.gmail.com> Message-ID: <57c63afe0908190524pb6bb1f5we0b1157f8d075e72@mail.gmail.com> 2009/8/19 Maciej Blizi?ski : > On Tue, Aug 18, 2009 at 6:54 PM, David Chelimsky wrote: >> I really don't have any ideas. I did run into an unrelated problem >> (manifest was out of date) and just pushed the fix for that. I'm able >> to build the gem using Ruby 1.8.7 with no warnings or errors. >> >> Anybody else here familiar w/ Solaris/Ruby idiosyncrasies? > > I checked it under Ubuntu Hardy: > > $ rake --version > rake, version 0.8.1 > $ gem --version > 1.1.1 > > $ git clone git://github.com/dchelimsky/rspec.git > $ cd rspec > $ rake gem > (in /home/maciej/src/rspec) > rake aborted! > undefined method `gem' for main:Object > /home/maciej/src/rspec/Rakefile:2 > (See full trace by running task with --trace) > > The same symptoms... it could due to gem version 1.1.1, though. Okay, > testing with a newer version, on a different Linux box: > > maciej at fennel ~/src $ git clone git://github.com/dchelimsky/rspec.git > Initialized empty Git repository in /home/maciej/src/rspec/.git/ > remote: Counting objects: 56169, done. > remote: Compressing objects: 100% (12694/12694), done. > remote: Total 56169 (delta 41074), reused 55651 (delta 40664) > Receiving objects: 100% (56169/56169), 7.05 MiB | 1360 KiB/s, done. > Resolving deltas: 100% (41074/41074), done. > maciej at fennel ~/src $ cd rspec > maciej at fennel ~/src/rspec $ rake gem > (in /home/maciej/src/rspec) > rake aborted! > Could not find RubyGem hoe (>= 2.0.0) > /home/maciej/src/rspec/Rakefile:2 > (See full trace by running task with --trace) > maciej at fennel ~/src/rspec $ rake --version > rake, version 0.8.7 > maciej at fennel ~/src/rspec $ gem --version > 1.3.1 > > So, the same symptoms, tested on Ubuntu Hardy, Gentoo and Solaris 10. Not really the same symptoms. "Could not find RubyGem hoe" is not the same issue as "undefined method `gem'" The gem problem is related to outdated versions of rubygems. The hoe problem is solved with "gem install hoe" HTH, David > It's weird that you can't reproduce the issue. Perhaps try with a > fresh system? I install: ruby, rubygems, rake, git. Then the above > sequence. > > Maciej > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Aug 19 08:36:14 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Aug 2009 07:36:14 -0500 Subject: [rspec-users] "undefined method `gem' for main:Object" when installing rspec from the sources In-Reply-To: <57c63afe0908190524pb6bb1f5we0b1157f8d075e72@mail.gmail.com> References: <57c63afe0908180806h4f01086fka5cb70fcb3ffd156@mail.gmail.com> <57c63afe0908180820g6bc33bf5h14bc09ab4873959d@mail.gmail.com> <57c63afe0908181054j7662b011nb0d45c0a8154e5b3@mail.gmail.com> <57c63afe0908190524pb6bb1f5we0b1157f8d075e72@mail.gmail.com> Message-ID: <57c63afe0908190536t123db22aq8e3121383a2df387@mail.gmail.com> On Wed, Aug 19, 2009 at 7:24 AM, David Chelimsky wrote: > 2009/8/19 Maciej Blizi?ski : >> On Tue, Aug 18, 2009 at 6:54 PM, David Chelimsky wrote: >>> I really don't have any ideas. I did run into an unrelated problem >>> (manifest was out of date) and just pushed the fix for that. I'm able >>> to build the gem using Ruby 1.8.7 with no warnings or errors. >>> >>> Anybody else here familiar w/ Solaris/Ruby idiosyncrasies? >> >> I checked it under Ubuntu Hardy: >> >> $ rake --version >> rake, version 0.8.1 >> $ gem --version >> 1.1.1 >> >> $ git clone git://github.com/dchelimsky/rspec.git >> $ cd rspec >> $ rake gem >> (in /home/maciej/src/rspec) >> rake aborted! >> undefined method `gem' for main:Object >> /home/maciej/src/rspec/Rakefile:2 >> (See full trace by running task with --trace) >> >> The same symptoms... it could due to gem version 1.1.1, though. Okay, >> testing with a newer version, on a different Linux box: >> >> maciej at fennel ~/src $ git clone git://github.com/dchelimsky/rspec.git >> Initialized empty Git repository in /home/maciej/src/rspec/.git/ >> remote: Counting objects: 56169, done. >> remote: Compressing objects: 100% (12694/12694), done. >> remote: Total 56169 (delta 41074), reused 55651 (delta 40664) >> Receiving objects: 100% (56169/56169), 7.05 MiB | 1360 KiB/s, done. >> Resolving deltas: 100% (41074/41074), done. >> maciej at fennel ~/src $ cd rspec >> maciej at fennel ~/src/rspec $ rake gem >> (in /home/maciej/src/rspec) >> rake aborted! >> Could not find RubyGem hoe (>= 2.0.0) >> /home/maciej/src/rspec/Rakefile:2 >> (See full trace by running task with --trace) >> maciej at fennel ~/src/rspec $ rake --version >> rake, version 0.8.7 >> maciej at fennel ~/src/rspec $ gem --version >> 1.3.1 >> >> So, the same symptoms, tested on Ubuntu Hardy, Gentoo and Solaris 10. > > Not really the same symptoms. "Could not find RubyGem hoe" is not the > same issue as "undefined method `gem'" The gem problem is related to > outdated versions of rubygems. The hoe problem is solved with "gem > install hoe" To clarify - try, on the last linux box you described: $ gem install hoe $ rake gem You may need other gems at this point, but if you do you'll get error messages like "Could not find RubyGem foo," in which case you would then say: $ gem install foo You're very close. Let us know when you get it working. Cheers, David > > HTH, > David > >> It's weird that you can't reproduce the issue. Perhaps try with a >> fresh system? I install: ruby, rubygems, rake, git. Then the above >> sequence. >> >> Maciej >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From dchelimsky at gmail.com Wed Aug 19 08:56:36 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Aug 2009 07:56:36 -0500 Subject: [rspec-users] question about throw_symbol In-Reply-To: <15F70580-3E8A-45CD-BCC2-1DF44C6AAD20@experthuman.com> References: <5FE46680-D456-4FAC-BE13-11D602F373BA@mac.com> <57c63afe0908181134r56ea29f9iefe74776d20f9603@mail.gmail.com> <0CBC802F-04B4-415A-BECD-A8D5052C54EC@mac.com> <15F70580-3E8A-45CD-BCC2-1DF44C6AAD20@experthuman.com> Message-ID: <57c63afe0908190556u5d86a5a0s7149f99f06b21433@mail.gmail.com> On Tue, Aug 18, 2009 at 2:46 PM, Tom Stuart wrote: > On 18 Aug 2009, at 20:16, Paul Mylchreest wrote: >> >> So, taking from your book, on page 212: > > [...] >> >> I guess that is a typo, correct? > > As an aside, I don't understand this section of the book ("Expecting a > Throw") at all. The original version of the loop already "short circuits" > (with return) without using throw/catch. What does "as soon as > working_too_hard == true" mean? And yes, it's weird to be setting a > throw_symbol expectation on a call to a method which is catching that throw. Yes - this has been reported in the errata and has not yet been addressed. It will be before we get to treeware :) > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Aug 20 12:37:33 2009 From: lists at ruby-forum.com (Davide Benini) Date: Thu, 20 Aug 2009 18:37:33 +0200 Subject: [rspec-users] Match a regex with Cucumber + Webrat Message-ID: <31f6a19bc45eeecf8d5e0f2655468639@ruby-forum.com> Hello folks, I am trying to learn Cucumber and testing in general. I am working on a app fo lingustic studies, but for the purpose of testing it can be compared to a "guess the song" app. When a new quiz is take, a page shows a number of flash players, each one with a single track. The app works, but I cannot pass the cucumber test. Here is my step definition: [code] Then /^I should see a flash player with "([^\"]*)"$/ do |arg1| response.should have_selector('param', :name => 'FlashVars') do |param| param.should =~ /.+#{Regexp.escape("numero-1")}.+/m end end [/code] I have been tweaking the regex a bit (eliminating the .+ and so on) but the test always fails. Here's the response: [code] Then I should see a flash player with "Corduroy" # features/step_definitions/experiment_step.rb:14 expected: /.+numero\-1.+/m, got: (using =~) [/code] Any suggestion? Thanks in advance. -- Posted via http://www.ruby-forum.com/. From tom at experthuman.com Thu Aug 20 12:48:26 2009 From: tom at experthuman.com (Tom Stuart) Date: Thu, 20 Aug 2009 17:48:26 +0100 Subject: [rspec-users] Match a regex with Cucumber + Webrat In-Reply-To: <31f6a19bc45eeecf8d5e0f2655468639@ruby-forum.com> References: <31f6a19bc45eeecf8d5e0f2655468639@ruby-forum.com> Message-ID: On 20 Aug 2009, at 17:37, Davide Benini wrote: > Then /^I should see a flash player with "([^\"]*)"$/ do |arg1| > response.should have_selector('param', :name => 'FlashVars') do | > param| > param.should =~ /.+#{Regexp.escape("numero-1")}.+/m > end > end > > I have been tweaking the regex a bit (eliminating the .+ and so on) > but > the test always fails. Shouldn't you be doing something with arg1? Cheers, -Tom From lists at ruby-forum.com Thu Aug 20 13:11:34 2009 From: lists at ruby-forum.com (Dave Nolan) Date: Thu, 20 Aug 2009 19:11:34 +0200 Subject: [rspec-users] Workaround for spec_server "can't dup NilClass" Message-ID: <769672b909e943a31ddbcf9bc14dbebc@ruby-forum.com> On recent versions of RSpec/RSpec rails, if you are using Machinist/Factory_Girl or similar, you may get "can't dup NilClass" errors running specs through spec_server. (Not on the initial run, but on all subsequent runs.) The workaround is to manually re-load the factories/templates each spec run e.g. by placing "load" statements within the Spec::Runner.configure block in spec_helper. I understand spec_server is deprecated but its replacement (spork) is not windows-compatible. So if you're stuck with spec_server, this is for you. (I'm running RSpec/RSpec Rails 1.2.7+ - YMMV) HTHSomeoneElse Dave -- Posted via http://www.ruby-forum.com/. From ed.ruder at gmail.com Thu Aug 20 15:00:41 2009 From: ed.ruder at gmail.com (Ed Ruder) Date: Thu, 20 Aug 2009 12:00:41 -0700 (PDT) Subject: [rspec-users] [Rails] How to mock/stub link_to from a Rails helper spec? Message-ID: All, In a Rails helper spec, how do I stub or mock the 'link_to' method? When i step into link_to, self.class is Spec::Rails::Example::HelperExampleGroup::Subclass_1::Subclass_5::Subclass_1. What I'm trying to do is stub link_to and check that its parameters are correct--i.e., that a helper method is properly constructing the parameters to link_to. The work-around (and what seems to me to be a more awkward approach) is to grep the output of the helper method for a link with a proper href property. Thoughts? Ed From ed.ruder at gmail.com Thu Aug 20 15:16:01 2009 From: ed.ruder at gmail.com (Ed Ruder) Date: Thu, 20 Aug 2009 12:16:01 -0700 (PDT) Subject: [rspec-users] Change in -l command line option when line number is inside a describe block? Message-ID: <1e3306b4-6ad0-4891-9ab9-4501c3933b3e@i8g2000pro.googlegroups.com> All, I often run specs from inside of TextMate, using the RSpec bundle. When the selection is inside of an example, I can run just that example using the RSpec bundle's "Run Single Example" script, which I assume ends up calling spec with a -l command line option ("line number"). Until a few versions ago (I don't know precisely when and I'm using 1.1.12), with a selection that's inside a describe block (but outside of any specific example block), "Run Single Example" would run all of the examples inside of that describe block--a very nice feature that I used all the time. In 1.1.12, it runs just the examples at the "root" of the file, in the top-most describe block, regardless of where the selection is. Was this an intentional change? Or, should I open up a ticket to restore this behavior? Thanks. Ed From dchelimsky at gmail.com Thu Aug 20 15:28:11 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 20 Aug 2009 14:28:11 -0500 Subject: [rspec-users] Change in -l command line option when line number is inside a describe block? In-Reply-To: <1e3306b4-6ad0-4891-9ab9-4501c3933b3e@i8g2000pro.googlegroups.com> References: <1e3306b4-6ad0-4891-9ab9-4501c3933b3e@i8g2000pro.googlegroups.com> Message-ID: <57c63afe0908201228x68d5981ai468b78bc8c7b68c5@mail.gmail.com> On Thu, Aug 20, 2009 at 2:16 PM, Ed Ruder wrote: > All, > > I often run specs from inside of TextMate, using the RSpec bundle. > When the selection is inside of an example, I can run just that > example using the RSpec bundle's "Run Single Example" script, which I > assume ends up calling spec with a -l command line option ("line > number"). > > Until a few versions ago (I don't know precisely when and I'm using > 1.1.12), with a selection that's inside a describe block (but outside > of any specific example block), "Run Single Example" would run all of > the examples inside of that describe block--a very nice feature that I > used all the time. In 1.1.12, it runs just the examples at the "root" > of the file, in the top-most describe block, regardless of where the > selection is. > > Was this an intentional change? Or, should I open up a ticket to > restore this behavior? It was unintentional but has since been fixed. If you can upgrade to 1.2.8 (current), that would be great. HTH, David > > Thanks. > > Ed > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ed.ruder at gmail.com Thu Aug 20 16:05:17 2009 From: ed.ruder at gmail.com (Ed Ruder) Date: Thu, 20 Aug 2009 13:05:17 -0700 (PDT) Subject: [rspec-users] Change in -l command line option when line number is inside a describe block? In-Reply-To: <57c63afe0908201228x68d5981ai468b78bc8c7b68c5@mail.gmail.com> References: <1e3306b4-6ad0-4891-9ab9-4501c3933b3e@i8g2000pro.googlegroups.com> <57c63afe0908201228x68d5981ai468b78bc8c7b68c5@mail.gmail.com> Message-ID: I lied--I'm running 1.2.7, but I'm happy that this was fixed in 1.2.8! Thanks, David. Ed On Aug 20, 12:28?pm, David Chelimsky wrote: > On Thu, Aug 20, 2009 at 2:16 PM, Ed Ruder wrote: > > All, > > > I often run specs from inside of TextMate, using the RSpec bundle. > > When the selection is inside of an example, I can run just that > > example using the RSpec bundle's "Run Single Example" script, which I > > assume ends up calling spec with a -l command line option ("line > > number"). > > > Until a few versions ago (I don't know precisely when and I'm using > > 1.1.12), with a selection that's inside a describe block (but outside > > of any specific example block), "Run Single Example" would run all of > > the examples inside of that describe block--a very nice feature that I > > used all the time. In 1.1.12, it runs just the examples at the "root" > > of the file, in the top-most describe block, regardless of where the > > selection is. > > > Was this an intentional change? Or, should I open up a ticket to > > restore this behavior? > > It was unintentional but has since been fixed. If you can upgrade to > 1.2.8 (current), that would be great. > > HTH, > David > > > > > Thanks. > > > Ed > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From balla at sogetthis.com Thu Aug 20 16:03:21 2009 From: balla at sogetthis.com (BallaBall) Date: Thu, 20 Aug 2009 13:03:21 -0700 (PDT) Subject: [rspec-users] RSpec stub/mock I18n Message-ID: I have some model with the following validation: validates_inclusion_of :value, :in => I18n.available_locales.map(&:to_s) I would think that I would be able to stub out that method in a test like so: it "should accepted any available locale as a value" do I18n.stub!(:available_locales).and_return(['abc']) my_model = MyModel.new( :value => 'abc' ) my_model.should have(:no).errors_on(:value) end But it keeps failing. It looks like the I18n inside the model is not being stubbed correctly?!?! What am I doing wrong? From mauricio.linhares at gmail.com Thu Aug 20 17:00:30 2009 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Thu, 20 Aug 2009 18:00:30 -0300 Subject: [rspec-users] RSpec stub/mock I18n In-Reply-To: References: Message-ID: When you spec runs (and your stub! is called) the method has already been called, so your stub will never catch anything. - Maur?cio Linhares http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr On Thu, Aug 20, 2009 at 5:03 PM, BallaBall wrote: > I have some model with the following validation: > > ?validates_inclusion_of :value, > ? ?:in => I18n.available_locales.map(&:to_s) > > I would think that I would be able to stub out that method in a test > like so: > > it "should accepted any available locale as a value" do > ? ? ?I18n.stub!(:available_locales).and_return(['abc']) > > ? ? ?my_model = MyModel.new( :value => 'abc' ) > > ? ? ?my_model.should have(:no).errors_on(:value) > end > > But it keeps failing. It looks like the I18n inside the model is not > being stubbed correctly?!?! What am I doing wrong? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From balla at sogetthis.com Thu Aug 20 17:07:30 2009 From: balla at sogetthis.com (BallaBall) Date: Thu, 20 Aug 2009 14:07:30 -0700 (PDT) Subject: [rspec-users] RSpec stub/mock I18n In-Reply-To: References: Message-ID: <42c0f67c-3f96-4cee-8e0f-518ca1747686@x5g2000prf.googlegroups.com> Ohhh so when the model is first loaded it has already run the method im trying to stub? On Aug 20, 2:00?pm, Maur?cio Linhares wrote: > When you spec runs (and your stub! is called) the method has already > been called, so your stub will never catch anything. > > - > Maur?cio Linhareshttp://codeshooter.wordpress.com/|http://twitter.com/mauriciojr > > > > On Thu, Aug 20, 2009 at 5:03 PM, BallaBall wrote: > > I have some model with the following validation: > > > ?validates_inclusion_of :value, > > ? ?:in => I18n.available_locales.map(&:to_s) > > > I would think that I would be able to stub out that method in a test > > like so: > > > it "should accepted any available locale as a value" do > > ? ? ?I18n.stub!(:available_locales).and_return(['abc']) > > > ? ? ?my_model = MyModel.new( :value => 'abc' ) > > > ? ? ?my_model.should have(:no).errors_on(:value) > > end > > > But it keeps failing. It looks like the I18n inside the model is not > > being stubbed correctly?!?! What am I doing wrong? > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From mauricio.linhares at gmail.com Thu Aug 20 18:12:38 2009 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Thu, 20 Aug 2009 19:12:38 -0300 Subject: [rspec-users] RSpec stub/mock I18n In-Reply-To: <42c0f67c-3f96-4cee-8e0f-518ca1747686@x5g2000prf.googlegroups.com> References: <42c0f67c-3f96-4cee-8e0f-518ca1747686@x5g2000prf.googlegroups.com> Message-ID: Yes, so it's useless trying to stub it. Tools like Remarkable will let you spec that validates call in a better way -> http://github.com/carlosbrando/remarkable/ - Maur?cio Linhares http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr On Thu, Aug 20, 2009 at 6:07 PM, BallaBall wrote: > Ohhh so when the model is first loaded it has already run the method > im trying to stub? > From celoserpa at gmail.com Thu Aug 20 20:00:40 2009 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Thu, 20 Aug 2009 19:00:40 -0500 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline Message-ID: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> Hello list, I'm working in a big project in the company I'm working on as a "BDD tech lead", this means I'm leading the implementation of BDD in ongoing projects, most of them did not use BDD from the start. I implemented the policy of "Only commit if all your tests are passing", this in all tests abstraction levels: From Cucumber features , scenarios, steps and rspec specs. The point of this rule is: "Never commit partial code". If it's not done/fully working (as the feature/specs say it should), don't commit it. However, a co-worker of mine came to me and said that partial commits are needed to share code. I don't agree with that, I think we can use patches or branches to do that (like a development branch) but at least one branch should have only stabe/deliverable code. For patches, however, he mentioned that we might have conflicts/code duplication, where the guy who shares the patches will have problems later on when pulling from the server (he already had part of the code that was committed). What do you think? I'm looking for some enlightenment! Any contributions welcome. Marcelo. From dchelimsky at gmail.com Thu Aug 20 20:14:15 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 20 Aug 2009 19:14:15 -0500 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> Message-ID: <57c63afe0908201714oee514c5w7d2bff2e8e6db6a3@mail.gmail.com> On Thu, Aug 20, 2009 at 7:00 PM, Marcelo de Moraes Serpa wrote: > Hello list, > > I'm working in a big project in the company I'm working on as a "BDD > tech lead", this means I'm leading the implementation of BDD in > ongoing projects, most of them did not use BDD from the start. > > I implemented the policy of "Only commit if all your tests are > passing", this in all tests abstraction levels: From Cucumber features > , scenarios, steps and rspec specs. > > The point of this rule is: "Never commit partial code". If it's not > done/fully working (as the feature/specs say it should), don't commit > it. > > However, a co-worker of mine came to me and said that partial commits > are needed to share code. I don't agree with that, I think we can use > patches or branches to do that (like a development branch) but at > least one branch should have only stabe/deliverable code. > > For patches, however, he mentioned that we might have conflicts/code > duplication, where the guy who shares the patches will have problems > later on when pulling from the server (he already had part of the code > that was committed). > > What do you think? I'm looking for some enlightenment! Any > contributions welcome. My approach, which is not mine originally, nor very unique, is follows: All developer specs (RSpec) should always be passing. Previously passing customer specs should continue passing. Customer specs for features in development are allowed to fail. You can enforce those rules in a CI build in any number of ways. Tagging features in development as @in_development, for example, and not running those as part of the CI build, or running them separately but allowing them to fail without considering the build a failed build. That all make sense? > > Marcelo. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Thu Aug 20 21:21:11 2009 From: ben at benmabey.com (Ben Mabey) Date: Thu, 20 Aug 2009 19:21:11 -0600 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: <57c63afe0908201714oee514c5w7d2bff2e8e6db6a3@mail.gmail.com> References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> <57c63afe0908201714oee514c5w7d2bff2e8e6db6a3@mail.gmail.com> Message-ID: <4A8DF687.20105@benmabey.com> David Chelimsky wrote: > On Thu, Aug 20, 2009 at 7:00 PM, Marcelo de Moraes > Serpa wrote: > >> Hello list, >> >> I'm working in a big project in the company I'm working on as a "BDD >> tech lead", this means I'm leading the implementation of BDD in >> ongoing projects, most of them did not use BDD from the start. >> >> I implemented the policy of "Only commit if all your tests are >> passing", this in all tests abstraction levels: From Cucumber features >> , scenarios, steps and rspec specs. >> >> The point of this rule is: "Never commit partial code". If it's not >> done/fully working (as the feature/specs say it should), don't commit >> it. >> >> However, a co-worker of mine came to me and said that partial commits >> are needed to share code. I don't agree with that, I think we can use >> patches or branches to do that (like a development branch) but at >> least one branch should have only stabe/deliverable code. >> >> For patches, however, he mentioned that we might have conflicts/code >> duplication, where the guy who shares the patches will have problems >> later on when pulling from the server (he already had part of the code >> that was committed). >> >> What do you think? I'm looking for some enlightenment! Any >> contributions welcome. >> We use remote branches (we use git) to collaborate and share code that isn't ready to be merged down to our mainline. Then when that branch is ready to be merged down we use git rebase --interactive to squash all the wip/garbage commits. This gives you the best of both worlds IMO. Using rebase can be dangerous though as it rewrites the repo's history. That means once someone rebases everyone will have to delete that branch and pull it again if they want to continue working on it. That is why we generally wait until the work on the branch is don't before we rebase. > > My approach, which is not mine originally, nor very unique, is follows: > > All developer specs (RSpec) should always be passing. > Previously passing customer specs should continue passing. > Customer specs for features in development are allowed to fail. > > You can enforce those rules in a CI build in any number of ways. > Tagging features in development as @in_development, for example, and > not running those as part of the CI build, or running them separately > but allowing them to fail without considering the build a failed > build. > > That all make sense? > Cucumber actually ships now with some additional rake tasks to help with this: rake cucumber # Alias for cucumber:ok rake cucumber:all # Run all features rake cucumber:ok # Run features that should pass rake cucumber:wip # Run features that are being worked on -Ben From sfeley at gmail.com Thu Aug 20 22:28:06 2009 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 20 Aug 2009 22:28:06 -0400 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> Message-ID: <1fb4df0908201928xf296f6du1a2f6372fc3330fa@mail.gmail.com> On Thu, Aug 20, 2009 at 8:00 PM, Marcelo de Moraes Serpa wrote: > > However, a co-worker of mine came to me and said that partial commits > are needed to share code. I don't agree with that, I think we can use > patches or branches to do that (like a development branch) but at > least one branch should have only stabe/deliverable code. First: you keep using that word. I do not think it means what you think it means. You can't really have a "partial commit." Commits are an atomic unit of version control; you've changed the state of the repository or you haven't. The *size* of a commit may vary, but a commit that's just part of everything you're working on is still a commit. And a commit to a development branch is a commit, too. It sounds to me like you're using "commit" not to mean "any update that alters the history of the repository," but an update to the official master branch (or trunk, if you're using Subversion). That's a bit more specialized, and I personally would advise a better word or phrase for it. "Push to master" works for me. It may be that some of your confusion with your team may just be a matter of unclear terminology. > For patches, however, he mentioned that we might have conflicts/code > duplication, where the guy who shares the patches will have problems > later on when pulling from the server (he already had part of the code > that was committed). Second: have you tried Git? With all this talk of patch conflicts, and "the server," and spotlighting development branches like they're a big deal, I'm guessing you're using Subversion or something else where branching and merging is a pain. Once I learned to appreciate how easy branches were in Git, and to use them properly and frequently, a lot of these sorts of problems just evaporated. (I've heard the same is true in Mercurial too, FWIW.) Get a proper tool that encourages branching and experimentation -- and then encourage people to branch and experiment. Your policy of having an "all green" master branch is truly a good one, but if it discourages people from _using_ the source control on a constant basis then something needs to be made easier. I personally can't imagine using Git but refusing to commit my changes to my personal repository until everything worked. I commit _constantly._ Mostly for the sake of being able to easily undo stuff. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From grail at velocitynet.com.au Thu Aug 20 22:54:03 2009 From: grail at velocitynet.com.au (grail at velocitynet.com.au) Date: Fri, 21 Aug 2009 12:54:03 +1000 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline Message-ID: <9393920e67af709e72007da63d8324e8@mail.velocitynet.com.au> "Partial Commits" are not needed to share code. That is why you use branches in Subversion: to provide a place for people working on a common development thread to put their work when it isn't ready for trunk. You still stick to "only commit when green". No broken code goes into the repository. Branching and merging in Subversion is fraught with peril, it's better in the long run to use git. Subversion keeps track of versions of documents, and merging involves you making decisions about which version of a document is more recent. Git tracks diffs between documents, so merging branches is simply a case of collecting all the changes together in one place. It is quite possible to use git-svn to do local (ie: on the developer's workstation) "non-green" commits in case someone wants to try different ways of not solving a problem. The only catch is to remember to track a branch on subversion using it's own specific branch in the git repository, and only use rebase to bring patches in and out to the other git branches into that svn-tracking branch. When you share a patch you will branch from trunk, write the patch on that branch, merge that in with trunk. Just keep in mind that subversion deals in versioning entire documents, while git tracks changes you make. From celoserpa at gmail.com Fri Aug 21 11:14:07 2009 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Fri, 21 Aug 2009 10:14:07 -0500 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: <1fb4df0908201928xf296f6du1a2f6372fc3330fa@mail.gmail.com> References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> <1fb4df0908201928xf296f6du1a2f6372fc3330fa@mail.gmail.com> Message-ID: <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> Thanks guys, Well, I think that one of the approaches would be to setup the integration server to run only "the features that should pass", and ignore the other ones (using tagging). @Stephen: Sorry, I used the wrong term. I did not mean partial commit in the technical term, but a "partial feature commit", which is committing a feature that is breaking or not fully working somehow to the main/stable line (and with a comment like "Feature x partially finished). **One good use-case of this, however, is when another developer needs code/artifacts you have wrote and you need to commit, but your commit does not represent the completion of a feature/step/spec.** <-- Here's the use case we are trying to come up with a solution for. I'm using git, actually I love git. However, we started with svn unfortunately and only now the management saw the benefits of git and we migrated. However, 99% of the developers of this project does not know how to use git, and with this I mean they don't know what branches are actually and how they work. The investment of time to teach them this would ruin this project, which is already behind the schedule. So, for now, we are in a "transition phase", using git in a half-***** way, with only the master branch. However, being master the only branch, I think the code there should be stable and have only solid code. Committing partially done or code that might break features would put us in chaos again, and nobody would really look into the CC.rb logs again (since they would fail all the time, as CC.rb is using this master branch too). My co-worder suggested running the whole test suite **only** in staging (we only update staging when all the features are supposedly working) but this would defeat the whole purpose of BDD/Continuous Integration, which must be a support tool in the process and not a specific phase. So, for this specific situation, I thought on other ways we could share unstable code (code that might break tests) without committing to the master branch -- which include patches or even just copy and paste. Or maybe we should just use branches, but won't be easy to convince the management to do this now. Does that make sense? Thanks again, Marcelo. On Thu, Aug 20, 2009 at 9:28 PM, Stephen Eley wrote: > On Thu, Aug 20, 2009 at 8:00 PM, Marcelo de Moraes > Serpa wrote: >> >> However, a co-worker of mine came to me and said that partial commits >> are needed to share code. I don't agree with that, I think we can use >> patches or branches to do that (like a development branch) but at >> least one branch should have only stabe/deliverable code. > > First: you keep using that word. ?I do not think it means what you > think it means. > > You can't really have a "partial commit." ?Commits are an atomic unit > of version control; you've changed the state of the repository or you > haven't. ?The *size* of a commit may vary, but a commit that's just > part of everything you're working on is still a commit. ?And a commit > to a development branch is a commit, too. > > It sounds to me like you're using "commit" not to mean "any update > that alters the history of the repository," but an update to the > official master branch (or trunk, if you're using Subversion). ?That's > a bit more specialized, and I personally would advise a better word or > phrase for it. ?"Push to master" works for me. ?It may be that some of > your confusion with your team may just be a matter of unclear > terminology. > > >> For patches, however, he mentioned that we might have conflicts/code >> duplication, where the guy who shares the patches will have problems >> later on when pulling from the server (he already had part of the code >> that was committed). > > Second: have you tried Git? ?With all this talk of patch conflicts, > and "the server," and spotlighting development branches like they're a > big deal, I'm guessing you're using Subversion or something else where > branching and merging is a pain. ?Once I learned to appreciate how > easy branches were in Git, and to use them properly and frequently, a > lot of these sorts of problems just evaporated. ?(I've heard the same > is true in Mercurial too, FWIW.) > > Get a proper tool that encourages branching and experimentation -- and > then encourage people to branch and experiment. ?Your policy of having > an "all green" master branch is truly a good one, but if it > discourages people from _using_ the source control on a constant basis > then something needs to be made easier. ?I personally can't imagine > using Git but refusing to commit my changes to my personal repository > until everything worked. ?I commit _constantly._ ?Mostly for the sake > of being able to easily undo stuff. > > > > > -- > Have Fun, > ? Steve Eley (sfeley at gmail.com) > ? ESCAPE POD - The Science Fiction Podcast Magazine > ? http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From george at benevolentcode.com Fri Aug 21 12:15:39 2009 From: george at benevolentcode.com (George Anderson) Date: Fri, 21 Aug 2009 12:15:39 -0400 Subject: [rspec-users] Problem Comparing Dates Message-ID: <782d66f30908210915l6f22c59djaf640c05ec245c88@mail.gmail.com> I'm having an issue comparing two seemingly equivalent dates: spec: it "sets the user's session_key_updated_at" do now = Time.zone.now Timecop.freeze(now) do verify_user @verified_user.session_key_updated_at.should == now end end output: sets the user's session_key_updated_at expected: Fri, 21 Aug 2009 16:08:51 UTC +00:00, got: Fri, 21 Aug 2009 16:08:51 UTC +00:00 (using ==) They're identical, no? They're the same class, too: now.class: ActiveSupport::TimeWithZone @verified_user.session_key_updated_at.class: ActiveSupport::TimeWithZone Any ideas on what's going on or what I'm doing wrong? For the record: > spec -v rspec 1.2.7 > script/about About your application's environment Ruby version 1.8.6 (i686-darwin9.1.0) RubyGems version 1.3.5 Rack version 1.0 Rails version 2.3.2 Active Record version 2.3.2 Action Pack version 2.3.2 Active Resource version 2.3.2 Action Mailer version 2.3.2 Active Support version 2.3.2 Environment development Database adapter sqlite3 Database schema version 20090812181104 Thanks, /g -- George Anderson BenevolentCode LLC george at benevolentcode.com From tom at experthuman.com Fri Aug 21 12:26:55 2009 From: tom at experthuman.com (Tom Stuart) Date: Fri, 21 Aug 2009 17:26:55 +0100 Subject: [rspec-users] Problem Comparing Dates In-Reply-To: <782d66f30908210915l6f22c59djaf640c05ec245c88@mail.gmail.com> References: <782d66f30908210915l6f22c59djaf640c05ec245c88@mail.gmail.com> Message-ID: On 21 Aug 2009, at 17:15, George Anderson wrote: > expected: Fri, 21 Aug 2009 16:08:51 UTC +00:00, > got: Fri, 21 Aug 2009 16:08:51 UTC +00:00 (using ==) > They're identical, no? Not necessarily -- Time instances are microsecond precision, so two of them can differ (in microseconds) but have the same string representation (which only shows seconds). See what the #usec method gives you for each of the times. Cheers, -Tom From rick.denatale at gmail.com Fri Aug 21 13:05:24 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 21 Aug 2009 13:05:24 -0400 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> <1fb4df0908201928xf296f6du1a2f6372fc3330fa@mail.gmail.com> <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> Message-ID: On Fri, Aug 21, 2009 at 11:14 AM, Marcelo de Moraes Serpa wrote: > we started with svn > unfortunately and only now the management saw the benefits of git and > we migrated. However, 99% of the developers of this project does not > know how to use git, and with this I mean they don't know what > branches are actually and how they work. The investment of time to > teach them this would ruin this project, which is already behind the > schedule. Ahh, the old "Our problems are so bad that we can't afford to address them." Perhaps the reason you are behind schedule is that your tools/process are holding you back. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From sfeley at gmail.com Fri Aug 21 13:17:00 2009 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 21 Aug 2009 13:17:00 -0400 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> <1fb4df0908201928xf296f6du1a2f6372fc3330fa@mail.gmail.com> <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> Message-ID: <1fb4df0908211017t74cf0dedpba6caf3aed870154@mail.gmail.com> On Fri, Aug 21, 2009 at 11:14 AM, Marcelo de Moraes Serpa wrote: > > I'm using git, actually I love git. However, we started with svn > unfortunately and only now the management saw the benefits of git and > we migrated. However, 99% of the developers of this project does not > know how to use git, and with this I mean they don't know what > branches are actually and how they work. The investment of time to > teach them this would ruin this project, which is already behind the > schedule. Sounds like you have a risk assessment decision to make. You are *already* introducing changes to a late project: you moved to Git, you're trying to implement CI, you're talking about version control policy. Given that -- which is more likely to pose a greater threat to your delivery schedule? 1.) Taking an hour for a mandatory lunch-and-learn, buying everyone pizza, and saying "Listen up folks. We're about to introduce our friends 'git checkout -b' and 'git merge', and then I'm going to tell you the version control policies, and you _will_ follow them or you get to be the one who babysits the continuous integration server." (Really, you _can_ explain Git branching in a few minutes. Hell, just show everyone the Peepcode screencast.) 2.) Stopping short of introducing changes that are responsive to the changes you've already made, and allowing people to continue the development practices that made your project late -- only now with tools they're unfamiliar with and using badly. I really don't think the answer to this is automatic. Sometimes #2 _is_ the right answer. But if that's the case, you should probably also abandon any attempt to maintain continuous integration policies. What you've just said then is that this is the wrong time to make things better. So stop. Don't make any decisions, don't change anything. And make sure you're out of the blame path for the project's schedule. > Or maybe we should just use branches, but won't be easy to convince > the management to do this now. Question for you: is "management" committing code? If not, why should you need to convince them of anything? Don't ask permission. Branching doesn't need any extra budget. Just start doing it. Follow good practices, and let your teammates know what you're doing and why. You guys are there to do your jobs. Management's job is to empower you to do so. If this is the sort of company where you have to raise your hand every time you need to go to the bathroom, then you have issues a continuous integration server won't solve. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From george at benevolentcode.com Fri Aug 21 13:44:02 2009 From: george at benevolentcode.com (George Anderson) Date: Fri, 21 Aug 2009 13:44:02 -0400 Subject: [rspec-users] Problem Comparing Dates In-Reply-To: References: <782d66f30908210915l6f22c59djaf640c05ec245c88@mail.gmail.com> Message-ID: <782d66f30908211044y3f72f2d2x401dcca5f6a9ff68@mail.gmail.com> Spot on, Tom. Thanks. For the (google) record: Time.usec Returns just the number of microseconds for the given time. ActiveRecord datetime attributes ignore microseconds (at least with the SQLite adapter). In my case: now.usec: 991786 @verified_user.session_key_updated_at.usec: 0 To fix the spec, don't use Time.now for the comparison: it "sets the user's session_key_updated_at" do now = Time.zone.local(2008, 9, 1, 12, 0, 0) Timecop.freeze(now) do verify_user @verified_user.session_key_updated_at.should == now end end Cheers, /g -- George Anderson BenevolentCode LLC O: (410) 461-7553 C: (410) 218-5185 george at benevolentcode.com On Fri, Aug 21, 2009 at 12:26 PM, Tom Stuart wrote: > On 21 Aug 2009, at 17:15, George Anderson wrote: >> >> expected: Fri, 21 Aug 2009 16:08:51 UTC +00:00, >> ? ? ? ?got: Fri, 21 Aug 2009 16:08:51 UTC +00:00 (using ==) >> They're identical, no? > > Not necessarily -- Time instances are microsecond precision, so two of them > can differ (in microseconds) but have the same string representation (which > only shows seconds). See what the #usec method gives you for each of the > times. > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From orengolan at gmail.com Fri Aug 21 16:13:18 2009 From: orengolan at gmail.com (oren) Date: Fri, 21 Aug 2009 13:13:18 -0700 (PDT) Subject: [rspec-users] running rake spec:remote Message-ID: When running autotest only 'rake spec' is running and I want it to run 'rake spec:remote' as well. How do i achieve that? thanks From rick.denatale at gmail.com Fri Aug 21 16:44:36 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 21 Aug 2009 16:44:36 -0400 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: <1fb4df0908211017t74cf0dedpba6caf3aed870154@mail.gmail.com> References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> <1fb4df0908201928xf296f6du1a2f6372fc3330fa@mail.gmail.com> <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> <1fb4df0908211017t74cf0dedpba6caf3aed870154@mail.gmail.com> Message-ID: On Fri, Aug 21, 2009 at 1:17 PM, Stephen Eley wrote: > Question for you: is "management" committing code? > > If not, why should you need to convince them of anything? ?Don't ask > permission. ?Branching doesn't need any extra budget. ?Just start > doing it. ?Follow good practices, and let your teammates know what > you're doing and why. Actually, the way I read it was that management was already on board with git and approved converting over to it which they have, but it's the cow orkers and their lack of training which is "preventing" them from actually benefitting from it. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From sfeley at gmail.com Fri Aug 21 17:08:39 2009 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 21 Aug 2009 17:08:39 -0400 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> <1fb4df0908201928xf296f6du1a2f6372fc3330fa@mail.gmail.com> <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> <1fb4df0908211017t74cf0dedpba6caf3aed870154@mail.gmail.com> Message-ID: <1fb4df0908211408k340883ffyde8ededd98b45025@mail.gmail.com> On Fri, Aug 21, 2009 at 4:44 PM, Rick DeNatale wrote: > > Actually, the way I read it was that management was already on board > with git and approved converting over to it which they have, but it's > the cow orkers and their lack of training which is "preventing" them > from actually benefitting from it. He specifically said he didn't think he could "convince the management" to allow using branches in git. A couple months ago I read _Joel on Software._ I'd resisted it for a while because I'd listened to Joel Spolsky's podcast for a while and thought he was too much of a blowhard. But the book really was good. This thread reminded me of one of the essays in it, but I couldn't remember what. I just dug around and found it: "Getting Things Done When You're Only a Grunt" http://www.joelonsoftware.com/articles/fog0000000332.html -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From ed.ruder at gmail.com Fri Aug 21 17:51:10 2009 From: ed.ruder at gmail.com (Ed Ruder) Date: Fri, 21 Aug 2009 14:51:10 -0700 (PDT) Subject: [rspec-users] [Rails] How to mock/stub link_to from a Rails helper spec? In-Reply-To: <339800360908201502n62b40634k285837ab6fd9f44c@mail.gmail.com> References: <339800360908201502n62b40634k285837ab6fd9f44c@mail.gmail.com> Message-ID: On Aug 20, 3:02?pm, Mike Sassak wrote: > On Thu, Aug 20, 2009 at 3:00 PM, Ed Ruder wrote: > > All, > > > In a Rails helper spec, how do I stub or mock the 'link_to' method? > > When i step into link_to, self.class is > > > Spec::Rails::Example::HelperExampleGroup::Subclass_1::Subclass_5::Subclass_ 1. > > > What I'm trying to do is stub link_to and check that its parameters > > are correct--i.e., that a helper method is properly constructing the > > parameters to link_to. The work-around (and what seems to me to be a > > more awkward approach) is to grep the output of the helper method for > > a link with a proper href property. > > Hi Ed, > > Verifying the output of the helper method isn't a work around at all. > Rather, it sounds like exactly what you should be doing in this case. Think > of the helper method as a black box--you only care what comes out, not, > necessarily, how it got there. Verifying output in this way rather than the > implementation makes your specs more resilient in the face of changes, (what > would happen, for example, if the calling semantics of link_to changed in a > newer versions of Rails?), and is one of the central tenets of test/behavior > driven development. RSpec already has lots of methods to verify HTML, too. > See the Expectations section athttp://rspec.info/rails/writing/views.htmlformore details. > > Mike Mike, Sounds OK. Thanks. Ed From lists at ruby-forum.com Sat Aug 22 08:09:27 2009 From: lists at ruby-forum.com (=?utf-8?Q?S=c5=82awosz_S=c5=82awi=c5=84ski?=) Date: Sat, 22 Aug 2009 14:09:27 +0200 Subject: [rspec-users] [Cucumber] testing emails with celerity - the best solution Message-ID: <635b2f5cd3d5a3ff66930536707cf072@ruby-forum.com> Hi, I'm trying to test emails with Celerity. The problem is, because Celerity browser uses environment 'cucumber', but Cucubmer runs in 'test'. Emails steps are running in 'test', so it is impossible to check mails send in 'cucumber'. I think, I can use webrat for steps with email sending, and cucmber for others (i.e. wiht Ajax). But maybe there is more logical and elegant solution? S?awosz -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Sat Aug 22 18:01:39 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 22 Aug 2009 23:01:39 +0100 Subject: [rspec-users] [Cucumber] testing emails with celerity - the best solution In-Reply-To: <635b2f5cd3d5a3ff66930536707cf072@ruby-forum.com> References: <635b2f5cd3d5a3ff66930536707cf072@ruby-forum.com> Message-ID: <121CE0D7-D880-40F0-BF69-676E56E24748@mattwynne.net> On 22 Aug 2009, at 13:09, S?awosz S?awi?ski wrote: > Hi, > I'm trying to test emails with Celerity. The problem is, because > Celerity browser uses environment 'cucumber', but Cucubmer runs in > 'test'. Emails steps are running in 'test', so it is impossible to > check > mails send in 'cucumber'. I think, I can use webrat for steps with > email > sending, and cucmber for others (i.e. wiht Ajax). But maybe there is > more logical and elegant solution? I'm not sure, but I think it's more likely the problem is that your tests are running in a different process to the app you're testing, so the usual railsey mail testing stuff doesn't work. We got around this by writing the emails to disk, then having the tests check the files on disk to validate the emails. Could that work for you? From matt at mattwynne.net Sat Aug 22 18:16:19 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 22 Aug 2009 23:16:19 +0100 Subject: [rspec-users] Sharing code and still keeping a "only commit if all is green" discipline In-Reply-To: <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> References: <1e5bcefd0908201700x310523e3vc4c035af1d5f7db0@mail.gmail.com> <1fb4df0908201928xf296f6du1a2f6372fc3330fa@mail.gmail.com> <1e5bcefd0908210814p6d1281b3s3b06056f927eae1a@mail.gmail.com> Message-ID: <1CDBCFDB-9016-4227-B2DB-69CBFC317E62@mattwynne.net> On 21 Aug 2009, at 16:14, Marcelo de Moraes Serpa wrote: > Thanks guys, > > Well, I think that one of the approaches would be to setup the > integration server to run only "the features that should pass", and > ignore the other ones (using tagging). This is good practice anyway - the @wip thing is a really useful idea so you can separate regression tests from development feedback tests. This really means you need to run two builds though - one on the development branch that might still have @wip hiding in it, and another one on the 'stable' branch that should not have any @wip left in it. > @Stephen: Sorry, I used the wrong term. I did not mean partial commit > in the technical term, but a "partial feature commit", which is > committing a feature that is breaking or not fully working somehow to > the main/stable line (and with a comment like "Feature x partially > finished). **One good use-case of this, however, is when another > developer needs code/artifacts you have wrote and you need to commit, > but your commit does not represent the completion of a > feature/step/spec.** <-- Here's the use case we are trying to come up > with a solution for. > > I'm using git, actually I love git. However, we started with svn > unfortunately and only now the management saw the benefits of git and > we migrated. However, 99% of the developers of this project does not > know how to use git, and with this I mean they don't know what > branches are actually and how they work. The investment of time to > teach them this would ruin this project, which is already behind the > schedule. This will not ruin the project - it takes a few minutes to learn, honestly. Get everyone on the team to read this: http://blog.hasmanythrough.com/2008/12/18/agile-git-and-the-story-branch-pattern Then, get them all to install the git_remote_branch gem > So, for now, we are in a "transition phase", using git in a half-***** > way, with only the master branch. However, being master the only > branch, I think the code there should be stable and have only solid > code. Committing partially done or code that might break features > would put us in chaos again, and nobody would really look into the > CC.rb logs again (since they would fail all the time, as CC.rb is > using this master branch too). You're right here. I think you have two choices: use @wip tags to hide partially complete scenarios from the build, or use branches. I think @wip might be better for you as it means you won't have to teach people how to use branches. However it does leave you with the problem that people might forget to remove the @wip tags... More on that in a moment. > My co-worder suggested running the whole test suite **only** in > staging (we only update staging when all the features are supposedly > working) but this would defeat the whole purpose of BDD/Continuous > Integration, which must be a support tool in the process and not a > specific phase. What we do at songkick, is maintain a 'staging' branch which we merge into when we have a green build of the master branch. Our cap tasks for staging deployment use this branch (I think you have to call it tag or somesuch in capistrano-speak). You don't have to touch this branch all that often, and when you do, the merges should be easy since nobody should really be making changes on the staging branch. This is the branch which you can run your 'no @wip' build on that will fail if there are any @wip tags left. > So, for this specific situation, I thought on other ways we could > share unstable code (code that might break tests) without committing > to the master branch -- which include patches or even just copy and > paste. > > Or maybe we should just use branches, but won't be easy to convince > the management to do this now. > > Does that make sense? > > Thanks again, > > Marcelo. > > On Thu, Aug 20, 2009 at 9:28 PM, Stephen Eley wrote: >> On Thu, Aug 20, 2009 at 8:00 PM, Marcelo de Moraes >> Serpa wrote: >>> >>> However, a co-worker of mine came to me and said that partial >>> commits >>> are needed to share code. I don't agree with that, I think we can >>> use >>> patches or branches to do that (like a development branch) but at >>> least one branch should have only stabe/deliverable code. >> >> First: you keep using that word. I do not think it means what you >> think it means. >> >> You can't really have a "partial commit." Commits are an atomic unit >> of version control; you've changed the state of the repository or you >> haven't. The *size* of a commit may vary, but a commit that's just >> part of everything you're working on is still a commit. And a commit >> to a development branch is a commit, too. >> >> It sounds to me like you're using "commit" not to mean "any update >> that alters the history of the repository," but an update to the >> official master branch (or trunk, if you're using Subversion). >> That's >> a bit more specialized, and I personally would advise a better word >> or >> phrase for it. "Push to master" works for me. It may be that some >> of >> your confusion with your team may just be a matter of unclear >> terminology. >> >> >>> For patches, however, he mentioned that we might have conflicts/code >>> duplication, where the guy who shares the patches will have problems >>> later on when pulling from the server (he already had part of the >>> code >>> that was committed). >> >> Second: have you tried Git? With all this talk of patch conflicts, >> and "the server," and spotlighting development branches like >> they're a >> big deal, I'm guessing you're using Subversion or something else >> where >> branching and merging is a pain. Once I learned to appreciate how >> easy branches were in Git, and to use them properly and frequently, a >> lot of these sorts of problems just evaporated. (I've heard the same >> is true in Mercurial too, FWIW.) >> >> Get a proper tool that encourages branching and experimentation -- >> and >> then encourage people to branch and experiment. Your policy of >> having >> an "all green" master branch is truly a good one, but if it >> discourages people from _using_ the source control on a constant >> basis >> then something needs to be made easier. I personally can't imagine >> using Git but refusing to commit my changes to my personal repository >> until everything worked. I commit _constantly._ Mostly for the sake >> of being able to easily undo stuff. >> >> >> >> >> -- >> Have Fun, >> Steve Eley (sfeley at gmail.com) >> ESCAPE POD - The Science Fiction Podcast Magazine >> http://www.escapepod.org >> _______________________________________________ >> 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 chs at proactive.or.at Sun Aug 23 05:51:59 2009 From: chs at proactive.or.at (Christoph Schiessl) Date: Sun, 23 Aug 2009 11:51:59 +0200 Subject: [rspec-users] Testing multi-model-form views in Rails 2.3.3 and RSpec 1.2.7 Message-ID: <35EA92F5-88FB-4421-BE14-667EE15BB0C9@proactive.or.at> I have two models in a has_many relationship. The parent model (Invoice) accepts the attributes for it's children (InvoiceItem). The models and the associated controller (InvoicesController) are absolutely standard stuff. This is the significant part of the model code: class Invoice < ActiveRecord::Base has_many :items, :class_name => "InvoiceItem", :dependent => :destroy accepts_nested_attributes_for :items, :allow_destroy => true, :reject_if => Proc.new { |attributes| attributes['quantity'].blank? && attributes['description'].blank? && attributes['unit_price'].blank? } validates_presence_of :recipient, :recipient_street validates_presence_of :recipient_zipcode, :recipient_city end class InvoiceItem < ActiveRecord::Base belongs_to :invoice validates_presence_of :invoice_id validates_presence_of :quantity, :description, :unit_price end Now, here's part of the view I'm trying to test: <% form_for @invoice, :html => {:multipart => true} do |f| %>

text fields for recipient, recipient_street, recipient_zipcode, recipient_city and so on go here

<% f.fields_for :items do |form_item| %>

text fields for quantity, description, unit_price and so on go here

<% # exception is thrown in the next line: %> <% unless form_item.object.new_record? %>
<%= form_item.check_box :_delete %> <%= form_item.label :_delete, "Remove" %> <% end %> <% end %> <% end %> Everything is working just fine if i test it manually in the browser. However, I don't get any rspec tests to work. describe "/invoices/_form.html.erb" do before do @items = [mock_model(InvoiceItem), mock_model(InvoiceItem)] assigns[:invoice] = @invoice = mock_model(Invoice, :items => @items) render end it "renders the invoice form" do response.should have_tag("form") end end When i run `rake spec:views` i get the following error (line numbers do not match with supplied sample code): ActionView::TemplateError in '/invoices/_form.html.erb renders the invoice form' You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.new_record? On line #3 of app/views/invoices/_form.html.erb 1: <% form_for @invoice, :html => {:multipart => true} do |f| %> 2: <% f.fields_for :items do |form_item| %> 3: <% unless form_item.object.new_record? %> 4:
<%= form_item.check_box :_delete %> 5: <%= form_item.label :_delete, "Remove" %> 6: <% end %> app/views/invoices/_form.html.erb:3 app/views/invoices/_form.html.erb:2 app/views/invoices/_form.html.erb:1 /spec/views/invoices/_form.html.erb_spec.rb:7 /usr/local/lib/ruby/1.8/timeout.rb:53:in `timeout' vendor/plugins/rspec/bin/spec:4 So, how do i prevent this? I can't imagine that no one has tried that before. I appreciate ANY advice or pointers greatly! From matt at mattwynne.net Sun Aug 23 07:57:19 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 23 Aug 2009 12:57:19 +0100 Subject: [rspec-users] Testing multi-model-form views in Rails 2.3.3 and RSpec 1.2.7 In-Reply-To: <35EA92F5-88FB-4421-BE14-667EE15BB0C9@proactive.or.at> References: <35EA92F5-88FB-4421-BE14-667EE15BB0C9@proactive.or.at> Message-ID: On 23 Aug 2009, at 10:51, Christoph Schiessl wrote: > I have two models in a has_many relationship. The parent model > (Invoice) accepts the attributes for it's children (InvoiceItem). > The models and the associated controller (InvoicesController) are > absolutely standard stuff. This is the significant part of the model > code: > > class Invoice < ActiveRecord::Base > has_many :items, :class_name => "InvoiceItem", :dependent > => :destroy > > accepts_nested_attributes_for :items, :allow_destroy => > true, :reject_if => Proc.new { |attributes| > attributes['quantity'].blank? && > attributes['description'].blank? && attributes['unit_price'].blank? > } > > validates_presence_of :recipient, :recipient_street > validates_presence_of :recipient_zipcode, :recipient_city > end > > class InvoiceItem < ActiveRecord::Base > belongs_to :invoice > validates_presence_of :invoice_id > validates_presence_of :quantity, :description, :unit_price > end > > Now, here's part of the view I'm trying to test: > > <% form_for @invoice, :html => {:multipart => true} do |f| %> >

text fields for recipient, recipient_street, recipient_zipcode, > recipient_city and so on go here

> <% f.fields_for :items do |form_item| %> >

text fields for quantity, description, unit_price and so on > go here

> <% # exception is thrown in the next line: %> > <% unless form_item.object.new_record? %> >
<%= form_item.check_box :_delete %> > <%= form_item.label :_delete, "Remove" %> > <% end %> > <% end %> > <% end %> > > Everything is working just fine if i test it manually in the browser. > However, I don't get any rspec tests to work. > > describe "/invoices/_form.html.erb" do > before do > @items = [mock_model(InvoiceItem), mock_model(InvoiceItem)] > assigns[:invoice] = @invoice = mock_model(Invoice, :items => > @items) > render > end > it "renders the invoice form" do > response.should have_tag("form") > end > end > > When i run `rake spec:views` i get the following error (line numbers > do not match with supplied sample code): > > ActionView::TemplateError in '/invoices/_form.html.erb renders the > invoice form' > You have a nil object when you didn't expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.new_record? > On line #3 of app/views/invoices/_form.html.erb > > 1: <% form_for @invoice, :html => {:multipart => true} do |f| %> > 2: <% f.fields_for :items do |form_item| %> > 3: <% unless form_item.object.new_record? %> > 4:
<%= form_item.check_box :_delete %> > 5: <%= form_item.label :_delete, "Remove" %> > 6: <% end %> > > app/views/invoices/_form.html.erb:3 > app/views/invoices/_form.html.erb:2 > app/views/invoices/_form.html.erb:1 > /spec/views/invoices/_form.html.erb_spec.rb:7 > /usr/local/lib/ruby/1.8/timeout.rb:53:in `timeout' > vendor/plugins/rspec/bin/spec:4 > > So, how do i prevent this? I can't imagine that no one has tried that > before. I appreciate ANY advice or pointers greatly! I'm just going to make a guess, but I'd say this could be to do with ActiveRecord's association proxy. I've had a few issues in the past trying to fake it with an array, as you've done here. It's ugly, I know, but could you try building a real Invoice instance in the database (use FactoryGirl, Fixjour or something) and adding a couple of InvoiceItems to it in your before block? If that works it would help us to narrow down the problem. cheers, Matt From nick.rutherford at gmail.com Sun Aug 23 11:08:49 2009 From: nick.rutherford at gmail.com (nruth) Date: Sun, 23 Aug 2009 08:08:49 -0700 (PDT) Subject: [rspec-users] rails view spec: delete link matching Message-ID: <64f8905d-f940-49a4-9a8a-8b5bb5743e65@s13g2000yql.googlegroups.com> I'd appreciate suggestions for improving this matcher. Currently it relies on the link saying "Delete", not whether it sends a delete request when used. def have_delete_link(href) simple_matcher("a link href='#{href}'") do |given| selector = have_selector("a[href='#{href}']", :content => "Delete") selector.matches? given end end From dchelimsky at gmail.com Sun Aug 23 12:54:28 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 23 Aug 2009 11:54:28 -0500 Subject: [rspec-users] rails view spec: delete link matching In-Reply-To: <64f8905d-f940-49a4-9a8a-8b5bb5743e65@s13g2000yql.googlegroups.com> References: <64f8905d-f940-49a4-9a8a-8b5bb5743e65@s13g2000yql.googlegroups.com> Message-ID: <57c63afe0908230954u66dd89bao333f42a5cd93cb74@mail.gmail.com> On Sun, Aug 23, 2009 at 10:08 AM, nruth wrote: > I'd appreciate suggestions for improving this matcher. Currently it > relies on the link saying "Delete", not whether it sends a delete > request when used. > > ? ?def have_delete_link(href) > ? ? ?simple_matcher("a link href='#{href}'") do |given| > ? ? ? ?selector = have_selector("a[href='#{href}']", :content => > "Delete") > ? ? ? ?selector.matches? given > ? ? ?end > ? ?end >From the outside, I'd prefer something abstracted to a slightly higher level: response.should have_delete_link_for(resource) and let the matcher figure out what that means. As for the details, there are a number of facilities in webrat that can help with this, but they're all internal to webrat :) What I'd like to be able to do (but can't right now w/ public APIs) is something like this: Spec::Matchers.define :have_delete_link_for do |resource| match do |response| response.links.any? do |link| link.href == url_for(resource) && link.http_method == :delete end end end That won't work because neither rspec nor webrat currently expose the necessary APIs. You _can_ do this right now, however: require 'webrat' Spec::Matchers.define :have_delete_link_for do |resource| match do |response| doc = Webrat::XML.document(response.body) links = Webrat::XML.xpath_search(doc, *Webrat::Link.xpath_search) links.any? do |link| webrat_link = Webrat::Link.new(nil, link) webrat_link.send(:href) == "/#{resource.class.name.underscore.pluralize}/#{resource.id}" && webrat_link.send(:http_method) == :delete end end end This is admittedly foul in many ways, and makes all sorts of assumptions - but it actually works and results in a very expressive matcher. I'll post a request to the webrat tracker to expose some methods that can help with this. But feel free to use and improve on this in the mean time (at your own risk, of course ;) ). Cheers, David From chs at proactive.or.at Sun Aug 23 15:32:55 2009 From: chs at proactive.or.at (Christoph Schiessl) Date: Sun, 23 Aug 2009 21:32:55 +0200 Subject: [rspec-users] Testing multi-model-form views in Rails 2.3.3 and RSpec 1.2.7 In-Reply-To: References: <35EA92F5-88FB-4421-BE14-667EE15BB0C9@proactive.or.at> Message-ID: <3111BCAF-0E68-414F-A5C0-D844DFF1320E@proactive.or.at> I've created a small application to demonstrate the problem in more detail: http://github.com/cs/nested_attributes_spec_demo Just clone it, migrate the sqlite database and run `rake spec`. You'll see 1 failing and 1 succeeding spec. The failing one uses Mocking to the view. The succeeding example tests exactly the same thing but actually creates real records in the database (as Matt suggested). I hope there's a genius somewhere who's able to tell me what I'm doing wrong or to fix the bug. Here's the shell script to get it running (for copy and paste): git clone git://github.com/cs/nested_attributes_spec_demo.git cd nested_attributes_spec_demo rake db:migrate rake db:test:clone rake spec On Aug 23, 2009, at 1:57 PM, Matt Wynne wrote: > > On 23 Aug 2009, at 10:51, Christoph Schiessl wrote: > >> I have two models in a has_many relationship. The parent model >> (Invoice) accepts the attributes for it's children (InvoiceItem). >> The models and the associated controller (InvoicesController) are >> absolutely standard stuff. This is the significant part of the model >> code: >> >> class Invoice < ActiveRecord::Base >> has_many :items, :class_name => "InvoiceItem", :dependent >> => :destroy >> >> accepts_nested_attributes_for :items, :allow_destroy => >> true, :reject_if => Proc.new { |attributes| >> attributes['quantity'].blank? && >> attributes['description'].blank? && attributes['unit_price'].blank? >> } >> >> validates_presence_of :recipient, :recipient_street >> validates_presence_of :recipient_zipcode, :recipient_city >> end >> >> class InvoiceItem < ActiveRecord::Base >> belongs_to :invoice >> validates_presence_of :invoice_id >> validates_presence_of :quantity, :description, :unit_price >> end >> >> Now, here's part of the view I'm trying to test: >> >> <% form_for @invoice, :html => {:multipart => true} do |f| %> >>

text fields for recipient, recipient_street, recipient_zipcode, >> recipient_city and so on go here

>> <% f.fields_for :items do |form_item| %> >>

text fields for quantity, description, unit_price and so on >> go here

>> <% # exception is thrown in the next line: %> >> <% unless form_item.object.new_record? %> >>
<%= form_item.check_box :_delete %> >> <%= form_item.label :_delete, "Remove" %> >> <% end %> >> <% end %> >> <% end %> >> >> Everything is working just fine if i test it manually in the browser. >> However, I don't get any rspec tests to work. >> >> describe "/invoices/_form.html.erb" do >> before do >> @items = [mock_model(InvoiceItem), mock_model(InvoiceItem)] >> assigns[:invoice] = @invoice = mock_model(Invoice, :items => >> @items) >> render >> end >> it "renders the invoice form" do >> response.should have_tag("form") >> end >> end >> >> When i run `rake spec:views` i get the following error (line >> numbers do not match with supplied sample code): >> >> ActionView::TemplateError in '/invoices/_form.html.erb renders the >> invoice form' >> You have a nil object when you didn't expect it! >> You might have expected an instance of ActiveRecord::Base. >> The error occurred while evaluating nil.new_record? >> On line #3 of app/views/invoices/_form.html.erb >> >> 1: <% form_for @invoice, :html => {:multipart => true} do |f| %> >> 2: <% f.fields_for :items do |form_item| %> >> 3: <% unless form_item.object.new_record? %> >> 4:
<%= form_item.check_box :_delete %> >> 5: <%= form_item.label :_delete, "Remove" %> >> 6: <% end %> >> >> app/views/invoices/_form.html.erb:3 >> app/views/invoices/_form.html.erb:2 >> app/views/invoices/_form.html.erb:1 >> /spec/views/invoices/_form.html.erb_spec.rb:7 >> /usr/local/lib/ruby/1.8/timeout.rb:53:in `timeout' >> vendor/plugins/rspec/bin/spec:4 >> >> So, how do i prevent this? I can't imagine that no one has tried that >> before. I appreciate ANY advice or pointers greatly! > > I'm just going to make a guess, but I'd say this could be to do with > ActiveRecord's association proxy. I've had a few issues in the past > trying to fake it with an array, as you've done here. > > It's ugly, I know, but could you try building a real Invoice > instance in the database (use FactoryGirl, Fixjour or something) and > adding a couple of InvoiceItems to it in your before block? If that > works it would help us to narrow down the problem. > > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Sun Aug 23 15:38:26 2009 From: ben at benmabey.com (Ben Mabey) Date: Sun, 23 Aug 2009 13:38:26 -0600 Subject: [rspec-users] [Cucumber] testing emails with celerity - the best solution In-Reply-To: <121CE0D7-D880-40F0-BF69-676E56E24748@mattwynne.net> References: <635b2f5cd3d5a3ff66930536707cf072@ruby-forum.com> <121CE0D7-D880-40F0-BF69-676E56E24748@mattwynne.net> Message-ID: <4A919AB2.7060808@benmabey.com> Matt Wynne wrote: > > On 22 Aug 2009, at 13:09, S?awosz S?awi?ski wrote: > >> Hi, >> I'm trying to test emails with Celerity. The problem is, because >> Celerity browser uses environment 'cucumber', but Cucubmer runs in >> 'test'. Emails steps are running in 'test', so it is impossible to check >> mails send in 'cucumber'. I think, I can use webrat for steps with email >> sending, and cucmber for others (i.e. wiht Ajax). But maybe there is >> more logical and elegant solution? > > I'm not sure, but I think it's more likely the problem is that your > tests are running in a different process to the app you're testing, so > the usual railsey mail testing stuff doesn't work. > > We got around this by writing the emails to disk, then having the > tests check the files on disk to validate the emails. Could that work > for you? I agree with Matt. You have three options to address this: 1. Run your server is the same process as Cucumber. If you are using Rails then I'd reccomend the mainline lib: http://github.com/gaffo/mainline/tree/master If you are using another Ruby framework this is trivially done by starting up the server in a new thread. Or.. you can go the route Matt suggested. If you are using email-spec you can use active record mailer or action mailer cache delivery. The ActiveRecord Mailer will work out of the box right now. For the ActionMailer cache lib you will need to use these forks ATM: http://github.com/liangzan/action_mailer_cache_delivery/tree/master http://github.com/liangzan/email-spec/tree/master I plan on merging the above into email spec soon. Even if you are not using email-spec then the above libs would be helpful. -Ben From adam.trepanier at gmail.com Sun Aug 23 21:57:20 2009 From: adam.trepanier at gmail.com (Jesterman81) Date: Sun, 23 Aug 2009 18:57:20 -0700 (PDT) Subject: [rspec-users] undefined method 'mock' Message-ID: <7808cfb7-0752-4c0d-8c33-4224ff02d696@l35g2000vba.googlegroups.com> Greetings, I am trying to use the mock method in rspec and it returns a undefined method 'mock' error. I am using this with the rspec book in chapter 6.3. Do I have to configure rspec someone. I have gem rspec 1.2.8 installed and using ruby 1.8. any help will be appreciated. thanks From dchelimsky at gmail.com Sun Aug 23 23:30:11 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 23 Aug 2009 22:30:11 -0500 Subject: [rspec-users] undefined method 'mock' In-Reply-To: <7808cfb7-0752-4c0d-8c33-4224ff02d696@l35g2000vba.googlegroups.com> References: <7808cfb7-0752-4c0d-8c33-4224ff02d696@l35g2000vba.googlegroups.com> Message-ID: <57c63afe0908232030ta663e99v90cefa8bb42fb6c0@mail.gmail.com> On Sun, Aug 23, 2009 at 8:57 PM, Jesterman81 wrote: > Greetings, > > I am trying to use the mock method in rspec and it returns a undefined > method 'mock' error. ?I am using this with the rspec book in chapter > 6.3. ?Do I have to configure rspec someone. ?I have gem rspec 1.2.8 > installed and using ruby 1.8. > > any help will be appreciated. Please post the example and the error you're getting so we can help you figure it out. Cheers, David > > thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Sun Aug 23 23:32:47 2009 From: ben at benmabey.com (Ben Mabey) Date: Sun, 23 Aug 2009 21:32:47 -0600 Subject: [rspec-users] undefined method 'mock' In-Reply-To: <7808cfb7-0752-4c0d-8c33-4224ff02d696@l35g2000vba.googlegroups.com> References: <7808cfb7-0752-4c0d-8c33-4224ff02d696@l35g2000vba.googlegroups.com> Message-ID: <4A9209DF.8040900@benmabey.com> Jesterman81 wrote: > Greetings, > > I am trying to use the mock method in rspec and it returns a undefined > method 'mock' error. I am using this with the rspec book in chapter > 6.3. Do I have to configure rspec someone. I have gem rspec 1.2.8 > installed and using ruby 1.8. > > any help will be appreciated. > > Please post the failing spec and your spec_helper.rb. Without those it is hard for us to diagnose the problem. -Ben From alexch at gmail.com Mon Aug 24 13:52:35 2009 From: alexch at gmail.com (Alex Chaffee) Date: Mon, 24 Aug 2009 10:52:35 -0700 Subject: [rspec-users] Problem Comparing Floats Message-ID: <7a93bd340908241052g4ffbb4d9r85188b7ed0f407bb@mail.gmail.com> Check out the following gist: http://gist.github.com/173975 It's from a Test-Driven Intro To Ruby class I'm working on. Looks good, right? Not so fast. Check out this spec: it "converts body temperature" do t = @temperature.ctof(37) (t*10).round.should == 986 end Why do we have to round? Cause floating-point math is messed up. If we just follow the pattern and do @temperature.ctof(37).should == 98.6 then the spec fails. Buh? See http://www.ruby-forum.com/topic/169330, especially response http://www.ruby-forum.com/topic/169330#742994 for more detail. Without opening up the whole debate over whether it's "correct" in some language-puritan way, I'd like to propose that the standard RSpec == matcher be rewritten to compare floats only to a certain degree of precision... say, 10 decimal places. That could be augmented by a new "equals_precisely" matcher that does the current == behavior for floats. Why do it that way and not just make a new "equals_approximately" matcher and use it for cases like the above? Because I submit that >99 times out of 100 the expected behavior is for float comparison to match the rules of regular math, not floating point math. The ftoc/ctof example is a good case of this: ftoc(98.6) == 37 but ctof(37) == 98.600000000000008526512829121202. But if I do a puts or an inspect of that float, it says "98.6" so it's very difficult for someone who doesn't know any better (i.e. 90% of Ruby programmers and 99% of Ruby students) to figure out what to do. But if you *do* happen to be doing complicated floating point math then you'll probably know enough to use "equals_approximately", or at least be able to figure that out when your ultra-precise spec starts failing. >> Temperature.new.ctof(37) => 98.6 >> Temperature.new.ctof(37) == 98.6 => false >> "%.30f" % Temperature.new.ctof(37) => "98.600000000000008526512829121202" Thoughts? --- Alex Chaffee - alex at stinky.com - http://alexch.github.com Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch | http://alexch.tumblr.com From alexch at gmail.com Mon Aug 24 13:56:00 2009 From: alexch at gmail.com (Alex Chaffee) Date: Mon, 24 Aug 2009 10:56:00 -0700 Subject: [rspec-users] Problem Comparing Floats In-Reply-To: <7a93bd340908241052g4ffbb4d9r85188b7ed0f407bb@mail.gmail.com> References: <7a93bd340908241052g4ffbb4d9r85188b7ed0f407bb@mail.gmail.com> Message-ID: <7a93bd340908241056hf4f807ck7fd753310fa10eda@mail.gmail.com> ...and, while I was composing that message, Brian sent me the following: > Rspec does provide the be_close matcher. See cheat rspec. @temperature.ctof(37).should be_close(98.6, 0.1) This will work (I'll go update the code now) but it still leaves the problem I mentioned that if you are unfamiliar with the vagaries of floating point math -- or even if you momentarily forget -- then using == will occasionally mysteriously fail. So my proposal remains: can the == matcher do be_close(x, 0.0000000001) for floats? Arguments pro and con? --- Alex Chaffee - alex at stinky.com - http://alexch.github.com Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch | http://alexch.tumblr.com From tom at experthuman.com Mon Aug 24 14:09:58 2009 From: tom at experthuman.com (Tom Stuart) Date: Mon, 24 Aug 2009 19:09:58 +0100 Subject: [rspec-users] Problem Comparing Floats In-Reply-To: <7a93bd340908241056hf4f807ck7fd753310fa10eda@mail.gmail.com> References: <7a93bd340908241052g4ffbb4d9r85188b7ed0f407bb@mail.gmail.com> <7a93bd340908241056hf4f807ck7fd753310fa10eda@mail.gmail.com> Message-ID: <575CCE8F-2FE1-4A1C-A051-069CD6261389@experthuman.com> On 24 Aug 2009, at 18:56, Alex Chaffee wrote: > == will occasionally mysteriously fail. So my proposal remains: can > the == matcher do be_close(x, 0.0000000001) for floats? Arguments pro > and con? The "problem" you describe is with Ruby's == operator, not with RSpec. The == matcher must agree with the semantics of Ruby's == operator in order to do its job. You wouldn't want the expectation "x.should == 42.0" to pass if x == 42.0 was false (for any reason). Cheers, -Tom From dchelimsky at gmail.com Mon Aug 24 14:15:46 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 24 Aug 2009 13:15:46 -0500 Subject: [rspec-users] Problem Comparing Floats In-Reply-To: <7a93bd340908241056hf4f807ck7fd753310fa10eda@mail.gmail.com> References: <7a93bd340908241052g4ffbb4d9r85188b7ed0f407bb@mail.gmail.com> <7a93bd340908241056hf4f807ck7fd753310fa10eda@mail.gmail.com> Message-ID: <57c63afe0908241115n2b0b340dlcbe09d873ab5e56@mail.gmail.com> On Mon, Aug 24, 2009 at 12:56 PM, Alex Chaffee wrote: > ...and, while I was composing that message, Brian sent me the following: > >> Rspec does provide the be_close matcher. See cheat rspec. > > @temperature.ctof(37).should be_close(98.6, 0.1) > > This will work (I'll go update the code now) but it still leaves the > problem I mentioned that if you are unfamiliar with the vagaries of > floating point math -- or even if you momentarily forget -- then using > == will occasionally mysteriously fail. So my proposal remains: can > the == matcher do be_close(x, 0.0000000001) for floats? Arguments pro > and con? What about a helpful error message when "should ==" fails on floats: expected 98.6, got 98.6 The expected and actual may appear to be the same due to Ruby's string representation of floating point numbers. For floating point math, we recommend using the be_close() matcher instead. ??? > > --- > Alex Chaffee - alex at stinky.com - http://alexch.github.com > Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch | > http://alexch.tumblr.com From alexch at gmail.com Mon Aug 24 14:33:16 2009 From: alexch at gmail.com (Alex Chaffee) Date: Mon, 24 Aug 2009 11:33:16 -0700 Subject: [rspec-users] Problem Comparing Floats In-Reply-To: <57c63afe0908241115n2b0b340dlcbe09d873ab5e56@mail.gmail.com> References: <7a93bd340908241052g4ffbb4d9r85188b7ed0f407bb@mail.gmail.com> <7a93bd340908241056hf4f807ck7fd753310fa10eda@mail.gmail.com> <57c63afe0908241115n2b0b340dlcbe09d873ab5e56@mail.gmail.com> Message-ID: <7a93bd340908241133o608ccf72if1e636db89b9dbc0@mail.gmail.com> > What about a helpful error message when "should ==" fails on floats: > > expected 98.6, got 98.6 > > The expected and actual may appear to be the same due to Ruby's string > representation of floating point numbers. For floating point math, we > recommend using the be_close() matcher instead. > > ??? !!! That's a great idea. Even better would be that it only shows up when the to_s values are the same, so it doesn't appear for a real failure. - A From steve at fenestra.com Mon Aug 24 14:25:33 2009 From: steve at fenestra.com (Steve Schafer) Date: Mon, 24 Aug 2009 14:25:33 -0400 Subject: [rspec-users] Problem Comparing Floats In-Reply-To: <7a93bd340908241056hf4f807ck7fd753310fa10eda@mail.gmail.com> References: <7a93bd340908241052g4ffbb4d9r85188b7ed0f407bb@mail.gmail.com> <7a93bd340908241056hf4f807ck7fd753310fa10eda@mail.gmail.com> Message-ID: On Mon, 24 Aug 2009 10:56:00 -0700, you wrote: >This will work (I'll go update the code now) but it still leaves the >problem I mentioned that if you are unfamiliar with the vagaries of >floating point math -- or even if you momentarily forget -- then using >== will occasionally mysteriously fail. So my proposal remains: can >the == matcher do be_close(x, 0.0000000001) for floats? Arguments pro >and con? If you are unfamiliar with the vagaries of floating-point math, then you need to get familiar, or else avoid using floating-point math. The world is already littered with software that doesn't work properly because the programmers didn't understand floating-point math. Perpetuating that kind of ignorance will not make the world a better place. Floating-point math is _inherently_ inexact. Back in my programmer support days, I used to have a standing bet, which I will reiterate now: Show me a technique that you claim "fixes" an inexactness problem with floating-point math. I bet you US$100 that I can supply a trivial example that breaks your fix. -Steve From ghnatiuk at gmail.com Mon Aug 24 15:19:31 2009 From: ghnatiuk at gmail.com (Gregory Hnatiuk) Date: Mon, 24 Aug 2009 12:19:31 -0700 (PDT) Subject: [rspec-users] Class instance variable scope with multiple spec files Message-ID: <0dab19b5-7862-4133-86b1-4ede0ad9e75b@g10g2000yqh.googlegroups.com> What is the expected/intended behavior for the scope of class instance variables when running multiple specs? It appears that setting a class instance variable in one spec will affect it in a second spec run like so: http://gist.github.com/174018 running `spec spec1_spec.rb spec2_spec.rb` or `spec .` from within that directory will fail because the state of the instance variable is maintained. I'm investigating a case where this behavior is affecting the passing/ failing of specs based on the order they are loaded by Rake's FileList, and am looking for a little background before I try to solve it. From dchelimsky at gmail.com Mon Aug 24 15:40:40 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 24 Aug 2009 14:40:40 -0500 Subject: [rspec-users] Class instance variable scope with multiple spec files In-Reply-To: <0dab19b5-7862-4133-86b1-4ede0ad9e75b@g10g2000yqh.googlegroups.com> References: <0dab19b5-7862-4133-86b1-4ede0ad9e75b@g10g2000yqh.googlegroups.com> Message-ID: <57c63afe0908241240kd15d5e0l58f3e0217eba2b75@mail.gmail.com> On Mon, Aug 24, 2009 at 2:19 PM, Gregory Hnatiuk wrote: > What is the expected/intended behavior for the scope of class instance > variables when running multiple specs? > > It appears that setting a class instance variable in one spec will > affect it in a second spec run like so: > > http://gist.github.com/174018 > > running `spec spec1_spec.rb spec2_spec.rb` ?or `spec .` from within > that directory will fail because the state of the instance variable is > maintained. > > I'm investigating a case where this behavior is affecting the passing/ > failing of specs based on the order they are loaded by Rake's > FileList, and am looking for a little background before I try to solve > it. Each example is run in a separate scope, so locals and instance variables are cleaned up by Ruby's gc after each example. All the examples run in one process, however, so globals are a different matter. RSpec will clean up globals that it sets internally, like if you stub methods on class objects, etc. Any global state changed by the spec or the app is really up to you as the spec author to clean up after each example. HTH, David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ghnatiuk at gmail.com Mon Aug 24 17:00:17 2009 From: ghnatiuk at gmail.com (Gregory Hnatiuk) Date: Mon, 24 Aug 2009 14:00:17 -0700 (PDT) Subject: [rspec-users] Class instance variable scope with multiple spec files In-Reply-To: <57c63afe0908241240kd15d5e0l58f3e0217eba2b75@mail.gmail.com> References: <0dab19b5-7862-4133-86b1-4ede0ad9e75b@g10g2000yqh.googlegroups.com> <57c63afe0908241240kd15d5e0l58f3e0217eba2b75@mail.gmail.com> Message-ID: <1be84b60-ff81-4d4b-af74-69a5cde4a47b@c34g2000yqi.googlegroups.com> Thanks. >From a best-practices perspective, should a spec which changes something global change it back afterwards in general, or should it be the responsibility of a given spec to ensure the environment is appropriate itself before running examples (or both)? It seems like changing something global in a spec and not reverting it would be bad form, but it also seems naive to assume that prior specs may not have changed the environment. Greg On Aug 24, 3:40?pm, David Chelimsky wrote: > On Mon, Aug 24, 2009 at 2:19 PM, Gregory Hnatiuk wrote: > > What is the expected/intended behavior for the scope of class instance > > variables when running multiple specs? > > > It appears that setting a class instance variable in one spec will > > affect it in a second spec run like so: > > >http://gist.github.com/174018 > > > running `spec spec1_spec.rb spec2_spec.rb` ?or `spec .` from within > > that directory will fail because the state of the instance variable is > > maintained. > > > I'm investigating a case where this behavior is affecting the passing/ > > failing of specs based on the order they are loaded by Rake's > > FileList, and am looking for a little background before I try to solve > > it. > > Each example is run in a separate scope, so locals and instance > variables are cleaned up by Ruby's gc after each example. > > All the examples run in one process, however, so globals are a > different matter. RSpec will clean up globals that it sets internally, > like if you stub methods on class objects, etc. Any global state > changed by the spec or the app is really up to you as the spec author > to clean up after each example. > > HTH, > David > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Mon Aug 24 18:22:15 2009 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 24 Aug 2009 23:22:15 +0100 Subject: [rspec-users] Class instance variable scope with multiple spec files In-Reply-To: <1be84b60-ff81-4d4b-af74-69a5cde4a47b@c34g2000yqi.googlegroups.com> References: <0dab19b5-7862-4133-86b1-4ede0ad9e75b@g10g2000yqh.googlegroups.com> <57c63afe0908241240kd15d5e0l58f3e0217eba2b75@mail.gmail.com> <1be84b60-ff81-4d4b-af74-69a5cde4a47b@c34g2000yqi.googlegroups.com> Message-ID: <04C5C636-8B51-486D-98CE-295B91DD60F9@mattwynne.net> On 24 Aug 2009, at 22:00, Gregory Hnatiuk wrote: > Thanks. > >> From a best-practices perspective, should a spec which changes > something global change it back afterwards in general, or should it be > the responsibility of a given spec to ensure the environment is > appropriate itself before running examples (or both)? > > It seems like changing something global in a spec and not reverting it > would be bad form, but it also seems naive to assume that prior specs > may not have changed the environment. I always try to put things back as I found them. For example: before(:all) do @original_thread_abort_on_exception = Thread.abort_on_exception Thread.abort_on_exception = true end after(:all) do Thread.abort_on_exception = @original_thread_abort_on_exception end Actually, I wonder what happens with these instance variables in before/after all blocks given what David just said. Do I get the behaviour I'd expect? > > Greg > > On Aug 24, 3:40 pm, David Chelimsky wrote: >> On Mon, Aug 24, 2009 at 2:19 PM, Gregory >> Hnatiuk wrote: >>> What is the expected/intended behavior for the scope of class >>> instance >>> variables when running multiple specs? >> >>> It appears that setting a class instance variable in one spec will >>> affect it in a second spec run like so: >> >>> http://gist.github.com/174018 >> >>> running `spec spec1_spec.rb spec2_spec.rb` or `spec .` from within >>> that directory will fail because the state of the instance >>> variable is >>> maintained. >> >>> I'm investigating a case where this behavior is affecting the >>> passing/ >>> failing of specs based on the order they are loaded by Rake's >>> FileList, and am looking for a little background before I try to >>> solve >>> it. >> >> Each example is run in a separate scope, so locals and instance >> variables are cleaned up by Ruby's gc after each example. >> >> All the examples run in one process, however, so globals are a >> different matter. RSpec will clean up globals that it sets >> internally, >> like if you stub methods on class objects, etc. Any global state >> changed by the spec or the app is really up to you as the spec author >> to clean up after each example. >> >> HTH, >> David >> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From adam.trepanier at gmail.com Mon Aug 24 18:46:11 2009 From: adam.trepanier at gmail.com (Jesterman81) Date: Mon, 24 Aug 2009 15:46:11 -0700 (PDT) Subject: [rspec-users] undefined method 'mock' In-Reply-To: <57c63afe0908232030ta663e99v90cefa8bb42fb6c0@mail.gmail.com> References: <7808cfb7-0752-4c0d-8c33-4224ff02d696@l35g2000vba.googlegroups.com> <57c63afe0908232030ta663e99v90cefa8bb42fb6c0@mail.gmail.com> Message-ID: <7fa3c2b0-be5b-4cf1-a9cc-b4f2e0489d6f@v2g2000vbb.googlegroups.com> Yeah, I'm an idiot. I was missing the whole 'it "should do something" do' line. Thanks for getting back so quick though! On Aug 23, 11:30?pm, David Chelimsky wrote: > On Sun, Aug 23, 2009 at 8:57 PM, Jesterman81 wrote: > > Greetings, > > > I am trying to use the mock method in rspec and it returns a undefined > > method 'mock' error. ?I am using this with the rspec book in chapter > > 6.3. ?Do I have to configure rspec someone. ?I have gem rspec 1.2.8 > > installed and using ruby 1.8. > > > any help will be appreciated. > > Please post the example and the error you're getting so we can help > you figure it out. > > Cheers, > David > > > > > thanks > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jgagne33 at gmail.com Mon Aug 24 19:09:44 2009 From: jgagne33 at gmail.com (jg) Date: Mon, 24 Aug 2009 16:09:44 -0700 (PDT) Subject: [rspec-users] Assigning instance variable :expected and :got appear to be the same Message-ID: <29438f04-60ae-4878-a800-ea95497f3a10@a26g2000yqn.googlegroups.com> I have a very fairly simple spec it "should assign an instance variable" do get 'new' assigns[:city].should == City.new end In my controller def new @city = City.new end but when I run it, I get 'CitiesController GET 'new' should assign an instance variable' FAILED expected: #, got: # (using ==) Those two things seem to be equal, am I wrong there? From dchelimsky at gmail.com Mon Aug 24 19:37:58 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 24 Aug 2009 18:37:58 -0500 Subject: [rspec-users] Assigning instance variable :expected and :got appear to be the same In-Reply-To: <29438f04-60ae-4878-a800-ea95497f3a10@a26g2000yqn.googlegroups.com> References: <29438f04-60ae-4878-a800-ea95497f3a10@a26g2000yqn.googlegroups.com> Message-ID: <57c63afe0908241637o4865cc37ybd22a56092bff938@mail.gmail.com> On Mon, Aug 24, 2009 at 6:09 PM, jg wrote: > I have a very fairly simple spec > > it "should assign an instance variable" do > ? get 'new' > ? assigns[:city].should == City.new > end > > In my controller > > def new > ?@city = City.new > end > > but when I run it, I get > > 'CitiesController GET 'new' should assign an instance variable' FAILED > expected: # nil>, > ? ? ? ? got: # nil> (using ==) > > Those two things seem to be equal, am I wrong there? According to ActiveRecord, two objects with nil IDs are not considered to be equal. Try this in script/console and you'll see: $ City.new == City.new => false HTH, David From chs at proactive.or.at Tue Aug 25 05:09:54 2009 From: chs at proactive.or.at (Christoph Schiessl) Date: Tue, 25 Aug 2009 11:09:54 +0200 Subject: [rspec-users] Assigning instance variable :expected and :got appear to be the same In-Reply-To: <29438f04-60ae-4878-a800-ea95497f3a10@a26g2000yqn.googlegroups.com> References: <29438f04-60ae-4878-a800-ea95497f3a10@a26g2000yqn.googlegroups.com> Message-ID: On Aug 25, 2009, at 1:09 AM, jg wrote: > I have a very fairly simple spec > > it "should assign an instance variable" do > get 'new' > assigns[:city].should == City.new > end > > In my controller > > def new > @city = City.new > end > > but when I run it, I get > > 'CitiesController GET 'new' should assign an instance variable' FAILED > expected: # nil>, > got: # nil> (using ==) > > Those two things seem to be equal, am I wrong there? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Your controller is okay. Try to change your test like this: it "should assign an instance variable" do City.should_receive(:new).and_return(@city = mock_model(City)) get 'new' assigns[:city].should == @city end That way, you are comparing the same object instance => it should pass. Best regards, Christoph From jgagne33 at gmail.com Tue Aug 25 12:12:39 2009 From: jgagne33 at gmail.com (jg) Date: Tue, 25 Aug 2009 09:12:39 -0700 (PDT) Subject: [rspec-users] Assigning instance variable :expected and :got appear to be the same In-Reply-To: References: <29438f04-60ae-4878-a800-ea95497f3a10@a26g2000yqn.googlegroups.com> Message-ID: <97952fff-ac13-4f06-b50c-5ca5bee91e93@32g2000yqj.googlegroups.com> Ahh, got it! Thanks alot guys. On Aug 25, 2:09?am, Christoph Schiessl wrote: > On Aug 25, 2009, at 1:09 AM, jg wrote: > > > > > > > I have a very fairly simple spec > > > it "should assign an instance variable" do > > ? get 'new' > > ? assigns[:city].should == City.new > > end > > > In my controller > > > def new > > ?@city = City.new > > end > > > but when I run it, I get > > > 'CitiesController GET 'new' should assign an instance variable' FAILED > > expected: # > nil>, > > ? ? ? ? got: # > nil> (using ==) > > > Those two things seem to be equal, am I wrong there? > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > Your controller is okay. > > Try to change your test like this: > > it "should assign an instance variable" do > ? ?City.should_receive(:new).and_return(@city = mock_model(City)) > ? ?get 'new' > ? ?assigns[:city].should == @city > end > > That way, you are comparing the same object instance => it should pass. > > Best regards, > Christoph > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From tom at experthuman.com Tue Aug 25 13:38:11 2009 From: tom at experthuman.com (Tom Stuart) Date: Tue, 25 Aug 2009 18:38:11 +0100 Subject: [rspec-users] mocks & stubs In-Reply-To: <4A941B95.30508@haskinferguson.net> References: <4A941B95.30508@haskinferguson.net> Message-ID: <1DF87C54-2A35-4052-B53D-E586E29EE02E@experthuman.com> On 25 Aug 2009, at 18:12, Denis Haskin wrote: > The key expectation in this example is: > @discount.should_not be_available(@order) > But I changed the implementation of Discount#available? so that it > calls Order#num_products instead of Order#line_items. My examples > now fail. > Why am I having trouble getting comfortable with this? Your specification describes the interaction of Discount with the rest of the system; the idea of mocking is to nail down how a Discount object behaves in isolation from all of the other objects it interacts with. (And then, at a higher level, you have integration tests to check that all of the individual behaviours you've specified play nicely together.) If you change the nature of these interactions, for example by getting Discount to ask Order for a number instead of for a collection of line items, then you're essentially changing the API between different parts of your application so your specs will and should fail. This is exactly the right amount of brittleness for the level the specs operate at. Your integration tests should still pass, indicating that the system as a whole still works, while your specs fail, indicating that the interactions between objects are not what you specified. Some of the time it does feel like you're fixing up unnecessary breakage but it's important for the specs to be able to reveal failures at this fine-grained level because these sorts of API changes aren't always made deliberately, especially when you're doing big refactorings. Note that your specs are only "brittle" in the sense that changes in the contracts between collaborating objects ("Discount expects Order to be able to return a collection of line items" changing to "Discount expects Order to be able to say how many products it consists of") require matching changes in those objects' specifications. You can change the implementation of methods on Discount as much as you like -- by replacing poor algorithms with more efficient ones, for example -- and the specs won't necessarily break unless your changes affect the interactions between Discount and "the outside world" of other objects. Cheers, -Tom From alexch at gmail.com Tue Aug 25 13:22:17 2009 From: alexch at gmail.com (Alex Chaffee) Date: Tue, 25 Aug 2009 10:22:17 -0700 Subject: [rspec-users] mocks & stubs In-Reply-To: <4A941B95.30508@haskinferguson.net> References: <4A941B95.30508@haskinferguson.net> Message-ID: <7a93bd340908251022x6183b411t6f2a83c5408a91dd@mail.gmail.com> Yep. That's why most people who are uncomfortable with mocks are uncomfortable with mocks. In my experience mocks work best at well-defined, relatively stable interfaces to external(ish) services. Otherwise you're testing the implementation, which makes refactoring difficult. But there are lots of people who use mocks all the time, so I'll let them make the arguments in favor... Stubs and Fakes, however, can be more robust. Don't paint all Test Doubles with the same brush! :-) --- Alex Chaffee - alex at stinky.com - http://alexch.github.com Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch | http://alexch.tumblr.com On Tue, Aug 25, 2009 at 10:12 AM, Denis Haskin wrote: > This isn't really an rspec question, but about mocks and stubs in general, > and maybe I'm looking for some best practices with rspec. > > I like mocks and stubs until code starts to change, and then I always get > frustrated because examples then seem so brittle and sensitive to > implementation details, which feels wrong to me. > > So a small example: this is in an example for a Discount model: > ????? @order.should_receive(:line_items).and_return(mock_model(LineItem, > :size => 2)) > (@order is a mock; I realize it maybe should just be a stub) > > The key expectation in this example is: > ????? @discount.should_not be_available(@order) > > But I changed the implementation of Discount#available? so that it calls > Order#num_products instead of Order#line_items.? My examples now fail. > > Why am I having trouble getting comfortable with this? > > Thanks, > > dwh > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cremes.devlist at mac.com Tue Aug 25 15:59:33 2009 From: cremes.devlist at mac.com (Chuck Remes) Date: Tue, 25 Aug 2009 14:59:33 -0500 Subject: [rspec-users] arbitrary handling of received messages in mocks Message-ID: I am trying to process a message sent to a mock to verify it contains the correct keys. In my case I am sending a JSON string to the mock built from data passed in via the test. The object internally builds a hash and then constructs the JSON string from it. I can't get my mock to fail though. Here's an example similar to what I've got. describe Foo it "should match the json string" do # setup stubs & mocks ... hsh = ... # keys and values used inside the method @api.should_receive(:publish_to_bus) do |message| false # should always fail end Foo.new(@api).decode hsh end end The documentation says the expectation passes or fails based upon the return value of the block. I can't even force it to fail by returning false. Once I figure this out, I plan to decode the JSON string in the mock block and compare the resulting collection with the data I originally passed in to the object. This behavior will likely become a helper method (if that matters). What am I doing wrong? rspec 1.2.8 ruby 1.8.6 patch 287, Windows Running under Netbeans 6.7.1 Thank you for your help. cr From ben at benmabey.com Tue Aug 25 18:04:51 2009 From: ben at benmabey.com (Ben Mabey) Date: Tue, 25 Aug 2009 16:04:51 -0600 Subject: [rspec-users] arbitrary handling of received messages in mocks In-Reply-To: References: Message-ID: <4A946003.60205@benmabey.com> Chuck Remes wrote: > I am trying to process a message sent to a mock to verify it contains > the correct keys. In my case I am sending a JSON string to the mock > built from data passed in via the test. The object internally builds a > hash and then constructs the JSON string from it. > > I can't get my mock to fail though. Here's an example similar to what > I've got. > > describe Foo > it "should match the json string" do > # setup stubs & mocks > ... > hsh = ... # keys and values used inside the method > @api.should_receive(:publish_to_bus) do |message| > false # should always fail > end > > Foo.new(@api).decode hsh > end > end > > The documentation says the expectation passes or fails based upon the > return value of the block. I can't even force it to fail by returning > false. Once I figure this out, I plan to decode the JSON string in the > mock block and compare the resulting collection with the data I > originally passed in to the object. This behavior will likely become a > helper method (if that matters). The docs could wrong.. I dunno.... When using the block form I always set expectation within the block. This may be the wrong way to use it, but it works. Like so: describe Foo it "should match the json string" do # setup stubs & mocks ... hsh = ... # keys and values used inside the method @api.should_receive(:publish_to_bus) do |message| JSON.parse(message).should == hsh # or whatever you need to do here. end Foo.new(@api).decode hsh end end -Ben From tom at experthuman.com Tue Aug 25 18:13:24 2009 From: tom at experthuman.com (Tom Stuart) Date: Tue, 25 Aug 2009 23:13:24 +0100 Subject: [rspec-users] arbitrary handling of received messages in mocks In-Reply-To: References: Message-ID: <7E9EA64E-EACC-46FD-A6D5-700C3AAC9E4A@experthuman.com> On 25 Aug 2009, at 20:59, Chuck Remes wrote: > The documentation says the expectation passes or fails based upon > the return value of the block. I can't even force it to fail by > returning false. The docs (http://rspec.info/documentation/mocks/message_expectations.html ) say: > You can supply a block to a message expectation. When the message is > received > by the mock, the block is passed any arguments and evaluated. The > result is > the return value of the block. This means that the mocked method will return the value that is returned by the block; by returning false in your block, you're just arranging for the mocked method to return false. (So this is the same as @api.should_receive(:publish_to_bus).and_return(false).) If you want the message expectation to fail, you need to put a failing expectation inside the block. Cheers, -Tom From oli.azevedo.barnes at gmail.com Tue Aug 25 19:19:26 2009 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Tue, 25 Aug 2009 20:19:26 -0300 Subject: [rspec-users] undefined method `and_return' Message-ID: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> Hello, I'm struggling with this controller spec for a few hours now http://pastie.org/594775 which is failing with an error I can't find any references about, neither on the list nor on the web in general: Admin::ImagesController handling PUT /images/1 with successful update should find the image requested undefined method `and_return' for # /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 /tmp/textmate-command-1859.rb:3 15 before(:each) do 16 @image = mock_model(Image, :to_param => "1") 17 Image.stub!(:find).and_return(@image) 18 end why would and_return() not be recognized, while stub!() is? has anybody experienced this problem before? I'm using rspec and rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing Spree 0.8.99 thanks Oliver From orengolan at gmail.com Tue Aug 25 19:31:42 2009 From: orengolan at gmail.com (oren) Date: Tue, 25 Aug 2009 16:31:42 -0700 (PDT) Subject: [rspec-users] running rake spec:remote In-Reply-To: References: Message-ID: any clues? On Aug 21, 1:13?pm, oren wrote: > When running autotest only 'rake spec' is running > and I want it to run 'rake spec:remote' as well. > > How do i achieve that? > > thanks > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Tue Aug 25 19:44:48 2009 From: ben at benmabey.com (Ben Mabey) Date: Tue, 25 Aug 2009 17:44:48 -0600 Subject: [rspec-users] running rake spec:remote In-Reply-To: References: Message-ID: <4A947770.1080808@benmabey.com> oren wrote: > When running autotest only 'rake spec' is running > and I want it to run 'rake spec:remote' as well. > > How do i achieve that? > > IIRC, autospec (not autotest) does not use rake at all. It uses the opts defined in spec/spec.opts. I would suggest making any needed changes in that file. HTH, Ben From tom at experthuman.com Wed Aug 26 03:38:41 2009 From: tom at experthuman.com (Tom Stuart) Date: Wed, 26 Aug 2009 08:38:41 +0100 Subject: [rspec-users] metaprogrammatically generating spec examples In-Reply-To: <8277b7f40908251539v4b9adc0fue7d5c893bd342b55@mail.gmail.com> References: <8277b7f40908251539v4b9adc0fue7d5c893bd342b55@mail.gmail.com> Message-ID: <0CC4C029-7C3C-480E-82A7-8C5ACA3A07A2@experthuman.com> On 25 Aug 2009, at 23:39, Joaquin Rivera Padron wrote: > where you iterate over an array of known required attributes and > then generate the typical %{it 'should require required attribute'} > spec example. That's easy with shoulda, but in this case the > validations are contextual, they have the :if => xxx option, and > shoulda doesn't support them (yet) > If not answering my former question: how you attack normally this > problem? There's no reason to avoid the shoulda macros. Using :if just means that, in some contexts (e.g. when #active? returns true) @the_instance.should validate_presence_of(:name), and in other contexts (e.g. when #active? returns false) @the_instance.should_not validate_presence_of(:name). Shoulda isn't going to be able to "support" :if, because in general it's not possible to automatically construct a context in which the :if condition is definitely true or definitely false -- that's your job, not Shoulda's. You shouldn't try to check the two different contexts with a single example. So, instead of just listing the attribute names, find a way to pair the attribute names with enough information to construct pairs of contexts in which you expect the validation to respectively fire and not fire. For example, if all of your :if arguments are actually just method names like :active? (rather than being blocks), you could say "REQ_ATTRS = [[:name, :active?], [:other, :need_other?]] ; REQ_ATTRS.each do |req_attr, if_method| ... end" and, inside the block, write one example that stubs the method to return true and checks that the validation fires, then write another example that stubs the method to return false and checks the validation doesn't fire. Cheers, -Tom From errabunda at gmail.com Wed Aug 26 01:38:09 2009 From: errabunda at gmail.com (Masha) Date: Tue, 25 Aug 2009 22:38:09 -0700 (PDT) Subject: [rspec-users] How do I get spec to look for _spec.rb files in multiple levels of subdirs? Message-ID: Hi, I have the following in my rspec.rake file, yet it doesn't treat ** as it should - iterating through all subdirectories of spec/qa, but instead it only finds relevant files that are one level down. script/runner ./vendor/gems/rspec-1.2.8/bin/spec --options "./spec/qa/ spec.opts" ./spec/qa/**/*_spec.rb Thank you much, Masha From dchelimsky at gmail.com Wed Aug 26 05:36:49 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 26 Aug 2009 04:36:49 -0500 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> Message-ID: <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> On Tue, Aug 25, 2009 at 6:19 PM, Oliver Barnes wrote: > Hello, > > I'm struggling with this controller spec for a few hours now > > http://pastie.org/594775 > > which is failing with an error I can't find any references about, > neither on the list nor on the web in general: > > Admin::ImagesController handling PUT /images/1 with successful update > should find the image requested > undefined method `and_return' for # > /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 > /tmp/textmate-command-1859.rb:3 > 15 ? ? ?before(:each) do > 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") > 17 ? ? ? ?Image.stub!(:find).and_return(@image) > 18 ? ? ?end > > why would and_return() not be recognized, while stub!() is? > > has anybody experienced this problem before? I'm using rspec and > rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing > Spree 0.8.99 Please run this spec from the command line with --backtrace so we can see the full backtrace. Thanks. > > thanks > Oliver > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Aug 26 06:10:42 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 26 Aug 2009 05:10:42 -0500 Subject: [rspec-users] How do I get spec to look for _spec.rb files in multiple levels of subdirs? In-Reply-To: References: Message-ID: <57c63afe0908260310m1603fbb1y50c8b56bab27ca7f@mail.gmail.com> On Wed, Aug 26, 2009 at 12:38 AM, Masha wrote: > Hi, > > I have the following in my rspec.rake file, yet it doesn't treat ** as > it should - iterating through all subdirectories of spec/qa, but > instead it only finds relevant files that are one level down. > > script/runner ./vendor/gems/rspec-1.2.8/bin/spec --options "./spec/qa/ > spec.opts" ./spec/qa/**/*_spec.rb Try just ./spec/qa. Also, script/spec would be simpler: script/spec --options ./spec/qa/spec.opts ./spec/qa HTH, David > > Thank you much, Masha > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From oli.azevedo.barnes at gmail.com Wed Aug 26 09:57:07 2009 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Wed, 26 Aug 2009 10:57:07 -0300 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> Message-ID: <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> sure thing: http://pastie.org/595363 2009/8/26 David Chelimsky : > On Tue, Aug 25, 2009 at 6:19 PM, Oliver > Barnes wrote: >> Hello, >> >> I'm struggling with this controller spec for a few hours now >> >> http://pastie.org/594775 >> >> which is failing with an error I can't find any references about, >> neither on the list nor on the web in general: >> >> Admin::ImagesController handling PUT /images/1 with successful update >> should find the image requested >> undefined method `and_return' for # >> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >> /tmp/textmate-command-1859.rb:3 >> 15 ? ? ?before(:each) do >> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >> 18 ? ? ?end >> >> why would and_return() not be recognized, while stub!() is? >> >> has anybody experienced this problem before? I'm using rspec and >> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >> Spree 0.8.99 > > Please run this spec from the command line with --backtrace so we can > see the full backtrace. Thanks. > >> >> thanks >> Oliver >> _______________________________________________ >> 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 cremes.devlist at mac.com Wed Aug 26 11:58:30 2009 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 26 Aug 2009 10:58:30 -0500 Subject: [rspec-users] arbitrary handling of received messages in mocks In-Reply-To: <7E9EA64E-EACC-46FD-A6D5-700C3AAC9E4A@experthuman.com> References: <7E9EA64E-EACC-46FD-A6D5-700C3AAC9E4A@experthuman.com> Message-ID: On Aug 25, 2009, at 5:13 PM, Tom Stuart wrote: > On 25 Aug 2009, at 20:59, Chuck Remes wrote: >> The documentation says the expectation passes or fails based upon >> the return value of the block. I can't even force it to fail by >> returning false. > > The docs (http://rspec.info/documentation/mocks/message_expectations.html > ) say: > >> You can supply a block to a message expectation. When the message >> is received >> by the mock, the block is passed any arguments and evaluated. The >> result is >> the return value of the block. > > This means that the mocked method will return the value that is > returned by the block; by returning false in your block, you're just > arranging for the mocked method to return false. (So this is the > same as @api.should_receive(:publish_to_bus).and_return(false).) > > If you want the message expectation to fail, you need to put a > failing expectation inside the block. Setting an expectation within the block makes it work. I think the docs should be clearer that the expectations inside are necessary. cr From errabunda at gmail.com Wed Aug 26 12:16:59 2009 From: errabunda at gmail.com (Masha) Date: Wed, 26 Aug 2009 09:16:59 -0700 (PDT) Subject: [rspec-users] How do I get spec to look for _spec.rb files in multiple levels of subdirs? In-Reply-To: <57c63afe0908260310m1603fbb1y50c8b56bab27ca7f@mail.gmail.com> References: <57c63afe0908260310m1603fbb1y50c8b56bab27ca7f@mail.gmail.com> Message-ID: That was it, thank you! On Aug 26, 3:10?am, David Chelimsky wrote: > On Wed, Aug 26, 2009 at 12:38 AM, Masha wrote: > > Hi, > > > I have the following in my rspec.rake file, yet it doesn't treat ** as > > it should - iterating through all subdirectories of spec/qa, but > > instead it only finds relevant files that are one level down. > > > script/runner ./vendor/gems/rspec-1.2.8/bin/spec --options "./spec/qa/ > > spec.opts" ./spec/qa/**/*_spec.rb > > Try just ./spec/qa. > > Also, script/spec would be simpler: > > script/spec ?--options ./spec/qa/spec.opts ./spec/qa > > HTH, > David > > > > > Thank you much, Masha > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From cremes.devlist at mac.com Wed Aug 26 14:57:35 2009 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 26 Aug 2009 13:57:35 -0500 Subject: [rspec-users] [Q] testing WIN32OLE_EVENT callbacks Message-ID: I'm trying to setup some specs (really just assertions) that verify some callbacks are executed in response to COM events. In the WIN32OLE_EVENT class you may subscribe to a COM event and have it delivered to you for processing. Syntax looks like: event_handler.on_event('StartEvent') do |*args| do_start_event args end The #do_start_event method is a member of the containing class. The only way I can confirm that it is being called is to set an expectation on the class under test. I've always noted that mocking/ stubbing the class under test is rather bad form. Regardless, I don't know how to "mock" the delivery of an event anyway so this may all be moot. I searched the list archives for 'win32ole' back to early 2007 and came up with 0 hits. Any suggestions on how to tackle this? cr From daniel at sibblingz.com Wed Aug 26 15:09:04 2009 From: daniel at sibblingz.com (morgflast) Date: Wed, 26 Aug 2009 12:09:04 -0700 (PDT) Subject: [rspec-users] running a fast subset of the specs Message-ID: <25154030.post@talk.nabble.com> My rails project has a lot of specs. Most of these run quickly. There are a handful of files, like spec/model/slow_spec1.rb and spec/model/slow_spec2.rb that run slowly because they have to do various slow operations like using a timer. I would like to write a rake task, like rake:spec:fast, that runs only the fast specs. Any ideas of how to do this? -- View this message in context: http://www.nabble.com/running-a-fast-subset-of-the-specs-tp25154030p25154030.html Sent from the rspec-users mailing list archive at Nabble.com. From alexch at gmail.com Wed Aug 26 16:48:19 2009 From: alexch at gmail.com (Alex Chaffee) Date: Wed, 26 Aug 2009 13:48:19 -0700 Subject: [rspec-users] running a fast subset of the specs In-Reply-To: <25154030.post@talk.nabble.com> References: <25154030.post@talk.nabble.com> Message-ID: <7a93bd340908261348y5bbe8821h259a3507ce34937@mail.gmail.com> Sure. Put all your fast specs in a subdirectory spec/fast. Then Spec::Rake::SpecTask.new do |t| t.spec_files = FileList['spec/fast/**/*_spec.rb'] end or something to that effect. Alternately, put your slow specs in a subdirectory, but I think the above way is arguably cleaner. --- Alex Chaffee - alex at stinky.com - http://alexch.github.com Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch | http://alexch.tumblr.com On Wed, Aug 26, 2009 at 12:09 PM, morgflast wrote: > > My rails project has a lot of specs. ? Most of these run quickly. ?There are > a handful of files, like spec/model/slow_spec1.rb and > spec/model/slow_spec2.rb that run slowly because they have to do various > slow operations like using a timer. > > I would like to write a rake task, like rake:spec:fast, that runs only the > fast specs. ?Any ideas of how to do this? > > > -- > View this message in context: http://www.nabble.com/running-a-fast-subset-of-the-specs-tp25154030p25154030.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Wed Aug 26 18:48:01 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 26 Aug 2009 18:48:01 -0400 Subject: [rspec-users] polymorphic controller testing In-Reply-To: <5b1b5e890908261139q20ed7252q9212b0ae74a03a5f@mail.gmail.com> References: <5b1b5e890908261139q20ed7252q9212b0ae74a03a5f@mail.gmail.com> Message-ID: On Wed, Aug 26, 2009 at 2:39 PM, john wrote: > Hi Rspec Community, > I ran into an interesting problem yesterday. > I'm using polymorphic_path for my controller, but I can't figure out how to > test it. > ################################################ > # routes.rb > map.resources :schedules > map.resources :meetings, :controller => 'schedules' > # meetings_controller_spec.rb > describe MeetingsController do > ??before(:each) do > ?? ?@current_user = mock_model(User, :id => 1) > ?? ?controller.stub!(:current_user).and_return(@current_user) > ?? ?controller.stub!(:login_required).and_return(:true) > ??end > ??it "should get 'new' action successfully" do > ?? ?get :new > ?? ?response.should be_success > ??end > end > # spec error output > /Users/john/.gem/ruby/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:443:in > `load_missing_constant': uninitialized constant MeetingsController > (NameError) > from > /Users/john/.gem/ruby/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:80:in > `const_missing' > from > /Users/john/.gem/ruby/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:92:in > `const_missing' > from ./spec/controllers/meetings_controller_spec.rb:3 > from > /Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:15:in > `load' > from > /Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:15:in > `load_files' > from > /Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:14:in > `each' > from > /Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:14:in > `load_files' > from > /Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/options.rb:107:in > `run_examples' > from > /Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/command_line.rb:9:in > `run' > from script/spec:5 > ################################## Didn't you mean SchedulesController instead of MeetingsController in the spec. >From the snippet from your routes.rb I wouldn't expect you to have a MeetingsController. And controller specs don't use routes to find controller methods anyway. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From oli.azevedo.barnes at gmail.com Thu Aug 27 10:35:31 2009 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Thu, 27 Aug 2009 11:35:31 -0300 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> Message-ID: <6466d9040908270735r4d162243y1fecb45c726ac8d7@mail.gmail.com> does that shed any light? 2009/8/26 Oliver Barnes : > sure thing: > > http://pastie.org/595363 > > 2009/8/26 David Chelimsky : >> On Tue, Aug 25, 2009 at 6:19 PM, Oliver >> Barnes wrote: >>> Hello, >>> >>> I'm struggling with this controller spec for a few hours now >>> >>> http://pastie.org/594775 >>> >>> which is failing with an error I can't find any references about, >>> neither on the list nor on the web in general: >>> >>> Admin::ImagesController handling PUT /images/1 with successful update >>> should find the image requested >>> undefined method `and_return' for # >>> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >>> /tmp/textmate-command-1859.rb:3 >>> 15 ? ? ?before(:each) do >>> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >>> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >>> 18 ? ? ?end >>> >>> why would and_return() not be recognized, while stub!() is? >>> >>> has anybody experienced this problem before? I'm using rspec and >>> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >>> Spree 0.8.99 >> >> Please run this spec from the command line with --backtrace so we can >> see the full backtrace. Thanks. >> >>> >>> thanks >>> Oliver >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From dchelimsky at gmail.com Thu Aug 27 10:48:01 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 27 Aug 2009 09:48:01 -0500 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <6466d9040908270735r4d162243y1fecb45c726ac8d7@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> <6466d9040908270735r4d162243y1fecb45c726ac8d7@mail.gmail.com> Message-ID: <57c63afe0908270748i12afda41rc98d608c26354eef@mail.gmail.com> Sorry, but no. The spec you showed in the original email should work exactly as you expect. Somehow, for reasons I don't understand, stub!() appears to be returning a Proc instead of a mock proxy object. On Thu, Aug 27, 2009 at 9:35 AM, Oliver Barnes wrote: > does that shed any light? > > 2009/8/26 Oliver Barnes : >> sure thing: >> >> http://pastie.org/595363 >> >> 2009/8/26 David Chelimsky : >>> On Tue, Aug 25, 2009 at 6:19 PM, Oliver >>> Barnes wrote: >>>> Hello, >>>> >>>> I'm struggling with this controller spec for a few hours now >>>> >>>> http://pastie.org/594775 >>>> >>>> which is failing with an error I can't find any references about, >>>> neither on the list nor on the web in general: >>>> >>>> Admin::ImagesController handling PUT /images/1 with successful update >>>> should find the image requested >>>> undefined method `and_return' for # >>>> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >>>> /tmp/textmate-command-1859.rb:3 >>>> 15 ? ? ?before(:each) do >>>> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >>>> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >>>> 18 ? ? ?end >>>> >>>> why would and_return() not be recognized, while stub!() is? >>>> >>>> has anybody experienced this problem before? I'm using rspec and >>>> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >>>> Spree 0.8.99 >>> >>> Please run this spec from the command line with --backtrace so we can >>> see the full backtrace. Thanks. >>> >>>> >>>> thanks >>>> Oliver >>>> _______________________________________________ >>>> 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 matt at mattwynne.net Thu Aug 27 11:12:47 2009 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 27 Aug 2009 16:12:47 +0100 Subject: [rspec-users] [Q] testing WIN32OLE_EVENT callbacks In-Reply-To: References: Message-ID: <43E6AABB-C015-4892-BC5D-DBCE05CCA79C@mattwynne.net> On 26 Aug 2009, at 19:57, Chuck Remes wrote: > I'm trying to setup some specs (really just assertions) that verify > some callbacks are executed in response to COM events. In the > WIN32OLE_EVENT class you may subscribe to a COM event and have it > delivered to you for processing. Syntax looks like: > > event_handler.on_event('StartEvent') do |*args| > do_start_event args > end > > The #do_start_event method is a member of the containing class. The > only way I can confirm that it is being called is to set an > expectation on the class under test. I've always noted that mocking/ > stubbing the class under test is rather bad form. Regardless, I > don't know how to "mock" the delivery of an event anyway so this may > all be moot. > > I searched the list archives for 'win32ole' back to early 2007 and > came up with 0 hits. Any suggestions on how to tackle this? This doesn't really have much to do with the specific technology you're dealing with, it's an issue about separating the layers so you can introduce fakes where you need to in order to test your own code. Can you use dependency injection (or some other trick) to swap in a fake event_handler into the code you've quoted above? If so, you can then get your fake to simulate the behaviour of the event_handler and exercise the code you want to actually test. There are a couple of good books on these sort of techniques: http://xunitpatterns.com/ http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052 does that help? Matt From oli.azevedo.barnes at gmail.com Thu Aug 27 11:25:24 2009 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Thu, 27 Aug 2009 12:25:24 -0300 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <57c63afe0908270748i12afda41rc98d608c26354eef@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> <6466d9040908270735r4d162243y1fecb45c726ac8d7@mail.gmail.com> <57c63afe0908270748i12afda41rc98d608c26354eef@mail.gmail.com> Message-ID: <6466d9040908270825m51a54790p5e0867e4cb54e578@mail.gmail.com> i guess it must be something wrong with my setup then? i've been messing with my gem infrastructure. going to try reinstalling rspec 2009/8/27 David Chelimsky : > Sorry, but no. The spec you showed in the original email should work > exactly as you expect. Somehow, for reasons I don't understand, > stub!() appears to be returning a Proc instead of a mock proxy object. > > On Thu, Aug 27, 2009 at 9:35 AM, Oliver > Barnes wrote: >> does that shed any light? >> >> 2009/8/26 Oliver Barnes : >>> sure thing: >>> >>> http://pastie.org/595363 >>> >>> 2009/8/26 David Chelimsky : >>>> On Tue, Aug 25, 2009 at 6:19 PM, Oliver >>>> Barnes wrote: >>>>> Hello, >>>>> >>>>> I'm struggling with this controller spec for a few hours now >>>>> >>>>> http://pastie.org/594775 >>>>> >>>>> which is failing with an error I can't find any references about, >>>>> neither on the list nor on the web in general: >>>>> >>>>> Admin::ImagesController handling PUT /images/1 with successful update >>>>> should find the image requested >>>>> undefined method `and_return' for # >>>>> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >>>>> /tmp/textmate-command-1859.rb:3 >>>>> 15 ? ? ?before(:each) do >>>>> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >>>>> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >>>>> 18 ? ? ?end >>>>> >>>>> why would and_return() not be recognized, while stub!() is? >>>>> >>>>> has anybody experienced this problem before? I'm using rspec and >>>>> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >>>>> Spree 0.8.99 >>>> >>>> Please run this spec from the command line with --backtrace so we can >>>> see the full backtrace. Thanks. >>>> >>>>> >>>>> thanks >>>>> Oliver >>>>> _______________________________________________ >>>>> 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 cremes.devlist at mac.com Thu Aug 27 12:02:26 2009 From: cremes.devlist at mac.com (Chuck Remes) Date: Thu, 27 Aug 2009 11:02:26 -0500 Subject: [rspec-users] [Q] testing WIN32OLE_EVENT callbacks In-Reply-To: <43E6AABB-C015-4892-BC5D-DBCE05CCA79C@mattwynne.net> References: <43E6AABB-C015-4892-BC5D-DBCE05CCA79C@mattwynne.net> Message-ID: <8CE70F40-10B1-41F2-9F67-536B387AC792@mac.com> On Aug 27, 2009, at 10:12 AM, Matt Wynne wrote: > > On 26 Aug 2009, at 19:57, Chuck Remes wrote: > >> I'm trying to setup some specs (really just assertions) that verify >> some callbacks are executed in response to COM events. In the >> WIN32OLE_EVENT class you may subscribe to a COM event and have it >> delivered to you for processing. Syntax looks like: >> >> event_handler.on_event('StartEvent') do |*args| >> do_start_event args >> end >> >> The #do_start_event method is a member of the containing class. The >> only way I can confirm that it is being called is to set an >> expectation on the class under test. I've always noted that mocking/ >> stubbing the class under test is rather bad form. Regardless, I >> don't know how to "mock" the delivery of an event anyway so this >> may all be moot. >> >> I searched the list archives for 'win32ole' back to early 2007 and >> came up with 0 hits. Any suggestions on how to tackle this? > > This doesn't really have much to do with the specific technology > you're dealing with, it's an issue about separating the layers so > you can introduce fakes where you need to in order to test your own > code. > > Can you use dependency injection (or some other trick) to swap in a > fake event_handler into the code you've quoted above? If so, you can > then get your fake to simulate the behaviour of the event_handler > and exercise the code you want to actually test. > > There are a couple of good books on these sort of techniques: > http://xunitpatterns.com/ > http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052 > > does that help? It does somewhat. I will definitely be looking at that XUnit patterns book. To answer an earlier question, I *can* pass in a mock for event_handler. However, I fail to see how I can use that in the example above to test that the statements in the block are executed. def bar event_handler event_handler.on_event('StartEvent') do |baz, qux| @obj1.method1 baz, qux end end Let's assume that method1 and method2 are acting upon other objects that I can also mock via DI. How can I generate the 'StartEvent' so that the block above is executed? BTW, the layers are as separated as they are going to get. In the WIN32OLE_EVENT class you *must* pass a block as shown above. I don't know how to get that block to execute in my specs without actually connecting to the COM service and getting it to generate that 'StartEvent'. Do you know of another way? it "should execute the block upon receipt of event 'StartEvent'" do handler = mock("event handler") handler.should_receive(:on_event).with('StartEvent') # necessary? obj1_mock = mock("obj1") obj1.should_receive(:method1) foo = Foo.new foo.obj1 = obj1 foo.bar # callback has been set; how do I generate the 'StartEvent' # to run that block? foo.??? end Do you see my problem more clearly with this example? Or have I obfuscated it even more... :) cr From matt at mattwynne.net Thu Aug 27 13:22:42 2009 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 27 Aug 2009 18:22:42 +0100 Subject: [rspec-users] [Q] testing WIN32OLE_EVENT callbacks In-Reply-To: <8CE70F40-10B1-41F2-9F67-536B387AC792@mac.com> References: <43E6AABB-C015-4892-BC5D-DBCE05CCA79C@mattwynne.net> <8CE70F40-10B1-41F2-9F67-536B387AC792@mac.com> Message-ID: <210FC527-6939-47C8-B5F8-68484A9FCA83@mattwynne.net> On 27 Aug 2009, at 17:02, Chuck Remes wrote: > > On Aug 27, 2009, at 10:12 AM, Matt Wynne wrote: > >> >> On 26 Aug 2009, at 19:57, Chuck Remes wrote: >> >>> I'm trying to setup some specs (really just assertions) that >>> verify some callbacks are executed in response to COM events. In >>> the WIN32OLE_EVENT class you may subscribe to a COM event and have >>> it delivered to you for processing. Syntax looks like: >>> >>> event_handler.on_event('StartEvent') do |*args| >>> do_start_event args >>> end >>> >>> The #do_start_event method is a member of the containing class. >>> The only way I can confirm that it is being called is to set an >>> expectation on the class under test. I've always noted that >>> mocking/stubbing the class under test is rather bad form. >>> Regardless, I don't know how to "mock" the delivery of an event >>> anyway so this may all be moot. >>> >>> I searched the list archives for 'win32ole' back to early 2007 and >>> came up with 0 hits. Any suggestions on how to tackle this? >> >> This doesn't really have much to do with the specific technology >> you're dealing with, it's an issue about separating the layers so >> you can introduce fakes where you need to in order to test your own >> code. >> >> Can you use dependency injection (or some other trick) to swap in a >> fake event_handler into the code you've quoted above? If so, you >> can then get your fake to simulate the behaviour of the >> event_handler and exercise the code you want to actually test. >> >> There are a couple of good books on these sort of techniques: >> http://xunitpatterns.com/ >> http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052 >> >> does that help? > > It does somewhat. I will definitely be looking at that XUnit > patterns book. > > To answer an earlier question, I *can* pass in a mock for > event_handler. However, I fail to see how I can use that in the > example above to test that the statements in the block are executed. > > def bar event_handler > event_handler.on_event('StartEvent') do |baz, qux| > @obj1.method1 baz, qux > end > end > > Let's assume that method1 and method2 are acting upon other objects > that I can also mock via DI. How can I generate the 'StartEvent' so > that the block above is executed? BTW, the layers are as separated > as they are going to get. In the WIN32OLE_EVENT class you *must* > pass a block as shown above. I don't know how to get that block to > execute in my specs without actually connecting to the COM service > and getting it to generate that 'StartEvent'. Do you know of another > way? > > it "should execute the block upon receipt of event 'StartEvent'" do > handler = mock("event handler") > handler.should_receive(:on_event).with('StartEvent') # necessary? > > obj1_mock = mock("obj1") > obj1.should_receive(:method1) > > foo = Foo.new > foo.obj1 = obj1 > > foo.bar > # callback has been set; how do I generate the 'StartEvent' > # to run that block? > foo.??? > end So I'm not sure if you can simulate a block being yeilded with RSpec's mocks, it's probably possible but I think you'd be simpler using a hand-made fake: class FakeEventHandler def initialize(*args_to_yield) @args_to_yield = *args_to_yield end def on_event(event_name) yield *@args_to_yield end end Something like that. Point being, a test-double (fake) doesn't always have to be a mock object. From orengolan at gmail.com Fri Aug 28 16:22:21 2009 From: orengolan at gmail.com (oren) Date: Fri, 28 Aug 2009 13:22:21 -0700 (PDT) Subject: [rspec-users] running rake spec:remote In-Reply-To: <4A947770.1080808@benmabey.com> References: <4A947770.1080808@benmabey.com> Message-ID: thanks Ben, I found that autotest and autospec are running all my specs. what I need to do is to separate the execution of spec/remote folder from the rest of the spec files. this folder must run after (or before) the rest. I find a way to tell autotest to ignore this folder, by creating .autotest file: Autotest.add_hook(:initialize) {|at| at.add_exception %r{^\.git} at.add_exception %r{^./tmp} at.clear_mappings # take out the default (test/test*rb) at.add_mapping(%r{^lib/.*\.rb$}) {|filename, _| Dir['spec/**/*.rb'] - Dir['spec/remote/*.rb'] } nil } Is it possible to tell autotest to first run spec/remote and only after it's done to run the rest? From oli.azevedo.barnes at gmail.com Fri Aug 28 18:02:43 2009 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Fri, 28 Aug 2009 19:02:43 -0300 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <6466d9040908270825m51a54790p5e0867e4cb54e578@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> <6466d9040908270735r4d162243y1fecb45c726ac8d7@mail.gmail.com> <57c63afe0908270748i12afda41rc98d608c26354eef@mail.gmail.com> <6466d9040908270825m51a54790p5e0867e4cb54e578@mail.gmail.com> Message-ID: <6466d9040908281502u4c3f1d8ftc8ca2c622d9c7866@mail.gmail.com> sorry to bother again, but no luck even after reinstalling rspec + rspec-rails: Big-Mac:spree(product-image-updates-fix) $ spec spec/controllers/admin/images_controller_spec.rb --backtrace /Users/oliver/Sites/spree/app/controllers/products_controller.rb:41: warning: parenthesize argument(s) for future version .FFFFF 1) NoMethodError in 'Admin::ImagesController handling PUT /images/1 with successful update should find the image requested' undefined method `and_return' for # ./spec/controllers/admin/images_controller_spec.rb:17: /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in `instance_eval' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in `eval_each_fail_fast' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in `each' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in `eval_each_fail_fast' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_hierarchy.rb:17:in `run_before_each' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:103:in `run_before_each' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:124:in `before_each_example' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:39:in `execute' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:48:in `timeout' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:37:in `execute' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:207:in `run_examples' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:205:in `each' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:205:in `run_examples' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:103:in `run' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:23:in `run' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:22:in `each' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:22:in `run' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/options.rb:127:in `run_examples' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/command_line.rb:9:in `run' /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/bin/spec:4: /usr/bin/spec:19:in `load' /usr/bin/spec:19: 2009/8/27 Oliver Barnes : > i guess it must be something wrong with my setup then? i've been > messing with my gem infrastructure. going to try reinstalling rspec > > 2009/8/27 David Chelimsky : >> Sorry, but no. The spec you showed in the original email should work >> exactly as you expect. Somehow, for reasons I don't understand, >> stub!() appears to be returning a Proc instead of a mock proxy object. >> >> On Thu, Aug 27, 2009 at 9:35 AM, Oliver >> Barnes wrote: >>> does that shed any light? >>> >>> 2009/8/26 Oliver Barnes : >>>> sure thing: >>>> >>>> http://pastie.org/595363 >>>> >>>> 2009/8/26 David Chelimsky : >>>>> On Tue, Aug 25, 2009 at 6:19 PM, Oliver >>>>> Barnes wrote: >>>>>> Hello, >>>>>> >>>>>> I'm struggling with this controller spec for a few hours now >>>>>> >>>>>> http://pastie.org/594775 >>>>>> >>>>>> which is failing with an error I can't find any references about, >>>>>> neither on the list nor on the web in general: >>>>>> >>>>>> Admin::ImagesController handling PUT /images/1 with successful update >>>>>> should find the image requested >>>>>> undefined method `and_return' for # >>>>>> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >>>>>> /tmp/textmate-command-1859.rb:3 >>>>>> 15 ? ? ?before(:each) do >>>>>> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >>>>>> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >>>>>> 18 ? ? ?end >>>>>> >>>>>> why would and_return() not be recognized, while stub!() is? >>>>>> >>>>>> has anybody experienced this problem before? I'm using rspec and >>>>>> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >>>>>> Spree 0.8.99 >>>>> >>>>> Please run this spec from the command line with --backtrace so we can >>>>> see the full backtrace. Thanks. >>>>> >>>>>> >>>>>> thanks >>>>>> Oliver >>>>>> _______________________________________________ >>>>>> 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 rick.denatale at gmail.com Fri Aug 28 18:33:59 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 28 Aug 2009 18:33:59 -0400 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <6466d9040908281502u4c3f1d8ftc8ca2c622d9c7866@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> <6466d9040908270735r4d162243y1fecb45c726ac8d7@mail.gmail.com> <57c63afe0908270748i12afda41rc98d608c26354eef@mail.gmail.com> <6466d9040908270825m51a54790p5e0867e4cb54e578@mail.gmail.com> <6466d9040908281502u4c3f1d8ftc8ca2c622d9c7866@mail.gmail.com> Message-ID: I don't usually top-post but in this case I think it works better. Is there ANY chance that Image or one of it's superclasses has defined a stub! method which would override the one in Spec::Mocks::Methods ? On Fri, Aug 28, 2009 at 6:02 PM, Oliver Barnes wrote: > sorry to bother again, but no luck even after reinstalling rspec + rspec-rails: > > Big-Mac:spree(product-image-updates-fix) $ spec > spec/controllers/admin/images_controller_spec.rb --backtrace > /Users/oliver/Sites/spree/app/controllers/products_controller.rb:41: > warning: parenthesize argument(s) for future version > .FFFFF > > 1) > NoMethodError in 'Admin::ImagesController handling PUT /images/1 with > successful update should find the image requested' > undefined method `and_return' for # > ./spec/controllers/admin/images_controller_spec.rb:17: > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in > `instance_eval' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in > `eval_each_fail_fast' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in > `each' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in > `eval_each_fail_fast' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_hierarchy.rb:17:in > `run_before_each' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:103:in > `run_before_each' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:124:in > `before_each_example' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:39:in > `execute' > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:48:in > `timeout' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:37:in > `execute' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:207:in > `run_examples' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:205:in > `each' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:205:in > `run_examples' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:103:in > `run' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:23:in > `run' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:22:in > `each' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:22:in > `run' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/options.rb:127:in > `run_examples' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/command_line.rb:9:in > `run' > /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/bin/spec:4: > /usr/bin/spec:19:in `load' > /usr/bin/spec:19: > > > 2009/8/27 Oliver Barnes : >> i guess it must be something wrong with my setup then? i've been >> messing with my gem infrastructure. going to try reinstalling rspec >> >> 2009/8/27 David Chelimsky : >>> Sorry, but no. The spec you showed in the original email should work >>> exactly as you expect. Somehow, for reasons I don't understand, >>> stub!() appears to be returning a Proc instead of a mock proxy object. >>> >>> On Thu, Aug 27, 2009 at 9:35 AM, Oliver >>> Barnes wrote: >>>> does that shed any light? >>>> >>>> 2009/8/26 Oliver Barnes : >>>>> sure thing: >>>>> >>>>> http://pastie.org/595363 >>>>> >>>>> 2009/8/26 David Chelimsky : >>>>>> On Tue, Aug 25, 2009 at 6:19 PM, Oliver >>>>>> Barnes wrote: >>>>>>> Hello, >>>>>>> >>>>>>> I'm struggling with this controller spec for a few hours now >>>>>>> >>>>>>> http://pastie.org/594775 >>>>>>> >>>>>>> which is failing with an error I can't find any references about, >>>>>>> neither on the list nor on the web in general: >>>>>>> >>>>>>> Admin::ImagesController handling PUT /images/1 with successful update >>>>>>> should find the image requested >>>>>>> undefined method `and_return' for # >>>>>>> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >>>>>>> /tmp/textmate-command-1859.rb:3 >>>>>>> 15 ? ? ?before(:each) do >>>>>>> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >>>>>>> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >>>>>>> 18 ? ? ?end >>>>>>> >>>>>>> why would and_return() not be recognized, while stub!() is? >>>>>>> >>>>>>> has anybody experienced this problem before? I'm using rspec and >>>>>>> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >>>>>>> Spree 0.8.99 >>>>>> >>>>>> Please run this spec from the command line with --backtrace so we can >>>>>> see the full backtrace. Thanks. >>>>>> >>>>>>> >>>>>>> thanks >>>>>>> Oliver >>>>>>> _______________________________________________ >>>>>>> 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 > -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From oli.azevedo.barnes at gmail.com Fri Aug 28 21:33:10 2009 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Fri, 28 Aug 2009 22:33:10 -0300 Subject: [rspec-users] undefined method `and_return' In-Reply-To: References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> <6466d9040908270735r4d162243y1fecb45c726ac8d7@mail.gmail.com> <57c63afe0908270748i12afda41rc98d608c26354eef@mail.gmail.com> <6466d9040908270825m51a54790p5e0867e4cb54e578@mail.gmail.com> <6466d9040908281502u4c3f1d8ftc8ca2c622d9c7866@mail.gmail.com> Message-ID: <6466d9040908281833n2ecdfe47j2e2468b3767f7264@mail.gmail.com> I've done a project-wide search for stub!, and so far I haven't found a conflicting method... but i'm brain-dead right now, will look again tomorrow with fresh eyes. thanks for the response Rick 2009/8/28 Rick DeNatale : > I don't usually top-post but in this case I think it works better. > > Is there ANY chance that Image or one of it's superclasses has defined > a stub! method which would override the one in Spec::Mocks::Methods ? > > On Fri, Aug 28, 2009 at 6:02 PM, Oliver > Barnes wrote: >> sorry to bother again, but no luck even after reinstalling rspec + rspec-rails: >> >> Big-Mac:spree(product-image-updates-fix) $ spec >> spec/controllers/admin/images_controller_spec.rb --backtrace >> /Users/oliver/Sites/spree/app/controllers/products_controller.rb:41: >> warning: parenthesize argument(s) for future version >> .FFFFF >> >> 1) >> NoMethodError in 'Admin::ImagesController handling PUT /images/1 with >> successful update should find the image requested' >> undefined method `and_return' for # >> ./spec/controllers/admin/images_controller_spec.rb:17: >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in >> `instance_eval' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in >> `eval_each_fail_fast' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in >> `each' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:70:in >> `eval_each_fail_fast' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_hierarchy.rb:17:in >> `run_before_each' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:103:in >> `run_before_each' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:124:in >> `before_each_example' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:39:in >> `execute' >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:48:in >> `timeout' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_methods.rb:37:in >> `execute' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:207:in >> `run_examples' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:205:in >> `each' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:205:in >> `run_examples' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/example/example_group_methods.rb:103:in >> `run' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:23:in >> `run' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:22:in >> `each' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:22:in >> `run' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/options.rb:127:in >> `run_examples' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/runner/command_line.rb:9:in >> `run' >> /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/bin/spec:4: >> /usr/bin/spec:19:in `load' >> /usr/bin/spec:19: >> >> >> 2009/8/27 Oliver Barnes : >>> i guess it must be something wrong with my setup then? i've been >>> messing with my gem infrastructure. going to try reinstalling rspec >>> >>> 2009/8/27 David Chelimsky : >>>> Sorry, but no. The spec you showed in the original email should work >>>> exactly as you expect. Somehow, for reasons I don't understand, >>>> stub!() appears to be returning a Proc instead of a mock proxy object. >>>> >>>> On Thu, Aug 27, 2009 at 9:35 AM, Oliver >>>> Barnes wrote: >>>>> does that shed any light? >>>>> >>>>> 2009/8/26 Oliver Barnes : >>>>>> sure thing: >>>>>> >>>>>> http://pastie.org/595363 >>>>>> >>>>>> 2009/8/26 David Chelimsky : >>>>>>> On Tue, Aug 25, 2009 at 6:19 PM, Oliver >>>>>>> Barnes wrote: >>>>>>>> Hello, >>>>>>>> >>>>>>>> I'm struggling with this controller spec for a few hours now >>>>>>>> >>>>>>>> http://pastie.org/594775 >>>>>>>> >>>>>>>> which is failing with an error I can't find any references about, >>>>>>>> neither on the list nor on the web in general: >>>>>>>> >>>>>>>> Admin::ImagesController handling PUT /images/1 with successful update >>>>>>>> should find the image requested >>>>>>>> undefined method `and_return' for # >>>>>>>> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >>>>>>>> /tmp/textmate-command-1859.rb:3 >>>>>>>> 15 ? ? ?before(:each) do >>>>>>>> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >>>>>>>> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >>>>>>>> 18 ? ? ?end >>>>>>>> >>>>>>>> why would and_return() not be recognized, while stub!() is? >>>>>>>> >>>>>>>> has anybody experienced this problem before? I'm using rspec and >>>>>>>> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >>>>>>>> Spree 0.8.99 >>>>>>> >>>>>>> Please run this spec from the command line with --backtrace so we can >>>>>>> see the full backtrace. Thanks. >>>>>>> >>>>>>>> >>>>>>>> thanks >>>>>>>> Oliver >>>>>>>> _______________________________________________ >>>>>>>> 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 >> > > > > -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Twitter: http://twitter.com/RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Fri Aug 28 23:26:56 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 28 Aug 2009 23:26:56 -0400 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <6466d9040908281833n2ecdfe47j2e2468b3767f7264@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <57c63afe0908260236yb4c8d7ar2da8e6de54c018dc@mail.gmail.com> <6466d9040908260657p5395517br9b3c4f791112bfed@mail.gmail.com> <6466d9040908270735r4d162243y1fecb45c726ac8d7@mail.gmail.com> <57c63afe0908270748i12afda41rc98d608c26354eef@mail.gmail.com> <6466d9040908270825m51a54790p5e0867e4cb54e578@mail.gmail.com> <6466d9040908281502u4c3f1d8ftc8ca2c622d9c7866@mail.gmail.com> <6466d9040908281833n2ecdfe47j2e2468b3767f7264@mail.gmail.com> Message-ID: On Fri, Aug 28, 2009 at 9:33 PM, Oliver Barnes wrote: > I've done a project-wide search for stub!, and so far I haven't found > a conflicting method... but i'm brain-dead right now, will look again > tomorrow with fresh eyes. thanks for the response Rick I'd be tempted to run the spec under rdebug, put a breakpoint before the stub! call and step into it to see what's going on. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From cremes.devlist at mac.com Sun Aug 30 10:24:05 2009 From: cremes.devlist at mac.com (Chuck Remes) Date: Sun, 30 Aug 2009 09:24:05 -0500 Subject: [rspec-users] [Q] testing WIN32OLE_EVENT callbacks In-Reply-To: <210FC527-6939-47C8-B5F8-68484A9FCA83@mattwynne.net> References: <43E6AABB-C015-4892-BC5D-DBCE05CCA79C@mattwynne.net> <8CE70F40-10B1-41F2-9F67-536B387AC792@mac.com> <210FC527-6939-47C8-B5F8-68484A9FCA83@mattwynne.net> Message-ID: On Aug 27, 2009, at 12:22 PM, Matt Wynne wrote: > > On 27 Aug 2009, at 17:02, Chuck Remes wrote: >> >> Let's assume that method1 and method2 are acting upon other objects >> that I can also mock via DI. How can I generate the 'StartEvent' so >> that the block above is executed? BTW, the layers are as separated >> as they are going to get. In the WIN32OLE_EVENT class you *must* >> pass a block as shown above. I don't know how to get that block to >> execute in my specs without actually connecting to the COM service >> and getting it to generate that 'StartEvent'. Do you know of >> another way? >> >> it "should execute the block upon receipt of event 'StartEvent'" do >> handler = mock("event handler") >> handler.should_receive(:on_event).with('StartEvent') # necessary? >> >> obj1_mock = mock("obj1") >> obj1.should_receive(:method1) >> >> foo = Foo.new >> foo.obj1 = obj1 >> >> foo.bar >> # callback has been set; how do I generate the 'StartEvent' >> # to run that block? >> foo.??? >> end > > So I'm not sure if you can simulate a block being yeilded with > RSpec's mocks, it's probably possible but I think you'd be simpler > using a hand-made fake: > > class FakeEventHandler > def initialize(*args_to_yield) > @args_to_yield = *args_to_yield > end > > def on_event(event_name) > yield *@args_to_yield > end > end > > Something like that. > > Point being, a test-double (fake) doesn't always have to be a mock > object. I often forget this. I have written fakes in the past using just this technique but it's so rare that I had forgotten about it again. I usually remember things permanently after I have had to rediscover them 4 or 5 times. :) Thanks for your insight. This technique will cure my testing problem. cr From matt at mattwynne.net Sun Aug 30 17:35:37 2009 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 30 Aug 2009 22:35:37 +0100 Subject: [rspec-users] Using "with(params)" with stubs make any sense? In-Reply-To: <1e5bcefd0908281144h73ae84b5ge11001bc2fe16dab@mail.gmail.com> References: <1e5bcefd0908281144h73ae84b5ge11001bc2fe16dab@mail.gmail.com> Message-ID: <8A6997D2-4803-47CB-A75F-BA5265C0D2AB@mattwynne.net> On 28 Aug 2009, at 19:44, Marcelo de Moraes Serpa wrote: > Hello list, > > Since stubs don't set expectations, do we have any use-case where > stubbing like this makes sense: > > @mock.stub!(:method).with(anything()).and_return(@collection). > > It is clear that and_return is the value from stubbing, but the with > doesn't make any sense, in case, IMO. I *think* the point here is that it would be distinct from another stub on the same method that specified #with some specific parameters. The one #with(anything()) would then be used as the fall-back. Maybe? From timcharper at gmail.com Mon Aug 31 18:25:38 2009 From: timcharper at gmail.com (Tim Harper) Date: Mon, 31 Aug 2009 17:25:38 -0500 Subject: [rspec-users] Workaround for spec_server "can't dup NilClass" In-Reply-To: <769672b909e943a31ddbcf9bc14dbebc@ruby-forum.com> References: <769672b909e943a31ddbcf9bc14dbebc@ruby-forum.com> Message-ID: Hi Dave, Have you voted for spork-windows support? It's getting closer, but issues will be tackled in the order of most votes. http://github.com/timcharper/spork/issues#issue/3 Tim On Thu, Aug 20, 2009 at 12:11 PM, Dave Nolan wrote: > On recent versions of RSpec/RSpec rails, if you are using > Machinist/Factory_Girl or similar, you may get "can't dup NilClass" > errors running specs through spec_server. (Not on the initial run, but > on all subsequent runs.) > > The workaround is to manually re-load the factories/templates each spec > run e.g. by placing "load" statements within the Spec::Runner.configure > block in spec_helper. > > I understand spec_server is deprecated but its replacement (spork) is > not windows-compatible. So if you're stuck with spec_server, this is for > you. > > (I'm running RSpec/RSpec Rails 1.2.7+ - YMMV) > > HTHSomeoneElse > Dave > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >