changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/runner/formatter/profile_formatter_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2require 'spec/runner/formatter/profile_formatter'
3
4module Spec
5 module Runner
6 module Formatter
7 describe ProfileFormatter do
8 attr_reader :io, :formatter
9 before(:each) do
10 @io = StringIO.new
11 options = mock('options')
12 options.stub!(:colour).and_return(true)
13 @formatter = ProfileFormatter.new(options, io)
14 end
15
16 it "should print a heading" do
17 formatter.start(0)
18 io.string.should eql("Profiling enabled.\n")
19 end
20
21 it "should record the current time when starting a new example" do
22 now = Time.now
23 Time.stub!(:now).and_return(now)
24 formatter.example_started('should foo')
25 formatter.instance_variable_get("@time").should == now
26 end
27
28 it "should correctly record a passed example" do
29 now = Time.now
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')
33
34 formatter.add_example_group(child_example_group)
35
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'))
39
40 formatter.start_dump
41 io.string.should include('Parent Child')
42 end
43
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]])
46 formatter.start_dump
47 formatter.instance_variable_get("@example_times").should == [ ['b', 'b', 0.3], ['c', 'c', 0.2], ['a', 'a', 0.1]]
48 end
49
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)
54
55 15.times do
56 formatter.example_passed(stub('foo', :description => 'i like ice cream'))
57 end
58
59 io.should_receive(:print).exactly(10)
60 formatter.start_dump
61 end
62 end
63 end
64 end
65end