rspec-html-matchers 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +12 -3
- data/README.md +61 -22
- data/lib/rspec-html-matchers.rb +16 -5
- data/rspec-html-matchers.gemspec +1 -1
- data/spec/matchers/have_tag_spec.rb +10 -0
- metadata +31 -19
data/CHANGELOG.md
CHANGED
@@ -5,15 +5,24 @@ unreleased(TODO)
|
|
5
5
|
----------------
|
6
6
|
|
7
7
|
* improve documentation(look at changelog and code!)
|
8
|
-
* add
|
9
|
-
|
8
|
+
* add :without to have\_tag? like have_tag('div', :without => { :class => 'test' })
|
9
|
+
|
10
|
+
0.2.4
|
11
|
+
-----
|
12
|
+
|
13
|
+
* added simple #description method for "it { should have_tag }" cases
|
14
|
+
|
15
|
+
0.2.3
|
16
|
+
-----
|
17
|
+
|
18
|
+
* fix for unicode text matching (issue #13)
|
10
19
|
|
11
20
|
0.2.2
|
12
21
|
-----
|
13
22
|
|
14
23
|
* leading and trailing whitespaces are ignored in tags where they should be ignored(#11, and again thanks to [Simon Schoeters](http://github.com/cimm))
|
15
24
|
* whitespaces ignoring as browser does in :text matching
|
16
|
-
* have_tag backwards compability(thanks to [Felix Tjandrawibawa](https://github.com/
|
25
|
+
* have_tag backwards compability(thanks to [Felix Tjandrawibawa](https://github.com/cemeng), #12)
|
17
26
|
|
18
27
|
0.2.1
|
19
28
|
-----
|
data/README.md
CHANGED
@@ -20,9 +20,11 @@ Install
|
|
20
20
|
|
21
21
|
Add to your Gemfile (in the :test group :) ):
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
```ruby
|
24
|
+
group :test do
|
25
|
+
gem 'rspec-html-matchers'
|
26
|
+
end
|
27
|
+
```
|
26
28
|
|
27
29
|
Instructions for [installing Nokogiri](http://nokogiri.org/tutorials/installing_nokogiri.html).
|
28
30
|
|
@@ -31,24 +33,61 @@ Usage
|
|
31
33
|
|
32
34
|
Simple example:
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
36
|
+
```ruby
|
37
|
+
view=<<-HTML
|
38
|
+
<h1>Simple Form</h1>
|
39
|
+
<form action="/users" method="post">
|
40
|
+
<p>
|
41
|
+
<input type="email" name="user[email]" />
|
42
|
+
</p>
|
43
|
+
<p>
|
44
|
+
<input type="submit" id="special_submit" />
|
45
|
+
</p>
|
46
|
+
</form>
|
47
|
+
HTML
|
48
|
+
|
49
|
+
view.should have_tag('form', :with => { :action => '/users', :method => 'post' }) do
|
50
|
+
with_tag "input", :with => { :name => "user[email]", :type => 'email' }
|
51
|
+
with_tag "input#special_submit", :count => 1
|
52
|
+
without_tag "h1", :text => 'unneeded tag'
|
53
|
+
without_tag "p", :text => /content/i
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Examples with more description:
|
58
|
+
|
59
|
+
* tag matching (matches one or more tags):
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
'<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag('p')
|
63
|
+
'<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag(:p)
|
64
|
+
'<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag('p#qwerty')
|
65
|
+
'<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag('p.qwe.rty')
|
66
|
+
|
67
|
+
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.should have_tag('p strong')
|
68
|
+
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.should have_tag('p#qwerty strong')
|
69
|
+
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.should have_tag('p.qwe.rty strong')
|
70
|
+
# or
|
71
|
+
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.should have_tag('p') do
|
72
|
+
with_tag('strong')
|
73
|
+
end
|
74
|
+
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.should have_tag('p#qwerty') do
|
75
|
+
with_tag('strong')
|
76
|
+
end
|
77
|
+
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.should have_tag('p.qwe.rty') do
|
78
|
+
with_tag('strong')
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
* special case: classes matching:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
# all of this are equivalent:
|
86
|
+
'<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag('p', :with => { :class => 'qwe rty' })
|
87
|
+
'<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag('p', :with => { :class => 'rty qwe' })
|
88
|
+
'<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag('p', :with => { :class => ['rty', 'qwe'] })
|
89
|
+
'<p class="qwe rty" id="qwerty">Paragraph</p>'.should have_tag('p', :with => { :class => ['qwe', 'rty'] })
|
90
|
+
```
|
52
91
|
|
53
92
|
Also included special matchers for form inputs:
|
54
93
|
-----------------------------------------------
|
@@ -100,7 +139,7 @@ Contributors
|
|
100
139
|
MIT Licensed
|
101
140
|
============
|
102
141
|
|
103
|
-
Copyright (c) 2011
|
142
|
+
Copyright (c) 2011-2012 Dmitrij Mjakotnyi
|
104
143
|
|
105
144
|
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:
|
106
145
|
|
data/lib/rspec-html-matchers.rb
CHANGED
@@ -10,9 +10,11 @@ module RSpec
|
|
10
10
|
attr_reader :failure_message, :negative_failure_message
|
11
11
|
attr_reader :parent_scope, :current_scope
|
12
12
|
|
13
|
-
|
13
|
+
TAG_FOUND_DESC = %Q|have at least 1 element matching "%s"|
|
14
|
+
TAG_NOT_FOUND_MSG = %Q|expected following:\n%s\nto #{TAG_FOUND_DESC}, found 0.|
|
14
15
|
TAG_FOUND_MSG = %Q|expected following:\n%s\nto NOT have element matching "%s", found %s.|
|
15
|
-
|
16
|
+
COUNT_DESC = %Q|have %s element(s) matching "%s"|
|
17
|
+
WRONG_COUNT_MSG = %Q|expected following:\n%s\nto #{COUNT_DESC}, found %s.|
|
16
18
|
RIGHT_COUNT_MSG = %Q|expected following:\n%s\nto NOT have %s element(s) matching "%s", but found.|
|
17
19
|
BETWEEN_COUNT_MSG = %Q|expected following:\n%s\nto have at least %s and at most %s element(s) matching "%s", found %s.|
|
18
20
|
RIGHT_BETWEEN_COUNT_MSG = %Q|expected following:\n%s\nto NOT have at least %s and at most %s element(s) matching "%s", but found %s.|
|
@@ -73,6 +75,15 @@ module RSpec
|
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
78
|
+
def description
|
79
|
+
# TODO should it be more complicated?
|
80
|
+
if @options.has_key?(:count)
|
81
|
+
COUNT_DESC % [@options[:count],@tag]
|
82
|
+
else
|
83
|
+
TAG_FOUND_DESC % @tag
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
76
87
|
private
|
77
88
|
|
78
89
|
def tag_presents?
|
@@ -243,7 +254,7 @@ module RSpec
|
|
243
254
|
def have_form action_url, method, options={}, &block
|
244
255
|
options[:with] ||= {}
|
245
256
|
id = options[:with].delete(:id)
|
246
|
-
tag = 'form'; tag
|
257
|
+
tag = 'form'; tag << '#'+id if id
|
247
258
|
options[:with].merge!(:action => action_url)
|
248
259
|
options[:with].merge!(:method => method.to_s)
|
249
260
|
have_tag tag, options, &block
|
@@ -396,7 +407,7 @@ module RSpec
|
|
396
407
|
def with_select name, options={}, &block
|
397
408
|
options[:with] ||= {}
|
398
409
|
id = options[:with].delete(:id)
|
399
|
-
tag='select'; tag
|
410
|
+
tag='select'; tag << '#'+id if id
|
400
411
|
options[:with].merge!(:name => name)
|
401
412
|
@__current_scope_for_nokogiri_matcher.should have_tag(tag, options, &block)
|
402
413
|
end
|
@@ -404,7 +415,7 @@ module RSpec
|
|
404
415
|
def without_select name, options={}, &block
|
405
416
|
options[:with] ||= {}
|
406
417
|
id = options[:with].delete(:id)
|
407
|
-
tag='select'; tag
|
418
|
+
tag='select'; tag << '#'+id if id
|
408
419
|
options[:with].merge!(:name => name)
|
409
420
|
@__current_scope_for_nokogiri_matcher.should_not have_tag(tag, options, &block)
|
410
421
|
end
|
data/rspec-html-matchers.gemspec
CHANGED
@@ -5,6 +5,12 @@ describe 'have_tag' do
|
|
5
5
|
context "through css selector" do
|
6
6
|
let(:rendered) { asset('search_and_submit') }
|
7
7
|
|
8
|
+
it "should have right description" do
|
9
|
+
have_tag('div').description.should == 'have at least 1 element matching "div"'
|
10
|
+
have_tag('div.class').description.should == 'have at least 1 element matching "div.class"'
|
11
|
+
have_tag('div#id').description.should == 'have at least 1 element matching "div#id"'
|
12
|
+
end
|
13
|
+
|
8
14
|
it "should find tags" do
|
9
15
|
rendered.should have_tag('div')
|
10
16
|
rendered.should have_tag(:div)
|
@@ -97,6 +103,10 @@ describe 'have_tag' do
|
|
97
103
|
context "by count" do
|
98
104
|
let(:rendered) { asset('paragraphs') }
|
99
105
|
|
106
|
+
it "should have right description" do
|
107
|
+
have_tag('div', :count => 100500).description.should == 'have 100500 element(s) matching "div"'
|
108
|
+
end
|
109
|
+
|
100
110
|
it "should find tags" do
|
101
111
|
rendered.should have_tag('p', :count => 3)
|
102
112
|
rendered.should have_tag('p', :count => 2..3)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-html-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2012-04-02 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rspec
|
17
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,15 @@ dependencies:
|
|
22
21
|
version: 2.0.0
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
26
30
|
- !ruby/object:Gem::Dependency
|
27
31
|
name: nokogiri
|
28
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
29
33
|
none: false
|
30
34
|
requirements:
|
31
35
|
- - ! '>='
|
@@ -33,10 +37,15 @@ dependencies:
|
|
33
37
|
version: 1.4.4
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.4.4
|
37
46
|
- !ruby/object:Gem::Dependency
|
38
47
|
name: simplecov
|
39
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
40
49
|
none: false
|
41
50
|
requirements:
|
42
51
|
- - ! '>='
|
@@ -44,10 +53,15 @@ dependencies:
|
|
44
53
|
version: '0'
|
45
54
|
type: :development
|
46
55
|
prerelease: false
|
47
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
48
62
|
- !ruby/object:Gem::Dependency
|
49
63
|
name: rake
|
50
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
51
65
|
none: false
|
52
66
|
requirements:
|
53
67
|
- - ! '>='
|
@@ -55,7 +69,12 @@ dependencies:
|
|
55
69
|
version: '0'
|
56
70
|
type: :development
|
57
71
|
prerelease: false
|
58
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
59
78
|
description: ! 'Nokogiri based ''have_tag'' and ''with_tag'' matchers for rspec 2.x.x.
|
60
79
|
Does not depend on assert_select matcher, provides useful error messages.
|
61
80
|
|
@@ -89,7 +108,6 @@ files:
|
|
89
108
|
- spec/matchers/have_tag_spec.rb
|
90
109
|
- spec/spec_helper.rb
|
91
110
|
- spec/support/helpers.rb
|
92
|
-
has_rdoc: true
|
93
111
|
homepage: http://github.com/kucaahbe/rspec-html-matchers
|
94
112
|
licenses: []
|
95
113
|
post_install_message:
|
@@ -102,21 +120,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
120
|
- - ! '>='
|
103
121
|
- !ruby/object:Gem::Version
|
104
122
|
version: '0'
|
105
|
-
segments:
|
106
|
-
- 0
|
107
|
-
hash: 982466547
|
108
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
124
|
none: false
|
110
125
|
requirements:
|
111
126
|
- - ! '>='
|
112
127
|
- !ruby/object:Gem::Version
|
113
128
|
version: '0'
|
114
|
-
segments:
|
115
|
-
- 0
|
116
|
-
hash: 982466547
|
117
129
|
requirements: []
|
118
130
|
rubyforge_project: rspec-html-matchers
|
119
|
-
rubygems_version: 1.
|
131
|
+
rubygems_version: 1.8.18
|
120
132
|
signing_key:
|
121
133
|
specification_version: 3
|
122
134
|
summary: Nokogiri based 'have_tag' and 'with_tag' matchers for rspec 2.x.x
|