changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec_helper.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 'stringio'
2
3dir = File.dirname(__FILE__)
4lib_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
8require 'spec'
9require 'spec/mocks'
10require 'spec/story'
11spec_classes_path = File.expand_path("#{dir}/../spec/spec/spec_classes")
12require spec_classes_path unless $LOAD_PATH.include?(spec_classes_path)
13require File.dirname(__FILE__) + '/../lib/spec/expectations/differs/default'
14
15module 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
59end
60
61class NonStandardError < Exception; end
62
63module 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
76end
77
78def exception_from(&block)
79 exception = nil
80 begin
81 yield
82 rescue StandardError => e
83 exception = e
84 end
85 exception
86end
87
88describe "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
103end