From 983275eb7c01eaeba5798a422514f4d9d6b74786 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 19 Feb 2017 12:12:06 -0500 Subject: [PATCH] Fix screenshot helper to provide correct file name We only want the file name to include the word `failures` if it failed, not any time the user wants to take a screenshot during a test run. --- .../system_testing/test_helpers/screenshot_helper.rb | 8 ++++++-- .../dispatch/system_testing/screenshot_helper_test.rb | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb b/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb index 1ad64b7f78..ab14910b41 100644 --- a/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +++ b/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb @@ -17,7 +17,7 @@ module ActionDispatch # Takes a screenshot of the current page in the browser if the test # failed. # - # +take_screenshot+ is included in system_test_helper.rb that is + # +take_failed_screenshot+ is included in system_test_helper.rb that is # generated with the application. To take screenshots when a test fails # add +take_failed_screenshot+ to the teardown block before clearing # sessions. @@ -26,8 +26,12 @@ module ActionDispatch end private + def image_name + passed? ? method_name : "failures_#{method_name}" + end + def image_path - "tmp/screenshots/failures_#{method_name}.png" + "tmp/screenshots/#{image_name}.png" end def save_image diff --git a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb index 3da89f4a10..8c14f799b0 100644 --- a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb +++ b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb @@ -5,6 +5,14 @@ class ScreenshotHelperTest < ActiveSupport::TestCase test "image path is saved in tmp directory" do new_test = ActionDispatch::SystemTestCase.new("x") - assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path) + assert_equal "tmp/screenshots/x.png", new_test.send(:image_path) + end + + test "image path includes failures text if test did not pass" do + new_test = ActionDispatch::SystemTestCase.new("x") + + new_test.stub :passed?, false do + assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path) + end end end