Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic ruby version test #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions test_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,28 @@ def test_ruby_setup
end
end

LATEST_RUBY_VERSION = %x(curl -sSL http://ruby.thoughtbot.com/latest)

def test_ruby_isnt_system
ruby_is_system = %x(which ruby).chomp == "/usr/bin/ruby"

return true unless ruby_is_system

error "ruby is not managed by a ruby version manager. Install rbenv, then run `rbenv install 2.2.0`."
error "ruby is not managed by a ruby version manager. Install rbenv, then run `rbenv install #{LATEST_RUBY_VERSION}`."
end

RUBY_VERSIONS = %w(2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0)
def test_ruby_version
ruby_version = %x(ruby -v | cut -d ' ' -f 2).chomp.split("p").first

return true if RUBY_VERSIONS.include?(ruby_version)

error "ruby is out of date (current running #{ruby_version}). Install rbenv, then run `rbenv install 2.2.0`."
return unless ruby_version_manager

latest_installed = if ruby_version_manager == :rbenv
/\d.+?(?=\s)/.match(%x(rbenv versions).split("\n").last)[-1]
else
%x(rvm rubies).split("ruby-").last.split(" ").first
end
Copy link
Owner

@mikelikesbikes mikelikesbikes Oct 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things here:

  1. Can you update the parsing bits to use https://github.com/mikelikesbikes/environment_linter/blob/master/test_setup.rb#L394-L431
  2. Pull the details out into a method installed_rubies
  3. Add a default for non-rvm/rbenv users, maybe just the currently running ruby in an array.


return true if latest_installed == LATEST_RUBY_VERSION

error "A newer stable version of Ruby is available. Install rbenv, then run `rbenv install #{LATEST_RUBY_VERSION}`."
end

def test_rubygems_location
Expand Down