Skip to content
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

Modernize specs #274

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ jobs:
- name: RuboCop
run: |
gem install rubocop
gem install rubocop-rspec
rubocop
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--format doc
--require spec_helper
12 changes: 12 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rspec

AllCops:
NewCops: enable
TargetRubyVersion: 2.6
Expand Down Expand Up @@ -30,6 +33,15 @@ Metrics/ModuleLength:
Exclude:
- 'spec/**/*'

RSpec/ExampleLength:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Max: 10

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma

Expand Down
79 changes: 71 additions & 8 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion spec/heathen/convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ def failing_step_1
end
end

describe Heathen::Converter do
RSpec.describe Heathen::Converter do
before do
Heathen::Task.clear 'test'
end

after do
Heathen::Task.clear 'test'
end
Expand Down
7 changes: 4 additions & 3 deletions spec/heathen/filename_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'spec_helper'
require 'filemagic/ext'

describe Heathen::Filename do
RSpec.describe Heathen::Filename do
let(:content) { 'The quick brown fox jumps over the lazy dog' }
let(:mime_type) { content.mime_type }
context '.suggest' do

describe '.suggest' do
it 'suggests foo.pdf' do
expect(described_class.suggest('foo.pdf', mime_type)).to eq 'foo.txt'
end
Expand All @@ -22,7 +23,7 @@
end
end

context '.suggest_in_new_dir' do
describe '.suggest_in_new_dir' do
it 'suggests (short dir) -> (longer dir)' do
expect(
described_class.suggest_in_new_dir('/home/joe/src/foo.pdf', mime_type, '/home', '/opt/users')
Expand Down
4 changes: 2 additions & 2 deletions spec/heathen/processor_methods/convert_image_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Heathen::Processor do
RSpec.describe Heathen::Processor do
let(:content) { File.read(fixture('heathen/quickfox.jpg')) }
let(:job) { Heathen::Job.new 'foo', content, 'en' }
let(:processor) { described_class.new job: job, logger: spec_logger }
Expand All @@ -9,7 +9,7 @@
processor.clean_up
end

context '#convert_image' do
describe '#convert_image' do
it 'converts to tiff' do
processor.convert_image to: :tiff, params: '-density 72'
expect(job.content.mime_type).to eq 'image/tiff; charset=binary'
Expand Down
4 changes: 2 additions & 2 deletions spec/heathen/processor_methods/htmltotext_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Heathen::Processor do
RSpec.describe Heathen::Processor do
let(:content) { File.read(fixture('heathen/quickfox.html')) }
let(:job) { Heathen::Job.new 'foo', content, 'en' }
let(:processor) { described_class.new job: job, logger: Logger.new($stderr) }
Expand All @@ -9,7 +9,7 @@
processor.clean_up
end

context '#htmltotext' do
describe '#htmltotext' do
it 'converts HTML to TXT' do
processor.htmltotext
expect(job.content.mime_type).to eq 'text/plain; charset=us-ascii'
Expand Down
14 changes: 12 additions & 2 deletions spec/heathen/processor_methods/libreoffice_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Heathen::Processor do
RSpec.describe Heathen::Processor do
let(:ms_word_content) { File.read(fixture('heathen/msword.docx')) }
let(:ms_spreadsheet_content) { File.read(fixture('heathen/msexcel.xlsx')) }
let(:ms_ppt_content) { File.read(fixture('heathen/mspowerpoint.pptx')) }
Expand All @@ -17,33 +17,38 @@ def new_job(content)
@processor.clean_up
end

context '#libreoffice' do
describe '#libreoffice' do
context 'convert to PDF' do
it 'from MS word' do
new_job ms_word_content
@processor.libreoffice format: 'pdf'
expect(@job.content.mime_type).to eq 'application/pdf; charset=binary'
end

it 'from MS spreadsheet' do
new_job ms_spreadsheet_content
@processor.libreoffice format: 'pdf'
expect(@job.content.mime_type).to eq 'application/pdf; charset=binary'
end

it 'from MS powerpoint' do
new_job ms_ppt_content
@processor.libreoffice format: 'pdf'
expect(@job.content.mime_type).to eq 'application/pdf; charset=binary'
end

it 'from OO word' do
new_job oo_word_content
@processor.libreoffice format: 'pdf'
expect(@job.content.mime_type).to eq 'application/pdf; charset=binary'
end

it 'from OO spreadsheet' do
new_job oo_spreadsheet_content
@processor.libreoffice format: 'pdf'
expect(@job.content.mime_type).to eq 'application/pdf; charset=binary'
end

it 'from OO presentation' do
new_job oo_presentation_content
@processor.libreoffice format: 'pdf'
Expand All @@ -57,11 +62,13 @@ def new_job(content)
@processor.libreoffice format: 'msoffice'
expect(ms_word_mime_types).to include(@job.content.mime_type)
end

it 'from OO spreadsheet' do
new_job oo_spreadsheet_content
@processor.libreoffice format: 'msoffice'
expect(ms_excel_mime_types).to include(@job.content.mime_type)
end

it 'from OO presentation' do
new_job oo_presentation_content
@processor.libreoffice format: 'msoffice'
Expand All @@ -75,11 +82,13 @@ def new_job(content)
@processor.libreoffice format: 'ooffice'
expect(oo_odt_mime_types).to include(@job.content.mime_type)
end

it 'from MS spreadsheet' do
new_job ms_spreadsheet_content
@processor.libreoffice format: 'ooffice'
expect(oo_ods_mime_types).to include(@job.content.mime_type)
end

it 'from MS powerpoint' do
new_job ms_ppt_content
@processor.libreoffice format: 'ooffice'
Expand All @@ -93,6 +102,7 @@ def new_job(content)
@processor.libreoffice format: 'txt'
expect(@job.content.mime_type).to eq 'text/plain; charset=us-ascii'
end

it 'from OO word' do
new_job oo_word_content
@processor.libreoffice format: 'txt'
Expand Down
4 changes: 2 additions & 2 deletions spec/heathen/processor_methods/pdftotext_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Heathen::Processor do
RSpec.describe Heathen::Processor do
let(:content) { File.read(fixture('heathen/quickfox.pdf')) }
let(:job) { Heathen::Job.new 'foo', content, 'en' }
let(:processor) { described_class.new job: job, logger: Logger.new($stderr) }
Expand All @@ -9,7 +9,7 @@
processor.clean_up
end

context '#pdftotext' do
describe '#pdftotext' do
it 'converts PDF to TXT' do
processor.pdftotext
expect(job.content.mime_type).to eq 'text/plain; charset=us-ascii'
Expand Down
6 changes: 4 additions & 2 deletions spec/heathen/processor_methods/tesseract_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Heathen::Processor do
RSpec.describe Heathen::Processor do
let(:content) { File.read(fixture('heathen/quickfox.tiff')) }
let(:job) { Heathen::Job.new 'foo', content, 'en' }
let(:processor) { described_class.new job: job, logger: spec_logger }
Expand All @@ -9,15 +9,17 @@
processor.clean_up
end

context '#tesseract' do
describe '#tesseract' do
it 'converts a tiff to text' do
processor.tesseract format: nil
expect(job.content.mime_type).to eq 'text/plain; charset=us-ascii'
end

it 'converts a tiff to PDF' do
processor.tesseract format: 'pdf'
expect(job.content.mime_type).to eq 'application/pdf; charset=binary'
end

it 'converts a tiff to HOCR' do
processor.tesseract format: 'hocr'
expect(tesseract_hocr_mime_types).to include(job.content.mime_type)
Expand Down
4 changes: 2 additions & 2 deletions spec/heathen/processor_methods/wkhtmltopdf_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Heathen::Processor do
RSpec.describe Heathen::Processor do
let(:content) { File.read(fixture('heathen/quickfox.html')) }
let(:job) { Heathen::Job.new 'foo', content, 'en' }
let(:processor) { described_class.new job: job, logger: spec_logger }
Expand All @@ -9,7 +9,7 @@
processor.clean_up
end

context '#wkhtmltopdf' do
describe '#wkhtmltopdf' do
it 'converts HTML to PDF' do
processor.wkhtmltopdf
expect(job.content.mime_type).to eq 'application/pdf; charset=binary'
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/standard_tasks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'Standard Heathen tasks:' do
RSpec.describe 'Standard Heathen tasks:' do
before do
setup_storage
allow(Colore::C_).to receive(:storage_directory) { tmp_storage_dir }
Expand Down
Loading