rspec-bash 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/Gemfile +1 -0
  4. data/README.md +23 -0
  5. data/Rakefile +15 -4
  6. data/bin/bash_stub.sh +92 -0
  7. data/bin/bash_wrapper.sh.erb +12 -0
  8. data/bin/ruby_stub.rb +33 -0
  9. data/lib/rspec/bash.rb +5 -4
  10. data/lib/rspec/bash/command.rb +5 -0
  11. data/lib/rspec/bash/command/call_configuration.rb +76 -0
  12. data/lib/rspec/bash/command/call_configuration_manager.rb +24 -0
  13. data/lib/rspec/bash/command/call_log.rb +48 -0
  14. data/lib/rspec/bash/command/call_log_manager.rb +38 -0
  15. data/lib/rspec/bash/command/stubbed_command.rb +64 -0
  16. data/lib/rspec/bash/server.rb +3 -0
  17. data/lib/rspec/bash/server/bash_stub_marshaller.rb +19 -0
  18. data/lib/rspec/bash/server/ruby_stub_marshaller.rb +13 -0
  19. data/lib/rspec/bash/server/stub_server.rb +47 -0
  20. data/lib/rspec/bash/stubbed_env.rb +75 -54
  21. data/lib/rspec/bash/util/call_conf_argument_list_matcher.rb +5 -5
  22. data/lib/rspec/bash/util/call_log_argument_list_matcher.rb +1 -1
  23. data/lib/rspec/bash/wrapper.rb +4 -0
  24. data/lib/rspec/bash/wrapper/bash_stub_script.rb +15 -0
  25. data/lib/rspec/bash/wrapper/bash_wrapper.rb +54 -0
  26. data/lib/rspec/bash/wrapper/ruby_stub_script.rb +15 -0
  27. data/lib/rspec/bash/wrapper/stub_function.rb +36 -0
  28. data/rspec-bash.gemspec +2 -1
  29. data/spec/classes/command/call_configuration_manager_spec.rb +68 -0
  30. data/spec/classes/{call_configuration_spec.rb → command/call_configuration_spec.rb} +51 -114
  31. data/spec/classes/command/call_log_manager_spec.rb +83 -0
  32. data/spec/classes/{call_log_spec.rb → command/call_log_spec.rb} +23 -82
  33. data/spec/classes/command/stubbed_command_spec.rb +118 -0
  34. data/spec/classes/server/bash_stub_marshaller_spec.rb +38 -0
  35. data/spec/classes/server/ruby_stub_marshaller_spec.rb +31 -0
  36. data/spec/classes/server/stub_server_spec.rb +121 -0
  37. data/spec/classes/stubbed_env_spec.rb +141 -280
  38. data/spec/classes/util/call_conf_argument_list_matcher_spec.rb +17 -17
  39. data/spec/classes/util/call_log_argument_list_matcher_spec.rb +24 -18
  40. data/spec/classes/wrapper/bash_wrapper_spec.rb +37 -0
  41. data/spec/classes/wrapper/ruby_stub_script_spec.rb +204 -0
  42. data/spec/helper/string_file_io.rb +1 -1
  43. data/spec/integration/call_log/called_with_args_spec.rb +8 -4
  44. data/spec/integration/call_log/called_with_no_args_spec.rb +1 -1
  45. data/spec/integration/call_log/stdin_spec.rb +10 -4
  46. data/spec/integration/edge_cases_spec.rb +34 -0
  47. data/spec/integration/matchers/be_called_with_arguments_spec.rb +12 -13
  48. data/spec/integration/matchers/be_called_with_no_arguments_spec.rb +6 -7
  49. data/spec/integration/stubbed_command/outputs_spec.rb +111 -91
  50. data/spec/integration/stubbed_command/returns_exitstatus_spec.rb +46 -37
  51. data/spec/integration/stubbed_env/execute_with_env_vars_spec.rb +3 -4
  52. data/spec/integration/stubbed_env/execute_with_path_spec.rb +6 -7
  53. data/spec/integration/stubbed_env/execute_with_stub_wrapper_spec.rb +4 -12
  54. data/spec/integration/stubbed_env/override_spec.rb +354 -0
  55. data/spec/integration/wrapper/bash_stub_script_spec.rb +383 -0
  56. data/spec/integration/wrapper/bash_wrapper_spec.rb +48 -0
  57. data/spec/scripts/function_library.sh +9 -1
  58. data/spec/spec_helper.rb +2 -0
  59. metadata +65 -21
  60. data/bin/function_override.sh.erb +0 -7
  61. data/bin/function_override_wrapper.sh.erb +0 -19
  62. data/bin/stub.rb.erb +0 -56
  63. data/lib/rspec/bash/call_configuration.rb +0 -62
  64. data/lib/rspec/bash/call_log.rb +0 -71
  65. data/lib/rspec/bash/stubbed_command.rb +0 -88
  66. data/spec/classes/stub_spec.rb +0 -510
  67. data/spec/classes/stubbed_command_spec.rb +0 -134
  68. data/spec/integration/assert_called_spec.rb +0 -0
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
+ include Rspec::Bash
2
3
 
3
4
  describe 'CallLog' do
4
5
  context '#called_with_no_args?' do
5
- include Rspec::Bash
6
6
  let(:stubbed_env) { create_stubbed_env }
7
7
  let!(:ls) { stubbed_env.stub_command('ls') }
8
8
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
+ include Rspec::Bash
2
3
 
3
4
  describe 'CallLog' do
4
- include Rspec::Bash
5
5
  let(:stubbed_env) { create_stubbed_env }
6
6
  let!(:first_command) { stubbed_env.stub_command('first_command') }
7
7
 
@@ -11,7 +11,8 @@ describe 'CallLog' do
11
11
  stubbed_env.execute_inline(
12
12
  <<-multiline_script
13
13
  echo -n 'first_call' | first_command first_argument second_argument
14
- echo -n 'second_call' | first_command first_argument second_argument third_argument
14
+ echo -e '\nsecond_call' | first_command first_argument second_argument third_argument
15
+ first_command first_argument second_argument third_argument fourth_argument
15
16
  multiline_script
16
17
  )
17
18
  end
@@ -31,7 +32,12 @@ describe 'CallLog' do
31
32
 
32
33
  it 'matches for anything matches' do
33
34
  expect(first_command
34
- .with_args(anything, anything, 'third_argument').stdin).to eql 'second_call'
35
+ .with_args(anything, anything, 'third_argument').stdin).to eql "\nsecond_call\n"
36
+ end
37
+
38
+ it 'is blank for cases where no stdin was passed' do
39
+ expect(first_command
40
+ .with_args(anything, anything, 'third_argument', 'fourth_argument').stdin).to be_empty
35
41
  end
36
42
 
37
43
  it 'matches for any_args matches' do
@@ -46,7 +52,7 @@ describe 'CallLog' do
46
52
 
47
53
  it 'matches for regex matches' do
48
54
  expect(first_command
49
- .with_args(/f..st_argument/, /se..nd_argument/, /.*/).stdin).to eql 'second_call'
55
+ .with_args(/f..st_argument/, /se..nd_argument/, /.*/).stdin).to eql "\nsecond_call\n"
50
56
  end
51
57
  end
52
58
  end
@@ -0,0 +1,34 @@
1
+ require 'rspec/bash'
2
+ include Rspec::Bash
3
+
4
+ describe 'scenarios where performance improvements break things' do
5
+ let(:stubbed_env) { create_stubbed_env }
6
+
7
+ context 'weird case where a docker flag argument gets removed' do
8
+ let!(:docker) { stubbed_env.stub_command('docker') }
9
+ before do
10
+ stubbed_env.execute_inline(
11
+ <<-multiline_script
12
+ docker run \
13
+ --rm \
14
+ -i \
15
+ --env HADOOP_USER_NAME \
16
+ --env CLIENT_CONF_URL \
17
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
18
+ hadoop fs -test -e hdfs:///xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
19
+ multiline_script
20
+ )
21
+ end
22
+ it 'should not remove the -e flag from the command log' do
23
+ expect(docker).to be_called_with_arguments(
24
+ 'run',
25
+ '--rm',
26
+ '-i',
27
+ '--env', 'HADOOP_USER_NAME',
28
+ '--env', 'CLIENT_CONF_URL',
29
+ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
30
+ 'hadoop', 'fs', '-test', '-e', 'hdfs:///xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
31
+ )
32
+ end
33
+ end
34
+ end
@@ -1,37 +1,36 @@
1
1
  require 'spec_helper'
2
+ include Rspec::Bash
2
3
 
3
4
  describe 'RSpec::Matchers' do
4
- include Rspec::Bash
5
5
  let(:stubbed_env) { create_stubbed_env }
6
6
 
7
7
  context '.be_called_with_arguments' do
8
8
  context 'with a command' do
9
+ let!(:command) { stubbed_env.stub_command('stubbed_command') }
9
10
  context 'and no chain calls' do
10
11
  before(:each) do
11
- @command = stubbed_env.stub_command('stubbed_command')
12
- @actual_stdout, @actual_stderr, @actual_status = stubbed_env.execute_inline(
12
+ stubbed_env.execute_inline(
13
13
  <<-multiline_script
14
14
  stubbed_command first_argument second_argument
15
15
  multiline_script
16
16
  )
17
17
  end
18
18
  it 'correctly identifies the called arguments' do
19
- expect(@command).to be_called_with_arguments('first_argument', 'second_argument')
19
+ expect(command).to be_called_with_arguments('first_argument', 'second_argument')
20
20
  end
21
21
  it 'correctly matches when wildcard is used for first argument' do
22
- expect(@command).to be_called_with_arguments(anything, 'second_argument')
22
+ expect(command).to be_called_with_arguments(anything, 'second_argument')
23
23
  end
24
24
  it 'correctly matches when wildcard is used for second argument' do
25
- expect(@command).to be_called_with_arguments('first_argument', anything)
25
+ expect(command).to be_called_with_arguments('first_argument', anything)
26
26
  end
27
27
  it 'correctly matches when wildcard is used for all arguments' do
28
- expect(@command).to be_called_with_arguments(anything, anything)
28
+ expect(command).to be_called_with_arguments(anything, anything)
29
29
  end
30
30
  end
31
31
  context 'and the times chain call' do
32
32
  before(:each) do
33
- @command = stubbed_env.stub_command('stubbed_command')
34
- @actual_stdout, @actual_stderr, @actual_status = stubbed_env.execute_inline(
33
+ stubbed_env.execute_inline(
35
34
  <<-multiline_script
36
35
  stubbed_command duplicated_argument once_called_argument
37
36
  stubbed_command duplicated_argument irrelevant_argument
@@ -39,19 +38,19 @@ describe 'RSpec::Matchers' do
39
38
  )
40
39
  end
41
40
  it 'matches when arguments are called twice' do
42
- expect(@command)
41
+ expect(command)
43
42
  .to be_called_with_arguments('duplicated_argument', anything).times(2)
44
43
  end
45
44
  it 'matches when argument is called once' do
46
- expect(@command)
45
+ expect(command)
47
46
  .to be_called_with_arguments(anything, 'once_called_argument').times(1)
48
47
  end
49
48
  it 'matches when argument combination is called once' do
50
- expect(@command)
49
+ expect(command)
51
50
  .to be_called_with_arguments('duplicated_argument', 'once_called_argument').times(1)
52
51
  end
53
52
  it 'matches when argument is not called' do
54
- expect(@command)
53
+ expect(command)
55
54
  .to_not be_called_with_arguments('not_called_argument').times(1)
56
55
  end
57
56
  end
@@ -1,34 +1,33 @@
1
1
  require 'spec_helper'
2
+ include Rspec::Bash
2
3
 
3
4
  describe 'RSpec::Matchers' do
4
- include Rspec::Bash
5
5
  let(:stubbed_env) { create_stubbed_env }
6
+ let!(:command) { stubbed_env.stub_command('stubbed_command') }
6
7
 
7
8
  context '.be_called_with_no_arguments' do
8
9
  context 'when command is called with no args' do
9
10
  before(:each) do
10
- @command = stubbed_env.stub_command('stubbed_command')
11
- @actual_stdout, @actual_stderr, @actual_status = stubbed_env.execute_inline(
11
+ stubbed_env.execute_inline(
12
12
  <<-multiline_script
13
13
  stubbed_command
14
14
  multiline_script
15
15
  )
16
16
  end
17
17
  it 'correctly identifies that no arguments were called' do
18
- expect(@command).to be_called_with_no_arguments
18
+ expect(command).to be_called_with_no_arguments
19
19
  end
20
20
  end
21
21
  context 'when command is called with args' do
22
22
  before(:each) do
23
- @command = stubbed_env.stub_command('stubbed_command')
24
- @actual_stdout, @actual_stderr, @actual_status = stubbed_env.execute_inline(
23
+ stubbed_env.execute_inline(
25
24
  <<-multiline_script
26
25
  stubbed_command argument
27
26
  multiline_script
28
27
  )
29
28
  end
30
29
  it 'correctly identifies that arguments were passed into command call' do
31
- expect(@command).to_not be_called_with_no_arguments
30
+ expect(command).to_not be_called_with_no_arguments
32
31
  end
33
32
  end
34
33
  end
@@ -1,87 +1,98 @@
1
1
  require 'spec_helper'
2
+ include Rspec::Bash
3
+
4
+ def execute_script(script)
5
+ let!(:execute_results) do
6
+ stdout, stderr, status = stubbed_env.execute_inline(
7
+ script
8
+ )
9
+ [stdout, stderr, status]
10
+ end
11
+ let(:stdout) { execute_results[0] }
12
+ let(:stderr) { execute_results[1] }
13
+ let(:exitcode) { execute_results[2].exitstatus }
14
+ end
2
15
 
3
16
  describe 'StubbedCommand' do
4
- include Rspec::Bash
5
17
  let(:stubbed_env) { create_stubbed_env }
6
- let!(:command1_stub) { stubbed_env.stub_command('command1') }
18
+ let!(:command) { stubbed_env.stub_command('stubbed_command') }
7
19
 
8
20
  describe '#outputs' do
9
21
  describe 'target stdout' do
10
22
  context 'when given no arguments to match' do
11
- let(:output) do
12
- command1_stub
13
- .outputs('hello', to: :stdout)
14
- output, = stubbed_env.execute_inline('command1 first_argument second_argument')
15
- output
23
+ before do
24
+ command.outputs("\nhello\n", to: :stdout)
16
25
  end
17
26
 
27
+ execute_script('stubbed_command first_argument second_argument')
28
+
18
29
  it 'outputs the expected output to stdout' do
19
- expect(output).to eql 'hello'
30
+ expect(stdout).to eql "\nhello\n"
20
31
  end
21
32
  end
22
33
  context 'when given an exact argument match' do
23
- let(:output) do
24
- command1_stub
34
+ before do
35
+ command
25
36
  .with_args('first_argument', 'second_argument')
26
- .outputs('hello', to: :stdout)
27
- output, = stubbed_env.execute_inline('command1 first_argument second_argument')
28
- output
37
+ .outputs("\nhello\n", to: :stdout)
29
38
  end
30
39
 
40
+ execute_script('stubbed_command first_argument second_argument')
41
+
31
42
  it 'outputs the expected output to stdout' do
32
- expect(output).to eql 'hello'
43
+ expect(stdout).to eql "\nhello\n"
33
44
  end
34
45
  end
35
46
  context 'when given an anything argument match' do
36
- let(:output) do
37
- command1_stub
47
+ before do
48
+ command
38
49
  .with_args('first_argument', anything)
39
50
  .outputs('i respond to anything', to: :stdout)
40
- output, = stubbed_env.execute_inline('command1 first_argument piglet')
41
- output
42
51
  end
43
52
 
53
+ execute_script('stubbed_command first_argument piglet')
54
+
44
55
  it 'outputs the expected output to stdout' do
45
- expect(output).to eql 'i respond to anything'
56
+ expect(stdout).to eql 'i respond to anything'
46
57
  end
47
58
  end
48
59
  context 'when given any_args argument match' do
49
- let(:output) do
50
- command1_stub
60
+ before do
61
+ command
51
62
  .with_args(any_args)
52
63
  .outputs('i respond to any_args', to: :stdout)
53
- output, = stubbed_env.execute_inline('command1 poglet piglet')
54
- output
55
64
  end
56
65
 
66
+ execute_script('stubbed_command poglet piglet')
67
+
57
68
  it 'outputs the expected output to stdout' do
58
- expect(output).to eql 'i respond to any_args'
69
+ expect(stdout).to eql 'i respond to any_args'
59
70
  end
60
71
  end
61
72
  context 'when given other types of RSpec::Mock::ArgumentMatcher argument match' do
62
- let(:output) do
63
- command1_stub
73
+ before do
74
+ command
64
75
  .with_args(instance_of(String), instance_of(String))
65
76
  .outputs('i respond to instance_of', to: :stdout)
66
- output, = stubbed_env.execute_inline('command1 poglet 1')
67
- output
68
77
  end
69
78
 
79
+ execute_script('stubbed_command poglet 1')
80
+
70
81
  it 'outputs the expected output to stdout' do
71
- expect(output).to eql 'i respond to instance_of'
82
+ expect(stdout).to eql 'i respond to instance_of'
72
83
  end
73
84
  end
74
85
  context 'when given regex argument match' do
75
- let(:output) do
76
- command1_stub
86
+ before do
87
+ command
77
88
  .with_args(/p.glet/, /p.glet/)
78
89
  .outputs('i respond to regex', to: :stdout)
79
- output, = stubbed_env.execute_inline('command1 poglet piglet')
80
- output
81
90
  end
82
91
 
92
+ execute_script('stubbed_command poglet piglet')
93
+
83
94
  it 'outputs the expected output to stdout' do
84
- expect(output).to eql 'i respond to regex'
95
+ expect(stdout).to eql 'i respond to regex'
85
96
  end
86
97
  end
87
98
  end
@@ -89,153 +100,160 @@ describe 'StubbedCommand' do
89
100
  # TODO: it is a bug that these require a \n in the output
90
101
  describe 'target stderr' do
91
102
  context 'when given no arguments to match' do
92
- let(:error) do
93
- command1_stub
94
- .outputs('hello', to: :stderr)
95
- _, error, = stubbed_env.execute_inline('command1 first_argument second_argument')
96
- error
103
+ before do
104
+ command
105
+ .outputs("\nhello\n", to: :stderr)
97
106
  end
98
107
 
108
+ execute_script('stubbed_command first_argument second_argument')
109
+
99
110
  it 'outputs the expected error to stderr' do
100
- expect(error).to eql "hello\n"
111
+ expect(stderr).to eql "\nhello\n"
101
112
  end
102
113
  end
103
114
  context 'when given an exact argument match' do
104
- let(:error) do
105
- command1_stub
115
+ before do
116
+ command
106
117
  .with_args('first_argument', 'second_argument')
107
- .outputs('hello', to: :stderr)
108
- _, error, = stubbed_env.execute_inline('command1 first_argument second_argument')
109
- error
118
+ .outputs("\nhello\n", to: :stderr)
110
119
  end
111
120
 
121
+ execute_script('stubbed_command first_argument second_argument')
122
+
112
123
  it 'outputs the expected error to stderr' do
113
- expect(error).to eql "hello\n"
124
+ expect(stderr).to eql "\nhello\n"
114
125
  end
115
126
  end
116
127
  context 'when given an anything argument match' do
117
- let(:error) do
118
- command1_stub
128
+ before do
129
+ command
119
130
  .with_args('first_argument', anything)
120
131
  .outputs('i respond to anything', to: :stderr)
121
- _, error, = stubbed_env.execute_inline('command1 first_argument piglet')
122
- error
123
132
  end
124
133
 
134
+ execute_script('stubbed_command first_argument piglet')
135
+
125
136
  it 'outputs the expected error to stderr' do
126
- expect(error).to eql "i respond to anything\n"
137
+ expect(stderr).to eql "i respond to anything\n"
127
138
  end
128
139
  end
129
140
  context 'when given any_args argument match' do
130
- let(:error) do
131
- command1_stub
141
+ before do
142
+ command
132
143
  .with_args(any_args)
133
144
  .outputs('i respond to any_args', to: :stderr)
134
- _, error, = stubbed_env.execute_inline('command1 poglet piglet')
135
- error
136
145
  end
137
146
 
147
+ execute_script('stubbed_command poglet piglet')
148
+
138
149
  it 'outputs the expected error to stderr' do
139
- expect(error).to eql "i respond to any_args\n"
150
+ expect(stderr).to eql "i respond to any_args\n"
140
151
  end
141
152
  end
142
153
  context 'when given other types of RSpec::Mock::ArgumentMatcher argument match' do
143
- let(:error) do
144
- command1_stub
154
+ before do
155
+ command
145
156
  .with_args(instance_of(String), instance_of(String))
146
157
  .outputs('i respond to instance_of', to: :stderr)
147
- _, error, = stubbed_env.execute_inline('command1 poglet 1')
148
- error
149
158
  end
150
159
 
160
+ execute_script('stubbed_command poglet 1')
161
+
151
162
  it 'outputs the expected error to stderr' do
152
- expect(error).to eql "i respond to instance_of\n"
163
+ expect(stderr).to eql "i respond to instance_of\n"
153
164
  end
154
165
  end
155
166
  context 'when given regex argument match' do
156
- let(:error) do
157
- command1_stub
167
+ before do
168
+ command
158
169
  .with_args(/p.glet/, /p.glet/)
159
170
  .outputs('i respond to regex', to: :stderr)
160
- _, error, = stubbed_env.execute_inline('command1 poglet piglet')
161
- error
162
171
  end
163
172
 
173
+ execute_script('stubbed_command poglet piglet')
174
+
164
175
  it 'outputs the expected error to stderr' do
165
- expect(error).to eql "i respond to regex\n"
176
+ expect(stderr).to eql "i respond to regex\n"
166
177
  end
167
178
  end
168
179
  end
169
180
 
170
181
  describe 'target file path' do
171
182
  let(:temp_file) { Tempfile.new('for-testing') }
183
+
172
184
  context 'when given no arguments to match' do
173
- before(:each) do
174
- command1_stub
175
- .outputs('hello', to: temp_file.path)
176
- stubbed_env.execute_inline('command1 first_argument second_argument')
185
+ before do
186
+ command
187
+ .outputs("\nhello\n", to: temp_file.path)
177
188
  end
178
189
 
190
+ execute_script('stubbed_command first_argument second_argument')
191
+
179
192
  it 'outputs the expected content to the file' do
180
- expect(temp_file.read).to eql 'hello'
193
+ expect(temp_file.read).to eql "\nhello\n"
181
194
  end
182
195
  end
183
196
  context 'when given an exact argument match' do
184
- before(:each) do
185
- command1_stub
197
+ before do
198
+ command
186
199
  .with_args('first_argument', 'second_argument')
187
- .outputs('hello', to: temp_file.path)
188
- stubbed_env.execute_inline('command1 first_argument second_argument')
200
+ .outputs("\nhello\n", to: temp_file.path)
189
201
  end
190
202
 
203
+ execute_script('stubbed_command first_argument second_argument')
204
+
191
205
  it 'outputs the expected content to the file' do
192
- expect(temp_file.read).to eql 'hello'
206
+ expect(temp_file.read).to eql "\nhello\n"
193
207
  end
194
208
  end
195
209
  context 'when given an anything argument match' do
196
- before(:each) do
197
- command1_stub
210
+ before do
211
+ command
198
212
  .with_args('first_argument', anything)
199
213
  .outputs('i respond to anything', to: temp_file.path)
200
- stubbed_env.execute_inline('command1 first_argument second_argument')
201
214
  end
202
215
 
216
+ execute_script('stubbed_command first_argument second_argument')
217
+
203
218
  it 'outputs the expected content to the file' do
204
219
  expect(temp_file.read).to eql 'i respond to anything'
205
220
  end
206
221
  end
207
222
  context 'when given any_args argument match' do
208
- before(:each) do
209
- command1_stub
223
+ before do
224
+ command
210
225
  .with_args(any_args)
211
226
  .outputs('i respond to any_args', to: temp_file.path)
212
- stubbed_env.execute_inline('command1 poglet piglet')
213
227
  end
214
228
 
229
+ execute_script('stubbed_command first_argument poglet')
230
+
215
231
  it 'outputs the expected content to the file' do
216
232
  expect(temp_file.read).to eql 'i respond to any_args'
217
233
  end
218
234
  end
219
235
  context 'when given other types of RSpec::Mock::ArgumentMatcher argument match' do
220
- before(:each) do
221
- command1_stub
236
+ before do
237
+ command
222
238
  .with_args(instance_of(String), instance_of(String))
223
239
  .outputs('i respond to instance_of', to: temp_file.path)
224
- stubbed_env.execute_inline('command1 poglet 1')
225
240
  end
226
241
 
242
+ execute_script('stubbed_command poglet 1')
243
+
227
244
  it 'outputs the expected content to the file' do
228
245
  expect(temp_file.read).to eql 'i respond to instance_of'
229
246
  end
230
247
  end
231
248
  context 'when given regex argument match' do
232
- before(:each) do
233
- command1_stub
249
+ before do
250
+ command
234
251
  .with_args(/p.glet/, /p.glet/)
235
252
  .outputs('i respond to regex', to: temp_file.path)
236
- stubbed_env.execute_inline('command1 poglet piglet')
237
253
  end
238
254
 
255
+ execute_script('stubbed_command poglet piglet')
256
+
239
257
  it 'outputs the expected content to the file' do
240
258
  expect(temp_file.read).to eql 'i respond to regex'
241
259
  end
@@ -243,12 +261,14 @@ describe 'StubbedCommand' do
243
261
 
244
262
  describe 'when given a passed argument for a filename' do
245
263
  let(:dynamic_file) { Pathname.new('output-piglet.txt') }
246
- before(:each) do
247
- command1_stub
264
+
265
+ before do
266
+ command
248
267
  .outputs('i have a dynamic file name', to: ['output-', :arg2, '.txt'])
249
- stubbed_env.execute_inline('command1 poglet piglet')
250
268
  end
251
269
 
270
+ execute_script('stubbed_command poglet piglet')
271
+
252
272
  it 'outputs the expected content to the file' do
253
273
  expect(dynamic_file.read).to eql 'i have a dynamic file name'
254
274
  end