Last active
July 18, 2017 19:14
-
-
Save sax/286791b04e51e4d5c4e9fafc0f75cc1e to your computer and use it in GitHub Desktop.
Flow output in feature specs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/support/capybara.rb | |
require 'test/scenario_flows' | |
RSpec.configure do |config| | |
config.include Test::ScenarioFlows, type: :feature | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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