-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathelabs_matchers.rb
98 lines (84 loc) · 4.07 KB
/
elabs_matchers.rb
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require "rspec/core"
require "rspec/expectations"
module ElabsMatchers
require "active_support/core_ext/hash/indifferent_access"
require "active_support/core_ext/object/blank"
require "active_support/core_ext/array/conversions"
require "active_support/inflector"
require "elabs_matchers/extensions/module"
require "elabs_matchers/helpers/fixtures"
require "elabs_matchers/helpers/normalize_keys"
require "elabs_matchers/helpers/reload_record"
require "elabs_matchers/helpers/select_year_and_month"
require "elabs_matchers/matchers/be_valid_with"
require "elabs_matchers/matchers/contain_hash"
require "elabs_matchers/matchers/have_attribute"
require "elabs_matchers/matchers/have_fields"
require "elabs_matchers/matchers/have_flash"
require "elabs_matchers/matchers/have_form_errors_on"
require "elabs_matchers/matchers/have_header"
require "elabs_matchers/matchers/have_image"
require "elabs_matchers/matchers/only_include"
require "elabs_matchers/matchers/persist"
class << self
attr_accessor :header_selector, :header_selector_type
attr_accessor :attribute_selector, :attribute_selector_type
attr_accessor :flash_notice_selector, :flash_notice_selector_type, :flash_alert_selector, :flash_alert_selector_type
attr_accessor :form_errors_on_selector
attr_accessor :image_selector, :image_selector_type
attr_accessor :table_row_selector
##
#
# Configure ElabsMatchers to suit your needs. The spec/spec_helper.rb
# file is a good place to put your configurations in.
#
# ElabsMatchers.configure do |config|
# config.header_selector = "//h1"
# config.header_selector_type = :xpath
# config.image_selector = lambda { |src| "img[src='#{src}']" }
# end
#
# === Configurable options
#
# [header_selctor = String] The selector to use when finding header tags (Default: "h1,h2")
# [header_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :css)
#
# [image_selctor = lamda] The selector to use when finding images (Default: see matcher)
# [image_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :css)
#
# [attribute_selector = lambda] A lambda that takes label and value as arguments and return a selector (Default: see matcher)
# [attribute_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :xpath)
#
# [flash_notice_selector = String] The selector to use when finding the flash notice (Default: "#flash.notice, #flash .notice, .flash.notice")
# [flash_notice_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :css)
# [flash_alert_selector = String] The selector to use when finding the flash alert (Default: "#flash.alert, #flash .alert, .flash.alert")
# [flash_alert_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :css)
#
# [form_errors_on_selector = String] A xpath expression to be used when finding associated error notices (Default: see matcher)
#
# [table_row_selector = lambda] A lambda that takes table row return a selector (Default: see matcher)
def configure
yield self
end
##
#
# Reset Elabs matchers to use the default configuration.
def use_default_configuration!
configure do |config|
config.header_selector = "h1,h2"
config.header_selector_type = :css
config.image_selector = nil
config.image_selector_type = :css
config.attribute_selector = nil
config.attribute_selector_type = :xpath
config.flash_notice_selector = "#flash.notice, #flash .notice, .flash.notice"
config.flash_notice_selector_type = :css
config.flash_alert_selector = "#flash.alert, #flash .alert, .flash.alert"
config.flash_alert_selector_type = :css
config.form_errors_on_selector = nil
config.table_row_selector = nil
end
end
end
end
ElabsMatchers.use_default_configuration!