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 CHANGED
@@ -1,12 +1,12 @@
1
- Double command line applications in your Cucumber features
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 `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).
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 hopefully nicely together.)
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
- Take a peek at `features/*.feature` for some examples and look in `lib/aruba-doubles/cucumber.rb` for all step definitions.
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/kill_a_random_cat`
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
 
@@ -2,10 +2,10 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'aruba-doubles'
5
- s.version = '0.0.1'
5
+ s.version = '0.0.2'
6
6
  s.authors = ["Björn Albers"]
7
7
  s.email = ["bjoernalbers@googlemail.com"]
8
- s.description = 'Double command line applications in your Cucumber features'
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
+
@@ -1,23 +1,38 @@
1
1
  module ArubaDoubles
2
2
  module Api
3
- def doubles_dir
4
- @doubles_dir ||= Dir.mktmpdir
3
+ def doubled?
4
+ !@doubles_dir.nil?
5
5
  end
6
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)
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
- def restore_original_path
13
- ENV['PATH'] = @__aruba_doubles_original_path.join(File::PATH_SEPARATOR)
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 create_double(filename, options = {})
17
- double = File.expand_path(filename, doubles_dir)
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-double"
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 remove_doubles
30
- FileUtils.rm_r(doubles_dir) if File.directory?(doubles_dir)
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
@@ -0,0 +1,7 @@
1
+ After do
2
+ remove_doubles if doubled?
3
+ end
4
+
5
+ Before('@repeat_arguments') do
6
+ @repeat_arguments = true
7
+ 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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
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-14 00:00:00 Z
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: Double command line applications in your Cucumber features
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.1
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