Skip to content
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

objects-and-methods 2203 #113

Open
wants to merge 11 commits into
base: edit_2203
Choose a base branch
from
2 changes: 1 addition & 1 deletion mythical-creatures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 19 additions & 13 deletions objects-and-methods/exercise-1/spec/bag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,64 @@

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")
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
end
10 changes: 5 additions & 5 deletions objects-and-methods/exercise-1/spec/trick_or_treater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
38 changes: 20 additions & 18 deletions objects-and-methods/exercise-2/spec/bag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,7 +110,3 @@
expect(candy.type).to eq('Lifesavers')
end
end




16 changes: 8 additions & 8 deletions objects-and-methods/exercise-2/spec/trick_or_treater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down