-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tree.rb runs, added a few minor tests. Need to work on testing #57
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 != [] |
There was a problem hiding this comment.
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.
I would love any and all feedback! Thanks!