rspec-html 0.2.5 → 0.2.8

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: a5241cc27dba3e36c05cd7595280908be306d659d6611e02b70d58984a2f8900
4
- data.tar.gz: 18e5487083e27fe812565b15c0411026ba622cb82c0bbbeb36787167928dab48
3
+ metadata.gz: a271ab933a02e1c5456ea472551e09d194132d79d9f47924cc8aa9cc4ae9c832
4
+ data.tar.gz: 230f1ae1e54404f1766b909074bea3d0b83d748f8a57a7df9c497a60137c4fc4
5
5
  SHA512:
6
- metadata.gz: 39065b13e1a1d959fcebecc3004b20e2940b560c06a9789d39b1ffa99c249f4cb0062c3888ed6af69e44d2523ff8ed4ea66989c4e35e3e924764610c51900414
7
- data.tar.gz: 4c275980c39e8f9506a03cbb8ceca6bfdf16304aaa37f4eba318ae0e085106cfc5502f34148d4d6dfe86d7a000d145e39015ab20471ee812447f16d7b09d60b3
6
+ metadata.gz: ad8a71ee657b000eb1b334d365da8f723ec0466c69aa7580b8104c87aae23066ca703cdbbea3717ac3b422fb57b59c8784ecef4a8eeb3366a0f719bd5f2808eb
7
+ data.tar.gz: a1eeede78f3c7bddc433c2162c4355779c55bd9c6c0ce984f42ad347eaef3e8c5cc22e7b78dbe29450a353c8acd679a24acaccd4a6add6981223ba90eaf45901
data/.rubocop.yml CHANGED
@@ -3,85 +3,9 @@ Metrics/BlockLength:
3
3
  - 'spec/**/*'
4
4
  - 'rspec-html.gemspec'
5
5
 
6
- Gemspec/RequiredRubyVersion:
7
- Enabled: false
8
-
9
- Layout/LineLength:
10
- Max: 100
6
+ AllCops:
7
+ NewCops: enable
11
8
 
12
9
  # Compatibility with older (< 2.6) Rubies.
13
10
  Style/SlicingWithRange:
14
11
  Enabled: false
15
-
16
- Layout/EmptyLinesAroundAttributeAccessor:
17
- Enabled: true
18
- Layout/SpaceAroundMethodCallOperator:
19
- Enabled: true
20
- Lint/DeprecatedOpenSSLConstant:
21
- Enabled: true
22
- Lint/DuplicateElsifCondition:
23
- Enabled: true
24
- Lint/MixedRegexpCaptureTypes:
25
- Enabled: true
26
- Lint/RaiseException:
27
- Enabled: true
28
- Lint/StructNewOverride:
29
- Enabled: true
30
- Style/AccessorGrouping:
31
- Enabled: true
32
- Style/ArrayCoercion:
33
- Enabled: true
34
- Style/BisectedAttrAccessor:
35
- Enabled: true
36
- Style/CaseLikeIf:
37
- Enabled: true
38
- Style/ExponentialNotation:
39
- Enabled: true
40
- Style/HashAsLastArrayItem:
41
- Enabled: true
42
- Style/HashEachMethods:
43
- Enabled: true
44
- Style/HashLikeCase:
45
- Enabled: true
46
- Style/HashTransformKeys:
47
- Enabled: true
48
- Style/HashTransformValues:
49
- Enabled: true
50
- Style/RedundantAssignment:
51
- Enabled: true
52
- Style/RedundantFetchBlock:
53
- Enabled: true
54
- Style/RedundantFileExtensionInRequire:
55
- Enabled: true
56
- Style/RedundantRegexpCharacterClass:
57
- Enabled: true
58
- Style/RedundantRegexpEscape:
59
- Enabled: true
60
- Lint/BinaryOperatorWithIdenticalOperands:
61
- Enabled: true
62
- Lint/DuplicateRescueException:
63
- Enabled: true
64
- Lint/EmptyConditionalBody:
65
- Enabled: true
66
- Lint/FloatComparison:
67
- Enabled: true
68
- Lint/MissingSuper:
69
- Enabled: true
70
- Lint/OutOfRangeRegexpRef:
71
- Enabled: true
72
- Lint/SelfAssignment:
73
- Enabled: true
74
- Lint/TopLevelReturnWithArgument:
75
- Enabled: true
76
- Lint/UnreachableLoop:
77
- Enabled: true
78
- Style/ExplicitBlockArgument:
79
- Enabled: true
80
- Style/GlobalStdStream:
81
- Enabled: true
82
- Style/OptionalBooleanParameter:
83
- Enabled: true
84
- Style/SingleArgumentDig:
85
- Enabled: true
86
- Style/StringConcatenation:
87
- Enabled: true
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.1
1
+ 2.6.9
data/Gemfile.lock CHANGED
@@ -1,80 +1,81 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-html (0.2.5)
4
+ rspec-html (0.2.8)
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.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)
11
+ ast (2.4.2)
12
+ concurrent-ruby (1.1.10)
13
+ devpack (0.4.0)
14
+ diff-lcs (1.5.0)
15
+ i18n (1.10.0)
17
16
  concurrent-ruby (~> 1.0)
18
- mini_portile2 (2.4.0)
19
- nokogiri (1.10.10)
20
- mini_portile2 (~> 2.4.0)
21
- paint (2.2.0)
22
- parallel (1.19.2)
23
- parser (2.7.1.4)
17
+ nokogiri (1.13.5-x86_64-linux)
18
+ racc (~> 1.4)
19
+ paint (2.2.1)
20
+ parallel (1.22.1)
21
+ parser (3.1.2.0)
24
22
  ast (~> 2.4.1)
25
- rainbow (3.0.0)
26
- rake (13.0.1)
27
- regexp_parser (1.7.1)
28
- rexml (3.2.4)
29
- rspec (3.9.0)
30
- rspec-core (~> 3.9.0)
31
- rspec-expectations (~> 3.9.0)
32
- rspec-mocks (~> 3.9.0)
33
- rspec-core (3.9.2)
34
- rspec-support (~> 3.9.3)
35
- rspec-expectations (3.9.2)
23
+ racc (1.6.0)
24
+ rainbow (3.1.1)
25
+ rake (13.0.6)
26
+ regexp_parser (2.3.1)
27
+ rexml (3.2.5)
28
+ rspec (3.11.0)
29
+ rspec-core (~> 3.11.0)
30
+ rspec-expectations (~> 3.11.0)
31
+ rspec-mocks (~> 3.11.0)
32
+ rspec-core (3.11.0)
33
+ rspec-support (~> 3.11.0)
34
+ rspec-expectations (3.11.0)
36
35
  diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.9.0)
36
+ rspec-support (~> 3.11.0)
38
37
  rspec-its (1.3.0)
39
38
  rspec-core (>= 3.0.0)
40
39
  rspec-expectations (>= 3.0.0)
41
- rspec-mocks (3.9.1)
40
+ rspec-mocks (3.11.1)
42
41
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.9.0)
44
- rspec-support (3.9.3)
45
- rubocop (0.89.1)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-support (3.11.0)
44
+ rubocop (1.29.0)
46
45
  parallel (~> 1.10)
47
- parser (>= 2.7.1.1)
46
+ parser (>= 3.1.0.0)
48
47
  rainbow (>= 2.2.2, < 4.0)
49
- regexp_parser (>= 1.7)
50
- rexml
51
- rubocop-ast (>= 0.3.0, < 1.0)
48
+ regexp_parser (>= 1.8, < 3.0)
49
+ rexml (>= 3.2.5, < 4.0)
50
+ rubocop-ast (>= 1.17.0, < 2.0)
52
51
  ruby-progressbar (~> 1.7)
53
- unicode-display_width (>= 1.4.0, < 2.0)
54
- rubocop-ast (0.3.0)
55
- parser (>= 2.7.1.4)
56
- rubocop-rspec (1.42.0)
57
- rubocop (>= 0.87.0)
58
- ruby-progressbar (1.10.1)
52
+ unicode-display_width (>= 1.4.0, < 3.0)
53
+ rubocop-ast (1.17.0)
54
+ parser (>= 3.1.1.0)
55
+ rubocop-rake (0.6.0)
56
+ rubocop (~> 1.0)
57
+ rubocop-rspec (2.10.0)
58
+ rubocop (~> 1.19)
59
+ ruby-progressbar (1.11.0)
59
60
  strong_versions (0.4.5)
60
61
  i18n (>= 0.5)
61
62
  paint (~> 2.0)
62
- unicode-display_width (1.7.0)
63
+ unicode-display_width (2.1.0)
63
64
 
64
65
  PLATFORMS
65
66
  ruby
66
67
 
67
68
  DEPENDENCIES
68
69
  bundler (~> 2.0)
69
- byebug (~> 11.0)
70
- devpack (~> 0.1.2)
70
+ devpack (~> 0.4.0)
71
71
  i18n (~> 1.7)
72
72
  rake (~> 13.0)
73
73
  rspec-html!
74
74
  rspec-its (~> 1.3)
75
- rubocop (~> 0.89.1)
76
- rubocop-rspec (~> 1.36)
75
+ rubocop (~> 1.29)
76
+ rubocop-rake (~> 0.6.0)
77
+ rubocop-rspec (~> 2.10)
77
78
  strong_versions (~> 0.4.5)
78
79
 
79
80
  BUNDLED WITH
80
- 2.1.4
81
+ 2.3.11
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.5'
10
+ gem 'rspec-html', '~> 0.2.8'
11
11
  ```
12
12
 
13
13
  And rebuild your bundle:
@@ -112,12 +112,15 @@ expect(document.body).to have_xpath '//html/body/div[@class="myclass"]'
112
112
  ### Custom Matchers
113
113
  <a name="matchers"></a>
114
114
 
115
- #### contain_text
115
+ #### match_text
116
116
 
117
- Use the `contain_text` matcher to locate text within a _DOM_ element. All mark-up elements are stripped when using this matcher.
117
+ Use the `match_text` matcher to locate text within a _DOM_ element. All mark-up elements are stripped when using this matcher.
118
+
119
+ This matcher receives either a string or a regular expression.
118
120
 
119
121
  ```ruby
120
- expect(document.body.form).to contain_text 'Please enter your password'
122
+ expect(document.body.form).to match_text 'Please enter your password'
123
+ expect(document.body.form).to match_text /Please enter your [a-z]+/
121
124
  ```
122
125
 
123
126
  #### contain_tag
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module HTML
5
- VERSION = '0.2.5'
5
+ VERSION = '0.2.8'
6
6
  end
7
7
  end
data/lib/rspec/html.rb CHANGED
@@ -11,11 +11,9 @@ module RSpec
11
11
  def document
12
12
  return @document if @document
13
13
 
14
- if !defined?(response) || response.nil?
15
- raise RSpecHTML::NoResponseError, 'No `response` object found. Make a request first.'
16
- end
17
-
18
14
  RSpecHTML::Element.new(Nokogiri::HTML.parse(response.body), :document)
15
+ rescue NameError
16
+ raise RSpecHTML::NoResponseError, 'No `response` object found. Make a request first.'
19
17
  end
20
18
 
21
19
  def parse_html(content)
@@ -8,7 +8,7 @@ module RSpecHTML
8
8
  extend Forwardable
9
9
 
10
10
  def_delegators :@search,
11
- :has_css?, :has_xpath?, :include?, :text, :truncated_text, :size, :length, :[]
11
+ :has_css?, :has_xpath?, :include?, :text, :truncated_text, :size, :length, :css, :xpath, :[]
12
12
 
13
13
  def initialize(element, name, options: {}, siblings: [])
14
14
  @name = name
@@ -2,13 +2,15 @@
2
2
 
3
3
  module RSpecHTML
4
4
  module Matchers
5
- # Matches text within a given DOM element.
5
+ # Matches text within a given DOM element (strips HTML tags and compares text content only).
6
+ # (Deprecated in favour of `#match_text`.
6
7
  class ContainText
7
8
  include Base
8
9
 
9
10
  diffable
10
11
 
11
12
  def match(actual)
13
+ warn('[rspec-html] The `contain_text` matcher is deprecated. Use `match_text` instead.')
12
14
  @rspec_actual = actual&.text
13
15
  (actual&.text || '').include?(@expected.to_s)
14
16
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ module Matchers
5
+ # Matches text or regex within a given DOM element (strips HTML tags and compares text content only).
6
+ class MatchText
7
+ include Base
8
+
9
+ diffable
10
+
11
+ def match(actual)
12
+ @rspec_actual = actual&.text
13
+ return (actual&.text || '').include?(@expected.to_s) unless @expected.is_a?(Regexp)
14
+
15
+ @expected.match(actual&.text || '')
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,6 +3,7 @@
3
3
  require 'rspec_html/matchers/base'
4
4
  require 'rspec_html/matchers/contain_text'
5
5
  require 'rspec_html/matchers/contain_tag'
6
+ require 'rspec_html/matchers/match_text'
6
7
 
7
8
  module RSpecHTML
8
9
  # Provides matchers for identifying elements and text within a DOM element.
@@ -29,5 +30,6 @@ module RSpecHTML
29
30
 
30
31
  define_matcher(:contain_text, ContainText)
31
32
  define_matcher(:contain_tag, ContainTag)
33
+ define_matcher(:match_text, MatchText)
32
34
  end
33
35
  end
@@ -100,6 +100,7 @@ module RSpecHTML
100
100
  else
101
101
  where_xpath(tag, query)
102
102
  end
103
+ return nil unless matched || all
103
104
  return matched&.first unless all
104
105
 
105
106
  matched
data/lib/rspec_html.rb CHANGED
@@ -15,6 +15,7 @@ require 'rspec_html/matchers'
15
15
  module RSpecHTML
16
16
  class Error < StandardError; end
17
17
  class NoResponseError < Error; end
18
+
18
19
  def self.root
19
20
  Pathname.new(__dir__).parent
20
21
  end
data/rspec-html.gemspec CHANGED
@@ -28,16 +28,18 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = []
29
29
  spec.require_paths = ['lib']
30
30
 
31
+ spec.required_ruby_version = '>= 2.6'
31
32
  spec.add_dependency 'nokogiri', '~> 1.10'
32
33
  spec.add_dependency 'rspec', '~> 3.0'
33
34
 
34
35
  spec.add_development_dependency 'bundler', '~> 2.0'
35
- spec.add_development_dependency 'byebug', '~> 11.0'
36
- spec.add_development_dependency 'devpack', '~> 0.1.2'
36
+ spec.add_development_dependency 'devpack', '~> 0.4.0'
37
37
  spec.add_development_dependency 'i18n', '~> 1.7'
38
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.89.1'
41
- spec.add_development_dependency 'rubocop-rspec', '~> 1.36'
40
+ spec.add_development_dependency 'rubocop', '~> 1.29'
41
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
42
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.10'
42
43
  spec.add_development_dependency 'strong_versions', '~> 0.4.5'
44
+ spec.metadata['rubygems_mfa_required'] = 'true'
43
45
  end
@@ -0,0 +1 @@
1
+ match text <%= expected.inspect %>
@@ -0,0 +1,5 @@
1
+ <% unless actual.exist? %>
2
+ Expected <%= actual.reconstituted %> to match <%= expected.inspect %> but the element did not exist.
3
+ <% else %>
4
+ Expected text in <%= actual.reconstituted %> <%= (actual.truncated_text).inspect %> to match <%= expected.inspect %> but it did not.
5
+ <% 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.2.5
4
+ version: 0.2.8
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-09-01 00:00:00.000000000 Z
11
+ date: 2022-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -52,34 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
- - !ruby/object:Gem::Dependency
56
- name: byebug
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '11.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '11.0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: devpack
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 0.1.2
61
+ version: 0.4.0
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 0.1.2
68
+ version: 0.4.0
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: i18n
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -128,28 +114,42 @@ dependencies:
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: 0.89.1
117
+ version: '1.29'
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: 0.89.1
124
+ version: '1.29'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.6.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.6.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.36'
145
+ version: '2.10'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '1.36'
152
+ version: '2.10'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: strong_versions
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -192,14 +192,17 @@ files:
192
192
  - lib/rspec_html/matchers/base.rb
193
193
  - lib/rspec_html/matchers/contain_tag.rb
194
194
  - lib/rspec_html/matchers/contain_text.rb
195
+ - lib/rspec_html/matchers/match_text.rb
195
196
  - lib/rspec_html/reconstituted_element.rb
196
197
  - lib/rspec_html/search.rb
197
198
  - lib/rspec_html/tags.rb
198
199
  - rspec-html.gemspec
199
200
  - templates/description/contain_tag.erb
200
201
  - templates/description/contain_text.erb
202
+ - templates/description/match_text.erb
201
203
  - templates/failure/contain_tag.erb
202
204
  - templates/failure/contain_text.erb
205
+ - templates/failure/match_text.erb
203
206
  homepage: https://github.com/bobf/rspec-html
204
207
  licenses:
205
208
  - MIT
@@ -207,6 +210,7 @@ metadata:
207
210
  homepage_uri: https://github.com/bobf/rspec-html
208
211
  source_code_uri: https://github.com/bobf/rspec-html
209
212
  changelog_uri: https://github.com/bobf/rspec-html/blob/master/LICENSE
213
+ rubygems_mfa_required: 'true'
210
214
  post_install_message:
211
215
  rdoc_options: []
212
216
  require_paths:
@@ -215,14 +219,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
219
  requirements:
216
220
  - - ">="
217
221
  - !ruby/object:Gem::Version
218
- version: '0'
222
+ version: '2.6'
219
223
  required_rubygems_version: !ruby/object:Gem::Requirement
220
224
  requirements:
221
225
  - - ">="
222
226
  - !ruby/object:Gem::Version
223
227
  version: '0'
224
228
  requirements: []
225
- rubygems_version: 3.1.2
229
+ rubygems_version: 3.0.3.1
226
230
  signing_key:
227
231
  specification_version: 4
228
232
  summary: RSpec HTML