rspec2-rails-views-matchers 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +9 -9
- data/docs/CHANGELOG.md +13 -13
- data/docs/mikhalok.jpg +0 -0
- data/lib/rspec/rails/views/matchers/have_tag.rb +55 -0
- data/lib/version.rb +1 -1
- data/spec/matchers/form_matchers_spec.rb +107 -10
- metadata +28 -3
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Test views, be true! :)
|
2
2
|
=======================
|
3
3
|
|
4
|
-
![
|
4
|
+
[![Build Status](http://travis-ci.org/kucaahbe/rspec2-rails-views-matchers.png)](http://travis-ci.org/kucaahbe/rspec2-rails-views-matchers)
|
5
5
|
|
6
|
-
|
6
|
+
[![Mikhalok](http://investigator.org.ua/wp-content/uploads/01_500_liapis_powe-300x192.jpg)](http://www.myspace.com/lyapis "Lyapis Trubetskoy ska-punk band")
|
7
7
|
|
8
8
|
Why?
|
9
9
|
===
|
@@ -19,19 +19,19 @@ Install
|
|
19
19
|
|
20
20
|
add to your Gemfile(in group :test :) ):
|
21
21
|
|
22
|
-
|
22
|
+
gem 'rspec2-rails-views-matchers'
|
23
23
|
|
24
24
|
Usage
|
25
25
|
-----
|
26
26
|
|
27
27
|
some examples:
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
rendered.should have_tag('form',:with => {:action => user_path, :method => 'post'}) do
|
30
|
+
with_tag "input", :with => { :name => "user[email]", :type => 'email' }
|
31
|
+
with_tag "input#special_submit", :count => 1
|
32
|
+
without_tag "h1", :text => 'unneeded tag'
|
33
|
+
without_tag "p", :text => /content/i
|
34
|
+
end
|
35
35
|
|
36
36
|
More info
|
37
37
|
---------
|
data/docs/CHANGELOG.md
CHANGED
@@ -11,23 +11,23 @@ unreleased(TODO)
|
|
11
11
|
* add :without to have\_tag?
|
12
12
|
* !make possible constructions like:
|
13
13
|
|
14
|
-
|
14
|
+
rendered.should have(3).tags('div').with(:class => 'some-class').and_content(/some content/)
|
15
15
|
|
16
|
-
0.0.5
|
16
|
+
0.0.5 (trial-trip)
|
17
17
|
----------------------
|
18
18
|
|
19
|
-
*
|
19
|
+
* added some experimental matchers:
|
20
20
|
* have\_form(will be finished when "child" matchers will be done)
|
21
21
|
* with\_hidden\_field
|
22
22
|
* with\_text\_field
|
23
23
|
* with\_password\_field
|
24
|
-
*
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
24
|
+
* with\_file\_field?
|
25
|
+
* with\_text\_area
|
26
|
+
* with\_check\_box
|
27
|
+
* with\_radio\_button
|
28
28
|
* with\_select
|
29
29
|
* with\_option
|
30
|
-
*
|
30
|
+
* with\_submit
|
31
31
|
|
32
32
|
0.0.4 (bugfix)
|
33
33
|
--------------
|
@@ -39,15 +39,15 @@ unreleased(TODO)
|
|
39
39
|
|
40
40
|
* now following will work:
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
rendered.should have_tag('div') do
|
43
|
+
with_tag('p')
|
44
|
+
end
|
45
45
|
|
46
46
|
* tags can be specified via symbol
|
47
47
|
* classes can be specified via array or string(class-names separated by spaces), so following will work:
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
'<div class="one two">'.should have_tag('div', :with => { :class => ['two', 'one'] })
|
50
|
+
'<div class="one two">'.should have_tag('div', :with => { :class => 'two one' })
|
51
51
|
|
52
52
|
0.0.2
|
53
53
|
------
|
data/docs/mikhalok.jpg
ADDED
Binary file
|
@@ -146,6 +146,7 @@ module RSpec
|
|
146
146
|
# rendered.should have_tag('div', :maximum => 3) # matches less(or equal) than 3 'div' tags
|
147
147
|
# rendered.should have_tag('p', :text => 'some content') # will match "<p>some content</p>"
|
148
148
|
# rendered.should have_tag('p', :text => /some content/i) # will match "<p>sOme cOntEnt</p>"
|
149
|
+
# rendered.should have_tag('textarea', :with => {:name => 'user[description]'}, :text => "I like pie")
|
149
150
|
# "<html>
|
150
151
|
# <body>
|
151
152
|
# <h1>some html document</h1>
|
@@ -216,6 +217,50 @@ module RSpec
|
|
216
217
|
@__current_scope_for_nokogiri_matcher.should_not have_tag('input', options)
|
217
218
|
end
|
218
219
|
|
220
|
+
def with_file_field name
|
221
|
+
options = { :with => { :name => name, :type => 'file' } }
|
222
|
+
@__current_scope_for_nokogiri_matcher.should have_tag('input', options)
|
223
|
+
end
|
224
|
+
|
225
|
+
def without_file_field name
|
226
|
+
options = { :with => { :name => name, :type => 'file' } }
|
227
|
+
@__current_scope_for_nokogiri_matcher.should_not have_tag('input', options)
|
228
|
+
end
|
229
|
+
|
230
|
+
def with_text_area name
|
231
|
+
options = { :with => { :name => name } }
|
232
|
+
@__current_scope_for_nokogiri_matcher.should have_tag('textarea', options)
|
233
|
+
end
|
234
|
+
|
235
|
+
def without_text_area name
|
236
|
+
options = { :with => { :name => name } }
|
237
|
+
@__current_scope_for_nokogiri_matcher.should_not have_tag('textarea', options)
|
238
|
+
end
|
239
|
+
|
240
|
+
def with_checkbox name, value=nil
|
241
|
+
options = { :with => { :name => name, :type => 'checkbox' } }
|
242
|
+
options[:with].merge!(:value => value) if value
|
243
|
+
@__current_scope_for_nokogiri_matcher.should have_tag('input', options)
|
244
|
+
end
|
245
|
+
|
246
|
+
def without_checkbox name, value=nil
|
247
|
+
options = { :with => { :name => name, :type => 'checkbox' } }
|
248
|
+
options[:with].merge!(:value => value) if value
|
249
|
+
@__current_scope_for_nokogiri_matcher.should_not have_tag('input', options)
|
250
|
+
end
|
251
|
+
|
252
|
+
def with_radio_button name, value
|
253
|
+
options = { :with => { :name => name, :type => 'radio' } }
|
254
|
+
options[:with].merge!(:value => value)
|
255
|
+
@__current_scope_for_nokogiri_matcher.should have_tag('input', options)
|
256
|
+
end
|
257
|
+
|
258
|
+
def without_radio_button name, value
|
259
|
+
options = { :with => { :name => name, :type => 'radio' } }
|
260
|
+
options[:with].merge!(:value => value)
|
261
|
+
@__current_scope_for_nokogiri_matcher.should_not have_tag('input', options)
|
262
|
+
end
|
263
|
+
|
219
264
|
def with_select name, options={}, &block
|
220
265
|
options[:with] ||= {}
|
221
266
|
id = options[:with].delete(:id)
|
@@ -264,5 +309,15 @@ module RSpec
|
|
264
309
|
@__current_scope_for_nokogiri_matcher.should_not have_tag(tag, options)
|
265
310
|
end
|
266
311
|
|
312
|
+
def with_submit value
|
313
|
+
options = { :with => { :type => 'submit', :value => value } }
|
314
|
+
@__current_scope_for_nokogiri_matcher.should have_tag('input', options)
|
315
|
+
end
|
316
|
+
|
317
|
+
def without_submit value
|
318
|
+
options = { :with => { :type => 'submit', :value => value } }
|
319
|
+
@__current_scope_for_nokogiri_matcher.should_not have_tag('input', options)
|
320
|
+
end
|
321
|
+
|
267
322
|
end
|
268
323
|
end
|
data/lib/version.rb
CHANGED
@@ -45,6 +45,55 @@ describe "have_form" do
|
|
45
45
|
<input id="user_password" name="user[password]" size="30" type="password" />
|
46
46
|
</li>
|
47
47
|
|
48
|
+
<li class="file optional" id="form_file_input">
|
49
|
+
<label for="form_file">
|
50
|
+
File
|
51
|
+
</label>
|
52
|
+
<input id="form_file" name="form[file]" type="file" />
|
53
|
+
</li>
|
54
|
+
|
55
|
+
<li class="text required" id="book_description_input">
|
56
|
+
<label for="book_description">
|
57
|
+
Description<abbr title="required">*</abbr>
|
58
|
+
</label>
|
59
|
+
<textarea cols="40" id="book_description" name="book[description]" rows="20"></textarea>
|
60
|
+
</li>
|
61
|
+
|
62
|
+
<li class="boolean required" id="book_still_in_print_input">
|
63
|
+
<label for="book_still_in_print">
|
64
|
+
Still in print<abbr title="required">*</abbr>
|
65
|
+
</label>
|
66
|
+
<input name="book[still_in_print]" type="hidden" value="0" />
|
67
|
+
<input id="book_still_in_print" name="book[still_in_print]" type="checkbox" value="1" />
|
68
|
+
</li>
|
69
|
+
|
70
|
+
<li class="radio required" id="form_name_input">
|
71
|
+
<fieldset>
|
72
|
+
<legend class="label">
|
73
|
+
<label>Name<abbr title="required">*</abbr></label>
|
74
|
+
</legend>
|
75
|
+
<ol>
|
76
|
+
<li class="name_true">
|
77
|
+
<label for="form_name_true">
|
78
|
+
<input id="form_name_true" name="form[name]" type="radio" value="true" /> Yes
|
79
|
+
</label>
|
80
|
+
</li>
|
81
|
+
<li class="name_false">
|
82
|
+
<label for="form_name_false">
|
83
|
+
<input id="form_name_false" name="form[name]" type="radio" value="false" /> No</label>
|
84
|
+
</li>
|
85
|
+
</ol>
|
86
|
+
</fieldset>
|
87
|
+
</li>
|
88
|
+
|
89
|
+
</ol>
|
90
|
+
</fieldset>
|
91
|
+
|
92
|
+
<fieldset class="buttons">
|
93
|
+
<ol>
|
94
|
+
<li class="commit">
|
95
|
+
<input class="create" id="book_submit" name="commit" type="submit" value="Create Book" />
|
96
|
+
</li>
|
48
97
|
</ol>
|
49
98
|
</fieldset>
|
50
99
|
</form>
|
@@ -175,36 +224,84 @@ HTML
|
|
175
224
|
|
176
225
|
context "with_file_field" do
|
177
226
|
|
178
|
-
it "should find file field"
|
179
|
-
|
227
|
+
it "should find file field" do
|
228
|
+
rendered.should have_form("/books", :post) do
|
229
|
+
with_file_field('form[file]')
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should not find file field" do
|
234
|
+
rendered.should have_form("/books", :post) do
|
235
|
+
without_file_field('user[file]')
|
236
|
+
end
|
237
|
+
end
|
180
238
|
|
181
239
|
end
|
182
240
|
|
183
241
|
context "with_text_area" do
|
184
242
|
|
185
|
-
it "should find text area"
|
186
|
-
|
243
|
+
it "should find text area" do
|
244
|
+
rendered.should have_form("/books", :post) do
|
245
|
+
with_text_area('book[description]')
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should not find text area" do
|
250
|
+
rendered.should have_form("/books", :post) do
|
251
|
+
without_text_area('user[bio]')
|
252
|
+
end
|
253
|
+
end
|
187
254
|
|
188
255
|
end
|
189
256
|
|
190
257
|
context "with_check_box" do
|
191
258
|
|
192
|
-
it "should find check box"
|
193
|
-
|
259
|
+
it "should find check box" do
|
260
|
+
rendered.should have_form("/books", :post) do
|
261
|
+
with_checkbox("book[still_in_print]")
|
262
|
+
with_checkbox("book[still_in_print]","1")
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should not find check box" do
|
267
|
+
rendered.should have_form("/books", :post) do
|
268
|
+
without_checkbox("book[book]")
|
269
|
+
without_checkbox("book[still_in_print]","500")
|
270
|
+
end
|
271
|
+
end
|
194
272
|
|
195
273
|
end
|
196
274
|
|
197
275
|
context "with_radio_button" do
|
198
276
|
|
199
|
-
it "should find radio button"
|
200
|
-
|
277
|
+
it "should find radio button" do
|
278
|
+
rendered.should have_form("/books", :post) do
|
279
|
+
with_radio_button("form[name]","true")
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should not find radio button" do
|
284
|
+
rendered.should have_form("/books", :post) do
|
285
|
+
without_radio_button("form[name]","100500")
|
286
|
+
without_radio_button("form[item]","false")
|
287
|
+
end
|
288
|
+
end
|
201
289
|
|
202
290
|
end
|
203
291
|
|
204
292
|
context "with_submit" do
|
205
293
|
|
206
|
-
it "should find submit"
|
207
|
-
|
294
|
+
it "should find submit" do
|
295
|
+
rendered.should have_form("/books", :post) do
|
296
|
+
with_submit("Create Book")
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should not find submit" do
|
301
|
+
rendered.should have_form("/books", :post) do
|
302
|
+
without_submit("Destroy Book")
|
303
|
+
end
|
304
|
+
end
|
208
305
|
|
209
306
|
end
|
210
307
|
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec2-rails-views-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- kucaahbe
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-05-19 00:00:00 +03:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +26,11 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ">="
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 0
|
24
34
|
version: 2.0.0
|
25
35
|
type: :runtime
|
26
36
|
version_requirements: *id001
|
@@ -32,6 +42,11 @@ dependencies:
|
|
32
42
|
requirements:
|
33
43
|
- - ~>
|
34
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 4
|
35
50
|
version: 1.4.4
|
36
51
|
type: :runtime
|
37
52
|
version_requirements: *id002
|
@@ -43,6 +58,9 @@ dependencies:
|
|
43
58
|
requirements:
|
44
59
|
- - ">="
|
45
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
46
64
|
version: "0"
|
47
65
|
type: :development
|
48
66
|
version_requirements: *id003
|
@@ -64,6 +82,7 @@ files:
|
|
64
82
|
- README.md
|
65
83
|
- Rakefile
|
66
84
|
- docs/CHANGELOG.md
|
85
|
+
- docs/mikhalok.jpg
|
67
86
|
- lib/rspec/rails/views/matchers.rb
|
68
87
|
- lib/rspec/rails/views/matchers/have_tag.rb
|
69
88
|
- lib/rspec2-rails-views-matchers.rb
|
@@ -87,17 +106,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
106
|
requirements:
|
88
107
|
- - ">="
|
89
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
110
|
+
segments:
|
111
|
+
- 0
|
90
112
|
version: "0"
|
91
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
114
|
none: false
|
93
115
|
requirements:
|
94
116
|
- - ">="
|
95
117
|
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
96
121
|
version: "0"
|
97
122
|
requirements: []
|
98
123
|
|
99
124
|
rubyforge_project: rspec2-rails-views-matchers
|
100
|
-
rubygems_version: 1.5.
|
125
|
+
rubygems_version: 1.5.0
|
101
126
|
signing_key:
|
102
127
|
specification_version: 3
|
103
128
|
summary: Nokogiri based 'have_tag' and 'with_tag' for rspec-2 without assert_select dependencies and useful error messages
|