rspec-bash 0.1.1 → 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 +4 -4
- data/.rubocop.yml +8 -0
- data/Gemfile +1 -0
- data/README.md +23 -0
- data/Rakefile +15 -4
- data/bin/bash_stub.sh +92 -0
- data/bin/bash_wrapper.sh.erb +12 -0
- data/bin/ruby_stub.rb +33 -0
- data/lib/rspec/bash.rb +5 -4
- data/lib/rspec/bash/command.rb +5 -0
- data/lib/rspec/bash/command/call_configuration.rb +76 -0
- data/lib/rspec/bash/command/call_configuration_manager.rb +24 -0
- data/lib/rspec/bash/command/call_log.rb +48 -0
- data/lib/rspec/bash/command/call_log_manager.rb +38 -0
- data/lib/rspec/bash/command/stubbed_command.rb +64 -0
- data/lib/rspec/bash/server.rb +3 -0
- data/lib/rspec/bash/server/bash_stub_marshaller.rb +19 -0
- data/lib/rspec/bash/server/ruby_stub_marshaller.rb +13 -0
- data/lib/rspec/bash/server/stub_server.rb +47 -0
- data/lib/rspec/bash/stubbed_env.rb +75 -54
- data/lib/rspec/bash/util/call_conf_argument_list_matcher.rb +5 -5
- data/lib/rspec/bash/util/call_log_argument_list_matcher.rb +1 -1
- data/lib/rspec/bash/wrapper.rb +4 -0
- data/lib/rspec/bash/wrapper/bash_stub_script.rb +15 -0
- data/lib/rspec/bash/wrapper/bash_wrapper.rb +54 -0
- data/lib/rspec/bash/wrapper/ruby_stub_script.rb +15 -0
- data/lib/rspec/bash/wrapper/stub_function.rb +36 -0
- data/rspec-bash.gemspec +2 -1
- data/spec/classes/command/call_configuration_manager_spec.rb +68 -0
- data/spec/classes/{call_configuration_spec.rb → command/call_configuration_spec.rb} +51 -114
- data/spec/classes/command/call_log_manager_spec.rb +83 -0
- data/spec/classes/{call_log_spec.rb → command/call_log_spec.rb} +23 -82
- data/spec/classes/command/stubbed_command_spec.rb +118 -0
- data/spec/classes/server/bash_stub_marshaller_spec.rb +38 -0
- data/spec/classes/server/ruby_stub_marshaller_spec.rb +31 -0
- data/spec/classes/server/stub_server_spec.rb +121 -0
- data/spec/classes/stubbed_env_spec.rb +141 -280
- data/spec/classes/util/call_conf_argument_list_matcher_spec.rb +17 -17
- data/spec/classes/util/call_log_argument_list_matcher_spec.rb +24 -18
- data/spec/classes/wrapper/bash_wrapper_spec.rb +37 -0
- data/spec/classes/wrapper/ruby_stub_script_spec.rb +204 -0
- data/spec/helper/string_file_io.rb +1 -1
- data/spec/integration/call_log/called_with_args_spec.rb +8 -4
- data/spec/integration/call_log/called_with_no_args_spec.rb +1 -1
- data/spec/integration/call_log/stdin_spec.rb +10 -4
- data/spec/integration/edge_cases_spec.rb +34 -0
- data/spec/integration/matchers/be_called_with_arguments_spec.rb +12 -13
- data/spec/integration/matchers/be_called_with_no_arguments_spec.rb +6 -7
- data/spec/integration/stubbed_command/outputs_spec.rb +111 -91
- data/spec/integration/stubbed_command/returns_exitstatus_spec.rb +46 -37
- data/spec/integration/stubbed_env/execute_with_env_vars_spec.rb +3 -4
- data/spec/integration/stubbed_env/execute_with_path_spec.rb +6 -7
- data/spec/integration/stubbed_env/execute_with_stub_wrapper_spec.rb +4 -12
- data/spec/integration/stubbed_env/override_spec.rb +354 -0
- data/spec/integration/wrapper/bash_stub_script_spec.rb +383 -0
- data/spec/integration/wrapper/bash_wrapper_spec.rb +48 -0
- data/spec/scripts/function_library.sh +9 -1
- data/spec/spec_helper.rb +2 -0
- metadata +65 -21
- data/bin/function_override.sh.erb +0 -7
- data/bin/function_override_wrapper.sh.erb +0 -19
- data/bin/stub.rb.erb +0 -56
- data/lib/rspec/bash/call_configuration.rb +0 -62
- data/lib/rspec/bash/call_log.rb +0 -71
- data/lib/rspec/bash/stubbed_command.rb +0 -88
- data/spec/classes/stub_spec.rb +0 -510
- data/spec/classes/stubbed_command_spec.rb +0 -134
- data/spec/integration/assert_called_spec.rb +0 -0
@@ -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 -
|
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
|
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
|
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
|
-
|
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(
|
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(
|
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(
|
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(
|
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
|
-
|
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(
|
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(
|
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(
|
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(
|
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
|
-
|
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(
|
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
|
-
|
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(
|
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!(:
|
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
|
-
|
12
|
-
|
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(
|
30
|
+
expect(stdout).to eql "\nhello\n"
|
20
31
|
end
|
21
32
|
end
|
22
33
|
context 'when given an exact argument match' do
|
23
|
-
|
24
|
-
|
34
|
+
before do
|
35
|
+
command
|
25
36
|
.with_args('first_argument', 'second_argument')
|
26
|
-
.outputs(
|
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(
|
43
|
+
expect(stdout).to eql "\nhello\n"
|
33
44
|
end
|
34
45
|
end
|
35
46
|
context 'when given an anything argument match' do
|
36
|
-
|
37
|
-
|
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(
|
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
|
-
|
50
|
-
|
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(
|
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
|
-
|
63
|
-
|
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(
|
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
|
-
|
76
|
-
|
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(
|
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
|
-
|
93
|
-
|
94
|
-
.outputs(
|
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(
|
111
|
+
expect(stderr).to eql "\nhello\n"
|
101
112
|
end
|
102
113
|
end
|
103
114
|
context 'when given an exact argument match' do
|
104
|
-
|
105
|
-
|
115
|
+
before do
|
116
|
+
command
|
106
117
|
.with_args('first_argument', 'second_argument')
|
107
|
-
.outputs(
|
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(
|
124
|
+
expect(stderr).to eql "\nhello\n"
|
114
125
|
end
|
115
126
|
end
|
116
127
|
context 'when given an anything argument match' do
|
117
|
-
|
118
|
-
|
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(
|
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
|
-
|
131
|
-
|
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(
|
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
|
-
|
144
|
-
|
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(
|
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
|
-
|
157
|
-
|
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(
|
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
|
174
|
-
|
175
|
-
.outputs(
|
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
|
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
|
185
|
-
|
197
|
+
before do
|
198
|
+
command
|
186
199
|
.with_args('first_argument', 'second_argument')
|
187
|
-
.outputs(
|
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
|
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
|
197
|
-
|
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
|
209
|
-
|
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
|
221
|
-
|
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
|
233
|
-
|
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
|
-
|
247
|
-
|
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
|