From b2851788b9ed6d0373c9922fa6c56b0f075fc590 Mon Sep 17 00:00:00 2001 From: Stephan Leroux Date: Mon, 11 Mar 2013 14:37:47 -0400 Subject: [PATCH] Removed unused cucumber. Added basic test for parser --- Gemfile | 1 - Rakefile | 3 -- features/RubySpamAssassin.feature | 9 ----- .../RubySpamAssassin_steps.rb | 0 features/support/env.rb | 13 ------- lib/RubySpamAssassin/report_parser.rb | 2 +- spec/RubySpamAssassin/report_parser_spec.rb | 14 +++++++ spec/RubySpamAssassin/spam_client_spec.rb | 1 + spec/RubySpamAssassin/spam_result_spec.rb | 1 + spec/RubySpamAssassin_spec.rb | 4 +- spec/data/spam_test1.txt | 39 +++++++++++++++++++ spec/spec_helper.rb | 1 - 12 files changed, 57 insertions(+), 31 deletions(-) delete mode 100644 features/RubySpamAssassin.feature delete mode 100644 features/step_definitions/RubySpamAssassin_steps.rb delete mode 100644 features/support/env.rb create mode 100644 spec/RubySpamAssassin/report_parser_spec.rb create mode 100644 spec/RubySpamAssassin/spam_client_spec.rb create mode 100644 spec/RubySpamAssassin/spam_result_spec.rb create mode 100644 spec/data/spam_test1.txt diff --git a/Gemfile b/Gemfile index 2fb9593..0fda1ff 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,6 @@ source "http://rubygems.org" # Include everything needed to run rake, tests, features, etc. group :development do gem "rspec", "~> 2.3.0" - gem "cucumber", ">= 0" gem "bundler" # , "~> 1.0.0" gem "jeweler" # , "~> 1.5.2" end diff --git a/Rakefile b/Rakefile index f989932..7735aaa 100644 --- a/Rakefile +++ b/Rakefile @@ -38,7 +38,4 @@ RSpec::Core::RakeTask.new(:rcov) do |spec| spec.rcov = true end -require 'cucumber/rake/task' -Cucumber::Rake::Task.new(:features) - task :default => :spec diff --git a/features/RubySpamAssassin.feature b/features/RubySpamAssassin.feature deleted file mode 100644 index b908b60..0000000 --- a/features/RubySpamAssassin.feature +++ /dev/null @@ -1,9 +0,0 @@ -Feature: something something - In order to something something - A user something something - something something something - - Scenario: something something - Given inspiration - When I create a sweet new gem - Then everyone should see how awesome I am diff --git a/features/step_definitions/RubySpamAssassin_steps.rb b/features/step_definitions/RubySpamAssassin_steps.rb deleted file mode 100644 index e69de29..0000000 diff --git a/features/support/env.rb b/features/support/env.rb deleted file mode 100644 index 556a74d..0000000 --- a/features/support/env.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'bundler' -begin - Bundler.setup(:default, :development) -rescue Bundler::BundlerError => e - $stderr.puts e.message - $stderr.puts "Run `bundle install` to install missing gems" - exit e.status_code -end - -$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib') -require 'RubySpamAssassin' - -require 'rspec/expectations' diff --git a/lib/RubySpamAssassin/report_parser.rb b/lib/RubySpamAssassin/report_parser.rb index 251a9d0..38a1599 100644 --- a/lib/RubySpamAssassin/report_parser.rb +++ b/lib/RubySpamAssassin/report_parser.rb @@ -10,7 +10,7 @@ def self.parse(report_text) rules = [] pts_rules.each_with_index do |pts_rule, i| rules << { - :pts => pts_rule.split(' ')[0], + :pts => pts_rule.split(' ')[0].to_f, :rule => pts_rule.split(' ')[1], :text => rule_texts[i + 1] } diff --git a/spec/RubySpamAssassin/report_parser_spec.rb b/spec/RubySpamAssassin/report_parser_spec.rb new file mode 100644 index 0000000..7c3ac22 --- /dev/null +++ b/spec/RubySpamAssassin/report_parser_spec.rb @@ -0,0 +1,14 @@ +require_relative '../spec_helper' + +describe "ReportParser" do + 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) + + # 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') + end +end diff --git a/spec/RubySpamAssassin/spam_client_spec.rb b/spec/RubySpamAssassin/spam_client_spec.rb new file mode 100644 index 0000000..291aa3e --- /dev/null +++ b/spec/RubySpamAssassin/spam_client_spec.rb @@ -0,0 +1 @@ +require_relative '../spec_helper' \ No newline at end of file diff --git a/spec/RubySpamAssassin/spam_result_spec.rb b/spec/RubySpamAssassin/spam_result_spec.rb new file mode 100644 index 0000000..291aa3e --- /dev/null +++ b/spec/RubySpamAssassin/spam_result_spec.rb @@ -0,0 +1 @@ +require_relative '../spec_helper' \ No newline at end of file diff --git a/spec/RubySpamAssassin_spec.rb b/spec/RubySpamAssassin_spec.rb index a3f19c0..3d899a5 100644 --- a/spec/RubySpamAssassin_spec.rb +++ b/spec/RubySpamAssassin_spec.rb @@ -1,7 +1,5 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "Rubyspamassassin" do - it "fails" do - fail "hey buddy, you should probably rename this file and start specing for real" - end + end diff --git a/spec/data/spam_test1.txt b/spec/data/spam_test1.txt new file mode 100644 index 0000000..bbac313 --- /dev/null +++ b/spec/data/spam_test1.txt @@ -0,0 +1,39 @@ +X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on + scanner.com +X-Spam-Level: *** +X-Spam-Status: No, score=3.4 required=5.0 tests=DATE_IN_PAST_24_48, + HTML_MESSAGE,HTML_MIME_NO_HTML_TAG,INVALID_MSGID,MIME_HTML_ONLY, + UNPARSEABLE_RELAY autolearn=no version=3.3.2 +Received: from dummyurl.com for ; Fri, 8 Mar 2013 14:53:15 -0500 +Date: Thu, 7 Mar 2013 00:02:33 -0500 +From: Dummy +Reply-To: Dummy +To: dummy@dummy.com +Message-Id: testdummy@dummy.com +Subject: Work Report +Mime-Version: 1.0 +Content-Type: text/html; charset=utf-8 +Auto-Submitted: auto-generated + +Hey, + +Was wondering if I could get a copy of the work report you made yesterday. Thanks! +Spam detection software, running on the system "scan1.blue.postageapp.com", has +identified this incoming email as possible spam. The original message +has been attached to this so you can view it (if it isn't spam) or label +similar future email. If you have any questions, see +the administrator of that system for details. + +Content preview: Hey, Was wondering if I could get a copy of the work report + you made yesterday. Thanks! [...] + +Content analysis details: (3.4 points, 5.0 required) + + pts rule name description +---- ---------------------- -------------------------------------------------- + 0.5 DATE_IN_PAST_24_48 Date: is 24 to 48 hours before Received: date + 0.0 HTML_MESSAGE BODY: HTML included in message + 1.1 MIME_HTML_ONLY BODY: Message only has text/html MIME parts + 0.6 HTML_MIME_NO_HTML_TAG HTML-only message, but there is no HTML tag + 1.2 INVALID_MSGID Message-Id is not valid, according to RFC 2822 + 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 12f4293..841d3f4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,5 +8,4 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |config| - end