howitzer 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +1 -4
- data/.yardopts +1 -2
- data/CHANGELOG.md +28 -1
- data/Gemfile +6 -0
- data/LICENSE +1 -1
- data/README.md +55 -85
- data/Rakefile +7 -7
- data/bin/howitzer +56 -31
- data/features/cli_new.feature +162 -79
- data/features/cli_update.feature +114 -21
- data/features/step_definitions/common_steps.rb +29 -9
- data/features/support/env.rb +1 -1
- data/features/support/transformers.rb +2 -2
- data/generators/base_generator.rb +121 -49
- data/generators/config/config_generator.rb +8 -5
- data/generators/config/templates/boot.rb +14 -0
- data/generators/config/templates/capybara.rb +156 -0
- data/generators/config/templates/custom.yml +2 -3
- data/generators/config/templates/default.yml +50 -82
- data/generators/cucumber/cucumber_generator.rb +9 -9
- data/generators/cucumber/templates/common_steps.rb +4 -4
- data/generators/cucumber/templates/cucumber.rake +63 -54
- data/generators/cucumber/templates/env.rb +24 -23
- data/generators/cucumber/templates/transformers.rb +23 -15
- data/generators/emails/emails_generator.rb +4 -2
- data/generators/emails/templates/example_email.rb +4 -4
- data/generators/prerequisites/prerequisites_generator.rb +24 -0
- data/generators/prerequisites/templates/base.rb +22 -0
- data/generators/prerequisites/templates/factory_girl.rb +30 -0
- data/generators/prerequisites/templates/user.rb +7 -0
- data/generators/prerequisites/templates/users.rb +12 -0
- data/generators/root/root_generator.rb +11 -7
- data/generators/root/templates/.rubocop.yml +32 -0
- data/generators/root/templates/Gemfile.erb +27 -0
- data/generators/root/templates/Rakefile +6 -8
- data/generators/rspec/rspec_generator.rb +7 -7
- data/generators/rspec/templates/example_spec.rb +1 -1
- data/generators/rspec/templates/rspec.rake +48 -29
- data/generators/rspec/templates/spec_helper.rb +33 -32
- data/generators/tasks/tasks_generator.rb +4 -2
- data/generators/tasks/templates/common.rake +1 -16
- data/generators/turnip/templates/.rspec +1 -0
- data/generators/turnip/templates/common_steps.rb +25 -0
- data/generators/turnip/templates/example.feature +8 -0
- data/generators/turnip/templates/spec_helper.rb +56 -0
- data/generators/turnip/templates/turnip.rake +61 -0
- data/generators/turnip/templates/turnip_helper.rb +6 -0
- data/generators/turnip/turnip_generator.rb +26 -0
- data/generators/web/templates/example_page.rb +15 -0
- data/generators/web/templates/menu_section.rb +13 -0
- data/generators/web/web_generator.rb +22 -0
- data/howitzer.gemspec +14 -21
- data/lib/howitzer.rb +47 -7
- data/lib/howitzer/cache.rb +70 -0
- data/lib/howitzer/capybara_helpers.rb +194 -0
- data/lib/howitzer/email.rb +96 -104
- data/lib/howitzer/exceptions.rb +10 -6
- data/lib/howitzer/log.rb +120 -0
- data/lib/howitzer/mail_adapters.rb +7 -0
- data/lib/howitzer/mail_adapters/abstract.rb +84 -0
- data/lib/howitzer/mail_adapters/mailgun.rb +115 -0
- data/lib/howitzer/mailgun_api.rb +9 -0
- data/lib/howitzer/mailgun_api/client.rb +79 -0
- data/lib/howitzer/mailgun_api/connector.rb +37 -0
- data/lib/howitzer/mailgun_api/response.rb +28 -0
- data/lib/howitzer/tasks/framework.rake +2 -2
- data/lib/howitzer/utils.rb +7 -1
- data/lib/howitzer/utils/string_extensions.rb +66 -0
- data/lib/howitzer/version.rb +2 -1
- data/lib/howitzer/web.rb +11 -0
- data/lib/howitzer/web/base_section.rb +27 -0
- data/lib/howitzer/web/blank_page.rb +12 -0
- data/lib/howitzer/web/capybara_methods_proxy.rb +29 -0
- data/lib/howitzer/web/element_dsl.rb +109 -0
- data/lib/howitzer/web/iframe_dsl.rb +93 -0
- data/lib/howitzer/web/page.rb +173 -0
- data/lib/howitzer/web/page_dsl.rb +64 -0
- data/lib/howitzer/web/page_validator.rb +118 -0
- data/lib/howitzer/web/section.rb +27 -0
- data/lib/howitzer/web/section_dsl.rb +154 -0
- data/spec/config/custom.yml +10 -1
- data/spec/spec_helper.rb +37 -19
- data/spec/support/generator_helper.rb +12 -11
- data/spec/support/logger_helper.rb +10 -9
- data/spec/support/mailgun_unit_client.rb +52 -44
- data/spec/support/shared_examples/capybara_context_holder.rb +33 -0
- data/spec/support/shared_examples/capybara_methods_proxy.rb +94 -0
- data/spec/support/shared_examples/dynamic_section_methods.rb +35 -0
- data/spec/support/shared_examples/element_dsl.rb +119 -0
- data/spec/unit/generators/base_generator_spec.rb +64 -33
- data/spec/unit/generators/config_generator_spec.rb +11 -7
- data/spec/unit/generators/cucumber_generator_spec.rb +26 -17
- data/spec/unit/generators/emails_generator_spec.rb +10 -6
- data/spec/unit/generators/prerequisites_generator_spec.rb +53 -0
- data/spec/unit/generators/root_generator_spec.rb +50 -13
- data/spec/unit/generators/rspec_generator_spec.rb +9 -9
- data/spec/unit/generators/tasks_generator_spec.rb +6 -6
- data/spec/unit/generators/turnip_generator_spec.rb +52 -0
- data/spec/unit/generators/web_generator_spec.rb +52 -0
- data/spec/unit/lib/cache_spec.rb +85 -0
- data/spec/unit/lib/capybara_helpers_spec.rb +696 -0
- data/spec/unit/lib/email_spec.rb +104 -91
- data/spec/unit/lib/howitzer.rb +31 -0
- data/spec/unit/lib/init_spec.rb +0 -1
- data/spec/unit/lib/log_spec.rb +122 -0
- data/spec/unit/lib/mail_adapters/abstract_spec.rb +62 -0
- data/spec/unit/lib/mail_adapters/mailgun_spec.rb +163 -0
- data/spec/unit/lib/mailgun_api/client_spec.rb +58 -0
- data/spec/unit/lib/mailgun_api/connector_spec.rb +54 -0
- data/spec/unit/lib/mailgun_api/response_spec.rb +28 -0
- data/spec/unit/lib/utils/string_extensions_spec.rb +77 -0
- data/spec/unit/lib/web/base_section_spec.rb +41 -0
- data/spec/unit/lib/web/element_dsl_spec.rb +17 -0
- data/spec/unit/lib/web/iframe_dsl_spec.rb +99 -0
- data/spec/unit/lib/web/page_dsl_spec.rb +52 -0
- data/spec/unit/lib/web/page_spec.rb +304 -0
- data/spec/unit/lib/web/page_validator_spec.rb +218 -0
- data/spec/unit/lib/web/section_dsl_spec.rb +165 -0
- data/spec/unit/lib/web/section_spec.rb +61 -0
- data/spec/unit/version_spec.rb +1 -1
- metadata +116 -203
- data/GETTING_STARTED.md +0 -774
- data/generators/cucumber/templates/cucumber.yml +0 -10
- data/generators/pages/pages_generator.rb +0 -21
- data/generators/pages/templates/example_menu.rb +0 -15
- data/generators/pages/templates/example_page.rb +0 -15
- data/generators/root/templates/Gemfile +0 -7
- data/generators/root/templates/boot.rb +0 -10
- data/lib/howitzer/blank_page.rb +0 -6
- data/lib/howitzer/capybara/dsl_ex.rb +0 -15
- data/lib/howitzer/capybara/settings.rb +0 -343
- data/lib/howitzer/helpers.rb +0 -230
- data/lib/howitzer/init.rb +0 -1
- data/lib/howitzer/mailgun/client.rb +0 -65
- data/lib/howitzer/mailgun/connector.rb +0 -34
- data/lib/howitzer/mailgun/response.rb +0 -28
- data/lib/howitzer/patches/rawler_patched.rb +0 -86
- data/lib/howitzer/settings.rb +0 -27
- data/lib/howitzer/utils/data_generator/data_storage.rb +0 -88
- data/lib/howitzer/utils/data_generator/gen.rb +0 -135
- data/lib/howitzer/utils/locator_store.rb +0 -217
- data/lib/howitzer/utils/log.rb +0 -139
- data/lib/howitzer/utils/page_validator.rb +0 -133
- 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/web_page.rb +0 -253
- data/spec/active_resource.rb +0 -0
- data/spec/config/default.yml +0 -26
- data/spec/support/boot_helper.rb +0 -15
- data/spec/unit/generators/pages_generator_spec.rb +0 -33
- data/spec/unit/lib/capybara/dsl_ex_spec.rb +0 -60
- data/spec/unit/lib/capybara/settings_spec.rb +0 -441
- data/spec/unit/lib/helpers_spec.rb +0 -1129
- data/spec/unit/lib/mailgun/client_spec.rb +0 -36
- data/spec/unit/lib/mailgun/connector_spec.rb +0 -70
- data/spec/unit/lib/mailgun/response_spec.rb +0 -28
- data/spec/unit/lib/settings_spec.rb +0 -17
- data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +0 -80
- data/spec/unit/lib/utils/data_generator/gen_spec.rb +0 -90
- data/spec/unit/lib/utils/locator_store_spec.rb +0 -157
- data/spec/unit/lib/utils/log_spec.rb +0 -107
- data/spec/unit/lib/utils/page_validator_spec.rb +0 -265
- data/spec/unit/lib/web_page_spec.rb +0 -346
@@ -0,0 +1,163 @@
|
|
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) }
|
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
|
+
).ordered.once { 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
|
+
).ordered.once { 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
|
+
).at_least(:twice).ordered { 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
|
@@ -0,0 +1,58 @@
|
|
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 { 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('[]') { resource }
|
28
|
+
allow(resource).to receive(:get).and_raise(StandardError, '401 Unauthorized: Forbidden')
|
29
|
+
allow(RestClient::Resource).to receive(:new) { 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) { response_raw }
|
45
|
+
allow(Howitzer::MailgunApi::Response).to receive(:new).with(response_raw) { 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) { 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
|
@@ -0,0 +1,54 @@
|
|
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
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'howitzer/mailgun_api/client'
|
3
|
+
require 'howitzer/exceptions'
|
4
|
+
|
5
|
+
RSpec.describe Howitzer::MailgunApi::Response do
|
6
|
+
let(:body) { { foo: 'bar' }.to_json }
|
7
|
+
let(:response) { double(:response, body: body, code: 201) }
|
8
|
+
describe '#body' do
|
9
|
+
subject { described_class.new(response).body }
|
10
|
+
it { is_expected.to eq('{"foo":"bar"}') }
|
11
|
+
end
|
12
|
+
describe '#code' do
|
13
|
+
subject { described_class.new(response).code }
|
14
|
+
it { is_expected.to eq(201) }
|
15
|
+
end
|
16
|
+
describe '#to_h' do
|
17
|
+
subject { described_class.new(response).to_h }
|
18
|
+
context 'when possible parse body' do
|
19
|
+
it { is_expected.to eq('foo' => 'bar') }
|
20
|
+
end
|
21
|
+
context 'when impossible parse body' do
|
22
|
+
let(:body) { "'123': '123' :123" }
|
23
|
+
it do
|
24
|
+
expect { subject }.to raise_error(Howitzer::ParseError)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'howitzer/utils/string_extensions'
|
3
|
+
|
4
|
+
RSpec.describe Howitzer::Utils::StringExtensions do
|
5
|
+
String.send(:include, Howitzer::Utils::StringExtensions)
|
6
|
+
|
7
|
+
let(:page_name) { 'my' }
|
8
|
+
let(:page_object) { double }
|
9
|
+
before { stub_const('MyPage', page_object) }
|
10
|
+
describe '#open' do
|
11
|
+
subject { page_name.open(:exit) }
|
12
|
+
before do
|
13
|
+
expect(page_object).to receive(:open).with(:exit).once
|
14
|
+
end
|
15
|
+
it { is_expected.to be_nil }
|
16
|
+
end
|
17
|
+
describe '#given' do
|
18
|
+
subject { page_name.given }
|
19
|
+
before do
|
20
|
+
allow(page_name).to receive(:as_page_class) { page_object }
|
21
|
+
expect(page_object).to receive(:given).once
|
22
|
+
end
|
23
|
+
it { is_expected.to be_nil }
|
24
|
+
end
|
25
|
+
describe '#displayed?' do
|
26
|
+
subject { page_name.displayed? }
|
27
|
+
before do
|
28
|
+
allow(page_name).to receive(:as_page_class) { page_object }
|
29
|
+
expect(page_object).to receive(:displayed?).once
|
30
|
+
end
|
31
|
+
it { is_expected.to be_nil }
|
32
|
+
end
|
33
|
+
describe '#as_page_class' do
|
34
|
+
subject { page_name.as_page_class }
|
35
|
+
context 'when 1 word' do
|
36
|
+
it { is_expected.to eql(page_object) }
|
37
|
+
end
|
38
|
+
context 'when more 1 word' do
|
39
|
+
let(:page_name) { 'my super mega' }
|
40
|
+
before { stub_const('MySuperMegaPage', page_object) }
|
41
|
+
it { is_expected.to eql(page_object) }
|
42
|
+
end
|
43
|
+
context 'when plural word' do
|
44
|
+
let(:page_name) { 'user notifications' }
|
45
|
+
before { stub_const('UserNotificationsPage', page_object) }
|
46
|
+
it { is_expected.to eql(page_object) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
describe '#as_email_class' do
|
50
|
+
subject { email_name.as_email_class }
|
51
|
+
let(:my_email) { double }
|
52
|
+
context 'when 1 word' do
|
53
|
+
let(:email_name) { 'my' }
|
54
|
+
before { stub_const('MyEmail', my_email) }
|
55
|
+
it { is_expected.to eql(my_email) }
|
56
|
+
end
|
57
|
+
context 'when more 1 word' do
|
58
|
+
let(:email_name) { 'my super mega' }
|
59
|
+
before { stub_const('MySuperMegaEmail', my_email) }
|
60
|
+
it { is_expected.to eql(my_email) }
|
61
|
+
end
|
62
|
+
context 'when plural word' do
|
63
|
+
let(:email_name) { 'email notifications' }
|
64
|
+
before { stub_const('EmailNotificationsEmail', my_email) }
|
65
|
+
it { is_expected.to eql(my_email) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
describe '#on' do
|
69
|
+
let(:block) { -> {} }
|
70
|
+
subject { page_name.on(&block) }
|
71
|
+
before do
|
72
|
+
allow(page_name).to receive(:as_page_class) { page_object }
|
73
|
+
expect(page_object).to receive(:on).once
|
74
|
+
end
|
75
|
+
it { is_expected.to be_nil }
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'howitzer/web/section_dsl'
|
3
|
+
require 'howitzer/web/base_section'
|
4
|
+
|
5
|
+
RSpec.describe Howitzer::Web::BaseSection do
|
6
|
+
describe 'element dsl methods' do
|
7
|
+
let(:parent) { double }
|
8
|
+
let(:capybara_context) { double }
|
9
|
+
|
10
|
+
let(:klass) { Class.new(described_class) }
|
11
|
+
let(:klass_object) { klass.new(parent, capybara_context) }
|
12
|
+
before { allow(klass_object).to receive(:capybara_context) { kontext } }
|
13
|
+
|
14
|
+
include_examples :element_dsl
|
15
|
+
end
|
16
|
+
describe 'DSL' do
|
17
|
+
describe '.me' do
|
18
|
+
it { expect { described_class.send(:me, '.foo') }.to raise_error(NoMethodError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.default_finder_args' do
|
23
|
+
subject { described_class.default_finder_args }
|
24
|
+
it { is_expected.to be_nil }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#parent' do
|
28
|
+
subject { described_class.new(:test, 1).parent }
|
29
|
+
it { is_expected.to eq(:test) }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#capybara_context' do
|
33
|
+
subject { described_class.new(1, :test).capybara_context }
|
34
|
+
it { is_expected.to eq(:test) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'includes proxied capybara methods' do
|
38
|
+
let(:reciever) { Class.new(described_class).new(:test, 1) }
|
39
|
+
include_examples :capybara_methods_proxy
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'howitzer/web/element_dsl'
|
3
|
+
|
4
|
+
RSpec.describe Howitzer::Web::ElementDsl do
|
5
|
+
let(:klass) do
|
6
|
+
Class.new do
|
7
|
+
include Howitzer::Web::ElementDsl
|
8
|
+
def capybara_context
|
9
|
+
Capybara.current_session
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
let(:klass_object) { klass.new }
|
14
|
+
|
15
|
+
include_examples :element_dsl
|
16
|
+
include_examples :capybara_context_holder
|
17
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'howitzer/web/page'
|
3
|
+
|
4
|
+
RSpec.describe Howitzer::Web::IframeDsl do
|
5
|
+
let(:fb_page_class) do
|
6
|
+
Class.new(Howitzer::Web::Page) do
|
7
|
+
section :navbar, :xpath, './body' do
|
8
|
+
element :like_button, '#foo_id'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:web_page_class) do
|
14
|
+
Class.new(Howitzer::Web::Page)
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow_any_instance_of(fb_page_class).to receive(:check_validations_are_defined!)
|
19
|
+
allow_any_instance_of(web_page_class).to receive(:check_validations_are_defined!)
|
20
|
+
stub_const('FbPage', fb_page_class)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.iframe' do
|
24
|
+
context 'when selector is integer' do
|
25
|
+
subject do
|
26
|
+
web_page_class.class_eval do
|
27
|
+
iframe :fb, 1
|
28
|
+
end
|
29
|
+
web_page_class
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create public :fb_iframe instance method' do
|
33
|
+
expect(subject.instance.public_methods(false)).to include(:fb_iframe)
|
34
|
+
end
|
35
|
+
it 'should create public :has_fb_iframe? instance method' do
|
36
|
+
expect(subject.instance.public_methods(false)).to include(:has_fb_iframe?)
|
37
|
+
end
|
38
|
+
it 'should create public :has_no_fb_iframe? instance method' do
|
39
|
+
expect(subject.instance.public_methods(false)).to include(:has_no_fb_iframe?)
|
40
|
+
end
|
41
|
+
it 'should be protected class method' do
|
42
|
+
expect { subject.iframe :bar }.to raise_error(NoMethodError)
|
43
|
+
expect(subject.protected_methods(true)).to include(:iframe)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
include_examples :capybara_context_holder
|
49
|
+
|
50
|
+
describe 'dynamic_methods' do
|
51
|
+
let(:web_page_object) { web_page_class.instance }
|
52
|
+
let(:kontext) { double(:kontext) }
|
53
|
+
before do
|
54
|
+
allow(Capybara).to receive(:current_session) { kontext }
|
55
|
+
end
|
56
|
+
after { subject }
|
57
|
+
|
58
|
+
describe '#name_iframe' do
|
59
|
+
let(:block) { proc {} }
|
60
|
+
subject { web_page_object.send(:fb_iframe, &block) }
|
61
|
+
context 'when integer selector' do
|
62
|
+
before { web_page_class.class_eval { iframe :fb, 1 } }
|
63
|
+
it do
|
64
|
+
expect(kontext).to receive(:within_frame).with(1) { |&block| block.call }
|
65
|
+
expect(block).to receive(:call).with(fb_page_class.instance)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
context 'when string selector' do
|
69
|
+
before { web_page_class.class_eval { iframe :fb, 'loko' } }
|
70
|
+
it do
|
71
|
+
expect(kontext).to receive(:within_frame).with('loko') { |&block| block.call }
|
72
|
+
expect(block).to receive(:call).with(fb_page_class.instance)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
describe '#has_name_iframe?' do
|
77
|
+
subject { web_page_object.has_fb_iframe? }
|
78
|
+
context 'when integer selector' do
|
79
|
+
before { web_page_class.class_eval { iframe :fb, 1 } }
|
80
|
+
it { expect(kontext).to receive(:has_selector?).with('iframe:nth-of-type(2)') }
|
81
|
+
end
|
82
|
+
context 'when string selector' do
|
83
|
+
before { web_page_class.class_eval { iframe :fb, 'loko' } }
|
84
|
+
it { expect(kontext).to receive(:has_selector?).with(:frame, 'loko') }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
describe '#has_no_name_iframe?' do
|
88
|
+
subject { web_page_object.has_no_fb_iframe? }
|
89
|
+
context 'when integer selector' do
|
90
|
+
before { web_page_class.class_eval { iframe :fb, 1 } }
|
91
|
+
it { expect(kontext).to receive(:has_no_selector?).with('iframe:nth-of-type(2)') }
|
92
|
+
end
|
93
|
+
context 'when string selector' do
|
94
|
+
before { web_page_class.class_eval { iframe :fb, 'loko' } }
|
95
|
+
it { expect(kontext).to receive(:has_no_selector?).with(:frame, 'loko') }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|