Skip to content

Commit

Permalink
Merge pull request #696 from brasmusson/html-formatter-embed-image-v1…
Browse files Browse the repository at this point in the history
….3.x

Support embedding images directly in html files
  • Loading branch information
mattwynne committed Aug 25, 2014
2 parents 5c127d5 + f39bf4e commit 4b2b948
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/cucumber/formatter/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 32 additions & 1 deletion spec/cucumber/formatter/html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 4b2b948

Please sign in to comment.