diff options
author | Martin Emde <martin.emde@gmail.com> | 2023-09-12 18:54:39 -0700 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-09-14 19:43:21 +0000 |
commit | 66ffa15ce01e1b8d46738032e714be18194af3ca (patch) | |
tree | 1753cd9cef0f8c816fccaea871be05eb177f833a /spec | |
parent | 0d33bc0cde5b9eca805cec1133e2c48ebdea5c84 (diff) | |
download | ruby-66ffa15ce01e1b8d46738032e714be18194af3ca.tar.gz |
[rubygems/rubygems] Gemfile ruby file: covers more version formats
Increase test coverage and be explicit about what is and is not supported.
https://github.com/rubygems/rubygems/commit/a096397a00
Diffstat (limited to 'spec')
-rw-r--r-- | spec/bundler/bundler/ruby_dsl_spec.rb | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/spec/bundler/bundler/ruby_dsl_spec.rb b/spec/bundler/bundler/ruby_dsl_spec.rb index 4af271ad59..6b00161571 100644 --- a/spec/bundler/bundler/ruby_dsl_spec.rb +++ b/spec/bundler/bundler/ruby_dsl_spec.rb @@ -21,11 +21,13 @@ RSpec.describe Bundler::RubyDsl do :engine => engine, :engine_version => engine_version } end + let(:project_root) { Pathname.new("/path/to/project") } + before { allow(Bundler).to receive(:root).and_return(project_root) } let(:invoke) do proc do args = [] - args << Array(ruby_version_arg) if ruby_version_arg + args << ruby_version_arg if ruby_version_arg args << options dsl.ruby(*args) @@ -97,53 +99,67 @@ RSpec.describe Bundler::RubyDsl do end context "with a file option" do - let(:options) { { :file => "foo" } } - let(:version) { "3.2.2" } - let(:ruby_version) { "3.2.2" } + let(:file) { ".ruby-version" } + let(:options) do + { :file => file, + :patchlevel => patchlevel, + :engine => engine, + :engine_version => engine_version } + end let(:ruby_version_arg) { nil } - let(:engine_version) { version } - let(:patchlevel) { nil } - let(:engine) { "ruby" } - let(:project_root) { Pathname.new("/path/to/project") } + let(:file_content) { "#{version}\n" } before do - allow(Bundler).to receive(:read_file).with(project_root.join("foo")).and_return("#{version}\n") - allow(Bundler).to receive(:root).and_return(Pathname.new("/path/to/project")) + allow(Bundler).to receive(:read_file).with(project_root.join(file)).and_return(file_content) end it_behaves_like "it stores the ruby version" + context "with the ruby- prefix in the file" do + let(:file_content) { "ruby-#{version}\n" } + + it_behaves_like "it stores the ruby version" + end + context "and a version" do - let(:ruby_version_arg) { "2.0.0" } + let(:ruby_version_arg) { version } it "raises an error" do - expect { subject }.to raise_error(Bundler::GemfileError, "Cannot specify version when using the file option") + expect { subject }.to raise_error(Bundler::GemfileError, "Do not pass version argument when using :file option") end end - end - context "with a (.tool-versions) file option" do - let(:options) { { :file => "foo" } } - let(:version) { "3.2.2" } - let(:ruby_version) { "3.2.2" } - let(:ruby_version_arg) { nil } - let(:engine_version) { version } - let(:patchlevel) { nil } - let(:engine) { "ruby" } - let(:project_root) { Pathname.new("/path/to/project") } + context "with a @gemset" do + let(:file_content) { "ruby-#{version}@gemset\n" } - before do - allow(Bundler).to receive(:read_file).with(project_root.join("foo")).and_return("nodejs 18.16.0\nruby #{version} # This is a comment\npnpm 8.6.12\n") - allow(Bundler).to receive(:root).and_return(Pathname.new("/path/to/project")) + it "raises an error" do + expect { subject }.to raise_error(Gem::Requirement::BadRequirementError, "Illformed requirement [\"#{version}@gemset\"]") + end end - it_behaves_like "it stores the ruby version" + context "with a .tool-versions file format" do + let(:file) { ".tool-versions" } + let(:ruby_version_arg) { nil } + let(:file_content) do + <<~TOOLS + nodejs 18.16.0 + ruby #{version} # This is a comment + pnpm 8.6.12 + TOOLS + end - context "and a version" do - let(:ruby_version_arg) { "2.0.0" } + it_behaves_like "it stores the ruby version" - it "raises an error" do - expect { subject }.to raise_error(Bundler::GemfileError, "Cannot specify version when using the file option") + context "with extra spaces and a very cozy comment" do + let(:file_content) do + <<~TOOLS + nodejs 18.16.0 + ruby #{version}# This is a cozy comment + pnpm 8.6.12 + TOOLS + end + + it_behaves_like "it stores the ruby version" end end end |