Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在插件中使用rspec测试rails控制器_Ruby On Rails_Rspec_Ruby On Rails Plugins - Fatal编程技术网

Ruby on rails 在插件中使用rspec测试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

我正在编写一个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 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