From 31d6fbba6a74b5fbdbb90c19aa619e2a1d6fe2be Mon Sep 17 00:00:00 2001 From: Venkat Dinavahi Date: Thu, 21 Jan 2016 15:05:42 -0500 Subject: [PATCH 1/2] Fixed prompt command to use STDIN --- lib/code/config.rb | 3 +-- lib/code/system.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/code/config.rb b/lib/code/config.rb index d28aabf..1ec8ddb 100644 --- a/lib/code/config.rb +++ b/lib/code/config.rb @@ -57,8 +57,7 @@ def get_property_value(property) def store_property_to_config(property, property_value, config) config.add(property, property_value) - - file = File.open ".codeconfig", "w" + file = File.open '.codeconfig', 'w+' config.write file file.close end diff --git a/lib/code/system.rb b/lib/code/system.rb index 0b286f7..16e9287 100644 --- a/lib/code/system.rb +++ b/lib/code/system.rb @@ -12,7 +12,7 @@ module System def prompt(prompt_text) print prompt_text + ": " - input = gets + input = STDIN.gets input.strip end From 8010603d9b27c2de01049b998d8c22787ba80a7e Mon Sep 17 00:00:00 2001 From: Venkat Dinavahi Date: Thu, 21 Jan 2016 16:03:29 -0500 Subject: [PATCH 2/2] Updated other IO comments to make use of STDIN and STDOUT. Updated tests to reflect this change. --- lib/code/system.rb | 12 ++++++++++-- spec/code/system_spec.rb | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/code/system.rb b/lib/code/system.rb index 16e9287..dc19524 100644 --- a/lib/code/system.rb +++ b/lib/code/system.rb @@ -12,7 +12,7 @@ module System def prompt(prompt_text) print prompt_text + ": " - input = STDIN.gets + input = gets input.strip end @@ -56,8 +56,16 @@ def command_failed? not $?.success? end + def print(text) + STDOUT.print text + end + def puts(text) - Kernel.puts text + STDOUT.puts text + end + + def gets + STDIN.gets end def noecho_gets diff --git a/spec/code/system_spec.rb b/spec/code/system_spec.rb index ff84787..4bd982d 100644 --- a/spec/code/system_spec.rb +++ b/spec/code/system_spec.rb @@ -4,15 +4,15 @@ module Code module System describe "#prompt" do it "should print the prompt, then ask for and return the input" do - expect(System).to receive(:print).with("Test: ").and_return("") - expect(System).to receive(:gets).and_return("test_user") + expect(STDOUT).to receive(:print).with("Test: ").and_return("") + expect(STDIN).to receive(:gets).and_return("test_user") input = System.prompt "Test" expect(input).to eq "test_user" end it "should strip special characters from the input" do - allow(System).to receive(:print).and_return("") - allow(System).to receive(:gets).and_return("test\n") + allow(STDOUT).to receive(:print).and_return("") + allow(STDIN).to receive(:gets).and_return("test\n") input = System.prompt "" expect(input).to eq "test"