fancy 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -14
- data/Rakefile +16 -4
- data/bin/fancy +3 -0
- data/bin/fspec +20 -0
- data/bin/fyi +27 -11
- data/bin/ifancy +1 -1
- data/boot/fancy_ext.rb +1 -0
- data/boot/fancy_ext/block_env.rb +1 -9
- data/boot/fancy_ext/delegator.rb +64 -0
- data/boot/fancy_ext/object.rb +4 -0
- data/boot/fancy_ext/thread.rb +4 -0
- data/boot/load.rb +5 -1
- data/boot/rbx-compiler/compiler/ast.rb +0 -1
- data/boot/rbx-compiler/compiler/ast/class_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/method_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/node.rb +10 -0
- data/boot/rbx-compiler/compiler/ast/ruby_args.rb +12 -0
- data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +2 -0
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/lexer.lex +5 -11
- data/boot/rbx-compiler/parser/parser.rb +16 -5
- data/boot/rbx-compiler/parser/parser.y +39 -24
- data/doc/api/fancy.css +1 -1
- data/doc/api/fancy.jsonp +1 -1
- data/doc/api/fdoc.js +22 -4
- data/doc/api/index.html +5 -6
- data/doc/api/jquery-ui.min.js +401 -0
- data/doc/api/jquery.tools.min.js +192 -0
- data/doc/api/themeswitchertool.js +250 -0
- data/doc/features.md +17 -0
- data/examples/actor_bunnies.fy +32 -0
- data/examples/actors.fy +26 -0
- data/examples/actors_primitive.fy +27 -0
- data/examples/actors_ring.fy +37 -0
- data/examples/armstrong_numbers.fy +1 -1
- data/examples/array.fy +7 -9
- data/examples/async_send.fy +1 -2
- data/examples/blocks.fy +4 -4
- data/examples/call_with_receiver.fy +1 -1
- data/examples/class.fy +1 -1
- data/examples/default_args.fy +4 -1
- data/examples/define_methods.fy +2 -2
- data/examples/echo.fy +1 -1
- data/examples/factorial.fy +1 -1
- data/examples/future_composition.fy +2 -2
- data/examples/futures.fy +0 -5
- data/examples/game_of_life.fy +1 -1
- data/examples/person.fy +1 -1
- data/lib/argv.fy +7 -2
- data/lib/array.fy +109 -42
- data/lib/block.fy +39 -14
- data/lib/boot.fy +2 -0
- data/lib/class.fy +2 -0
- data/lib/compiler/ast.fy +2 -1
- data/lib/compiler/ast/assign.fy +2 -3
- data/lib/compiler/ast/async_send.fy +1 -15
- data/lib/compiler/ast/class_def.fy +2 -1
- data/lib/compiler/ast/expression_list.fy +4 -5
- data/lib/compiler/ast/future_send.fy +1 -10
- data/lib/compiler/ast/goto.fy +46 -0
- data/lib/compiler/ast/identifier.fy +9 -7
- data/lib/compiler/ast/literals.fy +8 -1
- data/lib/compiler/ast/match.fy +14 -4
- data/lib/compiler/ast/message_send.fy +34 -6
- data/lib/compiler/ast/method_def.fy +6 -6
- data/lib/compiler/ast/node.fy +3 -3
- data/lib/compiler/ast/range.fy +1 -0
- data/lib/compiler/ast/script.fy +0 -2
- data/lib/compiler/ast/singleton_method_def.fy +2 -4
- data/lib/compiler/ast/string_interpolation.fy +17 -0
- data/lib/compiler/ast/super.fy +5 -4
- data/lib/compiler/ast/try_catch.fy +8 -6
- data/lib/compiler/ast/tuple_literal.fy +3 -2
- data/lib/compiler/command.fy +0 -1
- data/lib/compiler/compiler.fy +1 -5
- data/lib/compiler/stages.fy +6 -14
- data/lib/documentation.fy +57 -46
- data/lib/enumerable.fy +257 -23
- data/lib/enumerator.fy +122 -15
- data/lib/false_class.fy +10 -1
- data/lib/fancy_spec.fy +263 -61
- data/lib/fdoc.fy +11 -25
- data/lib/fiber.fy +11 -0
- data/lib/file.fy +8 -11
- data/lib/future.fy +84 -5
- data/lib/hash.fy +65 -14
- data/lib/integer.fy +35 -0
- data/lib/iteration.fy +54 -29
- data/lib/message.fy +6 -0
- data/lib/method.fy +0 -16
- data/lib/nil_class.fy +58 -8
- data/lib/number.fy +49 -22
- data/lib/object.fy +371 -65
- data/lib/package.fy +24 -1
- data/lib/package/installer.fy +5 -9
- data/lib/package/specification.fy +2 -2
- data/lib/parser/ext/lexer.lex +15 -11
- data/lib/parser/ext/parser.y +70 -23
- data/lib/parser/methods.fy +33 -14
- data/lib/proxy.fy +33 -3
- data/lib/range.fy +28 -0
- data/lib/rbx.fy +3 -1
- data/lib/rbx/actor.fy +53 -0
- data/lib/rbx/alpha.fy +31 -0
- data/lib/rbx/array.fy +21 -12
- data/lib/rbx/bignum.fy +6 -2
- data/lib/rbx/block.fy +23 -26
- data/lib/rbx/class.fy +54 -2
- data/lib/rbx/code_loader.fy +8 -4
- data/lib/rbx/date.fy +9 -0
- data/lib/rbx/directory.fy +18 -0
- data/lib/rbx/environment_variables.fy +1 -0
- data/lib/rbx/exception.fy +9 -2
- data/lib/rbx/fiber.fy +22 -4
- data/lib/rbx/file.fy +5 -5
- data/lib/rbx/fixnum.fy +5 -0
- data/lib/rbx/float.fy +11 -3
- data/lib/rbx/hash.fy +31 -16
- data/lib/rbx/integer.fy +1 -0
- data/lib/rbx/io.fy +17 -7
- data/lib/rbx/match_data.fy +15 -4
- data/lib/rbx/method.fy +40 -7
- data/lib/rbx/name_error.fy +4 -0
- data/lib/rbx/object.fy +92 -24
- data/lib/rbx/range.fy +20 -6
- data/lib/rbx/regexp.fy +11 -3
- data/lib/rbx/string.fy +51 -1
- data/lib/rbx/stringio.fy +17 -0
- data/lib/rbx/symbol.fy +15 -1
- data/lib/rbx/system.fy +20 -2
- data/lib/rbx/tcp_server.fy +4 -1
- data/lib/rbx/tcp_socket.fy +11 -0
- data/lib/rbx/time.fy +6 -0
- data/lib/rbx/tuple.fy +14 -5
- data/lib/set.fy +144 -29
- data/lib/stack.fy +42 -11
- data/lib/string.fy +118 -8
- data/lib/struct.fy +13 -3
- data/lib/symbol.fy +21 -2
- data/lib/thread_pool.fy +2 -1
- data/lib/true_class.fy +45 -7
- data/lib/tuple.fy +27 -9
- data/lib/version.fy +2 -2
- data/ruby_lib/fancy +43 -0
- data/ruby_lib/fdoc +23 -0
- data/ruby_lib/fspec +3 -0
- data/ruby_lib/fyi +3 -0
- data/ruby_lib/ifancy +3 -0
- data/tests/argv.fy +5 -9
- data/tests/array.fy +323 -196
- data/tests/assignment.fy +29 -29
- data/tests/block.fy +72 -59
- data/tests/class.fy +227 -138
- data/tests/control_flow.fy +83 -51
- data/tests/documentation.fy +8 -8
- data/tests/enumerable.fy +8 -0
- data/tests/enumerator.fy +47 -29
- data/tests/exception.fy +49 -32
- data/tests/file.fy +28 -28
- data/tests/fixnum.fy +170 -0
- data/tests/future.fy +24 -7
- data/tests/hash.fy +55 -38
- data/tests/method.fy +50 -43
- data/tests/nil_class.fy +37 -37
- data/tests/object.fy +152 -70
- data/tests/pattern_matching.fy +67 -31
- data/tests/range.fy +6 -6
- data/tests/set.fy +101 -4
- data/tests/stack.fy +14 -5
- data/tests/string.fy +115 -61
- data/tests/stringio.fy +18 -0
- data/tests/struct.fy +27 -0
- data/tests/symbol.fy +19 -6
- data/tests/true_class.fy +34 -34
- data/tests/tuple.fy +30 -12
- metadata +103 -81
- data/boot/rbx-compiler/compiler/ast/require.rb +0 -20
- data/examples/actor.fy +0 -37
- data/examples/curl_async.fy +0 -37
- data/lib/compiler/ast/require.fy +0 -15
- data/tests/number.fy +0 -135
- data/tests/parsing/sexp.fy +0 -50
data/lib/false_class.fy
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class FalseClass {
|
2
|
-
"
|
2
|
+
"""
|
3
|
+
FalseClass. The class of the singleton @false value.
|
4
|
+
"""
|
3
5
|
|
4
6
|
def FalseClass new {
|
5
7
|
# always return false singleton object when trying to create a new
|
@@ -35,6 +37,8 @@ class FalseClass {
|
|
35
37
|
"false"
|
36
38
|
}
|
37
39
|
|
40
|
+
alias_method: 'inspect for: 'to_s
|
41
|
+
|
38
42
|
def to_a {
|
39
43
|
"Returns an empty @Array@."
|
40
44
|
[]
|
@@ -50,3 +54,8 @@ class FalseClass {
|
|
50
54
|
true
|
51
55
|
}
|
52
56
|
}
|
57
|
+
|
58
|
+
false documentation: """
|
59
|
+
@false is the singleton boolean false value (only instance of @FalseClass@).
|
60
|
+
FalseClass##new yields @false.
|
61
|
+
"""
|
data/lib/fancy_spec.fy
CHANGED
@@ -4,29 +4,77 @@ class FancySpec {
|
|
4
4
|
Have a look at the tests/ directory to see some examples.
|
5
5
|
"""
|
6
6
|
|
7
|
-
|
8
7
|
def initialize: @description test_obj: @test_obj (@description) {
|
8
|
+
"""
|
9
|
+
@description Description @String@ for testcase.
|
10
|
+
@test_obj Object to be tested, defaults to @description.
|
11
|
+
"""
|
12
|
+
|
9
13
|
@spec_tests = []
|
14
|
+
@before_blocks = []
|
15
|
+
@after_blocks = []
|
10
16
|
}
|
11
17
|
|
12
18
|
def FancySpec describe: test_obj with: block {
|
19
|
+
"""
|
20
|
+
Factory method for creating FancySpec instances.
|
21
|
+
Calls @block with the new FancySpec instance as the receiver, then runs it.
|
22
|
+
|
23
|
+
FancySpec describe: MyTestClass with: {
|
24
|
+
# test cases using it:for:when: here.
|
25
|
+
}
|
26
|
+
"""
|
27
|
+
|
13
28
|
spec = FancySpec new: test_obj
|
14
29
|
block call_with_receiver: spec
|
15
30
|
spec run
|
16
31
|
}
|
17
32
|
|
18
33
|
def FancySpec describe: description for: test_obj with: block {
|
34
|
+
"""
|
35
|
+
Similar to FancySpec##describe:with: but also taking an explicit @test_obj.
|
36
|
+
|
37
|
+
FancySpec describe: \"My cool class\" for: MyCoolClass with: {
|
38
|
+
# test cases using it:for:when: here.
|
39
|
+
}
|
40
|
+
"""
|
41
|
+
|
19
42
|
spec = FancySpec new: description test_obj: test_obj
|
20
43
|
block call_with_receiver: spec
|
21
44
|
spec run
|
22
45
|
}
|
23
46
|
|
24
47
|
def it: spec_info_string when: spec_block {
|
48
|
+
"""
|
49
|
+
@spec_info_string Info @String@ related to the test case defined in @spec_block.
|
50
|
+
@spec_block @Block@ that holds the testcase's code (including assertions).
|
51
|
+
|
52
|
+
Example usage:
|
53
|
+
it: \"should be an empty Array\" when: {
|
54
|
+
arr = [1,2,3]
|
55
|
+
3 times: { arr pop }
|
56
|
+
arr empty? is == true
|
57
|
+
}
|
58
|
+
"""
|
59
|
+
|
25
60
|
test = SpecTest new: spec_info_string block: spec_block
|
26
61
|
@spec_tests << test
|
27
62
|
}
|
28
63
|
|
29
|
-
def it: spec_info_string
|
64
|
+
def it: spec_info_string with: method_name when: spec_block {
|
65
|
+
"""
|
66
|
+
@spec_info_string Info @String@ related to the test case defined in @spec_block.
|
67
|
+
@method_name Name of Method that this testcase is related to.
|
68
|
+
@spec_block @Block@ that holds the testcase's code (including assertions).
|
69
|
+
|
70
|
+
Example usage:
|
71
|
+
it: \"should be an empty Array\" with: 'empty? when: {
|
72
|
+
arr = [1,2,3]
|
73
|
+
3 times: { arr pop }
|
74
|
+
arr empty? is == true
|
75
|
+
}
|
76
|
+
"""
|
77
|
+
|
30
78
|
test = SpecTest new: spec_info_string block: spec_block
|
31
79
|
# try {
|
32
80
|
# @test_obj method: method_name . if_true: |method| {
|
@@ -38,12 +86,40 @@ class FancySpec {
|
|
38
86
|
@spec_tests << test
|
39
87
|
}
|
40
88
|
|
89
|
+
alias_method: 'it:for:when: for: 'it:with:when:
|
90
|
+
|
91
|
+
def before_each: block {
|
92
|
+
"""
|
93
|
+
@block @Block@ to be run before each test case.
|
94
|
+
"""
|
95
|
+
|
96
|
+
@before_blocks << block
|
97
|
+
}
|
98
|
+
|
99
|
+
def after_each: block {
|
100
|
+
"""
|
101
|
+
@block @Block@ to be run after each test case.
|
102
|
+
"""
|
103
|
+
|
104
|
+
@after_blocks << block
|
105
|
+
}
|
106
|
+
|
41
107
|
def run {
|
42
|
-
"
|
108
|
+
"""
|
109
|
+
Runs a FancySpec's test cases.
|
110
|
+
"""
|
111
|
+
|
112
|
+
# " " ++ @description ++ ": " print
|
43
113
|
@spec_tests each: |test| {
|
114
|
+
@before_blocks each: |b| {
|
115
|
+
b call_with_receiver: test
|
116
|
+
}
|
44
117
|
test run: @test_obj
|
118
|
+
@after_blocks each: |b| {
|
119
|
+
b call_with_receiver: test
|
120
|
+
}
|
45
121
|
}
|
46
|
-
|
122
|
+
|
47
123
|
# untested_methods = @test_obj methods select: |m| {
|
48
124
|
# m tests size == 0
|
49
125
|
# }
|
@@ -51,63 +127,129 @@ class FancySpec {
|
|
51
127
|
# ["WARNING: These methods need tests:",
|
52
128
|
# untested_methods map: 'name . select: |m| { m whitespace? not } . join: ", "] println
|
53
129
|
# }
|
54
|
-
Console newline
|
55
130
|
}
|
56
131
|
|
57
132
|
|
58
133
|
class SpecTest {
|
59
|
-
|
60
|
-
|
134
|
+
"""
|
135
|
+
FancySpec test case class.
|
136
|
+
"""
|
137
|
+
|
138
|
+
read_slot: 'info_str
|
139
|
+
|
140
|
+
@@failed_positive = <[]>
|
141
|
+
@@failed_negative = <[]>
|
142
|
+
@@failed_count = 0
|
143
|
+
@@total_tests = 0
|
144
|
+
@@total_expectations = 0
|
145
|
+
|
146
|
+
def SpecTest add_expectation {
|
147
|
+
@@total_expectations = @@total_expectations + 1
|
148
|
+
}
|
61
149
|
|
62
|
-
def SpecTest failed_test:
|
63
|
-
|
150
|
+
def SpecTest failed_test: test {
|
151
|
+
"""
|
152
|
+
@actual_and_expected Pair of actual and expected values for a failed test case.
|
153
|
+
|
154
|
+
Gets called when a SpecTest failed.
|
155
|
+
"""
|
156
|
+
|
157
|
+
@@failed_positive[@@current_test_obj]: $ @@failed_positive[@@current_test_obj] || { Set new }
|
158
|
+
@@failed_positive[@@current_test_obj] << test
|
159
|
+
@@failed_count = @@failed_count + 1
|
160
|
+
}
|
161
|
+
|
162
|
+
def SpecTest failed_negative_test: test {
|
163
|
+
"""
|
164
|
+
@value Value that should not have occured.
|
165
|
+
|
166
|
+
Gets called when a negative SpecTest (using @NegativeMatcher@) failed.
|
167
|
+
"""
|
168
|
+
|
169
|
+
@@failed_negative[@@current_test_obj]: $ @@failed_negative[@@current_test_obj] || { Set new }
|
170
|
+
@@failed_negative[@@current_test_obj] << test
|
171
|
+
@@failed_count = @@failed_count + 1
|
64
172
|
}
|
65
173
|
|
66
|
-
def SpecTest
|
67
|
-
@@
|
174
|
+
def SpecTest current {
|
175
|
+
@@current
|
176
|
+
}
|
177
|
+
|
178
|
+
def SpecTest print_failures {
|
179
|
+
@@failed_positive each: |test_obj failed_tests| {
|
180
|
+
failed_tests each: |t| {
|
181
|
+
Console newline
|
182
|
+
"> FAILED: " ++ test_obj ++ " " ++ (t info_str) print
|
183
|
+
t print_failed_positive
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
@@failed_negative each: |test_obj failed_tests| {
|
188
|
+
failed_tests each: |t| {
|
189
|
+
Console newline
|
190
|
+
"> FAILED: " ++ test_obj ++ " " ++ (t info_str) print
|
191
|
+
t print_failed_negative
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
Console newline
|
196
|
+
"Ran #{@@total_tests} tests (#{@@total_expectations} expectations) with #{@@failed_count} failures." println
|
197
|
+
if: (@@failed_count > 0) then: {
|
198
|
+
System exit: 1
|
199
|
+
} else: {
|
200
|
+
System exit: 0
|
201
|
+
}
|
68
202
|
}
|
69
203
|
|
70
204
|
def initialize: @info_str block: @block {
|
71
|
-
{ @@failed_positive = [] } unless: @@failed_positive
|
72
|
-
{ @@failed_negative = [] } unless: @@failed_negative
|
205
|
+
{ @@failed_positive = <[]> } unless: @@failed_positive
|
206
|
+
{ @@failed_negative = <[]> } unless: @@failed_negative
|
207
|
+
@failed_positive = []
|
208
|
+
@failed_negative = []
|
73
209
|
}
|
74
210
|
|
75
211
|
def run: test_obj {
|
76
|
-
@@
|
77
|
-
@@
|
212
|
+
@@current_test_obj = test_obj
|
213
|
+
@@current = self
|
214
|
+
@@total_tests = @@total_tests + 1
|
78
215
|
try {
|
79
|
-
@block
|
80
|
-
} catch
|
81
|
-
|
216
|
+
@block call_with_receiver: self
|
217
|
+
} catch Exception => e {
|
218
|
+
failed: (e, "No Exception")
|
82
219
|
}
|
83
220
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
"> FAILED: " ++ test_obj ++ " " ++ @info_str print
|
89
|
-
print_failed_positive
|
221
|
+
if: failed? then: {
|
222
|
+
"f" print
|
223
|
+
} else: {
|
224
|
+
"." print
|
90
225
|
}
|
226
|
+
}
|
91
227
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
228
|
+
def failed: actual_and_expected {
|
229
|
+
@failed_positive << (actual_and_expected, caller(5) at: 0)
|
230
|
+
SpecTest failed_test: self
|
231
|
+
}
|
232
|
+
|
233
|
+
def failed_negative: value {
|
234
|
+
{ value = [value, 'negative_failure] } unless: $ value responds_to?: 'at:
|
235
|
+
@failed_negative << (value, caller(6) at: 0)
|
236
|
+
SpecTest failed_negative_test: self
|
237
|
+
}
|
98
238
|
|
99
|
-
|
239
|
+
def failed? {
|
240
|
+
@failed_positive empty? not || { @failed_negative empty? not }
|
100
241
|
}
|
101
242
|
|
243
|
+
|
102
244
|
def print_failed_positive {
|
103
|
-
" [" ++ (
|
104
|
-
print_failed_common:
|
245
|
+
" [" ++ (@failed_positive size) ++ " unexpected values]" println
|
246
|
+
print_failed_common: @failed_positive
|
105
247
|
}
|
106
248
|
|
107
249
|
def print_failed_negative {
|
108
|
-
" [" ++ (
|
250
|
+
" [" ++ (@failed_negative size) ++ " unexpected values]" println
|
109
251
|
"Should not have gotten the following values: " println
|
110
|
-
print_failed_common:
|
252
|
+
print_failed_common: @failed_negative
|
111
253
|
}
|
112
254
|
|
113
255
|
def print_failed_common: failures {
|
@@ -117,75 +259,103 @@ class FancySpec {
|
|
117
259
|
location = location split: "/" . from: -2 to: -1 . join: "/"
|
118
260
|
|
119
261
|
location println
|
120
|
-
|
121
|
-
|
262
|
+
unless: (expected == 'negative_failure) do: {
|
263
|
+
" Expected: #{expected inspect}" println
|
264
|
+
" Received: #{actual inspect}" println
|
265
|
+
} else: {
|
266
|
+
" " ++ (actual inspect) println
|
267
|
+
}
|
122
268
|
}
|
123
269
|
}
|
124
270
|
}
|
125
271
|
|
126
272
|
class PositiveMatcher {
|
127
|
-
"""
|
128
|
-
|
129
|
-
|
273
|
+
"""
|
274
|
+
PositiveMatcher expects its actual value to be equal to an
|
275
|
+
expected value.
|
276
|
+
If the values are not equal, a SpecTest failure is generated.
|
277
|
+
"""
|
130
278
|
|
131
279
|
def initialize: @actual_value {
|
280
|
+
SpecTest add_expectation
|
132
281
|
}
|
133
282
|
|
134
283
|
def == expected_value {
|
135
284
|
unless: (@actual_value == expected_value) do: {
|
136
|
-
SpecTest
|
285
|
+
SpecTest current failed: (@actual_value, expected_value)
|
137
286
|
}
|
138
287
|
}
|
139
288
|
|
140
289
|
def != expected_value {
|
141
290
|
unless: (@actual_value != expected_value) do: {
|
142
|
-
SpecTest
|
291
|
+
SpecTest current failed_negative: (@actual_value, expected_value)
|
143
292
|
}
|
144
293
|
}
|
145
294
|
|
146
295
|
def raise: exception_class {
|
147
296
|
try {
|
148
297
|
@actual_value call
|
298
|
+
# make sure we raise an exception.
|
299
|
+
# if no exepction raised at this point, we have an error.
|
300
|
+
SpecTest current failed: (nil, exception_class)
|
149
301
|
} catch exception_class {
|
150
302
|
# ok
|
151
303
|
} catch Exception => e {
|
152
|
-
SpecTest
|
304
|
+
SpecTest current failed: (e class, exception_class)
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
def raise: exception_class with: block {
|
309
|
+
try {
|
310
|
+
@actual_value call
|
311
|
+
# same here
|
312
|
+
SpecTest current failed: (nil, exception_class)
|
313
|
+
} catch exception_class => e {
|
314
|
+
block call: [e]
|
315
|
+
# ok
|
316
|
+
} catch Exception => e {
|
317
|
+
SpecTest current failed: (e class, exception_class)
|
153
318
|
}
|
154
319
|
}
|
155
320
|
|
156
321
|
def unknown_message: msg with_params: params {
|
157
|
-
"""
|
158
|
-
|
322
|
+
"""
|
323
|
+
Forwards any other message and parameters to the object itself
|
324
|
+
and checks the return value.
|
325
|
+
"""
|
159
326
|
|
160
|
-
unless: (@actual_value
|
161
|
-
SpecTest
|
327
|
+
unless: (@actual_value receive_message: msg with_params: params) do: {
|
328
|
+
SpecTest current failed: (@actual_value, params first)
|
162
329
|
}
|
163
330
|
}
|
164
331
|
|
165
332
|
def be: block {
|
166
333
|
unless: (block call: [@actual_value]) do: {
|
167
|
-
SpecTest
|
334
|
+
SpecTest current failed: (@actual_value, nil)
|
168
335
|
}
|
169
336
|
}
|
170
337
|
}
|
171
338
|
|
172
339
|
class NegativeMatcher {
|
173
|
-
"""
|
174
|
-
|
175
|
-
|
340
|
+
"""
|
341
|
+
NegativeMatcher expects its actual value to be unequal to an
|
342
|
+
expected value.
|
343
|
+
If the values are equal, a SpecTest failure is generated.
|
344
|
+
"""
|
176
345
|
|
177
346
|
def initialize: @actual_value {
|
347
|
+
SpecTest add_expectation
|
178
348
|
}
|
179
349
|
|
180
350
|
def == expected_value {
|
181
351
|
if: (@actual_value == expected_value) then: {
|
182
|
-
SpecTest
|
352
|
+
SpecTest current failed_negative: @actual_value
|
183
353
|
}
|
184
354
|
}
|
185
355
|
|
186
356
|
def != expected_value {
|
187
357
|
if: (@actual_value != expected_value) then: {
|
188
|
-
SpecTest
|
358
|
+
SpecTest current failed: (@actual_value, expected_value)
|
189
359
|
}
|
190
360
|
}
|
191
361
|
|
@@ -193,7 +363,7 @@ class FancySpec {
|
|
193
363
|
try {
|
194
364
|
@actual_value call
|
195
365
|
} catch exception_class {
|
196
|
-
SpecTest
|
366
|
+
SpecTest current failed_negative: (exception_class, nil)
|
197
367
|
} catch Exception => e {
|
198
368
|
true
|
199
369
|
# ok
|
@@ -201,17 +371,19 @@ class FancySpec {
|
|
201
371
|
}
|
202
372
|
|
203
373
|
def unknown_message: msg with_params: params {
|
204
|
-
"""
|
205
|
-
|
374
|
+
"""
|
375
|
+
Forwards any other message and parameters to the object itself
|
376
|
+
and checks the return value.
|
377
|
+
"""
|
206
378
|
|
207
|
-
if: (@actual_value
|
208
|
-
SpecTest
|
379
|
+
if: (@actual_value receive_message: msg with_params: params) then: {
|
380
|
+
SpecTest current failed_negative: @actual_value
|
209
381
|
}
|
210
382
|
}
|
211
383
|
|
212
384
|
def be: block {
|
213
385
|
if: (block call: [@actual_value]) then: {
|
214
|
-
SpecTest
|
386
|
+
SpecTest current failed_negative: @actual_value
|
215
387
|
}
|
216
388
|
}
|
217
389
|
}
|
@@ -219,12 +391,42 @@ class FancySpec {
|
|
219
391
|
|
220
392
|
class Object {
|
221
393
|
def should {
|
222
|
-
"
|
394
|
+
"""
|
395
|
+
Returns a @PositiveMatcher@ for self.
|
396
|
+
"""
|
397
|
+
|
223
398
|
FancySpec PositiveMatcher new: self
|
224
399
|
}
|
225
400
|
|
401
|
+
alias_method: 'is for: 'should
|
402
|
+
alias_method: 'does for: 'should
|
403
|
+
|
404
|
+
def is: expected {
|
405
|
+
is == expected
|
406
|
+
}
|
407
|
+
|
408
|
+
def is_not: expected {
|
409
|
+
does_not == expected
|
410
|
+
}
|
411
|
+
|
226
412
|
def should_not {
|
227
|
-
"
|
413
|
+
"""
|
414
|
+
Returns a @NegativeMatcher@ for self.
|
415
|
+
"""
|
416
|
+
|
228
417
|
FancySpec NegativeMatcher new: self
|
229
418
|
}
|
419
|
+
|
420
|
+
alias_method: 'is_not for: 'should_not
|
421
|
+
alias_method: 'does_not for: 'should_not
|
230
422
|
}
|
423
|
+
|
424
|
+
class Block {
|
425
|
+
def raises: exception_class {
|
426
|
+
FancySpec PositiveMatcher new: self . raise: exception_class
|
427
|
+
}
|
428
|
+
|
429
|
+
def raises: exception_class with: block {
|
430
|
+
FancySpec PositiveMatcher new: self . raise: exception_class with: block
|
431
|
+
}
|
432
|
+
}
|