aruba-doubles 0.1.1 → 0.2.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/Guardfile +15 -0
- data/README.md +44 -28
- data/Rakefile +6 -0
- data/aruba-doubles.gemspec +3 -1
- data/features/double.feature +85 -0
- data/features/environment-friendly.feature +3 -3
- data/features/step_definitions/dev_steps.rb +8 -0
- data/lib/aruba-doubles/api.rb +35 -23
- data/lib/aruba-doubles/cucumber.rb +8 -8
- data/lib/aruba-doubles/double.rb +23 -0
- data/lib/aruba-doubles/hooks.rb +0 -5
- data/spec/aruba-doubles/double_spec.rb +98 -0
- data/spec/spec_helper.rb +1 -0
- metadata +46 -8
- data/features/double_cli_apps.feature +0 -104
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2, :cli => '--color' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'cucumber' do
|
11
|
+
watch(%r{^lib/.+$}) { 'features' }
|
12
|
+
watch(%r{^features/.+\.feature$})
|
13
|
+
watch(%r{^features/support/.+$}) { 'features' }
|
14
|
+
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
|
15
|
+
end
|
data/README.md
CHANGED
@@ -4,11 +4,11 @@ Stub and mock command line applications with Cucumber
|
|
4
4
|
|
5
5
|
## Introduction
|
6
6
|
|
7
|
-
|
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
|
9
|
-
Aruba-
|
7
|
+
Developing a command line application in proper [BDD](http://en.wikipedia.org/wiki/Behavior_Driven_Development)-style with [Cucumber](http://cukes.info/) and [Aruba](https://github.com/cucumber/aruba) can be cumbersome, when your application depends on other CLI stuff (i.e. calling under certain conditions `kill_the_cat`).
|
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!)
|
9
|
+
Aruba-Doubles are some convenient Cucumber steps to fake CLI applications during your tests (by injecting temporary doubles in front of your PATH).
|
10
10
|
|
11
|
-
(Note:
|
11
|
+
(Note: Aruba-Doubles is not an official part of Aruba but a good companion in the same domain, hence the name.)
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
@@ -20,33 +20,46 @@ Then, `require` the library in one of your ruby files under `features/support` (
|
|
20
20
|
|
21
21
|
require 'aruba-doubles/cucumber'
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
23
|
+
### Stubbing
|
24
|
+
|
25
|
+
You can stub commands by using the `I could run` steps:
|
26
|
+
|
27
|
+
Background:
|
28
|
+
Given I could run `kill_the_cat` with stdout:
|
29
|
+
"""
|
30
|
+
R.I.P.
|
31
|
+
"""
|
32
|
+
|
33
|
+
Scenario: Call stubbed command
|
34
|
+
When I run `kill_the_cat`
|
35
|
+
Then the exit status should be 0
|
36
|
+
And the stdout should contain "R.I.P."
|
37
|
+
And the stderr should be empty
|
38
|
+
|
39
|
+
Scenario: Call stubbed command with unexpected argument
|
40
|
+
When I run `kill_the_cat --force`
|
41
|
+
Then the exit status should not be 0
|
42
|
+
And the stdout should be empty
|
43
|
+
And the stderr should contain "--force"
|
44
|
+
|
45
|
+
Scenario: Add expected arguments to stub
|
46
|
+
And I could run `kill_the_cat --gently` with exit status 255 and stderr:
|
47
|
+
"""
|
48
|
+
ERROR: Unable to kill gently... with a chainsaw!
|
49
|
+
"""
|
50
|
+
When I run `kill_the_cat`
|
51
|
+
Then the stdout should contain "R.I.P."
|
52
|
+
And the stderr should be empty
|
53
|
+
When I run `kill_the_cat --gently`
|
54
|
+
Then the stdout should be empty
|
55
|
+
And the stderr should contain "ERROR: Unable to kill gently..."
|
47
56
|
|
48
57
|
Take a peek at `features/*.feature` for further examples and at `lib/aruba-doubles/cucumber.rb` for all step definitions.
|
49
58
|
|
59
|
+
### Mocking
|
60
|
+
|
61
|
+
Currently you can't check if a double was called at all, but hopefully this will be a feature in the future (patches are welcome!).
|
62
|
+
|
50
63
|
## Caveats
|
51
64
|
|
52
65
|
Aruba-Double won't work, if your command...
|
@@ -55,6 +68,9 @@ Aruba-Double won't work, if your command...
|
|
55
68
|
* defines its own PATH
|
56
69
|
* calls build-in commands from your shell like `echo` (but who want to stub that)
|
57
70
|
|
71
|
+
Of course you'll only see stdout and sterr from doubles if these aren't silenced by the calling command (like redirecting to /dev/null.)
|
72
|
+
Keep that in mind when you want to compare expected and acutal arguments.
|
73
|
+
|
58
74
|
Also note that doubles will be created as scripts in temporary directories on your filesystem, which might slow down your tests.
|
59
75
|
|
60
76
|
## Note on Patches/Pull Requests
|
data/Rakefile
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'cucumber/rake/task'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
5
|
Cucumber::Rake::Task.new(:features) do |t|
|
5
6
|
t.cucumber_opts = "--format pretty"
|
6
7
|
end
|
7
8
|
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
t.rspec_opts = %w[--color]
|
11
|
+
t.pattern = "./spec/**/*_spec.rb"
|
12
|
+
end
|
13
|
+
|
8
14
|
task :default => :features
|
data/aruba-doubles.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'aruba-doubles'
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '0.2.0'
|
6
6
|
s.authors = ["Björn Albers"]
|
7
7
|
s.email = ["bjoernalbers@googlemail.com"]
|
8
8
|
s.description = 'Stub command line applications with Cucumber'
|
@@ -12,6 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.add_dependency 'cucumber', '>= 1.0.2'
|
13
13
|
|
14
14
|
s.add_development_dependency 'aruba', '>= 0.4.6'
|
15
|
+
s.add_development_dependency 'guard-cucumber', '>= 0.7.3'
|
16
|
+
s.add_development_dependency 'guard-rspec', '>= 0.5.1'
|
15
17
|
|
16
18
|
s.files = `git ls-files`.split("\n")
|
17
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -0,0 +1,85 @@
|
|
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 "I could run" steps
|
6
|
+
|
7
|
+
Scenario: Stub with default stdout, stderr and exit status
|
8
|
+
Given I could run `foo`
|
9
|
+
When I successfully run `foo`
|
10
|
+
Then the stdout should be empty
|
11
|
+
And the stderr should be empty
|
12
|
+
|
13
|
+
Scenario: Stub stdout
|
14
|
+
Given I could run `foo` with stdout:
|
15
|
+
"""
|
16
|
+
hello, world.
|
17
|
+
"""
|
18
|
+
When I successfully run `foo`
|
19
|
+
Then the stdout should contain exactly:
|
20
|
+
"""
|
21
|
+
hello, world.
|
22
|
+
|
23
|
+
"""
|
24
|
+
And the stderr should be empty
|
25
|
+
|
26
|
+
Scenario: Stub stderr
|
27
|
+
Given I could run `foo` with stderr:
|
28
|
+
"""
|
29
|
+
error: something crashed!
|
30
|
+
"""
|
31
|
+
When I successfully run `foo`
|
32
|
+
And the stdout should be empty
|
33
|
+
Then the stderr should contain exactly:
|
34
|
+
"""
|
35
|
+
error: something crashed!
|
36
|
+
|
37
|
+
"""
|
38
|
+
|
39
|
+
Scenario: Stub exit status
|
40
|
+
Given I could run `foo` with exit status 255
|
41
|
+
When I run `foo`
|
42
|
+
Then the exit status should be 255
|
43
|
+
And the stdout should be empty
|
44
|
+
And the stderr should be empty
|
45
|
+
|
46
|
+
Scenario: Stub exit status and stdout
|
47
|
+
Given I could run `foo` with exit status 255 and stdout:
|
48
|
+
"""
|
49
|
+
hello, world.
|
50
|
+
"""
|
51
|
+
When I run `foo`
|
52
|
+
Then the exit status should be 255
|
53
|
+
And the stdout should contain exactly:
|
54
|
+
"""
|
55
|
+
hello, world.
|
56
|
+
|
57
|
+
"""
|
58
|
+
And the stderr should be empty
|
59
|
+
|
60
|
+
Scenario: Run with unexpected arguments
|
61
|
+
Given I could run `foo --bar` with stdout:
|
62
|
+
"""
|
63
|
+
hello, world.
|
64
|
+
"""
|
65
|
+
When I run `foo --baz`
|
66
|
+
Then the exit status should not be 0
|
67
|
+
And the stdout should be empty
|
68
|
+
And the stderr should contain "Unexpected arguments"
|
69
|
+
|
70
|
+
Scenario: Stub multiple calls
|
71
|
+
Given I could run `foo --bar` with stdout:
|
72
|
+
"""
|
73
|
+
hello, bar.
|
74
|
+
"""
|
75
|
+
And I could run `foo --baz` with stdout:
|
76
|
+
"""
|
77
|
+
hello, baz.
|
78
|
+
"""
|
79
|
+
When I successfully run `foo --bar`
|
80
|
+
And the stdout should contain "hello, bar."
|
81
|
+
And the stdout should not contain "hello, baz."
|
82
|
+
And the stderr should be empty
|
83
|
+
When I successfully run `foo --baz`
|
84
|
+
And the stdout should contain "hello, baz."
|
85
|
+
And the stderr should be empty
|
@@ -9,12 +9,12 @@ Feature: Environment-friendly
|
|
9
9
|
Then the doubles directory should not exist
|
10
10
|
|
11
11
|
Scenario: Patch the original path only once
|
12
|
-
Given
|
13
|
-
And
|
12
|
+
Given I could run `ls`
|
13
|
+
And I could run `ls`
|
14
14
|
Then the path should include 1 doubles directory
|
15
15
|
|
16
16
|
Scenario: Create doubles directory...
|
17
|
-
Given
|
17
|
+
Given I could run `ls`
|
18
18
|
When I keep the doubles directory in mind
|
19
19
|
|
20
20
|
Scenario: ...and check that it was deleted
|
@@ -14,4 +14,12 @@ Then /^the previous doubles directory should not exist$/ do
|
|
14
14
|
File.should_not be_exist(@@previous_doubles_dir)
|
15
15
|
end
|
16
16
|
|
17
|
+
Then /^the (stdout|stderr) should be empty$/ do |stdout_stderr|
|
18
|
+
steps %Q{
|
19
|
+
Then the #{stdout_stderr} should contain exactly:
|
20
|
+
"""
|
21
|
+
"""
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
17
25
|
|
data/lib/aruba-doubles/api.rb
CHANGED
@@ -1,17 +1,40 @@
|
|
1
|
+
require 'aruba-doubles/double'
|
2
|
+
|
1
3
|
module ArubaDoubles
|
2
4
|
module Api
|
3
5
|
def doubled?
|
4
6
|
!@doubles_dir.nil?
|
5
7
|
end
|
6
8
|
|
7
|
-
def
|
9
|
+
def create_double_by_cmd(cmd, options = {})
|
10
|
+
filename = cmd.split.first
|
11
|
+
arguments = cmd.split[1..-1]
|
12
|
+
create_double(filename, arguments, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_double(filename, arguments, options = {})
|
8
16
|
unless doubled?
|
9
17
|
create_doubles_dir
|
10
18
|
patch_original_path
|
11
|
-
end
|
12
|
-
write_double(
|
19
|
+
end
|
20
|
+
write_double(filename, get_double(filename, arguments, options))
|
13
21
|
end
|
14
22
|
|
23
|
+
def write_double(filename, double)
|
24
|
+
fullpath = File.expand_path(filename, @doubles_dir)
|
25
|
+
File.open(fullpath, 'w') do |f|
|
26
|
+
f.puts "#!/usr/bin/env ruby"
|
27
|
+
f.puts "# Doubled command line application by aruba-doubles\n"
|
28
|
+
f.puts "require 'aruba-doubles/double'"
|
29
|
+
f.puts "double = ArubaDoubles::Double.new(#{double.expectations.inspect})"
|
30
|
+
f.puts "double.run"
|
31
|
+
f.puts "puts double.stdout if double.stdout"
|
32
|
+
f.puts "warn double.stderr if double.stderr"
|
33
|
+
f.puts "exit(double.exit_status) if double.exit_status"
|
34
|
+
end
|
35
|
+
FileUtils.chmod(0755, fullpath)
|
36
|
+
end
|
37
|
+
|
15
38
|
def remove_doubles
|
16
39
|
restore_original_path
|
17
40
|
remove_doubles_dir
|
@@ -22,32 +45,21 @@ module ArubaDoubles
|
|
22
45
|
def create_doubles_dir
|
23
46
|
@doubles_dir = Dir.mktmpdir
|
24
47
|
end
|
48
|
+
|
49
|
+
def doubles
|
50
|
+
@doubles ||= {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_double(filename, arguments, options)
|
54
|
+
doubles[filename] ||= ArubaDoubles::Double.new
|
55
|
+
doubles[filename].could_receive(arguments, options)
|
56
|
+
end
|
25
57
|
|
26
58
|
def patch_original_path
|
27
59
|
@__aruba_doubles_original_path = (ENV['PATH'] || '').split(File::PATH_SEPARATOR)
|
28
60
|
ENV['PATH'] = ([@doubles_dir] + @__aruba_doubles_original_path).join(File::PATH_SEPARATOR)
|
29
61
|
end
|
30
62
|
|
31
|
-
def write_double(command_line, options = {})
|
32
|
-
args = command_line.split
|
33
|
-
filename = args.shift
|
34
|
-
double = File.expand_path(filename, @doubles_dir)
|
35
|
-
File.open(double, 'w') do |f|
|
36
|
-
f.puts "#!/usr/bin/env ruby"
|
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.join(' ')}\""
|
40
|
-
f.puts " warn \" got: #{filename} \#{ARGV.join(' ')}\""
|
41
|
-
f.puts " exit(1)"
|
42
|
-
f.puts "end"
|
43
|
-
f.puts "puts ([File.basename(__FILE__)] + ARGV).join(' ')" if @repeat_arguments
|
44
|
-
f.puts "puts \"#{options[:stdout]}\"" if options[:stdout]
|
45
|
-
f.puts "warn \"#{options[:stderr]}\"" if options[:stderr]
|
46
|
-
f.puts "exit(#{options[:exit_status]})" if options[:exit_status]
|
47
|
-
end
|
48
|
-
FileUtils.chmod(0755, double)
|
49
|
-
end
|
50
|
-
|
51
63
|
def restore_original_path
|
52
64
|
ENV['PATH'] = @__aruba_doubles_original_path.join(File::PATH_SEPARATOR) unless doubled?
|
53
65
|
end
|
@@ -3,18 +3,18 @@ require 'aruba-doubles/api'
|
|
3
3
|
|
4
4
|
World(ArubaDoubles::Api)
|
5
5
|
|
6
|
-
Given /^
|
7
|
-
|
6
|
+
Given /^I could run `([^`]*)`$/ do |cmd|
|
7
|
+
create_double_by_cmd(cmd)
|
8
8
|
end
|
9
9
|
|
10
|
-
Given /^
|
11
|
-
|
10
|
+
Given /^I could run `([^`]*)` with (stdout|stderr):$/ do |cmd, type, output|
|
11
|
+
create_double_by_cmd(cmd, type.to_sym => output)
|
12
12
|
end
|
13
13
|
|
14
|
-
Given /^
|
15
|
-
|
14
|
+
Given /^I could run `([^`]*)` with exit status (\d+)$/ do |cmd, exit|
|
15
|
+
create_double_by_cmd(cmd, :exit_status => exit.to_i)
|
16
16
|
end
|
17
17
|
|
18
|
-
Given /^
|
19
|
-
|
18
|
+
Given /^I could run `([^`]*)` with exit status (\d+) and (stdout|stderr):$/ do |cmd, exit, type, output|
|
19
|
+
create_double_by_cmd(cmd, :exit_status => exit.to_i, type.to_sym => output)
|
20
20
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ArubaDoubles
|
2
|
+
class Double
|
3
|
+
attr_reader :stdout, :stderr, :exit_status, :expectations
|
4
|
+
|
5
|
+
def initialize(expectations = {})
|
6
|
+
@expectations = expectations
|
7
|
+
end
|
8
|
+
|
9
|
+
def could_receive(args, options = {})
|
10
|
+
args = args.join(' ') if args.respond_to?(:join)
|
11
|
+
@expectations[args] = options
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(argv = ARGV)
|
16
|
+
argv = argv.join(' ')
|
17
|
+
raise "Unexpected arguments" unless @expectations.has_key?(argv)
|
18
|
+
@stdout = @expectations[argv][:stdout]
|
19
|
+
@stderr = @expectations[argv][:stderr]
|
20
|
+
@exit_status = @expectations[argv][:exit_status]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/aruba-doubles/hooks.rb
CHANGED
@@ -1,8 +1,3 @@
|
|
1
1
|
After do
|
2
2
|
remove_doubles if doubled?
|
3
3
|
end
|
4
|
-
|
5
|
-
Before('@repeat_arguments') do
|
6
|
-
warn(%{\e[35m The @repeat_arguments tag is deprecated and will soon be removed. Please use the new mock feature to check for arguments (see README)!\e[0m})
|
7
|
-
@repeat_arguments = true
|
8
|
-
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ArubaDoubles::Double, '#could_receive' do
|
4
|
+
before do
|
5
|
+
@double = ArubaDoubles::Double.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should set expected arguments" do
|
9
|
+
@double.could_receive("--foo", :stdout => "foo")
|
10
|
+
@double.could_receive("--bar", :stdout => "bar")
|
11
|
+
@double.run(["--foo"])
|
12
|
+
@double.stdout.should eql("foo")
|
13
|
+
@double.run(["--bar"])
|
14
|
+
@double.stdout.should eql("bar")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should accept expected arguments as array" do
|
18
|
+
@double.could_receive(["--foo"], :stdout => "foo")
|
19
|
+
@double.could_receive(["--bar"], :stdout => "bar")
|
20
|
+
@double.run(["--foo"])
|
21
|
+
@double.stdout.should eql("foo")
|
22
|
+
@double.run(["--bar"])
|
23
|
+
@double.stdout.should eql("bar")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return self" do
|
27
|
+
@double.could_receive("").should be(@double)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set defaults when called without options" do
|
31
|
+
@double.could_receive("")
|
32
|
+
@double.run([])
|
33
|
+
@double.stdout.should be_nil
|
34
|
+
@double.stderr.should be_nil
|
35
|
+
@double.exit_status.should be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set optional stdout" do
|
39
|
+
@double.could_receive("", :stdout => "hi")
|
40
|
+
@double.run([])
|
41
|
+
@double.stdout.should eql("hi")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set optional stderr" do
|
45
|
+
@double.could_receive("", :stderr => "HO!")
|
46
|
+
@double.run([])
|
47
|
+
@double.stderr.should eql("HO!")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set optional exit status" do
|
51
|
+
@double.could_receive("", :exit_status => 1)
|
52
|
+
@double.run([])
|
53
|
+
@double.exit_status.should eql(1)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ArubaDoubles::Double, '#run' do
|
58
|
+
before do
|
59
|
+
@double = ArubaDoubles::Double.new
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should read ARGV by default" do
|
63
|
+
original_arguments = ARGV
|
64
|
+
ARGV = ["--foo"]
|
65
|
+
@double.could_receive("--foo", :stdout => "foo")
|
66
|
+
@double.run
|
67
|
+
@double.stdout.should eql("foo")
|
68
|
+
ARGV = original_arguments
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should raise when called with unexpected arguments" do
|
72
|
+
lambda {
|
73
|
+
@double.run(["--unexpected"])
|
74
|
+
}.should raise_error("Unexpected arguments")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ArubaDoubles::Double do
|
79
|
+
it "should be serializable" do
|
80
|
+
double = ArubaDoubles::Double.new
|
81
|
+
double.could_receive("")
|
82
|
+
double.could_receive("--foo", :stdout=>"foo")
|
83
|
+
double.could_receive("--bar", :stderr=>"OOPS!", :exit_status=>255)
|
84
|
+
loaded_double = ArubaDoubles::Double.new(double.expectations)
|
85
|
+
loaded_double.run([])
|
86
|
+
loaded_double.stdout.should be_nil
|
87
|
+
loaded_double.stderr.should be_nil
|
88
|
+
loaded_double.exit_status.should be_nil
|
89
|
+
loaded_double.run(["--foo"])
|
90
|
+
loaded_double.stdout.should eql("foo")
|
91
|
+
loaded_double.stderr.should be_nil
|
92
|
+
loaded_double.exit_status.should be_nil
|
93
|
+
loaded_double.run(["--bar"])
|
94
|
+
loaded_double.stdout.should be_nil
|
95
|
+
loaded_double.stderr.should eql("OOPS!")
|
96
|
+
loaded_double.exit_status.should eql(255)
|
97
|
+
end
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba-doubles/double'
|
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.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-
|
18
|
+
date: 2011-11-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: cucumber
|
@@ -49,6 +49,38 @@ dependencies:
|
|
49
49
|
version: 0.4.6
|
50
50
|
type: :development
|
51
51
|
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: guard-cucumber
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 5
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
- 7
|
64
|
+
- 3
|
65
|
+
version: 0.7.3
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: guard-rspec
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 9
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
- 5
|
80
|
+
- 1
|
81
|
+
version: 0.5.1
|
82
|
+
type: :development
|
83
|
+
version_requirements: *id004
|
52
84
|
description: Stub command line applications with Cucumber
|
53
85
|
email:
|
54
86
|
- bjoernalbers@googlemail.com
|
@@ -61,18 +93,22 @@ extra_rdoc_files: []
|
|
61
93
|
files:
|
62
94
|
- .gitignore
|
63
95
|
- Gemfile
|
96
|
+
- Guardfile
|
64
97
|
- LICENSE
|
65
98
|
- README.md
|
66
99
|
- Rakefile
|
67
100
|
- aruba-doubles.gemspec
|
68
|
-
- features/
|
101
|
+
- features/double.feature
|
69
102
|
- features/environment-friendly.feature
|
70
103
|
- features/step_definitions/dev_steps.rb
|
71
104
|
- features/support/env.rb
|
72
105
|
- lib/aruba-doubles.rb
|
73
106
|
- lib/aruba-doubles/api.rb
|
74
107
|
- lib/aruba-doubles/cucumber.rb
|
108
|
+
- lib/aruba-doubles/double.rb
|
75
109
|
- lib/aruba-doubles/hooks.rb
|
110
|
+
- spec/aruba-doubles/double_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
76
112
|
homepage: https://github.com/bjoernalbers/aruba-doubles
|
77
113
|
licenses: []
|
78
114
|
|
@@ -105,9 +141,11 @@ rubyforge_project:
|
|
105
141
|
rubygems_version: 1.8.8
|
106
142
|
signing_key:
|
107
143
|
specification_version: 3
|
108
|
-
summary: aruba-doubles-0.
|
144
|
+
summary: aruba-doubles-0.2.0
|
109
145
|
test_files:
|
110
|
-
- features/
|
146
|
+
- features/double.feature
|
111
147
|
- features/environment-friendly.feature
|
112
148
|
- features/step_definitions/dev_steps.rb
|
113
149
|
- features/support/env.rb
|
150
|
+
- spec/aruba-doubles/double_spec.rb
|
151
|
+
- spec/spec_helper.rb
|
@@ -1,104 +0,0 @@
|
|
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 "foo"
|
9
|
-
When I run `foo`
|
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 "foo" with stdout:
|
20
|
-
"""
|
21
|
-
hello, world.
|
22
|
-
"""
|
23
|
-
When I successfully run `foo`
|
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 "foo" with stderr:
|
35
|
-
"""
|
36
|
-
error: something crashed!
|
37
|
-
"""
|
38
|
-
When I successfully run `foo`
|
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 "foo" with exit status 255
|
50
|
-
When I run `foo`
|
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 "foo" with exit status 255 and stdout:
|
61
|
-
"""
|
62
|
-
hello, world.
|
63
|
-
"""
|
64
|
-
When I run `foo`
|
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
|
-
Scenario: Double with expected arguments
|
76
|
-
Given a double of "foo --bar baz" with stdout:
|
77
|
-
"""
|
78
|
-
hello, world.
|
79
|
-
"""
|
80
|
-
When I run `foo`
|
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: foo --bar baz
|
88
|
-
got: foo
|
89
|
-
|
90
|
-
"""
|
91
|
-
|
92
|
-
|
93
|
-
@repeat_arguments
|
94
|
-
Scenario: Double with repeating arguments
|
95
|
-
Given a double of "foo"
|
96
|
-
When I run `foo`
|
97
|
-
Then the stdout should contain exactly:
|
98
|
-
"""
|
99
|
-
foo
|
100
|
-
|
101
|
-
"""
|
102
|
-
And the stderr should contain exactly:
|
103
|
-
"""
|
104
|
-
"""
|