Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support embedding images directly in html files #696

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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