Skip to content

Instantly share code, notes, and snippets.

@olleolleolle
Last active August 29, 2015 14:21
Show Gist options
  • Save olleolleolle/bc6a0f91614e20c4fed7 to your computer and use it in GitHub Desktop.
Save olleolleolle/bc6a0f91614e20c4fed7 to your computer and use it in GitHub Desktop.
Reveal-md formatter for Cucumber: show the Scenarios and Features on a beamer.

HI!

You write Cucumber features for collaboration.

If you present them as flat plaintext, non-programmers won't read them.

Try, using Reveal.js and show the scenario texts on a beamer.

This is a guide on how to do it!

First, copy the reveal_formatter.rb into your Cucumber support folder.

mkdir -p features/support/cucumber/formatter
cd features/support/cucumber/formatter
wget https://gist.githubusercontent.com/olleolleolle/bc6a0f91614e20c4fed7/raw/442197afe4f90b18ab90a3581861918fc7a78577/reveal_formatter.rb

So, in my support folder, I now have the formatter's file in the necessary folder structure:

├── cucumber
│   └── formatter
│       └── reveal_formatter.rb

In order to keep the formatter's long name out of the way, we have created a Profile in cucumber.yml.

reveal: '--format Cucumber::Formatter::RevealFormatter --out slides.md'

Then, I can call it shorter using the fancy reveal Cucumber profile:

$ bundle exec cucumber -p reveal

So, that created a Markdown file: slides.md. Let's make a slideshow from it using Reveal-md.

$ npm install -g reveal-md
$ reveal-md slides.md

Re-run reveal-md using a custom theme, until you get a style you desire:

reveal-md slides.md --theme solarized

So. There you have it. Cucumber collaboration can be harder than it has to be, if the text isn't presented clearly.

require 'cucumber/formatter/io'
module Cucumber
module Formatter
class RevealFormatter
include Io
def initialize(runtime, path_or_io, options)
@last_scenario_title = nil
@last_tags = nil
@io = ensure_io(path_or_io, 'md')
end
def before_features(features)
@io.puts '# Cucumber Features'
@io.puts '## With steps'
@io.puts
@io.puts '---'
@io.puts
end
def tag_name(tag_name)
@io.puts "#{tag_name}<br>"
end
def before_comment(comment)
@io.puts '```'
end
def after_comment(comment)
@io.puts '```'
end
def comment_line(comment_line)
@io.puts comment_line
end
def before_feature(feature)
@last_scenario_title = feature.short_name
end
def before_steps(*args)
@io.puts "\n----\n\n"
@io.puts "Steps to prove the scenario:"
end
def scenario_name(keyword, name, file_colon_line, source_indent)
@io.puts "# #{@last_scenario_title}"
@io.puts "## #{name}"
end
def step_name(keyword, step_match, status, source_indent, background, file_colon_line)
@io.puts "> #{keyword} #{step_match.format_args('%s')}<br>" unless @in_background
end
def before_background(background)
@in_background = true
end
def after_background(background)
@in_background = nil
end
def background_name(keyword, name, file_colon_line, source_indent)
@listing_background = true
@io.puts "#{keyword} #{name}"
end
def after_steps(*args)
#@io.puts "\n---\n"
end
def after_feature_element(*args)
@io.puts
@io.puts '---'
@io.puts
end
def after_features(*args)
@io.puts
@io.puts '---'
@io.puts
@io.puts "# Thanks!"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment