aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Landauer <matthew@openaustralia.org>2012-10-10 11:16:49 +1100
committerMatthew Landauer <matthew@openaustralia.org>2012-10-10 11:16:49 +1100
commit59def426f6ab693c6a4afd8b910ececf8547a97d (patch)
treecda16da60ee44e59b538736658f84cf23e62c606
parent9cb4135c8089f37a5769eb1fe7c13385edd281df (diff)
Simplify tests just a little
-rw-r--r--spec/models/exim_log_spec.rb28
1 files changed, 12 insertions, 16 deletions
diff --git a/spec/models/exim_log_spec.rb b/spec/models/exim_log_spec.rb
index d7948ff3a..c10100d36 100644
--- a/spec/models/exim_log_spec.rb
+++ b/spec/models/exim_log_spec.rb
@@ -2,15 +2,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe EximLog do
describe ".load_file" do
- it "loads relevant lines of an uncompressed exim log file" do
+ before :each do
Configuration.stub!(:incoming_email_domain).and_return("example.com")
- File.stub_chain(:stat, :mtime).and_return(Date.new(2012, 10, 10))
- log = [
- "This is a line of a logfile relevant to foi+request-1234@example.com",
- "This is the second line for the same foi+request-1234@example.com email address"
- ]
+ File.stub_chain(:stat, :mtime).and_return(DateTime.new(2012, 10, 10))
+ end
+
+ let(:log) {[
+ "This is a line of a logfile relevant to foi+request-1234@example.com",
+ "This is the second line for the same foi+request-1234@example.com email address"
+ ]}
+
+ let(:ir) { info_requests(:fancy_dog_request) }
+
+ it "loads relevant lines of an uncompressed exim log file" do
File.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10", "r").and_return(log)
- ir = info_requests(:fancy_dog_request)
InfoRequest.should_receive(:find_by_incoming_email).with("request-1234@example.com").twice.and_return(ir)
EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10")
@@ -25,7 +30,6 @@ describe EximLog do
end
it "doesn't load the log file twice if it's unchanged" do
- File.stub_chain(:stat, :mtime).and_return(DateTime.new(2012, 10, 10))
File.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10", "r").once.and_return([])
EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10")
@@ -34,23 +38,15 @@ describe EximLog do
it "loads the log file again if it's changed" do
File.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10", "r").twice.and_return([])
- File.stub_chain(:stat, :mtime).and_return(DateTime.new(2012, 10, 10))
EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10")
File.stub_chain(:stat, :mtime).and_return(DateTime.new(2012, 10, 11))
EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10")
end
it "doesn't end up with two copies of each line when the same file is actually loaded twice" do
- Configuration.stub!(:incoming_email_domain).and_return("example.com")
- log = [
- "This is a line of a logfile relevant to foi+request-1234@example.com",
- "This is the second line for the same foi+request-1234@example.com email address"
- ]
File.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10", "r").twice.and_return(log)
- ir = info_requests(:fancy_dog_request)
InfoRequest.should_receive(:find_by_incoming_email).with("request-1234@example.com").any_number_of_times.and_return(ir)
- File.stub_chain(:stat, :mtime).and_return(DateTime.new(2012, 10, 10))
EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10")
ir.exim_logs.count.should == 2