Check arrays are empty instead of size 0

In ruby we check for `array.empty?` instead of `array.size == 0`, so
it's natural to write the tests in the same way.
This commit is contained in:
Javi Martín
2019-09-24 20:49:26 +02:00
parent 98fe8349d7
commit 4301937e85
9 changed files with 15 additions and 12 deletions

View File

@@ -91,7 +91,7 @@ describe EmailDigest do
email_digest = EmailDigest.new(user) email_digest = EmailDigest.new(user)
email_digest.deliver(Time.current) email_digest.deliver(Time.current)
expect(all_emails.count).to eq(0) expect(all_emails).to be_empty
end end
end end

View File

@@ -10,11 +10,11 @@ describe Verification::Residence do
it "is valid with postal codes starting with 280" do it "is valid with postal codes starting with 280" do
residence.postal_code = "28012" residence.postal_code = "28012"
residence.valid? residence.valid?
expect(residence.errors[:postal_code].size).to eq(0) expect(residence.errors[:postal_code]).to be_empty
residence.postal_code = "28023" residence.postal_code = "28023"
residence.valid? residence.valid?
expect(residence.errors[:postal_code].size).to eq(0) expect(residence.errors[:postal_code]).to be_empty
end end
it "is not valid with postal codes not starting with 280" do it "is not valid with postal codes not starting with 280" do

View File

@@ -762,7 +762,7 @@ describe Debate do
it "does not return any debates when user has not interests" do it "does not return any debates when user has not interests" do
create(:debate) create(:debate)
expect(Debate.recommendations(user).size).to eq 0 expect(Debate.recommendations(user)).to be_empty
end end
it "returns debates ordered by cached_votes_total" do it "returns debates ordered by cached_votes_total" do

View File

@@ -91,7 +91,8 @@ describe Officing::Residence do
custom_residence = Officing::Residence.new("date_of_birth(3i)" => "1", custom_residence = Officing::Residence.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1", "date_of_birth(2i)" => "1",
"date_of_birth(1i)" => "1980") "date_of_birth(1i)" => "1980")
expect(custom_residence.errors[:date_of_birth].size).to eq(0)
expect(custom_residence.errors[:date_of_birth]).to be_empty
end end
it "is not valid without a date of birth" do it "is not valid without a date of birth" do

View File

@@ -48,11 +48,11 @@ describe Organization do
let!(:organization) { create(:organization, name: "Watershed", user: create(:user, phone_number: "333")) } let!(:organization) { create(:organization, name: "Watershed", user: create(:user, phone_number: "333")) }
it "returns no results if search term is empty" do it "returns no results if search term is empty" do
expect(Organization.search(" ").size).to eq(0) expect(Organization.search(" ")).to be_empty
end end
it "finds fuzzily by name" do it "finds fuzzily by name" do
expect(Organization.search("Greenpeace").size).to eq 0 expect(Organization.search("Greenpeace")).to be_empty
search = Organization.search("Tershe") search = Organization.search("Tershe")
expect(search.size).to eq 1 expect(search.size).to eq 1
expect(search.first).to eq organization expect(search.first).to eq organization

View File

@@ -1000,7 +1000,7 @@ describe Proposal do
it "does not return any proposals when user has not interests" do it "does not return any proposals when user has not interests" do
create(:proposal) create(:proposal)
expect(Proposal.recommendations(user).size).to eq 0 expect(Proposal.recommendations(user)).to be_empty
end end
it "returns proposals ordered by cached_votes_up" do it "returns proposals ordered by cached_votes_up" do
@@ -1034,7 +1034,7 @@ describe Proposal do
result = Proposal.recommendations(user) result = Proposal.recommendations(user)
expect(result.size).to eq 0 expect(result).to be_empty
end end
it "does not return proposals when user is the author" do it "does not return proposals when user is the author" do

View File

@@ -448,7 +448,7 @@ describe User do
end end
it "returns no results if no search term provided" do it "returns no results if no search term provided" do
expect(User.search(" ").size).to eq(0) expect(User.search(" ")).to be_empty
end end
end end

View File

@@ -74,7 +74,8 @@ describe Verification::Management::Document do
verification_document = Verification::Management::Document.new("date_of_birth(3i)" => "1", verification_document = Verification::Management::Document.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1", "date_of_birth(2i)" => "1",
"date_of_birth(1i)" => "1980") "date_of_birth(1i)" => "1980")
expect(verification_document.errors[:date_of_birth].size).to eq(0)
expect(verification_document.errors[:date_of_birth]).to be_empty
end end
it "is not valid without a date of birth" do it "is not valid without a date of birth" do

View File

@@ -14,7 +14,8 @@ describe Verification::Residence do
describe "dates" do describe "dates" do
it "is valid with a valid date of birth" do it "is valid with a valid date of birth" do
residence = Verification::Residence.new("date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "1980") residence = Verification::Residence.new("date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => "1980")
expect(residence.errors[:date_of_birth].size).to eq(0)
expect(residence.errors[:date_of_birth]).to be_empty
end end
it "is not valid without a date of birth" do it "is not valid without a date of birth" do