diff --git a/features/pretty_face_report.feature b/features/pretty_face_report.feature index 42b029a..e02a295 100644 --- a/features/pretty_face_report.feature +++ b/features/pretty_face_report.feature @@ -3,7 +3,7 @@ Feature: pretty face report Background: When I run `cucumber fixtures --profile fixture` - Scenario: Cucumber crefates an html report + Scenario: Cucumber creates an html report Then the following files should exist: | results/fixture.html | diff --git a/lib/pretty_face/formatter/html.rb b/lib/pretty_face/formatter/html.rb index 8abdff2..5e232e3 100644 --- a/lib/pretty_face/formatter/html.rb +++ b/lib/pretty_face/formatter/html.rb @@ -2,9 +2,9 @@ require 'fileutils' require 'cucumber/formatter/io' require 'cucumber/formatter/duration' -require 'cucumber/ast/scenario' -require 'cucumber/ast/table' -require 'cucumber/ast/outline_table' +require 'cucumber/core/ast/scenario' +require 'cucumber/core/ast/data_table' +require 'cucumber/core/ast/scenario_outline' require File.join(File.dirname(__FILE__), 'view_helper') require File.join(File.dirname(__FILE__), 'report') @@ -22,11 +22,13 @@ class Html attr_reader :report, :logo - def initialize(step_mother, path_or_io, options) + # Olle TODO: https://github.com/cucumber/cucumber/commits/master/lib/cucumber/formatter/html.rb + + def initialize(runtime, path_or_io, options) @path = path_or_io set_path_and_file(path_or_io) @path_to_erb = File.join(File.dirname(__FILE__), '..', 'templates') - @step_mother = step_mother + @runtime = runtime @options = options # The expand option is set to true by RubyMine and cannot be turned off using the IDE. This option causes # a test run while using this gem to terminate. @@ -107,7 +109,7 @@ def after_table_row(example_row) @report.current_scenario.populate(example_row) build_scenario_outline_steps(example_row) end - populate_cells(example_row) if example_row.instance_of? Cucumber::Ast::Table::Cells + populate_cells(example_row) if example_row.instance_of? Cucumber::Core::Ast::DataTable end def before_step(step) @@ -234,7 +236,7 @@ def process_step(step, status=nil) report_step = ReportStep.new(step) report_step.duration = duration report_step.status = status unless status.nil? - if step.background? + if !!step.background @report.current_feature.background << report_step if @report.processing_background_steps? else @report.add_step report_step @@ -243,18 +245,18 @@ def process_step(step, status=nil) end def scenario_outline?(feature_element) - feature_element.is_a? Cucumber::Ast::ScenarioOutline + feature_element.is_a? Cucumber::Core::Ast::ScenarioOutline end def info_row?(example_row) return example_row.scenario_outline.nil? if example_row.respond_to? :scenario_outline - return true if example_row.instance_of? Cucumber::Ast::Table::Cells + return true if example_row.instance_of? Cucumber::Core::Ast::DataTable false end - def step_belongs_to_outline?(step) - scenario = step.instance_variable_get "@feature_element" - not scenario.nil? + def step_belongs_to_outline?(step_invocation) + scenario = step_invocation.step.instance_variable_get "@feature_element" + !scenario.nil? end def build_scenario_outline_steps(example_row) diff --git a/lib/pretty_face/formatter/report.rb b/lib/pretty_face/formatter/report.rb index 373ab5b..676ad72 100644 --- a/lib/pretty_face/formatter/report.rb +++ b/lib/pretty_face/formatter/report.rb @@ -89,7 +89,7 @@ def initialize(feature, parent_filename) @scenarios = [] @background = [] @start_time = Time.now - @description = feature.description + @description = feature.send(:description) @parent_filename = parent_filename end @@ -174,10 +174,10 @@ def initialize(scenario) def populate(scenario) @duration = Time.now - @start - if scenario.instance_of? Cucumber::Ast::Scenario + if scenario.instance_of? Cucumber::Core::Ast::Scenario @name = scenario.name @file_colon_line = scenario.file_colon_line - elsif scenario.instance_of? Cucumber::Ast::OutlineTable::ExampleRow + elsif scenario.instance_of? Cucumber::Core::Ast::ExamplesTable::Row @name = scenario.scenario_outline.name @file_colon_line = scenario.backtrace_line end @@ -195,7 +195,7 @@ class ReportStep def initialize(step) @name = step.name @file_colon_line = step.file_colon_line - unless step.instance_of? Cucumber::Ast::Background + unless step.instance_of? Cucumber::Core::Ast::Background if step.respond_to? :actual_keyword @keyword = step.actual_keyword else diff --git a/lib/pretty_face/formatter/view_helper.rb b/lib/pretty_face/formatter/view_helper.rb index 26279de..c111860 100644 --- a/lib/pretty_face/formatter/view_helper.rb +++ b/lib/pretty_face/formatter/view_helper.rb @@ -1,4 +1,4 @@ -require 'cucumber/ast/scenario_outline' +require 'cucumber/core/ast/scenario_outline' module PrettyFace module Formatter @@ -9,11 +9,11 @@ def start_time end def step_count - @step_mother.steps.length + @runtime.steps.length end def scenario_count - @step_mother.scenarios.length + @runtime.scenarios.length end def total_duration @@ -34,11 +34,11 @@ def scenario_average_duration(features) end def scenarios_summary_for(status) - summary_percent(@step_mother.scenarios(status).length, scenario_count) + summary_percent(@runtime.scenarios(status).length, scenario_count) end def steps_summary_for(status) - summary_percent(@step_mother.steps(status).length, step_count) + summary_percent(@runtime.steps(status).length, step_count) end def failed_scenario?(scenario) @@ -49,6 +49,7 @@ def failed_scenario?(scenario) private def get_average_from_float_array(arr) + return 0 if arr.size == 0 arr.reduce(:+).to_f / arr.size end diff --git a/spec/lib/html_formatter_spec.rb b/spec/lib/html_formatter_spec.rb index f84531d..8975359 100644 --- a/spec/lib/html_formatter_spec.rb +++ b/spec/lib/html_formatter_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -require 'cucumber/ast/step' +require 'cucumber/core/ast/step' describe PrettyFace::Formatter::Html do - let(:step_mother) { double('step_mother') } - let(:formatter) { Html.new(step_mother, nil, nil) } + let(:runtime) { double('runtime') } + let(:formatter) { Html.new(runtime, nil, nil) } let(:parameter) { double('parameter') } let(:step) { Cucumber::Ast::Step.new(1, 'Given', 'A cucumber Step') } @@ -28,74 +28,74 @@ context "when building the report for scenarios" do it "should track number of scenarios" do - expect(step_mother).to receive(:scenarios).and_return([1,2,3]) + expect(runtime).to receive(:scenarios).and_return([1,2,3]) expect(formatter.scenario_count).to eql 3 end it "should keep track of passing scenarios" do - expect(step_mother).to receive(:scenarios).with(:passed).and_return([1,2]) - expect(step_mother).to receive(:scenarios).and_return([1,2]) + expect(runtime).to receive(:scenarios).with(:passed).and_return([1,2]) + expect(runtime).to receive(:scenarios).and_return([1,2]) expect(formatter.scenarios_summary_for(:passed)).to eql "2 (100.0%)" end it "should keep track of failing scenarios" do - expect(step_mother).to receive(:scenarios).with(:failed).and_return([1,2]) - expect(step_mother).to receive(:scenarios).and_return([1,2]) + expect(runtime).to receive(:scenarios).with(:failed).and_return([1,2]) + expect(runtime).to receive(:scenarios).and_return([1,2]) expect(formatter.scenarios_summary_for(:failed)).to eql "2 (100.0%)" end it "should keep track of pending scenarios" do - expect(step_mother).to receive(:scenarios).with(:pending).and_return([1,2]) - expect(step_mother).to receive(:scenarios).and_return([1,2]) + expect(runtime).to receive(:scenarios).with(:pending).and_return([1,2]) + expect(runtime).to receive(:scenarios).and_return([1,2]) expect(formatter.scenarios_summary_for(:pending)).to eql "2 (100.0%)" end it "should keep track of undefined scenarios" do - expect(step_mother).to receive(:scenarios).with(:undefined).and_return([1,2]) - expect(step_mother).to receive(:scenarios).and_return([1,2]) + expect(runtime).to receive(:scenarios).with(:undefined).and_return([1,2]) + expect(runtime).to receive(:scenarios).and_return([1,2]) expect(formatter.scenarios_summary_for(:undefined)).to eql "2 (100.0%)" end it "should keep track of skipped scenarios" do - expect(step_mother).to receive(:scenarios).with(:skipped).and_return([1,2]) - expect(step_mother).to receive(:scenarios).and_return([1,2]) + expect(runtime).to receive(:scenarios).with(:skipped).and_return([1,2]) + expect(runtime).to receive(:scenarios).and_return([1,2]) expect(formatter.scenarios_summary_for(:skipped)).to eql "2 (100.0%)" end end context "when building the report for steps" do it "should track number of steps" do - expect(step_mother).to receive(:steps).and_return([1,2]) + expect(runtime).to receive(:steps).and_return([1,2]) expect(formatter.step_count).to eql 2 end it "should keep track of passing steps" do - expect(step_mother).to receive(:steps).with(:passed).and_return([1,2]) - expect(step_mother).to receive(:steps).and_return([1,2]) + expect(runtime).to receive(:steps).with(:passed).and_return([1,2]) + expect(runtime).to receive(:steps).and_return([1,2]) expect(formatter.steps_summary_for(:passed)).to eql "2 (100.0%)" end it "should keep track of failing steps" do - expect(step_mother).to receive(:steps).with(:failed).and_return([1,2]) - expect(step_mother).to receive(:steps).and_return([1,2]) + expect(runtime).to receive(:steps).with(:failed).and_return([1,2]) + expect(runtime).to receive(:steps).and_return([1,2]) expect(formatter.steps_summary_for(:failed)).to eql "2 (100.0%)" end it "should keep track of skipped steps" do - expect(step_mother).to receive(:steps).with(:skipped).and_return([1,2]) - expect(step_mother).to receive(:steps).and_return([1,2]) + expect(runtime).to receive(:steps).with(:skipped).and_return([1,2]) + expect(runtime).to receive(:steps).and_return([1,2]) expect(formatter.steps_summary_for(:skipped)).to eql "2 (100.0%)" end it "should keep track of pending steps" do - expect(step_mother).to receive(:steps).with(:pending).and_return([1,2]) - expect(step_mother).to receive(:steps).and_return([1,2]) + expect(runtime).to receive(:steps).with(:pending).and_return([1,2]) + expect(runtime).to receive(:steps).and_return([1,2]) expect(formatter.steps_summary_for(:pending)).to eql "2 (100.0%)" end it "should keep track of undefined steps" do - expect(step_mother).to receive(:steps).with(:undefined).and_return([1,2]) - expect(step_mother).to receive(:steps).and_return([1,2]) + expect(runtime).to receive(:steps).with(:undefined).and_return([1,2]) + expect(runtime).to receive(:steps).and_return([1,2]) expect(formatter.steps_summary_for(:undefined)).to eql "2 (100.0%)" end end