rspec-html-matchers 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/lib/rspec-html-matchers.rb +62 -25
- data/spec/have_tag_spec.rb +73 -8
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17c280c0fd064492e078852526a508bd84e6caca
|
4
|
+
data.tar.gz: 83887d4b20b714cfb7456b079960e3df4f3c5d53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8abf7a4a88eb220f105603e528e4b75c7807caa1e3174a20e0c689276b484153c9724d810a5042beb71a9812681e97a04641a457f27d0078c2ac0c9dc309ade6
|
7
|
+
data.tar.gz: 784db376e190ad1f85d1bd181e3db36fe9dcdace86d516b906ce79f637abddc6800ab762225b83216506fe69d32f061fe787b70b029f4b50cb4f250054acfb5b
|
data/CHANGELOG.md
CHANGED
@@ -11,6 +11,19 @@ unreleased(TODO)
|
|
11
11
|
* order matching
|
12
12
|
* improve documentation, add more usage examples (look at changelog and code!)
|
13
13
|
|
14
|
+
0.9.0
|
15
|
+
-----
|
16
|
+
|
17
|
+
* fixed `with\_tag` nesting (thanks to [randoum](https://github.com/randoum): [#59](https://github.com/kucaahbe/rspec-html-matchers/pull/59))
|
18
|
+
* added ~> 2.4 ruby support
|
19
|
+
* removed ~> 2 ruby support
|
20
|
+
|
21
|
+
0.8.2
|
22
|
+
-----
|
23
|
+
|
24
|
+
* fixed README (thanks to [Rodrigo Castro](https://github.com/roooodcastro))
|
25
|
+
* fixed deep nesting (thanks to [Misha Gorodnitzky](https://github.com/misaka))
|
26
|
+
|
14
27
|
0.8.1
|
15
28
|
-----
|
16
29
|
|
data/README.md
CHANGED
@@ -152,7 +152,7 @@ Input can be any html string. Let's take a look at these examples:
|
|
152
152
|
expect('<p> Some content here</p>').to have_tag('p', :text => mymock.text)
|
153
153
|
# or
|
154
154
|
expect('<p> Some content here</p>').to have_tag('p') do
|
155
|
-
|
155
|
+
with_text mymock.text
|
156
156
|
end
|
157
157
|
|
158
158
|
# matching text content as it's seen by user:
|
data/lib/rspec-html-matchers.rb
CHANGED
@@ -108,29 +108,31 @@ module RSpecHtmlMatchers
|
|
108
108
|
|
109
109
|
case document
|
110
110
|
when String
|
111
|
-
@parent_scope =
|
111
|
+
@parent_scope = Nokogiri::HTML(document)
|
112
112
|
@document = document
|
113
113
|
else
|
114
114
|
@parent_scope = document.current_scope
|
115
|
-
@current_scope = begin
|
116
|
-
document.parent_scope.css(@tag)
|
117
|
-
# on jruby this produce exception if css was not found:
|
118
|
-
# undefined method `decorate' for nil:NilClass
|
119
|
-
rescue NoMethodError
|
120
|
-
Nokogiri::XML::NodeSet.new(Nokogiri::XML::Document.new)
|
121
|
-
end
|
122
115
|
@document = @parent_scope.to_html
|
123
116
|
end
|
124
|
-
|
117
|
+
@current_scope = begin
|
118
|
+
@parent_scope.css(@tag)
|
119
|
+
# on jruby this produce exception if css was not found:
|
120
|
+
# undefined method `decorate' for nil:NilClass
|
121
|
+
rescue NoMethodError
|
122
|
+
Nokogiri::XML::NodeSet.new(Nokogiri::XML::Document.new)
|
123
|
+
end
|
125
124
|
if tag_presents? and text_right? and count_right?
|
126
|
-
@
|
127
|
-
@block.call if @block
|
125
|
+
@block.call(self) if @block
|
128
126
|
true
|
129
127
|
else
|
130
128
|
false
|
131
129
|
end
|
132
130
|
end
|
133
131
|
|
132
|
+
def document
|
133
|
+
@document
|
134
|
+
end
|
135
|
+
|
134
136
|
def description
|
135
137
|
# TODO should it be more complicated?
|
136
138
|
if @options.has_key?(:count)
|
@@ -309,14 +311,18 @@ module RSpecHtmlMatchers
|
|
309
311
|
raise StandardError, 'this matcher should be used inside "have_tag" matcher block' unless defined?(@__current_scope_for_nokogiri_matcher)
|
310
312
|
raise ArgumentError, 'this matcher does not accept block' if block_given?
|
311
313
|
tag = @__current_scope_for_nokogiri_matcher.instance_variable_get(:@tag)
|
312
|
-
|
314
|
+
within_nested_tag do
|
315
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, :text => text)
|
316
|
+
end
|
313
317
|
end
|
314
318
|
|
315
319
|
def without_text text
|
316
320
|
raise StandardError, 'this matcher should be used inside "have_tag" matcher block' unless defined?(@__current_scope_for_nokogiri_matcher)
|
317
321
|
raise ArgumentError, 'this matcher does not accept block' if block_given?
|
318
322
|
tag = @__current_scope_for_nokogiri_matcher.instance_variable_get(:@tag)
|
319
|
-
|
323
|
+
within_nested_tag do
|
324
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, :text => text)
|
325
|
+
end
|
320
326
|
end
|
321
327
|
alias :but_without_text :without_text
|
322
328
|
|
@@ -325,7 +331,9 @@ module RSpecHtmlMatchers
|
|
325
331
|
# @see #have_tag
|
326
332
|
# @note this should be used within block of have_tag matcher
|
327
333
|
def with_tag tag, options={}, &block
|
328
|
-
|
334
|
+
within_nested_tag do
|
335
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, options, &block)
|
336
|
+
end
|
329
337
|
end
|
330
338
|
|
331
339
|
# without_tag matcher
|
@@ -333,7 +341,9 @@ module RSpecHtmlMatchers
|
|
333
341
|
# @see #have_tag
|
334
342
|
# @note this should be used within block of have_tag matcher
|
335
343
|
def without_tag tag, options={}, &block
|
336
|
-
|
344
|
+
within_nested_tag do
|
345
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, options, &block)
|
346
|
+
end
|
337
347
|
end
|
338
348
|
|
339
349
|
# form assertion
|
@@ -458,14 +468,18 @@ module RSpecHtmlMatchers
|
|
458
468
|
# TODO, should be: with_text_area name, text=nil
|
459
469
|
#options = form_tag_options('text',name,value)
|
460
470
|
options = { :with => { :name => name } }
|
461
|
-
|
471
|
+
within_nested_tag do
|
472
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag('textarea', options)
|
473
|
+
end
|
462
474
|
end
|
463
475
|
|
464
476
|
def without_text_area name
|
465
477
|
# TODO, should be: without_text_area name, text=nil
|
466
478
|
#options = form_tag_options('text',name,value)
|
467
479
|
options = { :with => { :name => name } }
|
468
|
-
|
480
|
+
within_nested_tag do
|
481
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag('textarea', options)
|
482
|
+
end
|
469
483
|
end
|
470
484
|
|
471
485
|
def with_checkbox name, value=nil
|
@@ -493,7 +507,9 @@ module RSpecHtmlMatchers
|
|
493
507
|
id = options[:with].delete(:id)
|
494
508
|
tag='select'; tag += '#'+id if id
|
495
509
|
options[:with].merge!(:name => name)
|
496
|
-
|
510
|
+
within_nested_tag do
|
511
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, options, &block)
|
512
|
+
end
|
497
513
|
end
|
498
514
|
|
499
515
|
def without_select name, options={}, &block
|
@@ -501,7 +517,9 @@ module RSpecHtmlMatchers
|
|
501
517
|
id = options[:with].delete(:id)
|
502
518
|
tag='select'; tag += '#'+id if id
|
503
519
|
options[:with].merge!(:name => name)
|
504
|
-
|
520
|
+
within_nested_tag do
|
521
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, options, &block)
|
522
|
+
end
|
505
523
|
end
|
506
524
|
|
507
525
|
def with_option text, value=nil, options={}
|
@@ -517,7 +535,9 @@ module RSpecHtmlMatchers
|
|
517
535
|
end
|
518
536
|
options.delete(:selected)
|
519
537
|
options.merge!(:text => text) if text
|
520
|
-
|
538
|
+
within_nested_tag do
|
539
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, options)
|
540
|
+
end
|
521
541
|
end
|
522
542
|
|
523
543
|
def without_option text, value=nil, options={}
|
@@ -533,7 +553,9 @@ module RSpecHtmlMatchers
|
|
533
553
|
end
|
534
554
|
options.delete(:selected)
|
535
555
|
options.merge!(:text => text) if text
|
536
|
-
|
556
|
+
within_nested_tag do
|
557
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, options)
|
558
|
+
end
|
537
559
|
end
|
538
560
|
|
539
561
|
def with_button text, value=nil, options={}
|
@@ -544,7 +566,9 @@ module RSpecHtmlMatchers
|
|
544
566
|
end
|
545
567
|
options[:with].merge!(:value => value.to_s) if value
|
546
568
|
options.merge!(:text => text) if text
|
547
|
-
|
569
|
+
within_nested_tag do
|
570
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag('button', options)
|
571
|
+
end
|
548
572
|
end
|
549
573
|
|
550
574
|
def without_button text, value=nil, options={}
|
@@ -555,7 +579,9 @@ module RSpecHtmlMatchers
|
|
555
579
|
end
|
556
580
|
options[:with].merge!(:value => value.to_s) if value
|
557
581
|
options.merge!(:text => text) if text
|
558
|
-
|
582
|
+
within_nested_tag do
|
583
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag('button', options)
|
584
|
+
end
|
559
585
|
end
|
560
586
|
|
561
587
|
def with_submit value
|
@@ -573,11 +599,15 @@ module RSpecHtmlMatchers
|
|
573
599
|
private
|
574
600
|
|
575
601
|
def should_have_input(options)
|
576
|
-
|
602
|
+
within_nested_tag do
|
603
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag('input', options)
|
604
|
+
end
|
577
605
|
end
|
578
606
|
|
579
607
|
def should_not_have_input(options)
|
580
|
-
|
608
|
+
within_nested_tag do
|
609
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag('input', options)
|
610
|
+
end
|
581
611
|
end
|
582
612
|
|
583
613
|
# form_tag in method name name mean smth. like input, submit, tags that should appear in a form
|
@@ -588,4 +618,11 @@ module RSpecHtmlMatchers
|
|
588
618
|
return options
|
589
619
|
end
|
590
620
|
|
621
|
+
def within_nested_tag(&block)
|
622
|
+
raise 'block needed' unless block_given?
|
623
|
+
parent_scope = @__current_scope_for_nokogiri_matcher
|
624
|
+
block.call
|
625
|
+
@__current_scope_for_nokogiri_matcher = parent_scope
|
626
|
+
end
|
627
|
+
|
591
628
|
end
|
data/spec/have_tag_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# encoding:
|
1
|
+
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'have_tag' do
|
@@ -463,7 +463,7 @@ describe 'have_tag' do
|
|
463
463
|
with_text 'SAMPLE text'
|
464
464
|
end
|
465
465
|
}.to raise_spec_error(
|
466
|
-
|
466
|
+
/"SAMPLE text" expected within "div" in following template:/
|
467
467
|
)
|
468
468
|
|
469
469
|
expect {
|
@@ -471,7 +471,7 @@ describe 'have_tag' do
|
|
471
471
|
with_text /SAMPLE tekzt/i
|
472
472
|
end
|
473
473
|
}.to raise_spec_error(
|
474
|
-
%
|
474
|
+
%r{/SAMPLE tekzt/i regexp expected within "div" in following template:}
|
475
475
|
)
|
476
476
|
end
|
477
477
|
|
@@ -481,7 +481,7 @@ describe 'have_tag' do
|
|
481
481
|
without_text 'sample text'
|
482
482
|
end
|
483
483
|
}.to raise_spec_error(
|
484
|
-
%
|
484
|
+
%r{"sample text" unexpected within "div" in following template:}
|
485
485
|
)
|
486
486
|
|
487
487
|
expect {
|
@@ -489,7 +489,7 @@ describe 'have_tag' do
|
|
489
489
|
without_text /SAMPLE text/i
|
490
490
|
end
|
491
491
|
}.to raise_spec_error(
|
492
|
-
%
|
492
|
+
%r{/SAMPLE text/i regexp unexpected within "div" in following template:}
|
493
493
|
)
|
494
494
|
end
|
495
495
|
|
@@ -578,15 +578,80 @@ describe 'have_tag' do
|
|
578
578
|
|
579
579
|
expect {
|
580
580
|
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('div') }
|
581
|
-
}.to raise_spec_error(/
|
581
|
+
}.to raise_spec_error(/to have at least 1 element matching "div", found 0/)
|
582
582
|
|
583
583
|
expect {
|
584
584
|
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :count => 10) }
|
585
|
-
}.to raise_spec_error(/
|
585
|
+
}.to raise_spec_error(/to have 10 element\(s\) matching "li", found 3/)
|
586
586
|
|
587
587
|
expect {
|
588
588
|
expect(rendered).to have_tag('ol') { with_tag('li'); with_tag('li', :text => /SAMPLE text/i) }
|
589
|
-
}.to raise_spec_error(/\/SAMPLE text\/i regexp expected within "li"
|
589
|
+
}.to raise_spec_error(/\/SAMPLE text\/i regexp expected within "li"/)
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
context "deep nesting" do
|
594
|
+
asset 'multiple_lists'
|
595
|
+
|
596
|
+
it "should allow deep nesting" do
|
597
|
+
expect(rendered).to have_tag('div') do
|
598
|
+
with_tag 'ul.numeric' do
|
599
|
+
with_tag 'li#one'
|
600
|
+
end
|
601
|
+
end
|
602
|
+
end
|
603
|
+
|
604
|
+
it "should clear context between nested tags" do
|
605
|
+
expect(rendered).to have_tag('div') do |div|
|
606
|
+
expect(div).to have_tag 'ul.numeric'
|
607
|
+
expect(div).to have_tag 'ul.alpha'
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
it "should narrow context when deep nesting" do
|
612
|
+
expect do
|
613
|
+
expect(rendered).to have_tag('div') do |div|
|
614
|
+
expect(div).to have_tag 'ul.numeric' do |ul_numeric|
|
615
|
+
expect(ul_numeric).to have_tag 'li#aye'
|
616
|
+
end
|
617
|
+
end
|
618
|
+
end .to raise_spec_error(/at least 1 element matching "li#aye", found 0/)
|
619
|
+
end
|
620
|
+
|
621
|
+
it "should narrow context for with_text" do
|
622
|
+
expect do
|
623
|
+
expect(rendered).to have_tag('div') do |div|
|
624
|
+
expect(div).to have_tag 'ul.numeric' do
|
625
|
+
with_text 'A'
|
626
|
+
end
|
627
|
+
end
|
628
|
+
end .to raise_spec_error(/"A" expected within "ul.numeric"/)
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
context 'find nested tags' do
|
633
|
+
asset 'nested_matchers'
|
634
|
+
|
635
|
+
it 'with block parameters' do
|
636
|
+
expect(rendered).to have_tag('div#one') do |a|
|
637
|
+
expect(a).to have_tag 'p.find_me', count: 2
|
638
|
+
|
639
|
+
expect(a).to have_tag 'b.nested', count: 3
|
640
|
+
expect(a).to have_tag('p.deep-nesting', count: 1) do |b|
|
641
|
+
expect(b).to have_tag 'b.nested', count: 2
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
it 'with short_hand methods' do
|
647
|
+
expect(rendered).to have_tag('div#one') do
|
648
|
+
with_tag 'p.find_me', count: 2
|
649
|
+
|
650
|
+
with_tag 'b.nested', count: 3
|
651
|
+
with_tag('p.deep-nesting', count: 1) do
|
652
|
+
with_tag 'b.nested', count: 2
|
653
|
+
end
|
654
|
+
end
|
590
655
|
end
|
591
656
|
end
|
592
657
|
|
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.
|
4
|
+
version: 0.9.0
|
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: 2017-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -192,15 +192,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
192
|
requirements:
|
193
193
|
- - ">="
|
194
194
|
- !ruby/object:Gem::Version
|
195
|
-
version: '
|
195
|
+
version: '2.1'
|
196
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
197
|
requirements:
|
198
198
|
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
|
-
rubyforge_project:
|
203
|
-
rubygems_version: 2.
|
202
|
+
rubyforge_project:
|
203
|
+
rubygems_version: 2.6.8
|
204
204
|
signing_key:
|
205
205
|
specification_version: 4
|
206
206
|
summary: Nokogiri based 'have_tag' and 'with_tag' matchers for rspec 3
|
@@ -214,4 +214,3 @@ test_files:
|
|
214
214
|
- features/step_definitions/steps.rb
|
215
215
|
- features/support/env.rb
|
216
216
|
- features/js_generated_content.feature
|
217
|
-
has_rdoc:
|