Merge pull request #14400 from dduugg/rspec-cop-fix

Resolve RSpec/VerifiedDoubles todos
This commit is contained in:
Mike McQuaid 2023-01-23 13:36:37 +00:00 committed by GitHub
commit f22f3eaa0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 116 additions and 112 deletions

View File

@ -11,6 +11,8 @@ module Dependable
# misuse in future.
RESERVED_TAGS = [:build, :optional, :recommended, :run, :test, :linked].freeze
attr_reader :tags
def build?
tags.include? :build
end

View File

@ -1,5 +0,0 @@
# typed: strict
module Dependable
def tags; end
end

View File

@ -13,7 +13,7 @@ class Dependency
include Dependable
extend Cachable
attr_reader :name, :tags, :env_proc, :option_names
attr_reader :name, :env_proc, :option_names
DEFAULT_ENV_PROC = proc {}.freeze
private_constant :DEFAULT_ENV_PROC

View File

@ -17,7 +17,7 @@ class Requirement
include Dependable
extend Cachable
attr_reader :tags, :name, :cask, :download
attr_reader :name, :cask, :download
def initialize(tags = [])
# Only allow instances of subclasses. This base class enforces no constraints on its own.

View File

@ -13,27 +13,3 @@ RSpec/InstanceVariable:
- "download_strategies/git_spec.rb"
- "support/helper/spec/shared_context/integration_test.rb"
- "utils/git_spec.rb"
# Offense count: 63
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- "cache_store_spec.rb"
- "cask/artifact/pkg_spec.rb"
- "cask/installer_spec.rb"
- "cask/pkg_spec.rb"
- "cmd/update-report_spec.rb"
- "compiler_failure_spec.rb"
- "compiler_selector_spec.rb"
- "dependable_spec.rb"
- "dependency_expansion_spec.rb"
- "description_cache_store_spec.rb"
- "exceptions_spec.rb"
- "formula_pin_spec.rb"
- "formula_spec.rb"
- "language/python/virtualenv_spec.rb"
- "linkage_cache_store_spec.rb"
- "resource_spec.rb"
- "software_spec_spec.rb"
- "utils/analytics_spec.rb"
- "version_spec.rb"

View File

@ -10,7 +10,7 @@ describe CacheStoreDatabase do
let(:type) { :test }
it "creates a new `DatabaseCache` instance" do
cache_store = double("cache_store", write_if_dirty!: nil)
cache_store = instance_double(described_class, "cache_store", write_if_dirty!: nil)
expect(described_class).to receive(:new).with(type).and_return(cache_store)
expect(cache_store).to receive(:write_if_dirty!)
described_class.use(type) { |_db| }
@ -18,7 +18,7 @@ describe CacheStoreDatabase do
end
describe "#set" do
let(:db) { double("db", :[]= => nil) }
let(:db) { instance_double(Hash, "db", :[]= => nil) }
it "sets the value in the `CacheStoreDatabase`" do
allow(File).to receive(:write)
@ -33,7 +33,7 @@ describe CacheStoreDatabase do
describe "#get" do
context "with a database created" do
let(:db) { double("db", :[] => "bar") }
let(:db) { instance_double(Hash, "db", :[] => "bar") }
it "gets value in the `CacheStoreDatabase` corresponding to the key" do
allow(sample_db).to receive(:created?).and_return(true)
@ -45,7 +45,7 @@ describe CacheStoreDatabase do
end
context "without a database created" do
let(:db) { double("db", :[] => nil) }
let(:db) { instance_double(Hash, "db", :[] => nil) }
before do
allow(sample_db).to receive(:created?).and_return(false)
@ -65,7 +65,7 @@ describe CacheStoreDatabase do
describe "#delete" do
context "with a database created" do
let(:db) { double("db", :[] => { foo: "bar" }) }
let(:db) { instance_double(Hash, "db", :[] => { foo: "bar" }) }
before do
allow(sample_db).to receive(:created?).and_return(true)
@ -79,7 +79,7 @@ describe CacheStoreDatabase do
end
context "without a database created" do
let(:db) { double("db", delete: nil) }
let(:db) { instance_double(Hash, "db", delete: nil) }
before do
allow(sample_db).to receive(:created?).and_return(false)

View File

@ -35,7 +35,7 @@ describe Cask::Artifact::Pkg, :cask do
it "passes the choice changes xml to the system installer" do
pkg = cask.artifacts.find { |a| a.is_a?(described_class) }
file = double(path: Pathname.new("/tmp/choices.xml"))
file = instance_double(Tempfile, path: Pathname.new("/tmp/choices.xml"))
expect(file).to receive(:write).with <<~XML
<?xml version="1.0" encoding="UTF-8"?>

View File

@ -3,10 +3,6 @@
describe Cask::Installer, :cask do
describe "install" do
let(:empty_depends_on_stub) {
double(formula: [], cask: [], macos: nil, arch: nil)
}
it "downloads and installs a nice fresh Cask" do
caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))

View File

@ -4,7 +4,13 @@
describe Cask::Pkg, :cask do
describe "#uninstall" do
let(:fake_system_command) { NeverSudoSystemCommand }
let(:empty_response) { double(stdout: "", plist: { "volume" => "/", "install-location" => "", "paths" => {} }) }
let(:empty_response) do
instance_double(
SystemCommand::Result,
stdout: "",
plist: { "volume" => "/", "install-location" => "", "paths" => {} },
)
end
let(:pkg) { described_class.new("my.fake.pkg", fake_system_command) }
it "removes files and dirs referenced by the pkg" do

View File

@ -27,8 +27,8 @@ describe "brew update-report" do
let(:hub) { ReporterHub.new }
def perform_update(fixture_name = "")
allow(Formulary).to receive(:factory).and_return(double(pkg_version: "1.0"))
allow(FormulaVersions).to receive(:new).and_return(double(formula_at_revision: "2.0"))
allow(Formulary).to receive(:factory).and_return(instance_double(Formula, pkg_version: "1.0"))
allow(FormulaVersions).to receive(:new).and_return(instance_double(FormulaVersions, formula_at_revision: "2.0"))
diff = YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")[fixture_name]
allow(reporter).to receive(:diff).and_return(diff || "")

View File

@ -9,31 +9,57 @@ describe CompilerFailure do
describe "::create" do
it "creates a failure when given a symbol" do
failure = described_class.create(:clang)
expect(failure).to fail_with(double("Compiler", type: :clang, name: :clang, version: 600))
expect(failure).to fail_with(
instance_double(CompilerSelector::Compiler, "Compiler", type: :clang, name: :clang, version: 600),
)
end
it "can be given a build number in a block" do
failure = described_class.create(:clang) { build 700 }
expect(failure).to fail_with(double("Compiler", type: :clang, name: :clang, version: 700))
expect(failure).to fail_with(
instance_double(CompilerSelector::Compiler, "Compiler", type: :clang, name: :clang, version: 700),
)
end
it "can be given an empty block" do
failure = described_class.create(:clang) {}
expect(failure).to fail_with(double("Compiler", type: :clang, name: :clang, version: 600))
expect(failure).to fail_with(
instance_double(CompilerSelector::Compiler, "Compiler", type: :clang, name: :clang, version: 600),
)
end
it "creates a failure when given a hash" do
failure = described_class.create(gcc: "7")
expect(failure).to fail_with(double("Compiler", type: :gcc, name: "gcc-7", version: Version.new("7")))
expect(failure).to fail_with(double("Compiler", type: :gcc, name: "gcc-7", version: Version.new("7.1")))
expect(failure).not_to fail_with(double("Compiler", type: :gcc, name: "gcc-6", version: Version.new("6.0")))
expect(failure).to fail_with(
instance_double(CompilerSelector::Compiler, "Compiler", type: :gcc, name: "gcc-7", version: Version.new("7")),
)
expect(failure).to fail_with(
instance_double(
CompilerSelector::Compiler, "Compiler", type: :gcc, name: "gcc-7", version: Version.new("7.1")
),
)
expect(failure).not_to fail_with(
instance_double(
CompilerSelector::Compiler, "Compiler", type: :gcc, name: "gcc-6", version: Version.new("6.0")
),
)
end
it "creates a failure when given a hash and a block with aversion" do
failure = described_class.create(gcc: "7") { version "7.1" }
expect(failure).to fail_with(double("Compiler", type: :gcc, name: "gcc-7", version: Version.new("7")))
expect(failure).to fail_with(double("Compiler", type: :gcc, name: "gcc-7", version: Version.new("7.1")))
expect(failure).not_to fail_with(double("Compiler", type: :gcc, name: "gcc-7", version: Version.new("7.2")))
expect(failure).to fail_with(
instance_double(CompilerSelector::Compiler, "Compiler", type: :gcc, name: "gcc-7", version: Version.new("7")),
)
expect(failure).to fail_with(
instance_double(
CompilerSelector::Compiler, "Compiler", type: :gcc, name: "gcc-7", version: Version.new("7.1")
),
)
expect(failure).not_to fail_with(
instance_double(
CompilerSelector::Compiler, "Compiler", type: :gcc, name: "gcc-7", version: Version.new("7.2")
),
)
end
end
end

View File

@ -10,12 +10,7 @@ describe CompilerSelector do
let(:compilers) { [:clang, :gnu] }
let(:software_spec) { SoftwareSpec.new }
let(:cc) { :clang }
let(:versions) do
double(
llvm_build_version: Version::NULL,
clang_build_version: Version.create("600"),
)
end
let(:versions) { class_double(DevelopmentTools, clang_build_version: Version.create("600")) }
before do
allow(versions).to receive(:gcc_version) do |name|
@ -46,13 +41,15 @@ describe CompilerSelector do
it "returns gcc-6 if gcc formula offers gcc-6 on mac", :needs_macos do
software_spec.fails_with(:clang)
allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: Version.new("6.0")))
allow(Formulary).to receive(:factory).with("gcc")
.and_return(instance_double(Formula, version: Version.new("6.0")))
expect(selector.compiler).to eq("gcc-6")
end
it "returns gcc-5 if gcc formula offers gcc-5 on linux", :needs_linux do
software_spec.fails_with(:clang)
allow(Formulary).to receive(:factory).with("gcc@11").and_return(double(version: Version.new("5.0")))
allow(Formulary).to receive(:factory).with("gcc@11")
.and_return(instance_double(Formula, version: Version.new("5.0")))
expect(selector.compiler).to eq("gcc-5")
end
@ -60,14 +57,16 @@ describe CompilerSelector do
software_spec.fails_with(:clang)
software_spec.fails_with(gcc: "5")
software_spec.fails_with(gcc: "7")
allow(Formulary).to receive(:factory).with("gcc@11").and_return(double(version: Version.new("5.0")))
allow(Formulary).to receive(:factory).with("gcc@11")
.and_return(instance_double(Formula, version: Version.new("5.0")))
expect(selector.compiler).to eq("gcc-6")
end
it "returns gcc-7 if gcc formula offers gcc-5 and fails with gcc <= 6 on linux", :needs_linux do
software_spec.fails_with(:clang)
software_spec.fails_with(:gcc) { version "6" }
allow(Formulary).to receive(:factory).with("gcc@11").and_return(double(version: Version.new("5.0")))
allow(Formulary).to receive(:factory).with("gcc@11")
.and_return(instance_double(Formula, version: Version.new("5.0")))
expect(selector.compiler).to eq("gcc-7")
end

View File

@ -6,9 +6,14 @@ require "dependable"
describe Dependable do
alias_matcher :be_a_build_dependency, :be_build
subject(:dependable) { double(tags: tags).extend(described_class) }
let(:tags) { ["foo", "bar", :build] }
subject(:dependable) {
Class.new {
include Dependable
def initialize
@tags = ["foo", "bar", :build]
end
}.new
}
specify "#options" do
expect(dependable.options.as_flags.sort).to eq(%w[--foo --bar].sort)

View File

@ -6,7 +6,7 @@ require "dependency"
describe Dependency do
def build_dep(name, tags = [], deps = [])
dep = described_class.new(name.to_s, tags)
allow(dep).to receive(:to_formula).and_return(double(deps: deps, name: name))
allow(dep).to receive(:to_formula).and_return(instance_double(Formula, deps: deps, name: name))
dep
end
@ -15,7 +15,7 @@ describe Dependency do
let(:baz) { build_dep(:baz) }
let(:qux) { build_dep(:qux) }
let(:deps) { [foo, bar, baz, qux] }
let(:formula) { double(deps: deps, name: "f") }
let(:formula) { instance_double(Formula, deps: deps, name: "f") }
describe "::expand" do
it "yields dependent and dependency pairs" do
@ -44,20 +44,20 @@ describe Dependency do
end
it "preserves dependency order" do
allow(foo).to receive(:to_formula).and_return(double(name: "f", deps: [qux, baz]))
allow(foo).to receive(:to_formula).and_return(instance_double(Formula, name: "f", deps: [qux, baz]))
expect(described_class.expand(formula)).to eq([qux, baz, foo, bar])
end
end
it "skips optionals by default" do
deps = [build_dep(:foo, [:optional]), bar, baz, qux]
f = double(deps: deps, build: double(with?: false), name: "f")
f = instance_double(Formula, deps: deps, build: instance_double(BuildOptions, with?: false), name: "f")
expect(described_class.expand(f)).to eq([bar, baz, qux])
end
it "keeps recommended dependencies by default" do
deps = [build_dep(:foo, [:recommended]), bar, baz, qux]
f = double(deps: deps, build: double(with?: true), name: "f")
f = instance_double(Formula, deps: deps, build: instance_double(BuildOptions, with?: true), name: "f")
expect(described_class.expand(f)).to eq(deps)
end
@ -75,7 +75,7 @@ describe Dependency do
it "merges dependencies and preserves env_proc" do
env_proc = double
dep = described_class.new("foo", [], env_proc)
allow(dep).to receive(:to_formula).and_return(double(deps: [], name: "foo"))
allow(dep).to receive(:to_formula).and_return(instance_double(Formula, deps: [], name: "foo"))
deps.replace([dep])
expect(described_class.expand(formula).first.env_proc).to eq(env_proc)
end
@ -89,7 +89,8 @@ describe Dependency do
end
it "skips parent but yields children with ::skip" do
f = double(
f = instance_double(
Formula,
name: "f",
deps: [
build_dep(:foo, [], [bar, baz]),
@ -107,7 +108,7 @@ describe Dependency do
it "keeps dependency but prunes recursive dependencies with ::keep_but_prune_recursive_deps" do
foo = build_dep(:foo, [:test], bar)
baz = build_dep(:baz, [:test])
f = double(name: "f", deps: [foo, baz])
f = instance_double(Formula, name: "f", deps: [foo, baz])
deps = described_class.expand(f) do |_dependent, dep|
described_class.keep_but_prune_recursive_deps if dep.test?
@ -124,15 +125,15 @@ describe Dependency do
it "doesn't raise an error when a dependency is cyclic" do
foo = build_dep(:foo)
bar = build_dep(:bar, [], [foo])
allow(foo).to receive(:to_formula).and_return(double(deps: [bar], name: foo.name))
f = double(name: "f", deps: [foo, bar])
allow(foo).to receive(:to_formula).and_return(instance_double(Formula, deps: [bar], name: foo.name))
f = instance_double(Formula, name: "f", deps: [foo, bar])
expect { described_class.expand(f) }.not_to raise_error
end
it "cleans the expand stack" do
foo = build_dep(:foo)
allow(foo).to receive(:to_formula).and_raise(FormulaUnavailableError, foo.name)
f = double(name: "f", deps: [foo])
f = instance_double(Formula, name: "f", deps: [foo])
expect { described_class.expand(f) }.to raise_error(FormulaUnavailableError)
expect(described_class.instance_variable_get(:@expand_stack)).to be_empty
end

View File

@ -1,12 +1,13 @@
# typed: false
# frozen_string_literal: true
require "cmd/update-report"
require "description_cache_store"
describe DescriptionCacheStore do
subject(:cache_store) { described_class.new(database) }
let(:database) { double("database") }
let(:database) { instance_double(CacheStoreDatabase, "database") }
let(:formula_name) { "test_name" }
let(:description) { "test_description" }
@ -27,7 +28,7 @@ describe DescriptionCacheStore do
end
describe "#update_from_report!" do
let(:report) { double(select_formula_or_cask: [], empty?: false) }
let(:report) { instance_double(ReporterHub, select_formula_or_cask: [], empty?: false) }
it "reads from the report" do
expect(database).to receive(:empty?).at_least(:once).and_return(false)
@ -59,10 +60,10 @@ describe DescriptionCacheStore do
describe CaskDescriptionCacheStore do
subject(:cache_store) { described_class.new(database) }
let(:database) { double("database") }
let(:database) { instance_double(CacheStoreDatabase, "database") }
describe "#update_from_report!" do
let(:report) { double(select_formula_or_cask: [], empty?: false) }
let(:report) { instance_double(ReporterHub, select_formula_or_cask: [], empty?: false) }
it "reads from the report" do
expect(database).to receive(:empty?).at_least(:once).and_return(false)

View File

@ -37,7 +37,7 @@ describe "Exception" do
describe TapFormulaOrCaskUnavailableError do
subject(:error) { described_class.new(tap, "foo") }
let(:tap) { double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) }
let(:tap) { instance_double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) }
its(:to_s) { is_expected.to match(%r{Please tap it and then try again: brew tap u/r}) }
end
@ -79,7 +79,7 @@ describe "Exception" do
describe TapFormulaUnavailableError do
subject { described_class.new(tap, "foo") }
let(:tap) { double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) }
let(:tap) { instance_double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) }
its(:to_s) { is_expected.to match(%r{Please tap it and then try again: brew tap u/r}) }
end
@ -141,7 +141,7 @@ describe "Exception" do
describe BuildError do
subject { described_class.new(formula, "badprg", %w[arg1 arg2], {}) }
let(:formula) { double(Formula, name: "foo") }
let(:formula) { instance_double(Formula, name: "foo") }
its(:to_s) { is_expected.to eq("Failed executing: badprg arg1 arg2") }
end
@ -155,7 +155,7 @@ describe "Exception" do
describe FormulaInstallationAlreadyAttemptedError do
subject { described_class.new(formula) }
let(:formula) { double(Formula, full_name: "foo/bar") }
let(:formula) { instance_double(Formula, full_name: "foo/bar") }
its(:to_s) { is_expected.to eq("Formula installation already attempted: foo/bar") }
end
@ -163,8 +163,8 @@ describe "Exception" do
describe FormulaConflictError do
subject { described_class.new(formula, [conflict]) }
let(:formula) { double(Formula, full_name: "foo/qux") }
let(:conflict) { double(name: "bar", reason: "I decided to") }
let(:formula) { instance_double(Formula, full_name: "foo/qux") }
let(:conflict) { instance_double(FormulaConflict, name: "bar", reason: "I decided to") }
its(:to_s) { is_expected.to match(/Please `brew unlink bar` before continuing\./) }
end
@ -172,7 +172,7 @@ describe "Exception" do
describe CompilerSelectionError do
subject { described_class.new(formula) }
let(:formula) { double(Formula, full_name: "foo") }
let(:formula) { instance_double(Formula, full_name: "foo") }
its(:to_s) { is_expected.to match(/foo cannot be built with any available compilers\./) }
end
@ -202,8 +202,8 @@ describe "Exception" do
describe ChecksumMismatchError do
subject { described_class.new("/file.tar.gz", hash1, hash2) }
let(:hash1) { double(hash_type: "sha256", to_s: "deadbeef") }
let(:hash2) { double(hash_type: "sha256", to_s: "deadcafe") }
let(:hash1) { instance_double(Checksum, to_s: "deadbeef") }
let(:hash2) { instance_double(Checksum, to_s: "deadcafe") }
its(:to_s) { is_expected.to match(/SHA256 mismatch/) }
end
@ -211,8 +211,8 @@ describe "Exception" do
describe ResourceMissingError do
subject { described_class.new(formula, resource) }
let(:formula) { double(Formula, full_name: "bar") }
let(:resource) { double(inspect: "<resource foo>") }
let(:formula) { instance_double(Formula, full_name: "bar") }
let(:resource) { instance_double(Resource, inspect: "<resource foo>") }
its(:to_s) { is_expected.to eq("bar does not define resource <resource foo>") }
end
@ -220,7 +220,7 @@ describe "Exception" do
describe DuplicateResourceError do
subject { described_class.new(resource) }
let(:resource) { double(inspect: "<resource foo>") }
let(:resource) { instance_double(Resource, inspect: "<resource foo>") }
its(:to_s) { is_expected.to eq("Resource <resource foo> is defined more than once") }
end
@ -228,7 +228,7 @@ describe "Exception" do
describe BottleFormulaUnavailableError do
subject { described_class.new("/foo.bottle.tar.gz", "foo/1.0/.brew/foo.rb") }
let(:formula) { double(Formula, full_name: "foo") }
let(:formula) { instance_double(Formula, full_name: "foo") }
its(:to_s) { is_expected.to match(/This bottle does not contain the formula file/) }
end

View File

@ -7,7 +7,7 @@ describe FormulaPin do
subject(:formula_pin) { described_class.new(formula) }
let(:name) { "double" }
let(:formula) { double(Formula, name: name, rack: HOMEBREW_CELLAR/name) }
let(:formula) { instance_double(Formula, name: name, rack: HOMEBREW_CELLAR/name) }
before do
formula.rack.mkpath

View File

@ -298,17 +298,19 @@ describe Formula do
let(:f) { Testball.new }
it "returns false if the #latest_installed_prefix is not a directory" do
allow(f).to receive(:latest_installed_prefix).and_return(double(directory?: false))
allow(f).to receive(:latest_installed_prefix).and_return(instance_double(Pathname, directory?: false))
expect(f).not_to be_latest_version_installed
end
it "returns false if the #latest_installed_prefix does not have children" do
allow(f).to receive(:latest_installed_prefix).and_return(double(directory?: true, children: []))
allow(f).to receive(:latest_installed_prefix)
.and_return(instance_double(Pathname, directory?: true, children: []))
expect(f).not_to be_latest_version_installed
end
it "returns true if the #latest_installed_prefix has children" do
allow(f).to receive(:latest_installed_prefix).and_return(double(directory?: true, children: [double]))
allow(f).to receive(:latest_installed_prefix)
.and_return(instance_double(Pathname, directory?: true, children: [double]))
expect(f).to be_latest_version_installed
end
end
@ -821,7 +823,7 @@ describe Formula do
keg = Keg.for(formula.latest_installed_prefix)
keg.link
linkage_checker = double("linkage checker", undeclared_deps: [dependency.name])
linkage_checker = instance_double(LinkageChecker, "linkage checker", undeclared_deps: [dependency.name])
allow(LinkageChecker).to receive(:new).and_return(linkage_checker)
expect(formula.runtime_dependencies.map(&:name)).to eq [dependency.name]

View File

@ -9,10 +9,10 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
let(:dir) { mktmpdir }
let(:resource) { double("resource", stage: true) }
let(:resource) { instance_double(Resource, "resource", stage: true) }
let(:formula_bin) { dir/"formula_bin" }
let(:formula_man) { dir/"formula_man" }
let(:formula) { double("formula", resource: resource, bin: formula_bin, man: formula_man) }
let(:formula) { instance_double(Formula, "formula", resource: resource, bin: formula_bin, man: formula_man) }
describe "#create" do
it "creates a venv" do

View File

@ -7,7 +7,7 @@ describe LinkageCacheStore do
subject(:linkage_cache) { described_class.new(keg_name, database) }
let(:keg_name) { "keg_name" }
let(:database) { double("database") }
let(:database) { instance_double(CacheStoreDatabase, "database") }
describe "#keg_exists?" do
context "when `keg_name` exists in cache" do

View File

@ -188,7 +188,7 @@ describe Resource do
end
specify "#verify_download_integrity_mismatch" do
fn = double(file?: true, basename: "foo")
fn = instance_double(Pathname, file?: true, basename: "foo")
checksum = resource.sha256(TEST_SHA256)
expect(fn).to receive(:verify_checksum).with(checksum)

View File

@ -9,7 +9,7 @@ describe SoftwareSpec do
subject(:spec) { described_class.new }
let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") }
let(:owner) { instance_double(Cask::Cask, name: "some_name", full_name: "some_name", tap: "homebrew/core") }
describe "#resource" do
it "defines a resource" do

View File

@ -143,7 +143,7 @@ describe Utils::Analytics do
context "when formula does not have a tap" do
let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) }
let(:f) { double(Formula, name: "foo", path: "blah", tap: nil) }
let(:f) { instance_double(Formula, name: "foo", path: "blah", tap: nil) }
it "does not report event if BuildError is raised" do
expect(described_class).not_to receive(:report_event)
@ -153,7 +153,7 @@ describe Utils::Analytics do
context "when tap for a formula is not installed" do
let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) }
let(:f) { double(Formula, name: "foo", path: "blah", tap: CoreTap.instance) }
let(:f) { instance_double(Formula, name: "foo", path: "blah", tap: CoreTap.instance) }
it "does not report event if BuildError is raised" do
allow_any_instance_of(Pathname).to receive(:directory?).and_return(false)

View File

@ -246,11 +246,6 @@ describe Version do
end
describe "::create" do
it "accepts objects responding to #to_str" do
value = double(to_str: "0.1")
expect(described_class.create(value).to_s).to eq("0.1")
end
it "raises a TypeError for non-string objects" do
expect { described_class.create(1.1) }.to raise_error(TypeError)
expect { described_class.create(1) }.to raise_error(TypeError)