synchronize git
[swftools.git] / spec / spec_helper.rb
1 require 'spec'
2
3 class WrongColor < Exception
4     def initialize(pixel)
5         @pixel = pixel
6     end
7     def to_s
8         "Wrong color at #{@pixel}"
9     end
10 end
11 class AreaError < Exception
12     def initialize(area,problem)
13         @area,@problem = area,problem
14     end
15     def to_s
16         "Area at #{@area} #{@problem}"
17     end
18 end
19 class PixelError < Exception
20     def initialize(p1, relation,p2)
21         @p1,@p2,@relation = p1,p2,relation
22     end
23     def to_s
24         "Pixel #{@p1} #{@relation} #{@p2}"
25     end
26 end
27
28 class Area
29     def initialize(x1,y1,x2,y2)
30         @x1,@y1,@x2,@y2 = x1,y1,x2,y2
31     end
32     def should_be_plain_colored
33         raise AreaError.new(self,"is not plain colored")
34     end
35     def should_not_be_plain_colored
36         raise AreaError.new(self,"is plain colored")
37     end
38     def to_s
39         "(#{@x1},#{@y1},#{@x2},#{@y2})"
40     end
41 end
42 class Pixel
43     def initialize(x,y)
44         @x = x
45         @y = y
46     end
47     def should_be_of_color(color)
48         raise WrongColor.new(self)
49     end
50     def should_be_brighter_than(pixel)
51         raise PixelError.new(self,"is not brighter than",pixel)
52     end
53     def should_be_less_bright_than(pixel)
54         raise PixelError.new(self,"is brighter than",pixel)
55     end
56     def should_be_the_same_as(pixel)
57         raise PixelError.new(self,"is not the same as",pixel)
58     end
59     def to_s
60         "(#{@x},#{@y})"
61     end
62 end
63 class DocFile
64     def initialize(filename, options)
65         @filename = filename
66         @page = (options[:page] or 1)
67     end
68     def area_at(x1,y1,x2,y2)
69         return Area.new(x1,y1,x2,y2)
70     end
71     def width
72         return 300
73     end
74     def height
75         return 200
76     end
77     def pixel_at(x,y)
78         return Pixel.new(x,y)
79     end
80 end
81
82 module Spec
83     module Example
84         module ExampleMethods
85            def area_at(x1,y1,x2,y2)
86                @file.area_at(x1,y1,x2,y2)
87            end
88            def width
89                @file.width
90            end
91            def height
92                @file.height
93            end
94            def pixel_at(x,y)
95                @file.pixel_at(x,y)
96            end
97            def initialize(proxy,&impl)
98                @_proxy = proxy
99                @_implementation = impl
100                @_backtrace = caller
101                @file = DocFile.new(proxy.description, proxy.options)
102            end
103         end
104         module ExampleGroupMethods
105             alias :convert_file :example
106             def page(nr)
107                 nr
108             end
109         end
110     end
111 end
112
113