draft_matchers 0.0.1.2 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/draft_matchers.rb +191 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a04ea5cb659061e9b5a4b5751cbcf9e291f5828f38256c21aa12908a490b0fc
|
4
|
+
data.tar.gz: a1729d957151996507e05018a34a4a6b1478eb56e1aef6a7d4ecc355e9a79d52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8261b4276f35f1eb476aa9d26d91a2023cef665dbc83ee95dfc28b08a48eccbba20f0b1e3e1d4b2fb08e9517ae80b549df8176d5b8b59f1b7a3bf72381929051
|
7
|
+
data.tar.gz: 2e8eca5e79eadbc66b482e45b6fd29b41719834fc60c78f3ade0818d3e2a6fd6e70ab893d2e610b8f5547dab8d8636399baab10aa791a289d2adb6f9a7f28e0d
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
require 'color_namer'
|
3
|
+
|
4
|
+
module DraftMatchers
|
5
|
+
|
6
|
+
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
7
|
+
match do |actual|
|
8
|
+
actual % expected == 0
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec::Matchers.define :have_color do |expected_color|
|
13
|
+
actual_color = nil
|
14
|
+
match do |actual|
|
15
|
+
rgba_color_value = actual.native.style("color")
|
16
|
+
color_number_values = rgba_color_value.gsub(/rgba?\(/, "").split(",")
|
17
|
+
|
18
|
+
red_value = color_number_values[0].to_i
|
19
|
+
green_value = color_number_values[1].to_i
|
20
|
+
blue_value = color_number_values[2].to_i
|
21
|
+
color_array = ColorNamer.name_from_rgb(red_value, green_value, blue_value)
|
22
|
+
actual_color = color_array.last.downcase
|
23
|
+
expected_color.downcase == actual_color
|
24
|
+
end
|
25
|
+
failure_message do |actual|
|
26
|
+
"expected #{actual.tag_name} to have a text color of '#{expected_color}', but was '#{actual_color}' instead'."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec::Matchers.define :have_background_color do |expected_color|
|
31
|
+
actual_color = nil
|
32
|
+
match do |actual|
|
33
|
+
rgba_color_value = actual.native.style("background-color")
|
34
|
+
color_number_values = rgba_color_value.gsub(/rgba?\(/, "").split(",")
|
35
|
+
|
36
|
+
red_value = color_number_values[0].to_i
|
37
|
+
green_value = color_number_values[1].to_i
|
38
|
+
blue_value = color_number_values[2].to_i
|
39
|
+
color_array = ColorNamer.name_from_rgb(red_value, green_value, blue_value)
|
40
|
+
actual_color = color_array.last.downcase
|
41
|
+
expected_color.downcase == actual_color
|
42
|
+
end
|
43
|
+
failure_message do |actual|
|
44
|
+
"expected #{actual.tag_name} to have a background color of '#{expected_color}', but was '#{actual_color}' instead'."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
RSpec::Matchers.define :have_border_color do |expected_color|
|
49
|
+
actual_color = nil
|
50
|
+
match do |actual|
|
51
|
+
rgba_color_value = actual.native.style("border-color")
|
52
|
+
color_number_values = rgba_color_value.gsub(/rgba?\(/, "").split(",")
|
53
|
+
|
54
|
+
red_value = color_number_values[0].to_i
|
55
|
+
green_value = color_number_values[1].to_i
|
56
|
+
blue_value = color_number_values[2].to_i
|
57
|
+
color_array = ColorNamer.name_from_rgb(red_value, green_value, blue_value)
|
58
|
+
actual_color = color_array.last.downcase
|
59
|
+
expected_color.downcase == actual_color
|
60
|
+
end
|
61
|
+
failure_message do |actual|
|
62
|
+
"expected #{actual.tag_name} to have a border color of '#{expected_color}', but was '#{actual_color}' instead'."
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
RSpec::Matchers.define :have_same_width_as do |expected|
|
67
|
+
actual_width = nil
|
68
|
+
expected_width = nil
|
69
|
+
match do |actual|
|
70
|
+
actual_width = actual.rect.width
|
71
|
+
expected_width = expected.rect.width
|
72
|
+
|
73
|
+
expected_width == actual_width
|
74
|
+
end
|
75
|
+
failure_message do |actual|
|
76
|
+
"expected #{actual.tag_name} to have the same width as '#{expected.tag_name}', but the actual width was '#{actual_width}' instead of #{expected_width}."
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
RSpec::Matchers.define :have_same_height_as do |expected|
|
81
|
+
actual_height = nil
|
82
|
+
expected_height = nil
|
83
|
+
match do |actual|
|
84
|
+
actual_height = actual.rect.height
|
85
|
+
expected_height = expected.rect.height
|
86
|
+
|
87
|
+
expected_height == actual_height
|
88
|
+
end
|
89
|
+
failure_message do |actual|
|
90
|
+
"expected #{actual.tag_name} to have the same height as '#{expected.tag_name}', but the actual height was '#{actual_height}' instead of #{expected_height}."
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
RSpec::Matchers.define :be_next_to do |expected|
|
95
|
+
actual_height = nil
|
96
|
+
expected_height = nil
|
97
|
+
match do |actual|
|
98
|
+
expected_top = expected.rect.y
|
99
|
+
expected_bottom = expected.rect.height + expected_top
|
100
|
+
expected_right = expected.rect.x
|
101
|
+
expected_left = expected_right + expected.rect.width
|
102
|
+
|
103
|
+
actual_top = actual.rect.y
|
104
|
+
actual_right = actual.rect.x
|
105
|
+
actual_left = actual_right + actual.rect.width
|
106
|
+
|
107
|
+
actual_top.between?(expected_top,expected_bottom) &&
|
108
|
+
(!actual_left.between?(expected_left, expected_right) && !actual_right.between?(expected_left, expected_right))
|
109
|
+
end
|
110
|
+
failure_message do |actual|
|
111
|
+
"expected #{actual.tag_name} to have the same height as '#{expected.tag_name}', but the actual height was '#{actual_height}' instead of #{expected_height}."
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
RSpec::Matchers.define :be_above do |expected|
|
116
|
+
actual_height = nil
|
117
|
+
expected_height = nil
|
118
|
+
match do |actual|
|
119
|
+
expected_top = expected.rect.y
|
120
|
+
expected_bottom = expected.rect.height + expected_top
|
121
|
+
|
122
|
+
actual_top = actual.rect.y
|
123
|
+
actual_bottom = actual.rect.height + actual_top
|
124
|
+
|
125
|
+
expected_bottom > actual_top
|
126
|
+
|
127
|
+
end
|
128
|
+
failure_message do |actual|
|
129
|
+
"expected #{actual.tag_name} to be above '#{expected.tag_name}', but the actual bottom was '#{expected_bottom}' when the expected top is #{actual_top}."
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
RSpec::Matchers.define :be_below do |expected|
|
134
|
+
actual_height = nil
|
135
|
+
actual_top = nil
|
136
|
+
expected_height = nil
|
137
|
+
expected_bottom = nil
|
138
|
+
match do |actual|
|
139
|
+
expected_top = expected.rect.y
|
140
|
+
expected_bottom = expected.rect.height + expected_top
|
141
|
+
|
142
|
+
actual_top = actual.rect.y
|
143
|
+
actual_bottom = actual.rect.height + actual_top
|
144
|
+
|
145
|
+
actual_top >= expected_bottom
|
146
|
+
|
147
|
+
end
|
148
|
+
failure_message do |actual|
|
149
|
+
"expected #{actual.tag_name} to be below '#{expected.tag_name}' element, but the top of the '<#{actual.tag_name}>' was '#{actual_top}px' less than the bottom of '<#{expected.tag_name}>', which is #{expected_bottom}px."
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
RSpec::Matchers.define :have_child do |expected|
|
154
|
+
|
155
|
+
match do |actual|
|
156
|
+
tag_name = actual.tag_name
|
157
|
+
actual.has_css?(expected.tag_name, text: expected.text)
|
158
|
+
end
|
159
|
+
failure_message do |actual|
|
160
|
+
"expected #{actual.tag_name} to have a child '#{expected.tag_name}' element, but couldn't find one."
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
RSpec::Matchers.define :have_matching_input do
|
165
|
+
for_attribute = nil
|
166
|
+
all_input_ids = []
|
167
|
+
match do |actual|
|
168
|
+
for_attribute = actual[:for]
|
169
|
+
|
170
|
+
all_inputs = page.all("input")
|
171
|
+
|
172
|
+
all_input_ids = all_inputs.map { |input| input[:id] }
|
173
|
+
all_input_ids.one?(for_attribute)
|
174
|
+
end
|
175
|
+
failure_message do |actual|
|
176
|
+
"Expected label’s for attribute(\"#{for_attribute}\") to match an <input> tags id attribute exactly once, but found 0 or more than 1 match (#{all_input_ids})."
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
RSpec::Matchers.define :have_for_attribute do
|
181
|
+
for_attribute = nil
|
182
|
+
|
183
|
+
match do |actual|
|
184
|
+
for_attribute = actual[:for]
|
185
|
+
!for_attribute.nil?
|
186
|
+
end
|
187
|
+
failure_message do |actual|
|
188
|
+
"Expected label's for attribute to be set to a non empty value, was '#{for_attribute}' instead."
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: draft_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jelani Woods
|
@@ -58,7 +58,8 @@ email: jelani@firstdraft.com
|
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
|
-
files:
|
61
|
+
files:
|
62
|
+
- lib/draft_matchers.rb
|
62
63
|
homepage: https://github.com/jelaniwoods/draft_matchers
|
63
64
|
licenses: []
|
64
65
|
metadata: {}
|