Skip to content

Commit

Permalink
Make Appraisal compatible with Ruby 1.8.7
Browse files Browse the repository at this point in the history
This includes:

* Lock some dependencies to version that supports Ruby 1.8.7 when
  running on Ruby 1.8.7.
* Remove usage of `require_relative`.
* Use old style of hash syntax throughout the code.
* Explicitly set `ENV` override as `Kernel#system` on Ruby 1.8.7 does
  not take first `env` argument.
* Use `ActiveSupport::OrderedHash` on dependencies list to maintain the
  hash ordering.
* Active Support become part of runtime dependency.

This also adds Ruby 1.8.7 to build matrix.
  • Loading branch information
Prem Sichanugrist committed Apr 1, 2015
1 parent d908b9a commit eb7e0f2
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 36 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ sudo: false
before_install: gem install bundler

rvm:
- 1.8
- 1.9
- 2.0
- 2.1
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Expand Up @@ -4,3 +4,8 @@ gemspec

# This here to make sure appraisal works with Rails 3.0.0.
gem 'thor', '~> 0.14.0'

if RUBY_VERSION < "1.9"
gem "i18n", "~> 0.6.0"
gem "activesupport", "~> 3.2.21"
end
2 changes: 1 addition & 1 deletion appraisal.gemspec
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('rake')
s.add_runtime_dependency('bundler')
s.add_runtime_dependency('thor', '>= 0.14.0')
s.add_runtime_dependency("activesupport", ">= 3.2.21")

s.add_development_dependency('activesupport', '>= 3.2.13')
s.add_development_dependency('rspec', '~> 3.0')
end
6 changes: 5 additions & 1 deletion lib/appraisal/command.rb
Expand Up @@ -19,7 +19,11 @@ def run
announce

with_clean_env do
unless Kernel.system(env, command_as_string)
env.each_pair do |key, value|
ENV[key] = value
end

unless Kernel.system(command_as_string)
exit(1)
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/appraisal/dependency_list.rb
@@ -1,9 +1,10 @@
require 'appraisal/dependency'
require "active_support/ordered_hash"

module Appraisal
class DependencyList
def initialize
@dependencies = {}
@dependencies = ActiveSupport::OrderedHash.new
end

def add(name, requirements)
Expand Down
9 changes: 5 additions & 4 deletions lib/appraisal/gemfile.rb
Expand Up @@ -4,6 +4,7 @@
require 'appraisal/path_source'
require 'appraisal/group'
require 'appraisal/platform'
require "active_support/ordered_hash"

module Appraisal
# Load bundler Gemfiles and merge dependencies
Expand All @@ -18,10 +19,10 @@ def initialize
@ruby_version = nil
@dependencies = DependencyList.new
@gemspec = nil
@groups = {}
@platforms = {}
@git_sources = {}
@path_sources = {}
@groups = ActiveSupport::OrderedHash.new
@platforms = ActiveSupport::OrderedHash.new
@git_sources = ActiveSupport::OrderedHash.new
@path_sources = ActiveSupport::OrderedHash.new
end

def load(path)
Expand Down
Expand Up @@ -27,7 +27,7 @@
gem 'milk'
end
gem 'appraisal', path: #{PROJECT_ROOT.inspect}
gem 'appraisal', :path => #{PROJECT_ROOT.inspect}
Gemfile

build_appraisal_file <<-Appraisals
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/bundle_with_custom_path_spec.rb
Expand Up @@ -5,7 +5,7 @@
build_gemfile <<-Gemfile
source "https://rubygems.org"
gem 'appraisal', path: #{PROJECT_ROOT.inspect}
gem 'appraisal', :path => #{PROJECT_ROOT.inspect}
Gemfile

build_appraisal_file <<-Appraisals
Expand Down
6 changes: 6 additions & 0 deletions spec/acceptance/cli/generate_spec.rb
Expand Up @@ -2,6 +2,12 @@

describe 'CLI', 'appraisal generate' do
it 'generates the gemfiles' do
build_gemfile <<-Gemfile
source "https://rubygems.org"
gem "appraisal", :path => "#{PROJECT_ROOT}"
Gemfile

build_appraisal_file <<-Appraisal
appraise '1.0.0' do
gem 'dummy', '1.0.0'
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/cli/install_spec.rb
Expand Up @@ -40,7 +40,7 @@
current_directory
end

context 'with job size', parallel: true do
context 'with job size', :parallel => true do
before do
build_appraisal_file <<-Appraisal
appraise '1.0.0' do
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/gemfile_dsl_compatibility_spec.rb
Expand Up @@ -26,7 +26,7 @@
gem "waffle"
end
gem 'appraisal', path: #{PROJECT_ROOT.inspect}
gem 'appraisal', :path => #{PROJECT_ROOT.inspect}
gemspec
Gemfile
Expand Down Expand Up @@ -111,7 +111,7 @@
build_gem "bacon", "1.2.0"

build_gemfile <<-Gemfile
gem "appraisal", path: #{PROJECT_ROOT.inspect}
gem "appraisal", :path => #{PROJECT_ROOT.inspect}
gem "bacon", "1.2.0"
Gemfile

Expand Down Expand Up @@ -142,7 +142,7 @@
build_gemspec

build_gemfile <<-Gemfile
gem "appraisal", path: #{PROJECT_ROOT.inspect}
gem "appraisal", :path => #{PROJECT_ROOT.inspect}
group :plugin do
gemspec
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/gemspec_spec.rb
Expand Up @@ -10,7 +10,7 @@
build_gemspec

write_file 'Gemfile', <<-Gemfile
gem 'appraisal', path: #{PROJECT_ROOT.inspect}
gem 'appraisal', :path => #{PROJECT_ROOT.inspect}
gemspec
Gemfile
Expand All @@ -26,9 +26,9 @@
build_gemspec 'specdir'

write_file 'Gemfile', <<-Gemfile
gem 'appraisal', path: #{PROJECT_ROOT.inspect}
gem 'appraisal', :path => #{PROJECT_ROOT.inspect}
gemspec path: './specdir'
gemspec :path => './specdir'
Gemfile

run 'bundle install --local'
Expand Down
16 changes: 8 additions & 8 deletions spec/appraisal/gemfile_spec.rb
Expand Up @@ -112,21 +112,21 @@
context "in :path option" do
it "handles dot path" do
gemfile = Appraisal::Gemfile.new
gemfile.gem "bacon", path: "."
gemfile.gem "bacon", :path => "."

expect(gemfile.to_s).to eq %(gem "bacon", :path => "../")
end

it "handles relative path" do
gemfile = Appraisal::Gemfile.new
gemfile.gem "bacon", path: "../bacon"
gemfile.gem "bacon", :path => "../bacon"

expect(gemfile.to_s).to eq %(gem "bacon", :path => "../../bacon")
end

it "handles absolute path" do
gemfile = Appraisal::Gemfile.new
gemfile.gem "bacon", path: "/tmp"
gemfile.gem "bacon", :path => "/tmp"

expect(gemfile.to_s).to eq %(gem "bacon", :path => "/tmp")
end
Expand All @@ -135,28 +135,28 @@
context "in :git option" do
it "handles dot git path" do
gemfile = Appraisal::Gemfile.new
gemfile.gem "bacon", git: "."
gemfile.gem "bacon", :git => "."

expect(gemfile.to_s).to eq %(gem "bacon", :git => "../")
end

it "handles relative git path" do
gemfile = Appraisal::Gemfile.new
gemfile.gem "bacon", git: "../bacon"
gemfile.gem "bacon", :git => "../bacon"

expect(gemfile.to_s).to eq %(gem "bacon", :git => "../../bacon")
end

it "handles absolute git path" do
gemfile = Appraisal::Gemfile.new
gemfile.gem "bacon", git: "/tmp"
gemfile.gem "bacon", :git => "/tmp"

expect(gemfile.to_s).to eq %(gem "bacon", :git => "/tmp")
end

it "handles git uri" do
gemfile = Appraisal::Gemfile.new
gemfile.gem "bacon", git: "git@github.com:bacon/bacon.git"
gemfile.gem "bacon", :git => "git@github.com:bacon/bacon.git"

expect(gemfile.to_s).
to eq %(gem "bacon", :git => "git@github.com:bacon/bacon.git")
Expand Down Expand Up @@ -268,7 +268,7 @@
context "in gemspec directive" do
it "handles gemspec path" do
gemfile = Appraisal::Gemfile.new
gemfile.gemspec path: "."
gemfile.gemspec :path => "."

expect(gemfile.to_s).to eq %(gemspec :path => "../")
end
Expand Down
11 changes: 6 additions & 5 deletions spec/appraisal/utils_spec.rb
Expand Up @@ -4,17 +4,18 @@
describe Appraisal::Utils do
describe '.format_string' do
it 'prints out a nice looking hash without a brackets' do
hash = { :foo => 'bar', 'baz' => { :ball => 'boo' } }
hash = { :foo => 'bar' }
expect(Appraisal::Utils.format_string(hash)).to eq(':foo => "bar"')

expect(Appraisal::Utils.format_string(hash)).to eq(
':foo => "bar", "baz" => { :ball => "boo" }'
)
hash = { 'baz' => { :ball => 'boo' }}
expect(Appraisal::Utils.format_string(hash)).
to eq('"baz" => { :ball => "boo" }')
end
end

describe '.format_arguments' do
it 'prints out arguments without enclosing square brackets' do
arguments = [:foo, bar: { baz: 'ball' }]
arguments = [:foo, { :bar => { :baz => 'ball' }}]

expect(Appraisal::Utils.format_arguments(arguments)).to eq(
':foo, :bar => { :baz => "ball" }'
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
@@ -1,7 +1,7 @@
require 'rubygems'
require 'bundler/setup'
require_relative 'support/acceptance_test_helpers'
require_relative 'support/stream_helpers'
require "./spec/support/acceptance_test_helpers"
require "./spec/support/stream_helpers"

PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
TMP_GEM_ROOT = File.join(PROJECT_ROOT, "tmp", "gems")
Expand Down
13 changes: 8 additions & 5 deletions spec/support/acceptance_test_helpers.rb
Expand Up @@ -3,7 +3,7 @@
require 'active_support/core_ext/string/filters'
require 'active_support/concern'
require 'appraisal/utils'
require_relative 'dependency_helpers'
require "./spec/support/dependency_helpers"

module AcceptanceTestHelpers
extend ActiveSupport::Concern
Expand All @@ -15,7 +15,7 @@ module AcceptanceTestHelpers
included do
metadata[:type] = :acceptance

before parallel: true do
before :parallel => true do
unless Appraisal::Utils.support_parallel_installation?
pending 'This Bundler version does not support --jobs flag.'
end
Expand Down Expand Up @@ -135,11 +135,14 @@ def build_default_gemfile
source 'https://rubygems.org'
gem 'appraisal', :path => '#{PROJECT_ROOT}'
if RUBY_VERSION < "1.9"
gem "i18n", "~> 0.6.0"
gem "activesupport", "~> 3.2.21"
end
Gemfile

in_test_directory do
`bundle install --binstubs --local`
end
run "bundle install --binstubs --local"
end

def in_test_directory(&block)
Expand Down

0 comments on commit eb7e0f2

Please sign in to comment.