Skip to content

Commit

Permalink
Merge pull request rails#30436 from y-yagi/backport_30421
Browse files Browse the repository at this point in the history
Backport rails#30421 to 5-1-stable
  • Loading branch information
eileencodes authored Aug 28, 2017
2 parents df776aa + 8f900b7 commit 595a231
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
6 changes: 6 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Make `take_failed_screenshot` work within engine.

Fixes #30405.

*Yuji Yaginuma*

## Rails 5.1.4.rc1 (August 24, 2017) ##

* No changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ def image_name
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
Expand All @@ -67,10 +71,10 @@ def display_image

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

Expand Down
26 changes: 20 additions & 6 deletions actionpack/test/dispatch/system_testing/screenshot_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,40 @@ 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

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
Expand Down

0 comments on commit 595a231

Please sign in to comment.