1
require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2
require 'spec/runner/formatter/profile_formatter'
7
describe ProfileFormatter do
8
attr_reader :io, :formatter
11
options = mock('options')
12
options.stub!(:colour).and_return(true)
13
@formatter = ProfileFormatter.new(options, io)
16
it "should print a heading" do
18
io.string.should eql("Profiling enabled.\n")
21
it "should record the current time when starting a new example" do
23
Time.stub!(:now).and_return(now)
24
formatter.example_started('should foo')
25
formatter.instance_variable_get("@time").should == now
28
it "should correctly record a passed example" do
30
Time.stub!(:now).and_return(now)
31
parent_example_group = Class.new(ExampleGroup).describe('Parent')
32
child_example_group = Class.new(parent_example_group).describe('Child')
34
formatter.add_example_group(child_example_group)
36
formatter.example_started('when foo')
37
Time.stub!(:now).and_return(now+1)
38
formatter.example_passed(stub('foo', :description => 'i like ice cream'))
41
io.string.should include('Parent Child')
44
it "should sort the results in descending order" do
45
formatter.instance_variable_set("@example_times", [['a', 'a', 0.1], ['b', 'b', 0.3], ['c', 'c', 0.2]])
47
formatter.instance_variable_get("@example_times").should == [ ['b', 'b', 0.3], ['c', 'c', 0.2], ['a', 'a', 0.1]]
50
it "should print the top 10 results" do
51
example_group = Class.new(::Spec::Example::ExampleGroup).describe("ExampleGroup")
52
formatter.add_example_group(example_group)
53
formatter.instance_variable_set("@time", Time.now)
56
formatter.example_passed(stub('foo', :description => 'i like ice cream'))
59
io.should_receive(:print).exactly(10)
b'\\ No newline at end of file'