Why is my layout not used in my mini-testing?

I am trying to write a test with Rails 5 and use minitest. Here is my test code ...

@client = Coinbase::Wallet::Client.new(api_key: ENV['COINBASE_KEY'], api_secret: ENV['COINBASE_SECRET'])
sell_price = 4000
assert sell_price > last_buy_price * (1 + MoneyMakerThreshhold.find_buy.pct_change)
@client.stub :sell_price, "USD" do
  {"base"=>"BTC", "currency"=>"USD", "amount"=>"#{sell_price}"}
end

svc = CryptoCurrencyService.new
svc.sell(last_transaction)

but when it esxecutes to below what prints, not my bullied selling price "4000", this is the actual selling price returned by the customer ...

  def sell(last_transaction)
    client = Coinbase::Wallet::Client.new(api_key: ENV['COINBASE_KEY'], api_secret: ENV['COINBASE_SECRET'])
    sell_price = client.sell_price(currency: 'USD').amount
    puts "buy: #{last_transaction.btc_price_in_usd} sellprice: #{sell_price} last:#{last_transaction.btc_price_in_usd}"

How do I make my layout work on things?

+4
source share
1 answer

The # stub object is the value of the stubs method for the duration of the block, since the documentation states

Add a temporary wired method that replaces the name for the duration of the block. If val_or_callable answers #call, it returns the result of its call, otherwise it returns as-is. Clears the plug at the end of the block.

Answering your initial question:

client.stub :sell_price, {"base"=>"BTC", "currency"=>"USD", "amount"=>"#{sell_price}"} do
  svc = CryptoCurrencyService.new
  svc.sell(last_transaction)  
end
0
source

Source: https://habr.com/ru/post/1686664/


All Articles