Commit 69cd6823 authored by charlie-ablett's avatar charlie-ablett
Browse files

Refactor tests, change successful = true to success!, better Mogrify example...

Refactor tests, change successful = true to success!, better Mogrify example and input file handling
parent 11f5d06a
......@@ -10,7 +10,7 @@ GIT
PATH
remote: .
specs:
inkstep_coko_conversion (1.0.2)
inkstep_coko_conversion (1.0.3)
GEM
remote: https://rubygems.org/
......
......@@ -14,7 +14,7 @@ module InkStep::Coko
output_file_path = File.join(working_directory, "#{source_file_name}.#{parameter(:output_file_format)}")
perform_calibre_conversion(File.join(working_directory, source_file_path), output_file_path)
@successful = true
success!
end
def version
......@@ -54,7 +54,6 @@ module InkStep::Coko
# see readme for more info about usage
# ebook-convert input_file output_file
command = "ebook-convert #{source_file_path} #{destination_file_path} #{parameter(:options)}"
log_as_step "running #{command}"
perform_command(command: command, error_prefix: "Error running ebook-convert")
end
......
......@@ -46,7 +46,6 @@ module InkStep::Coko
# see readme for more info about usage
# ebook-convert input_file output_file
command = "ebook-convert #{source_file_path} #{destination_file_path}"
log_as_step "running #{command}"
perform_command(command: command, error_prefix: "Error running ebook-convert")
end
......
......@@ -5,10 +5,11 @@ module InkStep::Coko
class MogrifyConversionStep < InkStep::ConversionStep
def perform_step
source_file_path = find_source_file(regex: /\.jpg$/)
source_file = parameter(:source_file) || find_source_file(regex: /\.jpg$/)
output_file_name = parameter(:output_file)
perform_conversion(File.join(working_directory, source_file_path))
@successful = true
perform_conversion(source_file, output_file_name)
success!
end
def version
......@@ -42,12 +43,12 @@ module InkStep::Coko
private
def perform_conversion(source_file_path)
def perform_conversion(source_file, output_file)
output_file_path = output_file ? File.join(working_directory, output_file) : nil
# Modifies the supplied image file
# magick mogrify -resize 50% rose.jpg
# ubuntu doesn't need the 'magick' bit
command = "mogrify #{parameter(:options)} -m #{source_file_path}"
log_as_step "running #{command}"
command = "mogrify #{parameter(:options)} #{File.join(working_directory, source_file)} #{output_file_path}"
perform_command(command: command, error_prefix: "Error running mogrify")
end
......
......@@ -8,7 +8,7 @@ module InkStep::Coko
source_file_path = find_source_file(regex: /\.html$/)
perform_conversion(File.join(working_directory, source_file_path))
@successful = true
success!
end
def version
......@@ -47,7 +47,6 @@ module InkStep::Coko
# Modifies the supplied html file
# tidy -m index.html
command = "tidy -m #{source_file_path} #{parameter(:options)} "
log_as_step "running #{command}"
perform_command(command: command, error_prefix: "Error running tidy")
end
......
......@@ -11,7 +11,7 @@ module InkStep::Coko
output_file_path = File.join(working_directory, "#{source_file_name}.pdf")
run_html_to_pdf_conversion(File.join(working_directory, source_file_name), output_file_path)
@successful = true
success!
end
def version
......
module CokoConversion
VERSION = '1.0.2'
VERSION = '1.0.3'
end
\ No newline at end of file
......@@ -22,7 +22,6 @@ describe InkStep::Coko::CalibreConversionStep do
context 'converting a file successfully using Calibre' do
specify do
@subject.combined_parameters = {input_file_format: "html", output_file_format: "epub", options: "--disable-font-rescaling"}
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......
......@@ -21,8 +21,6 @@ describe InkStep::Coko::CalibreHtmlToEpubStep do
describe '#perform_step' do
context 'converting a file successfully' do
specify do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......
......@@ -15,15 +15,23 @@ describe InkStep::Coko::MogrifyConversionStep do
end
after :each do
FileUtils.rm_rf(FileUtils.rm_rf(Dir.glob("#{temp_directory}/*")))
# FileUtils.rm_rf(FileUtils.rm_rf(Dir.glob("#{temp_directory}/*")))
end
describe '#perform_step' do
context 'converting a file successfully' do
context 'with no options' do
specify do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
context 'with some options' do
specify do
@subject.combined_parameters = {options: "-crop 120x120+10+5"}
expect_successful_conversion(test_subject: @subject)
expect(@subject.process_log.grep(/Error running mogrify/).any?).to be_falsey
end
end
end
......
......@@ -23,8 +23,6 @@ describe InkStep::Coko::PandocEpubToHtmlStep do
describe '#perform_step' do
context 'converting a file successfully using EpubToHTML (Pandoc)' do
specify do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......
......@@ -27,8 +27,6 @@ describe InkStep::Coko::PandocEpubToIcmlStep do
context 'first file' do
specify do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......
......@@ -22,10 +22,7 @@ describe InkStep::Coko::TidyConversionStep do
context 'converting a file successfully using Calibre' do
specify do
# subject.combined_parameters = {options: "‑clean"}
@subject.perform_step
expect_successful_conversion expected_output: [{path: "asdf", size: "123kb"}], test_subject: @subject
expect_successful_conversion expected_output: [{:path=>"some_text.html", :size=>"276 bytes", :checksum=>"571d6310ddc7b1b03954fee4196ec716", :tag=>:modified}], test_subject: @subject
end
end
end
......
......@@ -24,8 +24,6 @@ describe InkStep::Coko::VivliostyleHtmlToPdfStep do
context 'and that file exists' do
it 'finds and converts only that file' do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......@@ -50,8 +48,6 @@ describe InkStep::Coko::VivliostyleHtmlToPdfStep do
end
it 'finds and converts that file' do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......@@ -62,8 +58,6 @@ describe InkStep::Coko::VivliostyleHtmlToPdfStep do
end
it 'finds and converts that file' do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......@@ -95,8 +89,6 @@ describe InkStep::Coko::VivliostyleHtmlToPdfStep do
end
specify do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......
......@@ -22,8 +22,6 @@ describe InkStep::Coko::WkHtmlToPdfStep do
context 'converting a file successfully using WkHTMLtoPDF Electron' do
specify do
@subject.perform_step
expect_successful_conversion(test_subject: @subject)
end
end
......
......@@ -14,9 +14,13 @@ def create_directory_if_needed(path)
end
def expect_successful_conversion(expected_output: nil, test_subject: subject)
# if expected_output
# expect(test_subject.output_file_manifest).to eq (expected_output)
# end
# expect(test_subject.output_file_manifest).to_not eq test_subject.input_file_manifest
# expect(test_subject.output_file_manifest).to_not be_nil
test_subject.input_file_manifest = test_subject.semantically_tagged_manifest
test_subject.perform_step
if expected_output
expect(test_subject.semantically_tagged_manifest).to eq (expected_output)
else
expect(test_subject.semantically_tagged_manifest).to_not eq test_subject.input_file_manifest
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment