forked from despo/hangman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman_test.rb
60 lines (46 loc) · 1.34 KB
/
hangman_test.rb
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
require_relative 'test_helper'
describe Hangman do
it "starts a game with a the specified word" do
hangman = Hangman.new("pokemon")
hangman.solution.must_equal("pokemon")
end
describe "guess" do
let(:hangman) { Hangman.new("flower") }
describe "when wrong" do
it "returns false" do
hangman.guess("c").must_equal(false)
end
it "stores the wrong guesses" do
hangman.guess("c").must_equal(false)
hangman.guess("p").must_equal(false)
hangman.wrong_guesses.must_equal(["c", "p"])
end
end
describe "when correct" do
it "returns true" do
hangman.guess("f").must_equal(true)
end
it "stores the correct guesses" do
hangman.guess("l").must_equal(true)
hangman.guess("o").must_equal(true)
hangman.correct_guesses.must_equal(["l", "o"])
end
it "updates the hangman string" do
hangman.guess("l")
hangman.to_s.must_equal("_l____")
hangman.guess("w")
hangman.to_s.must_equal("_l_w__")
end
end
describe "#hint" do
it "gives hint to player" do
hangman.solution.must_include(hangman.hint)
end
it "is a correct guess" do
hint = hangman.hint
hangman.guess(hint)
hangman.correct_guesses.must_include(hint)
end
end
end
end