Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Fix/cucumber2 requires #42

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/pretty_face_report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
26 changes: 14 additions & 12 deletions lib/pretty_face/formatter/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/pretty_face/formatter/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions lib/pretty_face/formatter/view_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cucumber/ast/scenario_outline'
require 'cucumber/core/ast/scenario_outline'

module PrettyFace
module Formatter
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down
50 changes: 25 additions & 25 deletions spec/lib/html_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -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') }

Expand All @@ -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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
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 <span class=\"percentage\">(100.0%)</span>"
end
end
Expand Down