howitzer 0.0.3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +32 -0
- data/GETTING_STARTED.md +529 -0
- data/Gemfile +4 -2
- data/LICENSE +2 -2
- data/README.md +57 -13
- data/Rakefile +9 -2
- data/bin/howitzer +79 -31
- data/generators/base_generator.rb +87 -0
- data/generators/config/config_generator.rb +16 -20
- data/generators/config/templates/default.yml +26 -7
- data/generators/cucumber/cucumber_generator.rb +20 -26
- data/generators/{tasks → cucumber}/templates/cucumber.rake +0 -0
- data/generators/{config → cucumber}/templates/cucumber.yml +0 -0
- data/generators/emails/emails_generator.rb +11 -18
- data/generators/emails/templates/example_email.rb +1 -0
- data/generators/pages/pages_generator.rb +16 -18
- data/generators/pages/templates/example_menu.rb +1 -0
- data/generators/pages/templates/example_page.rb +1 -1
- data/generators/root/root_generator.rb +18 -20
- data/generators/root/templates/.gitignore +2 -1
- data/generators/root/templates/Gemfile +3 -2
- data/generators/root/templates/Rakefile +10 -0
- data/generators/root/templates/boot.rb +3 -9
- data/generators/rspec/rspec_generator.rb +23 -0
- data/generators/rspec/templates/example_spec.rb +7 -0
- data/generators/rspec/templates/rspec.rake +34 -0
- data/generators/rspec/templates/spec_helper.rb +56 -0
- data/generators/tasks/tasks_generator.rb +11 -17
- data/generators/tasks/templates/common.rake +15 -0
- data/howitzer.gemspec +13 -2
- data/lib/howitzer.rb +1 -0
- data/lib/howitzer/helpers.rb +87 -2
- data/lib/howitzer/init.rb +0 -1
- data/lib/howitzer/patches/rawler_patched.rb +86 -0
- data/lib/howitzer/settings.rb +27 -0
- data/lib/howitzer/utils.rb +3 -12
- data/lib/howitzer/utils/capybara_patched.rb +3 -2
- data/lib/howitzer/utils/capybara_settings.rb +158 -24
- data/lib/howitzer/utils/data_generator/data_storage.rb +35 -1
- data/lib/howitzer/utils/data_generator/gen.rb +45 -3
- data/lib/howitzer/utils/email/email.rb +44 -5
- data/lib/howitzer/utils/email/mail_client.rb +28 -22
- data/lib/howitzer/utils/email/mailgun_helper.rb +30 -4
- data/lib/howitzer/utils/locator_store.rb +111 -19
- data/lib/howitzer/utils/log.rb +137 -0
- data/lib/howitzer/utils/page_validator.rb +86 -0
- data/lib/howitzer/vendor/firebug-1.12.1-fx.xpi +0 -0
- data/lib/howitzer/vendor/firepath-0.9.7-fx.xpi +0 -0
- data/lib/howitzer/version.rb +2 -2
- data/lib/howitzer/web_page.rb +159 -19
- data/spec/active_resource.rb +0 -0
- data/spec/config/custom.yml +1 -0
- data/spec/config/default.yml +28 -0
- data/spec/spec_helper.rb +46 -1
- data/spec/support/boot_helper.rb +15 -0
- data/spec/support/generator_helper.rb +13 -0
- data/spec/support/logger_helper.rb +12 -0
- data/spec/unit/bin/howitzer_spec.rb +175 -0
- data/spec/unit/generators/generators_spec.rb +175 -0
- data/spec/unit/lib/capybara_settings_spec.rb +170 -0
- data/spec/unit/lib/helpers_spec.rb +619 -0
- data/spec/unit/lib/init_spec.rb +14 -0
- data/spec/unit/lib/settings_spec.rb +17 -0
- data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +62 -0
- data/spec/unit/lib/utils/data_generator/gen_spec.rb +151 -0
- data/spec/unit/lib/utils/email/email_spec.rb +75 -0
- data/spec/unit/lib/utils/email/mail_client_spec.rb +115 -0
- data/spec/unit/lib/utils/email/mailgun_helper_spec.rb +95 -0
- data/spec/unit/lib/utils/locator_store_spec.rb +122 -0
- data/spec/unit/lib/utils/log_spec.rb +107 -0
- data/spec/unit/lib/utils/page_validator_spec.rb +142 -0
- data/spec/unit/lib/web_page_spec.rb +250 -0
- data/spec/unit/version_spec.rb +8 -0
- metadata +215 -15
- data/Gemfile.lock +0 -103
- data/History.md +0 -20
- data/lib/howitzer/utils/logger.rb +0 -108
- data/spec/howitzer/version_spec.rb +0 -8
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "#{lib_path}/howitzer/utils/data_generator/gen.rb"
|
3
|
+
require 'capybara/dsl'
|
4
|
+
|
5
|
+
describe "Helpers" do
|
6
|
+
before do
|
7
|
+
stub_const("Mailgun", double)
|
8
|
+
expect(settings).to receive(:mailgun_api_key){ 'some_api' }
|
9
|
+
end
|
10
|
+
it "should init Mailgun and include modules" do
|
11
|
+
expect(Mailgun).to receive(:init).with('some_api').once
|
12
|
+
require "#{lib_path}/howitzer/init.rb"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Settings" do
|
4
|
+
context "#settings" do
|
5
|
+
subject { settings }
|
6
|
+
context "when method called two times" do
|
7
|
+
let(:other_settings) { settings }
|
8
|
+
it { expect(subject).to equal(other_settings) }
|
9
|
+
it { expect(other_settings).to be_a_kind_of(SexySettings::Base) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
context "SexySettings configuration" do
|
13
|
+
subject { SexySettings.configuration }
|
14
|
+
it { expect(subject.path_to_custom_settings).to include('config/custom.yml') }
|
15
|
+
it { expect(subject.path_to_default_settings).to include('config/default.yml') }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "#{lib_path}/howitzer/utils/data_generator/data_storage"
|
3
|
+
|
4
|
+
describe "DataGenerator" do
|
5
|
+
describe "DataStorage" do
|
6
|
+
describe ".store" do
|
7
|
+
subject { DataGenerator::DataStorage.store(ns, 7, :halt) }
|
8
|
+
context "when namespace specified" do
|
9
|
+
let(:ns) { :user }
|
10
|
+
it "should return value" do
|
11
|
+
expect(subject).to eql(:halt)
|
12
|
+
end
|
13
|
+
it "should store namespace value" do
|
14
|
+
adata = DataGenerator::DataStorage.instance_variable_get(:@data)
|
15
|
+
expect(adata[:user]).to eql({7 => :halt})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
context "when namespace empty" do
|
19
|
+
let(:ns) { nil }
|
20
|
+
it { expect {subject}.to raise_error(RuntimeError, "Data storage namespace can not be empty") }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe ".extract" do
|
24
|
+
subject { DataGenerator::DataStorage.extract(ns, key) }
|
25
|
+
before { DataGenerator::DataStorage.instance_variable_set(:@data, {user: {7 => :exit}}) }
|
26
|
+
describe "when namespace specified" do
|
27
|
+
let(:ns) { :user }
|
28
|
+
context "and namespace key found" do
|
29
|
+
let(:key) { 7 }
|
30
|
+
it { expect(subject).to eql(:exit) }
|
31
|
+
end
|
32
|
+
context "and namespace key not found" do
|
33
|
+
let(:key) { 5 }
|
34
|
+
it { expect(subject).to be_nil }
|
35
|
+
end
|
36
|
+
context "but namespace key not specified" do
|
37
|
+
let(:key) { nil }
|
38
|
+
it { expect(subject).to eql({ 7 => :exit }) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context "when namespace not found" do
|
42
|
+
let(:ns) { :guest }
|
43
|
+
let(:key) { 11 }
|
44
|
+
it { expect(subject).to be_nil }
|
45
|
+
end
|
46
|
+
context "when namespace not specified" do
|
47
|
+
let(:ns) { nil }
|
48
|
+
let(:key) { nil }
|
49
|
+
it { expect {subject}.to raise_error(RuntimeError, "Data storage namespace can not be empty") }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
describe ".clear_ns" do
|
53
|
+
subject { DataGenerator::DataStorage.clear_ns(:user) }
|
54
|
+
before { DataGenerator::DataStorage.instance_variable_set(:@data, {user: {7 => :exit}}) }
|
55
|
+
it "should return empty hash" do
|
56
|
+
subject
|
57
|
+
adata = DataGenerator::DataStorage.instance_variable_get(:@data)
|
58
|
+
expect(adata[:user]).to eql({})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "#{lib_path}/howitzer/utils/data_generator/gen"
|
3
|
+
|
4
|
+
describe "DataGenerator" do
|
5
|
+
describe "Gen" do
|
6
|
+
describe ".user" do
|
7
|
+
subject { DataGenerator::Gen.user(params) }
|
8
|
+
before do
|
9
|
+
allow(settings).to receive(:def_test_pass) { 'test_pass' }
|
10
|
+
allow(settings).to receive(:mail_pop3_domain) { 'mail.com' }
|
11
|
+
allow(DataGenerator::Gen).to receive(:serial) { '012345678abcde' }
|
12
|
+
end
|
13
|
+
context "when params specified" do
|
14
|
+
let(:params) { { login: 'alex', password: 'pa$$w0rd', mailbox: 'member@test.com' } }
|
15
|
+
it { expect(subject).to be_an_instance_of DataGenerator::Gen::User }
|
16
|
+
it { expect(subject.email).to eql 'u012345678abcde@mail.com' }
|
17
|
+
it do
|
18
|
+
email_nm = subject.instance_variable_get(:@email_name)
|
19
|
+
expect(email_nm).to eql 'u012345678abcde'
|
20
|
+
end
|
21
|
+
it { expect(subject.domain).to eql 'mail.com' }
|
22
|
+
it { expect(subject.login).to eql 'alex' }
|
23
|
+
it { expect(subject.password).to eql 'pa$$w0rd' }
|
24
|
+
it { expect(subject.first_name).to eql 'FirstName012345678abcde' }
|
25
|
+
it { expect(subject.last_name).to eql 'LastName012345678abcde' }
|
26
|
+
it { expect(subject.mailbox).to eql 'member@test.com' }
|
27
|
+
end
|
28
|
+
context "with empty params" do
|
29
|
+
let(:params) { {} }
|
30
|
+
it { expect(subject).to be_an_instance_of DataGenerator::Gen::User }
|
31
|
+
it { expect(subject.email).to eql 'u012345678abcde@mail.com' }
|
32
|
+
it do
|
33
|
+
email_nm = subject.instance_variable_get(:@email_name)
|
34
|
+
expect(email_nm).to eql 'u012345678abcde'
|
35
|
+
end
|
36
|
+
it { expect(subject.domain).to eql 'mail.com' }
|
37
|
+
it { expect(subject.login).to eql 'u012345678abcde' }
|
38
|
+
it { expect(subject.password).to eql 'test_pass' }
|
39
|
+
it { expect(subject.first_name).to eql 'FirstName012345678abcde' }
|
40
|
+
it { expect(subject.last_name).to eql 'LastName012345678abcde' }
|
41
|
+
it { expect(subject.mailbox).to be_nil }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
describe ".given_user_by_number" do
|
45
|
+
subject { DataGenerator::Gen.given_user_by_number(7) }
|
46
|
+
before { stub_const("DataGenerator::DataStorage", double) }
|
47
|
+
context "when namespace key found" do
|
48
|
+
before { expect(DataGenerator::DataStorage).to receive(:extract).with('user', 7) { :namespace_value } }
|
49
|
+
it { expect(subject).to eql(:namespace_value) }
|
50
|
+
end
|
51
|
+
context "when namespace key not found" do
|
52
|
+
let(:dat) { :data_store }
|
53
|
+
before do
|
54
|
+
allow(DataGenerator::Gen).to receive(:user) { dat }
|
55
|
+
expect(DataGenerator::DataStorage).to receive(:extract).with('user', 7) { nil }
|
56
|
+
allow(DataGenerator::DataStorage).to receive(:store).with('user', 7, dat)
|
57
|
+
end
|
58
|
+
it { expect(subject).to eql :data_store }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
describe ".serial" do
|
62
|
+
subject { DataGenerator::Gen.serial }
|
63
|
+
let(:ser) { 1 }
|
64
|
+
context "received value should conform to template" do
|
65
|
+
let(:ser) { subject }
|
66
|
+
it { expect(ser).to match /\d{9}\w{5}/ }
|
67
|
+
end
|
68
|
+
context "received values should be different" do
|
69
|
+
it { expect(subject).to_not eql ser }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
describe ".delete_all_mailboxes" do
|
73
|
+
subject { DataGenerator::Gen.delete_all_mailboxes }
|
74
|
+
let(:mbox1) { double }
|
75
|
+
let(:mbox2) { double }
|
76
|
+
before do
|
77
|
+
stub_const("DataGenerator::DataStorage", double)
|
78
|
+
expect(DataGenerator::DataStorage).to receive(:extract).with('user') { { 1 => mbox1, 2 => mbox2 } }
|
79
|
+
end
|
80
|
+
it do
|
81
|
+
expect(mbox1).to receive(:delete_mailbox).once
|
82
|
+
expect(mbox2).to receive(:delete_mailbox).once
|
83
|
+
subject
|
84
|
+
end
|
85
|
+
end
|
86
|
+
describe "User" do
|
87
|
+
describe "#initialize" do
|
88
|
+
subject { DataGenerator::Gen::User.new(params) }
|
89
|
+
let(:params) { { email: 'alex.petrenko@mail.com', login: 'alex', password: 'pa$$w0rd',
|
90
|
+
first_name: 'Alexey', last_name: 'Petrenko', mailbox: 'member@test.com' } }
|
91
|
+
it { expect(subject).to be_an_instance_of DataGenerator::Gen::User }
|
92
|
+
it { expect(subject.email).to eql 'alex.petrenko@mail.com' }
|
93
|
+
it do
|
94
|
+
email_nm = subject.instance_variable_get(:@email_name)
|
95
|
+
expect(email_nm).to eql 'alex.petrenko'
|
96
|
+
end
|
97
|
+
it { expect(subject.domain).to eql 'mail.com' }
|
98
|
+
it { expect(subject.login).to eql 'alex' }
|
99
|
+
it { expect(subject.password).to eql 'pa$$w0rd' }
|
100
|
+
it { expect(subject.first_name).to eql 'Alexey' }
|
101
|
+
it { expect(subject.last_name).to eql 'Petrenko' }
|
102
|
+
it { expect(subject.full_name).to eql 'Alexey Petrenko' }
|
103
|
+
it { expect(subject.mailbox).to eql 'member@test.com' }
|
104
|
+
end
|
105
|
+
describe "#create_mailbox" do
|
106
|
+
subject { nu_user.create_mailbox }
|
107
|
+
let(:nu_user) { DataGenerator::Gen::User.new({ email: 'alex.petrenko@mail.com', mailbox: 'member@test.com' }) }
|
108
|
+
before { stub_const('MailClient', double) }
|
109
|
+
context "should return User object" do
|
110
|
+
before do
|
111
|
+
allow(settings).to receive(:mail_pop3_domain) { 'mail.com' }
|
112
|
+
expect(MailClient).to receive(:create_mailbox).with('alex.petrenko').once { 'petrenko@test.com' }
|
113
|
+
end
|
114
|
+
it { expect(subject).to be_an_instance_of DataGenerator::Gen::User }
|
115
|
+
end
|
116
|
+
context "when mail_pop3_domain settings are equal to @domain" do
|
117
|
+
before do
|
118
|
+
allow(settings).to receive(:mail_pop3_domain) { 'mail.com' }
|
119
|
+
expect(MailClient).to receive(:create_mailbox).with('alex.petrenko').once { 'petrenko@test.com' }
|
120
|
+
end
|
121
|
+
it do
|
122
|
+
subject
|
123
|
+
expect(nu_user.mailbox).to eql 'petrenko@test.com'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
context "when mail_pop3_domain settings are not equal to @domain" do
|
127
|
+
before { allow(settings).to receive(:mail_pop3_domain) { 'post.com' } }
|
128
|
+
it do
|
129
|
+
subject
|
130
|
+
expect(nu_user.mailbox).to eql 'member@test.com'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
describe "#delete_mailbox" do
|
135
|
+
subject { nu_user.delete_mailbox }
|
136
|
+
let(:nu_user) { DataGenerator::Gen::User.new({ mailbox: mbox }) }
|
137
|
+
before { stub_const('MailClient', double) }
|
138
|
+
context "when mailbox spcified" do
|
139
|
+
before { expect(MailClient).to receive(:delete_mailbox).with(mbox).once { 'mailbox deleted' } }
|
140
|
+
let(:mbox) { 'member@test.com' }
|
141
|
+
it { expect(subject).to eql 'mailbox deleted' }
|
142
|
+
end
|
143
|
+
context "when mailbox not spcified" do
|
144
|
+
before { expect(MailClient).to_not receive(:delete_mailbox).with(mbox) }
|
145
|
+
let(:mbox) { nil }
|
146
|
+
it { expect(subject).to be_nil }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "#{lib_path}/howitzer/utils/log"
|
3
|
+
require "#{lib_path}/howitzer/utils/email/email"
|
4
|
+
|
5
|
+
|
6
|
+
describe Email do
|
7
|
+
let(:message) { double }
|
8
|
+
let(:message_subject) { 'test_subject' }
|
9
|
+
let(:mail_address) { double }
|
10
|
+
let(:recipient) { 'vasya@test.com' }
|
11
|
+
let(:email_object) { Email.new(message) }
|
12
|
+
before do
|
13
|
+
stub_const("Email::SUBJECT", 'test_subject')
|
14
|
+
stub_const("::Mail::Address", mail_address)
|
15
|
+
allow(mail_address).to receive(:new).with(recipient).and_return(mail_address)
|
16
|
+
allow(message).to receive(:to).and_return([recipient])
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#new" do
|
20
|
+
subject { Email.new(message) }
|
21
|
+
before { allow(message).to receive(:subject).and_return('test_subject') }
|
22
|
+
context "when subject is the same" do
|
23
|
+
it { expect(subject.instance_variable_get(:@recipient_address)).to eql(mail_address) }
|
24
|
+
it { expect(subject.instance_variable_get(:@message)).to eql(message) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".find_by_recipient" do
|
29
|
+
subject { Email.find_by_recipient(recipient) }
|
30
|
+
context "when 'recipient' specified " do
|
31
|
+
before { expect(Email).to receive(:find).with(recipient, 'test_subject').and_return(true).once }
|
32
|
+
it { expect(subject).to be_true }
|
33
|
+
end
|
34
|
+
context "when 'recipient' not specified " do
|
35
|
+
let(:recipient) { nil }
|
36
|
+
before { expect(Email).to receive(:find).with(recipient,'test_subject').and_return(nil).once }
|
37
|
+
it { expect(subject).to be_nil }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".find" do
|
42
|
+
let(:mail_client) { double }
|
43
|
+
subject { Email.find('Vasya', 'Text') }
|
44
|
+
before do
|
45
|
+
stub_const("MailClient", double)
|
46
|
+
allow(MailClient).to receive(:by_email).and_return(mail_client)
|
47
|
+
allow(mail_client).to receive(:find_mail).and_return(messages )
|
48
|
+
allow(message).to receive(:subject).and_return('test_subject')
|
49
|
+
end
|
50
|
+
context "when messages.first present" do
|
51
|
+
let(:messages) { [message] }
|
52
|
+
it {expect(subject).to be_kind_of(Email) }
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when messages.first not present" do
|
56
|
+
let(:messages) {[]}
|
57
|
+
it do
|
58
|
+
expect(log).to receive(:error).with("Email was not found (recipient: 'Vasya')").once
|
59
|
+
subject
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#plain_text_body" do
|
65
|
+
subject { email_object.plain_text_body }
|
66
|
+
let(:email_object) { Email.new(message) }
|
67
|
+
let(:mime_part) { double }
|
68
|
+
before do
|
69
|
+
allow(message).to receive(:subject).and_return('test_subject')
|
70
|
+
expect(mime_part).to receive(:to_s).and_return('test_string')
|
71
|
+
expect(email_object).to receive(:get_mime_part).with(message, 'text/plain').and_return(mime_part)
|
72
|
+
end
|
73
|
+
it { expect(subject).to eql('test_string') }
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "#{lib_path}/howitzer/utils/log"
|
3
|
+
require "#{lib_path}/howitzer/utils/email/mail_client"
|
4
|
+
|
5
|
+
describe MailClient do
|
6
|
+
|
7
|
+
describe ".default" do
|
8
|
+
subject { MailClient.default }
|
9
|
+
it do
|
10
|
+
expect(log).to receive(:info).with("Connect to default mailbox").once
|
11
|
+
expect(subject).to be_instance_of(MailClient)
|
12
|
+
options = {
|
13
|
+
smtp: {
|
14
|
+
address: "smtp.demo.com",
|
15
|
+
port: 25,
|
16
|
+
domain: "demo.com",
|
17
|
+
user_name: "test_user",
|
18
|
+
password: "mypass",
|
19
|
+
authentication: "plain",
|
20
|
+
enable_starttls_auto: true
|
21
|
+
},
|
22
|
+
pop3: {
|
23
|
+
address: "pop.demo.com",
|
24
|
+
port: 995,
|
25
|
+
user_name: "test_user",
|
26
|
+
password: "mypass"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
expect(subject.instance_variable_get(:@options)).to eql(options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".by_email" do
|
34
|
+
subject { MailClient.by_email("vasya@gmail.com") }
|
35
|
+
it do
|
36
|
+
expect(log).to receive(:info).with("Connect to 'vasya@gmail.com' mailbox").once
|
37
|
+
expect(subject).to be_instance_of(MailClient)
|
38
|
+
options = {
|
39
|
+
smtp: {
|
40
|
+
address: "smtp.demo.com",
|
41
|
+
port: 25,
|
42
|
+
domain: "demo.com",
|
43
|
+
user_name: "test_user",
|
44
|
+
password: "mypass",
|
45
|
+
authentication: "plain",
|
46
|
+
enable_starttls_auto: true
|
47
|
+
},
|
48
|
+
pop3: {
|
49
|
+
address: "pop.demo.com",
|
50
|
+
port: 995,
|
51
|
+
user_name: "vasya@gmail.com",
|
52
|
+
password: "mypass"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
expect(subject.instance_variable_get(:@options)).to eql(options)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".merge_opts" do
|
60
|
+
subject { MailClient.merge_opts(*options) }
|
61
|
+
context "when default options" do
|
62
|
+
let(:expected_option) do
|
63
|
+
{
|
64
|
+
smtp: {
|
65
|
+
address: "smtp.demo.com",
|
66
|
+
port: 25,
|
67
|
+
domain: "demo.com",
|
68
|
+
user_name: "test_user",
|
69
|
+
password: "mypass",
|
70
|
+
authentication: "plain",
|
71
|
+
enable_starttls_auto: true
|
72
|
+
},
|
73
|
+
pop3: {
|
74
|
+
address: "pop.demo.com",
|
75
|
+
port: 995,
|
76
|
+
user_name: "test_user",
|
77
|
+
password: "mypass"
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
let(:options) { [] }
|
82
|
+
it { expect(subject).to eql(expected_option) }
|
83
|
+
end
|
84
|
+
context "when custom options" do
|
85
|
+
let(:options) do
|
86
|
+
[{
|
87
|
+
smtp: {
|
88
|
+
address: 'fake_address',
|
89
|
+
port: 1123,
|
90
|
+
domain: 'fake_domain',
|
91
|
+
user_name: "fake_user_name",
|
92
|
+
password: "fake_password",
|
93
|
+
authentication: "plain",
|
94
|
+
enable_starttls_auto: true
|
95
|
+
},
|
96
|
+
pop3: {
|
97
|
+
address: "fake_address",
|
98
|
+
port: 999,
|
99
|
+
user_name: "fake_user_name",
|
100
|
+
password: "fake_password"
|
101
|
+
}
|
102
|
+
}]
|
103
|
+
end
|
104
|
+
it { expect(subject).to eql(options.first)}
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#find_mail"
|
108
|
+
describe "#send_mail"
|
109
|
+
describe "#empty_inbox"
|
110
|
+
describe "#start"
|
111
|
+
describe "constructor"
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "#{lib_path}/howitzer/utils/log"
|
3
|
+
require "#{lib_path}/howitzer/utils/email/mailgun_helper"
|
4
|
+
|
5
|
+
describe MailgunHelper do
|
6
|
+
let(:mailgun) { double.extend MailgunHelper }
|
7
|
+
let(:user_name) { 'vasyapupkin' }
|
8
|
+
let(:settings_obj) { double }
|
9
|
+
let(:mbox) { double }
|
10
|
+
before do
|
11
|
+
stub_const('Mailbox', double)
|
12
|
+
end
|
13
|
+
describe "#create_mailbox" do
|
14
|
+
subject { mailgun.create_mailbox(user_name, *opts) }
|
15
|
+
before do
|
16
|
+
expect(log).to receive(:info).with(log_message).once
|
17
|
+
allow(Mailbox).to receive(:new).and_return(mbox)
|
18
|
+
expect(mbox).to receive(:upsert).once
|
19
|
+
end
|
20
|
+
context "when domain and password are present" do
|
21
|
+
let(:log_message) { "Create 'vasyapupkin@mail.ru' mailbox" }
|
22
|
+
let(:opts) { ['mail.ru', '123'] }
|
23
|
+
it { expect(subject).to eql(mbox) }
|
24
|
+
end
|
25
|
+
context "when domain and password are missed" do
|
26
|
+
let(:opts) { [] }
|
27
|
+
let(:log_message) { "Create 'vasyapupkin@test.com' mailbox" }
|
28
|
+
before do
|
29
|
+
allow(mailgun).to receive(:settings).and_return(settings_obj)
|
30
|
+
allow(settings_obj).to receive(:mail_pop3_domain).and_return('test.com')
|
31
|
+
allow(settings_obj).to receive(:mail_pop3_user_pass).and_return('test123')
|
32
|
+
end
|
33
|
+
it { expect(subject).to eql(mbox) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#delete_mailbox" do
|
38
|
+
subject{ mailgun.delete_mailbox(mbox)}
|
39
|
+
before do
|
40
|
+
allow(mbox).to receive(:user).and_return('vasyapupkin')
|
41
|
+
allow(mbox).to receive(:domain).and_return('mail.ru')
|
42
|
+
expect(log).to receive(:info).with("Delete 'vasyapupkin@mail.ru' mailbox").once
|
43
|
+
end
|
44
|
+
context "when successful result" do
|
45
|
+
before {expect(Mailbox).to receive(:remove).with(mbox).and_return(true)}
|
46
|
+
it { expect(subject).to be_true }
|
47
|
+
end
|
48
|
+
context "when impossible to remove mailbox" do
|
49
|
+
before {expect(Mailbox).to receive(:remove).with(mbox).and_raise('Test error message')}
|
50
|
+
it do
|
51
|
+
expect(log).to receive(:warn).with("Unable to delete 'vasyapupkin' mailbox: Test error message")
|
52
|
+
subject
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#delete_all_mailboxes" do
|
58
|
+
let(:domain) { 'mail.ru' }
|
59
|
+
let(:mailbox1) do
|
60
|
+
m = double
|
61
|
+
allow(m).to receive(:id).and_return(1)
|
62
|
+
allow(m).to receive(:user).and_return('vasyapupkin')
|
63
|
+
allow(m).to receive(:domain).and_return(domain)
|
64
|
+
m
|
65
|
+
end
|
66
|
+
let(:mailbox2) do
|
67
|
+
m = double
|
68
|
+
allow(m).to receive(:id).and_return(2)
|
69
|
+
allow(m).to receive(:user).and_return('postmaster')
|
70
|
+
allow(m).to receive(:domain).and_return(domain)
|
71
|
+
m
|
72
|
+
end
|
73
|
+
let(:mailbox3) do
|
74
|
+
m = double
|
75
|
+
allow(m).to receive(:id).and_return(3)
|
76
|
+
allow(m).to receive(:user).and_return('admin')
|
77
|
+
allow(m).to receive(:domain).and_return(domain)
|
78
|
+
m
|
79
|
+
end
|
80
|
+
let(:mail_for_exception){ 'admin@mail.ru' }
|
81
|
+
subject{mailgun.delete_all_mailboxes(mail_for_exception)}
|
82
|
+
before do
|
83
|
+
allow(settings).to receive(:mail_smtp_domain).and_return("mail.ru")
|
84
|
+
allow(Mailbox).to receive(:find).with(:all).and_return([mailbox1, mailbox2, mailbox3])
|
85
|
+
end
|
86
|
+
it do
|
87
|
+
expect(log).to receive(:info).with("Delete all mailboxes except: \"admin@mail.ru\", \"postmaster@mail.ru\"")
|
88
|
+
expect(Mailbox).to receive(:delete).with(1).once
|
89
|
+
expect(Mailbox).to_not receive(:delete).with(2)
|
90
|
+
expect(Mailbox).to_not receive(:delete).with(3)
|
91
|
+
expect(log).to receive(:info).with("Were deleted '1' mailboxes")
|
92
|
+
subject
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|