aruba-doubles 1.0.1 → 1.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/aruba-doubles.gemspec +1 -1
- data/features/define_output.feature +9 -0
- data/lib/aruba-doubles.rb +4 -4
- data/lib/aruba-doubles/double.rb +23 -15
- data/spec/aruba-doubles/double_spec.rb +34 -15
- metadata +17 -17
data/aruba-doubles.gemspec
CHANGED
|
@@ -90,3 +90,12 @@ Feature: Define Output
|
|
|
90
90
|
Then the exit status should be 0
|
|
91
91
|
And the stdout should be empty
|
|
92
92
|
And the stderr should be empty
|
|
93
|
+
|
|
94
|
+
Scenario: Double with multiple outputs
|
|
95
|
+
Given I double `foo --hello` with "hello, world."
|
|
96
|
+
And I double `foo --hello --loud` with "HELLO, WORLD!"
|
|
97
|
+
When I run `foo --hello`
|
|
98
|
+
Then the stdout should contain "hello, world."
|
|
99
|
+
But the stdout should not contain "HELLO, WORLD!"
|
|
100
|
+
When I run `foo --hello --loud`
|
|
101
|
+
Then the stdout should contain "HELLO, WORLD!"
|
data/lib/aruba-doubles.rb
CHANGED
|
@@ -4,9 +4,9 @@ require 'aruba-doubles/double'
|
|
|
4
4
|
|
|
5
5
|
module ArubaDoubles
|
|
6
6
|
def double_cmd(cmd, output = {})
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
argv = Shellwords.split(cmd)
|
|
8
|
+
filename = argv.shift
|
|
9
|
+
double = Double.find(filename) || Double.new(filename)
|
|
10
|
+
double.create { on argv, output }
|
|
11
11
|
end
|
|
12
12
|
end
|
data/lib/aruba-doubles/double.rb
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
module ArubaDoubles
|
|
2
2
|
class Double
|
|
3
|
+
|
|
4
|
+
@doubles = {}
|
|
5
|
+
|
|
3
6
|
class << self
|
|
4
7
|
|
|
8
|
+
attr_reader :doubles
|
|
9
|
+
|
|
5
10
|
# Setup the doubles environment.
|
|
6
11
|
def setup
|
|
7
12
|
patch_path
|
|
@@ -37,6 +42,10 @@ module ArubaDoubles
|
|
|
37
42
|
@bindir ||= Dir.mktmpdir
|
|
38
43
|
end
|
|
39
44
|
|
|
45
|
+
def find(filename)
|
|
46
|
+
self.doubles[filename]
|
|
47
|
+
end
|
|
48
|
+
|
|
40
49
|
# Iterate over all registered doubles.
|
|
41
50
|
def each
|
|
42
51
|
all.each { |double| yield(double) }
|
|
@@ -45,7 +54,7 @@ module ArubaDoubles
|
|
|
45
54
|
# Return all registered doubles.
|
|
46
55
|
# @return [Array<ArubaDoubles::Double>]
|
|
47
56
|
def all
|
|
48
|
-
|
|
57
|
+
self.doubles.values
|
|
49
58
|
end
|
|
50
59
|
|
|
51
60
|
private
|
|
@@ -77,39 +86,37 @@ module ArubaDoubles
|
|
|
77
86
|
end
|
|
78
87
|
end
|
|
79
88
|
|
|
80
|
-
attr_reader :filename, :output
|
|
89
|
+
attr_reader :filename, :output
|
|
81
90
|
|
|
82
91
|
# Instantiate and register new double.
|
|
83
92
|
# @return [ArubaDoubles::Double]
|
|
84
93
|
def initialize(cmd, default_output = {}, &block)
|
|
85
94
|
@filename = cmd
|
|
86
|
-
@
|
|
87
|
-
@
|
|
88
|
-
self.class.all << self
|
|
95
|
+
@default_output = {:puts => nil, :warn => nil, :exit => nil}.merge(default_output)
|
|
96
|
+
@outputs = {}
|
|
89
97
|
self.instance_eval(&block) if block_given?
|
|
90
98
|
end
|
|
91
99
|
|
|
92
100
|
# Add ARGV matcher with output.
|
|
93
101
|
def on(argv, output = nil)
|
|
94
|
-
@
|
|
102
|
+
@outputs[argv] = output
|
|
95
103
|
end
|
|
96
104
|
|
|
97
105
|
# Run the double.
|
|
98
106
|
#
|
|
99
107
|
# This will actually display any outputs if defined and exit.
|
|
100
108
|
def run(argv = ARGV)
|
|
101
|
-
@
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
puts @output[:puts] if @output[:puts]
|
|
106
|
-
warn @output[:warn] if @output[:warn]
|
|
107
|
-
exit @output[:exit] if @output[:exit]
|
|
109
|
+
output = @outputs[argv] || @default_output
|
|
110
|
+
puts output[:puts] if output[:puts]
|
|
111
|
+
warn output[:warn] if output[:warn]
|
|
112
|
+
exit output[:exit] if output[:exit]
|
|
108
113
|
end
|
|
109
114
|
|
|
110
115
|
# Create the executable double.
|
|
111
116
|
# @return [String] full path to the double.
|
|
112
|
-
def create
|
|
117
|
+
def create(&block)
|
|
118
|
+
self.instance_eval(&block) if block_given?
|
|
119
|
+
self.class.doubles[@filename] = self
|
|
113
120
|
content = self.to_ruby
|
|
114
121
|
fullpath = File.join(self.class.bindir, filename)
|
|
115
122
|
#puts "creating double: #{fullpath} with content:\n#{content}" # debug
|
|
@@ -117,6 +124,7 @@ module ArubaDoubles
|
|
|
117
124
|
f.puts content
|
|
118
125
|
f.close
|
|
119
126
|
FileUtils.chmod(0755, File.join(self.class.bindir, filename))
|
|
127
|
+
self
|
|
120
128
|
end
|
|
121
129
|
|
|
122
130
|
# Export the double to executable Ruby code.
|
|
@@ -127,7 +135,7 @@ module ArubaDoubles
|
|
|
127
135
|
ruby << "$: << '#{File.expand_path('..', File.dirname(__FILE__))}'"
|
|
128
136
|
ruby << 'require "aruba-doubles"'
|
|
129
137
|
ruby << 'ArubaDoubles::Double.run do'
|
|
130
|
-
@
|
|
138
|
+
@outputs.each_pair { |argv,output| ruby << " on #{argv.inspect}, #{output.inspect}" }
|
|
131
139
|
ruby << 'end'
|
|
132
140
|
ruby.join("\n")
|
|
133
141
|
end
|
|
@@ -67,16 +67,6 @@ describe ArubaDoubles::Double do
|
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
describe '.new' do
|
|
70
|
-
it 'should register the double' do
|
|
71
|
-
d = ArubaDoubles::Double.new('bar')
|
|
72
|
-
ArubaDoubles::Double.all.should include(d)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it 'should initialize all output attributes with nil' do
|
|
76
|
-
output = ArubaDoubles::Double.new('foo').output
|
|
77
|
-
output.should eql({:puts => nil, :warn => nil, :exit => nil})
|
|
78
|
-
end
|
|
79
|
-
|
|
80
70
|
it 'should execute a given block in the doubles context' do
|
|
81
71
|
double = ArubaDoubles::Double.new('bar') { def hi; "hi" end }
|
|
82
72
|
double.should respond_to(:hi)
|
|
@@ -86,6 +76,17 @@ describe ArubaDoubles::Double do
|
|
|
86
76
|
it 'should raise error on absolute filename'
|
|
87
77
|
end
|
|
88
78
|
|
|
79
|
+
describe '.find' do
|
|
80
|
+
it 'should return a registered double by name' do
|
|
81
|
+
File.stub(:open).and_return(stub(:puts => nil, :close => nil))
|
|
82
|
+
FileUtils.stub(:chmod)
|
|
83
|
+
|
|
84
|
+
ArubaDoubles::Double.find('registered_double').should be_nil
|
|
85
|
+
double = ArubaDoubles::Double.create('registered_double')
|
|
86
|
+
ArubaDoubles::Double.find('registered_double').should eql(double)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
89
90
|
describe '.run' do
|
|
90
91
|
before do
|
|
91
92
|
@double = double('double', :run => nil)
|
|
@@ -193,23 +194,41 @@ describe ArubaDoubles::Double do
|
|
|
193
194
|
end
|
|
194
195
|
|
|
195
196
|
describe '#create' do
|
|
197
|
+
before do
|
|
198
|
+
File.stub(:open).and_return(stub(:puts => nil, :close => nil))
|
|
199
|
+
FileUtils.stub(:chmod)
|
|
200
|
+
ArubaDoubles::Double.stub(:bindir).and_return('/tmp/foo')
|
|
201
|
+
end
|
|
202
|
+
|
|
196
203
|
it 'should create the executable command inside the doubles dir' do
|
|
197
204
|
file = double('file', :puts => nil, :close => nil)
|
|
198
|
-
ArubaDoubles::Double.stub(:bindir).and_return('/tmp/foo')
|
|
199
205
|
File.should_receive(:open).with('/tmp/foo/bar', 'w').and_return(file)
|
|
200
|
-
FileUtils.stub(:chmod)
|
|
201
206
|
ArubaDoubles::Double.new('bar').create
|
|
202
207
|
end
|
|
203
208
|
|
|
204
209
|
it 'should make the file executable' do
|
|
205
|
-
ArubaDoubles::Double.stub(:bindir).and_return('/tmp/foo')
|
|
206
210
|
File.stub(:open).and_return(stub(:puts => nil, :close => nil))
|
|
207
|
-
|
|
208
211
|
filename = '/tmp/foo/bar'
|
|
209
212
|
FileUtils.should_receive(:chmod).with(0755, filename)
|
|
210
|
-
|
|
211
213
|
ArubaDoubles::Double.new('bar').create
|
|
212
214
|
end
|
|
215
|
+
|
|
216
|
+
it 'should register the double' do
|
|
217
|
+
double = ArubaDoubles::Double.create('bar')
|
|
218
|
+
ArubaDoubles::Double.all.should include(double)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it 'should return self' do
|
|
222
|
+
double = ArubaDoubles::Double.new('foo')
|
|
223
|
+
double.create.should eql(double)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it 'should execute a block on that double when given' do
|
|
227
|
+
double = ArubaDoubles::Double.create('bar')
|
|
228
|
+
block = Proc.new {}
|
|
229
|
+
double.should_receive(:instance_eval).with(&block)
|
|
230
|
+
double.create(&block)
|
|
231
|
+
end
|
|
213
232
|
end
|
|
214
233
|
|
|
215
234
|
describe '#to_ruby' do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aruba-doubles
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-04-
|
|
12
|
+
date: 2012-04-20 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: cucumber
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &70304475014040 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: 1.0.2
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *70304475014040
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: rspec
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &70304475013040 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ! '>='
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: 2.6.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *70304475013040
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: rake
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &70304475012120 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ! '>='
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: 0.9.2.2
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *70304475012120
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: aruba
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &70304475011300 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ! '>='
|
|
@@ -54,10 +54,10 @@ dependencies:
|
|
|
54
54
|
version: 0.4.6
|
|
55
55
|
type: :development
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *70304475011300
|
|
58
58
|
- !ruby/object:Gem::Dependency
|
|
59
59
|
name: guard-cucumber
|
|
60
|
-
requirement: &
|
|
60
|
+
requirement: &70304475010300 !ruby/object:Gem::Requirement
|
|
61
61
|
none: false
|
|
62
62
|
requirements:
|
|
63
63
|
- - ! '>='
|
|
@@ -65,10 +65,10 @@ dependencies:
|
|
|
65
65
|
version: 0.7.3
|
|
66
66
|
type: :development
|
|
67
67
|
prerelease: false
|
|
68
|
-
version_requirements: *
|
|
68
|
+
version_requirements: *70304475010300
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: guard-rspec
|
|
71
|
-
requirement: &
|
|
71
|
+
requirement: &70304475009200 !ruby/object:Gem::Requirement
|
|
72
72
|
none: false
|
|
73
73
|
requirements:
|
|
74
74
|
- - ! '>='
|
|
@@ -76,7 +76,7 @@ dependencies:
|
|
|
76
76
|
version: 0.5.1
|
|
77
77
|
type: :development
|
|
78
78
|
prerelease: false
|
|
79
|
-
version_requirements: *
|
|
79
|
+
version_requirements: *70304475009200
|
|
80
80
|
description: Cucumber Steps to double Command Line Applications
|
|
81
81
|
email:
|
|
82
82
|
- bjoernalbers@googlemail.com
|
|
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
117
117
|
version: '0'
|
|
118
118
|
segments:
|
|
119
119
|
- 0
|
|
120
|
-
hash:
|
|
120
|
+
hash: 884917047948355837
|
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
none: false
|
|
123
123
|
requirements:
|
|
@@ -126,13 +126,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
126
126
|
version: '0'
|
|
127
127
|
segments:
|
|
128
128
|
- 0
|
|
129
|
-
hash:
|
|
129
|
+
hash: 884917047948355837
|
|
130
130
|
requirements: []
|
|
131
131
|
rubyforge_project:
|
|
132
132
|
rubygems_version: 1.8.10
|
|
133
133
|
signing_key:
|
|
134
134
|
specification_version: 3
|
|
135
|
-
summary: aruba-doubles-1.0
|
|
135
|
+
summary: aruba-doubles-1.1.0
|
|
136
136
|
test_files:
|
|
137
137
|
- features/define_output.feature
|
|
138
138
|
- features/double_commands.feature
|