开发者

Testing rails controller with rspec within a plugin

I'm writing a Rails plugin and I'd like to be able to test a controller within the plugin:

des开发者_C百科cribe ReportsController, :type => :controller do

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

end

unfortunately this results in the following error:

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 in plugin's spec_helper.rb is loaded:

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

Any ideas?


Solved by adding:

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

to plugin_dir/spec/spec_helper.rb

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜