aruba-doubles 0.0.2 → 0.1.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.
- data/README.md +21 -4
- data/Rakefile +1 -2
- data/aruba-doubles.gemspec +1 -1
- data/features/double_cli_apps.feature +31 -14
- data/lib/aruba-doubles/api.rb +10 -3
- data/lib/aruba-doubles/hooks.rb +1 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# Aruba-Doubles
|
2
2
|
|
3
|
-
|
3
|
+
Stub and mock command line applications with Cucumber
|
4
|
+
|
5
|
+
## Introduction
|
4
6
|
|
5
7
|
Let's say you develop a command line application ([BDD](http://en.wikipedia.org/wiki/Behavior_Driven_Development)-style with [Cucumber](http://cukes.info/) and [Aruba](https://github.com/cucumber/aruba)) which itself relys on other CLI stuff that makes testing harder (i.e. it calls under certain conditions `kill_the_cat`... Don't do that in your tests!).
|
6
8
|
Mocking and stubbing with Cucumber is usually [not recommended](https://github.com/cucumber/cucumber/wiki/Mocking-and-Stubbing-with-Cucumber) and tricky because we have do do it across processes but in some cases it could make your life easier (Your cat will thank you later.)
|
@@ -18,15 +20,30 @@ Then, `require` the library in one of your ruby files under `features/support` (
|
|
18
20
|
|
19
21
|
require 'aruba-doubles/cucumber'
|
20
22
|
|
21
|
-
Here
|
23
|
+
Here are some examples:
|
22
24
|
|
23
|
-
Scenario:
|
25
|
+
Scenario: Stubbing with exit code and stderr
|
24
26
|
Given a double of "kill_the_cat" with exit status 255 and stderr:
|
25
27
|
"""
|
26
28
|
ERROR: You don't even have a cat!
|
27
29
|
"""
|
28
30
|
When I run `my_fancy_new_script`
|
29
31
|
Then ...
|
32
|
+
|
33
|
+
Scenario: Mocking
|
34
|
+
Given a double of "kill_the_cat --gently" with stdout:
|
35
|
+
"""
|
36
|
+
R.I.P.
|
37
|
+
"""
|
38
|
+
When I run `kill_the_cat`
|
39
|
+
Then the stdout should contain exactly:
|
40
|
+
"""
|
41
|
+
"""
|
42
|
+
And the stderr should contain exactly:
|
43
|
+
"""
|
44
|
+
expected: kill_the_cat --gently
|
45
|
+
got: kill_the_cat
|
46
|
+
"""
|
30
47
|
|
31
48
|
Take a peek at `features/*.feature` for further examples and at `lib/aruba-doubles/cucumber.rb` for all step definitions.
|
32
49
|
|
data/Rakefile
CHANGED
data/aruba-doubles.gemspec
CHANGED
@@ -5,8 +5,8 @@ Feature: Double command line applications
|
|
5
5
|
I want to use the "double of" steps
|
6
6
|
|
7
7
|
Scenario: Double default behaviour
|
8
|
-
Given a double of "
|
9
|
-
When I run `
|
8
|
+
Given a double of "foo"
|
9
|
+
When I run `foo`
|
10
10
|
Then the exit status should be 0
|
11
11
|
And the stdout should contain exactly:
|
12
12
|
"""
|
@@ -16,11 +16,11 @@ Feature: Double command line applications
|
|
16
16
|
"""
|
17
17
|
|
18
18
|
Scenario: Double with stdout
|
19
|
-
Given a double of "
|
19
|
+
Given a double of "foo" with stdout:
|
20
20
|
"""
|
21
21
|
hello, world.
|
22
22
|
"""
|
23
|
-
When I successfully run `
|
23
|
+
When I successfully run `foo`
|
24
24
|
Then the stdout should contain exactly:
|
25
25
|
"""
|
26
26
|
hello, world.
|
@@ -31,11 +31,11 @@ Feature: Double command line applications
|
|
31
31
|
"""
|
32
32
|
|
33
33
|
Scenario: Double with stderr
|
34
|
-
Given a double of "
|
34
|
+
Given a double of "foo" with stderr:
|
35
35
|
"""
|
36
36
|
error: something crashed!
|
37
37
|
"""
|
38
|
-
When I successfully run `
|
38
|
+
When I successfully run `foo`
|
39
39
|
And the stdout should contain exactly:
|
40
40
|
"""
|
41
41
|
"""
|
@@ -46,8 +46,8 @@ Feature: Double command line applications
|
|
46
46
|
"""
|
47
47
|
|
48
48
|
Scenario: Double with exit status
|
49
|
-
Given a double of "
|
50
|
-
When I run `
|
49
|
+
Given a double of "foo" with exit status 255
|
50
|
+
When I run `foo`
|
51
51
|
Then the exit status should be 255
|
52
52
|
And the stdout should contain exactly:
|
53
53
|
"""
|
@@ -57,11 +57,11 @@ Feature: Double command line applications
|
|
57
57
|
"""
|
58
58
|
|
59
59
|
Scenario: Double with exit status and stdout
|
60
|
-
Given a double of "
|
60
|
+
Given a double of "foo" with exit status 255 and stdout:
|
61
61
|
"""
|
62
62
|
hello, world.
|
63
63
|
"""
|
64
|
-
When I run `
|
64
|
+
When I run `foo`
|
65
65
|
Then the exit status should be 255
|
66
66
|
And the stdout should contain exactly:
|
67
67
|
"""
|
@@ -72,16 +72,33 @@ Feature: Double command line applications
|
|
72
72
|
"""
|
73
73
|
"""
|
74
74
|
|
75
|
+
Scenario: Double with expected arguments
|
76
|
+
Given a double of "ls --la" with stdout:
|
77
|
+
"""
|
78
|
+
hello, world.
|
79
|
+
"""
|
80
|
+
When I run `ls`
|
81
|
+
Then the exit status should not be 0
|
82
|
+
And the stdout should contain exactly:
|
83
|
+
"""
|
84
|
+
"""
|
85
|
+
And the stderr should contain exactly:
|
86
|
+
"""
|
87
|
+
expected: ls --la
|
88
|
+
got: ls
|
89
|
+
|
90
|
+
"""
|
91
|
+
|
92
|
+
|
75
93
|
@repeat_arguments
|
76
94
|
Scenario: Double with repeating arguments
|
77
|
-
Given a double of "
|
78
|
-
When I run `
|
95
|
+
Given a double of "foo"
|
96
|
+
When I run `foo`
|
79
97
|
Then the stdout should contain exactly:
|
80
98
|
"""
|
81
|
-
|
99
|
+
foo
|
82
100
|
|
83
101
|
"""
|
84
102
|
And the stderr should contain exactly:
|
85
103
|
"""
|
86
104
|
"""
|
87
|
-
|
data/lib/aruba-doubles/api.rb
CHANGED
@@ -28,11 +28,18 @@ module ArubaDoubles
|
|
28
28
|
ENV['PATH'] = ([@doubles_dir] + @__aruba_doubles_original_path).join(File::PATH_SEPARATOR)
|
29
29
|
end
|
30
30
|
|
31
|
-
def write_double(
|
32
|
-
|
31
|
+
def write_double(command_line, options = {})
|
32
|
+
args = command_line.split
|
33
|
+
filename = args.shift
|
34
|
+
double = File.expand_path(filename, @doubles_dir)
|
33
35
|
File.open(double, 'w') do |f|
|
34
36
|
f.puts "#!/usr/bin/env ruby"
|
35
|
-
f.puts "# Doubled command line application by aruba-doubles"
|
37
|
+
f.puts "# Doubled command line application by aruba-doubles\n"
|
38
|
+
f.puts "unless ARGV.to_s == \"#{args}\""
|
39
|
+
f.puts " warn \"expected: #{filename} #{args}\""
|
40
|
+
f.puts " warn \" got: #{filename} \#{ARGV}\""
|
41
|
+
f.puts " exit(1)"
|
42
|
+
f.puts "end"
|
36
43
|
f.puts "puts ([File.basename(__FILE__)] + ARGV).join(' ')" if @repeat_arguments
|
37
44
|
f.puts "puts \"#{options[:stdout]}\"" if options[:stdout]
|
38
45
|
f.puts "warn \"#{options[:stderr]}\"" if options[:stderr]
|
data/lib/aruba-doubles/hooks.rb
CHANGED
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Bj\xC3\xB6rn Albers"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-21 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: cucumber
|
@@ -105,7 +105,7 @@ rubyforge_project:
|
|
105
105
|
rubygems_version: 1.8.8
|
106
106
|
signing_key:
|
107
107
|
specification_version: 3
|
108
|
-
summary: aruba-doubles-0.0
|
108
|
+
summary: aruba-doubles-0.1.0
|
109
109
|
test_files:
|
110
110
|
- features/double_cli_apps.feature
|
111
111
|
- features/environment-friendly.feature
|