如何testingparams传递到控制器在轨3,使用rspec?

我们的代码:

describe "GET show" do it "assigns the requested subcategory as @subcategory" do subcategory = Subcategory.create! valid_attributes get :show, :id => subcategory.id.to_s assigns(:subcategory).should eq(subcategory) end it "has a sort parameter in the url" do subcategory = Subcategory.create! valid_attributes get :show, {:id => subcategory.id.to_s, :params => {:sort => 'title'}} helper.params[:sort].should_not be_nil end end 

我收到以下错误信息:

 1) SubcategoriesController GET show has a sort parameter in the url Failure/Error: helper.params[:sort].should_not be_nil NameError: undefined local variable or method `helper' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_2:0x007f81a467c848> # ./spec/controllers/subcategories_controller_spec.rb:54:in `block (3 levels) in <top (required)>' 

我怎样才能在rspec中testingparams?

 get :show, {:id => subcategory.id.to_s, :params => {:sort => 'title'}} 

应该

 get :show, :id => subcategory.id.to_s, :sort => 'title' 

除非你的意思是通过params[:params][:sort]

 helper.params[:sort].should_not be_nil 

应该

 controller.params[:sort].should_not be_nil controller.params[:sort].should eql 'title' 

(如果你的意思是testing一个帮手,你应该写一个帮手规格。)