Move tests
This commit is contained in:
parent
23587b70a1
commit
1f742727af
@ -59,4 +59,45 @@ describe Homebrew::Search do
|
||||
expect { described_class.query_regexp("/+/") }.to raise_error(/not a valid regex/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#search" do
|
||||
let(:collection) { ["with-dashes"] }
|
||||
|
||||
context "when given a block" do
|
||||
let(:collection) { [["with-dashes", "withdashes"]] }
|
||||
|
||||
it "searches by the selected argument" do
|
||||
expect(described_class.search(collection, /withdashes/) { |_, short_name| short_name }).not_to be_empty
|
||||
expect(described_class.search(collection, /withdashes/) { |long_name, _| long_name }).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "when given a regex" do
|
||||
it "does not simplify strings" do
|
||||
expect(described_class.search(collection, /with-dashes/)).to eq ["with-dashes"]
|
||||
end
|
||||
end
|
||||
|
||||
context "when given a string" do
|
||||
it "simplifies both the query and searched strings" do
|
||||
expect(described_class.search(collection, "with dashes")).to eq ["with-dashes"]
|
||||
end
|
||||
end
|
||||
|
||||
context "when searching a Hash" do
|
||||
let(:collection) { { "foo" => "bar" } }
|
||||
|
||||
it "returns a Hash" do
|
||||
expect(described_class.search(collection, "foo")).to eq "foo" => "bar"
|
||||
end
|
||||
|
||||
context "with a nil value" do
|
||||
let(:collection) { { "foo" => nil } }
|
||||
|
||||
it "does not raise an error" do
|
||||
expect(described_class.search(collection, "foo")).to eq "foo" => nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,49 +0,0 @@
|
||||
# typed: false
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "searchable"
|
||||
|
||||
describe Searchable do
|
||||
subject(:searchable_collection) { collection.extend(described_class) }
|
||||
|
||||
let(:collection) { ["with-dashes"] }
|
||||
|
||||
describe "#search" do
|
||||
context "when given a block" do
|
||||
let(:collection) { [["with-dashes", "withdashes"]] }
|
||||
|
||||
it "searches by the selected argument" do
|
||||
expect(searchable_collection.search(/withdashes/) { |_, short_name| short_name }).not_to be_empty
|
||||
expect(searchable_collection.search(/withdashes/) { |long_name, _| long_name }).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "when given a regex" do
|
||||
it "does not simplify strings" do
|
||||
expect(searchable_collection.search(/with-dashes/)).to eq ["with-dashes"]
|
||||
end
|
||||
end
|
||||
|
||||
context "when given a string" do
|
||||
it "simplifies both the query and searched strings" do
|
||||
expect(searchable_collection.search("with dashes")).to eq ["with-dashes"]
|
||||
end
|
||||
end
|
||||
|
||||
context "when searching a Hash" do
|
||||
let(:collection) { { "foo" => "bar" } }
|
||||
|
||||
it "returns a Hash" do
|
||||
expect(searchable_collection.search("foo")).to eq "foo" => "bar"
|
||||
end
|
||||
|
||||
context "with a nil value" do
|
||||
let(:collection) { { "foo" => nil } }
|
||||
|
||||
it "does not raise an error" do
|
||||
expect(searchable_collection.search("foo")).to eq "foo" => nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user