2016-04-26 11 views
0

私はアクションでcheckouts_controller.rbを持っている:コントローラのヘルパーステートメントをテストするには?

def create 
    if create_customer(params[:stripeToken], @plan.my_plan_id, params[:code], params[:new_price]) 
     redirect_to user_path(id: current_user.to_param, customer_share: true) 
    else 
     redirect_to new_checkout_path(plan_id: @plan) 
    end 
end 

users_helper.rbで:

def create_customer 
if customer != nil 
... 
else 
flash[:error] = 'Something went wrong, please try again.' 
end 

は、だから私は他にチェックし、 flash[:error]ためにRSpecの中でそれをテストする必要があります。

答えて

0

私はcreate_customermake the code testableへの引数としてflashに合格しています。これはOOPの原則とも一致しています。その後、

しかし、あなたは本当にそれがあるとして、コードをテストする必要がある場合、:

module UsersHelper 
    def flash 
    @flash ||= {} 
    end 
end 

describe UsersHelper do 
    subject { Object.new.extend(described_class) } 

    context 'Customer does not exist' do 
    it 'sets flash mesage' do 
     # your test code 
    end 
    end 
end 
+0

火災ストライプ:: InvalidRequestError –

+0

どうやらあなたは 'ストライプruby'宝石を使用しています。ストライプ関連のすべての要件を満たす必要があります。 – Uzbekjon

関連する問題