rspec-html-matchers 0.7.0 → 0.10.0
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 +5 -5
- data/CHANGELOG.md +79 -12
- data/README.md +63 -57
- data/features/step_definitions/steps.rb +3 -1
- data/features/support/env.rb +22 -3
- data/lib/rspec-html-matchers/have_tag.rb +290 -0
- data/lib/rspec-html-matchers/nokogiri_regexp_helper.rb +17 -0
- data/lib/rspec-html-matchers/nokogiri_text_helper.rb +24 -0
- data/lib/rspec-html-matchers/version.rb +5 -0
- data/lib/rspec-html-matchers.rb +167 -331
- data/spec/form_matchers_spec.rb +132 -130
- data/spec/have_empty_tag_spec.rb +31 -0
- data/spec/have_tag_spec.rb +281 -167
- data/spec/issues_spec.rb +17 -0
- data/spec/spec_helper.rb +5 -4
- data/spec/support/asset_helpers.rb +5 -5
- data/spec/support/raise_spec_error_helper.rb +9 -7
- metadata +74 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1240c0b682d8f66bf9058191105b0264804359ab93edc3217251ebd28c76b8c9
|
4
|
+
data.tar.gz: a287233a778683a27fb2a22dfa5f4947707f442826c6780b0554ec9061127100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce5b239fe81a0deae7783c2698f5eecd173e24c903c1248774d2a7143b10d9d0841c05f16c36761e6844aa2dc8fc9c877ffcfdfb490cacb1522dbb9bd727e796
|
7
|
+
data.tar.gz: 20f258033ce55b259f5ff97d054f2a151e50a7365bb44853047c10f171f0b9c6007aff944a01b015d5bd4f26cae9f556cafbf5e9e78db90887744e480cd48d94
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,82 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
0.10.0
|
5
|
+
------
|
6
|
+
|
7
|
+
* relax rspec dependecy upper limit
|
8
|
+
* add ruby 3.0 to test matrix
|
9
|
+
* add ruby 3.1 to test matrix
|
10
|
+
* remove 1.8 ruby from test matrix, this is the first step to remove it's support completely
|
11
|
+
|
12
|
+
0.9.4
|
13
|
+
-----
|
14
|
+
* html/body matching from now is forbidden ([#75](https://github.com/kucaahbe/rspec-html-matchers/pull/75))
|
15
|
+
* make ruby 2.7 possible to fail on CI
|
16
|
+
|
17
|
+
0.9.3
|
18
|
+
-----
|
19
|
+
* fix for :seen option ([#73](https://github.com/kucaahbe/rspec-html-matchers/issues/73))
|
20
|
+
* fix for html/body matching ([#62](https://github.com/kucaahbe/rspec-html-matchers/issues/62))
|
21
|
+
* a bit of linting and refactoring
|
22
|
+
|
23
|
+
0.9.2
|
24
|
+
-----
|
25
|
+
|
26
|
+
* fixed have_empty_tag matcher on jruby
|
27
|
+
* added ruby 2.7 to build matrix (no official support until stable release though)
|
28
|
+
* added ruby 2.6 to build matrix ([#70](https://github.com/kucaahbe/rspec-html-matchers/pull/70))
|
29
|
+
|
30
|
+
infrastructure/misc:
|
31
|
+
|
32
|
+
* migrated to travis-ci.com instead of travis-ci.org (thanks [Hamada Takayuki](https://github.com/hamadata) for inspiration: [#70](https://github.com/kucaahbe/rspec-html-matchers/pull/70))
|
33
|
+
* refactor travis-ci build setup
|
34
|
+
* updated status badges to SVG (thanks to [Olle Jonsson](https://github.com/olleolleolle): [#71](https://github.com/kucaahbe/rspec-html-matchers/pull/71))
|
35
|
+
|
36
|
+
0.9.1
|
37
|
+
-----
|
38
|
+
|
39
|
+
* re-added ruby support back to 1.8.7 (supporting same versions as rspec 3)
|
40
|
+
* split lib in few files
|
41
|
+
|
42
|
+
0.9.0
|
43
|
+
-----
|
44
|
+
|
45
|
+
* fixed `with_tag` nesting (thanks to [randoum](https://github.com/randoum): [#59](https://github.com/kucaahbe/rspec-html-matchers/pull/59))
|
46
|
+
* added ~> 2.4 ruby support
|
47
|
+
* removed ~> 2 ruby support
|
48
|
+
|
49
|
+
0.8.2
|
50
|
+
-----
|
51
|
+
|
52
|
+
* fixed README (thanks to [Rodrigo Castro](https://github.com/roooodcastro))
|
53
|
+
* fixed deep nesting (thanks to [Misha Gorodnitzky](https://github.com/misaka))
|
54
|
+
|
55
|
+
0.8.1
|
56
|
+
-----
|
57
|
+
|
58
|
+
* Rspec differ fix (thanks to [Misha Gorodnitzky](https://github.com/misaka))
|
59
|
+
|
60
|
+
0.8.0
|
61
|
+
-----
|
62
|
+
|
63
|
+
* "seen" text matching (thanks to [Alex Shi](https://github.com/hlcfan))
|
64
|
+
|
65
|
+
0.7.3
|
66
|
+
-----
|
67
|
+
|
68
|
+
* move license information into separate `LICENSE.md` file
|
69
|
+
|
70
|
+
0.7.2
|
71
|
+
-----
|
72
|
+
|
73
|
+
* add support for `frozen_string_literals`
|
74
|
+
* fix for rdoc links and not only
|
75
|
+
|
76
|
+
0.7.1
|
77
|
+
-----
|
6
78
|
|
7
|
-
*
|
8
|
-
* add ability to have_form('/url', 'PUT') or have_form('/url', :PUT)
|
9
|
-
* inteligent check comments(make sure it is not searching inside comments)
|
10
|
-
* shouldn't show all markup in error message if it is too big
|
11
|
-
* order matching
|
12
|
-
* improve documentation, add more usage examples (look at changelog and code!)
|
79
|
+
* become compatible with RSpec pre-release versions
|
13
80
|
|
14
81
|
0.7.0
|
15
82
|
-----
|
@@ -36,7 +103,7 @@ unreleased(TODO)
|
|
36
103
|
0.4.4
|
37
104
|
-----
|
38
105
|
|
39
|
-
* options for have_tag now support Regexp (thanks to [Ian C. Anderson](
|
106
|
+
* options for have_tag now support Regexp (thanks to [Ian C. Anderson](https://github.com/iancanderson))
|
40
107
|
|
41
108
|
0.4.3
|
42
109
|
-----
|
@@ -85,14 +152,14 @@ unreleased(TODO)
|
|
85
152
|
0.2.2
|
86
153
|
-----
|
87
154
|
|
88
|
-
* leading and trailing whitespaces are ignored in tags where they should be ignored(#11, and again thanks to [Simon Schoeters](
|
155
|
+
* leading and trailing whitespaces are ignored in tags where they should be ignored(#11, and again thanks to [Simon Schoeters](https://github.com/cimm))
|
89
156
|
* whitespaces ignoring as browser does in :text matching
|
90
157
|
* have_tag backwards compability(thanks to [Felix Tjandrawibawa](https://github.com/cemeng), #12)
|
91
158
|
|
92
159
|
0.2.1
|
93
160
|
-----
|
94
161
|
|
95
|
-
* make possible use non-string as :text option(#10, thanks for idea to [Simon Schoeters](
|
162
|
+
* make possible use non-string as :text option(#10, thanks for idea to [Simon Schoeters](https://github.com/cimm))
|
96
163
|
|
97
164
|
0.2.0
|
98
165
|
-----
|
@@ -111,7 +178,7 @@ unreleased(TODO)
|
|
111
178
|
0.0.6
|
112
179
|
-----
|
113
180
|
|
114
|
-
* allow for single quotes in content matchers (thanks to [Kelly Felkins](
|
181
|
+
* allow for single quotes in content matchers (thanks to [Kelly Felkins](https://github.com/kellyfelkins)).
|
115
182
|
|
116
183
|
0.0.5 (trial-trip)
|
117
184
|
------------------
|
data/README.md
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
rspec-html-matchers
|
2
|
-
===================
|
1
|
+
# rspec-html-matchers [](https://badge.fury.io/rb/rspec-html-matchers)
|
3
2
|
|
4
|
-
[RSpec
|
3
|
+
[RSpec](https://www.relishapp.com/rspec) matchers for testing your html (for [RSpec 2](https://www.relishapp.com/rspec/rspec-core/v/2-99/docs) use 0.5.x version).
|
5
4
|
|
6
|
-
[](https://github.com/kucaahbe/rspec-html-matchers/actions/workflows/rspec-mri.yml)
|
6
|
+
[](https://github.com/kucaahbe/rspec-html-matchers/actions/workflows/rspec-jruby.yml)
|
7
|
+
[](https://github.com/kucaahbe/rspec-html-matchers/actions/workflows/cucumber-mri.yml)
|
8
8
|
|
9
9
|
Goals
|
10
10
|
-----
|
11
11
|
|
12
|
-
* for testing **
|
13
|
-
* [assert_select](
|
12
|
+
* designed for testing **complex** html output. If you plan to perform simple matching, consider using:
|
13
|
+
* [assert_select](https://api.rubyonrails.org/classes/ActionDispatch/Assertions/SelectorAssertions.html#method-i-assert_select)
|
14
14
|
* [matchers provided out of the box in rspec-rails](https://www.relishapp.com/rspec/rspec-rails/v/2-11/docs/view-specs/view-spec)
|
15
|
-
* [matchers provided by capybara](
|
16
|
-
* developer-
|
17
|
-
* built on top of [nokogiri](nokogiri.org)
|
15
|
+
* [matchers provided by capybara](https://rdoc.info/github/jnicklas/capybara/Capybara/Node/Matchers)
|
16
|
+
* developer-friendly output in error messages
|
17
|
+
* built on top of [nokogiri](https://www.nokogiri.org/)
|
18
18
|
* has support for [capybara](https://github.com/jnicklas/capybara), see below
|
19
|
-
* syntax is similar to
|
20
|
-
* framework agnostic, as input should be String(or capybara's page, see below)
|
19
|
+
* syntax is similar to `have_tag` matcher from rspec-rails 1.x, but with own syntactic sugar
|
20
|
+
* framework agnostic, as input should be `String` (or capybara's page, see below)
|
21
21
|
|
22
22
|
Install
|
23
23
|
-------
|
@@ -28,7 +28,7 @@ Add to your Gemfile in the `:test` group:
|
|
28
28
|
gem 'rspec-html-matchers'
|
29
29
|
```
|
30
30
|
|
31
|
-
|
31
|
+
Include it in your RSpec configuration:
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
RSpec.configure do |config|
|
@@ -36,7 +36,7 @@ RSpec.configure do |config|
|
|
36
36
|
end
|
37
37
|
```
|
38
38
|
|
39
|
-
or just in
|
39
|
+
or just in your spec(s):
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
describe "my view spec" do
|
@@ -45,7 +45,6 @@ describe "my view spec" do
|
|
45
45
|
it "has tags" do
|
46
46
|
expect(rendered).to have_tag('div')
|
47
47
|
end
|
48
|
-
|
49
48
|
end
|
50
49
|
```
|
51
50
|
|
@@ -55,12 +54,12 @@ Cucumber configuration:
|
|
55
54
|
World RSpecHtmlMatchers
|
56
55
|
```
|
57
56
|
|
58
|
-
as this gem requires **nokogiri**, here [instructions for installing it](
|
57
|
+
as this gem requires **nokogiri**, here are [instructions for installing it](https://nokogiri.org/tutorials/installing_nokogiri.html).
|
59
58
|
|
60
59
|
Usage
|
61
60
|
-----
|
62
61
|
|
63
|
-
so
|
62
|
+
so perhaps your code produces following output:
|
64
63
|
|
65
64
|
```html
|
66
65
|
<h1>Simple Form</h1>
|
@@ -74,7 +73,7 @@ so perharps your code produces following output:
|
|
74
73
|
</form>
|
75
74
|
```
|
76
75
|
|
77
|
-
so you test it with following:
|
76
|
+
so you test it with the following:
|
78
77
|
|
79
78
|
```ruby
|
80
79
|
expect(rendered).to have_tag('form', :with => { :action => '/users', :method => 'post' }) do
|
@@ -85,9 +84,9 @@ expect(rendered).to have_tag('form', :with => { :action => '/users', :method =>
|
|
85
84
|
end
|
86
85
|
```
|
87
86
|
|
88
|
-
Example
|
87
|
+
Example above should be self-descriptive, if not, please refer to the [`have_tag`](https://www.rubydoc.info/gems/rspec-html-matchers/RSpecHtmlMatchers%3Ahave_tag) documentation
|
89
88
|
|
90
|
-
Input
|
89
|
+
Input can be any html string. Let's take a look at these examples:
|
91
90
|
|
92
91
|
* matching tags by css:
|
93
92
|
|
@@ -149,11 +148,19 @@ Input could be any html string. Let's take a look at these examples:
|
|
149
148
|
end
|
150
149
|
|
151
150
|
# mymock.text == 'Some content here'
|
152
|
-
expect('<p> Some content here</p>').to have_tag('p', :
|
151
|
+
expect('<p> Some content here</p>').to have_tag('p', :text => mymock.text)
|
153
152
|
# or
|
154
153
|
expect('<p> Some content here</p>').to have_tag('p') do
|
155
|
-
|
154
|
+
with_text mymock.text
|
156
155
|
end
|
156
|
+
|
157
|
+
# matching text content as it's seen by user:
|
158
|
+
rendered = <<HTML
|
159
|
+
<p>
|
160
|
+
content with ignored spaces around
|
161
|
+
</p>
|
162
|
+
HTML
|
163
|
+
expect(rendered).to have_tag('p', :seen => 'content with ignored spaces around')
|
157
164
|
```
|
158
165
|
|
159
166
|
* usage with capybara and cucumber:
|
@@ -166,25 +173,26 @@ where `page` is an instance of Capybara::Session
|
|
166
173
|
|
167
174
|
* also included shorthand matchers for form inputs:
|
168
175
|
|
169
|
-
-
|
170
|
-
-
|
171
|
-
-
|
172
|
-
-
|
173
|
-
-
|
174
|
-
-
|
175
|
-
-
|
176
|
-
-
|
177
|
-
-
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
-
|
183
|
-
-
|
184
|
-
-
|
185
|
-
-
|
186
|
-
|
187
|
-
and of course you can use the `without_` matchers
|
176
|
+
- have\_form
|
177
|
+
- with\_checkbox
|
178
|
+
- with\_email\_field
|
179
|
+
- with\_file\_field
|
180
|
+
- with\_hidden\_field
|
181
|
+
- with\_option
|
182
|
+
- with\_password\_field
|
183
|
+
- with\_radio\_button
|
184
|
+
- with\_button
|
185
|
+
- with\_select
|
186
|
+
- with\_submit
|
187
|
+
- with\_text\_area
|
188
|
+
- with\_text\_field
|
189
|
+
- with\_url\_field
|
190
|
+
- with\_number\_field
|
191
|
+
- with\_range\_field
|
192
|
+
- with\_date\_field
|
193
|
+
|
194
|
+
and of course you can use the `without_` matchers,
|
195
|
+
for more info take a look at [documentation](https://www.rubydoc.info/gems/rspec-html-matchers/RSpecHtmlMatchers)
|
188
196
|
|
189
197
|
### rspec 1 partial backwards compatibility:
|
190
198
|
|
@@ -195,14 +203,23 @@ expect(response).to have_tag('div', 'expected content')
|
|
195
203
|
expect(response).to have_tag('div', /regexp matching expected content/)
|
196
204
|
```
|
197
205
|
|
198
|
-
[RSpec 1 `have_tag` documentation](
|
206
|
+
[RSpec 1 `have_tag` documentation](https://old.rspec.info/rails/writing/views.html)
|
207
|
+
|
208
|
+
Matching Tag Attributes
|
209
|
+
-----------------------
|
210
|
+
|
211
|
+
You can also match the content of attributes by using selectors. For example, to ensure an `img` tag has an `alt` attribute, you can match:
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
expect(index).to have_tag("img[alt!='']")
|
215
|
+
```
|
199
216
|
|
200
217
|
More info
|
201
218
|
---------
|
202
219
|
|
203
|
-
You can find more on [
|
220
|
+
You can find more on [documentation](https://www.rubydoc.info/gems/rspec-html-matchers/RSpecHtmlMatchers)
|
204
221
|
|
205
|
-
Also, please read [CHANGELOG](https://github.com/kucaahbe/rspec-html-matchers/blob/master/CHANGELOG.md),
|
222
|
+
Also, please read [CHANGELOG](https://github.com/kucaahbe/rspec-html-matchers/blob/master/CHANGELOG.md) and [issues](https://github.com/kucaahbe/rspec-html-matchers/issues), might be helpful.
|
206
223
|
|
207
224
|
Contribution
|
208
225
|
============
|
@@ -216,21 +233,10 @@ Contribution
|
|
216
233
|
Contributors
|
217
234
|
============
|
218
235
|
|
219
|
-
- [Kelly Felkins](
|
220
|
-
- [Ryan Wilcox](
|
236
|
+
- [Kelly Felkins](https://github.com/kellyfelkins)
|
237
|
+
- [Ryan Wilcox](https://github.com/rwilcox)
|
221
238
|
- [Simon Schoeters](https://github.com/cimm)
|
222
239
|
- [Felix Tjandrawibawa](https://github.com/cemenghttps://github.com/cemeng)
|
223
240
|
- [Szymon Przybył](https://github.com/apocalyptiq)
|
224
241
|
- [Manuel Meurer](https://github.com/manuelmeurer)
|
225
242
|
- [Andreas Riemer](https://github.com/arfl)
|
226
|
-
|
227
|
-
MIT Licensed
|
228
|
-
============
|
229
|
-
|
230
|
-
Copyright (c) 2011-2014 Dmitrij Mjakotnyi
|
231
|
-
|
232
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
233
|
-
|
234
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
235
|
-
|
236
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/features/support/env.rb
CHANGED
@@ -1,20 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# setup rspec matchers
|
2
4
|
require 'rspec/expectations'
|
3
5
|
World(RSpec::Matchers)
|
4
6
|
require 'sinatra/base'
|
5
7
|
require 'capybara/cucumber'
|
6
8
|
require 'rspec-html-matchers'
|
9
|
+
require 'webdrivers'
|
10
|
+
require 'selenium-webdriver'
|
7
11
|
|
8
12
|
World RSpecHtmlMatchers
|
9
13
|
|
10
|
-
|
11
|
-
$
|
14
|
+
# rubocop:disable Style/GlobalVars
|
15
|
+
$ASSETS_DIR = File.expand_path('../tmp', __FILE__)
|
16
|
+
$INDEX_HTML = File.join($ASSETS_DIR, 'index.html')
|
12
17
|
|
13
18
|
class SimpleApp < Sinatra::Base
|
14
19
|
set :public_folder, $ASSETS_DIR
|
15
20
|
end
|
16
21
|
|
17
|
-
Capybara.
|
22
|
+
Capybara.register_driver :headless_chrome do |app|
|
23
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
24
|
+
options.add_argument('--headless')
|
25
|
+
options.add_argument('--disable-gpu')
|
26
|
+
options.add_argument('--window-size=800,600')
|
27
|
+
|
28
|
+
Capybara::Selenium::Driver.new(app, :browser => :chrome, :options => options)
|
29
|
+
end
|
30
|
+
|
31
|
+
Capybara.configure do |config|
|
32
|
+
config.default_max_wait_time = 15 if config.respond_to? :default_max_wait_time=
|
33
|
+
config.default_driver = :headless_chrome
|
34
|
+
end
|
35
|
+
|
18
36
|
Capybara.app = SimpleApp
|
19
37
|
|
20
38
|
Before do
|
@@ -24,3 +42,4 @@ end
|
|
24
42
|
After do
|
25
43
|
FileUtils.rm_rf $ASSETS_DIR
|
26
44
|
end
|
45
|
+
# rubocop:enable Style/GlobalVars
|