diff --git a/README.rdoc b/README.rdoc index d785cb4f..012204db 100644 --- a/README.rdoc +++ b/README.rdoc @@ -9,7 +9,7 @@ NOTE: The player directory structure changed on July 18, 2009. If you have an ol == Getting Started -Run the "rubywarrior" executable (contained in the bin directory) to setup your profile which will create a ruby-warrior directory in your current location. There you will find a player.rb file in your profile's directory which looks like this: +Run the "rubywarrior" executable (contained in the bin directory) to setup your profile which will create a rubywarrior directory in your current location. There you will find a player.rb file in your profile's directory which looks like this: class Player def play_turn(warrior) diff --git a/features/command_options.feature b/features/command_options.feature index 5f69443f..2dfa9b22 100644 --- a/features/command_options.feature +++ b/features/command_options.feature @@ -1,46 +1,46 @@ Feature: Command Options In order to play the game the way I want As a player - I want to customize ruby-warrior with options + I want to customize rubywarrior with options Background: Given no profile at "tmp" Scenario: Run ruby warrior in specified directory with -d option Given a profile named "Joe" on "beginner" - When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb" - And I run rubywarrior with options "-d tmp/ruby-warrior/joe-beginner -t 0" + When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb" + And I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -t 0" And I answer "y" to "next level" - Then I should see "the updated README in the ruby-warrior/joe-beginner directory" + Then I should see "the updated README in the rubywarrior/joe-beginner directory" Scenario: Skip user input with -s option Given a profile named "Joe" on "beginner" - When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb" - And I run rubywarrior with options "-d tmp/ruby-warrior/joe-beginner -t 0 -s" + When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb" + And I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -t 0 -s" Then I should see "current level" - When I run rubywarrior with options "-d tmp/ruby-warrior/joe-beginner -t 0" + When I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -t 0" And I answer "y" to "next level" - Then I should see "the updated README in the ruby-warrior/joe-beginner directory" - When I run rubywarrior with options "-d tmp/ruby-warrior/joe-beginner -t 0 -s" + Then I should see "the updated README in the rubywarrior/joe-beginner directory" + When I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -t 0 -s" Then I should see "failed level 2" Scenario: Unable to practice level if not epic Given a profile named "Joe" on "beginner" - When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb" - And I run rubywarrior with options "-d tmp/ruby-warrior/joe-beginner -l 2" + When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb" + And I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -l 2" Then I should see "Unable" Scenario: Practice specific level when epic When I copy fixture "short-tower" to "towers/short" Given a profile named "Bill" on "short" - When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/bill-short/player.rb" + When I copy fixture "walking_player.rb" to "tmp/rubywarrior/bill-short/player.rb" And I run rubywarrior And I choose "Bill - short - level 1" for "profile" Then I answer "y" to "next level" - And I should see "the updated README in the ruby-warrior/bill-short directory" + And I should see "the updated README in the rubywarrior/bill-short directory" When I run rubywarrior And I choose "Bill - short - level 2" for "profile" Then I answer "y" to "epic" And I should see "epic mode" - When I run rubywarrior with options "-d tmp/ruby-warrior/bill-short -l 2" + When I run rubywarrior with options "-d tmp/rubywarrior/bill-short -l 2" Then I should not see "Level 1" before "Total Score: 17" diff --git a/features/levels.feature b/features/levels.feature index d1e728d8..066cd8e8 100644 --- a/features/levels.feature +++ b/features/levels.feature @@ -8,11 +8,11 @@ Feature: Play levels Scenario: Pass first level, fail second level Given a profile named "Joe" on "beginner" - When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb" + When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb" And I run rubywarrior And I choose "Joe - beginner - level 1" for "profile" And I answer "y" to "next level" - Then I should see "the updated README in the ruby-warrior/joe-beginner directory" + Then I should see "the updated README in the rubywarrior/joe-beginner directory" When I run rubywarrior And I choose "Joe - beginner - level 2" for "profile" And I answer "y" to "clues" @@ -20,7 +20,7 @@ Feature: Play levels Scenario: Retry first level Given a profile named "Joe" on "beginner" - When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb" + When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb" And I run rubywarrior And I choose "Joe - beginner - level 1" for "profile" And I answer "n" to "next level" @@ -32,11 +32,11 @@ Feature: Play levels Scenario: Replay levels as epic when finishing last level with grades When I copy fixture "short-tower" to "towers/short" Given a profile named "Bill" on "short" - When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/bill-short/player.rb" + When I copy fixture "walking_player.rb" to "tmp/rubywarrior/bill-short/player.rb" And I run rubywarrior And I choose "Bill - short - level 1" for "profile" Then I answer "y" to "next level" - And I should see "the updated README in the ruby-warrior/bill-short directory" + And I should see "the updated README in the rubywarrior/bill-short directory" When I run rubywarrior And I choose "Bill - short - level 2" for "profile" Then I answer "y" to "epic" diff --git a/features/profiles.feature b/features/profiles.feature index 49c5272b..1845c55e 100644 --- a/features/profiles.feature +++ b/features/profiles.feature @@ -12,7 +12,7 @@ Feature: Manage Profiles And I choose "beginner" for "tower" And I answer "Joe" to "name" Then I should see "generated" - And I should find file at "tmp/ruby-warrior" + And I should find file at "tmp/rubywarrior" When I run rubywarrior Then I should see "Joe - beginner - level 1 - score 0" @@ -39,8 +39,18 @@ Feature: Manage Profiles Scenario: Auto select profile at given path Given a profile named "Joe" on "beginner" - And current directory is "tmp/ruby-warrior/joe-beginner" - When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb" + And current directory is "tmp/rubywarrior/joe-beginner" + When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb" And I run rubywarrior And I answer "y" to "next level" - Then I should see "the updated README in the ruby-warrior/joe-beginner directory" + Then I should see "the updated README in the rubywarrior/joe-beginner directory" + + Scenario: Move legacy ruby-warrior profile + Given a directory at "tmp/ruby-warrior" + And no directory at "tmp/rubywarrior" + When I run rubywarrior + And I choose "beginner" for "tower" + And I answer "Joe" to "name" + Then I should see "generated" + And I should find file at "tmp/rubywarrior" + And I should find no file at "tmp/ruby-warrior" diff --git a/features/step_definitions/common_steps.rb b/features/step_definitions/common_steps.rb index 8170a617..8351b765 100644 --- a/features/step_definitions/common_steps.rb +++ b/features/step_definitions/common_steps.rb @@ -1,3 +1,11 @@ +Given /^a directory at "([^\"]*)"$/ do |path| + Dir.mkdir(path) unless File.exist? path +end + +Given /^no directory at "([^\"]*)"$/ do |path| + Dir.rmdir(path) if File.exist? path +end + When /^I copy fixture "([^\"]*)" to "([^\"]*)"$/ do |from, to| FileUtils.cp_r("spec/fixtures/" + from, to) end @@ -5,3 +13,7 @@ Then /^I should find file at "([^\"]*)"$/ do |path| File.exist?(path).should be_true end + +Then /^I should find no file at "([^\"]*)"$/ do |path| + File.exist?(path).should be_false +end diff --git a/features/step_definitions/interaction_steps.rb b/features/step_definitions/interaction_steps.rb index f293fb56..5c1b50ee 100644 --- a/features/step_definitions/interaction_steps.rb +++ b/features/step_definitions/interaction_steps.rb @@ -8,7 +8,7 @@ Given /^no profile at "([^\"]*)"$/ do |path| RubyWarrior::Config.path_prefix = path - FileUtils.rm_rf("#{path}/ruby-warrior") + FileUtils.rm_rf("#{path}/rubywarrior") end Given /^current directory is "([^\"]*)"$/ do |path| diff --git a/lib/ruby_warrior/game.rb b/lib/ruby_warrior/game.rb index 12277678..de6daf82 100644 --- a/lib/ruby_warrior/game.rb +++ b/lib/ruby_warrior/game.rb @@ -4,18 +4,21 @@ class Game def start UI.puts "Welcome to Ruby Warrior" - if File.exists?(Config.path_prefix + '/.profile') + if File.exist?(Config.path_prefix + '/.profile') @profile = Profile.load(Config.path_prefix + '/.profile') else - make_game_directory unless File.exists?(Config.path_prefix + '/ruby-warrior') + 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') end profile.epic? ? play_epic_mode : play_normal_mode end def make_game_directory - if UI.ask("No ruby-warrior directory found, would you like to create one?") - Dir.mkdir(Config.path_prefix + '/ruby-warrior') + if UI.ask("No rubywarrior directory found, would you like to create one?") + Dir.mkdir(Config.path_prefix + '/rubywarrior') else UI.puts "Unable to continue without directory." exit @@ -47,7 +50,7 @@ def play_normal_mode else if current_level.number.zero? prepare_next_level - UI.puts "First level has been generated. See the ruby-warrior/#{profile.directory_name}/README for instructions." + UI.puts "First level has been generated. See the rubywarrior/#{profile.directory_name}/README for instructions." else play_current_level end @@ -86,7 +89,7 @@ def request_next_level if !Config.skip_input? && (next_level.exists? ? UI.ask("Would you like to continue on to the next level?") : UI.ask("Would you like to continue on to epic mode?")) if next_level.exists? prepare_next_level - UI.puts "See the updated README in the ruby-warrior/#{profile.directory_name} directory." + UI.puts "See the updated README in the rubywarrior/#{profile.directory_name} directory." else prepare_epic_mode UI.puts "Run rubywarrior again to play epic mode." @@ -116,7 +119,7 @@ def profiles end def profile_paths - Dir[Config.path_prefix + '/ruby-warrior/**/.profile'] + Dir[Config.path_prefix + '/rubywarrior/**/.profile'] end def profile diff --git a/lib/ruby_warrior/profile.rb b/lib/ruby_warrior/profile.rb index 7f47b4c2..921ae70d 100644 --- a/lib/ruby_warrior/profile.rb +++ b/lib/ruby_warrior/profile.rb @@ -37,7 +37,7 @@ def self.load(path) end def player_path - @player_path || Config.path_prefix + "/ruby-warrior/#{directory_name}" + @player_path || Config.path_prefix + "/rubywarrior/#{directory_name}" end def directory_name diff --git a/spec/ruby_warrior/game_spec.rb b/spec/ruby_warrior/game_spec.rb index cbaf27c4..b7314d4d 100644 --- a/spec/ruby_warrior/game_spec.rb +++ b/spec/ruby_warrior/game_spec.rb @@ -9,7 +9,7 @@ it "should make game directory if player says so" do RubyWarrior::UI.stubs(:ask).returns(true) - Dir.expects(:mkdir).with('./ruby-warrior') + Dir.expects(:mkdir).with('./rubywarrior') @game.make_game_directory end @@ -30,7 +30,7 @@ end it "should find profile paths using Dir[] search" do - Dir.expects(:[]).with("./ruby-warrior/**/.profile") + Dir.expects(:[]).with("./rubywarrior/**/.profile") @game.profile_paths end diff --git a/spec/ruby_warrior/profile_spec.rb b/spec/ruby_warrior/profile_spec.rb index e5f58322..02e67a90 100644 --- a/spec/ruby_warrior/profile_spec.rb +++ b/spec/ruby_warrior/profile_spec.rb @@ -128,7 +128,7 @@ end it "should guess at the player path" do - @profile.player_path.should == './ruby-warrior/john-smith-tower' + @profile.player_path.should == './rubywarrior/john-smith-tower' end it "should use specified player path" do