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..dc19524 100644 --- a/lib/code/system.rb +++ b/lib/code/system.rb @@ -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"