blue-shell 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,7 +50,8 @@ module BlueShell
50
50
 
51
51
  STDOUT.putc c if @debug
52
52
 
53
- # wear your flip flops
53
+ # evaluate true when \e is read and continue to
54
+ # until m is read
54
55
  unless (c == "\e") .. (c == "m")
55
56
  if c == "\b"
56
57
  if position > 0 && buffer[position - 1] && buffer[position - 1].chr != "\n"
@@ -77,10 +78,12 @@ module BlueShell
77
78
  end
78
79
 
79
80
  def output_ended?(timeout)
80
- timeout.to_i.times do
81
- return true if (@out.is_a?(IO) && !IO.select([@out], nil, nil, 1)) || @out.eof?
81
+ [timeout.to_i, 1].max.times do
82
+ if(@out.is_a?(IO) && IO.select([@out], nil, nil, 1))
83
+ return @out.eof?
84
+ end
82
85
  end
83
- false
86
+ true
84
87
  end
85
88
  end
86
89
  end
@@ -1,12 +1,5 @@
1
1
  module BlueShell
2
2
  module Errors
3
3
  class InvalidInputError < StandardError; end
4
-
5
- class NonZeroExitCodeError < StandardError
6
- attr_reader :exit_code
7
- def initialize(exit_code)
8
- @exit_code = exit_code
9
- end
10
- end
11
4
  end
12
5
  end
@@ -15,8 +15,7 @@ module BlueShell
15
15
  if block_given?
16
16
  yield self
17
17
  else
18
- code = exit_code
19
- raise Errors::NonZeroExitCodeError.new(code) unless code == 0
18
+ wait_for_exit()
20
19
  end
21
20
  end
22
21
 
@@ -1,3 +1,3 @@
1
1
  module BlueShell
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -23,20 +23,45 @@ describe BlueShell::BufferedReaderExpector do
23
23
  end
24
24
 
25
25
  describe "output_ended?" do
26
- it "should not wait the full timeout if the command has already exited" do
26
+ it "does not wait the full timeout if the command has already exited" do
27
27
  begin_time = Time.now
28
28
  Thread.new() do
29
29
  sleep(2)
30
- write.puts Net::EOF
30
+ write.close
31
31
  end
32
- subject.send(:output_ended?, 10)
32
+ subject.send(:output_ended?, 10).should be_true
33
33
  duration = Time.now - begin_time
34
34
 
35
35
  duration.should <= 5
36
36
  end
37
37
 
38
- it "should handle non-integer timeouts" do
38
+ it "handles non-integer timeouts" do
39
39
  expect { subject.send(:output_ended?, 0.1) }.to_not raise_error
40
40
  end
41
+
42
+ it "waits the full timeout when no output is arriving" do
43
+ begin_time = Time.now
44
+ Thread.new() do
45
+ sleep(3)
46
+ write.puts("not done")
47
+ end
48
+ subject.send(:output_ended?, 2).should be_true
49
+ duration = Time.now - begin_time
50
+
51
+ duration.should < 3
52
+ duration.should >= 1.9
53
+ end
54
+
55
+ it "returns false if the output is readable" do
56
+ begin_time = Time.now
57
+ Thread.new() do
58
+ sleep(1)
59
+ write.puts("not done")
60
+ end
61
+ subject.send(:output_ended?, 4).should be_false
62
+ duration = Time.now - begin_time
63
+
64
+ duration.should <= 2
65
+ end
41
66
  end
42
67
  end
@@ -8,25 +8,15 @@ module BlueShell
8
8
  describe "running a command" do
9
9
  let(:file) do
10
10
  file = Tempfile.new('blue-shell-runner')
11
- sleep 1 # wait one second to make sure touching the file does something measurable
11
+ sleep 1 # wait one second to make sure touching the file does something measurable
12
12
  file
13
13
  end
14
14
 
15
15
  after { file.unlink }
16
16
 
17
- context "with an invalid command" do
18
- it "raises an exception" do
19
- expect {
20
- BlueShell::Runner.run("false")
21
- }.to raise_error(Errors::NonZeroExitCodeError) { |error| error.exit_code.should == 1 }
22
- end
23
- end
24
-
25
- context "with a valid command" do
26
- it "runs a command" do
27
- BlueShell::Runner.run("touch -a #{file.path}")
28
- file.stat.atime.should > file.stat.mtime
29
- end
17
+ it "runs a command" do
18
+ BlueShell::Runner.run("touch -a #{file.path}")
19
+ file.stat.atime.should > file.stat.mtime
30
20
  end
31
21
  end
32
22
 
@@ -38,6 +28,10 @@ module BlueShell
38
28
  }
39
29
  runner.should_not be_success
40
30
  runner.should_not be_successful
31
+
32
+ runner = BlueShell::Runner.run("false")
33
+ runner.should_not be_success
34
+ runner.should_not be_successful
41
35
  end
42
36
  end
43
37
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blue-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: