Module: Capextensions
- Defined in:
- lib/mundo_pepino/capybara/extensions.rb
Constant Summary collapse
- DATE_TIME_SUFFIXES =
{ :year => '1i', :month => '2i', :day => '3i', :hour => '4i', :minute => '5i' }
Instance Method Summary collapse
- #click_link_within(selector, link_text) ⇒ Object
- #contain(content) ⇒ Object
- #have_selector(path, options = {}) ⇒ Object
- #have_tag(*args, &block) ⇒ Object
-
#response(*args, &block) ⇒ Object
Maybe this methos should be defined in the other order, capybara is the default?.
- #select_date(date_to_select, options = {}) ⇒ Object
- #select_datetime(time_to_select, options = {}) ⇒ Object
- #select_time(time_to_select, options = {}) ⇒ Object
Instance Method Details
#click_link_within(selector, link_text) ⇒ Object
11 12 13 14 15 |
# File 'lib/mundo_pepino/capybara/extensions.rb', line 11 def click_link_within(selector, link_text) within(:css, selector) do click_link link_text end end |
#contain(content) ⇒ Object
125 126 127 |
# File 'lib/mundo_pepino/capybara/extensions.rb', line 125 def contain(content) have_text(content) end |
#have_selector(path, options = {}) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/mundo_pepino/capybara/extensions.rb', line 118 def have_selector(path, = {}) # content key to text key content = .delete(:content) [:text] = content unless content.nil? have_css(path, ) end |
#have_tag(*args, &block) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/mundo_pepino/capybara/extensions.rb', line 109 def have_tag(*args, &block) text = args[1] unless text.blank? have_css(args.first, :text => text) else have_css(args.first) end end |
#response(*args, &block) ⇒ Object
Maybe this methos should be defined in the other order, capybara is the default?
105 106 107 |
# File 'lib/mundo_pepino/capybara/extensions.rb', line 105 def response(*args, &block) page(*args, &block) end |
#select_date(date_to_select, options = {}) ⇒ Object
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 |
# File 'lib/mundo_pepino/capybara/extensions.rb', line 17 def select_date(date_to_select, ={}) date = date_to_select.is_a?(Date) || date_to_select.is_a?(Time) ? date_to_select : Date.parse(date_to_select) if [:id_prefix].blank? if [:from].blank? source = locate(:xpath, Capybara::XPath.append("//select[contains(@id, '_#{DATE_TIME_SUFFIXES[:year]}')]")) id_prefix = source.node.attributes["id"].value[/(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/, 1] else msg = "cannot select option, no select box with id, name, or label '#{[:from]}' found" begin label = locate(:xpath, Capybara::XPath.append("//label[text()='#{[:from]}']"), msg) id_prefix = label.node.attributes["for"].value rescue Capybara::ElementNotFound begin previous_exception = $! label = locate(:xpath, Capybara::XPath.append("//label[text()='#{[:from].capitalize}']"), msg) id_prefix = label.node.attributes["for"].value rescue raise "#{previous_exception}\nand\n#{$!}" end end end end id_prefix ||= [:id_prefix] select date.year.to_s, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}" select date.strftime('%B'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:month]}" select date.day.to_s, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}" end |
#select_datetime(time_to_select, options = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/mundo_pepino/capybara/extensions.rb', line 79 def select_datetime(time_to_select, ={}) time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select) if [:from] msg = "cannot select option, no select box with id, name, or label '#{[:from]}' found" begin label = locate(:xpath, Capybara::XPath.append("//label[text()='#{[:from]}']"), msg) id_prefix = label.node.attributes["for"].value rescue Capybara::ElementNotFound begin previous_exception = $! label = locate(:xpath, Capybara::XPath.append("//label[text()='#{[:from].capitalize}']"), msg) id_prefix = label.node.attributes["for"].value rescue raise "#{previous_exception}\nand\n#{$!}" end end end [:id_prefix] ||= ([:from] ? id_prefix : nil) select_date time, select_time time, end |
#select_time(time_to_select, options = {}) ⇒ Object
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 |
# File 'lib/mundo_pepino/capybara/extensions.rb', line 49 def select_time(time_to_select, ={}) time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select) if [:id_prefix].blank? if [:from].blank? source = locate(:xpath, Capybara::XPath.append("//select[contains(@id, '_#{DATE_TIME_SUFFIXES[:hour]}')]")) id_prefix = source.node.attributes["id"].value[/(.*?)_#{DATE_TIME_SUFFIXES[:hour]}$/, 1] else msg = "cannot select option, no select box with id, name, or label '#{[:from]}' found" begin label = locate(:xpath, Capybara::XPath.append("//label[text()='#{[:from]}']"), msg) id_prefix = label.node.attributes["for"].value rescue Capybara::ElementNotFound begin previous_exception = $! label = locate(:xpath, Capybara::XPath.append("//label[text()='#{[:from].capitalize}']"), msg) id_prefix = label.node.attributes["for"].value rescue raise "#{previous_exception}\nand\n#{$!}" end end end end id_prefix ||= [:id_prefix] select time.hour.to_s.rjust(2, '0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:hour]}" select time.min.to_s.rjust(2, '0'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:minute]}" end |