Skip to content

Commit

Permalink
Merge PR #697 "Support of relative image sources". Update History.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
brasmusson committed Dec 28, 2014
2 parents 8bd1fa9 + 4cc2e76 commit ddde9ef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### New Features

* Let the HTML formatter store the relative path to files in the report ([697](https://github.com/cucumber/cucumber/pull/697) @idstein, @brasmusson)
* Allow cucumber.yml to parse % erb code lines ([755](https://github.com/cucumber/cucumber/pull/755) @snowe2010)
* Give each step definition a unique copy of argument objects ([760](https://github.com/cucumber/cucumber/pull/760) @tooky)

Expand Down
5 changes: 5 additions & 0 deletions lib/cucumber/formatter/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'builder'
require 'cucumber/formatter/duration'
require 'cucumber/formatter/io'
require 'pathname'

module Cucumber
module Formatter
Expand Down Expand Up @@ -50,6 +51,10 @@ def embed(src, mime_type, label)
def embed_image(src, label)
id = "img_#{@img_id}"
@img_id += 1
if @io.respond_to?(:path) and File.file?(src)
out_dir = Pathname.new(File.dirname(File.absolute_path(@io.path)))
src = Pathname.new(File.absolute_path(src)).relative_path_from(out_dir)
end
@builder.span(:class => 'embed') do |pre|
pre << %{<a href="" onclick="img=document.getElementById('#{id}'); img.style.display = (img.style.display == 'none' ? 'block' : 'none');return false">#{label}</a><br>&nbsp;
<img id="#{id}" style="display: none" src="#{src}"/>}
Expand Down
29 changes: 29 additions & 0 deletions spec/cucumber/formatter/html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ module Formatter
}).not_to raise_error
end

describe "when writing the report to a file" do
before(:each) do
allow(@out).to receive(:respond_to?).with(:path, false).and_return(true)
expect(@out).to receive(:respond_to?).with(:path).and_return(true)
expect(@out).to receive(:path).and_return('out/file.html')
run_defined_feature
@doc = Nokogiri.HTML(@out.string)
end

describe "with a step that embeds a snapshot" do
define_steps do
Given(/snap/) {
RSpec::Mocks.allow_message(File, :file?) { true }
embed('out/snapshot.jpeg', 'image/jpeg')
}
end

define_feature(<<-FEATURE)
Feature:
Scenario:
Given snap
FEATURE

it "converts the snapshot path to a relative path" do
expect(@doc.css('.embed img').first.attributes['src'].to_s).to eq "snapshot.jpeg"
end
end
end

describe "given a single feature" do
before(:each) do
run_defined_feature
Expand Down

0 comments on commit ddde9ef

Please sign in to comment.