From 23c3c07dcf93c07cfc536cfd5d26933ae2d4b7a8 Mon Sep 17 00:00:00 2001 From: mo k Date: Thu, 16 Feb 2012 23:01:49 -0700 Subject: figure out how to interact with the console. --- bin/app.rb | 2 ++ lib/console.rb | 29 +++++++++++++++++++++++++++++ spec/console_specs.rb | 22 ++++++++++++++++++++++ spec/ts_all.rb | 1 + 4 files changed, 54 insertions(+) create mode 100644 lib/console.rb create mode 100644 spec/console_specs.rb diff --git a/bin/app.rb b/bin/app.rb index c1cca1e..a0b530f 100755 --- a/bin/app.rb +++ b/bin/app.rb @@ -3,3 +3,5 @@ require "rover" puts ARGV + +console = Console.new(STDIN, STDOUT) diff --git a/lib/console.rb b/lib/console.rb new file mode 100644 index 0000000..128f6da --- /dev/null +++ b/lib/console.rb @@ -0,0 +1,29 @@ +class Console + def initialize(input, output) + @input = input + @output = output + end + def run(presenter) + @output.puts("Please enter the size of the terrain:") + presenter.provide_upper_right_coordinates(@input.gets) + command = @input.gets + while command != "q" do + presenter.deploy_rover_to(command) + @output.puts("Enter commands to navigate rover:") + presenter.navigate_rover_using(@input.gets) + end + presenter.process_output + end +end +class Presenter + def initialize(command_processor) + end + def provide_upper_right_coordinates(coordinates) + end + def deploy_rover_to(coordinates) + end + def navigate_rover_using(instructions) + end + def process_output + end +end diff --git a/spec/console_specs.rb b/spec/console_specs.rb new file mode 100644 index 0000000..a61855d --- /dev/null +++ b/spec/console_specs.rb @@ -0,0 +1,22 @@ +require "console" + +describe Console do + before do + @input = fake + @output = fake + @presenter = fake + @sut = Console.new(@input, @output) + end + describe "when run" do + it "should ask for the size of the terrain" do + @output.received(:puts).called_with("Please enter the size of the terrain:").wont_be_nil + end + it "should create the terrain" do + @presenter.received(:provide_upper_right_coordinates).called_with("5 5").wont_be_nil + end + before do + @input.stub(:gets).and_return("5 5") + #@sut.run(@presenter) + end + end +end diff --git a/spec/ts_all.rb b/spec/ts_all.rb index 1311bca..a7dff2d 100755 --- a/spec/ts_all.rb +++ b/spec/ts_all.rb @@ -10,4 +10,5 @@ require "rover_specs" require "north_specs" require "south_specs" require "terrain_specs" +require "console_specs" require "specifications/find_all_books_by_author_specs" -- cgit v1.2.3