howitzer 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.travis.yml +3 -2
  4. data/CHANGELOG.md +25 -5
  5. data/GETTING_STARTED.md +158 -13
  6. data/README.md +49 -32
  7. data/Rakefile +10 -1
  8. data/bin/howitzer +49 -78
  9. data/features/cli_help.feature +30 -0
  10. data/features/cli_new.feature +263 -0
  11. data/features/cli_unknown.feature +17 -0
  12. data/features/cli_version.feature +14 -0
  13. data/features/step_definitions/common_steps.rb +1 -0
  14. data/features/support/env.rb +1 -0
  15. data/features/support/transformers.rb +3 -0
  16. data/generators/base_generator.rb +2 -0
  17. data/generators/config/config_generator.rb +1 -1
  18. data/generators/config/templates/default.yml +4 -14
  19. data/generators/cucumber/cucumber_generator.rb +1 -1
  20. data/generators/cucumber/templates/cucumber.yml +1 -2
  21. data/generators/cucumber/templates/env.rb +8 -7
  22. data/generators/emails/emails_generator.rb +1 -1
  23. data/generators/pages/pages_generator.rb +1 -1
  24. data/generators/pages/templates/example_page.rb +2 -2
  25. data/generators/root/root_generator.rb +1 -1
  26. data/generators/root/templates/Gemfile +1 -1
  27. data/generators/rspec/rspec_generator.rb +1 -1
  28. data/generators/rspec/templates/example_spec.rb +2 -2
  29. data/generators/rspec/templates/rspec.rake +1 -1
  30. data/generators/rspec/templates/spec_helper.rb +6 -5
  31. data/generators/tasks/tasks_generator.rb +1 -1
  32. data/generators/tasks/templates/common.rake +1 -0
  33. data/howitzer.gemspec +8 -8
  34. data/lib/howitzer.rb +4 -1
  35. data/lib/howitzer/blank_page.rb +6 -0
  36. data/lib/howitzer/capybara/dsl_ex.rb +15 -0
  37. data/lib/howitzer/capybara/settings.rb +267 -0
  38. data/lib/howitzer/email.rb +134 -0
  39. data/lib/howitzer/exceptions.rb +18 -0
  40. data/lib/howitzer/helpers.rb +34 -23
  41. data/lib/howitzer/init.rb +1 -4
  42. data/lib/howitzer/mailgun/client.rb +48 -0
  43. data/lib/howitzer/mailgun/connector.rb +34 -0
  44. data/lib/howitzer/mailgun/response.rb +28 -0
  45. data/lib/howitzer/utils.rb +2 -2
  46. data/lib/howitzer/utils/data_generator/data_storage.rb +15 -2
  47. data/lib/howitzer/utils/data_generator/gen.rb +14 -10
  48. data/lib/howitzer/utils/locator_store.rb +14 -7
  49. data/lib/howitzer/utils/log.rb +2 -0
  50. data/lib/howitzer/utils/page_validator.rb +74 -27
  51. data/lib/howitzer/version.rb +1 -1
  52. data/lib/howitzer/web_page.rb +83 -32
  53. data/spec/config/default.yml +10 -12
  54. data/spec/spec_helper.rb +12 -0
  55. data/spec/support/mailgun_unit_client.rb +60 -0
  56. data/spec/unit/generators/generators_spec.rb +7 -7
  57. data/spec/unit/lib/capybara/dsl_ex_spec.rb +60 -0
  58. data/spec/unit/lib/{capybara_settings_spec.rb → capybara/settings_spec.rb} +16 -10
  59. data/spec/unit/lib/email_spec.rb +129 -0
  60. data/spec/unit/lib/helpers_spec.rb +160 -34
  61. data/spec/unit/lib/init_spec.rb +1 -12
  62. data/spec/unit/lib/mailgun/client_spec.rb +36 -0
  63. data/spec/unit/lib/mailgun/connector_spec.rb +70 -0
  64. data/spec/unit/lib/mailgun/response_spec.rb +29 -0
  65. data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +23 -5
  66. data/spec/unit/lib/utils/data_generator/gen_spec.rb +2 -63
  67. data/spec/unit/lib/utils/locator_store_spec.rb +41 -6
  68. data/spec/unit/lib/utils/log_spec.rb +1 -1
  69. data/spec/unit/lib/utils/page_validator_spec.rb +149 -25
  70. data/spec/unit/lib/web_page_spec.rb +127 -53
  71. metadata +102 -142
  72. data/lib/howitzer/utils/capybara_patched.rb +0 -23
  73. data/lib/howitzer/utils/capybara_settings.rb +0 -247
  74. data/lib/howitzer/utils/email/email.rb +0 -85
  75. data/lib/howitzer/utils/email/mail_client.rb +0 -132
  76. data/lib/howitzer/utils/email/mailgun.rb +0 -175
  77. data/lib/howitzer/utils/email/mailgun_helper.rb +0 -61
  78. data/spec/unit/bin/howitzer_spec.rb +0 -175
  79. data/spec/unit/lib/utils/email/email_spec.rb +0 -75
  80. data/spec/unit/lib/utils/email/mail_client_spec.rb +0 -115
  81. data/spec/unit/lib/utils/email/mailgun_helper_spec.rb +0 -95
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,11 @@ require 'ffaker'
6
6
  require 'capybara'
7
7
  require 'json'
8
8
  require 'capybara/dsl'
9
+ require 'active_support'
10
+ require 'active_support/core_ext'
11
+ require 'repeater'
12
+ require 'howitzer/exceptions'
13
+ require 'howitzer/utils/log'
9
14
 
10
15
  SimpleCov.start do
11
16
  add_filter "/spec/"
@@ -27,6 +32,13 @@ RSpec.configure do |config|
27
32
  config.mock_with :rspec do |c|
28
33
  c.syntax = :expect
29
34
  end
35
+ config.around(:each) do |ex|
36
+ $stdout = StringIO.new
37
+ $stderr = StringIO.new
38
+ ex.run
39
+ $stdout = STDOUT
40
+ $stderr = STDERR
41
+ end
30
42
  end
31
43
 
32
44
  def project_path
@@ -0,0 +1,60 @@
1
+ require "time"
2
+ require "json"
3
+ require 'howitzer/exceptions'
4
+
5
+ module Mailgun
6
+ class UnitClient
7
+
8
+ attr_reader :url, :options, :block, :body, :code
9
+
10
+ def initialize(url, options={}, backwards_compatibility=nil, &block)
11
+ @url = url
12
+ @block = block
13
+ @options = options
14
+ @body = nil
15
+ @code = nil
16
+ end
17
+
18
+ def [](resource_path, &new_block)
19
+ case
20
+ when block_given? then self.class.new(resource_path, options, &new_block)
21
+ when block then self.class.new(resource_path, options, &block)
22
+ else
23
+ self.class.new(resource_path, options)
24
+ end
25
+ end
26
+
27
+ def get(options, query_string = nil)
28
+ begin
29
+ if query_string
30
+
31
+ response = response_generator("bounces")
32
+ else
33
+ response = response_generator("bounces")
34
+ end
35
+ Response.new(response)
36
+ rescue Exception => e
37
+ log.error Howitzer::CommunicationError.new(e), e.response
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def response_generator(resource_endpoint)
44
+ case resource_endpoint
45
+ when "messages"
46
+ t = Time.now
47
+ id = "<#{t.to_i}.#{rand(99999999)}.5817@example.com>"
48
+ @body = JSON.generate({"message" => "Queued. Thank you.", "id" => id})
49
+ when "bounces"
50
+ @body = JSON.generate({"total_count" => 1, "items" => {"created_at" => "Fri, 21 Oct 2011 11:02:55 GMT", "code" => 550, "address" => "baz@example.com", "error" => "Message was not accepted -- invalid mailbox. Local mailbox baz@example.com is unavailable: user not found"}})
51
+ when "lists"
52
+ @body = JSON.generate({"member" => {"vars" => {"age" => 26}, "name" => "Foo Bar", "subscribed" => false, "address" => "bar@example.com"}, "message" => "Mailing list member has been updated"})
53
+ when "campaigns"
54
+ @body = JSON.generate({"message" => "Campaign has been deleted", "id" => "ABC123"})
55
+ end
56
+ self
57
+ end
58
+ end
59
+
60
+ end
@@ -28,7 +28,7 @@ describe "Generators" do
28
28
  it { expect(subject).to eql(expected_result) }
29
29
  describe "output" do
30
30
  let(:expected_output) do
31
- " Creates config files.
31
+ " * Config files generation ...
32
32
  Added 'config/custom.yml' file
33
33
  Added 'config/default.yml' file\n"
34
34
  end
@@ -48,7 +48,7 @@ describe "Generators" do
48
48
  it { expect(subject).to eql(expected_result) }
49
49
  describe "output" do
50
50
  let(:expected_output) do
51
- " Creates PageOriented pattern structure
51
+ " * PageOriented pattern structure generation ...
52
52
  Added 'pages/example_page.rb' file
53
53
  Added 'pages/example_menu.rb' file\n"
54
54
  end
@@ -67,7 +67,7 @@ describe "Generators" do
67
67
  it { expect(subject).to eql(expected_result) }
68
68
  describe "output" do
69
69
  let(:expected_output) do
70
- " Creates RAKE tasks folder and file.
70
+ " * Base rake task generation ...
71
71
  Added 'tasks/common.rake' file\n"
72
72
  end
73
73
  subject { output.string }
@@ -85,7 +85,7 @@ describe "Generators" do
85
85
  it { expect(subject).to eql(expected_result) }
86
86
  describe "output" do
87
87
  let(:expected_output) do
88
- " Creates a simple email class.\"
88
+ " * Email example generation ...
89
89
  Added '/emails/example_email.rb' file\n"
90
90
  end
91
91
  subject { output.string }
@@ -104,7 +104,7 @@ describe "Generators" do
104
104
  it { expect(subject).to eql(expected_result) }
105
105
  describe "output" do
106
106
  let(:expected_output) do
107
- " Creates root config files.
107
+ " * Root files generation ...
108
108
  Added '.gitignore' file
109
109
  Added 'Gemfile' file
110
110
  Added 'Rakefile' file
@@ -134,7 +134,7 @@ describe "Generators" do
134
134
  it { expect(subject).to eql(expected_result) }
135
135
  describe "output" do
136
136
  let(:expected_output) do
137
- " Integrates Cucumber to the framework
137
+ " * Cucumber integration to the framework ...
138
138
  Added 'features/step_definitions/common_steps.rb' file
139
139
  Added 'features/support/env.rb' file
140
140
  Added 'features/support/transformers.rb' file
@@ -160,7 +160,7 @@ describe "Generators" do
160
160
  it { expect(subject).to eql(expected_result) }
161
161
  describe "output" do
162
162
  let(:expected_output) do
163
- " Integrates RSpec to the framework.
163
+ " * RSpec integration to the framework ...
164
164
  Added 'spec/spec_helper.rb' file
165
165
  Added 'spec/example_spec.rb' file
166
166
  Added 'tasks/rspec.rake' file\n"
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'howitzer/capybara/dsl_ex'
3
+
4
+ describe Howitzer::Capybara::DslEx do
5
+ let(:test_page_klass) do
6
+ Class.new do
7
+ include Howitzer::Capybara::DslEx
8
+ extend Howitzer::Capybara::DslEx
9
+ end
10
+ end
11
+ let(:test_page) { test_page_klass.new }
12
+
13
+ describe "#find" do
14
+ context "when string argument with block" do
15
+ subject { test_page.find('foo'){ 'bar' } }
16
+ it do
17
+ expect(test_page.page).to receive(:find).with('foo').and_yield.once
18
+ subject
19
+ end
20
+ end
21
+ context "when first hash argument and second hash" do
22
+ subject { test_page.find({xpath: '//bar'}, {with: 'foo'}) }
23
+ it do
24
+ expect(test_page.page).to receive(:find).with(:xpath, '//bar', {:with=>"foo"}).once
25
+ subject
26
+ end
27
+ end
28
+ context "when array argument" do
29
+ subject { test_page.find([:xpath, '//bar']) }
30
+ it do
31
+ expect(test_page.page).to receive(:find).with(:xpath, '//bar').once
32
+ subject
33
+ end
34
+ end
35
+ end
36
+
37
+ describe ".find" do
38
+ context "when string argument with block" do
39
+ subject { test_page_klass.find('foo'){ 'bar' } }
40
+ it do
41
+ expect(test_page.page).to receive(:find).with('foo').and_yield.once
42
+ subject
43
+ end
44
+ end
45
+ context "when first hash argument and second hash" do
46
+ subject { test_page_klass.find({xpath: '//bar'}, {with: 'foo'}) }
47
+ it do
48
+ expect(test_page.page).to receive(:find).with(:xpath, '//bar', {:with=>"foo"}).once
49
+ subject
50
+ end
51
+ end
52
+ context "when array argument" do
53
+ subject { test_page_klass.find([:xpath, '//bar']) }
54
+ it do
55
+ expect(test_page.page).to receive(:find).with(:xpath, '//bar').once
56
+ subject
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,10 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- require "#{lib_path}/howitzer/utils/capybara_settings"
3
+ require 'howitzer/capybara/settings'
4
4
 
5
5
  describe "CapybaraSettings" do
6
+ it "supports deprecated module name" do
7
+ expect { CapybaraSettings }.to_not raise_error
8
+ expect(CapybaraSettings).to eq(Capybara::Settings)
9
+ end
10
+ end
11
+
12
+ describe "Capybara::Settings" do
6
13
  let(:log) { double("log") }
7
- let(:test_object) { double("test_object").extend(CapybaraSettings) }
14
+ let(:test_object) { double("test_object").extend(Capybara::Settings) }
8
15
  before do
9
16
  allow(log).to receive(:error).and_return( true )
10
17
  end
@@ -12,21 +19,20 @@ describe "CapybaraSettings" do
12
19
  describe "#sauce_resource_path" do
13
20
  subject { test_object.sauce_resource_path(name) }
14
21
  let (:name) { "test_name" }
15
- before do
22
+ before do
16
23
  allow(settings).to receive(:sl_user) { "vlad" }
17
24
  allow(settings).to receive(:sl_api_key) { "11111" }
18
25
  allow(test_object).to receive(:session_id) { '12341234' }
19
26
  end
20
-
21
27
  it { expect(subject).to eql("https://vlad:11111@saucelabs.com/rest/vlad/jobs/12341234/results/test_name") }
22
28
  end
23
29
  describe ".sauce_resource_path" do
24
- subject { CapybaraSettings.sauce_resource_path(name) }
30
+ subject { Capybara::Settings.sauce_resource_path(name) }
25
31
  let (:name) { "test_name" }
26
32
  before do
27
33
  allow(settings).to receive(:sl_user) { "vlad" }
28
34
  allow(settings).to receive(:sl_api_key) { "11111" }
29
- allow(CapybaraSettings).to receive(:session_id) { '12341234' }
35
+ allow(Capybara::Settings).to receive(:session_id) { '12341234' }
30
36
  end
31
37
 
32
38
  it { expect(subject).to eql("https://vlad:11111@saucelabs.com/rest/vlad/jobs/12341234/results/test_name") }
@@ -48,11 +54,11 @@ describe "CapybaraSettings" do
48
54
  end
49
55
 
50
56
  describe ".update_sauce_resource_path" do
51
- subject { CapybaraSettings.update_sauce_job_status }
57
+ subject { Capybara::Settings.update_sauce_job_status }
52
58
  before do
53
59
  allow(settings).to receive(:sl_user) { "vlad1" }
54
60
  allow(settings).to receive(:sl_api_key) { "22222" }
55
- allow(CapybaraSettings).to receive(:session_id) { '12341234' }
61
+ allow(Capybara::Settings).to receive(:session_id) { '12341234' }
56
62
  stub_const("RestClient", double)
57
63
  end
58
64
 
@@ -99,7 +105,7 @@ describe "CapybaraSettings" do
99
105
  end
100
106
 
101
107
  describe ".suite_name" do
102
- subject { CapybaraSettings.suite_name }
108
+ subject { Capybara::Settings.suite_name }
103
109
  before do
104
110
  allow(settings).to receive(:sl_browser_name) { 'ie' }
105
111
  end
@@ -152,7 +158,7 @@ describe "CapybaraSettings" do
152
158
  end
153
159
 
154
160
  describe ".session_id" do
155
- subject { CapybaraSettings.session_id }
161
+ subject { Capybara::Settings.session_id }
156
162
  before do
157
163
  browser = double
158
164
  current_session = double
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+ require "howitzer/email"
3
+ require "howitzer/utils/log"
4
+ require 'howitzer/exceptions'
5
+
6
+ describe "Email" do
7
+ let(:recipient){ 'first_tester@gmail.com' }
8
+ let(:message) do
9
+ {
10
+ 'body-plain' => 'test body footer',
11
+ 'stripped-html' => "<p> test body </p> <p> footer </p>",
12
+ 'stripped-text' => 'test body',
13
+ 'From' => "Strong Tester <tester@gmail.com>",
14
+ 'To' => recipient,
15
+ 'Received' => "by 10.216.46.75 with HTTP; Sat, 5 Apr 2014 05:10:42 -0700 (PDT)",
16
+ 'sender' => 'tester@gmail.com',
17
+ 'attachments' => []
18
+ }
19
+ end
20
+ let(:message_subject){ 'test subject' }
21
+ let(:mail_address){ double }
22
+ let(:email_object){ Email.new(message) }
23
+ before do
24
+ stub_const('Email::SUBJECT', message_subject)
25
+ end
26
+
27
+ describe '#new' do
28
+ context 'when Email instance receive message and add create @message variable that' do
29
+ it { expect(email_object.instance_variable_get(:@message)).to eql message}
30
+ end
31
+ end
32
+
33
+ describe '.find_by_recipient' do
34
+ let(:recipient) { 'test@user.com' }
35
+ subject { Email.find_by_recipient(recipient) }
36
+ it do
37
+ expect(Email).to receive(:find).with(recipient, message_subject).once
38
+ subject
39
+ end
40
+ end
41
+
42
+ describe '.find' do
43
+ let(:mailgun_message){ double(to_h: message) }
44
+ let(:events) { double(to_h: {'items' => [event]}) }
45
+ subject { Email.find(recipient, message_subject) }
46
+ context "when message is found" do
47
+ let(:event) { {'message' => {'recipients' => [recipient], 'headers' => {'subject' => message_subject} }, 'storage' => {'key' => '1234567890'} } }
48
+ before do
49
+ allow(Mailgun::Connector.instance.client).to receive(:get).with("mailgun@test.domain/events", event: 'stored').ordered.once {events}
50
+ allow(Mailgun::Connector.instance.client).to receive(:get).with("domains/mailgun@test.domain/messages/1234567890").ordered.once { mailgun_message }
51
+ end
52
+ it do
53
+ expect(Email).to receive(:new).with(message).once
54
+ subject
55
+ end
56
+ end
57
+ context "when message is not found" do
58
+ let(:event) { {'message' => {'recipients' => ["other@test.com"], 'headers' => {'subject' => message_subject} }, 'storage' => {'key' => '1234567890'} } }
59
+ before do
60
+ allow(settings).to receive(:timeout_small) { 0.5 }
61
+ allow(settings).to receive(:timeout_short) { 0.05 }
62
+ allow(Mailgun::Connector.instance.client).to receive(:get).with("mailgun@test.domain/events", event: 'stored').at_least(:twice).ordered {events}
63
+ end
64
+ it do
65
+ expect(log).to receive(:error).with(Howitzer::EmailNotFoundError, "Message with subject '#{message_subject}' for recipient '#{recipient}' was not found.")
66
+ subject
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '#plain_text_body' do
72
+ it { expect(email_object.plain_text_body).to eql message['body-plain'] }
73
+ end
74
+
75
+ describe '#html_body' do
76
+ it { expect(email_object.html_body).to eql message['stripped-html'] }
77
+ end
78
+
79
+ describe '#text' do
80
+ it { expect(email_object.text).to eql message['stripped-text'] }
81
+ end
82
+
83
+ describe '#mail_from' do
84
+ it { expect(email_object.mail_from).to eql message['From'] }
85
+ end
86
+
87
+ describe '#recipients' do
88
+ subject { email_object.recipients }
89
+ it { expect(subject).to be_a_kind_of Array }
90
+
91
+ context 'when one recipient' do
92
+ it { expect(subject).to include message['To']}
93
+ end
94
+
95
+ context 'when more than one recipient' do
96
+ let(:second_recipient) { "second_tester@gmail.com" }
97
+ let(:message_with_multiple_recipients) { message.merge({'To' => "#{recipient}, #{second_recipient}"}) }
98
+ let(:email_object) { Email.new(message_with_multiple_recipients) }
99
+ it { expect(subject).to eql [recipient, second_recipient] }
100
+ end
101
+ end
102
+
103
+ describe '#received_time' do
104
+ it { expect(email_object.received_time).to eql message['Received'][27..63] }
105
+ end
106
+
107
+ describe '#sender_email' do
108
+ it { expect(email_object.sender_email).to eql message['sender'] }
109
+ end
110
+
111
+ describe '#get_mime_part' do
112
+ subject { email_object.get_mime_part }
113
+
114
+ context 'when has attachments' do
115
+ let(:files) { [double] }
116
+ before { email_object.instance_variable_set(:@message, 'attachments' => files)}
117
+ it { expect(subject).to eq(files) }
118
+ end
119
+
120
+ context 'when no attachments' do
121
+ let(:error) { Howitzer::NoAttachmentsError }
122
+ let(:error_message) { 'No attachments where found.' }
123
+ it do
124
+ expect(log).to receive(:error).with(error, error_message).once
125
+ subject
126
+ end
127
+ end
128
+ end
129
+ end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'active_support/core_ext'
3
- require "#{lib_path}/howitzer/helpers"
2
+ require "howitzer/helpers"
4
3
 
5
4
  describe "Helpers" do
6
5
  let(:settings) { double("settings")}
@@ -22,7 +21,10 @@ describe "Helpers" do
22
21
  end
23
22
  context "when driver is not specified" do
24
23
  let(:driver_setting) { nil }
25
- it { expect {subject}.to raise_error(DriverNotSpecified, "Please check your settings") }
24
+ it do
25
+ expect(log).to receive(:error).with(Howitzer::DriverNotSpecifiedError, "Please check your settings").once.and_call_original
26
+ expect { subject }.to raise_error(Howitzer::DriverNotSpecifiedError)
27
+ end
26
28
  end
27
29
  end
28
30
 
@@ -43,7 +45,34 @@ describe "Helpers" do
43
45
  end
44
46
  context "when driver is not specified" do
45
47
  let(:driver_setting) { nil }
46
- it { expect {subject}.to raise_error(DriverNotSpecified, "Please check your settings") }
48
+ it do
49
+ expect(log).to receive(:error).with(Howitzer::DriverNotSpecifiedError, "Please check your settings").once.and_call_original
50
+ expect { subject }.to raise_error(Howitzer::DriverNotSpecifiedError)
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "#phantomjs_driver?" do
56
+ subject { phantomjs_driver? }
57
+ before { allow(settings).to receive(:driver) { driver_setting } }
58
+ context "when :phantomjs" do
59
+ let(:driver_setting) {:phantomjs}
60
+ it{ expect(subject).to be_true }
61
+ end
62
+ context "when not :phantomjs" do
63
+ let(:driver_setting) {:selenium}
64
+ it{ expect(subject).to be_false }
65
+ end
66
+ context "when driver specified as String" do
67
+ let(:driver_setting) {"phantomjs"}
68
+ it{ expect(subject).to be_true }
69
+ end
70
+ context "when driver is not specified" do
71
+ let(:driver_setting) { nil }
72
+ it do
73
+ expect(log).to receive(:error).with(Howitzer::DriverNotSpecifiedError, "Please check your settings").once.and_call_original
74
+ expect { subject }.to raise_error(Howitzer::DriverNotSpecifiedError)
75
+ end
47
76
  end
48
77
  end
49
78
 
@@ -64,7 +93,10 @@ describe "Helpers" do
64
93
  end
65
94
  context "when driver is not specified" do
66
95
  let(:driver_setting) { nil }
67
- it { expect {subject}.to raise_error(DriverNotSpecified, "Please check your settings") }
96
+ it do
97
+ expect(log).to receive(:error).with(Howitzer::DriverNotSpecifiedError, "Please check your settings").once.and_call_original
98
+ expect { subject }.to raise_error(Howitzer::DriverNotSpecifiedError)
99
+ end
68
100
  end
69
101
  end
70
102
 
@@ -89,7 +121,10 @@ describe "Helpers" do
89
121
  end
90
122
  context "settings.sl_browser_name is not specified" do
91
123
  before { allow(settings).to receive(:sl_browser_name) { nil } }
92
- it { expect {subject}.to raise_error(SlBrowserNameNotSpecified, "Please check your settings") }
124
+ it do
125
+ expect(log).to receive(:error).with(Howitzer::SlBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
126
+ expect { subject }.to raise_error(Howitzer::SlBrowserNotSpecifiedError)
127
+ end
93
128
  end
94
129
  end
95
130
  context "when sauce_driver? is FALSE" do
@@ -112,7 +147,10 @@ describe "Helpers" do
112
147
  end
113
148
  context "settings.sel_browser is not specified" do
114
149
  before { allow(settings).to receive(:sel_browser) { nil } }
115
- it { expect {subject}.to raise_error(SelBrowserNotSpecified, "Please check your settings") }
150
+ it do
151
+ expect(log).to receive(:error).with(Howitzer::SelBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
152
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError)
153
+ end
116
154
  end
117
155
  end
118
156
  context "when selenium_driver? is FALSE" do
@@ -147,7 +185,10 @@ describe "Helpers" do
147
185
  end
148
186
  context "settings.tb_browser_name is not specified" do
149
187
  before { allow(settings).to receive(:tb_browser_name) { nil } }
150
- it { expect{subject}.to raise_error(TbBrowserNameNotSpecified, "Please check your settings") }
188
+ it do
189
+ expect(log).to receive(:error).with(Howitzer::TbBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
190
+ expect { subject }.to raise_error(Howitzer::TbBrowserNotSpecifiedError)
191
+ end
151
192
  end
152
193
  end
153
194
  context "when testingbot_driver? is FALSE" do
@@ -169,7 +210,10 @@ describe "Helpers" do
169
210
  end
170
211
  context "settings.sl_browser_name is not specified" do
171
212
  before { allow(settings).to receive(:sl_browser_name) { nil } }
172
- it { expect {subject}.to raise_error(SlBrowserNameNotSpecified, "Please check your settings") }
213
+ it do
214
+ expect(log).to receive(:error).with(Howitzer::SlBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
215
+ expect { subject }.to raise_error(Howitzer::SlBrowserNotSpecifiedError)
216
+ end
173
217
  end
174
218
  end
175
219
  end
@@ -193,7 +237,10 @@ describe "Helpers" do
193
237
  end
194
238
  context "settings.sel_browser is not specified" do
195
239
  before { allow(settings).to receive(:sel_browser) { nil } }
196
- it { expect {subject}.to raise_error(SelBrowserNotSpecified, "Please check your settings") }
240
+ it do
241
+ expect(log).to receive(:error).with(Howitzer::SelBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
242
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError)
243
+ end
197
244
  end
198
245
  end
199
246
  end
@@ -226,7 +273,10 @@ describe "Helpers" do
226
273
  end
227
274
  context "settings.tb_browser_name is not specified" do
228
275
  before { allow(settings).to receive(:tb_browser_name) { nil } }
229
- it { expect{subject}.to raise_error(TbBrowserNameNotSpecified, "Please check your settings") }
276
+ it do
277
+ expect(log).to receive(:error).with(Howitzer::TbBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
278
+ expect { subject }.to raise_error(Howitzer::TbBrowserNotSpecifiedError)
279
+ end
230
280
  end
231
281
  end
232
282
  end
@@ -252,7 +302,10 @@ describe "Helpers" do
252
302
  end
253
303
  context "settings.sl_browser_name is not specified" do
254
304
  before { allow(settings).to receive(:sl_browser_name) { nil } }
255
- it { expect {subject}.to raise_error(SlBrowserNameNotSpecified, "Please check your settings") }
305
+ it do
306
+ expect(log).to receive(:error).with(Howitzer::SlBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
307
+ expect { subject }.to raise_error(Howitzer::SlBrowserNotSpecifiedError)
308
+ end
256
309
  end
257
310
  end
258
311
  context "when sauce_driver? is FALSE" do
@@ -275,7 +328,10 @@ describe "Helpers" do
275
328
  end
276
329
  context "settings.sel_browser is not specified" do
277
330
  before { allow(settings).to receive(:sel_browser) { nil } }
278
- it { expect {subject}.to raise_error(SelBrowserNotSpecified, "Please check your settings") }
331
+ it do
332
+ expect(log).to receive(:error).with(Howitzer::SelBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
333
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError)
334
+ end
279
335
  end
280
336
  end
281
337
  context "when selenium_driver? is FALSE" do
@@ -310,7 +366,10 @@ describe "Helpers" do
310
366
  end
311
367
  context "settings.tb_browser_name is not specified" do
312
368
  before { allow(settings).to receive(:tb_browser_name) { nil } }
313
- it { expect{subject}.to raise_error(TbBrowserNameNotSpecified, "Please check your settings") }
369
+ it do
370
+ expect(log).to receive(:error).with(Howitzer::TbBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
371
+ expect { subject }.to raise_error(Howitzer::TbBrowserNotSpecifiedError)
372
+ end
314
373
  end
315
374
  end
316
375
  context "when testingbot_driver? is FALSE" do
@@ -332,7 +391,10 @@ describe "Helpers" do
332
391
  end
333
392
  context "settings.sl_browser_name is not specified" do
334
393
  before { allow(settings).to receive(:sl_browser_name) { nil } }
335
- it { expect {subject}.to raise_error(SlBrowserNameNotSpecified, "Please check your settings") }
394
+ it do
395
+ expect(log).to receive(:error).with(Howitzer::SlBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
396
+ expect { subject }.to raise_error(Howitzer::SlBrowserNotSpecifiedError)
397
+ end
336
398
  end
337
399
  end
338
400
  end
@@ -356,7 +418,10 @@ describe "Helpers" do
356
418
  end
357
419
  context "settings.sel_browser is not specified" do
358
420
  before { allow(settings).to receive(:sel_browser) { nil } }
359
- it { expect {subject}.to raise_error(SelBrowserNotSpecified, "Please check your settings") }
421
+ it do
422
+ expect(log).to receive(:error).with(Howitzer::SelBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
423
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError)
424
+ end
360
425
  end
361
426
  end
362
427
  end
@@ -389,7 +454,10 @@ describe "Helpers" do
389
454
  end
390
455
  context "settings.tb_browser_name is not specified" do
391
456
  before { allow(settings).to receive(:tb_browser_name) { nil } }
392
- it { expect{subject}.to raise_error(TbBrowserNameNotSpecified, "Please check your settings") }
457
+ it do
458
+ expect(log).to receive(:error).with(Howitzer::TbBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
459
+ expect { subject }.to raise_error(Howitzer::TbBrowserNotSpecifiedError)
460
+ end
393
461
  end
394
462
  end
395
463
 
@@ -412,7 +480,10 @@ describe "Helpers" do
412
480
  end
413
481
  context "settings.sl_browser_name is not specified" do
414
482
  before { allow(settings).to receive(:sl_browser_name) { nil } }
415
- it { expect {subject}.to raise_error(SlBrowserNameNotSpecified, "Please check your settings") }
483
+ it do
484
+ expect(log).to receive(:error).with(Howitzer::SlBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
485
+ expect { subject }.to raise_error(Howitzer::SlBrowserNotSpecifiedError)
486
+ end
416
487
  end
417
488
  end
418
489
  context "when sauce_driver? is FALSE" do
@@ -431,7 +502,10 @@ describe "Helpers" do
431
502
  end
432
503
  context "settings.sel_browser is not specified" do
433
504
  before { allow(settings).to receive(:sel_browser) { nil } }
434
- it { expect {subject}.to raise_error(SelBrowserNotSpecified, "Please check your settings") }
505
+ it do
506
+ expect(log).to receive(:error).with(Howitzer::SelBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
507
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError)
508
+ end
435
509
  end
436
510
  end
437
511
  context "when selenium_driver? is FALSE" do
@@ -459,7 +533,10 @@ describe "Helpers" do
459
533
  end
460
534
  context "settings.tb_browser_name is not specified" do
461
535
  before { allow(settings).to receive(:tb_browser_name) { nil } }
462
- it { expect{subject}.to raise_error(TbBrowserNameNotSpecified, "Please check your settings") }
536
+ it do
537
+ expect(log).to receive(:error).with(Howitzer::TbBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
538
+ expect { subject }.to raise_error(Howitzer::TbBrowserNotSpecifiedError)
539
+ end
463
540
  end
464
541
  end
465
542
  context "when testingbot_driver? is FALSE" do
@@ -477,7 +554,10 @@ describe "Helpers" do
477
554
  end
478
555
  context "settings.sl_browser_name is not specified" do
479
556
  before { allow(settings).to receive(:sl_browser_name) { nil } }
480
- it { expect {subject}.to raise_error(SlBrowserNameNotSpecified, "Please check your settings") }
557
+ it do
558
+ expect(log).to receive(:error).with(Howitzer::SlBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
559
+ expect { subject }.to raise_error(Howitzer::SlBrowserNotSpecifiedError)
560
+ end
481
561
  end
482
562
  end
483
563
 
@@ -498,7 +578,10 @@ describe "Helpers" do
498
578
  end
499
579
  context "settings.sel_browser is not specified" do
500
580
  before { allow(settings).to receive(:sel_browser) { nil } }
501
- it { expect {subject}.to raise_error(SelBrowserNotSpecified, "Please check your settings") }
581
+ it do
582
+ expect(log).to receive(:error).with(Howitzer::SelBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
583
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError)
584
+ end
502
585
  end
503
586
  end
504
587
 
@@ -519,7 +602,10 @@ describe "Helpers" do
519
602
  end
520
603
  context "settings.sel_browser is not specified" do
521
604
  before { allow(settings).to receive(:sel_browser) { nil } }
522
- it { expect {subject}.to raise_error(SelBrowserNotSpecified, "Please check your settings") }
605
+ it do
606
+ expect(log).to receive(:error).with(Howitzer::SelBrowserNotSpecifiedError, "Please check your settings").once.and_call_original
607
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError)
608
+ end
523
609
  end
524
610
  end
525
611
  context "when selenium_driver? is FALSE" do
@@ -591,29 +677,69 @@ describe "Helpers" do
591
677
  it { expect {subject}.to raise_error(RuntimeError, /boom/) }
592
678
  end
593
679
  describe String do
680
+ let(:page_name) { "my" }
681
+ let(:page_object) { double }
682
+ before { stub_const("MyPage", page_object) }
594
683
  describe "#open" do
595
- subject { "my".open(:exit) }
596
- let(:page_object) { double }
684
+ subject { page_name.open(:exit) }
597
685
  before do
598
- stub_const("MyPage", page_object)
599
686
  expect(page_object).to receive(:open).with(:exit).once
600
687
  end
601
688
  it { expect(subject).to be_nil }
602
689
  end
603
690
  describe "#given" do
604
- subject { "my".given }
605
- let(:page_object) { double }
691
+ subject { page_name.given }
606
692
  before do
607
- stub_const("MyPage", page_object)
608
- expect(page_object).to receive(:new).once
693
+ allow(page_name).to receive(:as_page_class){ page_object }
694
+ expect(page_object).to receive(:given).once
695
+ end
696
+ it { expect(subject).to be_nil }
697
+ end
698
+ describe "#wait_for_opened" do
699
+ subject { page_name.wait_for_opened }
700
+ before do
701
+ allow(page_name).to receive(:as_page_class){ page_object }
702
+ expect(page_object).to receive(:wait_for_opened).once
609
703
  end
610
704
  it { expect(subject).to be_nil }
611
705
  end
612
706
  describe "#as_page_class" do
613
- subject { "my".as_page_class }
614
- let(:my_page) { double }
615
- before { stub_const("MyPage", my_page) }
616
- it { expect(subject).to eql(my_page) }
707
+ subject { page_name.as_page_class }
708
+ context "when 1 word" do
709
+ it { expect(subject).to eql(page_object) }
710
+ end
711
+ context "when more 1 word" do
712
+ let(:page_name) { 'my super mega' }
713
+ before { stub_const("MySuperMegaPage", page_object) }
714
+ it { expect(subject).to eql(page_object) }
715
+ end
716
+
717
+ context "when plural word" do
718
+ let(:page_name) { 'user notifications' }
719
+ before { stub_const("UserNotificationsPage", page_object) }
720
+ it { expect(subject).to eql(page_object) }
721
+ end
722
+ end
723
+ describe "#as_email_class" do
724
+ subject { email_name.as_email_class }
725
+ let(:my_email) { double }
726
+ context "when 1 word" do
727
+ let(:email_name) { 'my' }
728
+ before { stub_const("MyEmail", my_email) }
729
+ it { expect(subject).to eql(my_email) }
730
+ end
731
+
732
+ context "when more 1 word" do
733
+ let(:email_name) { 'my super mega' }
734
+ before { stub_const("MySuperMegaEmail", my_email) }
735
+ it { expect(subject).to eql(my_email) }
736
+ end
737
+
738
+ context "when plural word" do
739
+ let(:email_name) { 'email notifications' }
740
+ before { stub_const("EmailNotificationsEmail", my_email) }
741
+ it { expect(subject).to eql(my_email) }
742
+ end
617
743
  end
618
744
  end
619
745
  end