-
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
tree.rb runs, added a few minor tests. Need to work on testing #57
base: master
Are you sure you want to change the base?
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,48 @@ | ||
require 'rspec' | ||
require 'tree' | ||
|
||
describe 'Tree' do | ||
describe Tree do | ||
it 'should be a Class' do | ||
expect(described_class.is_a? 'Class').to be_true | ||
expect(described_class.is_a? Class).to eq true | ||
end | ||
|
||
it 'should have height' do | ||
tree = Tree.new | ||
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. The idiomatic rspec way would be to use a 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 kinda like local variables. ¯\_(ツ)_/¯ Extracting the repetition of |
||
expect(tree.height).to_not eq nil | ||
end | ||
|
||
it 'should age' do | ||
tree = Tree.new | ||
tree.age! | ||
expect(tree.height).to eq 1 | ||
expect(tree.age).to eq 1 | ||
expect(tree.apples).to_not eq [] | ||
end | ||
|
||
it 'should add apples' do | ||
tree = Tree.new | ||
tree.add_apples | ||
expect(tree.apples).to_not eq [] | ||
end | ||
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 a lot of these tests, you might do some thinking about what the subject of the test really is. Here, for instance, the subject is really the Also, think about whether this is the right test. Sometimes you might want to call |
||
|
||
it 'should have apples' do | ||
tree = Tree.new | ||
tree.add_apples | ||
expect(tree.any_apples?).to eq true | ||
end | ||
end | ||
|
||
describe 'Fruit' do | ||
describe Fruit do | ||
end | ||
|
||
describe 'Apple' do | ||
describe Apple do | ||
it 'should be a Class' do | ||
expect(described_class.is_a? Class).to eq true | ||
end | ||
|
||
it 'should create a new Apple' do | ||
apple = Apple.new("Red", 5) | ||
expect(apple.color).to eq "Red" | ||
expect(apple.diameter).to eq 5 | ||
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.
@apples.empty?
would work too, and it a bit more readable IMO.