我尝试使用facebook
测试一个简单的omniauth
登录信息。但是,收到错误消息“auth
'未定义variable
或method
。 omniauth
测试文档没有包含facebook
示例
运行黄瓜特征测试
undefined local variable or method `auth' for #<Cucumber::Rails::World:0x007fa17eeafc78> (NameError)
./features/step_definitions/microsites/quiz/microsites_quiz_entrant_sign_in_facebook_steps.rb:26:in `/^I log in with my facebook email and password quiz$/'
steps.rb文件
Then(/^I log in with my facebook email and password quiz$/) do
OmniAuth.config.add_mock(:facebook, {
:provider => "facebook",
:uid => '12345',
:name => "John Smith",
info: {
email: "test@test.com",
first_name: "Test",
last_name: "Tester",
gender: "male",
dob: auth.extra.raw_info.birthday
}
})
end
配置/环境/ test.rb
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({
:provider => 'twitter',
:uid => '123545'
})
模型文件
def self.from_facebook auth, campaign, password
campaign.entrants.where(fb_uid: auth.uid).first_or_create do |entrant|
entrant.fb_uid = auth.uid
entrant.email = auth.info.email
entrant.first_name = auth.info.first_name
entrant.last_name = auth.info.last_name
entrant.password = password
entrant.password_confirmation = password
entrant.campaign_id = campaign.id
# DOB is not returned from FB consistently, or not at all
entrant.dob = auth.extra.raw_info.birthday
# If DOB is returned, this create will pass, and this line should fire:
entrant.skip_confirmation!
end
end
答案 0 :(得分:1)
您正在嘲笑auth响应,因此您无权访问auth
对象以获取dob - 而是您需要类似
OmniAuth.config.add_mock(:facebook, {
:provider => "facebook",
:uid => '12345',
:name => "John Smith",
info: {
email: "test@test.com",
first_name: "Test",
last_name: "Tester",
gender: "male"
},
'extra' => {
'raw_info' => { 'dob' => '1980-01-01 or whatever format is returned by Facebook'}
}
})