[Ruby] sending POST/PUT/DELETE requests via cucumber steps in a Rails app

228 views
Skip to first unread message

Giuseppe Bertini

unread,
Apr 27, 2012, 3:25:53 AM4/27/12
to cu...@googlegroups.com
I my Rails app, I want features describing what happens if a user sends an invalid request bypassing the UI (say, submitting a forged form).

I know how to do this with controller rspecs, but I would like to test the full stack with cucumber, and obviously I cannot "visit pages" or "click buttons" to trigger the expected behavior (e.g. redirecting to the root path).

How can I write a step that does the equivalent to what the following does in rspec

delete :destroy, id: 2

I must be missing something obvious, but I cannot seem to find this info in the Cucumber Book or elsewhere.

Thanks,
Giuseppe

Andy

unread,
Apr 27, 2012, 4:19:03 AM4/27/12
to cu...@googlegroups.com
Use RestClient or a similar HTTP library.

-- There are two rules:
 
1) Please prefix the subject with [Ruby], [JVM] or [JS]. This allows people to filter messages.
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en

Aslak Hellesøy

unread,
Apr 27, 2012, 4:20:54 AM4/27/12
to cu...@googlegroups.com
This is explained in the REST chapter in the book.

Aslak

Thanks,
Giuseppe

Giuseppe Bertini

unread,
Apr 28, 2012, 3:28:48 AM4/28/12
to cu...@googlegroups.com
Thanks Andy & Aslak,
I am now trying the "in-process" approach with rack-test.

Quick question: when I call a rack-test method such as post, does it know about the ongoing session?
I mean, does it know that during the previous steps I successfully logged in (which is required before I can post anything).
Or are the capybara steps and the rack-test calls sort of independent of one another?
Because right now those rack-test requests do not cause any errors but seem to do absolutely nothing.

I suspect that even the way I formulate the questions gives away a fundamental lack of understanding of the process...
Sorry, and thanks in advance.

Giuseppe
Reply all
Reply to author
Forward
0 new messages