|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe Bundler::IncorrectLockfileDependencies do |
| 4 | + describe "#message" do |
| 5 | + let(:spec) do |
| 6 | + double("LazySpecification", full_name: "rubocop-1.82.0") |
| 7 | + end |
| 8 | + |
| 9 | + context "without dependency details" do |
| 10 | + subject { described_class.new(spec) } |
| 11 | + |
| 12 | + it "provides a basic error message" do |
| 13 | + expect(subject.message).to include("Bundler found incorrect dependencies in the lockfile for rubocop-1.82.0") |
| 14 | + expect(subject.message).to include("Please run `bundle install` to regenerate the lockfile.") |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + context "with dependency details" do |
| 19 | + let(:actual_dependencies) do |
| 20 | + [ |
| 21 | + Gem::Dependency.new("json", [">= 2.3", "< 4.0"]), |
| 22 | + Gem::Dependency.new("parallel", ["~> 1.10"]), |
| 23 | + Gem::Dependency.new("parser", [">= 3.3.0.2"]), |
| 24 | + ] |
| 25 | + end |
| 26 | + |
| 27 | + let(:lockfile_dependencies) do |
| 28 | + [ |
| 29 | + Gem::Dependency.new("json", [">= 2.3", "< 3.0"]), |
| 30 | + Gem::Dependency.new("parallel", ["~> 1.10"]), |
| 31 | + Gem::Dependency.new("parser", [">= 3.2.0.0"]), |
| 32 | + ] |
| 33 | + end |
| 34 | + |
| 35 | + subject { described_class.new(spec, actual_dependencies, lockfile_dependencies) } |
| 36 | + |
| 37 | + it "shows only mismatched dependencies" do |
| 38 | + message = subject.message |
| 39 | + |
| 40 | + expect(message).to include("json: gemspec specifies") |
| 41 | + expect(message).to include("parser: gemspec specifies") |
| 42 | + expect(message).not_to include("parallel") |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context "when gemspec has dependencies but lockfile has none" do |
| 47 | + let(:actual_dependencies) do |
| 48 | + [ |
| 49 | + Gem::Dependency.new("myrack-test", ["~> 1.0"]), |
| 50 | + ] |
| 51 | + end |
| 52 | + |
| 53 | + let(:lockfile_dependencies) { [] } |
| 54 | + |
| 55 | + subject { described_class.new(spec, actual_dependencies, lockfile_dependencies) } |
| 56 | + |
| 57 | + it "shows the dependency as not in lockfile" do |
| 58 | + message = subject.message |
| 59 | + |
| 60 | + expect(message).to include("myrack-test: gemspec specifies ~> 1.0, not in lockfile") |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + context "when gemspec has no dependencies but lockfile has some" do |
| 65 | + let(:actual_dependencies) { [] } |
| 66 | + |
| 67 | + let(:lockfile_dependencies) do |
| 68 | + [ |
| 69 | + Gem::Dependency.new("unexpected", ["~> 1.0"]), |
| 70 | + ] |
| 71 | + end |
| 72 | + |
| 73 | + subject { described_class.new(spec, actual_dependencies, lockfile_dependencies) } |
| 74 | + |
| 75 | + it "shows the dependency as not in gemspec" do |
| 76 | + message = subject.message |
| 77 | + |
| 78 | + expect(message).to include("unexpected: not in gemspec, lockfile has ~> 1.0") |
| 79 | + end |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + describe "#status_code" do |
| 84 | + let(:spec) { double("LazySpecification", full_name: "test-1.0.0") } |
| 85 | + subject { described_class.new(spec) } |
| 86 | + |
| 87 | + it "returns 41" do |
| 88 | + expect(subject.status_code).to eq(41) |
| 89 | + end |
| 90 | + end |
| 91 | +end |
0 commit comments