-
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
My initial commit, with a fixed tree. #65
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.
Looking good.
FRUIT_AGE = 2 | ||
GROWTH_PER_YEAR = 2 # inches | ||
|
||
attr_accessor :height, :age, :apples, :alive |
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.
should everything be writable? you can make these private as well.
class Foo
def bar
baz = 'bang'
end
private
attr_accessor :baz
end
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? |
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.
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 |
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.
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 |
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.
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) |
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.
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 |
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.
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
@jaybobo, please review at your leisure.