Module: HandyFeatureHelpers::MainHelpers

Included in:
AllHelpers
Defined in:
lib/handy_feature_helpers/main_helpers.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#accept_alertObject



74
75
76
77
78
# File 'lib/handy_feature_helpers/main_helpers.rb', line 74

def accept_alert
  if Capybara.javascript_driver == 'selenium'
    page.driver.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError
  end
end


34
35
36
# File 'lib/handy_feature_helpers/main_helpers.rb', line 34

def cancel_link
  "#cancel-#{@@resource}-link"
end

#click(selector) ⇒ Object



92
93
94
# File 'lib/handy_feature_helpers/main_helpers.rb', line 92

def click(selector)
  find(selector).click
end

#click_option(resource) ⇒ Object



100
101
102
# File 'lib/handy_feature_helpers/main_helpers.rb', line 100

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

#click_text(text) ⇒ Object



96
97
98
# File 'lib/handy_feature_helpers/main_helpers.rb', line 96

def click_text(text)
  find('a',:text => text).click
end

#closeObject



70
71
72
# File 'lib/handy_feature_helpers/main_helpers.rb', line 70

def close
  '.close'
end

#count?(count) ⇒ Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/handy_feature_helpers/main_helpers.rb', line 147

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

#count_divObject



42
43
44
# File 'lib/handy_feature_helpers/main_helpers.rb', line 42

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

#current_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/handy_feature_helpers/main_helpers.rb', line 151

def current_path?(path)
  expect(current_path).to eq path
end


66
67
68
# File 'lib/handy_feature_helpers/main_helpers.rb', line 66

def delete_link
  '.delete-link'
end


54
55
56
# File 'lib/handy_feature_helpers/main_helpers.rb', line 54

def edit_link
  '.edit-link'
end

#ensure_cancel_creating_is_workingObject



127
128
129
130
131
132
133
134
135
# File 'lib/handy_feature_helpers/main_helpers.rb', line 127

def ensure_cancel_creating_is_working
  click cancel_link

  invisible? form
  click new_link

  visible? submit
  invisible? new_link
end

#ensure_cancel_modal_is_workingObject



137
138
139
140
# File 'lib/handy_feature_helpers/main_helpers.rb', line 137

def ensure_cancel_modal_is_working
  click cancel_link
  invisible? modal
end

#ensure_delete_is_workingObject



120
121
122
123
124
125
# File 'lib/handy_feature_helpers/main_helpers.rb', line 120

def ensure_delete_is_working
  tr_count = size_of table_rows
  within(table) { click delete_link }
  accept_alert
  size_of(table_rows) == tr_count - 1
end

#formObject



22
23
24
# File 'lib/handy_feature_helpers/main_helpers.rb', line 22

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

#get_resourceObject



14
15
16
# File 'lib/handy_feature_helpers/main_helpers.rb', line 14

def get_resource
  @@resource
end

#has_content?(text) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/handy_feature_helpers/main_helpers.rb', line 104

def has_content?(text)
  expect(page).to have_content(text)
end

#has_no_content?(text) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/handy_feature_helpers/main_helpers.rb', line 108

def has_no_content?(text)
  expect(page).to have_no_content(text)
end

#has_validations?Boolean

Returns:

  • (Boolean)


142
143
144
145
# File 'lib/handy_feature_helpers/main_helpers.rb', line 142

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

#invisible?(selector) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/handy_feature_helpers/main_helpers.rb', line 88

def invisible?(selector)
  !page.find(selector).visible?
end


58
59
60
# File 'lib/handy_feature_helpers/main_helpers.rb', line 58

def js_edit_link
  '.js-edit-link'
end


38
39
40
# File 'lib/handy_feature_helpers/main_helpers.rb', line 38

def modal
  '.modal'
end


26
27
28
# File 'lib/handy_feature_helpers/main_helpers.rb', line 26

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

#set_resource(x) ⇒ Object



9
10
11
12
# File 'lib/handy_feature_helpers/main_helpers.rb', line 9

def set_resource(x)
  @@resource = x
  @@resource_plural = plural(x)
end


62
63
64
# File 'lib/handy_feature_helpers/main_helpers.rb', line 62

def show_link
  '.show-link'
end

#size_of(selector) ⇒ Object



80
81
82
# File 'lib/handy_feature_helpers/main_helpers.rb', line 80

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

#submitObject



30
31
32
# File 'lib/handy_feature_helpers/main_helpers.rb', line 30

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


18
19
20
# File 'lib/handy_feature_helpers/main_helpers.rb', line 18

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

#tableObject



46
47
48
# File 'lib/handy_feature_helpers/main_helpers.rb', line 46

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

#table_has_content?(text) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/handy_feature_helpers/main_helpers.rb', line 112

def table_has_content?(text)
  within(table) { has_content?(text) }
end

#table_has_no_content?(text) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/handy_feature_helpers/main_helpers.rb', line 116

def table_has_no_content?(text)
  within(table) { has_no_content?(text) }
end

#table_rowsObject



50
51
52
# File 'lib/handy_feature_helpers/main_helpers.rb', line 50

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

#visible?(selector) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/handy_feature_helpers/main_helpers.rb', line 84

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