Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created April 7, 2020 05:47
Show Gist options
  • Save harrisonmalone/7887a3131bb94d957e44f9e32cde1c02 to your computer and use it in GitHub Desktop.
Save harrisonmalone/7887a3131bb94d957e44f9e32cde1c02 to your computer and use it in GitHub Desktop.
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
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