spec/gurke/reporters/compact_reporter_spec.rb in gurke-3.3.4 vs spec/gurke/reporters/compact_reporter_spec.rb in gurke-3.3.5
- old
+ new
@@ -1,96 +1,95 @@
# frozen_string_literal: true
-# rubocop:disable MissingCopEnableDirective
-# rubocop:disable Style/Semicolon
+# rubocop:disable Lint/MissingCopEnableDirective
require 'spec_helper'
RSpec.describe Gurke::Reporters::CompactReporter do
- let(:output) { StringIO.new }
- let(:reporter) { described_class.new(output) }
- subject { output.string }
+ subject(:out) do
+ reporter = described_class.new(StringIO.new)
+ reporter.send(*action)
+ reporter.io.string
+ end
+ let(:feature) { instance_double(Gurke::Feature) }
+ let(:scenario) { instance_double(Gurke::Scenario) }
+ let(:step) { instance_double(Gurke::Step) }
+
describe '#before_feature' do
- let(:feature) { double('feature') }
+ let(:action) { [:before_feature, feature] }
- subject { reporter.before_feature(feature); super() }
-
it { is_expected.to eq '' }
end
describe '#start_background' do
- let(:feature) { double('feature') }
+ let(:action) { [:start_background, feature] }
- subject { reporter.start_background(feature); super() }
-
it { is_expected.to eq '' }
end
describe '#before_scenario' do
- let(:scenario) { double('scenario') }
+ let(:action) { [:before_scenario, scenario] }
- subject { reporter.before_scenario(scenario); super() }
-
it { is_expected.to eq '' }
end
describe '#before_step' do
- let(:step) { double('step') }
+ let(:action) { [:before_step, step] }
- subject { reporter.before_step(step); super() }
-
it { is_expected.to eq '' }
end
describe '#after_step' do
- let(:feature) { double('feature') }
- let(:scenario) { double('scenario') }
- let(:step) { double('step') }
- let(:result) { double('result') }
+ let(:action) { [:after_step, result, scenario] }
+
+ let(:result) { instance_double(Gurke::Step::StepResult) }
let(:backgrounds) { [] }
let(:exception) { nil }
let(:steps) do
[step]
end
before do
- allow(result).to receive(:step).and_return(step)
- allow(result).to receive(:scenario).and_return(scenario)
- allow(result).to receive(:state).and_return(state)
- allow(result).to receive(:exception).and_return(exception)
+ allow(result).to receive_messages(
+ step: step,
+ scenario: scenario,
+ state: state,
+ exception: exception,
+ )
end
before do
- allow(step).to receive(:name).and_return 'the scenario is passing'
- allow(step).to receive(:keyword).and_return 'Given'
+ allow(step).to receive_messages(
+ name: 'the scenario is passing',
+ keyword: 'Given',
+ )
end
before do
- allow(scenario).to receive(:feature).and_return(feature)
- allow(scenario).to receive(:steps).and_return(steps)
-
- allow(scenario).to receive(:name).and_return 'Running the scenario'
- allow(scenario).to receive(:file).and_return \
- File.join(Dir.getwd, 'features', 'file.feature')
- allow(scenario).to receive(:line).and_return 5
+ allow(scenario).to receive_messages(
+ feature: feature,
+ steps: steps,
+ name: 'Running the scenario',
+ file: File.join(Dir.getwd, 'features', 'file.feature'),
+ line: 5,
+ )
end
before do
- allow(feature).to receive(:backgrounds).and_return(backgrounds)
-
- allow(feature).to receive(:name).and_return 'Demo feature'
- allow(feature).to receive(:file).and_return \
- File.join(Dir.getwd, 'features', 'file.feature')
- allow(feature).to receive(:line).and_return 1
- allow(feature).to receive(:description).and_return \
- "As a developer\nI would like have this spec passed\nIn order to work on"
+ allow(feature).to receive_messages(
+ backgrounds: backgrounds,
+ name: 'Demo feature',
+ file: File.join(Dir.getwd, 'features', 'file.feature'),
+ line: 1,
+ description: "As a developer\n" \
+ "I would like have this spec passed\n" \
+ 'In order to work on',
+ )
end
- subject { reporter.after_step(result, scenario); super() }
-
context 'with step passing' do
let(:state) { :passed }
it { is_expected.to eq '' }
end
@@ -99,44 +98,38 @@
let(:state) { :pending }
it { is_expected.to eq '' }
end
- context 'with step pending' do
+ context 'with step nil' do
let(:state) { nil }
it { is_expected.to eq '' }
end
context 'with step failing' do
let(:state) { :failed }
before do
- e = double 'exception'
- c = double 'exception'
+ error = instance_double RuntimeError
+ cause = instance_double IOError
- allow(e).to receive(:class).and_return(RuntimeError)
- allow(e).to receive(:message).and_return('An error occurred')
- allow(e).to receive(:backtrace).and_return([
- '/path/to/file.rb:5:in `block (4 levels) in <top (required)>\'',
- '/path/to/file.rb:24:in in `fail_with\''
- ])
+ allow(error).to receive_messages(class: RuntimeError, message: 'An error occurred', backtrace: [
+ '/path/to/file.rb:5:in `block (4 levels) in <top (required)>\'',
+ '/path/to/file.rb:24:in in `fail_with\'',
+ ], cause: cause,)
- allow(e).to receive(:cause).and_return(c)
+ allow(cause).to receive_messages(class: IOError, message: 'Socket closed', backtrace: [
+ 'script.rb:5:in `a\'',
+ 'script.rb:10:in `b\'',
+ ],)
- allow(c).to receive(:class).and_return(IOError)
- allow(c).to receive(:message).and_return('Socket closed')
- allow(c).to receive(:backtrace).and_return([
- 'script.rb:5:in `a\'',
- 'script.rb:10:in `b\''
- ])
-
- expect(result).to receive(:exception).and_return e
+ allow(result).to receive(:exception).and_return error
end
it do
- is_expected.to eq unindent <<~TEXT
+ expect(out).to eq unindent <<~TEXT
.E
.Feature: Demo feature # features/file.feature:1
. Scenario: Running the scenario # features/file.feature:5
. Given the scenario is passing
. RuntimeError: An error occurred
@@ -151,26 +144,20 @@
end
end
end
describe '#retry_scenario' do
- let(:scenario) { double('scenario') }
+ let(:action) { [:retry_scenario, scenario] }
- subject { reporter.retry_scenario(scenario); super() }
-
it { is_expected.to eq '' }
end
describe '#after_scenario' do
- let(:scenario) { double('scenario') }
+ let(:action) { [:after_scenario, scenario] }
- subject { reporter.after_scenario(scenario); super() }
-
before do
- allow(scenario).to receive(:failed?).and_return(false)
- allow(scenario).to receive(:passed?).and_return(true)
- allow(scenario).to receive(:pending?).and_return(false)
+ allow(scenario).to receive_messages(failed?: false, passed?: true, pending?: false)
end
it { is_expected.to eq '.' }
context '<failed>' do
@@ -189,23 +176,19 @@
it { is_expected.to eq '?' }
end
end
describe '#after_feature' do
- let(:feature) { double('feature') }
+ let(:action) { [:after_feature, feature] }
- subject { reporter.after_feature(feature); super() }
-
it { is_expected.to eq '' }
end
describe '#after_features' do
- let(:features) { [] }
+ let(:action) { [:after_features, []] }
- subject { reporter.after_features(features); super() }
-
it do
- is_expected.to eq unindent <<~TEXT
+ expect(out).to eq unindent <<~TEXT
.
.
.0 scenarios: 0 passed, 0 failing, 0 pending
.
TEXT