]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec_helper.rb
1318176d55603958a1cd59d7617c0d0dc04c25e6
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec_helper.rb
1 require 'stringio'
2
3 dir = File.dirname(__FILE__)
4 lib_path = File.expand_path("#{dir}/../lib")
5 $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
6 $_spec_spec = true # Prevents Kernel.exit in various places
7
8 require 'spec'
9 require 'spec/mocks'
10 require 'spec/story'
11 spec_classes_path = File.expand_path("#{dir}/../spec/spec/spec_classes")
12 require spec_classes_path unless $LOAD_PATH.include?(spec_classes_path)
13 require File.dirname(__FILE__) + '/../lib/spec/expectations/differs/default'
14
15 module Spec
16   module Matchers
17     def fail
18       raise_error(Spec::Expectations::ExpectationNotMetError)
19     end
20
21     def fail_with(message)
22       raise_error(Spec::Expectations::ExpectationNotMetError, message)
23     end
24
25     class Pass
26       def matches?(proc, &block)
27         begin
28           proc.call
29           true
30         rescue Exception => @error
31           false
32         end
33       end
34
35       def failure_message
36         @error.message + "\n" + @error.backtrace.join("\n")
37       end
38     end
39
40     def pass
41       Pass.new
42     end
43     
44     class CorrectlyOrderedMockExpectation
45       def initialize(&event)
46         @event = event
47       end
48       
49       def expect(&expectations)
50         expectations.call
51         @event.call
52       end
53     end
54     
55     def during(&block)
56       CorrectlyOrderedMockExpectation.new(&block) 
57     end
58   end
59 end
60
61 class NonStandardError < Exception; end
62
63 module Custom
64   class ExampleGroupRunner
65     attr_reader :options, :arg
66     def initialize(options, arg)
67       @options, @arg = options, arg
68     end
69
70     def load_files(files)
71     end
72
73     def run
74     end
75   end  
76 end
77
78 def exception_from(&block)
79   exception = nil
80   begin
81     yield
82   rescue StandardError => e
83     exception = e
84   end
85   exception
86 end
87
88 describe "sandboxed rspec_options", :shared => true do
89   attr_reader :options
90
91   before(:all) do
92     @original_rspec_options = $rspec_options
93   end
94
95   before(:each) do
96     @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
97     $rspec_options = options
98   end
99
100   after do
101     $rspec_options = @original_rspec_options
102   end
103 end