ray 0.0.1 → 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/.gemtest +0 -0
  2. data/.yardopts +4 -0
  3. data/README.md +17 -21
  4. data/Rakefile +18 -139
  5. data/VERSION +1 -1
  6. data/ext/audio.cpp +723 -0
  7. data/ext/{color.c → color.cpp} +25 -13
  8. data/ext/drawable.cpp +91 -0
  9. data/ext/event.cpp +460 -0
  10. data/ext/extconf.rb +5 -104
  11. data/ext/font.cpp +190 -0
  12. data/ext/image.cpp +733 -0
  13. data/ext/input.cpp +74 -0
  14. data/ext/ray.cpp +168 -0
  15. data/ext/ray.hpp +356 -0
  16. data/ext/{rect.c → rect.cpp} +51 -37
  17. data/ext/shader.cpp +169 -0
  18. data/ext/shape.cpp +409 -0
  19. data/ext/sprite.cpp +306 -0
  20. data/ext/text.cpp +181 -0
  21. data/ext/vector.cpp +215 -0
  22. data/guide.md +619 -0
  23. data/lib/ray/audio.rb +0 -41
  24. data/lib/ray/color.rb +32 -10
  25. data/lib/ray/drawable.rb +16 -0
  26. data/lib/ray/dsl/event_listener.rb +25 -2
  27. data/lib/ray/dsl/event_runner.rb +33 -5
  28. data/lib/ray/dsl/event_translator.rb +66 -30
  29. data/lib/ray/dsl/handler.rb +3 -2
  30. data/lib/ray/dsl/matcher.rb +58 -14
  31. data/lib/ray/font.rb +38 -96
  32. data/lib/ray/font_set.rb +8 -8
  33. data/lib/ray/game.rb +87 -66
  34. data/lib/ray/helper.rb +105 -10
  35. data/lib/ray/image.rb +150 -24
  36. data/lib/ray/image_set.rb +3 -1
  37. data/lib/ray/input.rb +10 -0
  38. data/lib/ray/music_set.rb +5 -3
  39. data/lib/ray/ray.rb +21 -9
  40. data/lib/ray/rect.rb +48 -7
  41. data/lib/ray/rmagick.rb +41 -0
  42. data/lib/ray/scene.rb +99 -43
  43. data/lib/ray/scene_list.rb +67 -0
  44. data/lib/ray/shape.rb +132 -0
  45. data/lib/ray/sound_set.rb +4 -2
  46. data/lib/ray/sprite.rb +49 -111
  47. data/lib/ray/text.rb +101 -0
  48. data/lib/ray/text_helper.rb +37 -0
  49. data/lib/ray/turtle.rb +215 -0
  50. data/lib/ray/vector.rb +226 -0
  51. data/samples/audio/spacial.rb +44 -0
  52. data/samples/hello_world/hello.rb +9 -13
  53. data/samples/hello_world/hello_dsl.rb +8 -12
  54. data/samples/hello_world/text.rb +15 -0
  55. data/samples/opengl/binding.rb +38 -0
  56. data/samples/opengl/image.rb +32 -0
  57. data/samples/opengl/opengl.rb +34 -0
  58. data/samples/opengl/shader.rb +42 -0
  59. data/samples/pong/pong.rb +14 -10
  60. data/samples/run_scene.rb +53 -0
  61. data/samples/shaders/scene.rb +40 -0
  62. data/samples/shaders/shaders.rb +42 -0
  63. data/samples/shaders/shape.rb +34 -0
  64. data/samples/sokoban/sokoban.rb +18 -18
  65. data/samples/test/actual_scene.rb +41 -0
  66. data/samples/test/scene_riot.rb +39 -0
  67. data/samples/test/scene_spec.rb +32 -0
  68. data/samples/test/scene_test_unit.rb +25 -0
  69. data/samples/turtle/byzantium.rb +45 -0
  70. data/samples/turtle/hilbert.rb +48 -0
  71. data/samples/turtle/koch.rb +55 -0
  72. data/samples/turtle/mandala.rb +61 -0
  73. data/samples/turtle/tree.rb +57 -0
  74. data/test/audio_test.rb +69 -0
  75. data/test/color_test.rb +77 -0
  76. data/test/drawable_test.rb +19 -0
  77. data/test/dsl_test.rb +93 -0
  78. data/test/font_test.rb +57 -0
  79. data/test/helpers.rb +94 -0
  80. data/test/image_test.rb +82 -0
  81. data/test/ray_test.rb +25 -0
  82. data/test/rect_test.rb +121 -0
  83. data/{spec → test}/res/VeraMono.ttf +0 -0
  84. data/{spec → test}/res/aqua.bmp +0 -0
  85. data/{spec → test}/res/aqua.png +0 -0
  86. data/{spec → test}/res/aqua2.bmp +0 -0
  87. data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
  88. data/{spec → test}/res/pop.wav +0 -0
  89. data/test/resource_set_test.rb +99 -0
  90. data/test/run_all.rb +7 -0
  91. data/test/shape_test.rb +101 -0
  92. data/test/sprite_test.rb +89 -0
  93. data/test/text_test.rb +78 -0
  94. data/test/turtle_test.rb +176 -0
  95. data/test/vector_test.rb +111 -0
  96. data/yard_ext.rb +0 -28
  97. metadata +95 -139
  98. data/.gitignore +0 -23
  99. data/.gitmodules +0 -3
  100. data/.rspec +0 -3
  101. data/ext/audio.c +0 -473
  102. data/ext/event.c +0 -557
  103. data/ext/font.c +0 -287
  104. data/ext/image.c +0 -933
  105. data/ext/joystick.c +0 -145
  106. data/ext/ray.c +0 -489
  107. data/ext/ray.h +0 -245
  108. data/ext/ray_osx.m +0 -161
  109. data/lib/ray/joystick.rb +0 -30
  110. data/psp/SDL_psp_main.c +0 -84
  111. data/psp/bigdecimal/README +0 -60
  112. data/psp/bigdecimal/bigdecimal.c +0 -4697
  113. data/psp/bigdecimal/bigdecimal.h +0 -216
  114. data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
  115. data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
  116. data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
  117. data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
  118. data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
  119. data/psp/digest/bubblebabble/bubblebabble.c +0 -142
  120. data/psp/digest/defs.h +0 -20
  121. data/psp/digest/digest.c +0 -643
  122. data/psp/digest/digest.h +0 -32
  123. data/psp/digest/lib/digest.rb +0 -50
  124. data/psp/digest/lib/md5.rb +0 -27
  125. data/psp/digest/lib/sha1.rb +0 -27
  126. data/psp/digest/md5/md5.c +0 -420
  127. data/psp/digest/md5/md5.h +0 -80
  128. data/psp/digest/md5/md5init.c +0 -40
  129. data/psp/digest/rmd160/rmd160.c +0 -457
  130. data/psp/digest/rmd160/rmd160.h +0 -56
  131. data/psp/digest/rmd160/rmd160init.c +0 -40
  132. data/psp/digest/sha1/sha1.c +0 -269
  133. data/psp/digest/sha1/sha1.h +0 -39
  134. data/psp/digest/sha1/sha1init.c +0 -40
  135. data/psp/digest/sha2/lib/sha2.rb +0 -73
  136. data/psp/digest/sha2/sha2.c +0 -919
  137. data/psp/digest/sha2/sha2.h +0 -109
  138. data/psp/digest/sha2/sha2init.c +0 -52
  139. data/psp/enumerator/enumerator.c +0 -298
  140. data/psp/etc/etc.c +0 -559
  141. data/psp/ext.c +0 -289
  142. data/psp/fcntl/fcntl.c +0 -187
  143. data/psp/lib/rbconfig.rb +0 -178
  144. data/psp/nkf/lib/kconv.rb +0 -367
  145. data/psp/nkf/nkf-utf8/config.h +0 -88
  146. data/psp/nkf/nkf-utf8/nkf.c +0 -6040
  147. data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
  148. data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
  149. data/psp/nkf/nkf.c +0 -654
  150. data/psp/socket/addrinfo.h +0 -173
  151. data/psp/socket/getaddrinfo.c +0 -676
  152. data/psp/socket/getnameinfo.c +0 -270
  153. data/psp/socket/pspsocket.c +0 -71
  154. data/psp/socket/pspsocket.h +0 -28
  155. data/psp/socket/socket.c +0 -4662
  156. data/psp/socket/sockport.h +0 -76
  157. data/psp/stringio/stringio.c +0 -1306
  158. data/psp/strscan/strscan.c +0 -1320
  159. data/psp/syck/bytecode.c +0 -1166
  160. data/psp/syck/emitter.c +0 -1242
  161. data/psp/syck/gram.c +0 -1894
  162. data/psp/syck/gram.h +0 -79
  163. data/psp/syck/handler.c +0 -174
  164. data/psp/syck/implicit.c +0 -2990
  165. data/psp/syck/node.c +0 -408
  166. data/psp/syck/rubyext.c +0 -2367
  167. data/psp/syck/syck.c +0 -504
  168. data/psp/syck/syck.h +0 -456
  169. data/psp/syck/token.c +0 -2725
  170. data/psp/syck/yaml2byte.c +0 -257
  171. data/psp/syck/yamlbyte.h +0 -170
  172. data/psp/thread/thread.c +0 -1175
  173. data/psp/zlib/zlib.c +0 -3547
  174. data/script.rb +0 -10
  175. data/spec/ray/audio_spec.rb +0 -146
  176. data/spec/ray/color_spec.rb +0 -57
  177. data/spec/ray/event_spec.rb +0 -80
  178. data/spec/ray/font_spec.rb +0 -93
  179. data/spec/ray/image_set_spec.rb +0 -48
  180. data/spec/ray/image_spec.rb +0 -162
  181. data/spec/ray/joystick_spec.rb +0 -21
  182. data/spec/ray/matcher_spec.rb +0 -50
  183. data/spec/ray/ray_spec.rb +0 -88
  184. data/spec/ray/rect_spec.rb +0 -154
  185. data/spec/ray/resource_set_spec.rb +0 -105
  186. data/spec/ray/sprite_spec.rb +0 -163
  187. data/spec/spec.opts +0 -4
  188. data/spec/spec_helper.rb +0 -8
@@ -0,0 +1,57 @@
1
+ # Drawing code stolen from here:
2
+ # http://www.rubyquiz.com/quiz104.html
3
+
4
+ $:.unshift File.expand_path(File.dirname(__FILE__) + "/../../lib")
5
+ $:.unshift File.expand_path(File.dirname(__FILE__) + "/../../ext")
6
+
7
+ require 'ray'
8
+
9
+ class Ray::Turtle
10
+ def tree(size)
11
+ if size < 5
12
+ forward size
13
+ backward size
14
+ else
15
+ forward size / 3
16
+
17
+ left 30
18
+ tree size * 2 / 3
19
+ right 30
20
+
21
+ forward size / 6
22
+
23
+ right 25
24
+ tree size / 2
25
+ left 25
26
+
27
+ forward size / 3
28
+ right 25
29
+ tree size / 2
30
+ left 25
31
+
32
+ forward size / 6
33
+ backward size
34
+ end
35
+ end
36
+ end
37
+
38
+ Ray::Game.new("Turtle") do
39
+ register do
40
+ add_hook :quit, method(:exit!)
41
+ end
42
+
43
+ scene :tree do
44
+ render do |win|
45
+ win.fill(Ray::Color.black).turtle do
46
+ pen_up
47
+ left 90
48
+ center
49
+ backward 180
50
+ pen_down
51
+ tree(240.0)
52
+ end
53
+ end
54
+ end
55
+
56
+ push_scene :tree
57
+ end
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
2
+
3
+ context "Ray::Audio" do
4
+ setup { Ray::Audio }
5
+
6
+ asserts(:volume).equals(100)
7
+
8
+ asserts(:pos).equals(Ray::Vector3[0, 0, 0])
9
+ asserts(:direction).equals(Ray::Vector3[0, 0, -1])
10
+
11
+ context "after changing the volume" do
12
+ hookup { topic.volume = 50 }
13
+ asserts(:volume).equals(50)
14
+ end
15
+
16
+ context "after changing the position" do
17
+ hookup { topic.pos = [10, -5, 3] }
18
+ asserts(:pos).equals(Ray::Vector3[10, -5, 3])
19
+ end
20
+
21
+ context "after changing the direction" do
22
+ hookup { topic.direction = [10, -5, 3] }
23
+ asserts(:direction).equals(Ray::Vector3[10, -5, 3])
24
+ end
25
+ end
26
+
27
+ [Ray::Sound, Ray::Music].each do |klass|
28
+ context klass do
29
+ setup { klass }
30
+
31
+ denies("created from a file") {
32
+ topic.new path_of("pop.wav")
33
+ }.raises(RuntimeError)
34
+
35
+ asserts("created from a non-existing file") {
36
+ topic.new path_of("doesnt_exist.wav")
37
+ }.raises(RuntimeError)
38
+
39
+ denies("created from an IO") {
40
+ open(path_of("pop.wav")) { |io| topic.new(io) }
41
+ }.raises(RuntimeError)
42
+
43
+ asserts("created from an invalid IO") {
44
+ open(path_of("aqua.png")) { |io| topic.new(io) }
45
+ }.raises(RuntimeError)
46
+ end
47
+ end
48
+
49
+ {
50
+ "a sound" => Ray::Sound.new(path_of("pop.wav")),
51
+ "a music" => Ray::Music.new(path_of("pop.wav"))
52
+ }.each do |name, object|
53
+ context name do
54
+ setup { object }
55
+
56
+ asserts(:volume).equals(100)
57
+ asserts(:pitch).equals(1)
58
+ asserts(:pos).equals(Ray::Vector3[0, 0, 0])
59
+ denies(:relative?)
60
+ asserts(:min_distance).equals(1)
61
+ asserts(:attenuation).equals(1)
62
+ asserts(:status).equals(:stopped)
63
+
64
+ asserts(:current_time).equals(0)
65
+ denies(:loop?)
66
+ end
67
+ end
68
+
69
+ run_tests if __FILE__ == $0
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
2
+
3
+ context "a color" do
4
+ setup { Ray::Color.new(10, 10, 10, 10) }
5
+
6
+ asserts("#* RGBA(255, 0, 0, 255)") {
7
+ topic * Ray::Color.red
8
+ }.equals Ray::Color.new(10, 0, 0, 10)
9
+
10
+ asserts("#+ RGBA(20, 10, 4, 255)") {
11
+ topic + Ray::Color.new(20, 10, 4, 255)
12
+ }.equals Ray::Color.new(30, 20, 14, 255)
13
+
14
+ asserts "is equal to a color with the same components" do
15
+ topic == Ray::Color.new(10, 10, 10, 10)
16
+ end
17
+
18
+ denies "is equal to a color with different components" do
19
+ topic == Ray::Color.new(20, 10, 10, 10)
20
+ end
21
+
22
+ [:red, :green, :blue, :alpha].each do |comp|
23
+ context "after having changed #{comp} to 30" do
24
+ hookup { topic.send("#{comp}=", 30) }
25
+
26
+ asserts(comp).equals(30)
27
+
28
+ asserts "other components keep their values" do
29
+ [:red, :green, :blue, :alpha].all? do |other|
30
+ other == comp || topic.send(other) == 10
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ context "created with 3 integers" do
37
+ setup { Ray::Color.new(10, 20, 30) }
38
+
39
+ asserts "has the components given at creation" do
40
+ topic.r == 10 && topic.g == 20 && topic.b == 30
41
+ end
42
+
43
+ asserts(:a).equals(255)
44
+ end
45
+
46
+ context "created with 4 integers" do
47
+ setup { Ray::Color.new(10, 20, 30, 127) }
48
+
49
+ asserts "has the components given at creation" do
50
+ topic.r == 10 && topic.g == 20 && topic.b == 30 && topic.a == 127
51
+ end
52
+ end
53
+
54
+ context "copied from another color" do
55
+ setup do
56
+ @old_topic = topic
57
+ topic.dup
58
+ end
59
+
60
+ asserts(:r).equals(10)
61
+ asserts(:g).equals(10)
62
+ asserts(:b).equals(10)
63
+ asserts(:g).equals(10)
64
+
65
+ denies "is the same object as the original" do
66
+ topic.equal? @old_topic
67
+ end
68
+
69
+ asserts "is eql? to the original" do
70
+ topic.eql? @old_topic
71
+ end
72
+
73
+ asserts(:hash).equals { @old_topic.hash }
74
+ end
75
+ end
76
+
77
+ run_tests if __FILE__ == $0
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
2
+
3
+ context "a drawable" do
4
+ setup do
5
+ @block = Proc.new {}
6
+ Ray::Drawable.new(&@block)
7
+ end
8
+
9
+ context "after drawing" do
10
+ hookup do
11
+ stub(@block).call
12
+ (@img = Ray::Image.new(:w => 10, :h => 10)).draw_drawable topic
13
+ end
14
+
15
+ asserts("the block") { @block }.received(:call) { @img }
16
+ end
17
+ end
18
+
19
+ run_tests if __FILE__ == $0
@@ -0,0 +1,93 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
2
+
3
+ context "an event runner" do
4
+ helper(:register_for) do |name, *args|
5
+ stub(@stub).__send__(name)
6
+ @obj.on(name, *args) { |*block_args| @stub.__send__(name, *block_args) }
7
+ end
8
+
9
+ helper(:raise_event) { |name, *args| @obj.raise_event(name, *args) }
10
+
11
+ helper(:enable_group) { |name| @obj.enable_event_group(name) }
12
+ helper(:disable_group) { |name| @obj.disable_event_group(name) }
13
+
14
+ helper(:event_group) { |name| @obj.current_event_group = name }
15
+
16
+ def runner_asserts(name, method = :asserts, &block)
17
+ send(method, "after #{name}") do
18
+ [:default, :test].each { |o| @obj.remove_event_group o }
19
+ instance_eval(&block)
20
+ topic.run
21
+
22
+ @stub
23
+ end
24
+ end
25
+
26
+ def runner_denies(name, &block)
27
+ runner_asserts(name, :denies, &block)
28
+ end
29
+
30
+ setup do
31
+ runner = Ray::DSL::EventRunner.new
32
+
33
+ @stub = Object.new
34
+ class << @stub
35
+ def inspect; "stub"; end
36
+ end
37
+
38
+ @obj = Object.new
39
+ @obj.extend Ray::Helper
40
+ @obj.event_runner = runner
41
+
42
+ runner
43
+ end
44
+
45
+ runner_asserts("sending a registred event") {
46
+ register_for :event
47
+ raise_event :event
48
+ }.received(:event)
49
+
50
+ runner_denies("sending an unregistred event") {
51
+ register_for :foo
52
+ raise_event :event
53
+ }.received(:event)
54
+
55
+ runner_asserts("sending a registred event with the same arguments") {
56
+ register_for :event, "argument"
57
+ raise_event :event, "argument"
58
+ }.received(:event, "argument")
59
+
60
+ runner_asserts("sending a registred event with matching arguments") {
61
+ register_for :event, /arg/
62
+ raise_event :event, "argument"
63
+ }.received(:event, "argument")
64
+
65
+ runner_denies("sending a registred event with less arguments") {
66
+ register_for :event, "argument1", "argument2"
67
+ raise_event :event, "argument1"
68
+ }.received(:event, "argument1")
69
+
70
+ runner_asserts("sending a register event with more arguments") {
71
+ register_for :event
72
+ raise_event :event, "bar"
73
+ }.received(:event, "bar")
74
+
75
+ runner_denies("sending an event registred in a disabled event group") {
76
+ event_group :test
77
+ register_for :event
78
+ disable_group :test
79
+
80
+ raise_event :event
81
+ }.received(:event)
82
+
83
+ runner_asserts("sending an event registred in an enabled event_group") {
84
+ event_group :test
85
+ register_for :event
86
+ disable_group :test
87
+ enable_group :test
88
+
89
+ raise_event :event
90
+ }.received(:event)
91
+ end
92
+
93
+ run_tests if __FILE__ == $0
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/helpers.rb'
2
+
3
+ context Ray::Font do
4
+ setup { Ray::Font }
5
+
6
+ denies("creating a font from a file") {
7
+ topic.new(path_of("VeraMono.ttf"))
8
+ }.raises(RuntimeError)
9
+
10
+ asserts("creating a font from a non-existing file") {
11
+ topic.new(path_of("doesnt_exist.ttf"))
12
+ }.raises(RuntimeError)
13
+
14
+ denies("creating a font from an IO object") {
15
+ open(path_of("VeraMono.ttf")) { |io| topic.new(io) }
16
+ }.raises(RuntimeError)
17
+
18
+ asserts("creating a font from an invalid IO object") {
19
+ open(path_of("aqua.png")) { |io| topic.new(io) }
20
+ }.raises(RuntimeError)
21
+ end
22
+
23
+ context "a font" do
24
+ setup { Ray::Font.default }
25
+
26
+ denies("height of a text containing two lines almost equals line skip") {
27
+ diff = (topic.size_of("Hello\nWorld", :size => 12).height - topic.line_skip(12)).abs
28
+ diff <= 1
29
+ }
30
+
31
+ asserts("width of a multi-line text") {
32
+ topic.width_of("Hello\nabcdefghijkmnopqrstuvwxyz\nWorld", :size => 12)
33
+ }.equals { topic.width_of("abcdefghijkmnopqrstuvwxyz", :size => 12) }
34
+
35
+ asserts("a drawn image's size") {
36
+ img = topic.draw("Hello world", :size => 12)
37
+ img.size
38
+ }.equals { topic.size_of("Hello world", :size => 12) }
39
+
40
+ asserts("return value of drawn when :on is set") {
41
+ topic.draw("Hello world", :on => Ray.screen, :size => 12)
42
+ }.equals { Ray.screen }
43
+
44
+ asserts("using an unknown style") {
45
+ topic.draw("Hello world", :size => 12, :style => [:foo])
46
+ }.raises(ArgumentError)
47
+
48
+ denies("using a know style") {
49
+ topic.draw("Hello world", :size => 12, :style => [:bold])
50
+ }.raises(ArgumentError)
51
+
52
+ asserts("not specifying the size") {
53
+ topic.draw("Hello world", {})
54
+ }.raises(ArgumentError)
55
+ end
56
+
57
+ run_tests if __FILE__ == $0
@@ -0,0 +1,94 @@
1
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "ext"))
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
+
4
+ require 'riot'
5
+ require 'riot/rr'
6
+
7
+ require 'ray'
8
+
9
+ include Math
10
+
11
+ def path_of(res)
12
+ File.expand_path(File.join(File.dirname(__FILE__), "res", res))
13
+ end
14
+
15
+ def run_tests
16
+ Ray.create_window(:w => 100, :h => 150)
17
+ exit Riot.run.success?
18
+ end
19
+
20
+ def deg_to_rad(deg)
21
+ deg * PI / 180
22
+ end
23
+
24
+ class AlmostEqualMacro < Riot::AssertionMacro
25
+ register :almost_equals
26
+
27
+ def test(actual, expected, epsilon)
28
+ (actual - expected).abs <= epsilon
29
+ end
30
+
31
+ def evaluate(actual, expected, epsilon = Float::EPSILON)
32
+ if test(actual, expected, epsilon)
33
+ pass "is almost equal to #{expected}"
34
+ else
35
+ fail "#{actual} +/- #{epsilon} is not equal to #{expected}"
36
+ end
37
+ end
38
+
39
+ def devaluate(actual, expected, epsilon = Float::EPSILON)
40
+ if test(actual, expected, epsilon)
41
+ fail "#{actual} is almost equal to #{expected}"
42
+ else
43
+ pass "+/- #{epsilon} is almost equal to #{expected}"
44
+ end
45
+ end
46
+ end
47
+
48
+ class ReceivedMacro < Riot::AssertionMacro
49
+ register :received
50
+
51
+ include RR::Adapters::RRMethods
52
+
53
+ def evaluate(recv, msg, *args)
54
+ msg, times = case msg
55
+ when Symbol then [msg, 1]
56
+ when Hash then msg.each.first
57
+ end
58
+
59
+ begin
60
+ received(recv).__send__(msg, *args).times(times).call
61
+ pass "received ##{msg} with #{args.map { |o| o.inspect }.join(', ') } " +
62
+ "#{times} time#{'s' if times != 1}"
63
+ rescue ::RR::Errors::RRError => e
64
+ fail "#{recv.inspect} didn't receive ##{msg} with " +
65
+ "#{args.map { |o| o.inspect }.join(', ') } " +
66
+ "#{times} time#{'s' if times != 1}"
67
+ end
68
+ end
69
+
70
+ def devaluate(recv, msg, *args)
71
+ msg, times = case msg
72
+ when Symbol then [msg, 1]
73
+ when Hash then msg.each.first
74
+ end
75
+
76
+ begin
77
+ received(recv).__send__(msg, *args).times(times).call
78
+ fail "#{recv.inspect} received ##{msg} with " +
79
+ "#{args.map { |o| o.inspect }.join(', ') } " +
80
+ "#{times} time#{'s' if times != 1}"
81
+ rescue ::RR::Errors::RRError
82
+ pass "received ##{msg} with " +
83
+ "#{args.map { |o| o.inspect }.join(', ') } " +
84
+ "#{times} time#{'s' if times != 1}"
85
+ end
86
+ end
87
+ end
88
+
89
+ class Riot::Context
90
+ include RR::Adapters::RRMethods
91
+ end
92
+
93
+ Riot.reporter = Riot::DotMatrixReporter unless ARGV.include? "--verbose"
94
+ Riot.alone!