简体   繁体   English

在Rails中测试页面重定向

[英]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. 我该如何在Rails中进行测试:一个学生转到他们的小组列表,当他们单击链接时,它会将他们带到该小组页面。

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. 您正在寻找redirect_to()方法。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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