summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTyler Mercier <tylermercier@gmail.com>2013-07-23 14:55:15 -0600
committerTyler Mercier <tylermercier@gmail.com>2013-07-23 14:55:15 -0600
commitdf3ac70840a315964e711bc760c23c7861dd8140 (patch)
tree45bec5ef6cebbcc97a9911a76bb1a166092fc2de /spec
parentb8adf8fcfa6457ccb7020a7884a330a432855d59 (diff)
switch back to features folder. cleanup spec_helper
Diffstat (limited to 'spec')
-rw-r--r--spec/features/google_spec.rb (renamed from spec/requests/google_spec.rb)0
-rw-r--r--spec/features/landing_page_spec.rb (renamed from spec/requests/landing_page_spec.rb)0
-rw-r--r--spec/spec_helper.rb6
-rw-r--r--spec/support/capybara_ext.rb99
4 files changed, 1 insertions, 104 deletions
diff --git a/spec/requests/google_spec.rb b/spec/features/google_spec.rb
index 86932fb..86932fb 100644
--- a/spec/requests/google_spec.rb
+++ b/spec/features/google_spec.rb
diff --git a/spec/requests/landing_page_spec.rb b/spec/features/landing_page_spec.rb
index 0321186..0321186 100644
--- a/spec/requests/landing_page_spec.rb
+++ b/spec/features/landing_page_spec.rb
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 92da919..a1e47fd 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -24,13 +24,12 @@ require 'capybara/rails'
require 'capybara/rspec'
require 'capybara/rspec'
require 'capybara/poltergeist'
-#require 'capybara-screenshot/rspec'
require 'database_cleaner'
Capybara.register_driver :poltergeist_with_long_timeout do |app|
Capybara::Poltergeist::Driver.new(app, timeout: 30)
end
-Capybara.javascript_driver = :poltergeist_with_long_timeout #unless FeatureFlag::BROWSER
+Capybara.javascript_driver = :poltergeist_with_long_timeout
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
@@ -59,9 +58,6 @@ RSpec.configure do |config|
config.include CapybaraExt
- config.include Capybara::DSL, type: :request
- config.include Capybara::RSpecMatchers, type: :request
-
#config.extend AuthorizationHelpers::Controller, type: :controller
config.include FactoryGirl::Syntax::Methods
diff --git a/spec/support/capybara_ext.rb b/spec/support/capybara_ext.rb
index 35b50ce..c910452 100644
--- a/spec/support/capybara_ext.rb
+++ b/spec/support/capybara_ext.rb
@@ -1,107 +1,8 @@
-# http://techblog.fundinggates.com/blog/2012/08/capybara-2-0-upgrade-guide/
-# https://github.com/mattheworiordan/capybara-screenshot
module CapybaraExt
- def page!
- save_and_open_page
- end
-
def wait_until(timeout = Capybara.default_wait_time)
Timeout.timeout(timeout) do
sleep(0.1) until value = yield
value
end
end
-
- def retry_on_timeout(n = 3, &block)
- begin
- block.call
- rescue Capybara::ElementNotFound
- if n > 0
- puts "Catched error: #{e.message}. #{n-1} more attempts."
- retry_on_timeout(n - 1, &block)
- else
- raise
- end
- end
- end
-
- def click_icon(type)
- first(".icon-#{type}").click
- end
-
- def eventually_fill_in(field, options={})
- Capybara.wait_until do
- find_field field
- end
- fill_in field, options
- end
-
- def within_row(num, &block)
- within("table.index tbody tr:nth-child(#{num})", &block)
- end
-
- def column_text(num)
- find("td:nth-child(#{num})").text
- end
-
- def set_select2_field(field, value)
- page.execute_script %Q{$('#{field}').select2('val', '#{value}')}
- end
-
- def select2_search(value, options)
- id = find_label_by_text(options[:from])
- options[:from] = "#s2id_#{id}"
- targetted_select2_search(value, options)
- end
-
- def targetted_select2_search(value, options)
- #p %Q{$('#{options[:from]}').select2('open')}
- page.execute_script %Q{$('#{options[:from]}').select2('open')}
- container = options[:dropdown_css] || ".select2-with-searchbox"
- #p "$('#{container} input.select2-input').val('#{value}').trigger('keyup-change');"
- page.execute_script "$('#{container} input.select2-input').val('#{value}').trigger('keyup-change');"
- select_select2_result(value)
- end
-
- def select2(value, options)
- id = find_label_by_text(options[:from])
-
- # generate select2 id
- options[:from] = "#s2id_#{id}"
- targetted_select2(value, options)
- end
-
- def targetted_select2(value, options)
- # find select2 element and click it
- find(options[:from]).find('a').click
- select_select2_result(value)
- end
-
- def select_select2_result(value)
- #p %Q{$("div.select2-result-label:contains('#{value}')").mouseup()}
- sleep(1)
- page.execute_script(%Q{$("div.select2-result-label:contains('#{value}')").mouseup()})
- end
-
- def find_label_by_text(text)
- label = find_label(text)
- counter = 0
-
- # Because JavaScript testing is prone to errors...
- while label.nil? && counter < 10
- sleep(1)
- counter += 1
- label = find_label(text)
- end
-
- if label.nil?
- raise "Could not find label by text #{text}"
- end
-
- label ? label['for'] : text
- end
-
- def find_label(text)
- first(:xpath, "//label[text()='#{text}']")
- end
end