Skip to content

Commit

Permalink
Merge pull request mattheworiordan#163 from jthornec/master
Browse files Browse the repository at this point in the history
Add support for RSpec's JSON formatter
  • Loading branch information
mattheworiordan committed Apr 26, 2016
2 parents 14af3c1 + 5ab44e4 commit 78141a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/capybara-screenshot/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "capybara-screenshot/rspec/text_reporter"
require "capybara-screenshot/rspec/html_link_reporter"
require "capybara-screenshot/rspec/html_embed_reporter"
require "capybara-screenshot/rspec/json_reporter"
require "capybara-screenshot/rspec/textmate_link_reporter"

module Capybara
Expand Down Expand Up @@ -39,6 +40,7 @@ module RSpec
"RSpec::Core::Formatters::ProgressFormatter" => Capybara::Screenshot::RSpec::TextReporter,
"RSpec::Core::Formatters::DocumentationFormatter" => Capybara::Screenshot::RSpec::TextReporter,
"RSpec::Core::Formatters::HtmlFormatter" => Capybara::Screenshot::RSpec::HtmlLinkReporter,
"RSpec::Core::Formatters::JsonFormatter" => Capybara::Screenshot::RSpec::JsonReporter,
"RSpec::Core::Formatters::TextMateFormatter" => Capybara::Screenshot::RSpec::TextMateLinkReporter, # RSpec 2
"RSpec::Mate::Formatters::TextMateFormatter" => Capybara::Screenshot::RSpec::TextMateLinkReporter, # RSpec 3
"Fuubar" => Capybara::Screenshot::RSpec::TextReporter
Expand Down
19 changes: 19 additions & 0 deletions lib/capybara-screenshot/rspec/json_reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'capybara-screenshot/rspec/base_reporter'

module Capybara
module Screenshot
module RSpec
module JsonReporter
extend BaseReporter

enhance_with_screenshot :format_example

def format_example_with_screenshot(example)
format_example_without_screenshot(example).merge({
screenshot: example.metadata[:screenshot]
})
end
end
end
end
end
3 changes: 2 additions & 1 deletion spec/rspec/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def cmd_with_format(format)
formatters = {
progress: 'HTML screenshot:',
documentation: 'HTML screenshot:',
html: %r{<a href="file://\./tmp/screenshot\.html"[^>]*>HTML page</a>}
html: %r{<a href="file://\./tmp/screenshot\.html"[^>]*>HTML page</a>},
json: '"screenshot":{"'
}

# Textmate formatter is only included in RSpec 2
Expand Down

0 comments on commit 78141a6

Please sign in to comment.