summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerence Lee <hone02@gmail.com>2012-12-26 19:09:56 -0500
committerTerence Lee <hone02@gmail.com>2012-12-26 19:09:56 -0500
commit78e3eb9385f943a314863388a8652e3f1e737121 (patch)
tree9288f4e061306c79bd098911f5eca731a786824e
parent13da67a63a1b3262a0a288fe267faecb8029ef63 (diff)
downloadbundler-78e3eb9385f943a314863388a8652e3f1e737121.tar.gz
slimmed down bundle bin to pull out ruby DSL info from Gemfile
-rwxr-xr-xbin/bundle_ruby56
-rw-r--r--spec/other/bundle_ruby_spec.rb112
-rw-r--r--spec/support/helpers.rb26
3 files changed, 194 insertions, 0 deletions
diff --git a/bin/bundle_ruby b/bin/bundle_ruby
new file mode 100755
index 0000000000..1e02c57501
--- /dev/null
+++ b/bin/bundle_ruby
@@ -0,0 +1,56 @@
+#!/usr/bin/env ruby
+
+Signal.trap("INT") { exit 1 }
+
+require 'bundler/ruby_version'
+require 'bundler/ruby_dsl'
+require 'bundler/shared_helpers'
+
+module Bundler
+ class GemfileError < RuntimeError; end
+ class Dsl
+ include RubyDsl
+
+ attr_accessor :ruby_version
+
+ def initialize
+ @ruby_version = nil
+ end
+
+ def eval_gemfile(gemfile, contents = nil)
+ contents ||= File.open(gemfile, "rb") { |f| f.read }
+ instance_eval(contents, gemfile.to_s, 1)
+ rescue SyntaxError => e
+ bt = e.message.split("\n")[1..-1]
+ raise GemfileError, ["Gemfile syntax error:", *bt].join("\n")
+ rescue ScriptError, RegexpError, NameError, ArgumentError => e
+ e.backtrace[0] = "#{e.backtrace[0]}: #{e.message} (#{e.class})"
+ STDERR.puts e.backtrace.join("\n ")
+ raise GemfileError, "There was an error in your Gemfile," \
+ " and Bundler cannot continue."
+ end
+
+ def source(source, options = {})
+ end
+
+ def gem(name, *args)
+ end
+
+ def group(*args, &blk)
+ end
+ end
+end
+
+dsl = Bundler::Dsl.new
+begin
+ dsl.eval_gemfile(Bundler::SharedHelpers.default_gemfile)
+ ruby_version = dsl.ruby_version
+ if ruby_version
+ puts ruby_version
+ else
+ puts "No ruby version specified"
+ end
+rescue Bundler::GemfileError => e
+ puts e.message
+ exit(-1)
+end
diff --git a/spec/other/bundle_ruby_spec.rb b/spec/other/bundle_ruby_spec.rb
new file mode 100644
index 0000000000..164a23c6ae
--- /dev/null
+++ b/spec/other/bundle_ruby_spec.rb
@@ -0,0 +1,112 @@
+require "spec_helper"
+
+describe "bundle_ruby" do
+ it "returns the ruby version" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.9.3", :engine => 'ruby', :engine_version => '1.9.3'
+
+ gem "foo"
+ G
+
+ bundle_ruby
+
+ expect(out).to eq("ruby 1.9.3")
+ end
+
+ it "engine defaults to MRI" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.9.3"
+
+ gem "foo"
+ G
+
+ bundle_ruby
+
+ expect(out).to 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'
+
+ gem "foo"
+ G
+
+ bundle_ruby
+
+ expect(out).to eq("ruby 1.8.7 (jruby 1.6.5)")
+ end
+
+ it "handles rbx" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'rbx', :engine_version => '1.2.4'
+
+ gem "foo"
+ G
+
+ bundle_ruby
+
+ expect(out).to 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_ruby :exitstatus => true
+ expect(exitstatus).not_to eq(0)
+
+ bundle_ruby
+ expect(out).to eq("Please define :engine_version")
+ 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_ruby :exitstatus => true
+ expect(exitstatus).not_to eq(0)
+
+ bundle_ruby
+ expect(out).to eq("Please define :engine")
+ 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_ruby :exitstatus => true
+ expect(exitstatus).not_to eq(0)
+
+ bundle_ruby
+ expect(out).to eq("ruby_version must match the :engine_version for MRI")
+ end
+
+ it "should print if no ruby version is specified" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+
+ gem "foo"
+ G
+
+ bundle_ruby
+
+ expect(out).to eq("No ruby version specified")
+ end
+end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 46921f4f6e..0fd74bde73 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -81,6 +81,32 @@ module Spec
end
end
+ def bundle_ruby(options = {})
+ expect_err = options.delete(:expect_err)
+ exitstatus = options.delete(:exitstatus)
+ options["no-color"] = true unless options.key?("no-color")
+
+ bundle_bin = File.expand_path('../../../bin/bundle_ruby', __FILE__)
+
+ requires = options.delete(:requires) || []
+ requires << File.expand_path('../fakeweb/'+options.delete(:fakeweb)+'.rb', __FILE__) if options.key?(:fakeweb)
+ requires << File.expand_path('../artifice/'+options.delete(:artifice)+'.rb', __FILE__) if options.key?(:artifice)
+ requires_str = requires.map{|r| "-r#{r}"}.join(" ")
+
+ env = (options.delete(:env) || {}).map{|k,v| "#{k}='#{v}' "}.join
+ args = options.map do |k,v|
+ v == true ? " --#{k}" : " --#{k} #{v}" if v
+ end.join
+
+ cmd = "#{env}#{Gem.ruby} -I#{lib} #{requires_str} #{bundle_bin}"
+
+ if exitstatus
+ sys_status(cmd)
+ else
+ sys_exec(cmd, expect_err){|i| yield i if block_given? }
+ end
+ end
+
def ruby(ruby, options = {})
expect_err = options.delete(:expect_err)
env = (options.delete(:env) || {}).map{|k,v| "#{k}='#{v}' "}.join