diff --git a/lib/ruby_warrior/game.rb b/lib/ruby_warrior/game.rb index 59f00c47..f261e08b 100644 --- a/lib/ruby_warrior/game.rb +++ b/lib/ruby_warrior/game.rb @@ -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? @@ -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 diff --git a/spec/ruby_warrior/game_spec.rb b/spec/ruby_warrior/game_spec.rb index a5f40853..c9720a94 100644 --- a/spec/ruby_warrior/game_spec.rb +++ b/spec/ruby_warrior/game_spec.rb @@ -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