From 022bcbb269da6746734aa917bc0d5b43619c2e73 Mon Sep 17 00:00:00 2001 From: Seeker Date: Mon, 11 Jan 2021 12:28:07 -0800 Subject: [PATCH] test/utils/*: use `described_class` or named `subject` --- Library/Homebrew/test/.rubocop_todo.yml | 48 ++------------ .../test/utils/bottles/collector_spec.rb | 32 +++++----- Library/Homebrew/test/utils/github_spec.rb | 38 +++++------ Library/Homebrew/test/utils/popen_spec.rb | 14 ++-- Library/Homebrew/test/utils/shell_spec.rb | 52 +++++++-------- Library/Homebrew/test/utils/tty_spec.rb | 64 +++++++++---------- 6 files changed, 107 insertions(+), 141 deletions(-) diff --git a/Library/Homebrew/test/.rubocop_todo.yml b/Library/Homebrew/test/.rubocop_todo.yml index 7e7fa024f6..8fdbaa949d 100644 --- a/Library/Homebrew/test/.rubocop_todo.yml +++ b/Library/Homebrew/test/.rubocop_todo.yml @@ -1,28 +1,26 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 100` -# on 2019-03-28 10:03:26 +0000 using RuboCop version 0.66.0. +# on 2021-01-11 20:21:22 UTC using RuboCop version 1.8.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 +# Offense count: 2 # Configuration parameters: Max. RSpec/ExampleLength: Exclude: - 'rubocops/patches_spec.rb' - - 'dev-cmd/bottle_spec.rb' -# Offense count: 6 +# Offense count: 7 # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: Exclude: - 'download_strategies_spec.rb' - 'support/helper/spec/shared_context/integration_test.rb' - 'utils/git_spec.rb' - - 'version_spec.rb' -# Offense count: 76 +# Offense count: 73 RSpec/MultipleDescribes: Exclude: - 'ENV_spec.rb' @@ -34,7 +32,6 @@ RSpec/MultipleDescribes: - 'cmd/--repository_spec.rb' - 'cmd/--version_spec.rb' - 'cmd/analytics_spec.rb' - - 'cmd/autoremove_spec.rb' - 'cmd/cleanup_spec.rb' - 'cmd/commands_spec.rb' - 'cmd/config_spec.rb' @@ -57,7 +54,6 @@ RSpec/MultipleDescribes: - 'cmd/readall_spec.rb' - 'cmd/reinstall_spec.rb' - 'cmd/search_spec.rb' - - 'cmd/switch_spec.rb' - 'cmd/tap-info_spec.rb' - 'cmd/tap_spec.rb' - 'cmd/uninstall_spec.rb' @@ -78,17 +74,14 @@ RSpec/MultipleDescribes: - 'dev-cmd/irb_spec.rb' - 'dev-cmd/linkage_spec.rb' - 'dev-cmd/livecheck_spec.rb' - - 'dev-cmd/pull_spec.rb' - 'dev-cmd/ruby_spec.rb' - 'dev-cmd/sh_spec.rb' - - 'dev-cmd/style_spec.rb' - 'dev-cmd/tap-new_spec.rb' - 'dev-cmd/test_spec.rb' - 'dev-cmd/unpack_spec.rb' - 'download_strategies_spec.rb' - 'exceptions_spec.rb' - 'formula_support_spec.rb' - - 'inreplace_spec.rb' - 'language/python_spec.rb' - 'options_spec.rb' - 'os/mac/mach_spec.rb' @@ -96,21 +89,18 @@ RSpec/MultipleDescribes: - 'rubocops/checksum_spec.rb' - 'rubocops/class_spec.rb' - 'rubocops/deprecate_disable_spec.rb' - - 'rubocops/formula_desc_spec.rb' - 'rubocops/lines_spec.rb' - 'rubocops/livecheck_spec.rb' - 'rubocops/text_spec.rb' - 'rubocops/urls_spec.rb' - 'software_spec_spec.rb' - 'tap_spec.rb' - - 'utils/git_spec.rb' - 'version_spec.rb' -# Offense count: 816 +# Offense count: 665 # Configuration parameters: IgnoreSharedExamples. RSpec/NamedSubject: Exclude: - - 'ARGV_spec.rb' - 'ENV_spec.rb' - 'build_environment_spec.rb' - 'build_options_spec.rb' @@ -118,7 +108,6 @@ RSpec/NamedSubject: - 'cask/audit_spec.rb' - 'cask/cmd/style_spec.rb' - 'cask/cmd_spec.rb' - - 'cask/depends_on_spec.rb' - 'cask/dsl/appcast_spec.rb' - 'caveats_spec.rb' - 'cleaner_spec.rb' @@ -132,13 +121,10 @@ RSpec/NamedSubject: - 'descriptions_spec.rb' - 'diagnostic_checks_spec.rb' - 'download_strategies_spec.rb' - - 'emoji_spec.rb' - 'error_during_execution_spec.rb' - 'exceptions_spec.rb' - 'formatter_spec.rb' - 'formula_pin_spec.rb' - - 'inreplace_spec.rb' - - 'java_requirement_spec.rb' - 'language/node_spec.rb' - 'language/python_spec.rb' - 'linkage_cache_store_spec.rb' @@ -150,9 +136,7 @@ RSpec/NamedSubject: - 'os/linux/diagnostic_spec.rb' - 'os/mac/dependency_collector_spec.rb' - 'os/mac/diagnostic_spec.rb' - - 'os/mac/java_requirement_spec.rb' - 'os/mac/keg_spec.rb' - - 'os/mac/version_spec.rb' - 'os/mac_spec.rb' - 'patch_spec.rb' - 'requirement_spec.rb' @@ -161,36 +145,18 @@ RSpec/NamedSubject: - 'sandbox_spec.rb' - 'searchable_spec.rb' - 'software_spec_spec.rb' - - 'string_spec.rb' - 'system_command_result_spec.rb' - 'tab_spec.rb' - 'tap_spec.rb' - - 'utils/bottles/collector_spec.rb' - - 'utils/github_spec.rb' - - 'utils/popen_spec.rb' - - 'utils/shell_spec.rb' - - 'utils/tty_spec.rb' - 'utils_spec.rb' - 'version_spec.rb' - - 'x11_requirement_spec.rb' -# Offense count: 24 -RSpec/SubjectStub: - Exclude: - - 'cache_store_spec.rb' - - 'download_strategies_spec.rb' - - 'formula_installer_spec.rb' - - 'java_requirement_spec.rb' - - 'language/python_spec.rb' - - 'os/mac/java_requirement_spec.rb' - -# Offense count: 66 +# Offense count: 64 # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: - 'cache_store_spec.rb' - 'cask/artifact/pkg_spec.rb' - - 'cask/cmd/style_spec.rb' - 'cask/cmd_spec.rb' - 'cask/installer_spec.rb' - 'cask/pkg_spec.rb' @@ -205,9 +171,7 @@ RSpec/VerifiedDoubles: - 'formula_spec.rb' - 'language/python_spec.rb' - 'linkage_cache_store_spec.rb' - - 'livecheck/livecheck_spec.rb' - 'resource_spec.rb' - 'software_spec_spec.rb' - - 'support/helper/formula.rb' - 'utils/analytics_spec.rb' - 'version_spec.rb' diff --git a/Library/Homebrew/test/utils/bottles/collector_spec.rb b/Library/Homebrew/test/utils/bottles/collector_spec.rb index 3314db26d8..831f978321 100644 --- a/Library/Homebrew/test/utils/bottles/collector_spec.rb +++ b/Library/Homebrew/test/utils/bottles/collector_spec.rb @@ -4,43 +4,45 @@ require "utils/bottles" describe Utils::Bottles::Collector do + subject(:collector) { described_class.new } + describe "#fetch_checksum_for" do it "returns passed tags" do - subject[:mojave] = "foo" - subject[:catalina] = "bar" - expect(subject.fetch_checksum_for(:catalina)).to eq(["bar", :catalina]) + collector[:mojave] = "foo" + collector[:catalina] = "bar" + expect(collector.fetch_checksum_for(:catalina)).to eq(["bar", :catalina]) end it "returns nil if empty" do - expect(subject.fetch_checksum_for(:foo)).to be nil + expect(collector.fetch_checksum_for(:foo)).to be nil end it "returns nil when there is no match" do - subject[:catalina] = "foo" - expect(subject.fetch_checksum_for(:foo)).to be nil + collector[:catalina] = "foo" + expect(collector.fetch_checksum_for(:foo)).to be nil end it "uses older tags when needed", :needs_macos do - subject[:mojave] = "foo" - expect(subject.send(:find_matching_tag, :mojave)).to eq(:mojave) - expect(subject.send(:find_matching_tag, :catalina)).to eq(:mojave) + collector[:mojave] = "foo" + expect(collector.send(:find_matching_tag, :mojave)).to eq(:mojave) + expect(collector.send(:find_matching_tag, :catalina)).to eq(:mojave) end it "does not use older tags when requested not to", :needs_macos do allow(Homebrew::EnvConfig).to receive(:developer?).and_return(true) allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true) allow(OS::Mac).to receive(:prerelease?).and_return(true) - subject[:mojave] = "foo" - expect(subject.send(:find_matching_tag, :mojave)).to eq(:mojave) - expect(subject.send(:find_matching_tag, :catalina)).to be_nil + collector[:mojave] = "foo" + expect(collector.send(:find_matching_tag, :mojave)).to eq(:mojave) + expect(collector.send(:find_matching_tag, :catalina)).to be_nil end it "ignores HOMEBREW_SKIP_OR_LATER_BOTTLES on release versions", :needs_macos do allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true) allow(OS::Mac).to receive(:prerelease?).and_return(false) - subject[:mojave] = "foo" - expect(subject.send(:find_matching_tag, :mojave)).to eq(:mojave) - expect(subject.send(:find_matching_tag, :catalina)).to eq(:mojave) + collector[:mojave] = "foo" + expect(collector.send(:find_matching_tag, :mojave)).to eq(:mojave) + expect(collector.send(:find_matching_tag, :catalina)).to eq(:mojave) end end end diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 8704b8f6a5..b1de7fd7f4 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -6,8 +6,8 @@ require "utils/github" describe GitHub do describe "::search_code", :needs_network do it "queries GitHub code with the passed parameters" do - results = subject.search_code(repo: "Homebrew/brew", path: "/", - filename: "readme", language: "markdown") + results = described_class.search_code(repo: "Homebrew/brew", path: "/", + filename: "readme", language: "markdown") expect(results.count).to eq(1) expect(results.first["name"]).to eq("README.md") @@ -17,27 +17,27 @@ describe GitHub do describe "::query_string" do it "builds a query with the given hash parameters formatted as key:value" do - query = subject.query_string(user: "Homebrew", repo: "brew") + query = described_class.query_string(user: "Homebrew", repo: "brew") expect(query).to eq("q=user%3AHomebrew+repo%3Abrew&per_page=100") end it "adds a variable number of top-level string parameters to the query when provided" do - query = subject.query_string("value1", "value2", user: "Homebrew") + query = described_class.query_string("value1", "value2", user: "Homebrew") expect(query).to eq("q=value1+value2+user%3AHomebrew&per_page=100") end it "turns array values into multiple key:value parameters" do - query = subject.query_string(user: ["Homebrew", "caskroom"]) + query = described_class.query_string(user: ["Homebrew", "caskroom"]) expect(query).to eq("q=user%3AHomebrew+user%3Acaskroom&per_page=100") end end describe "::search_issues", :needs_network do it "queries GitHub issues with the passed parameters" do - results = subject.search_issues("brew search", - repo: "Homebrew/legacy-homebrew", - author: "MikeMcQuaid", - is: "closed") + results = described_class.search_issues("brew search", + repo: "Homebrew/legacy-homebrew", + author: "MikeMcQuaid", + is: "closed") expect(results).not_to be_empty expect(results.first["title"]).to eq("Shall we run `brew update` automatically?") end @@ -45,7 +45,7 @@ describe GitHub do describe "::approved_reviews", :needs_network do it "can get reviews for a pull request" do - reviews = subject.approved_reviews("Homebrew", "homebrew-core", 1, commit: "deadbeef") + reviews = described_class.approved_reviews("Homebrew", "homebrew-core", 1, commit: "deadbeef") expect(reviews).to eq([]) end end @@ -53,7 +53,7 @@ describe GitHub do describe "::sponsors_by_tier", :needs_network do it "errors on an unauthenticated token" do expect { - subject.sponsors_by_tier("Homebrew") + described_class.sponsors_by_tier("Homebrew") }.to raise_error(/INSUFFICIENT_SCOPES|FORBIDDEN|token needs the 'admin:org' scope/) end end @@ -61,23 +61,23 @@ describe GitHub do describe "::get_artifact_url", :needs_network do it "fails to find a nonexistant workflow" do expect { - subject.get_artifact_url( - subject.get_workflow_run("Homebrew", "homebrew-core", 1), + described_class.get_artifact_url( + described_class.get_workflow_run("Homebrew", "homebrew-core", 1), ) }.to raise_error(/No matching workflow run found/) end it "fails to find artifacts that don't exist" do expect { - subject.get_artifact_url( - subject.get_workflow_run("Homebrew", "homebrew-core", 51971, artifact_name: "false_bottles"), + described_class.get_artifact_url( + described_class.get_workflow_run("Homebrew", "homebrew-core", 51971, artifact_name: "false_bottles"), ) }.to raise_error(/No artifact .+ was found/) end it "gets an artifact link" do - url = subject.get_artifact_url( - subject.get_workflow_run("Homebrew", "homebrew-core", 51971, artifact_name: "bottles"), + url = described_class.get_artifact_url( + described_class.get_workflow_run("Homebrew", "homebrew-core", 51971, artifact_name: "bottles"), ) expect(url).to eq("https://api.github.com/repos/Homebrew/homebrew-core/actions/artifacts/3557392/zip") end @@ -87,11 +87,11 @@ describe GitHub do hashes = %w[188606a4a9587365d930b02c98ad6857b1d00150 25a71fe1ea1558415d6496d23834dc70778ddee5] it "gets commit hashes for a pull request" do - expect(subject.pull_request_commits("Homebrew", "legacy-homebrew", 50678)).to eq(hashes) + expect(described_class.pull_request_commits("Homebrew", "legacy-homebrew", 50678)).to eq(hashes) end it "gets commit hashes for a paginated pull request API response" do - expect(subject.pull_request_commits("Homebrew", "legacy-homebrew", 50678, per_page: 1)).to eq(hashes) + expect(described_class.pull_request_commits("Homebrew", "legacy-homebrew", 50678, per_page: 1)).to eq(hashes) end end end diff --git a/Library/Homebrew/test/utils/popen_spec.rb b/Library/Homebrew/test/utils/popen_spec.rb index 7ea5474e7a..5a00a0904e 100644 --- a/Library/Homebrew/test/utils/popen_spec.rb +++ b/Library/Homebrew/test/utils/popen_spec.rb @@ -6,13 +6,13 @@ require "utils/popen" describe Utils do describe "::popen_read" do it "reads the standard output of a given command" do - expect(subject.popen_read("sh", "-c", "echo success").chomp).to eq("success") + expect(described_class.popen_read("sh", "-c", "echo success").chomp).to eq("success") expect($CHILD_STATUS).to be_a_success end it "can be given a block to manually read from the pipe" do expect( - subject.popen_read("sh", "-c", "echo success") do |pipe| + described_class.popen_read("sh", "-c", "echo success") do |pipe| pipe.read.chomp end, ).to eq("success") @@ -20,7 +20,7 @@ describe Utils do end it "fails when the command does not exist" do - expect(subject.popen_read("./nonexistent", err: :out)) + expect(described_class.popen_read("./nonexistent", err: :out)) .to eq("brew: command not found: ./nonexistent\n") expect($CHILD_STATUS).to be_a_failure end @@ -32,14 +32,14 @@ describe Utils do before { foo.write "Foo\n" } it "supports writing to a command's standard input" do - subject.popen_write("grep", "-q", "success") do |pipe| + described_class.popen_write("grep", "-q", "success") do |pipe| pipe.write "success\n" end expect($CHILD_STATUS).to be_a_success end it "returns the command's standard output before writing" do - child_stdout = subject.popen_write("cat", foo, "-") do |pipe| + child_stdout = described_class.popen_write("cat", foo, "-") do |pipe| pipe.write "Bar\n" end expect($CHILD_STATUS).to be_a_success @@ -50,7 +50,7 @@ describe Utils do end it "returns the command's standard output after writing" do - child_stdout = subject.popen_write("cat", "-", foo) do |pipe| + child_stdout = described_class.popen_write("cat", "-", foo) do |pipe| pipe.write "Bar\n" end expect($CHILD_STATUS).to be_a_success @@ -61,7 +61,7 @@ describe Utils do end it "supports interleaved writing between two reads" do - child_stdout = subject.popen_write("cat", foo, "-", foo) do |pipe| + child_stdout = described_class.popen_write("cat", foo, "-", foo) do |pipe| pipe.write "Bar\n" end expect($CHILD_STATUS).to be_a_success diff --git a/Library/Homebrew/test/utils/shell_spec.rb b/Library/Homebrew/test/utils/shell_spec.rb index 3db721c63f..0e32d29361 100644 --- a/Library/Homebrew/test/utils/shell_spec.rb +++ b/Library/Homebrew/test/utils/shell_spec.rb @@ -7,76 +7,76 @@ describe Utils::Shell do describe "::profile" do it "returns ~/.profile by default" do ENV["SHELL"] = "/bin/another_shell" - expect(subject.profile).to eq("~/.profile") + expect(described_class.profile).to eq("~/.profile") end it "returns ~/.profile for sh" do ENV["SHELL"] = "/bin/sh" - expect(subject.profile).to eq("~/.profile") + expect(described_class.profile).to eq("~/.profile") end it "returns ~/.profile for Bash" do ENV["SHELL"] = "/bin/bash" - expect(subject.profile).to eq("~/.profile") + expect(described_class.profile).to eq("~/.profile") end it "returns /tmp/.zshrc for Zsh if ZDOTDIR is /tmp" do ENV["SHELL"] = "/bin/zsh" ENV["ZDOTDIR"] = "/tmp" - expect(subject.profile).to eq("/tmp/.zshrc") + expect(described_class.profile).to eq("/tmp/.zshrc") end it "returns ~/.zshrc for Zsh" do ENV["SHELL"] = "/bin/zsh" ENV["ZDOTDIR"] = nil - expect(subject.profile).to eq("~/.zshrc") + expect(described_class.profile).to eq("~/.zshrc") end it "returns ~/.kshrc for Ksh" do ENV["SHELL"] = "/bin/ksh" - expect(subject.profile).to eq("~/.kshrc") + expect(described_class.profile).to eq("~/.kshrc") end end describe "::from_path" do it "supports a raw command name" do - expect(subject.from_path("bash")).to eq(:bash) + expect(described_class.from_path("bash")).to eq(:bash) end it "supports full paths" do - expect(subject.from_path("/bin/bash")).to eq(:bash) + expect(described_class.from_path("/bin/bash")).to eq(:bash) end it "supports versions" do - expect(subject.from_path("zsh-5.2")).to eq(:zsh) + expect(described_class.from_path("zsh-5.2")).to eq(:zsh) end it "strips newlines" do - expect(subject.from_path("zsh-5.2\n")).to eq(:zsh) + expect(described_class.from_path("zsh-5.2\n")).to eq(:zsh) end it "returns nil when input is invalid" do - expect(subject.from_path("")).to be nil - expect(subject.from_path("@@@@@@")).to be nil - expect(subject.from_path("invalid_shell-4.2")).to be nil + expect(described_class.from_path("")).to be nil + expect(described_class.from_path("@@@@@@")).to be nil + expect(described_class.from_path("invalid_shell-4.2")).to be nil end end specify "::sh_quote" do - expect(subject.send(:sh_quote, "")).to eq("''") - expect(subject.send(:sh_quote, "\\")).to eq("\\\\") - expect(subject.send(:sh_quote, "\n")).to eq("'\n'") - expect(subject.send(:sh_quote, "$")).to eq("\\$") - expect(subject.send(:sh_quote, "word")).to eq("word") + expect(described_class.send(:sh_quote, "")).to eq("''") + expect(described_class.send(:sh_quote, "\\")).to eq("\\\\") + expect(described_class.send(:sh_quote, "\n")).to eq("'\n'") + expect(described_class.send(:sh_quote, "$")).to eq("\\$") + expect(described_class.send(:sh_quote, "word")).to eq("word") end specify "::csh_quote" do - expect(subject.send(:csh_quote, "")).to eq("''") - expect(subject.send(:csh_quote, "\\")).to eq("\\\\") + expect(described_class.send(:csh_quote, "")).to eq("''") + expect(described_class.send(:csh_quote, "\\")).to eq("\\\\") # NOTE: this test is different than for sh - expect(subject.send(:csh_quote, "\n")).to eq("'\\\n'") - expect(subject.send(:csh_quote, "$")).to eq("\\$") - expect(subject.send(:csh_quote, "word")).to eq("word") + expect(described_class.send(:csh_quote, "\n")).to eq("'\\\n'") + expect(described_class.send(:csh_quote, "$")).to eq("\\$") + expect(described_class.send(:csh_quote, "word")).to eq("word") end describe "::prepend_path_in_profile" do @@ -84,20 +84,20 @@ describe Utils::Shell do it "supports Tcsh" do ENV["SHELL"] = "/bin/tcsh" - expect(subject.prepend_path_in_profile(path)) + expect(described_class.prepend_path_in_profile(path)) .to eq("echo 'setenv PATH #{path}:$PATH' >> #{shell_profile}") end it "supports Bash" do ENV["SHELL"] = "/bin/bash" - expect(subject.prepend_path_in_profile(path)) + expect(described_class.prepend_path_in_profile(path)) .to eq("echo 'export PATH=\"#{path}:$PATH\"' >> #{shell_profile}") end it "supports Fish" do ENV["SHELL"] = "/usr/local/bin/fish" ENV["fish_user_paths"] = "/some/path" - expect(subject.prepend_path_in_profile(path)) + expect(described_class.prepend_path_in_profile(path)) .to eq("echo 'set -g fish_user_paths \"#{path}\" $fish_user_paths' >> #{shell_profile}") end end diff --git a/Library/Homebrew/test/utils/tty_spec.rb b/Library/Homebrew/test/utils/tty_spec.rb index 6f728041f0..948306a645 100644 --- a/Library/Homebrew/test/utils/tty_spec.rb +++ b/Library/Homebrew/test/utils/tty_spec.rb @@ -4,31 +4,31 @@ describe Tty do describe "::strip_ansi" do it "removes ANSI escape codes from a string" do - expect(subject.strip_ansi("\033\[36;7mhello\033\[0m")).to eq("hello") + expect(described_class.strip_ansi("\033\[36;7mhello\033\[0m")).to eq("hello") end end describe "::width" do it "returns an Integer" do - expect(subject.width).to be_kind_of(Integer) + expect(described_class.width).to be_kind_of(Integer) end it "cannot be negative" do - expect(subject.width).to be >= 0 + expect(described_class.width).to be >= 0 end end describe "::truncate" do it "truncates the text to the terminal width, minus 4, to account for '==> '" do - allow(subject).to receive(:width).and_return(15) + allow(described_class).to receive(:width).and_return(15) - expect(subject.truncate("foobar something very long")).to eq("foobar some") - expect(subject.truncate("truncate")).to eq("truncate") + expect(described_class.truncate("foobar something very long")).to eq("foobar some") + expect(described_class.truncate("truncate")).to eq("truncate") end it "doesn't truncate the text if the terminal is unsupported, i.e. the width is 0" do - allow(subject).to receive(:width).and_return(0) - expect(subject.truncate("foobar something very long")).to eq("foobar something very long") + allow(described_class).to receive(:width).and_return(0) + expect(described_class.truncate("foobar something very long")).to eq("foobar something very long") end end @@ -38,14 +38,14 @@ describe Tty do end it "returns an empty string for all colors" do - expect(subject.to_s).to eq("") - expect(subject.red.to_s).to eq("") - expect(subject.green.to_s).to eq("") - expect(subject.yellow.to_s).to eq("") - expect(subject.blue.to_s).to eq("") - expect(subject.magenta.to_s).to eq("") - expect(subject.cyan.to_s).to eq("") - expect(subject.default.to_s).to eq("") + expect(described_class.to_s).to eq("") + expect(described_class.red.to_s).to eq("") + expect(described_class.green.to_s).to eq("") + expect(described_class.yellow.to_s).to eq("") + expect(described_class.blue.to_s).to eq("") + expect(described_class.magenta.to_s).to eq("") + expect(described_class.cyan.to_s).to eq("") + expect(described_class.default.to_s).to eq("") end end @@ -55,26 +55,26 @@ describe Tty do end it "returns ANSI escape codes for colors" do - expect(subject.to_s).to eq("") - expect(subject.red.to_s).to eq("\033[31m") - expect(subject.green.to_s).to eq("\033[32m") - expect(subject.yellow.to_s).to eq("\033[33m") - expect(subject.blue.to_s).to eq("\033[34m") - expect(subject.magenta.to_s).to eq("\033[35m") - expect(subject.cyan.to_s).to eq("\033[36m") - expect(subject.default.to_s).to eq("\033[39m") + expect(described_class.to_s).to eq("") + expect(described_class.red.to_s).to eq("\033[31m") + expect(described_class.green.to_s).to eq("\033[32m") + expect(described_class.yellow.to_s).to eq("\033[33m") + expect(described_class.blue.to_s).to eq("\033[34m") + expect(described_class.magenta.to_s).to eq("\033[35m") + expect(described_class.cyan.to_s).to eq("\033[36m") + expect(described_class.default.to_s).to eq("\033[39m") end it "returns an empty string for all colors when HOMEBREW_NO_COLOR is set" do ENV["HOMEBREW_NO_COLOR"] = "1" - expect(subject.to_s).to eq("") - expect(subject.red.to_s).to eq("") - expect(subject.green.to_s).to eq("") - expect(subject.yellow.to_s).to eq("") - expect(subject.blue.to_s).to eq("") - expect(subject.magenta.to_s).to eq("") - expect(subject.cyan.to_s).to eq("") - expect(subject.default.to_s).to eq("") + expect(described_class.to_s).to eq("") + expect(described_class.red.to_s).to eq("") + expect(described_class.green.to_s).to eq("") + expect(described_class.yellow.to_s).to eq("") + expect(described_class.blue.to_s).to eq("") + expect(described_class.magenta.to_s).to eq("") + expect(described_class.cyan.to_s).to eq("") + expect(described_class.default.to_s).to eq("") end end end