Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 224 lines (159 sloc) 5.564 kb
bea39de Josep M. Bach Just started...
authored
1 #stendhal
2
3832560 Josep M. Bach Docs
authored
3 A small test framework developed as a personal kata to improve my ruby.
bea39de Josep M. Bach Just started...
authored
4
18f4356 Josep M. Bach Update readme with ruby compatibilities
authored
5 Tested with Ruby 1.8.7, 1.9.2, JRuby 1.5.3 and Rubinius 1.1.
6
2f768f1 Josep M. Bach 0.1.0
authored
7 Currently under development, there is only basic functionality for now.
8 Below I will be posting whatever features are available throughout the
9 development.
10
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
11 ##Current features
12
c390e9e Josep M. Bach Version bump
authored
13 * Pretty decent reporter with colors
4d43184 Josep M. Bach 0.1.7 - Partial stubbing
authored
14 * Test doubles and stubs (also partial stubbing!)
4e84c52 Josep M. Bach Mocks can return stubbed values
authored
15 * Mocks (message expectations) with _optionally_ stubbable return values
c390e9e Josep M. Bach Version bump
authored
16 * Nested example groups (declare them with either describe or context)
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
17 * Pending examples
488d134 Josep M. Bach 0.1.8 - Rake tasks and runner improvements
authored
18 * A rake task to run the specs
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
19 * Matchers (use with object.must or object.must_not)
577956e Josep M. Bach readme
authored
20
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
21 eq() / eql()
577956e Josep M. Bach readme
authored
22
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
23 be_a() / be_kind_of() / be_a_kind_of()
577956e Josep M. Bach readme
authored
24
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
25 be_whatever # asks object.whatever?
26
27
2f768f1 Josep M. Bach 0.1.0
authored
28 ##Installation
29
30 gem install stendhal
f593f47 Josep M. Bach docs
authored
31
7de76d2 Josep M. Bach readme
authored
32 ##Usage
f593f47 Josep M. Bach docs
authored
33
488d134 Josep M. Bach 0.1.8 - Rake tasks and runner improvements
authored
34 In your Gemfile:
35
36 gem 'stendhal'
37
38 If you want the :spec task, in your Rakefile:
39
40 require 'stendhal'
41 Stendhal::RakeTask.new
42
43 task :default => :spec
44
45 ##Syntax
46
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
47 # your spec file for some class - foo_spec.rb
f593f47 Josep M. Bach docs
authored
48
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
49 describe "Foo" do
f593f47 Josep M. Bach docs
authored
50
2f768f1 Josep M. Bach 0.1.0
authored
51 it "does something" do
52 my_object = MyClass.new
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
53 my_object.must be_a(MyClass)
54 end
2f768f1 Josep M. Bach 0.1.0
authored
55
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
56
57 it "fails when 7 is not 9" do
58 (3 + 4).must eq(9)
2f768f1 Josep M. Bach 0.1.0
authored
59 end
f593f47 Josep M. Bach docs
authored
60
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
61 it "asks for a kind of object" do
62 "string".must be_a(String)
63 end
64
65 it "asks things to objects" do
66 "string".must be_frozen
67 end
68
69 it "has common sense" do
70 "string".must_not eq(3)
71 end
72
73 describe "Pending examples" do
2f768f1 Josep M. Bach 0.1.0
authored
74
75 it "should do something but I don't know what yet"
76
77 pending "will do something else" do
78 my_object = MyClass.new
79 my_object.future_method
80 end
81
c390e9e Josep M. Bach Version bump
authored
82 context "under some unknown circumstances" do
83 it "may act differently" do
84 MyClass.must be_a(Class)
85 end
86 end
87
2f768f1 Josep M. Bach 0.1.0
authored
88 end
4cc2a04 Josep M. Bach Pending examples report
authored
89
478ef83 Josep M. Bach Can I has test doubles
authored
90 describe "Test double" do
91 it "is declared with fake" do
92 my_logger = fake('logger')
93 end
94
95 it "is declared with double as well" do
96 my_logger = double('logger')
97 end
98
99 it "can be given stubs" do
100 my_logger = double('logger', :my_method => 6)
101 my_logger.my_method.must eq(6)
102 end
103 end
104
4d43184 Josep M. Bach 0.1.7 - Partial stubbing
authored
105 describe "Partial stubbing" do
106 it "returns nil by default" do
107 string = "my string"
108 string.stubs(:some_method)
109
110 string.some_method # => nil
111 end
112
113 it "returns a value if you tell it to" do
114 string = "my string"
115 string.stubs(:some_method) { 'some value' }
116
117 string.some_method # => "some value"
118 end
119 end
120
0647b1b Josep M. Bach 0.1.5 - Mocks aka message expectations
authored
121 describe "Message expectation" do
122 it "is declared with expects" do
123 string = "my string"
124 string.expects(:reverse)
125
126 string.reverse # Expectation fulfilled!
127 end
128
4e84c52 Josep M. Bach Mocks can return stubbed values
authored
129 it "can be told the number of times it is expected" do
130 string = "my string"
131 string.expects(:reverse).once # or
132 string.expects(:reverse).twice # or
133 string.expects(:reverse).exactly(3).times
134
135 string.reverse # Fails!
136 end
137
138 it "can return a stubbed value" do
139 string = "my string"
140 string.expects(:reverse).and_returns 'stubbed value'
141
142 string.reverse # => "stubbed value"
143 end
144
145 it "can return a stubbed proc" do
146 string = "my string"
147 string.expects(:reverse).and_returns do
148 3 + 4
149 end
150
151 string.reverse # => 7
152 end
153
0647b1b Josep M. Bach 0.1.5 - Mocks aka message expectations
authored
154 it "is declared with does_not_expect in case it is negative" do
155 string = "my string"
156 string.does_not_expect(:reverse)
157
158 string.reverse # Fails!
159 end
160 end
161
4cc2a04 Josep M. Bach Pending examples report
authored
162 end
163
7de76d2 Josep M. Bach readme
authored
164 ###Running the specs!
f593f47 Josep M. Bach docs
authored
165
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
166 stendhal foo_spec.rb
bea39de Josep M. Bach Just started...
authored
167
c390e9e Josep M. Bach Version bump
authored
168 ###And the nice colored output...
4cc2a04 Josep M. Bach Pending examples report
authored
169
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
170 Foo
c390e9e Josep M. Bach Version bump
authored
171 * does something
172 * fails when 7 is not 9 [FAILED]
173 expected 7 to equal 9
174 * asks for a kind of object
175 * asks things to objects [FAILED]
176 expected "string" to be frozen
177 * has common sense
617c3b9 Josep M. Bach Stendhal 0.1.1
authored
178
179 Pending examples
c390e9e Josep M. Bach Version bump
authored
180 * should do something but I don't know what yet
181 * will do something else
182 under some unknown circumstances
183 * may act differently
4cc2a04 Josep M. Bach Pending examples report
authored
184
478ef83 Josep M. Bach Can I has test doubles
authored
185 Test double
c390e9e Josep M. Bach Version bump
authored
186 * is declared with fake
187 * is declared with double as well
188 * can be given stubs
4d43184 Josep M. Bach 0.1.7 - Partial stubbing
authored
189
190 Partial stubbing
191 * returns nil by default
192 * returns a value if you tell it to
478ef83 Josep M. Bach Can I has test doubles
authored
193
0647b1b Josep M. Bach 0.1.5 - Mocks aka message expectations
authored
194 Message expectation
195 * is declared with expects
4e84c52 Josep M. Bach Mocks can return stubbed values
authored
196 * can be told the number of times it is expected [FAILED]
197 * can return a stubbed value
198 * can return a stubbed proc
ee85b24 Josep M. Bach Update readme
authored
199 * is declared with does_not_expect in case it is negative [FAILED]
0647b1b Josep M. Bach 0.1.5 - Mocks aka message expectations
authored
200
4d43184 Josep M. Bach 0.1.7 - Partial stubbing
authored
201 18 examples, 4 failures, 2 pending
4cc2a04 Josep M. Bach Pending examples report
authored
202
6cd50b4 Josep M. Bach Update readme
authored
203 ##Feedback
204
205 Reporting issues, asking for new features and constructive criticizing can be
206 done either through Github issues, the mailing list
207 (http://librelist.com/browser/stendhal/) or you can always reach me on twitter
208 (I am @txustice). Don't hesitate to tell me anything! :)
209
bea39de Josep M. Bach Just started...
authored
210 ##Note on Patches/Pull Requests
211
212 * Fork the project.
213 * Make your feature addition or bug fix.
214 * Add specs for it. This is important so I don't break it in a
215 future version unintentionally.
216 * Commit, do not mess with rakefile, version, or history.
217 If you want to have your own version, that is fine but bump version
218 in a commit by itself I can ignore when I pull.
219 * Send me a pull request. Bonus points for topic branches.
220
221 ## Copyright
222
223 Copyright (c) 2010 Josep M. Bach. See LICENSE for details.
Something went wrong with that request. Please try again.