From b06740a04868bd72b83256077b1d7c38b054ea0c Mon Sep 17 00:00:00 2001 From: idstein Date: Wed, 25 Jun 2014 17:21:32 +0200 Subject: [PATCH] Support of relative image sources If an File-based image is not placed correctly, embedding the image will fail. This sanity check creates a relative path to the HTML IO object. Pre-conditions: - The image to be embedded must be file based - The html IO object must be support an absolute_path method (http://www.ruby-doc.org/core-2.1.2/File.html#method-c-absolute_path) --- lib/cucumber/formatter/html.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/cucumber/formatter/html.rb b/lib/cucumber/formatter/html.rb index a478c1c331..6439e3d006 100644 --- a/lib/cucumber/formatter/html.rb +++ b/lib/cucumber/formatter/html.rb @@ -2,6 +2,7 @@ require 'builder' require 'cucumber/formatter/duration' require 'cucumber/formatter/io' +require 'pathname' module Cucumber module Formatter @@ -43,6 +44,9 @@ def embed(src, mime_type, label) def embed_image(src, label) id = "img_#{@img_id}" @img_id += 1 + if @io.respond_to?(:absolute_path) and File.exist?(src) + src = Pathname.new(File.absolute_path(src)).relative_path_from(@io.absolute_path) + end @builder.span(:class => 'embed') do |pre| pre << %{#{label}
  }