我应该如何使用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
答案 0 :(得分:5)
我不清楚你在问什么。粗略地说,它将是:
describe ApplicationHelper do
context 'provider is facebook'
it 'should...' do
helper.build_rpx_url('facebook').should ==
等