【发布时间】:2012-03-05 23:15:38
【问题描述】:
您好,感谢您的耐心等待! 我的 rails 应用程序结合使用 rspec 和 shoulda 来运行测试。测试是自动化的 overguard 和 spork。我的一个控制器测试看起来像
它{should respond_with(:success)}
运行测试时我得到
预期响应为 200,但为 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
【问题讨论】:
-
你没有重定向吗?
-
目前没有。 routes.rb 只是声明了
resources :plans并有一个类似match '/pricing' => 'plans#index'的别名。你知道我之前提到的测试是在 PlansController 类的方法上。 -
嗯,重定向通常发生在控制器内
-
也许您在此操作之前有一些身份验证过滤器,而您没有在规范中定义它
-
编辑问题以显示更多代码,反正我的控制器中没有任何重定向 atm。
标签: ruby-on-rails testing rspec shoulda