mache 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -3
- data/README.md +7 -10
- data/lib/mache/dsl.rb +97 -12
- data/lib/mache/version.rb +1 -1
- data/lib/mache.rb +1 -1
- metadata +2 -3
- data/lib/mache/component.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7d084d201649e516f630f6a837d312fcd6e62ec
|
4
|
+
data.tar.gz: 5cc13f16c2078c326c9979d953690cf7c3f34eb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afd3efc23afd21149227b50c0a461cb3f61ce49b30d4894560d76e1a6b9befdc850518b84247f4ff91ec4694eb5c5b73760c8c2da87dfc111efb190018fa05ef
|
7
|
+
data.tar.gz: d05c14504c5bc9ed11b9f0e918307b53860b242a68cf7fa42dc1ff67f286269cb9f89a98d91089d6e554be099eed786e07199aedcaed058a2e3b20e2aef6999e
|
data/.rubocop.yml
CHANGED
@@ -6,12 +6,18 @@ AllCops:
|
|
6
6
|
Metrics/BlockLength:
|
7
7
|
ExcludedMethods: describe
|
8
8
|
|
9
|
+
Style/BlockDelimiters:
|
10
|
+
Enabled: false
|
11
|
+
|
9
12
|
Style/Documentation:
|
10
13
|
Exclude:
|
11
14
|
- "spec/**/*"
|
12
15
|
|
13
|
-
Style/StringLiterals:
|
14
|
-
EnforcedStyle: double_quotes
|
15
|
-
|
16
16
|
Style/FrozenStringLiteralComment:
|
17
17
|
Enabled: false
|
18
|
+
|
19
|
+
Style/SpaceInsideHashLiteralBraces:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/StringLiterals:
|
23
|
+
EnforcedStyle: double_quotes
|
data/README.md
CHANGED
@@ -87,7 +87,7 @@ page.node # <Capybara::Node>
|
|
87
87
|
### Elements
|
88
88
|
|
89
89
|
To make our page object more useful, we can define an element on our page
|
90
|
-
object class using the `element` macro. An element is simply
|
90
|
+
object class using the `element` macro. An element is simply an HTML element
|
91
91
|
that we expect to find on the page using a CSS selector.
|
92
92
|
|
93
93
|
Let's define a `main` element to represent the main section of our HTML page:
|
@@ -106,21 +106,19 @@ We can query the `main` element as an attribute of our page object:
|
|
106
106
|
|
107
107
|
```ruby
|
108
108
|
page.has_main? # true
|
109
|
-
page.main.visible? # true
|
110
109
|
page.main.text # "lorem ipsum"
|
111
110
|
```
|
112
111
|
|
113
112
|
### Components
|
114
113
|
|
115
114
|
For elements that can be shared across any number of page object classes it may
|
116
|
-
be useful to define a reusable component by extending the `Mache::
|
117
|
-
|
118
|
-
components).
|
115
|
+
be useful to define a reusable component by extending the `Mache::Node` class.
|
116
|
+
A component can contain any number of elements (or even other components).
|
119
117
|
|
120
118
|
Let's define a `Header` component to represent the header of our HTML page:
|
121
119
|
|
122
120
|
```ruby
|
123
|
-
class Header < Mache::
|
121
|
+
class Header < Mache::Node
|
124
122
|
element :title, "h1"
|
125
123
|
end
|
126
124
|
```
|
@@ -143,7 +141,6 @@ Querying a component of our page object is much the same as with an element:
|
|
143
141
|
|
144
142
|
```ruby
|
145
143
|
page.has_header? # true
|
146
|
-
page.header.visible? # true
|
147
144
|
page.header.title.text # "Welcome"
|
148
145
|
```
|
149
146
|
|
@@ -154,17 +151,17 @@ Let's look at a more complete example for our `WelcomePage`. Note that the
|
|
154
151
|
object classes we may define later for our web application.
|
155
152
|
|
156
153
|
```ruby
|
157
|
-
class Header < Mache::
|
154
|
+
class Header < Mache::Node
|
158
155
|
element :title, "h1"
|
159
156
|
end
|
160
157
|
|
161
|
-
class NavItem < Mache::
|
158
|
+
class NavItem < Mache::Node
|
162
159
|
def selected?
|
163
160
|
node[:class].include?("selected")
|
164
161
|
end
|
165
162
|
end
|
166
163
|
|
167
|
-
class Nav < Mache::
|
164
|
+
class Nav < Mache::Node
|
168
165
|
components :items, NavItem, "a"
|
169
166
|
end
|
170
167
|
|
data/lib/mache/dsl.rb
CHANGED
@@ -1,42 +1,127 @@
|
|
1
1
|
module Mache
|
2
|
-
#
|
3
|
-
module DSL
|
2
|
+
# See {ClassMethods} for documentation.
|
3
|
+
module DSL # :nodoc:
|
4
4
|
def self.included(base)
|
5
5
|
base.extend ClassMethods
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
# Provides a set of macro-like methods for wrapping HTML fragments in {Node}
|
9
|
+
# objects.
|
10
|
+
#
|
11
|
+
# ## Elements
|
12
|
+
#
|
13
|
+
# The {#element} method wraps an HTML fragment in a {Node} and exposes it as
|
14
|
+
# an *attribute* of the declaring class.
|
15
|
+
#
|
16
|
+
# The following example declares the `main` element, which is found on the
|
17
|
+
# welcome page using the `#main` selector:
|
18
|
+
#
|
19
|
+
# class WelcomePage < Mache::Page
|
20
|
+
# element :main, "#main"
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# The `main` element can be accessed as an attribute of a `WelcomePage`
|
24
|
+
# instance:
|
25
|
+
#
|
26
|
+
# page = WelcomePage.new
|
27
|
+
# page.has_main? # true
|
28
|
+
# page.main.text # lorem ipsum
|
29
|
+
#
|
30
|
+
# ## Components
|
31
|
+
#
|
32
|
+
# The {#component} method wraps an HTML fragment in a user-defined class and
|
33
|
+
# exposes it as an *attribute* of the declaring class.
|
34
|
+
#
|
35
|
+
# The following example declaring the `alert` component, which is found on
|
36
|
+
# the welcome page using the `#alert` selector. The component will be
|
37
|
+
# wrapped in the user-defined `Alert` class:
|
38
|
+
#
|
39
|
+
# class WelcomePage < Mache::Page
|
40
|
+
# component :alert, Alert, "#alert"
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# The `Alert` class can define an API for accessing the alert HTML fragment:
|
44
|
+
#
|
45
|
+
# class Alert < Mache::Node
|
46
|
+
# element :close_button, "button.close"
|
47
|
+
#
|
48
|
+
# def dismiss
|
49
|
+
# close_button.click
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
module ClassMethods
|
9
54
|
def automation(*ids)
|
10
55
|
ids.map { |id| %([data-automation="#{id}"]) }.join(" ")
|
11
56
|
end
|
12
57
|
|
13
|
-
|
58
|
+
# Defines an element that wraps an HTML fragment.
|
59
|
+
#
|
60
|
+
# @param name [String, Symbol] the elements collection name
|
61
|
+
# @param selector [String] the selector to find the element
|
62
|
+
# @param options [Hash] the options to pass to the Capybara finder
|
63
|
+
def element(name, selector, options = {})
|
14
64
|
define_method(name.to_s) do
|
15
|
-
@node.find(selector)
|
65
|
+
Node.new(node: @node.find(selector, options))
|
16
66
|
end
|
67
|
+
|
17
68
|
define_helper_methods(name, selector)
|
18
69
|
end
|
19
70
|
|
20
|
-
|
71
|
+
# Defines a collection of elements that wrap HTML fragments.
|
72
|
+
#
|
73
|
+
# @param name [String, Symbol] the elements collection name
|
74
|
+
# @param selector [String] the selector to find the elements
|
75
|
+
# @param options [Hash] the options to pass to the Capybara finder
|
76
|
+
def elements(name, selector, options = {})
|
77
|
+
options = {minimum: 1}.merge(options)
|
78
|
+
|
21
79
|
define_method(name.to_s) do
|
22
|
-
@node.all(selector,
|
80
|
+
@node.all(selector, options).map do |node|
|
81
|
+
Node.new(node: node)
|
82
|
+
end
|
23
83
|
end
|
84
|
+
|
24
85
|
define_helper_methods(name, selector)
|
25
86
|
end
|
26
87
|
|
27
|
-
|
88
|
+
# Defines a component that wraps an HTML fragment.
|
89
|
+
#
|
90
|
+
# @param name [String, Symbol] the elements collection name
|
91
|
+
# @param klass [Class] the component class
|
92
|
+
# @param selector [String] the selector to find the component
|
93
|
+
# @param options [Hash] the options to pass to the Capybara finder
|
94
|
+
def component(name, klass, selector, options = {})
|
95
|
+
unless klass < Node
|
96
|
+
raise ArgumentError, "Must be given a subclass of Node"
|
97
|
+
end
|
98
|
+
|
28
99
|
define_method(name.to_s) do
|
29
|
-
klass.new(node: @node.find(selector))
|
100
|
+
klass.new(node: @node.find(selector, options))
|
30
101
|
end
|
102
|
+
|
31
103
|
define_helper_methods(name, selector)
|
32
104
|
end
|
33
105
|
|
34
|
-
|
106
|
+
# Defines a collection of components that wrap HTML fragments.
|
107
|
+
#
|
108
|
+
# @param name [String, Symbol] the elements collection name
|
109
|
+
# @param klass [Class] the component class
|
110
|
+
# @param selector [String] the selector to find the components
|
111
|
+
# @param options [Hash] the options to pass to the Capybara finder
|
112
|
+
def components(name, klass, selector, options = {})
|
113
|
+
unless klass < Node
|
114
|
+
raise ArgumentError, "Must be given a subclass of Node"
|
115
|
+
end
|
116
|
+
|
117
|
+
options = {minimum: 1}.merge(options)
|
118
|
+
|
35
119
|
define_method(name.to_s) do
|
36
|
-
@node.all(selector,
|
37
|
-
klass.new(node:
|
120
|
+
@node.all(selector, options).map do |node|
|
121
|
+
klass.new(node: node)
|
38
122
|
end
|
39
123
|
end
|
124
|
+
|
40
125
|
define_helper_methods(name, selector)
|
41
126
|
end
|
42
127
|
|
data/lib/mache/version.rb
CHANGED
data/lib/mache.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Bassett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -114,7 +114,6 @@ files:
|
|
114
114
|
- Rakefile
|
115
115
|
- bin/console
|
116
116
|
- lib/mache.rb
|
117
|
-
- lib/mache/component.rb
|
118
117
|
- lib/mache/dsl.rb
|
119
118
|
- lib/mache/node.rb
|
120
119
|
- lib/mache/page.rb
|
data/lib/mache/component.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "mache/node"
|
2
|
-
|
3
|
-
module Mache
|
4
|
-
# The Component class wraps a fragment of HTML and can be used in any number
|
5
|
-
# of {Page} classes using the `component` macro. A component can contain
|
6
|
-
# elements and other components.
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
#
|
10
|
-
# class NavItem < Mache::Component
|
11
|
-
# def selected?
|
12
|
-
# node[:class].include?("selected")
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# class Nav < Mache::Component
|
17
|
-
# components :items, NavItem, "a"
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
class Component < Node
|
21
|
-
end
|
22
|
-
end
|