diff --git a/lib/kidsruby/rubywarrior.rb b/lib/kidsruby/rubywarrior.rb index 8779d06..3cf1fb7 100644 --- a/lib/kidsruby/rubywarrior.rb +++ b/lib/kidsruby/rubywarrior.rb @@ -1,5 +1,6 @@ require 'ruby_warrior' +# various monkey patches needed to get rubywarrior working within kidsruby environment module RubyWarrior Config.in_stream = StdIn.new Config.out_stream = $stdout @@ -7,12 +8,11 @@ module RubyWarrior Config.path_prefix = File.expand_path(File.dirname(__FILE__) + "../../..") def self.play - game = RubyWarrior::Game.new + game = Game.new game.verify_setup game.start end - # just generate the .profile file as needed class Game def verify_setup make_game_directory unless File.exist?(Config.path_prefix + '/rubywarrior') @@ -21,22 +21,22 @@ def verify_setup alias_method :prepare_next_level_original, :prepare_next_level def prepare_next_level prepare_next_level_original - next_level.display_description + next_level.show_description end end - # do not load player class from rubywarrior directory, because it should be in kid's editor class Level + # do not load player class from rubywarrior directory, because it should be in kidsruby editor def load_player; end - def display_description + def show_description load_level - UI.puts PlayerGenerator.new(self).level_description + UI.puts PlayerGenerator.new(self).show_description end end class PlayerGenerator - def level_description + def show_description read_template(templates_path + '/README.erb') end end diff --git a/spec/lib/rubywarrior_spec.rb b/spec/lib/rubywarrior_spec.rb new file mode 100644 index 0000000..53a7221 --- /dev/null +++ b/spec/lib/rubywarrior_spec.rb @@ -0,0 +1,56 @@ +require_relative "../spec_helper" +require_relative "../../lib/kidsruby/stdio" +require_relative "../../lib/kidsruby/rubywarrior" + +describe 'rubywarrior' do + describe 'Game' do + it "must be able to start" do + RubyWarrior::Game.any_instance.expects(:verify_setup).returns(nil) + RubyWarrior::Game.any_instance.expects(:start).returns(nil) + RubyWarrior.play + end + + it "must be able to verify setup where no game directory exists yet" do + File.expects(:exist?).returns(false) + RubyWarrior::Game.any_instance.expects(:make_game_directory).returns(nil) + RubyWarrior::Game.new.verify_setup + end + + it "must be able to prepare the next level" do + @next_level = mock("level") + @next_level.expects(:show_description).returns(nil) + RubyWarrior::Game.any_instance.expects(:next_level).returns(@next_level) + RubyWarrior::Game.any_instance.expects(:prepare_next_level_original).returns(nil) + RubyWarrior::Game.new.prepare_next_level + end + end + + describe 'Level' do + before do + @profile = mock('profile') + @level = RubyWarrior::Level.new(@profile, 1) + end + + it "must not load player from file" do + @level.expects(:load).never + @level.load_player + end + + it "must be able to show description" do + @level.expects(:load_level) + RubyWarrior::PlayerGenerator.any_instance.expects(:show_description) + RubyWarrior::UI.expects(:puts) + @level.show_description + end + end + + describe 'PlayerGenerator' do + it "must be able to show description" do + @level = mock('level') + RubyWarrior::PlayerGenerator.any_instance.expects(:read_template) + RubyWarrior::PlayerGenerator.new(@level).show_description + end + end + +end +