requirement: require instances to use a subclass
This commit is contained in:
parent
ea44c21822
commit
93647e5c98
@ -20,6 +20,10 @@ class Requirement
|
||||
attr_reader :tags, :name, :cask, :download
|
||||
|
||||
def initialize(tags = [])
|
||||
# Only allow instances of subclasses. This base class enforces no constraints on its own.
|
||||
# Individual subclasses use the `satisfy` DSL to define those constraints.
|
||||
raise "Do not call `Requirement.new' directly without a subclass." unless self.class < Requirement
|
||||
|
||||
@cask = self.class.cask
|
||||
@download = self.class.download
|
||||
tags.each do |tag|
|
||||
|
||||
@ -12,7 +12,7 @@ describe Requirement do
|
||||
let(:klass) { Class.new(described_class) }
|
||||
|
||||
describe "#tags" do
|
||||
subject { described_class.new(tags) }
|
||||
subject { klass.new(tags) }
|
||||
|
||||
context "with a single tag" do
|
||||
let(:tags) { ["bar"] }
|
||||
@ -149,7 +149,7 @@ describe Requirement do
|
||||
|
||||
describe "#build?" do
|
||||
context "when the :build tag is specified" do
|
||||
subject { described_class.new([:build]) }
|
||||
subject { klass.new([:build]) }
|
||||
|
||||
it { is_expected.to be_a_build_requirement }
|
||||
end
|
||||
@ -186,24 +186,24 @@ describe Requirement do
|
||||
end
|
||||
|
||||
describe "#eql? and #==" do
|
||||
subject(:requirement) { described_class.new }
|
||||
subject(:requirement) { klass.new }
|
||||
|
||||
it "returns true if the names and tags are equal" do
|
||||
other = described_class.new
|
||||
other = klass.new
|
||||
|
||||
expect(requirement).to eql(other)
|
||||
expect(requirement).to eq(other)
|
||||
end
|
||||
|
||||
it "returns false if names differ" do
|
||||
other = described_class.new
|
||||
other = klass.new
|
||||
allow(other).to receive(:name).and_return("foo")
|
||||
expect(requirement).not_to eql(other)
|
||||
expect(requirement).not_to eq(other)
|
||||
end
|
||||
|
||||
it "returns false if tags differ" do
|
||||
other = described_class.new([:optional])
|
||||
other = klass.new([:optional])
|
||||
|
||||
expect(requirement).not_to eql(other)
|
||||
expect(requirement).not_to eq(other)
|
||||
@ -211,21 +211,21 @@ describe Requirement do
|
||||
end
|
||||
|
||||
describe "#hash" do
|
||||
subject(:requirement) { described_class.new }
|
||||
subject(:requirement) { klass.new }
|
||||
|
||||
it "is equal if names and tags are equal" do
|
||||
other = described_class.new
|
||||
other = klass.new
|
||||
expect(requirement.hash).to eq(other.hash)
|
||||
end
|
||||
|
||||
it "differs if names differ" do
|
||||
other = described_class.new
|
||||
other = klass.new
|
||||
allow(other).to receive(:name).and_return("foo")
|
||||
expect(requirement.hash).not_to eq(other.hash)
|
||||
end
|
||||
|
||||
it "differs if tags differ" do
|
||||
other = described_class.new([:optional])
|
||||
other = klass.new([:optional])
|
||||
expect(requirement.hash).not_to eq(other.hash)
|
||||
end
|
||||
end
|
||||
|
||||
@ -12,7 +12,8 @@ describe Requirements do
|
||||
end
|
||||
|
||||
it "merges duplicate requirements" do
|
||||
requirements << Requirement.new << Requirement.new
|
||||
klass = Class.new(Requirement)
|
||||
requirements << klass.new << klass.new
|
||||
expect(requirements.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user