aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionsystemtest/lib/action_system_test/test_helper.rb2
-rw-r--r--actionsystemtest/lib/action_system_test/test_helpers.rb2
-rw-r--r--actionsystemtest/lib/action_system_test/test_helpers/assertions.rb40
-rw-r--r--actionsystemtest/lib/action_system_test/test_helpers/form_helper.rb58
-rw-r--r--actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb22
-rw-r--r--actionsystemtest/test/abstract_unit.rb56
6 files changed, 71 insertions, 109 deletions
diff --git a/actionsystemtest/lib/action_system_test/test_helper.rb b/actionsystemtest/lib/action_system_test/test_helper.rb
index 9ff5746244..46a4ac466b 100644
--- a/actionsystemtest/lib/action_system_test/test_helper.rb
+++ b/actionsystemtest/lib/action_system_test/test_helper.rb
@@ -3,8 +3,6 @@ require "action_system_test/test_helpers"
module ActionSystemTest
module TestHelper # :nodoc:
- include TestHelpers::Assertions
- include TestHelpers::FormHelper
include TestHelpers::ScreenshotHelper
include Capybara::DSL
diff --git a/actionsystemtest/lib/action_system_test/test_helpers.rb b/actionsystemtest/lib/action_system_test/test_helpers.rb
index 10ddeff92f..bc0e015874 100644
--- a/actionsystemtest/lib/action_system_test/test_helpers.rb
+++ b/actionsystemtest/lib/action_system_test/test_helpers.rb
@@ -2,8 +2,6 @@ module ActionSystemTest
module TestHelpers
extend ActiveSupport::Autoload
- autoload :Assertions
- autoload :FormHelper
autoload :ScreenshotHelper
end
end
diff --git a/actionsystemtest/lib/action_system_test/test_helpers/assertions.rb b/actionsystemtest/lib/action_system_test/test_helpers/assertions.rb
deleted file mode 100644
index edc8dbaa7f..0000000000
--- a/actionsystemtest/lib/action_system_test/test_helpers/assertions.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module ActionSystemTest
- module TestHelpers
- # Assertions for system testing that aren't included by default in Capybara.
- # These are assertions that are useful specifically for Rails applications.
- module Assertions
- # Asserts that all of the provided selectors are present on the given page.
- #
- # assert_all_of_selectors('p', 'td')
- def assert_all_of_selectors(*items)
- options = items.extract_options!
- type = type_for_selector(items)
-
- items.each do |item|
- assert_selector type, item, options
- end
- end
-
- # Asserts that none of the provided selectors are present on the page.
- #
- # assert_none_of_selectors('ul', 'ol')
- def assert_none_of_selectors(*items)
- options = items.extract_options!
- type = type_for_selector(items)
-
- items.each do |item|
- assert_no_selector type, item, options
- end
- end
-
- private
- def type_for_selector(*items)
- if items.first.is_a?(Symbol)
- items.shift
- else
- Capybara.default_selector
- end
- end
- end
- end
-end
diff --git a/actionsystemtest/lib/action_system_test/test_helpers/form_helper.rb b/actionsystemtest/lib/action_system_test/test_helpers/form_helper.rb
deleted file mode 100644
index 3c65c23f6d..0000000000
--- a/actionsystemtest/lib/action_system_test/test_helpers/form_helper.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-module ActionSystemTest
- module TestHelpers
- # Form helpers for system testing that aren't included by default in
- # Capybara.
- module FormHelper
- # Finds all provided fields or text areas and fills in with supplied values.
- #
- # fill_in_all_fields('Name' => 'Eileen', 'Job Title' => 'Programmer')
- def fill_in_all_fields(fields)
- fields.each do |name, value|
- fill_in name, with: value
- end
- end
-
- # Locates a checkbox that is present inside a label and checks it. When
- # using styled boxes Selenium may not be able to see the checkbox. This
- # form helper looks inside the checkbox and clicks the label instead of
- # setting the value of the checkbox.
- #
- # click_checkbox_label 'Admin'
- #
- # By default +click_checkbox_label+ looks for checkboxes that are not
- # checked by default. To locate an already checked box and uncheck it
- # set checked to true:
- #
- # click_checkbox_label 'Admin', checked: true
- def click_checkbox_label(name, checked: false)
- field = find_checkbox(name, checked)
- label = find_label_wrapper(field)
- label.click
- end
-
- # In lieu of locating a button and calling +click_on+, +press_enter+ will
- # submit the form via enter. This method will only work for drivers that
- # load a browser like Selenium.
- #
- # test 'Adding a User' do
- # fill_in 'Name', with: 'Arya'
- #
- # press_enter
- #
- # assert_text 'Arya'
- # end
- def press_enter
- page.driver.browser.action.send_keys(:enter).perform
- end
-
- private
- def find_checkbox(name, checked)
- find(:field, name, visible: :all, checked: checked)
- end
-
- def find_label_wrapper(field, location: "./ancestor::label")
- field.find :xpath, location
- end
- end
- end
-end
diff --git a/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb b/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb
index 1b198b9b29..d4d0d79e95 100644
--- a/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb
+++ b/actionsystemtest/lib/action_system_test/test_helpers/screenshot_helper.rb
@@ -13,24 +13,32 @@ module ActionSystemTest
# ActionSystemTest.driver.supports_screenshots?
# => true
def take_screenshot
+ save_image
puts "[Screenshot]: #{image_path}"
- puts find_image
+ puts display_image
end
- # Takes a screenshot only if the test failed. This is included
- # by default in +teardown+ of system test.
+ # Takes a screenshot of the current page in the browser if the test
+ # failed.
+ #
+ # +take_screenshot+ is included in <tt>system_test_helper.rb</tt> that is
+ # generated with the application. To take screenshots when a test fails
+ # add +take_failed_screenshot+ to the teardown block before clearing any
+ # sessions.
def take_failed_screenshot
take_screenshot unless passed?
end
private
def image_path
- path = "tmp/screenshots/failures_#{method_name}.png"
- page.save_screenshot(Rails.root.join(path))
- path
+ "tmp/screenshots/failures_#{method_name}.png"
+ end
+
+ def save_image
+ page.save_screenshot(Rails.root.join(image_path))
end
- def find_image
+ def display_image
if ENV["CAPYBARA_INLINE_SCREENSHOT"] == "artifact"
"\e]1338;url=artifact://#{image_path}\a"
else
diff --git a/actionsystemtest/test/abstract_unit.rb b/actionsystemtest/test/abstract_unit.rb
index 26da9c7ccb..81630ca66d 100644
--- a/actionsystemtest/test/abstract_unit.rb
+++ b/actionsystemtest/test/abstract_unit.rb
@@ -3,6 +3,62 @@ require "action_controller"
require "action_dispatch"
require "action_system_test"
+# Set the Rails tests to use the +:rack_test+ driver because
+# we're not testing Capybara or it's drivers, but rather that
+# the methods accept the proper arguments.
+class RoutedRackApp
+ attr_reader :routes
+
+ def initialize(routes, &blk)
+ @routes = routes
+ @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
+ end
+
+ def call(env)
+ @stack.call(env)
+ end
+end
+
+class ActionSystemTestCase < ActionSystemTest::Base
+ ActionSystemTest.driver = :rack_test
+
+ def self.build_app(routes = nil)
+ RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new)
+ end
+end
+
+class PostsController < ActionController::Base
+ def index
+ render inline: <<HTML
+<html>
+<body>
+ <h1>This</h1>
+ <p title="the title" class="test">Paragraph 1</p>
+ <p title="the others" class="test">Paragraph 2</p>
+</body>
+</html>
+HTML
+ end
+end
+
+CapybaraRoutes = ActionDispatch::Routing::RouteSet.new
+CapybaraRoutes.draw do
+ resources :posts
+end
+
+# Initialize an application
+APP = ActionSystemTestCase.build_app(CapybaraRoutes)
+
+# Initialize an application for Capybara
+RailsApp = ActionSystemTestCase.new(APP)
+
+# Assign Capybara.app to original Rack Application
+Capybara.app = APP
+
+Capybara.add_selector :title_test do
+ xpath { |name| XPath.css(".test")[XPath.attr(:title).is(name.to_s)] }
+end
+
# Skips the current run on Rubinius using Minitest::Assertions#skip
def rubinius_skip(message = "")
skip message if RUBY_ENGINE == "rbx"