rspec-html-matchers 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +15 -12
- data/README.md +11 -15
- data/features/support/env.rb +16 -1
- data/lib/rspec-html-matchers.rb +6 -1
- data/lib/rspec-html-matchers/have_tag.rb +42 -7
- data/lib/rspec-html-matchers/version.rb +2 -4
- metadata +35 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9562deaafdea89229b40132a80f29ba68f3010738105688ba29ee42a245755e8
|
4
|
+
data.tar.gz: dd881bf03c6e5ab533eb9249d7d0450adf03ce7245f4e5ba430203cfbcb20b8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2abbd53202a5cd53d43e564fa4ea7d5663703d22d04af4dd7f9fdce45a3e3621a9766440968d686c879643e3035f1c4b537d107db631fa0961f968931155431f
|
7
|
+
data.tar.gz: b17d9eb26651fb25389e024009369fa6cea40f36f7c0c911c8775e92cb96629a947308aada13dd427c99a22a462680ead185f36d80896bcc13dbf8229f84ca37
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
0.9.2
|
5
|
+
-----
|
6
|
+
|
7
|
+
* fixed have_empty_tag matcher on jruby
|
8
|
+
* added ruby 2.7 to build matrix (no official support until stable release though)
|
9
|
+
* added ruby 2.6 to build matrix ([#70](https://github.com/kucaahbe/rspec-html-matchers/pull/70))
|
10
|
+
|
11
|
+
infrastructure/misc:
|
6
12
|
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
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!)
|
13
|
+
* 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))
|
14
|
+
* refactor travis-ci build setup
|
15
|
+
* updated status badges to SVG (thanks to [Olle Jonsson](https://github.com/olleolleolle): [#71](https://github.com/kucaahbe/rspec-html-matchers/pull/71))
|
13
16
|
|
14
17
|
0.9.1
|
15
18
|
-----
|
@@ -81,7 +84,7 @@ unreleased(TODO)
|
|
81
84
|
0.4.4
|
82
85
|
-----
|
83
86
|
|
84
|
-
* options for have_tag now support Regexp (thanks to [Ian C. Anderson](
|
87
|
+
* options for have_tag now support Regexp (thanks to [Ian C. Anderson](https://github.com/iancanderson))
|
85
88
|
|
86
89
|
0.4.3
|
87
90
|
-----
|
@@ -130,14 +133,14 @@ unreleased(TODO)
|
|
130
133
|
0.2.2
|
131
134
|
-----
|
132
135
|
|
133
|
-
* leading and trailing whitespaces are ignored in tags where they should be ignored(#11, and again thanks to [Simon Schoeters](
|
136
|
+
* leading and trailing whitespaces are ignored in tags where they should be ignored(#11, and again thanks to [Simon Schoeters](https://github.com/cimm))
|
134
137
|
* whitespaces ignoring as browser does in :text matching
|
135
138
|
* have_tag backwards compability(thanks to [Felix Tjandrawibawa](https://github.com/cemeng), #12)
|
136
139
|
|
137
140
|
0.2.1
|
138
141
|
-----
|
139
142
|
|
140
|
-
* make possible use non-string as :text option(#10, thanks for idea to [Simon Schoeters](
|
143
|
+
* make possible use non-string as :text option(#10, thanks for idea to [Simon Schoeters](https://github.com/cimm))
|
141
144
|
|
142
145
|
0.2.0
|
143
146
|
-----
|
@@ -156,7 +159,7 @@ unreleased(TODO)
|
|
156
159
|
0.0.6
|
157
160
|
-----
|
158
161
|
|
159
|
-
* allow for single quotes in content matchers (thanks to [Kelly Felkins](
|
162
|
+
* allow for single quotes in content matchers (thanks to [Kelly Felkins](https://github.com/kellyfelkins)).
|
160
163
|
|
161
164
|
0.0.5 (trial-trip)
|
162
165
|
------------------
|
data/README.md
CHANGED
@@ -1,20 +1,16 @@
|
|
1
|
-
rspec-html-matchers
|
2
|
-
===================
|
1
|
+
# rspec-html-matchers [![Gem Version](https://badge.fury.io/rb/rspec-html-matchers.svg)](https://badge.fury.io/rb/rspec-html-matchers) [![Build Status](https://travis-ci.com/kucaahbe/rspec-html-matchers.svg?branch=master)](https://travis-ci.com/kucaahbe/rspec-html-matchers)
|
3
2
|
|
4
3
|
[RSpec 3](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
|
-
[![Gem Version](https://badge.fury.io/rb/rspec-html-matchers.png)](http://badge.fury.io/rb/rspec-html-matchers)
|
7
|
-
[![Build Status](https://travis-ci.org/kucaahbe/rspec-html-matchers.png)](http://travis-ci.org/kucaahbe/rspec-html-matchers)
|
8
|
-
|
9
5
|
Goals
|
10
6
|
-----
|
11
7
|
|
12
8
|
* designed for testing **complex** html output. If you plan to perform simple matching, consider using:
|
13
|
-
* [assert_select](
|
9
|
+
* [assert_select](https://api.rubyonrails.org/classes/ActionDispatch/Assertions/SelectorAssertions.html#method-i-assert_select)
|
14
10
|
* [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](
|
11
|
+
* [matchers provided by capybara](https://rdoc.info/github/jnicklas/capybara/Capybara/Node/Matchers)
|
16
12
|
* developer-friendly output in error messages
|
17
|
-
* built on top of [nokogiri](
|
13
|
+
* built on top of [nokogiri](https://www.nokogiri.org/)
|
18
14
|
* has support for [capybara](https://github.com/jnicklas/capybara), see below
|
19
15
|
* syntax is similar to `have_tag` matcher from rspec-rails 1.x, but with own syntactic sugar
|
20
16
|
* framework agnostic, as input should be `String` (or capybara's page, see below)
|
@@ -55,7 +51,7 @@ Cucumber configuration:
|
|
55
51
|
World RSpecHtmlMatchers
|
56
52
|
```
|
57
53
|
|
58
|
-
as this gem requires **nokogiri**, here are [instructions for installing it](
|
54
|
+
as this gem requires **nokogiri**, here are [instructions for installing it](https://nokogiri.org/tutorials/installing_nokogiri.html).
|
59
55
|
|
60
56
|
Usage
|
61
57
|
-----
|
@@ -85,7 +81,7 @@ expect(rendered).to have_tag('form', :with => { :action => '/users', :method =>
|
|
85
81
|
end
|
86
82
|
```
|
87
83
|
|
88
|
-
Example above should be self-descriptive, if not, please refer to the [`have_tag`](
|
84
|
+
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
85
|
|
90
86
|
Input can be any html string. Let's take a look at these examples:
|
91
87
|
|
@@ -193,7 +189,7 @@ where `page` is an instance of Capybara::Session
|
|
193
189
|
- with\_date\_field
|
194
190
|
|
195
191
|
and of course you can use the `without_` matchers,
|
196
|
-
for more info take a look at [documentation](
|
192
|
+
for more info take a look at [documentation](https://www.rubydoc.info/gems/rspec-html-matchers/RSpecHtmlMatchers)
|
197
193
|
|
198
194
|
### rspec 1 partial backwards compatibility:
|
199
195
|
|
@@ -204,7 +200,7 @@ expect(response).to have_tag('div', 'expected content')
|
|
204
200
|
expect(response).to have_tag('div', /regexp matching expected content/)
|
205
201
|
```
|
206
202
|
|
207
|
-
[RSpec 1 `have_tag` documentation](
|
203
|
+
[RSpec 1 `have_tag` documentation](https://old.rspec.info/rails/writing/views.html)
|
208
204
|
|
209
205
|
Matching Tag Attributes
|
210
206
|
-----------------------
|
@@ -218,7 +214,7 @@ expect(index).to have_tag("img[alt!='']")
|
|
218
214
|
More info
|
219
215
|
---------
|
220
216
|
|
221
|
-
You can find more on [documentation](
|
217
|
+
You can find more on [documentation](https://www.rubydoc.info/gems/rspec-html-matchers/RSpecHtmlMatchers)
|
222
218
|
|
223
219
|
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.
|
224
220
|
|
@@ -234,8 +230,8 @@ Contribution
|
|
234
230
|
Contributors
|
235
231
|
============
|
236
232
|
|
237
|
-
- [Kelly Felkins](
|
238
|
-
- [Ryan Wilcox](
|
233
|
+
- [Kelly Felkins](https://github.com/kellyfelkins)
|
234
|
+
- [Ryan Wilcox](https://github.com/rwilcox)
|
239
235
|
- [Simon Schoeters](https://github.com/cimm)
|
240
236
|
- [Felix Tjandrawibawa](https://github.com/cemenghttps://github.com/cemeng)
|
241
237
|
- [Szymon Przybył](https://github.com/apocalyptiq)
|
data/features/support/env.rb
CHANGED
@@ -4,6 +4,8 @@ World(RSpec::Matchers)
|
|
4
4
|
require 'sinatra/base'
|
5
5
|
require 'capybara/cucumber'
|
6
6
|
require 'rspec-html-matchers'
|
7
|
+
require 'webdrivers'
|
8
|
+
require 'selenium-webdriver'
|
7
9
|
|
8
10
|
World RSpecHtmlMatchers
|
9
11
|
|
@@ -14,7 +16,20 @@ class SimpleApp < Sinatra::Base
|
|
14
16
|
set :public_folder, $ASSETS_DIR
|
15
17
|
end
|
16
18
|
|
17
|
-
Capybara.
|
19
|
+
Capybara.register_driver :headless_chrome do |app|
|
20
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
21
|
+
options.add_argument('--headless')
|
22
|
+
options.add_argument('--disable-gpu')
|
23
|
+
options.add_argument('--window-size=800,600')
|
24
|
+
|
25
|
+
Capybara::Selenium::Driver.new(app, :browser => :chrome, :options => options)
|
26
|
+
end
|
27
|
+
|
28
|
+
Capybara.configure do |config|
|
29
|
+
config.default_max_wait_time = 15 if config.respond_to? :default_max_wait_time=
|
30
|
+
config.default_driver = :headless_chrome
|
31
|
+
end
|
32
|
+
|
18
33
|
Capybara.app = SimpleApp
|
19
34
|
|
20
35
|
Before do
|
data/lib/rspec-html-matchers.rb
CHANGED
@@ -50,8 +50,13 @@ module RSpecHtmlMatchers
|
|
50
50
|
@__current_scope_for_nokogiri_matcher = HaveTag.new(tag, options, &block)
|
51
51
|
end
|
52
52
|
|
53
|
+
# tests whether tag have any content inside
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# expect('<div></div>').to have_empty_tag('div') # success
|
57
|
+
# expect('<div>hi</div>').to have_empty_tag('div') # fail
|
53
58
|
def have_empty_tag tag, options={}
|
54
|
-
have_tag(tag, options.merge(:
|
59
|
+
have_tag(tag, options.merge(:blank => true))
|
55
60
|
end
|
56
61
|
|
57
62
|
def with_text text
|
@@ -30,6 +30,9 @@ module RSpecHtmlMatchers
|
|
30
30
|
:expected_at_least => %Q|expected following:\n%s\nto have at least %i element(s) matching "%s", found %i.|,
|
31
31
|
:unexpected_at_least => %Q|expected following:\n%s\nto NOT have at least %i element(s) matching "%s", but found %i.|,
|
32
32
|
|
33
|
+
:expected_blank => %Q|expected following template to contain empty tag %s:\n%s|,
|
34
|
+
:unexpected_blank => %Q|expected following template to contain tag %s with other tags:\n%s|,
|
35
|
+
|
33
36
|
:expected_regexp => %Q|%s regexp expected within "%s" in following template:\n%s|,
|
34
37
|
:unexpected_regexp => %Q|%s regexp unexpected within "%s" in following template:\n%s\nbut was found.|,
|
35
38
|
|
@@ -80,13 +83,13 @@ module RSpecHtmlMatchers
|
|
80
83
|
@document = @parent_scope.to_html
|
81
84
|
end
|
82
85
|
@current_scope = begin
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if tag_presents? and
|
86
|
+
@parent_scope.css(@tag)
|
87
|
+
# on jruby this produce exception if css was not found:
|
88
|
+
# undefined method `decorate' for nil:NilClass
|
89
|
+
rescue NoMethodError
|
90
|
+
Nokogiri::XML::NodeSet.new(Nokogiri::XML::Document.new)
|
91
|
+
end
|
92
|
+
if tag_presents? and proper_content? and count_right?
|
90
93
|
@block.call(self) if @block
|
91
94
|
true
|
92
95
|
else
|
@@ -146,6 +149,30 @@ module RSpecHtmlMatchers
|
|
146
149
|
end
|
147
150
|
end
|
148
151
|
|
152
|
+
def proper_content?
|
153
|
+
if @options.key?(:blank)
|
154
|
+
maybe_empty?
|
155
|
+
else
|
156
|
+
text_right?
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def maybe_empty?
|
161
|
+
if @options[:blank]
|
162
|
+
@failure_message_when_negated = MESSAGES[:unexpected_blank] % [@tag, @document]
|
163
|
+
@failure_message = MESSAGES[:expected_blank] % [@tag, @document]
|
164
|
+
else
|
165
|
+
@failure_message_when_negated = MESSAGES[:expected_blank] % [@tag, @document]
|
166
|
+
@failure_message = MESSAGES[:unexpected_blank] % [@tag, @document]
|
167
|
+
end
|
168
|
+
|
169
|
+
if @options[:blank]
|
170
|
+
@current_scope.children.empty?
|
171
|
+
else
|
172
|
+
!@current_scope.children.empty?
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
149
176
|
def text_right?
|
150
177
|
return true unless @options[:text]
|
151
178
|
|
@@ -176,11 +203,19 @@ module RSpecHtmlMatchers
|
|
176
203
|
protected
|
177
204
|
|
178
205
|
def validate_options!
|
206
|
+
validate_text_options!
|
179
207
|
validate_count_presence!
|
180
208
|
validate_count_when_set_min_max!
|
181
209
|
validate_count_when_set_range!
|
182
210
|
end
|
183
211
|
|
212
|
+
def validate_text_options!
|
213
|
+
# TODO: test these options validations
|
214
|
+
if @options.key?(:blank)
|
215
|
+
raise ':text option is not accepted when :blank => true' if @options[:blank] && @options.key?(:text)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
184
219
|
def validate_count_presence!
|
185
220
|
raise 'wrong :count specified' unless [Range, NilClass].include?(@options[:count].class) or @options[:count].is_a?(Integer)
|
186
221
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-html-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kucaahbe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -45,21 +45,35 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: cucumber
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '1'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '1'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: capybara
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: sinatra
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - "~>"
|
@@ -73,47 +87,47 @@ dependencies:
|
|
73
87
|
- !ruby/object:Gem::Version
|
74
88
|
version: '1'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
90
|
+
name: selenium-webdriver
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
93
|
- - "~>"
|
80
94
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
95
|
+
version: '3'
|
82
96
|
type: :development
|
83
97
|
prerelease: false
|
84
98
|
version_requirements: !ruby/object:Gem::Requirement
|
85
99
|
requirements:
|
86
100
|
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
102
|
+
version: '3'
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
104
|
+
name: webdrivers
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
107
|
- - "~>"
|
94
108
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
109
|
+
version: '4'
|
96
110
|
type: :development
|
97
111
|
prerelease: false
|
98
112
|
version_requirements: !ruby/object:Gem::Requirement
|
99
113
|
requirements:
|
100
114
|
- - "~>"
|
101
115
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
116
|
+
version: '4'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
118
|
+
name: simplecov
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
106
120
|
requirements:
|
107
121
|
- - "~>"
|
108
122
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
123
|
+
version: '0'
|
110
124
|
type: :development
|
111
125
|
prerelease: false
|
112
126
|
version_requirements: !ruby/object:Gem::Requirement
|
113
127
|
requirements:
|
114
128
|
- - "~>"
|
115
129
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
130
|
+
version: '0'
|
117
131
|
- !ruby/object:Gem::Dependency
|
118
132
|
name: rake
|
119
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,7 +199,7 @@ files:
|
|
185
199
|
- spec/spec_helper.rb
|
186
200
|
- spec/support/asset_helpers.rb
|
187
201
|
- spec/support/raise_spec_error_helper.rb
|
188
|
-
homepage:
|
202
|
+
homepage: https://github.com/kucaahbe/rspec-html-matchers
|
189
203
|
licenses:
|
190
204
|
- MIT
|
191
205
|
metadata: {}
|
@@ -204,18 +218,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
218
|
- !ruby/object:Gem::Version
|
205
219
|
version: '0'
|
206
220
|
requirements: []
|
207
|
-
|
208
|
-
rubygems_version: 2.5.2
|
221
|
+
rubygems_version: 3.0.3
|
209
222
|
signing_key:
|
210
223
|
specification_version: 4
|
211
224
|
summary: Nokogiri based 'have_tag' and 'with_tag' matchers for rspec 3
|
212
225
|
test_files:
|
226
|
+
- spec/have_tag_spec.rb
|
227
|
+
- spec/support/asset_helpers.rb
|
228
|
+
- spec/support/raise_spec_error_helper.rb
|
213
229
|
- spec/spec_helper.rb
|
214
230
|
- spec/have_empty_tag_spec.rb
|
215
231
|
- spec/form_matchers_spec.rb
|
216
|
-
- spec/have_tag_spec.rb
|
217
|
-
- spec/support/raise_spec_error_helper.rb
|
218
|
-
- spec/support/asset_helpers.rb
|
219
|
-
- features/step_definitions/steps.rb
|
220
232
|
- features/support/env.rb
|
233
|
+
- features/step_definitions/steps.rb
|
221
234
|
- features/js_generated_content.feature
|