page_magic 2.0.0.alpha1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -2
  3. data/.zsh_config +5 -5
  4. data/Dockerfile +2 -1
  5. data/Gemfile +2 -1
  6. data/Gemfile.lock +9 -5
  7. data/Makefile +7 -3
  8. data/README.md +16 -4
  9. data/VERSION +1 -1
  10. data/lib/active_support/core_ext/object/to_query.rb +6 -6
  11. data/lib/page_magic.rb +15 -16
  12. data/lib/page_magic/class_methods.rb +1 -1
  13. data/lib/page_magic/comparator.rb +37 -0
  14. data/lib/page_magic/comparator/fuzzy.rb +23 -0
  15. data/lib/page_magic/comparator/literal.rb +22 -0
  16. data/lib/page_magic/comparator/null.rb +26 -0
  17. data/lib/page_magic/comparator/parameter_map.rb +52 -0
  18. data/lib/page_magic/drivers.rb +2 -2
  19. data/lib/page_magic/element.rb +19 -8
  20. data/lib/page_magic/element/locators.rb +4 -4
  21. data/lib/page_magic/element/not_found.rb +38 -0
  22. data/lib/page_magic/element/query.rb +19 -27
  23. data/lib/page_magic/element/query/multiple_results.rb +21 -0
  24. data/lib/page_magic/element/query/prefetched_result.rb +26 -0
  25. data/lib/page_magic/element/query/single_result.rb +20 -0
  26. data/lib/page_magic/element/selector.rb +38 -16
  27. data/lib/page_magic/element/selector/methods.rb +18 -0
  28. data/lib/page_magic/element/selector/model.rb +21 -0
  29. data/lib/page_magic/element_context.rb +5 -21
  30. data/lib/page_magic/element_definition_builder.rb +17 -24
  31. data/lib/page_magic/elements.rb +62 -102
  32. data/lib/page_magic/elements/config.rb +103 -0
  33. data/lib/page_magic/elements/inheritance_hooks.rb +15 -0
  34. data/lib/page_magic/elements/types.rb +25 -0
  35. data/lib/page_magic/exceptions.rb +3 -0
  36. data/lib/page_magic/instance_methods.rb +2 -2
  37. data/lib/page_magic/mapping.rb +79 -0
  38. data/lib/page_magic/session.rb +10 -32
  39. data/lib/page_magic/session_methods.rb +1 -1
  40. data/lib/page_magic/transitions.rb +49 -0
  41. data/lib/page_magic/utils/string.rb +4 -0
  42. data/lib/page_magic/utils/url.rb +20 -0
  43. data/lib/page_magic/watcher.rb +10 -17
  44. data/lib/page_magic/watchers.rb +28 -15
  45. data/spec/page_magic/class_methods_spec.rb +64 -37
  46. data/spec/page_magic/comparator/fuzzy_spec.rb +44 -0
  47. data/spec/page_magic/comparator/literal_spec.rb +41 -0
  48. data/spec/page_magic/comparator/null_spec.rb +35 -0
  49. data/spec/page_magic/comparator/parameter_map_spec.rb +75 -0
  50. data/spec/page_magic/driver_spec.rb +25 -29
  51. data/spec/page_magic/drivers/poltergeist_spec.rb +4 -7
  52. data/spec/page_magic/drivers/rack_test_spec.rb +4 -9
  53. data/spec/page_magic/drivers/selenium_spec.rb +9 -12
  54. data/spec/page_magic/drivers_spec.rb +36 -29
  55. data/spec/page_magic/element/locators_spec.rb +26 -25
  56. data/spec/page_magic/element/not_found_spec.rb +24 -0
  57. data/spec/page_magic/element/query/multiple_results_spec.rb +14 -0
  58. data/spec/page_magic/element/query/single_result_spec.rb +21 -0
  59. data/spec/page_magic/element/query_spec.rb +26 -47
  60. data/spec/page_magic/element/selector_spec.rb +118 -110
  61. data/spec/page_magic/element_context_spec.rb +46 -88
  62. data/spec/page_magic/element_definition_builder_spec.rb +12 -71
  63. data/spec/page_magic/element_spec.rb +256 -0
  64. data/spec/page_magic/elements/config_spec.rb +200 -0
  65. data/spec/page_magic/elements_spec.rb +87 -138
  66. data/spec/page_magic/instance_methods_spec.rb +63 -63
  67. data/spec/page_magic/mapping_spec.rb +181 -0
  68. data/spec/page_magic/session_methods_spec.rb +27 -25
  69. data/spec/page_magic/session_spec.rb +109 -198
  70. data/spec/page_magic/transitions_spec.rb +43 -0
  71. data/spec/page_magic/utils/string_spec.rb +20 -27
  72. data/spec/page_magic/utils/url_spec.rb +9 -0
  73. data/spec/page_magic/wait_methods_spec.rb +14 -22
  74. data/spec/page_magic/watcher_spec.rb +22 -0
  75. data/spec/page_magic/watchers_spec.rb +56 -62
  76. data/spec/page_magic_spec.rb +27 -24
  77. data/spec/spec_helper.rb +7 -3
  78. data/spec/support/shared_examples.rb +15 -17
  79. metadata +48 -15
  80. data/lib/page_magic/element/query_builder.rb +0 -61
  81. data/lib/page_magic/element/selector_methods.rb +0 -16
  82. data/lib/page_magic/matcher.rb +0 -130
  83. data/spec/element_spec.rb +0 -251
  84. data/spec/page_magic/element/query_builder_spec.rb +0 -110
  85. data/spec/page_magic/matcher_spec.rb +0 -338
  86. data/spec/support/shared_contexts/files_context.rb +0 -9
  87. data/spec/support/shared_contexts/nested_elements_html_context.rb +0 -18
  88. data/spec/support/shared_contexts/rack_application_context.rb +0 -11
  89. data/spec/support/shared_contexts/webapp_fixture_context.rb +0 -41
  90. data/spec/watcher_spec.rb +0 -64
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_context :nested_elements_html do
4
- require 'sinatra/base'
5
-
6
- let(:nested_elements_html) do
7
- <<-HTML
8
- <div id="parent">
9
- <div id="child">
10
- </div>
11
- </div>
12
- HTML
13
- end
14
-
15
- let(:nested_elements_node) do
16
- Capybara::Node::Simple.new(nested_elements_html)
17
- end
18
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_context :rack_application do
4
- let(:rack_application) do
5
- Class.new do
6
- def call(_env)
7
- [200, {}, ['hello world!!']]
8
- end
9
- end
10
- end
11
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_context :webapp_fixture do
4
- require 'sinatra/base'
5
-
6
- let(:rack_app) do
7
- Class.new(Sinatra::Base) do
8
- get '/page1' do
9
- "<html><head><title>page1</title></head><body><a href='/page2'>next page</a></body></html>"
10
- end
11
-
12
- get '/page2' do
13
- 'page 2 content'
14
- end
15
-
16
- get '/elements' do
17
- <<-ELEMENTS
18
- <a href='#'>a link</a>
19
-
20
-
21
- <div id='form' class="form">
22
- <a id='form_link' href='/page2'>link in a form</a>
23
- <label>enter text
24
- <input id='field_id' name='field_name' class='input_class' type='text' value='filled in'/>
25
- </label>
26
- <button id='form_button' type='submit' value='a button'/>
27
- </form>
28
-
29
- ELEMENTS
30
- end
31
- end
32
- end
33
-
34
- before :each do
35
- Capybara.app = rack_app
36
- end
37
-
38
- after do
39
- Capybara.reset!
40
- end
41
- end
data/spec/watcher_spec.rb DELETED
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PageMagic
4
- describe Watcher do
5
- describe '#initialize' do
6
- context 'check has not been called yet' do
7
- subject do
8
- described_class.new(:custom_watcher)
9
- end
10
- it 'it sets last to nil' do
11
- expect(subject.last).to be_nil
12
- end
13
- end
14
- end
15
-
16
- describe '#check' do
17
- context 'method supplied to constructor' do
18
- subject do
19
- described_class.new(:object_id)
20
- end
21
-
22
- it 'assigns last to be the result of calling the method' do
23
- subject.check(self)
24
- expect(subject.last).to eq(object_id)
25
- end
26
- end
27
- context 'name and attribute supplied to constructor' do
28
- subject do
29
- described_class.new(:my_button, :text)
30
- end
31
-
32
- it 'assigns last to the value of attribute definined in the constructor' do
33
- browser_element = double(text: :hello)
34
- page_element = double(my_button: browser_element)
35
- expect(subject.check(page_element).last).to eq(:hello)
36
- end
37
- end
38
-
39
- context 'block supplied to constructor' do
40
- def method_on_self(value = nil)
41
- return @value unless value
42
-
43
- @value = value
44
- end
45
-
46
- subject do
47
- described_class.new(:custom_watcher) do
48
- method_on_self(:called)
49
- :result
50
- end
51
- end
52
-
53
- it 'is called on self' do
54
- subject.check(self)
55
- expect(method_on_self).to be(:called)
56
- end
57
-
58
- it 'assigns last to the resut of the block' do
59
- expect(subject.check(self).last).to eq(:result)
60
- end
61
- end
62
- end
63
- end
64
- end