Created
April 7, 2020 05:47
-
-
Save harrisonmalone/7887a3131bb94d957e44f9e32cde1c02 to your computer and use it in GitHub Desktop.
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 School | |
attr_reader :name, :students | |
def initialize(name) | |
@name = name | |
@students = [] | |
end | |
def enroll(student) | |
@students << student # "Jake" | |
end | |
def search(searched_student) | |
@students.each do |student| | |
if searched_student == student | |
return student | |
end | |
end | |
end | |
end |
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
require "school" | |
describe School do | |
let(:school) { School.new('Beverly Hills High School') } | |
it 'has a name' do | |
expect(school.name).to eq('Beverly Hills High School') | |
end | |
it 'should start off with no students' do | |
expect(school.students).to eq([]) | |
end | |
it 'school should be able to enroll a new student' do | |
school.enroll('Jake') | |
expect(school.students).to eq(['Jake']) | |
end | |
it 'school should be able to search for student by name' do | |
school.enroll('Jake') | |
result = school.search('Jake') | |
expect(result).to eq('Jake') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment