howitzer 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +27 -18
  3. data/.travis.yml +4 -3
  4. data/CHANGELOG.md +15 -1
  5. data/README.md +6 -3
  6. data/Rakefile +1 -1
  7. data/features/cli_new.feature +12 -8
  8. data/features/cli_update.feature +14 -9
  9. data/features/step_definitions/common_steps.rb +3 -3
  10. data/generators/base_generator.rb +1 -1
  11. data/generators/config/config_generator.rb +2 -1
  12. data/generators/config/templates/boot.rb +1 -1
  13. data/generators/config/templates/capybara.rb +2 -1
  14. data/generators/config/templates/default.yml +22 -4
  15. data/generators/config/templates/drivers/appium.rb +25 -0
  16. data/generators/config/templates/drivers/headless_firefox.rb +23 -0
  17. data/generators/cucumber/templates/cuke_sniffer.rake +2 -2
  18. data/generators/cucumber/templates/env.rb +8 -0
  19. data/generators/prerequisites/templates/factory_bot.rb +1 -0
  20. data/generators/root/root_generator.rb +1 -1
  21. data/generators/root/templates/{.rubocop.yml → .rubocop.yml.erb} +34 -13
  22. data/generators/root/templates/Gemfile.erb +4 -0
  23. data/generators/rspec/templates/spec_helper.rb +1 -0
  24. data/generators/turnip/templates/spec_helper.rb +1 -0
  25. data/howitzer.gemspec +3 -3
  26. data/lib/howitzer.rb +40 -0
  27. data/lib/howitzer/cache.rb +19 -18
  28. data/lib/howitzer/capybara_helpers.rb +13 -5
  29. data/lib/howitzer/email.rb +1 -0
  30. data/lib/howitzer/mail_adapters/gmail.rb +3 -0
  31. data/lib/howitzer/mail_adapters/mailgun.rb +2 -0
  32. data/lib/howitzer/mail_adapters/mailtrap.rb +3 -0
  33. data/lib/howitzer/mailgun_api/connector.rb +1 -0
  34. data/lib/howitzer/meta.rb +11 -0
  35. data/lib/howitzer/meta/actions.rb +38 -0
  36. data/lib/howitzer/meta/element.rb +38 -0
  37. data/lib/howitzer/meta/entry.rb +62 -0
  38. data/lib/howitzer/meta/iframe.rb +41 -0
  39. data/lib/howitzer/meta/section.rb +30 -0
  40. data/lib/howitzer/version.rb +1 -1
  41. data/lib/howitzer/web/capybara_context_holder.rb +1 -0
  42. data/lib/howitzer/web/capybara_methods_proxy.rb +4 -1
  43. data/lib/howitzer/web/element_dsl.rb +1 -0
  44. data/lib/howitzer/web/iframe_dsl.rb +2 -0
  45. data/lib/howitzer/web/page.rb +10 -0
  46. data/lib/howitzer/web/page_dsl.rb +3 -0
  47. data/lib/howitzer/web/page_validator.rb +2 -0
  48. data/lib/howitzer/web/section.rb +8 -0
  49. data/lib/howitzer/web/section_dsl.rb +1 -0
  50. data/spec/support/shared_examples/capybara_context_holder.rb +1 -1
  51. data/spec/support/shared_examples/meta_highlight_xpath.rb +41 -0
  52. data/spec/unit/generators/config_generator_spec.rb +4 -2
  53. data/spec/unit/generators/root_generator_spec.rb +32 -21
  54. data/spec/unit/generators/templates/cucumber_spec.rb +97 -0
  55. data/spec/unit/generators/templates/rspec_spec.rb +88 -0
  56. data/spec/unit/generators/templates/turnip_spec.rb +98 -0
  57. data/spec/unit/lib/capybara_helpers_spec.rb +37 -4
  58. data/spec/unit/lib/howitzer_spec.rb +23 -0
  59. data/spec/unit/lib/meta/element_spec.rb +59 -0
  60. data/spec/unit/lib/meta/entry_spec.rb +77 -0
  61. data/spec/unit/lib/meta/iframe_spec.rb +66 -0
  62. data/spec/unit/lib/meta/section_spec.rb +43 -0
  63. data/spec/unit/lib/utils/string_extensions_spec.rb +1 -1
  64. data/spec/unit/lib/web/element_dsl_spec.rb +10 -1
  65. data/spec/unit/lib/web/page_spec.rb +7 -0
  66. data/spec/unit/lib/web/section_spec.rb +7 -0
  67. metadata +31 -15
  68. data/generators/config/templates/drivers/phantomjs.rb +0 -19
@@ -66,4 +66,27 @@ RSpec.describe 'Howitzer' do
66
66
  end
67
67
  it { is_expected.to be_nil }
68
68
  end
69
+ describe '.session_name' do
70
+ context 'when default' do
71
+ subject { Howitzer.session_name }
72
+ it do
73
+ is_expected.to be_eql('default')
74
+ end
75
+ end
76
+ context 'when set' do
77
+ subject { Howitzer.session_name = 'another' }
78
+ it do
79
+ expect(Capybara).to receive(:session_name=).with('another')
80
+ is_expected.to be_eql('another')
81
+ end
82
+ end
83
+ end
84
+ describe 'using_session' do
85
+ before { Howitzer.session_name = 'default' }
86
+ it do
87
+ expect(Capybara).to receive(:using_session).with('another')
88
+ Howitzer.using_session('another') {}
89
+ expect(Howitzer.session_name).to be_eql('default')
90
+ end
91
+ end
69
92
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'howitzer/meta/element'
3
+
4
+ RSpec.describe Howitzer::Meta::Element do
5
+ let(:context) { double }
6
+ let(:name) { 'foo' }
7
+ let(:element) { described_class.new(name, context) }
8
+
9
+ describe '.new' do
10
+ it { expect(element.context).to eq(context) }
11
+ it { expect(element.name).to eq('foo') }
12
+ end
13
+
14
+ describe '#capybara_elements' do
15
+ context 'without arguments' do
16
+ subject { element.capybara_elements }
17
+ it do
18
+ expect(context).to receive(:send).with("#{name}_elements")
19
+ subject
20
+ end
21
+ end
22
+ context 'whith custom arguments' do
23
+ subject { element.capybara_elements('test', text: 'test', wait: 5) }
24
+ it do
25
+ expect(context).to receive(:send).with("#{name}_elements", 'test', text: 'test', wait: 5)
26
+ subject
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#capybara_element' do
32
+ subject { element.capybara_element }
33
+ context 'when element is present' do
34
+ context 'with default arguments' do
35
+ it do
36
+ expect(context).to receive(:send).with("#{name}_element", match: :first, wait: 0)
37
+ subject
38
+ end
39
+ end
40
+ context 'with custom arguments' do
41
+ subject { element.capybara_element('test', { text: 'test' }, wait: 5) }
42
+ it do
43
+ expect(context).to receive(:send).with("#{name}_element", 'test', text: 'test', match: :first, wait: 5)
44
+ subject
45
+ end
46
+ end
47
+ end
48
+ context 'when element is not found' do
49
+ before do
50
+ allow(context).to receive(:send).with("#{name}_element", match: :first, wait: 0) do
51
+ raise Capybara::ElementNotFound
52
+ end
53
+ end
54
+ it { is_expected.to be_nil }
55
+ end
56
+ end
57
+
58
+ include_examples :meta_highlight_xpath
59
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+ require 'howitzer/meta/entry'
3
+
4
+ RSpec.describe Howitzer::Meta::Entry do
5
+ let(:klass) do
6
+ Class.new do
7
+ include Howitzer::Web::ElementDsl
8
+ def capybara_scopes
9
+ @capybara_scopes ||= Hash.new { |hash, key| hash[key] = [Capybara.current_session] }
10
+ @capybara_scopes[Howitzer.session_name]
11
+ end
12
+
13
+ def foo_section; end
14
+
15
+ def bar_section; end
16
+
17
+ def foo_sections; end
18
+
19
+ def bar_sections; end
20
+
21
+ def foo_iframe; end
22
+
23
+ def bar_iframe; end
24
+
25
+ def has_foo_iframe?; end
26
+
27
+ def has_bar_iframe?; end
28
+ end
29
+ end
30
+ let(:klass_object) { klass.new }
31
+
32
+ before do
33
+ klass.class_eval do
34
+ element :foo, :xpath, '//a'
35
+ element :bar, '#bar'
36
+ end
37
+ end
38
+
39
+ describe '.new' do
40
+ let(:context) { klass.new }
41
+ subject { described_class.new(context) }
42
+ it { expect(subject.context).to eq(context) }
43
+ end
44
+
45
+ describe '#elements' do
46
+ subject { described_class.new(klass.new).elements }
47
+ it { expect(subject.map(&:name)).to contain_exactly('foo', 'bar') }
48
+ it { expect(subject.count).to eq(2) }
49
+ end
50
+
51
+ describe '#element' do
52
+ subject { described_class.new(klass.new).element('foo') }
53
+ it { expect(subject.name).to eq('foo') }
54
+ end
55
+
56
+ describe '#sections' do
57
+ subject { described_class.new(klass.new).sections }
58
+ it { expect(subject.map(&:name)).to contain_exactly('foo', 'bar') }
59
+ it { expect(subject.count).to eq(2) }
60
+ end
61
+
62
+ describe '#section' do
63
+ subject { described_class.new(klass.new).section('foo') }
64
+ it { expect(subject.name).to eq('foo') }
65
+ end
66
+
67
+ describe '#iframes' do
68
+ subject { described_class.new(klass.new).iframes }
69
+ it { expect(subject.map(&:name)).to contain_exactly('foo', 'bar') }
70
+ it { expect(subject.count).to eq(2) }
71
+ end
72
+
73
+ describe '#iframe' do
74
+ subject { described_class.new(klass.new).iframe('foo') }
75
+ it { expect(subject.name).to eq('foo') }
76
+ end
77
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'howitzer/meta/iframe'
3
+
4
+ RSpec.describe Howitzer::Meta::Iframe do
5
+ let(:context) { double }
6
+ let(:name) { 'foo' }
7
+ let(:iframe) { described_class.new(name, context) }
8
+
9
+ describe '.new' do
10
+ it { expect(iframe.context).to eq(context) }
11
+ it { expect(iframe.name).to eq('foo') }
12
+ end
13
+
14
+ describe '#capybara_elements' do
15
+ subject { iframe.capybara_elements }
16
+ it do
17
+ expect(iframe).to receive(:site_value)
18
+ expect(context).to receive_message_chain(:capybara_context, :all)
19
+ subject
20
+ end
21
+ end
22
+
23
+ describe '#capybara_element' do
24
+ subject { iframe.capybara_element }
25
+ context 'when element is present' do
26
+ context 'with default arguments' do
27
+ it do
28
+ expect(iframe).to receive(:site_value)
29
+ expect(context).to receive_message_chain(:capybara_context, :find)
30
+ subject
31
+ end
32
+ end
33
+ context 'with custom arguments' do
34
+ subject { iframe.capybara_element(wait: 5) }
35
+ it do
36
+ expect(iframe).to receive(:site_value)
37
+ expect(context).to receive_message_chain(:capybara_context, :find)
38
+ subject
39
+ end
40
+ end
41
+ end
42
+ context 'when element is not found' do
43
+ before do
44
+ allow(iframe).to receive(:site_value)
45
+ allow(context).to receive_message_chain(:capybara_context, :find) { raise Capybara::ElementNotFound }
46
+ end
47
+ it { is_expected.to be_nil }
48
+ end
49
+ end
50
+
51
+ describe '#site_value' do
52
+ subject { iframe.site_value }
53
+ context 'when site value is present' do
54
+ before { iframe.instance_variable_set(:@site_value, 'test') }
55
+ it { is_expected.to eq('test') }
56
+ end
57
+ context 'when site value is blank' do
58
+ it do
59
+ expect(context).to receive(:send).with("#{name}_iframe")
60
+ subject
61
+ end
62
+ end
63
+ end
64
+
65
+ include_examples :meta_highlight_xpath
66
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'howitzer/meta/section'
3
+
4
+ RSpec.describe Howitzer::Meta::Section do
5
+ let(:context) { double }
6
+ let(:name) { 'foo' }
7
+ let(:section) { described_class.new(name, context) }
8
+
9
+ describe '.new' do
10
+ it { expect(section.context).to eq(context) }
11
+ it { expect(section.name).to eq('foo') }
12
+ end
13
+
14
+ describe '#capybara_elements' do
15
+ subject { section.capybara_elements }
16
+ let(:capybara_element) { double }
17
+ it do
18
+ expect(context).to receive(:send).with("#{name}_sections") { [capybara_element] }
19
+ expect(capybara_element).to receive(:capybara_context)
20
+ subject
21
+ end
22
+ end
23
+
24
+ describe '#capybara_element' do
25
+ let(:capybara_element) { double }
26
+ subject { section.capybara_element }
27
+ context 'when element is present' do
28
+ it do
29
+ expect(context).to receive(:send).with("#{name}_sections") { [capybara_element] }
30
+ expect(capybara_element).to receive(:capybara_context)
31
+ subject
32
+ end
33
+ end
34
+ context 'when element is not found' do
35
+ it do
36
+ expect(context).to receive(:send).with("#{name}_sections") { [] }
37
+ is_expected.to be_nil
38
+ end
39
+ end
40
+ end
41
+
42
+ include_examples :meta_highlight_xpath
43
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'howitzer/utils/string_extensions'
3
3
 
4
4
  RSpec.describe Howitzer::Utils::StringExtensions do
5
- String.send(:include, Howitzer::Utils::StringExtensions)
5
+ String.include Howitzer::Utils::StringExtensions
6
6
 
7
7
  let(:page_name) { 'my' }
8
8
  let(:page_object) { double }
@@ -6,7 +6,8 @@ RSpec.describe Howitzer::Web::ElementDsl do
6
6
  Class.new do
7
7
  include Howitzer::Web::ElementDsl
8
8
  def capybara_scopes
9
- @_scopes ||= [Capybara.current_session]
9
+ @capybara_scopes ||= Hash.new { |hash, key| hash[key] = [Capybara.current_session] }
10
+ @capybara_scopes[Howitzer.session_name]
10
11
  end
11
12
  end
12
13
  end
@@ -17,6 +18,14 @@ RSpec.describe Howitzer::Web::ElementDsl do
17
18
  expect(klass_object.capybara_context).to eq('session')
18
19
  end
19
20
 
21
+ it 'returns another capybara context' do
22
+ allow(Capybara).to receive(:current_session) { 'session' }
23
+ expect(klass_object.capybara_context).to eq('session')
24
+ Howitzer.session_name = 'session2'
25
+ allow(Capybara).to receive(:current_session) { 'session2' }
26
+ expect(klass_object.capybara_context).to eq('session2')
27
+ end
28
+
20
29
  include_examples :element_dsl
21
30
  include_examples :capybara_context_holder
22
31
  end
@@ -371,6 +371,13 @@ RSpec.describe Howitzer::Web::Page do
371
371
  it { is_expected.to eq(:context) }
372
372
  end
373
373
 
374
+ describe '#meta' do
375
+ let(:page) { described_class.instance }
376
+ it { expect(page.instance_variable_get(:@meta)).to be_nil }
377
+ it { expect(page.meta).to be_an_instance_of(Howitzer::Meta::Entry) }
378
+ it { expect(page.meta.context).to eq(page) }
379
+ end
380
+
374
381
  describe 'includes proxied capybara methods' do
375
382
  let(:reciever) { described_class.instance }
376
383
  include_examples :capybara_methods_proxy
@@ -60,4 +60,11 @@ RSpec.describe Howitzer::Web::Section do
60
60
  subject { described_class.new(1, :test).capybara_context }
61
61
  it { is_expected.to eq(:test) }
62
62
  end
63
+
64
+ describe '#meta' do
65
+ let(:section) { described_class.new(1, :test) }
66
+ it { expect(section.meta).to be_an_instance_of(Howitzer::Meta::Entry) }
67
+ it { expect(section.meta.context).to eq(section) }
68
+ it { expect(section.instance_variable_get(:@meta)).to be_nil }
69
+ end
63
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howitzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Parashchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-04 00:00:00.000000000 Z
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,22 +28,16 @@ dependencies:
28
28
  name: capybara
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '2.1'
34
31
  - - "<"
35
32
  - !ruby/object:Gem::Version
36
- version: '3.0'
33
+ version: '4.0'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '2.1'
44
38
  - - "<"
45
39
  - !ruby/object:Gem::Version
46
- version: '3.0'
40
+ version: '4.0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: colorize
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -284,10 +278,11 @@ files:
284
278
  - generators/config/templates/capybara.rb
285
279
  - generators/config/templates/custom.yml
286
280
  - generators/config/templates/default.yml
281
+ - generators/config/templates/drivers/appium.rb
287
282
  - generators/config/templates/drivers/browserstack.rb
288
283
  - generators/config/templates/drivers/crossbrowsertesting.rb
289
284
  - generators/config/templates/drivers/headless_chrome.rb
290
- - generators/config/templates/drivers/phantomjs.rb
285
+ - generators/config/templates/drivers/headless_firefox.rb
291
286
  - generators/config/templates/drivers/poltergeist.rb
292
287
  - generators/config/templates/drivers/sauce.rb
293
288
  - generators/config/templates/drivers/selenium.rb
@@ -311,7 +306,7 @@ files:
311
306
  - generators/prerequisites/templates/users.rb
312
307
  - generators/root/root_generator.rb
313
308
  - generators/root/templates/.gitignore
314
- - generators/root/templates/.rubocop.yml
309
+ - generators/root/templates/.rubocop.yml.erb
315
310
  - generators/root/templates/Gemfile.erb
316
311
  - generators/root/templates/Rakefile
317
312
  - generators/rspec/rspec_generator.rb
@@ -351,6 +346,12 @@ files:
351
346
  - lib/howitzer/mailgun_api/response.rb
352
347
  - lib/howitzer/mailtrap_api.rb
353
348
  - lib/howitzer/mailtrap_api/client.rb
349
+ - lib/howitzer/meta.rb
350
+ - lib/howitzer/meta/actions.rb
351
+ - lib/howitzer/meta/element.rb
352
+ - lib/howitzer/meta/entry.rb
353
+ - lib/howitzer/meta/iframe.rb
354
+ - lib/howitzer/meta/section.rb
354
355
  - lib/howitzer/tasks/framework.rake
355
356
  - lib/howitzer/utils.rb
356
357
  - lib/howitzer/utils/string_extensions.rb
@@ -375,6 +376,7 @@ files:
375
376
  - spec/support/shared_examples/capybara_methods_proxy.rb
376
377
  - spec/support/shared_examples/dynamic_section_methods.rb
377
378
  - spec/support/shared_examples/element_dsl.rb
379
+ - spec/support/shared_examples/meta_highlight_xpath.rb
378
380
  - spec/unit/generators/base_generator_spec.rb
379
381
  - spec/unit/generators/config_generator_spec.rb
380
382
  - spec/unit/generators/cucumber_generator_spec.rb
@@ -383,6 +385,9 @@ files:
383
385
  - spec/unit/generators/root_generator_spec.rb
384
386
  - spec/unit/generators/rspec_generator_spec.rb
385
387
  - spec/unit/generators/tasks_generator_spec.rb
388
+ - spec/unit/generators/templates/cucumber_spec.rb
389
+ - spec/unit/generators/templates/rspec_spec.rb
390
+ - spec/unit/generators/templates/turnip_spec.rb
386
391
  - spec/unit/generators/turnip_generator_spec.rb
387
392
  - spec/unit/generators/web_generator_spec.rb
388
393
  - spec/unit/lib/cache_spec.rb
@@ -400,6 +405,10 @@ files:
400
405
  - spec/unit/lib/mailgun_api/connector_spec.rb
401
406
  - spec/unit/lib/mailgun_api/response_spec.rb
402
407
  - spec/unit/lib/mailtrap_api/client_spec.rb
408
+ - spec/unit/lib/meta/element_spec.rb
409
+ - spec/unit/lib/meta/entry_spec.rb
410
+ - spec/unit/lib/meta/iframe_spec.rb
411
+ - spec/unit/lib/meta/section_spec.rb
403
412
  - spec/unit/lib/utils/string_extensions_spec.rb
404
413
  - spec/unit/lib/web/base_section_spec.rb
405
414
  - spec/unit/lib/web/element_dsl_spec.rb
@@ -422,15 +431,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
422
431
  requirements:
423
432
  - - ">="
424
433
  - !ruby/object:Gem::Version
425
- version: 2.2.2
434
+ version: '2.3'
426
435
  required_rubygems_version: !ruby/object:Gem::Requirement
427
436
  requirements:
428
437
  - - ">="
429
438
  - !ruby/object:Gem::Version
430
439
  version: '0'
431
440
  requirements: []
432
- rubyforge_project:
433
- rubygems_version: 2.6.8
441
+ rubygems_version: 3.0.2
434
442
  signing_key:
435
443
  specification_version: 4
436
444
  summary: Ruby based framework for acceptance testing
@@ -450,6 +458,7 @@ test_files:
450
458
  - spec/support/shared_examples/capybara_methods_proxy.rb
451
459
  - spec/support/shared_examples/dynamic_section_methods.rb
452
460
  - spec/support/shared_examples/element_dsl.rb
461
+ - spec/support/shared_examples/meta_highlight_xpath.rb
453
462
  - spec/unit/generators/base_generator_spec.rb
454
463
  - spec/unit/generators/config_generator_spec.rb
455
464
  - spec/unit/generators/cucumber_generator_spec.rb
@@ -458,6 +467,9 @@ test_files:
458
467
  - spec/unit/generators/root_generator_spec.rb
459
468
  - spec/unit/generators/rspec_generator_spec.rb
460
469
  - spec/unit/generators/tasks_generator_spec.rb
470
+ - spec/unit/generators/templates/cucumber_spec.rb
471
+ - spec/unit/generators/templates/rspec_spec.rb
472
+ - spec/unit/generators/templates/turnip_spec.rb
461
473
  - spec/unit/generators/turnip_generator_spec.rb
462
474
  - spec/unit/generators/web_generator_spec.rb
463
475
  - spec/unit/lib/cache_spec.rb
@@ -475,6 +487,10 @@ test_files:
475
487
  - spec/unit/lib/mailgun_api/connector_spec.rb
476
488
  - spec/unit/lib/mailgun_api/response_spec.rb
477
489
  - spec/unit/lib/mailtrap_api/client_spec.rb
490
+ - spec/unit/lib/meta/element_spec.rb
491
+ - spec/unit/lib/meta/entry_spec.rb
492
+ - spec/unit/lib/meta/iframe_spec.rb
493
+ - spec/unit/lib/meta/section_spec.rb
478
494
  - spec/unit/lib/utils/string_extensions_spec.rb
479
495
  - spec/unit/lib/web/base_section_spec.rb
480
496
  - spec/unit/lib/web/element_dsl_spec.rb