Skip to content

Commit

Permalink
Added ability to map rvm versions to a specific version with config/a…
Browse files Browse the repository at this point in the history
…ruba-rvm.yml
  • Loading branch information
aslakhellesoy committed Feb 24, 2010
1 parent 4230210 commit 989107a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,5 @@
== In Git == In Git
* Added ability to map rvm versions to a specific version with config/aruba-rvm.yml. (Aslak Hellesøy)
* Check for presence of files. (Aslak Hellesøy) * Check for presence of files. (Aslak Hellesøy)
* Allow specification of rvm gemsets. (Aslak Hellesøy) * Allow specification of rvm gemsets. (Aslak Hellesøy)
* Detect ruby commands and use current ruby when rvm is not explicitly used. (Aslak Hellesøy) * Detect ruby commands and use current ruby when rvm is not explicitly used. (Aslak Hellesøy)
Expand Down
1 change: 1 addition & 0 deletions config/.gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
aruba-rvm.yml
38 changes: 27 additions & 11 deletions features/running_ruby.feature
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ Feature: Running ruby
I want to have control over what Ruby version is used, I want to have control over what Ruby version is used,
possibly using a different Ruby than the one I launch Cucumber with. possibly using a different Ruby than the one I launch Cucumber with.


Scenario Outline: Specify a certain rvm Scenario: Run with ruby 1.9.1
Given I am using rvm "<rvm_ruby_version>" Given I am using rvm "1.9.1"
When I run "ruby -e 'puts RUBY_VERSION'" When I run "ruby -e 'puts RUBY_VERSION'"
Then I should see "<see>" Then I should see "ruby-1.9.1-p378"
And I should not see "<not_see>" And I should not see "rvm usage"


Examples: Scenario: Run with ruby JRuby
| rvm_ruby_version | see | not_see | Given I am using rvm "jruby-1.4.0"
| 1.9.1 | ruby-1.9.1-p378 | rvm usage | When I run "ruby -e 'puts JRUBY_VERSION'"
| jruby-1.4.0 | jruby 1.4.0 (ruby 1.8.7 patchlevel 174) | rvm usage | Then I should see "1.4.0"
| bogus | Unrecognized command line argument | XX | And I should not see "rvm usage"


Scenario: Specify both rvm and gemset Scenario: Specify both rvm and gemset
Given I am using rvm "1.9.1" Given I am using rvm "1.9.1"
Given I am using rvm gemset "a-gemset-where-nothing-is-installed-except-default-rvm-gems" And I am using rvm gemset "a-gemset-where-nothing-is-installed-except-default-rvm-gems"
When I run "ruby -S gem list" When I run "gem list"
Then I should see: Then I should see:
""" """
Expand All @@ -28,6 +28,22 @@ Feature: Running ruby
""" """


# I have trouble running rvm 1.8.7 in OS X Leopard, which is
# ruby-1.8.7-p249 (It segfaults rather often). However, a previous
# patchlevel of 1.8.7 runs fine for me: ruby-1.8.7-tv1_8_7_174
#
# In order to provide some level of flexibility (and readability)
# it should be possible to set up a mapping from a version specified
# in Gherkin to an *actual* version.
Scenario: Specify an alias for an rvm
Given I have a local file named "config/aruba-rvm.yml" with:
"""
1.8.7: ruby-1.8.7-tv1_8_7_174
"""
And I am using rvm "1.8.7"
When I run "ruby --version"
Then I should see "patchlevel 174"

# To verify this, make sure current rvm is *not* JRuby and run: # To verify this, make sure current rvm is *not* JRuby and run:
# #
# ~/.rvm/rubies/jruby-1.4.0/bin/jruby -S cucumber features/running_ruby.feature # ~/.rvm/rubies/jruby-1.4.0/bin/jruby -S cucumber features/running_ruby.feature
Expand Down
4 changes: 4 additions & 0 deletions features/support/step_definitions.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,7 @@
Given /^I have a local file named "([^\"]*)" with:$/ do |filename, content|
File.open(filename, 'w') {|io| io.write(content)}
end

Then /^I should see the JRuby version$/ do Then /^I should see the JRuby version$/ do
Then %{I should see "#{JRUBY_VERSION}"} Then %{I should see "#{JRUBY_VERSION}"}
end end
19 changes: 15 additions & 4 deletions lib/aruba/api.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ def combined_output
end end


def use_rvm(rvm_ruby_version) def use_rvm(rvm_ruby_version)
@rvm_ruby_version = rvm_ruby_version if File.exist?('config/aruba-rvm.yml')
@rvm_ruby_version = YAML.load_file('config/aruba-rvm.yml')[rvm_ruby_version] || rvm_ruby_version
else
@rvm_ruby_version = rvm_ruby_version
end
end end


def use_rvm_gemset(rvm_gemset) def use_rvm_gemset(rvm_gemset)
Expand All @@ -90,13 +94,20 @@ def run(command, world=nil, announce=nil)
@last_stderr = IO.read(stderr_file.path) @last_stderr = IO.read(stderr_file.path)
end end


RUBY_PATTERN = /^ruby\s/
RUBY_SCRIPTS_PATTERN = /^(?:gem|rake)\s/

def detect_ruby(command) def detect_ruby(command)
if command =~ /^ruby\s/ ruby_command = command =~ RUBY_PATTERN
ruby_script = command =~ RUBY_SCRIPTS_PATTERN
if ruby_command || ruby_script
if @rvm_ruby_version if @rvm_ruby_version
rvm_ruby_version_with_gemset = @rvm_gemset ? "#{@rvm_ruby_version}%#{@rvm_gemset}" : @rvm_ruby_version rvm_ruby_version_with_gemset = @rvm_gemset ? "#{@rvm_ruby_version}%#{@rvm_gemset}" : @rvm_ruby_version
command.gsub(/^ruby\s/, "rvm #{rvm_ruby_version_with_gemset} ") command = "rvm #{rvm_ruby_version_with_gemset} #{command}"
else elsif ruby_command
command.gsub(/^ruby\s/, "#{File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])} ") command.gsub(/^ruby\s/, "#{File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])} ")
else
"#{File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])} -S #{command}"
end end
else else
command command
Expand Down

0 comments on commit 989107a

Please sign in to comment.