質問したいこと
下記の街灯のソースコードような状況の時、
}.to change(payment_source, :gateway_customer_profile_id).from(nil).to start_with("cus_") .and change(payment_source, :gateway_payment_profile_id).from(nil).to start_with("card_") .and change(payment_source, :cc_type).from(nil).to eq("visa")
ここの部分で複数個条件を追加して判定していますが、下記のエラーメッセージが出てしまいます。
なぜこのエラーメッセージが出るのか、原因と解決法をご教示いただけますと幸いです。w
該当のソースコード
credit_card_spec.rb
require 'spec_helper' describe Spree::Gateway::StripeGateway::CreditCard do let!(:order) { create(:order_with_line_items, state: "payment") } let!(:creditcard_payment) { create(:creditcard_payment, order: order) } let(:payment_source) { creditcard_payment.source } describe "#create_profile" do FactoryGirl.create(:creditcard_gateway) def create_profile(payment) gateway_test = Spree::Gateway::StripeGateway::CreditCard.new gateway_test.create_profile(payment) end context "stripeのvisaカードトークンを使用した時" do it "cc_typeはvisa、gateway_customer_profile_idとgateway_payment_profile_idは正常なstripeのcustomerトークンが保存されるはず" do expect { create_profile(creditcard_payment) }.to change(payment_source, :gateway_customer_profile_id).from(nil).to start_with("cus_") .and change(payment_source, :gateway_payment_profile_id).from(nil).to start_with("card_") .and change(payment_source, :cc_type).from(nil).to eq("visa") end end end end
factories.rb
FactoryGirl.define do factory :creditcard, class: Spree::CreditCard do user_id 29311 token_id { 'tok_visa' } end factory :preferences, class: Hash do secret_key { 'hogehogehogehogehoge' } publishable_key { 'hogehogehogehogehoge' } server { 'test' } test_mode true initialize_with { attributes } end factory :creditcard_gateway, class: Spree::PaymentMethod do type { 'Spree::Gateway::StripeGateway::CreditCard' } name { 'spree_credit_card' } active 1 display_on { 'both' } auto_capture 1 preferences { build(:preferences) } end factory :creditcard_payment, class: Spree::Payment do order amount { 100.0 } state { 'checkout' } association(:payment_method, factory: :creditcard_gateway) association(:source, factory: :creditcard) end end
エラーメッセージ
1) Spree::Gateway::StripeGateway::CreditCard#create_profile stripeのvisaカードトークンを使用した時 cc_typeはvisa、gateway_customer_profile_idとgateway_payment_profile_idは正常なstripeのcustomerトークンが保存されるはず Failure/Error: expect { create_profile(creditcard_payment) }.to change(payment_source, :gateway_customer_profile_id).from(nil).to start_with("cus_") .and change(payment_source, :gateway_payment_profile_id).from(nil).to start_with("card_") .and change(payment_source, :cc_type).from(nil).to eq("visa") expected `Spree::CreditCard#gateway_customer_profile_id` to have changed to start with "cus_" and change `Spree::CreditCard#gateway_payment_profile_id` from nil to start with "card_" and change `Spree::CreditCard#cc_type` from nil to eq "visa", but is now "cus_EqxhSXiZmxVyUY" # ./spec/models/spree/gateway/stripe_gateway/credit_card_spec.rb:19:in `block (4 levels) in <top (required)>' Finished in 36.66 seconds (files took 6 minutes 33 seconds to load) 1 example, 1 failure
試したこと
おそらく、andで繋げた
.and change(payment_source, :gateway_payment_profile_id).from(nil).to start_with("card_") .and change(payment_source, :cc_type).from(nil).to eq("visa")
の部分がrspecのメソッドとして判定されていないことが原因かと考えていますが、andの改行を無くしたり、
expect do create_profile(creditcard_payment) end.to change(payment_source, :gateway_customer_profile_id).from(nil).to start_with("cus_") .and change(payment_source, :gateway_payment_profile_id).from(nil).to start_with("card_") .and change(payment_source, :cc_type).from(nil).to eq("visa")
のように、 expectの後をdo ~ endに変えたりしていますが、エラーメッセージに特段の変化がありません。
恐れ入りますが、ほんとだけでも結構ですのでご教示いただけますと幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/09 15:49