0
我正在使用rspec來測試Ruby終端應用程序。我似乎無法想出測試散列中的變化rspec和期望更改的問題
我仍然試圖將我的頭包裹在一般測試中,所以很可能我誤解了有關測試的多個事情。
我試圖測試,當收費被添加到帳戶的實例但收費超過帳戶限制。賬戶餘額不變。
class Account
def apply_charge(card_holder_name, charge)
charge = int_dollar_input(charge)
account = find_account_by_card_holder(card_holder_name)
temp_balance = account[:balance] + charge
account[:balance] = account[:balance] + charge if temp_balance < account[:limit]
end
end
describe "Adding a charge to an account" do
context "GIVEN a charge amount that exceeds the account limit" do
let(:account) { subject.add_account("William", 5454545454545454,'$1000') }
it "will do nothing" do
expect(subject.apply_charge('William', '$1200')).
to_not change {account[:balance]}
end
end
end
帳戶是散列(S)
account.inspect = [{:card_holder_name=>"William", :card_number=>5454545454545454, :limit=>1000, :balance=>0}]
1) Account Adding a charge to an account GIVEN a charge amount that exceeds the account limit will do nothing Failure/Error: expect(subject.apply_charge('William', '$1200')). to_not change {account[:balance]}
expected `account[:balance]` not to have changed, but was not given a block # ./spec/account_spec.rb:46:in `block (4 levels) in <top (required)>'