使用 RSpec 测试辅助方法 [英] Testing helper methods w/ RSpec

查看:43
本文介绍了使用 RSpec 测试辅助方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何使用 RSpec 测试这个助手?

How should I go about testing this helper with RSpec?

module ApplicationHelper
  def build_rpx_url(provider)
    signin_url(provider) << "?token_url=" << token_url << provider_params(provider)
  end


  private

  def signin_url(provider)
    case provider.downcase
    when 'facebook'; 'https://login.xyz.net/facebook/connect_start'
    when 'google';   'https://login.xyz.net/openid/start'
    when 'twitter';  'https://login.xyz.net/twitter/start'
    when 'linkedin'; 'https://login.xyz.net/linkedin/start'
    when 'yahoo';    'https://login.xyz.net/openid/start'
    end
  end

  def provider_params(provider)
    params = case provider.downcase
    when 'facebook'; ["ext_perm=publish_stream,email,offline_access"]
    when 'google';   ["openid_identifier=https://www.google.com/accounts/o8/id"]
    when 'twitter';  []
    when 'linkedin'; []
    when 'yahoo';    ["openid_identifier=http://me.yahoo.com/"]
    end

    params.empty? ? '' : "&" << params.join('&')
  end

  def token_url
    "#{new_user_session_url}?authenticity_token=#{Rack::Utils.escape(form_authenticity_token)}"
  end
end

推荐答案

我不太清楚你在问什么.粗略地说,应该是:

I'm not really clear on what you're asking. Roughly, it would be:

describe ApplicationHelper do 
  context 'provider is facebook' 
    it 'should...' do
      helper.build_rpx_url('facebook').should ==

这篇关于使用 RSpec 测试辅助方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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