upgrade incoming_mail_processor to new rspec syntax

refs CNVS-34040

test plan: specs should pass

Change-Id: Ifea91036ccb1f4981c29c3247fe40966b741a4ce
Reviewed-on: https://gerrit.instructure.com/98412
Reviewed-by: Landon Wilkins <lwilkins@instructure.com>
Product-Review: Landon Wilkins <lwilkins@instructure.com>
QA-Review: Landon Wilkins <lwilkins@instructure.com>
Tested-by: Jenkins
This commit is contained in:
Simon Williams 2016-12-22 16:12:00 -07:00
parent 8276039026
commit b7fe6659de
6 changed files with 73 additions and 73 deletions

View File

@ -35,7 +35,7 @@ describe IncomingMailProcessor::ConfigurableTimeout do
end
it "should provide a default timeout" do
lambda { @tester.with_timeout { sleep 1 } }.should raise_error(Timeout::Error)
expect { @tester.with_timeout { sleep 1 } }.to raise_error(Timeout::Error)
end
it "should use the provided timeout method" do
@ -47,31 +47,31 @@ describe IncomingMailProcessor::ConfigurableTimeout do
block.call
end
@tester.with_timeout { block_called = true }
method_called.should be_truthy
block_called.should be_truthy
expect(method_called).to be_truthy
expect(block_called).to be_truthy
end
it "should return what the timeout method returns" do
@tester.set_timeout_method { 42 }
@tester.with_timeout.should equal 42
expect(@tester.with_timeout).to equal 42
end
it "should raise what the timeout method raises" do
@tester.set_timeout_method { raise ArgumentError }
lambda { @tester.with_timeout { 42 } }.should raise_error(ArgumentError)
expect { @tester.with_timeout { 42 } }.to raise_error(ArgumentError)
end
it "should raise what the target method raises" do
lambda { @tester.with_timeout { raise ArgumentError } }.should raise_error(ArgumentError)
expect { @tester.with_timeout { raise ArgumentError } }.to raise_error(ArgumentError)
end
it "should allow easy wrapping of methods" do
@tester.wrap_with_timeout(@tester, [:foo])
@tester.set_timeout_method { raise ArgumentError }
lambda { @tester.foo(42) }.should raise_error(ArgumentError)
@tester.untimed_foo(42).should equal 42
expect { @tester.foo(42) }.to raise_error(ArgumentError)
expect(@tester.untimed_foo(42)).to equal 42
@tester.set_timeout_method {|&block| block.call }
@tester.foo(42).should equal 42
expect(@tester.foo(42)).to equal 42
end
end

View File

@ -33,12 +33,12 @@ describe IncomingMailProcessor::DirectoryMailbox do
it "should connect if folder exists" do
expect(@mailbox).to receive(:folder_exists?).with(default_config[:folder]).and_return(true)
expect { @mailbox.connect}.to_not raise_error
expect { @mailbox.connect }.to_not raise_error
end
it "should raise on connect if folder does not exist" do
expect(@mailbox).to receive(:folder_exists?).with(default_config[:folder]).and_return(false)
expect { @mailbox.connect }.to raise_error
expect { @mailbox.connect }.to raise_error(/Folder .* does not exist/)
end
describe ".each_message" do
@ -58,7 +58,7 @@ describe IncomingMailProcessor::DirectoryMailbox do
@mailbox.each_message do |*values|
yielded_values << values
end
yielded_values.should eql [["foo", "foo body"], ["bar", "bar body"], ["baz", "baz body"], ]
expect(yielded_values).to eql [["foo", "foo body"], ["bar", "bar body"], ["baz", "baz body"], ]
end
it "iterates with stride and offset" do
@ -79,19 +79,19 @@ describe IncomingMailProcessor::DirectoryMailbox do
@mailbox.each_message(stride: 2, offset: 0) do |*values|
yielded_values << values
end
yielded_values.should eql [["bar", "bar body"], ["baz", "baz body"], ]
expect(yielded_values).to eql [["bar", "bar body"], ["baz", "baz body"], ]
yielded_values = []
@mailbox.each_message(stride: 2, offset: 1) do |*values|
yielded_values << values
end
yielded_values.should eql [["foo", "foo body"]]
expect(yielded_values).to eql [["foo", "foo body"]]
end
end
describe '#unprocessed_message_count' do
it "should return nil" do
@mailbox.unprocessed_message_count.should be_nil
expect(@mailbox.unprocessed_message_count).to be_nil
end
end

View File

@ -59,23 +59,23 @@ describe IncomingMailProcessor::ImapMailbox do
:password => "secret-user-password",
})
@mailbox.server.should eql "imap.server.com"
@mailbox.port.should eql 1234
@mailbox.ssl.should eql "truthy-value"
@mailbox.filter.should eql ["ALL"]
@mailbox.username.should eql "user@server.com"
@mailbox.password.should eql "secret-user-password"
expect(@mailbox.server).to eql "imap.server.com"
expect(@mailbox.port).to eql 1234
expect(@mailbox.ssl).to eql "truthy-value"
expect(@mailbox.filter).to eql ["ALL"]
expect(@mailbox.username).to eql "user@server.com"
expect(@mailbox.password).to eql "secret-user-password"
end
it "should accept non-array filter" do
@mailbox = IncomingMailProcessor::ImapMailbox.new(:filter => "BLAH")
@mailbox.filter.should eql ["BLAH"]
expect(@mailbox.filter).to eql ["BLAH"]
end
it "should accept folder parameter" do
# this isn't necessary for gmail, but just in case
@mailbox = IncomingMailProcessor::ImapMailbox.new(:folder => "inbox")
@mailbox.folder.should eql "inbox"
expect(@mailbox.folder).to eql "inbox"
end
end
@ -90,12 +90,12 @@ describe IncomingMailProcessor::ImapMailbox do
describe '#unprocessed_message_count' do
it 'returns zero if there are no messages' do
expect(@imap_mock).to receive(:search).with(["X-GM-RAW", "label:unread"]).once.and_return([])
@mailbox.unprocessed_message_count.should eql 0
expect(@mailbox.unprocessed_message_count).to eql 0
end
it 'returns the number of messages if there are any' do
expect(@imap_mock).to receive(:search).with(["X-GM-RAW", "label:unread"]).once.and_return([1,2,3,58,42])
@mailbox.unprocessed_message_count.should eql 5
expect(@mailbox.unprocessed_message_count).to eql 5
end
end
@ -124,7 +124,7 @@ describe IncomingMailProcessor::ImapMailbox do
@mailbox.each_message do |message_id, message_body|
yielded_values << [message_id, message_body]
end
yielded_values.should eql [[1, "foo"], [2, "bar"], [3, "baz"]]
expect(yielded_values).to eql [[1, "foo"], [2, "bar"], [3, "baz"]]
end
it "retrieves messages uses stride and offset" do
@ -141,13 +141,13 @@ describe IncomingMailProcessor::ImapMailbox do
@mailbox.each_message(stride: 2, offset: 0) do |message_id, message_body|
yielded_values << [message_id, message_body]
end
yielded_values.should eql [[2, "bar"]]
expect(yielded_values).to eql [[2, "bar"]]
yielded_values = []
@mailbox.each_message(stride: 2, offset: 1) do |message_id, message_body|
yielded_values << [message_id, message_body]
end
yielded_values.should eql [[1, "foo"], [3, "baz"]]
expect(yielded_values).to eql [[1, "foo"], [3, "baz"]]
end
it "should delete a retrieved message" do
@ -208,7 +208,7 @@ describe IncomingMailProcessor::ImapMailbox do
describe "timeouts" do
it "should use timeout method on connect call" do
@mailbox.set_timeout_method { raise Timeout::Error }
lambda { @mailbox.connect }.should raise_error(Timeout::Error)
expect { @mailbox.connect }.to raise_error(Timeout::Error)
end
# if these work, others are likely wrapped with timeouts as well because of wrap_with_timeout
@ -226,7 +226,7 @@ describe IncomingMailProcessor::ImapMailbox do
rescue SyntaxError => e
exception_propegated = true
end
exception_propegated.should be_truthy
expect(exception_propegated).to be_truthy
end
end
end

View File

@ -77,10 +77,10 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
message = get_processed_message(filename)
text_body = message.body.strip
text_body.should == get_expected_text(filename).strip
expect(text_body).to eq(get_expected_text(filename).strip)
html_body = message.html_body.strip
html_body.should == get_expected_html(filename).strip
expect(html_body).to eq(get_expected_html(filename).strip)
end
def get_processed_message(name)
@ -121,21 +121,21 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
it "should consult .poll_interval and .ignore_stdin for backwards compatibility" do
IncomingMessageProcessor.logger = logger
IncomingMessageProcessor.configure('poll_interval' => 0, 'ignore_stdin' => true)
IncomingMessageProcessor.run_periodically?.should be_truthy
expect(IncomingMessageProcessor.run_periodically?).to be_truthy
IncomingMessageProcessor.configure('poll_interval' => 0, 'ignore_stdin' => false)
IncomingMessageProcessor.run_periodically?.should be_falsey
expect(IncomingMessageProcessor.run_periodically?).to be_falsey
IncomingMessageProcessor.configure('poll_interval' => 42, 'ignore_stdin' => true)
IncomingMessageProcessor.run_periodically?.should be_falsey
expect(IncomingMessageProcessor.run_periodically?).to be_falsey
end
it "should use 'run_periodically' configuration setting" do
IncomingMessageProcessor.configure({})
IncomingMessageProcessor.run_periodically?.should be_falsey
expect(IncomingMessageProcessor.run_periodically?).to be_falsey
IncomingMessageProcessor.configure('run_periodically' => true)
IncomingMessageProcessor.run_periodically?.should be_truthy
expect(IncomingMessageProcessor.run_periodically?).to be_truthy
end
end
@ -149,8 +149,8 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
content_type 'text/plain; charset=UTF-8'
body "he\xffllo".force_encoding(Encoding::BINARY) }, '')
message_handler.body.should == "hello"
message_handler.html_body.should == "hello"
expect(message_handler.body).to eq("hello")
expect(message_handler.html_body).to eq("hello")
end
it "should convert another charset to UTF-8" do
@ -161,8 +161,8 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
comparison_string = "\xe3\x82\xa1"
comparison_string.force_encoding("UTF-8")
message_handler.body.should == comparison_string
message_handler.html_body.should == comparison_string
expect(message_handler.body).to eq(comparison_string)
expect(message_handler.html_body).to eq(comparison_string)
end
it "should pick up html from a multipart" do
@ -175,8 +175,8 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
body '<h1>This is HTML</h1>'
end
}, '')
message_handler.body.should == 'This is plain text'
message_handler.html_body.should == '<h1>This is HTML</h1>'
expect(message_handler.body).to eq('This is plain text')
expect(message_handler.html_body).to eq('<h1>This is HTML</h1>')
end
it "should not send a bounce reply when the incoming message is an auto-response" do
@ -193,8 +193,8 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
content_type 'text/html; charset=UTF-8'
body '<h1>This is HTML</h1>'
}, '')
message_handler.body.should == "************\nThis is HTML\n************"
message_handler.html_body.should == '<h1>This is HTML</h1>'
expect(message_handler.body).to eq("************\nThis is HTML\n************")
expect(message_handler.html_body).to eq('<h1>This is HTML</h1>')
end
it "creates missing text part from html part" do
@ -204,8 +204,8 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
body '<h1>This is HTML</h1>'
end
}, '')
message_handler.body.should == "************\nThis is HTML\n************"
message_handler.html_body.should == '<h1>This is HTML</h1>'
expect(message_handler.body).to eq("************\nThis is HTML\n************")
expect(message_handler.html_body).to eq('<h1>This is HTML</h1>')
end
it "works with multipart emails with no html part" do
@ -229,8 +229,8 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
content_type nil
body "hello" }, '')
message_handler.body.should == "hello"
message_handler.html_body.should == "hello"
expect(message_handler.body).to eq("hello")
expect(message_handler.html_body).to eq("hello")
end
context "reporting stats" do
@ -504,15 +504,15 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
}
IncomingMessageProcessor.configure(config)
accounts = IncomingMessageProcessor.mailbox_accounts
accounts.size.should eql 3
expect(accounts.size).to eql 3
protocols = accounts.map(&:protocol)
protocols.count.should eql 3
protocols.count(:imap).should eql 2
protocols.count(:directory).should eql 1
expect(protocols.count).to eql 3
expect(protocols.count(:imap)).to eql 2
expect(protocols.count(:directory)).to eql 1
usernames = accounts.map(&:config).map{ |c| c[:username] }
usernames.count('foo').should eql 1
usernames.count('bar').should eql 1
usernames.count(nil).should eql 1
expect(usernames.count('foo')).to eql 1
expect(usernames.count('bar')).to eql 1
expect(usernames.count(nil)).to eql 1
end
it "should not try to load messages with invalid address tag" do
@ -522,7 +522,7 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
expect(account).to receive(:address).and_return('user@example.com')
expect(message).to receive(:to).and_return(['user@example.com'])
result = IncomingMessageProcessor.extract_address_tag(message, account)
result.should == false
expect(result).to eq(false)
end
end
@ -565,7 +565,7 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
err = MockErrorReporter.new
expect(err).to receive(:log_exception).once
IncomingMessageProcessor.new(message_handler, err).process
processed_second.should be_truthy
expect(processed_second).to be_truthy
end
end
end

View File

@ -19,11 +19,11 @@
shared_examples_for 'Mailbox' do
describe "Mailbox interface" do
it { should respond_to :connect }
it { should respond_to :each_message }
it { should respond_to :delete_message }
it { should respond_to :move_message }
it { should respond_to :disconnect }
it { should respond_to :set_timeout_method }
it { is_expected.to respond_to :connect }
it { is_expected.to respond_to :each_message }
it { is_expected.to respond_to :delete_message }
it { is_expected.to respond_to :move_message }
it { is_expected.to respond_to :disconnect }
it { is_expected.to respond_to :set_timeout_method }
end
end

View File

@ -52,11 +52,11 @@ describe IncomingMailProcessor::Pop3Mailbox do
:password => "secret-user-password",
})
@mailbox.server.should eql "pop3.server.com"
@mailbox.port.should eql 1234
@mailbox.ssl.should eql "truthy-value"
@mailbox.username.should eql "user@server.com"
@mailbox.password.should eql "secret-user-password"
expect(@mailbox.server).to eql "pop3.server.com"
expect(@mailbox.port).to eql 1234
expect(@mailbox.ssl).to eql "truthy-value"
expect(@mailbox.username).to eql "user@server.com"
expect(@mailbox.password).to eql "secret-user-password"
end
end
@ -99,7 +99,7 @@ describe IncomingMailProcessor::Pop3Mailbox do
describe '#unprocessed_message_count' do
it "should return nil" do
IncomingMailProcessor::Pop3Mailbox.new(default_config).unprocessed_message_count.should be_nil
expect(IncomingMailProcessor::Pop3Mailbox.new(default_config).unprocessed_message_count).to be_nil
end
end
@ -121,7 +121,7 @@ describe IncomingMailProcessor::Pop3Mailbox do
yielded_values << [message_id, body]
end
yielded_values.should eql [[foo, "foo body"], [bar, "bar body"], [baz, "baz body"]]
expect(yielded_values).to eql [[foo, "foo body"], [bar, "bar body"], [baz, "baz body"]]
end
it "retrieves messages using a stride and offset" do
@ -136,13 +136,13 @@ describe IncomingMailProcessor::Pop3Mailbox do
@mailbox.each_message(stride: 2, offset: 0) do |message_id, body|
yielded_values << [message_id, body]
end
yielded_values.should eql [[bar, "bar body"], [baz, "baz body"]]
expect(yielded_values).to eql [[bar, "bar body"], [baz, "baz body"]]
yielded_values = []
@mailbox.each_message(stride: 2, offset: 1) do |message_id, body|
yielded_values << [message_id, body]
end
yielded_values.should eql [[foo, "foo body"]]
expect(yielded_values).to eql [[foo, "foo body"]]
end
context "with simple foo message" do