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.
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.
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.
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.
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.
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 |
jaybobo
left a comment
There was a problem hiding this comment.
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.
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.
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.
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