howitzer 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/LICENSE +1 -1
  4. data/README.md +16 -16
  5. data/generators/base_generator.rb +1 -1
  6. data/generators/config/config_generator.rb +1 -4
  7. data/generators/config/templates/boot.rb +1 -1
  8. data/generators/config/templates/capybara.rb +1 -3
  9. data/generators/config/templates/default.yml +5 -19
  10. data/generators/config/templates/drivers/browserstack.rb +1 -1
  11. data/generators/config/templates/drivers/crossbrowsertesting.rb +1 -1
  12. data/generators/config/templates/drivers/headless_chrome.rb +1 -1
  13. data/generators/config/templates/drivers/headless_firefox.rb +1 -1
  14. data/generators/config/templates/drivers/sauce.rb +1 -1
  15. data/generators/config/templates/drivers/selenium.rb +1 -1
  16. data/generators/config/templates/drivers/selenium_grid.rb +2 -2
  17. data/generators/config/templates/drivers/testingbot.rb +1 -1
  18. data/generators/cucumber/templates/env.rb +1 -1
  19. data/generators/cucumber/templates/hooks.rb +8 -2
  20. data/generators/cucumber/templates/transformers.rb +1 -1
  21. data/generators/prerequisites/templates/factory_bot.rb +1 -1
  22. data/generators/root/templates/Gemfile.erb +4 -10
  23. data/generators/rspec/templates/spec_helper.rb +4 -4
  24. data/generators/turnip/templates/spec_helper.rb +4 -4
  25. data/generators/web/templates/example_page.rb +1 -1
  26. data/lib/howitzer/cache.rb +1 -1
  27. data/lib/howitzer/capybara_helpers.rb +27 -7
  28. data/lib/howitzer/email.rb +2 -2
  29. data/lib/howitzer/exceptions.rb +21 -21
  30. data/lib/howitzer/gmail_api/client.rb +13 -4
  31. data/lib/howitzer/log.rb +6 -6
  32. data/lib/howitzer/mailgun_api/client.rb +3 -2
  33. data/lib/howitzer/mailgun_api/response.rb +1 -2
  34. data/lib/howitzer/mailtrap_api/client.rb +1 -1
  35. data/lib/howitzer/meta/actions.rb +13 -16
  36. data/lib/howitzer/meta/element.rb +12 -10
  37. data/lib/howitzer/utils/string_extensions.rb +6 -2
  38. data/lib/howitzer/version.rb +1 -1
  39. data/lib/howitzer/web/base_section.rb +1 -1
  40. data/lib/howitzer/web/capybara_methods_proxy.rb +11 -5
  41. data/lib/howitzer/web/element_dsl.rb +104 -45
  42. data/lib/howitzer/web/iframe_dsl.rb +2 -2
  43. data/lib/howitzer/web/page.rb +4 -14
  44. data/lib/howitzer/web/page_dsl.rb +15 -6
  45. data/lib/howitzer/web/page_validator.rb +25 -26
  46. data/lib/howitzer/web/section.rb +5 -2
  47. data/lib/howitzer/web/section_dsl.rb +64 -30
  48. data/lib/howitzer.rb +2 -2
  49. metadata +24 -161
  50. data/.coveralls.yml +0 -1
  51. data/.gitignore +0 -14
  52. data/.rspec +0 -3
  53. data/.rubocop.yml +0 -60
  54. data/.ruby-gemset +0 -1
  55. data/.travis.yml +0 -8
  56. data/Gemfile +0 -14
  57. data/ISSUE_TEMPLATE.md +0 -16
  58. data/MAINTENANCE.md +0 -32
  59. data/Rakefile +0 -38
  60. data/features/cli_help.feature +0 -31
  61. data/features/cli_new.feature +0 -393
  62. data/features/cli_unknown.feature +0 -17
  63. data/features/cli_update.feature +0 -223
  64. data/features/cli_version.feature +0 -14
  65. data/features/step_definitions/common_steps.rb +0 -34
  66. data/features/support/env.rb +0 -1
  67. data/generators/config/templates/drivers/poltergeist.rb +0 -11
  68. data/generators/config/templates/drivers/webkit.rb +0 -6
  69. data/generators/root/templates/.gitignore +0 -21
  70. data/generators/root/templates/.rubocop.yml.erb +0 -56
  71. data/generators/turnip/templates/.rspec +0 -1
  72. data/howitzer.gemspec +0 -39
  73. data/lib/howitzer/mail_adapters/debugmail.rb +0 -0
  74. data/spec/config/custom.yml +0 -9
  75. data/spec/spec_helper.rb +0 -73
  76. data/spec/support/generator_helper.rb +0 -21
  77. data/spec/support/logger_helper.rb +0 -13
  78. data/spec/support/shared_examples/capybara_context_holder.rb +0 -33
  79. data/spec/support/shared_examples/capybara_methods_proxy.rb +0 -94
  80. data/spec/support/shared_examples/dynamic_section_methods.rb +0 -35
  81. data/spec/support/shared_examples/element_dsl.rb +0 -242
  82. data/spec/support/shared_examples/meta_highlight_xpath.rb +0 -41
  83. data/spec/unit/generators/base_generator_spec.rb +0 -283
  84. data/spec/unit/generators/config_generator_spec.rb +0 -61
  85. data/spec/unit/generators/cucumber_generator_spec.rb +0 -62
  86. data/spec/unit/generators/emails_generator_spec.rb +0 -35
  87. data/spec/unit/generators/prerequisites_generator_spec.rb +0 -53
  88. data/spec/unit/generators/root_generator_spec.rb +0 -86
  89. data/spec/unit/generators/rspec_generator_spec.rb +0 -36
  90. data/spec/unit/generators/tasks_generator_spec.rb +0 -31
  91. data/spec/unit/generators/templates/cucumber_spec.rb +0 -97
  92. data/spec/unit/generators/templates/rspec_spec.rb +0 -88
  93. data/spec/unit/generators/templates/turnip_spec.rb +0 -98
  94. data/spec/unit/generators/turnip_generator_spec.rb +0 -52
  95. data/spec/unit/generators/web_generator_spec.rb +0 -52
  96. data/spec/unit/lib/cache_spec.rb +0 -85
  97. data/spec/unit/lib/capybara_helpers_spec.rb +0 -730
  98. data/spec/unit/lib/email_spec.rb +0 -186
  99. data/spec/unit/lib/gmail_api/client_spec.rb +0 -26
  100. data/spec/unit/lib/howitzer_spec.rb +0 -92
  101. data/spec/unit/lib/init_spec.rb +0 -2
  102. data/spec/unit/lib/log_spec.rb +0 -122
  103. data/spec/unit/lib/mail_adapters/abstract_spec.rb +0 -62
  104. data/spec/unit/lib/mail_adapters/gmail_spec.rb +0 -128
  105. data/spec/unit/lib/mail_adapters/mailgun_spec.rb +0 -158
  106. data/spec/unit/lib/mail_adapters/mailtrap_spec.rb +0 -130
  107. data/spec/unit/lib/mailgun_api/client_spec.rb +0 -80
  108. data/spec/unit/lib/mailgun_api/connector_spec.rb +0 -54
  109. data/spec/unit/lib/mailgun_api/response_spec.rb +0 -28
  110. data/spec/unit/lib/mailtrap_api/client_spec.rb +0 -67
  111. data/spec/unit/lib/meta/element_spec.rb +0 -59
  112. data/spec/unit/lib/meta/entry_spec.rb +0 -77
  113. data/spec/unit/lib/meta/iframe_spec.rb +0 -66
  114. data/spec/unit/lib/meta/section_spec.rb +0 -43
  115. data/spec/unit/lib/utils/string_extensions_spec.rb +0 -77
  116. data/spec/unit/lib/web/base_section_spec.rb +0 -43
  117. data/spec/unit/lib/web/element_dsl_spec.rb +0 -31
  118. data/spec/unit/lib/web/iframe_dsl_spec.rb +0 -203
  119. data/spec/unit/lib/web/page_dsl_spec.rb +0 -74
  120. data/spec/unit/lib/web/page_spec.rb +0 -385
  121. data/spec/unit/lib/web/page_validator_spec.rb +0 -276
  122. data/spec/unit/lib/web/section_dsl_spec.rb +0 -165
  123. data/spec/unit/lib/web/section_spec.rb +0 -70
  124. data/spec/unit/version_spec.rb +0 -8
@@ -1,158 +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
- before do
9
- allow(Howitzer).to receive(:mail_adapter) { 'mailgun' }
10
- Howitzer::Email.adapter = 'mailgun'
11
- end
12
- let(:recipient) { 'first_tester@gmail.com' }
13
- let(:message) do
14
- {
15
- 'body-plain' => 'test body footer',
16
- 'stripped-html' => '<p> test body </p> <p> footer </p>',
17
- 'stripped-text' => 'test body',
18
- 'From' => 'Strong Tester <tester@gmail.com>',
19
- 'To' => recipient,
20
- 'Received' => 'by 10.216.46.75 with HTTP; Sat, 5 Apr 2014 05:10:42 -0700 (PDT)',
21
- 'sender' => 'tester@gmail.com',
22
- 'attachments' => []
23
- }
24
- end
25
- let(:message_subject) { 'test subject' }
26
- let(:mail_address) { double }
27
- let(:email_object) { Howitzer::Email.adapter.new(message) }
28
-
29
- before do
30
- stub_const('Howitzer::Email::SUBJECT', message_subject)
31
- end
32
-
33
- describe '.find' do
34
- let(:mailgun_message) { JSON.generate(message) }
35
- let(:events) { JSON.generate('items' => [event]) }
36
- before do
37
- FakeWeb.register_uri(:any, 'https://api:mailgun_account_private_key@api.mailgun.net/v3/'\
38
- 'mailgun@test.domain/events?event=stored', body: events.to_s)
39
- FakeWeb.register_uri(:any, 'https://api:mailgun_account_private_key@si.api.mailgun.net/v3/'\
40
- 'domains/mg.strongqa.com/messages/1234567890', body: mailgun_message.to_s)
41
- end
42
- subject { Howitzer::MailAdapters::Mailgun.find(recipient, message_subject, wait: 0.01) }
43
-
44
- context 'when message is found' do
45
- let(:event) do
46
- {
47
- 'message' => {
48
- 'recipients' => [recipient],
49
- 'headers' => {
50
- 'subject' => message_subject
51
- }
52
- },
53
- 'storage' => {
54
- 'key' => '1234567890',
55
- 'url' => 'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
56
- }
57
- }
58
- end
59
- it do
60
- expect(Howitzer::Email.adapter).to receive(:new).with(message).once
61
- subject
62
- end
63
- end
64
-
65
- context 'when message is not found' do
66
- let(:event) do
67
- {
68
- 'message' => {
69
- 'recipients' => ['other@test.com'],
70
- 'headers' => {
71
- 'subject' => message_subject
72
- }
73
- },
74
- 'storage' => {
75
- 'key' => '1234567890',
76
- 'url' => 'https://si.api.mailgun.net/v3/domains/mg.strongqa.com/messages/1234567890'
77
- }
78
- }
79
- end
80
- it do
81
- expect { subject }.to raise_error(
82
- Howitzer::EmailNotFoundError,
83
- "Message with subject '#{message_subject}' for recipient '#{recipient}' was not found."
84
- )
85
- end
86
- end
87
- end
88
-
89
- describe '#plain_text_body' do
90
- it { expect(email_object.plain_text_body).to eql message['body-plain'] }
91
- end
92
-
93
- describe '#html_body' do
94
- it { expect(email_object.html_body).to eql message['stripped-html'] }
95
- end
96
-
97
- describe '#text' do
98
- it { expect(email_object.text).to eql message['stripped-text'] }
99
- end
100
-
101
- describe '#mail_from' do
102
- it { expect(email_object.mail_from).to eql message['From'] }
103
- end
104
-
105
- describe '#recipients' do
106
- subject { email_object.recipients }
107
- it { is_expected.to be_a_kind_of Array }
108
-
109
- context 'when one recipient' do
110
- it { is_expected.to include message['To'] }
111
- end
112
-
113
- context 'when more than one recipient' do
114
- let(:second_recipient) { 'second_tester@gmail.com' }
115
- let(:message_with_multiple_recipients) { message.merge('To' => "#{recipient}, #{second_recipient}") }
116
- let(:email_object) { Howitzer::Email.adapter.new(message_with_multiple_recipients) }
117
- it { is_expected.to eql [recipient, second_recipient] }
118
- end
119
- end
120
-
121
- describe '#received_time' do
122
- it { expect(email_object.received_time).to eql message['Received'][27..63] }
123
- end
124
-
125
- describe '#sender_email' do
126
- it { expect(email_object.sender_email).to eql message['sender'] }
127
- end
128
-
129
- describe '#mime_part' do
130
- subject { email_object.mime_part }
131
-
132
- context 'when has attachments' do
133
- let(:files) { [double] }
134
- before { email_object.instance_variable_set(:@message, 'attachments' => files) }
135
- it { is_expected.to eq(files) }
136
- end
137
-
138
- context 'when no attachments' do
139
- it { is_expected.to eq([]) }
140
- end
141
- end
142
-
143
- describe '#mime_part!' do
144
- subject { email_object.mime_part! }
145
-
146
- context 'when has attachments' do
147
- let(:files) { [double] }
148
- before { email_object.instance_variable_set(:@message, 'attachments' => files) }
149
- it { is_expected.to eq(files) }
150
- end
151
-
152
- context 'when no attachments' do
153
- it do
154
- expect { subject }.to raise_error(Howitzer::NoAttachmentsError, 'No attachments were found.')
155
- end
156
- end
157
- end
158
- end
@@ -1,130 +0,0 @@
1
- require 'spec_helper'
2
- require 'howitzer/email'
3
- require 'howitzer/log'
4
- require 'howitzer/exceptions'
5
- RSpec.describe 'Mailtrap Email Adapter' do
6
- before do
7
- allow(Howitzer).to receive(:mail_adapter) { 'mailtrap' }
8
- Howitzer::Email.adapter = 'mailtrap'
9
- allow(Howitzer).to receive(:mailtrap_inbox_id) { 777_777 }
10
- allow(Howitzer).to receive(:mailtrap_api_token) { 'fake_api_token' }
11
- base_url = 'https://mailtrap.io/api/v1/inboxes/777777/messages'
12
- stub_const('Howitzer::MailtrapApi::Client::BASE_URL', base_url.gsub('/messages', ''))
13
- FakeWeb.register_uri(:get, "#{base_url}/475265146/attachments", body: attachment.to_s)
14
- FakeWeb.register_uri(:get, "#{base_url}/32/attachments", body: '[]')
15
- FakeWeb.register_uri(:get, "#{base_url}?search=#{recipient}", body: "[#{message.to_s.gsub('=>', ':')}]")
16
- end
17
- let(:recipient) { 'test@mail.com' }
18
- let(:mail_subject) { 'Confirmation instructions' }
19
- let(:message) do
20
- {
21
- 'id' => 475_265_146,
22
- 'inbox_id' => 777_777,
23
- 'subject' => 'Confirmation instructions',
24
- 'sent_at' => '2017-07-18T08:55:49.389Z',
25
- 'from_email' => 'noreply@test.com',
26
- 'from_name' => '',
27
- 'to_email' => 'test@mail.com',
28
- 'to_name' => '',
29
- 'html_body' => '<p> Test Email! </p>',
30
- 'text_body' => 'Test Email!',
31
- 'created_at' => '2017-07-18T14:14:31.641Z'
32
- }
33
- end
34
- let(:attachment) do
35
- '[{
36
- "id": 1737,
37
- "message_id": 475265146,
38
- "filename": "Photos.png",
39
- "attachment_type": "attachment",
40
- "content_type": "image/png",
41
- "download_path": "/api/v1/inboxes/777777/messages/475265146/attachments/45120545/download"
42
- }]'
43
- end
44
- let(:email_object) { Howitzer::Email.adapter.new(message) }
45
- describe '.find' do
46
- subject { Howitzer::MailAdapters::Mailtrap.find(recipient, mail_subject, wait: 0.01) }
47
- context 'when message is found' do
48
- it do
49
- expect(Howitzer::Email.adapter).to receive(:new).with(message).once
50
- subject
51
- end
52
- end
53
-
54
- context 'when message is not found' do
55
- let(:mail_subject) { 'Wrong subject' }
56
- it do
57
- expect { subject }.to raise_error(
58
- Howitzer::EmailNotFoundError,
59
- "Message with subject '#{mail_subject}' for recipient '#{recipient}' was not found."
60
- )
61
- end
62
- end
63
- end
64
-
65
- describe '#plain_text_body' do
66
- it { expect(email_object.plain_text_body).to eql message['text_body'] }
67
- end
68
-
69
- describe '#html_body' do
70
- it { expect(email_object.html_body).to eql message['html_body'] }
71
- end
72
-
73
- describe '#text' do
74
- it { expect(email_object.text).to eql message['text_body'] }
75
- end
76
-
77
- describe '#mail_from' do
78
- it { expect(email_object.mail_from).to eql message['from_email'] }
79
- end
80
-
81
- describe '#recipients' do
82
- subject { email_object.recipients }
83
- it { is_expected.to be_a_kind_of Array }
84
-
85
- context 'when one recipient' do
86
- it { is_expected.to include message['to_email'] }
87
- end
88
-
89
- context 'when more than one recipient' do
90
- let(:second_recipient) { 'second_tester@gmail.com' }
91
- let(:message_with_multiple_recipients) { message.merge('to_email' => "#{recipient}, #{second_recipient}") }
92
- let(:email_object) { Howitzer::Email.adapter.new(message_with_multiple_recipients) }
93
- it { is_expected.to eql [recipient, second_recipient] }
94
- end
95
- end
96
-
97
- describe '#received_time' do
98
- it { expect(email_object.received_time).to eql Time.parse(message['created_at']).to_s }
99
- end
100
-
101
- describe '#sender_email' do
102
- it { expect(email_object.sender_email).to eql message['from_email'] }
103
- end
104
-
105
- describe '#mime_part' do
106
- context 'when has attachments' do
107
- it { expect(email_object.mime_part).not_to be_empty }
108
- end
109
-
110
- context 'when no attachments' do
111
- let(:another_message) { message.merge('id' => 32) }
112
- let(:email_object) { Howitzer::Email.adapter.new(another_message) }
113
- it { expect(email_object.mime_part).to be_empty }
114
- end
115
- end
116
-
117
- describe '#mime_part!' do
118
- context 'when has attachments' do
119
- it { expect(email_object.mime_part!).not_to be_empty }
120
- end
121
-
122
- context 'when no attachments' do
123
- let(:another_message) { message.merge('id' => 32) }
124
- let(:email_object) { Howitzer::Email.adapter.new(another_message) }
125
- it do
126
- expect { email_object.mime_part! }.to raise_error(Howitzer::NoAttachmentsError, 'No attachments were found.')
127
- end
128
- end
129
- end
130
- end
@@ -1,80 +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
- let(:bounce_msg) do
7
- JSON.generate(
8
- 'total_count' => 1,
9
- 'items' => {
10
- 'created_at' => 'Fri, 21 Oct 2011 11:02:55 GMT',
11
- 'code' => 550,
12
- 'address' => 'baz@example.com',
13
- 'error' => 'Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is" +
14
- " unavailable: user not found'
15
- }
16
- )
17
- end
18
- let(:message) do
19
- {
20
- 'body-plain' => 'test body footer',
21
- 'stripped-html' => '<p> test body </p> <p> footer </p>',
22
- 'stripped-text' => 'test body',
23
- 'From' => 'Strong Tester <tester@gmail.com>',
24
- 'To' => 'baz@example.com',
25
- 'Received' => 'by 10.216.46.75 with HTTP; Sat, 5 Apr 2014 05:10:42 -0700 (PDT)',
26
- 'sender' => 'tester@gmail.com',
27
- 'attachments' => []
28
- }
29
- end
30
- describe '.new' do
31
- subject { mg_obj }
32
- it { expect { subject }.not_to raise_error }
33
- end
34
-
35
- describe '#get' do
36
- let(:query_string) { { 'skip' => '10', 'limit' => '5' } }
37
- subject { mg_obj.get('test.com/bounces', params: query_string) }
38
- context 'when simulation of client' do
39
- before do
40
- FakeWeb.register_uri(:get, 'https://api:Fake-API-Key@api.mailgun.net/v3/test.com/'\
41
- 'bounces?skip=10&limit=5', body: bounce_msg.to_s)
42
- end
43
- it do
44
- expect(subject.body).to include('total_count')
45
- expect(subject.body).to include('items')
46
- end
47
- end
48
- context 'when real client' do
49
- let(:resource) { double }
50
- before do
51
- allow(resource).to receive('[]').and_return(resource)
52
- allow(resource).to receive(:get).and_raise(StandardError, '401 Unauthorized: Forbidden')
53
- allow(RestClient::Resource).to receive(:new).and_return(resource)
54
- end
55
- it do
56
- expect { subject }.to raise_error(Howitzer::CommunicationError, '401 Unauthorized: Forbidden')
57
- end
58
- end
59
- end
60
-
61
- describe '#get_url' do
62
- let(:response_raw) { double }
63
- before do
64
- FakeWeb.register_uri(:any, 'https://api:Fake-API-Key@ci.api.mailgan.com/'\
65
- 'domains/test_domain/messages/asdfasdf', body: JSON.generate(message))
66
- end
67
- subject { mg_obj.get_url('https://ci.api.mailgan.com/domains/test_domain/messages/asdfasdf') }
68
- context 'when success request' do
69
- it { expect(subject.to_h).to eq(message) }
70
- end
71
- context 'when error happens' do
72
- before do
73
- allow(RestClient::Resource).to receive(:new).with(any_args).and_return(response_raw)
74
- mg_obj
75
- allow(RestClient::Request).to receive(:execute).with(any_args).and_raise(StandardError, 'Some message')
76
- end
77
- it { expect { subject }.to raise_error(Howitzer::CommunicationError, 'Some message') }
78
- end
79
- end
80
- 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
@@ -1,28 +0,0 @@
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
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
- require 'howitzer/mailtrap_api/client'
3
-
4
- RSpec.describe Howitzer::MailtrapApi::Client do
5
- let(:mailtrap_obj) { described_class.new }
6
- let(:recipient) { 'test@mail.com' }
7
- let(:mail_subject) { 'Confirmation instructions' }
8
- let(:message) do
9
- '[{"id": 475265146,
10
- "inbox_id": 777777,
11
- "subject": "Confirmation instructions",
12
- "sent_at": "2017-07-18T08:55:49.389Z",
13
- "from_email": "noreply@test.com",
14
- "from_name": "",
15
- "to_email": "test@mail.com",
16
- "to_name": "",
17
- "html_body": "<p> Test Email! </p>"}]'
18
- end
19
- let(:attachment) do
20
- '[{
21
- "id": 1737,
22
- "message_id": 475265146,
23
- "filename": "Photos.png",
24
- "attachment_type": "attachment",
25
- "content_type": "image/png"
26
- }]'
27
- end
28
- before do
29
- allow(Howitzer).to receive(:mailtrap_inbox_id) { 777_777 }
30
- allow(Howitzer).to receive(:mailtrap_api_token) { 'fake_api_token' }
31
- stub_const('Howitzer::MailtrapApi::Client::BASE_URL', 'https://mailtrap.io/api/v1/inboxes/777777')
32
- end
33
-
34
- describe '.new' do
35
- subject { mailtrap_obj }
36
- it { expect { subject }.not_to raise_error }
37
- end
38
-
39
- describe '#find_message' do
40
- before do
41
- FakeWeb.register_uri(:get, "https://mailtrap.io/api/v1/inboxes/#{Howitzer.mailtrap_inbox_id}/"\
42
- "messages?search=#{recipient}", body: message.to_s)
43
- end
44
- subject { described_class.new.find_message(recipient, mail_subject) }
45
- it do
46
- expect(subject['to_email']).to eql(recipient)
47
- expect(subject['subject']).to eql(mail_subject)
48
- end
49
- end
50
-
51
- describe '#find_attachements' do
52
- before do
53
- FakeWeb.register_uri(:get, "https://mailtrap.io/api/v1/inboxes/#{Howitzer.mailtrap_inbox_id}/"\
54
- "messages?search=#{recipient}", body: message.to_s)
55
- FakeWeb.register_uri(:get, "https://mailtrap.io/api/v1/inboxes/#{Howitzer.mailtrap_inbox_id}/"\
56
- 'messages/475265146/attachments', body: attachment.to_s)
57
- end
58
- let(:found_message) { described_class.new.find_message(recipient, mail_subject) }
59
- subject { described_class.new.find_attachments(found_message) }
60
- it do
61
- subject.each do |attachment|
62
- expect(attachment['message_id']).to eql found_message['id']
63
- expect(attachment['filename'].to_s).not_to be_empty
64
- end
65
- end
66
- end
67
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
- require 'howitzer/meta/element'
3
-
4
- RSpec.describe Howitzer::Meta::Element do
5
- let(:context) { double }
6
- let(:name) { 'foo' }
7
- let(:element) { described_class.new(name, context) }
8
-
9
- describe '.new' do
10
- it { expect(element.context).to eq(context) }
11
- it { expect(element.name).to eq('foo') }
12
- end
13
-
14
- describe '#capybara_elements' do
15
- context 'without arguments' do
16
- subject { element.capybara_elements }
17
- it do
18
- expect(context).to receive(:send).with("#{name}_elements")
19
- subject
20
- end
21
- end
22
- context 'whith custom arguments' do
23
- subject { element.capybara_elements('test', text: 'test', wait: 5) }
24
- it do
25
- expect(context).to receive(:send).with("#{name}_elements", 'test', text: 'test', wait: 5)
26
- subject
27
- end
28
- end
29
- end
30
-
31
- describe '#capybara_element' do
32
- subject { element.capybara_element }
33
- context 'when element is present' do
34
- context 'with default arguments' do
35
- it do
36
- expect(context).to receive(:send).with("#{name}_element", match: :first, wait: 0)
37
- subject
38
- end
39
- end
40
- context 'with custom arguments' do
41
- subject { element.capybara_element('test', { text: 'test' }, wait: 5) }
42
- it do
43
- expect(context).to receive(:send).with("#{name}_element", 'test', text: 'test', match: :first, wait: 5)
44
- subject
45
- end
46
- end
47
- end
48
- context 'when element is not found' do
49
- before do
50
- allow(context).to receive(:send).with("#{name}_element", match: :first, wait: 0) do
51
- raise Capybara::ElementNotFound
52
- end
53
- end
54
- it { is_expected.to be_nil }
55
- end
56
- end
57
-
58
- include_examples :meta_highlight_xpath
59
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
- require 'howitzer/meta/entry'
3
-
4
- RSpec.describe Howitzer::Meta::Entry do
5
- let(:klass) do
6
- Class.new do
7
- include Howitzer::Web::ElementDsl
8
- def capybara_scopes
9
- @capybara_scopes ||= Hash.new { |hash, key| hash[key] = [Capybara.current_session] }
10
- @capybara_scopes[Howitzer.session_name]
11
- end
12
-
13
- def foo_section; end
14
-
15
- def bar_section; end
16
-
17
- def foo_sections; end
18
-
19
- def bar_sections; end
20
-
21
- def foo_iframe; end
22
-
23
- def bar_iframe; end
24
-
25
- def has_foo_iframe?; end
26
-
27
- def has_bar_iframe?; end
28
- end
29
- end
30
- let(:klass_object) { klass.new }
31
-
32
- before do
33
- klass.class_eval do
34
- element :foo, :xpath, '//a'
35
- element :bar, '#bar'
36
- end
37
- end
38
-
39
- describe '.new' do
40
- let(:context) { klass.new }
41
- subject { described_class.new(context) }
42
- it { expect(subject.context).to eq(context) }
43
- end
44
-
45
- describe '#elements' do
46
- subject { described_class.new(klass.new).elements }
47
- it { expect(subject.map(&:name)).to contain_exactly('foo', 'bar') }
48
- it { expect(subject.count).to eq(2) }
49
- end
50
-
51
- describe '#element' do
52
- subject { described_class.new(klass.new).element('foo') }
53
- it { expect(subject.name).to eq('foo') }
54
- end
55
-
56
- describe '#sections' do
57
- subject { described_class.new(klass.new).sections }
58
- it { expect(subject.map(&:name)).to contain_exactly('foo', 'bar') }
59
- it { expect(subject.count).to eq(2) }
60
- end
61
-
62
- describe '#section' do
63
- subject { described_class.new(klass.new).section('foo') }
64
- it { expect(subject.name).to eq('foo') }
65
- end
66
-
67
- describe '#iframes' do
68
- subject { described_class.new(klass.new).iframes }
69
- it { expect(subject.map(&:name)).to contain_exactly('foo', 'bar') }
70
- it { expect(subject.count).to eq(2) }
71
- end
72
-
73
- describe '#iframe' do
74
- subject { described_class.new(klass.new).iframe('foo') }
75
- it { expect(subject.name).to eq('foo') }
76
- end
77
- end