2010-07-22 95 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