rspec-html 0.2.10 → 0.2.13
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/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/rspec/html/version.rb +1 -1
- data/lib/rspec_html/element.rb +6 -3
- data/lib/rspec_html/matchers/match_text.rb +19 -1
- data/lib/rspec_html/reconstituted_element.rb +19 -1
- data/lib/rspec_html/search.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b32fbdddde32e9e09c268a609b9491a616442c4817c729e530a57085d908027
|
4
|
+
data.tar.gz: d38316dc4ba034dc06d15569ce0865fc8e342db728d4f3fbfc19fb27331a35db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b5d891c6b6088337c89e9d5db30a2055124416d602804390d14e1d6a7774ea726b96ffe958977208f4204efaf1a4845801ee188c9be83d2bf275d487b72a483
|
7
|
+
data.tar.gz: 11ede37a337b267e453b4c105645f831f1996f590f5380f6d282fb705555c90a92e0c2af8ef43472bbcff3bd734df27e9548f6450616296f61e9e11f0827ecaf
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/rspec/html/version.rb
CHANGED
data/lib/rspec_html/element.rb
CHANGED
@@ -8,13 +8,16 @@ module RSpecHTML
|
|
8
8
|
extend Forwardable
|
9
9
|
|
10
10
|
def_delegators :@search,
|
11
|
-
:has_css?, :has_xpath?, :include?,
|
11
|
+
:has_css?, :has_xpath?, :include?,
|
12
|
+
:siblings, :text, :truncated_text,
|
13
|
+
:size, :length, :[],
|
14
|
+
:css, :xpath
|
12
15
|
|
13
16
|
def initialize(element, name, options: {}, siblings: [])
|
14
17
|
@name = name
|
15
18
|
@element = element
|
16
19
|
@options = options
|
17
|
-
@siblings = siblings
|
20
|
+
@siblings = siblings || []
|
18
21
|
@search = Search.new(@element, @siblings)
|
19
22
|
end
|
20
23
|
|
@@ -26,7 +29,7 @@ module RSpecHTML
|
|
26
29
|
alias exist? present?
|
27
30
|
|
28
31
|
def inspect
|
29
|
-
|
32
|
+
reconstituted
|
30
33
|
end
|
31
34
|
|
32
35
|
def to_s
|
@@ -10,10 +10,28 @@ module RSpecHTML
|
|
10
10
|
|
11
11
|
def match(actual)
|
12
12
|
@rspec_actual = actual&.text
|
13
|
-
return (actual
|
13
|
+
return regexp_match?(actual) || regexp_siblings_match?(actual) if @expected.is_a?(Regexp)
|
14
14
|
|
15
|
+
string_match?(actual) || string_siblings_match?(actual)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def regexp_match?(actual)
|
15
21
|
@expected.match(actual&.text || '')
|
16
22
|
end
|
23
|
+
|
24
|
+
def regexp_siblings_match?(actual)
|
25
|
+
actual.siblings.any? { |sibling| @expected.match(sibling&.text || '') }
|
26
|
+
end
|
27
|
+
|
28
|
+
def string_match?(actual)
|
29
|
+
(actual&.text || '').include?(@expected.to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
def string_siblings_match?(actual)
|
33
|
+
actual.siblings.any? { |sibling| (sibling&.text || '').include?(@expected.to_s) }
|
34
|
+
end
|
17
35
|
end
|
18
36
|
end
|
19
37
|
end
|
@@ -12,7 +12,7 @@ module RSpecHTML
|
|
12
12
|
name = @tag.to_s.downcase
|
13
13
|
return '#document' if name == 'document'
|
14
14
|
return name if name == 'document'
|
15
|
-
return "<#{name}#{
|
15
|
+
return "<#{name}#{shorthand_options} />" if @options.is_a?(String)
|
16
16
|
return "<#{name}#{formatted_attributes} />" unless @options&.key?(:text)
|
17
17
|
|
18
18
|
"<#{name}#{formatted_attributes}>#{@options[:text]}</#{name}>"
|
@@ -33,5 +33,23 @@ module RSpecHTML
|
|
33
33
|
def formatted_attributes
|
34
34
|
mapped_attributes.empty? ? nil : " #{mapped_attributes.join(' ')}"
|
35
35
|
end
|
36
|
+
|
37
|
+
def shorthand_options
|
38
|
+
case @options[0]
|
39
|
+
when '.'
|
40
|
+
" #{shorthand_classes}"
|
41
|
+
when '#'
|
42
|
+
options = %( id="#{@options.partition('#').last.partition('.').first}")
|
43
|
+
shorthand_classes.nil? ? options : "#{options} #{shorthand_classes}"
|
44
|
+
else
|
45
|
+
@options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def shorthand_classes
|
50
|
+
return nil unless @options.include?('.')
|
51
|
+
|
52
|
+
%(class="#{@options.partition('.').last.split('.').map(&:strip).reject(&:empty?).join(' ')}")
|
53
|
+
end
|
36
54
|
end
|
37
55
|
end
|
data/lib/rspec_html/search.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Farrell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|