aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-08-26 18:39:40 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-08-27 20:44:01 +0900
commit52422f2af60c0830da6e5749700f911c6c0b22ea (patch)
treef30cc5896cc16b713358c993fb7715b76c514b0f /actionpack
parentca2a66abef16f0b0a529c1cd533e7ba179e30890 (diff)
downloadrails-52422f2af60c0830da6e5749700f911c6c0b22ea.tar.gz
rails-52422f2af60c0830da6e5749700f911c6c0b22ea.tar.bz2
rails-52422f2af60c0830da6e5749700f911c6c0b22ea.zip
Retrive screenshot in relative path of current directory
In Rails engine `Rails.root `returns the path of the dummy application. Therefore, there is no `tmp` directly where the test is running, so can not get the screenshot. For this reason, instead of directly specifying tmp, retrive screenshot by relative path from the current directory. Fixes #30405
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md6
-rw-r--r--actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb14
-rw-r--r--actionpack/test/dispatch/system_testing/screenshot_helper_test.rb32
3 files changed, 39 insertions, 13 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 938b24a6b9..b56a1c5d4b 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Make `take_failed_screenshot` work within engine.
+
+ Fixes #30405.
+
+ *Yuji Yaginuma*
+
* Deprecate `ActionDispatch::TestResponse` response aliases
`#success?`, `#missing?` & `#error?` are not supported by the actual
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 7efdeb4e7b..6c337cdc31 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
@@ -44,11 +44,15 @@ module ActionDispatch
end
def image_path
- "tmp/screenshots/#{image_name}.png"
+ @image_path ||= absolute_image_path.relative_path_from(Pathname.pwd).to_s
+ end
+
+ def absolute_image_path
+ Rails.root.join("tmp/screenshots/#{image_name}.png")
end
def save_image
- page.save_screenshot(Rails.root.join(image_path))
+ page.save_screenshot(absolute_image_path)
end
def output_type
@@ -69,10 +73,10 @@ module ActionDispatch
case output_type
when "artifact"
- message << "\e]1338;url=artifact://#{image_path}\a\n"
+ message << "\e]1338;url=artifact://#{absolute_image_path}\a\n"
when "inline"
- name = inline_base64(File.basename(image_path))
- image = inline_base64(File.read(image_path))
+ name = inline_base64(File.basename(absolute_image_path))
+ image = inline_base64(File.read(absolute_image_path))
message << "\e]1337;File=name=#{name};height=400px;inline=1:#{image}\a\n"
end
diff --git a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
index 4b49a42317..2afda31cf5 100644
--- a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
+++ b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
@@ -8,23 +8,29 @@ class ScreenshotHelperTest < ActiveSupport::TestCase
test "image path is saved in tmp directory" do
new_test = DrivenBySeleniumWithChrome.new("x")
- assert_equal "tmp/screenshots/x.png", new_test.send(:image_path)
+ Rails.stub :root, Pathname.getwd do
+ assert_equal "tmp/screenshots/x.png", new_test.send(:image_path)
+ end
end
test "image path includes failures text if test did not pass" do
new_test = DrivenBySeleniumWithChrome.new("x")
- new_test.stub :passed?, false do
- assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path)
+ Rails.stub :root, Pathname.getwd do
+ new_test.stub :passed?, false do
+ assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path)
+ end
end
end
test "image path does not include failures text if test skipped" do
new_test = DrivenBySeleniumWithChrome.new("x")
- new_test.stub :passed?, false do
- new_test.stub :skipped?, true do
- assert_equal "tmp/screenshots/x.png", new_test.send(:image_path)
+ Rails.stub :root, Pathname.getwd do
+ new_test.stub :passed?, false do
+ new_test.stub :skipped?, true do
+ assert_equal "tmp/screenshots/x.png", new_test.send(:image_path)
+ end
end
end
end
@@ -36,13 +42,23 @@ class ScreenshotHelperTest < ActiveSupport::TestCase
new_test = DrivenBySeleniumWithChrome.new("x")
- new_test.stub :passed?, false do
- assert_match "\e]1338;url=artifact://tmp/screenshots/failures_x.png\a", new_test.send(:display_image)
+ Rails.stub :root, Pathname.getwd do
+ new_test.stub :passed?, false do
+ assert_match %r|url=artifact://.+?tmp/screenshots/failures_x\.png|, new_test.send(:display_image)
+ end
end
ensure
ENV["RAILS_SYSTEM_TESTING_SCREENSHOT"] = original_output_type
end
end
+
+ test "image path returns the relative path from current directory" do
+ new_test = DrivenBySeleniumWithChrome.new("x")
+
+ Rails.stub :root, Pathname.getwd.join("..") do
+ assert_equal "../tmp/screenshots/x.png", new_test.send(:image_path)
+ end
+ end
end
class RackTestScreenshotsTest < DrivenByRackTest