summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2018-09-13 14:54:06 +1000
committerAsh McKenzie <amckenzie@gitlab.com>2018-09-13 14:54:06 +1000
commit58acc2b668e86946c58db4dd41d50edceb7218f9 (patch)
tree365e3f051c2527688f12fcb76ba71296b63d6f91
parent708e60c24d2eb9678e19838a550071c95c3c1a3a (diff)
downloadgitlab-shell-58acc2b668e86946c58db4dd41d50edceb7218f9.tar.gz
Make ordered expectations around results output
This also cleans up the output from the tests as previously, Base64 encoded output was printed.
-rw-r--r--lib/action/custom.rb4
-rw-r--r--spec/action/custom_spec.rb19
-rw-r--r--spec/vcr_cassettes/custom-action-ok.yml4
3 files changed, 21 insertions, 6 deletions
diff --git a/lib/action/custom.rb b/lib/action/custom.rb
index c781f00..2aea41a 100644
--- a/lib/action/custom.rb
+++ b/lib/action/custom.rb
@@ -90,8 +90,8 @@ module Action
def print_flush(str)
return false unless str
- print(Base64.decode64(str))
- STDOUT.flush
+ $stdout.print(Base64.decode64(str))
+ $stdout.flush
end
def validate!
diff --git a/spec/action/custom_spec.rb b/spec/action/custom_spec.rb
index e85df71..c3224a6 100644
--- a/spec/action/custom_spec.rb
+++ b/spec/action/custom_spec.rb
@@ -38,9 +38,24 @@ describe Action::Custom do
end
context 'and responds correctly' do
- it 'returns an instance of Net::HTTPCreated' do
+ it 'prints a Base64 encoded result to $stdout' do
VCR.use_cassette("custom-action-ok") do
- expect(subject.execute).to be_instance_of(Net::HTTPCreated)
+ expect($stdout).to receive(:print).with('info_refs-result').ordered
+ expect($stdout).to receive(:print).with('push-result').ordered
+ subject.execute
+ end
+ end
+
+ context 'with results printed to $stdout' do
+ before do
+ allow($stdout).to receive(:print).with('info_refs-result')
+ allow($stdout).to receive(:print).with('push-result')
+ end
+
+ it 'returns an instance of Net::HTTPCreated' do
+ VCR.use_cassette("custom-action-ok") do
+ expect(subject.execute ).to be_instance_of(Net::HTTPCreated)
+ end
end
end
end
diff --git a/spec/vcr_cassettes/custom-action-ok.yml b/spec/vcr_cassettes/custom-action-ok.yml
index a057441..9d44a37 100644
--- a/spec/vcr_cassettes/custom-action-ok.yml
+++ b/spec/vcr_cassettes/custom-action-ok.yml
@@ -46,7 +46,7 @@ http_interactions:
- '1.436040'
body:
encoding: UTF-8
- string: '{"result":"info_refs-result"}'
+ string: '{"result":"aW5mb19yZWZzLXJlc3VsdA==\n"}'
http_version:
recorded_at: Fri, 20 Jul 2018 06:18:58 GMT
- request:
@@ -93,7 +93,7 @@ http_interactions:
- '0.786754'
body:
encoding: UTF-8
- string: '{"result":"push-result"}'
+ string: '{"result":"cHVzaC1yZXN1bHQ=\n"}'
http_version:
recorded_at: Fri, 20 Jul 2018 06:19:08 GMT
recorded_with: VCR 2.4.0