views:

624

answers:

1

I have a feeling I'm just doing something wrong syntactically but it's surprisingly difficult to Google "GET" so I was hoping someone here might know the answer to this.

I'm trying to test a Rails controller from an RSpec test. I'm following an example I found here - http://www.elevatedrails.com/articles/2007/09/10/testing-controllers-with-rspec/ but I'm stuck on the actual execution of the method I'm testing.

I'm doing a GET request where as the post above does a POST. I'm passing in 2 parameters manufacturer and model.

My URL will ideally look something like http://mysite.com/Products/index/Manufacturer/ModelName

I can't figure out the syntax for the get request call in the rest. Right now I have

get :index, :manufacturer=>@manufacturer, :modelName=>@modelName

and I get back

ArgumentError in 'ProductController Find a valid product should retrieve the product' wrong number of arguments (0 for 2)

Any thoughts?

edit: It should be noted @manufacturer and @modelName are defined in before(:each)

A: 

As i suspected this was me being green to rails programming.

I was defining the controller method as

def index(manufacturer, modelName)

When really i needed to use the params hash to access the attributes. I then had to define a custom route as id is the only parameter expected to be passed into a controller method by default.

once i did that i changed the spec to read

get :index, {:manufacturer=>@manufacturer, :modelName=>@modelName}

and it worked.

Thanks for the comments everyone.

JoshReedSchramm