lib/cucumber/formatter/gherkin_formatter_adapter.rb in cucumber-1.3.20 vs lib/cucumber/formatter/gherkin_formatter_adapter.rb in cucumber-2.0.0.beta.1

- old
+ new

@@ -8,32 +8,28 @@ 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 - @delay_output = true @gf.background(background.gherkin_statement) end def before_feature_element(feature_element) - @delay_output = true case(feature_element) - when Ast::Scenario + when Core::Ast::Scenario @outline = false @gf.scenario(feature_element.gherkin_statement) - when Ast::ScenarioOutline + when Core::Ast::ScenarioOutline @outline = true if @options[:expand] @in_instantiated_scenario = false @current_scenario_hash = to_hash(feature_element.gherkin_statement) else @@ -60,24 +56,20 @@ @current_scenario_hash['keyword'], @current_scenario_hash['name'], @current_scenario_hash['description'], example_row_hash['line'], example_row_hash['id']) - @delay_output = true @gf.scenario(scenario) end end def before_step(step) unless @outline and @options[:expand] @gf.step(step.gherkin_statement) - pass_delayed_output - @delay_output = false else if @in_instantiated_scenario @current_step_hash = to_hash(step.gherkin_statement) - @delay_output = true end end if @print_empty_match if(@outline) match = Gherkin::Formatter::Model::Match.new(step.gherkin_statement.outline_args, nil) @@ -120,12 +112,10 @@ @current_step_hash['keyword'], step_match.format_args(), @current_step_hash['line'], @current_step_hash['rows'], @current_step_hash['doc_string'])) - pass_delayed_output - @delay_output = false @gf.match(@current_match) @gf.result(@current_result) end end @@ -154,52 +144,32 @@ def after_features(features) @gf.done end def embed(file, mime_type, label) - if File.file?(file) + # Only embed if file exists + if File.exists?(file) data = File.open(file, 'rb') { |f| f.read } - else - if mime_type =~ /;base64$/ - mime_type = mime_type[0..-8] - data = Base64.decode64(file) - else - data = file + + if defined?(JRUBY_VERSION) + data = data.to_java_bytes end - end - if defined?(JRUBY_VERSION) - data = data.to_java_bytes - end - unless @delay_output @gf.embedding(mime_type, data) - else - @delayed_embeddings.push [mime_type, data] end end def puts(message) - unless @delay_output - @gf.write(message) - else - @delayed_messages.push message - end + @gf.write(message) 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