[rspec-users] what does 'these' mean in a PUT controller spec?
hi, all, the spec above is found in my controller spec for a 'category' resource. It's a generated spec. - start extract describe "PUT update" do describe "with valid params" do it "updates the requested category" do category = Category.create! valid_attributes # Assuming there are no other categories in the database, this # specifies that the Category created on the previous line # receives the :update_attributes message with whatever params are # submitted in the request. Category.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) put :update, :id => category.id, :category => {'these' => 'params'} end - end extract When the spec is run, it fails with the error below. - start extract 1) CategoriesController PUT update with valid params updates the requested category Failure/Error: put :update, :id => category.id, :category => {'these' => 'params'} # received :update_attributes with unexpected arguments expected: ({"these"=>"params"}) got: ({"these"=>"params", "updated_by"=>1}) # /Users/anexiole/projects/try_rails/app/controllers/ categories_controller.rb:72:in `block in update' # /Users/anexiole/projects/try_rails/app/controllers/ categories_controller.rb:71:in `update' # ./categories_controller_spec.rb:92:in `block (4 levels) in ' Finished in 19.15 seconds 16 examples, 1 failure Failed examples: rspec ./categories_controller_spec.rb:85 # CategoriesController PUT update with valid params updates the requested category - end extract My 'update' method in the categories controller file itself has one added rule for which I will assign the current user's id to the updated_by attribute before a call to update_attribute is made. - start extract # PUT /categories/1 # PUT /categories/1.json def update # Record current user's id as he/she created the part params[:category][:updated_by] = current_user.id @category = Category.find(params[:id]) respond_to do |format| if @category.update_attributes(params[:category]) format.html { redirect_to @category, notice: 'Category was successfully updated.' } format.json { head :ok } else format.html { render action: "edit" } format.json { render json: @category.errors, status: :unprocessable_entity } end end end - end extract Can someone please tell me what does 'these' refer to in the spec? Where can I read up more about them? I would like to fix the failing spec example. Thank you Gorodn ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] what does 'these' mean in a PUT controller spec?
On Jan 16, 2012, at 4:59 AM, Gordon wrote: > hi, all, > > the spec above is found in my controller spec for a 'category' > resource. > > It's a generated spec. > > - start extract > describe "PUT update" do >describe "with valid params" do > it "updates the requested category" do >category = Category.create! valid_attributes ># Assuming there are no other categories in the database, this ># specifies that the Category created on the previous line ># receives the :update_attributes message with whatever params > are ># submitted in the request. > > Category.any_instance.should_receive(:update_attributes).with({'these' > => 'params'}) >put :update, :id => category.id, :category => {'these' => > 'params'} > end > - end extract > > When the spec is run, it fails with the error below. > > - start extract > > 1) CategoriesController PUT update with valid params updates the > requested category > Failure/Error: put :update, :id => category.id, :category => > {'these' => 'params'} > # received :update_attributes with > unexpected arguments > expected: ({"these"=>"params"}) > got: ({"these"=>"params", "updated_by"=>1}) > # /Users/anexiole/projects/try_rails/app/controllers/ > categories_controller.rb:72:in `block in update' > # /Users/anexiole/projects/try_rails/app/controllers/ > categories_controller.rb:71:in `update' > # ./categories_controller_spec.rb:92:in `block (4 levels) in (required)>' > > Finished in 19.15 seconds > 16 examples, 1 failure > > Failed examples: > > rspec ./categories_controller_spec.rb:85 # CategoriesController PUT > update with valid params updates the requested category > > - end extract > > My 'update' method in the categories controller file itself has one > added rule for which > I will assign the current user's id to the updated_by attribute > before a call to update_attribute is made. > > - start extract > # PUT /categories/1 > # PUT /categories/1.json > def update ># Record current user's id as he/she created the part >params[:category][:updated_by] = current_user.id > >@category = Category.find(params[:id]) > >respond_to do |format| > if @category.update_attributes(params[:category]) >format.html { redirect_to @category, notice: 'Category was > successfully updated.' } >format.json { head :ok } > else >format.html { render action: "edit" } >format.json { render json: @category.errors, > status: :unprocessable_entity } > end >end > end > > - end extract > > > Can someone please tell me what does 'these' refer to in the spec? > Where can I read up more about them? > I would like to fix the failing spec example. What's being specified here is that the contents of params[:category] are passed to update attributes. What they actually contain is not of concern to the controller or the controller spec, since they get passed directly to the model in the generated controller. 'these' => 'params' could just as easily be 'foo' => 'bar'. The important thing is that the same params get received by the model object. The reason the spec is failing now is that the line you added modifies the hash before it gets sent to model object. If you change the spec to this: Category.any_instance.should_receive(:update_attributes).with('these' => 'params', 'updated_by' => 1) then it will pass. If you find 'these' => 'params' to be confusing, feel free to change it to what ever you like. Just make sure you do so in both places in the example. HTH, David ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] rspec and requests, and folders conventions
I'm trying to run rspec requests, using jruby, and I set the defaults in a env.rb file, but it doesn't seem to be loaded when I run the specs. My folder setup is: /spec/requests/ /spec/requests/section/section_spec.rb /spec/support/env.rb (where I configured selenium as the driver etc.) I also tried putting support here: /spec/requests/support/env.rb When I run rspec, it says I need a rack test or something. I just want to confirm, will rspec auto load the env.rb with any of the above folder conventions, or do I have to require it manually somewhere? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec and requests, and folders conventions
On Jan 16, 2012, at 9:16 AM, S Ahmed wrote: > I'm trying to run rspec requests, using jruby, and I set the defaults in a > env.rb file, but it doesn't seem to be loaded when I run the specs. > > My folder setup is: > > /spec/requests/ > /spec/requests/section/section_spec.rb > /spec/support/env.rb (where I configured selenium as the driver etc.) > > > I also tried putting support here: > > /spec/requests/support/env.rb > > When I run rspec, it says I need a rack test or something. > > I just want to confirm, will rspec auto load the env.rb with any of the above > folder conventions, No. > or do I have to require it manually somewhere? Yes. The convention is to do something like this in spec/spec_helper.rb: Dir["spec/support/**/*.rb"].each {|f| require f} This can be found in the spec_helper.rb generated by rspec-rails when you run "rake rspec:install", but that's just a convention/convenience. There's nothing in RSpec that implicitly loads files in spec/support. HTH, David ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] rspec output on windows
I have rails 3.1.3 and rspec 2.8.0 on windows 7 (32bit) installed. When running rspec I receive the following output: ←[32m.←[0m←[32m.←[0m Finished in 0.33 seconds ←[32m2 examples, 0 failures←[0m I have no glue how to get rid of the "special characters". Since I am new to rails I appreciate any help or suggestions. Tom -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec output on windows
On Mon, Jan 16, 2012 at 5:41 PM, Thomas Krebs wrote: > I have rails 3.1.3 and rspec 2.8.0 on windows 7 (32bit) installed. > When running rspec I receive the following output: > > ←[32m.←[0m←[32m.←[0m > > Finished in 0.33 seconds > ←[32m2 examples, 0 failures←[0m > > I have no glue how to get rid of the "special characters". Since I am > new to rails I appreciate any help or suggestions. Remove --color / --colour option from project .rspec file (or rspec.opts file, don't remember the name) -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exupéry ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] rspec output on windows
thanks - that worked! -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] Controller specs and default_url_options
Hello, I'm using Rails 3.1.3 with rspec-rails 2.8.1. I have a scope ':locale' in routes.rb and I want to run controller and routing specs. I'm aware of the problem with setting default_url_options in application.rb controller so I apply the solution found in the last comment on rspec issue #255 ( https://github.com/rspec/rspec-rails/issues/255 ) #./spec/support/default_locale.rb class ActionView::TestCase::TestController def default_url_options(options={}) { :locale => I18n.default_locale } end end class ActionDispatch::Routing::RouteSet def default_url_options(options={}) { :locale => I18n.default_locale } end end #./spec/controllers/categories_controller_spec.rb require "spec_helper" describe CategoriesController do describe "GET index" do it "assigns all categories as @categories" do category = Factory :category get :index assigns(:categories).to_a.should eq([category]) end end end This test fails with routing error but if I use "get :index, locale: :fr" instead of just "get :index" the test pass. This test is a example of controller spec but I have failing tests for routing and request. (I have no view specs but I'm pretty sure they would also fail) I can't figure out where the problem come from and why the patch doesn't solve it. Is there another thing to do ? (I just put the code in ./spec/support/default_locale.rb and verify that it loads correctly). Thanks in advance. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Controller specs and default_url_options
On Jan 16, 2012, at 5:17 PM, Titinux wrote: > Hello, > > I'm using Rails 3.1.3 with rspec-rails 2.8.1. I have a scope ':locale' > in routes.rb and I want to run controller and routing > specs. I'm aware of the problem with setting default_url_options in > application.rb controller so I apply the solution found in the last > comment on rspec issue #255 ( https://github.com/rspec/rspec-rails/issues/255 > ) > > #./spec/support/default_locale.rb > class ActionView::TestCase::TestController > def default_url_options(options={}) >{ :locale => I18n.default_locale } > end > end > > class ActionDispatch::Routing::RouteSet > def default_url_options(options={}) >{ :locale => I18n.default_locale } > end > end > > #./spec/controllers/categories_controller_spec.rb > require "spec_helper" > > describe CategoriesController do > > describe "GET index" do >it "assigns all categories as @categories" do > category = Factory :category > > get :index > assigns(:categories).to_a.should eq([category]) >end > end > end > > This test fails with routing error but if I use "get :index, > locale: :fr" instead of just "get :index" the test pass. > This test is a example of controller spec but I have failing tests for > routing and request. (I have no view specs but > I'm pretty sure they would also fail) > > I can't figure out where the problem come from and why the patch > doesn't solve it. Is there another thing to do ? (I just put the code > in ./spec/support/default_locale.rb and verify that it loads > correctly). > > Thanks in advance. No guarantees here, but it's possible that ActionView::TestCase::TestController is not loaded yet, in which case its own definition of default_url_options would clobber yours when it does get loaded. Try this instead: ActionView::TestCase::TestController.class_eval do undef_method :default_url_options def default_url_options(options={}) { :locale => I18n.default_locale } end end ActionDispatch::Routing::RouteSet.class_eval do undef_method :default_url_options def default_url_options(options={}) { :locale => I18n.default_locale } end end If those classes aren't loaded yet, Rails will find and load them first (via its autoload strategy) before invoking class_eval on them, thus ensuring that you're replacing the existing methods rather than writing methods that will later be replaced. HTH, David ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] does jruby rspec have to use selenium?
With jruby and rspec requests, do you have to use selenium webdriver? I'm confused, with ruby and rubyonrails using cucumber with capybara, I didn't have to set the default driver, what was it using and can i use that with jruby? Things just worked w/o me even having to know about it :) ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] does jruby rspec have to use selenium?
On Jan 16, 2012, at 7:35 PM, S Ahmed wrote: > With jruby and rspec requests, do you have to use selenium webdriver? > > I'm confused, with ruby and rubyonrails using cucumber with capybara, I > didn't have to set the default driver, what was it using and can i use that > with jruby? Things just worked w/o me even having to know about it :) > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users They capybara build is passing with jRuby: http://travis-ci.org/#!/jnicklas/capybara/jobs/512756 Just check out the README to get it setup with RSpec - it's all there. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] does jruby rspec have to use selenium?
I'm using jruby and with a java app, so after reading it is clear I can only use selenium since it is not a rack app. selenium is very very slow, sheesh! I was hoping there was a better way. It keeps the firefox browser open also, which is strange (after it completes running). On Mon, Jan 16, 2012 at 10:51 PM, Justin Ko wrote: > > On Jan 16, 2012, at 7:35 PM, S Ahmed wrote: > > > With jruby and rspec requests, do you have to use selenium webdriver? > > > > I'm confused, with ruby and rubyonrails using cucumber with capybara, I > didn't have to set the default driver, what was it using and can i use that > with jruby? Things just worked w/o me even having to know about it :) > > ___ > > rspec-users mailing list > > rspec-users@rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > They capybara build is passing with jRuby: > http://travis-ci.org/#!/jnicklas/capybara/jobs/512756 > > Just check out the README to get it setup with RSpec - it's all there. > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users