This repository has been archived by the owner on Dec 28, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved message formatting to separate Class
- Loading branch information
Mike Cook
committed
Nov 17, 2011
1 parent
0e5fac7
commit ebe54ba
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |