2010-07-22 67 views
1

我正在写一个Rails插件,我希望能够在插件中测试控制器内使用RSpec控制器:测试轨道插件

describe ReportsController, :type => :controller do 

    it "shows paginated reports if the user is authorized" do 
    get 'index' 
    response.should render_template("index") 
    end 

end 

不幸的是这将导致以下错误:

在插件的spec_helper.rb
NoMethodError in 'ReportsController index action shows paginated reports if the user is authorized' 
undefined method `get' for #<Spec::Example::ExampleGroup::Subclass_1::Subclass_1:0x7f7155e042a0> 

Rails的ENV加载:

ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..' 
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb')) 

任何想法?

回答

1

通过添加解决:

require File.expand_path(File.join(ENV['RAILS_ROOT'], 'spec/spec_helper.rb')) 

到PLUGIN_DIR /规格/ spec_helper.rb