rspec-html-matchers 0.9.2 → 0.9.3
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.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/features/step_definitions/steps.rb +3 -1
- data/features/support/env.rb +6 -2
- data/lib/rspec-html-matchers.rb +103 -88
- data/lib/rspec-html-matchers/have_tag.rb +141 -133
- data/lib/rspec-html-matchers/nokogiri_regexp_helper.rb +3 -5
- data/lib/rspec-html-matchers/nokogiri_text_helper.rb +3 -5
- data/lib/rspec-html-matchers/version.rb +3 -1
- data/spec/form_matchers_spec.rb +128 -126
- data/spec/have_empty_tag_spec.rb +5 -3
- data/spec/have_tag_spec.rb +152 -164
- data/spec/issues_spec.rb +27 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/asset_helpers.rb +5 -5
- data/spec/support/raise_spec_error_helper.rb +9 -7
- metadata +22 -6
@@ -1,52 +1,51 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'nokogiri'
|
5
5
|
|
6
|
+
module RSpecHtmlMatchers
|
6
7
|
# @api
|
7
8
|
# @private
|
8
|
-
class HaveTag
|
9
|
-
attr_reader :failure_message, :failure_message_when_negated
|
10
|
-
attr_reader :parent_scope, :current_scope
|
11
|
-
|
9
|
+
class HaveTag # rubocop:disable Metrics/ClassLength
|
12
10
|
DESCRIPTIONS = {
|
13
|
-
|
14
|
-
|
15
|
-
}
|
11
|
+
:have_at_least_1 => %(have at least 1 element matching "%s"),
|
12
|
+
:have_n => %(have %i element(s) matching "%s"),
|
13
|
+
}.freeze
|
16
14
|
|
17
15
|
MESSAGES = {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
:expected_count => %Q|expected following:\n%s\nto #{DESCRIPTIONS[:have_n]}, found %s.|,
|
22
|
-
:unexpected_count => %Q|expected following:\n%s\nto NOT have %i element(s) matching "%s", but found.|,
|
16
|
+
:expected_tag => %(expected following:\n%s\nto #{DESCRIPTIONS[:have_at_least_1]}, found 0.),
|
17
|
+
:unexpected_tag => %(expected following:\n%s\nto NOT have element matching "%s", found %s.),
|
23
18
|
|
24
|
-
|
25
|
-
|
19
|
+
:expected_count => %(expected following:\n%s\nto #{DESCRIPTIONS[:have_n]}, found %s.),
|
20
|
+
:unexpected_count => %(expected following:\n%s\nto NOT have %i element(s) matching "%s", but found.),
|
26
21
|
|
27
|
-
|
28
|
-
|
22
|
+
:expected_btw_count => %(expected following:\n%s\nto have at least %i and at most %i element(s) matching "%s", found %i.),
|
23
|
+
:unexpected_btw_count => %(expected following:\n%s\nto NOT have at least %i and at most %i element(s) matching "%s", but found %i.),
|
29
24
|
|
30
|
-
|
31
|
-
|
25
|
+
:expected_at_most => %(expected following:\n%s\nto have at most %i element(s) matching "%s", found %i.),
|
26
|
+
:unexpected_at_most => %(expected following:\n%s\nto NOT have at most %i element(s) matching "%s", but found %i.),
|
32
27
|
|
33
|
-
|
34
|
-
|
28
|
+
:expected_at_least => %(expected following:\n%s\nto have at least %i element(s) matching "%s", found %i.),
|
29
|
+
:unexpected_at_least => %(expected following:\n%s\nto NOT have at least %i element(s) matching "%s", but found %i.),
|
35
30
|
|
36
|
-
|
37
|
-
|
31
|
+
:expected_blank => %(expected following template to contain empty tag %s:\n%s),
|
32
|
+
:unexpected_blank => %(expected following template to contain tag %s with other tags:\n%s),
|
38
33
|
|
39
|
-
|
40
|
-
|
34
|
+
:expected_regexp => %(%s regexp expected within "%s" in following template:\n%s),
|
35
|
+
:unexpected_regexp => %(%s regexp unexpected within "%s" in following template:\n%s\nbut was found.),
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
:bad_range_error => %Q|Your :count range(%s) has no sence!|,
|
45
|
-
}
|
37
|
+
:expected_text => %("%s" expected within "%s" in following template:\n%s),
|
38
|
+
:unexpected_text => %("%s" unexpected within "%s" in following template:\n%s\nbut was found.),
|
46
39
|
|
40
|
+
:wrong_count_error => %(:count with :minimum or :maximum has no sence!),
|
41
|
+
:min_max_error => %(:minimum should be less than :maximum!),
|
42
|
+
:bad_range_error => %(Your :count range(%s) has no sence!),
|
43
|
+
}.freeze
|
47
44
|
|
48
|
-
def initialize tag, options={}, &block
|
49
|
-
@tag
|
45
|
+
def initialize tag, options = {}, &block
|
46
|
+
@tag = tag.to_s
|
47
|
+
@options = options
|
48
|
+
@block = block
|
50
49
|
|
51
50
|
if with_attrs = @options.delete(:with)
|
52
51
|
if classes = with_attrs.delete(:class)
|
@@ -66,30 +65,35 @@ module RSpecHtmlMatchers
|
|
66
65
|
end
|
67
66
|
|
68
67
|
validate_options!
|
69
|
-
|
68
|
+
organize_options!
|
70
69
|
end
|
71
70
|
|
72
|
-
|
71
|
+
attr_reader :failure_message
|
72
|
+
attr_reader :failure_message_when_negated
|
73
|
+
attr_reader :current_scope
|
74
|
+
|
75
|
+
def matches? src, &block
|
73
76
|
@block = block if block
|
74
77
|
|
75
|
-
|
78
|
+
src = src.html if defined?(Capybara::Session) && src.is_a?(Capybara::Session)
|
76
79
|
|
77
|
-
case
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
case src
|
81
|
+
when String
|
82
|
+
parent_scope = Nokogiri::HTML::DocumentFragment.parse(src)
|
83
|
+
@document = src
|
84
|
+
else
|
85
|
+
parent_scope = src.current_scope
|
86
|
+
@document = parent_scope.to_html
|
84
87
|
end
|
88
|
+
|
85
89
|
@current_scope = begin
|
86
|
-
|
90
|
+
parent_scope.css(tag)
|
87
91
|
# on jruby this produce exception if css was not found:
|
88
92
|
# undefined method `decorate' for nil:NilClass
|
89
93
|
rescue NoMethodError
|
90
94
|
Nokogiri::XML::NodeSet.new(Nokogiri::XML::Document.new)
|
91
95
|
end
|
92
|
-
if tag_presents?
|
96
|
+
if tag_presents? && proper_content? && count_right?
|
93
97
|
@block.call(self) if @block
|
94
98
|
true
|
95
99
|
else
|
@@ -97,60 +101,74 @@ module RSpecHtmlMatchers
|
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
100
|
-
def document
|
101
|
-
@document
|
102
|
-
end
|
103
|
-
|
104
104
|
def description
|
105
|
-
# TODO should it be more complicated?
|
106
|
-
if
|
107
|
-
DESCRIPTIONS[:have_n]
|
105
|
+
# TODO: should it be more complicated?
|
106
|
+
if options.key?(:count)
|
107
|
+
format(DESCRIPTIONS[:have_n], options[:count], tag)
|
108
108
|
else
|
109
|
-
DESCRIPTIONS[:have_at_least_1] %
|
109
|
+
DESCRIPTIONS[:have_at_least_1] % tag
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
private
|
114
114
|
|
115
|
-
|
115
|
+
attr_reader :tag
|
116
|
+
attr_reader :options
|
117
|
+
attr_reader :document
|
118
|
+
|
119
|
+
def classes_to_selector classes
|
116
120
|
case classes
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
+
when Array
|
122
|
+
classes.join('.')
|
123
|
+
when String
|
124
|
+
classes.gsub(/\s+/, '.')
|
121
125
|
end
|
122
126
|
end
|
123
127
|
|
124
128
|
def tag_presents?
|
125
|
-
if
|
126
|
-
@count =
|
127
|
-
|
128
|
-
true
|
129
|
+
if current_scope.first
|
130
|
+
@count = current_scope.count
|
131
|
+
match_succeeded! :unexpected_tag, document, tag, @count
|
129
132
|
else
|
130
|
-
|
131
|
-
false
|
133
|
+
match_failed! :expected_tag, document, tag
|
132
134
|
end
|
133
135
|
end
|
134
136
|
|
135
|
-
def count_right?
|
136
|
-
case
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
137
|
+
def count_right? # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
138
|
+
case options[:count]
|
139
|
+
when Integer
|
140
|
+
if @count == options[:count]
|
141
|
+
match_succeeded! :unexpected_count, document, @count, tag
|
142
|
+
else
|
143
|
+
match_failed! :expected_count, document, options[:count], tag, @count
|
144
|
+
end
|
145
|
+
when Range
|
146
|
+
if options[:count].member? @count
|
147
|
+
match_succeeded! :unexpected_btw_count, document, options[:count].min, options[:count].max, tag, @count
|
148
|
+
else
|
149
|
+
match_failed! :expected_btw_count, document, options[:count].min, options[:count].max, tag, @count
|
150
|
+
end
|
151
|
+
when nil
|
152
|
+
if options[:maximum]
|
153
|
+
if @count <= options[:maximum]
|
154
|
+
match_succeeded! :unexpected_at_most, document, options[:maximum], tag, @count
|
146
155
|
else
|
147
|
-
|
156
|
+
match_failed! :expected_at_most, document, options[:maximum], tag, @count
|
148
157
|
end
|
158
|
+
elsif options[:minimum]
|
159
|
+
if @count >= options[:minimum]
|
160
|
+
match_succeeded! :unexpected_at_least, document, options[:minimum], tag, @count
|
161
|
+
else
|
162
|
+
match_failed! :expected_at_least, document, options[:minimum], tag, @count
|
163
|
+
end
|
164
|
+
else
|
165
|
+
true
|
166
|
+
end
|
149
167
|
end
|
150
168
|
end
|
151
169
|
|
152
170
|
def proper_content?
|
153
|
-
if
|
171
|
+
if options.key?(:blank)
|
154
172
|
maybe_empty?
|
155
173
|
else
|
156
174
|
text_right?
|
@@ -158,50 +176,36 @@ module RSpecHtmlMatchers
|
|
158
176
|
end
|
159
177
|
|
160
178
|
def maybe_empty?
|
161
|
-
if
|
162
|
-
|
163
|
-
@failure_message = MESSAGES[:expected_blank] % [@tag, @document]
|
164
|
-
else
|
165
|
-
@failure_message_when_negated = MESSAGES[:expected_blank] % [@tag, @document]
|
166
|
-
@failure_message = MESSAGES[:unexpected_blank] % [@tag, @document]
|
167
|
-
end
|
168
|
-
|
169
|
-
if @options[:blank]
|
170
|
-
@current_scope.children.empty?
|
179
|
+
if options[:blank] && current_scope.children.empty?
|
180
|
+
match_succeeded! :unexpected_blank, tag, document
|
171
181
|
else
|
172
|
-
|
182
|
+
match_failed! :expected_blank, tag, document
|
173
183
|
end
|
174
184
|
end
|
175
185
|
|
176
186
|
def text_right?
|
177
|
-
return true unless
|
178
|
-
|
179
|
-
case text
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
@failure_message_when_negated = MESSAGES[:unexpected_regexp] % [text.inspect,@tag,@document]
|
185
|
-
true
|
186
|
-
else
|
187
|
-
@failure_message = MESSAGES[:expected_regexp] % [text.inspect,@tag,@document]
|
188
|
-
false
|
189
|
-
end
|
187
|
+
return true unless options[:text]
|
188
|
+
|
189
|
+
case text = options[:text]
|
190
|
+
when Regexp
|
191
|
+
new_scope = current_scope.css(':regexp()', NokogiriRegexpHelper.new(text))
|
192
|
+
if new_scope.empty?
|
193
|
+
match_failed! :expected_regexp, text.inspect, tag, document
|
190
194
|
else
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
195
|
+
@count = new_scope.count
|
196
|
+
match_succeeded! :unexpected_regexp, text.inspect, tag, document
|
197
|
+
end
|
198
|
+
else
|
199
|
+
new_scope = current_scope.css(':content()', NokogiriTextHelper.new(text, options[:squeeze_text]))
|
200
|
+
if new_scope.empty?
|
201
|
+
match_failed! :expected_text, text, tag, document
|
202
|
+
else
|
203
|
+
@count = new_scope.count
|
204
|
+
match_succeeded! :unexpected_text, text, tag, document
|
205
|
+
end
|
200
206
|
end
|
201
207
|
end
|
202
208
|
|
203
|
-
protected
|
204
|
-
|
205
209
|
def validate_options!
|
206
210
|
validate_text_options!
|
207
211
|
validate_count_presence!
|
@@ -211,56 +215,60 @@ module RSpecHtmlMatchers
|
|
211
215
|
|
212
216
|
def validate_text_options!
|
213
217
|
# TODO: test these options validations
|
214
|
-
if
|
215
|
-
raise ':text option is not accepted when :blank => true'
|
218
|
+
if options.key?(:blank) && options[:blank] && options.key?(:text) # rubocop:disable Style/GuardClause, Style/IfUnlessModifier
|
219
|
+
raise ':text option is not accepted when :blank => true'
|
216
220
|
end
|
217
221
|
end
|
218
222
|
|
219
223
|
def validate_count_presence!
|
220
|
-
raise 'wrong :count specified' unless [Range, NilClass].include?(
|
224
|
+
raise 'wrong :count specified' unless [Range, NilClass].include?(options[:count].class) || options[:count].is_a?(Integer)
|
221
225
|
|
222
226
|
[:min, :minimum, :max, :maximum].each do |key|
|
223
|
-
raise MESSAGES[:wrong_count_error] if
|
227
|
+
raise MESSAGES[:wrong_count_error] if options.key?(key) && options.key?(:count)
|
224
228
|
end
|
225
229
|
end
|
226
230
|
|
227
231
|
def validate_count_when_set_min_max!
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
rescue ArgumentError # 2 < nil
|
232
|
-
end
|
232
|
+
raise MESSAGES[:min_max_error] if options[:minimum] > options[:maximum]
|
233
|
+
rescue NoMethodError # nil > 4 # rubocop:disable Lint/HandleExceptions
|
234
|
+
rescue ArgumentError # 2 < nil # rubocop:disable Lint/HandleExceptions
|
233
235
|
end
|
234
236
|
|
235
237
|
def validate_count_when_set_range!
|
236
238
|
begin
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
raise MESSAGES[:bad_range_error] % [@options[:count].to_s]
|
241
|
-
end
|
242
|
-
rescue TypeError # fix for 1.8.7 for 'rescue ArgumentError, "comparison of String with"' stroke
|
243
|
-
raise MESSAGES[:bad_range_error] % [@options[:count].to_s]
|
239
|
+
raise format(MESSAGES[:bad_range_error], options[:count].to_s) if count_is_range_but_no_min?
|
240
|
+
rescue ArgumentError, 'comparison of String with' # if options[:count] == 'a'..'z' # rubocop:disable Lint/RescueType
|
241
|
+
raise format(MESSAGES[:bad_range_error], options[:count].to_s)
|
244
242
|
end
|
243
|
+
rescue TypeError # fix for 1.8.7 for 'rescue ArgumentError, "comparison of String with"' stroke
|
244
|
+
raise format(MESSAGES[:bad_range_error], options[:count].to_s)
|
245
245
|
end
|
246
246
|
|
247
247
|
def count_is_range_but_no_min?
|
248
|
-
|
249
|
-
|
248
|
+
options[:count].is_a?(Range) &&
|
249
|
+
(options[:count].min.nil? || (options[:count].min < 0))
|
250
250
|
end
|
251
251
|
|
252
|
-
def
|
252
|
+
def organize_options!
|
253
253
|
@options[:minimum] ||= @options.delete(:min)
|
254
254
|
@options[:maximum] ||= @options.delete(:max)
|
255
255
|
|
256
|
-
@options[:text] = @options[:text].to_s if @options.
|
256
|
+
@options[:text] = @options[:text].to_s if @options.key?(:text) && !@options[:text].is_a?(Regexp)
|
257
257
|
|
258
|
-
if @options.
|
258
|
+
if @options.key?(:seen) && !@options[:seen].is_a?(Regexp) # rubocop:disable Style/GuardClause
|
259
259
|
@options[:text] = @options[:seen].to_s
|
260
260
|
@options[:squeeze_text] = true
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
|
-
|
264
|
+
def match_succeeded! message, *args
|
265
|
+
@failure_message_when_negated = format MESSAGES[message], *args
|
266
|
+
true
|
267
|
+
end
|
265
268
|
|
269
|
+
def match_failed! message, *args
|
270
|
+
@failure_message = format MESSAGES[message], *args
|
271
|
+
false
|
272
|
+
end
|
273
|
+
end
|
266
274
|
end
|
@@ -1,13 +1,12 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module RSpecHtmlMatchers
|
5
|
-
|
6
5
|
# @api
|
7
6
|
# @private
|
8
7
|
# for nokogiri regexp matching
|
9
8
|
class NokogiriRegexpHelper
|
10
|
-
def initialize
|
9
|
+
def initialize regex
|
11
10
|
@regex = regex
|
12
11
|
end
|
13
12
|
|
@@ -15,5 +14,4 @@ module RSpecHtmlMatchers
|
|
15
14
|
node_set.find_all { |node| node.content =~ @regex }
|
16
15
|
end
|
17
16
|
end
|
18
|
-
|
19
|
-
end
|
17
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
1
|
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module RSpecHtmlMatchers
|
5
|
-
|
6
5
|
# @api
|
7
6
|
# @private
|
8
7
|
class NokogiriTextHelper
|
@@ -16,11 +15,10 @@ module RSpecHtmlMatchers
|
|
16
15
|
def content node_set
|
17
16
|
node_set.find_all do |node|
|
18
17
|
actual_content = node.content.gsub(NON_BREAKING_SPACE, ' ')
|
19
|
-
actual_content = node.content.
|
18
|
+
actual_content = node.content.gsub(/\s+/, ' ').strip if @squeeze_text
|
20
19
|
|
21
20
|
actual_content == @text
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
|
-
|
26
|
-
end
|
24
|
+
end
|
data/spec/form_matchers_spec.rb
CHANGED
@@ -1,53 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe 'have_form' do
|
4
6
|
asset 'form'
|
5
7
|
|
6
|
-
context
|
7
|
-
it
|
8
|
+
context 'without &block' do
|
9
|
+
it 'should find form' do
|
8
10
|
# sanity check
|
9
|
-
expect(rendered).to have_form(
|
10
|
-
expect(rendered).to have_form(
|
11
|
+
expect(rendered).to have_form('/books', :post)
|
12
|
+
expect(rendered).to have_form('/books', 'post', :with => { :id => 'new_book', :class => %w[book formtastic] })
|
11
13
|
end
|
12
14
|
|
13
|
-
it
|
14
|
-
expect(rendered).to_not have_form(
|
15
|
-
expect(rendered).to_not have_form(
|
15
|
+
it 'should not find form' do
|
16
|
+
expect(rendered).to_not have_form('/some_url', :post)
|
17
|
+
expect(rendered).to_not have_form('/books', :get)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
context
|
20
|
-
context
|
21
|
-
it
|
22
|
-
expect(rendered).to have_form(
|
23
|
-
with_select(
|
24
|
-
with_select(
|
21
|
+
context 'with &block' do
|
22
|
+
context 'with_select' do
|
23
|
+
it 'should find select' do
|
24
|
+
expect(rendered).to have_form('/books', :post) do
|
25
|
+
with_select('book[publisher_id]', :with => { :id => 'book_publisher_id' })
|
26
|
+
with_select('book[publisher_id]', :with => { :id => 'book_publisher_id' })
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
it
|
29
|
-
expect(rendered).to have_form(
|
30
|
-
without_select(
|
31
|
-
without_select(
|
30
|
+
it 'should not find select' do
|
31
|
+
expect(rendered).to have_form('/books', :post) do
|
32
|
+
without_select('book[publisher_id]', :with => { :id => 'other_id' })
|
33
|
+
without_select('koob[publisher_id]', :with => { :id => 'book_publisher_id' })
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
|
-
context
|
36
|
-
it
|
37
|
-
expect(rendered).to have_form(
|
38
|
-
with_select(
|
37
|
+
context 'with_option' do
|
38
|
+
it 'should find options' do
|
39
|
+
expect(rendered).to have_form('/books', :post) do
|
40
|
+
with_select('book[publisher_id]') do
|
39
41
|
with_option(nil)
|
40
|
-
with_option(
|
41
|
-
with_option(/sitepoint/,2)
|
42
|
+
with_option('The Pragmatic Bookshelf', :selected => true)
|
43
|
+
with_option(/sitepoint/, 2)
|
42
44
|
with_option("O'Reilly", 3, :selected => false)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
it
|
48
|
-
expect(rendered).to have_form(
|
49
|
-
with_select(
|
50
|
-
without_option(
|
49
|
+
it 'should not find options' do
|
50
|
+
expect(rendered).to have_form('/books', :post) do
|
51
|
+
with_select('book[publisher_id]') do
|
52
|
+
without_option('blah blah')
|
51
53
|
without_option("O'Reilly", 3, :selected => true)
|
52
54
|
without_option("O'Reilly", 100500)
|
53
55
|
end
|
@@ -55,245 +57,245 @@ describe "have_form" do
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
context
|
59
|
-
it
|
60
|
-
expect(rendered).to have_form(
|
61
|
-
with_button(
|
60
|
+
context 'with_button' do
|
61
|
+
it 'should find button' do
|
62
|
+
expect(rendered).to have_form('/books', :post) do
|
63
|
+
with_button('Cancel Book')
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
|
-
it
|
66
|
-
expect(rendered).to have_form(
|
67
|
-
without_button(
|
67
|
+
it 'should not find button' do
|
68
|
+
expect(rendered).to have_form('/books', :post) do
|
69
|
+
without_button('Create Book')
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
73
|
-
context
|
74
|
-
it
|
75
|
-
expect(rendered).to have_form(
|
76
|
-
with_hidden_field(
|
77
|
-
with_hidden_field(
|
75
|
+
context 'with_hidden_field' do
|
76
|
+
it 'should find hidden field' do
|
77
|
+
expect(rendered).to have_form('/books', :post) do
|
78
|
+
with_hidden_field('authenticity_token')
|
79
|
+
with_hidden_field('authenticity_token', '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE=')
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
|
-
it
|
82
|
-
expect(rendered).to have_form(
|
83
|
+
it 'should not find hidden field' do
|
84
|
+
expect(rendered).to have_form('/books', :post) do
|
83
85
|
without_hidden_field('user_id')
|
84
86
|
without_hidden_field('authenticity_token', 'blabla')
|
85
87
|
end
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
89
|
-
context
|
90
|
-
it
|
91
|
-
expect(rendered).to have_form(
|
91
|
+
context 'with_text_field' do
|
92
|
+
it 'should find text field' do
|
93
|
+
expect(rendered).to have_form('/books', :post) do
|
92
94
|
with_text_field('book[title]')
|
93
|
-
with_text_field('book[title]',nil)
|
94
|
-
with_text_field('book[author]','Authorname')
|
95
|
+
with_text_field('book[title]', nil)
|
96
|
+
with_text_field('book[author]', 'Authorname')
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
98
|
-
it
|
99
|
-
expect(rendered).to have_form(
|
100
|
-
without_text_field('book[title]','title does not exist')
|
100
|
+
it 'should not find text field' do
|
101
|
+
expect(rendered).to have_form('/books', :post) do
|
102
|
+
without_text_field('book[title]', 'title does not exist')
|
101
103
|
without_text_field('book[authoRR]')
|
102
104
|
without_text_field('book[blabla]')
|
103
105
|
end
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
107
|
-
context
|
108
|
-
it
|
109
|
-
expect(rendered).to have_form(
|
109
|
+
context 'with_email_field' do
|
110
|
+
it 'should find email field' do
|
111
|
+
expect(rendered).to have_form('/books', :post) do
|
110
112
|
with_email_field('user[email]')
|
111
113
|
with_email_field('user[email]', 'email@example.com')
|
112
114
|
with_email_field('user[email_confirmation]', nil)
|
113
115
|
end
|
114
116
|
end
|
115
117
|
|
116
|
-
it
|
117
|
-
expect(rendered).to have_form(
|
118
|
-
without_email_field('book[author]','Authorname')
|
118
|
+
it 'should not find email field' do
|
119
|
+
expect(rendered).to have_form('/books', :post) do
|
120
|
+
without_email_field('book[author]', 'Authorname')
|
119
121
|
without_email_field('user[emaiL]')
|
120
122
|
without_email_field('user[apocalyptiq]')
|
121
123
|
end
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
125
|
-
context
|
126
|
-
it
|
127
|
-
expect(rendered).to have_form(
|
127
|
+
context 'with_url_field' do
|
128
|
+
it 'should find url field' do
|
129
|
+
expect(rendered).to have_form('/books', :post) do
|
128
130
|
with_url_field('user[url]')
|
129
131
|
with_url_field('user[url]', 'http://user.com')
|
130
132
|
end
|
131
133
|
end
|
132
134
|
|
133
|
-
it
|
134
|
-
expect(rendered).to have_form(
|
135
|
-
without_url_field('user[url]','Authorname')
|
135
|
+
it 'should not find url field' do
|
136
|
+
expect(rendered).to have_form('/books', :post) do
|
137
|
+
without_url_field('user[url]', 'Authorname')
|
136
138
|
without_url_field('user[emaiL]')
|
137
139
|
without_url_field('user[apocalyptiq]')
|
138
140
|
end
|
139
141
|
end
|
140
142
|
end
|
141
143
|
|
142
|
-
context
|
143
|
-
it
|
144
|
-
expect(rendered).to have_form(
|
144
|
+
context 'with_number_field' do
|
145
|
+
it 'should find number field' do
|
146
|
+
expect(rendered).to have_form('/books', :post) do
|
145
147
|
with_number_field('number')
|
146
148
|
with_number_field('number_defined', 3)
|
147
149
|
with_number_field('number_defined', '3')
|
148
150
|
end
|
149
151
|
end
|
150
152
|
|
151
|
-
it
|
152
|
-
expect(rendered).to have_form(
|
153
|
-
without_number_field('number',400)
|
154
|
-
without_number_field('number','400')
|
153
|
+
it 'should not find number field' do
|
154
|
+
expect(rendered).to have_form('/books', :post) do
|
155
|
+
without_number_field('number', 400)
|
156
|
+
without_number_field('number', '400')
|
155
157
|
without_number_field('user[emaiL]')
|
156
158
|
without_number_field('user[apocalyptiq]')
|
157
159
|
end
|
158
160
|
end
|
159
161
|
end
|
160
162
|
|
161
|
-
context
|
162
|
-
it
|
163
|
-
expect(rendered).to have_form(
|
163
|
+
context 'with_range_field' do
|
164
|
+
it 'should find range field' do
|
165
|
+
expect(rendered).to have_form('/books', :post) do
|
164
166
|
with_range_field('range1', 1, 3)
|
165
|
-
with_range_field('range1','1','3')
|
166
|
-
with_range_field('range2', 1, 3, :with => { :value => 2 }
|
167
|
-
with_range_field('range2', 1, 3, :with => { :value => '2' }
|
167
|
+
with_range_field('range1', '1', '3')
|
168
|
+
with_range_field('range2', 1, 3, :with => { :value => 2 })
|
169
|
+
with_range_field('range2', 1, 3, :with => { :value => '2' })
|
168
170
|
end
|
169
171
|
end
|
170
172
|
|
171
|
-
it
|
172
|
-
expect(rendered).to have_form(
|
173
|
+
it 'should not find range field' do
|
174
|
+
expect(rendered).to have_form('/books', :post) do
|
173
175
|
without_range_field('number')
|
174
176
|
without_range_field('range1', 1, 5)
|
175
|
-
without_range_field('range2', 1, 3, :with => { :value => 5 }
|
177
|
+
without_range_field('range2', 1, 3, :with => { :value => 5 })
|
176
178
|
end
|
177
179
|
end
|
178
180
|
end
|
179
181
|
|
180
|
-
context
|
181
|
-
it
|
182
|
-
expect(rendered).to have_form(
|
182
|
+
context 'with_date_field' do
|
183
|
+
it 'should find date field' do
|
184
|
+
expect(rendered).to have_form('/books', :post) do
|
183
185
|
with_date_field(:date)
|
184
186
|
with_date_field(:date, 'book_date')
|
185
187
|
with_date_field(:month, 'book_month', :with => { :value => 5 })
|
186
|
-
with_date_field(:week,'book_week')
|
188
|
+
with_date_field(:week, 'book_week')
|
187
189
|
with_date_field(:time, 'book_time')
|
188
190
|
with_date_field(:datetime, 'book_datetime')
|
189
191
|
with_date_field('datetime-local', 'book_datetime_local')
|
190
192
|
end
|
191
193
|
end
|
192
194
|
|
193
|
-
it
|
194
|
-
expect(rendered).to have_form(
|
195
|
+
it 'should not find date field' do
|
196
|
+
expect(rendered).to have_form('/books', :post) do
|
195
197
|
without_date_field(:date, 'book_something')
|
196
198
|
without_date_field(:month, 'book_month', :with => { :value => 100500 })
|
197
199
|
end
|
198
200
|
end
|
199
201
|
|
200
|
-
it
|
202
|
+
it 'should raise exception if wrong date field type specified' do
|
201
203
|
expect do
|
202
|
-
expect(rendered).to have_form(
|
204
|
+
expect(rendered).to have_form('/books', :post) do
|
203
205
|
without_date_field(:unknown, 'book_something')
|
204
206
|
end
|
205
207
|
end.to raise_error('unknown type `unknown` for date picker')
|
206
208
|
expect do
|
207
|
-
expect(rendered).to have_form(
|
209
|
+
expect(rendered).to have_form('/books', :post) do
|
208
210
|
with_date_field(:unknown, 'book_something')
|
209
211
|
end
|
210
212
|
end.to raise_error('unknown type `unknown` for date picker')
|
211
213
|
end
|
212
214
|
end
|
213
215
|
|
214
|
-
context
|
215
|
-
it
|
216
|
-
expect(rendered).to have_form(
|
216
|
+
context 'with_password_field' do
|
217
|
+
it 'should find password field' do
|
218
|
+
expect(rendered).to have_form('/books', :post) do
|
217
219
|
with_password_field('user[password]')
|
218
220
|
end
|
219
221
|
end
|
220
222
|
|
221
|
-
it
|
222
|
-
expect(rendered).to have_form(
|
223
|
+
it 'should not find password field' do
|
224
|
+
expect(rendered).to have_form('/books', :post) do
|
223
225
|
without_password_field('account[password]')
|
224
226
|
end
|
225
227
|
end
|
226
228
|
end
|
227
229
|
|
228
|
-
context
|
229
|
-
it
|
230
|
-
expect(rendered).to have_form(
|
230
|
+
context 'with_file_field' do
|
231
|
+
it 'should find file field' do
|
232
|
+
expect(rendered).to have_form('/books', :post) do
|
231
233
|
with_file_field('form[file]')
|
232
234
|
end
|
233
235
|
end
|
234
236
|
|
235
|
-
it
|
236
|
-
expect(rendered).to have_form(
|
237
|
+
it 'should not find file field' do
|
238
|
+
expect(rendered).to have_form('/books', :post) do
|
237
239
|
without_file_field('user[file]')
|
238
240
|
end
|
239
241
|
end
|
240
242
|
end
|
241
243
|
|
242
|
-
context
|
243
|
-
it
|
244
|
-
expect(rendered).to have_form(
|
244
|
+
context 'with_text_area' do
|
245
|
+
it 'should find text area' do
|
246
|
+
expect(rendered).to have_form('/books', :post) do
|
245
247
|
with_text_area('book[description]')
|
246
248
|
end
|
247
249
|
end
|
248
250
|
|
249
|
-
it
|
250
|
-
expect(rendered).to have_form(
|
251
|
+
it 'should not find text area' do
|
252
|
+
expect(rendered).to have_form('/books', :post) do
|
251
253
|
without_text_area('user[bio]')
|
252
254
|
end
|
253
255
|
end
|
254
256
|
end
|
255
257
|
|
256
|
-
context
|
257
|
-
it
|
258
|
-
expect(rendered).to have_form(
|
259
|
-
with_checkbox(
|
260
|
-
with_checkbox(
|
258
|
+
context 'with_check_box' do
|
259
|
+
it 'should find check box' do
|
260
|
+
expect(rendered).to have_form('/books', :post) do
|
261
|
+
with_checkbox('book[still_in_print]')
|
262
|
+
with_checkbox('book[still_in_print]', '1')
|
261
263
|
end
|
262
264
|
end
|
263
265
|
|
264
|
-
it
|
265
|
-
expect(rendered).to have_form(
|
266
|
-
without_checkbox(
|
267
|
-
without_checkbox(
|
266
|
+
it 'should not find check box' do
|
267
|
+
expect(rendered).to have_form('/books', :post) do
|
268
|
+
without_checkbox('book[book]')
|
269
|
+
without_checkbox('book[still_in_print]', '500')
|
268
270
|
end
|
269
271
|
end
|
270
272
|
end
|
271
273
|
|
272
|
-
context
|
273
|
-
it
|
274
|
-
expect(rendered).to have_form(
|
275
|
-
with_radio_button(
|
274
|
+
context 'with_radio_button' do
|
275
|
+
it 'should find radio button' do
|
276
|
+
expect(rendered).to have_form('/books', :post) do
|
277
|
+
with_radio_button('form[name]', 'true')
|
276
278
|
end
|
277
279
|
end
|
278
280
|
|
279
|
-
it
|
280
|
-
expect(rendered).to have_form(
|
281
|
-
without_radio_button(
|
282
|
-
without_radio_button(
|
281
|
+
it 'should not find radio button' do
|
282
|
+
expect(rendered).to have_form('/books', :post) do
|
283
|
+
without_radio_button('form[name]', '100500')
|
284
|
+
without_radio_button('form[item]', 'false')
|
283
285
|
end
|
284
286
|
end
|
285
287
|
end
|
286
288
|
|
287
|
-
context
|
288
|
-
it
|
289
|
-
expect(rendered).to have_form(
|
290
|
-
with_submit(
|
289
|
+
context 'with_submit' do
|
290
|
+
it 'should find submit' do
|
291
|
+
expect(rendered).to have_form('/books', :post) do
|
292
|
+
with_submit('Create Book')
|
291
293
|
end
|
292
294
|
end
|
293
295
|
|
294
|
-
it
|
295
|
-
expect(rendered).to have_form(
|
296
|
-
without_submit(
|
296
|
+
it 'should not find submit' do
|
297
|
+
expect(rendered).to have_form('/books', :post) do
|
298
|
+
without_submit('Destroy Book')
|
297
299
|
end
|
298
300
|
end
|
299
301
|
end
|