Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Print example name when started and result at the end
Browse files Browse the repository at this point in the history
[#130739823](https://www.pivotaltracker.com/story/show/130739823)

Signed-off-by: Cornelius Schumacher <[email protected]>
Signed-off-by: Felix Riegger <[email protected]>
  • Loading branch information
beyhan authored and friegger committed Nov 2, 2016
1 parent 720e5bc commit c67164c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 9 deletions.
20 changes: 19 additions & 1 deletion lib/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@
require_relative 'cli'

class TestsuiteFormatter < RSpec::Core::Formatters::DocumentationFormatter
RSpec::Core::Formatters.register self, :dump_failures, :dump_pending, :dump_summary
RSpec::Core::Formatters.register self, :dump_failures, :dump_pending, :dump_summary,
:example_started, :example_pending, :example_failed

def initialize(output)
super
@env = Cli.new(ENV)
end

def example_started(notification)
output.print "#{current_indentation}#{notification.example.description}... "
end

def example_passed(notification)
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("passed", :success)
end

def example_failed(notification)
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("failed", :failure)
end

def example_pending(pending)
pending_msg = pending.example.execution_result.pending_message
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("skipped: #{pending_msg}", :pending)
end

def dump_failures(notification)
return if notification.failure_notifications.empty?
formatted = "\nFailures:\n"
Expand Down
5 changes: 2 additions & 3 deletions lib/validator/cli/cf_openstack_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ def execute_specs
"2> #{log_path}"
]
Open3.popen3(env, rspec_command.join(' '), :unsetenv_others => true) do |_, stdout_out, _, wait_thr|
stdout_out.each do |line|
puts line
end
stdout_out.each_char {|c| print c }

unless wait_thr.value == 0
raise ErrorWithLogDetails.new("Executing '#{rspec_command}' failed", log_path)
end
Expand Down
57 changes: 57 additions & 0 deletions spec/unit/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,63 @@
ENV['VERBOSE_FORMATTER'] = 'false'
end

describe '#example_started' do
let(:notification) {
instance_double(RSpec::Core::Notifications::ExampleNotification)
}

let(:example) { double('example', description: 'example_name') }

it 'prints the identation and example name' do
allow(notification).to receive(:example).and_return(example)
allow(subject).to receive(:current_indentation).and_return('IDENTATION')

subject.example_started(notification)

expect(output.string).to eq('IDENTATIONexample_name... ')
end
end

describe '#example_passed' do
it 'it prints `passed` in success color' do
allow(RSpec::Core::Formatters::ConsoleCodes).to receive(:wrap).and_call_original

subject.example_passed(nil)

expect(RSpec::Core::Formatters::ConsoleCodes).to have_received(:wrap).with(anything, :success)
expect(output.string).to eq("passed\n")
end
end

describe '#example_failed' do
it 'it prints `failed` in failure color' do
allow(RSpec::Core::Formatters::ConsoleCodes).to receive(:wrap).and_call_original

subject.example_failed(nil)

expect(RSpec::Core::Formatters::ConsoleCodes).to have_received(:wrap).with(anything, :failure)
expect(output.string).to eq("failed\n")
end
end

describe '#example_pending' do

let(:notification) {
execution_result = double('execution_result', pending_message: 'pending_message')
example = double('example', execution_result: execution_result)
instance_double(RSpec::Core::Notifications::FailedExampleNotification, example:example)
}

it 'it prints the skipping reason in pending color' do
allow(RSpec::Core::Formatters::ConsoleCodes).to receive(:wrap).and_call_original

subject.example_pending(notification)

expect(RSpec::Core::Formatters::ConsoleCodes).to have_received(:wrap).with(anything, :pending)
expect(output.string).to eq("skipped: pending_message\n")
end
end

describe '#dump_failures' do

let(:notification) {
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/validator/cli/cf_openstack_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,16 @@ module Validator::Cli
end

it 'should write the stdout to stdout' do
allow(Open3).to receive(:popen3).and_yield('', ['we write stdout to stdout'], [''], OpenStruct.new(:value => 0))
allow(Open3).to receive(:popen3).and_yield('', 'we write stdout to stdout', [''], OpenStruct.new(:value => 0))

expect{
subject.execute_specs
}.to output("we write stdout to stdout\n").to_stdout
}.to output("we write stdout to stdout").to_stdout
end

context 'when execution fails' do
it 'raises an error' do
allow(Open3).to receive(:popen3).and_yield('', [''], [''], OpenStruct.new(:value => 1))
allow(Open3).to receive(:popen3).and_yield('', '', '', OpenStruct.new(:value => 1))

expect{
subject.execute_specs
Expand Down
4 changes: 2 additions & 2 deletions src/specs/cpi_lifecycle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def with_cpi(error_message)
end

it 'can save and retrieve user-data from metadata service' do
Validator::Api::skip_test('Skipped optional metadata test. `config_drive` is configured in validator.yml.') if CfValidator.configuration.openstack['config_drive']
Validator::Api::skip_test('`config_drive` is configured in validator.yml.') if CfValidator.configuration.openstack['config_drive']

@resources.consumes(:vm_cid_with_floating_ip, 'No VM to use')

Expand All @@ -210,7 +210,7 @@ def with_cpi(error_message)
end

it 'can save and retrieve user-data from config_drive' do
Validator::Api::skip_test('Skipped optional config_drive test. `config_drive` is not configured in validator.yml.') unless CfValidator.configuration.openstack['config_drive']
Validator::Api::skip_test('`config_drive` is not configured in validator.yml.') unless CfValidator.configuration.openstack['config_drive']

@resources.consumes(:vm_cid_with_floating_ip, 'No VM to use')
vcap_password = 'c1oudc0w'
Expand Down

0 comments on commit c67164c

Please sign in to comment.