Module: RSpec::Matchers
- Defined in:
- lib/rspec2-rails-views-matchers.rb
Constant Summary
- DATE_FIELD_TYPES =
%w( date month week time datetime datetime-local )
Instance Method Summary (collapse)
- - (Object) have_form(action_url, method, options = {}, &block)
-
- (Object) have_tag(tag, options = {}) { ... }
have_tag matcher.
- - (Object) with_button(text, value = nil, options = {})
- - (Object) with_checkbox(name, value = nil)
- - (Object) with_date_field(date_field_type, name = nil, options = {})
- - (Object) with_email_field(name, value = nil)
- - (Object) with_file_field(name)
- - (Object) with_hidden_field(name, value = nil)
- - (Object) with_number_field(name, value = nil)
- - (Object) with_option(text, value = nil, options = {})
- - (Object) with_password_field(name)
- - (Object) with_radio_button(name, value)
- - (Object) with_range_field(name, min, max, options = {})
- - (Object) with_select(name, options = {}, &block)
- - (Object) with_submit(value)
-
- (Object) with_tag(tag, options = {}) { ... }
with_tag matcher.
- - (Object) with_text_area(name)
- - (Object) with_text_field(name, value = nil)
- - (Object) with_url_field(name, value = nil)
- - (Object) without_button(text, value = nil, options = {})
- - (Object) without_checkbox(name, value = nil)
- - (Object) without_date_field(date_field_type, name = nil, options = {})
- - (Object) without_email_field(name, value = nil)
- - (Object) without_file_field(name)
- - (Object) without_hidden_field(name, value = nil)
- - (Object) without_number_field(name, value = nil)
- - (Object) without_option(text, value = nil, options = {})
- - (Object) without_password_field(name)
- - (Object) without_radio_button(name, value)
- - (Object) without_range_field(name, min = nil, max = nil, options = {})
- - (Object) without_select(name, options = {}, &block)
- - (Object) without_submit(value)
-
- (Object) without_tag(tag, options = {}) { ... }
without_tag matcher.
- - (Object) without_text_area(name)
- - (Object) without_text_field(name, value = nil)
- - (Object) without_url_field(name, value = nil)
Instance Method Details
- (Object) have_form(action_url, method, options = {}, &block)
232 233 234 235 236 237 238 239 |
# File 'lib/rspec2-rails-views-matchers.rb', line 232 def have_form action_url, method, ={}, &block [:with] ||= {} id = [:with].delete(:id) tag = 'form'; tag += '#'+id if id [:with].merge!(:action => action_url) [:with].merge!(:method => method.to_s) have_tag tag, , &block end |
- (Object) have_tag(tag, options = {}) { ... }
have_tag matcher
209 210 211 212 213 214 |
# File 'lib/rspec2-rails-views-matchers.rb', line 209 def have_tag tag, ={}, &block if .kind_of? String = { :text => } end @__current_scope_for_nokogiri_matcher = NokogiriMatcher.new(tag, , &block) end |
- (Object) with_button(text, value = nil, options = {})
433 434 435 436 437 438 439 440 441 442 |
# File 'lib/rspec2-rails-views-matchers.rb', line 433 def text, value=nil, ={} [:with] ||= {} if value.is_a?(Hash) .merge!(value) value=nil end [:with].merge!(:value => value.to_s) if value .merge!(:text => text) if text @__current_scope_for_nokogiri_matcher.should have_tag('button', ) end |
- (Object) with_checkbox(name, value = nil)
361 362 363 364 365 |
# File 'lib/rspec2-rails-views-matchers.rb', line 361 def with_checkbox name, value=nil = { :with => { :name => name, :type => 'checkbox' } } [:with].merge!(:value => value) if value should_have_input() end |
- (Object) with_date_field(date_field_type, name = nil, options = {})
315 316 317 318 319 320 321 |
# File 'lib/rspec2-rails-views-matchers.rb', line 315 def with_date_field date_field_type, name=nil, ={} date_field_type = date_field_type.to_s raise "unknown type `#{date_field_type}` for date picker" unless DATE_FIELD_TYPES.include?(date_field_type) = { :with => { :type => date_field_type.to_s }.merge(.delete(:with)||{}) } [:with].merge!(:name => name.to_s) if name should_have_input() end |
- (Object) with_email_field(name, value = nil)
265 266 267 268 269 |
# File 'lib/rspec2-rails-views-matchers.rb', line 265 def with_email_field name, value=nil = { :with => { :name => name, :type => 'email' } } [:with].merge!(:value => value) if value should_have_input() end |
- (Object) with_file_field(name)
341 342 343 344 |
# File 'lib/rspec2-rails-views-matchers.rb', line 341 def with_file_field name = { :with => { :name => name, :type => 'file' } } should_have_input() end |
- (Object) with_hidden_field(name, value = nil)
241 242 243 244 245 |
# File 'lib/rspec2-rails-views-matchers.rb', line 241 def with_hidden_field name, value=nil = { :with => { :name => name, :type => 'hidden' } } [:with].merge!(:value => value) if value should_have_input() end |
- (Object) with_number_field(name, value = nil)
289 290 291 292 293 |
# File 'lib/rspec2-rails-views-matchers.rb', line 289 def with_number_field name, value=nil = { :with => { :name => name, :type => 'number' } } [:with].merge!(:value => value.to_s) if value should_have_input() end |
- (Object) with_option(text, value = nil, options = {})
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/rspec2-rails-views-matchers.rb', line 401 def with_option text, value=nil, ={} [:with] ||= {} if value.is_a?(Hash) .merge!(value) value=nil end tag='option' [:with].merge!(:value => value.to_s) if value if [:selected] [:with].merge!(:selected => "selected") end .delete(:selected) .merge!(:text => text) if text @__current_scope_for_nokogiri_matcher.should have_tag(tag, ) end |
- (Object) with_password_field(name)
331 332 333 334 |
# File 'lib/rspec2-rails-views-matchers.rb', line 331 def with_password_field name = { :with => { :name => name, :type => 'password' } } should_have_input() end |
- (Object) with_radio_button(name, value)
373 374 375 376 377 |
# File 'lib/rspec2-rails-views-matchers.rb', line 373 def name, value = { :with => { :name => name, :type => 'radio' } } [:with].merge!(:value => value) should_have_input() end |
- (Object) with_range_field(name, min, max, options = {})
301 302 303 304 |
# File 'lib/rspec2-rails-views-matchers.rb', line 301 def with_range_field name, min, max, ={} = { :with => { :name => name, :type => 'range', :min => min.to_s, :max => max.to_s }.merge(.delete(:with)||{}) } should_have_input() end |
- (Object) with_select(name, options = {}, &block)
385 386 387 388 389 390 391 |
# File 'lib/rspec2-rails-views-matchers.rb', line 385 def with_select name, ={}, &block [:with] ||= {} id = [:with].delete(:id) tag='select'; tag += '#'+id if id [:with].merge!(:name => name) @__current_scope_for_nokogiri_matcher.should have_tag(tag, , &block) end |
- (Object) with_submit(value)
455 456 457 458 |
# File 'lib/rspec2-rails-views-matchers.rb', line 455 def with_submit value = { :with => { :type => 'submit', :value => value } } should_have_input() end |
- (Object) with_tag(tag, options = {}) { ... }
Note:
this should be used within block of have_tag matcher
with_tag matcher
220 221 222 |
# File 'lib/rspec2-rails-views-matchers.rb', line 220 def with_tag tag, ={}, &block @__current_scope_for_nokogiri_matcher.should have_tag(tag, , &block) end |
- (Object) with_text_area(name)
351 352 353 354 |
# File 'lib/rspec2-rails-views-matchers.rb', line 351 def with_text_area name = { :with => { :name => name } } @__current_scope_for_nokogiri_matcher.should have_tag('textarea', ) end |
- (Object) with_text_field(name, value = nil)
253 254 255 256 257 |
# File 'lib/rspec2-rails-views-matchers.rb', line 253 def with_text_field name, value=nil = { :with => { :name => name, :type => 'text' } } [:with].merge!(:value => value) if value should_have_input() end |
- (Object) with_url_field(name, value = nil)
277 278 279 280 281 |
# File 'lib/rspec2-rails-views-matchers.rb', line 277 def with_url_field name, value=nil = { :with => { :name => name, :type => 'url' } } [:with].merge!(:value => value) if value should_have_input() end |
- (Object) without_button(text, value = nil, options = {})
444 445 446 447 448 449 450 451 452 453 |
# File 'lib/rspec2-rails-views-matchers.rb', line 444 def text, value=nil, ={} [:with] ||= {} if value.is_a?(Hash) .merge!(value) value=nil end [:with].merge!(:value => value.to_s) if value .merge!(:text => text) if text @__current_scope_for_nokogiri_matcher.should_not have_tag('button', ) end |
- (Object) without_checkbox(name, value = nil)
367 368 369 370 371 |
# File 'lib/rspec2-rails-views-matchers.rb', line 367 def without_checkbox name, value=nil = { :with => { :name => name, :type => 'checkbox' } } [:with].merge!(:value => value) if value should_not_have_input() end |
- (Object) without_date_field(date_field_type, name = nil, options = {})
323 324 325 326 327 328 329 |
# File 'lib/rspec2-rails-views-matchers.rb', line 323 def without_date_field date_field_type, name=nil, ={} date_field_type = date_field_type.to_s raise "unknown type `#{date_field_type}` for date picker" unless DATE_FIELD_TYPES.include?(date_field_type) = { :with => { :type => date_field_type.to_s }.merge(.delete(:with)||{}) } [:with].merge!(:name => name.to_s) if name should_not_have_input() end |
- (Object) without_email_field(name, value = nil)
271 272 273 274 275 |
# File 'lib/rspec2-rails-views-matchers.rb', line 271 def without_email_field name, value=nil = { :with => { :name => name, :type => 'email' } } [:with].merge!(:value => value) if value should_not_have_input() end |
- (Object) without_file_field(name)
346 347 348 349 |
# File 'lib/rspec2-rails-views-matchers.rb', line 346 def without_file_field name = { :with => { :name => name, :type => 'file' } } should_not_have_input() end |
- (Object) without_hidden_field(name, value = nil)
247 248 249 250 251 |
# File 'lib/rspec2-rails-views-matchers.rb', line 247 def without_hidden_field name, value=nil = { :with => { :name => name, :type => 'hidden' } } [:with].merge!(:value => value) if value should_not_have_input() end |
- (Object) without_number_field(name, value = nil)
295 296 297 298 299 |
# File 'lib/rspec2-rails-views-matchers.rb', line 295 def without_number_field name, value=nil = { :with => { :name => name, :type => 'number' } } [:with].merge!(:value => value.to_s) if value should_not_have_input() end |
- (Object) without_option(text, value = nil, options = {})
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/rspec2-rails-views-matchers.rb', line 417 def without_option text, value=nil, ={} [:with] ||= {} if value.is_a?(Hash) .merge!(value) value=nil end tag='option' [:with].merge!(:value => value.to_s) if value if [:selected] [:with].merge!(:selected => "selected") end .delete(:selected) .merge!(:text => text) if text @__current_scope_for_nokogiri_matcher.should_not have_tag(tag, ) end |
- (Object) without_password_field(name)
336 337 338 339 |
# File 'lib/rspec2-rails-views-matchers.rb', line 336 def without_password_field name = { :with => { :name => name, :type => 'password' } } should_not_have_input() end |
- (Object) without_radio_button(name, value)
379 380 381 382 383 |
# File 'lib/rspec2-rails-views-matchers.rb', line 379 def name, value = { :with => { :name => name, :type => 'radio' } } [:with].merge!(:value => value) should_not_have_input() end |
- (Object) without_range_field(name, min = nil, max = nil, options = {})
306 307 308 309 310 311 |
# File 'lib/rspec2-rails-views-matchers.rb', line 306 def without_range_field name, min=nil, max=nil, ={} = { :with => { :name => name, :type => 'range' }.merge(.delete(:with)||{}) } [:with].merge!(:min => min.to_s) if min [:with].merge!(:max => max.to_s) if max should_not_have_input() end |
- (Object) without_select(name, options = {}, &block)
393 394 395 396 397 398 399 |
# File 'lib/rspec2-rails-views-matchers.rb', line 393 def without_select name, ={}, &block [:with] ||= {} id = [:with].delete(:id) tag='select'; tag += '#'+id if id [:with].merge!(:name => name) @__current_scope_for_nokogiri_matcher.should_not have_tag(tag, , &block) end |
- (Object) without_submit(value)
460 461 462 463 |
# File 'lib/rspec2-rails-views-matchers.rb', line 460 def without_submit value = { :with => { :type => 'submit', :value => value } } should_not_have_input() end |
- (Object) without_tag(tag, options = {}) { ... }
Note:
this should be used within block of have_tag matcher
without_tag matcher
228 229 230 |
# File 'lib/rspec2-rails-views-matchers.rb', line 228 def without_tag tag, ={}, &block @__current_scope_for_nokogiri_matcher.should_not have_tag(tag, , &block) end |
- (Object) without_text_area(name)
356 357 358 359 |
# File 'lib/rspec2-rails-views-matchers.rb', line 356 def without_text_area name = { :with => { :name => name } } @__current_scope_for_nokogiri_matcher.should_not have_tag('textarea', ) end |
- (Object) without_text_field(name, value = nil)
259 260 261 262 263 |
# File 'lib/rspec2-rails-views-matchers.rb', line 259 def without_text_field name, value=nil = { :with => { :name => name, :type => 'text' } } [:with].merge!(:value => value) if value should_not_have_input() end |
- (Object) without_url_field(name, value = nil)
283 284 285 286 287 |
# File 'lib/rspec2-rails-views-matchers.rb', line 283 def without_url_field name, value=nil = { :with => { :name => name, :type => 'url' } } [:with].merge!(:value => value) if value should_not_have_input() end |