lib/cucumber/ast/tree_walker.rb in cucumber-0.8.6 vs lib/cucumber/ast/tree_walker.rb in cucumber-0.8.7

- old
+ new

@@ -1,14 +1,14 @@ module Cucumber module Ast # Walks the AST, executing steps and notifying listeners class TreeWalker - attr_accessor :configuration #:nodoc: + attr_accessor :options #:nodoc: attr_reader :step_mother #:nodoc: - def initialize(step_mother, listeners = [], configuration = Cucumber::Configuration.default) - @step_mother, @listeners, @configuration = step_mother, listeners, configuration + def initialize(step_mother, listeners = [], options = {}, io = STDOUT) + @step_mother, @listeners, @options, @io = step_mother, listeners, options, io end def visit_features(features) broadcast(features) do features.accept(self) @@ -120,11 +120,11 @@ def visit_exception(exception, status) #:nodoc: broadcast(exception, status) end - def visit_doc_string(string) + def visit_py_string(string) broadcast(string) end def visit_table_row(table_row) broadcast(table_row) do @@ -140,19 +140,19 @@ def visit_table_cell_value(value, status) broadcast(value, status) end - # Print +messages+. This method can be called from within StepDefinitions. - def puts(*messages) - broadcast(*messages) + # Print +announcement+. This method can be called from within StepDefinitions. + def announce(announcement) + broadcast(announcement) end # Embed +file+ of +mime_type+ in the formatter. This method can be called from within StepDefinitions. # For most formatters this is a no-op. - def embed(file, mime_type, label) - broadcast(file, mime_type, label) + def embed(file, mime_type) + broadcast(file, mime_type) end private def broadcast(*args, &block) @@ -169,13 +169,51 @@ end def send_to_all(message, *args) @listeners.each do |listener| if listener.respond_to?(message) - listener.__send__(message, *args) + if legacy_listener?(listener) + warn_legacy(listener) + legacy_invoke(listener, message, *args) + else + listener.__send__(message, *args) + end end end end + + def legacy_listener?(listener) + listener.respond_to?(:feature_name) && + (listener.method(:feature_name) rescue false) && + listener.method(:feature_name).arity == 1 + end + + def warn_legacy(listener) + @warned_listeners ||= [] + unless @warned_listeners.index(listener) + warn("#{listener.class} is using a deprecated formatter API. Starting with Cucumber 0.7.0 the signatures\n" + + "that have changed are:\n" + + " feature_name(keyword, name) # Two arguments. The keyword argument will not contain a colon.\n" + + " scenario_name(keyword, name, file_colon_line, source_indent) # The keyword argument will not contain a colon.\n" + + " examples_name(keyword, name) # The keyword argument will not contain a colon.\n" + ) + end + @warned_listeners << listener + end + + def legacy_invoke(listener, message, *args) + case message.to_sym + when :feature_name + listener.feature_name("#{args[0]}: #{args[1]}") + when :scenario_name, :examples_name + args_with_colon = args.dup + args_with_colon[0] += ':' + listener.__send__(message, *args_with_colon) + else + listener.__send__(message, *args) + end + end + def extract_method_name_from(call_stack) call_stack[0].match(/in `(.*)'/).captures[0] end end \ No newline at end of file