brew/Library/Homebrew/test/patch_spec.rb

107 lines
2.9 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2017-02-15 15:19:06 +01:00
require "patch"
describe Patch do
describe "#create" do
context "with a simple patch" do
2017-02-15 15:19:06 +01:00
subject { described_class.create(:p2, nil) }
2022-09-13 09:43:09 +01:00
it { is_expected.to be_a ExternalPatch }
2017-02-15 15:19:06 +01:00
it { is_expected.to be_external }
its(:strip) { is_expected.to eq(:p2) }
end
context "with a string patch" do
2017-02-15 15:19:06 +01:00
subject { described_class.create(:p0, "foo") }
2022-09-13 09:43:09 +01:00
it { is_expected.to be_a StringPatch }
2017-02-15 15:19:06 +01:00
its(:strip) { is_expected.to eq(:p0) }
end
context "with a string patch without strip" do
2017-02-15 15:19:06 +01:00
subject { described_class.create("foo", nil) }
2022-09-13 09:43:09 +01:00
it { is_expected.to be_a StringPatch }
2017-02-15 15:19:06 +01:00
its(:strip) { is_expected.to eq(:p1) }
end
context "with a data patch" do
2017-02-15 15:19:06 +01:00
subject { described_class.create(:p0, :DATA) }
2022-09-13 09:43:09 +01:00
it { is_expected.to be_a DATAPatch }
2017-02-15 15:19:06 +01:00
its(:strip) { is_expected.to eq(:p0) }
end
context "with a data patch without strip" do
2017-02-15 15:19:06 +01:00
subject { described_class.create(:DATA, nil) }
2022-09-13 09:43:09 +01:00
it { is_expected.to be_a DATAPatch }
2017-02-15 15:19:06 +01:00
its(:strip) { is_expected.to eq(:p1) }
end
it "raises an error for unknown values" do
expect {
described_class.create(Object.new)
}.to raise_error(ArgumentError)
expect {
described_class.create(Object.new, Object.new)
}.to raise_error(ArgumentError)
end
end
describe "#patch_files" do
subject(:patch) { described_class.create(:p2, nil) }
2017-02-15 15:19:06 +01:00
context "when the patch is empty" do
2022-09-13 09:43:09 +01:00
its(:resource) { is_expected.to be_a Resource::PatchResource }
its(:patch_files) { is_expected.to eq(patch.resource.patch_files) }
2017-02-15 15:19:06 +01:00
its(:patch_files) { is_expected.to eq([]) }
end
it "returns applied patch files" do
patch.resource.apply("patch1.diff")
expect(patch.patch_files).to eq(["patch1.diff"])
2017-02-15 15:19:06 +01:00
patch.resource.apply("patch2.diff", "patch3.diff")
expect(patch.patch_files).to eq(["patch1.diff", "patch2.diff", "patch3.diff"])
2017-02-15 15:19:06 +01:00
patch.resource.apply(["patch4.diff", "patch5.diff"])
expect(patch.patch_files.count).to eq(5)
2017-02-15 15:19:06 +01:00
patch.resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff")
expect(patch.patch_files.count).to eq(7)
2017-02-15 15:19:06 +01:00
end
end
describe EmbeddedPatch do
describe "#new" do
subject { described_class.new(:p1) }
its(:inspect) { is_expected.to eq("#<EmbeddedPatch: :p1>") }
end
2017-02-15 15:19:06 +01:00
end
describe ExternalPatch do
subject(:patch) { described_class.new(:p1) { url "file:///my.patch" } }
2017-02-15 15:19:06 +01:00
describe "#url" do
its(:url) { is_expected.to eq("file:///my.patch") }
end
2017-02-15 15:19:06 +01:00
describe "#inspect" do
its(:inspect) { is_expected.to eq('#<ExternalPatch: :p1 "file:///my.patch">') }
2017-02-15 15:19:06 +01:00
end
describe "#cached_download" do
before do
allow(patch.resource).to receive(:cached_download).and_return("/tmp/foo.tar.gz")
end
its(:cached_download) { is_expected.to eq("/tmp/foo.tar.gz") }
end
2017-02-15 15:19:06 +01:00
end
end