Module: RSpec::Matchers
- Defined in:
- lib/rspec-html-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 = {}) { ... }
form assertion.
-
- (Object) have_tag(tag, options = {}) { ... }
tag assertion, this is the core of functionality, other matchers are shortcuts to this 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, value = nil)
-
- (Object) with_hidden_field(name, value = nil)
TODO fix code duplications.
- - (Object) with_number_field(name, value = nil)
- - (Object) with_option(text, value = nil, options = {})
- - (Object) with_password_field(name, value = nil)
- - (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(text)
-
- (Object) with_text_area(name)
TODO, text=nil.
- - (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, value = nil)
- - (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, value = nil)
- - (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(text) (also: #but_without_text)
-
- (Object) without_text_area(name)
TODO, text=nil.
- - (Object) without_text_field(name, value = nil)
- - (Object) without_url_field(name, value = nil)
Instance Method Details
- (Object) have_form(action_url, method, options = {}) { ... }
form assertion
it is a shortcut to
have_tag 'form', :with => { :action => action_url, :method => method ... }
292 293 294 295 296 297 298 299 |
# File 'lib/rspec-html-matchers.rb', line 292 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 = {}) { ... }
tag assertion, this is the core of functionality, other matchers are shortcuts to this matcher
249 250 251 252 253 |
# File 'lib/rspec-html-matchers.rb', line 249 def have_tag tag, ={}, &block # for backwards compatibility with rpecs have tag: = { :text => } if .kind_of? String @__current_scope_for_nokogiri_matcher = NokogiriMatcher.new(tag, , &block) end |
- (Object) with_button(text, value = nil, options = {})
483 484 485 486 487 488 489 490 491 492 |
# File 'lib/rspec-html-matchers.rb', line 483 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)
415 416 417 418 |
# File 'lib/rspec-html-matchers.rb', line 415 def with_checkbox name, value=nil = ('checkbox',name,value) should_have_input() end |
- (Object) with_date_field(date_field_type, name = nil, options = {})
367 368 369 370 371 372 373 |
# File 'lib/rspec-html-matchers.rb', line 367 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)
323 324 325 326 |
# File 'lib/rspec-html-matchers.rb', line 323 def with_email_field name, value=nil = ('email',name,value) should_have_input() end |
- (Object) with_file_field(name, value = nil)
393 394 395 396 |
# File 'lib/rspec-html-matchers.rb', line 393 def with_file_field name, value=nil = ('file',name,value) should_have_input() end |
- (Object) with_hidden_field(name, value = nil)
TODO fix code duplications
303 304 305 306 |
# File 'lib/rspec-html-matchers.rb', line 303 def with_hidden_field name, value=nil = ('hidden',name,value) should_have_input() end |
- (Object) with_number_field(name, value = nil)
343 344 345 346 |
# File 'lib/rspec-html-matchers.rb', line 343 def with_number_field name, value=nil = ('number',name,value) should_have_input() end |
- (Object) with_option(text, value = nil, options = {})
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/rspec-html-matchers.rb', line 451 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, value = nil)
383 384 385 386 |
# File 'lib/rspec-html-matchers.rb', line 383 def with_password_field name, value=nil = ('password',name,value) should_have_input() end |
- (Object) with_radio_button(name, value)
425 426 427 428 |
# File 'lib/rspec-html-matchers.rb', line 425 def name, value = ('radio',name,value) should_have_input() end |
- (Object) with_range_field(name, min, max, options = {})
353 354 355 356 |
# File 'lib/rspec-html-matchers.rb', line 353 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)
435 436 437 438 439 440 441 |
# File 'lib/rspec-html-matchers.rb', line 435 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)
505 506 507 508 509 |
# File 'lib/rspec-html-matchers.rb', line 505 def with_submit value = { :with => { :type => 'submit', :value => value } } #options = form_tag_options('text',name,value) should_have_input() end |
- (Object) with_tag(tag, options = {}) { ... }
Note:
this should be used within block of have_tag matcher
with_tag matcher
274 275 276 |
# File 'lib/rspec-html-matchers.rb', line 274 def with_tag tag, ={}, &block @__current_scope_for_nokogiri_matcher.should have_tag(tag, , &block) end |
- (Object) with_text(text)
255 256 257 258 259 260 |
# File 'lib/rspec-html-matchers.rb', line 255 def with_text text raise StandardError, 'this matcher should be used inside "have_tag" matcher block' unless defined?(@__current_scope_for_nokogiri_matcher) raise ArgumentError, 'this matcher does not accept block' if block_given? tag = @__current_scope_for_nokogiri_matcher.instance_variable_get(:@tag) @__current_scope_for_nokogiri_matcher.should have_tag(tag, :text => text) end |
- (Object) with_text_area(name)
TODO, text=nil
403 404 405 406 407 |
# File 'lib/rspec-html-matchers.rb', line 403 def with_text_area name#TODO, text=nil #options = form_tag_options('text',name,value) = { :with => { :name => name } } @__current_scope_for_nokogiri_matcher.should have_tag('textarea', ) end |
- (Object) with_text_field(name, value = nil)
313 314 315 316 |
# File 'lib/rspec-html-matchers.rb', line 313 def with_text_field name, value=nil = ('text',name,value) should_have_input() end |
- (Object) with_url_field(name, value = nil)
333 334 335 336 |
# File 'lib/rspec-html-matchers.rb', line 333 def with_url_field name, value=nil = ('url',name,value) should_have_input() end |
- (Object) without_button(text, value = nil, options = {})
494 495 496 497 498 499 500 501 502 503 |
# File 'lib/rspec-html-matchers.rb', line 494 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)
420 421 422 423 |
# File 'lib/rspec-html-matchers.rb', line 420 def without_checkbox name, value=nil = ('checkbox',name,value) should_not_have_input() end |
- (Object) without_date_field(date_field_type, name = nil, options = {})
375 376 377 378 379 380 381 |
# File 'lib/rspec-html-matchers.rb', line 375 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)
328 329 330 331 |
# File 'lib/rspec-html-matchers.rb', line 328 def without_email_field name, value=nil = ('email',name,value) should_not_have_input() end |
- (Object) without_file_field(name, value = nil)
398 399 400 401 |
# File 'lib/rspec-html-matchers.rb', line 398 def without_file_field name, value=nil = ('file',name,value) should_not_have_input() end |
- (Object) without_hidden_field(name, value = nil)
308 309 310 311 |
# File 'lib/rspec-html-matchers.rb', line 308 def without_hidden_field name, value=nil = ('hidden',name,value) should_not_have_input() end |
- (Object) without_number_field(name, value = nil)
348 349 350 351 |
# File 'lib/rspec-html-matchers.rb', line 348 def without_number_field name, value=nil = ('number',name,value) should_not_have_input() end |
- (Object) without_option(text, value = nil, options = {})
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/rspec-html-matchers.rb', line 467 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, value = nil)
388 389 390 391 |
# File 'lib/rspec-html-matchers.rb', line 388 def without_password_field name, value=nil = ('password',name,value) should_not_have_input() end |
- (Object) without_radio_button(name, value)
430 431 432 433 |
# File 'lib/rspec-html-matchers.rb', line 430 def name, value = ('radio',name,value) should_not_have_input() end |
- (Object) without_range_field(name, min = nil, max = nil, options = {})
358 359 360 361 362 363 |
# File 'lib/rspec-html-matchers.rb', line 358 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)
443 444 445 446 447 448 449 |
# File 'lib/rspec-html-matchers.rb', line 443 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)
511 512 513 514 515 |
# File 'lib/rspec-html-matchers.rb', line 511 def without_submit value #options = form_tag_options('text',name,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
282 283 284 |
# File 'lib/rspec-html-matchers.rb', line 282 def without_tag tag, ={}, &block @__current_scope_for_nokogiri_matcher.should_not have_tag(tag, , &block) end |
- (Object) without_text(text) Also known as: but_without_text
262 263 264 265 266 267 |
# File 'lib/rspec-html-matchers.rb', line 262 def without_text text raise StandardError, 'this matcher should be used inside "have_tag" matcher block' unless defined?(@__current_scope_for_nokogiri_matcher) raise ArgumentError, 'this matcher does not accept block' if block_given? tag = @__current_scope_for_nokogiri_matcher.instance_variable_get(:@tag) @__current_scope_for_nokogiri_matcher.should_not have_tag(tag, :text => text) end |
- (Object) without_text_area(name)
TODO, text=nil
409 410 411 412 413 |
# File 'lib/rspec-html-matchers.rb', line 409 def without_text_area name#TODO, text=nil #options = form_tag_options('text',name,value) = { :with => { :name => name } } @__current_scope_for_nokogiri_matcher.should_not have_tag('textarea', ) end |
- (Object) without_text_field(name, value = nil)
318 319 320 321 |
# File 'lib/rspec-html-matchers.rb', line 318 def without_text_field name, value=nil = ('text',name,value) should_not_have_input() end |
- (Object) without_url_field(name, value = nil)
338 339 340 341 |
# File 'lib/rspec-html-matchers.rb', line 338 def without_url_field name, value=nil = ('url',name,value) should_not_have_input() end |