Merge pull request #2104 from reitermarkus/spec-integration-test-helpers
Convert `brew desc` test to spec and add integration test helper methods.
This commit is contained in:
commit
c7121f6be5
@ -335,7 +335,7 @@ class Pathname
|
|||||||
alias to_str to_s unless method_defined?(:to_str)
|
alias to_str to_s unless method_defined?(:to_str)
|
||||||
|
|
||||||
def cd
|
def cd
|
||||||
Dir.chdir(self) { yield }
|
Dir.chdir(self) { yield self }
|
||||||
end
|
end
|
||||||
|
|
||||||
def subdirs
|
def subdirs
|
||||||
|
|||||||
40
Library/Homebrew/test/cmd/desc_spec.rb
Normal file
40
Library/Homebrew/test/cmd/desc_spec.rb
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
describe "brew desc", :integration_test do
|
||||||
|
let(:desc_cache) { HOMEBREW_CACHE/"desc_cache.json" }
|
||||||
|
|
||||||
|
it "shows a given Formula's description" do
|
||||||
|
setup_test_formula "testball"
|
||||||
|
|
||||||
|
expect { brew "desc", "testball" }
|
||||||
|
.to output("testball: Some test\n").to_stdout
|
||||||
|
.and not_to_output.to_stderr
|
||||||
|
.and be_a_success
|
||||||
|
end
|
||||||
|
|
||||||
|
it "fails when both --search and --name are specified" do
|
||||||
|
expect { brew "desc", "--search", "--name" }
|
||||||
|
.to output(/Pick one, and only one/).to_stderr
|
||||||
|
.and not_to_output.to_stdout
|
||||||
|
.and be_a_failure
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "--search" do
|
||||||
|
it "fails when no search term is given" do
|
||||||
|
expect { brew "desc", "--search" }
|
||||||
|
.to output(/You must provide a search term/).to_stderr
|
||||||
|
.and not_to_output.to_stdout
|
||||||
|
.and be_a_failure
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "--description" do
|
||||||
|
it "creates a description cache" do
|
||||||
|
expect(desc_cache).not_to exist
|
||||||
|
|
||||||
|
shutup do
|
||||||
|
expect { brew "desc", "--description", "testball" }.to be_a_success
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(desc_cache).to exist
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,17 +0,0 @@
|
|||||||
require "testing_env"
|
|
||||||
|
|
||||||
class IntegrationCommandTestDesc < IntegrationCommandTestCase
|
|
||||||
def test_desc
|
|
||||||
setup_test_formula "testball"
|
|
||||||
|
|
||||||
assert_equal "testball: Some test", cmd("desc", "testball")
|
|
||||||
assert_match "Pick one, and only one", cmd_fail("desc", "--search", "--name")
|
|
||||||
assert_match "You must provide a search term", cmd_fail("desc", "--search")
|
|
||||||
|
|
||||||
desc_cache = HOMEBREW_CACHE/"desc_cache.json"
|
|
||||||
refute_predicate desc_cache, :exist?, "Cached file should not exist"
|
|
||||||
|
|
||||||
cmd("desc", "--description", "testball")
|
|
||||||
assert_predicate desc_cache, :exist?, "Cached file should not exist"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -37,6 +37,10 @@ RSpec.configure do |config|
|
|||||||
skip "Not on macOS." unless OS.mac?
|
skip "Not on macOS." unless OS.mac?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if example.metadata[:needs_official_cmd_taps]
|
||||||
|
skip "Needs official command Taps." unless ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"]
|
||||||
|
end
|
||||||
|
|
||||||
if example.metadata[:needs_python]
|
if example.metadata[:needs_python]
|
||||||
skip "Python not installed." unless which("python")
|
skip "Python not installed." unless which("python")
|
||||||
end
|
end
|
||||||
|
|||||||
@ -87,6 +87,80 @@ RSpec.shared_context "integration test" do
|
|||||||
status
|
status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setup_test_formula(name, content = nil)
|
||||||
|
case name
|
||||||
|
when /^testball/
|
||||||
|
content = <<-EOS.undent
|
||||||
|
desc "Some test"
|
||||||
|
homepage "https://example.com/#{name}"
|
||||||
|
url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
|
||||||
|
sha256 "#{TESTBALL_SHA256}"
|
||||||
|
|
||||||
|
option "with-foo", "Build with foo"
|
||||||
|
|
||||||
|
def install
|
||||||
|
(prefix/"foo"/"test").write("test") if build.with? "foo"
|
||||||
|
prefix.install Dir["*"]
|
||||||
|
(buildpath/"test.c").write \
|
||||||
|
"#include <stdio.h>\\nint main(){return printf(\\"test\\");}"
|
||||||
|
bin.mkpath
|
||||||
|
system ENV.cc, "test.c", "-o", bin/"test"
|
||||||
|
end
|
||||||
|
|
||||||
|
#{content}
|
||||||
|
|
||||||
|
# something here
|
||||||
|
EOS
|
||||||
|
when "foo"
|
||||||
|
content = <<-EOS.undent
|
||||||
|
url "https://example.com/#{name}-1.0"
|
||||||
|
EOS
|
||||||
|
when "bar"
|
||||||
|
content = <<-EOS.undent
|
||||||
|
url "https://example.com/#{name}-1.0"
|
||||||
|
depends_on "foo"
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
Formulary.core_path(name).tap do |formula_path|
|
||||||
|
formula_path.write <<-EOS.undent
|
||||||
|
class #{Formulary.class_s(name)} < Formula
|
||||||
|
#{content}
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_remote_tap(name)
|
||||||
|
Tap.fetch(name).tap do |tap|
|
||||||
|
tap.install(full_clone: false, quiet: true) unless tap.installed?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def install_and_rename_coretap_formula(old_name, new_name)
|
||||||
|
shutup do
|
||||||
|
CoreTap.instance.path.cd do |tap_path|
|
||||||
|
system "git", "init"
|
||||||
|
system "git", "add", "--all"
|
||||||
|
system "git", "commit", "-m",
|
||||||
|
"#{old_name.capitalize} has not yet been renamed"
|
||||||
|
|
||||||
|
brew "install", old_name
|
||||||
|
|
||||||
|
(tap_path/"Formula/#{old_name}.rb").unlink
|
||||||
|
(tap_path/"formula_renames.json").write JSON.generate(old_name => new_name)
|
||||||
|
|
||||||
|
system "git", "add", "--all"
|
||||||
|
system "git", "commit", "-m",
|
||||||
|
"#{old_name.capitalize} has been renamed to #{new_name.capitalize}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def testball
|
||||||
|
"#{TEST_FIXTURE_DIR}/testball.rb"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user