Skip to content

Instantly share code, notes, and snippets.

@xunker
Created September 6, 2012 18:32
Show Gist options
  • Save xunker/3659267 to your computer and use it in GitHub Desktop.
Save xunker/3659267 to your computer and use it in GitHub Desktop.
Question about Rspec post with rocket_pants

I know you have to supply { :version => nnn } with each, but either that doesn't work with post or the post method is getting confused about which argument is the version number and which is the post payload. Didn't see anything in the docs about post(), only get() with rspec.

First, here are my routes:

api :version => 1 do
 resource :authenticate, :controller => "authenticate", :only => [ :show, :create, :update, :destroy ]
end

Now, the code I am having problems with. I want to simulate a post, so doing:

post :create, :version => 1, { :email => 'some@email.com', :password => 'some_password' }

..returns:

syntax error, unexpected '\n', expecting tASSOC (SyntaxError)

Similarly, doing:

post :create, { :email => 'some@email.com', :password => 'some_password' }, :version => 1

..returns:

ActionController::RoutingError: No route matches {:email=>"some@email.com", :password=>"some_password", :controller=>"authenticate", :action=>"create"}

What is the syntax for a post in rspec with RP? The standard rails/rspec syntax doesn't appear to work, or I am missing something.

@Sutto
Copy link

Sutto commented Sep 8, 2012

I believe the error it gives is an issue in the controller possibly (it's a parser error on some file) - so rails bails out generating the route since it needs to read the controller to render the route (I'd double check - ruby -c path/to/your/file should help there.

Ideally, version should be in the hash as the email / password params though - it is just a normal param. Doing that may also solve the problem. The other thing to consider there is using the default_version macro, e.g:

describe YourAwesomeController do

  default_version 1

end

Which will make all routes under the specified controller / actions automatically render the url for version one (so no need to include it on every item).

@xunker
Copy link
Author

xunker commented Sep 10, 2012

Thanks for your insight, after placing the :version symbol in proper place it is working now. I have forked + updated the readme to mention the post syntax and the default_version flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment