views:

51

answers:

1

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

describe 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?

+1  A: 

Solved by adding:

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

to plugin_dir/spec/spec_helper.rb

snitko