cli_tester 0.0.1 → 0.0.2

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: 96b04015e8e4ba1f7f601ce673e7992c4e0e0921
4
- data.tar.gz: 6734dbd213f3ff50f53c1cb3d17e3c79f8fb0775
3
+ metadata.gz: 4343ab065292f81005f46fe1ace77d94635c8e73
4
+ data.tar.gz: 9e53169eb4c9ba270e3bb27c7d317a30c54fef44
5
5
  SHA512:
6
- metadata.gz: 721c3c34801cc2b0b7862cfc78c510bec00bd228dcd3456b7615bddf4eaca4107067c4b3ffbcf3a8ded3e3be2e2651080ff3c1c19525e9463a68b5699ac02010
7
- data.tar.gz: 5c92c09ffe28f8ea36df8de8e40ed20f596c5d78e79db91a946d917c582e28237327885f8d961530fe2a1767abf2daa9c669a15ea043c78607ee6e39e5b01828
6
+ metadata.gz: d0d9474f66ced81371e030f7cbb2d7cdd57ce003fda3f089fdc1b0b1055bc202bd5867d9401150218158224e6452a5fe050cc63f99e7158889d3ad8109f05648
7
+ data.tar.gz: 61b3fdcf28daf6d1ff70fcbce2a3b128d9899711fae80ce4afd9b64c9ee4b7767af23b0016c7a2cf7844ad8b8402cee3e6b2bc221a29ee8448cc30e458295d87
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/cli_tester.svg)](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
@@ -16,6 +16,10 @@ elsif ARGV == ["list"]
16
16
  elsif ARGV == ["ls"]
17
17
  puts Dir.entries(Dir.pwd).sort
18
18
  exit 0
19
+ elsif ARGV == ["fail"]
20
+ STDERR.puts "failed"
21
+ STDOUT.puts "right"
22
+ exit 1
19
23
  else
20
24
  STDERR.puts "Unrecognized arguments: #{ARGV}"
21
25
  exit 1
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
@@ -1,3 +1,3 @@
1
1
  module CliTester
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.1
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-06-14 00:00:00.000000000 Z
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: