Skip to content

Instantly share code, notes, and snippets.

@sax
Last active July 18, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sax/286791b04e51e4d5c4e9fafc0f75cc1e to your computer and use it in GitHub Desktop.
Save sax/286791b04e51e4d5c4e9fafc0f75cc1e to your computer and use it in GitHub Desktop.
Flow output in feature specs
# lib/test/scenario_flows.rb
module Test
module ScenarioFlows
def formatter
@formatter ||= RSpec.configuration.formatters.first
end
def formatter_names
@formatter_names ||= RSpec.configuration.formatters.map { |f| f.class.to_s }.join(' ')
end
def output
@output ||= formatter.output
end
def flow_info(msg, ending: "\n")
output.printf("\e[1;36m#{msg}\e[0m#{ending}")
end
def flow(description)
raise 'Feature flows must be used with blocks' unless block_given?
flow_info('.', ending: '') if formatter_names.include?('Progress')
flow_info("#{formatter.send(:current_indentation)}#{description}") if formatter_names.include?('Documentation')
yield
end
end
end
# spec/support/capybara.rb
require 'test/scenario_flows'
RSpec.configure do |config|
config.include Test::ScenarioFlows, type: :feature
end
# spec/features/with_flow_spec.rb
require 'rails_helper'
RSpec.describe 'it does stuff', type: :feature do
let(:user) { FactoryGirl.create(:user) }
scenario 'with things' do
flow 'sign in' do
sign_in user
end
flow 'visit other pages' do
visit '/blah'
click_link 'Wow'
expect(page).to have_text('Such amaze')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment