diff options
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/build_options_spec.rb | 52 | ||||
| -rw-r--r-- | Library/Homebrew/test/build_options_test.rb | 50 | ||||
| -rw-r--r-- | Library/Homebrew/test/caveats_spec.rb | 29 | ||||
| -rw-r--r-- | Library/Homebrew/test/caveats_test.rb | 30 | ||||
| -rw-r--r-- | Library/Homebrew/test/cmd/info_spec.rb | 20 | ||||
| -rw-r--r-- | Library/Homebrew/test/info_test.rb | 20 | ||||
| -rw-r--r-- | Library/Homebrew/test/options_spec.rb | 148 | ||||
| -rw-r--r-- | Library/Homebrew/test/options_test.rb | 148 | ||||
| -rw-r--r-- | Library/Homebrew/test/tab_spec.rb | 10 |
9 files changed, 254 insertions, 253 deletions
diff --git a/Library/Homebrew/test/build_options_spec.rb b/Library/Homebrew/test/build_options_spec.rb new file mode 100644 index 000000000..5acc12f30 --- /dev/null +++ b/Library/Homebrew/test/build_options_spec.rb @@ -0,0 +1,52 @@ +require "build_options" +require "options" + +RSpec::Matchers.alias_matcher :be_built_with, :be_with +RSpec::Matchers.alias_matcher :be_built_without, :be_without + +describe BuildOptions do + subject { described_class.new(args, opts) } + let(:bad_build) { described_class.new(bad_args, opts) } + let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) } + let(:opts) { Options.create(%w[--with-foo --with-bar --without-baz --without-qux]) } + let(:bad_args) { Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc]) } + + specify "#include?" do + expect(subject).to include("with-foo") + expect(subject).not_to include("with-qux") + expect(subject).not_to include("--with-foo") + end + + specify "#with?" do + expect(subject).to be_built_with("foo") + expect(subject).to be_built_with("bar") + expect(subject).to be_built_with("baz") + end + + specify "#without?" do + expect(subject).to be_built_without("qux") + expect(subject).to be_built_without("xyz") + end + + specify "#used_options" do + expect(subject.used_options).to include("--with-foo") + expect(subject.used_options).to include("--with-bar") + end + + specify "#unused_options" do + expect(subject.unused_options).to include("--without-baz") + end + + specify "#invalid_options" do + expect(subject.invalid_options).to be_empty + expect(bad_build.invalid_options).to include("--without-bas") + expect(bad_build.invalid_options).to include("--without-abc") + expect(bad_build.invalid_options).not_to include("--with-foo") + expect(bad_build.invalid_options).not_to include("--with-baz") + end + + specify "#invalid_option_names" do + expect(subject.invalid_option_names).to be_empty + expect(bad_build.invalid_option_names).to eq(%w[--without-abc --without-bas]) + end +end diff --git a/Library/Homebrew/test/build_options_test.rb b/Library/Homebrew/test/build_options_test.rb deleted file mode 100644 index 05e7ccd94..000000000 --- a/Library/Homebrew/test/build_options_test.rb +++ /dev/null @@ -1,50 +0,0 @@ -require "testing_env" -require "build_options" -require "options" - -class BuildOptionsTests < Homebrew::TestCase - def setup - super - args = Options.create(%w[--with-foo --with-bar --without-qux]) - opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux]) - @build = BuildOptions.new(args, opts) - bad_args = Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc]) - @bad_build = BuildOptions.new(bad_args, opts) - end - - def test_include - assert_includes @build, "with-foo" - refute_includes @build, "with-qux" - refute_includes @build, "--with-foo" - end - - def test_with_without - assert @build.with?("foo") - assert @build.with?("bar") - assert @build.with?("baz") - assert @build.without?("qux") - assert @build.without?("xyz") - end - - def test_used_options - assert_includes @build.used_options, "--with-foo" - assert_includes @build.used_options, "--with-bar" - end - - def test_unused_options - assert_includes @build.unused_options, "--without-baz" - end - - def test_invalid_options - assert_empty @build.invalid_options - assert_includes @bad_build.invalid_options, "--without-bas" - assert_includes @bad_build.invalid_options, "--without-abc" - refute_includes @bad_build.invalid_options, "--with-foo" - refute_includes @bad_build.invalid_options, "--with-baz" - end - - def test_invalid_option_names - assert_empty @build.invalid_option_names - assert_equal @bad_build.invalid_option_names, %w[--without-abc --without-bas] - end -end diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb new file mode 100644 index 000000000..d8be9dc52 --- /dev/null +++ b/Library/Homebrew/test/caveats_spec.rb @@ -0,0 +1,29 @@ +require "formula" +require "caveats" + +describe Caveats do + subject { described_class.new(f) } + let(:f) { formula { url "foo-1.0" } } + + specify "#f" do + expect(subject.f).to eq(f) + end + + describe "#empty?" do + it "returns true if the Formula has no caveats" do + expect(subject).to be_empty + end + + it "returns false if the Formula has caveats" do + f = formula do + url "foo-1.0" + + def caveats + "something" + end + end + + expect(described_class.new(f)).not_to be_empty + end + end +end diff --git a/Library/Homebrew/test/caveats_test.rb b/Library/Homebrew/test/caveats_test.rb deleted file mode 100644 index 3a582b907..000000000 --- a/Library/Homebrew/test/caveats_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "testing_env" -require "formula" -require "caveats" - -class CaveatsTests < Homebrew::TestCase - def setup - super - @f = formula { url "foo-1.0" } - @c = Caveats.new @f - end - - def test_f - assert_equal @f, @c.f - end - - def test_empty? - assert @c.empty? - - f = formula do - url "foo-1.0" - - def caveats - "something" - end - end - c = Caveats.new f - - refute c.empty? - end -end diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index d33035972..8deef3d23 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -1,3 +1,5 @@ +require "cmd/info" + describe "brew info", :integration_test do it "prints information about a given Formula" do setup_test_formula "testball" @@ -8,3 +10,21 @@ describe "brew info", :integration_test do .and be_a_success end end + +describe Homebrew do + let(:remote) { "https://github.com/Homebrew/homebrew-core" } + + specify "::github_remote_path" do + expect(subject.github_remote_path(remote, "Formula/git.rb")) + .to eq("https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb") + + expect(subject.github_remote_path("#{remote}.git", "Formula/git.rb")) + .to eq("https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb") + + expect(subject.github_remote_path("git@github.com:user/repo", "foo.rb")) + .to eq("https://github.com/user/repo/blob/master/foo.rb") + + expect(subject.github_remote_path("https://mywebsite.com", "foo/bar.rb")) + .to eq("https://mywebsite.com/foo/bar.rb") + end +end diff --git a/Library/Homebrew/test/info_test.rb b/Library/Homebrew/test/info_test.rb deleted file mode 100644 index d8a0f7904..000000000 --- a/Library/Homebrew/test/info_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "testing_env" -require "cmd/info" -require "formula" -require "testing_env" - -class InfoCommandTests < Homebrew::TestCase - def test_github_remote_path - remote = "https://github.com/Homebrew/homebrew-core" - assert_equal "https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb", - Homebrew.github_remote_path(remote, "Formula/git.rb") - assert_equal "https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb", - Homebrew.github_remote_path("#{remote}.git", "Formula/git.rb") - - assert_equal "https://github.com/user/repo/blob/master/foo.rb", - Homebrew.github_remote_path("git@github.com:user/repo", "foo.rb") - - assert_equal "https://mywebsite.com/foo/bar.rb", - Homebrew.github_remote_path("https://mywebsite.com", "foo/bar.rb") - end -end diff --git a/Library/Homebrew/test/options_spec.rb b/Library/Homebrew/test/options_spec.rb new file mode 100644 index 000000000..a05bb139e --- /dev/null +++ b/Library/Homebrew/test/options_spec.rb @@ -0,0 +1,148 @@ +require "options" + +describe Option do + subject { described_class.new("foo") } + + specify "#to_s" do + expect(subject.to_s).to eq("--foo") + end + + specify "equality" do + foo = Option.new("foo") + bar = Option.new("bar") + expect(subject).to eq(foo) + expect(subject).not_to eq(bar) + expect(subject).to eql(foo) + expect(subject).not_to eql(bar) + end + + specify "#description" do + expect(subject.description).to be_empty + expect(Option.new("foo", "foo").description).to eq("foo") + end + + specify "#inspect" do + expect(subject.inspect).to eq("#<Option: \"--foo\">") + end +end + +describe DeprecatedOption do + subject { described_class.new("foo", "bar") } + + specify "#old" do + expect(subject.old).to eq("foo") + end + + specify "#old_flag" do + expect(subject.old_flag).to eq("--foo") + end + + specify "#current" do + expect(subject.current).to eq("bar") + end + + specify "#current_flag" do + expect(subject.current_flag).to eq("--bar") + end + + specify "equality" do + foobar = DeprecatedOption.new("foo", "bar") + boofar = DeprecatedOption.new("boo", "far") + expect(foobar).to eq(subject) + expect(subject).to eq(foobar) + expect(boofar).not_to eq(subject) + expect(subject).not_to eq(boofar) + end +end + +describe Options do + it "removes duplicate options" do + subject << Option.new("foo") + subject << Option.new("foo") + expect(subject).to include("--foo") + expect(subject.count).to eq(1) + end + + it "preserves existing member when adding a duplicate" do + a = Option.new("foo", "bar") + b = Option.new("foo", "qux") + subject << a << b + expect(subject.count).to eq(1) + expect(subject.first).to be(a) + expect(subject.first.description).to eq(a.description) + end + + specify "#include?" do + subject << Option.new("foo") + expect(subject).to include("--foo") + expect(subject).to include("foo") + expect(subject).to include(Option.new("foo")) + end + + describe "#+" do + it "returns options" do + expect(subject + Options.new).to be_an_instance_of(Options) + end + end + + describe "#-" do + it "returns options" do + expect(subject - Options.new).to be_an_instance_of(Options) + end + end + + specify "#&" do + foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) } + options = Options.new << foo << bar + subject << foo << baz + expect((subject & options).to_a).to eq([foo]) + end + + specify "#|" do + foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) } + options = Options.new << foo << bar + subject << foo << baz + expect((subject | options).sort).to eq([foo, bar, baz].sort) + end + + specify "#*" do + subject << Option.new("aa") << Option.new("bb") << Option.new("cc") + expect((subject * "XX").split("XX").sort).to eq(%w[--aa --bb --cc]) + end + + describe "<<" do + it "returns itself" do + expect(subject << Option.new("foo")).to be subject + end + end + + specify "#as_flags" do + subject << Option.new("foo") + expect(subject.as_flags).to eq(%w[--foo]) + end + + specify "#to_a" do + option = Option.new("foo") + subject << option + expect(subject.to_a).to eq([option]) + end + + specify "#to_ary" do + option = Option.new("foo") + subject << option + expect(subject.to_ary).to eq([option]) + end + + specify "::create_with_array" do + array = %w[--foo --bar] + option1 = Option.new("foo") + option2 = Option.new("bar") + expect(Options.create(array).sort).to eq([option1, option2].sort) + end + + specify "#inspect" do + expect(subject.inspect).to eq("#<Options: []>") + subject << Option.new("foo") + expect(subject.inspect).to eq("#<Options: [#<Option: \"--foo\">]>") + end +end diff --git a/Library/Homebrew/test/options_test.rb b/Library/Homebrew/test/options_test.rb deleted file mode 100644 index 0a6e198d3..000000000 --- a/Library/Homebrew/test/options_test.rb +++ /dev/null @@ -1,148 +0,0 @@ -require "testing_env" -require "options" - -class OptionTests < Homebrew::TestCase - def setup - super - @option = Option.new("foo") - end - - def test_to_s - assert_equal "--foo", @option.to_s - end - - def test_equality - foo = Option.new("foo") - bar = Option.new("bar") - assert_equal foo, @option - refute_equal bar, @option - assert_eql @option, foo - refute_eql @option, bar - end - - def test_description - assert_empty @option.description - assert_equal "foo", Option.new("foo", "foo").description - end - - def test_inspect - assert_equal "#<Option: \"--foo\">", @option.inspect - end -end - -class DeprecatedOptionTests < Homebrew::TestCase - def setup - super - @deprecated_option = DeprecatedOption.new("foo", "bar") - end - - def test_old - assert_equal "foo", @deprecated_option.old - assert_equal "--foo", @deprecated_option.old_flag - end - - def test_current - assert_equal "bar", @deprecated_option.current - assert_equal "--bar", @deprecated_option.current_flag - end - - def test_equality - foobar = DeprecatedOption.new("foo", "bar") - boofar = DeprecatedOption.new("boo", "far") - assert_equal foobar, @deprecated_option - refute_equal boofar, @deprecated_option - assert_eql @deprecated_option, foobar - refute_eql @deprecated_option, boofar - end -end - -class OptionsTests < Homebrew::TestCase - def setup - super - @options = Options.new - end - - def test_no_duplicate_options - @options << Option.new("foo") - @options << Option.new("foo") - assert_includes @options, "--foo" - assert_equal 1, @options.count - end - - def test_preserves_existing_member_when_pushing_duplicate - a = Option.new("foo", "bar") - b = Option.new("foo", "qux") - @options << a << b - assert_equal 1, @options.count - assert_same a, @options.first - assert_equal a.description, @options.first.description - end - - def test_include - @options << Option.new("foo") - assert_includes @options, "--foo" - assert_includes @options, "foo" - assert_includes @options, Option.new("foo") - end - - def test_union_returns_options - assert_instance_of Options, @options + Options.new - end - - def test_difference_returns_options - assert_instance_of Options, @options - Options.new - end - - def test_shovel_returns_self - assert_same @options, @options << Option.new("foo") - end - - def test_as_flags - @options << Option.new("foo") - assert_equal %w[--foo], @options.as_flags - end - - def test_to_a - option = Option.new("foo") - @options << option - assert_equal [option], @options.to_a - end - - def test_to_ary - option = Option.new("foo") - @options << option - assert_equal [option], @options.to_ary - end - - def test_intersection - foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) } - options = Options.new << foo << bar - @options << foo << baz - assert_equal [foo], (@options & options).to_a - end - - def test_set_union - foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) } - options = Options.new << foo << bar - @options << foo << baz - assert_equal [foo, bar, baz].sort, (@options | options).sort - end - - def test_times - @options << Option.new("aa") << Option.new("bb") << Option.new("cc") - assert_equal %w[--aa --bb --cc], (@options * "XX").split("XX").sort - end - - def test_create_with_array - array = %w[--foo --bar] - option1 = Option.new("foo") - option2 = Option.new("bar") - assert_equal [option1, option2].sort, Options.create(array).sort - end - - def test_inspect - assert_equal "#<Options: []>", @options.inspect - @options << Option.new("foo") - assert_equal "#<Options: [#<Option: \"--foo\">]>", @options.inspect - end -end diff --git a/Library/Homebrew/test/tab_spec.rb b/Library/Homebrew/test/tab_spec.rb index 32a06a681..01dbeb67c 100644 --- a/Library/Homebrew/test/tab_spec.rb +++ b/Library/Homebrew/test/tab_spec.rb @@ -1,7 +1,7 @@ require "tab" require "formula" -RSpec::Matchers.alias_matcher :have_option_with, :be_with +RSpec::Matchers.alias_matcher :be_built_with, :be_with describe Tab do matcher :be_poured_from_bottle do @@ -80,10 +80,10 @@ describe Tab do end specify "#with?" do - expect(subject).to have_option_with("foo") - expect(subject).to have_option_with("qux") - expect(subject).not_to have_option_with("bar") - expect(subject).not_to have_option_with("baz") + expect(subject).to be_built_with("foo") + expect(subject).to be_built_with("qux") + expect(subject).not_to be_built_with("bar") + expect(subject).not_to be_built_with("baz") end specify "#universal?" do |
