Skip to content
This repository has been archived by the owner on Dec 28, 2017. It is now read-only.

Commit

Permalink
moved message formatting to separate Class
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Cook committed Nov 17, 2011
1 parent 0e5fac7 commit ebe54ba
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/epub_validator/format_error_message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module EpubValidator
class FormatErrorMessage
def process_message(message)
return ['Passed.'] if message.match('No errors or warnings detected')

m_array = message.split(/\n/)

# clean up all useless info
m_array.delete_if do |s|
s.empty? or
s.match('^Epubcheck Version.*') or
s.match('^Check finished.*')
end

m_array.unshift('FAILED!')
end
end
end
29 changes: 29 additions & 0 deletions spec/epub_validator/format_error_message_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

module EpubValidator
describe FormatErrorMessage do
context "when it recieves a missing file message" do
it "should return a 'FAILED!' message as an array" do
message = "ERROR: test.epub: I/O error: test.epub (No such file or directory)"
formatted_message = ["FAILED!", "ERROR: test.epub: I/O error: test.epub (No such file or directory)"]
errm = FormatErrorMessage.new
errm.process_message(message).should eq(formatted_message)
end
end
context "when it recieves a valid file message" do
it "should return 'Passed.' message as an array" do
message = "Epubcheck Version 1.2\n\nNo errors or warnings detected\n"
errm = FormatErrorMessage.new
errm.process_message(message).should eq(['Passed.'])
end
end
context "when it recieves an invalid file message" do
it "should return error message as an array" do
message = "Epubcheck Version 1.2\n\nERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing\n\nCheck finished with warnings or errors!"
formatted_message = ["FAILED!", "ERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing"]
errm = FormatErrorMessage.new
errm.process_message(message).should eq(formatted_message)
end
end
end
end

0 comments on commit ebe54ba

Please sign in to comment.