Created
November 11, 2015 21:03
-
-
Save jferris/3c11146d817867a6bff1 to your computer and use it in GitHub Desktop.
Use string comparisons for better spec failure messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Person do | |
describe "#billable" do | |
it "returns people with a billable role" do | |
billable = create(:role, billable: true) | |
unbillable = create(:role, billable: false) | |
create(:person, name: "BillableOne", role: billable) | |
create(:person, name: "BillableTwo", role: billable) | |
create(:person, name: "Unbillable", role: unbillable) | |
result = Person.billable | |
expect(result.map(&:name)).to match_array(%w(BillableOne BillableTwo)) | |
end | |
end | |
end | |
# Failures look like: | |
# | |
# 1) Person#billable returns people with a billable role | |
# Failure/Error: expect(result.map(&:name)).to match_array(%w(BillableOne BillableTwo)) | |
# expected collection contained: ["BillableTwo", "BillableOne"] | |
# actual collection contained: ["BillableTwo", "Unbillable", "BillableOne"] | |
# the extra elements were: ["Unbillable"] | |
# # ./spec/models/person_spec.rb:14:in `block (3 levels) in <top (required)>' | |
describe Person do | |
describe "#billable" do | |
it "returns people with a billable role" do | |
billable = create(:role, billable: true) | |
unbillable = create(:role, billable: false) | |
expected_people = [ | |
create(:person, role: billable), | |
create(:person, role: billable) | |
] | |
create(:person, role: unbillable) | |
result = Person.billable | |
expect(result).to match_array(expected_people) | |
end | |
end | |
end | |
# Failures look like: | |
# | |
# 1) Person#billable returns people with a billable role | |
# Failure/Error: expect(result).to match_array(expected_people) | |
# expected collection contained: [#<Person id: 6, name: "Name 1", role_id: 4, location_id: nil, manager_id: nil, salary: 0>, #<Person id: 7, name: "Name 2", role_id: 4, location_id: nil, manager_id: nil, salary: 0>] | |
# actual collection contained: [#<Person id: 6, name: "Name 1", role_id: 4, location_id: nil, manager_id: nil, salary: 0>, #<Person id: 7, name: "Name 2", role_id: 4, location_id: nil, manager_id: nil, salary: 0>, #<Person id: 8, name: "Name 3", role_id: 5, location_id: nil, manager_id: nil, salary: 0>] | |
# the extra elements were: [#<Person id: 8, name: "Name 3", role_id: 5, location_id: nil, manager_id: nil, salary: 0>] | |
# # ./spec/models/person_spec.rb:16:in `block (3 levels) in <top (required)>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment