未定义的方法错误试图让omniauth黄瓜测试正常工作

时间:2012-02-22 11:29:48

标签: ruby-on-rails facebook devise cucumber omniauth

我正试图通过Facebook工作来获得omniauth的一些黄瓜测试。

目前我收到以下错误:

Given I am not logged in                         # features/step_definitions/user_steps.rb:79
When I go to the homepage                      # features/step_definitions/web_steps.rb:51
And I follow "Sign in"                         # features/step_definitions/web_steps.rb:61
Then I should see "Facebook"                   # features/step_definitions/web_steps.rb:110
When I sign in with facebook                   # features/step_definitions/omniauth_steps.rb:1
  undefined method `[]=' for nil:NilClass (NoMethodError)
  (eval):2:in `click_link'
  ./features/step_definitions/web_steps.rb:62:in `/^(?:|I )follow "([^"]*)"$/'
  features/users/login_with_facebook.feature:14:in `When I sign in with facebook'
Then I should be signed in                     # features/step_definitions/user_steps.rb:60

我有以下omniauth_steps.rb文件

Given /^I sign in with facebook$/ do
  step %{I follow "Facebook"}
end

并支持/ omniauth.rb

Before('@omniauth_test') do
  OmniAuth.config.test_mode = true
  p "OmniAuth.config.test_mode is #{OmniAuth.config.test_mode}"
  OmniAuth.config.mock_auth[:facebook] = {
    :provider => 'facebook',
    :uid => '1234567',
    :info => {
      :nickname => 'jbloggs',
      :email => 'joe@bloggs.com',
      :name => 'Joe Bloggs',
      :first_name => 'Joe',
      :last_name => 'Bloggs',
    },
    :credentials => {
      :token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
      :expires_at => 1321747205, # when the access token expires (if it expires)
      :expires => true # if you request `offline_access` this will be false
    },
    :extra => {
      :raw_info => {
        :id => '1234567',
        :name => 'Joe Bloggs',
        :first_name => 'Joe',
        :last_name => 'Bloggs',
        :username => 'jbloggs',
        :email => 'joe@bloggs.com',
      }
    }
  }
end

After('@omniauth_test') do
  OmniAuth.config.test_mode = false
end

当我进行手动测试时,一切正常,所以我很高兴我的配置没问题,这只是腰带和牙套。错误信息没有太多信息,所以我希望有人可以阻止一个明显的缺陷!我正在为rails,devise,omniauth和omniauth-facebook运行最新的宝石。

修改

查看日志,我在开发日志中看到了这一点:

Started GET "/users/auth/facebook" for 127.0.0.1 at 2012-02-22 14:52:16 +0100
  Processing by Users::SessionsController#setup as HTML
  Rendered text template (0.0ms)
Completed 404 Not Found in 2ms (Views: 0.6ms | ActiveRecord: 0.2ms)
Started GET "/users/auth/facebook/callback?code=AQ<snip>IE" for 127.0.0.1 at 2012-02-22 14:52:18 +0100
Processing by Users::SessionsController#setup as HTML

测试日志不同,我得到两个404。第一个是合法的(我使用自定义的Omniauth设置),但第二个是再次调用“users / auth / facebook”而不是“/ users / auth / facebook / callback”

0 个答案:

没有答案