For several of my cuke scenarios, I want to POST the user to a page with an object in the params, so that Rails will make a new object in the database. Is there a convenient way to send a POST+params to an action (either using something in cucumber or rails) or do I have to write my own function using Net::Http?
views:
116answers:
2It sounds like you don't have a form for this action? If you do have a form, you just complete the interaction via the web UI (using the tool of your choice ... webrat etc etc)
Otherwise, if this is to setup some test data, it's probably better to create the object directly in a step.
Given that an object exists
Do ...
Under the "Given" step, create the necessary object too meet the assumption in the rest of the test steps.
Just visit the controller you want to post some parameters to in order to create an object.
You certainly do not need a form to do this. Just post the values to whatever controller is handling these posts and continue on with your testing. All the controller cares about is getting params to work with, however they get posted.
visit "/user", :post, :firstName => "Foo", :lastName => "Bar"
As detailed in the webrat documentation:
visit (url = nil, http_method = :get, data = {})