aruba 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
  gemspec
3
3
 
4
- gem 'cucumber', :path => '../cucumber' if File.directory?(File.dirname(__FILE__) + '/../cucumber')
5
- gem 'gherkin', :path => '../gherkin' if File.directory?(File.dirname(__FILE__) + '/../gherkin')
4
+ # Use source from sibling folders (if available) instead of gems
5
+ %w[cucumber].each do |g|
6
+ if File.directory?(File.dirname(__FILE__) + "/../#{g}")
7
+ @dependencies.reject!{|dep| dep.name == g}
8
+ gem g, :path => "../#{g}"
9
+ end
10
+ end
data/History.txt CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.2.3
2
+
3
+ === Bug fixes
4
+ * Directory should not exist gives false-positive (#13,#15 Nicholas Rutherford)
5
+
6
+ === New Features
7
+ * Added step definitions for comparing file contents with regexps (#9 Aslak Hellesøy)
8
+ * Always put ./bin at the beginning of $PATH to make it easier to run own executables (#7 Aslak Hellesøy)
9
+ * Communication with interactive processes (#4 Mike Sassak)
10
+ * Remove hyphens separating stdout and stderr (Arve Knudsen)
11
+
1
12
  == 0.2.2
2
13
 
3
14
  === New Features
data/README.rdoc CHANGED
@@ -1,8 +1,7 @@
1
1
  = aruba
2
2
 
3
3
  Cucumber steps for driving out command line applications. The command line application can be anything,
4
- a compiled C program, a Java program, a Perl script - anything. There is also special support for various
5
- Ruby versions (see below).
4
+ a compiled C program, a Java program, a Perl script - anything.
6
5
 
7
6
  == Usage
8
7
 
@@ -18,13 +17,14 @@ itself).
18
17
 
19
18
  == Getting more output with tags.
20
19
 
21
- Aruba has several tags you can use to see what command actually gets run (useful if you're using the RVM steps),
22
- STDOUT or STDERR. You can put these tags on individual scenarios, or on a feature. The tags are:
20
+ Aruba has several tags you can use to get more information. You can put these tags on individual scenarios, or on a feature. The tags are:
23
21
 
24
- * <tt>@announce-cmd</tt>
25
- * <tt>@announce-stdout</tt>
26
- * <tt>@announce-stderr</tt>
27
- * <tt>@announce</tt> (does all of the above)
22
+ * <tt>@announce-cmd</tt> - See what command is is run
23
+ * <tt>@announce-stdout</tt> - See the stdout
24
+ * <tt>@announce-stderr</tt> - See the stderr
25
+ * <tt>@announce-dir</tt> - See the current directory
26
+ * <tt>@announce-env</tt> - See environment variables set by Aruba
27
+ * <tt>@announce</tt> - Does all of the above
28
28
 
29
29
  == Note on Patches/Pull Requests
30
30
 
data/aruba.gemspec CHANGED
@@ -1,17 +1,17 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
2
 
4
3
  Gem::Specification.new do |s|
5
4
  s.name = 'aruba'
6
- s.version = "0.2.2"
5
+ s.version = "0.2.3"
7
6
  s.authors = ["Aslak Hellesøy", "David Chelimsky"]
8
7
  s.description = 'CLI Steps for Cucumber, hand-crafted for you in Aruba'
9
8
  s.summary = "aruba-#{s.version}"
10
9
  s.email = 'cukes@googlegroups.com'
11
10
  s.homepage = 'http://github.com/aslakhellesoy/aruba'
12
11
 
13
- s.add_dependency 'cucumber', '~> 0.9.0' unless File.directory?(File.dirname(__FILE__) + '/../cucumber')
14
- s.add_development_dependency('rspec', "~> 2.0.0.beta.22")
12
+ s.add_dependency 'cucumber', '~> 0.9.0'
13
+ s.add_dependency 'background_process' # Can't specify a version - bundler/rubygems chokes on '2.1'
14
+ s.add_development_dependency 'rspec', '~> 2.0.0.beta.22'
15
15
 
16
16
  s.rubygems_version = "1.3.7"
17
17
  s.files = `git ls-files`.split("\n")
@@ -74,7 +74,17 @@ Feature: file system commands
74
74
  Then the following directories should exist:
75
75
  | foo/bar |
76
76
  | foo/bla |
77
-
77
+
78
+ Scenario: check for absence of directories
79
+ Given a directory named "foo/bar"
80
+ Given a directory named "foo/bla"
81
+ Then the following step should fail with Spec::Expectations::ExpectationNotMetError:
82
+ """
83
+ Then the following directories should not exist:
84
+ | foo/bar/ |
85
+ | foo/bla/ |
86
+ """
87
+
78
88
  Scenario: Check file contents
79
89
  Given a file named "foo" with:
80
90
  """
@@ -82,3 +92,11 @@ Feature: file system commands
82
92
  """
83
93
  Then the file "foo" should contain "hello world"
84
94
  And the file "foo" should not contain "HELLO WORLD"
95
+
96
+ Scenario: Check file contents
97
+ Given a file named "foo" with:
98
+ """
99
+ hello world
100
+ """
101
+ Then the file "foo" should match /hel.o world/
102
+ And the file "foo" should not match /HELLO WORLD/
@@ -0,0 +1,30 @@
1
+ Feature: Interactive process control
2
+
3
+ In order to test interactive command line applications
4
+ As a developer using Cucumber
5
+ I want to use the interactive session steps
6
+
7
+ Scenario: Running ruby interactively
8
+ Given a file named "echo.rb" with:
9
+ """
10
+ while res = gets.chomp
11
+ break if res == "quit"
12
+ puts res.reverse
13
+ end
14
+ """
15
+ When I run "ruby echo.rb" interactively
16
+ And I type "hello, world"
17
+ And I type "quit"
18
+ Then the output should contain:
19
+ """
20
+ dlrow ,olleh
21
+ """
22
+
23
+ Scenario: Running a native binary interactively
24
+ When I run "bc -q" interactively
25
+ And I type "4 + 3"
26
+ And I type "quit"
27
+ Then the output should contain:
28
+ """
29
+ 7
30
+ """
@@ -8,7 +8,7 @@ Feature: Output
8
8
  When I run "neverever gonna work"
9
9
  Then the output should contain:
10
10
  """
11
- sh: neverever: command not found
11
+ No such file or directory - neverever gonna work
12
12
  """
13
13
 
14
14
  Scenario: Detect subset of one-line output
@@ -83,6 +83,14 @@ Feature: Output
83
83
  hello
84
84
  """
85
85
 
86
+ @announce-stdout
87
+ Scenario: Match failing exit status and output with regex
88
+ When I run "ruby -e 'puts \"hello\\nworld\";exit 99'"
89
+ Then it should fail with regex:
90
+ """
91
+ hello\s*world
92
+ """
93
+
86
94
  @announce-cmd
87
95
  Scenario: Match output in stdout
88
96
  When I run "ruby -e 'puts \"hello\\nworld\"'"
@@ -1,7 +1,3 @@
1
- Given /^I have a local file named "([^"]*)" with:$/ do |filename, content|
2
- File.open(filename, 'w') {|io| io.write(content)}
3
- end
4
-
5
1
  When /^I do aruba (.*)$/ do |aruba_step|
6
2
  begin
7
3
  When(aruba_step)
@@ -10,15 +6,10 @@ When /^I do aruba (.*)$/ do |aruba_step|
10
6
  end
11
7
  end
12
8
 
13
- Then /^the output should contain the JRuby version$/ do
14
- pending "This must be manually run in JRuby" unless defined?(JRUBY_VERSION)
15
- Then %{the output should contain "#{JRUBY_VERSION}"}
16
- end
17
-
18
- Then /^the output should contain the current Ruby version$/ do
19
- Then %{the output should contain "#{RUBY_VERSION}"}
9
+ Then /^aruba should fail with "([^"]*)"$/ do |error_message|
10
+ @aruba_exception.message.should =~ regexp(error_message)
20
11
  end
21
12
 
22
- Then /^aruba should fail with "([^"]*)"$/ do |error_message|
23
- @aruba_exception.message.should =~ compile_and_escape(error_message)
13
+ Then /^the following step should fail with Spec::Expectations::ExpectationNotMetError:$/ do |multiline_step|
14
+ proc {steps multiline_step}.should raise_error(RSpec::Expectations::ExpectationNotMetError)
24
15
  end
data/lib/aruba/api.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'tempfile'
2
2
  require 'rbconfig'
3
+ require 'background_process'
3
4
 
4
5
  module Aruba
5
6
  module Api
@@ -54,7 +55,7 @@ module Aruba
54
55
  end
55
56
 
56
57
  def check_file_content(file, partial_content, expect_match)
57
- regexp = compile_and_escape(partial_content)
58
+ regexp = regexp(partial_content)
58
59
  in_current_dir do
59
60
  content = IO.read(file)
60
61
  if expect_match
@@ -91,16 +92,20 @@ module Aruba
91
92
  eval(%{"#{string}"})
92
93
  end
93
94
 
94
- def compile_and_escape(string)
95
- Regexp.compile(Regexp.escape(string))
95
+ def regexp(string_or_regexp)
96
+ Regexp === string_or_regexp ? string_or_regexp : Regexp.compile(Regexp.escape(string_or_regexp))
96
97
  end
97
98
 
98
99
  def combined_output
99
- @last_stdout + (@last_stderr == '' ? '' : "\n#{'-'*70}\n#{@last_stderr}")
100
+ if @interactive
101
+ interactive_output
102
+ else
103
+ @last_stdout + @last_stderr
104
+ end
100
105
  end
101
106
 
102
107
  def assert_partial_output(partial_output)
103
- combined_output.should =~ compile_and_escape(partial_output)
108
+ combined_output.should =~ regexp(partial_output)
104
109
  end
105
110
 
106
111
  def assert_passing_with(partial_output)
@@ -131,24 +136,16 @@ module Aruba
131
136
  def run(cmd, fail_on_error=true)
132
137
  cmd = detect_ruby(cmd)
133
138
 
134
- stderr_file = Tempfile.new('cucumber')
135
- stderr_file.close
136
139
  in_current_dir do
137
140
  announce_or_puts("$ cd #{Dir.pwd}") if @announce_dir
138
141
  announce_or_puts("$ #{cmd}") if @announce_cmd
139
-
140
- mode = RUBY_VERSION =~ /^1\.9/ ? {:external_encoding=>"UTF-8"} : 'r'
141
-
142
- IO.popen("#{cmd} 2> #{stderr_file.path}", mode) do |io|
143
- @last_stdout = io.read
144
- announce_or_puts(@last_stdout) if @announce_stdout
145
- end
146
-
147
- @last_exit_status = $?.exitstatus
142
+ ps = BackgroundProcess.run(cmd)
143
+ @last_exit_status = ps.exitstatus # waits for the process to finish
144
+ @last_stdout = ps.stdout.read
145
+ announce_or_puts(@last_stdout) if @announce_stdout
146
+ @last_stderr = ps.stderr.read
147
+ announce_or_puts(@last_stderr) if @announce_stderr
148
148
  end
149
- @last_stderr = IO.read(stderr_file.path)
150
-
151
- announce_or_puts(@last_stderr) if @announce_stderr
152
149
 
153
150
  if(@last_exit_status != 0 && fail_on_error)
154
151
  fail("Exit status was #{@last_exit_status}. Output:\n#{combined_output}")
@@ -157,6 +154,27 @@ module Aruba
157
154
  @last_stderr
158
155
  end
159
156
 
157
+ def run_interactive(cmd)
158
+ cmd = detect_ruby(cmd)
159
+
160
+ in_current_dir do
161
+ @interactive = BackgroundProcess.run(cmd)
162
+ end
163
+ end
164
+
165
+ def interactive_output
166
+ if @interactive
167
+ @interactive.wait(1) || @interactive.kill('TERM')
168
+ @interactive.stdout.read
169
+ else
170
+ ""
171
+ end
172
+ end
173
+
174
+ def write_interactive(input)
175
+ @interactive.stdin.write(input)
176
+ end
177
+
160
178
  def announce_or_puts(msg)
161
179
  if(@puts)
162
180
  puts(msg)
@@ -174,7 +192,7 @@ module Aruba
174
192
  end
175
193
 
176
194
  def current_ruby
177
- File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
195
+ File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
178
196
  end
179
197
 
180
198
  def use_clean_gemset(gemset)
@@ -216,5 +234,9 @@ module Aruba
216
234
  def original_env
217
235
  @original_env ||= {}
218
236
  end
237
+
238
+ def ensure_newline(str)
239
+ str.chomp << "\n"
240
+ end
219
241
  end
220
242
  end
@@ -6,12 +6,12 @@ Before('@disable-bundler') do
6
6
  unset_bundler_env_vars
7
7
  end
8
8
 
9
- Before('@bin') do
9
+ Before do
10
10
  @__aruba_original_paths = (ENV['PATH'] || '').split(File::PATH_SEPARATOR)
11
11
  ENV['PATH'] = ([File.expand_path('bin')] + @__aruba_original_paths).join(File::PATH_SEPARATOR)
12
12
  end
13
13
 
14
- After('@bin') do
14
+ After do
15
15
  ENV['PATH'] = @__aruba_original_paths.join(File::PATH_SEPARATOR)
16
16
  end
17
17
 
@@ -95,20 +95,28 @@ When /^I successfully run "(.*)"$/ do |cmd|
95
95
  run(unescape(cmd))
96
96
  end
97
97
 
98
+ When /^I run "([^"]*)" interactively$/ do |cmd|
99
+ run_interactive(unescape(cmd))
100
+ end
101
+
102
+ When /^I type "([^"]*)"$/ do |input|
103
+ write_interactive(ensure_newline(input))
104
+ end
105
+
98
106
  Then /^the output should contain "([^"]*)"$/ do |partial_output|
99
107
  assert_partial_output(partial_output)
100
108
  end
101
109
 
102
110
  Then /^the output should not contain "([^"]*)"$/ do |partial_output|
103
- combined_output.should_not =~ compile_and_escape(partial_output)
111
+ combined_output.should_not =~ regexp(partial_output)
104
112
  end
105
113
 
106
114
  Then /^the output should contain:$/ do |partial_output|
107
- combined_output.should =~ compile_and_escape(partial_output)
115
+ combined_output.should =~ regexp(partial_output)
108
116
  end
109
117
 
110
118
  Then /^the output should not contain:$/ do |partial_output|
111
- combined_output.should_not =~ compile_and_escape(partial_output)
119
+ combined_output.should_not =~ regexp(partial_output)
112
120
  end
113
121
 
114
122
  Then /^the output should contain exactly "([^"]*)"$/ do |exact_output|
@@ -143,20 +151,29 @@ Then /^it should (pass|fail) with:$/ do |pass_fail, partial_output|
143
151
  self.__send__("assert_#{pass_fail}ing_with", partial_output)
144
152
  end
145
153
 
154
+ Then /^it should (pass|fail) with regexp?:$/ do |pass_fail, partial_output|
155
+ Then "the output should match:", partial_output
156
+ if pass_fail == 'pass'
157
+ @last_exit_status.should == 0
158
+ else
159
+ @last_exit_status.should_not == 0
160
+ end
161
+ end
162
+
146
163
  Then /^the stderr should contain "([^"]*)"$/ do |partial_output|
147
- @last_stderr.should =~ compile_and_escape(partial_output)
164
+ @last_stderr.should =~ regexp(partial_output)
148
165
  end
149
166
 
150
167
  Then /^the stdout should contain "([^"]*)"$/ do |partial_output|
151
- @last_stdout.should =~ compile_and_escape(partial_output)
168
+ @last_stdout.should =~ regexp(partial_output)
152
169
  end
153
170
 
154
171
  Then /^the stderr should not contain "([^"]*)"$/ do |partial_output|
155
- @last_stderr.should_not =~ compile_and_escape(partial_output)
172
+ @last_stderr.should_not =~ regexp(partial_output)
156
173
  end
157
174
 
158
175
  Then /^the stdout should not contain "([^"]*)"$/ do |partial_output|
159
- @last_stdout.should_not =~ compile_and_escape(partial_output)
176
+ @last_stdout.should_not =~ regexp(partial_output)
160
177
  end
161
178
 
162
179
  Then /^the following files should exist:$/ do |files|
@@ -172,7 +189,7 @@ Then /^the following directories should exist:$/ do |directories|
172
189
  end
173
190
 
174
191
  Then /^the following directories should not exist:$/ do |directories|
175
- check_file_presence(directories.raw.map{|directory_row| directory_row[0]}, false)
192
+ check_directory_presence(directories.raw.map{|directory_row| directory_row[0]}, false)
176
193
  end
177
194
 
178
195
  Then /^the file "([^"]*)" should contain "([^"]*)"$/ do |file, partial_content|
@@ -186,3 +203,11 @@ end
186
203
  Then /^the file "([^"]*)" should contain exactly:$/ do |file, exact_content|
187
204
  check_exact_file_content(file, exact_content)
188
205
  end
206
+
207
+ Then /^the file "([^"]*)" should match \/([^\/]*)\/$/ do |file, partial_content|
208
+ check_file_content(file, /#{partial_content}/, true)
209
+ end
210
+
211
+ Then /^the file "([^"]*)" should not match \/([^\/]*)\/$/ do |file, partial_content|
212
+ check_file_content(file, /#{partial_content}/, false)
213
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aruba
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 17
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 2
9
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - "Aslak Helles\xC3\xB8y"
@@ -15,16 +16,46 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-09-28 00:00:00 +02:00
19
+ date: 2010-09-29 00:00:00 +02:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
- name: rspec
23
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
+ hash: 59
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 0
33
+ version: 0.9.0
34
+ requirement: *id001
35
+ type: :runtime
36
+ name: cucumber
37
+ prerelease: false
38
+ - !ruby/object:Gem::Dependency
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ type: :runtime
50
+ name: background_process
51
+ prerelease: false
52
+ - !ruby/object:Gem::Dependency
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 62196431
28
59
  segments:
29
60
  - 2
30
61
  - 0
@@ -32,9 +63,10 @@ dependencies:
32
63
  - beta
33
64
  - 22
34
65
  version: 2.0.0.beta.22
66
+ requirement: *id003
35
67
  type: :development
68
+ name: rspec
36
69
  prerelease: false
37
- version_requirements: *id001
38
70
  description: CLI Steps for Cucumber, hand-crafted for you in Aruba
39
71
  email: cukes@googlegroups.com
40
72
  executables: []
@@ -59,6 +91,7 @@ files:
59
91
  - config/.gitignore
60
92
  - features/exit_statuses.feature
61
93
  - features/file_system_commands.feature
94
+ - features/interactive.feature
62
95
  - features/output.feature
63
96
  - features/step_definitions/aruba_dev_steps.rb
64
97
  - features/support/env.rb
@@ -79,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
112
  requirements:
80
113
  - - ">="
81
114
  - !ruby/object:Gem::Version
82
- hash: -4569990399703836797
115
+ hash: 3
83
116
  segments:
84
117
  - 0
85
118
  version: "0"
@@ -88,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
121
  requirements:
89
122
  - - ">="
90
123
  - !ruby/object:Gem::Version
91
- hash: -4569990399703836797
124
+ hash: 3
92
125
  segments:
93
126
  - 0
94
127
  version: "0"
@@ -98,10 +131,11 @@ rubyforge_project:
98
131
  rubygems_version: 1.3.7
99
132
  signing_key:
100
133
  specification_version: 3
101
- summary: aruba-0.2.2
134
+ summary: aruba-0.2.3
102
135
  test_files:
103
136
  - features/exit_statuses.feature
104
137
  - features/file_system_commands.feature
138
+ - features/interactive.feature
105
139
  - features/output.feature
106
140
  - features/step_definitions/aruba_dev_steps.rb
107
141
  - features/support/env.rb