diff --git a/spec/test_hook.rb b/spec/test_hook.rb index 0dd2109..380c9c7 100755 --- a/spec/test_hook.rb +++ b/spec/test_hook.rb @@ -1,6 +1,12 @@ #!/usr/bin/env ruby # frozen_string_literal: true +output = [] $stdin.readlines.each do |line| - puts line.gsub(/([^\s]*)\s*=\s*(.*)/, '\1 = \2') + exit 0 if line.chomp == '#clear' + output << line.gsub(/([^\s]*)\s*=\s*(.*)/, '\1 = \2') +end + +output.each do |line| + puts line end diff --git a/spec/test_hook_spec.rb b/spec/test_hook_spec.rb new file mode 100644 index 0000000..167de49 --- /dev/null +++ b/spec/test_hook_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +describe 'Test Hook' do + it 'adds spaces around =' do + out = run 'a=b' + + expect(out).to eq('a = b') + end + + it 'returns empty output if it as a #clear line' do + out = run "a=b\n#clear\nc = d" + expect(out).to eq '' + end + + def run(input) + IO.popen ['ruby', "#{__dir__}/test_hook.rb"], mode: File::RDWR do |io| + io.write input + io.close_write + io.read.chomp + end + end +end