rspec2-rails-views-matchers 0.1.6 → 0.2.0

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.
File without changes
@@ -1,16 +1,17 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "version"
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = "rspec2-rails-views-matchers"
7
- s.version = RSpec::Rails::Views::Matchers::VERSION
6
+ s.version = '0.2.0'
8
7
  s.platform = Gem::Platform::RUBY
9
8
  s.authors = ["kucaahbe"]
10
9
  s.email = ["kucaahbe@ukr.net"]
11
10
  s.homepage = "http://github.com/kucaahbe/rspec2-rails-views-matchers"
12
- s.summary = %q{Nokogiri based 'have_tag' and 'with_tag' for rspec-2 without assert_select dependencies and useful error messages}
13
- s.description = s.summary
11
+ s.summary = %q{Nokogiri based 'have_tag' and 'with_tag' matchers for rspec 2.x.x}
12
+ s.description = <<DESC
13
+ #{s.summary}. Does not depend on assert_select matcher, provides useful error messages.
14
+ DESC
14
15
 
15
16
  s.rubyforge_project = "rspec2-rails-views-matchers"
16
17
 
@@ -20,7 +21,7 @@ Gem::Specification.new do |s|
20
21
  s.require_paths = ["lib"]
21
22
 
22
23
  s.add_dependency 'rspec', '>= 2.0.0'
23
- s.add_dependency 'nokogiri', '~> 1.5.0'
24
+ s.add_dependency 'nokogiri', '>= 1.4.4'
24
25
 
25
26
  s.add_development_dependency 'simplecov'
26
27
  s.add_development_dependency 'rake'
@@ -1,110 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "have_form" do
4
-
5
- before :each do
6
- render_html <<HTML
7
- <form action="/books" class="formtastic book" id="new_book" method="post">
8
-
9
- <div style="margin:0;padding:0;display:inline">
10
- <input name="authenticity_token" type="hidden" value="718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE=" />
11
- </div>
12
-
13
- <fieldset class="inputs">
14
- <ol>
15
- <li class="select required" id="book_publisher_input">
16
- <label for="book_publisher_id">
17
- Publisher<abbr title="required">*</abbr>
18
- </label>
19
- <select id="book_publisher_id" name="book[publisher_id]">
20
- <option value=""></option>
21
- <option value="1" selected="selected">The Pragmatic Bookshelf</option>
22
- <option value="2">sitepoint</option>
23
- <option value="3">O'Reilly</option>
24
- </select>
25
- </li>
26
-
27
- <li class="string required" id="book_title_input">
28
- <label for="book_title">
29
- Title<abbr title="required">*</abbr>
30
- </label>
31
- <input id="book_title" maxlength="255" name="book[title]" size="50" type="text" />
32
- </li>
33
-
34
- <li class="string required" id="book_author_input">
35
- <label for="book_author">
36
- Author<abbr title="required">*</abbr>
37
- </label>
38
- <input id="book_author" maxlength="255" name="book[author]" size="50" type="text" value="Authorname" />
39
- </li>
40
-
41
- <li class="password optional" id="user_password_input">
42
- <label for="user_password">
43
- Password:
44
- </label>
45
- <input id="user_password" name="user[password]" size="30" type="password" />
46
- </li>
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>
97
- </ol>
98
- </fieldset>
99
- </form>
100
- HTML
101
- end
4
+ let(:rendered) { IO.read(File.dirname(__FILE__)+"/../../assets/form.html") }
102
5
 
103
6
  context "without &block" do
104
-
105
7
  it "should find form" do
106
8
  rendered.should have_form("/books", :post)
107
-
108
9
  self.should_receive(:have_tag).with("form#new_book", :with => { :method => "post", :action => "/books", :class => %w(book formtastic) })
109
10
  rendered.should have_form("/books", "post", :with => { :id => "new_book", :class => %w(book formtastic) })
110
11
  end
@@ -113,197 +14,297 @@ HTML
113
14
  rendered.should_not have_form("/some_url", :post)
114
15
  rendered.should_not have_form("/books", :get)
115
16
  end
116
-
117
17
  end
118
18
 
119
19
  context "with &block" do
120
-
121
20
  context "with_select" do
122
-
123
21
  it "should find select" do
124
- rendered.should have_form("/books", :post) do
125
- with_select("book[publisher_id]", :with => { :id => "book_publisher_id" })
126
-
127
- self.should_receive(:have_tag).with("select#book_publisher_id", :with => { :name => "book[publisher_id]" })
128
- with_select("book[publisher_id]", :with => { :id => "book_publisher_id" })
129
- end
22
+ rendered.should have_form("/books", :post) do
23
+ with_select("book[publisher_id]", :with => { :id => "book_publisher_id" })
24
+ self.should_receive(:have_tag).with("select#book_publisher_id", :with => { :name => "book[publisher_id]" })
25
+ with_select("book[publisher_id]", :with => { :id => "book_publisher_id" })
26
+ end
130
27
  end
131
28
 
132
29
  it "should not find select" do
133
- rendered.should have_form("/books", :post) do
134
- without_select("book[publisher_id]", :with => { :id => "other_id" })
135
-
136
- self.should_receive(:have_tag).with("select#book_publisher_id", :with => { :name => "koob[publisher_id]" })
137
- without_select("koob[publisher_id]", :with => { :id => "book_publisher_id" })
138
- end
30
+ rendered.should have_form("/books", :post) do
31
+ without_select("book[publisher_id]", :with => { :id => "other_id" })
32
+ self.should_receive(:have_tag).with("select#book_publisher_id", :with => { :name => "koob[publisher_id]" })
33
+ without_select("koob[publisher_id]", :with => { :id => "book_publisher_id" })
34
+ end
139
35
  end
140
36
 
141
37
  context "with_option" do
142
-
143
- it "should find options" do
144
- rendered.should have_form("/books", :post) do
145
- with_select("book[publisher_id]") do
146
- with_option(nil)
147
- with_option("The Pragmatic Bookshelf", :selected => true)
148
- with_option(/sitepoint/,2)
149
-
150
- self.should_receive(:have_tag).with('option', :with => { :value => '3' }, :text => "O'Reilly")
151
- with_option("O'Reilly", 3, :selected => false)
152
- end
153
- end
154
- end
155
-
156
- it "should not find options" do
157
- rendered.should have_form("/books", :post) do
158
- with_select("book[publisher_id]") do
159
- without_option("blah blah")
160
- without_option("O'Reilly", 3, :selected => true)
161
- without_option("O'Reilly", 100500)
162
- end
163
- end
164
- end
165
-
38
+ it "should find options" do
39
+ rendered.should have_form("/books", :post) do
40
+ with_select("book[publisher_id]") do
41
+ with_option(nil)
42
+ with_option("The Pragmatic Bookshelf", :selected => true)
43
+ with_option(/sitepoint/,2)
44
+ self.should_receive(:have_tag).with('option', :with => { :value => '3' }, :text => "O'Reilly")
45
+ with_option("O'Reilly", 3, :selected => false)
46
+ end
47
+ end
48
+ end
49
+
50
+ it "should not find options" do
51
+ rendered.should have_form("/books", :post) do
52
+ with_select("book[publisher_id]") do
53
+ without_option("blah blah")
54
+ without_option("O'Reilly", 3, :selected => true)
55
+ without_option("O'Reilly", 100500)
56
+ end
57
+ end
58
+ end
166
59
  end
167
60
 
61
+ context "with_button" do
62
+ it "should find button" do
63
+ rendered.should have_form("/books", :post) do
64
+ self.should_receive(:have_tag).with('button', :with => {}, :text => "Cancel Book")
65
+ with_button("Cancel Book")
66
+ end
67
+ end
68
+
69
+ it "should not find button" do
70
+ rendered.should have_form("/books", :post) do
71
+ without_button("Cancel Book")
72
+ end
73
+ end
74
+ end
168
75
  end
169
76
 
170
77
  context "with_hidden_field" do
171
-
172
78
  it "should find hidden field" do
173
- rendered.should have_form("/books", :post) do
174
- with_hidden_field("authenticity_token")
175
- self.should_receive(:have_tag).with('input', :with => { :name => 'authenticity_token', :type => 'hidden', :value => '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE=' })
176
- with_hidden_field("authenticity_token", '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE=')
177
- end
79
+ rendered.should have_form("/books", :post) do
80
+ with_hidden_field("authenticity_token")
81
+ self.should_receive(:have_tag).with('input', :with => {
82
+ :name => 'authenticity_token',
83
+ :type => 'hidden',
84
+ :value => '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE='
85
+ })
86
+ with_hidden_field("authenticity_token", '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE=')
87
+ end
178
88
  end
179
89
 
180
90
  it "should not find hidden field" do
181
- rendered.should have_form("/books", :post) do
182
- without_hidden_field('user_id')
183
- without_hidden_field('authenticity_token', 'blabla')
184
- end
91
+ rendered.should have_form("/books", :post) do
92
+ without_hidden_field('user_id')
93
+ without_hidden_field('authenticity_token', 'blabla')
94
+ end
185
95
  end
186
-
187
96
  end
188
97
 
189
98
  context "with_text_field" do
190
-
191
99
  it "should find text field" do
192
- rendered.should have_form("/books", :post) do
193
- with_text_field('book[title]')
194
- with_text_field('book[title]',nil)
195
- with_text_field('book[author]','Authorname')
196
- end
100
+ rendered.should have_form("/books", :post) do
101
+ with_text_field('book[title]')
102
+ with_text_field('book[title]',nil)
103
+ with_text_field('book[author]','Authorname')
104
+ end
197
105
  end
198
106
 
199
107
  it "should not find text field" do
200
- rendered.should have_form("/books", :post) do
201
- without_text_field('book[title]','title does not exist')
202
- without_text_field('book[authoRR]')
203
- without_text_field('book[blabla]')
204
- end
108
+ rendered.should have_form("/books", :post) do
109
+ without_text_field('book[title]','title does not exist')
110
+ without_text_field('book[authoRR]')
111
+ without_text_field('book[blabla]')
112
+ end
113
+ end
114
+ end
115
+
116
+ context "with_email_field" do
117
+ it "should find email field" do
118
+ rendered.should have_form("/books", :post) do
119
+ with_email_field('user[email]')
120
+ with_email_field('user[email]', 'email@example.com')
121
+ with_email_field('user[email_confirmation]', nil)
122
+ end
205
123
  end
206
124
 
125
+ it "should not find email field" do
126
+ rendered.should have_form("/books", :post) do
127
+ without_email_field('book[author]','Authorname')
128
+ without_email_field('user[emaiL]')
129
+ without_email_field('user[apocalyptiq]')
130
+ end
131
+ end
207
132
  end
208
133
 
209
- context "with_password_field" do
134
+ context "with_url_field" do
135
+ it "should find url field" do
136
+ rendered.should have_form("/books", :post) do
137
+ with_url_field('user[url]')
138
+ with_url_field('user[url]', 'http://user.com')
139
+ end
140
+ end
141
+
142
+ it "should not find url field" do
143
+ rendered.should have_form("/books", :post) do
144
+ without_url_field('user[url]','Authorname')
145
+ without_url_field('user[emaiL]')
146
+ without_url_field('user[apocalyptiq]')
147
+ end
148
+ end
149
+ end
150
+
151
+ context "with_number_field" do
152
+ it "should find number field" do
153
+ rendered.should have_form("/books", :post) do
154
+ with_number_field('number')
155
+ with_number_field('number_defined', 3)
156
+ with_number_field('number_defined', '3')
157
+ end
158
+ end
159
+
160
+ it "should not find number field" do
161
+ rendered.should have_form("/books", :post) do
162
+ without_number_field('number',400)
163
+ without_number_field('number','400')
164
+ without_number_field('user[emaiL]')
165
+ without_number_field('user[apocalyptiq]')
166
+ end
167
+ end
168
+ end
169
+
170
+ context "with_range_field" do
171
+ it "should find range field" do
172
+ rendered.should have_form("/books", :post) do
173
+ with_range_field('range1', 1, 3)
174
+ with_range_field('range1','1','3')
175
+ with_range_field('range2', 1, 3, :with => { :value => 2 } )
176
+ with_range_field('range2', 1, 3, :with => { :value => '2' } )
177
+ end
178
+ end
179
+
180
+ it "should not find range field" do
181
+ rendered.should have_form("/books", :post) do
182
+ without_range_field('number')
183
+ without_range_field('range1', 1, 5)
184
+ without_range_field('range2', 1, 3, :with => { :value => 5 } )
185
+ end
186
+ end
187
+ end
188
+
189
+ context "with_date_field" do
190
+ it "should find date field" do
191
+ rendered.should have_form("/books", :post) do
192
+ with_date_field(:date)
193
+ with_date_field(:date, 'book_date')
194
+ with_date_field(:month, 'book_month', :with => { :value => 5 })
195
+ with_date_field(:week,'book_week')
196
+ with_date_field(:time, 'book_time')
197
+ with_date_field(:datetime, 'book_datetime')
198
+ with_date_field('datetime-local', 'book_datetime_local')
199
+ end
200
+ end
201
+
202
+ it "should not find date field" do
203
+ rendered.should have_form("/books", :post) do
204
+ without_date_field(:date, 'book_something')
205
+ without_date_field(:month, 'book_month', :with => { :value => 100500 })
206
+ end
207
+ end
208
+
209
+ it "should raise exception if wrong date field type specified" do
210
+ expect do
211
+ rendered.should have_form("/books", :post) do
212
+ without_date_field(:unknown, 'book_something')
213
+ end
214
+ end.to raise_error('unknown type `unknown` for date picker')
215
+ expect do
216
+ rendered.should have_form("/books", :post) do
217
+ with_date_field(:unknown, 'book_something')
218
+ end
219
+ end.to raise_error('unknown type `unknown` for date picker')
220
+ end
221
+ end
210
222
 
223
+ context "with_password_field" do
211
224
  it "should find password field" do
212
- rendered.should have_form("/books", :post) do
213
- with_password_field('user[password]')
214
- end
225
+ rendered.should have_form("/books", :post) do
226
+ with_password_field('user[password]')
227
+ end
215
228
  end
216
229
 
217
230
  it "should not find password field" do
218
- rendered.should have_form("/books", :post) do
219
- without_password_field('account[password]')
220
- end
231
+ rendered.should have_form("/books", :post) do
232
+ without_password_field('account[password]')
233
+ end
221
234
  end
222
-
223
235
  end
224
236
 
225
237
  context "with_file_field" do
226
-
227
238
  it "should find file field" do
228
- rendered.should have_form("/books", :post) do
229
- with_file_field('form[file]')
230
- end
239
+ rendered.should have_form("/books", :post) do
240
+ with_file_field('form[file]')
241
+ end
231
242
  end
232
243
 
233
244
  it "should not find file field" do
234
- rendered.should have_form("/books", :post) do
235
- without_file_field('user[file]')
236
- end
245
+ rendered.should have_form("/books", :post) do
246
+ without_file_field('user[file]')
247
+ end
237
248
  end
238
-
239
249
  end
240
250
 
241
251
  context "with_text_area" do
242
-
243
252
  it "should find text area" do
244
- rendered.should have_form("/books", :post) do
245
- with_text_area('book[description]')
246
- end
253
+ rendered.should have_form("/books", :post) do
254
+ with_text_area('book[description]')
255
+ end
247
256
  end
248
257
 
249
258
  it "should not find text area" do
250
- rendered.should have_form("/books", :post) do
251
- without_text_area('user[bio]')
252
- end
259
+ rendered.should have_form("/books", :post) do
260
+ without_text_area('user[bio]')
261
+ end
253
262
  end
254
-
255
263
  end
256
264
 
257
265
  context "with_check_box" do
258
-
259
266
  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
267
+ rendered.should have_form("/books", :post) do
268
+ with_checkbox("book[still_in_print]")
269
+ with_checkbox("book[still_in_print]","1")
270
+ end
264
271
  end
265
272
 
266
273
  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
274
+ rendered.should have_form("/books", :post) do
275
+ without_checkbox("book[book]")
276
+ without_checkbox("book[still_in_print]","500")
277
+ end
271
278
  end
272
-
273
279
  end
274
280
 
275
281
  context "with_radio_button" do
276
-
277
282
  it "should find radio button" do
278
- rendered.should have_form("/books", :post) do
279
- with_radio_button("form[name]","true")
280
- end
283
+ rendered.should have_form("/books", :post) do
284
+ with_radio_button("form[name]","true")
285
+ end
281
286
  end
282
287
 
283
288
  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
289
+ rendered.should have_form("/books", :post) do
290
+ without_radio_button("form[name]","100500")
291
+ without_radio_button("form[item]","false")
292
+ end
288
293
  end
289
-
290
294
  end
291
295
 
292
296
  context "with_submit" do
293
-
294
297
  it "should find submit" do
295
- rendered.should have_form("/books", :post) do
296
- with_submit("Create Book")
297
- end
298
+ rendered.should have_form("/books", :post) do
299
+ with_submit("Create Book")
300
+ end
298
301
  end
299
302
 
300
303
  it "should not find submit" do
301
- rendered.should have_form("/books", :post) do
302
- without_submit("Destroy Book")
303
- end
304
+ rendered.should have_form("/books", :post) do
305
+ without_submit("Destroy Book")
306
+ end
304
307
  end
305
-
306
308
  end
307
-
308
309
  end
309
310
  end