rspec-html 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a44b3e325c465425333bc192cf43486377191f17056c9aaf4ec8de1f69d8b98
4
- data.tar.gz: 59a989375d49adf9a4a53400f521660ef56aae326334835c5fd57deb83e44148
3
+ metadata.gz: 0d6b33d4bbde8f992f361359fed2e7ca1fa5aea60031bfeb72fcc719fe61bb4a
4
+ data.tar.gz: c8bbd8cae270839cba34034bdbd78a8d42085f01fe29891ef01eed6299805b1b
5
5
  SHA512:
6
- metadata.gz: 7e17251c5710734d9b62badbea60798acd280d51e5bb208606fecd23fcff33e8c41220e979121925c5264bbb27a4effee9b54cb4d9a89fddb5a30e8858adc847
7
- data.tar.gz: ea4ab89dc355ee02ae240746b4acb1f31a5b533e70b119b1f323f6ca290064194c9fa52de9a42b907a00d7452318d299e74ab8985f94a5a76fd15b10aebdfb25
6
+ metadata.gz: 810cc82b373e10c3ab4f137d7dc4648972f81654f07478b937b7eb38d43832273c5b0203ad8ebcc7fb6927efea78ac1d048663d9c4a5f95d8afa8459f8bdae97
7
+ data.tar.gz: 0a9e83ccf82b023d0f4809935c354ef3d31b5bb6cc95161395bd8b4246ae839fcc71abfc933563d913eea8fcd9ee0935992c535a5455ef230a768e91ca48981d
@@ -2,3 +2,50 @@ Metrics/BlockLength:
2
2
  Exclude:
3
3
  - 'spec/**/*'
4
4
  - 'rspec-html.gemspec'
5
+
6
+ Layout/EmptyLinesAroundAttributeAccessor:
7
+ Enabled: true
8
+ Layout/SpaceAroundMethodCallOperator:
9
+ Enabled: true
10
+ Lint/DeprecatedOpenSSLConstant:
11
+ Enabled: true
12
+ Lint/DuplicateElsifCondition:
13
+ Enabled: true
14
+ Lint/MixedRegexpCaptureTypes:
15
+ Enabled: true
16
+ Lint/RaiseException:
17
+ Enabled: true
18
+ Lint/StructNewOverride:
19
+ Enabled: true
20
+ Style/AccessorGrouping:
21
+ Enabled: true
22
+ Style/ArrayCoercion:
23
+ Enabled: true
24
+ Style/BisectedAttrAccessor:
25
+ Enabled: true
26
+ Style/CaseLikeIf:
27
+ Enabled: true
28
+ Style/ExponentialNotation:
29
+ Enabled: true
30
+ Style/HashAsLastArrayItem:
31
+ Enabled: true
32
+ Style/HashEachMethods:
33
+ Enabled: true
34
+ Style/HashLikeCase:
35
+ Enabled: true
36
+ Style/HashTransformKeys:
37
+ Enabled: true
38
+ Style/HashTransformValues:
39
+ Enabled: true
40
+ Style/RedundantAssignment:
41
+ Enabled: true
42
+ Style/RedundantFetchBlock:
43
+ Enabled: true
44
+ Style/RedundantFileExtensionInRequire:
45
+ Enabled: true
46
+ Style/RedundantRegexpCharacterClass:
47
+ Enabled: true
48
+ Style/RedundantRegexpEscape:
49
+ Enabled: true
50
+ Style/SlicingWithRange:
51
+ Enabled: true
@@ -1,38 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-html (0.1.2)
4
+ rspec-html (0.2.0)
5
5
  nokogiri (~> 1.10)
6
6
  rspec (~> 3.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- ast (2.4.0)
12
- betterp (0.1.3)
13
- paint (~> 2.0)
14
- byebug (11.0.1)
15
- concurrent-ruby (1.1.5)
16
- diff-lcs (1.3)
17
- i18n (1.7.0)
11
+ ast (2.4.1)
12
+ byebug (11.1.3)
13
+ concurrent-ruby (1.1.6)
14
+ devpack (0.1.2)
15
+ diff-lcs (1.4.4)
16
+ i18n (1.8.5)
18
17
  concurrent-ruby (~> 1.0)
19
- jaro_winkler (1.5.4)
20
18
  mini_portile2 (2.4.0)
21
- nokogiri (1.10.9)
19
+ nokogiri (1.10.10)
22
20
  mini_portile2 (~> 2.4.0)
23
- paint (2.1.1)
24
- parallel (1.19.1)
25
- parser (2.6.5.0)
26
- ast (~> 2.4.0)
21
+ paint (2.2.0)
22
+ parallel (1.19.2)
23
+ parser (2.7.1.4)
24
+ ast (~> 2.4.1)
27
25
  rainbow (3.0.0)
28
- rake (10.5.0)
26
+ rake (13.0.1)
27
+ regexp_parser (1.7.1)
28
+ rexml (3.2.4)
29
29
  rspec (3.9.0)
30
30
  rspec-core (~> 3.9.0)
31
31
  rspec-expectations (~> 3.9.0)
32
32
  rspec-mocks (~> 3.9.0)
33
- rspec-core (3.9.0)
34
- rspec-support (~> 3.9.0)
35
- rspec-expectations (3.9.0)
33
+ rspec-core (3.9.2)
34
+ rspec-support (~> 3.9.3)
35
+ rspec-expectations (3.9.2)
36
36
  diff-lcs (>= 1.2.0, < 2.0)
37
37
  rspec-support (~> 3.9.0)
38
38
  rspec-its (1.3.0)
@@ -41,36 +41,40 @@ GEM
41
41
  rspec-mocks (3.9.1)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
43
  rspec-support (~> 3.9.0)
44
- rspec-support (3.9.0)
45
- rubocop (0.76.0)
46
- jaro_winkler (~> 1.5.1)
44
+ rspec-support (3.9.3)
45
+ rubocop (0.88.0)
47
46
  parallel (~> 1.10)
48
- parser (>= 2.6)
47
+ parser (>= 2.7.1.1)
49
48
  rainbow (>= 2.2.2, < 4.0)
49
+ regexp_parser (>= 1.7)
50
+ rexml
51
+ rubocop-ast (>= 0.1.0, < 1.0)
50
52
  ruby-progressbar (~> 1.7)
51
- unicode-display_width (>= 1.4.0, < 1.7)
52
- rubocop-rspec (1.36.0)
53
- rubocop (>= 0.68.1)
53
+ unicode-display_width (>= 1.4.0, < 2.0)
54
+ rubocop-ast (0.2.0)
55
+ parser (>= 2.7.0.1)
56
+ rubocop-rspec (1.42.0)
57
+ rubocop (>= 0.87.0)
54
58
  ruby-progressbar (1.10.1)
55
- strong_versions (0.3.2)
56
- i18n (>= 0.5.0)
59
+ strong_versions (0.4.5)
60
+ i18n (>= 0.5)
57
61
  paint (~> 2.0)
58
- unicode-display_width (1.6.0)
62
+ unicode-display_width (1.7.0)
59
63
 
60
64
  PLATFORMS
61
65
  ruby
62
66
 
63
67
  DEPENDENCIES
64
- betterp (~> 0.1.3)
65
68
  bundler (~> 2.0)
66
69
  byebug (~> 11.0)
70
+ devpack (~> 0.1.2)
67
71
  i18n (~> 1.7)
68
- rake (~> 10.0)
72
+ rake (~> 13.0)
69
73
  rspec-html!
70
74
  rspec-its (~> 1.3)
71
- rubocop (~> 0.76.0)
75
+ rubocop (~> 0.88.0)
72
76
  rubocop-rspec (~> 1.36)
73
- strong_versions (~> 0.3.2)
77
+ strong_versions (~> 0.4.5)
74
78
 
75
79
  BUNDLED WITH
76
80
  2.0.2
data/README.md CHANGED
@@ -5,7 +5,7 @@ _RSpec::HTML_ provides a simple object interface to HTML responses from [_RSpec
5
5
  ## Installation
6
6
 
7
7
  ```ruby
8
- gem 'rspec-html', '~> 0.1.3'
8
+ gem 'rspec-html', '~> 0.2.0'
9
9
  ```
10
10
 
11
11
  Bundle
@@ -26,17 +26,61 @@ Require the gem in your `spec_helper.rb`:
26
26
  require 'rspec/html'
27
27
  ```
28
28
 
29
- In request specs, access the HTML document through the provided object interface:
29
+ In request specs, access the HTML document through the provided `document` object.
30
30
 
31
+ ### Object Interface
32
+
33
+ To navigating the _DOM_ by a sequence of tag names use chained method calls on the `document` object:
34
+
35
+ #### Tag Traversal
36
+ ```ruby
37
+ expect(document.body.div.span).to include 'some text'
38
+ ```
39
+
40
+ #### Attribute Matching
41
+ To select an element matching certain attributes pass a hash to any of the chained methods:
42
+ ```ruby
43
+ expect(document.body.div(id: 'my-div').span(class: 'my-class')).to eql 'some text'
44
+ ```
45
+
46
+ #### Attribute Retrieval
47
+ To select an attribute from an element use the hash-style interface:
48
+ ```ruby
49
+ expect(document.body.div.span[:class]).to eql 'my-class'
50
+ expect(document.body.div.span['data-content']).to eql 'my content'
51
+ ```
52
+
53
+ #### Indexing a Matching Set
54
+ To select an index from a set of matched elements use the array-style interface (the first matching element is `1`, not `0`):
55
+ ```ruby
56
+ expect(document.body.div[1].span[1][:class]).to eql 'my-class'
57
+ ```
58
+
59
+ #### Element Existence
60
+ To test if a matching element was found use the `exist` matcher:
61
+ ```ruby
62
+ expect(document.body.div[1]).to exist
63
+ expect(document.body.div[4]).to_not exist
64
+ ```
65
+
66
+ #### Length of matched attributes
67
+ To test the length of matched elements use the `#size` or `#length` method:
68
+ ```ruby
69
+ expect(document.body.div.size).to eql 3
70
+ expect(document.body.div.length).to eql 3
71
+ ```
72
+
73
+ #### XPath / CSS Selectors
74
+ If you need something more specific you can always use the _Nokogiri_ `#xpath` and `#css` methods on any element:
75
+ ```ruby
76
+ expect(document.body.xpath('//span[@class="my-class"]')).to include 'some text'
77
+ expect(document.body.css('span.my-class')).to include 'some text'
78
+ ```
79
+
80
+ To simply check that an _XPath_ or _CSS_ selector exists use `have_xpath` and `have_css`:
31
81
  ```ruby
32
- RSpec.describe 'something', type: :request do
33
- it 'does something' do
34
- get '/'
35
- expect(document.body).to include 'something'
36
- expect(document.body).to have_css 'html body div.myclass'
37
- expect(document.body).to have_xpath '//html/body/div[@class="myclass"]'
38
- end
39
- end
82
+ expect(document.body).to have_css 'html body div.myclass'
83
+ expect(document.body).to have_xpath '//html/body/div[@class="myclass"]'
40
84
  ```
41
85
 
42
86
  ## Contributing
@@ -9,7 +9,7 @@ module RSpec
9
9
  # Module extension for RSpec::SharedContext
10
10
  module HTML
11
11
  def document
12
- RSpecHTML::Document.new(response.body)
12
+ RSpecHTML::Element.new(Nokogiri::HTML.parse(response.body), :document)
13
13
  end
14
14
  end
15
15
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module HTML
5
- VERSION = '0.1.3'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -5,10 +5,8 @@ require 'pathname'
5
5
 
6
6
  require 'rspec_html/nameable'
7
7
  require 'rspec_html/searchable'
8
- require 'rspec_html/body'
9
- require 'rspec_html/document'
10
- require 'rspec_html/head'
11
- require 'rspec_html/title'
8
+ require 'rspec_html/element'
9
+ require 'rspec_html/tags'
12
10
 
13
11
  # Support module for rspec/html
14
12
  module RSpecHTML
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ # HTML DOM element abstraction
5
+ class Element
6
+ include Searchable
7
+ include Nameable
8
+
9
+ def initialize(element, name, siblings: [])
10
+ @name = name
11
+ @element = element
12
+ @siblings = siblings
13
+ end
14
+ end
15
+ end
@@ -4,33 +4,98 @@ module RSpecHTML
4
4
  # Mixin module providing methods for searching text content of HTML entities
5
5
  module Searchable
6
6
  def include?(val)
7
- @entity.text.include?(val)
7
+ @element.text.include?(val)
8
8
  end
9
9
 
10
10
  def css(*args)
11
- @entity.css(*args)
11
+ self.class.new(@element&.css(*args), :css)
12
12
  end
13
13
 
14
14
  def xpath(*args)
15
- @entity.xpath(*args)
15
+ self.class.new(@element&.xpath(*args), :xpath)
16
16
  end
17
17
 
18
+ def present?
19
+ !@element.nil?
20
+ end
21
+ alias exist? present?
22
+
18
23
  # rubocop:disable Naming/PredicateName
19
24
  def has_css?(*args)
20
- !css(*args).empty?
25
+ !@element&.css(*args)&.empty?
21
26
  end
22
27
 
23
28
  def has_xpath?(*args)
24
- !xpath(*args).empty?
29
+ !@element&.xpath(*args)&.empty?
25
30
  end
26
31
  # rubocop:enable Naming/PredicateName
27
32
 
28
33
  def to_s
29
- @entity.text.strip
34
+ @element&.text&.strip
30
35
  end
31
36
 
32
37
  def inspect
33
- %("#{self}")
38
+ %("#{@element}")
39
+ end
40
+
41
+ def [](val)
42
+ return index(val) if val.is_a?(Integer)
43
+ return range(val) if val.is_a?(Range)
44
+
45
+ @element&.attr(val.to_s)
46
+ end
47
+
48
+ def size
49
+ return @element.size if @element.respond_to?(:size)
50
+
51
+ @siblings.size
52
+ end
53
+ alias length size
54
+
55
+ private
56
+
57
+ def method_missing(tag, *args)
58
+ return super unless Tags.include?(tag)
59
+ return self.class.new(find(tag), tag, siblings: find(tag, all: true)) if args.empty?
60
+
61
+ self.class.new(where(tag, args.first), tag, siblings: where(tag, args.first, all: true))
62
+ end
63
+
64
+ def index(val)
65
+ zero_index_error if val.zero?
66
+ self.class.new(@siblings[val - 1], name)
67
+ end
68
+
69
+ def range(val)
70
+ zero_index_error if val.first.zero?
71
+ self.class.new(@siblings[(val.first - 1)..(val.last - 1)], :range)
72
+ end
73
+
74
+ def zero_index_error
75
+ raise ArgumentError, 'Index for matched sets starts at 1, not 0.'
76
+ end
77
+
78
+ def where(tag, query, all: false)
79
+ matched = @element&.xpath("//#{tag}[#{where_conditions(query)}]")
80
+ return matched&.first unless all
81
+
82
+ matched
83
+ end
84
+
85
+ def where_conditions(query)
86
+ query.map do |key, value|
87
+ %(@#{key}="#{value}")
88
+ end.join ' and '
89
+ end
90
+
91
+ def find(tag, all: false)
92
+ return @element&.css(tag.to_s)&.first unless all
93
+
94
+ @element&.css(tag.to_s)
95
+ end
96
+
97
+ def respond_to_missing?(method_name, *_)
98
+ Tags.include?(method_name)
34
99
  end
35
100
  end
36
101
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ # HTML tag identification, used to determine viability for DOM traversal via chained methods.
5
+ class Tags
6
+ def self.include?(val)
7
+ tags.include?(val.to_s.upcase)
8
+ end
9
+
10
+ # rubocop:disable Metrics/MethodLength
11
+ def self.tags
12
+ %w[
13
+ A ABBR ACRONYM ADDRESS APPLET AREA ARTICLE ASIDE AUDIO B BASE BASEFONT BDI BDO BGSOUND
14
+ BIG BLINK BLOCKQUOTE BODY BR BUTTON CANVAS CAPTION CENTER CITE CODE COL COLGROUP COMMAND
15
+ CONTENT DATA DATALIST DD DEL DETAILS DFN DIALOG DIR DIV DL DT ELEMENT EM EMBED FIELDSET
16
+ FIGCAPTION FIGURE FONT FOOTER FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HEADER HGROUP HR
17
+ HTML I IFRAME IMAGE IMG INPUT INS ISINDEX KBD KEYGEN LABEL LEGEND LI LINK LISTING MAIN
18
+ MAIN MAP MARK MARQUEE MENU MENUITEM META METER MULTICOL NAV NEXTID NOBR NOEMBED NOFRAMES
19
+ NOSCRIPT OBJECT OL OPTGROUP OPTION OUTPUT P PARAM PICTURE PLAINTEXT PRE PROGRESS Q RB RP
20
+ RT RTC RUBY S SAMP SCRIPT SECTION SELECT SHADOW SLOT SMALL SOURCE SPACER SPAN STRIKE
21
+ STRONG STYLE SUB SUMMARY SUP TABLE TBODY TD TEMPLATE TEXTAREA TFOOT TH THEAD TIME TITLE
22
+ TR TRACK TT U UL VAR VIDEO WBR XMP
23
+ ]
24
+ end
25
+ # rubocop:enable Metrics/MethodLength
26
+ end
27
+ end
@@ -31,13 +31,13 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency 'nokogiri', '~> 1.10'
32
32
  spec.add_dependency 'rspec', '~> 3.0'
33
33
 
34
- spec.add_development_dependency 'betterp', '~> 0.1.3'
35
34
  spec.add_development_dependency 'bundler', '~> 2.0'
36
35
  spec.add_development_dependency 'byebug', '~> 11.0'
36
+ spec.add_development_dependency 'devpack', '~> 0.1.2'
37
37
  spec.add_development_dependency 'i18n', '~> 1.7'
38
- spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rake', '~> 13.0'
39
39
  spec.add_development_dependency 'rspec-its', '~> 1.3'
40
- spec.add_development_dependency 'rubocop', '~> 0.76.0'
40
+ spec.add_development_dependency 'rubocop', '~> 0.88.0'
41
41
  spec.add_development_dependency 'rubocop-rspec', '~> 1.36'
42
- spec.add_development_dependency 'strong_versions', '~> 0.3.2'
42
+ spec.add_development_dependency 'strong_versions', '~> 0.4.5'
43
43
  end
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.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -39,47 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: betterp
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.3
47
+ version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.3
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bundler
56
+ name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '11.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: '11.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: byebug
70
+ name: devpack
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '11.0'
75
+ version: 0.1.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '11.0'
82
+ version: 0.1.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: i18n
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '10.0'
103
+ version: '13.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '10.0'
110
+ version: '13.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec-its
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.76.0
131
+ version: 0.88.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.76.0
138
+ version: 0.88.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.3.2
159
+ version: 0.4.5
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 0.3.2
166
+ version: 0.4.5
167
167
  description: HTML document abstraction and matchers for RSpec
168
168
  email:
169
169
  - git@bob.frl
@@ -187,12 +187,10 @@ files:
187
187
  - lib/rspec/html.rb
188
188
  - lib/rspec/html/version.rb
189
189
  - lib/rspec_html.rb
190
- - lib/rspec_html/body.rb
191
- - lib/rspec_html/document.rb
192
- - lib/rspec_html/head.rb
190
+ - lib/rspec_html/element.rb
193
191
  - lib/rspec_html/nameable.rb
194
192
  - lib/rspec_html/searchable.rb
195
- - lib/rspec_html/title.rb
193
+ - lib/rspec_html/tags.rb
196
194
  - rspec-html.gemspec
197
195
  homepage: https://github.com/bobf/rspec-html
198
196
  licenses:
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RSpecHTML
4
- # HTML/BODY abstraction
5
- class Body
6
- include Searchable
7
- include Nameable
8
-
9
- def initialize(parsed_html)
10
- @name = :body
11
- @entity = parsed_html.css('body')
12
- end
13
- end
14
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RSpecHTML
4
- # HTML Document representation
5
- class Document
6
- def initialize(html)
7
- @html = html
8
- end
9
-
10
- # rubocop:disable Naming/PredicateName
11
- def has_xpath?(*args)
12
- !parsed_html.xpath(*args).empty?
13
- end
14
-
15
- def has_css?(*args)
16
- !parsed_html.css(*args).empty?
17
- end
18
- # rubocop:enable Naming/PredicateName
19
-
20
- def body
21
- Body.new(parsed_html)
22
- end
23
-
24
- def head
25
- Head.new(parsed_html)
26
- end
27
-
28
- private
29
-
30
- def parsed_html
31
- @parsed_html ||= Nokogiri::HTML(@html)
32
- end
33
- end
34
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RSpecHTML
4
- # HTML/BODY abstraction
5
- class Head
6
- include Nameable
7
- include Searchable
8
-
9
- def initialize(parsed_html)
10
- @parsed_html = parsed_html
11
- @entity = parsed_html.css('head')
12
- @name = :head
13
- end
14
-
15
- def title
16
- Title.new(@parsed_html)
17
- end
18
-
19
- def include?(val)
20
- title.include?(val)
21
- end
22
- end
23
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RSpecHTML
4
- # HTML/HEAD/TITLE abstraction
5
- class Title
6
- include Searchable
7
- include Nameable
8
-
9
- def initialize(parsed_html)
10
- @name = :title
11
- @entity = parsed_html.css('head title')
12
- end
13
- end
14
- end