rspec-html-matchers 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/rspec-html-matchers/have_tag.rb +17 -1
- data/lib/rspec-html-matchers/version.rb +1 -1
- data/spec/form_matchers_spec.rb +18 -18
- data/spec/have_empty_tag_spec.rb +3 -3
- data/spec/have_tag_spec.rb +62 -14
- data/spec/issues_spec.rb +1 -11
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c80050c4efaf8917fde81c8f5b139f846731b679f1a9001fec4a3e49690451b3
|
4
|
+
data.tar.gz: bc7e5523735f253a51fff1055e364f1189d7daa5dcedacf388612c4a57889e5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2febc5b59c123bd2e9232aecfb7839a047f29dbd0b30c0958378523bc04f3c119ad60923a7535def8c2748bb5f92793b47707a9db16ff864dc20696f7e8985d0
|
7
|
+
data.tar.gz: 38c6bf3867215196fd61a4877f8cabbd6bade0dc66ae4ae1edb00945b9d0ac6deecdbcdc0101530255347f6647c1e619f540a4cfe3fb6ca84d807fbf735b7ac6
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
0.9.4
|
5
|
+
-----
|
6
|
+
* html/body matching from now is forbidden ([#75](https://github.com/kucaahbe/rspec-html-matchers/pull/75))
|
7
|
+
* make ruby 2.7 possible to fail on CI
|
8
|
+
|
9
|
+
0.9.3
|
10
|
+
-----
|
11
|
+
* fix for :seen option ([#73](https://github.com/kucaahbe/rspec-html-matchers/issues/73))
|
12
|
+
* fix for html/body matching ([#62](https://github.com/kucaahbe/rspec-html-matchers/issues/62))
|
13
|
+
* a bit of linting and refactoring
|
14
|
+
|
4
15
|
0.9.2
|
5
16
|
-----
|
6
17
|
|
@@ -79,7 +79,7 @@ module RSpecHtmlMatchers
|
|
79
79
|
|
80
80
|
case src
|
81
81
|
when String
|
82
|
-
parent_scope = Nokogiri::HTML
|
82
|
+
parent_scope = Nokogiri::HTML(src)
|
83
83
|
@document = src
|
84
84
|
else
|
85
85
|
parent_scope = src.current_scope
|
@@ -207,12 +207,28 @@ module RSpecHtmlMatchers
|
|
207
207
|
end
|
208
208
|
|
209
209
|
def validate_options!
|
210
|
+
validate_html_body_tags!
|
210
211
|
validate_text_options!
|
211
212
|
validate_count_presence!
|
212
213
|
validate_count_when_set_min_max!
|
213
214
|
validate_count_when_set_range!
|
214
215
|
end
|
215
216
|
|
217
|
+
# here is a demo:
|
218
|
+
# irb(main):009:0> Nokogiri::HTML('<p>asd</p>').xpath('//html')
|
219
|
+
# => [#<Nokogiri::XML::Element:0x3fea02cd3f58 name="html" children=[#<Nokogiri::XML::Element:0x3fea02cd37c4 name="body" children=[#<Nokogiri::XML::Element:0x3fea02cd34e0 name="p" children=[#<Nokogiri::XML::Text:0x3fea02cd3134 "asd">]>]>]>]
|
220
|
+
# irb(main):010:0> Nokogiri::HTML('<p>asd</p>').xpath('//body')
|
221
|
+
# => [#<Nokogiri::XML::Element:0x3fea02ce3df4 name="body" children=[#<Nokogiri::XML::Element:0x3fea02ce3a70 name="p" children=[#<Nokogiri::XML::Text:0x3fea02ce350c "asd">]>]>]
|
222
|
+
# irb(main):011:0> Nokogiri::HTML('<p>asd</p>').xpath('//p')
|
223
|
+
# => [#<Nokogiri::XML::Element:0x3fea02cf3754 name="p" children=[#<Nokogiri::XML::Text:0x3fea02cf2f98 "asd">]>]
|
224
|
+
# irb(main):012:0> Nokogiri::HTML('<p>asd</p>').xpath('//a')
|
225
|
+
# => []
|
226
|
+
def validate_html_body_tags!
|
227
|
+
if %w[html body].include?(tag) && options.empty?
|
228
|
+
raise ArgumentError, 'matching <html> and <body> tags without specifying additional options does not work, see: https://github.com/kucaahbe/rspec-html-matchers/pull/75'
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
216
232
|
def validate_text_options!
|
217
233
|
# TODO: test these options validations
|
218
234
|
if options.key?(:blank) && options[:blank] && options.key?(:text) # rubocop:disable Style/GuardClause, Style/IfUnlessModifier
|
data/spec/form_matchers_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
describe 'have_form' do
|
6
6
|
asset 'form'
|
7
7
|
|
8
|
-
context 'without &block' do
|
8
|
+
context '[without &block]' do
|
9
9
|
it 'should find form' do
|
10
10
|
# sanity check
|
11
11
|
expect(rendered).to have_form('/books', :post)
|
@@ -18,8 +18,8 @@ describe 'have_form' do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
context 'with &block' do
|
22
|
-
context 'with_select' do
|
21
|
+
context '[with &block]' do
|
22
|
+
context '[with_select]' do
|
23
23
|
it 'should find select' do
|
24
24
|
expect(rendered).to have_form('/books', :post) do
|
25
25
|
with_select('book[publisher_id]', :with => { :id => 'book_publisher_id' })
|
@@ -34,7 +34,7 @@ describe 'have_form' do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
context 'with_option' do
|
37
|
+
context '[with_option]' do
|
38
38
|
it 'should find options' do
|
39
39
|
expect(rendered).to have_form('/books', :post) do
|
40
40
|
with_select('book[publisher_id]') do
|
@@ -57,7 +57,7 @@ describe 'have_form' do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
context 'with_button' do
|
60
|
+
context '[with_button]' do
|
61
61
|
it 'should find button' do
|
62
62
|
expect(rendered).to have_form('/books', :post) do
|
63
63
|
with_button('Cancel Book')
|
@@ -72,7 +72,7 @@ describe 'have_form' do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context 'with_hidden_field' do
|
75
|
+
context '[with_hidden_field]' do
|
76
76
|
it 'should find hidden field' do
|
77
77
|
expect(rendered).to have_form('/books', :post) do
|
78
78
|
with_hidden_field('authenticity_token')
|
@@ -88,7 +88,7 @@ describe 'have_form' do
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
context 'with_text_field' do
|
91
|
+
context '[with_text_field]' do
|
92
92
|
it 'should find text field' do
|
93
93
|
expect(rendered).to have_form('/books', :post) do
|
94
94
|
with_text_field('book[title]')
|
@@ -106,7 +106,7 @@ describe 'have_form' do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
context 'with_email_field' do
|
109
|
+
context '[with_email_field]' do
|
110
110
|
it 'should find email field' do
|
111
111
|
expect(rendered).to have_form('/books', :post) do
|
112
112
|
with_email_field('user[email]')
|
@@ -124,7 +124,7 @@ describe 'have_form' do
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
context 'with_url_field' do
|
127
|
+
context '[with_url_field]' do
|
128
128
|
it 'should find url field' do
|
129
129
|
expect(rendered).to have_form('/books', :post) do
|
130
130
|
with_url_field('user[url]')
|
@@ -141,7 +141,7 @@ describe 'have_form' do
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
-
context 'with_number_field' do
|
144
|
+
context '[with_number_field]' do
|
145
145
|
it 'should find number field' do
|
146
146
|
expect(rendered).to have_form('/books', :post) do
|
147
147
|
with_number_field('number')
|
@@ -160,7 +160,7 @@ describe 'have_form' do
|
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
-
context 'with_range_field' do
|
163
|
+
context '[with_range_field]' do
|
164
164
|
it 'should find range field' do
|
165
165
|
expect(rendered).to have_form('/books', :post) do
|
166
166
|
with_range_field('range1', 1, 3)
|
@@ -179,7 +179,7 @@ describe 'have_form' do
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
context 'with_date_field' do
|
182
|
+
context '[with_date_field]' do
|
183
183
|
it 'should find date field' do
|
184
184
|
expect(rendered).to have_form('/books', :post) do
|
185
185
|
with_date_field(:date)
|
@@ -213,7 +213,7 @@ describe 'have_form' do
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
-
context 'with_password_field' do
|
216
|
+
context '[with_password_field]' do
|
217
217
|
it 'should find password field' do
|
218
218
|
expect(rendered).to have_form('/books', :post) do
|
219
219
|
with_password_field('user[password]')
|
@@ -227,7 +227,7 @@ describe 'have_form' do
|
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
230
|
-
context 'with_file_field' do
|
230
|
+
context '[with_file_field]' do
|
231
231
|
it 'should find file field' do
|
232
232
|
expect(rendered).to have_form('/books', :post) do
|
233
233
|
with_file_field('form[file]')
|
@@ -241,7 +241,7 @@ describe 'have_form' do
|
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
244
|
-
context 'with_text_area' do
|
244
|
+
context '[with_text_area]' do
|
245
245
|
it 'should find text area' do
|
246
246
|
expect(rendered).to have_form('/books', :post) do
|
247
247
|
with_text_area('book[description]')
|
@@ -255,7 +255,7 @@ describe 'have_form' do
|
|
255
255
|
end
|
256
256
|
end
|
257
257
|
|
258
|
-
context 'with_check_box' do
|
258
|
+
context '[with_check_box]' do
|
259
259
|
it 'should find check box' do
|
260
260
|
expect(rendered).to have_form('/books', :post) do
|
261
261
|
with_checkbox('book[still_in_print]')
|
@@ -271,7 +271,7 @@ describe 'have_form' do
|
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
274
|
-
context 'with_radio_button' do
|
274
|
+
context '[with_radio_button]' do
|
275
275
|
it 'should find radio button' do
|
276
276
|
expect(rendered).to have_form('/books', :post) do
|
277
277
|
with_radio_button('form[name]', 'true')
|
@@ -286,7 +286,7 @@ describe 'have_form' do
|
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
|
-
context 'with_submit' do
|
289
|
+
context '[with_submit]' do
|
290
290
|
it 'should find submit' do
|
291
291
|
expect(rendered).to have_form('/books', :post) do
|
292
292
|
with_submit('Create Book')
|
data/spec/have_empty_tag_spec.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'spec_helper'
|
5
5
|
|
6
6
|
describe 'have_empty_tag' do
|
7
|
-
context '
|
7
|
+
context '[single element]' do
|
8
8
|
asset 'single_element'
|
9
9
|
|
10
10
|
it { expect(rendered).to have_empty_tag('div') }
|
@@ -13,13 +13,13 @@ describe 'have_empty_tag' do
|
|
13
13
|
it { expect(rendered).to have_empty_tag('div', :class => 'foo bar') }
|
14
14
|
end
|
15
15
|
|
16
|
-
context '
|
16
|
+
context '[paragraphs]' do
|
17
17
|
asset 'paragraphs'
|
18
18
|
|
19
19
|
it { expect(rendered).to_not have_empty_tag('p') }
|
20
20
|
end
|
21
21
|
|
22
|
-
context '
|
22
|
+
context '[ordered list]' do
|
23
23
|
asset 'ordered_list'
|
24
24
|
|
25
25
|
it { expect(rendered).to_not have_empty_tag('html') }
|
data/spec/have_tag_spec.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'spec_helper'
|
5
5
|
|
6
6
|
describe 'have_tag' do
|
7
|
-
context 'through css selector' do
|
7
|
+
context '[through css selector]' do
|
8
8
|
asset 'search_and_submit'
|
9
9
|
|
10
10
|
it 'should have right description' do
|
@@ -65,7 +65,7 @@ describe 'have_tag' do
|
|
65
65
|
)
|
66
66
|
end
|
67
67
|
|
68
|
-
context 'with additional HTML attributes(:with option)' do
|
68
|
+
context '[with additional HTML attributes(:with option)]' do
|
69
69
|
it 'should find tags' do
|
70
70
|
expect(rendered).to have_tag('input#search', :with => { :type => 'text' })
|
71
71
|
expect(rendered).to have_tag(:input, :with => { :type => 'submit', :value => 'Save' })
|
@@ -115,7 +115,7 @@ describe 'have_tag' do
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
context 'with additional HTML attributes (:without option)' do
|
118
|
+
context '[with additional HTML attributes (:without option)]' do
|
119
119
|
asset 'single_element'
|
120
120
|
|
121
121
|
it 'should find tags that have classes specified via array (or string)' do
|
@@ -133,7 +133,7 @@ describe 'have_tag' do
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
context 'by count' do
|
136
|
+
context '[by count]' do
|
137
137
|
asset 'paragraphs'
|
138
138
|
|
139
139
|
it 'should have right description' do
|
@@ -279,10 +279,10 @@ describe 'have_tag' do
|
|
279
279
|
end
|
280
280
|
end
|
281
281
|
|
282
|
-
context 'with :text/:seen specified' do
|
282
|
+
context '[with :text/:seen specified]' do
|
283
283
|
asset 'quotes'
|
284
284
|
|
285
|
-
context 'using standard syntax' do
|
285
|
+
context '[using standard syntax]' do
|
286
286
|
it 'should find tags' do
|
287
287
|
expect(rendered).to have_tag('div', :text => 'sample text')
|
288
288
|
expect(rendered).to have_tag('p', :text => 'one')
|
@@ -358,7 +358,7 @@ describe 'have_tag' do
|
|
358
358
|
end
|
359
359
|
end
|
360
360
|
|
361
|
-
context 'using alternative syntax(with_text/without_text)' do
|
361
|
+
context '[using alternative syntax(with_text/without_text)]' do
|
362
362
|
it 'should raise exception when used outside any other tag matcher' do
|
363
363
|
expect {
|
364
364
|
with_text 'sample text'
|
@@ -494,7 +494,7 @@ describe 'have_tag' do
|
|
494
494
|
end
|
495
495
|
end
|
496
496
|
|
497
|
-
context 'mixed matching' do
|
497
|
+
context '[mixed matching]' do
|
498
498
|
asset 'special'
|
499
499
|
|
500
500
|
it 'should find tags by count and exact content' do
|
@@ -535,7 +535,7 @@ describe 'have_tag' do
|
|
535
535
|
end
|
536
536
|
end
|
537
537
|
|
538
|
-
context 'nested matching
|
538
|
+
context '[nested matching]' do
|
539
539
|
asset 'ordered_list'
|
540
540
|
|
541
541
|
it 'should find tags' do
|
@@ -585,7 +585,7 @@ describe 'have_tag' do
|
|
585
585
|
end
|
586
586
|
end
|
587
587
|
|
588
|
-
context 'deep nesting' do
|
588
|
+
context '[deep nesting]' do
|
589
589
|
asset 'multiple_lists'
|
590
590
|
|
591
591
|
it 'should allow deep nesting' do
|
@@ -624,7 +624,7 @@ describe 'have_tag' do
|
|
624
624
|
end
|
625
625
|
end
|
626
626
|
|
627
|
-
context 'find nested tags' do
|
627
|
+
context '[find nested tags]' do
|
628
628
|
asset 'nested_matchers'
|
629
629
|
|
630
630
|
it 'with block parameters' do
|
@@ -650,16 +650,16 @@ describe 'have_tag' do
|
|
650
650
|
end
|
651
651
|
end
|
652
652
|
|
653
|
-
context 'backwards compatibility for unnamed arguments' do
|
653
|
+
context '[backwards compatibility for unnamed arguments]' do
|
654
654
|
asset 'quotes'
|
655
655
|
|
656
|
-
context 'string as second argument' do
|
656
|
+
context '[string as second argument]' do
|
657
657
|
it 'should map a string argument to :text => string' do
|
658
658
|
expect(rendered).to have_tag('div', 'sample text')
|
659
659
|
end
|
660
660
|
end
|
661
661
|
|
662
|
-
context 'Regexp as second argument' do
|
662
|
+
context '[Regexp as second argument]' do
|
663
663
|
it 'should match against a valid Regexp' do
|
664
664
|
expect(rendered).to have_tag('div', /sample\s/)
|
665
665
|
end
|
@@ -669,4 +669,52 @@ describe 'have_tag' do
|
|
669
669
|
end
|
670
670
|
end
|
671
671
|
end
|
672
|
+
|
673
|
+
context '[html and body elements]' do
|
674
|
+
asset 'document'
|
675
|
+
|
676
|
+
context '[matching attributes]' do
|
677
|
+
it 'should find the html element with specified attributes' do
|
678
|
+
expect(rendered).to have_tag('html', :class => 'nojs')
|
679
|
+
end
|
680
|
+
|
681
|
+
it 'should find the body element with specified attributes' do
|
682
|
+
expect(rendered).to have_tag('body', :class => 'container')
|
683
|
+
end
|
684
|
+
|
685
|
+
it 'should not find the html element with specified attributes' do
|
686
|
+
expect(rendered).to have_tag('html', :class => 'nonexistent')
|
687
|
+
end
|
688
|
+
|
689
|
+
it 'should not find the body element with specified attributes' do
|
690
|
+
expect(rendered).to have_tag('body', :class => 'nonexistent')
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
694
|
+
context '[quirk: when no attributes specified, match is not intended to work]' do
|
695
|
+
it '<html> positive match should raise error' do
|
696
|
+
expect {
|
697
|
+
expect(rendered).to have_tag('html')
|
698
|
+
}.to raise_error(ArgumentError)
|
699
|
+
end
|
700
|
+
|
701
|
+
it '<html> negative match should raise error' do
|
702
|
+
expect {
|
703
|
+
expect(rendered).to_not have_tag('html')
|
704
|
+
}.to raise_error(ArgumentError)
|
705
|
+
end
|
706
|
+
|
707
|
+
it '<body> positive match should raise error' do
|
708
|
+
expect {
|
709
|
+
expect(rendered).to have_tag('body')
|
710
|
+
}.to raise_error(ArgumentError)
|
711
|
+
end
|
712
|
+
|
713
|
+
it '<body> negative match should raise error' do
|
714
|
+
expect {
|
715
|
+
expect(rendered).to_not have_tag('body')
|
716
|
+
}.to raise_error(ArgumentError)
|
717
|
+
end
|
718
|
+
end
|
719
|
+
end
|
672
720
|
end
|
data/spec/issues_spec.rb
CHANGED
@@ -4,17 +4,7 @@
|
|
4
4
|
require 'spec_helper'
|
5
5
|
|
6
6
|
describe 'working on github issues' do
|
7
|
-
|
8
|
-
it 'should not have html tag' do
|
9
|
-
expect('<p>My paragraph.</p>').not_to have_tag('html')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should not have body tag' do
|
13
|
-
expect('<p>My paragraph.</p>').not_to have_tag('body')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it '#73' do # https://github.com/kucaahbe/rspec-html-matchers/issues/73
|
7
|
+
it '[seen Option Not Matching Seen Text (https://github.com/kucaahbe/rspec-html-matchers/issues/73)]' do
|
18
8
|
rendered = <<HTML
|
19
9
|
<p>
|
20
10
|
content with ignored
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kucaahbe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -187,7 +187,7 @@ dependencies:
|
|
187
187
|
description: 'Nokogiri based ''have_tag'' and ''with_tag'' matchers for rspec 3. Does
|
188
188
|
not depend on assert_select matcher, provides useful error messages.
|
189
189
|
|
190
|
-
'
|
190
|
+
'
|
191
191
|
email:
|
192
192
|
- kucaahbe@ukr.net
|
193
193
|
- randoum@gmail.com
|
@@ -233,17 +233,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
233
|
- !ruby/object:Gem::Version
|
234
234
|
version: '0'
|
235
235
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
236
|
+
rubygems_version: 3.0.6
|
237
237
|
signing_key:
|
238
238
|
specification_version: 4
|
239
239
|
summary: Nokogiri based 'have_tag' and 'with_tag' matchers for rspec 3
|
240
240
|
test_files:
|
241
|
-
- spec/support/raise_spec_error_helper.rb
|
242
|
-
- spec/support/asset_helpers.rb
|
243
|
-
- spec/have_empty_tag_spec.rb
|
244
241
|
- spec/form_matchers_spec.rb
|
245
242
|
- spec/spec_helper.rb
|
243
|
+
- spec/have_empty_tag_spec.rb
|
246
244
|
- spec/issues_spec.rb
|
245
|
+
- spec/support/raise_spec_error_helper.rb
|
246
|
+
- spec/support/asset_helpers.rb
|
247
247
|
- spec/have_tag_spec.rb
|
248
248
|
- features/support/env.rb
|
249
249
|
- features/step_definitions/steps.rb
|