Skip to content

Conversation

@Joehimes
Copy link

@Joehimes Joehimes commented Dec 9, 2017

I would love any and all feedback! Thanks!

Copy link

@sjreich sjreich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty solid. I made some suggestions, especially on the tests.

end

it 'should have height' do
tree = Tree.new
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idiomatic rspec way would be to use a let statement for tree here. Generally speaking, let statements are preferred over local variables.

Copy link
Member

@mikegee mikegee Dec 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda like local variables. ¯\_(ツ)_/¯

Extracting the repetition of tree = Tree.new is nice, but the clarity of the local variable has some benefit too.

tree = Tree.new
tree.add_apples
expect(tree.apples).to_not eq []
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a lot of these tests, you might do some thinking about what the subject of the test really is. Here, for instance, the subject is really the add_apples method, rather than the Tree class itself. So using a nested describe block would be a good way to represent that.

Also, think about whether this is the right test. Sometimes you might want to call add_apples on a tree that already had apples, in which case the fact that tree.apples is not empty is pretty meaningless.

end

def any_apples?
@apples != []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apples.empty? would work too, and it a bit more readable IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants