Instructions
Create a Dog class with:
- An
initializemethod that takes anameparameter - A
namereader attribute - A
barkmethod that returns "Woof!"
Hints:
- Use attr_reader :name
- Initialize with @name = name
- bark method just returns the string
Your Code
class Dog
attr_reader :name
def initialize(name)
@name = name
end
def bark
"Woof!"
end
end
RSpec.describe Dog do
let(:dog) { Dog.new("Buddy") }
it "has a name" do
expect(dog.name).to eq("Buddy")
end
it "can bark" do
expect(dog.bark).to eq("Woof!")
end
end
Results
Click "Run Tests" to see results
1 / 3
Next: Counter Class