title: Rails 3.0.9 + Devise + Cucumber + Capybara the infamous "No route matches /users/sign_out"
body: <p>I am using devise 1.4.2 with rails 3.0.9, cucumber-rails 1.0.2, capybara 1.0.0. I got <code>No route matches "/users/sign_out"</code> error when I clicked logout. I added <code>:method =&gt; :delete</code> to link_to tag after going through this so question ( <a href="https://stackoverflow.com/questions/6557311/no-route-matches-users-sign-out-devise-rails-3">no-route-matches-users-sign-out-devise-rails-3</a> ). </p>
  
  <p>Since I replaced prototype with jquery, I also had to change</p>
  
  <pre><code>config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>config.action_view.javascript_expansions[:defaults] = %w(jquery jquery_ujs)
  </code></pre>
  
  <p>to get around rails.js not found error.</p>
  
  <p>Although with above changes I am able to successfully sign out and redirected to root, when I look at response of localhost:3000/users/sign_out request in FireBug it shows the same routing error message <a href="http://tardis1.tinygrab.com/auhm" rel="nofollow noreferrer">click here to see the screenshot with notes</a></p>
  
  <p>After successfully implementing authentication to rails 3 app through devise, When I added feature and specs using Cucumber + Capybara + RSpec following this tutorial (<a href="http://github.com/RailsApps/rails3-devise-rspec-cucumber/wiki/Tutorial" rel="nofollow noreferrer">github.com/RailsApps/rails3-devise-rspec-cucumber/wiki/Tutorial</a>), I got following error</p>
  
  <pre><code>When I sign in as "user@test.com/please"                              # features/step_definitions/user_steps.rb:41
  Then I should be signed in                                            # features/step_definitions/user_steps.rb:49
  And I sign out                                                        # features/step_definitions/user_steps.rb:53
    No route matches "/users/sign_out" (ActionController::RoutingError)
    &lt;internal:prelude&gt;:10:in `synchronize'
    ./features/step_definitions/user_steps.rb:55:in `/^I sign out$/'
    features/users/sign_out.feature:10:in `And I sign out'
  And I should see "Signed out"                                         # features/step_definitions/web_steps.rb:105
  When I return next time                                               # features/step_definitions/user_steps.rb:60
  Then I should be signed out  
  </code></pre>
  
  <p>with the following step_definition for 'I sign out'</p>
  
  <pre><code>Then /^I sign out$/ do
      visit('/users/sign_out')
  end
  </code></pre>
  
  <p>I searched a lot and found that this is because of unobrusive javascript in Rails 3 being used for 'data-method' attributes, but I also read somewhere that Capybara does check for data-method attributes and behaves accordingly. But it did not work for me, so following this post <a href="http://blog.ardes.com/2010/4/28/capybara-and-rack-test-sessions-and-http-methods" rel="nofollow noreferrer">Capybara attack: rack-test, lost sessions and http request methods</a> I changed my step definition to following:</p>
  
  <pre><code>Then /^I sign out$/ do
      rack_test_session_wrapper = Capybara.current_session.driver
      rack_test_session_wrapper.process :delete, '/users/sign_out'
  end
  </code></pre>
  
  <p>but I got undefined method <code>process</code> for <code>Capybara::RackTest::Driver (NoMethodError)</code>.</p>
  
  <p>Following this lead I changed the above step definition as following:</p>
  
  <pre><code>Then /^I sign out$/ do
      rack_test_session_wrapper = Capybara.current_session.driver
      rack_test_session_wrapper.delete '/users/sign_out'
  end
  </code></pre>
  
  <p>This at least passed the 'I sign out' step, but it did not redirected to the home page after signing out and the next step failed:</p>
  
  <pre><code>And I should see "Signed out"                                         # features/step_definitions/web_steps.rb:105
    expected there to be content "Signed out" in "YasPiktochart\n\n  \n      Signed in as user@test.com. Not you?\n      Logout\n  \n\n    Signed in successfully.\n\n  Home\n  User: user@test.com\n\n\n\n" (RSpec::Expectations::ExpectationNotMetError)
    ./features/step_definitions/web_steps.rb:107:in `/^(?:|I )should see "([^"]*)"$/'
    features/users/sign_out.feature:11:in `And I should see "Signed out"'
  </code></pre>
  
  <p>After all this I had to resort to adding 'GET' method for logout in the routes file:</p>
  
  <pre><code>devise_for :users do get 'logout' =&gt; 'devise/sessions#destroy' end
  </code></pre>
  
  <p>modified my view from</p>
  
  <pre><code>&lt;%= link_to "Logout", destroy_user_session_path, :method =&gt; :delete %&gt;
  </code></pre>
  
  <p>to</p>
  
  <pre><code>&lt;%= link_to "Logout", logout_path %&gt;
  </code></pre>
  
  <p>and changed my step definition to following:</p>
  
  <pre><code>Then /^I sign out$/ do
      visit('/logout')
  end
  </code></pre>
  
  <p>This obviously solved all the problems, all the tests passed and firebug did not show any error on sign_out. But I know that using 'get' request for destroying sessions is not a good practice, because it's a state-changing behavior. </p>
  
  <p>Could this be due to particular version or Rails, Devise, Cucumber-Rails, or Capybara I am using? I want to use Devise's default sign_out route instead of overriding it with get method and be able to do BDD using Cucumber and RSpec. I am new to using Cucumber+Capybara, does there exists another method to send POST request instead of using "visit('/users/sign_out')", which only uses GET method?</p>