diff --git a/mythical-creatures/README.md b/mythical-creatures/README.md index d4d0ec65..04b60ec5 100644 --- a/mythical-creatures/README.md +++ b/mythical-creatures/README.md @@ -11,7 +11,7 @@ In order to complete these exercises create a class for each of the mythical cre Navigate to the `mythical-creatures` directory in your terminal, and then run your first test: ``` -ruby test/unicorn_spec.rb +ruby spec/unicorn_spec.rb ``` If you get an error regarding a certain gem not being installed, you may need to run the following command from your terminal: diff --git a/objects-and-methods/exercise-1/spec/bag_spec.rb b/objects-and-methods/exercise-1/spec/bag_spec.rb index 4e20cd51..b8201f46 100644 --- a/objects-and-methods/exercise-1/spec/bag_spec.rb +++ b/objects-and-methods/exercise-1/spec/bag_spec.rb @@ -4,48 +4,54 @@ RSpec.describe Bag do it 'is empty' do - expect(Bag.new.empty?).to be true + bag = Bag.new + + expect(bag.empty?).to be true end xit 'can count the candy in an empty bag' do + bag = Bag.new + expect(Bag.new.count).to eq(0) end xit 'has no candies when it is empty' do + bag = Bag.new + expect(Bag.new.candies).to eq([]) end xit 'can put a candy in a bag' do bag = Bag.new - candy = Candy.new('Sour frogs') - - bag << candy + bag.add_candy candy expect(bag.candies).to eq([candy]) end xit 'is not empty when it has candies' do bag = Bag.new - bag << Candy.new("Nerds") + bag.add_candy Candy.new("Nerds") expect(bag.empty?).to be false end xit 'can count candies' do bag = Bag.new - bag << Candy.new("Caramelized Almonds") + bag.add_candy Candy.new("Caramelized Almonds") expect(bag.count).to eq(1) end + # NOTE: + # You usually don't want to chain a bunch of + # different methods together like this: + # type = bag.candies.first.type + # We'll talk about it more in a few weeks. + # However. it's important to understand how these methods work. xit 'contains candies and candies have a type' do bag = Bag.new - bag << Candy.new("Hershey's Kisses") - # You usually don't want to chain a bunch of different - # types of things together like this. - # We'll talk about it more in a few weeks. - # It's important to understand how these methods work, though. + bag.add_candy Candy.new("Hershey's Kisses") type = bag.candies.first.type expect(type).to eq("Hershey's Kisses") @@ -53,9 +59,9 @@ xit 'can be asked if it has a particular kind of candy' do bag = Bag.new - bag << Candy.new("Lindt chocolate") + bag.add_candy Candy.new("Lindt chocolate") expect(bag.contains?('Lindt chocolate')).to be true - expect(bag.contains?('Nerds')).to false + expect(bag.contains?('Nerds')).to be false end end diff --git a/objects-and-methods/exercise-1/spec/trick_or_treater_spec.rb b/objects-and-methods/exercise-1/spec/trick_or_treater_spec.rb index 31b319a8..cf243141 100644 --- a/objects-and-methods/exercise-1/spec/trick_or_treater_spec.rb +++ b/objects-and-methods/exercise-1/spec/trick_or_treater_spec.rb @@ -31,7 +31,7 @@ xit 'can get candies' do trick_or_treater = TrickOrTreater.new(Costume.new('Spaceship Mechanic')) - trick_or_treater.bag << Candy.new('Gummy bears') + trick_or_treater.bag.add_candy Candy.new('Gummy bears') expect(trick_or_treater.has_candy?).to be true end @@ -41,16 +41,16 @@ expect(trick_or_treater.candy_count).to eq(0) - trick_or_treater.bag << Candy.new('Gummy bears') + trick_or_treater.bag.add_candy Candy.new('Gummy bears') expect(trick_or_treater.candy_count).to eq(1) end xit 'can eat candies' do trick_or_treater = TrickOrTreater.new(Costume.new("Baron")) - trick_or_treater.bag << Candy.new("Gummy worms") - trick_or_treater.bag << Candy.new("Liquorice") - trick_or_treater.bag << Candy.new("Salty Serpents") + trick_or_treater.bag.add_candy Candy.new("Gummy worms") + trick_or_treater.bag.add_candy Candy.new("Liquorice") + trick_or_treater.bag.add_candy Candy.new("Salty Serpents") expect(trick_or_treater.candy_count).to eq(3) trick_or_treater.eat diff --git a/objects-and-methods/exercise-2/spec/bag_spec.rb b/objects-and-methods/exercise-2/spec/bag_spec.rb index 3733387e..535b297e 100644 --- a/objects-and-methods/exercise-2/spec/bag_spec.rb +++ b/objects-and-methods/exercise-2/spec/bag_spec.rb @@ -4,59 +4,65 @@ RSpec.describe Bag do it 'is empty' do - expect(Bag.new.empty?).to be true + bag = Bag.new + + expect(bag.empty?).to be true end xit 'can count the candy in an empty bag' do + bag = Bag.new + expect(Bag.new.count).to eq(0) end xit 'has no candies when it is empty' do + bag = Bag.new + expect(Bag.new.candies).to eq([]) end xit 'can put a candy in a bag' do bag = Bag.new - candy = Candy.new('Sour frogs') - - bag << candy + bag.add_candy candy expect(bag.candies).to eq([candy]) end xit 'is not empty when it has candies' do bag = Bag.new - bag << Candy.new('Nerds') + bag.add_candy Candy.new("Nerds") expect(bag.empty?).to be false end xit 'can count candies' do bag = Bag.new - bag << Candy.new('Caramelized Almonds') + bag.add_candy Candy.new("Caramelized Almonds") expect(bag.count).to eq(1) end + # NOTE: + # You usually don't want to chain a bunch of + # different methods together like this: + # type = bag.candies.first.type + # We'll talk about it more in a few weeks. + # However. it's important to understand how these methods work. xit 'contains candies and candies have a type' do bag = Bag.new - bag << Candy.new('Hersheys Kisses') - # You usually don't want to chain a bunch of different - # types of things together like this. - # We'll talk about it more in a few weeks. - # It's important to understand how these methods work, though. + bag.add_candy Candy.new("Hershey's Kisses") type = bag.candies.first.type - expect(type).to eq('Hersheys Kisses') + expect(type).to eq("Hershey's Kisses") end xit 'can be asked if it has a particular kind of candy' do bag = Bag.new - bag << Candy.new('Lindt chocolate') + bag.add_candy Candy.new("Lindt chocolate") expect(bag.contains?('Lindt chocolate')).to be true - expect(bag.contains?('Nerds')).to false + expect(bag.contains?('Nerds')).to be false end xit 'can get a particular type of candy' do @@ -104,7 +110,3 @@ expect(candy.type).to eq('Lifesavers') end end - - - - diff --git a/objects-and-methods/exercise-2/spec/trick_or_treater_spec.rb b/objects-and-methods/exercise-2/spec/trick_or_treater_spec.rb index 2fa35907..123a514a 100644 --- a/objects-and-methods/exercise-2/spec/trick_or_treater_spec.rb +++ b/objects-and-methods/exercise-2/spec/trick_or_treater_spec.rb @@ -31,7 +31,7 @@ xit 'can get candies' do trick_or_treater = TrickOrTreater.new(Costume.new('Spaceship Mechanic')) - trick_or_treater.bag << Candy.new('Gummy bears') + trick_or_treater.bag.add_candy Candy.new('Gummy bears') expect(trick_or_treater.has_candy?).to be true end @@ -41,16 +41,16 @@ expect(trick_or_treater.candy_count).to eq(0) - trick_or_treater.bag << Candy.new('Gummy bears') + trick_or_treater.bag.add_candy Candy.new('Gummy bears') expect(trick_or_treater.candy_count).to eq(1) end xit 'can eat candies' do trick_or_treater = TrickOrTreater.new(Costume.new('Baron')) - trick_or_treater.bag << Candy.new('Gummy worms') - trick_or_treater.bag << Candy.new('Liquorice') - trick_or_treater.bag << Candy.new('Salty Serpents') + trick_or_treater.bag.add_candy Candy.new('Gummy worms') + trick_or_treater.bag.add_candy Candy.new('Liquorice') + trick_or_treater.bag.add_candy Candy.new('Salty Serpents') expect(trick_or_treater.candy_count).to eq(3) trick_or_treater.eat @@ -73,9 +73,9 @@ xit 'increases the sugar level when it eats candies' do trick_or_treater = TrickOrTreater.new(Costume.new('Hobbit')) - trick_or_treater.bag << Candy.new('Gummy worms', 88) - trick_or_treater.bag << Candy.new('Liquorice', 83) - trick_or_treater.bag << Candy.new('Salty Serpents', 71) + trick_or_treater.bag.add_candy Candy.new('Gummy worms', 88) + trick_or_treater.bag.add_candy Candy.new('Liquorice', 83) + trick_or_treater.bag.add_candy Candy.new('Salty Serpents', 71) trick_or_treater.eat trick_or_treater.eat