简体   繁体   中英

Testing page redirect in rails

How can I test this in rails: A student goes to a list of their groups, and when they click the link, it brings them to that group page.

I have the gist of it down, but how can I test that it went to a page? I was thinking something along the lines of:

expect(page).to eq()

but then I am not sure what to do from there. I don't want to just expect the page to have the name of the group, because that that would be on the overall list and the page the link would bring them to. Any advice?

You're looking for the redirect_to() method. So an example would be:

require 'spec_helper'

describe FoobarController do

  describe "GET foo" do
    it "redirects to bar" do
      get :foo
      expect(response).to redirect_to(bar_path)
    end
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM