← Back to Upcase

A question about user_spec.rb in Todo application

(HsienTe Fang) #1

In the test for User#todos, the original code is:

it 'returns todos whose owner_email is the email instantiated with' do
  create(:todo, description: 'Buy some eggs', owner_email: 'person@example.com')
  create(:todo, description: 'Buy some milk', owner_email: 'other_person@example.com')
  user = User.new('person@example.com')
  expect(user.todos.length).to eq 1
  expect(user.todos.first.description).to eq 'Buy some eggs'

Can I rewrite to code to:

person_todo = create(:todo, description: 'Buy some eggs', owner_email: 'person@example.com')
expect(user.todos).to eq [person_todo]

It seems more straightforward to me and it can pass the test. Or, am I overlooking something important?

(Anders Lundström) #2

Im also in the workshop and learning, but perhaps i may add my perceptions
i see that the line length is already over what most guidelines recommended (80)
even though i see many of these tests break it, this would make it 93
So for me that makes it less readable
And i also think that the assignment itself makes my brain hurt more specially since im a testing newbie, so thats a second reason for me to want the original version, unless is doesnt pass without it.
I also want to see what someone good has to say about it

(Ben Orenstein) #3

Seems like a reasonable refactoring to me!