lib/cucumber/formatter/gherkin_formatter_adapter.rb in cucumber-2.0.0.beta.2 vs lib/cucumber/formatter/gherkin_formatter_adapter.rb in cucumber-2.0.0.beta.3
- old
+ new
@@ -8,23 +8,27 @@
class GherkinFormatterAdapter
def initialize(gherkin_formatter, print_empty_match, options)
@gf = gherkin_formatter
@print_empty_match = print_empty_match
@options = options
+ @delayed_messages = []
+ @delayed_embeddings = []
end
def before_feature(feature)
@gf.uri(feature.file)
@gf.feature(feature.gherkin_statement)
end
def before_background(background)
@outline = false
+ @before_steps = true
@gf.background(background.gherkin_statement)
end
def before_feature_element(feature_element)
+ @before_steps = true
case(feature_element)
when Core::Ast::Scenario
@outline = false
@gf.scenario(feature_element.gherkin_statement)
when Core::Ast::ScenarioOutline
@@ -63,10 +67,12 @@
end
def before_step(step)
unless @outline and @options[:expand]
@gf.step(step.gherkin_statement)
+ pass_delayed_output
+ @before_steps = false
else
if @in_instantiated_scenario
@current_step_hash = to_hash(step.gherkin_statement)
end
end
@@ -109,13 +115,15 @@
if @outline and @options[:expand] and @in_instantiated_scenario
@gf.step(Gherkin::Formatter::Model::Step.new(
@current_step_hash['comments'],
@current_step_hash['keyword'],
step_match.format_args(),
- @current_step_hash['line'],
+ file_colon_line.split(':')[1].to_i,
@current_step_hash['rows'],
@current_step_hash['doc_string']))
+ pass_delayed_output
+ @before_steps = false
@gf.match(@current_match)
@gf.result(@current_result)
end
end
@@ -157,24 +165,39 @@
end
end
if defined?(JRUBY_VERSION)
data = data.to_java_bytes
end
- @gf.embedding(mime_type, data)
+ unless @before_steps
+ @gf.embedding(mime_type, data)
+ else
+ @delayed_embeddings.push [mime_type, data]
+ end
end
def puts(message)
- @gf.write(message)
+ unless @before_steps
+ @gf.write(message)
+ else
+ @delayed_messages.push message
+ end
end
private
def to_hash(gherkin_statement)
if defined?(JRUBY_VERSION)
gherkin_statement.toMap()
else
gherkin_statement.to_hash
end
+ end
+
+ def pass_delayed_output
+ @delayed_messages.each { |message| @gf.write(message) }
+ @delayed_embeddings.each { |embed_data| @gf.embedding(embed_data[0], embed_data[1]) }
+ @delayed_messages = []
+ @delayed_embeddings = []
end
end
end
end