Skip to content

Commit

Permalink
Support embedding images directly in html files
Browse files Browse the repository at this point in the history
  • Loading branch information
brasmusson committed Jun 22, 2014
1 parent 0bb7ed0 commit 7f146d3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/cucumber/formatter/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ 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,/

This comment has been minimized.

Copy link
@Vanuan

Vanuan Sep 8, 2015

what about http urls?

src = "data:" + mime_type + ";base64," + 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') }
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 7f146d3

Please sign in to comment.