rspec-html 0.2.11 → 0.2.14
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 +4 -2
- data/README.md +6 -1
- data/lib/rspec/html/version.rb +1 -1
- data/lib/rspec_html/element.rb +3 -3
- data/lib/rspec_html/matchers/match_text.rb +5 -0
- data/lib/rspec_html/reconstituted_element.rb +19 -1
- data/lib/rspec_html/search.rb +8 -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: 01bcf5f299f82598a2836fee0f3ef8eb79af8b8219c65c74f6d130d3aa33a0e3
|
4
|
+
data.tar.gz: 8c784dec087fd10eb08a889db1e69dfaecbc1c3120347f66307ddc0071556bd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 566fbca771830a80666a798820e683ed857d01bf15c7fc147894986af724399d3b78c01e14316da5e9b3de7ed0e8a3e5a61f5de82512e7cad3c1e096809b4b0c
|
7
|
+
data.tar.gz: e12956efafa2e2a917e12640cee2bf43abe24d14f5ab9b19a87173e2e9689b83f741a50a18ece0f0dd9c82843b93c7539443a649ac431b3540a841c2158ba8f2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-html (0.2.
|
4
|
+
rspec-html (0.2.14)
|
5
5
|
nokogiri (~> 1.10)
|
6
6
|
rspec (~> 3.0)
|
7
7
|
|
@@ -14,7 +14,9 @@ GEM
|
|
14
14
|
diff-lcs (1.5.0)
|
15
15
|
i18n (1.10.0)
|
16
16
|
concurrent-ruby (~> 1.0)
|
17
|
-
|
17
|
+
mini_portile2 (2.8.0)
|
18
|
+
nokogiri (1.13.8)
|
19
|
+
mini_portile2 (~> 2.8.0)
|
18
20
|
racc (~> 1.4)
|
19
21
|
paint (2.2.1)
|
20
22
|
parallel (1.22.1)
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ _RSpec::HTML_ provides a simple object interface to HTML responses from [_RSpec
|
|
7
7
|
Add the gem to your `Gemfile`:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'rspec-html', '~> 0.2.
|
10
|
+
gem 'rspec-html', '~> 0.2.13'
|
11
11
|
```
|
12
12
|
|
13
13
|
And rebuild your bundle:
|
@@ -59,6 +59,11 @@ To select an element matching certain attributes pass a hash to any of the chain
|
|
59
59
|
expect(document.body.div(id: 'my-div').span(align: 'left')).to contain_text 'some text'
|
60
60
|
```
|
61
61
|
|
62
|
+
Special attributes like `checked` can be found using the `#attributes` method:
|
63
|
+
```ruby
|
64
|
+
expect(document.input(type: 'checkbox', name: 'my-name')).attributes).to include 'checked'
|
65
|
+
```
|
66
|
+
|
62
67
|
#### Class Matching
|
63
68
|
_CSS_ classes are treated as a special case: to select an element matching a set of classes pass the `class` parameter:
|
64
69
|
```ruby
|
data/lib/rspec/html/version.rb
CHANGED
data/lib/rspec_html/element.rb
CHANGED
@@ -9,7 +9,7 @@ module RSpecHTML
|
|
9
9
|
|
10
10
|
def_delegators :@search,
|
11
11
|
:has_css?, :has_xpath?, :include?,
|
12
|
-
:siblings, :text, :truncated_text,
|
12
|
+
:siblings, :text, :truncated_text, :attributes,
|
13
13
|
:size, :length, :[],
|
14
14
|
:css, :xpath
|
15
15
|
|
@@ -17,7 +17,7 @@ module RSpecHTML
|
|
17
17
|
@name = name
|
18
18
|
@element = element
|
19
19
|
@options = options
|
20
|
-
@siblings = siblings
|
20
|
+
@siblings = siblings || []
|
21
21
|
@search = Search.new(@element, @siblings)
|
22
22
|
end
|
23
23
|
|
@@ -29,7 +29,7 @@ module RSpecHTML
|
|
29
29
|
alias exist? present?
|
30
30
|
|
31
31
|
def inspect
|
32
|
-
|
32
|
+
reconstituted
|
33
33
|
end
|
34
34
|
|
35
35
|
def to_s
|
@@ -9,6 +9,7 @@ module RSpecHTML
|
|
9
9
|
diffable
|
10
10
|
|
11
11
|
def match(actual)
|
12
|
+
raise_argument_error unless actual.is_a?(RSpecHTML::Element)
|
12
13
|
@rspec_actual = actual&.text
|
13
14
|
return regexp_match?(actual) || regexp_siblings_match?(actual) if @expected.is_a?(Regexp)
|
14
15
|
|
@@ -32,6 +33,10 @@ module RSpecHTML
|
|
32
33
|
def string_siblings_match?(actual)
|
33
34
|
actual.siblings.any? { |sibling| (sibling&.text || '').include?(@expected.to_s) }
|
34
35
|
end
|
36
|
+
|
37
|
+
def raise_argument_error
|
38
|
+
raise ArumentError, 'Expected RSpecHTML::Element with `match_text` matcher.'
|
39
|
+
end
|
35
40
|
end
|
36
41
|
end
|
37
42
|
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
@@ -11,6 +11,10 @@ module RSpecHTML
|
|
11
11
|
@siblings = siblings
|
12
12
|
end
|
13
13
|
|
14
|
+
def to_s
|
15
|
+
@element&.to_s
|
16
|
+
end
|
17
|
+
|
14
18
|
def include?(val)
|
15
19
|
text.include?(val)
|
16
20
|
end
|
@@ -56,6 +60,10 @@ module RSpecHTML
|
|
56
60
|
"#{text[0..max]}...#{text[-max..-1]}"
|
57
61
|
end
|
58
62
|
|
63
|
+
def attributes
|
64
|
+
@element&.attributes&.to_h { |key, val| [key.to_sym, val.to_s] } || {}
|
65
|
+
end
|
66
|
+
|
59
67
|
def size
|
60
68
|
return @element.size if @element.respond_to?(:size)
|
61
69
|
|
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.14
|
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-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|