howitzer 2.0.3 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +69 -11
- data/LICENSE +1 -1
- data/README.md +21 -17
- data/bin/howitzer +7 -6
- data/generators/base_generator.rb +31 -17
- data/generators/config/config_generator.rb +11 -3
- data/generators/config/templates/boot.rb +3 -3
- data/generators/config/templates/capybara.rb +6 -131
- data/generators/config/templates/default.yml +34 -13
- data/generators/config/templates/drivers/appium.rb +25 -0
- data/generators/config/templates/drivers/browserstack.rb +23 -0
- data/generators/config/templates/drivers/crossbrowsertesting.rb +29 -0
- data/generators/config/templates/drivers/headless_chrome.rb +15 -0
- data/generators/config/templates/drivers/headless_firefox.rb +23 -0
- data/generators/config/templates/drivers/sauce.rb +25 -0
- data/generators/config/templates/drivers/selenium.rb +24 -0
- data/generators/config/templates/drivers/selenium_grid.rb +31 -0
- data/generators/config/templates/drivers/testingbot.rb +24 -0
- data/generators/cucumber/cucumber_generator.rb +2 -2
- data/generators/cucumber/templates/common_steps.rb +3 -3
- data/generators/cucumber/templates/cucumber.rake +5 -13
- data/generators/cucumber/templates/cuke_sniffer.rake +2 -2
- data/generators/cucumber/templates/env.rb +9 -1
- data/generators/cucumber/templates/hooks.rb +8 -2
- data/generators/cucumber/templates/transformers.rb +11 -25
- data/generators/emails/emails_generator.rb +2 -2
- data/generators/emails/templates/example_email.rb +1 -1
- data/generators/prerequisites/prerequisites_generator.rb +3 -3
- data/generators/prerequisites/templates/base.rb +1 -1
- data/generators/prerequisites/templates/{factory_girl.rb → factory_bot.rb} +7 -6
- data/generators/prerequisites/templates/users.rb +1 -1
- data/generators/root/root_generator.rb +3 -3
- data/generators/root/templates/Gemfile.erb +16 -22
- data/generators/rspec/rspec_generator.rb +2 -2
- data/generators/rspec/templates/rspec.rake +8 -8
- data/generators/rspec/templates/spec_helper.rb +6 -5
- data/generators/tasks/tasks_generator.rb +2 -2
- data/generators/turnip/templates/spec_helper.rb +6 -5
- data/generators/turnip/turnip_generator.rb +2 -2
- data/generators/web/templates/example_page.rb +1 -1
- data/generators/web/web_generator.rb +2 -2
- data/lib/howitzer/cache.rb +20 -19
- data/lib/howitzer/capybara_helpers.rb +58 -13
- data/lib/howitzer/email.rb +3 -2
- data/lib/howitzer/exceptions.rb +21 -20
- data/lib/howitzer/gmail_api/client.rb +31 -0
- data/lib/howitzer/gmail_api.rb +7 -0
- data/lib/howitzer/log.rb +6 -6
- data/lib/howitzer/mail_adapters/gmail.rb +96 -0
- data/lib/howitzer/mail_adapters/mailgun.rb +4 -2
- data/lib/howitzer/mail_adapters/mailtrap.rb +108 -0
- data/lib/howitzer/mailgun_api/client.rb +3 -2
- data/lib/howitzer/mailgun_api/connector.rb +1 -0
- data/lib/howitzer/mailgun_api/response.rb +1 -2
- data/lib/howitzer/mailtrap_api/client.rb +52 -0
- data/lib/howitzer/mailtrap_api.rb +7 -0
- data/lib/howitzer/meta/actions.rb +35 -0
- data/lib/howitzer/meta/element.rb +40 -0
- data/lib/howitzer/meta/entry.rb +62 -0
- data/lib/howitzer/meta/iframe.rb +41 -0
- data/lib/howitzer/meta/section.rb +30 -0
- data/lib/howitzer/meta.rb +11 -0
- data/lib/howitzer/utils/string_extensions.rb +6 -2
- data/lib/howitzer/version.rb +1 -1
- data/lib/howitzer/web/base_section.rb +1 -1
- data/lib/howitzer/web/capybara_context_holder.rb +1 -0
- data/lib/howitzer/web/capybara_methods_proxy.rb +15 -6
- data/lib/howitzer/web/element_dsl.rb +104 -44
- data/lib/howitzer/web/iframe_dsl.rb +23 -3
- data/lib/howitzer/web/page.rb +16 -4
- data/lib/howitzer/web/page_dsl.rb +19 -7
- data/lib/howitzer/web/page_validator.rb +27 -26
- data/lib/howitzer/web/section.rb +13 -2
- data/lib/howitzer/web/section_dsl.rb +65 -30
- data/lib/howitzer.rb +66 -10
- metadata +67 -133
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.rubocop.yml +0 -44
- data/.ruby-gemset +0 -1
- data/.travis.yml +0 -7
- data/Gemfile +0 -13
- data/MAINTENANCE.md +0 -32
- data/Rakefile +0 -22
- data/features/cli_help.feature +0 -31
- data/features/cli_new.feature +0 -349
- data/features/cli_unknown.feature +0 -17
- data/features/cli_update.feature +0 -178
- data/features/cli_version.feature +0 -14
- data/features/step_definitions/common_steps.rb +0 -29
- data/features/support/env.rb +0 -1
- data/features/support/transformers.rb +0 -3
- data/generators/root/templates/.gitignore +0 -21
- data/generators/root/templates/.rubocop.yml +0 -35
- data/generators/turnip/templates/.rspec +0 -1
- data/howitzer.gemspec +0 -37
- data/lib/howitzer/mail_adapters/debugmail.rb +0 -0
- data/spec/config/custom.yml +0 -9
- data/spec/spec_helper.rb +0 -72
- data/spec/support/generator_helper.rb +0 -21
- data/spec/support/logger_helper.rb +0 -13
- data/spec/support/mailgun_unit_client.rb +0 -68
- data/spec/support/shared_examples/capybara_context_holder.rb +0 -33
- data/spec/support/shared_examples/capybara_methods_proxy.rb +0 -94
- data/spec/support/shared_examples/dynamic_section_methods.rb +0 -35
- data/spec/support/shared_examples/element_dsl.rb +0 -242
- data/spec/unit/generators/base_generator_spec.rb +0 -272
- data/spec/unit/generators/config_generator_spec.rb +0 -38
- data/spec/unit/generators/cucumber_generator_spec.rb +0 -62
- data/spec/unit/generators/emails_generator_spec.rb +0 -35
- data/spec/unit/generators/prerequisites_generator_spec.rb +0 -53
- data/spec/unit/generators/root_generator_spec.rb +0 -72
- data/spec/unit/generators/rspec_generator_spec.rb +0 -36
- data/spec/unit/generators/tasks_generator_spec.rb +0 -31
- data/spec/unit/generators/turnip_generator_spec.rb +0 -52
- data/spec/unit/generators/web_generator_spec.rb +0 -52
- data/spec/unit/lib/cache_spec.rb +0 -85
- data/spec/unit/lib/capybara_helpers_spec.rb +0 -696
- data/spec/unit/lib/email_spec.rb +0 -186
- data/spec/unit/lib/howitzer_spec.rb +0 -40
- data/spec/unit/lib/init_spec.rb +0 -2
- data/spec/unit/lib/log_spec.rb +0 -122
- data/spec/unit/lib/mail_adapters/abstract_spec.rb +0 -62
- data/spec/unit/lib/mail_adapters/mailgun_spec.rb +0 -163
- data/spec/unit/lib/mailgun_api/client_spec.rb +0 -58
- data/spec/unit/lib/mailgun_api/connector_spec.rb +0 -54
- data/spec/unit/lib/mailgun_api/response_spec.rb +0 -28
- data/spec/unit/lib/utils/string_extensions_spec.rb +0 -77
- data/spec/unit/lib/web/base_section_spec.rb +0 -43
- data/spec/unit/lib/web/element_dsl_spec.rb +0 -22
- data/spec/unit/lib/web/iframe_dsl_spec.rb +0 -144
- data/spec/unit/lib/web/page_dsl_spec.rb +0 -74
- data/spec/unit/lib/web/page_spec.rb +0 -349
- data/spec/unit/lib/web/page_validator_spec.rb +0 -276
- data/spec/unit/lib/web/section_dsl_spec.rb +0 -165
- data/spec/unit/lib/web/section_spec.rb +0 -63
- data/spec/unit/version_spec.rb +0 -8
data/spec/unit/lib/email_spec.rb
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'howitzer/email'
|
3
|
-
require 'howitzer/log'
|
4
|
-
require 'howitzer/exceptions'
|
5
|
-
|
6
|
-
RSpec.describe Howitzer::Email do
|
7
|
-
let(:recipient) { 'first_tester@gmail.com' }
|
8
|
-
let(:message_subject) { 'test subject' }
|
9
|
-
let(:message) { double(:message) }
|
10
|
-
let(:email_object) { described_class.new(message) }
|
11
|
-
|
12
|
-
describe '.adapter' do
|
13
|
-
it do
|
14
|
-
expect(described_class.adapter)
|
15
|
-
.to eql(Howitzer::MailAdapters.const_get(Howitzer.mail_adapter.to_s.capitalize))
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '.adapter_name' do
|
20
|
-
it { expect(described_class.adapter_name).to eql Howitzer.mail_adapter.to_sym }
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '.adapter=' do
|
24
|
-
subject { described_class.adapter = name }
|
25
|
-
|
26
|
-
context 'when adapter_name is Symbol or String' do
|
27
|
-
let(:name) { Howitzer.mail_adapter }
|
28
|
-
it { expect(described_class.adapter).to eql Howitzer::MailAdapters.const_get(name.to_s.capitalize) }
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when adapter_name is not Symbol or String' do
|
32
|
-
let(:name) { nil }
|
33
|
-
it { expect { subject }.to raise_error(Howitzer::NoMailAdapterError) }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '.subject' do
|
38
|
-
it do
|
39
|
-
described_class.send(:subject, message_subject)
|
40
|
-
expect(described_class.send(:subject_value)).to eql message_subject
|
41
|
-
expect(described_class.private_methods(true)).to include(:subject_value)
|
42
|
-
end
|
43
|
-
it 'should be protected' do
|
44
|
-
expect { described_class.subject(message_subject) }.to raise_error(NoMethodError)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '.wait_time' do
|
49
|
-
subject { Class.new(described_class) }
|
50
|
-
it 'should be protected' do
|
51
|
-
expect { subject.wait_time(10) }.to raise_error(NoMethodError)
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when specified' do
|
55
|
-
before { subject.send(:wait_time, 10) }
|
56
|
-
it do
|
57
|
-
expect(subject.send(:wait_time_value)).to eql 10
|
58
|
-
expect(subject.private_methods(true)).to include(:wait_time_value)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'when missing' do
|
63
|
-
it do
|
64
|
-
expect(subject.send(:wait_time_value)).to eql 60
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '.find_by_recipient' do
|
70
|
-
let(:recipient) { 'test@user.com' }
|
71
|
-
|
72
|
-
context 'simple subject without parameters' do
|
73
|
-
before { described_class.class_eval { subject 'Some title' } }
|
74
|
-
it do
|
75
|
-
expect(described_class.adapter).to receive(:find).with(recipient, 'Some title', wait: 60).once
|
76
|
-
described_class.find_by_recipient(recipient)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'complex subject with 1 parameter' do
|
81
|
-
subject { described_class.find_by_recipient(recipient, name: 'Vasya') }
|
82
|
-
before { described_class.class_eval { subject 'Some title from :name' } }
|
83
|
-
it do
|
84
|
-
expect(described_class.adapter).to receive(:find).with(recipient, 'Some title from Vasya', wait: 60).once
|
85
|
-
subject
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'complex subject with 2 parameters' do
|
90
|
-
subject { described_class.find_by_recipient(recipient, foo: 1, bar: 2) }
|
91
|
-
before { described_class.class_eval { subject 'Some title with :foo and :bar' } }
|
92
|
-
it do
|
93
|
-
expect(described_class.adapter).to receive(:find).with(recipient, 'Some title with 1 and 2', wait: 60).once
|
94
|
-
subject
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'missing subject' do
|
99
|
-
subject { described_class.find_by_recipient(recipient) }
|
100
|
-
before do
|
101
|
-
described_class.instance_eval { undef :subject_value }
|
102
|
-
end
|
103
|
-
it do
|
104
|
-
expect { subject }.to raise_error(Howitzer::NoEmailSubjectError)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'nil subject' do
|
109
|
-
subject { described_class.find_by_recipient(recipient) }
|
110
|
-
before { described_class.class_eval { subject nil } }
|
111
|
-
it do
|
112
|
-
expect { subject }.to raise_error(Howitzer::NoEmailSubjectError)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe '#new' do
|
118
|
-
context 'when Email instance receive message and add create @message variable that' do
|
119
|
-
it { expect(email_object.instance_variable_get(:@message)).to eql message }
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe '#plain_text_body' do
|
124
|
-
subject { email_object.plain_text_body }
|
125
|
-
it do
|
126
|
-
expect(message).to receive(:plain_text_body).once
|
127
|
-
subject
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe '#html_body' do
|
132
|
-
subject { email_object.html_body }
|
133
|
-
it do
|
134
|
-
expect(message).to receive(:html_body).once
|
135
|
-
subject
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe '#text' do
|
140
|
-
subject { email_object.text }
|
141
|
-
it do
|
142
|
-
expect(message).to receive(:text).once
|
143
|
-
subject
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe '#mail_from' do
|
148
|
-
subject { email_object.mail_from }
|
149
|
-
it do
|
150
|
-
expect(message).to receive(:mail_from).once
|
151
|
-
subject
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe '#recipients' do
|
156
|
-
subject { email_object.recipients }
|
157
|
-
it do
|
158
|
-
expect(message).to receive(:recipients).once
|
159
|
-
subject
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe '#received_time' do
|
164
|
-
subject { email_object.received_time }
|
165
|
-
it do
|
166
|
-
expect(message).to receive(:received_time).once
|
167
|
-
subject
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe '#sender_email' do
|
172
|
-
subject { email_object.sender_email }
|
173
|
-
it do
|
174
|
-
expect(message).to receive(:sender_email).once
|
175
|
-
subject
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe '#mime_part' do
|
180
|
-
subject { email_object.mime_part }
|
181
|
-
it do
|
182
|
-
expect(message).to receive(:mime_part).once
|
183
|
-
subject
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'howitzer'
|
3
|
-
|
4
|
-
RSpec.describe 'Howitzer' do
|
5
|
-
describe 'SexySettings configuration' do
|
6
|
-
subject { SexySettings.configuration }
|
7
|
-
it { expect(subject.path_to_custom_settings).to include('config/custom.yml') }
|
8
|
-
it { expect(subject.path_to_default_settings).to include('config/default.yml') }
|
9
|
-
end
|
10
|
-
describe '.app_uri' do
|
11
|
-
before do
|
12
|
-
allow(Howitzer).to receive(:app_base_auth_login) { app_base_auth_login_setting }
|
13
|
-
allow(Howitzer).to receive(:app_base_auth_pass) { app_base_auth_pass_setting }
|
14
|
-
allow(Howitzer).to receive(:app_protocol) { app_protocol_setting }
|
15
|
-
allow(Howitzer).to receive(:app_host) { app_host_setting }
|
16
|
-
end
|
17
|
-
let(:app_protocol_setting) { nil }
|
18
|
-
let(:app_host_setting) { 'redmine.strongqa.com' }
|
19
|
-
context 'when login and password present' do
|
20
|
-
let(:app_base_auth_login_setting) { 'alex' }
|
21
|
-
let(:app_base_auth_pass_setting) { 'pa$$w0rd' }
|
22
|
-
it { expect(Howitzer.app_uri.site).to eq('http://alex:pa$$w0rd@redmine.strongqa.com') }
|
23
|
-
it { expect(Howitzer.app_uri.origin).to eq('http://redmine.strongqa.com') }
|
24
|
-
end
|
25
|
-
context 'when login and password blank' do
|
26
|
-
let(:app_base_auth_login_setting) { nil }
|
27
|
-
let(:app_base_auth_pass_setting) { nil }
|
28
|
-
it { expect(Howitzer.app_uri.site).to eq('http://redmine.strongqa.com') }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
describe '.mailgun_idle_timeout' do
|
32
|
-
subject { Howitzer.mailgun_idle_timeout }
|
33
|
-
before do
|
34
|
-
expect_any_instance_of(Object).to receive(:puts).with(
|
35
|
-
"WARNING! 'mailgun_idle_timeout' setting is deprecated. Please replace with 'mail_wait_time' setting."
|
36
|
-
)
|
37
|
-
end
|
38
|
-
it { is_expected.to be_nil }
|
39
|
-
end
|
40
|
-
end
|
data/spec/unit/lib/init_spec.rb
DELETED
data/spec/unit/lib/log_spec.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'howitzer/log'
|
3
|
-
include Howitzer::LoggerHelper
|
4
|
-
|
5
|
-
RSpec.describe Howitzer::Log do
|
6
|
-
context '.instance' do
|
7
|
-
subject { described_class.instance }
|
8
|
-
let(:other_log) { described_class.instance }
|
9
|
-
it { is_expected.to be_a_kind_of(described_class) }
|
10
|
-
it { is_expected.to equal(other_log) }
|
11
|
-
end
|
12
|
-
|
13
|
-
context '.debug' do
|
14
|
-
it do
|
15
|
-
expect(described_class.instance).to receive(:debug).with('Foo')
|
16
|
-
described_class.debug('Foo')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context '.info' do
|
21
|
-
it do
|
22
|
-
expect(described_class.instance).to receive(:info).with('Foo')
|
23
|
-
described_class.info('Foo')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context '.warn' do
|
28
|
-
it do
|
29
|
-
expect(described_class.instance).to receive(:warn).with('Foo')
|
30
|
-
described_class.warn('Foo')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context '.fatal' do
|
35
|
-
it do
|
36
|
-
expect(described_class.instance).to receive(:fatal).with('Foo')
|
37
|
-
described_class.fatal('Foo')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context '.error' do
|
42
|
-
it do
|
43
|
-
expect(described_class.instance).to receive(:error).with('Foo')
|
44
|
-
described_class.error('Foo')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context '.print_feature_name' do
|
49
|
-
it do
|
50
|
-
expect(described_class.instance).to receive(:print_feature_name).with('Foo')
|
51
|
-
described_class.print_feature_name('Foo')
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context '.settings_as_formatted_text' do
|
56
|
-
it do
|
57
|
-
expect(described_class.instance).to receive(:settings_as_formatted_text).with(no_args)
|
58
|
-
described_class.settings_as_formatted_text
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context '.print_scenario_name' do
|
63
|
-
it do
|
64
|
-
expect(described_class.instance).to receive(:print_scenario_name).with('Foo')
|
65
|
-
described_class.print_scenario_name('Foo')
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#debug' do
|
70
|
-
it do
|
71
|
-
expect(described_class.instance.instance_variable_get(:@logger)).to receive(:debug).with(:foo)
|
72
|
-
described_class.instance.debug :foo
|
73
|
-
end
|
74
|
-
end
|
75
|
-
describe '#info' do
|
76
|
-
it do
|
77
|
-
expect(described_class.instance.instance_variable_get(:@logger)).to receive(:info).with(:foo)
|
78
|
-
described_class.instance.info :foo
|
79
|
-
end
|
80
|
-
end
|
81
|
-
describe '#warn' do
|
82
|
-
it do
|
83
|
-
expect(described_class.instance.instance_variable_get(:@logger)).to receive(:warn).with(:foo)
|
84
|
-
described_class.instance.warn :foo
|
85
|
-
end
|
86
|
-
end
|
87
|
-
describe '#fatal' do
|
88
|
-
it do
|
89
|
-
expect(described_class.instance.instance_variable_get(:@logger)).to receive(:fatal).with(:foo)
|
90
|
-
described_class.instance.fatal :foo
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe '#error' do
|
95
|
-
it do
|
96
|
-
expect(described_class.instance.instance_variable_get(:@logger)).to receive(:error).with(:foo)
|
97
|
-
described_class.instance.error :foo
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe '#print_feature_name' do
|
102
|
-
it do
|
103
|
-
expect(described_class.instance).to receive(:log_without_formatting) { |&arg| arg.call }
|
104
|
-
expect(described_class.instance).to receive(:info).with('*** Feature: FOO ***')
|
105
|
-
described_class.instance.print_feature_name('Foo')
|
106
|
-
end
|
107
|
-
end
|
108
|
-
describe '#settings_as_formatted_text' do
|
109
|
-
it do
|
110
|
-
expect(described_class.instance).to receive(:log_without_formatting) { |&arg| arg.call }
|
111
|
-
expect(described_class.instance).to receive(:info).with(SexySettings::Base.instance.as_formatted_text)
|
112
|
-
described_class.instance.settings_as_formatted_text
|
113
|
-
end
|
114
|
-
end
|
115
|
-
describe '#print_scenario_name' do
|
116
|
-
it do
|
117
|
-
expect(described_class.instance).to receive(:log_without_formatting) { |&arg| arg.call }
|
118
|
-
expect(described_class.instance).to receive(:info).with(' => Scenario: Foo')
|
119
|
-
described_class.instance.print_scenario_name('Foo')
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'howitzer/email'
|
3
|
-
require 'howitzer/mail_adapters/abstract'
|
4
|
-
|
5
|
-
RSpec.describe Howitzer::MailAdapters::Abstract do
|
6
|
-
let(:recipient) { 'first_tester@gmail.com' }
|
7
|
-
let(:message_subject) { 'test subject' }
|
8
|
-
let(:message) { double(:message) }
|
9
|
-
let(:abstract_adapter) { described_class.new(message) }
|
10
|
-
let(:email_object) { Howitzer::Email.adapter.new(message) }
|
11
|
-
|
12
|
-
describe '.find' do
|
13
|
-
subject { described_class.find(recipient, message_subject, _wait: 10) }
|
14
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#new' do
|
18
|
-
context 'when Email instance receive message and add create @message variable that' do
|
19
|
-
it { expect(email_object.instance_variable_get(:@message)).to eql message }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#plain_text_body' do
|
24
|
-
subject { abstract_adapter.plain_text_body }
|
25
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#html_body' do
|
29
|
-
subject { abstract_adapter.html_body }
|
30
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#text' do
|
34
|
-
subject { abstract_adapter.text }
|
35
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#mail_from' do
|
39
|
-
subject { abstract_adapter.mail_from }
|
40
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#recipients' do
|
44
|
-
subject { abstract_adapter.recipients }
|
45
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#received_time' do
|
49
|
-
subject { abstract_adapter.received_time }
|
50
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#sender_email' do
|
54
|
-
subject { abstract_adapter.sender_email }
|
55
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#mime_part' do
|
59
|
-
subject { abstract_adapter.mime_part }
|
60
|
-
it { expect { subject }.to raise_error(NotImplementedError) }
|
61
|
-
end
|
62
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'howitzer/email'
|
3
|
-
require 'howitzer/log'
|
4
|
-
require 'howitzer/exceptions'
|
5
|
-
require 'howitzer/mailgun_api/connector'
|
6
|
-
|
7
|
-
RSpec.describe 'Mailgun Email Adapter' do
|
8
|
-
let(:recipient) { 'first_tester@gmail.com' }
|
9
|
-
let(:message) do
|
10
|
-
{
|
11
|
-
'body-plain' => 'test body footer',
|
12
|
-
'stripped-html' => '<p> test body </p> <p> footer </p>',
|
13
|
-
'stripped-text' => 'test body',
|
14
|
-
'From' => 'Strong Tester <tester@gmail.com>',
|
15
|
-
'To' => recipient,
|
16
|
-
'Received' => 'by 10.216.46.75 with HTTP; Sat, 5 Apr 2014 05:10:42 -0700 (PDT)',
|
17
|
-
'sender' => 'tester@gmail.com',
|
18
|
-
'attachments' => []
|
19
|
-
}
|
20
|
-
end
|
21
|
-
let(:message_subject) { 'test subject' }
|
22
|
-
let(:mail_address) { double }
|
23
|
-
let(:email_object) { Howitzer::Email.adapter.new(message) }
|
24
|
-
|
25
|
-
before do
|
26
|
-
stub_const('Howitzer::Email::SUBJECT', message_subject)
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '.find' do
|
30
|
-
let(:mailgun_message) { double(to_h: message) }
|
31
|
-
let(:events) { double(to_h: { 'items' => [event] }) }
|
32
|
-
subject { Howitzer::MailAdapters::Mailgun.find(recipient, message_subject, wait: 0.01) }
|
33
|
-
|
34
|
-
context 'when message is found' do
|
35
|
-
let(:event) do
|
36
|
-
{
|
37
|
-
'message' => {
|
38
|
-
'recipients' => [recipient],
|
39
|
-
'headers' => {
|
40
|
-
'subject' => message_subject
|
41
|
-
}
|
42
|
-
},
|
43
|
-
'storage' => {
|
44
|
-
'key' => '1234567890',
|
45
|
-
'url' => 'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
|
46
|
-
}
|
47
|
-
}
|
48
|
-
end
|
49
|
-
before do
|
50
|
-
allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get).with(
|
51
|
-
'mailgun@test.domain/events',
|
52
|
-
params: { event: 'stored' }
|
53
|
-
) { events }
|
54
|
-
allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get_url).with(
|
55
|
-
'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
|
56
|
-
) { mailgun_message }
|
57
|
-
end
|
58
|
-
it do
|
59
|
-
expect(Howitzer::Email.adapter).to receive(:new).with(message).once
|
60
|
-
subject
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'when message is not found' do
|
65
|
-
let(:event) do
|
66
|
-
{
|
67
|
-
'message' => {
|
68
|
-
'recipients' => ['other@test.com'],
|
69
|
-
'headers' => {
|
70
|
-
'subject' => message_subject
|
71
|
-
}
|
72
|
-
},
|
73
|
-
'storage' => {
|
74
|
-
'key' => '1234567890',
|
75
|
-
'url' => 'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
|
76
|
-
}
|
77
|
-
}
|
78
|
-
end
|
79
|
-
before do
|
80
|
-
allow(Howitzer::MailgunApi::Connector.instance.client).to receive(:get).with(
|
81
|
-
'mailgun@test.domain/events',
|
82
|
-
params: { event: 'stored' }
|
83
|
-
) { events }
|
84
|
-
end
|
85
|
-
it do
|
86
|
-
expect { subject }.to raise_error(
|
87
|
-
Howitzer::EmailNotFoundError,
|
88
|
-
"Message with subject '#{message_subject}' for recipient '#{recipient}' was not found."
|
89
|
-
)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe '#plain_text_body' do
|
95
|
-
it { expect(email_object.plain_text_body).to eql message['body-plain'] }
|
96
|
-
end
|
97
|
-
|
98
|
-
describe '#html_body' do
|
99
|
-
it { expect(email_object.html_body).to eql message['stripped-html'] }
|
100
|
-
end
|
101
|
-
|
102
|
-
describe '#text' do
|
103
|
-
it { expect(email_object.text).to eql message['stripped-text'] }
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '#mail_from' do
|
107
|
-
it { expect(email_object.mail_from).to eql message['From'] }
|
108
|
-
end
|
109
|
-
|
110
|
-
describe '#recipients' do
|
111
|
-
subject { email_object.recipients }
|
112
|
-
it { is_expected.to be_a_kind_of Array }
|
113
|
-
|
114
|
-
context 'when one recipient' do
|
115
|
-
it { is_expected.to include message['To'] }
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'when more than one recipient' do
|
119
|
-
let(:second_recipient) { 'second_tester@gmail.com' }
|
120
|
-
let(:message_with_multiple_recipients) { message.merge('To' => "#{recipient}, #{second_recipient}") }
|
121
|
-
let(:email_object) { Howitzer::Email.adapter.new(message_with_multiple_recipients) }
|
122
|
-
it { is_expected.to eql [recipient, second_recipient] }
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '#received_time' do
|
127
|
-
it { expect(email_object.received_time).to eql message['Received'][27..63] }
|
128
|
-
end
|
129
|
-
|
130
|
-
describe '#sender_email' do
|
131
|
-
it { expect(email_object.sender_email).to eql message['sender'] }
|
132
|
-
end
|
133
|
-
|
134
|
-
describe '#mime_part' do
|
135
|
-
subject { email_object.mime_part }
|
136
|
-
|
137
|
-
context 'when has attachments' do
|
138
|
-
let(:files) { [double] }
|
139
|
-
before { email_object.instance_variable_set(:@message, 'attachments' => files) }
|
140
|
-
it { is_expected.to eq(files) }
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'when no attachments' do
|
144
|
-
it { is_expected.to eq([]) }
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe '#mime_part!' do
|
149
|
-
subject { email_object.mime_part! }
|
150
|
-
|
151
|
-
context 'when has attachments' do
|
152
|
-
let(:files) { [double] }
|
153
|
-
before { email_object.instance_variable_set(:@message, 'attachments' => files) }
|
154
|
-
it { is_expected.to eq(files) }
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'when no attachments' do
|
158
|
-
it do
|
159
|
-
expect { subject }.to raise_error(Howitzer::NoAttachmentsError, 'No attachments where found.')
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'howitzer/mailgun_api/client'
|
3
|
-
|
4
|
-
RSpec.describe Howitzer::MailgunApi::Client do
|
5
|
-
let(:mg_obj) { described_class.new(api_key: 'Fake-API-Key') }
|
6
|
-
describe '.new' do
|
7
|
-
subject { mg_obj }
|
8
|
-
it { expect { subject }.not_to raise_error }
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#get' do
|
12
|
-
let(:query_string) { { 'skip' => '10', 'limit' => '5' } }
|
13
|
-
subject { mg_obj.get('test.com/bounces', params: query_string) }
|
14
|
-
context 'when simulation of client' do
|
15
|
-
before do
|
16
|
-
expect(RestClient::Resource).to receive(:new)
|
17
|
-
.once.and_return(Howitzer::MailgunApi::UnitClient.new('Fake-API-Key', 'api.mailgun.net', 'v2'))
|
18
|
-
end
|
19
|
-
it do
|
20
|
-
expect(subject.body).to include('total_count')
|
21
|
-
expect(subject.body).to include('items')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
context 'when real client' do
|
25
|
-
let(:resource) { double }
|
26
|
-
before do
|
27
|
-
allow(resource).to receive('[]').and_return(resource)
|
28
|
-
allow(resource).to receive(:get).and_raise(StandardError, '401 Unauthorized: Forbidden')
|
29
|
-
allow(RestClient::Resource).to receive(:new).and_return(resource)
|
30
|
-
end
|
31
|
-
it do
|
32
|
-
expect { subject }.to raise_error(Howitzer::CommunicationError, '401 Unauthorized: Forbidden')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#get_url' do
|
38
|
-
let(:response_raw) { double }
|
39
|
-
subject { mg_obj.get_url('https://ci.api.mailgan.com/domains/test_domain/messages/asdfasdf') }
|
40
|
-
context 'when success request' do
|
41
|
-
let(:response_raw) { double }
|
42
|
-
let(:response_real) { double }
|
43
|
-
before do
|
44
|
-
allow(RestClient::Request).to receive(:execute).with(any_args).and_return(response_raw)
|
45
|
-
allow(Howitzer::MailgunApi::Response).to receive(:new).with(response_raw).and_return(response_real)
|
46
|
-
end
|
47
|
-
it { is_expected.to eq(response_real) }
|
48
|
-
end
|
49
|
-
context 'when error happens' do
|
50
|
-
before do
|
51
|
-
allow(RestClient::Resource).to receive(:new).with(any_args).and_return(response_raw)
|
52
|
-
mg_obj
|
53
|
-
allow(RestClient::Request).to receive(:execute).with(any_args).and_raise(StandardError, 'Some message')
|
54
|
-
end
|
55
|
-
it { expect { subject }.to raise_error(Howitzer::CommunicationError, 'Some message') }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'howitzer/mailgun_api/connector'
|
3
|
-
|
4
|
-
RSpec.describe Howitzer::MailgunApi::Connector do
|
5
|
-
let(:connector) { described_class.instance }
|
6
|
-
let(:domain_name) { 'test@domain.com' }
|
7
|
-
describe '#client' do
|
8
|
-
subject { connector.client }
|
9
|
-
context 'when api_key is default' do
|
10
|
-
context 'when client is not initialized' do
|
11
|
-
it { is_expected.to be_an_instance_of Howitzer::MailgunApi::Client }
|
12
|
-
end
|
13
|
-
context 'when client is already initialized' do
|
14
|
-
it do
|
15
|
-
object_id = connector.client.object_id
|
16
|
-
expect(subject.object_id).to eq(object_id)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
context 'when api_key is custom' do
|
21
|
-
let(:key) { 'some api key' }
|
22
|
-
subject { connector.client(key) }
|
23
|
-
it { is_expected.to be_an_instance_of Howitzer::MailgunApi::Client }
|
24
|
-
end
|
25
|
-
context 'when api_key is nil' do
|
26
|
-
let(:key) { nil }
|
27
|
-
subject { connector.client(key) }
|
28
|
-
it do
|
29
|
-
expect { subject }.to raise_error(Howitzer::InvalidApiKeyError, 'Api key can not be blank')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
context 'when api_key is blank string' do
|
33
|
-
let(:key) { '' }
|
34
|
-
subject { connector.client(key) }
|
35
|
-
it do
|
36
|
-
expect { subject }.to raise_error(Howitzer::InvalidApiKeyError, 'Api key can not be blank')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
describe '#domain' do
|
41
|
-
subject { connector.domain }
|
42
|
-
context 'when default domain' do
|
43
|
-
it do
|
44
|
-
is_expected.to eq(Howitzer.mailgun_domain)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
context 'when domain is already set' do
|
48
|
-
before do
|
49
|
-
connector.domain = domain_name
|
50
|
-
end
|
51
|
-
it { is_expected.to eql(domain_name) }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|