rspec-html-matchers 0.4.4 → 0.5.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 +12 -1
- data/README.md +38 -27
- data/features/support/env.rb +0 -5
- data/lib/rspec-html-matchers.rb +36 -30
- data/spec/fixtures/form.html +1 -0
- data/spec/{matchers/form_matchers_spec.rb → form_matchers_spec.rb} +52 -62
- data/spec/{matchers/have_tag_spec.rb → have_tag_spec.rb} +221 -139
- data/spec/spec_helper.rb +53 -4
- metadata +66 -41
- data/.gitignore +0 -18
- data/.rspec +0 -1
- data/.travis.yml +0 -13
- data/.yardopts +0 -4
- data/Gemfile +0 -2
- data/Rakefile +0 -32
- data/cucumber.yml +0 -1
- data/rspec-html-matchers.gemspec +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d61a10851ace0712b7207d446f43cde42af550c0
|
4
|
+
data.tar.gz: 9732c49d3720bb2b14aa3c31eff82f83c259b12b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61822c3ee0067e015ca243c0c1ffd4d706febb4a0b01daf929c248229befeb9419f971b5967a46178bd3bef14e11c62757dc6e2c198141a8ed7a580315e9924c
|
7
|
+
data.tar.gz: 5b05ffd9c02613e165b1407eaec75784ec3944ed5cbd4e1be8306fdd946a3b4d0a96574b558cb8f1c867cd75dcf2f6e0bd99ce106e9ca826a9e88798975c1204
|
data/CHANGELOG.md
CHANGED
@@ -9,11 +9,22 @@ unreleased(TODO)
|
|
9
9
|
* inteligent check comments(make sure it is not searching inside comments)
|
10
10
|
* shouldn't show all markup in error message if it is too big
|
11
11
|
* order matching
|
12
|
+
* improve documentation, add more usage examples (look at changelog and code!)
|
12
13
|
|
13
14
|
0.5.0
|
14
15
|
-----
|
15
16
|
|
16
|
-
*
|
17
|
+
* new "expect" syntax support
|
18
|
+
|
19
|
+
0.4.4
|
20
|
+
-----
|
21
|
+
|
22
|
+
* options for have_tag now support Regexp (thanks to [Ian C. Anderson](http://github.com/iancanderson))
|
23
|
+
|
24
|
+
0.4.3
|
25
|
+
-----
|
26
|
+
|
27
|
+
* added license to gemspec
|
17
28
|
|
18
29
|
0.4.2
|
19
30
|
-----
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ so perharps your code produces following output:
|
|
50
50
|
so you test it with following:
|
51
51
|
|
52
52
|
```ruby
|
53
|
-
rendered.
|
53
|
+
expect(rendered).to have_tag('form', :with => { :action => '/users', :method => 'post' }) do
|
54
54
|
with_tag "input", :with => { :name => "user[email]", :type => 'email' }
|
55
55
|
with_tag "input#special_submit", :count => 1
|
56
56
|
without_tag "h1", :text => 'unneeded tag'
|
@@ -66,22 +66,22 @@ Input could be any html string. Let's take a look at these examples:
|
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
# simple examples:
|
69
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
70
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
71
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
72
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
69
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p')
|
70
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag(:p)
|
71
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p#qwerty')
|
72
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p.qwe.rty')
|
73
73
|
# more complicated examples:
|
74
|
-
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.
|
75
|
-
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.
|
76
|
-
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.
|
74
|
+
expect('<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>').to have_tag('p strong')
|
75
|
+
expect('<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>').to have_tag('p#qwerty strong')
|
76
|
+
expect('<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>').to have_tag('p.qwe.rty strong')
|
77
77
|
# or you can use another syntax for examples above
|
78
|
-
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.
|
78
|
+
expect('<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>').to have_tag('p') do
|
79
79
|
with_tag('strong')
|
80
80
|
end
|
81
|
-
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.
|
81
|
+
expect('<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>').to have_tag('p#qwerty') do
|
82
82
|
with_tag('strong')
|
83
83
|
end
|
84
|
-
'<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>'.
|
84
|
+
expect('<p class="qwe rty" id="qwerty"><strong>Para</strong>graph</p>').to have_tag('p.qwe.rty') do
|
85
85
|
with_tag('strong')
|
86
86
|
end
|
87
87
|
```
|
@@ -90,41 +90,41 @@ Input could be any html string. Let's take a look at these examples:
|
|
90
90
|
|
91
91
|
```ruby
|
92
92
|
# all of this are equivalent:
|
93
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
94
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
95
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
96
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
93
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p', :with => { :class => 'qwe rty' })
|
94
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p', :with => { :class => 'rty qwe' })
|
95
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p', :with => { :class => ['rty', 'qwe'] })
|
96
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p', :with => { :class => ['qwe', 'rty'] })
|
97
97
|
```
|
98
98
|
|
99
99
|
The same works with `:without`:
|
100
100
|
|
101
101
|
```ruby
|
102
102
|
# all of this are equivalent:
|
103
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
104
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
105
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
106
|
-
'<p class="qwe rty" id="qwerty">Paragraph</p>'.
|
103
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p', :without => { :class => 'qwe rty' })
|
104
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p', :without => { :class => 'rty qwe' })
|
105
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p', :without => { :class => ['rty', 'qwe'] })
|
106
|
+
expect('<p class="qwe rty" id="qwerty">Paragraph</p>').to have_tag('p', :without => { :class => ['qwe', 'rty'] })
|
107
107
|
```
|
108
108
|
|
109
109
|
* content matching:
|
110
110
|
|
111
111
|
```ruby
|
112
|
-
'<p> Some content here</p>'.
|
112
|
+
expect('<p> Some content here</p>').to have_tag('p', :text => ' Some content here')
|
113
113
|
# or
|
114
|
-
'<p> Some content here</p>'.
|
114
|
+
expect('<p> Some content here</p>').to have_tag('p') do
|
115
115
|
with_text ' Some content here'
|
116
116
|
end
|
117
117
|
|
118
|
-
'<p> Some content here</p>'.
|
118
|
+
expect('<p> Some content here</p>').to have_tag('p', :text => /Some content here/)
|
119
119
|
# or
|
120
|
-
'<p> Some content here</p>'.
|
120
|
+
expect('<p> Some content here</p>').to have_tag('p') do
|
121
121
|
with_text /Some content here/
|
122
122
|
end
|
123
123
|
|
124
124
|
# mymock.text == 'Some content here'
|
125
|
-
'<p> Some content here</p>'.
|
125
|
+
expect('<p> Some content here</p>').to have_tag('p', :content => mymock.text)
|
126
126
|
# or
|
127
|
-
'<p> Some content here</p>'.
|
127
|
+
expect('<p> Some content here</p>').to have_tag('p') do
|
128
128
|
with_content mymock.text
|
129
129
|
end
|
130
130
|
```
|
@@ -132,7 +132,7 @@ Input could be any html string. Let's take a look at these examples:
|
|
132
132
|
* usage with capybara and cucumber:
|
133
133
|
|
134
134
|
```ruby
|
135
|
-
page.
|
135
|
+
expect(page).to have_tag( ... )
|
136
136
|
```
|
137
137
|
|
138
138
|
where `page` is an instance of Capybara::Session
|
@@ -159,6 +159,17 @@ where `page` is an instance of Capybara::Session
|
|
159
159
|
|
160
160
|
and of course you can use the `without_` matchers (see the documentation).
|
161
161
|
|
162
|
+
### rspec 1 partial backwards compatibility:
|
163
|
+
|
164
|
+
you can match:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
expect(response).to have_tag('div', 'expected content')
|
168
|
+
expect(response).to have_tag('div', /regexp matching expected content/)
|
169
|
+
```
|
170
|
+
|
171
|
+
[RSpec 1 `have_tag` documentation](http://old.rspec.info/rails/writing/views.html)
|
172
|
+
|
162
173
|
More info
|
163
174
|
---------
|
164
175
|
|
@@ -188,7 +199,7 @@ Contributors
|
|
188
199
|
MIT Licensed
|
189
200
|
============
|
190
201
|
|
191
|
-
Copyright (c) 2011-
|
202
|
+
Copyright (c) 2011-2014 Dmitrij Mjakotnyi
|
192
203
|
|
193
204
|
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:
|
194
205
|
|
data/features/support/env.rb
CHANGED
@@ -9,11 +9,6 @@ class SimpleApp < Sinatra::Base
|
|
9
9
|
set :public_folder, $ASSETS_DIR
|
10
10
|
end
|
11
11
|
|
12
|
-
unless ENV.has_key? 'TRAVIS'
|
13
|
-
Capybara.register_driver :selenium do |app|
|
14
|
-
Capybara::Selenium::Driver.new(app, :browser => (ENV['BROWSER'] || :chrome))
|
15
|
-
end
|
16
|
-
end
|
17
12
|
Capybara.default_driver = :selenium
|
18
13
|
Capybara.app = SimpleApp
|
19
14
|
|
data/lib/rspec-html-matchers.rb
CHANGED
@@ -102,7 +102,13 @@ module RSpec
|
|
102
102
|
@document = document
|
103
103
|
else
|
104
104
|
@parent_scope = document.current_scope
|
105
|
-
@current_scope =
|
105
|
+
@current_scope = begin
|
106
|
+
document.parent_scope.css(@tag)
|
107
|
+
# on jruby this produce exception if css was not found:
|
108
|
+
# undefined method `decorate' for nil:NilClass
|
109
|
+
rescue NoMethodError
|
110
|
+
Nokogiri::XML::NodeSet.new(Nokogiri::XML::Document.new)
|
111
|
+
end
|
106
112
|
@document = @parent_scope.to_html
|
107
113
|
end
|
108
114
|
|
@@ -239,24 +245,24 @@ module RSpec
|
|
239
245
|
# @option options [String/Regexp] :text to match tag content, could be either String or Regexp
|
240
246
|
#
|
241
247
|
# @example
|
242
|
-
# rendered.
|
243
|
-
# rendered.
|
244
|
-
# rendered.
|
245
|
-
# rendered.
|
246
|
-
# rendered.
|
247
|
-
# rendered.
|
248
|
-
# rendered.
|
249
|
-
# rendered.
|
250
|
-
# rendered.
|
251
|
-
# rendered.
|
252
|
-
# rendered.
|
253
|
-
# "<html>
|
248
|
+
# expect(rendered).to have_tag('div')
|
249
|
+
# expect(rendered).to have_tag('h1.header')
|
250
|
+
# expect(rendered).to have_tag('div#footer')
|
251
|
+
# expect(rendered).to have_tag('input#email', :with => { :name => 'user[email]', :type => 'email' } )
|
252
|
+
# expect(rendered).to have_tag('div', :count => 3) # matches exactly 3 'div' tags
|
253
|
+
# expect(rendered).to have_tag('div', :count => 3..7) # shortcut for have_tag('div', :minimum => 3, :maximum => 7)
|
254
|
+
# expect(rendered).to have_tag('div', :minimum => 3) # matches more(or equal) than 3 'div' tags
|
255
|
+
# expect(rendered).to have_tag('div', :maximum => 3) # matches less(or equal) than 3 'div' tags
|
256
|
+
# expect(rendered).to have_tag('p', :text => 'some content') # will match "<p>some content</p>"
|
257
|
+
# expect(rendered).to have_tag('p', :text => /some content/i) # will match "<p>sOme cOntEnt</p>"
|
258
|
+
# expect(rendered).to have_tag('textarea', :with => {:name => 'user[description]'}, :text => "I like pie")
|
259
|
+
# expect("<html>
|
254
260
|
# <body>
|
255
261
|
# <h1>some html document</h1>
|
256
262
|
# </body>
|
257
|
-
# </html>".
|
258
|
-
# '<div class="one two">'.
|
259
|
-
# '<div class="one two">'.
|
263
|
+
# </html>").to have_tag('body') { with_tag('h1', :text => 'some html document') }
|
264
|
+
# expect('<div class="one two">').to have_tag('div', :with => { :class => ['two', 'one'] })
|
265
|
+
# expect('<div class="one two">').to have_tag('div', :with => { :class => 'two one' })
|
260
266
|
def have_tag tag, options={}, &block
|
261
267
|
# for backwards compatibility with rpecs have tag:
|
262
268
|
options = { :text => options } if options.kind_of?(String) || options.kind_of?(Regexp)
|
@@ -267,14 +273,14 @@ module RSpec
|
|
267
273
|
raise StandardError, 'this matcher should be used inside "have_tag" matcher block' unless defined?(@__current_scope_for_nokogiri_matcher)
|
268
274
|
raise ArgumentError, 'this matcher does not accept block' if block_given?
|
269
275
|
tag = @__current_scope_for_nokogiri_matcher.instance_variable_get(:@tag)
|
270
|
-
@__current_scope_for_nokogiri_matcher.
|
276
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, :text => text)
|
271
277
|
end
|
272
278
|
|
273
279
|
def without_text text
|
274
280
|
raise StandardError, 'this matcher should be used inside "have_tag" matcher block' unless defined?(@__current_scope_for_nokogiri_matcher)
|
275
281
|
raise ArgumentError, 'this matcher does not accept block' if block_given?
|
276
282
|
tag = @__current_scope_for_nokogiri_matcher.instance_variable_get(:@tag)
|
277
|
-
@__current_scope_for_nokogiri_matcher.
|
283
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, :text => text)
|
278
284
|
end
|
279
285
|
alias :but_without_text :without_text
|
280
286
|
|
@@ -283,7 +289,7 @@ module RSpec
|
|
283
289
|
# @see #have_tag
|
284
290
|
# @note this should be used within block of have_tag matcher
|
285
291
|
def with_tag tag, options={}, &block
|
286
|
-
@__current_scope_for_nokogiri_matcher.
|
292
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, options, &block)
|
287
293
|
end
|
288
294
|
|
289
295
|
# without_tag matcher
|
@@ -291,7 +297,7 @@ module RSpec
|
|
291
297
|
# @see #have_tag
|
292
298
|
# @note this should be used within block of have_tag matcher
|
293
299
|
def without_tag tag, options={}, &block
|
294
|
-
@__current_scope_for_nokogiri_matcher.
|
300
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, options, &block)
|
295
301
|
end
|
296
302
|
|
297
303
|
# form assertion
|
@@ -415,13 +421,13 @@ module RSpec
|
|
415
421
|
def with_text_area name#TODO, text=nil
|
416
422
|
#options = form_tag_options('text',name,value)
|
417
423
|
options = { :with => { :name => name } }
|
418
|
-
@__current_scope_for_nokogiri_matcher.
|
424
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag('textarea', options)
|
419
425
|
end
|
420
426
|
|
421
427
|
def without_text_area name#TODO, text=nil
|
422
428
|
#options = form_tag_options('text',name,value)
|
423
429
|
options = { :with => { :name => name } }
|
424
|
-
@__current_scope_for_nokogiri_matcher.
|
430
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag('textarea', options)
|
425
431
|
end
|
426
432
|
|
427
433
|
def with_checkbox name, value=nil
|
@@ -449,7 +455,7 @@ module RSpec
|
|
449
455
|
id = options[:with].delete(:id)
|
450
456
|
tag='select'; tag << '#'+id if id
|
451
457
|
options[:with].merge!(:name => name)
|
452
|
-
@__current_scope_for_nokogiri_matcher.
|
458
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, options, &block)
|
453
459
|
end
|
454
460
|
|
455
461
|
def without_select name, options={}, &block
|
@@ -457,7 +463,7 @@ module RSpec
|
|
457
463
|
id = options[:with].delete(:id)
|
458
464
|
tag='select'; tag << '#'+id if id
|
459
465
|
options[:with].merge!(:name => name)
|
460
|
-
@__current_scope_for_nokogiri_matcher.
|
466
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, options, &block)
|
461
467
|
end
|
462
468
|
|
463
469
|
def with_option text, value=nil, options={}
|
@@ -473,7 +479,7 @@ module RSpec
|
|
473
479
|
end
|
474
480
|
options.delete(:selected)
|
475
481
|
options.merge!(:text => text) if text
|
476
|
-
@__current_scope_for_nokogiri_matcher.
|
482
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag(tag, options)
|
477
483
|
end
|
478
484
|
|
479
485
|
def without_option text, value=nil, options={}
|
@@ -489,7 +495,7 @@ module RSpec
|
|
489
495
|
end
|
490
496
|
options.delete(:selected)
|
491
497
|
options.merge!(:text => text) if text
|
492
|
-
@__current_scope_for_nokogiri_matcher.
|
498
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag(tag, options)
|
493
499
|
end
|
494
500
|
|
495
501
|
def with_button text, value=nil, options={}
|
@@ -500,7 +506,7 @@ module RSpec
|
|
500
506
|
end
|
501
507
|
options[:with].merge!(:value => value.to_s) if value
|
502
508
|
options.merge!(:text => text) if text
|
503
|
-
@__current_scope_for_nokogiri_matcher.
|
509
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag('button', options)
|
504
510
|
end
|
505
511
|
|
506
512
|
def without_button text, value=nil, options={}
|
@@ -511,7 +517,7 @@ module RSpec
|
|
511
517
|
end
|
512
518
|
options[:with].merge!(:value => value.to_s) if value
|
513
519
|
options.merge!(:text => text) if text
|
514
|
-
@__current_scope_for_nokogiri_matcher.
|
520
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag('button', options)
|
515
521
|
end
|
516
522
|
|
517
523
|
def with_submit value
|
@@ -529,11 +535,11 @@ module RSpec
|
|
529
535
|
private
|
530
536
|
|
531
537
|
def should_have_input(options)
|
532
|
-
@__current_scope_for_nokogiri_matcher.
|
538
|
+
expect(@__current_scope_for_nokogiri_matcher).to have_tag('input', options)
|
533
539
|
end
|
534
540
|
|
535
541
|
def should_not_have_input(options)
|
536
|
-
@__current_scope_for_nokogiri_matcher.
|
542
|
+
expect(@__current_scope_for_nokogiri_matcher).to_not have_tag('input', options)
|
537
543
|
end
|
538
544
|
|
539
545
|
# form_tag in method name name mean smth. like input, submit, tags that should appear in a form
|
data/spec/fixtures/form.html
CHANGED
@@ -5,54 +5,50 @@ describe "have_form" do
|
|
5
5
|
|
6
6
|
context "without &block" do
|
7
7
|
it "should find form" do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
rendered.should have_form("/books", "post", :with => { :id => "new_book", :class => %w(book formtastic) })
|
8
|
+
# sanity check
|
9
|
+
expect(rendered).to have_form("/books", :post)
|
10
|
+
expect(rendered).to have_form("/books", "post", with: { id: "new_book", class: %w(book formtastic) })
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should not find form" do
|
15
|
-
rendered.
|
16
|
-
rendered.
|
14
|
+
expect(rendered).to_not have_form("/some_url", :post)
|
15
|
+
expect(rendered).to_not have_form("/books", :get)
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
19
|
context "with &block" do
|
21
20
|
context "with_select" do
|
22
21
|
it "should find select" do
|
23
|
-
rendered.
|
24
|
-
with_select("book[publisher_id]", :
|
25
|
-
|
26
|
-
with_select("book[publisher_id]", :with => { :id => "book_publisher_id" })
|
22
|
+
expect(rendered).to have_form("/books", :post) do
|
23
|
+
with_select("book[publisher_id]", with: { id: "book_publisher_id" })
|
24
|
+
with_select("book[publisher_id]", with: { id: "book_publisher_id" })
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
30
28
|
it "should not find select" do
|
31
|
-
rendered.
|
32
|
-
without_select("book[publisher_id]", :
|
33
|
-
|
34
|
-
without_select("koob[publisher_id]", :with => { :id => "book_publisher_id" })
|
29
|
+
expect(rendered).to have_form("/books", :post) do
|
30
|
+
without_select("book[publisher_id]", with: { id: "other_id" })
|
31
|
+
without_select("koob[publisher_id]", with: { id: "book_publisher_id" })
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
35
|
context "with_option" do
|
39
36
|
it "should find options" do
|
40
|
-
rendered.
|
37
|
+
expect(rendered).to have_form("/books", :post) do
|
41
38
|
with_select("book[publisher_id]") do
|
42
39
|
with_option(nil)
|
43
|
-
with_option("The Pragmatic Bookshelf", :
|
40
|
+
with_option("The Pragmatic Bookshelf", selected: true)
|
44
41
|
with_option(/sitepoint/,2)
|
45
|
-
|
46
|
-
with_option("O'Reilly", 3, :selected => false)
|
42
|
+
with_option("O'Reilly", 3, selected: false)
|
47
43
|
end
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
51
47
|
it "should not find options" do
|
52
|
-
rendered.
|
48
|
+
expect(rendered).to have_form("/books", :post) do
|
53
49
|
with_select("book[publisher_id]") do
|
54
50
|
without_option("blah blah")
|
55
|
-
without_option("O'Reilly", 3, :
|
51
|
+
without_option("O'Reilly", 3, selected: true)
|
56
52
|
without_option("O'Reilly", 100500)
|
57
53
|
end
|
58
54
|
end
|
@@ -61,15 +57,14 @@ describe "have_form" do
|
|
61
57
|
|
62
58
|
context "with_button" do
|
63
59
|
it "should find button" do
|
64
|
-
rendered.
|
65
|
-
self.should_receive(:have_tag).with('button', :with => {}, :text => "Cancel Book")
|
60
|
+
expect(rendered).to have_form("/books", :post) do
|
66
61
|
with_button("Cancel Book")
|
67
62
|
end
|
68
63
|
end
|
69
64
|
|
70
65
|
it "should not find button" do
|
71
|
-
rendered.
|
72
|
-
without_button("
|
66
|
+
expect(rendered).to have_form("/books", :post) do
|
67
|
+
without_button("Create Book")
|
73
68
|
end
|
74
69
|
end
|
75
70
|
end
|
@@ -77,19 +72,14 @@ describe "have_form" do
|
|
77
72
|
|
78
73
|
context "with_hidden_field" do
|
79
74
|
it "should find hidden field" do
|
80
|
-
rendered.
|
75
|
+
expect(rendered).to have_form("/books", :post) do
|
81
76
|
with_hidden_field("authenticity_token")
|
82
|
-
self.should_receive(:have_tag).with('input', :with => {
|
83
|
-
:name => 'authenticity_token',
|
84
|
-
:type => 'hidden',
|
85
|
-
:value => '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE='
|
86
|
-
})
|
87
77
|
with_hidden_field("authenticity_token", '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE=')
|
88
78
|
end
|
89
79
|
end
|
90
80
|
|
91
81
|
it "should not find hidden field" do
|
92
|
-
rendered.
|
82
|
+
expect(rendered).to have_form("/books", :post) do
|
93
83
|
without_hidden_field('user_id')
|
94
84
|
without_hidden_field('authenticity_token', 'blabla')
|
95
85
|
end
|
@@ -98,7 +88,7 @@ describe "have_form" do
|
|
98
88
|
|
99
89
|
context "with_text_field" do
|
100
90
|
it "should find text field" do
|
101
|
-
rendered.
|
91
|
+
expect(rendered).to have_form("/books", :post) do
|
102
92
|
with_text_field('book[title]')
|
103
93
|
with_text_field('book[title]',nil)
|
104
94
|
with_text_field('book[author]','Authorname')
|
@@ -106,7 +96,7 @@ describe "have_form" do
|
|
106
96
|
end
|
107
97
|
|
108
98
|
it "should not find text field" do
|
109
|
-
rendered.
|
99
|
+
expect(rendered).to have_form("/books", :post) do
|
110
100
|
without_text_field('book[title]','title does not exist')
|
111
101
|
without_text_field('book[authoRR]')
|
112
102
|
without_text_field('book[blabla]')
|
@@ -116,7 +106,7 @@ describe "have_form" do
|
|
116
106
|
|
117
107
|
context "with_email_field" do
|
118
108
|
it "should find email field" do
|
119
|
-
rendered.
|
109
|
+
expect(rendered).to have_form("/books", :post) do
|
120
110
|
with_email_field('user[email]')
|
121
111
|
with_email_field('user[email]', 'email@example.com')
|
122
112
|
with_email_field('user[email_confirmation]', nil)
|
@@ -124,7 +114,7 @@ describe "have_form" do
|
|
124
114
|
end
|
125
115
|
|
126
116
|
it "should not find email field" do
|
127
|
-
rendered.
|
117
|
+
expect(rendered).to have_form("/books", :post) do
|
128
118
|
without_email_field('book[author]','Authorname')
|
129
119
|
without_email_field('user[emaiL]')
|
130
120
|
without_email_field('user[apocalyptiq]')
|
@@ -134,14 +124,14 @@ describe "have_form" do
|
|
134
124
|
|
135
125
|
context "with_url_field" do
|
136
126
|
it "should find url field" do
|
137
|
-
rendered.
|
127
|
+
expect(rendered).to have_form("/books", :post) do
|
138
128
|
with_url_field('user[url]')
|
139
129
|
with_url_field('user[url]', 'http://user.com')
|
140
130
|
end
|
141
131
|
end
|
142
132
|
|
143
133
|
it "should not find url field" do
|
144
|
-
rendered.
|
134
|
+
expect(rendered).to have_form("/books", :post) do
|
145
135
|
without_url_field('user[url]','Authorname')
|
146
136
|
without_url_field('user[emaiL]')
|
147
137
|
without_url_field('user[apocalyptiq]')
|
@@ -151,7 +141,7 @@ describe "have_form" do
|
|
151
141
|
|
152
142
|
context "with_number_field" do
|
153
143
|
it "should find number field" do
|
154
|
-
rendered.
|
144
|
+
expect(rendered).to have_form("/books", :post) do
|
155
145
|
with_number_field('number')
|
156
146
|
with_number_field('number_defined', 3)
|
157
147
|
with_number_field('number_defined', '3')
|
@@ -159,7 +149,7 @@ describe "have_form" do
|
|
159
149
|
end
|
160
150
|
|
161
151
|
it "should not find number field" do
|
162
|
-
rendered.
|
152
|
+
expect(rendered).to have_form("/books", :post) do
|
163
153
|
without_number_field('number',400)
|
164
154
|
without_number_field('number','400')
|
165
155
|
without_number_field('user[emaiL]')
|
@@ -170,29 +160,29 @@ describe "have_form" do
|
|
170
160
|
|
171
161
|
context "with_range_field" do
|
172
162
|
it "should find range field" do
|
173
|
-
rendered.
|
163
|
+
expect(rendered).to have_form("/books", :post) do
|
174
164
|
with_range_field('range1', 1, 3)
|
175
165
|
with_range_field('range1','1','3')
|
176
|
-
with_range_field('range2', 1, 3, :
|
177
|
-
with_range_field('range2', 1, 3, :
|
166
|
+
with_range_field('range2', 1, 3, with: { value: 2 } )
|
167
|
+
with_range_field('range2', 1, 3, with: { value: '2' } )
|
178
168
|
end
|
179
169
|
end
|
180
170
|
|
181
171
|
it "should not find range field" do
|
182
|
-
rendered.
|
172
|
+
expect(rendered).to have_form("/books", :post) do
|
183
173
|
without_range_field('number')
|
184
174
|
without_range_field('range1', 1, 5)
|
185
|
-
without_range_field('range2', 1, 3, :
|
175
|
+
without_range_field('range2', 1, 3, with: { value: 5 } )
|
186
176
|
end
|
187
177
|
end
|
188
178
|
end
|
189
179
|
|
190
180
|
context "with_date_field" do
|
191
181
|
it "should find date field" do
|
192
|
-
rendered.
|
182
|
+
expect(rendered).to have_form("/books", :post) do
|
193
183
|
with_date_field(:date)
|
194
184
|
with_date_field(:date, 'book_date')
|
195
|
-
with_date_field(:month, 'book_month', :
|
185
|
+
with_date_field(:month, 'book_month', with: { value: 5 })
|
196
186
|
with_date_field(:week,'book_week')
|
197
187
|
with_date_field(:time, 'book_time')
|
198
188
|
with_date_field(:datetime, 'book_datetime')
|
@@ -201,20 +191,20 @@ describe "have_form" do
|
|
201
191
|
end
|
202
192
|
|
203
193
|
it "should not find date field" do
|
204
|
-
rendered.
|
194
|
+
expect(rendered).to have_form("/books", :post) do
|
205
195
|
without_date_field(:date, 'book_something')
|
206
|
-
without_date_field(:month, 'book_month', :
|
196
|
+
without_date_field(:month, 'book_month', with: { value: 100500 })
|
207
197
|
end
|
208
198
|
end
|
209
199
|
|
210
200
|
it "should raise exception if wrong date field type specified" do
|
211
201
|
expect do
|
212
|
-
rendered.
|
202
|
+
expect(rendered).to have_form("/books", :post) do
|
213
203
|
without_date_field(:unknown, 'book_something')
|
214
204
|
end
|
215
205
|
end.to raise_error('unknown type `unknown` for date picker')
|
216
206
|
expect do
|
217
|
-
rendered.
|
207
|
+
expect(rendered).to have_form("/books", :post) do
|
218
208
|
with_date_field(:unknown, 'book_something')
|
219
209
|
end
|
220
210
|
end.to raise_error('unknown type `unknown` for date picker')
|
@@ -223,13 +213,13 @@ describe "have_form" do
|
|
223
213
|
|
224
214
|
context "with_password_field" do
|
225
215
|
it "should find password field" do
|
226
|
-
rendered.
|
216
|
+
expect(rendered).to have_form("/books", :post) do
|
227
217
|
with_password_field('user[password]')
|
228
218
|
end
|
229
219
|
end
|
230
220
|
|
231
221
|
it "should not find password field" do
|
232
|
-
rendered.
|
222
|
+
expect(rendered).to have_form("/books", :post) do
|
233
223
|
without_password_field('account[password]')
|
234
224
|
end
|
235
225
|
end
|
@@ -237,13 +227,13 @@ describe "have_form" do
|
|
237
227
|
|
238
228
|
context "with_file_field" do
|
239
229
|
it "should find file field" do
|
240
|
-
rendered.
|
230
|
+
expect(rendered).to have_form("/books", :post) do
|
241
231
|
with_file_field('form[file]')
|
242
232
|
end
|
243
233
|
end
|
244
234
|
|
245
235
|
it "should not find file field" do
|
246
|
-
rendered.
|
236
|
+
expect(rendered).to have_form("/books", :post) do
|
247
237
|
without_file_field('user[file]')
|
248
238
|
end
|
249
239
|
end
|
@@ -251,13 +241,13 @@ describe "have_form" do
|
|
251
241
|
|
252
242
|
context "with_text_area" do
|
253
243
|
it "should find text area" do
|
254
|
-
rendered.
|
244
|
+
expect(rendered).to have_form("/books", :post) do
|
255
245
|
with_text_area('book[description]')
|
256
246
|
end
|
257
247
|
end
|
258
248
|
|
259
249
|
it "should not find text area" do
|
260
|
-
rendered.
|
250
|
+
expect(rendered).to have_form("/books", :post) do
|
261
251
|
without_text_area('user[bio]')
|
262
252
|
end
|
263
253
|
end
|
@@ -265,14 +255,14 @@ describe "have_form" do
|
|
265
255
|
|
266
256
|
context "with_check_box" do
|
267
257
|
it "should find check box" do
|
268
|
-
rendered.
|
258
|
+
expect(rendered).to have_form("/books", :post) do
|
269
259
|
with_checkbox("book[still_in_print]")
|
270
260
|
with_checkbox("book[still_in_print]","1")
|
271
261
|
end
|
272
262
|
end
|
273
263
|
|
274
264
|
it "should not find check box" do
|
275
|
-
rendered.
|
265
|
+
expect(rendered).to have_form("/books", :post) do
|
276
266
|
without_checkbox("book[book]")
|
277
267
|
without_checkbox("book[still_in_print]","500")
|
278
268
|
end
|
@@ -281,13 +271,13 @@ describe "have_form" do
|
|
281
271
|
|
282
272
|
context "with_radio_button" do
|
283
273
|
it "should find radio button" do
|
284
|
-
rendered.
|
274
|
+
expect(rendered).to have_form("/books", :post) do
|
285
275
|
with_radio_button("form[name]","true")
|
286
276
|
end
|
287
277
|
end
|
288
278
|
|
289
279
|
it "should not find radio button" do
|
290
|
-
rendered.
|
280
|
+
expect(rendered).to have_form("/books", :post) do
|
291
281
|
without_radio_button("form[name]","100500")
|
292
282
|
without_radio_button("form[item]","false")
|
293
283
|
end
|
@@ -296,13 +286,13 @@ describe "have_form" do
|
|
296
286
|
|
297
287
|
context "with_submit" do
|
298
288
|
it "should find submit" do
|
299
|
-
rendered.
|
289
|
+
expect(rendered).to have_form("/books", :post) do
|
300
290
|
with_submit("Create Book")
|
301
291
|
end
|
302
292
|
end
|
303
293
|
|
304
294
|
it "should not find submit" do
|
305
|
-
rendered.
|
295
|
+
expect(rendered).to have_form("/books", :post) do
|
306
296
|
without_submit("Destroy Book")
|
307
297
|
end
|
308
298
|
end
|