aruba-doubles 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -7
- data/aruba-doubles.gemspec +2 -2
- data/features/environment-friendly.feature +23 -0
- data/features/step_definitions/dev_steps.rb +17 -0
- data/lib/aruba-doubles/api.rb +32 -13
- data/lib/aruba-doubles/cucumber.rb +1 -13
- data/lib/aruba-doubles/hooks.rb +7 -0
- metadata +11 -6
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
1
|
+
Stub command line applications with Cucumber
|
2
2
|
|
3
3
|
## Motivation
|
4
4
|
|
5
|
-
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 `
|
6
|
-
|
7
|
-
Aruba-Double lets you
|
5
|
+
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
|
+
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.)
|
7
|
+
Aruba-Double lets you fake those evil CLI applications by injecting temporary doubles in your system PATH during tests.
|
8
8
|
|
9
|
-
(Note: This little Gem isn't an official part of Aruba but it works as a complement, so they'll play
|
9
|
+
(Note: This little Gem isn't an official part of Aruba but it works as a complement, so they'll play nice together.)
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
@@ -18,13 +18,23 @@ Then, `require` the library in one of your ruby files under `features/support` (
|
|
18
18
|
|
19
19
|
require 'aruba-doubles/cucumber'
|
20
20
|
|
21
|
-
|
21
|
+
Here is an example:
|
22
|
+
|
23
|
+
Scenario: Something went wrong
|
24
|
+
Given a double of "kill_the_cat" with exit status 255 and stderr:
|
25
|
+
"""
|
26
|
+
ERROR: You don't even have a cat!
|
27
|
+
"""
|
28
|
+
When I run `my_fancy_new_script`
|
29
|
+
Then ...
|
30
|
+
|
31
|
+
Take a peek at `features/*.feature` for further examples and at `lib/aruba-doubles/cucumber.rb` for all step definitions.
|
22
32
|
|
23
33
|
## Caveats
|
24
34
|
|
25
35
|
Aruba-Double won't work, if your command...
|
26
36
|
|
27
|
-
* calls other commands with absolute path, i.e. `/usr/local/
|
37
|
+
* calls other commands with absolute path, i.e. `/usr/local/kill_the_cat`
|
28
38
|
* defines its own PATH
|
29
39
|
* calls build-in commands from your shell like `echo` (but who want to stub that)
|
30
40
|
|
data/aruba-doubles.gemspec
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'aruba-doubles'
|
5
|
-
s.version = '0.0.
|
5
|
+
s.version = '0.0.2'
|
6
6
|
s.authors = ["Björn Albers"]
|
7
7
|
s.email = ["bjoernalbers@googlemail.com"]
|
8
|
-
s.description = '
|
8
|
+
s.description = 'Stub command line applications with Cucumber'
|
9
9
|
s.summary = "#{s.name}-#{s.version}"
|
10
10
|
s.homepage = 'https://github.com/bjoernalbers/aruba-doubles'
|
11
11
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Feature: Environment-friendly
|
2
|
+
|
3
|
+
In order to not mess up my system or tests
|
4
|
+
As a developer using Cucumber
|
5
|
+
I want Aruba-Doubles to behave environment-friendly
|
6
|
+
|
7
|
+
Scenario: Create doubles directory only when necessary
|
8
|
+
When I run `ls`
|
9
|
+
Then the doubles directory should not exist
|
10
|
+
|
11
|
+
Scenario: Patch the original path only once
|
12
|
+
Given a double of "ls"
|
13
|
+
And a double of "ls"
|
14
|
+
Then the path should include 1 doubles directory
|
15
|
+
|
16
|
+
Scenario: Create doubles directory...
|
17
|
+
Given a double of "ls"
|
18
|
+
When I keep the doubles directory in mind
|
19
|
+
|
20
|
+
Scenario: ...and check that it was deleted
|
21
|
+
Then the previous doubles directory should not exist
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Then /^the doubles directory should not exist$/ do
|
2
|
+
@doubles_dir.should be_nil
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^the path should include (\d+) doubles directory$/ do |count|
|
6
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).count(@doubles_dir).should eql(count.to_i)
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I keep the doubles directory in mind$/ do
|
10
|
+
@@previous_doubles_dir = @doubles_dir
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^the previous doubles directory should not exist$/ do
|
14
|
+
File.should_not be_exist(@@previous_doubles_dir)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
data/lib/aruba-doubles/api.rb
CHANGED
@@ -1,23 +1,38 @@
|
|
1
1
|
module ArubaDoubles
|
2
2
|
module Api
|
3
|
-
def
|
4
|
-
|
3
|
+
def doubled?
|
4
|
+
!@doubles_dir.nil?
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
7
|
+
def create_double(file, options = {})
|
8
|
+
unless doubled?
|
9
|
+
create_doubles_dir
|
10
|
+
patch_original_path
|
11
|
+
end
|
12
|
+
write_double(file, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_doubles
|
16
|
+
restore_original_path
|
17
|
+
remove_doubles_dir
|
10
18
|
end
|
11
19
|
|
12
|
-
|
13
|
-
|
20
|
+
private
|
21
|
+
|
22
|
+
def create_doubles_dir
|
23
|
+
@doubles_dir = Dir.mktmpdir
|
24
|
+
end
|
25
|
+
|
26
|
+
def patch_original_path
|
27
|
+
@__aruba_doubles_original_path = (ENV['PATH'] || '').split(File::PATH_SEPARATOR)
|
28
|
+
ENV['PATH'] = ([@doubles_dir] + @__aruba_doubles_original_path).join(File::PATH_SEPARATOR)
|
14
29
|
end
|
15
30
|
|
16
|
-
def
|
17
|
-
double = File.expand_path(
|
31
|
+
def write_double(file, options = {})
|
32
|
+
double = File.expand_path(file, @doubles_dir)
|
18
33
|
File.open(double, 'w') do |f|
|
19
34
|
f.puts "#!/usr/bin/env ruby"
|
20
|
-
f.puts "# Doubled command line application by aruba-
|
35
|
+
f.puts "# Doubled command line application by aruba-doubles"
|
21
36
|
f.puts "puts ([File.basename(__FILE__)] + ARGV).join(' ')" if @repeat_arguments
|
22
37
|
f.puts "puts \"#{options[:stdout]}\"" if options[:stdout]
|
23
38
|
f.puts "warn \"#{options[:stderr]}\"" if options[:stderr]
|
@@ -25,9 +40,13 @@ module ArubaDoubles
|
|
25
40
|
end
|
26
41
|
FileUtils.chmod(0755, double)
|
27
42
|
end
|
28
|
-
|
29
|
-
def
|
30
|
-
|
43
|
+
|
44
|
+
def restore_original_path
|
45
|
+
ENV['PATH'] = @__aruba_doubles_original_path.join(File::PATH_SEPARATOR) unless doubled?
|
46
|
+
end
|
47
|
+
|
48
|
+
def remove_doubles_dir
|
49
|
+
FileUtils.rm_r(@doubles_dir) unless @doubles_dir.nil?
|
31
50
|
end
|
32
51
|
end
|
33
52
|
end
|
@@ -1,20 +1,8 @@
|
|
1
|
+
require 'aruba-doubles/hooks'
|
1
2
|
require 'aruba-doubles/api'
|
2
3
|
|
3
4
|
World(ArubaDoubles::Api)
|
4
5
|
|
5
|
-
Before do
|
6
|
-
patch_original_path
|
7
|
-
end
|
8
|
-
|
9
|
-
After do
|
10
|
-
restore_original_path
|
11
|
-
remove_doubles
|
12
|
-
end
|
13
|
-
|
14
|
-
Before('@repeat_arguments') do
|
15
|
-
@repeat_arguments = true
|
16
|
-
end
|
17
|
-
|
18
6
|
Given /^a double of "([^"]*)"$/ do |file|
|
19
7
|
create_double(file)
|
20
8
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aruba-doubles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
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-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: cucumber
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: 0.4.6
|
50
50
|
type: :development
|
51
51
|
version_requirements: *id002
|
52
|
-
description:
|
52
|
+
description: Stub command line applications with Cucumber
|
53
53
|
email:
|
54
54
|
- bjoernalbers@googlemail.com
|
55
55
|
executables: []
|
@@ -66,10 +66,13 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- aruba-doubles.gemspec
|
68
68
|
- features/double_cli_apps.feature
|
69
|
+
- features/environment-friendly.feature
|
70
|
+
- features/step_definitions/dev_steps.rb
|
69
71
|
- features/support/env.rb
|
70
72
|
- lib/aruba-doubles.rb
|
71
73
|
- lib/aruba-doubles/api.rb
|
72
74
|
- lib/aruba-doubles/cucumber.rb
|
75
|
+
- lib/aruba-doubles/hooks.rb
|
73
76
|
homepage: https://github.com/bjoernalbers/aruba-doubles
|
74
77
|
licenses: []
|
75
78
|
|
@@ -102,7 +105,9 @@ rubyforge_project:
|
|
102
105
|
rubygems_version: 1.8.8
|
103
106
|
signing_key:
|
104
107
|
specification_version: 3
|
105
|
-
summary: aruba-doubles-0.0.
|
108
|
+
summary: aruba-doubles-0.0.2
|
106
109
|
test_files:
|
107
110
|
- features/double_cli_apps.feature
|
111
|
+
- features/environment-friendly.feature
|
112
|
+
- features/step_definitions/dev_steps.rb
|
108
113
|
- features/support/env.rb
|