Module: TestSelector::TestHelper
- Defined in:
- lib/test_selector/test_helper.rb
Instance Method Summary collapse
- #find_test_selector(html, selector) ⇒ Object
- #get_selector(path, name = nil, value = nil) ⇒ Object
- #test_selector(path, name = nil, value = nil) ⇒ Object
Instance Method Details
#find_test_selector(html, selector) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/test_selector/test_helper.rb', line 21 def find_test_selector(html, selector) test_selector = selector.split(' ').first test_value = selector.split(' ').second doc = Nokogiri::HTML(html).css("[#{test_selector}]") if test_value doc.css("[#{test_value}]") else doc end end |
#get_selector(path, name = nil, value = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/test_selector/test_helper.rb', line 9 def get_selector(path, name = nil, value = nil) underscore_path = path.gsub(%r{/|\.}, '_') if name && value "_#{underscore_path}__#{name} test-value=#{value}" elsif name "_#{underscore_path}__#{name}" else "_#{underscore_path}" end end |
#test_selector(path, name = nil, value = nil) ⇒ Object
5 6 7 |
# File 'lib/test_selector/test_helper.rb', line 5 def test_selector(path, name = nil, value = nil) "test-selector=#{get_selector(path, name, value)}" end |