rspec_rails_4
rspec_rails_4 copied to clipboard
Ch.4, p.43 - Confusing example
The contact.rb
example on page 43 (bottom) is a bit confusing.
According to the book we can "just add" the validation in the example to the contact model, and everything will work. However this was not the case for me. When I added the validation rule the filter last name by letter
test failed. This test isn't mentioned anywhere in the chapter, and thus hasn't been updated to use FactoryGirl unlike all the other tests. I was a bit confused by this, but in the end I converted it to FactoryGirl myself. Perhaps it would be a good idea to have the converted version in the book with the other tests to avoid any confusion.
In relation to this issue I looked in the source code on branch 04_factories and discovered the following FactoryGirl version of the test:
describe "filter last name by letter" do
before :each do
@smith = create(:contact,
lastname: 'Smith', email: '[email protected]')
@jones = create(:contact,
lastname: 'Jones', email: '[email protected]')
@johnson = create(:contact,
lastname: 'Johnson', email: '[email protected]')
end
....
end
This was different from my own test in that I didn't manually specify email adresses for each contact. Is this necessary? In my optics this test doesn't care about email addresses and will be happy with those randomly generated by Faker & FactoryGirl.
Book version: 2013-10-29 (PDF)