Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
loosen ruby directive for engines
Browse files Browse the repository at this point in the history
allow other engines to qualify when the engine is omitted. So, in the
Gemfile:

ruby "1.9.3"

will work with JRuby and RBX as long as the RUBY_VERSION matches
  • Loading branch information
hone committed Jul 13, 2012
1 parent 17e7f34 commit 438ef20
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/bundler/ruby_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def initialize(version, engine, engine_version)

@version = version
@engine = engine || "ruby"
# keep track of the engine specified by the user
@input_engine = engine
@engine_version = engine_version || version
end

Expand All @@ -40,11 +42,11 @@ def ==(other)
# 2. ruby_version
# 3. engine_version
def diff(other)
if engine != other.engine
if engine != other.engine && @input_engine
[ :engine, engine, other.engine ]
elsif version != other.version
[ :version, version, other.version ]
elsif engine_version != other.engine_version
elsif engine_version != other.engine_version && @input_engine
[ :engine_version, engine_version, other.engine_version ]
else
nil
Expand Down
164 changes: 164 additions & 0 deletions spec/other/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
end

let(:ruby_version_correct) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{local_engine_version}\"" }
let(:ruby_version_correct_engineless) { "ruby \"#{RUBY_VERSION}\"" }
let(:ruby_version_incorrect) { "ruby \"#{not_local_ruby_version}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_ruby_version}\"" }
let(:engine_incorrect) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{not_local_tag}\", :engine_version => \"#{RUBY_VERSION}\"" }
let(:engine_version_incorrect) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_engine_version}\"" }
Expand Down Expand Up @@ -192,6 +193,19 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
bundled_app('Gemfile.lock').should exist
end

it "installs fine with any engine" do
simulate_ruby_engine "jruby" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
#{ruby_version_correct_engineless}
G

bundled_app('Gemfile.lock').should exist
end
end

it "doesn't install when the ruby version doesn't match" do
install_gemfile <<-G, :exitstatus => true
source "file://#{gem_repo1}"
Expand Down Expand Up @@ -250,6 +264,26 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
out.should == "The Gemfile's dependencies are satisfied"
end

it "checks fine with any engine" do
simulate_ruby_engine "jruby" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
G

gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
#{ruby_version_correct_engineless}
G

bundle :check, :exitstatus => true
exitstatus.should eq(0)
out.should == "The Gemfile's dependencies are satisfied"
end
end

it "fails when ruby version doesn't match" do
install_gemfile <<-G
source "file://#{gem_repo1}"
Expand Down Expand Up @@ -331,6 +365,24 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
should_be_installed "rack 1.2", "rack-obama 1.0", "activesupport 3.0"
end

it "updates fine with any engine" do
simulate_ruby_engine "jruby" do
gemfile <<-G
source "file://#{gem_repo2}"
gem "activesupport"
gem "rack-obama"
#{ruby_version_correct_engineless}
G
update_repo2 do
build_gem "activesupport", "3.0"
end

bundle "update"
should_be_installed "rack 1.2", "rack-obama 1.0", "activesupport 3.0"
end
end

it "fails when ruby version doesn't match" do
gemfile <<-G
source "file://#{gem_repo2}"
Expand Down Expand Up @@ -402,6 +454,20 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
out.should == default_bundle_path('gems', 'rails-2.3.2').to_s
end

it "prints path if ruby version is correct for any engine" do
simulate_ruby_engine "jruby" do
gemfile <<-G
source "file://#{gem_repo1}"
gem "rails"
#{ruby_version_correct_engineless}
G

bundle "show rails"
out.should == default_bundle_path('gems', 'rails-2.3.2').to_s
end
end

it "fails if ruby version doesn't match" do
gemfile <<-G
source "file://#{gem_repo1}"
Expand Down Expand Up @@ -461,6 +527,19 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
bundled_app("vendor/cache/rack-1.0.0.gem").should exist
end

it "copies the .gem file to vendor/cache when ruby version matches for any engine" do
simulate_ruby_engine "jruby" do
gemfile <<-G
gem 'rack'
#{ruby_version_correct_engineless}
G

bundle :cache
bundled_app("vendor/cache/rack-1.0.0.gem").should exist
end
end

it "fails if the ruby version doesn't match" do
gemfile <<-G
gem 'rack'
Expand Down Expand Up @@ -517,6 +596,19 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
bundled_app("vendor/cache/rack-1.0.0.gem").should exist
end

it "copies the .gem file to vendor/cache when ruby version matches any engine" do
simulate_ruby_engine "jruby" do
gemfile <<-G
gem 'rack'
#{ruby_version_correct_engineless}
G

bundle :pack
bundled_app("vendor/cache/rack-1.0.0.gem").should exist
end
end

it "fails if the ruby version doesn't match" do
gemfile <<-G
gem 'rack'
Expand Down Expand Up @@ -569,6 +661,19 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
out.should == "0.9.1"
end

it "activates the correct gem when ruby version matches any engine" do
simulate_ruby_engine "jruby" do
gemfile <<-G
gem "rack", "0.9.1"
#{ruby_version_correct_engineless}
G

bundle "exec rackup"
out.should == "0.9.1"
end
end

it "fails when the ruby version doesn't match" do
gemfile <<-G
gem "rack", "0.9.1"
Expand Down Expand Up @@ -632,6 +737,25 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
out.should include("0.9.1")
end

it "starts IRB with the default group loaded when ruby version matches any engine" do
simulate_ruby_engine "jruby" do
gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
gem "activesupport", :group => :test
gem "rack_middleware", :group => :development
#{ruby_version_correct_engineless}
G

bundle "console" do |input|
input.puts("puts RACK")
input.puts("exit")
end
out.should include("0.9.1")
end
end

it "fails when ruby version doesn't match" do
gemfile <<-G
source "file://#{gem_repo1}"
Expand Down Expand Up @@ -703,6 +827,25 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
bundled_app("Gemfile.lock").should exist
end

it "makes a Gemfile.lock if setup succeeds for any engine" do
simulate_ruby_engine "jruby" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "yard"
gem "rack"
#{ruby_version_correct_engineless}
G

File.read(bundled_app("Gemfile.lock"))

FileUtils.rm(bundled_app("Gemfile.lock"))

run "1"
bundled_app("Gemfile.lock").should exist
end
end

it "fails when ruby version doesn't match" do
install_gemfile <<-G
source "file://#{gem_repo1}"
Expand Down Expand Up @@ -822,6 +965,27 @@ def should_be_engine_version_incorrect(opts = {:exitstatus => true})
out.should include("foo (1.0")
end

it "returns list of outdated gems when the ruby version matches for any engine" do
simulate_ruby_engine "jruby" do
update_repo2 do
build_gem "activesupport", "3.0"
update_git "foo", :path => lib_path("foo")
end

gemfile <<-G
source "file://#{gem_repo2}"
gem "activesupport", "2.3.5"
gem "foo", :git => "#{lib_path('foo')}"
#{ruby_version_correct_engineless}
G

bundle "outdated"
out.should include("activesupport (3.0 > 2.3.5)")
out.should include("foo (1.0")
end
end

it "fails when the ruby version doesn't match" do
update_repo2 do
build_gem "activesupport", "3.0"
Expand Down

1 comment on commit 438ef20

@indirect
Copy link
Member

Choose a reason for hiding this comment

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

👍

Please sign in to comment.