2010-08-18 122 views
1

我應該如何去測試這個幫助器與RSpec?測試幫助器方法w/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 

回答

5

我不是很清楚你在問什麼。粗略地說,這將是:

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