-
Notifications
You must be signed in to change notification settings - Fork 72
finish tree #55
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
base: master
Are you sure you want to change the base?
finish tree #55
Conversation
lib/tree.rb
Outdated
| class AppleTree | ||
| attr_#fill_in :height, :age, :apples, :alive | ||
| class Tree | ||
| 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.
why attr_accessor here instead of attr_reader or attr_writer?
lib/tree.rb
Outdated
| end | ||
|
|
||
| def any_apples? | ||
| return @apples.length > 0 |
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.
lib/tree.rb
Outdated
| end | ||
|
|
||
| def add_apples | ||
| apple = 12.times { @apples.push Apple.new("Red", Random.rand(1..6)) } #adds between 1-3 more apples every year, with random diameter |
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.
what's being done with the apple variable?
spec/tree_spec.rb
Outdated
| describe 'Tree' do | ||
| it 'should be a Class' do | ||
| expect(described_class.is_a? 'Class').to be_true | ||
| expect(Tree_class.is_a? 'Class').to be_true |
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.
Do your tests pass when you run rspec?
https://ruby-doc.org/core-2.4.1/Object.html#method-i-is_a-3F
spec/tree_spec.rb
Outdated
| expect(Tree_class.is_a? 'Class').to be_true | ||
| end | ||
|
|
||
| it 'grows one foot' 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.
why might grouping your tests into contexts be a good idea?
www.betterspecs.org/#contexts
spec/tree_spec.rb
Outdated
| end | ||
|
|
||
| it 'is a Fruit' do | ||
| expect(Apple < Fruit).to be true |
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.
what's happening here?
jaybobo
left a comment
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.
Take another look at betterspecs.org to see how contexts are used. Remember to run your rspec tests to ensure they run.
| end | ||
|
|
||
| it 'is a Fruit' do | ||
| expect(Apple < Fruit).to be true # expects to be inheriting from apple if it is a fruit |
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 like this. There's a couple of other ways to do this as well.
https://stackoverflow.com/questions/23027236/how-to-test-ruby-inheritance-with-rspec
The documentation spells out your method here.
https://ruby-doc.org/core-2.3.0/Module.html#method-i-3C
| end | ||
|
|
||
| describe 'Apple' do | ||
| apple = Apple.new("Red", 30) |
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 things like this, we use let. Refactor any variables used here using let instead.
http://www.betterspecs.org/#let
|
|
||
| context 'when dies after 25 years' do | ||
| it "equals false" do | ||
| (1..13).each{ |idx| tree.age!} |
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 works. You could also use .times which would make this cleaner.
https://ruby-doc.org/core-2.2.2/Integer.html#method-i-times
@jaybobo @jack-chester