Permalink
Browse files

change dsl for ruby_version to ruby

  • Loading branch information...
1 parent 4ef6cc2 commit b484ed15e0955c0d0145775d63a4871d35060734 @hone hone committed Apr 28, 2012
Showing with 153 additions and 68 deletions.
  1. +19 −2 lib/bundler/cli.rb
  2. +1 −1 lib/bundler/dsl.rb
  3. +133 −65 spec/other/ruby_spec.rb
View
@@ -630,10 +630,27 @@ def clean
method_option "ruby", :type => :boolean, :default => false, :banner =>
"only display ruby related platform information"
def platform
+ platforms = Bundler.definition.platforms
ruby_version = Bundler.definition.ruby_version
- ruby_version = "No ruby version specified" unless ruby_version
+ output = []
- Bundler.ui.info ruby_version
+ output << "Your platform is: #{RUBY_PLATFORM}"
+ output << "Your app has gems that work on these platforms:\n#{platforms.join("\n")}"
+
+ if ruby_version
+ output << "Your Gemfile specifies a Ruby version requirement:\n* #{ruby_version}"
+
+ begin
+ Bundler.definition.validate_ruby!
+ output << "Your current platform satisfies the Ruby version requirement."
+ rescue RubyVersionMismatch => e
+ output << e.message
+ end
+ else
+ output << "Your Gemfile does not specify a Ruby version requirement."
+ end
+
+ Bundler.ui.info output.join("\n\n")
end
private
View
@@ -170,7 +170,7 @@ def env(name)
@env = old
end
- def ruby_version(ruby_version, options = {})
+ def ruby(ruby_version, options = {})
raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil?
raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
View
@@ -1,101 +1,169 @@
require "spec_helper"
describe "bundle platform" do
- it "returns ruby version when explicit" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby_version "1.9.3", :engine => 'ruby', :engine_version => '1.9.3'
+ context "without flags" do
+ it "returns all the output" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
- gem "foo"
- G
+ #{ruby_version_correct}
- bundle "platform"
+ gem "foo"
+ G
- out.should eq("ruby 1.9.3")
- end
+ bundle "platform"
+ out.should == <<-G.chomp
+Your platform is: #{RUBY_PLATFORM}
- it "engine defaults to MRI" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby_version "1.9.3"
+Your app has gems that work on these platforms:
+ruby
- gem "foo"
- G
+Your Gemfile specifies a Ruby version requirement:
+* ruby #{RUBY_VERSION}
- bundle "platform"
+Your current platform satisfies the Ruby version requirement.
+G
+ end
- out.should eq("ruby 1.9.3")
- end
+ it "doesn't print ruby version requirement if it isn't specified" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
- it "handles jruby" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby_version "1.8.7", :engine => 'jruby', :engine_version => '1.6.5'
+ gem "foo"
+ G
- gem "foo"
- G
+ bundle "platform"
+ out.should == <<-G.chomp
+Your platform is: #{RUBY_PLATFORM}
- bundle "platform"
+Your app has gems that work on these platforms:
+ruby
- out.should eq("ruby 1.8.7 (jruby 1.6.5)")
- end
+Your Gemfile does not specify a Ruby version requirement.
+G
+ end
+
+ it "doesn't match the ruby version requirement" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
- it "handles rbx" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby_version "1.8.7", :engine => 'rbx', :engine_version => '1.2.4'
+ #{ruby_version_incorrect}
- gem "foo"
- G
+ gem "foo"
+ G
- bundle "platform"
+ bundle "platform"
+ out.should == <<-G.chomp
+Your platform is: #{RUBY_PLATFORM}
- out.should eq("ruby 1.8.7 (rbx 1.2.4)")
+Your app has gems that work on these platforms:
+ruby
+
+Your Gemfile specifies a Ruby version requirement:
+* ruby #{not_local_ruby_version}
+
+Your Ruby version is #{RUBY_VERSION}, but your Gemfile specified #{not_local_ruby_version}
+G
+ end
end
- it "raises an error if engine is used but engine version is not" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby_version "1.8.7", :engine => 'rbx'
+ context "--ruby" do
+ it "returns ruby version when explicit" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.9.3", :engine => 'ruby', :engine_version => '1.9.3'
- gem "foo"
- G
+ gem "foo"
+ G
- bundle "platform", :exitstatus => true
+ bundle "platform"
- exitstatus.should_not == 0
- end
+ out.should eq("ruby 1.9.3")
+ end
- it "raises an error if engine_version is used but engine is not" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby_version "1.8.7", :engine_version => '1.2.4'
+ it "engine defaults to MRI" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.9.3"
- gem "foo"
- G
+ gem "foo"
+ G
- bundle "platform", :exitstatus => true
+ bundle "platform"
- exitstatus.should_not == 0
- end
+ out.should eq("ruby 1.9.3")
+ end
+
+ it "handles jruby" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'jruby', :engine_version => '1.6.5'
- it "raises an error if engine version doesn't match ruby version for mri" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby_version "1.8.7", :engine => 'ruby', :engine_version => '1.2.4'
+ gem "foo"
+ G
+
+ bundle "platform"
- gem "foo"
- G
+ out.should eq("ruby 1.8.7 (jruby 1.6.5)")
+ end
- bundle "platform", :exitstatus => true
+ it "handles rbx" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'rbx', :engine_version => '1.2.4'
- exitstatus.should_not == 0
+ gem "foo"
+ G
+
+ bundle "platform"
+
+ out.should eq("ruby 1.8.7 (rbx 1.2.4)")
+ end
+
+ it "raises an error if engine is used but engine version is not" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'rbx'
+
+ gem "foo"
+ G
+
+ bundle "platform", :exitstatus => true
+
+ exitstatus.should_not == 0
+ end
+
+ it "raises an error if engine_version is used but engine is not" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine_version => '1.2.4'
+
+ gem "foo"
+ G
+
+ bundle "platform", :exitstatus => true
+
+ exitstatus.should_not == 0
+ end
+
+ it "raises an error if engine version doesn't match ruby version for mri" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'ruby', :engine_version => '1.2.4'
+
+ gem "foo"
+ G
+
+ bundle "platform", :exitstatus => true
+
+ exitstatus.should_not == 0
+ end
end
- let(:ruby_version_correct) { "ruby_version \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{local_engine_version}\"" }
- let(:ruby_version_incorrect) { "ruby_version \"#{not_local_ruby_version}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_ruby_version}\"" }
- let(:engine_incorrect) { "ruby_version \"#{RUBY_VERSION}\", :engine => \"#{not_local_tag}\", :engine_version => \"#{RUBY_VERSION}\"" }
- let(:engine_version_incorrect) { "ruby_version \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_engine_version}\"" }
+ let(:ruby_version_correct) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{local_engine_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}\"" }
def should_be_ruby_version_incorrect(opts = {:exitstatus => true})
exitstatus.should eq(18) if opts[:exitstatus]

0 comments on commit b484ed1

Please sign in to comment.