您好,感谢您的耐心等待! 我的 Rails 应用程序使用 rspec 和 shoulda 的组合来运行测试。测试是自动进行的。我的一个 Controller 测试看起来像
it {should respond_with(:success)}
运行测试时我得到
Expected response to be a 200, but was 301
通过浏览和 wget 进行手动测试,一切正常,页面正确响应 200 状态代码。由于我对 Rails 测试还很陌生,所以我不太了解测试目前是如何运行的。它们是如何实现的?环境“测试”的目的是什么?是否有某种网络服务器在后台运行以运行测试?显然存在某种不需要的重定向。 提前致谢!
编辑:更多来源
Controller :
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
最佳答案
您在 get :index
上下文的 before block 中缺少 :each
,因此您永远不会调用索引操作。
更新如下:
context " get :index" do
before(:each) do
get :index
end
it { should respond_with(:success) }
end
关于ruby-on-rails - shoulda、rspec、guard、spork 与 http 响应有关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279398/