From 4c743f8d983a7dd0ec9877a027f24c12fa7b0589 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Mon, 10 Aug 2009 15:23:40 +0200 Subject: [PATCH] added spec/ directory --- spec/spec_helper.rb | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 spec/spec_helper.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..3c6b4da --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,112 @@ +require 'spec' + +class WrongColor < Exception + def initialize(pixel) + @pixel = pixel + end + def to_s + "Wrong color at #{@pixel}" + end +end +class AreaError < Exception + def initialize(area,problem) + @area,@problem = area,problem + end + def to_s + "Area at #{@area} #{@problem}" + end +end +class PixelError < Exception + def initialize(p1, relation,p2) + @p1,@p2,@relation = p1,p2,relation + end + def to_s + "Pixel #{@p1} #{@relation} #{@p2}" + end +end + +class Area + def initialize(x1,y1,x2,y2) + @x1,@y1,@x2,@y2 = x1,y1,x2,y2 + end + def should_be_plain_colored + raise AreaError.new(self,"is not plain colored") + end + def should_not_be_plain_colored + raise AreaError.new(self,"is plain colored") + end + def to_s + "(#{@x1},#{@y1},#{@x2},#{@y2})" + end +end +class Pixel + def initialize(x,y) + @x = x + @y = y + end + def should_be_of_color(color) + raise WrongColor.new(self) + end + def should_be_brighter_than(pixel) + raise PixelError.new(self,"is not brighter than",pixel) + end + def should_be_less_bright_than(pixel) + raise PixelError.new(self,"is brighter than",pixel) + end + def should_be_the_same_as(pixel) + raise PixelError.new(self,"is not the same as",pixel) + end + def to_s + "(#{@x},#{@y})" + end +end +class DocFile + def initialize(filename, options) + @filename = filename + @page = (options[:page] or 1) + end + def area_at(x1,y1,x2,y2) + return Area.new(x1,y1,x2,y2) + end + def width + return 300 + end + def height + return 200 + end + def pixel_at(x,y) + return Pixel.new(x,y) + end +end + +module Spec + module Example + module ExampleMethods + def area_at(x1,y1,x2,y2) + @file.area_at(x1,y1,x2,y2) + end + def width + @file.width + end + def height + @file.height + end + def pixel_at(x,y) + @file.pixel_at(x,y) + end + def initialize(proxy,&impl) + @_proxy = proxy + @_implementation = impl + @_backtrace = caller + @file = DocFile.new(proxy.description, proxy.options) + end + end + module ExampleGroupMethods + alias :convert_file :example + def page(nr) + nr + end + end + end +end + -- 1.7.10.4