0

I want to write tests for destroying objects on ruby on rails with cucumber and capybara and rack_test.

I think that I should write a scenario like:

When I try to delete X object
Then I should be on the index page for ...
And I should see "Object deleted successfully" 

I don't want to test it by clicking on a link on the index page or the show/edit page because I think I should be testing something different than purely the delete action.

Also, clicking on a link means that the interface is ok, but what happens if someone send a request to delete an object he can't and the interface doesn't show the link?

Given this, I need to send a delete request in the first step and then inspect the response to that request.

I've find troubles trying to do that because when I implement the first step as delete url then when I try page.should have_contain(text) I get the error No response yet. Request a page first. (Rack::Test::Error)

What do you think about it?

Bishma Stornelli
  • 2,539
  • 4
  • 22
  • 30

1 Answers1

0

check out how-do-you-post-to-a-url-in-capybara (answering another question) but there a several examples of how to use visit in a capybara test like

visit "item/:id/delete" 
Community
  • 1
  • 1
jethroo
  • 2,086
  • 2
  • 18
  • 30
  • Ok that question seems to solve one problem. Although after I do the post request, which works perfectly, I want to check that I'm redirected to the correct path. The problem is that after the post request, the variable `last_request.url` has the url of the redirected page but `current_url` doesn't and the step to check the url use `current_url` instead of `last_request.url`. Worst, if I change it for `last_request.url` I get `undefined method `url' for # (NoMethodError)`. – Bishma Stornelli Sep 27 '12 at 23:35