aruba 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.1.5
2
+ * Added ability to map rvm versions to a specific version with config/aruba-rvm.yml. (Aslak Hellesøy)
3
+ * Check for presence of files. (Aslak Hellesøy)
4
+ * Allow specification of rvm gemsets. (Aslak Hellesøy)
5
+ * Detect ruby commands and use current ruby when rvm is not explicitly used. (Aslak Hellesøy)
6
+ * Added support for rvm, making it possible to choose Ruby interpreter. (Aslak Hellesøy)
7
+ * Added @announce-cmd, @announce-stdout and @announce tags, useful for seeing what's executed and outputted. (Aslak Hellesøy)
8
+
1
9
  == 0.1.4
2
10
  * New step definition for appending to a file (Aslak Hellesøy)
3
11
 
data/Rakefile CHANGED
@@ -1,14 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require 'rubygems'
2
3
  require 'rake'
3
4
 
4
5
  begin
5
6
  require 'jeweler'
6
7
  Jeweler::Tasks.new do |gem|
7
- gem.version = "0.1.4"
8
+ gem.version = "0.1.5"
8
9
  gem.name = "aruba"
9
10
  gem.summary = %Q{CLI Steps for Cucumber}
10
11
  gem.description = %Q{CLI Steps for Cucumber, hand-crafted for you in Aruba}
11
- gem.email = "cukes@groups.google.com"
12
+ gem.email = "cukes@googlegroups.com"
12
13
  gem.homepage = "http://github.com/aslakhellesoy/aruba"
13
14
  gem.authors = ["Aslak Hellesøy", "David Chelimsky"]
14
15
  gem.add_development_dependency "rspec", ">= 1.3.0"
@@ -22,17 +23,12 @@ end
22
23
  begin
23
24
  require 'cucumber/rake/task'
24
25
 
25
- namespace :cucumber do
26
- Cucumber::Rake::Task.new(:pass) do |t|
27
- t.cucumber_opts = '--tags ~@fail'
28
- end
29
-
30
- Cucumber::Rake::Task.new(:fail) do |t|
31
- t.cucumber_opts = '--tags @fail --wip'
32
- end
26
+ Cucumber::Rake::Task.new do |t|
27
+ t.cucumber_opts = %w{--tags ~@jruby} unless defined?(JRUBY_VERSION)
28
+ t.rcov = true
33
29
  end
34
30
 
35
- task :cucumber => [:check_dependencies, 'cucumber:pass', 'cucumber:fail']
31
+ task :cucumber => :check_dependencies
36
32
  rescue LoadError
37
33
  task :cucumber do
38
34
  abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
data/aruba.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aruba}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aslak Helles\303\270y", "David Chelimsky"]
12
- s.date = %q{2010-02-23}
12
+ s.date = %q{2010-02-26}
13
13
  s.description = %q{CLI Steps for Cucumber, hand-crafted for you in Aruba}
14
- s.email = %q{cukes@groups.google.com}
14
+ s.email = %q{cukes@googlegroups.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -24,10 +24,12 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "aruba.gemspec",
27
+ "config/.gitignore",
27
28
  "features/exit_statuses.feature",
28
29
  "features/file_system_commands.feature",
29
30
  "features/output.feature",
30
- "features/step_definitions/aruba_steps.rb",
31
+ "features/running_ruby.feature",
32
+ "features/step_definitions/aruba_dev_steps.rb",
31
33
  "features/support/env.rb",
32
34
  "lib/aruba.rb",
33
35
  "lib/aruba/api.rb",
data/config/.gitignore ADDED
@@ -0,0 +1 @@
1
+ aruba-rvm.yml
@@ -12,3 +12,10 @@ Feature: exit statuses
12
12
  When I run "ruby -e 'exit 56'"
13
13
  Then the exit status should be 56
14
14
  And the exit status should not be 0
15
+
16
+ Scenario: Successfully run something
17
+ When I successfully run "ruby -e 'exit 0'"
18
+
19
+ Scenario: Unsuccessfully run something
20
+ When I do aruba I successfully run "ruby -e 'exit 10'"
21
+ Then aruba should fail with "got: 10"
@@ -48,10 +48,30 @@ Feature: file system commands
48
48
  When I run "ruby example.rb"
49
49
  Then the exit status should be 1
50
50
 
51
- @fail
52
51
  Scenario: Holler if cd to bad dir
53
52
  Given a file named "foo/bar/example.rb" with:
54
53
  """
55
54
  puts "hello world"
56
55
  """
57
- When I cd to "foo/nonexistant"
56
+ When I do aruba I cd to "foo/nonexistant"
57
+ Then aruba should fail with "tmp/aruba/foo/nonexistant is not a directory"
58
+
59
+ Scenario: Check for presence of a subset of files
60
+ Given an empty file named "lorem/ipsum/dolor"
61
+ Given an empty file named "lorem/ipsum/sit"
62
+ Given an empty file named "lorem/ipsum/amet"
63
+ Then the following files should exist:
64
+ | lorem/ipsum/dolor |
65
+ | lorem/ipsum/amet |
66
+
67
+ Scenario: Check for absence of files
68
+ Then the following files should not exist:
69
+ | lorem/ipsum/dolor |
70
+
71
+ Scenario: Check file contents
72
+ Given a file named "foo" with:
73
+ """
74
+ hello world
75
+ """
76
+ Then the file "foo" should contain "hello world"
77
+ And the file "foo" should not contain "HELLO WORLD"
@@ -8,19 +8,23 @@ Feature: Output
8
8
  When I run "ruby -e 'puts \"hello world\"'"
9
9
  Then I should see "hello world"
10
10
 
11
+ Scenario: Detect subset of one-line output
12
+ When I run "echo 'hello world'"
13
+ Then I should see "hello world"
14
+
11
15
  Scenario: Detect absence of one-line output
12
16
  When I run "ruby -e 'puts \"hello world\"'"
13
17
  Then I should not see "good-bye"
14
18
 
15
19
  Scenario: Detect subset of multiline output
16
- When I run "ruby -e 'puts \"hello\nworld\"'"
20
+ When I run "ruby -e 'puts \"hello\\nworld\"'"
17
21
  Then I should see:
18
22
  """
19
23
  hello
20
24
  """
21
25
 
22
26
  Scenario: Detect subset of multiline output
23
- When I run "ruby -e 'puts \"hello\nworld\"'"
27
+ When I run "ruby -e 'puts \"hello\\nworld\"'"
24
28
  Then I should not see:
25
29
  """
26
30
  good-bye
@@ -31,7 +35,7 @@ Feature: Output
31
35
  Then I should see exactly "hello world\n"
32
36
 
33
37
  Scenario: Detect exact multiline output
34
- When I run "ruby -e 'puts \"hello\nworld\"'"
38
+ When I run "ruby -e 'puts \"hello\\nworld\"'"
35
39
  Then I should see exactly:
36
40
  """
37
41
  hello
@@ -39,26 +43,29 @@ Feature: Output
39
43
 
40
44
  """
41
45
 
46
+ @announce
42
47
  Scenario: Match passing exit status and partial output
43
- When I run "ruby -e 'puts \"hello\nworld\"'"
48
+ When I run "ruby -e 'puts \"hello\\nworld\"'"
44
49
  Then it should pass with:
45
50
  """
46
51
  hello
47
52
  """
48
53
 
54
+ @announce-stdout
49
55
  Scenario: Match failing exit status and partial output
50
- When I run "ruby -e 'puts \"hello\nworld\";exit 99'"
56
+ When I run "ruby -e 'puts \"hello\\nworld\";exit 99'"
51
57
  Then it should fail with:
52
58
  """
53
59
  hello
54
60
  """
55
-
61
+
62
+ @announce-cmd
56
63
  Scenario: Match output in stdout
57
- When I run "ruby -e 'puts \"hello\nworld\"'"
64
+ When I run "ruby -e 'puts \"hello\\nworld\"'"
58
65
  Then the stdout should contain "hello"
59
66
  Then the stderr should not contain "hello"
60
67
 
61
68
  Scenario: Match output in stderr
62
- When I run "ruby -e 'STDERR.puts \"hello\nworld\";exit 99'"
69
+ When I run "ruby -e 'STDERR.puts \"hello\\nworld\";exit 99'"
63
70
  Then the stderr should contain "hello"
64
71
  Then the stdout should not contain "hello"
@@ -0,0 +1,74 @@
1
+ @announce
2
+ Feature: Running ruby
3
+ In order to test a Ruby-based CLI app
4
+ I want to have control over what Ruby version is used,
5
+ possibly using a different Ruby than the one I launch Cucumber with.
6
+
7
+ Scenario: Run with ruby 1.9.1
8
+ Given I am using rvm "1.9.1"
9
+ When I run "ruby -e 'puts RUBY_VERSION'"
10
+ Then I should see "ruby-1.9.1-p378"
11
+ And I should not see "rvm usage"
12
+
13
+ Scenario: Run with ruby JRuby
14
+ Given I am using rvm "jruby-1.4.0"
15
+ When I run "ruby -e 'puts JRUBY_VERSION'"
16
+ Then I should see "1.4.0"
17
+ And I should not see "rvm usage"
18
+
19
+ Scenario: Specify both rvm and gemset
20
+ Given I am using rvm "1.9.1"
21
+ And I am using rvm gemset "a-gemset-where-nothing-is-installed-except-default-rvm-gems"
22
+ When I run "gem list"
23
+ Then I should see:
24
+ """
25
+
26
+ rake (0.8.7)
27
+ rubygems-update (1.3.5)
28
+
29
+ """
30
+
31
+ Scenario: Find the version of ruby 1.9.1
32
+ Given I am using rvm "1.9.1"
33
+ When I run "ruby --version"
34
+ Then I should see "1.9.1"
35
+
36
+ Scenario: Find the version of cucumber on ruby 1.9.1
37
+ Given I am using rvm "1.9.1"
38
+ When I run "cucumber --version"
39
+ Then I should see "0.6.2"
40
+
41
+ Scenario: Use current ruby
42
+ When I run "ruby --version"
43
+ Then I should see the current Ruby version
44
+
45
+ Scenario: Use current ruby and a gem bin file
46
+ When I run "rake --version"
47
+ Then I should see "rake, version"
48
+
49
+ # I have trouble running rvm 1.8.7 in OS X Leopard, which is
50
+ # ruby-1.8.7-p249 (It segfaults rather often). However, a previous
51
+ # patchlevel of 1.8.7 runs fine for me: ruby-1.8.7-tv1_8_7_174
52
+ #
53
+ # In order to provide some level of flexibility (and readability)
54
+ # it should be possible to set up a mapping from a version specified
55
+ # in Gherkin to an *actual* version.
56
+ #
57
+ # In order to make this scenario pass you therefore need to install
58
+ # ruby-1.8.7-tv1_8_7_174 with rvm.
59
+ Scenario: Specify an alias for an rvm
60
+ Given I have a local file named "config/aruba-rvm.yml" with:
61
+ """
62
+ 1.8.7: ruby-1.8.7-tv1_8_7_174
63
+ """
64
+ And I am using rvm "1.8.7"
65
+ When I run "ruby --version"
66
+ Then I should see "patchlevel 174"
67
+
68
+ # To verify this, make sure current rvm is *not* JRuby and run:
69
+ #
70
+ # ~/.rvm/rubies/jruby-1.4.0/bin/jruby -S cucumber features/running_ruby.feature -n "launched Cucumber"
71
+ @jruby
72
+ Scenario: Don't use rvm, but default to same Ruby as the one that launched Cucumber
73
+ When I run "ruby -e 'puts JRUBY_VERSION'"
74
+ Then I should see the JRuby version
@@ -0,0 +1,23 @@
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
+ When /^I do aruba (.*)$/ do |aruba_step|
6
+ begin
7
+ When(aruba_step)
8
+ rescue => e
9
+ @aruba_exception = e
10
+ end
11
+ end
12
+
13
+ Then /^I should see the JRuby version$/ do
14
+ Then %{I should see "#{JRUBY_VERSION}"}
15
+ end
16
+
17
+ Then /^I should see the current Ruby version$/ do
18
+ Then %{I should see "#{RUBY_VERSION}"}
19
+ end
20
+
21
+ Then /^aruba should fail with "([^\"]*)"$/ do |error_message|
22
+ @aruba_exception.message.should =~ compile_and_escape(error_message)
23
+ end
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
2
  require 'aruba'
3
+ require 'fileutils'
3
4
 
4
5
  begin
5
6
  # rspec-2
@@ -8,3 +9,7 @@ rescue LoadError
8
9
  # rspec-1
9
10
  require 'spec/expectations'
10
11
  end
12
+
13
+ Before do
14
+ FileUtils.rm(Dir['config/*.yml'])
15
+ end
data/lib/aruba/api.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tempfile'
2
+ require 'rbconfig'
2
3
 
3
4
  module Aruba
4
5
  module Api
@@ -39,6 +40,30 @@ module Api
39
40
  end
40
41
  end
41
42
 
43
+ def check_file_presence(paths, expect_presence)
44
+ in_current_dir do
45
+ paths.each do |path|
46
+ if expect_presence
47
+ File.should be_file(path)
48
+ else
49
+ File.should_not be_file(path)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def check_file_content(file, partial_content, expect_match)
56
+ regexp = compile_and_escape(partial_content)
57
+ in_current_dir do
58
+ content = IO.read(file)
59
+ if expect_match
60
+ content.should match(regexp)
61
+ else
62
+ content.should_not match(regexp)
63
+ end
64
+ end
65
+ end
66
+
42
67
  def _mkdir(dir_name)
43
68
  FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
44
69
  end
@@ -55,18 +80,62 @@ module Api
55
80
  @last_stdout + (@last_stderr == '' ? '' : "\n#{'-'*70}\n#{@last_stderr}")
56
81
  end
57
82
 
58
- def run(command)
83
+ def use_rvm(rvm_ruby_version)
84
+ if File.exist?('config/aruba-rvm.yml')
85
+ @rvm_ruby_version = YAML.load_file('config/aruba-rvm.yml')[rvm_ruby_version] || rvm_ruby_version
86
+ else
87
+ @rvm_ruby_version = rvm_ruby_version
88
+ end
89
+ end
90
+
91
+ def use_rvm_gemset(rvm_gemset)
92
+ @rvm_gemset = rvm_gemset
93
+ end
94
+
95
+ def run(cmd)
96
+ cmd = detect_ruby_script(cmd)
97
+ cmd = detect_ruby(cmd)
98
+
99
+ announce("$ #{cmd}") if @announce_cmd
100
+
59
101
  stderr_file = Tempfile.new('cucumber')
60
102
  stderr_file.close
61
103
  in_current_dir do
62
104
  mode = RUBY_VERSION =~ /^1\.9/ ? {:external_encoding=>"UTF-8"} : 'r'
63
- IO.popen("#{command} 2> #{stderr_file.path}", mode) do |io|
105
+ IO.popen("#{cmd} 2> #{stderr_file.path}", mode) do |io|
64
106
  @last_stdout = io.read
107
+
108
+ announce(@last_stdout) if @announce_stdout
65
109
  end
66
110
 
67
111
  @last_exit_status = $?.exitstatus
68
112
  end
69
113
  @last_stderr = IO.read(stderr_file.path)
70
114
  end
115
+
116
+ def detect_ruby(cmd)
117
+ if cmd =~ /^ruby\s/
118
+ cmd.gsub(/^ruby\s/, "#{current_ruby} ")
119
+ else
120
+ cmd
121
+ end
122
+ end
123
+
124
+ def detect_ruby_script(cmd)
125
+ if cmd =~ /^(?:cucumber|gem|jeweler|rails|rake|rspec|spec)\s/
126
+ "ruby -S #{cmd}"
127
+ else
128
+ cmd
129
+ end
130
+ end
131
+
132
+ def current_ruby
133
+ if @rvm_ruby_version
134
+ rvm_ruby_version_with_gemset = @rvm_gemset ? "#{@rvm_ruby_version}%#{@rvm_gemset}" : @rvm_ruby_version
135
+ "rvm #{rvm_ruby_version_with_gemset} ruby"
136
+ else
137
+ File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
138
+ end
139
+ end
71
140
  end
72
141
  end
@@ -6,6 +6,27 @@ Before do
6
6
  FileUtils.rm_rf(current_dir)
7
7
  end
8
8
 
9
+ Before('@announce-cmd') do
10
+ @announce_cmd = true
11
+ end
12
+
13
+ Before('@announce-stdout') do
14
+ @announce_stdout = true
15
+ end
16
+
17
+ Before('@announce') do
18
+ @announce_stdout = true
19
+ @announce_cmd = true
20
+ end
21
+
22
+ Given /^I am using rvm "([^\"]*)"$/ do |rvm_ruby_version|
23
+ use_rvm(rvm_ruby_version)
24
+ end
25
+
26
+ Given /^I am using rvm gemset "([^\"]*)"$/ do |rvm_gemset|
27
+ use_rvm_gemset(rvm_gemset)
28
+ end
29
+
9
30
  Given /^a directory named "([^\"]*)"$/ do |dir_name|
10
31
  create_dir(dir_name)
11
32
  end
@@ -14,6 +35,10 @@ Given /^a file named "([^\"]*)" with:$/ do |file_name, file_content|
14
35
  create_file(file_name, file_content)
15
36
  end
16
37
 
38
+ Given /^an empty file named "([^\"]*)"$/ do |file_name|
39
+ create_file(file_name, "")
40
+ end
41
+
17
42
  When /^I append to "([^\"]*)" with:$/ do |file_name, file_content|
18
43
  append_to_file(file_name, file_content)
19
44
  end
@@ -26,6 +51,11 @@ When /^I run "(.*)"$/ do |cmd|
26
51
  run(unescape(cmd))
27
52
  end
28
53
 
54
+ When /^I successfully run "(.*)"$/ do |cmd|
55
+ run(unescape(cmd))
56
+ @last_exit_status.should == 0
57
+ end
58
+
29
59
  Then /^I should see "([^\"]*)"$/ do |partial_output|
30
60
  combined_output.should =~ compile_and_escape(partial_output)
31
61
  end
@@ -59,12 +89,12 @@ Then /^the exit status should not be (\d+)$/ do |exit_status|
59
89
  end
60
90
 
61
91
  Then /^it should (pass|fail) with:$/ do |pass_fail, partial_output|
92
+ Then "I should see:", partial_output
62
93
  if pass_fail == 'pass'
63
94
  @last_exit_status.should == 0
64
95
  else
65
96
  @last_exit_status.should_not == 0
66
97
  end
67
- Then "I should see:", partial_output
68
98
  end
69
99
 
70
100
  Then /^the stderr should contain "([^\"]*)"$/ do |partial_output|
@@ -82,3 +112,19 @@ end
82
112
  Then /^the stdout should not contain "([^\"]*)"$/ do |partial_output|
83
113
  @last_stdout.should_not =~ compile_and_escape(partial_output)
84
114
  end
115
+
116
+ Then /^the following files should exist:$/ do |files|
117
+ check_file_presence(files.raw.map{|file_row| file_row[0]}, true)
118
+ end
119
+
120
+ Then /^the following files should not exist:$/ do |files|
121
+ check_file_presence(files.raw.map{|file_row| file_row[0]}, false)
122
+ end
123
+
124
+ Then /^the file "([^\"]*)" should contain "([^\"]*)"$/ do |file, partial_content|
125
+ check_file_content(file, partial_content, true)
126
+ end
127
+
128
+ Then /^the file "([^\"]*)" should not contain "([^\"]*)"$/ do |file, partial_content|
129
+ check_file_content(file, partial_content, false)
130
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Aslak Helles\xC3\xB8y"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-02-23 00:00:00 +01:00
18
+ date: 2010-02-26 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -47,7 +47,7 @@ dependencies:
47
47
  type: :development
48
48
  version_requirements: *id002
49
49
  description: CLI Steps for Cucumber, hand-crafted for you in Aruba
50
- email: cukes@groups.google.com
50
+ email: cukes@googlegroups.com
51
51
  executables: []
52
52
 
53
53
  extensions: []
@@ -63,10 +63,12 @@ files:
63
63
  - README.rdoc
64
64
  - Rakefile
65
65
  - aruba.gemspec
66
+ - config/.gitignore
66
67
  - features/exit_statuses.feature
67
68
  - features/file_system_commands.feature
68
69
  - features/output.feature
69
- - features/step_definitions/aruba_steps.rb
70
+ - features/running_ruby.feature
71
+ - features/step_definitions/aruba_dev_steps.rb
70
72
  - features/support/env.rb
71
73
  - lib/aruba.rb
72
74
  - lib/aruba/api.rb
File without changes