~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/rspec/spec/spec/runner/formatter/profile_formatter_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Pollock
  • Date: 2009-04-13 17:12:47 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (3.1.3 squeeze) (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20090413171247-61zlnwi5esw1lhtv
ImportĀ upstreamĀ versionĀ 0.24.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2
 
require 'spec/runner/formatter/profile_formatter'
3
 
 
4
 
module 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
65
 
end
 
 
b'\\ No newline at end of file'