changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/spec_classes.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
1# This file contains various classes used by the specs.
2module Spec
3 module Expectations
4 class Person
5 attr_reader :name
6 def initialize name
7 @name = name
8 end
9 def == other
10 return @name == other.name
11 end
12 end
13
14 class ClassWithMultiWordPredicate
15 def multi_word_predicate?
16 true
17 end
18 end
19
20 module Helper
21 class CollectionWithSizeMethod
22 def initialize; @list = []; end
23 def size; @list.size; end
24 def push(item); @list.push(item); end
25 end
26
27 class CollectionWithLengthMethod
28 def initialize; @list = []; end
29 def length; @list.size; end
30 def push(item); @list.push(item); end
31 end
32
33 class CollectionOwner
34 attr_reader :items_in_collection_with_size_method, :items_in_collection_with_length_method
35
36 def initialize
37 @items_in_collection_with_size_method = CollectionWithSizeMethod.new
38 @items_in_collection_with_length_method = CollectionWithLengthMethod.new
39 end
40
41 def add_to_collection_with_size_method(item)
42 @items_in_collection_with_size_method.push(item)
43 end
44
45 def add_to_collection_with_length_method(item)
46 @items_in_collection_with_length_method.push(item)
47 end
48
49 def items_for(arg)
50 return [1, 2, 3] if arg == 'a'
51 [1]
52 end
53
54 def items
55 @items_in_collection_with_size_method
56 end
57 end
58
59 class HandCodedMock
60 include Spec::Matchers
61 def initialize(return_val)
62 @return_val = return_val
63 @funny_called = false
64 end
65
66 def funny?
67 @funny_called = true
68 @return_val
69 end
70
71 def hungry?(a, b, c)
72 a.should equal(1)
73 b.should equal(2)
74 c.should equal(3)
75 @funny_called = true
76 @return_val
77 end
78
79 def exists?
80 @return_val
81 end
82
83 def multi_word_predicate?
84 @return_val
85 end
86
87 def rspec_verify
88 @funny_called.should be_true
89 end
90 end
91 class ClassWithUnqueriedPredicate
92 attr_accessor :foo
93 def initialize(foo)
94 @foo = foo
95 end
96 end
97 end
98 end
99end
100
101module Custom
102 require 'spec/runner/formatter/base_text_formatter'
103 class Formatter < Spec::Runner::Formatter::BaseTextFormatter
104 attr_reader :options, :where
105
106 def initialize(options, where)
107 @options = options
108 @where = where
109 end
110 end
111
112 class BadFormatter < Spec::Runner::Formatter::BaseTextFormatter
113 attr_reader :where
114
115 def initialize(options, where)
116 bad_method
117 end
118 end
119
120 class Differ
121 attr_reader :options
122 def initialize(options)
123 @options = options
124 end
125
126 def diff_as_object(target, expected)
127 ""
128 end
129 end
130end
131
132class FakeReporter < Spec::Runner::Reporter
133end