public
Description: Flexible game creation library for Ruby
Homepage: http://rubygame.org
Clone URL: git://github.com/jacius/rubygame.git
rubygame / spec / misc_events_spec.rb
100644 147 lines (98 sloc) 3.227 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Prefer local library over installed version.
$:.unshift( File.join( File.dirname(__FILE__), "..", "lib" ) )
$:.unshift( File.join( File.dirname(__FILE__), "..", "ext", "rubygame" ) )
 
require 'rubygame'
include Rubygame::Events
 
 
 
 
describe "a simple event", :shared => true do
  
  it "should take zero arguments at creation" do
    lambda { @class.new }.should_not raise_error
    lambda { @class.new(:foo) }.should raise_error
  end
 
end
 
 
 
describe InputFocusGained do
  before :each do
    @class = InputFocusGained
  end
 
  it_should_behave_like "a simple event"
end
 
describe InputFocusLost do
  before :each do
    @class = InputFocusLost
  end
 
  it_should_behave_like "a simple event"
end
 
 
 
describe MouseFocusGained do
  before :each do
    @class = MouseFocusGained
  end
 
  it_should_behave_like "a simple event"
end
 
describe MouseFocusLost do
  before :each do
    @class = MouseFocusLost
  end
 
  it_should_behave_like "a simple event"
end
 
 
 
describe WindowMinimized do
  before :each do
    @class = WindowMinimized
  end
 
  it_should_behave_like "a simple event"
end
 
describe WindowUnminimized do
  before :each do
    @class = WindowUnminimized
  end
 
  it_should_behave_like "a simple event"
end
 
 
 
describe WindowExposed do
  before :each do
    @class = WindowExposed
  end
 
  it_should_behave_like "a simple event"
end
 
 
 
describe QuitRequested do
  before :each do
    @class = QuitRequested
  end
 
  it_should_behave_like "a simple event"
end
 
 
 
 
describe WindowResized do
  
  it "should have a size" do
    WindowResized.new([20,20]).should respond_to(:size)
  end
 
  it "should accept an [x,y] Array as size" do
    lambda { WindowResized.new([20,20]) }.should_not raise_error(ArgumentError)
  end
 
  it "should reject negative sizes" do
    lambda { WindowResized.new([-20, 20]) }.should raise_error(ArgumentError)
    lambda { WindowResized.new([ 20,-20]) }.should raise_error(ArgumentError)
    lambda { WindowResized.new([-20,-20]) }.should raise_error(ArgumentError)
  end
 
  it "should reject size zero" do
    lambda { WindowResized.new([ 0, 20]) }.should raise_error(ArgumentError)
    lambda { WindowResized.new([ 20, 0]) }.should raise_error(ArgumentError)
    lambda { WindowResized.new([ 0, 0]) }.should raise_error(ArgumentError)
  end
 
  it "should reject non-Array-like objects as size" do
    lambda { WindowResized.new( 20 ) }.should raise_error(NoMethodError)
    lambda { WindowResized.new( :foo ) }.should raise_error(NoMethodError)
    lambda { WindowResized.new( "blue" ) }.should raise_error(NoMethodError)
  end
 
  it "should reject sizes with wrong number of elements" do
    lambda { WindowResized.new([ ]) }.should raise_error(ArgumentError)
    lambda { WindowResized.new([ 20 ]) }.should raise_error(ArgumentError)
    lambda { WindowResized.new([ 20,20,20 ]) }.should raise_error(ArgumentError)
  end
 
  it "size should be read-only" do
    WindowResized.new([20,20]).should_not respond_to(:size=)
  end
 
  it "size should be frozen" do
    WindowResized.new([20,20]).size.should be_frozen
  end
 
  it "should not freeze the original Array passed as size" do
    a = [20,20]
    WindowResized.new(a)
    a.should_not be_frozen
  end
 
end