Justin Love
Justin Love

Reputation: 4447

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

Upvotes: 0

Views: 1687

Answers (2)

Tom Wang
Tom Wang

Reputation: 898

I believe the problem is that MyController is not extending ApplicationController. That's why the method action is not defined for MyController.

Upvotes: 2

Justin Love
Justin Love

Reputation: 4447

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

Upvotes: 0

Related Questions