rspec-bash 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 840b1879e77a1e03bd1d2b0ee87e1ccc47126294
4
- data.tar.gz: 73cc3d08c7cb46f4f85198f477aeb2417d7774ed
3
+ metadata.gz: 49d5aad81e5823b77cd475a99f803af8afc6f445
4
+ data.tar.gz: 8dbe7fb5dfb13c7cccc5b6b791318a4341afc53c
5
5
  SHA512:
6
- metadata.gz: 853e2d1bcf90edcc2ce938269fd9360f225fc46f1a386f929955ad8544ea5de3b7e5bbd0da22b58a4bd0c402f8243901d49fad68e3d560569fd25c7051e00025
7
- data.tar.gz: b1a371ab0fa15617d931ad5579d108189d7d0efe20087902dff1beb0ff3bdac136b21b43acba14dae73c7483e13088fbbb09d4926870e38546bb8b2b0633131a
6
+ metadata.gz: 956d35847b75501827d811a4453c1db3dd988baec17306aaa4bb8ee82dbd49f42b635ade5e19fe56da6ed82a98bff3fc7c1853db70b8e2e2d2b1b8fc2fbdf34d
7
+ data.tar.gz: 0a308ef87217a944f9bcbeda8444d797daf6f3ea3cd4d6f057d718179cea4fe198ce8a5da4b0aaad03fba0c3dca12362a001b5151bfa9ffef4512f1c429b1d45
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![Stories in Ready](https://badge.waffle.io/mdurban/rspec-bash.png?label=ready&title=Ready)](http://waffle.io/mdurban/rspec-bash)
2
2
  [![Build Status](https://travis-ci.org/mdurban/rspec-bash.svg?branch=master)](https://travis-ci.org/mdurban/rspec-bash)
3
+ [![Dependency Status](https://gemnasium.com/badges/github.com/mdurban/rspec-bash.svg)](https://gemnasium.com/github.com/mdurban/rspec-bash)
3
4
 
4
5
  # Rspec::Bash
5
6
 
@@ -55,8 +55,12 @@ function send-to-server {
55
55
  echo -n "${2}" | nc localhost ${1}
56
56
  }
57
57
 
58
- function extract-properties {
59
- echo -n "${1}" | sed -En "s/^\"${2}\":\"?([^,\"]*)\"?,?$/\1/gp"
58
+ function extract-number-properties {
59
+ echo -n "${1}" | sed -En "s/^\"${2}\":([0-9]+),?$/\1/gp"
60
+ }
61
+
62
+ function extract-string-properties {
63
+ echo -n "${1}" | sed -En "s/^\"${2}\":\"(.*)\",?$/\1/gp"
60
64
  }
61
65
 
62
66
  function print-output {
@@ -76,9 +80,9 @@ function main {
76
80
  client_message=$(create-call-log "${@}")
77
81
  server_message=$(send-to-server "${2}" "${client_message}")
78
82
  IFS=$'\n'
79
- target_list=( $(extract-properties "${server_message}" "outputs\..*\.target") )
80
- content_list=( $(extract-properties "${server_message}" "outputs\..*\.content") )
81
- exit_code=$(extract-properties "${server_message}" "exitcode")
83
+ target_list=( $(extract-string-properties "${server_message}" "outputs\..*\.target") )
84
+ content_list=( $(extract-string-properties "${server_message}" "outputs\..*\.content") )
85
+ exit_code=$(extract-number-properties "${server_message}" "exitcode")
82
86
 
83
87
  for index in "${!target_list[@]}"; do
84
88
  target=${target_list[${index}]}
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'rspec-bash'
7
- spec.version = '0.2.0'
7
+ spec.version = '0.2.1'
8
8
  spec.authors = ['Ben Brewer', 'Mike Urban', 'Matthijs Groen']
9
9
  spec.email = ['ben@benbrewer.me', 'mike.david.urban@gmail.com']
10
10
  spec.summary = 'Test Bash with RSpec'
@@ -159,25 +159,29 @@ describe 'BashStub' do
159
159
  end
160
160
  end
161
161
 
162
- context '.extract-properties' do
162
+ context '.extract-*-properties' do
163
163
  context 'given a standard call conf message' do
164
164
  let(:call_conf) do
165
165
  JSON.pretty_generate(
166
166
  Sparsify.sparse(
167
167
  {
168
- exitcode: 10,
168
+ exitcode: 10_000,
169
169
  outputs: [
170
170
  {
171
171
  target: 'stdout',
172
- content: "stdout\nstdout stdout"
172
+ content: "stdout\nstdout,stdout"
173
+ },
174
+ {
175
+ target: 'stdout',
176
+ content: 1
173
177
  },
174
178
  {
175
179
  target: 'stderr',
176
- content: "stderr stderr\nstderr"
180
+ content: "stderr\" stderr\nstderr"
177
181
  },
178
182
  {
179
183
  target: 'tofile',
180
- content: "tofile\ntofile tofile"
184
+ content: "tofile\ntofile:\", tofile"
181
185
  }
182
186
  ]
183
187
  }, sparse_array: true
@@ -188,18 +192,18 @@ describe 'BashStub' do
188
192
  it 'extracts a single value field' do
189
193
  stdout, = stubbed_env.execute_function(
190
194
  BashStubScript.path,
191
- "extract-properties '#{call_conf}' 'exitcode'"
195
+ "extract-number-properties '#{call_conf}' 'exitcode'"
192
196
  )
193
- expect(stdout.chomp).to eql '10'
197
+ expect(stdout.chomp).to eql '10000'
194
198
  end
195
199
 
196
200
  it 'extracts a multiple value field' do
197
201
  stdout, _stderr = stubbed_env.execute_function(
198
202
  BashStubScript.path,
199
- "extract-properties '#{call_conf}' 'outputs\\..*\\.content'"
203
+ "extract-string-properties '#{call_conf}' 'outputs\\..*\\.content'"
200
204
  )
201
- expect(stdout.chomp).to eql "stdout\\nstdout stdout\nstderr stderr\\nstderr" \
202
- "\ntofile\\ntofile tofile"
205
+ expect(stdout.chomp).to eql "stdout\\nstdout,stdout\nstderr\\\" stderr\\nstderr" \
206
+ "\ntofile\\ntofile:\\\", tofile"
203
207
  end
204
208
  end
205
209
  end
@@ -318,19 +322,20 @@ describe 'BashStub' do
318
322
  context '.main' do
319
323
  context 'with stdin, command, port and arguments' do
320
324
  before(:all) do
321
- stubbed_env = create_stubbed_env
322
- @create_call_log = stubbed_env.stub_command('create-call-log').outputs('call log')
323
- @send_to_server = stubbed_env.stub_command('send-to-server').outputs('call conf')
324
- @extract_properties = stubbed_env.stub_command('extract-properties')
325
- @print_output = stubbed_env.stub_command('print-output')
326
-
327
- @extract_properties
325
+ stubbed_env = create_stubbed_env
326
+ @create_call_log = stubbed_env.stub_command('create-call-log').outputs('call log')
327
+ @send_to_server = stubbed_env.stub_command('send-to-server').outputs('call conf')
328
+ @extract_string_properties = stubbed_env.stub_command('extract-string-properties')
329
+ @extract_number_properties = stubbed_env.stub_command('extract-number-properties')
330
+ @print_output = stubbed_env.stub_command('print-output')
331
+
332
+ @extract_string_properties
328
333
  .with_args('call conf', 'outputs\..*\.target')
329
334
  .outputs("stdout\nstderr\ntofile\n")
330
- @extract_properties
335
+ @extract_string_properties
331
336
  .with_args('call conf', 'outputs\..*\.content')
332
337
  .outputs("\\nstd out\\n\n\\nstd err\\n\n\\nto file\\n\n")
333
- @extract_properties.with_args('call conf', 'exitcode').outputs("3\n")
338
+ @extract_number_properties.with_args('call conf', 'exitcode').outputs("3\n")
334
339
 
335
340
  _, _, @status = stubbed_env.execute_function(
336
341
  BashStubScript.path,
@@ -350,17 +355,17 @@ describe 'BashStub' do
350
355
  )
351
356
  end
352
357
  it 'extracts the target list from the call conf returned by the server' do
353
- expect(@extract_properties).to be_called_with_arguments(
358
+ expect(@extract_string_properties).to be_called_with_arguments(
354
359
  'call conf', 'outputs\..*\.target'
355
360
  )
356
361
  end
357
362
  it 'extracts the content list from the call conf returned by the server' do
358
- expect(@extract_properties).to be_called_with_arguments(
363
+ expect(@extract_string_properties).to be_called_with_arguments(
359
364
  'call conf', 'outputs\..*\.content'
360
365
  )
361
366
  end
362
367
  it 'extracts the exit code from the call conf returned by the server' do
363
- expect(@extract_properties).to be_called_with_arguments(
368
+ expect(@extract_number_properties).to be_called_with_arguments(
364
369
  'call conf', 'exitcode'
365
370
  )
366
371
  end
@@ -10,3 +10,7 @@ require 'yaml'
10
10
 
11
11
  require 'helper/string_file_io'
12
12
  require 'helper/shared_tmpdir'
13
+
14
+ RSpec.configure do |c|
15
+ c.include Rspec::Bash
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-bash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Brewer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-12-15 00:00:00.000000000 Z
13
+ date: 2017-12-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sparsify
@@ -121,7 +121,7 @@ files:
121
121
  - spec/integration/call_log/called_with_args_spec.rb
122
122
  - spec/integration/call_log/called_with_no_args_spec.rb
123
123
  - spec/integration/call_log/stdin_spec.rb
124
- - spec/integration/edge_cases_spec.rb
124
+ - spec/integration/edge_cases/long_command_spec.rb
125
125
  - spec/integration/matchers/be_called_with_arguments_spec.rb
126
126
  - spec/integration/matchers/be_called_with_no_arguments_spec.rb
127
127
  - spec/integration/stubbed_command/outputs_spec.rb
@@ -177,7 +177,7 @@ test_files:
177
177
  - spec/integration/call_log/called_with_args_spec.rb
178
178
  - spec/integration/call_log/called_with_no_args_spec.rb
179
179
  - spec/integration/call_log/stdin_spec.rb
180
- - spec/integration/edge_cases_spec.rb
180
+ - spec/integration/edge_cases/long_command_spec.rb
181
181
  - spec/integration/matchers/be_called_with_arguments_spec.rb
182
182
  - spec/integration/matchers/be_called_with_no_arguments_spec.rb
183
183
  - spec/integration/stubbed_command/outputs_spec.rb