From 3505b1ac4236e44206c6b323b6ad3ca220fd813b Mon Sep 17 00:00:00 2001 From: Fernando Morgenstern Date: Wed, 13 Dec 2017 13:39:10 -0200 Subject: [PATCH 1/2] Change tests in report_parser_spec.rb to actually check values They weren't using expect() so rspec wasn't testing anything. --- spec/RubySpamAssassin/report_parser_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/RubySpamAssassin/report_parser_spec.rb b/spec/RubySpamAssassin/report_parser_spec.rb index 7c3ac22..74144b6 100644 --- a/spec/RubySpamAssassin/report_parser_spec.rb +++ b/spec/RubySpamAssassin/report_parser_spec.rb @@ -4,11 +4,11 @@ it "should parse the report text into an informative hash" do spam = File.read('spec/data/spam_test1.txt') result = RubySpamAssassin::ReportParser.parse(spam) - result.length.equal?(6) + expect(result.length).to eq(6) # Check contents of first one to make sure text/points are formatted correctly - result[0][:pts].equal?(0.5) - result[0][:rule].equal?('DATE_IN_PAST_24_48') - result[0][:text].equal?('Date: is 24 to 48 hours before Received: date') + expect(result[0][:pts]).to eq(0.5) + expect(result[0][:rule]).to eq('DATE_IN_PAST_24_48') + expect(result[0][:text]).to eq('Date: is 24 to 48 hours before Received: date') end end From 0f82773b2ab4c8f36a3d1da6d91b6abebc95097e Mon Sep 17 00:00:00 2001 From: Fernando Morgenstern Date: Wed, 13 Dec 2017 13:42:06 -0200 Subject: [PATCH 2/2] Fix rule texts parsing It was using squeeze method without any parameter which will squeeze all characters. Texts like "Message-Id is not valid, according to RFC 2822" were parsed as "Mesage-Id is not valid, acording to RFC 282". Note that Message-Id was changed to Mesage-Id and RFC 2822 was changed to RFC 282. --- lib/RubySpamAssassin/report_parser.rb | 2 +- spec/RubySpamAssassin/report_parser_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/RubySpamAssassin/report_parser.rb b/lib/RubySpamAssassin/report_parser.rb index 400a18f..5fbafa9 100644 --- a/lib/RubySpamAssassin/report_parser.rb +++ b/lib/RubySpamAssassin/report_parser.rb @@ -5,7 +5,7 @@ class RubySpamAssassin::ReportParser def self.parse(report_text) last_part = report_text.split(LINE_REGEXP)[1].sub(/^[\n\r]/,'').chomp.chomp pts_rules = last_part.gsub(RULE_REGEXP).collect { |sub| sub.chomp(' ') } - rule_texts = last_part.split(RULE_REGEXP).collect { |text| text.delete("\n").squeeze.chomp(' ').sub(/^\s/, '') } + rule_texts = last_part.split(RULE_REGEXP).collect { |text| text.delete("\n").squeeze(' ').strip } rules = [] pts_rules.each_with_index do |pts_rule, i| diff --git a/spec/RubySpamAssassin/report_parser_spec.rb b/spec/RubySpamAssassin/report_parser_spec.rb index 74144b6..fc7b2ac 100644 --- a/spec/RubySpamAssassin/report_parser_spec.rb +++ b/spec/RubySpamAssassin/report_parser_spec.rb @@ -6,9 +6,13 @@ result = RubySpamAssassin::ReportParser.parse(spam) expect(result.length).to eq(6) - # Check contents of first one to make sure text/points are formatted correctly + # Check contents of some rules to make sure text/points are formatted correctly expect(result[0][:pts]).to eq(0.5) expect(result[0][:rule]).to eq('DATE_IN_PAST_24_48') expect(result[0][:text]).to eq('Date: is 24 to 48 hours before Received: date') + + expect(result[4][:pts]).to eq(1.2) + expect(result[4][:rule]).to eq('INVALID_MSGID') + expect(result[4][:text]).to eq('Message-Id is not valid, according to RFC 2822') end end