aruba-doubles 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Aruba-Doubles
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/bjoernalbers/aruba-doubles.png)](http://travis-ci.org/bjoernalbers/aruba-doubles)
4
-
5
3
  Cucumber Steps to double Command Line Applications
6
4
 
7
5
  ## Introduction
@@ -27,8 +25,8 @@ Cucumber Steps to double Command Line Applications
27
25
  Aruba-Doubles is a [Cucumber](http://cukes.info/) extention to
28
26
  temporarily "replace" selected Command Line Applications by Test
29
27
  Doubles.
30
- This allows you to simply stub them or fake their output depending on
31
- ARGV.
28
+ This allows you to simply stub these applications, fake their output and
29
+ check if and how they have been called.
32
30
 
33
31
  (Aruba-Doubles is not an official part of
34
32
  [Aruba](https://github.com/cucumber/aruba) but a good companion in the
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'aruba-doubles'
5
- s.version = '1.1.1'
5
+ s.version = '1.2.0'
6
6
  s.authors = ['Björn Albers']
7
7
  s.email = ['bjoernalbers@googlemail.com']
8
8
  s.description = 'Cucumber Steps to double Command Line Applications'
@@ -0,0 +1,15 @@
1
+ Feature: History
2
+
3
+ In order to check if and how a Test Double has been called
4
+ As a BDD-guy
5
+ I want to have all calls to Test Doubles logged into a History
6
+
7
+ Scenario: Check history
8
+ Given I double `foo --bar baz`
9
+ Then the double `foo --bar baz` should not have been run
10
+ When I run `foo --bar baz`
11
+ Then the double `foo --bar baz` should have been run
12
+ But the double `foo` should not have been run
13
+
14
+ Scenario: Clean history after each scenario
15
+ Then the double `foo --bar baz` should not have been run
data/lib/aruba-doubles.rb CHANGED
@@ -1,12 +1,22 @@
1
1
  require 'tempfile'
2
2
  require 'shellwords'
3
+ require 'pstore'
3
4
  require 'aruba-doubles/double'
5
+ require 'aruba-doubles/history'
4
6
 
5
7
  module ArubaDoubles
8
+
9
+ # Basename of the history file
10
+ HISTORY_FILE = 'history.pstore'
11
+
6
12
  def double_cmd(cmd, output = {})
7
- argv = Shellwords.split(cmd)
13
+ argv = cmd.shellsplit
8
14
  filename = argv.shift
9
15
  double = Double.find(filename) || Double.new(filename)
10
16
  double.create { on argv, output }
11
17
  end
18
+
19
+ def history
20
+ @history ||= History.new(File.join(Double.bindir, HISTORY_FILE))
21
+ end
12
22
  end
@@ -8,6 +8,7 @@ end
8
8
 
9
9
  After do
10
10
  ArubaDoubles::Double.teardown
11
+ history.clear
11
12
  end
12
13
 
13
14
  Given /^I double `([^`]*)`$/ do |cmd|
@@ -37,3 +38,11 @@ end
37
38
  Given /^I double `([^`]*)` with exit status (\d+)$/ do |cmd, exit_status|
38
39
  double_cmd(cmd, :exit => exit_status.to_i)
39
40
  end
41
+
42
+ Then /^the double `([^`]*)` should have been run$/ do |cmd|
43
+ history.should include(cmd.shellsplit)
44
+ end
45
+
46
+ Then /^the double `([^`]*)` should not have been run$/ do |cmd|
47
+ history.should_not include(cmd.shellsplit)
48
+ end
@@ -38,6 +38,7 @@ module ArubaDoubles
38
38
  end
39
39
 
40
40
  # Return the doubles directory.
41
+ #
41
42
  # @return [String]
42
43
  def bindir
43
44
  @bindir ||= Dir.mktmpdir
@@ -53,6 +54,7 @@ module ArubaDoubles
53
54
  end
54
55
 
55
56
  # Return all registered doubles.
57
+ #
56
58
  # @return [Array<ArubaDoubles::Double>]
57
59
  def all
58
60
  self.doubles.values
@@ -90,6 +92,7 @@ module ArubaDoubles
90
92
  attr_reader :filename, :output
91
93
 
92
94
  # Instantiate and register new double.
95
+ #
93
96
  # @return [ArubaDoubles::Double]
94
97
  def initialize(cmd, default_output = {}, &block)
95
98
  @filename = cmd
@@ -105,8 +108,10 @@ module ArubaDoubles
105
108
 
106
109
  # Run the double.
107
110
  #
108
- # This will actually display any outputs if defined and exit.
111
+ # This will append the call to the doubles history, display any
112
+ # outputs if defined and exit.
109
113
  def run(argv = ARGV)
114
+ history << [filename] + argv
110
115
  output = @outputs[argv] || @default_output
111
116
  puts output[:puts] if output[:puts]
112
117
  warn output[:warn] if output[:warn]
@@ -114,6 +119,7 @@ module ArubaDoubles
114
119
  end
115
120
 
116
121
  # Create the executable double.
122
+ #
117
123
  # @return [String] full path to the double.
118
124
  def create(&block)
119
125
  register
@@ -160,5 +166,19 @@ module ArubaDoubles
160
166
  self.class.doubles.delete(filename)
161
167
  end
162
168
 
169
+ # Return the history object for this double.
170
+ #
171
+ # @return [ArubaDoubles::History]
172
+ def history
173
+ @history ||= History.new(history_file)
174
+ end
175
+
176
+ # Return full (absolute) path to history file.
177
+ # The file will reside in the doubles directory.
178
+ #
179
+ # @return [String]
180
+ def history_file
181
+ File.expand_path(HISTORY_FILE, File.dirname($PROGRAM_NAME))
182
+ end
163
183
  end
164
184
  end
@@ -0,0 +1,35 @@
1
+ module ArubaDoubles
2
+ class History
3
+
4
+ include Enumerable
5
+
6
+ def initialize(filename)
7
+ @store = PStore.new(filename)
8
+ end
9
+
10
+ def <<(args)
11
+ @store.transaction do
12
+ @store[:history] ||= []
13
+ @store[:history] << args
14
+ end
15
+ end
16
+
17
+ def clear
18
+ @store.transaction do
19
+ @store[:history] = []
20
+ end
21
+ end
22
+
23
+ def each
24
+ entries.each { |e| yield(e) }
25
+ end
26
+
27
+ private
28
+
29
+ def entries
30
+ @store.transaction(readonly=true) do
31
+ @store[:history] || []
32
+ end
33
+ end
34
+ end
35
+ end
@@ -112,6 +112,7 @@ describe ArubaDoubles::Double do
112
112
 
113
113
  describe '#run' do
114
114
  before do
115
+ ArubaDoubles::History.stub(:new).and_return(stub(:<< => nil))
115
116
  @double = ArubaDoubles::Double.new('foo',
116
117
  :puts => 'default stdout',
117
118
  :warn => 'default stderr',
@@ -123,6 +124,13 @@ describe ArubaDoubles::Double do
123
124
  @double.stub(:puts => nil, :warn => nil, :exit => nil)
124
125
  end
125
126
 
127
+ it 'should append the call to the doubles history' do
128
+ history = double('history')
129
+ history.should_receive(:<<).with(%w[foo] + ARGV)
130
+ ArubaDoubles::History.should_receive(:new).and_return(history)
131
+ @double.run
132
+ end
133
+
126
134
  context 'when ARGV does match' do
127
135
  def run_double
128
136
  @double.run %w[--hello]
@@ -164,8 +172,6 @@ describe ArubaDoubles::Double do
164
172
  run_double
165
173
  end
166
174
  end
167
-
168
- it 'should read ARGV'
169
175
  end
170
176
 
171
177
  describe '.create' do
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe ArubaDoubles::History do
5
+
6
+ #TODO: Add examples to test the transactional stuff with PStore!
7
+
8
+ it 'should initialize a PStore with the filename' do
9
+ PStore.should_receive(:new).with('history.pstore')
10
+ ArubaDoubles::History.new('history.pstore')
11
+ end
12
+ end
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.1.1
4
+ version: 1.2.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-20 00:00:00.000000000Z
12
+ date: 2012-04-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
16
- requirement: &70185558974140 !ruby/object:Gem::Requirement
16
+ requirement: &70241989258120 !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: *70185558974140
24
+ version_requirements: *70241989258120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70185558973580 !ruby/object:Gem::Requirement
27
+ requirement: &70241989257520 !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: *70185558973580
35
+ version_requirements: *70241989257520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70185558972880 !ruby/object:Gem::Requirement
38
+ requirement: &70241989256900 !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: *70185558972880
46
+ version_requirements: *70241989256900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: aruba
49
- requirement: &70185558972260 !ruby/object:Gem::Requirement
49
+ requirement: &70241989256280 !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: *70185558972260
57
+ version_requirements: *70241989256280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-cucumber
60
- requirement: &70185558971700 !ruby/object:Gem::Requirement
60
+ requirement: &70241989255780 !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: *70185558971700
68
+ version_requirements: *70241989255780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &70185558971120 !ruby/object:Gem::Requirement
71
+ requirement: &70241989255140 !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: *70185558971120
79
+ version_requirements: *70241989255140
80
80
  description: Cucumber Steps to double Command Line Applications
81
81
  email:
82
82
  - bjoernalbers@googlemail.com
@@ -87,7 +87,6 @@ files:
87
87
  - .gitignore
88
88
  - .rbenv-version
89
89
  - .rvmrc
90
- - .travis.yml
91
90
  - Gemfile
92
91
  - Guardfile
93
92
  - LICENSE
@@ -96,12 +95,15 @@ files:
96
95
  - aruba-doubles.gemspec
97
96
  - features/define_output.feature
98
97
  - features/double_commands.feature
98
+ - features/history.feature
99
99
  - features/step_definitions/dev_steps.rb
100
100
  - features/support/env.rb
101
101
  - lib/aruba-doubles.rb
102
102
  - lib/aruba-doubles/cucumber.rb
103
103
  - lib/aruba-doubles/double.rb
104
+ - lib/aruba-doubles/history.rb
104
105
  - spec/aruba-doubles/double_spec.rb
106
+ - spec/aruba-doubles/history_spec.rb
105
107
  - spec/spec_helper.rb
106
108
  homepage: https://github.com/bjoernalbers/aruba-doubles
107
109
  licenses: []
@@ -117,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
119
  version: '0'
118
120
  segments:
119
121
  - 0
120
- hash: 1055015783693989593
122
+ hash: -2111762355513459524
121
123
  required_rubygems_version: !ruby/object:Gem::Requirement
122
124
  none: false
123
125
  requirements:
@@ -126,17 +128,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
128
  version: '0'
127
129
  segments:
128
130
  - 0
129
- hash: 1055015783693989593
131
+ hash: -2111762355513459524
130
132
  requirements: []
131
133
  rubyforge_project:
132
134
  rubygems_version: 1.8.10
133
135
  signing_key:
134
136
  specification_version: 3
135
- summary: aruba-doubles-1.1.1
137
+ summary: aruba-doubles-1.2.0
136
138
  test_files:
137
139
  - features/define_output.feature
138
140
  - features/double_commands.feature
141
+ - features/history.feature
139
142
  - features/step_definitions/dev_steps.rb
140
143
  - features/support/env.rb
141
144
  - spec/aruba-doubles/double_spec.rb
145
+ - spec/aruba-doubles/history_spec.rb
142
146
  - spec/spec_helper.rb
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- - 1.9.3