shoulda、rspec、guard、spork 的 http 响应问题
您好,感谢您的耐心等待! 我的 Rails 应用程序使用 rspec 和 Shoulda 的组合来运行测试。测试是自动进行的,overguard 和 spork。我的一个控制器测试看起来像
它{应该respond_with(:success)}
运行测试时我得到
预期响应为 200,但实际响应为 301
通过浏览和手动测试得到 301。 wget 一切正常,页面正确响应,状态代码为 200。由于我对 Rails 测试相当陌生,因此我可能不了解测试当前是如何运行的。它们是如何实施的?环境“测试”的目的是什么?是否有某种网络服务器在后台运行来运行测试?显然存在某种不需要的重定向。 提前致谢!
编辑:更多来源
控制器:
class PlansController < ApplicationController
def index
@plans=Plan.all
end
... more methods ...
end
测试:
describe PlansController do
before :each do
@plan=FactoryGirl.create(:plan)
end
context " get :index" do
before do
get :index
end
it {should respond_with(:success)}
end
... more tests..
end
Hello and thanks for you patience!
My rails app uses a combination of rspec and shoulda to run tests. The tests are automated over guard and spork. One of my controllers tests looks like
it {should respond_with(:success)}
When running tests i get
Expected response to be a 200, but was 301
manually testing by browsing & wget things go right, the page is responding correctly with 200 status code. As I am quite new to rails testing, proberly I am not understanding how the tests are currently ran. How are they implemented? What was the purpose of the environment 'test'? Is there some kind of webserver running in backgroud to run the tests? Obviously there is some kind of non-wanted redirecting.
Thanks in advance!
Edit: More sources
controller:
class PlansController < ApplicationController
def index
@plans=Plan.all
end
... more methods ...
end
test:
describe PlansController do
before :each do
@plan=FactoryGirl.create(:plan)
end
context " get :index" do
before do
get :index
end
it {should respond_with(:success)}
end
... more tests..
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在
get :index
上下文的 before 块中缺少:each
,因此您永远不会调用索引操作。更新如下:
You are missing an
:each
in the before block of the context forget :index
so you are never calling the index action.Update as follows: