aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/system_testing/test_helpers/assertions.rb
blob: 6e5b62e3c557ef1dde997eec45af4f288978ac08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module SystemTesting
  module TestHelpers
    # Assertions for system testing that aren't included by default in Capybara.
    # These are assertions that are useful specifically for Rails applications.
    module Assertions
      # Asserts that all of the provided selectors are present on the given page.
      #
      #   assert_all_of_selectors('p', 'td')
      def assert_all_of_selectors(*items)
        options = items.extract_options!
        type = type_for_selector(items)

        items.each do |item|
          assert_selector type, item, options
        end
      end

      # Asserts that none of the provided selectors are present on the page.
      #
      #   assert_none_of_selectors('ul', 'ol')
      def assert_none_of_selectors(*items)
        options = items.extract_options!
        type = type_for_selector(items)

        items.each do |item|
          assert_no_selector type, item, options
        end
      end

      private
        def type_for_selector(*items)
          if items.first.is_a?(Symbol)
            items.shift
          else
            Capybara.default_selector
          end
        end
    end
  end
end