howitzer 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +32 -0
  4. data/.travis.yml +1 -4
  5. data/.yardopts +1 -2
  6. data/CHANGELOG.md +28 -1
  7. data/Gemfile +6 -0
  8. data/LICENSE +1 -1
  9. data/README.md +55 -85
  10. data/Rakefile +7 -7
  11. data/bin/howitzer +56 -31
  12. data/features/cli_new.feature +162 -79
  13. data/features/cli_update.feature +114 -21
  14. data/features/step_definitions/common_steps.rb +29 -9
  15. data/features/support/env.rb +1 -1
  16. data/features/support/transformers.rb +2 -2
  17. data/generators/base_generator.rb +121 -49
  18. data/generators/config/config_generator.rb +8 -5
  19. data/generators/config/templates/boot.rb +14 -0
  20. data/generators/config/templates/capybara.rb +156 -0
  21. data/generators/config/templates/custom.yml +2 -3
  22. data/generators/config/templates/default.yml +50 -82
  23. data/generators/cucumber/cucumber_generator.rb +9 -9
  24. data/generators/cucumber/templates/common_steps.rb +4 -4
  25. data/generators/cucumber/templates/cucumber.rake +63 -54
  26. data/generators/cucumber/templates/env.rb +24 -23
  27. data/generators/cucumber/templates/transformers.rb +23 -15
  28. data/generators/emails/emails_generator.rb +4 -2
  29. data/generators/emails/templates/example_email.rb +4 -4
  30. data/generators/prerequisites/prerequisites_generator.rb +24 -0
  31. data/generators/prerequisites/templates/base.rb +22 -0
  32. data/generators/prerequisites/templates/factory_girl.rb +30 -0
  33. data/generators/prerequisites/templates/user.rb +7 -0
  34. data/generators/prerequisites/templates/users.rb +12 -0
  35. data/generators/root/root_generator.rb +11 -7
  36. data/generators/root/templates/.rubocop.yml +32 -0
  37. data/generators/root/templates/Gemfile.erb +27 -0
  38. data/generators/root/templates/Rakefile +6 -8
  39. data/generators/rspec/rspec_generator.rb +7 -7
  40. data/generators/rspec/templates/example_spec.rb +1 -1
  41. data/generators/rspec/templates/rspec.rake +48 -29
  42. data/generators/rspec/templates/spec_helper.rb +33 -32
  43. data/generators/tasks/tasks_generator.rb +4 -2
  44. data/generators/tasks/templates/common.rake +1 -16
  45. data/generators/turnip/templates/.rspec +1 -0
  46. data/generators/turnip/templates/common_steps.rb +25 -0
  47. data/generators/turnip/templates/example.feature +8 -0
  48. data/generators/turnip/templates/spec_helper.rb +56 -0
  49. data/generators/turnip/templates/turnip.rake +61 -0
  50. data/generators/turnip/templates/turnip_helper.rb +6 -0
  51. data/generators/turnip/turnip_generator.rb +26 -0
  52. data/generators/web/templates/example_page.rb +15 -0
  53. data/generators/web/templates/menu_section.rb +13 -0
  54. data/generators/web/web_generator.rb +22 -0
  55. data/howitzer.gemspec +14 -21
  56. data/lib/howitzer.rb +47 -7
  57. data/lib/howitzer/cache.rb +70 -0
  58. data/lib/howitzer/capybara_helpers.rb +194 -0
  59. data/lib/howitzer/email.rb +96 -104
  60. data/lib/howitzer/exceptions.rb +10 -6
  61. data/lib/howitzer/log.rb +120 -0
  62. data/lib/howitzer/mail_adapters.rb +7 -0
  63. data/lib/howitzer/mail_adapters/abstract.rb +84 -0
  64. data/lib/howitzer/mail_adapters/mailgun.rb +115 -0
  65. data/lib/howitzer/mailgun_api.rb +9 -0
  66. data/lib/howitzer/mailgun_api/client.rb +79 -0
  67. data/lib/howitzer/mailgun_api/connector.rb +37 -0
  68. data/lib/howitzer/mailgun_api/response.rb +28 -0
  69. data/lib/howitzer/tasks/framework.rake +2 -2
  70. data/lib/howitzer/utils.rb +7 -1
  71. data/lib/howitzer/utils/string_extensions.rb +66 -0
  72. data/lib/howitzer/version.rb +2 -1
  73. data/lib/howitzer/web.rb +11 -0
  74. data/lib/howitzer/web/base_section.rb +27 -0
  75. data/lib/howitzer/web/blank_page.rb +12 -0
  76. data/lib/howitzer/web/capybara_methods_proxy.rb +29 -0
  77. data/lib/howitzer/web/element_dsl.rb +109 -0
  78. data/lib/howitzer/web/iframe_dsl.rb +93 -0
  79. data/lib/howitzer/web/page.rb +173 -0
  80. data/lib/howitzer/web/page_dsl.rb +64 -0
  81. data/lib/howitzer/web/page_validator.rb +118 -0
  82. data/lib/howitzer/web/section.rb +27 -0
  83. data/lib/howitzer/web/section_dsl.rb +154 -0
  84. data/spec/config/custom.yml +10 -1
  85. data/spec/spec_helper.rb +37 -19
  86. data/spec/support/generator_helper.rb +12 -11
  87. data/spec/support/logger_helper.rb +10 -9
  88. data/spec/support/mailgun_unit_client.rb +52 -44
  89. data/spec/support/shared_examples/capybara_context_holder.rb +33 -0
  90. data/spec/support/shared_examples/capybara_methods_proxy.rb +94 -0
  91. data/spec/support/shared_examples/dynamic_section_methods.rb +35 -0
  92. data/spec/support/shared_examples/element_dsl.rb +119 -0
  93. data/spec/unit/generators/base_generator_spec.rb +64 -33
  94. data/spec/unit/generators/config_generator_spec.rb +11 -7
  95. data/spec/unit/generators/cucumber_generator_spec.rb +26 -17
  96. data/spec/unit/generators/emails_generator_spec.rb +10 -6
  97. data/spec/unit/generators/prerequisites_generator_spec.rb +53 -0
  98. data/spec/unit/generators/root_generator_spec.rb +50 -13
  99. data/spec/unit/generators/rspec_generator_spec.rb +9 -9
  100. data/spec/unit/generators/tasks_generator_spec.rb +6 -6
  101. data/spec/unit/generators/turnip_generator_spec.rb +52 -0
  102. data/spec/unit/generators/web_generator_spec.rb +52 -0
  103. data/spec/unit/lib/cache_spec.rb +85 -0
  104. data/spec/unit/lib/capybara_helpers_spec.rb +696 -0
  105. data/spec/unit/lib/email_spec.rb +104 -91
  106. data/spec/unit/lib/howitzer.rb +31 -0
  107. data/spec/unit/lib/init_spec.rb +0 -1
  108. data/spec/unit/lib/log_spec.rb +122 -0
  109. data/spec/unit/lib/mail_adapters/abstract_spec.rb +62 -0
  110. data/spec/unit/lib/mail_adapters/mailgun_spec.rb +163 -0
  111. data/spec/unit/lib/mailgun_api/client_spec.rb +58 -0
  112. data/spec/unit/lib/mailgun_api/connector_spec.rb +54 -0
  113. data/spec/unit/lib/mailgun_api/response_spec.rb +28 -0
  114. data/spec/unit/lib/utils/string_extensions_spec.rb +77 -0
  115. data/spec/unit/lib/web/base_section_spec.rb +41 -0
  116. data/spec/unit/lib/web/element_dsl_spec.rb +17 -0
  117. data/spec/unit/lib/web/iframe_dsl_spec.rb +99 -0
  118. data/spec/unit/lib/web/page_dsl_spec.rb +52 -0
  119. data/spec/unit/lib/web/page_spec.rb +304 -0
  120. data/spec/unit/lib/web/page_validator_spec.rb +218 -0
  121. data/spec/unit/lib/web/section_dsl_spec.rb +165 -0
  122. data/spec/unit/lib/web/section_spec.rb +61 -0
  123. data/spec/unit/version_spec.rb +1 -1
  124. metadata +116 -203
  125. data/GETTING_STARTED.md +0 -774
  126. data/generators/cucumber/templates/cucumber.yml +0 -10
  127. data/generators/pages/pages_generator.rb +0 -21
  128. data/generators/pages/templates/example_menu.rb +0 -15
  129. data/generators/pages/templates/example_page.rb +0 -15
  130. data/generators/root/templates/Gemfile +0 -7
  131. data/generators/root/templates/boot.rb +0 -10
  132. data/lib/howitzer/blank_page.rb +0 -6
  133. data/lib/howitzer/capybara/dsl_ex.rb +0 -15
  134. data/lib/howitzer/capybara/settings.rb +0 -343
  135. data/lib/howitzer/helpers.rb +0 -230
  136. data/lib/howitzer/init.rb +0 -1
  137. data/lib/howitzer/mailgun/client.rb +0 -65
  138. data/lib/howitzer/mailgun/connector.rb +0 -34
  139. data/lib/howitzer/mailgun/response.rb +0 -28
  140. data/lib/howitzer/patches/rawler_patched.rb +0 -86
  141. data/lib/howitzer/settings.rb +0 -27
  142. data/lib/howitzer/utils/data_generator/data_storage.rb +0 -88
  143. data/lib/howitzer/utils/data_generator/gen.rb +0 -135
  144. data/lib/howitzer/utils/locator_store.rb +0 -217
  145. data/lib/howitzer/utils/log.rb +0 -139
  146. data/lib/howitzer/utils/page_validator.rb +0 -133
  147. data/lib/howitzer/vendor/firebug-1.12.1-fx.xpi +0 -0
  148. data/lib/howitzer/vendor/firepath-0.9.7-fx.xpi +0 -0
  149. data/lib/howitzer/web_page.rb +0 -253
  150. data/spec/active_resource.rb +0 -0
  151. data/spec/config/default.yml +0 -26
  152. data/spec/support/boot_helper.rb +0 -15
  153. data/spec/unit/generators/pages_generator_spec.rb +0 -33
  154. data/spec/unit/lib/capybara/dsl_ex_spec.rb +0 -60
  155. data/spec/unit/lib/capybara/settings_spec.rb +0 -441
  156. data/spec/unit/lib/helpers_spec.rb +0 -1129
  157. data/spec/unit/lib/mailgun/client_spec.rb +0 -36
  158. data/spec/unit/lib/mailgun/connector_spec.rb +0 -70
  159. data/spec/unit/lib/mailgun/response_spec.rb +0 -28
  160. data/spec/unit/lib/settings_spec.rb +0 -17
  161. data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +0 -80
  162. data/spec/unit/lib/utils/data_generator/gen_spec.rb +0 -90
  163. data/spec/unit/lib/utils/locator_store_spec.rb +0 -157
  164. data/spec/unit/lib/utils/log_spec.rb +0 -107
  165. data/spec/unit/lib/utils/page_validator_spec.rb +0 -265
  166. data/spec/unit/lib/web_page_spec.rb +0 -346
@@ -6,19 +6,19 @@ RSpec.describe 'Generators' do
6
6
  subject { file_tree_info(destination) }
7
7
  before do
8
8
  Howitzer::BaseGenerator.logger = output
9
- generator_name.new
9
+ generator_name.new(rspec: true)
10
10
  end
11
11
  after { FileUtils.rm_r(destination) }
12
12
 
13
- describe 'RSpecGenerator' do
14
- let(:generator_name) { Howitzer::RspecGenerator }
13
+ describe Howitzer::RspecGenerator do
14
+ let(:generator_name) { described_class }
15
15
  let(:expected_result) do
16
16
  [
17
- {:name=> '/spec', :is_directory=>true},
18
- {:name=> '/spec/example_spec.rb', :is_directory=>false, :size=>template_file_size('rspec', 'example_spec.rb')},
19
- {:name=> '/spec/spec_helper.rb', :is_directory=>false, :size=>template_file_size('rspec', 'spec_helper.rb')},
20
- {:name=> '/tasks', :is_directory=>true},
21
- {:name=> '/tasks/rspec.rake', :is_directory=>false, :size=>template_file_size('rspec', 'rspec.rake')}
17
+ { name: '/spec', is_directory: true },
18
+ { name: '/spec/example_spec.rb', is_directory: false, size: template_file_size('rspec', 'example_spec.rb') },
19
+ { name: '/spec/spec_helper.rb', is_directory: false, size: template_file_size('rspec', 'spec_helper.rb') },
20
+ { name: '/tasks', is_directory: true },
21
+ { name: '/tasks/rspec.rake', is_directory: false, size: template_file_size('rspec', 'rspec.rake') }
22
22
  ]
23
23
  end
24
24
  it { is_expected.to eql(expected_result) }
@@ -33,4 +33,4 @@ RSpec.describe 'Generators' do
33
33
  it { is_expected.to eql(expected_output) }
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -6,16 +6,16 @@ RSpec.describe 'Generators' do
6
6
  subject { file_tree_info(destination) }
7
7
  before do
8
8
  Howitzer::BaseGenerator.logger = output
9
- generator_name.new
9
+ generator_name.new({})
10
10
  end
11
11
  after { FileUtils.rm_r(destination) }
12
12
 
13
- describe 'TasksGenerator' do
14
- let(:generator_name) { Howitzer::TasksGenerator }
13
+ describe Howitzer::TasksGenerator do
14
+ let(:generator_name) { described_class }
15
15
  let(:expected_result) do
16
16
  [
17
- {:name=> '/tasks', :is_directory=>true},
18
- {:name=> '/tasks/common.rake', :is_directory=>false, :size=>template_file_size('tasks', 'common.rake')}
17
+ { name: '/tasks', is_directory: true },
18
+ { name: '/tasks/common.rake', is_directory: false, size: template_file_size('tasks', 'common.rake') }
19
19
  ]
20
20
  end
21
21
  it { is_expected.to eql(expected_result) }
@@ -28,4 +28,4 @@ RSpec.describe 'Generators' do
28
28
  it { is_expected.to eql(expected_output) }
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Generators' do
4
+ let(:destination) { Howitzer::BaseGenerator.destination }
5
+ let(:output) { StringIO.new }
6
+ subject { file_tree_info(destination) }
7
+ before do
8
+ Howitzer::BaseGenerator.logger = output
9
+ generator_name.new(turnip: true)
10
+ end
11
+ after { FileUtils.rm_r(destination) }
12
+
13
+ describe Howitzer::TurnipGenerator do
14
+ let(:generator_name) { described_class }
15
+ let(:expected_result) do
16
+ [
17
+ { name: '/.rspec', is_directory: false, size: 15 },
18
+ { name: '/spec', is_directory: true },
19
+ { name: '/spec/acceptance', is_directory: true },
20
+ {
21
+ name: '/spec/acceptance/example.feature',
22
+ is_directory: false,
23
+ size: template_file_size('turnip', 'example.feature')
24
+ },
25
+ { name: '/spec/spec_helper.rb', is_directory: false, size: template_file_size('turnip', 'spec_helper.rb') },
26
+ { name: '/spec/steps', is_directory: true },
27
+ {
28
+ name: '/spec/steps/common_steps.rb',
29
+ is_directory: false,
30
+ size: template_file_size('turnip', 'common_steps.rb')
31
+ },
32
+ { name: '/spec/turnip_helper.rb', is_directory: false, size: template_file_size('turnip', 'turnip_helper.rb') },
33
+ { name: '/tasks', is_directory: true },
34
+ { name: '/tasks/turnip.rake', is_directory: false, size: template_file_size('turnip', 'turnip.rake') }
35
+ ]
36
+ end
37
+ it { is_expected.to eql(expected_result) }
38
+ describe 'output' do
39
+ let(:expected_output) do
40
+ " * Turnip integration to the framework ...
41
+ Added '.rspec' file
42
+ Added 'spec/spec_helper.rb' file
43
+ Added 'spec/turnip_helper.rb' file
44
+ Added 'spec/acceptance/example.feature' file
45
+ Added 'spec/steps/common_steps.rb' file
46
+ Added 'tasks/turnip.rake' file\n"
47
+ end
48
+ subject { output.string }
49
+ it { is_expected.to eql(expected_output) }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Generators' do
4
+ let(:destination) { Howitzer::BaseGenerator.destination }
5
+ let(:output) { StringIO.new }
6
+ subject { file_tree_info(destination) }
7
+ before do
8
+ Howitzer::BaseGenerator.logger = output
9
+ generator_name.new({})
10
+ end
11
+ after { FileUtils.rm_r(destination) }
12
+
13
+ describe Howitzer::WebGenerator do
14
+ let(:generator_name) { described_class }
15
+ let(:expected_result) do
16
+ [
17
+ {
18
+ name: '/web',
19
+ is_directory: true
20
+ },
21
+ {
22
+ name: '/web/pages',
23
+ is_directory: true
24
+ },
25
+ {
26
+ name: '/web/pages/example_page.rb',
27
+ is_directory: false,
28
+ size: template_file_size('web', 'example_page.rb')
29
+ },
30
+ {
31
+ name: '/web/sections',
32
+ is_directory: true
33
+ },
34
+ {
35
+ name: '/web/sections/menu_section.rb',
36
+ is_directory: false,
37
+ size: template_file_size('web', 'menu_section.rb')
38
+ }
39
+ ]
40
+ end
41
+ it { is_expected.to eql(expected_result) }
42
+ describe 'output' do
43
+ let(:expected_output) do
44
+ " * PageOriented pattern structure generation ...
45
+ Added 'web/pages/example_page.rb' file
46
+ Added 'web/sections/menu_section.rb' file\n"
47
+ end
48
+ subject { output.string }
49
+ it { is_expected.to eql(expected_output) }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'howitzer/cache'
3
+
4
+ RSpec.describe Howitzer::Cache do
5
+ before { described_class.data.clear }
6
+ describe '.store' do
7
+ subject { described_class.store(ns, 7, :halt) }
8
+ context 'when namespace specified' do
9
+ let(:ns) { :user }
10
+ it 'should return value' do
11
+ is_expected.to eql(:halt)
12
+ end
13
+ it 'should store namespace value' do
14
+ subject
15
+ expect(described_class.data[:user]).to eql(7 => :halt)
16
+ end
17
+ end
18
+ context 'when namespace empty' do
19
+ let(:ns) { nil }
20
+ it { expect { subject }.to raise_error(Howitzer::NoDataError, 'Data storage namespace can not be empty') }
21
+ end
22
+ end
23
+ describe '.extract' do
24
+ subject { described_class.extract(ns, key) }
25
+ before { described_class.data[:user] = { 7 => :exit } }
26
+ describe 'when namespace specified' do
27
+ let(:ns) { :user }
28
+ context 'and namespace key found' do
29
+ let(:key) { 7 }
30
+ it { is_expected.to eql(:exit) }
31
+ end
32
+ context 'and namespace key not found' do
33
+ let(:key) { 5 }
34
+ it { is_expected.to be_nil }
35
+ end
36
+ context 'but namespace key not specified' do
37
+ let(:key) { nil }
38
+ it { is_expected.to eql(7 => :exit) }
39
+ end
40
+ end
41
+ context 'when namespace not found' do
42
+ let(:ns) { :guest }
43
+ let(:key) { 11 }
44
+ it { is_expected.to be_nil }
45
+ end
46
+ context 'when namespace not specified' do
47
+ let(:ns) { nil }
48
+ let(:key) { nil }
49
+ it { expect { subject }.to raise_error(Howitzer::NoDataError, 'Data storage namespace can not be empty') }
50
+ end
51
+ end
52
+ describe '.clear_ns' do
53
+ subject { described_class.clear_ns(:user) }
54
+ before { described_class.data[:user] = { 7 => :exit } }
55
+ it 'should return empty hash' do
56
+ subject
57
+ data = described_class.instance_variable_get(:@data)
58
+ expect(data[:user]).to eql({})
59
+ end
60
+ end
61
+ describe '.clear_all_ns' do
62
+ before do
63
+ described_class.store(:cloud, :status, false)
64
+ described_class.store(:foo, 'foo', 'some value1')
65
+ described_class.store(:bar, 'bar', 'some value2')
66
+ described_class.store(:baz, 'baz', 'some value3')
67
+ end
68
+ context 'when default argument' do
69
+ before { described_class.clear_all_ns }
70
+ it { expect(described_class.data).to eq(cloud: { status: false }, foo: {}, bar: {}, baz: {}) }
71
+ end
72
+ context 'when custom argument' do
73
+ let(:exception_list) { [:foo, :bar] }
74
+ before { described_class.clear_all_ns(exception_list) }
75
+ it do
76
+ expect(described_class.data).to eq(
77
+ cloud: {},
78
+ foo: { 'foo' => 'some value1' },
79
+ bar: { 'bar' => 'some value2' },
80
+ baz: {}
81
+ )
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,696 @@
1
+ require 'spec_helper'
2
+ require 'howitzer/capybara_helpers'
3
+
4
+ RSpec.describe Howitzer::CapybaraHelpers do
5
+ include Howitzer::CapybaraHelpers
6
+
7
+ let(:selenium_driver) { false }
8
+ let(:selenium_grid_driver) { false }
9
+ let(:phantomjs_driver) { false }
10
+ let(:sauce_driver) { false }
11
+ let(:test_object) { described_class }
12
+
13
+ describe '#cloud_driver?' do
14
+ subject { cloud_driver? }
15
+ before { allow(Howitzer).to receive(:driver) { driver_setting } }
16
+ context 'when sauce driver' do
17
+ let(:driver_setting) { :sauce }
18
+ it { is_expected.to be_truthy }
19
+ end
20
+ context 'when testingbot driver' do
21
+ let(:driver_setting) { :testingbot }
22
+ it { is_expected.to be_truthy }
23
+ end
24
+ context 'when browserstack driver' do
25
+ let(:driver_setting) { :browserstack }
26
+ it { is_expected.to be_truthy }
27
+ end
28
+ context 'when not cloud driver' do
29
+ let(:driver_setting) { :phantomjs }
30
+ it { is_expected.to be_falsey }
31
+ end
32
+ context 'when driver specified as String' do
33
+ let(:driver_setting) { 'testingbot' }
34
+ it { is_expected.to be true }
35
+ end
36
+ end
37
+
38
+ describe '#selenium_driver?' do
39
+ subject { selenium_driver? }
40
+ before { allow(Howitzer).to receive(:driver) { driver_setting } }
41
+ context 'when :selenium' do
42
+ let(:driver_setting) { :selenium }
43
+ it { is_expected.to be_truthy }
44
+ end
45
+ context 'when :selenium_grid' do
46
+ let(:driver_setting) { :selenium_grid }
47
+ it { is_expected.to be_falsey }
48
+ end
49
+ context 'when not :selenium' do
50
+ let(:driver_setting) { :phantomjs }
51
+ it { is_expected.to be_falsey }
52
+ end
53
+ context 'when driver specified as String' do
54
+ let(:driver_setting) { 'selenium' }
55
+ it { is_expected.to be_truthy }
56
+ end
57
+ end
58
+
59
+ describe '#selenium_grid_driver?' do
60
+ subject { selenium_grid_driver? }
61
+ before { allow(Howitzer).to receive(:driver) { driver_setting } }
62
+ context 'when :selenium_grid' do
63
+ let(:driver_setting) { :selenium_grid }
64
+ it { is_expected.to be_truthy }
65
+ end
66
+ context 'when :selenium' do
67
+ let(:driver_setting) { :selenium }
68
+ it { is_expected.to be_falsey }
69
+ end
70
+ context 'when not :selenium' do
71
+ let(:driver_setting) { :phantomjs }
72
+ it { is_expected.to be_falsey }
73
+ end
74
+ context 'when driver specified as String' do
75
+ let(:driver_setting) { 'selenium_grid' }
76
+ it { is_expected.to be_truthy }
77
+ end
78
+ end
79
+
80
+ describe '#ie_browser?' do
81
+ subject { ie_browser? }
82
+ before { allow(self).to receive(:selenium_grid_driver?) { selenium_grid_driver } }
83
+ context 'when cloud_driver? is TRUE' do
84
+ before { allow(self).to receive(:cloud_driver?) { true } }
85
+ context 'Howitzer.cloud_browser_name = :ie' do
86
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :ie } }
87
+ it { is_expected.to be_truthy }
88
+ end
89
+ context 'Howitzer.cloud_browser_name = :iexplore' do
90
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :iexplore } }
91
+ it { is_expected.to be_truthy }
92
+ end
93
+ context 'Howitzer.cloud_browser_name = :chrome' do
94
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :chrome } }
95
+ it { is_expected.to be_falsey }
96
+ end
97
+ context 'Howitzer.cloud_browser_name is not specified' do
98
+ before { allow(Howitzer).to receive(:cloud_browser_name) { nil } }
99
+ it do
100
+ expect { subject }.to raise_error(Howitzer::CloudBrowserNotSpecifiedError, 'Please check your settings')
101
+ end
102
+ end
103
+ end
104
+ context 'when cloud_driver? is FALSE' do
105
+ before do
106
+ allow(self).to receive(:cloud_driver?) { false }
107
+ allow(self).to receive(:selenium_driver?) { selenium_driver }
108
+ end
109
+ context 'when selenium_driver? is TRUE' do
110
+ let(:selenium_driver) { true }
111
+ context 'Howitzer.selenium_browser = :ie' do
112
+ before { allow(Howitzer).to receive(:selenium_browser) { :ie } }
113
+ it { is_expected.to be_truthy }
114
+ end
115
+ context 'Howitzer.selenium_browser = :iexplore' do
116
+ before { allow(Howitzer).to receive(:selenium_browser) { :iexplore } }
117
+ it { is_expected.to be_truthy }
118
+ end
119
+ context 'Howitzer.selenium_browser = :chrome' do
120
+ before { allow(Howitzer).to receive(:selenium_browser) { :chrome } }
121
+ it { is_expected.to be_falsey }
122
+ end
123
+ context 'Howitzer.selenium_browser is not specified' do
124
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
125
+ it do
126
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
127
+ end
128
+ end
129
+ end
130
+ context 'when selenium_driver? is FALSE' do
131
+ it { is_expected.to be_falsey }
132
+ end
133
+ context 'when selenium_grid_driver? is TRUE' do
134
+ let(:selenium_grid_driver) { true }
135
+ context 'Howitzer.selenium_browser = :ie' do
136
+ before { allow(Howitzer).to receive(:selenium_browser) { :ie } }
137
+ it { is_expected.to be_truthy }
138
+ end
139
+ context 'Howitzer.selenium_browser = :iexplore' do
140
+ before { allow(Howitzer).to receive(:selenium_browser) { :iexplore } }
141
+ it { is_expected.to be_truthy }
142
+ end
143
+ context 'Howitzer.selenium_browser = :chrome' do
144
+ before { allow(Howitzer).to receive(:selenium_browser) { :chrome } }
145
+ it { is_expected.to be_falsey }
146
+ end
147
+ context 'Howitzer.selenium_browser is not specified' do
148
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
149
+ it do
150
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
151
+ end
152
+ end
153
+ end
154
+ context 'when selenium_grid_driver? is FALSE' do
155
+ it { is_expected.to be_falsey }
156
+ end
157
+ end
158
+ context 'when selenium_driver? is TRUE' do
159
+ before do
160
+ allow(self).to receive(:selenium_driver?) { selenium_driver }
161
+ allow(self).to receive(:cloud_driver?) { false }
162
+ end
163
+ context 'when selenium_driver? is TRUE' do
164
+ let(:selenium_driver) { true }
165
+ context 'Howitzer.selenium_browser = :ie' do
166
+ before { allow(Howitzer).to receive(:selenium_browser) { :ie } }
167
+ it { is_expected.to be_truthy }
168
+ end
169
+ context 'Howitzer.selenium_browser = :iexplore' do
170
+ before { allow(Howitzer).to receive(:selenium_browser) { :iexplore } }
171
+ it { is_expected.to be_truthy }
172
+ end
173
+ context 'Howitzer.selenium_browser = :chrome' do
174
+ before { allow(Howitzer).to receive(:selenium_browser) { :chrome } }
175
+ it { is_expected.to be_falsey }
176
+ end
177
+ context 'Howitzer.selenium_browser is not specified' do
178
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
179
+ it do
180
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
181
+ end
182
+ end
183
+ end
184
+ end
185
+ context 'when selenium_driver? is FALSE' do
186
+ before { allow(self).to receive(:selenium_driver?) { false } }
187
+ context 'when cloud_driver? is TRUE' do
188
+ before { allow(self).to receive(:cloud_driver?) { true } }
189
+ context 'Howitzer.cloud_browser_name = :ie' do
190
+ before do
191
+ allow(Howitzer).to receive(:cloud_browser_name) { :ie }
192
+ allow(Howitzer).to receive(:cloud_browser_version) { 9 }
193
+ end
194
+ it { is_expected.to be_truthy }
195
+ end
196
+ context 'Howitzer.cloud_browser_name = :iexplore' do
197
+ before do
198
+ allow(Howitzer).to receive(:cloud_browser_name) { :iexplore }
199
+ allow(Howitzer).to receive(:cloud_browser_version) { 9 }
200
+ end
201
+ it { is_expected.to be_truthy }
202
+ end
203
+ context 'Howitzer.cloud_browser_name = :firefox' do
204
+ before do
205
+ allow(Howitzer).to receive(:cloud_browser_name) { :firefox }
206
+ allow(Howitzer).to receive(:cloud_browser_version) { 8 }
207
+ end
208
+ it { is_expected.to be_falsey }
209
+ end
210
+ context 'Howitzer.cloud_browser_name is not specified' do
211
+ before { allow(Howitzer).to receive(:cloud_browser_name) { nil } }
212
+ it do
213
+ expect { subject }.to raise_error(Howitzer::CloudBrowserNotSpecifiedError, 'Please check your settings')
214
+ end
215
+ end
216
+ end
217
+ end
218
+ end
219
+
220
+ describe '#ff_browser?' do
221
+ subject { ff_browser? }
222
+ before do
223
+ allow(self).to receive(:selenium_grid_driver?) { selenium_grid_driver }
224
+ end
225
+ context 'when cloud_driver? is TRUE' do
226
+ before { allow(self).to receive(:cloud_driver?) { true } }
227
+ context 'Howitzer.cloud_browser_name = :ff' do
228
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :ff } }
229
+ it { is_expected.to be_truthy }
230
+ end
231
+ context 'Howitzer.cloud_browser_name = :firefox' do
232
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :firefox } }
233
+ it { is_expected.to be_truthy }
234
+ end
235
+ context 'Howitzer.cloud_browser_name = :chrome' do
236
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :chrome } }
237
+ it { is_expected.to be_falsey }
238
+ end
239
+ context 'Howitzer.cloud_browser_name is not specified' do
240
+ before { allow(Howitzer).to receive(:cloud_browser_name) { nil } }
241
+ it do
242
+ expect { subject }.to raise_error(Howitzer::CloudBrowserNotSpecifiedError, 'Please check your settings')
243
+ end
244
+ end
245
+ end
246
+ context 'when cloud_driver? is FALSE' do
247
+ before do
248
+ allow(self).to receive(:cloud_driver?) { false }
249
+ allow(self).to receive(:selenium_driver?) { selenium_driver }
250
+ end
251
+ context 'when selenium_driver? is TRUE' do
252
+ let(:selenium_driver) { true }
253
+ context 'Howitzer.selenium_browser = :ff' do
254
+ before { allow(Howitzer).to receive(:selenium_browser) { :ff } }
255
+ it { is_expected.to be_truthy }
256
+ end
257
+ context 'Howitzer.selenium_browser = :firefox' do
258
+ before { allow(Howitzer).to receive(:selenium_browser) { :firefox } }
259
+ it { is_expected.to be_truthy }
260
+ end
261
+ context 'Howitzer.selenium_browser = :chrome' do
262
+ before { allow(Howitzer).to receive(:selenium_browser) { :chrome } }
263
+ it { is_expected.to be_falsey }
264
+ end
265
+ context 'Howitzer.selenium_browser is not specified' do
266
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
267
+ it do
268
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
269
+ end
270
+ end
271
+ end
272
+ context 'when selenium_driver? is FALSE' do
273
+ it { is_expected.to be_falsey }
274
+ end
275
+ end
276
+ context 'when selenium_driver? is TRUE' do
277
+ before { allow(self).to receive(:cloud_driver?) { false } }
278
+ before { allow(self).to receive(:selenium_driver?) { selenium_driver } }
279
+ context 'when selenium_driver? is TRUE' do
280
+ let(:selenium_driver) { true }
281
+ context 'Howitzer.selenium_browser = :ff' do
282
+ before { allow(Howitzer).to receive(:selenium_browser) { :ff } }
283
+ it { is_expected.to be_truthy }
284
+ end
285
+ context 'Howitzer.selenium_browser = :firefox' do
286
+ before { allow(Howitzer).to receive(:selenium_browser) { :firefox } }
287
+ it { is_expected.to be_truthy }
288
+ end
289
+ context 'Howitzer.selenium_browser = :chrome' do
290
+ before { allow(Howitzer).to receive(:selenium_browser) { :chrome } }
291
+ it { is_expected.to be_falsey }
292
+ end
293
+ context 'Howitzer.selenium_browser is not specified' do
294
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
295
+ it do
296
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
297
+ end
298
+ end
299
+ end
300
+ end
301
+ context 'when selenium_driver? is FALSE' do
302
+ before { allow(self).to receive(:selenium_driver?) { false } }
303
+ context 'when cloud_driver? is TRUE' do
304
+ before { allow(self).to receive(:cloud_driver?) { true } }
305
+ context 'Howitzer.cloud_browser_name = :firefox' do
306
+ before do
307
+ allow(Howitzer).to receive(:cloud_browser_name) { :firefox }
308
+ allow(Howitzer).to receive(:cloud_browser_version) { 8 }
309
+ end
310
+ it { is_expected.to be_truthy }
311
+ end
312
+ context 'Howitzer.cloud_browser_name = :ff' do
313
+ before do
314
+ allow(Howitzer).to receive(:cloud_browser_name) { :ff }
315
+ allow(Howitzer).to receive(:cloud_browser_version) { 8 }
316
+ end
317
+ it { is_expected.to be_truthy }
318
+ end
319
+ context 'Howitzer.cloud_browser_name = :iexplore' do
320
+ before do
321
+ allow(Howitzer).to receive(:cloud_browser_name) { :iexplore }
322
+ allow(Howitzer).to receive(:cloud_browser_version) { 9 }
323
+ end
324
+ it { is_expected.to be_falsey }
325
+ end
326
+ context 'Howitzer.cloud_browser_name is not specified' do
327
+ before { allow(Howitzer).to receive(:cloud_browser_name) { nil } }
328
+ it do
329
+ expect { subject }.to raise_error(Howitzer::CloudBrowserNotSpecifiedError, 'Please check your settings')
330
+ end
331
+ end
332
+ end
333
+ context 'when selenium_grid_driver? is TRUE' do
334
+ before { allow(self).to receive(:selenium_grid_driver?) { selenium_grid_driver } }
335
+ before { allow(self).to receive(:cloud_driver?) { false } }
336
+ context 'when selenium_grid_driver? is TRUE' do
337
+ let(:selenium_grid_driver) { true }
338
+ context 'Howitzer.selenium_browser = :ff' do
339
+ before { allow(Howitzer).to receive(:selenium_browser) { :ff } }
340
+ it { is_expected.to be_truthy }
341
+ end
342
+ context 'Howitzer.selenium_browser = :firefox' do
343
+ before { allow(Howitzer).to receive(:selenium_browser) { :firefox } }
344
+ it { is_expected.to be_truthy }
345
+ end
346
+ context 'Howitzer.selenium_browser = :chrome' do
347
+ before { allow(Howitzer).to receive(:selenium_browser) { :chrome } }
348
+ it { is_expected.to be_falsey }
349
+ end
350
+ context 'Howitzer.selenium_browser is not specified' do
351
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
352
+ it do
353
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
354
+ end
355
+ end
356
+ end
357
+ end
358
+ context 'when selenium_grid_driver? is FALSE' do
359
+ before { allow(self).to receive(:selenium_grid_driver?) { false } }
360
+ context 'when cloud_driver? is TRUE' do
361
+ before { allow(self).to receive(:cloud_driver?) { true } }
362
+ context 'Howitzer.cloud_browser_name = :firefox' do
363
+ before do
364
+ allow(Howitzer).to receive(:cloud_browser_name) { :firefox }
365
+ allow(Howitzer).to receive(:cloud_browser_version) { 8 }
366
+ end
367
+ it { is_expected.to be_truthy }
368
+ end
369
+ context 'Howitzer.cloud_browser_name = :ff' do
370
+ before do
371
+ allow(Howitzer).to receive(:cloud_browser_name) { :ff }
372
+ allow(Howitzer).to receive(:cloud_browser_version) { 8 }
373
+ end
374
+ it { is_expected.to be_truthy }
375
+ end
376
+ context 'Howitzer.cloud_browser_name = :iexplore' do
377
+ before do
378
+ allow(Howitzer).to receive(:cloud_browser_name) { :iexplore }
379
+ allow(Howitzer).to receive(:cloud_browser_version) { 9 }
380
+ end
381
+ it { is_expected.to be_falsey }
382
+ end
383
+ context 'Howitzer.cloud_browser_name is not specified' do
384
+ before { allow(Howitzer).to receive(:cloud_browser_name) { nil } }
385
+ it do
386
+ expect { subject }.to raise_error(Howitzer::CloudBrowserNotSpecifiedError, 'Please check your settings')
387
+ end
388
+ end
389
+ end
390
+ end
391
+ end
392
+ end
393
+
394
+ describe '#chrome_browser?' do
395
+ subject { chrome_browser? }
396
+ before { allow(self).to receive(:selenium_grid_driver?) { selenium_grid_driver } }
397
+ context 'when cloud_driver? is TRUE' do
398
+ before { allow(self).to receive(:cloud_driver?) { true } }
399
+ context 'Howitzer.cloud_browser_name = :chrome' do
400
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :chrome } }
401
+ it { is_expected.to be_truthy }
402
+ end
403
+ context 'Howitzer.cloud_browser_name = :firefox' do
404
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :firefox } }
405
+ it { is_expected.to be_falsey }
406
+ end
407
+ context 'Howitzer.cloud_browser_name is not specified' do
408
+ before { allow(Howitzer).to receive(:cloud_browser_name) { nil } }
409
+ it do
410
+ expect { subject }.to raise_error(Howitzer::CloudBrowserNotSpecifiedError, 'Please check your settings')
411
+ end
412
+ end
413
+ end
414
+ context 'when selenium_driver? is TRUE' do
415
+ before { allow(self).to receive(:cloud_driver?) { false } }
416
+ before { allow(self).to receive(:selenium_driver?) { selenium_driver } }
417
+ context 'when selenium_driver? is TRUE' do
418
+ let(:selenium_driver) { true }
419
+ context 'Howitzer.selenium_browser = :chrome' do
420
+ before { allow(Howitzer).to receive(:selenium_browser) { :chrome } }
421
+ it { is_expected.to be_truthy }
422
+ end
423
+ context 'Howitzer.selenium_browser = :firefox' do
424
+ before { allow(Howitzer).to receive(:selenium_browser) { :firefox } }
425
+ it { is_expected.to be_falsey }
426
+ end
427
+ context 'Howitzer.selenium_browser is not specified' do
428
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
429
+ it do
430
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
431
+ end
432
+ end
433
+ end
434
+ end
435
+ end
436
+
437
+ describe '#safari_browser?' do
438
+ subject { safari_browser? }
439
+ before { allow(self).to receive(:selenium_grid_driver?) { selenium_grid_driver } }
440
+ context 'when cloud_driver? is TRUE' do
441
+ before { allow(self).to receive(:cloud_driver?) { true } }
442
+ context 'Howitzer.cloud_browser_name = :safari' do
443
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :safari } }
444
+ it { is_expected.to be_truthy }
445
+ end
446
+ context 'Howitzer.cloud_browser_name = :firefox' do
447
+ before { allow(Howitzer).to receive(:cloud_browser_name) { :firefox } }
448
+ it { is_expected.to be_falsey }
449
+ end
450
+ context 'Howitzer.cloud_browser_name is not specified' do
451
+ before { allow(Howitzer).to receive(:cloud_browser_name) { nil } }
452
+ it do
453
+ expect { subject }.to raise_error(Howitzer::CloudBrowserNotSpecifiedError, 'Please check your settings')
454
+ end
455
+ end
456
+ end
457
+ context 'when sauce_driver? is FALSE' do
458
+ before { allow(self).to receive(:selenium_driver?) { selenium_driver } }
459
+ before { allow(self).to receive(:cloud_driver?) { false } }
460
+ context 'when selenium_driver? is TRUE' do
461
+ let(:selenium_driver) { true }
462
+ context 'Howitzer.selenium_browser = :safari' do
463
+ before { allow(Howitzer).to receive(:selenium_browser) { :safari } }
464
+ it { is_expected.to be_truthy }
465
+ end
466
+ context 'Howitzer.selenium_browser = :firefox' do
467
+ before { allow(Howitzer).to receive(:selenium_browser) { :firefox } }
468
+ it { is_expected.to be_falsey }
469
+ end
470
+ context 'Howitzer.selenium_browser is not specified' do
471
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
472
+ it do
473
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
474
+ end
475
+ end
476
+ end
477
+ context 'when selenium_driver? is FALSE' do
478
+ it { is_expected.to be_falsey }
479
+ end
480
+ end
481
+ context 'when selenium_driver? is TRUE' do
482
+ before { allow(self).to receive(:cloud_driver?) { false } }
483
+ before { allow(self).to receive(:selenium_driver?) { selenium_driver } }
484
+ context 'when selenium_driver? is TRUE' do
485
+ let(:selenium_driver) { true }
486
+ context 'Howitzer.selenium_browser = :safari' do
487
+ before { allow(Howitzer).to receive(:selenium_browser) { :safari } }
488
+ it { is_expected.to be_truthy }
489
+ end
490
+ context 'Howitzer.selenium_browser = :firefox' do
491
+ before { allow(Howitzer).to receive(:selenium_browser) { :firefox } }
492
+ it { is_expected.to be_falsey }
493
+ end
494
+ context 'Howitzer.selenium_browser is not specified' do
495
+ before { allow(Howitzer).to receive(:selenium_browser) { nil } }
496
+ it do
497
+ expect { subject }.to raise_error(Howitzer::SelBrowserNotSpecifiedError, 'Please check your settings')
498
+ end
499
+ end
500
+ end
501
+ end
502
+ end
503
+ describe '#duration' do
504
+ context 'when more than hour' do
505
+ it { expect(duration(10_000)).to eq('[2h 46m 40s]') }
506
+ end
507
+ context 'when 1 hour exactly' do
508
+ it { expect(duration(3600)).to eq('[1h 0m 0s]') }
509
+ end
510
+ context 'when 0 hours and more than minute' do
511
+ it { expect(duration(2000)).to eq('[33m 20s]') }
512
+ end
513
+ context 'when 1 minute exactly' do
514
+ it { expect(duration(60)).to eq('[1m 0s]') }
515
+ end
516
+ context 'when less than minute' do
517
+ it { expect(duration(45)).to eq('[0m 45s]') }
518
+ end
519
+ context 'when zero' do
520
+ it { expect(duration(0)).to eq('[0m 0s]') }
521
+ end
522
+ end
523
+
524
+ describe '.sauce_resource_path' do
525
+ subject { sauce_resource_path(kind) }
526
+ let(:name) { 'test_name' }
527
+ before do
528
+ allow(Howitzer).to receive(:cloud_auth_login) { 'vlad' }
529
+ allow(Howitzer).to receive(:cloud_auth_pass) { '11111' }
530
+ allow(self).to receive(:session_id) { '12341234' }
531
+ end
532
+ context 'when kind video' do
533
+ let(:kind) { :video }
534
+ it { is_expected.to eql('https://vlad:11111@saucelabs.com/rest/vlad/jobs/12341234/results/video.flv') }
535
+ end
536
+ context 'when kind server_log' do
537
+ let(:kind) { :server_log }
538
+ it { is_expected.to eql('https://vlad:11111@saucelabs.com/rest/vlad/jobs/12341234/results/selenium-server.log') }
539
+ end
540
+ context 'when unknown kind' do
541
+ let(:kind) { :unknown }
542
+ it { expect { subject }.to raise_error(ArgumentError, "Unknown 'unknown' kind") }
543
+ end
544
+ end
545
+
546
+ describe '.update_sauce_job_statu' do
547
+ subject { update_sauce_job_status }
548
+ before do
549
+ allow(Howitzer).to receive(:cloud_auth_login) { 'vlad1' }
550
+ allow(Howitzer).to receive(:cloud_auth_pass) { '22222' }
551
+ allow(self).to receive(:session_id) { '12341234' }
552
+ stub_const('RestClient', double)
553
+ end
554
+
555
+ it do
556
+ expect(RestClient).to receive(:put).with(
557
+ 'http://vlad1:22222@saucelabs.com/rest/v1/vlad1/jobs/12341234',
558
+ '{}',
559
+ content_type: :json,
560
+ accept: :json
561
+ ).once
562
+ subject
563
+ end
564
+ end
565
+
566
+ describe '.update_cloud_job_status' do
567
+ subject { update_cloud_job_status(status: true) }
568
+ context 'when sauce driver' do
569
+ before do
570
+ allow(Howitzer).to receive(:driver) { 'sauce' }
571
+ expect(self).to receive(:update_sauce_job_status).with(status: true) { true }
572
+ end
573
+ it { is_expected.to eq(true) }
574
+ end
575
+ context 'when other driver' do
576
+ before { allow(Howitzer).to receive(:driver) { 'browserstack' } }
577
+ it { is_expected.to eq('[NOT IMPLEMENTED]') }
578
+ end
579
+ end
580
+
581
+ describe '.session_id' do
582
+ subject { session_id }
583
+ before do
584
+ browser = double
585
+ current_session = double
586
+ driver = double
587
+ instance_variable = double
588
+ allow(Capybara).to receive(:current_session) { current_session }
589
+ allow(current_session).to receive(:driver) { driver }
590
+ allow(driver).to receive(:browser) { browser }
591
+ allow(browser).to receive(:instance_variable_get).with(:@bridge) { instance_variable }
592
+ allow(instance_variable).to receive(:session_id) { 'test' }
593
+ end
594
+
595
+ it { is_expected.to eql('test') }
596
+ end
597
+
598
+ describe '.required_cloud_caps' do
599
+ subject { required_cloud_caps }
600
+ before do
601
+ allow(Howitzer).to receive(:cloud_platform) { 'Windows' }
602
+ allow(Howitzer).to receive(:cloud_browser_name) { 'Safari' }
603
+ allow(Howitzer).to receive(:cloud_browser_version) { '10.0' }
604
+ allow(self).to receive(:prefix_name) { 'Suite' }
605
+ end
606
+ it 'should return correct hash' do
607
+ is_expected.to eq(
608
+ platform: 'Windows',
609
+ browserName: 'Safari',
610
+ version: '10.0',
611
+ name: 'Suite Safari'
612
+ )
613
+ end
614
+ end
615
+
616
+ describe '.remote_file_detector' do
617
+ subject { remote_file_detector }
618
+ it 'should return lambda' do
619
+ is_expected.to be_a(Proc)
620
+ end
621
+
622
+ it 'should return nil when file missing' do
623
+ expect(subject.call('unknown.file')).to be_nil
624
+ end
625
+ end
626
+
627
+ describe '.cloud_driver' do
628
+ let(:app) { double(:app) }
629
+ let(:caps) { double(:caps) }
630
+ let(:url) { 'https://example.com' }
631
+ let(:file_detector) { double(:file) }
632
+ let(:driver) { double(:driver) }
633
+ let(:driver_browser) { double(:driver_browser) }
634
+ let(:cap_class) { double(:cap_class) }
635
+ let(:des_caps) { double(:des_class) }
636
+ let(:http_class) { double(:http_class) }
637
+ let(:http_client) { double(:http_client) }
638
+ subject { cloud_driver(app, caps, url) }
639
+ before do
640
+ allow(Howitzer).to receive(:cloud_http_idle_timeout) { 10 }
641
+ allow(self).to receive(:remote_file_detector) { file_detector }
642
+ stub_const('Selenium::WebDriver::Remote::Capabilities', cap_class)
643
+ allow(cap_class).to receive(:new).with(caps) { des_caps }
644
+ stub_const('Selenium::WebDriver::Remote::Http::Default', http_class)
645
+ allow(http_class).to receive(:new).with(no_args) { http_client }
646
+ expect(http_client).to receive(:timeout=).with(10)
647
+ allow(Capybara::Selenium::Driver).to receive(:new).with(app, kind_of(Hash)) { driver }
648
+ expect(driver).to receive(:browser) { driver_browser }
649
+ expect(driver_browser).to receive(:file_detector=).with(file_detector)
650
+ end
651
+ it { is_expected.to eq(driver) }
652
+ end
653
+
654
+ describe '.cloud_resource_path' do
655
+ subject { cloud_resource_path(:video) }
656
+ context 'when sauce driver' do
657
+ before do
658
+ allow(Howitzer).to receive(:driver) { 'sauce' }
659
+ expect(self).to receive(:sauce_resource_path).with(:video) { true }
660
+ end
661
+ it { is_expected.to eq(true) }
662
+ end
663
+ context 'when other driver' do
664
+ before { allow(Howitzer).to receive(:driver) { 'browserstack' } }
665
+ it { is_expected.to eq('[NOT IMPLEMENTED]') }
666
+ end
667
+ end
668
+
669
+ describe '.prefix_name' do
670
+ subject { prefix_name }
671
+ context 'when current rake task present' do
672
+ before { Howitzer.current_rake_task = 'Foo' }
673
+ after { Howitzer.current_rake_task = nil }
674
+ it { is_expected.to eq('FOO') }
675
+ end
676
+ context 'when rake_task_name empty' do
677
+ it { is_expected.to eq('ALL') }
678
+ end
679
+ end
680
+
681
+ describe '.load_driver_gem!' do
682
+ subject { load_driver_gem!(:webkit, 'capybara-webkit', 'capybara-webkit') }
683
+ context 'when possible to require' do
684
+ before { allow(self).to receive(:require).with(:webkit) { true } }
685
+ it { expect { subject }.not_to raise_error(LoadError) }
686
+ end
687
+ context 'when impossible to require' do
688
+ it do
689
+ expect { subject }.to raise_error(
690
+ LoadError,
691
+ "`:webkit` driver is unable to load `capybara-webkit`, please add `gem 'capybara-webkit'` to your Gemfile."
692
+ )
693
+ end
694
+ end
695
+ end
696
+ end