console-blackjack 1.0.5 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e53727e957fb5e163cc56ac04e0c1e79e027d58834691e6290059ac8d653ddf
4
- data.tar.gz: 3cc3c0b725b9592d85d92735a3bc4ce1208170f7369ace802ea15b9b1e3ef86e
3
+ metadata.gz: 1a3369825b0d070363a8da6637b068793e21b2faef84732507dad91edcefeb4a
4
+ data.tar.gz: e8c8ab2105f823bb1971bce15d1a6d3cf4943441e45307152cc8444ca0b5dbc2
5
5
  SHA512:
6
- metadata.gz: 109ceb08d745fc3c6848c8872e7e7e6d4f354dfbb21361d1daedd5211c308cbe3673acdbc54e212540d57560ee986ddc92c07a001d8712b81e771bebcc391957
7
- data.tar.gz: 89d6b9c4d3fbb0dcc557868125f5591cc7cd551fb33ce9de568255223273e4f33784b12f33ba99c792398ab150504167a1352df854f77606dca00e27db145159
6
+ metadata.gz: 057dd5b492a59aeb487ba9e3d2969654f5ca99c5474f3ca204494b197ccc73a8394ca12b74fe94105995557407cf58f1416ac51074319feff3849a7d77e2a34a
7
+ data.tar.gz: 58bee05314cb656e6fb5135aaa7c460797d9a309ab01843570b4c424e7848a81cb28f7a57eaeb76b2a8f4475f45eb08dcac56da75202cebe136de0c6c9057efc
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ruby '2.7.5'
4
+
3
5
  source 'https://rubygems.org'
4
6
 
5
7
  gem 'coveralls', require: false
@@ -9,5 +11,6 @@ gem 'rake'
9
11
  gem 'rest-client', '>= 1.8.0'
10
12
  gem 'rspec'
11
13
  gem 'rubocop', require: false
14
+ gem 'rubocop-rake'
12
15
  gem 'rubocop-rspec'
13
16
  gem 'simplecov', require: false
data/Gemfile.lock CHANGED
@@ -1,97 +1,100 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (6.0.3.1)
4
+ activesupport (7.0.1)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
- i18n (>= 0.7, < 2)
7
- minitest (~> 5.1)
8
- tzinfo (~> 1.1)
9
- zeitwerk (~> 2.2, >= 2.2.2)
10
- ast (2.4.0)
11
- coderay (1.1.2)
12
- concurrent-ruby (1.1.6)
6
+ i18n (>= 1.6, < 2)
7
+ minitest (>= 5.1)
8
+ tzinfo (~> 2.0)
9
+ ast (2.4.2)
10
+ coderay (1.1.3)
11
+ concurrent-ruby (1.1.9)
13
12
  coveralls (0.7.1)
14
13
  multi_json (~> 1.3)
15
14
  rest-client
16
15
  simplecov (>= 0.7)
17
16
  term-ansicolor
18
17
  thor
19
- diff-lcs (1.3)
20
- docile (1.3.2)
18
+ diff-lcs (1.5.0)
19
+ docile (1.4.0)
21
20
  domain_name (0.5.20190701)
22
21
  unf (>= 0.0.5, < 1.0.0)
23
- factory_bot (5.2.0)
24
- activesupport (>= 4.2.0)
22
+ factory_bot (6.2.0)
23
+ activesupport (>= 5.0.0)
25
24
  http-accept (1.7.0)
26
- http-cookie (1.0.3)
25
+ http-cookie (1.0.4)
27
26
  domain_name (~> 0.5)
28
- i18n (1.8.2)
27
+ i18n (1.8.11)
29
28
  concurrent-ruby (~> 1.0)
30
29
  method_source (1.0.0)
31
- mime-types (3.3.1)
30
+ mime-types (3.4.1)
32
31
  mime-types-data (~> 3.2015)
33
- mime-types-data (3.2020.0512)
34
- minitest (5.14.1)
35
- multi_json (1.14.1)
32
+ mime-types-data (3.2022.0105)
33
+ minitest (5.15.0)
34
+ multi_json (1.15.0)
36
35
  netrc (0.11.0)
37
- parallel (1.19.1)
38
- parser (2.7.1.3)
39
- ast (~> 2.4.0)
40
- pry (0.13.1)
36
+ parallel (1.21.0)
37
+ parser (3.1.0.0)
38
+ ast (~> 2.4.1)
39
+ pry (0.14.1)
41
40
  coderay (~> 1.1)
42
41
  method_source (~> 1.0)
43
- rainbow (3.0.0)
44
- rake (13.0.1)
42
+ rainbow (3.1.1)
43
+ rake (13.0.6)
44
+ regexp_parser (2.2.0)
45
45
  rest-client (2.1.0)
46
46
  http-accept (>= 1.7.0, < 2.0)
47
47
  http-cookie (>= 1.0.2, < 2.0)
48
48
  mime-types (>= 1.16, < 4.0)
49
49
  netrc (~> 0.8)
50
- rexml (3.2.4)
51
- rspec (3.9.0)
52
- rspec-core (~> 3.9.0)
53
- rspec-expectations (~> 3.9.0)
54
- rspec-mocks (~> 3.9.0)
55
- rspec-core (3.9.2)
56
- rspec-support (~> 3.9.3)
57
- rspec-expectations (3.9.2)
50
+ rexml (3.2.5)
51
+ rspec (3.10.0)
52
+ rspec-core (~> 3.10.0)
53
+ rspec-expectations (~> 3.10.0)
54
+ rspec-mocks (~> 3.10.0)
55
+ rspec-core (3.10.1)
56
+ rspec-support (~> 3.10.0)
57
+ rspec-expectations (3.10.2)
58
58
  diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.9.0)
60
- rspec-mocks (3.9.1)
59
+ rspec-support (~> 3.10.0)
60
+ rspec-mocks (3.10.2)
61
61
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.9.0)
63
- rspec-support (3.9.3)
64
- rubocop (0.84.0)
62
+ rspec-support (~> 3.10.0)
63
+ rspec-support (3.10.3)
64
+ rubocop (1.24.1)
65
65
  parallel (~> 1.10)
66
- parser (>= 2.7.0.1)
66
+ parser (>= 3.0.0.0)
67
67
  rainbow (>= 2.2.2, < 4.0)
68
+ regexp_parser (>= 1.8, < 3.0)
68
69
  rexml
69
- rubocop-ast (>= 0.0.3)
70
+ rubocop-ast (>= 1.15.1, < 2.0)
70
71
  ruby-progressbar (~> 1.7)
71
- unicode-display_width (>= 1.4.0, < 2.0)
72
- rubocop-ast (0.0.3)
73
- parser (>= 2.7.0.1)
74
- rubocop-rspec (1.39.0)
75
- rubocop (>= 0.68.1)
76
- ruby-progressbar (1.10.1)
77
- simplecov (0.18.5)
72
+ unicode-display_width (>= 1.4.0, < 3.0)
73
+ rubocop-ast (1.15.1)
74
+ parser (>= 3.0.1.1)
75
+ rubocop-rake (0.6.0)
76
+ rubocop (~> 1.0)
77
+ rubocop-rspec (2.7.0)
78
+ rubocop (~> 1.19)
79
+ ruby-progressbar (1.11.0)
80
+ simplecov (0.21.2)
78
81
  docile (~> 1.1)
79
82
  simplecov-html (~> 0.11)
80
- simplecov-html (0.12.2)
83
+ simplecov_json_formatter (~> 0.1)
84
+ simplecov-html (0.12.3)
85
+ simplecov_json_formatter (0.1.3)
81
86
  sync (0.5.0)
82
87
  term-ansicolor (1.7.1)
83
88
  tins (~> 1.0)
84
- thor (1.0.1)
85
- thread_safe (0.3.6)
86
- tins (1.25.0)
89
+ thor (1.2.1)
90
+ tins (1.31.0)
87
91
  sync
88
- tzinfo (1.2.7)
89
- thread_safe (~> 0.1)
92
+ tzinfo (2.0.4)
93
+ concurrent-ruby (~> 1.0)
90
94
  unf (0.1.4)
91
95
  unf_ext
92
- unf_ext (0.0.7.7)
93
- unicode-display_width (1.7.0)
94
- zeitwerk (2.3.0)
96
+ unf_ext (0.0.8)
97
+ unicode-display_width (2.1.0)
95
98
 
96
99
  PLATFORMS
97
100
  ruby
@@ -104,8 +107,12 @@ DEPENDENCIES
104
107
  rest-client (>= 1.8.0)
105
108
  rspec
106
109
  rubocop
110
+ rubocop-rake
107
111
  rubocop-rspec
108
112
  simplecov
109
113
 
114
+ RUBY VERSION
115
+ ruby 2.7.5p203
116
+
110
117
  BUNDLED WITH
111
118
  2.1.4
data/README.md CHANGED
@@ -14,7 +14,7 @@ Run:
14
14
 
15
15
  ## Status
16
16
 
17
- [![Build Status](https://travis-ci.org/gdonald/console-blackjack-ruby.svg?branch=master)](https://travis-ci.org/gdonald/console-blackjack-ruby)
17
+ [![Ruby](https://github.com/gdonald/console-blackjack-ruby/workflows/Ruby/badge.svg)](https://github.com/gdonald/console-blackjack-ruby/actions)
18
18
  [![Coverage Status](https://coveralls.io/repos/github/gdonald/console-blackjack-ruby/badge.svg?branch=master)](https://coveralls.io/github/gdonald/console-blackjack-ruby?branch=master)
19
19
  [![Downloads](https://ruby-gem-downloads-badge.herokuapp.com/console-blackjack?color=blue&type=total&total_label=)](https://rubygems.org/gems/console-blackjack)
20
20
 
data/bj.txt CHANGED
@@ -1 +1 @@
1
- 1|10000|500
1
+ 1|11000|500
Binary file
Binary file
@@ -3,9 +3,9 @@
3
3
  require 'rake'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
+ spec.required_ruby_version = '>= 2.7.5'
6
7
  spec.name = 'console-blackjack'
7
- spec.version = '1.0.5'
8
- spec.date = '2020-05-26'
8
+ spec.version = '1.0.9'
9
9
  spec.summary = 'Console Blackjack'
10
10
  spec.description = 'Blackjack for your console, full version.'
11
11
  spec.author = 'Greg Donald'
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  class Card
@@ -52,22 +52,19 @@ module Menus
52
52
 
53
53
  def draw_bet_options
54
54
  puts ' (D) Deal Hand (B) Change Bet (O) Options (Q) Quit'
55
- loop do
56
- c = Blackjack.getc
57
- case c
58
- when 'd'
59
- deal_new_hand
60
- when 'b'
61
- new_bet
62
- when 'o'
63
- clear_draw_hands_game_options
64
- when 'q'
65
- clear
66
- exit
67
- else
68
- clear_draw_hands_bet_options
69
- end
70
- break if %w[d b o].include?(c)
55
+ c = Blackjack.getc
56
+ case c
57
+ when 'd'
58
+ deal_new_hand
59
+ when 'b'
60
+ new_bet
61
+ when 'o'
62
+ clear_draw_hands_game_options
63
+ when 'q'
64
+ clear
65
+ exit
66
+ else
67
+ clear_draw_hands_bet_options
71
68
  end
72
69
  end
73
70
  end
@@ -92,21 +92,18 @@ class PlayerHand < Hand
92
92
 
93
93
  def action?
94
94
  draw_actions
95
- loop do
96
- c = Blackjack.getc
97
- case c
98
- when 'h'
99
- hit
100
- when 's'
101
- stand
102
- when 'p'
103
- blackjack.split_current_hand
104
- when 'd'
105
- dbl
106
- else
107
- clear_draw_hands_action
108
- end
109
- break if %w[h s p d].include?(c)
95
+ c = Blackjack.getc
96
+ case c
97
+ when 'h'
98
+ hit
99
+ when 's'
100
+ stand
101
+ when 'p'
102
+ blackjack.split_current_hand
103
+ when 'd'
104
+ dbl
105
+ else
106
+ clear_draw_hands_action
110
107
  end
111
108
  end
112
109
 
@@ -117,11 +114,11 @@ class PlayerHand < Hand
117
114
  end
118
115
 
119
116
  def draw_actions
120
- out = String.new(' ')
121
- out << '(H) Hit ' if can_hit?
122
- out << '(S) Stand ' if can_stand?
123
- out << '(P) Split ' if can_split?
124
- out << '(D) Double ' if can_dbl?
125
- puts out
117
+ actions = []
118
+ actions << '(H) Hit' if can_hit?
119
+ actions << '(S) Stand' if can_stand?
120
+ actions << '(P) Split' if can_split?
121
+ actions << '(D) Double' if can_dbl?
122
+ puts " #{actions.join(' ')}"
126
123
  end
127
124
  end
data/lib/blackjack.rb CHANGED
@@ -135,7 +135,7 @@ class Blackjack
135
135
  puts " Current Bet: $#{Format.money(current_bet / 100)}\n"
136
136
  print ' Enter New Bet: $'
137
137
 
138
- self.current_bet = STDIN.gets.to_i * 100
138
+ self.current_bet = $stdin.gets.to_i * 100
139
139
 
140
140
  normalize_current_bet
141
141
  deal_new_hand
@@ -144,7 +144,7 @@ class Blackjack
144
144
  def new_num_decks
145
145
  puts " Number Of Decks: #{num_decks}"
146
146
  print ' New Number Of Decks (1-8): '
147
- self.num_decks = STDIN.gets.to_i
147
+ self.num_decks = $stdin.gets.to_i
148
148
 
149
149
  normalize_num_decks
150
150
  clear_draw_hands_game_options
@@ -204,7 +204,7 @@ class Blackjack
204
204
  def self.getc
205
205
  begin
206
206
  system('stty raw -echo')
207
- c = STDIN.getc
207
+ c = $stdin.getc
208
208
  ensure
209
209
  system('stty -raw echo')
210
210
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  RSpec.describe Card do
@@ -5,11 +5,6 @@ RSpec.describe DealerHand do
5
5
  let(:blackjack) { build(:blackjack) }
6
6
  let(:dealer_hand) { build(:dealer_hand, blackjack: blackjack) }
7
7
  let(:ace) { build(:card, :ace) }
8
- let(:five) { build(:card, :five) }
9
- let(:six) { build(:card, :six) }
10
- let(:seven) { build(:card, :seven) }
11
- let(:eight) { build(:card, :eight) }
12
- let(:nine) { build(:card, :nine) }
13
8
  let(:ten) { build(:card, :ten) }
14
9
 
15
10
  describe '.new' do
@@ -132,15 +127,13 @@ RSpec.describe DealerHand do
132
127
  end
133
128
 
134
129
  describe '#deal_required_cards' do
135
- let(:shoe) { build(:shoe, :new_regular) }
136
-
137
130
  before do
138
- blackjack.shoe = shoe
131
+ blackjack.shoe = build(:shoe, :new_regular)
139
132
  end
140
133
 
141
134
  context 'when soft is < 18' do
142
135
  it 'deals cards' do
143
- dealer_hand.cards << ace << seven
136
+ dealer_hand.cards << ace << build(:card, :seven)
144
137
  dealer_hand.deal_required_cards
145
138
  expect(dealer_hand.cards.size >= 3).to be_truthy
146
139
  end
@@ -148,7 +141,7 @@ RSpec.describe DealerHand do
148
141
 
149
142
  context 'when hard is < 17' do
150
143
  it 'deals cards' do
151
- dealer_hand.cards << ace << ten << five
144
+ dealer_hand.cards << ace << ten << build(:card, :five)
152
145
  dealer_hand.deal_required_cards
153
146
  expect(dealer_hand.cards.size >= 4).to be_truthy
154
147
  end
@@ -1,15 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe PlayerHand do
4
- let(:shoe) { build(:shoe, :new_regular) }
5
- let(:blackjack) { build(:blackjack, shoe: shoe) }
4
+ let(:blackjack) { build(:blackjack, shoe: build(:shoe, :new_regular)) }
6
5
  let(:player_hand) { build(:player_hand, blackjack: blackjack) }
7
6
  let(:dealer_hand) { build(:dealer_hand, blackjack: blackjack) }
8
7
  let(:ace) { build(:card, :ace) }
9
- let(:six) { build(:card, :six) }
10
- let(:seven) { build(:card, :seven) }
11
- let(:eight) { build(:card, :eight) }
12
- let(:nine) { build(:card, :nine) }
13
8
  let(:ten) { build(:card, :ten) }
14
9
 
15
10
  describe '.new' do
@@ -126,7 +121,7 @@ RSpec.describe PlayerHand do
126
121
 
127
122
  context 'when soft count of 21' do
128
123
  it 'returns true' do
129
- player_hand.cards << ace << ace << nine
124
+ player_hand.cards << ace << ace << build(:card, :nine)
130
125
  expect(player_hand).to be_done
131
126
  end
132
127
  end
@@ -140,7 +135,7 @@ RSpec.describe PlayerHand do
140
135
 
141
136
  context 'when pair of sevens' do
142
137
  it 'returns false' do
143
- player_hand.cards << seven << seven
138
+ player_hand.cards << build(:card, :seven) << build(:card, :seven)
144
139
  expect(player_hand).to_not be_done
145
140
  end
146
141
  end
@@ -163,7 +158,7 @@ RSpec.describe PlayerHand do
163
158
 
164
159
  context 'when not enough money' do
165
160
  it 'returns false' do
166
- blackjack.money = 9999
161
+ blackjack.money = 499
167
162
  expect(player_hand).to_not be_can_split
168
163
  end
169
164
  end
@@ -177,14 +172,14 @@ RSpec.describe PlayerHand do
177
172
 
178
173
  context 'when card values do not match' do
179
174
  it 'returns false' do
180
- player_hand.cards << seven << nine
175
+ player_hand.cards << build(:card, :seven) << build(:card, :nine)
181
176
  expect(player_hand).to_not be_can_split
182
177
  end
183
178
  end
184
179
 
185
180
  context 'when card values match' do
186
181
  it 'returns true' do
187
- player_hand.cards << seven << seven
182
+ player_hand.cards << build(:card, :seven) << build(:card, :seven)
188
183
  expect(player_hand).to be_can_split
189
184
  end
190
185
  end
@@ -193,7 +188,7 @@ RSpec.describe PlayerHand do
193
188
  describe '#can_dbl?' do
194
189
  context 'when not enough money' do
195
190
  it 'returns false' do
196
- blackjack.money = 9999
191
+ blackjack.money = 499
197
192
  expect(player_hand).to_not be_can_dbl
198
193
  end
199
194
  end
@@ -221,7 +216,7 @@ RSpec.describe PlayerHand do
221
216
 
222
217
  context 'when a pair of sixes' do
223
218
  it 'returns true' do
224
- player_hand.cards << six << six
219
+ player_hand.cards << build(:card, :six) << build(:card, :six)
225
220
  expect(player_hand).to be_can_dbl
226
221
  end
227
222
  end
@@ -244,14 +239,14 @@ RSpec.describe PlayerHand do
244
239
 
245
240
  context 'when busted' do
246
241
  it 'returns false' do
247
- player_hand.cards << eight << eight << eight
242
+ player_hand.cards << build(:card, :eight) << build(:card, :eight) << build(:card, :eight)
248
243
  expect(player_hand).to_not be_can_stand
249
244
  end
250
245
  end
251
246
 
252
247
  context 'when a pair of sixes' do
253
248
  it 'returns true' do
254
- player_hand.cards << six << six
249
+ player_hand.cards << build(:card, :six) << build(:card, :six)
255
250
  expect(player_hand).to be_can_stand
256
251
  end
257
252
  end
@@ -281,21 +276,21 @@ RSpec.describe PlayerHand do
281
276
 
282
277
  context 'when busted' do
283
278
  it 'returns false' do
284
- player_hand.cards << eight << eight << eight
279
+ player_hand.cards << build(:card, :eight) << build(:card, :eight) << build(:card, :eight)
285
280
  expect(player_hand).to_not be_can_hit
286
281
  end
287
282
  end
288
283
 
289
284
  context 'when a hard 21' do
290
285
  it 'returns false' do
291
- player_hand.cards << seven << seven << seven
286
+ player_hand.cards << build(:card, :seven) << build(:card, :seven) << build(:card, :seven)
292
287
  expect(player_hand).to_not be_can_hit
293
288
  end
294
289
  end
295
290
 
296
291
  context 'when a pair of sixes' do
297
292
  it 'returns true' do
298
- player_hand.cards << six << six
293
+ player_hand.cards << build(:card, :six) << build(:card, :six)
299
294
  expect(player_hand).to be_can_hit
300
295
  end
301
296
  end
@@ -494,6 +489,66 @@ RSpec.describe PlayerHand do
494
489
  end
495
490
  end
496
491
 
492
+ describe '#draw_actions' do
493
+ it 'can hit and stand' do
494
+ expect do
495
+ player_hand.draw_actions
496
+ end.to output(" (H) Hit (S) Stand\n").to_stdout
497
+ end
498
+
499
+ it 'cannot hit' do
500
+ allow(player_hand).to receive(:can_hit?).and_return(false)
501
+ expect do
502
+ player_hand.draw_actions
503
+ end.to output(" (S) Stand\n").to_stdout
504
+ end
505
+
506
+ it 'cannot stand' do
507
+ allow(player_hand).to receive(:can_stand?).and_return(false)
508
+ expect do
509
+ player_hand.draw_actions
510
+ end.to output(" (H) Hit\n").to_stdout
511
+ end
512
+
513
+ it 'can split' do
514
+ allow(player_hand).to receive(:can_split?).and_return(true)
515
+ expect do
516
+ player_hand.draw_actions
517
+ end.to output(" (H) Hit (S) Stand (P) Split\n").to_stdout
518
+ end
519
+
520
+ it 'can double' do
521
+ allow(player_hand).to receive(:can_dbl?).and_return(true)
522
+ expect do
523
+ player_hand.draw_actions
524
+ end.to output(" (H) Hit (S) Stand (D) Double\n").to_stdout
525
+ end
526
+ end
527
+
528
+ describe '#draw_lost_str' do
529
+ it 'returns Busted!' do
530
+ allow(player_hand).to receive(:busted?).and_return(true)
531
+ expect(player_hand.draw_lost_str).to eq('Busted!')
532
+ end
533
+
534
+ it 'returns Lose!' do
535
+ allow(player_hand).to receive(:busted?).and_return(false)
536
+ expect(player_hand.draw_lost_str).to eq('Lose!')
537
+ end
538
+ end
539
+
540
+ describe '#draw_won_str' do
541
+ it 'returns Blackjack!' do
542
+ allow(player_hand).to receive(:blackjack?).and_return(true)
543
+ expect(player_hand.draw_won_str).to eq('Blackjack!')
544
+ end
545
+
546
+ it 'returns Won!' do
547
+ allow(player_hand).to receive(:blackjack?).and_return(false)
548
+ expect(player_hand.draw_won_str).to eq('Won!')
549
+ end
550
+ end
551
+
497
552
  describe '#pay' do
498
553
  it 'returns if already payed' do
499
554
  player_hand.payed = true
@@ -535,25 +590,25 @@ RSpec.describe PlayerHand do
535
590
  end
536
591
 
537
592
  it 'hand is lost' do
538
- player_hand.cards << ten << seven
593
+ player_hand.cards << ten << build(:card, :seven)
539
594
  player_hand.pay(18, false)
540
595
  expect(player_hand.status).to eq(LOST)
541
596
  end
542
597
 
543
598
  it 'blackjack money is descreased by player hand bet' do
544
- player_hand.cards << ten << seven
599
+ player_hand.cards << ten << build(:card, :seven)
545
600
  player_hand.pay(18, false)
546
601
  expect(blackjack.money).to eq(9500)
547
602
  end
548
603
 
549
604
  it 'hand is push' do
550
- player_hand.cards << ten << seven
605
+ player_hand.cards << ten << build(:card, :seven)
551
606
  player_hand.pay(17, false)
552
607
  expect(player_hand.status).to eq(PUSH)
553
608
  end
554
609
 
555
610
  it 'blackjack money is unaltered' do
556
- player_hand.cards << ten << seven
611
+ player_hand.cards << ten << build(:card, :seven)
557
612
  player_hand.pay(17, false)
558
613
  expect(blackjack.money).to eq(10_000)
559
614
  end
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Blackjack do
4
- let(:shoe) { build(:shoe, :new_regular) }
5
- let(:blackjack) { build(:blackjack, shoe: shoe) }
4
+ let(:blackjack) { build(:blackjack, shoe: build(:shoe, :new_regular)) }
6
5
  let(:player_hand) { build(:player_hand, blackjack: blackjack) }
7
6
  let(:dealer_hand) { build(:dealer_hand, blackjack: blackjack) }
8
7
  let(:ace) { build(:card, :ace) }
9
- let(:seven) { build(:card, :seven) }
10
- let(:six) { build(:card, :six) }
11
8
  let(:ten) { build(:card, :ten) }
12
9
 
13
10
  describe '#current_player_hand' do
@@ -30,7 +27,7 @@ RSpec.describe Blackjack do
30
27
 
31
28
  describe '#getc' do
32
29
  it 'get a single character from stdin' do
33
- allow(STDIN).to receive(:getc).and_return('q')
30
+ allow($stdin).to receive(:getc).and_return('q')
34
31
  c = described_class.getc
35
32
  expect(c).to eq('q')
36
33
  end
@@ -44,13 +41,24 @@ RSpec.describe Blackjack do
44
41
  end
45
42
 
46
43
  describe '#need_to_play_dealer_hand?' do
47
- it 'returns false' do
48
- expect(blackjack).to_not be_need_to_play_dealer_hand
44
+ before do
45
+ blackjack.player_hands << player_hand
49
46
  end
50
47
 
51
- it 'returns true' do
52
- blackjack.player_hands << player_hand
53
- expect(blackjack).to be_need_to_play_dealer_hand
48
+ context 'when busted' do
49
+ it 'returns false' do
50
+ allow(player_hand).to receive(:blackjack?).and_return(false)
51
+ allow(player_hand).to receive(:busted?).and_return(true)
52
+ expect(blackjack).to_not be_need_to_play_dealer_hand
53
+ end
54
+ end
55
+
56
+ context 'when blackjack' do
57
+ it 'returns false' do
58
+ allow(player_hand).to receive(:busted?).and_return(false)
59
+ allow(player_hand).to receive(:blackjack?).and_return(true)
60
+ expect(blackjack).to_not be_need_to_play_dealer_hand
61
+ end
54
62
  end
55
63
  end
56
64
 
@@ -92,38 +100,46 @@ RSpec.describe Blackjack do
92
100
  end
93
101
 
94
102
  describe '#save_game' do
95
- let(:file) { instance_double('File') }
96
- let(:content) { "#{blackjack.num_decks}|#{blackjack.money}|#{blackjack.current_bet}" }
97
-
98
103
  it 'opens and put save file data' do
104
+ file = instance_double('File')
99
105
  allow(File).to receive(:open).with(SAVE_FILE, 'w').and_yield(file)
100
106
  allow(file).to receive(:puts)
101
107
  blackjack.save_game
102
- expect(file).to have_received(:puts).with(content)
108
+ expect(file).to have_received(:puts).with("#{blackjack.num_decks}|#{blackjack.money}|#{blackjack.current_bet}")
103
109
  end
104
110
  end
105
111
 
106
112
  describe '#load_game' do
107
- let(:content) { '8|2000|1000' }
113
+ context 'with a unreadable save file' do
114
+ it 'fails to load save file' do
115
+ allow(File).to receive(:read).with(SAVE_FILE)
116
+ allow(File).to receive(:readable?).with(SAVE_FILE).and_return(false)
108
117
 
109
- before do
110
- allow(File).to receive(:readable?).with(SAVE_FILE).and_return(true)
111
- allow(File).to receive(:read).with(SAVE_FILE).and_return(content)
118
+ blackjack.load_game
119
+ expect(File).to_not have_received(:read).with(SAVE_FILE)
120
+ end
112
121
  end
113
122
 
114
- it 'loads num_decks from save file data' do
115
- blackjack.load_game
116
- expect(blackjack.num_decks).to eq(8)
117
- end
123
+ context 'with a readabale save file' do
124
+ before do
125
+ allow(File).to receive(:readable?).with(SAVE_FILE).and_return(true)
126
+ allow(File).to receive(:read).with(SAVE_FILE).and_return('8|2000|1000')
127
+ end
118
128
 
119
- it 'loads money from save file data' do
120
- blackjack.load_game
121
- expect(blackjack.money).to eq(2000)
122
- end
129
+ it 'loads num_decks from save file data' do
130
+ blackjack.load_game
131
+ expect(blackjack.num_decks).to eq(8)
132
+ end
123
133
 
124
- it 'loads current_bet from save file data' do
125
- blackjack.load_game
126
- expect(blackjack.current_bet).to eq(1000)
134
+ it 'loads money from save file data' do
135
+ blackjack.load_game
136
+ expect(blackjack.money).to eq(2000)
137
+ end
138
+
139
+ it 'loads current_bet from save file data' do
140
+ blackjack.load_game
141
+ expect(blackjack.current_bet).to eq(1000)
142
+ end
127
143
  end
128
144
  end
129
145
 
@@ -257,19 +273,19 @@ RSpec.describe Blackjack do
257
273
  dealer_hand.cards << ten << ten
258
274
  allow(blackjack).to receive(:build_new_hand).and_return(player_hand)
259
275
  allow(player_hand).to receive(:action?)
260
- allow(shoe).to receive(:new_regular)
276
+ allow(blackjack.shoe).to receive(:new_regular)
261
277
  end
262
278
 
263
279
  it 'shuffles' do
264
- allow(shoe).to receive(:needs_to_shuffle?).and_return(true)
280
+ allow(blackjack.shoe).to receive(:needs_to_shuffle?).and_return(true)
265
281
  blackjack.deal_new_hand
266
- expect(shoe).to have_received(:new_regular)
282
+ expect(blackjack.shoe).to have_received(:new_regular)
267
283
  end
268
284
 
269
285
  it 'does not shuffle' do
270
- allow(shoe).to receive(:needs_to_shuffle?).and_return(false)
286
+ allow(blackjack.shoe).to receive(:needs_to_shuffle?).and_return(false)
271
287
  blackjack.deal_new_hand
272
- expect(shoe).to_not have_received(:new_regular)
288
+ expect(blackjack.shoe).to_not have_received(:new_regular)
273
289
  end
274
290
  end
275
291
 
@@ -372,7 +388,7 @@ RSpec.describe Blackjack do
372
388
  describe '#new_bet' do
373
389
  before do
374
390
  blackjack.dealer_hand = dealer_hand
375
- allow(STDIN).to receive(:gets).and_return('10')
391
+ allow($stdin).to receive(:gets).and_return('10')
376
392
  allow(described_class).to receive(:getc).and_return('s', 'q')
377
393
  allow(blackjack).to receive(:print)
378
394
  allow(blackjack).to receive(:puts)
@@ -526,7 +542,7 @@ RSpec.describe Blackjack do
526
542
  describe '#new_num_decks' do
527
543
  before do
528
544
  blackjack.dealer_hand = dealer_hand
529
- allow(STDIN).to receive(:gets).and_return('2')
545
+ allow($stdin).to receive(:gets).and_return('2')
530
546
  allow(described_class).to receive(:getc).and_return('b', 'q')
531
547
  allow(blackjack).to receive(:print)
532
548
  allow(blackjack).to receive(:puts)
@@ -593,44 +609,44 @@ RSpec.describe Blackjack do
593
609
 
594
610
  it 'builds a new regular' do
595
611
  allow(described_class).to receive(:getc).and_return('1')
596
- allow(shoe).to receive(:new_regular)
612
+ allow(blackjack.shoe).to receive(:new_regular)
597
613
  blackjack.new_deck_type
598
- expect(shoe).to have_received(:new_regular)
614
+ expect(blackjack.shoe).to have_received(:new_regular)
599
615
  end
600
616
 
601
617
  it 'builds a new aces' do
602
618
  allow(described_class).to receive(:getc).and_return('2')
603
- allow(shoe).to receive(:new_aces)
619
+ allow(blackjack.shoe).to receive(:new_aces)
604
620
  blackjack.new_deck_type
605
- expect(shoe).to have_received(:new_aces)
621
+ expect(blackjack.shoe).to have_received(:new_aces)
606
622
  end
607
623
 
608
624
  it 'builds a new jacks' do
609
625
  allow(described_class).to receive(:getc).and_return('3')
610
- allow(shoe).to receive(:new_jacks)
626
+ allow(blackjack.shoe).to receive(:new_jacks)
611
627
  blackjack.new_deck_type
612
- expect(shoe).to have_received(:new_jacks)
628
+ expect(blackjack.shoe).to have_received(:new_jacks)
613
629
  end
614
630
 
615
631
  it 'builds a new aces_jacks' do
616
632
  allow(described_class).to receive(:getc).and_return('4')
617
- allow(shoe).to receive(:new_aces_jacks)
633
+ allow(blackjack.shoe).to receive(:new_aces_jacks)
618
634
  blackjack.new_deck_type
619
- expect(shoe).to have_received(:new_aces_jacks)
635
+ expect(blackjack.shoe).to have_received(:new_aces_jacks)
620
636
  end
621
637
 
622
638
  it 'builds a new sevens' do
623
639
  allow(described_class).to receive(:getc).and_return('5')
624
- allow(shoe).to receive(:new_sevens)
640
+ allow(blackjack.shoe).to receive(:new_sevens)
625
641
  blackjack.new_deck_type
626
- expect(shoe).to have_received(:new_sevens)
642
+ expect(blackjack.shoe).to have_received(:new_sevens)
627
643
  end
628
644
 
629
645
  it 'builds a new eights' do
630
646
  allow(described_class).to receive(:getc).and_return('6')
631
- allow(shoe).to receive(:new_eights)
647
+ allow(blackjack.shoe).to receive(:new_eights)
632
648
  blackjack.new_deck_type
633
- expect(shoe).to have_received(:new_eights)
649
+ expect(blackjack.shoe).to have_received(:new_eights)
634
650
  end
635
651
  end
636
652
 
@@ -765,7 +781,7 @@ RSpec.describe Blackjack do
765
781
 
766
782
  context 'when dealer hand is not blackjack' do
767
783
  before do
768
- dealer_hand.cards << ace << seven
784
+ dealer_hand.cards << ace << build(:card, :seven)
769
785
  allow(blackjack).to receive(:play_dealer_hand)
770
786
  end
771
787
 
@@ -822,7 +838,7 @@ RSpec.describe Blackjack do
822
838
 
823
839
  context 'when current hand can split' do
824
840
  before do
825
- player_hand.cards << six << six
841
+ player_hand.cards << build(:card, :six) << build(:card, :six)
826
842
  allow(described_class).to receive(:getc).and_return('s', 's')
827
843
  allow(blackjack).to receive(:draw_bet_options)
828
844
  allow(blackjack).to receive(:draw_hands)
@@ -843,7 +859,7 @@ RSpec.describe Blackjack do
843
859
 
844
860
  context 'when current hand cannot split' do
845
861
  before do
846
- player_hand.cards << ace << six
862
+ player_hand.cards << ace << build(:card, :six)
847
863
  allow(described_class).to receive(:getc).and_return('s')
848
864
  allow(blackjack).to receive(:draw_bet_options)
849
865
  allow(blackjack).to receive(:draw_hands)
data/spec/spec_helper.rb CHANGED
@@ -3,14 +3,16 @@
3
3
  require 'simplecov'
4
4
  SimpleCov.start do
5
5
  add_filter %r{/spec/}
6
+ enable_coverage :branch
7
+ primary_coverage :branch
6
8
  end
7
9
 
8
10
  require 'coveralls'
9
11
  Coveralls.wear!
10
12
 
11
13
  Dir.glob(File.join(File.dirname(__FILE__),
12
- '..' + File::SEPARATOR + 'lib', '**',
13
- '*.rb'), &method(:require))
14
+ "..#{File::SEPARATOR}lib", '**',
15
+ '*.rb')).sort.each(&method(:require))
14
16
 
15
17
  require 'factory_bot'
16
18
  require 'pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console-blackjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Donald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-26 00:00:00.000000000 Z
11
+ date: 2022-01-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Blackjack for your console, full version.
14
14
  email: gdonald@gmail.com
@@ -25,6 +25,8 @@ files:
25
25
  - bin/console-blackjack
26
26
  - bj.png
27
27
  - bj.txt
28
+ - console-blackjack-1.0.7.gem
29
+ - console-blackjack-1.0.8.gem
28
30
  - console-blackjack.gemspec
29
31
  - lib/blackjack.rb
30
32
  - lib/blackjack/card.rb
@@ -68,16 +70,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
70
  requirements:
69
71
  - - ">="
70
72
  - !ruby/object:Gem::Version
71
- version: '0'
73
+ version: 2.7.5
72
74
  required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  requirements:
74
76
  - - ">="
75
77
  - !ruby/object:Gem::Version
76
78
  version: '0'
77
79
  requirements: []
78
- rubygems_version: 3.0.3
80
+ rubygems_version: 3.1.6
79
81
  signing_key:
80
82
  specification_version: 4
81
83
  summary: Console Blackjack
82
84
  test_files: []
83
- ...