Module: Gaku::Testing::FeatureHelpers

Defined in:
lib/gaku/testing/feature_helpers.rb

Constant Summary collapse

@@resource =
''
@@resource_plural =
''

Instance Method Summary collapse

Instance Method Details

#accept_alertObject



79
80
81
# File 'lib/gaku/testing/feature_helpers.rb', line 79

def accept_alert
  page.driver.browser.switch_to.alert.accept if Capybara.javascript_driver == :selenium
end


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



132
133
134
135
# File 'lib/gaku/testing/feature_helpers.rb', line 132

def check_path(current_url, expected_path)
  uri = URI.parse(current_url)
  "#{uri.path}?#{uri.query}".should == expected_path
end

#click(selector) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/gaku/testing/feature_helpers.rb', line 95

def click(selector)
  if Capybara.javascript_driver == :selenium
    find(selector).click
  else
    find(selector).trigger('click')
  end
end

#click_option(resource) ⇒ Object



103
104
105
# File 'lib/gaku/testing/feature_helpers.rb', line 103

def click_option(resource)
  find("option[value='#{resource.id}']").click
end

#closeObject



75
76
77
# File 'lib/gaku/testing/feature_helpers.rb', line 75

def close
  '.close'
end

#count?(count) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/gaku/testing/feature_helpers.rb', line 128

def count?(count)
  within(count_div) { page.has_content? count }
end

#count_divObject



39
40
41
# File 'lib/gaku/testing/feature_helpers.rb', line 39

def count_div
  ".#{@@resource_plural}-count"
end


71
72
73
# File 'lib/gaku/testing/feature_helpers.rb', line 71

def delete_link
  '.delete-link'
end


51
52
53
# File 'lib/gaku/testing/feature_helpers.rb', line 51

def edit_link
  '.edit-link'
end

#ensure_delete_is_workingObject



107
108
109
110
# File 'lib/gaku/testing/feature_helpers.rb', line 107

def ensure_delete_is_working
  within(table) { click delete_link }
  accept_alert
end

#formObject



19
20
21
# File 'lib/gaku/testing/feature_helpers.rb', line 19

def form
  "#new-#{@@resource}"
end

#get_resourceObject



11
12
13
# File 'lib/gaku/testing/feature_helpers.rb', line 11

def get_resource
  @@resource
end

#has_validations?Boolean

Returns:

  • (Boolean)


123
124
125
126
# File 'lib/gaku/testing/feature_helpers.rb', line 123

def has_validations?
  click submit
  page.has_content? "can't be blank"
end

#invisible?(selector) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/gaku/testing/feature_helpers.rb', line 91

def invisible?(selector)
  page.has_no_selector?(selector)
end


55
56
57
# File 'lib/gaku/testing/feature_helpers.rb', line 55

def js_edit_link
  '.js-edit-link'
end


35
36
37
# File 'lib/gaku/testing/feature_helpers.rb', line 35

def modal
  '.modal'
end


63
64
65
# File 'lib/gaku/testing/feature_helpers.rb', line 63

def modal_delete_link
  '.modal-delete-link'
end


23
24
25
# File 'lib/gaku/testing/feature_helpers.rb', line 23

def new_link
  "#new-#{@@resource}-link"
end

#picture_pathObject



137
138
139
# File 'lib/gaku/testing/feature_helpers.rb', line 137

def picture_path
  Rails.root + '../../../core/spec/support/120x120.jpg'
end


59
60
61
# File 'lib/gaku/testing/feature_helpers.rb', line 59

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


67
68
69
# File 'lib/gaku/testing/feature_helpers.rb', line 67

def show_link
  '.show-link'
end

#size_of(selector) ⇒ Object



83
84
85
# File 'lib/gaku/testing/feature_helpers.rb', line 83

def size_of(selector)
  page.all(selector).size
end

#submitObject



27
28
29
# File 'lib/gaku/testing/feature_helpers.rb', line 27

def submit
  "#submit-#{@@resource}-button"
end


15
16
17
# File 'lib/gaku/testing/feature_helpers.rb', line 15

def tab_link
  "##{@@resource_plural}-tab-link"
end

#tableObject



43
44
45
# File 'lib/gaku/testing/feature_helpers.rb', line 43

def table
  "##{@@resource_plural}-index"
end

#table_rowsObject



47
48
49
# File 'lib/gaku/testing/feature_helpers.rb', line 47

def table_rows
  "##{@@resource_plural}-index tr"
end

#visible?(selector) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/gaku/testing/feature_helpers.rb', line 87

def visible?(selector)
  find(selector).visible?
end

#wait_for_ajax(timeout = Capybara.default_wait_time) ⇒ Object



116
117
118
119
120
121
# File 'lib/gaku/testing/feature_helpers.rb', line 116

def wait_for_ajax(timeout = Capybara.default_wait_time)
  Timeout.timeout(timeout) do
    active = page.evaluate_script('jQuery.active')
    active = page.evaluate_script('jQuery.active') until active == 0
  end
end

#wait_for_readyObject



112
113
114
# File 'lib/gaku/testing/feature_helpers.rb', line 112

def wait_for_ready
  page.has_no_selector?('.nprogress-busy')
end