isomorfeus-puppetmaster 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +191 -0
  3. data/lib/isomorfeus-puppetmaster.rb +43 -0
  4. data/lib/isomorfeus/puppetmaster.rb +62 -0
  5. data/lib/isomorfeus/puppetmaster/console_message.rb +19 -0
  6. data/lib/isomorfeus/puppetmaster/cookie.rb +46 -0
  7. data/lib/isomorfeus/puppetmaster/document.rb +160 -0
  8. data/lib/isomorfeus/puppetmaster/driver/jsdom.rb +370 -0
  9. data/lib/isomorfeus/puppetmaster/driver/jsdom_document.rb +908 -0
  10. data/lib/isomorfeus/puppetmaster/driver/jsdom_node.rb +836 -0
  11. data/lib/isomorfeus/puppetmaster/driver/puppeteer.rb +401 -0
  12. data/lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb +944 -0
  13. data/lib/isomorfeus/puppetmaster/driver/puppeteer_node.rb +866 -0
  14. data/lib/isomorfeus/puppetmaster/driver_registration.rb +19 -0
  15. data/lib/isomorfeus/puppetmaster/dsl.rb +40 -0
  16. data/lib/isomorfeus/puppetmaster/errors.rb +90 -0
  17. data/lib/isomorfeus/puppetmaster/iframe.rb +17 -0
  18. data/lib/isomorfeus/puppetmaster/node.rb +241 -0
  19. data/lib/isomorfeus/puppetmaster/node/checkbox.rb +17 -0
  20. data/lib/isomorfeus/puppetmaster/node/content_editable.rb +18 -0
  21. data/lib/isomorfeus/puppetmaster/node/filechooser.rb +9 -0
  22. data/lib/isomorfeus/puppetmaster/node/input.rb +21 -0
  23. data/lib/isomorfeus/puppetmaster/node/radiobutton.rb +13 -0
  24. data/lib/isomorfeus/puppetmaster/node/select.rb +36 -0
  25. data/lib/isomorfeus/puppetmaster/node/textarea.rb +7 -0
  26. data/lib/isomorfeus/puppetmaster/request.rb +17 -0
  27. data/lib/isomorfeus/puppetmaster/response.rb +26 -0
  28. data/lib/isomorfeus/puppetmaster/rspec/features.rb +23 -0
  29. data/lib/isomorfeus/puppetmaster/rspec/matcher_proxies.rb +80 -0
  30. data/lib/isomorfeus/puppetmaster/rspec/matchers.rb +164 -0
  31. data/lib/isomorfeus/puppetmaster/rspec/matchers/base.rb +98 -0
  32. data/lib/isomorfeus/puppetmaster/rspec/matchers/become_closed.rb +33 -0
  33. data/lib/isomorfeus/puppetmaster/rspec/matchers/compound.rb +88 -0
  34. data/lib/isomorfeus/puppetmaster/rspec/matchers/have_current_path.rb +29 -0
  35. data/lib/isomorfeus/puppetmaster/rspec/matchers/have_selector.rb +69 -0
  36. data/lib/isomorfeus/puppetmaster/rspec/matchers/have_text.rb +33 -0
  37. data/lib/isomorfeus/puppetmaster/rspec/matchers/have_title.rb +29 -0
  38. data/lib/isomorfeus/puppetmaster/rspec/matchers/match_selector.rb +27 -0
  39. data/lib/isomorfeus/puppetmaster/rspec/matchers/match_style.rb +38 -0
  40. data/lib/isomorfeus/puppetmaster/self_forwardable.rb +31 -0
  41. data/lib/isomorfeus/puppetmaster/server.rb +128 -0
  42. data/lib/isomorfeus/puppetmaster/server/checker.rb +40 -0
  43. data/lib/isomorfeus/puppetmaster/server/middleware.rb +60 -0
  44. data/lib/isomorfeus/puppetmaster/server_registration.rb +37 -0
  45. data/lib/isomorfeus/puppetmaster/version.rb +3 -0
  46. metadata +282 -0
@@ -0,0 +1,9 @@
1
+ module Isomorfeus
2
+ module Puppetmaster
3
+ class Filechooser < Isomorfeus::Puppetmaster::Input
4
+ def attach_file(file_path)
5
+ @driver.attach_file(self, file_path)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ module Isomorfeus
2
+ module Puppetmaster
3
+ class Input < Isomorfeus::Puppetmaster::Node
4
+ node_forward %i[
5
+ disabled?
6
+ value
7
+ value=
8
+ ]
9
+
10
+ attr_accessor :type
11
+
12
+ def multiple?
13
+ !!self[:multiple]
14
+ end
15
+
16
+ def readonly?
17
+ !!self[:readOnly]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Isomorfeus
2
+ module Puppetmaster
3
+ class Radiobutton < Isomorfeus::Puppetmaster::Input
4
+ def choose
5
+ @driver.choose(self)
6
+ end
7
+
8
+ def chosen?
9
+ @driver.chosen?(self)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ module Isomorfeus
2
+ module Puppetmaster
3
+ class Select < Isomorfeus::Puppetmaster::Input
4
+
5
+ class Option
6
+ def select
7
+ @driver.select(self)
8
+ end
9
+
10
+ def selected?
11
+ !!self[:selected]
12
+ end
13
+
14
+ def unselect
15
+ @driver.unselect(self)
16
+ end
17
+ end
18
+
19
+ def select(option)
20
+ # find option.select
21
+ end
22
+
23
+ def selected
24
+ # find selected options
25
+ end
26
+
27
+ def selected?(option)
28
+ # find option.selected?
29
+ end
30
+
31
+ def unselect
32
+ # find option.unselect
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ module Isomorfeus
2
+ module Puppetmaster
3
+ class Textarea < Isomorfeus::Puppetmaster::Input
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module Isomorfeus
2
+ module Puppetmaster
3
+ class Request
4
+ def initialize(request_hash = {})
5
+ @request_hash = request_hash ? request_hash : {}
6
+ end
7
+
8
+ def method_missing(name, *args)
9
+ if %i[failure headers method post_data resource_type url].include?(name)
10
+ @request_hash[name.to_s]
11
+ else
12
+ super(name, *args)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module Isomorfeus
2
+ module Puppetmaster
3
+ class Response
4
+ attr_reader :request
5
+
6
+ def initialize(response_hash = {})
7
+ @response_hash = response_hash ? response_hash : {}
8
+ @request = Isomorfeus::Puppetmaster::Request.new(@response_hash['request'])
9
+ end
10
+
11
+ def method_missing(name, *args)
12
+ if %i[headers ok remote_address security_details status status_text text url].include?(name)
13
+ @response_hash[name.to_s]
14
+ elsif :ok? == name
15
+ @response_hash['ok']
16
+ else
17
+ super(name, *args)
18
+ end
19
+ end
20
+
21
+ def ok?
22
+ @response_hash[:ok]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_context 'Capybara Features', capybara_feature: true do
4
+ instance_eval do
5
+ alias background before
6
+ alias given let
7
+ alias given! let!
8
+ end
9
+ end
10
+
11
+ # ensure shared_context is included if default shared_context_metadata_behavior is changed
12
+ RSpec.configure do |config|
13
+ config.include_context 'Capybara Features', capybara_feature: true if config.respond_to?(:include_context)
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.alias_example_group_to :feature, :capybara_feature, type: :feature
18
+ config.alias_example_group_to :xfeature, :capybara_feature, type: :feature, skip: 'Temporarily disabled with xfeature'
19
+ config.alias_example_group_to :ffeature, :capybara_feature, :focus, type: :feature
20
+ config.alias_example_to :scenario
21
+ config.alias_example_to :xscenario, skip: 'Temporarily disabled with xscenario'
22
+ config.alias_example_to :fscenario, :focus
23
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capybara
4
+ module RSpecMatcherProxies
5
+ def all(*args, &block)
6
+ if defined?(::RSpec::Matchers::BuiltIn::All) && args.first.respond_to?(:matches?)
7
+ ::RSpec::Matchers::BuiltIn::All.new(*args)
8
+ else
9
+ find_all(*args, &block)
10
+ end
11
+ end
12
+
13
+ def within(*args)
14
+ if block_given?
15
+ within_element(*args, &Proc.new)
16
+ else
17
+ be_within(*args)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ if RUBY_ENGINE == 'jruby'
24
+ module Capybara::DSL
25
+ class <<self
26
+ remove_method :included
27
+
28
+ def included(base)
29
+ warn 'including Capybara::DSL in the global scope is not recommended!' if base == Object
30
+ if defined?(::RSpec::Matchers) && base.include?(::RSpec::Matchers)
31
+ base.send(:include, ::Capybara::RSpecMatcherProxies)
32
+ end
33
+ super
34
+ end
35
+ end
36
+ end
37
+
38
+ if defined?(::RSpec::Matchers)
39
+ module ::RSpec::Matchers
40
+ def self.included(base)
41
+ base.send(:include, ::Capybara::RSpecMatcherProxies) if base.include?(::Capybara::DSL)
42
+ super
43
+ end
44
+ end
45
+ end
46
+ else
47
+ module Capybara::DSLRSpecProxyInstaller
48
+ module ClassMethods
49
+ def included(base)
50
+ base.include(::Capybara::RSpecMatcherProxies) if defined?(::RSpec::Matchers) && base.include?(::RSpec::Matchers)
51
+ super
52
+ end
53
+ end
54
+
55
+ def self.prepended(base)
56
+ class <<base
57
+ prepend ClassMethods
58
+ end
59
+ end
60
+ end
61
+
62
+ module Capybara::RSpecMatcherProxyInstaller
63
+ module ClassMethods
64
+ def included(base)
65
+ base.include(::Capybara::RSpecMatcherProxies) if base.include?(::Capybara::DSL)
66
+ super
67
+ end
68
+ end
69
+
70
+ def self.prepended(base)
71
+ class <<base
72
+ prepend ClassMethods
73
+ end
74
+ end
75
+ end
76
+
77
+ Capybara::DSL.prepend ::Capybara::DSLRSpecProxyInstaller
78
+
79
+ ::RSpec::Matchers.prepend ::Capybara::RSpecMatcherProxyInstaller if defined?(::RSpec::Matchers)
80
+ end
@@ -0,0 +1,164 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'capybara/rspec/matchers/have_selector'
4
+ require 'capybara/rspec/matchers/match_selector'
5
+ require 'capybara/rspec/matchers/have_current_path'
6
+ require 'capybara/rspec/matchers/match_style'
7
+ require 'capybara/rspec/matchers/have_text'
8
+ require 'capybara/rspec/matchers/have_title'
9
+ require 'capybara/rspec/matchers/become_closed'
10
+
11
+ module Capybara
12
+ module RSpecMatchers
13
+ # RSpec matcher for whether the element(s) matching a given selector exist
14
+ # See {Capybara::Node::Matcher#assert_selector}
15
+ def have_selector(*args, &optional_filter_block)
16
+ Matchers::HaveSelector.new(*args, &optional_filter_block)
17
+ end
18
+
19
+ # RSpec matcher for whether the element(s) matching a group of selectors exist
20
+ # See {Capybara::Node::Matcher#assert_all_of_selectors}
21
+ def have_all_of_selectors(*args, &optional_filter_block)
22
+ Matchers::HaveAllSelectors.new(*args, &optional_filter_block)
23
+ end
24
+
25
+ # RSpec matcher for whether no element(s) matching a group of selectors exist
26
+ # See {Capybara::Node::Matcher#assert_none_of_selectors}
27
+ def have_none_of_selectors(*args, &optional_filter_block)
28
+ Matchers::HaveNoSelectors.new(*args, &optional_filter_block)
29
+ end
30
+
31
+ # RSpec matcher for whether the element(s) matching any of a group of selectors exist
32
+ # See {Capybara::Node::Matcher#assert_any_of_selectors}
33
+ def have_any_of_selectors(*args, &optional_filter_block)
34
+ Matchers::HaveAnySelectors.new(*args, &optional_filter_block)
35
+ end
36
+
37
+ # RSpec matcher for whether the current element matches a given selector
38
+ # See {Capybara::Node::Matchers#assert_matches_selector}
39
+ def match_selector(*args, &optional_filter_block)
40
+ Matchers::MatchSelector.new(*args, &optional_filter_block)
41
+ end
42
+
43
+ %i[css xpath].each do |selector|
44
+ define_method "have_#{selector}" do |expr, **options, &optional_filter_block|
45
+ Matchers::HaveSelector.new(selector, expr, options, &optional_filter_block)
46
+ end
47
+
48
+ define_method "match_#{selector}" do |expr, **options, &optional_filter_block|
49
+ Matchers::MatchSelector.new(selector, expr, options, &optional_filter_block)
50
+ end
51
+ end
52
+
53
+ # @!method have_xpath(xpath, **options, &optional_filter_block)
54
+ # RSpec matcher for whether elements(s) matching a given xpath selector exist
55
+ # See {Capybara::Node::Matchers#has_xpath?}
56
+
57
+ # @!method have_css(css, **options, &optional_filter_block)
58
+ # RSpec matcher for whether elements(s) matching a given css selector exist
59
+ # See {Capybara::Node::Matchers#has_css?}
60
+
61
+ # @!method match_xpath(xpath, **options, &optional_filter_block)
62
+ # RSpec matcher for whether the current element matches a given xpath selector
63
+ # See {Capybara::Node::Matchers#matches_xpath?}
64
+
65
+ # @!method match_css(css, **options, &optional_filter_block)
66
+ # RSpec matcher for whether the current element matches a given css selector
67
+ # See {Capybara::Node::Matchers#matches_css?}
68
+
69
+ %i[link button field select table].each do |selector|
70
+ define_method "have_#{selector}" do |locator = nil, **options, &optional_filter_block|
71
+ Matchers::HaveSelector.new(selector, locator, options, &optional_filter_block)
72
+ end
73
+ end
74
+
75
+ # @!method have_link(locator = nil, **options, &optional_filter_block)
76
+ # RSpec matcher for links
77
+ # See {Capybara::Node::Matchers#has_link?}
78
+
79
+ # @!method have_button(locator = nil, **options, &optional_filter_block)
80
+ # RSpec matcher for buttons
81
+ # See {Capybara::Node::Matchers#has_button?}
82
+
83
+ # @!method have_field(locator = nil, **options, &optional_filter_block)
84
+ # RSpec matcher for links
85
+ # See {Capybara::Node::Matchers#has_field?}
86
+
87
+ # @!method have_select(locator = nil, **options, &optional_filter_block)
88
+ # RSpec matcher for select elements
89
+ # See {Capybara::Node::Matchers#has_select?}
90
+
91
+ # @!method have_table(locator = nil, **options, &optional_filter_block)
92
+ # RSpec matcher for table elements
93
+ # See {Capybara::Node::Matchers#has_table?}
94
+
95
+ %i[checked unchecked].each do |state|
96
+ define_method "have_#{state}_field" do |locator = nil, **options, &optional_filter_block|
97
+ Matchers::HaveSelector.new(:field, locator, options.merge(state => true), &optional_filter_block)
98
+ end
99
+ end
100
+
101
+ # @!method have_checked_field(locator = nil, **options, &optional_filter_block)
102
+ # RSpec matcher for checked fields
103
+ # See {Capybara::Node::Matchers#has_checked_field?}
104
+
105
+ # @!method have_unchecked_field(locator = nil, **options, &optional_filter_block)
106
+ # RSpec matcher for unchecked fields
107
+ # See {Capybara::Node::Matchers#has_unchecked_field?}
108
+
109
+ # RSpec matcher for text content
110
+ # See {Capybara::SessionMatchers#assert_text}
111
+ def have_text(*args)
112
+ Matchers::HaveText.new(*args)
113
+ end
114
+ alias_method :have_content, :have_text
115
+
116
+ def have_title(title, **options)
117
+ Matchers::HaveTitle.new(title, options)
118
+ end
119
+
120
+ # RSpec matcher for the current path
121
+ # See {Capybara::SessionMatchers#assert_current_path}
122
+ def have_current_path(path, **options)
123
+ Matchers::HaveCurrentPath.new(path, options)
124
+ end
125
+
126
+ # RSpec matcher for element style
127
+ # See {Capybara::Node::Matchers#matches_style?}
128
+ def match_style(styles, **options)
129
+ Matchers::MatchStyle.new(styles, options)
130
+ end
131
+
132
+ ##
133
+ # @deprecated
134
+ #
135
+ def have_style(styles, **options)
136
+ warn 'DEPRECATED: have_style is deprecated, please use match_style'
137
+ match_style(styles, **options)
138
+ end
139
+
140
+ %w[selector css xpath text title current_path link button
141
+ field checked_field unchecked_field select table].each do |matcher_type|
142
+ define_method "have_no_#{matcher_type}" do |*args, &optional_filter_block|
143
+ Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, &optional_filter_block))
144
+ end
145
+ end
146
+ alias_method :have_no_content, :have_no_text
147
+
148
+ %w[selector css xpath].each do |matcher_type|
149
+ define_method "not_match_#{matcher_type}" do |*args, &optional_filter_block|
150
+ Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, &optional_filter_block))
151
+ end
152
+ end
153
+
154
+ ##
155
+ # Wait for window to become closed.
156
+ # @example
157
+ # expect(window).to become_closed(wait: 0.8)
158
+ # @param options [Hash] optional param
159
+ # @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum wait time
160
+ def become_closed(**options)
161
+ Matchers::BecomeClosed.new(options)
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'capybara/rspec/matchers/compound'
4
+
5
+ module Capybara
6
+ module RSpecMatchers
7
+ module Matchers
8
+ class Base
9
+ include ::Capybara::RSpecMatchers::Matchers::Compound if defined?(::Capybara::RSpecMatchers::Matchers::Compound)
10
+
11
+ attr_reader :failure_message, :failure_message_when_negated
12
+
13
+ def initialize(*args, &filter_block)
14
+ @args = args.dup
15
+ @filter_block = filter_block
16
+ end
17
+
18
+ private
19
+
20
+ def session_query_args
21
+ if @args.last.is_a? Hash
22
+ @args.last[:session_options] = session_options
23
+ else
24
+ @args.push(session_options: session_options)
25
+ end
26
+ @args
27
+ end
28
+
29
+ def session_options
30
+ @context_el ||= nil
31
+ if @context_el.respond_to? :session_options
32
+ @context_el.session_options
33
+ elsif @context_el.respond_to? :current_scope
34
+ @context_el.current_scope.session_options
35
+ else
36
+ Capybara.session_options
37
+ end
38
+ end
39
+ end
40
+
41
+ class WrappedElementMatcher < Base
42
+ def matches?(actual)
43
+ element_matches?(wrap(actual))
44
+ rescue Capybara::ExpectationNotMet => err
45
+ @failure_message = err.message
46
+ false
47
+ end
48
+
49
+ def does_not_match?(actual)
50
+ element_does_not_match?(wrap(actual))
51
+ rescue Capybara::ExpectationNotMet => err
52
+ @failure_message_when_negated = err.message
53
+ false
54
+ end
55
+
56
+ private
57
+
58
+ def wrap(actual)
59
+ actual = actual.to_capybara_node if actual.respond_to?(:to_capybara_node)
60
+ @context_el = if actual.respond_to?(:has_selector?)
61
+ actual
62
+ else
63
+ Capybara.string(actual.to_s)
64
+ end
65
+ end
66
+ end
67
+
68
+ class NegatedMatcher
69
+ include ::Capybara::RSpecMatchers::Matchers::Compound if defined?(::Capybara::RSpecMatchers::Matchers::Compound)
70
+
71
+ def initialize(matcher)
72
+ super()
73
+ @matcher = matcher
74
+ end
75
+
76
+ def matches?(actual)
77
+ @matcher.does_not_match?(actual)
78
+ end
79
+
80
+ def does_not_match?(actual)
81
+ @matcher.matches?(actual)
82
+ end
83
+
84
+ def description
85
+ "not #{@matcher.description}"
86
+ end
87
+
88
+ def failure_message
89
+ @matcher.failure_message_when_negated
90
+ end
91
+
92
+ def failure_message_when_negated
93
+ @matcher.failure_message
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end