Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

133 lines (108 sloc) 3.846 kB
require "spec_helper"
module RSpec::Core
describe Reporter do
describe "abort" do
let(:formatter) { double("formatter").as_null_object }
let(:example) { double("example") }
let(:reporter) { Reporter.new(formatter) }
%w[start_dump dump_pending dump_failures dump_summary close].each do |message|
it "sends #{message} to the formatter(s)" do
formatter.should_receive(message)
reporter.abort(nil)
end
end
end
describe 'start' do
it 'notifies the formatter of start with example count and load time' do
formatter = double("formatter")
example = double("example")
reporter = Reporter.new(formatter)
formatter.should_receive(:start).with(0,5)
RSpec.configuration.start_time = 5
reporter.start 0, 10
end
end
context "given one formatter" do
it "passes messages to that formatter" do
formatter = double("formatter")
example = double("example")
reporter = Reporter.new(formatter)
formatter.should_receive(:example_started).
with(example)
reporter.example_started(example)
end
it "passes example_group_started and example_group_finished messages to that formatter in that order" do
order = []
formatter = double("formatter").as_null_object
formatter.stub(:example_group_started) { |group| order << "Started: #{group.description}" }
formatter.stub(:example_group_finished) { |group| order << "Finished: #{group.description}" }
group = ExampleGroup.describe("root")
group.describe("context 1") do
example("ignore") {}
end
group.describe("context 2") do
example("ignore") {}
end
group.run(Reporter.new(formatter))
expect(order).to eq([
"Started: root",
"Started: context 1",
"Finished: context 1",
"Started: context 2",
"Finished: context 2",
"Finished: root"
])
end
end
context "given an example group with no examples" do
it "does not pass example_group_started or example_group_finished to formatter" do
formatter = double("formatter").as_null_object
formatter.should_not_receive(:example_group_started)
formatter.should_not_receive(:example_group_finished)
group = ExampleGroup.describe("root")
group.run(Reporter.new(formatter))
end
end
context "given multiple formatters" do
it "passes messages to all formatters" do
formatters = [double("formatter"), double("formatter")]
example = double("example")
reporter = Reporter.new(*formatters)
formatters.each do |formatter|
formatter.
should_receive(:example_started).
with(example)
end
reporter.example_started(example)
end
end
describe "#report" do
it "supports one arg (count)" do
Reporter.new.report(1) {}
end
it "supports two args (count, seed)" do
Reporter.new.report(1, 2) {}
end
it "yields itself" do
reporter = Reporter.new
yielded = nil
reporter.report(3) {|r| yielded = r}
expect(yielded).to eq(reporter)
end
end
describe "timing" do
it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
formatter = double(:formatter).as_null_object
reporter = Reporter.new formatter
reporter.start 1
Time.stub(:now => Time.utc(2012, 10, 1))
duration = nil
formatter.stub(:dump_summary) do |dur, _, _, _|
duration = dur
end
reporter.finish 1234
expect(duration).to be < 0.2
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.