Last active
April 24, 2017 20:16
-
-
Save jerilevine/478fdeb43754d4e9b7ce6b4f74fa2e06 to your computer and use it in GitHub Desktop.
Stepwise logging for Turnip
This file contains hidden or 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
| LOG_DIR = Rails.root.join('log') | |
| LOG = Logger.new(File.join(LOG_DIR, "turnip_#{Time.now.strftime("%Y%m%d%H%M")}.log")) | |
| LOG.level = Logger::DEBUG | |
| RSpec.configure do |config| | |
| config.before(:each) do | scenario | | |
| LOG.info("========================================") | |
| LOG.info("Starting test #{scenario.example_group.description}") | |
| end | |
| config.after(:each) do | scenario | | |
| LOG.info("Test #{scenario.example_group.description} completed.") | |
| end | |
| end |
This file contains hidden or 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
| # Monkeypatch for https://github.com/jnicklas/turnip | |
| # Output Turnip stepwise results to log file | |
| module Turnip | |
| module RSpec | |
| module Execute | |
| alias_method :old_run_step, :run_step | |
| def run_step(feature_file, step) | |
| begin | |
| old_run_step(feature_file, step) | |
| LOG.info("#{step.description}: As expected. PASS") | |
| rescue Turnip::Pending, ::RSpec::Core::Pending::SkipDeclaredInExample => e | |
| LOG.warn("#{step.description}: No such step. PENDING") | |
| raise | |
| rescue StandardError, ::RSpec::Expectations::ExpectationNotMetError => e | |
| LOG.error("#{step.description}: FAILED") | |
| raise e | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment