Module: Test::Unit::Capybara::Assertions
- Defined in:
- lib/test/unit/capybara.rb
Instance Method Summary collapse
-
#assert_all(*args) ⇒ Array<::Capybara::Element>
The found elements.
-
#assert_body(expected, options = {}) {|expected_response, actual_response| ... } ⇒ Object
Passes if @expected@ == @source@.
- #assert_not_find(*args, &block) ⇒ Object
-
#flunk_find(base_node, options = {}) ⇒ Object
Fails always with Capybara::Node::Element is not found message.
Instance Method Details
#assert_all(*args) ⇒ Array<::Capybara::Element> #assert_all(node, *args) ⇒ Array<::Capybara::Element>
Returns The found elements.
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/test/unit/capybara.rb', line 283 def assert_all(*args) node = nil node = args.shift if args[0].is_a?(::Capybara::Node::Base) args = normalize_page_finder_arguments(args) format = <<-EOT <?>(?) expected to find one or more elements in <?> EOT current_context = node || page.send(:current_scope) current_context_source = node_source(current_context) = AssertionMessage.literal(current_context_source) = (args[:message], format, args[:locator], args[:kind], ) if node elements = node.all(*args[:finder_arguments]) else elements = all(*args[:finder_arguments]) end assert_block() do not elements.empty? end elements end |
#assert_body(expected, options = {}) {|expected_response, actual_response| ... } ⇒ Object
Passes if @expected@ == @source@. @source@ is a method provided by Capybara::DSL.
@source@ may be parsed depended on response Content-Type before comparing. Here are parsed Content-Types:
- @"application/json"@ := It's parsed by @JSON.parse@.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/test/unit/capybara.rb', line 203 def assert_body(expected, ={}, &block) content_type = [:content_type] actual_response = { :content_type => page_content_type, :body => parsed_page_body, } expected_response = {:body => expected} if content_type expected_response[:content_type] = normalize_content_type(content_type) else actual_response.delete(:content_type) end if block_given? expected_response, actual_response = yield(expected_response, actual_response) end assert_equal(expected_response, actual_response) end |
#assert_not_find(*args, &block) ⇒ Object #assert_not_find(node, *args, &block) ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/test/unit/capybara.rb', line 380 def assert_not_find(*args, &block) node = nil node = args.shift if args[0].is_a?(::Capybara::Node::Base) args = normalize_page_finder_arguments(args) begin if node element = node.first(*args[:finder_arguments], **args[:finder_options]) else element = first(*args[:finder_arguments], **args[:finder_options]) end rescue ::Capybara::ExpectationNotMet element = nil end format = <<-EOT <?>(?) expected to not find an element but was <?> in <?> EOT element_source = nil element_source = node_source(element) if element current_context = node || page.send(:current_scope) current_context_source = node_source(current_context) = AssertionMessage.literal(current_context_source) = (args[:message], format, args[:locator], args[:kind], AssertionMessage.literal(element_source), ) assert_block() do element.nil? end end |
#flunk_find(base_node, options = {}) ⇒ Object
Fails always with Capybara::Node::Element is not found message.
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/test/unit/capybara.rb', line 430 def flunk_find(base_node, ={}) format = <<-EOT <?>(?) expected to find an element in <?> EOT base_html = AssertionMessage.literal(node_source(base_node)) = ([:message], format, [:locator], [:kind], base_html) assert_block() do false end end |