Ruby on rails 在插件中使用rspec测试rails控制器
我正在编写一个Rails插件,我希望能够测试插件中的控制器:Ruby on rails 在插件中使用rspec测试rails控制器,ruby-on-rails,rspec,ruby-on-rails-plugins,Ruby On Rails,Rspec,Ruby On Rails Plugins,我正在编写一个Rails插件,我希望能够测试插件中的控制器: describe ReportsController, :type => :controller do it "shows paginated reports if the user is authorized" do get 'index' response.should render_template("index") end end 不幸的是,这会导致以下错误: NoMethodError i
describe ReportsController, :type => :controller do
it "shows paginated reports if the user is authorized" do
get 'index'
response.should render_template("index")
end
end
不幸的是,这会导致以下错误:
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>
有什么想法吗?通过添加以下内容解决:
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'spec/spec_helper.rb'))
要添加plugin_dir/spec/spec_helper.rb,请添加以下内容:
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'spec/spec_helper.rb'))
到plugin_dir/spec/spec_helper.rb