aruba-doubles 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- Stub command line applications with Cucumber
1
+ # Aruba-Doubles
2
2
 
3
- ## Motivation
3
+ Stub and mock command line applications with Cucumber
4
+
5
+ ## Introduction
4
6
 
5
7
  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
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.)
@@ -18,15 +20,30 @@ Then, `require` the library in one of your ruby files under `features/support` (
18
20
 
19
21
  require 'aruba-doubles/cucumber'
20
22
 
21
- Here is an example:
23
+ Here are some examples:
22
24
 
23
- Scenario: Something went wrong
25
+ Scenario: Stubbing with exit code and stderr
24
26
  Given a double of "kill_the_cat" with exit status 255 and stderr:
25
27
  """
26
28
  ERROR: You don't even have a cat!
27
29
  """
28
30
  When I run `my_fancy_new_script`
29
31
  Then ...
32
+
33
+ Scenario: Mocking
34
+ Given a double of "kill_the_cat --gently" with stdout:
35
+ """
36
+ R.I.P.
37
+ """
38
+ When I run `kill_the_cat`
39
+ Then the stdout should contain exactly:
40
+ """
41
+ """
42
+ And the stderr should contain exactly:
43
+ """
44
+ expected: kill_the_cat --gently
45
+ got: kill_the_cat
46
+ """
30
47
 
31
48
  Take a peek at `features/*.feature` for further examples and at `lib/aruba-doubles/cucumber.rb` for all step definitions.
32
49
 
data/Rakefile CHANGED
@@ -1,9 +1,8 @@
1
1
  require 'bundler/gem_tasks'
2
-
3
2
  require 'cucumber/rake/task'
4
3
 
5
4
  Cucumber::Rake::Task.new(:features) do |t|
6
5
  t.cucumber_opts = "--format pretty"
7
6
  end
8
7
 
9
- task :default => :features
8
+ task :default => :features
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'aruba-doubles'
5
- s.version = '0.0.2'
5
+ s.version = '0.1.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'
@@ -5,8 +5,8 @@ Feature: Double command line applications
5
5
  I want to use the "double of" steps
6
6
 
7
7
  Scenario: Double default behaviour
8
- Given a double of "ls"
9
- When I run `ls -la`
8
+ Given a double of "foo"
9
+ When I run `foo`
10
10
  Then the exit status should be 0
11
11
  And the stdout should contain exactly:
12
12
  """
@@ -16,11 +16,11 @@ Feature: Double command line applications
16
16
  """
17
17
 
18
18
  Scenario: Double with stdout
19
- Given a double of "ls" with stdout:
19
+ Given a double of "foo" with stdout:
20
20
  """
21
21
  hello, world.
22
22
  """
23
- When I successfully run `ls -la`
23
+ When I successfully run `foo`
24
24
  Then the stdout should contain exactly:
25
25
  """
26
26
  hello, world.
@@ -31,11 +31,11 @@ Feature: Double command line applications
31
31
  """
32
32
 
33
33
  Scenario: Double with stderr
34
- Given a double of "ls" with stderr:
34
+ Given a double of "foo" with stderr:
35
35
  """
36
36
  error: something crashed!
37
37
  """
38
- When I successfully run `ls -la`
38
+ When I successfully run `foo`
39
39
  And the stdout should contain exactly:
40
40
  """
41
41
  """
@@ -46,8 +46,8 @@ Feature: Double command line applications
46
46
  """
47
47
 
48
48
  Scenario: Double with exit status
49
- Given a double of "ls" with exit status 255
50
- When I run `ls -la`
49
+ Given a double of "foo" with exit status 255
50
+ When I run `foo`
51
51
  Then the exit status should be 255
52
52
  And the stdout should contain exactly:
53
53
  """
@@ -57,11 +57,11 @@ Feature: Double command line applications
57
57
  """
58
58
 
59
59
  Scenario: Double with exit status and stdout
60
- Given a double of "ls" with exit status 255 and stdout:
60
+ Given a double of "foo" with exit status 255 and stdout:
61
61
  """
62
62
  hello, world.
63
63
  """
64
- When I run `ls -la`
64
+ When I run `foo`
65
65
  Then the exit status should be 255
66
66
  And the stdout should contain exactly:
67
67
  """
@@ -72,16 +72,33 @@ Feature: Double command line applications
72
72
  """
73
73
  """
74
74
 
75
+ Scenario: Double with expected arguments
76
+ Given a double of "ls --la" with stdout:
77
+ """
78
+ hello, world.
79
+ """
80
+ When I run `ls`
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: ls --la
88
+ got: ls
89
+
90
+ """
91
+
92
+
75
93
  @repeat_arguments
76
94
  Scenario: Double with repeating arguments
77
- Given a double of "ls"
78
- When I run `ls -la`
95
+ Given a double of "foo"
96
+ When I run `foo`
79
97
  Then the stdout should contain exactly:
80
98
  """
81
- ls -la
99
+ foo
82
100
 
83
101
  """
84
102
  And the stderr should contain exactly:
85
103
  """
86
104
  """
87
-
@@ -28,11 +28,18 @@ module ArubaDoubles
28
28
  ENV['PATH'] = ([@doubles_dir] + @__aruba_doubles_original_path).join(File::PATH_SEPARATOR)
29
29
  end
30
30
 
31
- def write_double(file, options = {})
32
- double = File.expand_path(file, @doubles_dir)
31
+ def write_double(command_line, options = {})
32
+ args = command_line.split
33
+ filename = args.shift
34
+ double = File.expand_path(filename, @doubles_dir)
33
35
  File.open(double, 'w') do |f|
34
36
  f.puts "#!/usr/bin/env ruby"
35
- f.puts "# Doubled command line application by aruba-doubles"
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}\""
40
+ f.puts " warn \" got: #{filename} \#{ARGV}\""
41
+ f.puts " exit(1)"
42
+ f.puts "end"
36
43
  f.puts "puts ([File.basename(__FILE__)] + ARGV).join(' ')" if @repeat_arguments
37
44
  f.puts "puts \"#{options[:stdout]}\"" if options[:stdout]
38
45
  f.puts "warn \"#{options[:stderr]}\"" if options[:stderr]
@@ -3,5 +3,6 @@ After do
3
3
  end
4
4
 
5
5
  Before('@repeat_arguments') do
6
+ warn(%{\e[35m The @repeat_arguments tag is deprecated and will be removed in v0.1.1. Please use the new mock feature to check for arguments (see README)!\e[0m})
6
7
  @repeat_arguments = true
7
8
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.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-10-17 00:00:00 Z
18
+ date: 2011-10-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cucumber
@@ -105,7 +105,7 @@ rubyforge_project:
105
105
  rubygems_version: 1.8.8
106
106
  signing_key:
107
107
  specification_version: 3
108
- summary: aruba-doubles-0.0.2
108
+ summary: aruba-doubles-0.1.0
109
109
  test_files:
110
110
  - features/double_cli_apps.feature
111
111
  - features/environment-friendly.feature