Skip to content

Instantly share code, notes, and snippets.

@jeroenvandijk
Created December 16, 2011 16:53
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 jeroenvandijk/1486853 to your computer and use it in GitHub Desktop.
Save jeroenvandijk/1486853 to your computer and use it in GitHub Desktop.
[Turnip] First hack to get line number and filename of feature
Failures:
1) Initialization Init and processing of schemes schemes until none left
Failure/Error: execute_without_backtrace(*args, &block)
expected 1 items, got 0
# ./spec/acceptance/sessions.feature:75
# spec/acceptance/steps/sessions_steps.rb:27:in `block (2 levels) in <top (required)>'
# ./spec/support/turnip_hack.rb:64:in `execute_with_backtrace'
# ./spec/support/turnip_hack.rb:31:in `block (6 levels) in run'
# ./spec/support/turnip_hack.rb:28:in `each'
# ./spec/support/turnip_hack.rb:28:in `block (5 levels) in run'
module Turnip
def self.run(feature_file)
Turnip::Builder.build(feature_file).features.each do |feature|
describe feature.name, feature.metadata_hash do
feature_tags = feature.active_tags.uniq
feature.backgrounds.each do |background|
before do
background.steps.each do |step|
# Hax here, add file_name
step.file_name = feature_file.file_name
Turnip::StepDefinition.execute(self, Turnip::StepModule.all_steps_for(*feature_tags), step)
end
end
end
feature.scenarios.each do |scenario|
context scenario.metadata_hash do
scenario_tags = (feature_tags + scenario.active_tags).uniq
Turnip::StepModule.modules_for(*scenario_tags).each { |mod| include mod }
it scenario.name do
scenario.steps.each do |step|
# Hax here, add file_name
step.file_name = feature_file.file_name
Turnip::StepDefinition.execute(self, Turnip::StepModule.all_steps_for(*scenario_tags), step)
end
end
end
end
end
end
end
end
class Turnip::Builder
# Hax here, add file_name and line accessor
class Step
attr_reader :line, :file_name
attr_writer :line, :file_name
end
def step(step)
if step.doc_string
extra_arg = step.doc_string.value
elsif step.rows
extra_arg = Turnip::Table.new(step.rows.map { |row| row.cells(&:value) })
end
# Hax here, add line number
@current_step_context.steps << Step.new(step.name, extra_arg).tap { |s| s.line = step.line }
end
end
class Turnip::StepDefinition
class << self
def execute_with_backtrace(*args, &block)
begin
execute_without_backtrace(*args, &block)
rescue Exception => e
e.backtrace.insert(3, "#{args[2].file_name}:#{args[2].line}")
raise e
end
end
# Ouch! alias_method_chain
alias_method_chain :execute, :backtrace
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment