ruby-on-railscontrollerrspecwebrat

Undefined method 'action' running single RSpec file for a rails controller


I have a peculiar situation - an rspec file fails when run independently, but run okay when run as part of the entire suite.

Failure/Error: visit oauth_callback_path
     NoMethodError:
       undefined method `action' for MyController:Class
     # <internal:prelude>:10:in `synchronize'
     # ./spec/requests/login_spec.rb:xx:in `block (5 levels) in <top (required)>'
     # ./spec/requests/login_spec.rb:xx:in `block (4 levels) in <top (required)>'

Simplified spec:

require 'spec_helper'

class MyController
  def oauth_response
    sign_in(
        ENV['TEST_ACCESS_TOKEN'],
        ENV['TEST_ACCESS_SECRET'])
    redirect_to root_path
  end
end


describe 'logging in' do
  it 'login' do
    visit oauth_callback_path
    response.should be_success
  end
end

Solution

  • The class MyController appears to be blocking Rails magic class loading. Either the test should explicitly require the controller, or the extension should be defined with MyController.class_eval