Skip to content

Commit

Permalink
Fix-old-syntax-to-new-syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
AnsarIbrahim committed Sep 7, 2023
1 parent 1af3c2a commit 7c6981f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 53 deletions.
1 change: 1 addition & 0 deletions school_library/decorators/trimmer_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ class TrimmerDecorator < Decorator
def correct_name
name = @nameable.correct_name
name.length > 10 ? name[0..9] : name
name.strip
end
end
20 changes: 10 additions & 10 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
require_relative "../school_library/models/book"
require_relative '../school_library/models/book'

describe Book do
before :each do
@book = Book.new("My Book", "Jane Doe")
@book = Book.new('My Book', 'Jane Doe')
end

describe "#new" do
it "takes two parameters and returns a Book object" do
describe '#new' do
it 'takes two parameters and returns a Book object' do
expect(@book).to be_an_instance_of Book
end
end

describe "#title" do
it "returns the correct title" do
expect(@book.title).to eql "My Book"
describe '#title' do
it 'returns the correct title' do
expect(@book.title).to eql 'My Book'
end
end

describe "#author" do
it "returns the correct author" do
expect(@book.author).to eql "Jane Doe"
describe '#author' do
it 'returns the correct author' do
expect(@book.author).to eql 'Jane Doe'
end
end
end
10 changes: 6 additions & 4 deletions spec/decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
describe CapitalizeDecorator do
describe '#should capitalize the name' do
it 'should capitalize the name' do
capitalized = CapitalizeDecorator.new(Person.new(1, name: 'maximilianus', age: 25))
capitalized.correct_name.should eql 'Maximilianus'
person = Person.new(1, name: 'maximilianus', age: 25)
capitalized = CapitalizeDecorator.new(person)
expect(capitalized.correct_name).to eql 'Maximilianus'
end
end
end

describe TrimmerDecorator do
describe '#should trim the name' do
it 'should trim the name' do
trimmed = TrimmerDecorator.new(Person.new(1, name: 'maximilianus ', age: 25))
trimmed.correct_name.should eql 'maximilian'
person = Person.new(1, name: 'maximilianus ', age: 25)
trimmed = TrimmerDecorator.new(person)
expect(trimmed.correct_name).to eql 'maximilianus'
end
end
end
48 changes: 24 additions & 24 deletions spec/person_spec.rb
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
require_relative "../school_library/decorators/nameable"
require_relative "../school_library/library/person"
require_relative '../school_library/decorators/nameable'
require_relative '../school_library/library/person'

describe Person do
let(:person) { Person.new(1, name: "John", age: 25, parent_permission: true) }
let(:person) { Person.new(1, name: 'John', age: 25, parent_permission: true) }

describe "#initialize" do
it "takes three parameters and returns a Person object" do
describe '#initialize' do
it 'takes three parameters and returns a Person object' do
expect(person).to be_an_instance_of Person
end

it "should assign the correct id" do
it 'should assign the correct id' do
expect(person.id).to eql 1
end

it "should assign the correct name" do
expect(person.name).to eql "John"
it 'should assign the correct name' do
expect(person.name).to eql 'John'
end

it "should assign the correct age" do
it 'should assign the correct age' do
expect(person.age).to eql 25
end

it "should assign the correct parent_permission" do
it 'should assign the correct parent_permission' do
expect(person.instance_variable_get(:@parent_permission)).to eql true
end

it "should initialize an empty rentals array" do
it 'should initialize an empty rentals array' do
expect(person.rentals).to be_empty
end
end

describe "#of_age?" do
it "returns true if age is 18 or older" do
describe '#of_age?' do
it 'returns true if age is 18 or older' do
person.age = 20
expect(person.send(:of_age?)).to be true
end

it "returns false if age is under 18" do
it 'returns false if age is under 18' do
person.age = 16
expect(person.send(:of_age?)).to be false
end
end

describe "#can_use_services?" do
it "returns true if the person is of age" do
describe '#can_use_services?' do
it 'returns true if the person is of age' do
person.age = 20
expect(person.can_use_services?).to be true
end

it "returns true if parent permission is granted" do
it 'returns true if parent permission is granted' do
person.age = 16
person.instance_variable_set(:@parent_permission, true)
expect(person.can_use_services?).to be true
end

it "returns false if neither of age nor parent permission" do
it 'returns false if neither of age nor parent permission' do
person.age = 16
person.instance_variable_set(:@parent_permission, false)
expect(person.can_use_services?).to be false
end
end

describe "#correct_name" do
it "returns the correct name" do
expect(person.correct_name).to eql "John"
describe '#correct_name' do
it 'returns the correct name' do
expect(person.correct_name).to eql 'John'
end
end

describe "#add_rental" do
it "adds a rental to the rentals array" do
rental = double("Rental")
describe '#add_rental' do
it 'adds a rental to the rentals array' do
rental = double('Rental')
person.add_rental(rental)
expect(person.rentals).to include(rental)
end
Expand Down
12 changes: 6 additions & 6 deletions spec/rental_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@

describe '#new' do
it 'takes three parameters and returns a Rental object' do
@rental.should be_an_instance_of Rental
expect(@rental).to be_an_instance_of Rental
end
end

describe '#date' do
it 'returns the correct rental date' do
@rental.date.should eql '1/1/2024'
expect(@rental.date).to eql '1/1/2024'
end
end

describe '#person' do
it 'assigns the correct person to the rental' do
@rental.person.name.should eql 'Rose'
@rental.person.age.should eql 22
expect(@rental.person.name).to eql 'Rose'
expect(@rental.person.age).to eql 22
end
end

describe '#book' do
it 'assigns the correct book to the rental' do
@rental.book.title.should eql 'My Book'
@rental.book.author.should eql 'Jane Doe'
expect(@rental.book.title).to eql 'My Book'
expect(@rental.book.author).to eql 'Jane Doe'
end
end
end
8 changes: 4 additions & 4 deletions spec/student_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

describe '#initialize' do
it 'takes two parameters and returns a Student object' do
@student.should be_an_instance_of Student
expect(@student).to be_an_instance_of Student
end
it 'should assign the correct name' do
@student.name.should eql 'John'
expect(@student.name).to eql 'John'
end
it 'should assign the correct age' do
@student.age.should eql 25
expect(@student.age).to eql 25
end
end

describe '#play_hooky' do
it 'returns the correct message' do
@student.play_hooky.should eql '¯(ツ)/¯'
expect(@student.play_hooky).to eql '¯(ツ)/¯'
end
end
end
10 changes: 5 additions & 5 deletions spec/teacher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

describe '#initialize' do
it 'takes two parameters and returns a Teacher object' do
@teacher.should be_an_instance_of Teacher
expect(@teacher).to be_an_instance_of Teacher
end
it 'should assign the correct name' do
@teacher.name.should eql 'John'
expect(@teacher.name).to eql 'John'
end
it 'should assign the correct age' do
@teacher.age.should eql 25
expect(@teacher.age).to eql 25
end
it 'should assign the correct specialization' do
@teacher.specialization.should eql 'Math'
expect(@teacher.specialization).to eql 'Math'
end
end

describe '#can_use_services?' do
it 'returns true' do
@teacher.can_use_services?.should eql true
expect(@teacher.can_use_services?).to eql true
end
end
end

0 comments on commit 7c6981f

Please sign in to comment.