-
Notifications
You must be signed in to change notification settings - Fork 71
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,79 @@ | ||
| require 'rspec' | ||
| require 'tree' | ||
|
|
||
| describe 'Tree' do | ||
| tree = Tree.new | ||
|
|
||
| describe Tree do | ||
| it 'should be a Class' do | ||
| expect(described_class.is_a? 'Class').to be_true | ||
| expect(Tree.is_a? Class).to eq true | ||
| end | ||
|
|
||
| context 'when grows one foot' do | ||
| it "equals 1" do | ||
| tree.age! | ||
| expect(tree.height).to eq(1) | ||
| end | ||
| end | ||
|
|
||
| context 'when ages one year' do | ||
| it "equals 1" do | ||
| expect(tree.age).to eq(1) | ||
| end | ||
| end | ||
|
|
||
| context 'when has no fruit' do | ||
| it "equals true" do | ||
| expect(tree.any_apples?).to eq true | ||
| end | ||
| end | ||
|
|
||
| context 'when has apples after 3 years' do | ||
| it "equals true" do | ||
| tree.age! | ||
| expect(tree.any_apples?).to be true | ||
| end | ||
| end | ||
|
|
||
| context 'when dies after 25 years' do | ||
| it "equals false" do | ||
| (1..13).each{ |idx| tree.age!} | ||
| expect(tree.dead?).to be false | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'Fruit' do | ||
| describe Fruit do | ||
| it 'should be a Class' do | ||
| expect(Fruit.is_a? Class).to eq true | ||
| end | ||
| end | ||
|
|
||
| describe 'Apple' do | ||
| apple = Apple.new("Red", 30) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For things like this, we use |
||
|
|
||
| describe Apple do | ||
| it 'should be a Class' do | ||
| expect(Apple.is_a? Class).to eq true | ||
| end | ||
|
|
||
| it 'is a Fruit' do | ||
| expect(Apple < Fruit).to be true # expects to be inheriting from apple if it is a fruit | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. The documentation spells out your method here. |
||
| end | ||
|
|
||
| context 'when sets a color' do | ||
| it "equals red" do | ||
| expect(apple.color).to eq("Red") | ||
| end | ||
| end | ||
|
|
||
| context 'when sets a diameter' do | ||
| it "equals 30" do | ||
| expect(apple.diameter).to eq(30) | ||
| end | ||
| end | ||
|
|
||
| context 'when calls super()' do | ||
| it "equals true" do | ||
| expect(apple.has_seeds).to eq true | ||
| end | ||
| end | ||
| end | ||
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
.timeswhich would make this cleaner.https://ruby-doc.org/core-2.2.2/Integer.html#method-i-times