Skip to content

Instantly share code, notes, and snippets.

@jerilevine
Last active April 24, 2017 20:16
Show Gist options
  • Select an option

  • Save jerilevine/478fdeb43754d4e9b7ce6b4f74fa2e06 to your computer and use it in GitHub Desktop.

Select an option

Save jerilevine/478fdeb43754d4e9b7ce6b4f74fa2e06 to your computer and use it in GitHub Desktop.
Stepwise logging for Turnip
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
# 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