forked from Gazler/githug
/
cli_spec.rb
80 lines (65 loc) · 2.3 KB
/
cli_spec.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'spec_helper'
require 'githug/cli'
describe Githug::CLI do
before(:each) do
game = mock.as_null_object
@cli = Githug::CLI.new
Githug::Game.stub(:new).and_return(game)
end
it "should print the logo" do
Githug::UI.should_receive(:word_box).with("Githug")
@cli.stub(:make_directory)
@cli.play
end
it "should create a directory if one does not exist" do
Githug::UI.stub(:ask).and_return(true)
Dir.should_receive(:mkdir).with("./git_hug")
Dir.should_receive(:chdir).with("git_hug")
File.should_receive(:open).with(".gitignore", "w").and_return(true)
@cli.make_directory
end
it "should not make a directory if you are in the game directory" do
Dir.stub(:pwd).and_return("/home/git_hug")
Githug::UI.should_not_receive(:ask)
@cli.make_directory
end
it "should exit if the user selects no" do
Githug::UI.stub(:ask).and_return(false)
lambda {@cli.make_directory}.should raise_error(SystemExit)
end
it "should prompt to change into the directory if it exists" do
File.stub(:exists?).and_return(true)
Githug::UI.should_receive(:puts).with("Please change into the git_hug directory")
lambda {@cli.make_directory}.should raise_error(SystemExit)
end
describe "level methods" do
before(:each) do
@level = mock
@profile = mock
@profile.stub(:level).and_return(1)
Githug::Profile.stub(:load).and_return(@profile)
Githug::Level.stub(:load).and_return(@level)
end
it "should call the hint method on the level" do
@level.should_receive(:show_hint)
@cli.hint
end
describe "reset" do
it "should reset the current level" do
@level.should_receive(:setup_level)
@level.should_receive(:full_description)
Githug::UI.should_receive(:word_box).with("Githug")
Githug::UI.should_receive(:puts).with("resetting level")
@cli.reset
end
it "should not reset if the level cannot be loaded" do
Githug::Level.stub(:load).and_return(false)
@level.should_not_receive(:setup_level)
@level.should_not_receive(:full_description)
Githug::UI.should_not_receive(:word_box).with("Githug")
Githug::UI.should_not_receive(:puts).with("resetting level")
@cli.reset
end
end
end
end