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



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


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

#closeObject



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

def close
  '.close'
end

#count?(count) ⇒ Boolean

Returns:

  • (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_divObject



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

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


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

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



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

#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)


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

Returns:

  • (Boolean)


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

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


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

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



140
141
142
# File 'lib/gaku/testing/feature_helpers.rb', line 140

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


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


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

#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)


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_readyObject



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

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