Add tests
This commit is contained in:
parent
d8d4d2031e
commit
9ab3cfb7a7
@ -58,7 +58,7 @@ module Cask
|
||||
sample_languages = if language_blocks.length > LANGUAGE_BLOCK_LIMIT && !@audit_new_cask
|
||||
sample_keys = language_blocks.keys.sample(LANGUAGE_BLOCK_LIMIT)
|
||||
sample_keys_sentence = ::Utils.to_sentence(sample_keys.map { |lang| lang[0].to_s })
|
||||
ohai "Auditing a sample of available languages: #{sameple_keys_sentence}"
|
||||
ohai "Auditing a sample of available languages: #{sample_keys_sentence}"
|
||||
language_blocks.select { |k| sample_keys.include?(k) }
|
||||
else
|
||||
language_blocks
|
||||
|
||||
@ -58,4 +58,51 @@ describe Utils do
|
||||
expect(described_class.pluralize("foo", 2, singular: "o", plural: "es")).to eq("fooes")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".to_sentence" do
|
||||
it "converts a plain array to a sentence" do
|
||||
expect(described_class.to_sentence([])).to eq("")
|
||||
expect(described_class.to_sentence(["one"])).to eq("one")
|
||||
expect(described_class.to_sentence(["one", "two"])).to eq("one and two")
|
||||
expect(described_class.to_sentence(["one", "two", "three"])).to eq("one, two, and three")
|
||||
end
|
||||
|
||||
it "converts an array to a sentence with a custom connector" do
|
||||
expect(described_class.to_sentence(["one", "two", "three"], words_connector: " ")).to eq("one two, and three")
|
||||
expect(described_class.to_sentence(["one", "two", "three"],
|
||||
words_connector: " & ")).to eq("one & two, and three")
|
||||
end
|
||||
|
||||
it "converts an array to a sentence with a custom last word connector" do
|
||||
expect(described_class.to_sentence(["one", "two", "three"],
|
||||
last_word_connector: ", and also ")).to eq("one, two, and also three")
|
||||
expect(described_class.to_sentence(["one", "two", "three"], last_word_connector: " ")).to eq("one, two three")
|
||||
expect(described_class.to_sentence(["one", "two", "three"],
|
||||
last_word_connector: " and ")).to eq("one, two and three")
|
||||
end
|
||||
|
||||
it "converts an array to a sentence with a custom two word connector" do
|
||||
expect(described_class.to_sentence(["one", "two"], two_words_connector: " ")).to eq("one two")
|
||||
end
|
||||
|
||||
it "creates a new string" do
|
||||
elements = ["one"]
|
||||
expect(described_class.to_sentence(elements).object_id).not_to eq(elements[0].object_id)
|
||||
end
|
||||
|
||||
it "converts a non-String to a sentence" do
|
||||
expect(described_class.to_sentence([1])).to eq("1")
|
||||
end
|
||||
|
||||
it "converts an array with blank elements to a sentence" do
|
||||
expect(described_class.to_sentence([nil, "one", "", "two", "three"])).to eq(", one, , two, and three")
|
||||
end
|
||||
|
||||
it "does not return a frozen string" do
|
||||
expect(described_class.to_sentence([])).not_to be_frozen
|
||||
expect(described_class.to_sentence(["one"])).not_to be_frozen
|
||||
expect(described_class.to_sentence(["one", "two"])).not_to be_frozen
|
||||
expect(described_class.to_sentence(["one", "two", "three"])).not_to be_frozen
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user