Module: Gaku::Testing::FeatureHelpers
- Defined in:
- lib/gaku/testing/feature_helpers.rb
Constant Summary collapse
- @@resource =
''
- @@resource_plural =
''
Instance Method Summary collapse
- #accept_alert ⇒ Object
- #cancel_link ⇒ Object
- #check_path(current_url, expected_path) ⇒ Object
- #click(selector) ⇒ Object
- #click_option(resource) ⇒ Object
- #close ⇒ Object
- #count?(count) ⇒ Boolean
- #count_div ⇒ Object
- #delete_link ⇒ Object
- #edit_link ⇒ Object
- #ensure_delete_is_working ⇒ Object
- #form ⇒ Object
- #get_resource ⇒ Object
- #has_validations? ⇒ Boolean
- #invisible?(selector) ⇒ Boolean
- #js_edit_link ⇒ Object
- #modal ⇒ Object
- #modal_delete_link ⇒ Object
- #new_link ⇒ Object
- #picture_path ⇒ Object
- #recovery_link ⇒ Object
- #set_resource(x) ⇒ Object
- #show_link ⇒ Object
- #size_of(selector) ⇒ Object
- #submit ⇒ Object
- #tab_link ⇒ Object
- #table ⇒ Object
- #table_rows ⇒ Object
- #visible?(selector) ⇒ Boolean
- #wait_for_ajax(timeout = Capybara.default_wait_time) ⇒ Object
- #wait_for_ready ⇒ Object
Instance Method Details
#accept_alert ⇒ Object
80 81 82 |
# File 'lib/gaku/testing/feature_helpers.rb', line 80 def accept_alert page.driver.browser.switch_to.alert.accept if Capybara.javascript_driver == :selenium end |
#cancel_link ⇒ Object
31 32 33 |
# File 'lib/gaku/testing/feature_helpers.rb', line 31 def cancel_link "#cancel-#{@@resource}-link" end |
#check_path(current_url, expected_path) ⇒ Object
135 136 137 138 |
# File 'lib/gaku/testing/feature_helpers.rb', line 135 def check_path(current_url,expected_path) uri = URI.parse(current_url) "#{uri.path}?#{uri.query}".should == expected_path end |
#click(selector) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/gaku/testing/feature_helpers.rb', line 96 def click(selector) if Capybara.javascript_driver == :selenium find(selector).click else find(selector).trigger('click') end end |
#click_option(resource) ⇒ Object
104 105 106 |
# File 'lib/gaku/testing/feature_helpers.rb', line 104 def click_option(resource) find("option[value='#{resource.id}']").click end |
#close ⇒ Object
76 77 78 |
# File 'lib/gaku/testing/feature_helpers.rb', line 76 def close '.close' end |
#count?(count) ⇒ Boolean
131 132 133 |
# File 'lib/gaku/testing/feature_helpers.rb', line 131 def count?(count) within(count_div) { page.has_content? count } end |
#count_div ⇒ Object
39 40 41 |
# File 'lib/gaku/testing/feature_helpers.rb', line 39 def count_div ".#{@@resource_plural}-count" end |
#delete_link ⇒ Object
72 73 74 |
# File 'lib/gaku/testing/feature_helpers.rb', line 72 def delete_link '.delete-link' end |
#edit_link ⇒ Object
51 52 53 |
# File 'lib/gaku/testing/feature_helpers.rb', line 51 def edit_link '.edit-link' end |
#ensure_delete_is_working ⇒ Object
108 109 110 111 |
# File 'lib/gaku/testing/feature_helpers.rb', line 108 def ensure_delete_is_working within(table) { click delete_link } accept_alert end |
#form ⇒ Object
19 20 21 |
# File 'lib/gaku/testing/feature_helpers.rb', line 19 def form "#new-#{@@resource}" end |
#get_resource ⇒ Object
11 12 13 |
# File 'lib/gaku/testing/feature_helpers.rb', line 11 def get_resource @@resource end |
#has_validations? ⇒ Boolean
126 127 128 129 |
# File 'lib/gaku/testing/feature_helpers.rb', line 126 def has_validations? click submit page.has_content? "can't be blank" end |
#invisible?(selector) ⇒ Boolean
92 93 94 |
# File 'lib/gaku/testing/feature_helpers.rb', line 92 def invisible?(selector) page.has_no_selector?(selector) end |
#js_edit_link ⇒ Object
55 56 57 |
# File 'lib/gaku/testing/feature_helpers.rb', line 55 def js_edit_link '.js-edit-link' end |
#modal ⇒ Object
35 36 37 |
# File 'lib/gaku/testing/feature_helpers.rb', line 35 def modal '.modal' end |
#modal_delete_link ⇒ Object
64 65 66 |
# File 'lib/gaku/testing/feature_helpers.rb', line 64 def modal_delete_link '.modal-delete-link' end |
#new_link ⇒ Object
23 24 25 |
# File 'lib/gaku/testing/feature_helpers.rb', line 23 def new_link "#new-#{@@resource}-link" end |
#picture_path ⇒ Object
140 141 142 |
# File 'lib/gaku/testing/feature_helpers.rb', line 140 def picture_path Rails.root + '../../../core/spec/support/120x120.jpg' end |
#recovery_link ⇒ Object
60 61 62 |
# File 'lib/gaku/testing/feature_helpers.rb', line 60 def recovery_link '.recovery-link' end |
#set_resource(x) ⇒ Object
6 7 8 9 |
# File 'lib/gaku/testing/feature_helpers.rb', line 6 def set_resource(x) @@resource = x @@resource_plural = plural(x) end |
#show_link ⇒ Object
68 69 70 |
# File 'lib/gaku/testing/feature_helpers.rb', line 68 def show_link '.show-link' end |
#size_of(selector) ⇒ Object
84 85 86 |
# File 'lib/gaku/testing/feature_helpers.rb', line 84 def size_of(selector) page.all(selector).size end |
#submit ⇒ Object
27 28 29 |
# File 'lib/gaku/testing/feature_helpers.rb', line 27 def submit "#submit-#{@@resource}-button" end |
#tab_link ⇒ Object
15 16 17 |
# File 'lib/gaku/testing/feature_helpers.rb', line 15 def tab_link "##{@@resource_plural}-tab-link" end |
#table ⇒ Object
43 44 45 |
# File 'lib/gaku/testing/feature_helpers.rb', line 43 def table "##{@@resource_plural}-index" end |
#table_rows ⇒ Object
47 48 49 |
# File 'lib/gaku/testing/feature_helpers.rb', line 47 def table_rows "##{@@resource_plural}-index tr" end |
#visible?(selector) ⇒ Boolean
88 89 90 |
# File 'lib/gaku/testing/feature_helpers.rb', line 88 def visible?(selector) find(selector).visible? end |
#wait_for_ajax(timeout = Capybara.default_wait_time) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/gaku/testing/feature_helpers.rb', line 117 def wait_for_ajax(timeout = Capybara.default_wait_time) Timeout.timeout(timeout) do active = page.evaluate_script('jQuery.active') until active == 0 active = page.evaluate_script('jQuery.active') end end end |
#wait_for_ready ⇒ Object
113 114 115 |
# File 'lib/gaku/testing/feature_helpers.rb', line 113 def wait_for_ready page.has_no_selector?('.nprogress-busy') end |