1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
9 require 'board/square_tag'
10 require 'board/point_converter'
14 class FakeTaggableBoard
15 include PointConverter
16 include TaggableSquares
18 square_tag :selection, :selection
21 def method_missing(m, *args)
39 class TestSquareTag < Test::Unit::TestCase
41 @board = FakeTaggableBoard.new
42 @stubbed_item = Object.new
43 class << @stubbed_item
50 assert @board.respond_to?(:selection)
51 assert @board.respond_to?(:selection=)
54 def test_empty_initial_tag
55 assert_nil @board.selection
58 def test_set_retrieve_tag
59 @board.expects(:add_item).with do |name, args|
60 name == :selection and args[:pos] == Point.new(30.0, 20.0)
61 end.returns(@stubbed_item)
62 @board.selection = Point.new(3, 2)
63 assert_equal Point.new(3, 2), @board.selection
66 def test_set_cancel_tag
67 @board.expects(:add_item).with do |name, args|
68 name == :selection and args[:pos] == Point.new(50.0, 30.0)
69 end.returns(@stubbed_item)
70 @board.expects(:remove_item).with(:selection)
72 @board.selection = Point.new(5, 3)
73 @board.selection = nil
74 assert_nil @board.selection