-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add Rspec Unit Tests #8
Merged
Merged
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
57ef9ef
Add preserve_data.rb file
GeekyHacks 4ee3920
preserve data update
ishimwepati 92daef6
Preserved update
ishimwepati b17e3ce
class updated
ishimwepati 8db9daf
Preserved file update
ishimwepati e2b6881
Fix linter errors
GeekyHacks 4f8e8b2
Update preserve_data.rb
ishimwepati 215cc6b
Add save_data and Load_data files
GeekyHacks 43b3f77
Merge branch 'PreserveData' of https://github.com/GeekyHacks/OOPSchoo…
GeekyHacks 4e61f8e
remove preserve_data file
GeekyHacks 7852bcb
Fix linter errors
GeekyHacks 41efc54
Add gem rspec
GeekyHacks eb8637c
Add the initialize tests for Person, Student, book
GeekyHacks 73abef5
classroom test
ishimwepati fd93e68
Teacher test added
ishimwepati a121af9
Renta test added
ishimwepati 2786a23
Update classroom.rb
ishimwepati b09e4ed
Update classroom_spec.rb
ishimwepati e365ee6
Update rental_spec.rb
ishimwepati e1d2833
Edit the book and student test cases
GeekyHacks 53d60ae
Merge branch 'AddUnitTests' of https://github.com/GeekyHacks/OOPSchoo…
GeekyHacks 7434e7d
Update rental_spec.rb
ishimwepati 90248aa
Edit the rental test file
GeekyHacks f3c0beb
Merge branch 'AddUnitTests' of https://github.com/GeekyHacks/OOPSchoo…
GeekyHacks cff89e2
Update rental_spec.rb
ishimwepati f2c2217
Update rental_spec.rb
ishimwepati 2c0f1c6
Fix linter errors
GeekyHacks 401973e
Merge branches 'AddUnitTests' and 'AddUnitTests' of https://github.co…
GeekyHacks 3df14cc
Fix linter errors
GeekyHacks d201e19
Edit Readme file accordingly
GeekyHacks ad056d9
Add more test cases to person and classroom
GeekyHacks 6864651
Add the required test cases
GeekyHacks f4ec053
Test correct_name method
GeekyHacks 7a4f740
Add required changes
GeekyHacks 73d444c
fix linter errors
GeekyHacks dee6453
fix linter errors, add default name test case
GeekyHacks db6cae0
fix linter errors
GeekyHacks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rubocop', '>= 1.0', '< 2.0' | ||
|
||
gem 'json' | ||
|
||
gem 'rspec' |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"title":"weqwewq","author":"qweqwe"},{"title":"qqqqqw","author":"wwee"}] |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"people":["{\"@id\":835,\"@age\":\"eee\",\"@name\":33,\"@parent_permission\":true,\"@rentals\":[],\"@specialization\":\"IT\"}"]} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'json' | ||
require './classroom' | ||
|
||
module Load | ||
def load_files | ||
load_books | ||
load_people | ||
load_rentals | ||
end | ||
|
||
def load_books | ||
File.exist?('./books.json') ? books_json = JSON.parse(File.read('books.json')) : return | ||
@books = books_json.map do |book| | ||
Book.new(book['title'], book['author']) | ||
end | ||
end | ||
|
||
def load_people | ||
File.exist?('./people.json') ? people_json = JSON.parse(File.read('people.json')) : return | ||
@people = people_json.map { |person| identify_person(person) } | ||
end | ||
|
||
def load_rentals | ||
File.exist?('./rentals.json') ? rentals_json = JSON.parse(File.read('rentals.json')) : return | ||
@rentals = rentals_json.map do |rental| | ||
person = identify_person(rental['person']) | ||
Rental.new(rental['date'], Book.new(rental['book']['title'], rental['book']['author']), person) | ||
end | ||
end | ||
|
||
def identify_person(person) | ||
if person['specialization'] | ||
teacher = Teacher.new(person['specialization'], person['age'], person['name']) | ||
teacher.id = person['id'] | ||
teacher | ||
else | ||
student = Student.new((person['classroom']), person['age'], person['name'], | ||
parent_permission: person['parent_permission']) | ||
student.id = person['id'] | ||
student | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"id":840,"name":"qwqw","age":22,"parent_permission":true,"classroom":"Unknown"},{"id":268,"name":33,"age":"qqqq","specialization":"it"},{"id":226,"name":"wweee","age":24,"parent_permission":true,"classroom":"#<Classroom:0x000055e07a3623c8>"}] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"book":{"title":"qqqqqw","author":"wwee"},"person":{"id":840,"name":"qwqw","age":22,"parent_permission":true,"classroom":"Unknown"},"date":"2023-10-27"}] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'json' | ||
|
||
module Save | ||
def save_files | ||
save_books | ||
save_people | ||
save_rentals | ||
end | ||
|
||
def save_books | ||
books_json = @books.map do |book| | ||
{ | ||
title: book.title, | ||
author: book.author | ||
} | ||
end | ||
File.write('./books.json', JSON.generate(books_json)) | ||
end | ||
|
||
def save_people | ||
people_json = [] | ||
@people.map do |person| | ||
person_json = { | ||
id: person.id, | ||
name: person.name, | ||
age: person.age | ||
} | ||
append_data(person, person_json) | ||
people_json.push(person_json) | ||
end | ||
File.write('./people.json', JSON.generate(people_json)) | ||
end | ||
|
||
def save_rentals | ||
rentals_json = [] | ||
@rentals.map do |rental| | ||
rental_json = { | ||
book: { | ||
title: rental.book.title, | ||
author: rental.book.author | ||
}, | ||
person: { | ||
id: rental.person.id, | ||
name: rental.person.name, | ||
age: rental.person.age | ||
}, | ||
date: rental.date | ||
} | ||
append_data(rental.person, rental_json[:person]) | ||
rentals_json.push(rental_json) | ||
end | ||
File.write('./rentals.json', JSON.generate(rentals_json)) | ||
end | ||
|
||
def append_data(person, person_json) | ||
if person.instance_of?(::Teacher) | ||
person_json[:specialization] = person.specialization | ||
else | ||
person_json[:parent_permission] = person.parent_permission | ||
person_json[:classroom] = person.classroom | ||
end | ||
person_json | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require './book' | ||
require './rental' | ||
|
||
describe Book do | ||
before(:each) do | ||
@book = Book.new('title', 'author') | ||
@rentals = [] | ||
end | ||
|
||
describe '#new' do | ||
it 'returns a new book object' do | ||
expect(@book).to be_an_instance_of(Book) | ||
end | ||
end | ||
|
||
describe '#add_rental' do | ||
after(:each) do | ||
@rentals = [@rental] | ||
end | ||
|
||
it 'returns a new rental object' do | ||
person = double('Person', rentals: []) | ||
@rental = Rental.new('2020-10-10', @book, person) | ||
|
||
expect(@rental).to be_an_instance_of(Rental) | ||
end | ||
|
||
it 'adds rental to person rentals list when add_rental method is called' do | ||
person = double('Person', rentals: []) | ||
@rental = Rental.new('2020-10-10', @book, person) | ||
|
||
expect(person.rentals).to include(@rental) | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require './classroom' | ||
require './student' | ||
|
||
describe Classroom do | ||
subject(:classroom) { described_class.new('Math Classroom') } | ||
|
||
it { is_expected.to have_attributes(label: 'Math Classroom') } | ||
|
||
it 'initially has no students' do | ||
expect(classroom.students).to be_empty | ||
end | ||
|
||
it 'can add students' do | ||
student1 = Student.new(classroom, 18, 'Alice') | ||
student2 = Student.new(classroom, 19, 'Bob') | ||
|
||
classroom.add_student(student1) | ||
classroom.add_student(student2) | ||
|
||
expect(classroom.students).to include(student1, student2) | ||
expect(student1.classroom).to eq(classroom) | ||
expect(student2.classroom).to eq(classroom) | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require './person' | ||
|
||
describe Person.new 23, 'Abdu' do | ||
it { is_expected.to have_attributes(age: 23) } | ||
it { is_expected.to have_attributes(name: 'Abdu') } | ||
it { is_expected.to have_attributes(parent_permission: true) } | ||
end | ||
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require './rental' | ||
require './book' | ||
require './person' | ||
|
||
describe Rental do | ||
let(:book) { Book.new('Book Title', 'Author') } | ||
let(:person) { Person.new(25, 'John Doe') } | ||
|
||
subject(:rental) { described_class.new('2023-10-26', book, person) } | ||
|
||
it { is_expected.to have_attributes(date: '2023-10-26', book: book, person: person) } | ||
|
||
it 'associates the rental with the book and person' do | ||
expect(book.rentals).to include(rental) | ||
expect(person.rentals).to include(rental) | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require './student' | ||
|
||
describe Student.new 'IT', 24, 'Abdu' do | ||
it { is_expected.to be_a(Person) } | ||
it { is_expected.to have_attributes(classroom: 'IT') } | ||
it { is_expected.to have_attributes(age: 24) } | ||
it { is_expected.to have_attributes(name: 'Abdu') } | ||
it { is_expected.to have_attributes(parent_permission: true) } | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require './teacher' | ||
|
||
describe Teacher do | ||
subject(:teacher) { described_class.new('Math', 35, 'John Doe') } | ||
|
||
it { is_expected.to be_a(Person) } | ||
it { is_expected.to have_attributes(specialization: 'Math', age: 35, name: 'John Doe') } | ||
|
||
it 'can use services' do | ||
expect(teacher.can_use_services?).to be(true) | ||
end | ||
end |
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can_use_services
,correct_name
,add_rental
also testdefault value for the optional name parameter if it is not provided