howitzer 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,35 +0,0 @@
1
- require 'spec_helper'
2
- RSpec.shared_examples :dynamic_section_methods do
3
- let(:web_page_object) { web_page_class.new }
4
-
5
- describe '#name_section' do
6
- let(:capybara_element) { double }
7
- subject { web_page_object.send("#{section_name}_section") }
8
- before { expect(session).to receive(:find).with(*finder_args).once.and_return(capybara_element) }
9
- it { is_expected.to be_a(section_class) }
10
- end
11
- describe '#name_sections' do
12
- subject { web_page_object.send("#{section_name}_sections") }
13
- let(:capybara_element1) { double }
14
- let(:capybara_element2) { double }
15
- before do
16
- expect(session).to receive(:all).with(*finder_args).once.and_return([capybara_element1, capybara_element2])
17
- end
18
- it 'should return collection of sections' do
19
- res = subject
20
- expect(res.size).to eq(2)
21
- expect(res.first).to be_a(section_class)
22
- expect(res.last).to be_a(section_class)
23
- end
24
- end
25
- describe '#has_name_section?' do
26
- subject { web_page_object.send("has_#{section_name}_section?") }
27
- before { expect(session).to receive(:has_selector?).with(*finder_args).once.and_return(true) }
28
- it { is_expected.to eq(true) }
29
- end
30
- describe '#has_no_name_element?' do
31
- subject { web_page_object.send("has_no_#{section_name}_section?") }
32
- before { expect(session).to receive(:has_no_selector?).with(*finder_args).once.and_return(true) }
33
- it { is_expected.to eq(true) }
34
- end
35
- end
@@ -1,242 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.shared_examples :element_dsl do
4
- describe '.element' do
5
- context 'when regular capybara params' do
6
- before do
7
- klass.class_eval do
8
- element :foo, :xpath, '//a'
9
- end
10
- end
11
- it 'should create private :foo_element instance method' do
12
- expect(klass_object.private_methods(false)).to include(:foo_element)
13
- end
14
- it 'should create private :foo_elements instance method' do
15
- expect(klass_object.private_methods(false)).to include(:foo_elements)
16
- end
17
- it 'should create private :wait_for_foo_element instance method' do
18
- expect(klass_object.private_methods(false)).to include(:wait_for_foo_element)
19
- end
20
- it 'should create public :has_foo_element? instance method' do
21
- expect(klass_object.public_methods(false)).to include(:has_foo_element?)
22
- end
23
- it 'should create public :has_no_foo_element? instance method' do
24
- expect(klass_object.public_methods(false)).to include(:has_no_foo_element?)
25
- end
26
- it 'should be protected class method' do
27
- expect { klass.element :bar }.to raise_error(NoMethodError)
28
- expect(klass.protected_methods(true)).to include(:element)
29
- end
30
- end
31
- context 'when 1 param is proc' do
32
- before do
33
- klass.class_eval do
34
- element :foo, :xpath, ->(title) { "//a[.='#{title}']" }
35
- end
36
- end
37
- it 'should create private :foo_element instance method' do
38
- expect(klass_object.private_methods(false)).to include(:foo_element)
39
- end
40
- it 'should create private :foo_elements instance method' do
41
- expect(klass_object.private_methods(false)).to include(:foo_elements)
42
- end
43
- it 'should create private :wait_for_foo_element instance method' do
44
- expect(klass_object.private_methods(false)).to include(:wait_for_foo_element)
45
- end
46
- it 'should create public :has_foo_element? instance method' do
47
- expect(klass_object.public_methods(false)).to include(:has_foo_element?)
48
- end
49
- it 'should create public :has_no_foo_element? instance method' do
50
- expect(klass_object.public_methods(false)).to include(:has_no_foo_element?)
51
- end
52
- it 'should be protected class method' do
53
- expect { klass.element :bar }.to raise_error(NoMethodError)
54
- expect(klass.protected_methods(true)).to include(:element)
55
- end
56
- end
57
- context 'when 2 params are proc' do
58
- subject do
59
- klass.class_eval do
60
- element :foo, -> { puts 1 }, ->(title) { "//a[.='#{title}']" }
61
- end
62
- end
63
- it 'should generate error' do
64
- expect { subject.element :bar }.to raise_error(
65
- Howitzer::BadElementParamsError,
66
- 'Using more than 1 proc in arguments is forbidden'
67
- )
68
- end
69
- end
70
- end
71
-
72
- describe 'dynamic_methods' do
73
- let(:web_page_object) { web_page_class.new }
74
- let(:kontext) { double(:kontext) }
75
- before do
76
- allow(Capybara).to receive(:current_session) { kontext }
77
- klass.class_eval do
78
- element :foo, :xpath,
79
- ->(title, name) { "//a[.='#{title}']/*[@name='#{name}']" }, text: 'original', match: :first
80
- element :bar, '.someclass', text: 'origin', match: :first
81
- element :top_panel, '.top', text: 'origin', match: :first
82
- end
83
- end
84
-
85
- describe '#name_element' do
86
- context 'when simple selector' do
87
- subject { klass_object.send(:bar_element, text: 'new', wait: 10) }
88
- after { subject }
89
- it do
90
- expect(klass_object.capybara_context).to receive(:find)
91
- .with('.someclass', wait: 10, text: 'new', match: :first)
92
- end
93
- end
94
- context 'when lambda selector' do
95
- subject { klass_object.send(:foo_element, 'Hello', 'super', text: 'new', wait: 10) }
96
- after { subject }
97
- it do
98
- expect(klass_object.capybara_context).to receive(:find)
99
- .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
100
- end
101
-
102
- context 'when several execution with different data' do
103
- it 'does not cache previous data' do
104
- expect(klass_object.capybara_context).to receive(:find)
105
- .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first).at_least(:once)
106
- klass_object.send(:foo_element, 'Hello', 'super', text: 'new', wait: 10)
107
-
108
- expect(klass_object.capybara_context).to receive(:find)
109
- .with(:xpath, "//a[.='Bye']/*[@name='puper']", wait: 15, text: 'new', match: :first).at_least(:once)
110
- klass_object.send(:foo_element, 'Bye', 'puper', text: 'new', wait: 15)
111
- end
112
- end
113
- end
114
- end
115
- describe '#name_elements' do
116
- after { subject }
117
- context 'when simple selector' do
118
- subject { klass_object.send(:bar_elements, text: 'new', wait: 10) }
119
- it do
120
- expect(klass_object.capybara_context).to receive(:all)
121
- .with('.someclass', wait: 10, text: 'new', match: :first)
122
- end
123
- end
124
- context 'when lambda selector' do
125
- subject { klass_object.send(:foo_elements, 'Hello', 'super', text: 'new', wait: 10) }
126
- it do
127
- expect(
128
- klass_object.capybara_context
129
- ).to receive(:all).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
130
- end
131
- end
132
- end
133
- describe '#wait_for_name_element' do
134
- context 'when simple selector' do
135
- subject { klass_object.send(:wait_for_bar_element, text: 'new', wait: 10) }
136
- it do
137
- expect(klass_object.capybara_context).to receive(:find)
138
- .with('.someclass', wait: 10, text: 'new', match: :first)
139
- is_expected.to eq(nil)
140
- end
141
- end
142
- context 'when lambda selector' do
143
- subject { klass_object.send(:wait_for_foo_element, 'Hello', 'super', text: 'new', wait: 10) }
144
- it do
145
- expect(
146
- klass_object.capybara_context
147
- ).to receive(:find).with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
148
- is_expected.to eq(nil)
149
- end
150
- end
151
- end
152
- describe '#within_name_element' do
153
- let(:within_scope) { double }
154
- after { subject }
155
- context 'not nested' do
156
- context 'when simple selector' do
157
- subject do
158
- klass_object.instance_eval do
159
- within_bar_element(wait: 5, text: 'new') do
160
- foo_element('Hello', 'super', wait: 10, text: 'new')
161
- end
162
- end
163
- end
164
- it do
165
- expect(klass_object.capybara_context).to receive(:find)
166
- .with('.someclass', wait: 5, text: 'new', match: :first) { within_scope }
167
- expect(within_scope).to receive(:find)
168
- .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
169
- end
170
- end
171
- context 'when lambda selector' do
172
- subject do
173
- klass_object.instance_eval do
174
- within_foo_element('Hello', 'super', wait: 10, text: 'new') do
175
- bar_element(wait: 10, text: 'new')
176
- end
177
- end
178
- end
179
- it do
180
- expect(klass_object.capybara_context).to receive(:find)
181
- .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first) { within_scope }
182
- expect(within_scope).to receive(:find).with('.someclass', wait: 10, text: 'new', match: :first)
183
- end
184
- end
185
- end
186
- context 'nested' do
187
- let(:nested_within_scope) { double }
188
- subject do
189
- klass_object.instance_eval do
190
- within_top_panel_element(wait: 10, text: 'new') do
191
- within_bar_element(wait: 10, text: 'new') do
192
- foo_element('Hello', 'super', wait: 10, text: 'new')
193
- end
194
- end
195
- end
196
- end
197
- it do
198
- expect(klass_object.capybara_context).to receive(:find)
199
- .with('.top', wait: 10, text: 'new', match: :first) { within_scope }
200
- expect(within_scope).to receive(:find)
201
- .with('.someclass', wait: 10, text: 'new', match: :first) { nested_within_scope }
202
- expect(nested_within_scope).to receive(:find)
203
- .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
204
- end
205
- end
206
- end
207
- describe '#has_name_element?' do
208
- after { subject }
209
- context 'when simple selector' do
210
- subject { klass_object.send(:has_bar_element?, wait: 10, text: 'new') }
211
- it do
212
- expect(klass_object.capybara_context).to receive(:has_selector?)
213
- .with('.someclass', wait: 10, text: 'new', match: :first)
214
- end
215
- end
216
- context 'when lambda selector' do
217
- subject { klass_object.send(:has_foo_element?, 'Hello', 'super', wait: 10, text: 'new') }
218
- it do
219
- expect(klass_object.capybara_context).to receive(:has_selector?)
220
- .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
221
- end
222
- end
223
- end
224
- describe '#has_no_name_element?' do
225
- after { subject }
226
- context 'when simple selector' do
227
- subject { klass_object.send(:has_no_bar_element?, wait: 10, text: 'new') }
228
- it do
229
- expect(klass_object.capybara_context).to receive(:has_no_selector?)
230
- .with('.someclass', wait: 10, text: 'new', match: :first)
231
- end
232
- end
233
- context 'when lambda selector' do
234
- subject { klass_object.send(:has_no_foo_element?, 'Hello', 'super', wait: 10, text: 'new', match: :first) }
235
- it do
236
- expect(klass_object.capybara_context).to receive(:has_no_selector?)
237
- .with(:xpath, "//a[.='Hello']/*[@name='super']", wait: 10, text: 'new', match: :first)
238
- end
239
- end
240
- end
241
- end
242
- end
@@ -1,41 +0,0 @@
1
- RSpec.shared_examples :meta_highlight_xpath do
2
- let(:element) { described_class.new(name, context) }
3
- describe '#xpath' do
4
- let(:capybara_element) { double }
5
- context 'when element is found' do
6
- before { allow(element).to receive(:capybara_element) { capybara_element } }
7
- it do
8
- expect(capybara_element).to receive(:path)
9
- element.xpath
10
- end
11
- end
12
- context 'when element is blank' do
13
- before { allow(element).to receive(:capybara_element) {} }
14
- it do
15
- expect(capybara_element).not_to receive(:path)
16
- element.xpath
17
- end
18
- end
19
- end
20
-
21
- describe '#highlight' do
22
- context 'when xpath blank' do
23
- before { allow(element).to receive(:xpath) { nil } }
24
- it do
25
- expect(Howitzer::Log).to receive(:debug).with("Element #{name} not found on the page")
26
- expect(context).not_to receive(:execute_script)
27
- element.highlight
28
- end
29
- end
30
- context 'when xpath is present' do
31
- before { allow(element).to receive(:xpath) { '//a' } }
32
- it do
33
- expect(context).to receive(:execute_script).with(
34
- "document.evaluate('//a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,"\
35
- ' null).singleNodeValue.style.border = "thick solid red"'
36
- )
37
- element.highlight
38
- end
39
- end
40
- end
41
- end
@@ -1,283 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Howitzer::BaseGenerator do
4
- let(:output) { StringIO.new }
5
- let(:destination) { Dir.mktmpdir }
6
-
7
- describe '.logger' do
8
- subject { described_class.logger }
9
- before { described_class.instance_variable_set('@logger', output) }
10
- it { is_expected.to eq(output) }
11
- end
12
-
13
- describe '.logger=' do
14
- subject { described_class.instance_variable_get('@logger') }
15
- before { described_class.logger = output }
16
- it { is_expected.to eq(output) }
17
- end
18
-
19
- describe '.destination' do
20
- subject { described_class.destination }
21
- before { described_class.instance_variable_set('@destination', destination) }
22
- it { is_expected.to eq(destination) }
23
- end
24
-
25
- describe '.destination=' do
26
- subject { described_class.instance_variable_get('@destination') }
27
- before { described_class.destination = destination }
28
- it { is_expected.to eq(destination) }
29
- end
30
-
31
- describe 'constructor' do
32
- let(:list1) { double(:list1) }
33
- let(:list2) { double(:list2) }
34
- let(:options) { { r: true, rspec: true } }
35
- subject { described_class.new(options) }
36
- before do
37
- expect_any_instance_of(described_class).to receive(:print_banner).with(no_args).once
38
- allow_any_instance_of(described_class).to receive(:manifest) do
39
- {
40
- files: list1,
41
- templates: list2,
42
- unknown: nil
43
- }
44
- end
45
- end
46
- it do
47
- expect_any_instance_of(described_class).to receive(:copy_files).with(list1).once
48
- expect_any_instance_of(described_class).to receive(:copy_templates).with(list2).once
49
- expect(subject.instance_variable_get(:@options)).to eql options
50
- end
51
- end
52
-
53
- describe '#manifest' do
54
- subject { described_class.new({}).manifest }
55
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
56
- it { is_expected.to eq([]) }
57
- end
58
-
59
- describe '#banner' do
60
- subject { described_class.new({}).send(:banner) }
61
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
62
- it { is_expected.to be_nil }
63
- end
64
-
65
- describe '#logger' do
66
- subject { described_class.new({}).send(:logger) }
67
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
68
- context 'when not specified' do
69
- before { described_class.instance_variable_set('@logger', nil) }
70
- it { is_expected.to eq($stdout) }
71
- end
72
- context 'when custom' do
73
- let(:output) { StringIO.new }
74
- before { described_class.instance_variable_set('@logger', output) }
75
- it { is_expected.to eq(output) }
76
- end
77
- end
78
-
79
- describe '#destination' do
80
- subject { described_class.new({}).send(:destination) }
81
- before do
82
- allow_any_instance_of(described_class).to receive(:print_banner) { nil }
83
- allow(described_class).to receive(:destination) { '/' }
84
- end
85
- it { is_expected.to eq('/') }
86
- end
87
-
88
- describe '#copy_files' do
89
- let(:list) { [{ source: 'example.txt' }] }
90
- let(:source_path) { '/example_path/example.txt' }
91
- let(:generator) { described_class.new({}) }
92
- subject { generator.send(:copy_files, list) }
93
- before do
94
- allow_any_instance_of(described_class).to receive(:print_banner) { nil }
95
- allow(generator).to receive(:source_path).with(list.first[:source]) { source_path }
96
- end
97
- after { subject }
98
- context 'when source_file exists' do
99
- before { allow(File).to receive(:exist?).with(source_path) { true } }
100
- it { expect(generator).to receive(:copy_with_path).with(list.first).once }
101
- end
102
- context 'when source_file missing' do
103
- before { allow(File).to receive(:exist?).with(source_path) { false } }
104
- it { expect(generator).to receive(:puts_error).with("File '/example_path/example.txt' was not found.").once }
105
- end
106
- end
107
-
108
- describe '#copy_templates' do
109
- let(:list) { [{ source: 'example.txt.erb', destination: 'example.txt' }] }
110
- let(:source_path) { '/example_path/example.txt.erb' }
111
- let(:destination_path) { '/example_path/example.txt' }
112
- let(:generator) { described_class.new('rspec' => true) }
113
- subject { generator.send(:copy_templates, list) }
114
- before do
115
- allow_any_instance_of(described_class).to receive(:print_banner) { nil }
116
- allow(generator).to receive(:source_path).with(list.first[:source]) { source_path }
117
- allow(generator).to receive(:dest_path).with(list.first[:destination]) { destination_path }
118
- allow(generator).to receive(:write_template).with(destination_path, source_path)
119
- allow(generator).to receive(:gets) { 'h' }
120
- end
121
- after { subject }
122
- context 'when destination file exists' do
123
- before { allow(File).to receive(:exist?).with(destination_path) { true } }
124
- it do
125
- expect(generator).to receive(:puts_info).with(
126
- ColorizedString.new("Conflict with '#{list.first[:destination]}' template").yellow
127
- ).once
128
- end
129
- it do
130
- expect(generator).to receive(:print_info).with(
131
- ColorizedString.new(" Overwrite '#{list.first[:destination]}' template? [Yn]:").yellow
132
- ).once
133
- end
134
- context 'and answer is yes' do
135
- before { allow(generator).to receive(:gets) { 'y' } }
136
- it { expect(generator).to receive(:write_template).with(destination_path, source_path).once }
137
- it { expect(generator).to receive(:puts_info).twice }
138
- end
139
- context 'and answer is no' do
140
- before { allow(generator).to receive(:gets) { 'n' } }
141
- it { expect(generator).to receive(:puts_info).twice }
142
- end
143
- end
144
- context 'when source file exists' do
145
- before { allow(File).to receive(:exist?).with(destination_path) { false } }
146
- it { expect(generator).to receive(:write_template).with(destination_path, source_path).once }
147
- end
148
- end
149
-
150
- describe '#print_banner' do
151
- let(:generator) { described_class.new({}) }
152
- subject { generator.send(:print_banner) }
153
- before do
154
- allow_any_instance_of(described_class).to receive(:banner) { banner }
155
- end
156
- after { subject }
157
- context 'when banner present' do
158
- let(:banner) { 'banner' }
159
- it { expect(described_class.logger).to receive(:puts).with(ColorizedString.new(banner.chomp).light_cyan).twice }
160
- end
161
- context 'when banner blank' do
162
- let(:banner) { '' }
163
- it { expect(described_class.logger).not_to receive(:puts) }
164
- end
165
- end
166
-
167
- describe '#print_info' do
168
- subject { described_class.new({}).send(:print_info, 'data') }
169
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
170
- after { subject }
171
- it { expect(described_class.logger).to receive(:print).with(' data') }
172
- end
173
-
174
- describe '#puts_info' do
175
- subject { described_class.new({}).send(:puts_info, 'data') }
176
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
177
- after { subject }
178
- it { expect(described_class.logger).to receive(:puts).with(' data') }
179
- end
180
-
181
- describe '#puts_error' do
182
- subject { described_class.new({}).send(:puts_error, 'data') }
183
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
184
- after { subject }
185
- it { expect(described_class.logger).to receive(:puts).with(ColorizedString.new(' ERROR: data').red) }
186
- end
187
-
188
- describe '#source_path' do
189
- subject { described_class.new({}).send(:source_path, 'example.txt') }
190
- before do
191
- allow_any_instance_of(described_class).to receive(:print_banner) { nil }
192
- end
193
- it { is_expected.to include('/base/templates/example.txt') }
194
- end
195
-
196
- describe '#dest_path' do
197
- subject { described_class.new({}).send(:dest_path, 'example.txt') }
198
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
199
- it { is_expected.to include('/example.txt') }
200
- end
201
-
202
- describe '#copy_with_path' do
203
- let(:generator) { described_class.new({}) }
204
- let(:data) { { source: 's.txt', destination: 'd.txt' } }
205
- let(:src) { '/path/to/s.txt' }
206
- let(:dst) { '/path/to/d.txt' }
207
- subject { generator.send(:copy_with_path, data) }
208
- before do
209
- allow_any_instance_of(described_class).to receive(:print_banner) { nil }
210
- allow(generator).to receive(:source_path).with('s.txt') { src }
211
- allow(generator).to receive(:dest_path).with('d.txt') { dst }
212
- allow(FileUtils).to receive(:mkdir_p).with('/path/to') { true }
213
- end
214
- after { subject }
215
- context 'when destination file present' do
216
- before { allow(File).to receive(:exist?).with(dst) { true } }
217
- context 'when identical with source file' do
218
- before { allow(FileUtils).to receive(:identical?).with(src, dst) { true } }
219
- it do
220
- expect(generator).to receive(:puts_info).with("#{ColorizedString.new('Identical').light_green}"\
221
- " 'd.txt' file").once
222
- end
223
- end
224
- context 'when not identical with source file' do
225
- before do
226
- allow(FileUtils).to receive(:identical?).with(src, dst) { false }
227
- expect(generator).to receive(:puts_info).with(ColorizedString.new("Conflict with 'd.txt' file").yellow)
228
- expect(generator).to receive(:print_info).with(ColorizedString.new(" Overwrite 'd.txt' file? [Yn]:").yellow)
229
- end
230
- context 'when user typed Y' do
231
- before { allow(generator).to receive(:gets) { 'Y' } }
232
- it do
233
- expect(FileUtils).to receive(:cp).with(src, dst) { nil }.once
234
- expect(generator).to receive(:puts_info).with(" #{ColorizedString.new('Forced').light_green}"\
235
- " 'd.txt' file")
236
- end
237
- end
238
- context 'when user typed y' do
239
- before { allow(generator).to receive(:gets) { 'y' } }
240
- it do
241
- expect(FileUtils).to receive(:cp).with(src, dst) { nil }.once
242
- expect(generator).to receive(:puts_info).with(" #{ColorizedString.new('Forced').light_green}"\
243
- " 'd.txt' file")
244
- end
245
- end
246
- context 'when user typed N' do
247
- before { allow(generator).to receive(:gets) { 'N' } }
248
- it do
249
- expect(generator).to receive(:puts_info).with(" #{ColorizedString.new('Skipped').light_black}"\
250
- " 'd.txt' file")
251
- expect(FileUtils).not_to receive(:cp)
252
- end
253
- end
254
- context 'when user typed n' do
255
- before { allow(generator).to receive(:gets) { 'n' } }
256
- it do
257
- expect(generator).to receive(:puts_info).with(" #{ColorizedString.new('Skipped').light_black}"\
258
- " 'd.txt' file")
259
- expect(FileUtils).not_to receive(:cp)
260
- end
261
- end
262
- context 'when user typed hello' do
263
- before { allow(generator).to receive(:gets) { 'hello' } }
264
- it do
265
- expect(generator).not_to receive(:puts_info)
266
- expect(FileUtils).not_to receive(:cp)
267
- end
268
- end
269
- end
270
- end
271
- context 'when destination file missing' do
272
- before { allow(File).to receive(:exist?).with(dst) { false } }
273
- it do
274
- expect(generator).to receive(:puts_info).with("#{ColorizedString.new('Added').light_green} 'd.txt' file")
275
- expect(FileUtils).to receive(:cp).with(src, dst).once
276
- end
277
- end
278
- context 'when exception happened' do
279
- before { allow(FileUtils).to receive(:mkdir_p).and_raise(StandardError.new('Some error')) }
280
- it { expect(generator).to receive(:puts_error).with("Impossible to create 'd.txt' file. Reason: Some error") }
281
- end
282
- end
283
- end
@@ -1,61 +0,0 @@
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::ConfigGenerator do
14
- let(:generator_name) { described_class }
15
- let(:expected_result) do
16
- [
17
- { name: '/config', is_directory: true },
18
- { name: '/config/boot.rb', is_directory: false, size: template_file_size('config', 'boot.rb') },
19
- { name: '/config/capybara.rb', is_directory: false, size: template_file_size('config', 'capybara.rb') },
20
- { name: '/config/custom.yml', is_directory: false, size: template_file_size('config', 'custom.yml') },
21
- { name: '/config/default.yml', is_directory: false, size: template_file_size('config', 'default.yml') },
22
- { name: '/config/drivers', is_directory: true },
23
- { name: '/config/drivers/appium.rb', is_directory: false, size: 723 },
24
- { name: '/config/drivers/browserstack.rb', is_directory: false, size: 1018 },
25
- { name: '/config/drivers/crossbrowsertesting.rb', is_directory: false, size: 1237 },
26
- { name: '/config/drivers/headless_chrome.rb', is_directory: false, size: 649 },
27
- { name: '/config/drivers/headless_firefox.rb', is_directory: false, size: 1059 },
28
- { name: '/config/drivers/poltergeist.rb', is_directory: false, size: 362 },
29
- { name: '/config/drivers/sauce.rb', is_directory: false, size: 968 },
30
- { name: '/config/drivers/selenium.rb', is_directory: false, size: 1097 },
31
- { name: '/config/drivers/selenium_grid.rb', is_directory: false, size: 1377 },
32
- { name: '/config/drivers/testingbot.rb', is_directory: false, size: 906 },
33
- { name: '/config/drivers/webkit.rb', is_directory: false, size: 179 }
34
- ]
35
- end
36
-
37
- it { is_expected.to eql(expected_result) }
38
- describe 'output' do
39
- let(:expected_output) do
40
- "#{ColorizedString.new(' * Config files generation ...').light_cyan}
41
- #{ColorizedString.new('Added').light_green} 'config/boot.rb' file
42
- #{ColorizedString.new('Added').light_green} 'config/custom.yml' file
43
- #{ColorizedString.new('Added').light_green} 'config/capybara.rb' file
44
- #{ColorizedString.new('Added').light_green} 'config/default.yml' file
45
- #{ColorizedString.new('Added').light_green} 'config/drivers/appium.rb' file
46
- #{ColorizedString.new('Added').light_green} 'config/drivers/browserstack.rb' file
47
- #{ColorizedString.new('Added').light_green} 'config/drivers/crossbrowsertesting.rb' file
48
- #{ColorizedString.new('Added').light_green} 'config/drivers/headless_chrome.rb' file
49
- #{ColorizedString.new('Added').light_green} 'config/drivers/headless_firefox.rb' file
50
- #{ColorizedString.new('Added').light_green} 'config/drivers/poltergeist.rb' file
51
- #{ColorizedString.new('Added').light_green} 'config/drivers/sauce.rb' file
52
- #{ColorizedString.new('Added').light_green} 'config/drivers/selenium.rb' file
53
- #{ColorizedString.new('Added').light_green} 'config/drivers/selenium_grid.rb' file
54
- #{ColorizedString.new('Added').light_green} 'config/drivers/testingbot.rb' file
55
- #{ColorizedString.new('Added').light_green} 'config/drivers/webkit.rb' file\n"
56
- end
57
- subject { output.string }
58
- it { is_expected.to eql(expected_output) }
59
- end
60
- end
61
- end