Created
July 6, 2015 16:42
-
-
Save tim-br/7cf79e314caaae38e6fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
module Flight | |
def fly | |
puts "I am a #{self.class} and I am flying" | |
end | |
end | |
class Animal | |
def warm_blooded? | |
return true | |
end | |
end | |
class Bird < Animal | |
include Flight | |
end | |
class Mammal < Animal | |
end | |
class Primate < Mammal | |
attr_reader :num_legs | |
def initialize | |
@num_legs = 2 | |
end | |
end | |
class Chimpanzee < Primate | |
end | |
class Amphibian < Animal | |
def warm_blooded? | |
return false | |
end | |
end | |
class Frog < Amphibian | |
end | |
class Bat < Bird | |
end | |
class Parrot < Bird | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './animal_classes.rb' | |
require 'pp' | |
describe Animal do | |
before do | |
@animal = Animal.new | |
end | |
end | |
describe Frog do | |
before do | |
@frog = Frog.new | |
end | |
describe '#warm_blooded?' do | |
it 'should return false' do | |
result = @frog.warm_blooded? | |
expect(result).to eq(false) | |
end | |
end | |
end | |
describe Chimpanzee do | |
before do | |
@chimp = Chimpanzee.new | |
end | |
describe '#num_legs' do | |
it 'should return 2' do | |
result = @chimp.num_legs | |
expect(result).to eq(2) | |
end | |
end | |
describe '#warm_blooded?' do | |
it 'should return false' do | |
result = @chimp.warm_blooded? | |
expect(result).to eq(true) | |
end | |
end | |
end | |
describe Parrot do | |
before do | |
@parrot = Parrot.new | |
end | |
describe '#fly' do | |
it 'should output I am a Parrot and I am flying' do | |
expect{@parrot.fly}.to output("I am a Parrot and I am flying").to_stdout | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment