howitzer 2.0.3 → 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 (139) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +69 -11
  3. data/LICENSE +1 -1
  4. data/README.md +21 -17
  5. data/bin/howitzer +7 -6
  6. data/generators/base_generator.rb +31 -17
  7. data/generators/config/config_generator.rb +11 -3
  8. data/generators/config/templates/boot.rb +3 -3
  9. data/generators/config/templates/capybara.rb +6 -131
  10. data/generators/config/templates/default.yml +34 -13
  11. data/generators/config/templates/drivers/appium.rb +25 -0
  12. data/generators/config/templates/drivers/browserstack.rb +23 -0
  13. data/generators/config/templates/drivers/crossbrowsertesting.rb +29 -0
  14. data/generators/config/templates/drivers/headless_chrome.rb +15 -0
  15. data/generators/config/templates/drivers/headless_firefox.rb +23 -0
  16. data/generators/config/templates/drivers/sauce.rb +25 -0
  17. data/generators/config/templates/drivers/selenium.rb +24 -0
  18. data/generators/config/templates/drivers/selenium_grid.rb +31 -0
  19. data/generators/config/templates/drivers/testingbot.rb +24 -0
  20. data/generators/cucumber/cucumber_generator.rb +2 -2
  21. data/generators/cucumber/templates/common_steps.rb +3 -3
  22. data/generators/cucumber/templates/cucumber.rake +5 -13
  23. data/generators/cucumber/templates/cuke_sniffer.rake +2 -2
  24. data/generators/cucumber/templates/env.rb +9 -1
  25. data/generators/cucumber/templates/hooks.rb +8 -2
  26. data/generators/cucumber/templates/transformers.rb +11 -25
  27. data/generators/emails/emails_generator.rb +2 -2
  28. data/generators/emails/templates/example_email.rb +1 -1
  29. data/generators/prerequisites/prerequisites_generator.rb +3 -3
  30. data/generators/prerequisites/templates/base.rb +1 -1
  31. data/generators/prerequisites/templates/{factory_girl.rb → factory_bot.rb} +7 -6
  32. data/generators/prerequisites/templates/users.rb +1 -1
  33. data/generators/root/root_generator.rb +3 -3
  34. data/generators/root/templates/Gemfile.erb +16 -22
  35. data/generators/rspec/rspec_generator.rb +2 -2
  36. data/generators/rspec/templates/rspec.rake +8 -8
  37. data/generators/rspec/templates/spec_helper.rb +6 -5
  38. data/generators/tasks/tasks_generator.rb +2 -2
  39. data/generators/turnip/templates/spec_helper.rb +6 -5
  40. data/generators/turnip/turnip_generator.rb +2 -2
  41. data/generators/web/templates/example_page.rb +1 -1
  42. data/generators/web/web_generator.rb +2 -2
  43. data/lib/howitzer/cache.rb +20 -19
  44. data/lib/howitzer/capybara_helpers.rb +58 -13
  45. data/lib/howitzer/email.rb +3 -2
  46. data/lib/howitzer/exceptions.rb +21 -20
  47. data/lib/howitzer/gmail_api/client.rb +31 -0
  48. data/lib/howitzer/gmail_api.rb +7 -0
  49. data/lib/howitzer/log.rb +6 -6
  50. data/lib/howitzer/mail_adapters/gmail.rb +96 -0
  51. data/lib/howitzer/mail_adapters/mailgun.rb +4 -2
  52. data/lib/howitzer/mail_adapters/mailtrap.rb +108 -0
  53. data/lib/howitzer/mailgun_api/client.rb +3 -2
  54. data/lib/howitzer/mailgun_api/connector.rb +1 -0
  55. data/lib/howitzer/mailgun_api/response.rb +1 -2
  56. data/lib/howitzer/mailtrap_api/client.rb +52 -0
  57. data/lib/howitzer/mailtrap_api.rb +7 -0
  58. data/lib/howitzer/meta/actions.rb +35 -0
  59. data/lib/howitzer/meta/element.rb +40 -0
  60. data/lib/howitzer/meta/entry.rb +62 -0
  61. data/lib/howitzer/meta/iframe.rb +41 -0
  62. data/lib/howitzer/meta/section.rb +30 -0
  63. data/lib/howitzer/meta.rb +11 -0
  64. data/lib/howitzer/utils/string_extensions.rb +6 -2
  65. data/lib/howitzer/version.rb +1 -1
  66. data/lib/howitzer/web/base_section.rb +1 -1
  67. data/lib/howitzer/web/capybara_context_holder.rb +1 -0
  68. data/lib/howitzer/web/capybara_methods_proxy.rb +15 -6
  69. data/lib/howitzer/web/element_dsl.rb +104 -44
  70. data/lib/howitzer/web/iframe_dsl.rb +23 -3
  71. data/lib/howitzer/web/page.rb +16 -4
  72. data/lib/howitzer/web/page_dsl.rb +19 -7
  73. data/lib/howitzer/web/page_validator.rb +27 -26
  74. data/lib/howitzer/web/section.rb +13 -2
  75. data/lib/howitzer/web/section_dsl.rb +65 -30
  76. data/lib/howitzer.rb +66 -10
  77. metadata +67 -133
  78. data/.coveralls.yml +0 -1
  79. data/.gitignore +0 -14
  80. data/.rspec +0 -3
  81. data/.rubocop.yml +0 -44
  82. data/.ruby-gemset +0 -1
  83. data/.travis.yml +0 -7
  84. data/Gemfile +0 -13
  85. data/MAINTENANCE.md +0 -32
  86. data/Rakefile +0 -22
  87. data/features/cli_help.feature +0 -31
  88. data/features/cli_new.feature +0 -349
  89. data/features/cli_unknown.feature +0 -17
  90. data/features/cli_update.feature +0 -178
  91. data/features/cli_version.feature +0 -14
  92. data/features/step_definitions/common_steps.rb +0 -29
  93. data/features/support/env.rb +0 -1
  94. data/features/support/transformers.rb +0 -3
  95. data/generators/root/templates/.gitignore +0 -21
  96. data/generators/root/templates/.rubocop.yml +0 -35
  97. data/generators/turnip/templates/.rspec +0 -1
  98. data/howitzer.gemspec +0 -37
  99. data/lib/howitzer/mail_adapters/debugmail.rb +0 -0
  100. data/spec/config/custom.yml +0 -9
  101. data/spec/spec_helper.rb +0 -72
  102. data/spec/support/generator_helper.rb +0 -21
  103. data/spec/support/logger_helper.rb +0 -13
  104. data/spec/support/mailgun_unit_client.rb +0 -68
  105. data/spec/support/shared_examples/capybara_context_holder.rb +0 -33
  106. data/spec/support/shared_examples/capybara_methods_proxy.rb +0 -94
  107. data/spec/support/shared_examples/dynamic_section_methods.rb +0 -35
  108. data/spec/support/shared_examples/element_dsl.rb +0 -242
  109. data/spec/unit/generators/base_generator_spec.rb +0 -272
  110. data/spec/unit/generators/config_generator_spec.rb +0 -38
  111. data/spec/unit/generators/cucumber_generator_spec.rb +0 -62
  112. data/spec/unit/generators/emails_generator_spec.rb +0 -35
  113. data/spec/unit/generators/prerequisites_generator_spec.rb +0 -53
  114. data/spec/unit/generators/root_generator_spec.rb +0 -72
  115. data/spec/unit/generators/rspec_generator_spec.rb +0 -36
  116. data/spec/unit/generators/tasks_generator_spec.rb +0 -31
  117. data/spec/unit/generators/turnip_generator_spec.rb +0 -52
  118. data/spec/unit/generators/web_generator_spec.rb +0 -52
  119. data/spec/unit/lib/cache_spec.rb +0 -85
  120. data/spec/unit/lib/capybara_helpers_spec.rb +0 -696
  121. data/spec/unit/lib/email_spec.rb +0 -186
  122. data/spec/unit/lib/howitzer_spec.rb +0 -40
  123. data/spec/unit/lib/init_spec.rb +0 -2
  124. data/spec/unit/lib/log_spec.rb +0 -122
  125. data/spec/unit/lib/mail_adapters/abstract_spec.rb +0 -62
  126. data/spec/unit/lib/mail_adapters/mailgun_spec.rb +0 -163
  127. data/spec/unit/lib/mailgun_api/client_spec.rb +0 -58
  128. data/spec/unit/lib/mailgun_api/connector_spec.rb +0 -54
  129. data/spec/unit/lib/mailgun_api/response_spec.rb +0 -28
  130. data/spec/unit/lib/utils/string_extensions_spec.rb +0 -77
  131. data/spec/unit/lib/web/base_section_spec.rb +0 -43
  132. data/spec/unit/lib/web/element_dsl_spec.rb +0 -22
  133. data/spec/unit/lib/web/iframe_dsl_spec.rb +0 -144
  134. data/spec/unit/lib/web/page_dsl_spec.rb +0 -74
  135. data/spec/unit/lib/web/page_spec.rb +0 -349
  136. data/spec/unit/lib/web/page_validator_spec.rb +0 -276
  137. data/spec/unit/lib/web/section_dsl_spec.rb +0 -165
  138. data/spec/unit/lib/web/section_spec.rb +0 -63
  139. data/spec/unit/version_spec.rb +0 -8
@@ -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,272 +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 { expect(generator).to receive(:puts_info).with("Conflict with '#{list.first[:destination]}' template").once }
125
- it do
126
- expect(generator).to receive(:print_info).with(
127
- " Overwrite '#{list.first[:destination]}' template? [Yn]:"
128
- ).once
129
- end
130
- context 'and answer is yes' do
131
- before { allow(generator).to receive(:gets) { 'y' } }
132
- it { expect(generator).to receive(:write_template).with(destination_path, source_path).once }
133
- it { expect(generator).to receive(:puts_info).twice }
134
- end
135
- context 'and answer is no' do
136
- before { allow(generator).to receive(:gets) { 'n' } }
137
- it { expect(generator).to receive(:puts_info).twice }
138
- end
139
- end
140
- context 'when source file exists' do
141
- before { allow(File).to receive(:exist?).with(destination_path) { false } }
142
- it { expect(generator).to receive(:write_template).with(destination_path, source_path).once }
143
- end
144
- end
145
-
146
- describe '#print_banner' do
147
- let(:generator) { described_class.new({}) }
148
- subject { generator.send(:print_banner) }
149
- before do
150
- allow_any_instance_of(described_class).to receive(:banner) { banner }
151
- end
152
- after { subject }
153
- context 'when banner present' do
154
- let(:banner) { 'banner' }
155
- it { expect(described_class.logger).to receive(:puts).with(banner).twice }
156
- end
157
- context 'when banner blank' do
158
- let(:banner) { '' }
159
- it { expect(described_class.logger).not_to receive(:puts) }
160
- end
161
- end
162
-
163
- describe '#print_info' do
164
- subject { described_class.new({}).send(:print_info, 'data') }
165
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
166
- after { subject }
167
- it { expect(described_class.logger).to receive(:print).with(' data') }
168
- end
169
-
170
- describe '#puts_info' do
171
- subject { described_class.new({}).send(:puts_info, 'data') }
172
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
173
- after { subject }
174
- it { expect(described_class.logger).to receive(:puts).with(' data') }
175
- end
176
-
177
- describe '#puts_error' do
178
- subject { described_class.new({}).send(:puts_error, 'data') }
179
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
180
- after { subject }
181
- it { expect(described_class.logger).to receive(:puts).with(' ERROR: data') }
182
- end
183
-
184
- describe '#source_path' do
185
- subject { described_class.new({}).send(:source_path, 'example.txt') }
186
- before do
187
- allow_any_instance_of(described_class).to receive(:print_banner) { nil }
188
- end
189
- it { is_expected.to include('/base/templates/example.txt') }
190
- end
191
-
192
- describe '#dest_path' do
193
- subject { described_class.new({}).send(:dest_path, 'example.txt') }
194
- before { allow_any_instance_of(described_class).to receive(:print_banner) { nil } }
195
- it { is_expected.to include('/example.txt') }
196
- end
197
-
198
- describe '#copy_with_path' do
199
- let(:generator) { described_class.new({}) }
200
- let(:data) { { source: 's.txt', destination: 'd.txt' } }
201
- let(:src) { '/path/to/s.txt' }
202
- let(:dst) { '/path/to/d.txt' }
203
- subject { generator.send(:copy_with_path, data) }
204
- before do
205
- allow_any_instance_of(described_class).to receive(:print_banner) { nil }
206
- allow(generator).to receive(:source_path).with('s.txt') { src }
207
- allow(generator).to receive(:dest_path).with('d.txt') { dst }
208
- allow(FileUtils).to receive(:mkdir_p).with('/path/to') { true }
209
- end
210
- after { subject }
211
- context 'when destination file present' do
212
- before { allow(File).to receive(:exist?).with(dst) { true } }
213
- context 'when identical with source file' do
214
- before { allow(FileUtils).to receive(:identical?).with(src, dst) { true } }
215
- it { expect(generator).to receive(:puts_info).with("Identical 'd.txt' file").once }
216
- end
217
- context 'when not identical with source file' do
218
- before do
219
- allow(FileUtils).to receive(:identical?).with(src, dst) { false }
220
- expect(generator).to receive(:puts_info).with("Conflict with 'd.txt' file")
221
- expect(generator).to receive(:print_info).with(" Overwrite 'd.txt' file? [Yn]:")
222
- end
223
- context 'when user typed Y' do
224
- before { allow(generator).to receive(:gets) { 'Y' } }
225
- it do
226
- expect(FileUtils).to receive(:cp).with(src, dst) { nil }.once
227
- expect(generator).to receive(:puts_info).with(" Forced 'd.txt' file")
228
- end
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(" Forced 'd.txt' file")
235
- end
236
- end
237
- context 'when user typed N' do
238
- before { allow(generator).to receive(:gets) { 'N' } }
239
- it do
240
- expect(generator).to receive(:puts_info).with(" Skipped 'd.txt' file")
241
- expect(FileUtils).not_to receive(:cp)
242
- end
243
- end
244
- context 'when user typed n' do
245
- before { allow(generator).to receive(:gets) { 'n' } }
246
- it do
247
- expect(generator).to receive(:puts_info).with(" Skipped 'd.txt' file")
248
- expect(FileUtils).not_to receive(:cp)
249
- end
250
- end
251
- context 'when user typed hello' do
252
- before { allow(generator).to receive(:gets) { 'hello' } }
253
- it do
254
- expect(generator).not_to receive(:puts_info)
255
- expect(FileUtils).not_to receive(:cp)
256
- end
257
- end
258
- end
259
- end
260
- context 'when destination file missing' do
261
- before { allow(File).to receive(:exist?).with(dst) { false } }
262
- it do
263
- expect(generator).to receive(:puts_info).with("Added 'd.txt' file")
264
- expect(FileUtils).to receive(:cp).with(src, dst).once
265
- end
266
- end
267
- context 'when exception happened' do
268
- before { allow(FileUtils).to receive(:mkdir_p).and_raise(StandardError.new('Some error')) }
269
- it { expect(generator).to receive(:puts_error).with("Impossible to create 'd.txt' file. Reason: Some error") }
270
- end
271
- end
272
- end
@@ -1,38 +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
- ]
23
- end
24
-
25
- it { is_expected.to eql(expected_result) }
26
- describe 'output' do
27
- let(:expected_output) do
28
- " * Config files generation ...
29
- Added 'config/boot.rb' file
30
- Added 'config/custom.yml' file
31
- Added 'config/capybara.rb' file
32
- Added 'config/default.yml' file\n"
33
- end
34
- subject { output.string }
35
- it { is_expected.to eql(expected_output) }
36
- end
37
- end
38
- end
@@ -1,62 +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(cucumber: true)
10
- end
11
- after { FileUtils.rm_r(destination) }
12
-
13
- describe Howitzer::CucumberGenerator do
14
- let(:generator_name) { described_class }
15
- let(:expected_result) do
16
- [
17
- { name: '/features', is_directory: true },
18
- {
19
- name: '/features/example.feature',
20
- is_directory: false,
21
- size: template_file_size('cucumber', 'example.feature')
22
- },
23
- { name: '/features/step_definitions', is_directory: true },
24
- {
25
- name: '/features/step_definitions/common_steps.rb',
26
- is_directory: false,
27
- size: template_file_size('cucumber', 'common_steps.rb')
28
- },
29
- { name: '/features/support', is_directory: true },
30
- { name: '/features/support/env.rb', is_directory: false, size: template_file_size('cucumber', 'env.rb') },
31
- { name: '/features/support/hooks.rb', is_directory: false, size: template_file_size('cucumber', 'hooks.rb') },
32
- {
33
- name: '/features/support/transformers.rb',
34
- is_directory: false,
35
- size: template_file_size('cucumber', 'transformers.rb')
36
- },
37
- { name: '/tasks', is_directory: true },
38
- { name: '/tasks/cucumber.rake', is_directory: false, size: template_file_size('cucumber', 'cucumber.rake') },
39
- {
40
- name: '/tasks/cuke_sniffer.rake',
41
- is_directory: false,
42
- size: template_file_size('cucumber', 'cuke_sniffer.rake')
43
- }
44
- ]
45
- end
46
- it { is_expected.to eql(expected_result) }
47
- describe 'output' do
48
- let(:expected_output) do
49
- " * Cucumber integration to the framework ...
50
- Added 'features/step_definitions/common_steps.rb' file
51
- Added 'features/support/env.rb' file
52
- Added 'features/support/hooks.rb' file
53
- Added 'features/support/transformers.rb' file
54
- Added 'features/example.feature' file
55
- Added 'tasks/cucumber.rake' file
56
- Added 'tasks/cuke_sniffer.rake' file\n"
57
- end
58
- subject { output.string }
59
- it { is_expected.to eql(expected_output) }
60
- end
61
- end
62
- end
@@ -1,35 +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::EmailsGenerator do
14
- let(:generator_name) { described_class }
15
- let(:expected_result) do
16
- [
17
- { name: '/emails', is_directory: true },
18
- {
19
- name: '/emails/example_email.rb',
20
- is_directory: false,
21
- size: template_file_size('emails', 'example_email.rb')
22
- }
23
- ]
24
- end
25
- it { is_expected.to eql(expected_result) }
26
- describe 'output' do
27
- let(:expected_output) do
28
- " * Email example generation ...
29
- Added '/emails/example_email.rb' file\n"
30
- end
31
- subject { output.string }
32
- it { is_expected.to eql(expected_output) }
33
- end
34
- end
35
- end