[英]Ruby on Rails - RSpec test for direct route
I have a direct route like so: 我有这样的直接路线:
direct :homepage do
"http://www.rubyonrails.org"
end
And I am trying to test this but I am not sure how. 我试图测试这个,但我不知道如何。 This is what I have:
这就是我所拥有的:
describe 'redirect' do
it 'directs to homepage', type: :request do
get :homepage
expect(response).to redirect_to('http://www.rubyonrails.org')
end
end
But this fails: 但这失败了:
1) redirect directs to homepage
Failure/Error: get :homepage
URI::InvalidURIError:
bad URI(is not URI?): "http://www.example.com:80homepage"
I have the url_helpers included in my Rspec config. 我的url_helpers包含在我的Rspec配置中。
How do I test a direct route? 我如何测试直接路线?
See: https://guides.rubyonrails.org/routing.html#direct-routes 请参阅: https : //guides.rubyonrails.org/routing.html#direct-routes
As soon as I wrote this example, it became clear. 我一写这个例子就很清楚了。
describe 'redirect' do
it 'directs to homepage' do
expect(homepage_url).to eq('http://www.rubyonrails.org')
end
end
I was writing my test in request specs. 我在请求规范中写了我的测试。 This works.
这有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.