diff options
author | Colby Swandale <colby@taplaboratories.com> | 2017-05-31 23:35:38 +1000 |
---|---|---|
committer | Colby Swandale <colby@taplaboratories.com> | 2017-06-01 01:01:43 +1000 |
commit | fab4838fa2680d32f3591e00ac97677d8382a517 (patch) | |
tree | 7daae22dc7598af9fabd2be8ea9f623d6139da92 /spec | |
parent | bf26b5515926c51008f2fe9e9d0054260d482e74 (diff) | |
download | bundler-fab4838fa2680d32f3591e00ac97677d8382a517.tar.gz |
handle invalid gemspec and add specs for untested behaviour in bundle init --gemspec
Diffstat (limited to 'spec')
-rw-r--r-- | spec/commands/init_spec.rb | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb index fbe03a78fa..c2477820a1 100644 --- a/spec/commands/init_spec.rb +++ b/spec/commands/init_spec.rb @@ -6,34 +6,60 @@ RSpec.describe "bundle init" do expect(bundled_app("Gemfile")).to exist end - it "does not change existing Gemfiles" do - gemfile <<-G - gem "rails" - G + context "when a Gemfile already exists" do + before do + gemfile <<-G + gem "rails" + G + end + + it "does not change existing Gemfiles" do + expect { bundle :init }.not_to change { File.read(bundled_app("Gemfile")) } + end - expect do + it "notifies the user that an existing Gemfile already exists" do bundle :init - end.not_to change { File.read(bundled_app("Gemfile")) } + expect(out).to include("Gemfile already exists") + end end - it "should generate from an existing gemspec" do - spec_file = tmp.join("test.gemspec") - File.open(spec_file, "w") do |file| - file << <<-S - Gem::Specification.new do |s| - s.name = 'test' - s.add_dependency 'rack', '= 1.0.1' - s.add_development_dependency 'rspec', '1.2' - end - S + context "given --gemspec option" do + let(:spec_file) { tmp.join("test.gemspec") } + + it "should generate from an existing gemspec" do + File.open(spec_file, "w") do |file| + file << <<-S + Gem::Specification.new do |s| + s.name = 'test' + s.add_dependency 'rack', '= 1.0.1' + s.add_development_dependency 'rspec', '1.2' + end + S + end + + bundle :init, :gemspec => spec_file + + gemfile = bundled_app("Gemfile").read + expect(gemfile).to match(%r{source 'https://rubygems.org'}) + expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) + expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) + expect(gemfile.scan(/group :development/).size).to eq(1) end - bundle :init, :gemspec => spec_file + context "when gemspec file is invalid" do + it "notifies the user that specification is invalid" do + File.open(spec_file, "w") do |file| + file << <<-S + Gem::Specification.new do |s| + s.name = 'test' + s.invalid_method_name + end + S + end - gemfile = bundled_app("Gemfile").read - expect(gemfile).to match(%r{source 'https://rubygems.org'}) - expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) - expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) - expect(gemfile.scan(/group :development/).size).to eq(1) + bundle :init, :gemspec => spec_file + expect(out).to include("Gem specification #{spec_file} is invalid") + end + end end end |