Rspec + Capybara在/ auth / developer上没有匹配RoutingError,它在开发中运行良好

时间:2015-12-04 12:42:08

标签: ruby-on-rails rspec capybara

该应用正在使用基本的omniauth登录策略。我的路线包括:

# config/routes.rb
root to: 'pages#root'

get '/auth/:provider/callback', to: 'sessions#create'
post '/auth/:provider/callback', to: 'sessions#create' # Needed for developer strategy

我刚刚开始实现一些功能测试(第一个,还没有单元测试)。它在第一次visit root_path通话时失败。

诊断这很困难,因为localhost:3000/auth/developer在我的开发环境中运行良好。有没有理由我的路线不会在测试中加载?

这是错误:

Failure/Error: visit root_path
     ActionController::RoutingError:
       No route matches [GET] "/auth/developer"

为了更好的衡量,我跑了$ RAILS_ENV=test rake routes然后回来了:

Prefix Verb   URI Pattern                        Controller#Action
    root GET    /                                  pages#root
         GET    /auth/:provider/callback(.:format) sessions#create
         POST   /auth/:provider/callback(.:format) sessions#create

编辑:自从阅读Omniauth Gem Docs以来,我已经实现了以下配置:

RSpec.configure do |config|
    config.use_transactional_fixtures = false
    config.include FactoryGirl::Syntax::Methods

  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
    OmniAuth.config.test_mode = true
    Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:developer]
  end
  ...
end

这没有任何帮助。

以下是规范:

require 'rails_helper'

feature 'user joins first conversation' do
    OmniAuth.config.mock_auth[:developer] = OmniAuth::AuthHash.new({
      :provider => 'developer',
      :uid => 'justuseapen@gmail.com'
    })

    scenario 'they receive quick tutorial from Alan' do
    visit root_path
    fill_in 'Email', with: 'any@email.com'
    click_button 'Sign In'
    expect(page).to have_css '#messages', 'My foobar'
  end
end

0 个答案:

没有答案