test-unit 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +43 -1
- data/Manifest.txt +1 -1
- data/html/index.html +57 -24
- data/html/index.html.ja +49 -25
- data/html/test-unit.css +3 -3
- data/lib/test/unit/assertions.rb +493 -40
- data/lib/test/unit/autorunner.rb +24 -0
- data/lib/test/unit/collector.rb +6 -4
- data/lib/test/unit/collector/load.rb +48 -5
- data/lib/test/unit/fixture.rb +12 -3
- data/lib/test/unit/testsuite.rb +11 -3
- data/lib/test/unit/ui/console/testrunner.rb +42 -8
- data/lib/test/unit/version.rb +1 -1
- data/test/run-test.rb +7 -0
- data/test/{test_assertions.rb → test-assertions.rb} +717 -65
- data/test/test-fixture.rb +37 -0
- data/test/test-testcase.rb +11 -3
- metadata +5 -6
data/History.txt
CHANGED
@@ -1,6 +1,48 @@
|
|
1
|
+
=== 2.2.0 / 2011-02-14
|
2
|
+
|
3
|
+
* 22 enhancements
|
4
|
+
* [#28808] accept String as delta for assert_in_delta.
|
5
|
+
[Daniel Berger]
|
6
|
+
* [test-unit-users-en:00035] make GC-able finished tests.
|
7
|
+
[Daniel Berger]
|
8
|
+
* use also COLUMNS environment variable to guess terminal width.
|
9
|
+
* make delta for assert_in_delta optiona.
|
10
|
+
[Nobuyoshi Nakada]
|
11
|
+
* add assert_not_respond_to.
|
12
|
+
[Nobuyoshi Nakada]
|
13
|
+
* add assert_not_match. assert_no_match is deprecated.
|
14
|
+
[Nobuyoshi Nakada]
|
15
|
+
* add assert_not_in_delta.
|
16
|
+
[Nobuyoshi Nakada]
|
17
|
+
* add assert_in_epsilon.
|
18
|
+
[Nobuyoshi Nakada]
|
19
|
+
* add assert_not_in_epsilon.
|
20
|
+
[Nobuyoshi Nakada]
|
21
|
+
* add assert_include.
|
22
|
+
[Nobuyoshi Nakada]
|
23
|
+
* add assert_not_include.
|
24
|
+
[Nobuyoshi Nakada]
|
25
|
+
* add assert_empty.
|
26
|
+
[Nobuyoshi Nakada]
|
27
|
+
* add assert_not_empty.
|
28
|
+
[Nobuyoshi Nakada]
|
29
|
+
* notify require failed paths.
|
30
|
+
* validate message value for assert.
|
31
|
+
* show throughputs at the last.
|
32
|
+
* support not ASCII compatible string diff.
|
33
|
+
* support colorized diff on encoding different string.
|
34
|
+
* normalize entry order of Hash for readable diff.
|
35
|
+
* add --ignore-name option.
|
36
|
+
* add --ignore-testcase option.
|
37
|
+
* add assert_not_send.
|
38
|
+
|
39
|
+
* Thanks
|
40
|
+
* Daniel Berger
|
41
|
+
* Nobuyoshi Nakada
|
42
|
+
|
1
43
|
=== 2.1.2 / 2010-11-25
|
2
44
|
|
3
|
-
* 1
|
45
|
+
* 1 enhancement
|
4
46
|
* support auto runner prepare hook.
|
5
47
|
|
6
48
|
=== 2.1.1 / 2010-07-29
|
data/Manifest.txt
CHANGED
@@ -84,6 +84,7 @@ test/collector/test-load.rb
|
|
84
84
|
test/collector/test_dir.rb
|
85
85
|
test/collector/test_objectspace.rb
|
86
86
|
test/run-test.rb
|
87
|
+
test/test-assertions.rb
|
87
88
|
test/test-attribute.rb
|
88
89
|
test/test-color-scheme.rb
|
89
90
|
test/test-color.rb
|
@@ -95,7 +96,6 @@ test/test-omission.rb
|
|
95
96
|
test/test-pending.rb
|
96
97
|
test/test-priority.rb
|
97
98
|
test/test-testcase.rb
|
98
|
-
test/test_assertions.rb
|
99
99
|
test/test_error.rb
|
100
100
|
test/test_failure.rb
|
101
101
|
test/test_testresult.rb
|
data/html/index.html
CHANGED
@@ -78,7 +78,7 @@ require "test/unit"</pre>
|
|
78
78
|
</p>
|
79
79
|
<h3 id="test-unit-latest">test-unit: The latest release</h3>
|
80
80
|
<p>
|
81
|
-
2.
|
81
|
+
2.2.0 is the latest release. It had been released at 2011-02-14.
|
82
82
|
</p>
|
83
83
|
<h3 id="test-unit-install">test-unit: Install</h3>
|
84
84
|
<p>
|
@@ -92,7 +92,7 @@ require "test/unit"</pre>
|
|
92
92
|
</p>
|
93
93
|
<h3 id="test-unit-full-latest">test-unit-full: The latest release</h3>
|
94
94
|
<p>
|
95
|
-
0.0.
|
95
|
+
0.0.3 is the latest release. It had been released at 2011-02-09.
|
96
96
|
</p>
|
97
97
|
<h3 id="test-unit-full-install">test-unit-full: Install</h3>
|
98
98
|
<p>
|
@@ -106,13 +106,26 @@ require "test/unit"</pre>
|
|
106
106
|
|
107
107
|
<h2 id="test-unit-notify">test-unit-notify</h2>
|
108
108
|
<p>
|
109
|
-
<
|
110
|
-
|
109
|
+
<div class="eye-catch">
|
110
|
+
<img alt="notification on GNOME"
|
111
|
+
src="test-unit-notify/screenshot/notify-on-gnome.png" />
|
112
|
+
<img alt="notification on Mac OS X"
|
113
|
+
src="test-unit-notify/screenshot/notify-on-mac-os-x.png" />
|
114
|
+
</div>
|
111
115
|
This package provides a test notifier.
|
116
|
+
|
117
|
+
<dl class="feature-list">
|
118
|
+
<dt>X Window System based eivornment such ad GNOME, Xfce, KDE and so on</dt>
|
119
|
+
<dd>"notify-send" command is used for notifying test result.</dd>
|
120
|
+
<dt>Mac OS X</dt>
|
121
|
+
<dd>"growlnotify" command is used for notifying test result.</dd>
|
122
|
+
<dt>Windows</dt>
|
123
|
+
<dd>How? Growl for Windows? (not implemented)</dd>
|
124
|
+
</dl>
|
112
125
|
</p>
|
113
126
|
<h3 id="test-unit-notify-latest">test-unit-notify: The latest release</h3>
|
114
127
|
<p>
|
115
|
-
0.
|
128
|
+
0.2.1 is the latest release. It had been released at 2011-02-10.
|
116
129
|
</p>
|
117
130
|
<h3 id="test-unit-notify-install">test-unit-notify: Install</h3>
|
118
131
|
<p>
|
@@ -127,18 +140,36 @@ require "test/unit"</pre>
|
|
127
140
|
You can use --notify option to notify test result by popup at the end.
|
128
141
|
</p>
|
129
142
|
|
130
|
-
<h2 id="test-unit-
|
143
|
+
<h2 id="test-unit-rr">test-unit-rr</h2>
|
144
|
+
<p>
|
145
|
+
This package provides a <a href="http://github.com/btakita/rr">RR</a>, a test dobule library, adapter for test-unit 2.
|
146
|
+
</p>
|
147
|
+
<h3 id="test-unit-rr-latest">test-unit-rr: The latest release</h3>
|
148
|
+
<p>
|
149
|
+
1.0.1 is the latest release. It had been released at 2011-02-10.
|
150
|
+
</p>
|
151
|
+
<h3 id="test-unit-rr-install">test-unit-rr: Install</h3>
|
152
|
+
<p>
|
153
|
+
Install:
|
154
|
+
<pre class="command">% sudo gem install test-unit-rr</pre>
|
155
|
+
</p>
|
156
|
+
<p>
|
157
|
+
Usage:
|
158
|
+
<pre class="code">require "test/unit/rr"</pre>
|
159
|
+
</p>
|
160
|
+
|
161
|
+
<h2 id="test-unit-runner-gtk2">test-unit-runner-gtk2</h2>
|
131
162
|
<p>
|
132
163
|
This package provides a GTK+ based test runner.
|
133
164
|
</p>
|
134
|
-
<h3 id="test-unit-gtk2-latest">test-unit-gtk2: The latest release</h3>
|
165
|
+
<h3 id="test-unit-runner-gtk2-latest">test-unit-runner-gtk2: The latest release</h3>
|
135
166
|
<p>
|
136
|
-
0.0.
|
167
|
+
0.0.2 is the latest release. It had been released at 2011-02-09.
|
137
168
|
</p>
|
138
|
-
<h3 id="test-unit-gtk2-install">test-unit-gtk2: Install</h3>
|
169
|
+
<h3 id="test-unit-runner-gtk2-install">test-unit-runner-gtk2: Install</h3>
|
139
170
|
<p>
|
140
171
|
Install:
|
141
|
-
<pre class="command">% sudo gem install test-unit-gtk2</pre>
|
172
|
+
<pre class="command">% sudo gem install test-unit-runner-gtk2</pre>
|
142
173
|
</p>
|
143
174
|
<p>
|
144
175
|
Usage:
|
@@ -148,18 +179,18 @@ require "test/unit"</pre>
|
|
148
179
|
You can use --runner=gtk2 to run tests with GTK+ based test runner.
|
149
180
|
</p>
|
150
181
|
|
151
|
-
<h2 id="test-unit-tk">test-unit-tk</h2>
|
182
|
+
<h2 id="test-unit-runner-tk">test-unit-runner-tk</h2>
|
152
183
|
<p>
|
153
184
|
This package provides a Tk based test runner.
|
154
185
|
</p>
|
155
|
-
<h3 id="test-unit-tk-latest">test-unit-tk: The latest release</h3>
|
186
|
+
<h3 id="test-unit-runner-tk-latest">test-unit-runner-tk: The latest release</h3>
|
156
187
|
<p>
|
157
188
|
0.0.1 is the latest release. It had been released at 2008-06-17.
|
158
189
|
</p>
|
159
|
-
<h3 id="test-unit-tk-install">test-unit-tk: Install</h3>
|
190
|
+
<h3 id="test-unit-runner-tk-install">test-unit-runner-tk: Install</h3>
|
160
191
|
<p>
|
161
192
|
Install:
|
162
|
-
<pre class="command">% sudo gem install test-unit-tk</pre>
|
193
|
+
<pre class="command">% sudo gem install test-unit-runner-tk</pre>
|
163
194
|
</p>
|
164
195
|
<p>
|
165
196
|
Usage:
|
@@ -169,18 +200,18 @@ require "test/unit"</pre>
|
|
169
200
|
You can use --runner=tk to run tests with Tk based test runner.
|
170
201
|
</p>
|
171
202
|
|
172
|
-
<h2 id="test-unit-fox">test-unit-fox</h2>
|
203
|
+
<h2 id="test-unit-runner-fox">test-unit-runner-fox</h2>
|
173
204
|
<p>
|
174
205
|
This package provides a FOX Toolkit based test runner.
|
175
206
|
</p>
|
176
|
-
<h3 id="test-unit-fox-latest">test-unit-fox: The latest release</h3>
|
207
|
+
<h3 id="test-unit-runner-fox-latest">test-unit-runner-fox: The latest release</h3>
|
177
208
|
<p>
|
178
209
|
0.0.1 is the latest release. It had been released at 2008-06-17.
|
179
210
|
</p>
|
180
|
-
<h3 id="test-unit-fox-install">test-unit-fox: Install</h3>
|
211
|
+
<h3 id="test-unit-runner-fox-install">test-unit-runner-fox: Install</h3>
|
181
212
|
<p>
|
182
213
|
Install:
|
183
|
-
<pre class="command">% sudo gem install test-unit-fox</pre>
|
214
|
+
<pre class="command">% sudo gem install test-unit-runner-fox</pre>
|
184
215
|
</p>
|
185
216
|
<p>
|
186
217
|
Usage:
|
@@ -206,12 +237,14 @@ require "test/unit"</pre>
|
|
206
237
|
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-full/trunk test-unit-full</pre></dd>
|
207
238
|
<dt>test-unit-notify</dt>
|
208
239
|
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-notify/trunk test-unit-notify</pre></dd>
|
209
|
-
<dt>test-unit-
|
210
|
-
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-
|
211
|
-
<dt>test-unit-
|
212
|
-
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-
|
213
|
-
<dt>test-unit-
|
214
|
-
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-
|
240
|
+
<dt>test-unit-rr</dt>
|
241
|
+
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-rr/trunk test-unit-rr</pre></dd>
|
242
|
+
<dt>test-unit-runner-gtk2</dt>
|
243
|
+
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-runner-gtk2/trunk test-unit-runner-gtk2</pre></dd>
|
244
|
+
<dt>test-unit-runner-tk</dt>
|
245
|
+
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-runner-tk/trunk test-unit-runner-tk</pre></dd>
|
246
|
+
<dt>test-unit-runner-fox</dt>
|
247
|
+
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-runner-fox/trunk test-unit-runner-fox</pre></dd>
|
215
248
|
</dl>
|
216
249
|
</div>
|
217
250
|
|
data/html/index.html.ja
CHANGED
@@ -91,7 +91,7 @@ require "test/unit"</pre>
|
|
91
91
|
</p>
|
92
92
|
<h3 id="test-unit-latest">test-unit最新リリース</h3>
|
93
93
|
<p>
|
94
|
-
|
94
|
+
2011-02-14にリリースされた2.2.0が最新リリースです。
|
95
95
|
</p>
|
96
96
|
<h3 id="test-unit-install">test-unitのインストール</h3>
|
97
97
|
<p>
|
@@ -105,7 +105,7 @@ require "test/unit"</pre>
|
|
105
105
|
</p>
|
106
106
|
<h3 id="test-unit-full-latest">test-unit-full最新リリース</h3>
|
107
107
|
<p>
|
108
|
-
|
108
|
+
2011-02-09にリリースされた0.0.3が最新リリースです。
|
109
109
|
</p>
|
110
110
|
<h3 id="test-unit-full-install">test-unit-fullのインストール</h3>
|
111
111
|
<p>
|
@@ -119,21 +119,25 @@ require "test/unit"</pre>
|
|
119
119
|
|
120
120
|
<h2 id="test-unit-notify">test-unit-notify</h2>
|
121
121
|
<p>
|
122
|
-
<
|
123
|
-
|
122
|
+
<div class="eye-catch">
|
123
|
+
<img alt="GNOME上での通知"
|
124
|
+
src="test-unit-notify/screenshot/notify-on-gnome.png" />
|
125
|
+
<img alt="Mac OS X上での通知"
|
126
|
+
src="test-unit-notify/screenshot/notify-on-mac-os-x.png" />
|
127
|
+
</div>
|
124
128
|
テストの実行結果をポップアップで通知します。通知方法は環境によって異なります。
|
125
129
|
<dl class="feature-list">
|
126
130
|
<dt>GNOMEやXfceやKDEなどのX Window Systemベースの環境</dt>
|
127
131
|
<dd>notify-sendを使ってD-Bus経由でnotification-daemonにリクエストを送ることにより通知します。notify-sendコマンドが無かったり、notification-daemonが動いていない場合は利用できません。</dd>
|
128
132
|
<dt>Mac OS X</dt>
|
129
|
-
<dd>Growl
|
133
|
+
<dd>growlnotifyを使って通知します。growlnotifyコマンドが無かったり、Growlが動いていない場合は利用できません。</dd>
|
130
134
|
<dt>Windows</dt>
|
131
135
|
<dd>どうやるのがいいのでしょうか。Growl for Windows?(未実装)</dd>
|
132
136
|
</dl>
|
133
137
|
</p>
|
134
138
|
<h3 id="test-unit-notify-latest">test-unit-notify最新リリース</h3>
|
135
139
|
<p>
|
136
|
-
|
140
|
+
2011-02-10にリリースされた0.2.1が最新リリースです。
|
137
141
|
</p>
|
138
142
|
<h3 id="test-unit-notify-install">test-unit-notifyのインストール</h3>
|
139
143
|
<p>
|
@@ -148,18 +152,36 @@ require "test/unit"</pre>
|
|
148
152
|
--notifyオプションが追加されます。--notifyオプションを指定するとテスト終了時にテスト結果をポップアップで通知します。
|
149
153
|
</p>
|
150
154
|
|
151
|
-
<h2 id="test-unit-
|
155
|
+
<h2 id="test-unit-rr">test-unit-rr</h2>
|
156
|
+
<p>
|
157
|
+
test-unit 2で<a href="http://capsctrl.que.jp/kdmsnr/wiki/bliki/?TestDouble">テストダブル(テスト代役)</a>ライブラリ<a href="http://github.com/btakita/rr">RR</a>を利用するためのパッケージです。
|
158
|
+
</p>
|
159
|
+
<h3 id="test-unit-rr-latest">test-unit-rr最新リリース</h3>
|
160
|
+
<p>
|
161
|
+
2011-02-10にリリースされた1.0.1が最新リリースです。
|
162
|
+
</p>
|
163
|
+
<h3 id="test-unit-rr-install">test-unit-rrのインストール</h3>
|
164
|
+
<p>
|
165
|
+
インストール:
|
166
|
+
<pre class="command">% sudo gem install test-unit-rr</pre>
|
167
|
+
</p>
|
168
|
+
<p>
|
169
|
+
使い方:
|
170
|
+
<pre class="code">require "test/unit/rr"</pre>
|
171
|
+
</p>
|
172
|
+
|
173
|
+
<h2 id="test-unit-runner-gtk2">test-unit-runner-gtk2</h2>
|
152
174
|
<p>
|
153
175
|
GTK+を用いて実装されたGUIのテスト実行機能です。
|
154
176
|
</p>
|
155
|
-
<h3 id="test-unit-gtk2-latest">test-unit-gtk2最新リリース</h3>
|
177
|
+
<h3 id="test-unit-runner-gtk2-latest">test-unit-runner-gtk2最新リリース</h3>
|
156
178
|
<p>
|
157
|
-
|
179
|
+
2011-02-09にリリースされた0.0.2が最新リリースです。
|
158
180
|
</p>
|
159
|
-
<h3 id="test-unit-gtk2-install">test-unit-gtk2のインストール</h3>
|
181
|
+
<h3 id="test-unit-runner-gtk2-install">test-unit-runner-gtk2のインストール</h3>
|
160
182
|
<p>
|
161
183
|
インストール:
|
162
|
-
<pre class="command">% sudo gem install test-unit-gtk2</pre>
|
184
|
+
<pre class="command">% sudo gem install test-unit-runner-gtk2</pre>
|
163
185
|
</p>
|
164
186
|
<p>
|
165
187
|
使い方:
|
@@ -170,18 +192,18 @@ require "test/unit"</pre>
|
|
170
192
|
</p>
|
171
193
|
|
172
194
|
|
173
|
-
<h2 id="test-unit-tk">test-unit-tk</h2>
|
195
|
+
<h2 id="test-unit-runner-tk">test-unit-runner-tk</h2>
|
174
196
|
<p>
|
175
197
|
Tkを用いて実装されたGUIのテスト実行機能です。
|
176
198
|
</p>
|
177
|
-
<h3 id="test-unit-tk-latest">test-unit-tk最新リリース</h3>
|
199
|
+
<h3 id="test-unit-runner-tk-latest">test-unit-runner-tk最新リリース</h3>
|
178
200
|
<p>
|
179
201
|
2008-06-17にリリースされた0.0.1が最新リリースです。
|
180
202
|
</p>
|
181
|
-
<h3 id="test-unit-tk-install">test-unit-tkのインストール</h3>
|
203
|
+
<h3 id="test-unit-runner-tk-install">test-unit-runner-tkのインストール</h3>
|
182
204
|
<p>
|
183
205
|
インストール:
|
184
|
-
<pre class="command">% sudo gem install test-unit-tk</pre>
|
206
|
+
<pre class="command">% sudo gem install test-unit-runner-tk</pre>
|
185
207
|
</p>
|
186
208
|
<p>
|
187
209
|
使い方:
|
@@ -191,18 +213,18 @@ require "test/unit"</pre>
|
|
191
213
|
--runner=tkオプションが追加されます。--runner=tkオプションを指定するとTkベースのUIでテストを実行します。
|
192
214
|
</p>
|
193
215
|
|
194
|
-
<h2 id="test-unit-fox">test-unit-fox</h2>
|
216
|
+
<h2 id="test-unit-runner-fox">test-unit-runner-fox</h2>
|
195
217
|
<p>
|
196
218
|
FOX Toolkitを用いて実装されたGUIのテスト実行機能です。
|
197
219
|
</p>
|
198
|
-
<h3 id="test-unit-fox-latest">test-unit-fox最新リリース</h3>
|
220
|
+
<h3 id="test-unit-runner-fox-latest">test-unit-runner-fox最新リリース</h3>
|
199
221
|
<p>
|
200
222
|
2008-06-17にリリースされた0.0.1が最新リリースです。
|
201
223
|
</p>
|
202
|
-
<h3 id="test-unit-fox-install">test-unit-foxのインストール</h3>
|
224
|
+
<h3 id="test-unit-runner-fox-install">test-unit-runner-foxのインストール</h3>
|
203
225
|
<p>
|
204
226
|
インストール:
|
205
|
-
<pre class="command">% sudo gem install test-unit-fox</pre>
|
227
|
+
<pre class="command">% sudo gem install test-unit-runner-fox</pre>
|
206
228
|
</p>
|
207
229
|
<p>
|
208
230
|
使い方:
|
@@ -229,12 +251,14 @@ require "test/unit"</pre>
|
|
229
251
|
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-full/trunk test-unit-full</pre></dd>
|
230
252
|
<dt>test-unit-notify</dt>
|
231
253
|
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-notify/trunk test-unit-notify</pre></dd>
|
232
|
-
<dt>test-unit-
|
233
|
-
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-
|
234
|
-
<dt>test-unit-
|
235
|
-
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-
|
236
|
-
<dt>test-unit-
|
237
|
-
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-
|
254
|
+
<dt>test-unit-rr</dt>
|
255
|
+
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-rr/trunk test-unit-rr</pre></dd>
|
256
|
+
<dt>test-unit-runner-gtk2</dt>
|
257
|
+
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-runner-gtk2/trunk test-unit-runner-gtk2</pre></dd>
|
258
|
+
<dt>test-unit-runner-tk</dt>
|
259
|
+
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-runner-tk/trunk test-unit-runner-tk</pre></dd>
|
260
|
+
<dt>test-unit-runner-fox</dt>
|
261
|
+
<dd><pre class="command">% svn co http://test-unit.rubyforge.org/svn/extensions/test-unit-runner-fox/trunk test-unit-runner-fox</pre></dd>
|
238
262
|
</dl>
|
239
263
|
</div>
|
240
264
|
|
data/html/test-unit.css
CHANGED
@@ -300,14 +300,14 @@ pre.code
|
|
300
300
|
padding: 5px 10px;
|
301
301
|
}
|
302
302
|
|
303
|
-
|
303
|
+
div.eye-catch
|
304
304
|
{
|
305
305
|
float: right;
|
306
306
|
}
|
307
307
|
|
308
|
-
|
308
|
+
div.eye-catch img
|
309
309
|
{
|
310
|
-
|
310
|
+
display: block;
|
311
311
|
}
|
312
312
|
|
313
313
|
dl.feature-list dd
|
data/lib/test/unit/assertions.rb
CHANGED
@@ -45,7 +45,7 @@ module Test
|
|
45
45
|
# end
|
46
46
|
|
47
47
|
public
|
48
|
-
def assert_block(message="assert_block failed.") # :yields:
|
48
|
+
def assert_block(message="assert_block failed.") # :yields:
|
49
49
|
_wrap_assertion do
|
50
50
|
if (! yield)
|
51
51
|
raise AssertionFailedError.new(message.to_s)
|
@@ -62,8 +62,19 @@ module Test
|
|
62
62
|
public
|
63
63
|
def assert(boolean, message=nil)
|
64
64
|
_wrap_assertion do
|
65
|
-
|
66
|
-
|
65
|
+
case message
|
66
|
+
when nil, String, Proc
|
67
|
+
else
|
68
|
+
error_message = "assertion message must be String or Proc: "
|
69
|
+
error_message << "<#{message.inspect}>(<#{message.class}>)"
|
70
|
+
raise ArgumentError, error_message, filter_backtrace(caller)
|
71
|
+
end
|
72
|
+
assert_block("assert should not be called with a block.") do
|
73
|
+
!block_given?
|
74
|
+
end
|
75
|
+
assert_block(build_message(message, "<?> is not true.", boolean)) do
|
76
|
+
boolean
|
77
|
+
end
|
67
78
|
end
|
68
79
|
end
|
69
80
|
|
@@ -297,6 +308,31 @@ EOT
|
|
297
308
|
end
|
298
309
|
end
|
299
310
|
|
311
|
+
##
|
312
|
+
# Passes if +object+ does not .respond_to? +method+.
|
313
|
+
#
|
314
|
+
# Example:
|
315
|
+
# assert_not_respond_to('bugbear', :nonexistence) # -> pass
|
316
|
+
# assert_not_respond_to('bugbear', :size) # -> fail
|
317
|
+
|
318
|
+
public
|
319
|
+
def assert_not_respond_to(object, method, message="")
|
320
|
+
_wrap_assertion do
|
321
|
+
full_message = build_message(message,
|
322
|
+
"<?>.kind_of\\?(Symbol) or\n" +
|
323
|
+
"<?>.respond_to\\?(:to_str) expected",
|
324
|
+
method, method)
|
325
|
+
assert_block(full_message) do
|
326
|
+
method.kind_of?(Symbol) or method.respond_to?(:to_str)
|
327
|
+
end
|
328
|
+
full_message = build_message(message,
|
329
|
+
"!<?>.respond_to\\?(?) expected\n" +
|
330
|
+
"(Class: <?>)",
|
331
|
+
object, method, object.class)
|
332
|
+
assert_block(full_message) {!object.respond_to?(method)}
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
300
336
|
##
|
301
337
|
# Passes if +string+ =~ +pattern+.
|
302
338
|
#
|
@@ -444,25 +480,49 @@ EOT
|
|
444
480
|
end
|
445
481
|
|
446
482
|
##
|
447
|
-
# Passes if +regexp+ !~ +string+
|
483
|
+
# Passes if +regexp+ !~ +string+
|
448
484
|
#
|
449
485
|
# Example:
|
450
|
-
#
|
486
|
+
# assert_not_match(/two/, 'one 2 three') # -> pass
|
487
|
+
# assert_not_match(/three/, 'one 2 three') # -> fail
|
451
488
|
|
452
489
|
public
|
453
|
-
def
|
490
|
+
def assert_not_match(regexp, string, message="")
|
454
491
|
_wrap_assertion do
|
455
|
-
assert_instance_of(Regexp, regexp,
|
456
|
-
|
492
|
+
assert_instance_of(Regexp, regexp,
|
493
|
+
"<REGEXP> in assert_not_match(<REGEXP>, ...) " +
|
494
|
+
"should be a Regexp.")
|
495
|
+
full_message = build_message(message,
|
496
|
+
"<?> expected to not match\n<?>.",
|
497
|
+
regexp, string)
|
457
498
|
assert_block(full_message) { regexp !~ string }
|
458
499
|
end
|
459
500
|
end
|
460
501
|
|
502
|
+
##
|
503
|
+
# Deprecated. Use #assert_not_match instead.
|
504
|
+
#
|
505
|
+
# Passes if +regexp+ !~ +string+
|
506
|
+
#
|
507
|
+
# Example:
|
508
|
+
# assert_no_match(/two/, 'one 2 three') # -> pass
|
509
|
+
# assert_no_match(/three/, 'one 2 three') # -> fail
|
510
|
+
|
511
|
+
public
|
512
|
+
def assert_no_match(regexp, string, message="")
|
513
|
+
_wrap_assertion do
|
514
|
+
assert_instance_of(Regexp, regexp,
|
515
|
+
"The first argument to assert_no_match " +
|
516
|
+
"should be a Regexp.")
|
517
|
+
assert_not_match(regexp, string, message)
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
461
521
|
UncaughtThrow = {
|
462
|
-
NameError => /^uncaught throw \`(.+)\'$/,
|
522
|
+
NameError => /^uncaught throw \`(.+)\'$/, #`
|
463
523
|
ArgumentError => /^uncaught throw (.+)$/,
|
464
|
-
ThreadError => /^uncaught throw \`(.+)\' in thread /
|
465
|
-
}
|
524
|
+
ThreadError => /^uncaught throw \`(.+)\' in thread / #`
|
525
|
+
}
|
466
526
|
|
467
527
|
##
|
468
528
|
# Passes if the block throws +expected_object+
|
@@ -550,7 +610,7 @@ EOT
|
|
550
610
|
# assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
|
551
611
|
|
552
612
|
public
|
553
|
-
def assert_in_delta(expected_float, actual_float, delta, message="")
|
613
|
+
def assert_in_delta(expected_float, actual_float, delta=0.001, message="")
|
554
614
|
_wrap_assertion do
|
555
615
|
_assert_in_delta_validate_arguments(expected_float,
|
556
616
|
actual_float,
|
@@ -565,6 +625,31 @@ EOT
|
|
565
625
|
end
|
566
626
|
end
|
567
627
|
|
628
|
+
##
|
629
|
+
# Passes if +expected_float+ and +actual_float+ are
|
630
|
+
# not equal within +delta+ tolerance.
|
631
|
+
#
|
632
|
+
# Example:
|
633
|
+
# assert_not_in_delta(0.05, (50000.0 / 10**6), 0.00002) # -> pass
|
634
|
+
# assert_not_in_delta(0.05, (50000.0 / 10**6), 0.00001) # -> fail
|
635
|
+
|
636
|
+
public
|
637
|
+
def assert_not_in_delta(expected_float, actual_float, delta=0.001, message="")
|
638
|
+
_wrap_assertion do
|
639
|
+
_assert_in_delta_validate_arguments(expected_float,
|
640
|
+
actual_float,
|
641
|
+
delta)
|
642
|
+
full_message = _assert_in_delta_message(expected_float,
|
643
|
+
actual_float,
|
644
|
+
delta,
|
645
|
+
message,
|
646
|
+
:negative_assertion => true)
|
647
|
+
assert_block(full_message) do
|
648
|
+
(expected_float.to_f - actual_float.to_f).abs > delta.to_f
|
649
|
+
end
|
650
|
+
end
|
651
|
+
end
|
652
|
+
|
568
653
|
# :stopdoc:
|
569
654
|
private
|
570
655
|
def _assert_in_delta_validate_arguments(expected_float,
|
@@ -579,30 +664,49 @@ EOT
|
|
579
664
|
"The arguments must respond to to_f; " +
|
580
665
|
"the #{name} did not")
|
581
666
|
end
|
667
|
+
delta = delta.to_f
|
582
668
|
assert_operator(delta, :>=, 0.0, "The delta should not be negative")
|
583
669
|
end
|
584
670
|
|
585
671
|
def _assert_in_delta_message(expected_float, actual_float, delta,
|
586
|
-
message)
|
587
|
-
|
588
|
-
|
589
|
-
<?>
|
672
|
+
message, options={})
|
673
|
+
if options[:negative_assertion]
|
674
|
+
format = <<-EOT
|
675
|
+
<?> -/+ <?> expected to not include
|
676
|
+
<?>.
|
677
|
+
EOT
|
678
|
+
else
|
679
|
+
format = <<-EOT
|
680
|
+
<?> -/+ <?> expected to include
|
681
|
+
<?>.
|
590
682
|
EOT
|
591
|
-
|
683
|
+
end
|
684
|
+
arguments = [expected_float, delta, actual_float]
|
592
685
|
normalized_expected = expected_float.to_f
|
593
686
|
normalized_actual = actual_float.to_f
|
594
687
|
normalized_delta = delta.to_f
|
595
688
|
relation_format = nil
|
596
689
|
relation_arguments = nil
|
597
690
|
if normalized_actual < normalized_expected - normalized_delta
|
598
|
-
relation_format = "<<?> < <?>-<?>
|
691
|
+
relation_format = "<<?> < <?>-<?>[?] <= <?>+<?>[?]>"
|
599
692
|
relation_arguments = [actual_float,
|
600
|
-
expected_float, delta,
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
693
|
+
expected_float, delta,
|
694
|
+
normalized_expected - normalized_delta,
|
695
|
+
expected_float, delta,
|
696
|
+
normalized_expected + normalized_delta]
|
697
|
+
elsif normalized_actual <= normalized_expected + normalized_delta
|
698
|
+
relation_format = "<<?>-<?>[?] <= <?> <= <?>+<?>[?]>"
|
699
|
+
relation_arguments = [expected_float, delta,
|
700
|
+
normalized_expected - normalized_delta,
|
701
|
+
actual_float,
|
702
|
+
expected_float, delta,
|
703
|
+
normalized_expected + normalized_delta]
|
704
|
+
else
|
705
|
+
relation_format = "<<?>-<?>[?] <= <?>+<?>[?] < <?>>"
|
706
|
+
relation_arguments = [expected_float, delta,
|
707
|
+
normalized_expected - normalized_delta,
|
708
|
+
expected_float, delta,
|
709
|
+
normalized_expected + normalized_delta,
|
606
710
|
actual_float]
|
607
711
|
end
|
608
712
|
|
@@ -617,6 +721,142 @@ EOT
|
|
617
721
|
|
618
722
|
build_message(message, format, *arguments)
|
619
723
|
end
|
724
|
+
|
725
|
+
public
|
726
|
+
# :startdoc:
|
727
|
+
|
728
|
+
##
|
729
|
+
# Passes if +expected_float+ and +actual_float+ are equal
|
730
|
+
# within +epsilon+ relative error of +expected_float+.
|
731
|
+
#
|
732
|
+
# Example:
|
733
|
+
# assert_in_epsilon(10000.0, 9900.0, 0.1) # -> pass
|
734
|
+
# assert_in_epsilon(10000.0, 9899.0, 0.1) # -> fail
|
735
|
+
|
736
|
+
public
|
737
|
+
def assert_in_epsilon(expected_float, actual_float, epsilon=0.001,
|
738
|
+
message="")
|
739
|
+
_wrap_assertion do
|
740
|
+
_assert_in_epsilon_validate_arguments(expected_float,
|
741
|
+
actual_float,
|
742
|
+
epsilon)
|
743
|
+
full_message = _assert_in_epsilon_message(expected_float,
|
744
|
+
actual_float,
|
745
|
+
epsilon,
|
746
|
+
message)
|
747
|
+
assert_block(full_message) do
|
748
|
+
normalized_expected_float = expected_float.to_f
|
749
|
+
delta = normalized_expected_float * epsilon.to_f
|
750
|
+
(normalized_expected_float - actual_float.to_f).abs <= delta
|
751
|
+
end
|
752
|
+
end
|
753
|
+
end
|
754
|
+
|
755
|
+
##
|
756
|
+
# Passes if +expected_float+ and +actual_float+ are
|
757
|
+
# not equal within +epsilon+ relative error of
|
758
|
+
# +expected_float+.
|
759
|
+
#
|
760
|
+
# Example:
|
761
|
+
# assert_not_in_epsilon(10000.0, 9900.0, 0.1) # -> fail
|
762
|
+
# assert_not_in_epsilon(10000.0, 9899.0, 0.1) # -> pass
|
763
|
+
|
764
|
+
public
|
765
|
+
def assert_not_in_epsilon(expected_float, actual_float, epsilon=0.001,
|
766
|
+
message="")
|
767
|
+
_wrap_assertion do
|
768
|
+
_assert_in_epsilon_validate_arguments(expected_float,
|
769
|
+
actual_float,
|
770
|
+
epsilon)
|
771
|
+
full_message = _assert_in_epsilon_message(expected_float,
|
772
|
+
actual_float,
|
773
|
+
epsilon,
|
774
|
+
message,
|
775
|
+
:negative_assertion => true)
|
776
|
+
assert_block(full_message) do
|
777
|
+
normalized_expected_float = expected_float.to_f
|
778
|
+
delta = normalized_expected_float * epsilon.to_f
|
779
|
+
(normalized_expected_float - actual_float.to_f).abs > delta
|
780
|
+
end
|
781
|
+
end
|
782
|
+
end
|
783
|
+
|
784
|
+
# :stopdoc:
|
785
|
+
private
|
786
|
+
def _assert_in_epsilon_validate_arguments(expected_float,
|
787
|
+
actual_float,
|
788
|
+
epsilon)
|
789
|
+
{
|
790
|
+
expected_float => "first float",
|
791
|
+
actual_float => "second float",
|
792
|
+
epsilon => "epsilon"
|
793
|
+
}.each do |float, name|
|
794
|
+
assert_respond_to(float, :to_f,
|
795
|
+
"The arguments must respond to to_f; " +
|
796
|
+
"the #{name} did not")
|
797
|
+
end
|
798
|
+
epsilon = epsilon.to_f
|
799
|
+
assert_operator(epsilon, :>=, 0.0, "The epsilon should not be negative")
|
800
|
+
end
|
801
|
+
|
802
|
+
def _assert_in_epsilon_message(expected_float, actual_float, epsilon,
|
803
|
+
message, options={})
|
804
|
+
normalized_expected = expected_float.to_f
|
805
|
+
normalized_actual = actual_float.to_f
|
806
|
+
normalized_epsilon = epsilon.to_f
|
807
|
+
delta = normalized_expected * normalized_epsilon
|
808
|
+
|
809
|
+
if options[:negative_assertion]
|
810
|
+
format = <<-EOT
|
811
|
+
<?> -/+ (<?> * <?>)[?] expected to not include
|
812
|
+
<?>.
|
813
|
+
EOT
|
814
|
+
else
|
815
|
+
format = <<-EOT
|
816
|
+
<?> -/+ (<?> * <?>)[?] expected to include
|
817
|
+
<?>.
|
818
|
+
EOT
|
819
|
+
end
|
820
|
+
arguments = [expected_float, expected_float, epsilon, delta,
|
821
|
+
actual_float]
|
822
|
+
|
823
|
+
relation_format = nil
|
824
|
+
relation_arguments = nil
|
825
|
+
if normalized_actual < normalized_expected - delta
|
826
|
+
relation_format = "<<?> < <?>-(<?>*<?>)[?] <= <?>+(<?>*<?>)[?]>"
|
827
|
+
relation_arguments = [actual_float,
|
828
|
+
expected_float, expected_float, epsilon,
|
829
|
+
normalized_expected - delta,
|
830
|
+
expected_float, expected_float, epsilon,
|
831
|
+
normalized_expected + delta]
|
832
|
+
elsif normalized_actual <= normalized_expected + delta
|
833
|
+
relation_format = "<<?>-(<?>*<?>)[?] <= <?> <= <?>+(<?>*<?>)[?]>"
|
834
|
+
relation_arguments = [expected_float, expected_float, epsilon,
|
835
|
+
normalized_expected - delta,
|
836
|
+
actual_float,
|
837
|
+
expected_float, expected_float, epsilon,
|
838
|
+
normalized_expected + delta]
|
839
|
+
else
|
840
|
+
relation_format = "<<?>-(<?>*<?>)[?] <= <?>+(<?>*<?>)[?] < <?>>"
|
841
|
+
relation_arguments = [expected_float, expected_float, epsilon,
|
842
|
+
normalized_expected - delta,
|
843
|
+
expected_float, expected_float, epsilon,
|
844
|
+
normalized_expected + delta,
|
845
|
+
actual_float]
|
846
|
+
end
|
847
|
+
|
848
|
+
if relation_format
|
849
|
+
format << <<-EOT
|
850
|
+
|
851
|
+
Relation:
|
852
|
+
#{relation_format}
|
853
|
+
EOT
|
854
|
+
arguments.concat(relation_arguments)
|
855
|
+
end
|
856
|
+
|
857
|
+
build_message(message, format, *arguments)
|
858
|
+
end
|
859
|
+
|
620
860
|
public
|
621
861
|
# :startdoc:
|
622
862
|
|
@@ -629,18 +869,76 @@ EOT
|
|
629
869
|
# * Arguments to the method
|
630
870
|
#
|
631
871
|
# Example:
|
632
|
-
# assert_send
|
872
|
+
# assert_send([[1, 2], :member?, 1]) # -> pass
|
873
|
+
# assert_send([[1, 2], :member?, 4]) # -> fail
|
633
874
|
|
634
875
|
public
|
635
|
-
def assert_send(send_array, message=
|
876
|
+
def assert_send(send_array, message=nil)
|
877
|
+
_wrap_assertion do
|
878
|
+
assert_instance_of(Array, send_array,
|
879
|
+
"assert_send requires an array " +
|
880
|
+
"of send information")
|
881
|
+
assert_operator(send_array.size, :>=, 2,
|
882
|
+
"assert_send requires at least a receiver " +
|
883
|
+
"and a message name")
|
884
|
+
format = <<EOT
|
885
|
+
<?> expected to respond to
|
886
|
+
<?(*?)> with a true value but was
|
887
|
+
<?>.
|
888
|
+
EOT
|
889
|
+
receiver, message_name, *arguments = send_array
|
890
|
+
result = nil
|
891
|
+
full_message =
|
892
|
+
build_message(message,
|
893
|
+
format,
|
894
|
+
receiver,
|
895
|
+
AssertionMessage.literal(message_name.to_s),
|
896
|
+
arguments,
|
897
|
+
AssertionMessage.delayed_literal {result})
|
898
|
+
assert_block(full_message) do
|
899
|
+
result = receiver.__send__(message_name, *arguments)
|
900
|
+
result
|
901
|
+
end
|
902
|
+
end
|
903
|
+
end
|
904
|
+
|
905
|
+
##
|
906
|
+
# Passes if the method send doesn't return a true value.
|
907
|
+
#
|
908
|
+
# +send_array+ is composed of:
|
909
|
+
# * A receiver
|
910
|
+
# * A method
|
911
|
+
# * Arguments to the method
|
912
|
+
#
|
913
|
+
# Example:
|
914
|
+
# assert_not_send([[1, 2], :member?, 1]) # -> fail
|
915
|
+
# assert_not_send([[1, 2], :member?, 4]) # -> pass
|
916
|
+
def assert_not_send(send_array, message=nil)
|
636
917
|
_wrap_assertion do
|
637
|
-
assert_instance_of(Array, send_array,
|
638
|
-
|
639
|
-
|
918
|
+
assert_instance_of(Array, send_array,
|
919
|
+
"assert_not_send requires an array " +
|
920
|
+
"of send information")
|
921
|
+
assert_operator(send_array.size, :>=, 2,
|
922
|
+
"assert_not_send requires at least a receiver " +
|
923
|
+
"and a message name")
|
924
|
+
format = <<EOT
|
640
925
|
<?> expected to respond to
|
641
|
-
<?(
|
926
|
+
<?(*?)> with not a true value but was
|
927
|
+
<?>.
|
642
928
|
EOT
|
643
|
-
|
929
|
+
receiver, message_name, *arguments = send_array
|
930
|
+
result = nil
|
931
|
+
full_message =
|
932
|
+
build_message(message,
|
933
|
+
format,
|
934
|
+
receiver,
|
935
|
+
AssertionMessage.literal(message_name.to_s),
|
936
|
+
arguments,
|
937
|
+
AssertionMessage.delayed_literal {result})
|
938
|
+
assert_block(full_message) do
|
939
|
+
result = receiver.__send__(message_name, *arguments)
|
940
|
+
not result
|
941
|
+
end
|
644
942
|
end
|
645
943
|
end
|
646
944
|
|
@@ -823,7 +1121,7 @@ EOT
|
|
823
1121
|
end
|
824
1122
|
|
825
1123
|
##
|
826
|
-
# Passes if +object+.+predicate+
|
1124
|
+
# Passes if +object+.+predicate+ is _true_.
|
827
1125
|
#
|
828
1126
|
# Example:
|
829
1127
|
# assert_predicate([], :empty?) # -> pass
|
@@ -845,7 +1143,7 @@ EOT
|
|
845
1143
|
end
|
846
1144
|
|
847
1145
|
##
|
848
|
-
# Passes if +object+.+predicate+
|
1146
|
+
# Passes if +object+.+predicate+ is not _true_.
|
849
1147
|
#
|
850
1148
|
# Example:
|
851
1149
|
# assert_not_predicate([1], :empty?) # -> pass
|
@@ -950,6 +1248,96 @@ EOT
|
|
950
1248
|
end
|
951
1249
|
end
|
952
1250
|
|
1251
|
+
##
|
1252
|
+
# Passes if +collection+ includes +object+.
|
1253
|
+
#
|
1254
|
+
# Example:
|
1255
|
+
# assert_include([1, 10], 1) # -> pass
|
1256
|
+
# assert_include(1..10, 5) # -> pass
|
1257
|
+
# assert_include([1, 10], 5) # -> fail
|
1258
|
+
# assert_include(1..10, 20) # -> fail
|
1259
|
+
def assert_include(collection, object, message=nil)
|
1260
|
+
_wrap_assertion do
|
1261
|
+
assert_respond_to(collection, :include?,
|
1262
|
+
"The collection must respond to :include?.")
|
1263
|
+
full_message = build_message(message,
|
1264
|
+
"<?> expected to include\n<?>.",
|
1265
|
+
collection,
|
1266
|
+
object)
|
1267
|
+
assert_block(full_message) do
|
1268
|
+
collection.include?(object)
|
1269
|
+
end
|
1270
|
+
end
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
##
|
1274
|
+
# Passes if +collection+ doesn't include +object+.
|
1275
|
+
#
|
1276
|
+
# Example:
|
1277
|
+
# assert_not_include([1, 10], 5) # -> pass
|
1278
|
+
# assert_not_include(1..10, 20) # -> pass
|
1279
|
+
# assert_not_include([1, 10], 1) # -> fail
|
1280
|
+
# assert_not_include(1..10, 5) # -> fail
|
1281
|
+
def assert_not_include(collection, object, message=nil)
|
1282
|
+
_wrap_assertion do
|
1283
|
+
assert_respond_to(collection, :include?,
|
1284
|
+
"The collection must respond to :include?.")
|
1285
|
+
full_message = build_message(message,
|
1286
|
+
"<?> expected to not include\n<?>.",
|
1287
|
+
collection,
|
1288
|
+
object)
|
1289
|
+
assert_block(full_message) do
|
1290
|
+
not collection.include?(object)
|
1291
|
+
end
|
1292
|
+
end
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
##
|
1296
|
+
# Passes if +object+ is empty.
|
1297
|
+
#
|
1298
|
+
# Example:
|
1299
|
+
# assert_empty("") # -> pass
|
1300
|
+
# assert_empty([]) # -> pass
|
1301
|
+
# assert_empty({}) # -> pass
|
1302
|
+
# assert_empty(" ") # -> fail
|
1303
|
+
# assert_empty([nil]) # -> fail
|
1304
|
+
# assert_empty({1 => 2}) # -> fail
|
1305
|
+
def assert_empty(object, message=nil)
|
1306
|
+
_wrap_assertion do
|
1307
|
+
assert_respond_to(object, :empty?,
|
1308
|
+
"The object must respond to :empty?.")
|
1309
|
+
full_message = build_message(message,
|
1310
|
+
"<?> expected to be empty.",
|
1311
|
+
object)
|
1312
|
+
assert_block(full_message) do
|
1313
|
+
object.empty?
|
1314
|
+
end
|
1315
|
+
end
|
1316
|
+
end
|
1317
|
+
|
1318
|
+
##
|
1319
|
+
# Passes if +object+ is not empty.
|
1320
|
+
#
|
1321
|
+
# Example:
|
1322
|
+
# assert_not_empty(" ") # -> pass
|
1323
|
+
# assert_not_empty([nil]) # -> pass
|
1324
|
+
# assert_not_empty({1 => 2}) # -> pass
|
1325
|
+
# assert_not_empty("") # -> fail
|
1326
|
+
# assert_not_empty([]) # -> fail
|
1327
|
+
# assert_not_empty({}) # -> fail
|
1328
|
+
def assert_not_empty(object, message=nil)
|
1329
|
+
_wrap_assertion do
|
1330
|
+
assert_respond_to(object, :empty?,
|
1331
|
+
"The object must respond to :empty?.")
|
1332
|
+
full_message = build_message(message,
|
1333
|
+
"<?> expected to not be empty.",
|
1334
|
+
object)
|
1335
|
+
assert_block(full_message) do
|
1336
|
+
not object.empty?
|
1337
|
+
end
|
1338
|
+
end
|
1339
|
+
end
|
1340
|
+
|
953
1341
|
##
|
954
1342
|
# Builds a failure message. +head+ is added before the +template+ and
|
955
1343
|
# +arguments+ replaces the '?'s positionally in the template.
|
@@ -961,21 +1349,21 @@ EOT
|
|
961
1349
|
end
|
962
1350
|
|
963
1351
|
private
|
964
|
-
def _wrap_assertion
|
1352
|
+
def _wrap_assertion(&block)
|
965
1353
|
@_assertion_wrapped ||= false
|
966
|
-
|
1354
|
+
if @_assertion_wrapped
|
1355
|
+
block.call
|
1356
|
+
else
|
967
1357
|
@_assertion_wrapped = true
|
968
1358
|
begin
|
969
1359
|
add_assertion
|
970
|
-
|
1360
|
+
block.call
|
971
1361
|
ensure
|
972
1362
|
@_assertion_wrapped = false
|
973
1363
|
end
|
974
|
-
else
|
975
|
-
return yield
|
976
1364
|
end
|
977
1365
|
end
|
978
|
-
|
1366
|
+
|
979
1367
|
##
|
980
1368
|
# Called whenever an assertion is made. Define this in classes that
|
981
1369
|
# include Test::Unit::Assertions to record assertion counts.
|
@@ -1062,6 +1450,14 @@ EOT
|
|
1062
1450
|
end
|
1063
1451
|
end
|
1064
1452
|
|
1453
|
+
def ensure_diffable_string(string)
|
1454
|
+
if string.respond_to?(:encoding) and
|
1455
|
+
!string.encoding.ascii_compatible?
|
1456
|
+
string = string.dup.force_encoding("ASCII-8BIT")
|
1457
|
+
end
|
1458
|
+
string
|
1459
|
+
end
|
1460
|
+
|
1065
1461
|
def prepare_for_diff(from, to)
|
1066
1462
|
if !from.is_a?(String) or !to.is_a?(String)
|
1067
1463
|
from = convert(from)
|
@@ -1069,6 +1465,8 @@ EOT
|
|
1069
1465
|
end
|
1070
1466
|
|
1071
1467
|
if diff_target_string?(from) and diff_target_string?(to)
|
1468
|
+
from = ensure_diffable_string(from)
|
1469
|
+
to = ensure_diffable_string(to)
|
1072
1470
|
[from, to]
|
1073
1471
|
else
|
1074
1472
|
[nil, nil]
|
@@ -1112,8 +1510,13 @@ EOM
|
|
1112
1510
|
if use_pp
|
1113
1511
|
begin
|
1114
1512
|
require 'pp' unless defined?(PP)
|
1513
|
+
if HashInspector.target?(object)
|
1514
|
+
pp_target = HashInspector.new(object)
|
1515
|
+
else
|
1516
|
+
pp_target = object
|
1517
|
+
end
|
1115
1518
|
begin
|
1116
|
-
return PP.pp(
|
1519
|
+
return PP.pp(pp_target, '').chomp
|
1117
1520
|
rescue NameError
|
1118
1521
|
end
|
1119
1522
|
rescue LoadError
|
@@ -1125,6 +1528,56 @@ EOM
|
|
1125
1528
|
end
|
1126
1529
|
end
|
1127
1530
|
|
1531
|
+
class HashInspector
|
1532
|
+
class << self
|
1533
|
+
def target?(object)
|
1534
|
+
object.is_a?(Hash) or object == ENV
|
1535
|
+
end
|
1536
|
+
|
1537
|
+
def normalize(object)
|
1538
|
+
if target?(object)
|
1539
|
+
new(object)
|
1540
|
+
else
|
1541
|
+
object
|
1542
|
+
end
|
1543
|
+
end
|
1544
|
+
end
|
1545
|
+
|
1546
|
+
def initialize(hash)
|
1547
|
+
@hash = hash
|
1548
|
+
end
|
1549
|
+
|
1550
|
+
def inspect
|
1551
|
+
@hash.inspect
|
1552
|
+
end
|
1553
|
+
|
1554
|
+
def pretty_print(q)
|
1555
|
+
q.group(1, '{', '}') do
|
1556
|
+
q.seplist(self, nil, :each_pair) do |k, v|
|
1557
|
+
q.group do
|
1558
|
+
q.pp(k)
|
1559
|
+
q.text('=>')
|
1560
|
+
q.group(1) do
|
1561
|
+
q.breakable('')
|
1562
|
+
q.pp(v)
|
1563
|
+
end
|
1564
|
+
end
|
1565
|
+
end
|
1566
|
+
end
|
1567
|
+
end
|
1568
|
+
|
1569
|
+
def pretty_print_cycle(q)
|
1570
|
+
q.text(@hash.empty? ? '{}' : '{...}')
|
1571
|
+
end
|
1572
|
+
|
1573
|
+
def each_pair
|
1574
|
+
@hash.keys.sort.each do |key|
|
1575
|
+
yield(self.class.normalize(key),
|
1576
|
+
self.class.normalize(@hash[key]))
|
1577
|
+
end
|
1578
|
+
end
|
1579
|
+
end
|
1580
|
+
|
1128
1581
|
class Literal
|
1129
1582
|
def initialize(value)
|
1130
1583
|
@value = value
|