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

added age and can drink? methods #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion models/human.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ def job_title=(value)
def job_title
@job_title
end
end
attr_accessor :age

def can_drink?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great simple implementation..
What happens if this is called and @age was never set? (we will discuss next week)

@age >= 18
end

end
24 changes: 21 additions & 3 deletions specs/models/human_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,27 @@
end
end

describe '.age' do
it 'it returns the age' do
human = Human.new('')
human.age = 20
expect(human.age).to eq(20)
end
end
describe '.can_drink' do
it 'it is legal to drink'do
human = Human.new('')
human.age = 18
expect(human.can_drink?).to eq(true)
end
it 'it is illegal to drink'do
human = Human.new('')
human.age = 10
expect(human.can_drink?).to eq(false)
end
end

it 'play area' do
puts Human.new('Caitlin').name
puts Human.new('Sarah').name
end
end