[英]Test (with RSpec) a controller outside of a Rails environment
我正在创建一个gem,它将为将使用它的Rails应用程序生成一个控制器。 在尝试测试控制器时,这对我来说是一个反复试验的过程。 当测试模型,它已经很容易的,但在测试控制器时,ActionController的:: TestUnit不包括(如描述在这里 )。 我试过要求它,以及Rails中所有类似的东西,但没有用。
我需要在spec_helper中要求什么才能使测试生效?
谢谢!
这是一个工作正常的Test :: Unit测试示例,其中包含一个受测试的简单控制器。也许这里有些部分需要转移到rspec代码。
require 'rubygems'
require 'test/unit'
require 'active_support'
require 'active_support/test_case'
require 'action_controller'
require 'action_controller/test_process'
class UnderTestController < ActionController::Base
def index
render :text => 'OK'
end
end
ActionController::Routing::Routes.draw {|map| map.resources :under_test }
class MyTest < ActionController::TestCase
def setup
@controller = UnderTestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
test "should succeed" do
get :index
assert_response :success
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.