我不知道我做错了什么,真的需要一些帮助。我正在尝试写一个简单的IntegrationTest为一个多租户网站,其中每个帐户都有自己的子域。
但是,在运行测试时,我按照here的说明更改了IntegrationTest中的主机
Minitest::Assertion: Expected response to be a redirect to <http://subdomain1.example.com:3000/login> but was a redirect to <http://www.example.com:3000/>.
Expected "http://subdomain1.example.com:3000/login" to be === "http://www.example.com:3000/".
test/integration/feedback_flow_test.rb:8:in `block in <class:FeedbackFlowTest>'
Finished in 0.26594s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips我编辑了我的主机文件,以便让subdomain1.example.com和www.example.com指向127.0.0.1。为了让它工作,我还需要做些什么吗?下面是IntegrationTest的代码
require 'test_helper'
class FeedbackFlowTest < ActionDispatch::IntegrationTest
test "no token should go to the login page" do
host! 'subdomain1.example.com:3000'
get feedback_path
assert_redirected_to login_url
follow_redirect!
assert_select '.alert-danger h3', 'You are not authorized '
end
end发布于 2019-07-02 22:08:46
抱歉,各位。已通过查看test.log找到问题。似乎我忘了为accounts模型创建一个fixture。因此,当测试运行时没有创建帐户,从而导致错误。我总是在我的test_helper.rb文件中执行fixtures :all,以便它加载所有用于测试的fixture。
https://stackoverflow.com/questions/56853674
复制相似问题