Commit 802aca908ef01c0d6a292553ff97ba368e440965

Authored by Marius Hanne
1 parent c6f461fab0

adjust usage of mocks to changes in MiniTest

Showing 2 changed files with 31 additions and 32 deletions Side-by-side Diff

spec/bitcoin/wallet/coinselector_spec.rb
... ... @@ -8,13 +8,14 @@
8 8 describe Bitcoin::Wallet::SimpleCoinSelector do
9 9  
10 10 def txout_mock(value, next_in = true, in_block = true)
11   - tx = Mock.new
12   - tx.expect(:get_block, in_block)
13   - txout = Mock.new
14   - txout.expect(:value, value)
15   - txout.expect(:get_next_in, next_in)
16   - txout.expect(:get_address, "addr")
17   - txout.expect(:get_tx, tx)
  11 + tx, txout = Mock.new, Mock.new
  12 + 2.times { tx.expect(:get_block, in_block) }
  13 + 5.times { txout.expect(:value, value) }
  14 + 2.times do
  15 + txout.expect(:get_next_in, next_in)
  16 + txout.expect(:get_address, "addr")
  17 + txout.expect(:get_tx, tx)
  18 + end
18 19 txout
19 20 end
20 21  
spec/bitcoin/wallet/wallet_spec.rb
... ... @@ -8,12 +8,11 @@
8 8 include Bitcoin::Wallet
9 9  
10 10 def txout_mock(value, next_in = true, in_block = true)
11   - tx = Mock.new
  11 + tx, txout = Mock.new, Mock.new
12 12 tx.expect(:get_block, in_block)
13   - txout = Mock.new
14   - txout.expect(:value, value)
15   - txout.expect(:get_next_in, next_in)
16   - txout.expect(:hash, [value, next_in].hash)
  13 + 4.times { txout.expect(:value, value) }
  14 + 2.times { txout.expect(:get_next_in, next_in) }
  15 + 6.times { txout.expect(:hash, [value, next_in].hash) }
17 16 txout.expect(:eql?, false, [1])
18 17 txout.expect(:==, false, [1])
19 18 txout.expect(:get_tx, tx)
20 19  
... ... @@ -24,11 +23,11 @@
24 23 class DummyKeyStore
25 24  
26 25 def initialize keys
27   - @keys = keys.map{|k|{:key => k}}
  26 + @keys = keys.map{|k| { key: k, addr: k.addr } }
28 27 end
29 28  
30 29 def key(addr)
31   - @keys.select{|k|k[:key].addr==addr}.first
  30 + @keys.select{|k| k[:key].addr == addr }.first
32 31 end
33 32  
34 33 def keys
35 34  
... ... @@ -37,13 +36,11 @@
37 36  
38 37 def new_key
39 38 k=Bitcoin::Key.generate
40   - @keys << {:key => k}
  39 + @keys << { key: k, addr: k.addr}
41 40 @keys[-1]
42 41 end
43 42 end
44 43  
45   -
46   -
47 44 before do
48 45 Bitcoin.network = :bitcoin
49 46 @storage = Mock.new
... ... @@ -112,17 +109,16 @@
112 109 before do
113 110 txout = txout_mock(5000, nil)
114 111 tx = Mock.new
115   - tx.expect(:binary_hash, "foo")
116   - tx.expect(:out, [txout])
117   - tx.expect(:get_block, true)
118   - txout.expect(:get_tx, tx)
119   - txout.expect(:get_address, @addr)
120   - txout.expect(:pk_script,
121   - Script.to_address_script(@addr))
122   - @storage.expect(:get_txouts_for_address, [txout], [@addr])
123   - selector = Mock.new
124   - selector.expect(:select, [txout], [[txout]])
125   - @selector.expect(:new, selector, [[txout]])
  112 + 2.times { tx.expect(:binary_hash, "foo") }
  113 + 8.times { tx.expect(:out, [txout]) }
  114 + 3.times { tx.expect(:get_block, true) }
  115 + 5.times { txout.expect(:get_tx, tx) }
  116 + 6.times { txout.expect(:get_address, @addr) }
  117 + 8.times { txout.expect(:pk_script, Script.to_address_script(@addr)) }
  118 +
  119 + 2.times { @storage.expect(:get_txouts_for_address, [txout], [@addr]) }
  120 + selector = Bitcoin::Wallet::SimpleCoinSelector.new([txout])
  121 + 2.times { @selector.expect(:new, selector, [[txout]]) }
126 122 @tx = @wallet.new_tx([[:address, '1M2JjkX7KAgwMyyF5xc2sPSfE7mL1jqkE7', 1000]])
127 123 end
128 124  
129 125  
... ... @@ -182,12 +178,14 @@
182 178 txout = txout_mock(5000, nil)
183 179 tx = Mock.new
184 180 tx.expect(:binary_hash, "foo")
185   - tx.expect(:out, [txout])
  181 + 4.times { tx.expect(:out, [txout]) }
186 182 tx.expect(:get_block, true)
187 183 txout.expect(:get_tx, tx)
188   - txout.expect(:get_address, @addr)
189   - txout.expect(:pk_script, Script.to_address_script(@addr))
190   - @storage.expect(:get_txouts_for_address, [txout], [@addr])
  184 + 2.times { txout.expect(:get_address, @addr) }
  185 + 4.times { txout.expect(:pk_script, Script.to_address_script(@addr)) }
  186 + @storage.expect(:get_txouts_for_address, [txout], [@key.addr])
  187 + @storage.expect(:get_txouts_for_address, [txout], [@key2.addr])
  188 + @storage.expect(:get_txouts_for_address, [txout], [@key3.addr])
191 189 @keystore = DummyKeyStore.new([@key, @key2, @key3])
192 190  
193 191 selector = Mock.new