rspec-html-matchers 0.7.1 → 0.7.2
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/CHANGELOG.md +6 -0
- data/README.md +25 -24
- data/lib/rspec-html-matchers.rb +18 -11
- data/spec/have_empty_tag_spec.rb +29 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be58541a3ca3493891f55b4edfb8d92aeec1bb70
|
4
|
+
data.tar.gz: 6496944bc83e1fde56b17327e42bebaf95f2e926
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31cf7e98ae6ce59d5a01c9ebf18aa4f142d1d87840c07baeb4ec6663f2d2caa95a740d542a2b2034e53e0a773a5011cb8645adcb4e56bb4bbca9eb001d1de4bd
|
7
|
+
data.tar.gz: b1d6768ffd9475d0aded6f7205a5aa8ff377eb01b6963c826c81853419c86558d7190c805902074c7349aebb4397160f42925b20d221d76ca9936afc04b9128e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -14,9 +14,9 @@ Goals
|
|
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
15
|
* [matchers provided by capybara](http://rdoc.info/github/jnicklas/capybara/Capybara/Node/Matchers)
|
16
16
|
* developer-firendly output in error messages
|
17
|
-
* built on top of [nokogiri](nokogiri.org)
|
17
|
+
* built on top of [nokogiri](http://www.nokogiri.org/)
|
18
18
|
* has support for [capybara](https://github.com/jnicklas/capybara), see below
|
19
|
-
* syntax is similar to
|
19
|
+
* syntax is similar to have_tag matcher from rspec-rails 1.x, but with own syntactic sugar
|
20
20
|
* framework agnostic, as input should be String(or capybara's page, see below)
|
21
21
|
|
22
22
|
Install
|
@@ -85,7 +85,7 @@ expect(rendered).to have_tag('form', :with => { :action => '/users', :method =>
|
|
85
85
|
end
|
86
86
|
```
|
87
87
|
|
88
|
-
Example about should be self-descriptive,
|
88
|
+
Example about should be self-descriptive, if not, please refer to [have_tag](http://www.rubydoc.info/gems/rspec-html-matchers/RSpecHtmlMatchers%3Ahave_tag) documentation
|
89
89
|
|
90
90
|
Input could be any html string. Let's take a look at these examples:
|
91
91
|
|
@@ -166,25 +166,26 @@ where `page` is an instance of Capybara::Session
|
|
166
166
|
|
167
167
|
* also included shorthand matchers for form inputs:
|
168
168
|
|
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
|
169
|
+
- have\_form
|
170
|
+
- with\_checkbox
|
171
|
+
- with\_email\_field
|
172
|
+
- with\_file\_field
|
173
|
+
- with\_hidden\_field
|
174
|
+
- with\_option
|
175
|
+
- with\_password\_field
|
176
|
+
- with\_radio\_button
|
177
|
+
- with\_button
|
178
|
+
- with\_select
|
179
|
+
- with\_submit
|
180
|
+
- with\_text\_area
|
181
|
+
- with\_text\_field
|
182
|
+
- with\_url\_field
|
183
|
+
- with\_number\_field
|
184
|
+
- with\_range\_field
|
185
|
+
- with\_date\_field
|
186
|
+
|
187
|
+
and of course you can use the `without_` matchers,
|
188
|
+
for more info take a look at [documentation](http://www.rubydoc.info/gems/rspec-html-matchers/RSpecHtmlMatchers)
|
188
189
|
|
189
190
|
### rspec 1 partial backwards compatibility:
|
190
191
|
|
@@ -200,9 +201,9 @@ expect(response).to have_tag('div', /regexp matching expected content/)
|
|
200
201
|
More info
|
201
202
|
---------
|
202
203
|
|
203
|
-
You can find more on [
|
204
|
+
You can find more on [documentation](http://www.rubydoc.info/gems/rspec-html-matchers/RSpecHtmlMatchers)
|
204
205
|
|
205
|
-
Also, please read [CHANGELOG](https://github.com/kucaahbe/rspec-html-matchers/blob/master/CHANGELOG.md),
|
206
|
+
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
207
|
|
207
208
|
Contribution
|
208
209
|
============
|
data/lib/rspec-html-matchers.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: UTF-8
|
2
3
|
require 'rspec'
|
3
4
|
require 'nokogiri'
|
@@ -79,18 +80,18 @@ module RSpecHtmlMatchers
|
|
79
80
|
|
80
81
|
if with_attrs = @options.delete(:with)
|
81
82
|
if classes = with_attrs.delete(:class)
|
82
|
-
@tag
|
83
|
+
@tag += '.' + classes_to_selector(classes)
|
83
84
|
end
|
84
85
|
selector = with_attrs.inject('') do |html_attrs_string, (k, v)|
|
85
|
-
html_attrs_string
|
86
|
+
html_attrs_string += "[#{k}='#{v}']"
|
86
87
|
html_attrs_string
|
87
88
|
end
|
88
|
-
@tag
|
89
|
+
@tag += selector
|
89
90
|
end
|
90
91
|
|
91
92
|
if without_attrs = @options.delete(:without)
|
92
93
|
if classes = without_attrs.delete(:class)
|
93
|
-
@tag
|
94
|
+
@tag += ":not(.#{classes_to_selector(classes)})"
|
94
95
|
end
|
95
96
|
end
|
96
97
|
|
@@ -275,6 +276,10 @@ module RSpecHtmlMatchers
|
|
275
276
|
@__current_scope_for_nokogiri_matcher = HaveTag.new(tag, options, &block)
|
276
277
|
end
|
277
278
|
|
279
|
+
def have_empty_tag tag, options={}
|
280
|
+
have_tag(tag, options.merge(text: ""))
|
281
|
+
end
|
282
|
+
|
278
283
|
def with_text text
|
279
284
|
raise StandardError, 'this matcher should be used inside "have_tag" matcher block' unless defined?(@__current_scope_for_nokogiri_matcher)
|
280
285
|
raise ArgumentError, 'this matcher does not accept block' if block_given?
|
@@ -315,13 +320,13 @@ module RSpecHtmlMatchers
|
|
315
320
|
def have_form action_url, method, options={}, &block
|
316
321
|
options[:with] ||= {}
|
317
322
|
id = options[:with].delete(:id)
|
318
|
-
tag = 'form'; tag
|
323
|
+
tag = 'form'; tag += '#'+id if id
|
319
324
|
options[:with].merge!(:action => action_url)
|
320
325
|
options[:with].merge!(:method => method.to_s)
|
321
326
|
have_tag tag, options, &block
|
322
327
|
end
|
323
328
|
|
324
|
-
|
329
|
+
#@TODO fix code duplications
|
325
330
|
|
326
331
|
def with_hidden_field name, value=nil
|
327
332
|
options = form_tag_options('hidden',name,value)
|
@@ -403,8 +408,8 @@ module RSpecHtmlMatchers
|
|
403
408
|
should_not_have_input(options)
|
404
409
|
end
|
405
410
|
|
406
|
-
# TODO add ability to explicitly say that value should be empty
|
407
411
|
def with_password_field name, value=nil
|
412
|
+
# TODO add ability to explicitly say that value should be empty
|
408
413
|
options = form_tag_options('password',name,value)
|
409
414
|
should_have_input(options)
|
410
415
|
end
|
@@ -424,13 +429,15 @@ module RSpecHtmlMatchers
|
|
424
429
|
should_not_have_input(options)
|
425
430
|
end
|
426
431
|
|
427
|
-
def with_text_area name
|
432
|
+
def with_text_area name
|
433
|
+
# TODO, should be: with_text_area name, text=nil
|
428
434
|
#options = form_tag_options('text',name,value)
|
429
435
|
options = { :with => { :name => name } }
|
430
436
|
expect(@__current_scope_for_nokogiri_matcher).to have_tag('textarea', options)
|
431
437
|
end
|
432
438
|
|
433
|
-
def without_text_area name
|
439
|
+
def without_text_area name
|
440
|
+
# TODO, should be: without_text_area name, text=nil
|
434
441
|
#options = form_tag_options('text',name,value)
|
435
442
|
options = { :with => { :name => name } }
|
436
443
|
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag('textarea', options)
|
@@ -459,7 +466,7 @@ module RSpecHtmlMatchers
|
|
459
466
|
def with_select name, options={}, &block
|
460
467
|
options[:with] ||= {}
|
461
468
|
id = options[:with].delete(:id)
|
462
|
-
tag='select'; tag
|
469
|
+
tag='select'; tag += '#'+id if id
|
463
470
|
options[:with].merge!(:name => name)
|
464
471
|
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, options, &block)
|
465
472
|
end
|
@@ -467,7 +474,7 @@ module RSpecHtmlMatchers
|
|
467
474
|
def without_select name, options={}, &block
|
468
475
|
options[:with] ||= {}
|
469
476
|
id = options[:with].delete(:id)
|
470
|
-
tag='select'; tag
|
477
|
+
tag='select'; tag += '#'+id if id
|
471
478
|
options[:with].merge!(:name => name)
|
472
479
|
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, options, &block)
|
473
480
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'have_empty_tag' do
|
5
|
+
context 'when single element' do
|
6
|
+
asset 'single_element'
|
7
|
+
|
8
|
+
it { expect(rendered).to have_empty_tag('div') }
|
9
|
+
it { expect(rendered).to have_empty_tag('div', class: "foo") }
|
10
|
+
it { expect(rendered).to have_empty_tag('div', class: "bar") }
|
11
|
+
it { expect(rendered).to have_empty_tag('div', class: "foo bar") }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when paragraphs' do
|
15
|
+
asset 'paragraphs'
|
16
|
+
|
17
|
+
it { expect(rendered).to_not have_empty_tag('p') }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when ordered list' do
|
21
|
+
asset 'ordered_list'
|
22
|
+
|
23
|
+
it { expect(rendered).to_not have_empty_tag('html') }
|
24
|
+
it { expect(rendered).to_not have_empty_tag('body') }
|
25
|
+
it { expect(rendered).to_not have_empty_tag('ol') }
|
26
|
+
it { expect(rendered).to_not have_empty_tag('ol', class: 'menu') }
|
27
|
+
it { expect(rendered).to_not have_empty_tag('li') }
|
28
|
+
end
|
29
|
+
end
|
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.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kucaahbe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -142,6 +142,20 @@ dependencies:
|
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '1'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: yard
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
145
159
|
description: 'Nokogiri based ''have_tag'' and ''with_tag'' matchers for rspec 3. Does
|
146
160
|
not depend on assert_select matcher, provides useful error messages.
|
147
161
|
|
@@ -161,6 +175,7 @@ files:
|
|
161
175
|
- features/support/env.rb
|
162
176
|
- lib/rspec-html-matchers.rb
|
163
177
|
- spec/form_matchers_spec.rb
|
178
|
+
- spec/have_empty_tag_spec.rb
|
164
179
|
- spec/have_tag_spec.rb
|
165
180
|
- spec/spec_helper.rb
|
166
181
|
- spec/support/asset_helpers.rb
|
@@ -191,6 +206,7 @@ specification_version: 4
|
|
191
206
|
summary: Nokogiri based 'have_tag' and 'with_tag' matchers for rspec 3
|
192
207
|
test_files:
|
193
208
|
- spec/form_matchers_spec.rb
|
209
|
+
- spec/have_empty_tag_spec.rb
|
194
210
|
- spec/have_tag_spec.rb
|
195
211
|
- spec/spec_helper.rb
|
196
212
|
- spec/support/asset_helpers.rb
|
@@ -198,3 +214,4 @@ test_files:
|
|
198
214
|
- features/step_definitions/steps.rb
|
199
215
|
- features/support/env.rb
|
200
216
|
- features/js_generated_content.feature
|
217
|
+
has_rdoc:
|