diff options
author | Bruno Ferreira <chalkos@chalkos.net> | 2016-06-07 21:14:43 +0100 |
---|---|---|
committer | Bruno Ferreira <chalkos@chalkos.net> | 2016-06-08 20:14:09 +0100 |
commit | 968f1edf83ede416e72adc164ef8355af6e73015 (patch) | |
tree | 394df0fa149c280f96fd9d614ff4fde4f3a76303 | |
parent | 666155de3273fd469a072ba87fe9d304fb3e68e7 (diff) | |
download | bundler-968f1edf83ede416e72adc164ef8355af6e73015.tar.gz |
changed code and specs according to suggestions
-rw-r--r-- | lib/bundler/ruby_version.rb | 7 | ||||
-rw-r--r-- | spec/bundler/ruby_version_spec.rb | 10 | ||||
-rw-r--r-- | spec/install/gemspecs_spec.rb | 75 |
3 files changed, 39 insertions, 53 deletions
diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index 131302d3c4..5936eca830 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -102,10 +102,9 @@ module Bundler def to_gem_version_with_patchlevel @gem_version_with_patch ||= begin - patch_number = @patchlevel ? Gem::Requirement.create(@patchlevel).requirements.first.last : 0 - Gem::Requirement.create("#{@gem_version}.#{patch_number}").requirements.first.last - rescue BadRequirementError - Gem::Requirement.create("#{@gem_version}.0").requirements.first.last + Gem::Version.create("#{@gem_version}.#{@patchlevel}") + rescue ArgumentError + @gem_version end end diff --git a/spec/bundler/ruby_version_spec.rb b/spec/bundler/ruby_version_spec.rb index 6c6ae9ce2f..414ec3c3c8 100644 --- a/spec/bundler/ruby_version_spec.rb +++ b/spec/bundler/ruby_version_spec.rb @@ -454,22 +454,22 @@ describe "Bundler::RubyVersion and its subclasses" do end describe "#to_gem_version_with_patchlevel" do - shared_examples_for "the patchlevel is 0" do - it "uses 0 as patchlevel" do - expect(subject.to_gem_version_with_patchlevel.to_s).to eq("#{version}.0") + shared_examples_for "the patchlevel is omitted" do + it "does not include a patch level" do + expect(subject.to_gem_version_with_patchlevel.to_s).to eq(version) end end context "with nil patch number" do let(:patchlevel) { nil } - it_behaves_like "the patchlevel is 0" + it_behaves_like "the patchlevel is omitted" end context "with negative patch number" do let(:patchlevel) { -1 } - it_behaves_like "the patchlevel is 0" + it_behaves_like "the patchlevel is omitted" end context "with a valid patch number" do diff --git a/spec/install/gemspecs_spec.rb b/spec/install/gemspecs_spec.rb index 9db8589cf8..7435687813 100644 --- a/spec/install/gemspecs_spec.rb +++ b/spec/install/gemspecs_spec.rb @@ -49,73 +49,60 @@ describe "bundle install" do context "when ruby version is specified in gemspec and gemfile" do it "installs when patch level is not specified and the version matches" do - build_lib("foo", :path => tmp.join("foo")) do |s| - s.write "Gemfile", <<-G - source "file://#{gem_repo1}" - ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby' - gemspec - G + build_lib("foo", :path => bundled_app) do |s| s.required_ruby_version = RUBY_VERSION end - Dir.chdir(tmp.join("foo")) do - bundle "install" - should_be_installed "foo 1.0" - end + install_gemfile <<-G + ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby' + gemspec + G + should_be_installed "foo 1.0" end it "installs when patch level is specified and the version still matches the current version" do - build_lib("foo", :path => tmp.join("foo")) do |s| - s.write "Gemfile", <<-G - source "file://#{gem_repo1}" - ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby', :patchlevel => '#{RUBY_PATCHLEVEL}' - gemspec - G + build_lib("foo", :path => bundled_app) do |s| s.required_ruby_version = "#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}" end - Dir.chdir(tmp.join("foo")) do - bundle "install" - should_be_installed "foo 1.0" - end + install_gemfile <<-G + ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby', :patchlevel => '#{RUBY_PATCHLEVEL}' + gemspec + G + should_be_installed "foo 1.0" end it "fails and complains about patchlevel on patchlevel mismatch" do patchlevel = RUBY_PATCHLEVEL.to_i + 1 - build_lib("foo", :path => tmp.join("foo")) do |s| - s.write "Gemfile", <<-G - source "file://#{gem_repo1}" - ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby', :patchlevel => '#{patchlevel}' - gemspec - G + build_lib("foo", :path => bundled_app) do |s| s.required_ruby_version = "#{RUBY_VERSION}.#{patchlevel}" end - Dir.chdir(tmp.join("foo")) do - bundle "install" - expect(out).to include("Ruby patchlevel") - expect(out).to include("but your Gemfile specified") - expect(exitstatus).to eq(18) if exitstatus - end + install_gemfile <<-G + ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby', :patchlevel => '#{patchlevel}' + gemspec + G + + expect(out).to include("Ruby patchlevel") + expect(out).to include("but your Gemfile specified") + expect(exitstatus).to eq(18) if exitstatus end it "fails and complains about version on version mismatch" do version = Gem::Requirement.create(RUBY_VERSION).requirements.first.last.bump.version - build_lib("foo", :path => tmp.join("foo")) do |s| - s.write "Gemfile", <<-G - source "file://#{gem_repo1}" - ruby '#{version}', :engine_version => '#{version}', :engine => 'ruby' - gemspec - G + + build_lib("foo", :path => bundled_app) do |s| s.required_ruby_version = version end - Dir.chdir(tmp.join("foo")) do - bundle "install" - expect(out).to include("Ruby version") - expect(out).to include("but your Gemfile specified") - expect(exitstatus).to eq(18) if exitstatus - end + install_gemfile <<-G + ruby '#{version}', :engine_version => '#{version}', :engine => 'ruby' + gemspec + G + + expect(out).to include("Ruby version") + expect(out).to include("but your Gemfile specified") + expect(exitstatus).to eq(18) if exitstatus end end end |