My initial commit, with a fixed tree.#65
Open
ericnoble wants to merge 1 commit intopaircolumbus:masterfrom
Open
My initial commit, with a fixed tree.#65ericnoble wants to merge 1 commit intopaircolumbus:masterfrom
ericnoble wants to merge 1 commit intopaircolumbus:masterfrom
Conversation
jaybobo
reviewed
Mar 21, 2018
| FRUIT_AGE = 2 | ||
| GROWTH_PER_YEAR = 2 # inches | ||
|
|
||
| attr_accessor :height, :age, :apples, :alive |
Member
There was a problem hiding this comment.
should everything be writable? you can make these private as well.
class Foo
def bar
baz = 'bang'
end
private
attr_accessor :baz
end|
|
||
| def pick_an_apple! | ||
| raise NoApplesError, "This tree has no apples" unless self.any_apples? | ||
| raise NoApplesError, 'This tree has no apples' unless any_apples? |
Member
There was a problem hiding this comment.
We've used a bang for this method name because it may possibly raise an error. If this mutates data, we may also use a bang.
| end | ||
| end | ||
| else | ||
| @alive = false |
Member
There was a problem hiding this comment.
It's good practice to use getters/setters when you can instead of ivars. One you may want to redefine a getter say...
def apples
@apples ||= []
end
|
|
||
| describe '#any_apples?' do | ||
| it 'should return false for a new Tree without apples' do | ||
| tree = Tree.new |
Member
There was a problem hiding this comment.
See subject and .let those are preferred here.
http://betterspecs.org/
| expect { tree.pick_an_apple! }.to raise_error(NoApplesError) | ||
| end | ||
|
|
||
| red_apple = Apple.new('red', 1) |
Member
There was a problem hiding this comment.
See my other comment about subject and let
| expect(tree.any_apples?).to eq(false) | ||
| end | ||
|
|
||
| it 'should return true for a Tree that has apples' do |
Member
There was a problem hiding this comment.
This is a good case for using a context. Contexts can also be nested.
describe '#any_apples?' do
context 'a tree with apples' do
it 'returns true' do
..
end
end
context 'a tree without apples' do
it 'returns false' do
..
end
end
end
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@jaybobo, please review at your leisure.