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

发布于 2025-01-08 19:29:57 字数 3067 浏览 1 评论 0原文

我正在尝试在 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

和support/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 => '[email protected]',
      :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 => '[email protected]',
      }
    }
  }
end

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

当我进行手动测试时,一切正常,所以我很高兴我的配置没问题,这只是皮带和大括号。错误消息的信息量不大,所以我希望有人能够阻止一个明显的缺陷!我正在运行 Rails、devise、omniauth 和omniauth-facebook 的最新 gem。

编辑

查看日志,我在开发日志中看到以下内容:

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”

I'm trying to get some cucumber tests of omniauth with Facebook working.

Currently I get the following error:

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

I have the following omniauth_steps.rb file

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

And support/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 => '[email protected]',
      :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 => '[email protected]',
      }
    }
  }
end

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

When I do manual tests, everything works, so I'm happy my configuration is ok, this is just belt and braces. The error message isn't too informative so I'm hoping that someone can stop an obvious flaw! I'm running the latest gems for rails, devise, omniauth and omniauth-facebook.

Edit

Looking at the logs, I see this in the development log:

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

The test log is different, I get two 404s. The first is legit (I use a custom Omniauth setup) but the second is calling "users/auth/facebook" again instead of "/users/auth/facebook/callback"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文