Test Redirection with RSpec and Capybara (Rails)
        Posted  
        
            by 
                balanv
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by balanv
        
        
        
        Published on 2012-06-27T10:36:04Z
        Indexed on 
            2012/06/29
            3:16 UTC
        
        
        Read the original article
        Hit count: 170
        
I just have learnt how cool RSpec and Cabybara is, and now working around it to learn writing actual test.
I am trying to check if after clicking a link, there is a redirection to a specific page. Below is the scenario
1) I have a page /projects/list
        - I have an anchor with html "Back" and it links to /projects/show
Below is the test i wrote in rspec
describe "Sample" do
  describe "GET /projects/list" do
    it "sample test" do
      visit "/projects/list"
      click_link "Back"
      assert_redirected_to "/projects/show" 
    end
  end
end
The test fails with a failure message like below
    Failure/Error: assert_redirected_to "/projects/show"
     ArgumentError:
       @request must be an ActionDispatch::Request
Please suggest me on how i should test the redirection and what am i doing wrong?
© Stack Overflow or respective owner