-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhand_spec.rb
More file actions
87 lines (68 loc) · 2.3 KB
/
hand_spec.rb
File metadata and controls
87 lines (68 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require_relative 'card'
require_relative 'hand'
RSpec.describe Hand do
before do
@hand = Hand.new
end
it 'responds to dealt cards' do
expect(@hand).to respond_to(:dealt_cards)
end
describe "#add_card" do
it 'responds to add_card' do
expect(@hand).to respond_to(:add_card)
end
it 'returns the correct properties of cards added' do
card1 = Card.new('Diamonds','4')
card2 = Card.new('Spades','Ace')
@hand.add_card card1
@hand.add_card card2
expect(@hand.dealt_cards.size).to eq(2)
expect(@hand.dealt_cards.first.suit).to eq("Diamonds")
expect(@hand.dealt_cards.first.rank).to eq("4")
expect(@hand.dealt_cards.last.suit).to eq("Spades")
expect(@hand.dealt_cards.last.rank).to eq("Ace")
end
end
describe "#get_value" do
it 'responds to get_value' do
expect(@hand).to respond_to(:get_value)
end
it 'returns correct value with no Ace' do
card1 = Card.new('Diamonds','Queen')
card2 = Card.new('Spades','9')
@hand.add_card card1
@hand.add_card card2
expect(@hand.get_value).to eq(19)
end
it 'returns correct value with an Ace and a Queen' do
card1 = Card.new('Diamonds','Queen')
card2 = Card.new('Spades','Ace')
@hand.add_card card1
@hand.add_card card2
expect(@hand.get_value).to eq 21
end
end
describe "Hand Output" do
it "returns the correct output if 'show' is true for all cards" do
@hand.add_card Card.new('Diamonds','Queen')
@hand.add_card Card.new('Spades','Ace')
expect("#{@hand}").to eq("Queen of Diamonds, Ace of Spades, Total Value: 21")
end
it "returns the correct output if 'show' if false for one card" do
card1 = Card.new('Diamonds','Queen')
card2 = Card.new('Spades','Ace')
card1.show = false
@hand.add_card card1
@hand.add_card card2
expect("#{@hand}").to eq("Ace of Spades, Total Value: 11")
end
it "returns the correct output if 'show' if false and first card is an Ace" do
card1 = Card.new('Diamonds','Ace')
card2 = Card.new('Spades','King')
card1.show = false
@hand.add_card card1
@hand.add_card card2
expect("#{@hand}").to eq("King of Spades, Total Value: 10")
end
end
end