[rspec-users] passing parameters when testing controller actions

norm codehacker at comcast.net
Tue Jul 28 13:44:37 EDT 2009


My grad_surveys_controller has a student_edit method. An id parameter
is passed in the url and a token is passed in a query string. For
example:
          http://www.example.com/students/34/grad_surveys/21/student_edit?token=ab56e1b47
so the params hash should contain
{"controller"=>"grad_surveys","action"=>"student_edit",
"student_id"=>"34", "id"=>"21", "token"=>"ab56e1b47"}

I am trying to test using the following example:

  it "should permit student access with the correct token supplied" do
    GradSurvey.stub!(:accepts_as_authorized).with
(:id=>"1",:token=>"ab56e1b47").and_return(true)
    GradSurvey.should_receive(:accepts_as_authorized).with
(:id=>"1", :token=>"ab56e1b47")

    get :student_edit, {:id=>"1", :token=>"ab56e1b47"}
  end

which fails with the message:
<GradSurvey(... snip... all the fields listed) (class)>
expected :accepts_as_authorized with ({:token=>"ab56e1b47", :id=>"1"})
but received it with ("1", "ab56e1b47")

What is the error in my example syntax that is causing the parameters
not to be correctly recognized.

thanks in advance for any assistance you are able to providd


More information about the rspec-users mailing list