Skip to content

Commit

Permalink
Add pdf processor test
Browse files Browse the repository at this point in the history
  • Loading branch information
frankete333 committed Feb 13, 2025
1 parent 2cb0d5a commit 35f51c0
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions spec/lib/academic_history/pdf_processor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'rails_helper'

RSpec.describe AcademicHistory::PdfProcessor, type: :lib do
let(:pdf_mock) {[

Check failure on line 4 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/MultilineBlockLayout: Block body expression is on the same line as the block start.

Check failure on line 4 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideBlockBraces: Space missing inside {.
double('page', text: " Test Subject 1 10 0 20/02/2024 Aceptable"),

Check failure on line 5 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [145/120]
double('page', text: " Test Subject 2 9 0 20/02/2024 Bueno"),

Check failure on line 6 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [141/120]
double('page', text: " Test Subject 3 8 0 20/02/2024 Muy Bueno"),

Check failure on line 7 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [145/120]
double('page', text: " Test Subject 4 7 0 20/02/2024 Excelente"),

Check failure on line 8 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [145/120]
double('page', text: " Test Subject 5 6 0 20/02/2024 S/C"),

Check failure on line 9 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [139/120]
double('page', text: " Failed Subject 1 8 1 ********** ***")

Check failure on line 10 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [138/120]
]}

Check failure on line 11 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/BlockEndNewline: Expression at 11, 4 should be on its own line.

let(:academic_entries) { described_class::AcademicEntry }

describe '.process' do
let(:file) { double('file', path: 'path') }
let(:reader) { double('reader') }
let(:academic_entries_list) {[

Check failure on line 18 in spec/lib/academic_history/pdf_processor_spec.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/MultilineBlockLayout: Block body expression is on the same line as the block start.
academic_entries.new('Test Subject 1', '10', '0', '20/02/2024', 'Aceptable'),
academic_entries.new('Test Subject 2', '9', '0', '20/02/2024', 'Bueno'),
academic_entries.new('Test Subject 3', '8', '0', '20/02/2024', 'Muy Bueno'),
academic_entries.new('Test Subject 4', '7', '0', '20/02/2024', 'Excelente'),
academic_entries.new('Test Subject 5', '6', '0', '20/02/2024', 'S/C'),
academic_entries.new('Failed Subject 1', '8', '1', '**********', '***')
]}

before do
allow(PDF::Reader).to receive(:new).with('path').and_return(reader)
allow(reader).to receive(:pages).and_return(pdf_mock)
end

it 'returns a list of academic entries' do
expect(described_class.process(file)).to all(be_an(academic_entries))
end

it 'parses the text from the pdf file' do
expect(described_class.process(file)).to eq(academic_entries_list)
end
end

describe 'academic entry' do
let(:entry) { academic_entries.new('Test Subject', '10', '0', '20/02/2024', 'Aceptable') }
let(:failed_entry) { academic_entries.new('Failed Subject', '10', '1', '**********', '***') }

it 'has a name' do
expect(entry.name).to eq('Test Subject')
end

it 'has a number of credits' do
expect(entry.credits).to eq('10')
end

it 'has a number of failures' do
expect(entry.number_of_failures).to eq('0')
end

it 'has a date of completion' do
expect(entry.date_of_completion).to eq('20/02/2024')
end

it 'has a grade' do
expect(entry.grade).to eq('Aceptable')
end

it 'is approved if the grade is not ***' do
expect(entry).to be_approved
end

it 'is not approved if the grade is ***' do
expect(failed_entry).not_to be_approved
end
end
end

0 comments on commit 35f51c0

Please sign in to comment.