当使用open_id_authentication插件时,如何伪造RSpec用户故事/ Cucumber中的OpenID登录 [英] How do I fake OpenID login in RSpec user story/Cucumber when using open_id_authentication plugin

查看:304
本文介绍了当使用open_id_authentication插件时,如何伪造RSpec用户故事/ Cucumber中的OpenID登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个Cucumber方案,要求我有一个登录的用户 - 这通常会很简单,但我只使用OpenID身份验证(curtosy的身份验证插件)。但是,在挖掘open_id_authentication插件后,我不知道如何在Cucumber中实现这个。

I'm trying to write a Cucumber scenario that requires me to have a logged in user - that would normally be quite simple but I'm only using OpenID authentication (curtosy of the authentication plugin). However after digging through the open_id_authentication plugins guts I'm not sure how I could achieve this within Cucumber.

推荐答案

如果你把它放在你的features / support / env.rb:

I've figured out a way, if you place this in your features/support/env.rb:

ActionController::Base.class_eval do
  private

  def begin_open_id_authentication(identity_url, options = {})
    yield OpenIdAuthentication::Result.new(:successful), identity_url, nil
  end 
end

然后,您可以在适当的步骤中执行以下操作:

Then you can just do something like this in your appropriate step:

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

我只是完全打破了开放式身份验证黄瓜功能,显然如果我需要实例,其中有失败的登录我可以根据提供的identity_url。

I'm just completely clobbering the open id auth for the cucumber features, obviously if I need instances where there is failed login I could do that based on the supplied identity_url.

这篇关于当使用open_id_authentication插件时,如何伪造RSpec用户故事/ Cucumber中的OpenID登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆