Skip to content

Commit

Permalink
completely removed old (should) rspec expectation format in favour of…
Browse files Browse the repository at this point in the history
… new (expect) expectation format, so that same format is used accross all tests
  • Loading branch information
ibalosh committed Sep 26, 2019
1 parent 9899498 commit 6d1f200
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 114 deletions.
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
RSpec.configure do |config|
include Postmark::RSpecHelpers

config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
config.expect_with(:rspec) { |c| c.syntax = :expect }

config.filter_run_excluding :skip_for_platform => lambda { |platform|
RUBY_PLATFORM.to_s =~ /^#{platform.to_s}/
Expand All @@ -50,8 +50,9 @@
end
end

# define custom matchers
RSpec::Matchers.define :be_serialized_to do |json|
match do |mail_message|
Postmark.convert_message_to_options_hash(mail_message).should == JSON.parse(json)
Postmark.convert_message_to_options_hash(mail_message) == JSON.parse(json)
end
end
32 changes: 16 additions & 16 deletions spec/support/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
shared_examples :mail do
it "should set text body for plain message" do
Postmark.send(:convert_message_to_options_hash, subject)['TextBody'].should_not be_nil
it "set text body for plain message" do
expect(Postmark.send(:convert_message_to_options_hash, subject)['TextBody']).not_to be_nil
end

it "should encode from properly when name is used" do
it "encode from properly when name is used" do
subject.from = "Sheldon Lee Cooper <[email protected]>"
subject.should be_serialized_to %q[{"Subject":"Hello!", "From":"Sheldon Lee Cooper <[email protected]>", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
expect(subject).to be_serialized_to %q[{"Subject":"Hello!", "From":"Sheldon Lee Cooper <[email protected]>", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
end

it "should encode reply to" do
it "encode reply to" do
subject.reply_to = ['[email protected]', '[email protected]']
subject.should be_serialized_to %q[{"Subject":"Hello!", "From":"[email protected]", "ReplyTo":"[email protected], [email protected]", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
expect(subject).to be_serialized_to %q[{"Subject":"Hello!", "From":"[email protected]", "ReplyTo":"[email protected], [email protected]", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
end

it "should encode tag" do
it "encode tag" do
subject.tag = "invite"
subject.should be_serialized_to %q[{"Subject":"Hello!", "From":"[email protected]", "Tag":"invite", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
expect(subject).to be_serialized_to %q[{"Subject":"Hello!", "From":"[email protected]", "Tag":"invite", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
end

it "should encode multiple recepients (TO)" do
it "encode multiple recepients (TO)" do
subject.to = ['[email protected]', '[email protected]']
subject.should be_serialized_to %q[{"Subject":"Hello!", "From":"[email protected]", "To":"[email protected], [email protected]", "TextBody":"Hello Sheldon!"}]
expect(subject).to be_serialized_to %q[{"Subject":"Hello!", "From":"[email protected]", "To":"[email protected], [email protected]", "TextBody":"Hello Sheldon!"}]
end

it "should encode multiple recepients (CC)" do
it "encode multiple recepients (CC)" do
subject.cc = ['[email protected]', '[email protected]']
subject.should be_serialized_to %q[{"Cc":"[email protected], [email protected]", "Subject":"Hello!", "From":"[email protected]", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
expect(subject).to be_serialized_to %q[{"Cc":"[email protected], [email protected]", "Subject":"Hello!", "From":"[email protected]", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
end

it "should encode multiple recepients (BCC)" do
it "encode multiple recepients (BCC)" do
subject.bcc = ['[email protected]', '[email protected]']
subject.should be_serialized_to %q[{"Bcc":"[email protected], [email protected]", "Subject":"Hello!", "From":"[email protected]", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
expect(subject).to be_serialized_to %q[{"Bcc":"[email protected], [email protected]", "Subject":"Hello!", "From":"[email protected]", "To":"[email protected]", "TextBody":"Hello Sheldon!"}]
end

it "should accept string as reply_to field" do
it "accept string as reply_to field" do
subject.reply_to = ['Anton Astashov <[email protected]>']
subject.should be_serialized_to %q[{"From": "[email protected]", "ReplyTo": "[email protected]", "To": "[email protected]", "Subject": "Hello!", "TextBody": "Hello Sheldon!"}]
expect(subject).to be_serialized_to %q[{"From": "[email protected]", "ReplyTo": "[email protected]", "To": "[email protected]", "Subject": "Hello!", "TextBody": "Hello Sheldon!"}]
end
end
33 changes: 15 additions & 18 deletions spec/unit/postmark/bounce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
subject { bounce }

context "attr readers" do

it { expect(subject).to respond_to(:email) }
it { expect(subject).to respond_to(:bounced_at) }
it { expect(subject).to respond_to(:type) }
Expand All @@ -32,7 +31,6 @@
it { expect(subject).to respond_to(:tag) }
it { expect(subject).to respond_to(:message_id) }
it { expect(subject).to respond_to(:subject) }

end

context "given a bounce created from bounce_data" do
Expand All @@ -49,14 +47,14 @@
expect(subject.dump_available?).to be true
end

its(:type) { should eq bounce_data[:type] }
its(:message_id) { should eq bounce_data[:message_id] }
its(:description) { should eq bounce_data[:description] }
its(:details) { should eq bounce_data[:details] }
its(:email) { should eq bounce_data[:email] }
its(:bounced_at) { should == Time.parse(bounce_data[:bounced_at]) }
its(:id) { should eq bounce_data[:id] }
its(:subject) { should eq bounce_data[:subject] }
its(:type) { is_expected.to eq bounce_data[:type] }
its(:message_id) { is_expected.to eq bounce_data[:message_id] }
its(:description) { is_expected.to eq bounce_data[:description] }
its(:details) { is_expected.to eq bounce_data[:details] }
its(:email) { is_expected.to eq bounce_data[:email] }
its(:bounced_at) { is_expected.to eq Time.parse(bounce_data[:bounced_at]) }
its(:id) { is_expected.to eq bounce_data[:id] }
its(:subject) { is_expected.to eq bounce_data[:subject] }

end

Expand All @@ -75,14 +73,13 @@
expect(subject.dump_available?).to be true
end

its(:type) { should eq bounce_data[:type] }
its(:message_id) { should eq bounce_data[:message_id] }
its(:details) { should eq bounce_data[:details] }
its(:email) { should eq bounce_data[:email] }
its(:bounced_at) { should == Time.parse(bounce_data[:bounced_at]) }
its(:id) { should eq bounce_data[:id] }
its(:subject) { should eq bounce_data[:subject] }

its(:type) { is_expected.to eq bounce_data[:type] }
its(:message_id) { is_expected.to eq bounce_data[:message_id] }
its(:details) { is_expected.to eq bounce_data[:details] }
its(:email) { is_expected.to eq bounce_data[:email] }
its(:bounced_at) { is_expected.to eq Time.parse(bounce_data[:bounced_at]) }
its(:id) { is_expected.to eq bounce_data[:id] }
its(:subject) { is_expected.to eq bounce_data[:subject] }
end

describe "#dump" do
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/postmark/handlers/mail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
describe '#deliver!' do
it "returns self by default" do
expect_any_instance_of(Postmark::ApiClient).to receive(:deliver_message).with(message)
message.deliver.should eq message
expect(message.deliver).to eq message
end

it "returns the actual response if :return_response setting is present" do
expect_any_instance_of(Postmark::ApiClient).to receive(:deliver_message).with(message)
message.delivery_method Mail::Postmark, :return_response => true
message.deliver.should eq message
expect(message.deliver).to eq message
end

it "allows setting the api token" do
message.delivery_method Mail::Postmark, :api_token => 'api-token'
message.delivery_method.settings[:api_token].should == 'api-token'
expect(message.delivery_method.settings[:api_token]).to eq 'api-token'
end

it 'uses provided API token' do
Expand Down
11 changes: 5 additions & 6 deletions spec/unit/postmark/helpers/hash_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
let(:target) { {"From" => "[email protected]", "ReplyTo" => "[email protected]"} }

it 'converts Hash keys to Postmark format' do
subject.to_postmark(source).should == target
expect(subject.to_postmark(source)).to eq target
end

it 'acts idempotentely' do
subject.to_postmark(target).should == target
expect(subject.to_postmark(target)).to eq target
end
end

Expand All @@ -19,16 +19,15 @@
let(:target) { {:from => "[email protected]", :reply_to => "[email protected]"} }

it 'converts Hash keys to Ruby format' do
subject.to_ruby(source).should == target
expect(subject.to_ruby(source)).to eq target
end

it 'has compatible mode' do
subject.to_ruby(source, true).should == target.merge(source)
expect(subject.to_ruby(source, true)).to eq target.merge(source)
end

it 'acts idempotentely' do
subject.to_ruby(target).should == target
expect(subject.to_ruby(target)).to eq target
end
end

end
49 changes: 26 additions & 23 deletions spec/unit/postmark/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def response_body(status, message = "")
end

context "when it is created without options" do
its(:api_token) { should eq api_token }
its(:api_key) { should eq api_token }
its(:host) { should eq 'api.postmarkapp.com' }
its(:port) { should eq 443 }
its(:secure) { should be true }
its(:path_prefix) { should eq '/' }
its(:http_read_timeout) { should eq 15 }
its(:http_open_timeout) { should eq 5 }
its(:api_token) { is_expected.to eq api_token }
its(:api_key) { is_expected.to eq api_token }
its(:host) { is_expected.to eq 'api.postmarkapp.com' }
its(:port) { is_expected.to eq 443 }
its(:secure) { is_expected.to be true }
its(:path_prefix) { is_expected.to eq '/' }
its(:http_read_timeout) { is_expected.to eq 15 }
its(:http_open_timeout) { is_expected.to eq 5 }

it 'uses TLS encryption', :skip_ruby_version => ['1.8.7'] do
http_client = subject.http
Expand Down Expand Up @@ -71,18 +71,18 @@ def response_body(status, message = "")
:http_open_timeout => http_open_timeout,
:http_read_timeout => http_read_timeout) }

its(:api_token) { should eq api_token }
its(:api_key) { should eq api_token }
its(:secure) { should == secure }
its(:proxy_host) { should == proxy_host }
its(:proxy_port) { should == proxy_port }
its(:proxy_user) { should == proxy_user }
its(:proxy_pass) { should == proxy_pass }
its(:host) { should == host }
its(:port) { should == port }
its(:path_prefix) { should == path_prefix }
its(:http_open_timeout) { should == http_open_timeout }
its(:http_read_timeout) { should == http_read_timeout }
its(:api_token) { is_expected.to eq api_token }
its(:api_key) { is_expected.to eq api_token }
its(:secure) { is_expected.to eq secure }
its(:proxy_host) { is_expected.to eq proxy_host }
its(:proxy_port) { is_expected.to eq proxy_port }
its(:proxy_user) { is_expected.to eq proxy_user }
its(:proxy_pass) { is_expected.to eq proxy_pass }
its(:host) { is_expected.to eq host }
its(:port) { is_expected.to eq port }
its(:path_prefix) { is_expected.to eq path_prefix }
its(:http_open_timeout) { is_expected.to eq http_open_timeout }
its(:http_read_timeout) { is_expected.to eq http_read_timeout }

it 'uses port 80 for plain HTTP connections' do
expect(Postmark::HttpClient.new(api_token, :secure => false).port).to eq(80)
Expand All @@ -106,7 +106,8 @@ def response_body(status, message = "")
it "sends a POST request to provided URI" do
FakeWeb.register_uri(:post, target_url, :body => response_body(200))
subject.post(target_path)
FakeWeb.should have_requested(:post, target_url)
expect(FakeWeb.last_request.method).to eq('POST')
expect(FakeWeb.last_request.path).to eq('/' + target_path)
end

it "raises a custom error when API token authorization fails" do
Expand Down Expand Up @@ -145,7 +146,8 @@ def response_body(status, message = "")
it "sends a GET request to provided URI" do
FakeWeb.register_uri(:get, target_url, :body => response_body(200))
subject.get(target_path)
expect(FakeWeb).to have_requested(:get, target_url)
expect(FakeWeb.last_request.method).to eq('GET')
expect(FakeWeb.last_request.path).to eq('/' + target_path)
end

it "raises a custom error when API token authorization fails" do
Expand Down Expand Up @@ -184,7 +186,8 @@ def response_body(status, message = "")
it "sends a PUT request to provided URI" do
FakeWeb.register_uri(:put, target_url, :body => response_body(200))
subject.put(target_path)
expect(FakeWeb).to have_requested(:put, target_url)
expect(FakeWeb.last_request.method).to eq('PUT')
expect(FakeWeb.last_request.path).to eq('/' + target_path)
end

it "raises a custom error when API token authorization fails" do
Expand Down
68 changes: 34 additions & 34 deletions spec/unit/postmark/inbound_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,81 @@
context "given a serialized inbound document" do
subject { Postmark::Inbound.to_ruby_hash(example_inbound) }

it { should have_key(:from) }
it { should have_key(:from_full) }
it { should have_key(:to) }
it { should have_key(:to_full) }
it { should have_key(:cc) }
it { should have_key(:cc_full) }
it { should have_key(:reply_to) }
it { should have_key(:subject) }
it { should have_key(:message_id) }
it { should have_key(:date) }
it { should have_key(:mailbox_hash) }
it { should have_key(:text_body) }
it { should have_key(:html_body) }
it { should have_key(:tag) }
it { should have_key(:headers) }
it { should have_key(:attachments) }
it { expect(subject).to have_key(:from) }
it { expect(subject).to have_key(:from_full) }
it { expect(subject).to have_key(:to) }
it { expect(subject).to have_key(:to_full) }
it { expect(subject).to have_key(:cc) }
it { expect(subject).to have_key(:cc_full) }
it { expect(subject).to have_key(:reply_to) }
it { expect(subject).to have_key(:subject) }
it { expect(subject).to have_key(:message_id) }
it { expect(subject).to have_key(:date) }
it { expect(subject).to have_key(:mailbox_hash) }
it { expect(subject).to have_key(:text_body) }
it { expect(subject).to have_key(:html_body) }
it { expect(subject).to have_key(:tag) }
it { expect(subject).to have_key(:headers) }
it { expect(subject).to have_key(:attachments) }

context "cc" do
it 'has 2 CCs' do
subject[:cc_full].count.should == 2
expect(subject[:cc_full].count).to eq 2
end

it 'stores CCs as an array of Ruby hashes' do
cc = subject[:cc_full].last
cc.should have_key(:email)
cc.should have_key(:name)
expect(cc).to have_key(:email)
expect(cc).to have_key(:name)
end
end

context "to" do
it 'has 1 recipients' do
subject[:to_full].count.should == 1
expect(subject[:to_full].count).to eq 1
end

it 'stores TOs as an array of Ruby hashes' do
cc = subject[:to_full].last
cc.should have_key(:email)
cc.should have_key(:name)
expect(cc).to have_key(:email)
expect(cc).to have_key(:name)
end
end

context "from" do
it 'is a hash' do
subject[:from_full].should be_a Hash
expect(subject[:from_full]).to be_a Hash
end

it 'should have all required fields' do
subject[:from_full].should have_key(:email)
subject[:from_full].should have_key(:name)
it 'has all required fields' do
expect(subject[:from_full]).to have_key(:email)
expect(subject[:from_full]).to have_key(:name)
end
end

context "headers" do
it 'has 8 headers' do
subject[:headers].count.should == 8
expect(subject[:headers].count).to eq 8
end

it 'stores headers as an array of Ruby hashes' do
header = subject[:headers].last
header.should have_key(:name)
header.should have_key(:value)
expect(header).to have_key(:name)
expect(header).to have_key(:value)
end
end

context "attachments" do
it 'has 2 attachments' do
subject[:attachments].count.should == 2
expect(subject[:attachments].count).to eq 2
end

it 'stores attachemnts as an array of Ruby hashes' do
attachment = subject[:attachments].last
attachment.should have_key(:name)
attachment.should have_key(:content)
attachment.should have_key(:content_type)
attachment.should have_key(:content_length)
expect(attachment).to have_key(:name)
expect(attachment).to have_key(:content)
expect(attachment).to have_key(:content_type)
expect(attachment).to have_key(:content_length)
end
end
end
Expand Down
Loading

0 comments on commit 6d1f200

Please sign in to comment.