aruba-doubles 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/aruba-doubles.gemspec +20 -0
- data/features/double_cli_apps.feature +87 -0
- data/features/support/env.rb +2 -0
- data/lib/aruba-doubles/api.rb +33 -0
- data/lib/aruba-doubles/cucumber.rb +32 -0
- data/lib/aruba-doubles.rb +1 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Björn Albers
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Double command line applications in your Cucumber features
|
2
|
+
|
3
|
+
## Motivation
|
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 `kill_a_random_cat` or `launch_nukes`... Don't do that in your tests!).
|
6
|
+
Stubbing and mocking in your Cucumber features is usually not recommended (in order to test "the full stack"), but in some cases it could make your life easier (Your cat will thank you later.)
|
7
|
+
Aruba-Double lets you stub out those evil commands in your scenarios by injecting temporary doubles in your system (it will hijack your PATH during tests).
|
8
|
+
|
9
|
+
(Note: This little Gem isn't an official part of Aruba but it works as a complement, so they'll play hopefully nicely together.)
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
If you have a `Gemfile`, add `aruba-doubles`. Otherwise, install it like this:
|
14
|
+
|
15
|
+
gem install aruba-doubles
|
16
|
+
|
17
|
+
Then, `require` the library in one of your ruby files under `features/support` (e.g. `env.rb`)
|
18
|
+
|
19
|
+
require 'aruba-doubles/cucumber'
|
20
|
+
|
21
|
+
Take a peek at `features/*.feature` for some examples and look in `lib/aruba-doubles/cucumber.rb` for all step definitions.
|
22
|
+
|
23
|
+
## Caveats
|
24
|
+
|
25
|
+
Aruba-Double won't work, if your command...
|
26
|
+
|
27
|
+
* calls other commands with absolute path, i.e. `/usr/local/kill_a_random_cat`
|
28
|
+
* defines its own PATH
|
29
|
+
* calls build-in commands from your shell like `echo` (but who want to stub that)
|
30
|
+
|
31
|
+
Also note that doubles will be created as scripts in temporary directories on your filesystem, which might slow down your tests.
|
32
|
+
|
33
|
+
## Note on Patches/Pull Requests
|
34
|
+
|
35
|
+
* Fork the project.
|
36
|
+
* Make your feature addition or bug fix.
|
37
|
+
* Add tests for it. This is important so I don't break it in a
|
38
|
+
future version unintentionally. Note: the existing tests may fail
|
39
|
+
* Commit, do not mess with Rakefile, gemspec or History.
|
40
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
41
|
+
* Send me a pull request. Bonus points for topic branches.
|
42
|
+
|
43
|
+
## Copyright
|
44
|
+
|
45
|
+
Copyright (c) 2011 Björn Albers. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'aruba-doubles'
|
5
|
+
s.version = '0.0.1'
|
6
|
+
s.authors = ["Björn Albers"]
|
7
|
+
s.email = ["bjoernalbers@googlemail.com"]
|
8
|
+
s.description = 'Double command line applications in your Cucumber features'
|
9
|
+
s.summary = "#{s.name}-#{s.version}"
|
10
|
+
s.homepage = 'https://github.com/bjoernalbers/aruba-doubles'
|
11
|
+
|
12
|
+
s.add_dependency 'cucumber', '>= 1.0.2'
|
13
|
+
|
14
|
+
s.add_development_dependency 'aruba', '>= 0.4.6'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
Feature: Double command line applications
|
2
|
+
|
3
|
+
In order to double command line applications
|
4
|
+
As a developer using Cucumber
|
5
|
+
I want to use the "double of" steps
|
6
|
+
|
7
|
+
Scenario: Double default behaviour
|
8
|
+
Given a double of "ls"
|
9
|
+
When I run `ls -la`
|
10
|
+
Then the exit status should be 0
|
11
|
+
And the stdout should contain exactly:
|
12
|
+
"""
|
13
|
+
"""
|
14
|
+
And the stderr should contain exactly:
|
15
|
+
"""
|
16
|
+
"""
|
17
|
+
|
18
|
+
Scenario: Double with stdout
|
19
|
+
Given a double of "ls" with stdout:
|
20
|
+
"""
|
21
|
+
hello, world.
|
22
|
+
"""
|
23
|
+
When I successfully run `ls -la`
|
24
|
+
Then the stdout should contain exactly:
|
25
|
+
"""
|
26
|
+
hello, world.
|
27
|
+
|
28
|
+
"""
|
29
|
+
And the stderr should contain exactly:
|
30
|
+
"""
|
31
|
+
"""
|
32
|
+
|
33
|
+
Scenario: Double with stderr
|
34
|
+
Given a double of "ls" with stderr:
|
35
|
+
"""
|
36
|
+
error: something crashed!
|
37
|
+
"""
|
38
|
+
When I successfully run `ls -la`
|
39
|
+
And the stdout should contain exactly:
|
40
|
+
"""
|
41
|
+
"""
|
42
|
+
Then the stderr should contain exactly:
|
43
|
+
"""
|
44
|
+
error: something crashed!
|
45
|
+
|
46
|
+
"""
|
47
|
+
|
48
|
+
Scenario: Double with exit status
|
49
|
+
Given a double of "ls" with exit status 255
|
50
|
+
When I run `ls -la`
|
51
|
+
Then the exit status should be 255
|
52
|
+
And the stdout should contain exactly:
|
53
|
+
"""
|
54
|
+
"""
|
55
|
+
And the stderr should contain exactly:
|
56
|
+
"""
|
57
|
+
"""
|
58
|
+
|
59
|
+
Scenario: Double with exit status and stdout
|
60
|
+
Given a double of "ls" with exit status 255 and stdout:
|
61
|
+
"""
|
62
|
+
hello, world.
|
63
|
+
"""
|
64
|
+
When I run `ls -la`
|
65
|
+
Then the exit status should be 255
|
66
|
+
And the stdout should contain exactly:
|
67
|
+
"""
|
68
|
+
hello, world.
|
69
|
+
|
70
|
+
"""
|
71
|
+
And the stderr should contain exactly:
|
72
|
+
"""
|
73
|
+
"""
|
74
|
+
|
75
|
+
@repeat_arguments
|
76
|
+
Scenario: Double with repeating arguments
|
77
|
+
Given a double of "ls"
|
78
|
+
When I run `ls -la`
|
79
|
+
Then the stdout should contain exactly:
|
80
|
+
"""
|
81
|
+
ls -la
|
82
|
+
|
83
|
+
"""
|
84
|
+
And the stderr should contain exactly:
|
85
|
+
"""
|
86
|
+
"""
|
87
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ArubaDoubles
|
2
|
+
module Api
|
3
|
+
def doubles_dir
|
4
|
+
@doubles_dir ||= Dir.mktmpdir
|
5
|
+
end
|
6
|
+
|
7
|
+
def patch_original_path
|
8
|
+
@__aruba_doubles_original_path = (ENV['PATH'] || '').split(File::PATH_SEPARATOR)
|
9
|
+
ENV['PATH'] = ([doubles_dir] + @__aruba_doubles_original_path).join(File::PATH_SEPARATOR)
|
10
|
+
end
|
11
|
+
|
12
|
+
def restore_original_path
|
13
|
+
ENV['PATH'] = @__aruba_doubles_original_path.join(File::PATH_SEPARATOR)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_double(filename, options = {})
|
17
|
+
double = File.expand_path(filename, doubles_dir)
|
18
|
+
File.open(double, 'w') do |f|
|
19
|
+
f.puts "#!/usr/bin/env ruby"
|
20
|
+
f.puts "# Doubled command line application by aruba-double"
|
21
|
+
f.puts "puts ([File.basename(__FILE__)] + ARGV).join(' ')" if @repeat_arguments
|
22
|
+
f.puts "puts \"#{options[:stdout]}\"" if options[:stdout]
|
23
|
+
f.puts "warn \"#{options[:stderr]}\"" if options[:stderr]
|
24
|
+
f.puts "exit(#{options[:exit_status]})" if options[:exit_status]
|
25
|
+
end
|
26
|
+
FileUtils.chmod(0755, double)
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_doubles
|
30
|
+
FileUtils.rm_r(doubles_dir) if File.directory?(doubles_dir)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'aruba-doubles/api'
|
2
|
+
|
3
|
+
World(ArubaDoubles::Api)
|
4
|
+
|
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
|
+
Given /^a double of "([^"]*)"$/ do |file|
|
19
|
+
create_double(file)
|
20
|
+
end
|
21
|
+
|
22
|
+
Given /^a double of "([^"]*)" with (stdout|stderr):$/ do |file, stdout_stderr, output|
|
23
|
+
create_double(file, stdout_stderr.to_sym => output)
|
24
|
+
end
|
25
|
+
|
26
|
+
Given /^a double of "([^"]*)" with exit status (\d+)$/ do |file, exit|
|
27
|
+
create_double(file, :exit_status => exit.to_i)
|
28
|
+
end
|
29
|
+
|
30
|
+
Given /^a double of "([^"]*)" with exit status (\d+) and (stdout|stderr):$/ do |file, exit, stdout_stderr, output|
|
31
|
+
create_double(file, :exit_status => exit.to_i, stdout_stderr.to_sym => output)
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Load nothing - just keep the file here to keep bundler happy.
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aruba-doubles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Bj\xC3\xB6rn Albers"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-14 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: cucumber
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 19
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
version: 1.0.2
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: aruba
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 4
|
48
|
+
- 6
|
49
|
+
version: 0.4.6
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: Double command line applications in your Cucumber features
|
53
|
+
email:
|
54
|
+
- bjoernalbers@googlemail.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- aruba-doubles.gemspec
|
68
|
+
- features/double_cli_apps.feature
|
69
|
+
- features/support/env.rb
|
70
|
+
- lib/aruba-doubles.rb
|
71
|
+
- lib/aruba-doubles/api.rb
|
72
|
+
- lib/aruba-doubles/cucumber.rb
|
73
|
+
homepage: https://github.com/bjoernalbers/aruba-doubles
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.8
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: aruba-doubles-0.0.1
|
106
|
+
test_files:
|
107
|
+
- features/double_cli_apps.feature
|
108
|
+
- features/support/env.rb
|