我有一个特殊情况 - 独立运行时rspec文件失败,但作为整个套件的一部分运行时运行正常。
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)>'
简化规范:
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
答案 0 :(得分:2)
我认为问题在于MyController
没有延伸ApplicationController
。这就是为action
定义MyController
方法的原因。
答案 1 :(得分:0)
class MyController
似乎阻止了Rails魔术类加载。测试应明确require
控制器,或扩展名应使用MyController.class_eval