here_or_there 0.1.2 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2296126f2ba3b8020b04bcff88b7b4021101094f
4
- data.tar.gz: 486e562e10fab76431d1775169292d5f5d435657
3
+ metadata.gz: 8a0a6ac5b03e5723003f89c3eafd08a4b29394e8
4
+ data.tar.gz: 0bfa81657dc8be9b51feab81de3e76263bd05f17
5
5
  SHA512:
6
- metadata.gz: 4dc59a3f9ca4d2bb794a8d3cb7c0c70b3e012db5f9a9a089ffd1d8050e6e93e187816c10d7ff13fd69bb029b96abafe94414034a405553b39f30564e482ab429
7
- data.tar.gz: a789966d16ea7857d23b9d159318b348105e4ea0ccea73632594bf0a677159a6ce694f38d6d0ce5207c3c3955bf939f9f60275c2ce5e2cabd6ed133085486f15
6
+ metadata.gz: 1c8c951034124752cffc44e5116f9c0415582a45bfdea49ee06293ea221e797ffb8106982dbbb6916d8e6d237d65447c913cba258f7c4b2cc3210a468eee60cd
7
+ data.tar.gz: 22482b2222600db561e51fa6a5b2061670eb0d51440d33e01f1ac235548c5f7b8d57efe7a57bfba7b95e9a7e2ecd61325616462e97f27ff3cc7c9bd8a3bd8f40
@@ -36,10 +36,9 @@ module HereOrThere
36
36
  session.exec! command do |channel, response_type, response_data|
37
37
 
38
38
  if response_type == :stdout
39
- stdout = response_data
40
- status = true
39
+ stdout << response_data
41
40
  else
42
- stderr = response_data
41
+ stderr << response_data
43
42
  status = false
44
43
  end
45
44
 
@@ -1,3 +1,3 @@
1
1
  module HereOrThere
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -5,7 +5,7 @@ describe HereOrThere::Local do
5
5
 
6
6
  it "returns a Response instance" do
7
7
  ret = HereOrThere::Local.new.run( 'spec/fixtures/hello_stdout')
8
- expect( ret.is_a? HereOrThere::Response ).to be_true
8
+ expect( ret.is_a? HereOrThere::Response ).to be_truthy
9
9
  end
10
10
  it "returns stdout as return.stdout" do
11
11
  ret = HereOrThere::Local.new.run( 'spec/fixtures/hello_stdout' )
@@ -19,12 +19,12 @@ describe HereOrThere::Local do
19
19
 
20
20
  it "returns a successful status for a successful command" do
21
21
  ret_succ = HereOrThere::Local.new.run( 'spec/fixtures/hello_stdout' )
22
- expect( ret_succ.success? ).to be_true
22
+ expect( ret_succ.success? ).to be_truthy
23
23
  end
24
24
 
25
25
  it "returns an unsuccessful status for an unsuccessful command" do
26
26
  ret_err = HereOrThere::Local.new.run( 'spec/fixtures/hello_stderr' )
27
- expect( ret_err.success? ).to be_false
27
+ expect( ret_err.success? ).to be_falsy
28
28
  end
29
29
  end
30
30
 
@@ -3,7 +3,8 @@ require 'spec_helper'
3
3
  describe HereOrThere::Remote do
4
4
 
5
5
  before :each do
6
- Net::SSH.stub( start: StubbedSession.new )
6
+ allow( Net::SSH ).to receive(:start)
7
+ .and_return( StubbedSession.new )
7
8
  end
8
9
 
9
10
  describe "::session" do
@@ -17,7 +18,7 @@ describe HereOrThere::Remote do
17
18
  it "creates an SSH object" do
18
19
  expect(
19
20
  HereOrThere::Remote.session( hostname: 'foo', user: 'bar' ).is_a?(HereOrThere::Remote::SSH)
20
- ).to be_true
21
+ ).to be_truthy
21
22
  end
22
23
 
23
24
  it "doesn't recreate an instance" do
@@ -40,13 +41,14 @@ describe HereOrThere::Remote do
40
41
 
41
42
  describe "#run" do
42
43
  it "returns a response object" do
43
- expect( @ssh.run("foo").is_a? HereOrThere::Response ).to be_true
44
+ expect( @ssh.run("foo").is_a? HereOrThere::Response ).to be_truthy
44
45
  end
45
46
 
46
47
  context "when response is stdout" do
47
48
 
48
49
  before :each do
49
- StubbedSession.any_instance.stub(:exec!).and_yield("foo", :stdout, "hello stdout")
50
+ allow_any_instance_of( StubbedSession ).to receive(:exec!)
51
+ .and_yield("foo", :stdout, "hello stdout")
50
52
  end
51
53
 
52
54
  it "assigns response_data to Response.stdout" do
@@ -62,7 +64,8 @@ describe HereOrThere::Remote do
62
64
  context "when response is stderr" do
63
65
 
64
66
  before :each do
65
- StubbedSession.any_instance.stub(:exec!).and_yield("foo", :stderr, "hello stderr")
67
+ allow_any_instance_of( StubbedSession ).to receive(:exec!)
68
+ .and_yield("foo", :stderr, "hello stderr")
66
69
  end
67
70
 
68
71
  it "assigns response_data to Response.stderr" do
@@ -75,12 +78,57 @@ describe HereOrThere::Remote do
75
78
 
76
79
  end
77
80
 
81
+ context "when response gets chunked" do
82
+ let(:session_double) { instance_double("Net::SSH::Connection::Session", closed?: false) }
83
+ before :each do
84
+ allow( Net::SSH ).to receive(:start)
85
+ .and_return( session_double )
86
+ end
87
+
88
+ it "returns the full stdout if it gets chunked" do
89
+ allow( session_double ).to receive(:exec!)
90
+ .and_yield("foo", :stdout, "hello stdout")
91
+ .and_yield("foo", :stdout, "hello stdout")
92
+
93
+ expect( @ssh.run("foo").stdout ).to eq "hello stdouthello stdout"
94
+ end
95
+
96
+ it "returns the full stderr if it gets chunked" do
97
+ allow( session_double ).to receive(:exec!)
98
+ .and_yield("foo", :stderr, "hello stderr")
99
+ .and_yield("foo", :stderr, "hello stderr")
100
+
101
+ expect( @ssh.run("foo").stderr ).to eq "hello stderrhello stderr"
102
+ end
103
+
104
+ it "returns false with stdout & stderr if an error is given" do
105
+ allow( session_double ).to receive(:exec!)
106
+ .and_yield("foo", :stdout, "hello stdout")
107
+ .and_yield("foo", :stderr, "hello stderr")
108
+
109
+ resp = @ssh.run("foo")
110
+ expect( resp.stderr ).to eq "hello stderr"
111
+ expect( resp.stdout ).to eq "hello stdout"
112
+ expect( resp ).not_to be_success
113
+
114
+ allow( session_double ).to receive(:exec!)
115
+ .and_yield("foo", :stderr, "hello stderr")
116
+ .and_yield("foo", :stdout, "hello stdout")
117
+
118
+ resp = @ssh.run("foo")
119
+ expect( resp.stderr ).to eq "hello stderr"
120
+ expect( resp.stdout ).to eq "hello stdout"
121
+ expect( resp ).not_to be_success
122
+ end
123
+ end
124
+
78
125
  context "when the block isn't called" do
79
126
  # this happens when there is an empty response
80
127
  # and no error from the remote
81
128
 
82
129
  before :each do
83
- StubbedSession.any_instance.stub(:exec!).and_return(nil)
130
+ allow_any_instance_of( StubbedSession ).to receive(:exec!)
131
+ .and_return(nil)
84
132
  end
85
133
 
86
134
  it "returns an empty successful response" do
@@ -95,7 +143,8 @@ describe HereOrThere::Remote do
95
143
  context "when raises Net::SSH::AuthenticationFailed" do
96
144
 
97
145
  before :each do
98
- StubbedSession.any_instance.stub(:exec!).and_raise(Net::SSH::AuthenticationFailed)
146
+ allow_any_instance_of( StubbedSession ).to receive(:exec!)
147
+ .and_raise(Net::SSH::AuthenticationFailed)
99
148
  end
100
149
 
101
150
  it "returns an unsucessful response with err as stderr" do
@@ -5,24 +5,26 @@ describe HereOrThere do
5
5
 
6
6
  describe "#run_local" do
7
7
  it "passes the command to a Local instance" do
8
- HereOrThere::Local.any_instance.should_receive(:run).with("foo")
8
+ expect_any_instance_of( HereOrThere::Local ).to receive(:run).with("foo")
9
9
 
10
10
  run_local('foo')
11
11
  end
12
12
  it "returns a response object" do
13
- expect( run_local('spec/fixtures/hello_stdout').is_a? HereOrThere::Response ).to be_true
13
+ expect( run_local('spec/fixtures/hello_stdout').is_a? HereOrThere::Response ).to be_truthy
14
14
  end
15
15
  end
16
16
 
17
17
  describe "#run_remote" do
18
18
  it "passes the command to a SSH instance" do
19
- HereOrThere::Remote::SSH.any_instance.should_receive(:run).with('ls')
19
+ expect_any_instance_of( HereOrThere::Remote::SSH ).to receive(:run).with('ls')
20
20
 
21
21
  run_remote( 'ls', hostname: 'foo', user: 'bar' )
22
22
  end
23
23
  it "returns a response object" do
24
- HereOrThere::Remote::SSH.any_instance.stub( session: StubbedSession.new )
25
- expect( run_remote( 'ls', hostname: 'foo', user: 'bar').is_a? HereOrThere::Response ).to be_true
24
+ allow_any_instance_of( HereOrThere::Remote::SSH ).to receive(:session)
25
+ .and_return(StubbedSession.new)
26
+
27
+ expect( run_remote( 'ls', hostname: 'foo', user: 'bar').is_a? HereOrThere::Response ).to be_truthy
26
28
  end
27
29
  end
28
30
 
data/spec/spec_helper.rb CHANGED
@@ -41,7 +41,7 @@ describe "fixtures" do
41
41
 
42
42
  it "returns success code" do
43
43
  stdout, stderr, status = Open3.capture3('spec/fixtures/hello_stdout')
44
- expect( status.success? ).to be_true
44
+ expect( status.success? ).to be_truthy
45
45
  end
46
46
  end
47
47
 
@@ -53,7 +53,7 @@ describe "fixtures" do
53
53
 
54
54
  it "returns error code" do
55
55
  stdout, stderr, status = Open3.capture3('spec/fixtures/hello_stderr')
56
- expect( status.success? ).to be_false
56
+ expect( status.success? ).to be_falsy
57
57
  end
58
58
  end
59
59
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: here_or_there
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 2.2.2
67
+ rubygems_version: 2.4.5
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Unified interface for running local and remote commands