diff --git a/lib/cucumber/formatter/html.rb b/lib/cucumber/formatter/html.rb index ef5d6b05e5..850e875e7a 100644 --- a/lib/cucumber/formatter/html.rb +++ b/lib/cucumber/formatter/html.rb @@ -28,6 +28,10 @@ def initialize(runtime, path_or_io, options) def embed(src, mime_type, label) case(mime_type) when /^image\/(png|gif|jpg|jpeg)/ + unless File.file?(src) or src =~ /^data:image\/(png|gif|jpg|jpeg);base64,/ + type = mime_type =~ /;base[0-9]+$/ ? mime_type : mime_type + ";base64" + src = "data:" + type + "," + src + end embed_image(src, label) end end diff --git a/spec/cucumber/formatter/html_spec.rb b/spec/cucumber/formatter/html_spec.rb index 15b7dfb2a8..0de8ebbd67 100644 --- a/spec/cucumber/formatter/html_spec.rb +++ b/spec/cucumber/formatter/html_spec.rb @@ -235,7 +235,10 @@ module Formatter describe "with a step that embeds a snapshot" do define_steps do - Given(/snap/) { embed('snapshot.jpeg', 'image/jpeg') } + Given(/snap/) { + File.should_receive(:file?).with('snapshot.jpeg').and_return(true) + embed('snapshot.jpeg', 'image/jpeg') + } end define_feature(<<-FEATURE) @@ -247,6 +250,34 @@ module Formatter it { @doc.css('.embed img').first.attributes['src'].to_s.should == "snapshot.jpeg" } end + describe "with a step that embeds a snapshot content manually" do + define_steps do + Given(/snap/) { embed('data:image/png;base64,YWJj', 'image/png') } + end + + define_feature(<<-FEATURE) + Feature: + Scenario: + Given snap + FEATURE + + it { @doc.css('.embed img').first.attributes['src'].to_s.should == "data:image/png;base64,YWJj" } + end + + describe "with a step that embeds a snapshot content" do + define_steps do + Given(/snap/) { embed('YWJj', 'image/png;base64') } + end + + define_feature(<<-FEATURE) + Feature: + Scenario: + Given snap + FEATURE + + it { @doc.css('.embed img').first.attributes['src'].to_s.should == "data:image/png;base64,YWJj" } + end + describe "with an undefined Given step then an undefined And step" do define_feature(<<-FEATURE) Feature: