| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  | require "extend/ENV" | 
					
						
							|  |  |  | require "requirement" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Requirement do | 
					
						
							| 
									
										
										
										
											2017-05-09 23:00:51 +02:00
										 |  |  |   alias_matcher :be_a_build_requirement, :be_a_build | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |   subject(:requirement) { klass.new } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let(:klass) { Class.new(described_class) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-21 18:10:20 -08:00
										 |  |  |   describe "base class" do | 
					
						
							|  |  |  |     it "raises an error when instantiated" do | 
					
						
							|  |  |  |       expect { described_class.new } | 
					
						
							|  |  |  |         .to raise_error(RuntimeError, "Requirement is declared as abstract; it cannot be instantiated") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |   describe "#tags" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |     subject(:req) { klass.new(tags) } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with a single tag" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:tags) { ["bar"] } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:tags) { expect(req.tags).to eq(tags) } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with multiple tags" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:tags) { ["bar", "baz"] } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:tags) { expect(req.tags).to eq(tags) } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with symbol tags" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:tags) { [:build] } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:tags) { expect(req.tags).to eq(tags) } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with symbol and string tags" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:tags) { [:build, "bar"] } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:tags) { expect(req.tags).to eq(tags) } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#fatal?" do | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#fatal true is specified" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:klass) do | 
					
						
							|  |  |  |         Class.new(described_class) do | 
					
						
							|  |  |  |           fatal true | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to be_fatal } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#fatal is omitted" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       it { is_expected.not_to be_fatal } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#satisfied?" do | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#satisfy with block and build_env returns true" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:klass) do | 
					
						
							|  |  |  |         Class.new(described_class) do | 
					
						
							|  |  |  |           satisfy(build_env: false) do | 
					
						
							|  |  |  |             true | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 14:08:40 +02:00
										 |  |  |       it { is_expected.to be_satisfied } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#satisfy with block and build_env returns false" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:klass) do | 
					
						
							|  |  |  |         Class.new(described_class) do | 
					
						
							|  |  |  |           satisfy(build_env: false) do | 
					
						
							|  |  |  |             false | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 14:08:40 +02:00
										 |  |  |       it { is_expected.not_to be_satisfied } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#satisfy returns true" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:klass) do | 
					
						
							|  |  |  |         Class.new(described_class) do | 
					
						
							|  |  |  |           satisfy true | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 14:08:40 +02:00
										 |  |  |       it { is_expected.to be_satisfied } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#satisfy returns false" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:klass) do | 
					
						
							|  |  |  |         Class.new(described_class) do | 
					
						
							|  |  |  |           satisfy false | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 14:08:40 +02:00
										 |  |  |       it { is_expected.not_to be_satisfied } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#satisfy with block returning true and without :build_env" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:klass) do | 
					
						
							|  |  |  |         Class.new(described_class) do | 
					
						
							|  |  |  |           satisfy do | 
					
						
							|  |  |  |             true | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "sets up build environment" do | 
					
						
							|  |  |  |         expect(ENV).to receive(:with_build_environment).and_call_original | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         requirement.satisfied? | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#satisfy with block returning true and :build_env set to false" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:klass) do | 
					
						
							|  |  |  |         Class.new(described_class) do | 
					
						
							|  |  |  |           satisfy(build_env: false) do | 
					
						
							|  |  |  |             true | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "skips setting up build environment" do | 
					
						
							|  |  |  |         expect(ENV).not_to receive(:with_build_environment) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         requirement.satisfied? | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#satisfy with block returning path and without :build_env" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       let(:klass) do | 
					
						
							|  |  |  |         Class.new(described_class) do | 
					
						
							|  |  |  |           satisfy do | 
					
						
							|  |  |  |             Pathname.new("/foo/bar/baz") | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "infers path from #satisfy result" do | 
					
						
							| 
									
										
										
										
											2024-02-18 15:08:05 -08:00
										 |  |  |         without_partial_double_verification do | 
					
						
							|  |  |  |           expect(ENV).to receive(:prepend_path).with("PATH", Pathname.new("/foo/bar")) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         requirement.satisfied? | 
					
						
							|  |  |  |         requirement.modify_build_environment | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#build?" do | 
					
						
							| 
									
										
										
										
											2021-02-21 01:02:57 +00:00
										 |  |  |     context "when the :build tag is specified" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |       subject { klass.new([:build]) } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to be_a_build_requirement } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 15:27:21 +01:00
										 |  |  |     describe "#build omitted" do | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       it { is_expected.not_to be_a_build_requirement } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#name and #option_names" do | 
					
						
							|  |  |  |     let(:const) { :FooRequirement } | 
					
						
							|  |  |  |     let(:klass) { self.class.const_get(const) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |     before do | 
					
						
							| 
									
										
										
										
											2024-01-08 18:38:20 +00:00
										 |  |  |       stub_const const.to_s, Class.new(described_class) | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |     it(:name) { expect(requirement.name).to eq("foo") } | 
					
						
							|  |  |  |     it(:option_names) { expect(requirement.option_names).to eq(["foo"]) } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#modify_build_environment" do | 
					
						
							|  |  |  |     context "without env proc" do | 
					
						
							|  |  |  |       let(:klass) { Class.new(described_class) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns nil" do | 
					
						
							| 
									
										
										
										
											2024-02-19 13:29:49 -08:00
										 |  |  |         expect { requirement.modify_build_environment }.not_to raise_error | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#eql? and #==" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |     subject(:requirement) { klass.new } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "returns true if the names and tags are equal" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |       other = klass.new | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(requirement).to eql(other) | 
					
						
							|  |  |  |       expect(requirement).to eq(other) | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns false if names differ" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |       other = klass.new | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       allow(other).to receive(:name).and_return("foo") | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(requirement).not_to eql(other) | 
					
						
							|  |  |  |       expect(requirement).not_to eq(other) | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns false if tags differ" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |       other = klass.new([:optional]) | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(requirement).not_to eql(other) | 
					
						
							|  |  |  |       expect(requirement).not_to eq(other) | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#hash" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |     subject(:requirement) { klass.new } | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "is equal if names and tags are equal" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |       other = klass.new | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(requirement.hash).to eq(other.hash) | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "differs if names differ" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |       other = klass.new | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |       allow(other).to receive(:name).and_return("foo") | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(requirement.hash).not_to eq(other.hash) | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "differs if tags differ" do | 
					
						
							| 
									
										
										
										
											2022-08-24 23:48:08 +01:00
										 |  |  |       other = klass.new([:optional]) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       expect(requirement.hash).not_to eq(other.hash) | 
					
						
							| 
									
										
										
										
											2017-02-12 17:26:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |