使用open_id_authentication插件时,如何在RSpec用户故事/ Cucumber中伪造OpenID登录

DEf*_*ion 6 openid rspec ruby-on-rails cucumber

我正在尝试编写一个Cucumber场景,要求我有一个登录用户 - 这通常很简单,但我只使用OpenID身份验证(认证插件的简化).然而,在深入挖掘open_id_authentication插件后,我不确定如何在Cucumber中实现这一点.

DEf*_*ion 4

我已经找到了一种方法,如果你把它放在你的 features/support/env.rb 中:

\n\n
ActionController::Base.class_eval do\n  private\n\n  def begin_open_id_authentication(identity_url, options = {})\n    yield OpenIdAuthentication::Result.new(:successful), identity_url, nil\n  end \nend\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后你可以在适当的步骤中执行类似的操作:

\n\n
Given /^I am logged in as "(.*)"$/ do |name|\n  user = User.find_by_name(user)\n  post \'/session\', :openid_url => user.identity_url\n  #\xc2\xa0Some assertions just to make sure our hack in env.rb is still working\n  response.should redirect_to(\'/\')\n  flash[:notice].should eql(\'Logged in successfully\')\nend\n
Run Code Online (Sandbox Code Playgroud)\n\n

我只是完全破坏了黄瓜功能的开放ID身份验证,显然如果我需要登录失败的实例,我可以根据提供的identity_url来做到这一点。

\n