cli_tester 0.0.1 → 0.0.2
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/README.md +2 -0
- data/bin/cli_tester +4 -0
- data/lib/cli_tester.rb +56 -0
- data/lib/version.rb +1 -1
- data/spec/cli_tester_spec.rb +18 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4343ab065292f81005f46fe1ace77d94635c8e73
|
4
|
+
data.tar.gz: 9e53169eb4c9ba270e3bb27c7d317a30c54fef44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0d9474f66ced81371e030f7cbb2d7cdd57ce003fda3f089fdc1b0b1055bc202bd5867d9401150218158224e6452a5fe050cc63f99e7158889d3ad8109f05648
|
7
|
+
data.tar.gz: 61b3fdcf28daf6d1ff70fcbce2a3b128d9899711fae80ce4afd9b64c9ee4b7767af23b0016c7a2cf7844ad8b8402cee3e6b2bc221a29ee8448cc30e458295d87
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](http://badge.fury.io/rb/cli_tester)
|
2
|
+
|
1
3
|
CliTester is a simple set of helpers for testing command line interfaces with
|
2
4
|
RSpec. It provides a method to run command line applications and a way to check
|
3
5
|
the output and exit codes.
|
data/bin/cli_tester
CHANGED
data/lib/cli_tester.rb
CHANGED
@@ -133,3 +133,59 @@ RSpec::Matchers.define :exit_with_success do |expected_stdout, expected_stderr|
|
|
133
133
|
message
|
134
134
|
end
|
135
135
|
end
|
136
|
+
|
137
|
+
RSpec::Matchers.define :exit_with_error do |exit_code, expected_stderr, expected_stdout|
|
138
|
+
match do |result|
|
139
|
+
return false if result.exit_code != exit_code
|
140
|
+
if expected_stderr.is_a?(Regexp)
|
141
|
+
return false if !expected_stderr.match(result.stderr)
|
142
|
+
else
|
143
|
+
return false if expected_stderr != result.stderr
|
144
|
+
end
|
145
|
+
if expected_stdout
|
146
|
+
if expected_stdout.is_a?(Regexp)
|
147
|
+
return false if !expected_stdout.match(result.stdout)
|
148
|
+
else
|
149
|
+
return false if expected_stdout != result.stdout
|
150
|
+
end
|
151
|
+
end
|
152
|
+
true
|
153
|
+
end
|
154
|
+
|
155
|
+
failure_message do |result|
|
156
|
+
message = "ran #{result.cmd}\n"
|
157
|
+
if result.error
|
158
|
+
message += "error message: #{result.error}\n"
|
159
|
+
end
|
160
|
+
if result.exit_code != exit_code
|
161
|
+
message += "expected exit code to be #{exit_code} (was #{result.exit_code})\n"
|
162
|
+
end
|
163
|
+
if expected_stderr.is_a?(Regexp)
|
164
|
+
message += "stderr didn't match #{expected_stderr.inspect}"
|
165
|
+
message += " (was '#{Regexp.escape(result.stderr)}')"
|
166
|
+
else
|
167
|
+
if result.stderr != expected_stderr
|
168
|
+
message += "expected stderr to be '#{Regexp.escape(expected_stderr)}'"
|
169
|
+
message += " (was '#{Regexp.escape(result.stderr)}')"
|
170
|
+
message += "\n\nDiff of stderr:"
|
171
|
+
differ = RSpec::Support::Differ.new(color: true)
|
172
|
+
message += differ.diff(result.stderr, expected_stderr)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
if expected_stdout
|
176
|
+
if expected_stdout.is_a?(Regexp)
|
177
|
+
message += "stdout didn't match #{expected_stdout.inspect}"
|
178
|
+
message += " (was '#{Regexp.escape(result.stdout)}')"
|
179
|
+
else
|
180
|
+
if result.stdout != expected_stdout
|
181
|
+
message += "expected stdout to be '#{Regexp.escape(expected_stdout)}'"
|
182
|
+
message += " (was '#{Regexp.escape(result.stdout)}')"
|
183
|
+
message += "\n\nDiff of stdout:"
|
184
|
+
differ = RSpec::Support::Differ.new(color: true)
|
185
|
+
message += differ.diff(result.stdout, expected_stdout)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
message
|
190
|
+
end
|
191
|
+
end
|
data/lib/version.rb
CHANGED
data/spec/cli_tester_spec.rb
CHANGED
@@ -26,6 +26,10 @@ describe "Command line interface" do
|
|
26
26
|
it "fails with unknown option" do
|
27
27
|
expect(run_command(args: ["--xxx"])).to exit_with_success("", /Unknown/)
|
28
28
|
end
|
29
|
+
|
30
|
+
it "fails with error" do
|
31
|
+
expect(run_command(args: ["fail"])).to exit_with_error(1, "failed\n")
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
describe "list" do
|
@@ -35,6 +39,20 @@ describe "Command line interface" do
|
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
42
|
+
describe "matchers" do
|
43
|
+
describe "exit_with_error" do
|
44
|
+
it "fails when stdout does not match" do
|
45
|
+
expect {
|
46
|
+
expect(run_command(args: ["fail"])).to exit_with_error(1, "failed\n", "wrong")
|
47
|
+
}.to raise_error RSpec::Expectations::ExpectationNotMetError
|
48
|
+
end
|
49
|
+
|
50
|
+
it "passes when stdout does match" do
|
51
|
+
expect(run_command(args: ["fail"])).to exit_with_error(1, "failed\n", "right\n")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
38
56
|
describe "options" do
|
39
57
|
use_given_filesystem
|
40
58
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli_tester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cornelius Schumacher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cheetah
|
@@ -97,3 +97,4 @@ signing_key:
|
|
97
97
|
specification_version: 4
|
98
98
|
summary: RSpec helpers for testing command line interfaces
|
99
99
|
test_files: []
|
100
|
+
has_rdoc:
|