Created
March 17, 2015 17:23
-
-
Save gkop/18d8c6497d84948c2099 to your computer and use it in GitHub Desktop.
Spec for Population mixin that counts instances of class and its subclasses
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
class Animal | |
include Population | |
end | |
class Kangaroo < Animal | |
end | |
class CaptainKangaroo < Kangaroo | |
end | |
RSpec.describe "Counting populations of classes" do | |
it "Counts the population of the top-most class" do | |
expect(Animal.population).to eq(0) | |
Animal.new | |
expect(Animal.population).to eq(1) | |
expect(Animal.population).to eq(1) | |
Animal.new | |
expect(Animal.population).to eq(2) | |
end | |
it "Counts the population of subclasses, also" do | |
expect(Animal.population).to eq(0) | |
expect(Kangaroo.population).to eq(0) | |
expect(CaptainKangaroo.population).to eq(0) | |
Kangaroo.new | |
expect(Kangaroo.population).to eq(1) | |
expect(Animal.population).to eq(1) | |
expect(CaptainKangaroo.population).to eq(0) | |
Animal.new | |
expect(Animal.population).to eq(2) | |
expect(Kangaroo.population).to eq(1) | |
expect(CaptainKangaroo.population).to eq(0) | |
CaptainKangaroo.new | |
expect(Animal.population).to eq(3) | |
expect(Kangaroo.population).to eq(2) | |
expect(CaptainKangaroo.population).to eq(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment