From 7c6981f45c6528ae4c30f24d512dd0ca4e4bf294 Mon Sep 17 00:00:00 2001 From: Ansar Ibrahim <117971223+AnsarIbrahim@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:59:42 +0530 Subject: [PATCH] Fix-old-syntax-to-new-syntax --- .../decorators/trimmer_decorator.rb | 1 + spec/book_spec.rb | 20 ++++---- spec/decorator_spec.rb | 10 ++-- spec/person_spec.rb | 48 +++++++++---------- spec/rental_spec.rb | 12 ++--- spec/student_spec.rb | 8 ++-- spec/teacher_spec.rb | 10 ++-- 7 files changed, 56 insertions(+), 53 deletions(-) diff --git a/school_library/decorators/trimmer_decorator.rb b/school_library/decorators/trimmer_decorator.rb index c7a0657..471d0f0 100644 --- a/school_library/decorators/trimmer_decorator.rb +++ b/school_library/decorators/trimmer_decorator.rb @@ -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 diff --git a/spec/book_spec.rb b/spec/book_spec.rb index 675d421..aa1bf9d 100644 --- a/spec/book_spec.rb +++ b/spec/book_spec.rb @@ -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 diff --git a/spec/decorator_spec.rb b/spec/decorator_spec.rb index c2ac128..fd78625 100644 --- a/spec/decorator_spec.rb +++ b/spec/decorator_spec.rb @@ -5,8 +5,9 @@ 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 @@ -14,8 +15,9 @@ 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 diff --git a/spec/person_spec.rb b/spec/person_spec.rb index 3798b6a..826c633 100644 --- a/spec/person_spec.rb +++ b/spec/person_spec.rb @@ -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 diff --git a/spec/rental_spec.rb b/spec/rental_spec.rb index 7bbf8f7..ffe14c9 100644 --- a/spec/rental_spec.rb +++ b/spec/rental_spec.rb @@ -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 diff --git a/spec/student_spec.rb b/spec/student_spec.rb index f82007f..f9ab2b4 100644 --- a/spec/student_spec.rb +++ b/spec/student_spec.rb @@ -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 diff --git a/spec/teacher_spec.rb b/spec/teacher_spec.rb index e1b54bb..24211c9 100644 --- a/spec/teacher_spec.rb +++ b/spec/teacher_spec.rb @@ -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