Skip to content

Conversation

@ericnoble
Copy link

@jaybobo, please review at your leisure.

Copy link
Member

@jaybobo jaybobo left a 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
Copy link
Member

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


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?
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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

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