Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add creating base directory for rubywarrior data #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/ruby_warrior/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def start
if File.exist?(Config.path_prefix + '/ruby-warrior')
FileUtils.mv(Config.path_prefix + '/ruby-warrior', Config.path_prefix + '/rubywarrior')
end
make_game_directory unless File.exist?(Config.path_prefix + '/rubywarrior')
make_game_directory unless File.exist?(Config.path_prefix)
make_game_directory('rubywarrior') unless File.exist?(Config.path_prefix + '/rubywarrior')
end

if profile.epic?
Expand All @@ -23,16 +24,19 @@ def start
play_normal_mode
end
end

def make_game_directory
if UI.ask("No rubywarrior directory found, would you like to create one?")
Dir.mkdir(Config.path_prefix + '/rubywarrior')

def make_game_directory(dir_name = nil)
dir_path = Config.path_prefix
dir_path = File.join(Config.path_prefix, dir_name) if dir_name

if UI.ask("No [#{dir_name || dir_path}] directory found, would you like to create one?")
Dir.mkdir(dir_path)
else
UI.puts "Unable to continue without directory."
UI.puts "Unable to continue without [#{dir_name || dir_path}] directory."
exit
end
end

def play_epic_mode
Config.delay /= 2 if Config.delay # speed up UI since we're going to be doing a lot here
profile.current_epic_score = 0
Expand Down
8 changes: 7 additions & 1 deletion spec/ruby_warrior/game_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
end

# GAME DIR

it "should make base directory if player says so" do
RubyWarrior::UI.stubs(:ask).returns(true)
Dir.expects(:mkdir).with(RubyWarrior::Config.path_prefix)
@game.make_game_directory
end

it "should make game directory if player says so" do
RubyWarrior::UI.stubs(:ask).returns(true)
Dir.expects(:mkdir).with('./rubywarrior')
@game.make_game_directory
@game.make_game_directory('rubywarrior')
end

it "should not make game and exit if player says no" do
Expand Down