yeah 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -2
- data/README.md +10 -2
- data/lib/monkey/numeric.rb +6 -0
- data/lib/yeah/basic_physics.rb +11 -0
- data/lib/yeah/color.rb +12 -9
- data/lib/yeah/desktop.rb +45 -7
- data/lib/yeah/entity.rb +118 -16
- data/lib/yeah/game.rb +33 -9
- data/lib/yeah/map.rb +35 -2
- data/lib/yeah/rectangle.rb +8 -1
- data/lib/yeah/surface.rb +20 -13
- data/lib/yeah/vector.rb +48 -41
- data/lib/yeah.rb +6 -3
- metadata +6 -20
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -60
- data/Guardfile +0 -6
- data/demo/happy_rectangle.rb +0 -44
- data/spec/color_spec.rb +0 -56
- data/spec/desktop_spec.rb +0 -123
- data/spec/entity_spec.rb +0 -70
- data/spec/game_spec.rb +0 -103
- data/spec/map_spec.rb +0 -20
- data/spec/rectangle_spec.rb +0 -71
- data/spec/spec_helper.rb +0 -13
- data/spec/surface_spec.rb +0 -141
- data/spec/vector_spec.rb +0 -197
- data/spec/yeah_spec.rb +0 -14
- data/tmp/rspec_guard_result +0 -1
- data/yeah-0.1.0.gem +0 -0
- data/yeah.gemspec +0 -18
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yeah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Ostrega
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Programming video games should have a positive impact on your health!
|
14
14
|
email: skoofoo@gmail.com
|
@@ -16,35 +16,20 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- Gemfile
|
20
|
-
- Guardfile
|
21
19
|
- lib/yeah/map.rb
|
22
20
|
- lib/yeah/game.rb
|
23
21
|
- lib/yeah/color.rb
|
24
22
|
- lib/yeah/surface.rb
|
25
23
|
- lib/yeah/vector.rb
|
24
|
+
- lib/yeah/basic_physics.rb
|
26
25
|
- lib/yeah/desktop.rb
|
27
26
|
- lib/yeah/rectangle.rb
|
28
27
|
- lib/yeah/entity.rb
|
28
|
+
- lib/monkey/numeric.rb
|
29
29
|
- lib/yeah.rb
|
30
|
+
- LICENSE.txt
|
30
31
|
- README.md
|
31
32
|
- CHANGELOG.md
|
32
|
-
- tmp/rspec_guard_result
|
33
|
-
- Gemfile.lock
|
34
|
-
- yeah.gemspec
|
35
|
-
- LICENSE.txt
|
36
|
-
- demo/happy_rectangle.rb
|
37
|
-
- yeah-0.1.0.gem
|
38
|
-
- spec/yeah_spec.rb
|
39
|
-
- spec/color_spec.rb
|
40
|
-
- spec/desktop_spec.rb
|
41
|
-
- spec/game_spec.rb
|
42
|
-
- spec/rectangle_spec.rb
|
43
|
-
- spec/surface_spec.rb
|
44
|
-
- spec/map_spec.rb
|
45
|
-
- spec/spec_helper.rb
|
46
|
-
- spec/entity_spec.rb
|
47
|
-
- spec/vector_spec.rb
|
48
33
|
homepage: https://github.com/skofo/yeah
|
49
34
|
licenses:
|
50
35
|
- MIT
|
@@ -70,3 +55,4 @@ signing_key:
|
|
70
55
|
specification_version: 4
|
71
56
|
summary: The positive video game framework
|
72
57
|
test_files: []
|
58
|
+
has_rdoc:
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
coderay (1.0.9)
|
5
|
-
diff-lcs (1.2.4)
|
6
|
-
ffi (1.9.0)
|
7
|
-
formatador (0.2.4)
|
8
|
-
guard (1.8.1)
|
9
|
-
formatador (>= 0.2.4)
|
10
|
-
listen (>= 1.0.0)
|
11
|
-
lumberjack (>= 1.0.2)
|
12
|
-
pry (>= 0.9.10)
|
13
|
-
thor (>= 0.14.6)
|
14
|
-
guard-rspec (3.0.2)
|
15
|
-
guard (>= 1.8)
|
16
|
-
rspec (~> 2.13)
|
17
|
-
libnotify (0.8.1)
|
18
|
-
ffi (>= 1.0.11)
|
19
|
-
listen (1.2.2)
|
20
|
-
rb-fsevent (>= 0.9.3)
|
21
|
-
rb-inotify (>= 0.9)
|
22
|
-
rb-kqueue (>= 0.2)
|
23
|
-
lumberjack (1.0.4)
|
24
|
-
method_source (0.8.1)
|
25
|
-
nice-ffi (0.4)
|
26
|
-
ffi (>= 0.5.0)
|
27
|
-
pry (0.9.12.2)
|
28
|
-
coderay (~> 1.0.5)
|
29
|
-
method_source (~> 0.8)
|
30
|
-
slop (~> 3.4)
|
31
|
-
rake (10.1.0)
|
32
|
-
rb-fsevent (0.9.3)
|
33
|
-
rb-inotify (0.9.0)
|
34
|
-
ffi (>= 0.5.0)
|
35
|
-
rb-kqueue (0.2.0)
|
36
|
-
ffi (>= 0.5.0)
|
37
|
-
rspec (2.14.1)
|
38
|
-
rspec-core (~> 2.14.0)
|
39
|
-
rspec-expectations (~> 2.14.0)
|
40
|
-
rspec-mocks (~> 2.14.0)
|
41
|
-
rspec-core (2.14.5)
|
42
|
-
rspec-expectations (2.14.2)
|
43
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
44
|
-
rspec-mocks (2.14.3)
|
45
|
-
ruby-sdl-ffi (0.4)
|
46
|
-
nice-ffi (>= 0.2)
|
47
|
-
rubygame (2.6.4)
|
48
|
-
rake (>= 0.7.0)
|
49
|
-
ruby-sdl-ffi (>= 0.1.0)
|
50
|
-
slop (3.4.5)
|
51
|
-
thor (0.18.1)
|
52
|
-
|
53
|
-
PLATFORMS
|
54
|
-
ruby
|
55
|
-
|
56
|
-
DEPENDENCIES
|
57
|
-
guard-rspec
|
58
|
-
libnotify
|
59
|
-
rspec
|
60
|
-
rubygame
|
data/Guardfile
DELETED
data/demo/happy_rectangle.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Happy Rectangle
|
4
|
-
# A barebones demo for Yeah.
|
5
|
-
|
6
|
-
lib = File.expand_path('../../lib/', __FILE__)
|
7
|
-
$:.unshift lib unless $:.include?(lib)
|
8
|
-
|
9
|
-
require 'yeah'
|
10
|
-
include Yeah
|
11
|
-
|
12
|
-
class HappyRectangle < Entity
|
13
|
-
def initialize(position)
|
14
|
-
super position
|
15
|
-
@visual = Rectangle.new(Vector[16, 24], Color[255, 255, 0, 255])
|
16
|
-
@updates = 0
|
17
|
-
@radius = 60
|
18
|
-
@center = (Game.new.resolution - @visual.size) / 2
|
19
|
-
end
|
20
|
-
|
21
|
-
def update
|
22
|
-
@updates += 1
|
23
|
-
@position.x = @center.x + (Math.cos(@updates) * @radius).floor
|
24
|
-
@position.y = @center.y + (Math.sin(@updates) * @radius).floor
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class HappyRectangleGame < Game
|
29
|
-
def initialize
|
30
|
-
super
|
31
|
-
@updates = 0
|
32
|
-
@entities << HappyRectangle.new(resolution/2)
|
33
|
-
end
|
34
|
-
|
35
|
-
def update
|
36
|
-
super
|
37
|
-
@updates += 1
|
38
|
-
puts "#{@updates}/60 updates."
|
39
|
-
abort if @updates == 60
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
g = HappyRectangleGame.new
|
44
|
-
g.start
|
data/spec/color_spec.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Color do
|
4
|
-
let(:klass) { described_class }
|
5
|
-
let(:instance) { klass.new }
|
6
|
-
|
7
|
-
it { klass.should be_kind_of Class }
|
8
|
-
|
9
|
-
[:new, :[]].each do |method_name|
|
10
|
-
describe "::#{method_name}" do
|
11
|
-
subject(:method) { klass.method(method_name) }
|
12
|
-
|
13
|
-
it { method.call.should be_instance_of klass }
|
14
|
-
it { method.call.rgba_bytes.should eq [0, 0, 0, 255] }
|
15
|
-
it { method.call([10, 20, 30, 40]).rgba_bytes.should eq [10, 20, 30, 40] }
|
16
|
-
it { method.call([55, 25, 55, 25]).rgba_bytes.should eq [55, 25, 55, 25] }
|
17
|
-
it { method.call(10, 20, 30, 40).rgba_bytes.should eq [10, 20, 30, 40] }
|
18
|
-
it { method.call(55, 25, 55, 25).rgba_bytes.should eq [55, 25, 55, 25] }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#==' do
|
23
|
-
subject(:method) { instance.method(:==).unbind }
|
24
|
-
|
25
|
-
it "is true for itself" do
|
26
|
-
color = klass[55, 54, 53, 52]
|
27
|
-
method.bind(color).call(color).should eq true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "is true for Color of same value" do
|
31
|
-
value = (1..4).map { Random.rand(255) }
|
32
|
-
method.bind(klass[value]).call(klass[value]).should eq true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "is false for Color of different value" do
|
36
|
-
value = (1..4).map { Random.rand(255) }
|
37
|
-
method.bind(klass[value]).call(klass[value.reverse]).should eq false
|
38
|
-
end
|
39
|
-
|
40
|
-
it "is false for nil" do
|
41
|
-
method.bind(klass[]).call(nil).should eq false
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#rgba_bytes' do
|
46
|
-
subject(:rgba_bytes) { instance.rgba_bytes }
|
47
|
-
|
48
|
-
it { should eq [0, 0, 0, 255] }
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#rgba_bytes=' do
|
52
|
-
subject(:method) { instance.method(:rgba_bytes=) }
|
53
|
-
|
54
|
-
it_behaves_like 'writer', (1..4).map { Random.rand(255) }
|
55
|
-
end
|
56
|
-
end
|
data/spec/desktop_spec.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Desktop do
|
4
|
-
let(:klass) { described_class }
|
5
|
-
let(:instance) { klass.new }
|
6
|
-
|
7
|
-
it { klass.should be_instance_of Class }
|
8
|
-
|
9
|
-
describe '::new' do
|
10
|
-
subject(:method) { klass.method(:new) }
|
11
|
-
|
12
|
-
it { method.call.resolution.should eq Vector[320, 240] }
|
13
|
-
|
14
|
-
it "accepts Vector as resolution" do
|
15
|
-
vector = Vector[Random.rand(250), Random.rand(250)]
|
16
|
-
desktop = method.call(vector)
|
17
|
-
desktop.resolution.should eq vector
|
18
|
-
desktop.screen.size.should eq vector[0..1]
|
19
|
-
end
|
20
|
-
|
21
|
-
it { method.call.instance_variables.should include :@clock }
|
22
|
-
it do
|
23
|
-
clock = method.call.instance_variable_get(:@clock)
|
24
|
-
clock.should be_instance_of Rubygame::Clock
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#screen' do
|
29
|
-
subject { instance.screen }
|
30
|
-
|
31
|
-
it { should be_instance_of Rubygame::Screen }
|
32
|
-
its(:size) { should eq [320, 240] }
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#resolution' do
|
36
|
-
subject { instance.resolution }
|
37
|
-
|
38
|
-
it { should eq Vector[320, 240] }
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#resolution=' do
|
42
|
-
subject(:method) { instance.method(:resolution=) }
|
43
|
-
|
44
|
-
it_behaves_like 'writer', Vector[Random.rand(250), Random.rand(250)]
|
45
|
-
|
46
|
-
it "changes screen size" do
|
47
|
-
resolution = Vector[Random.rand(250)+1, Random.rand(250)+1]
|
48
|
-
method.call(resolution)
|
49
|
-
instance.screen.size.should eq resolution.components[0..1]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#render' do
|
54
|
-
subject(:method) { instance.method(:render) }
|
55
|
-
|
56
|
-
it { expect { method.call }.to raise_error ArgumentError }
|
57
|
-
|
58
|
-
it "renders a Surface" do
|
59
|
-
surface = Surface.new(instance.resolution)
|
60
|
-
surface.fill(Color[255, 255, 0, 255], Vector[0, 0], Vector[1, 1])
|
61
|
-
|
62
|
-
screen_update_count = 0
|
63
|
-
allow(instance.screen).to receive(:update) { screen_update_count += 1 }
|
64
|
-
|
65
|
-
method.call(surface)
|
66
|
-
instance.screen.get_at([0, 0]).should eq [255, 255, 0, 255]
|
67
|
-
screen_update_count.should eq 1
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#each_tick' do
|
72
|
-
subject(:method) { instance.method(:each_tick) }
|
73
|
-
|
74
|
-
it { expect { method.call }.to raise_error LocalJumpError }
|
75
|
-
|
76
|
-
it "repeatedly calls passed block" do
|
77
|
-
call_count = 0
|
78
|
-
|
79
|
-
method.call do
|
80
|
-
call_count += 1
|
81
|
-
break if call_count == 5
|
82
|
-
end
|
83
|
-
|
84
|
-
call_count.should eq 5
|
85
|
-
end
|
86
|
-
|
87
|
-
it "calls Rubygame::Clock#tick per call" do
|
88
|
-
call_count = 0
|
89
|
-
tick_call_count = 0
|
90
|
-
allow(instance.instance_variable_get(:@clock)).to receive(:tick) do
|
91
|
-
tick_call_count += 1
|
92
|
-
end
|
93
|
-
|
94
|
-
method.call do
|
95
|
-
break if tick_call_count == 5
|
96
|
-
call_count += 1
|
97
|
-
end
|
98
|
-
|
99
|
-
call_count.should eq 5
|
100
|
-
tick_call_count.should eq 5
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe '#tickrate' do
|
105
|
-
subject { instance.tickrate }
|
106
|
-
|
107
|
-
its(:round) { should eq 30 }
|
108
|
-
end
|
109
|
-
|
110
|
-
describe '#tickrate=' do
|
111
|
-
subject(:method) { instance.method(:tickrate=) }
|
112
|
-
|
113
|
-
it_behaves_like 'writer', 60
|
114
|
-
|
115
|
-
it "sets @clock#target_framerate" do
|
116
|
-
tickrate = Random.rand(30) + 30
|
117
|
-
clock = instance.instance_variable_get(:@clock)
|
118
|
-
method.call(tickrate)
|
119
|
-
|
120
|
-
clock.target_framerate.round.should eq tickrate
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
data/spec/entity_spec.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Entity do
|
4
|
-
let(:klass) { described_class }
|
5
|
-
let(:instance) { klass.new }
|
6
|
-
|
7
|
-
it { klass.should be_instance_of Class }
|
8
|
-
|
9
|
-
describe '::new' do
|
10
|
-
subject(:method) { klass.method(:new) }
|
11
|
-
|
12
|
-
it { method.call.should be_instance_of klass }
|
13
|
-
it { method.call.position.should eq Vector[0, 0, 0] }
|
14
|
-
it { method.call(Vector[2, 4, 8]).position.should eq Vector[2, 4, 8] }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#position' do
|
18
|
-
subject(:position) { instance.position }
|
19
|
-
|
20
|
-
it { should be_instance_of Vector }
|
21
|
-
it { position.components.should eq [0, 0, 0] }
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#position=' do
|
25
|
-
subject(:method) { instance.method(:position=) }
|
26
|
-
|
27
|
-
it_behaves_like 'writer', Vector[Random.rand(100)]
|
28
|
-
end
|
29
|
-
|
30
|
-
[:x, :y, :z].each do |method_name|
|
31
|
-
describe "##{method_name}" do
|
32
|
-
it "is #position.#{method_name}" do
|
33
|
-
instance.position.send("#{method_name}=", Random.rand(100))
|
34
|
-
instance.send(method_name).should eq instance.position.send(method_name)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "##{method_name}=" do
|
39
|
-
it "assigns #position.#{method_name}" do
|
40
|
-
value = Random.rand(100)
|
41
|
-
instance.send("#{method_name}=", value)
|
42
|
-
instance.position.send(method_name).should eq value
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '#visual' do
|
48
|
-
subject { instance.visual }
|
49
|
-
|
50
|
-
it { should eq nil }
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#visual=' do
|
54
|
-
subject { instance.method(:visual=) }
|
55
|
-
|
56
|
-
it_behaves_like 'writer', Rectangle.new(Vector[50, 50])
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#draw' do
|
60
|
-
subject(:method) { instance.method(:draw) }
|
61
|
-
|
62
|
-
its(:call) { should eq nil }
|
63
|
-
|
64
|
-
it "calls #draw method of #visual if it exists" do
|
65
|
-
instance.visual = Rectangle.new
|
66
|
-
instance.visual.should receive(:draw)
|
67
|
-
method.call
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/spec/game_spec.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Game do
|
4
|
-
let(:klass) { described_class }
|
5
|
-
let(:instance) { klass.new }
|
6
|
-
|
7
|
-
it { klass.should be_instance_of Class }
|
8
|
-
|
9
|
-
describe '#platform' do
|
10
|
-
subject { instance.platform }
|
11
|
-
|
12
|
-
it { should be_instance_of Desktop }
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#resolution' do
|
16
|
-
subject { instance.resolution }
|
17
|
-
|
18
|
-
it { should eq Vector[320, 240] }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#resolution=' do
|
22
|
-
subject { instance.method(:resolution=) }
|
23
|
-
|
24
|
-
it_behaves_like 'writer', Vector[512, 384]
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#entities' do
|
28
|
-
subject(:entities) { instance.entities }
|
29
|
-
|
30
|
-
it { should eq [] }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#entities=' do
|
34
|
-
subject(:method) { instance.method(:entities=) }
|
35
|
-
|
36
|
-
it_behaves_like 'writer', [Entity.new(Random.rand(10))]
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#update' do
|
40
|
-
subject(:method) { instance.method(:update) }
|
41
|
-
|
42
|
-
it "calls #update of each element in #entities" do
|
43
|
-
instance.entities = (1..3).map { Entity.new }
|
44
|
-
instance.entities.each { |e| e.should receive(:update) }
|
45
|
-
method.call
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#draw' do
|
50
|
-
subject(:method) { instance.method(:draw) }
|
51
|
-
|
52
|
-
it "clears #screen" do
|
53
|
-
instance.screen.should receive(:fill).with(Color[0, 0, 0, 0])
|
54
|
-
method.call
|
55
|
-
end
|
56
|
-
|
57
|
-
it "calls #draw of each element in #entities" do
|
58
|
-
instance.entities = (1..3).map { Entity.new }
|
59
|
-
instance.entities.each { |e| e.should receive(:draw) }
|
60
|
-
method.call
|
61
|
-
end
|
62
|
-
|
63
|
-
it "draws entities on #screen" do
|
64
|
-
color = Color[0, 255, 0, 255]
|
65
|
-
entity = Entity.new
|
66
|
-
entity.visual = Rectangle.new(Vector[1, 1], color)
|
67
|
-
entity.position = Vector[Random.rand(10), Random.rand(10)]
|
68
|
-
instance.entities << entity
|
69
|
-
method.call
|
70
|
-
|
71
|
-
instance.screen.color_at(entity.position).should eq color
|
72
|
-
end
|
73
|
-
|
74
|
-
it "writes to #platform#screen#struct#pixels" do
|
75
|
-
pixels = instance.platform.screen.send(:struct).pixels
|
76
|
-
pixel_data = pixels.read_string(instance.screen.data.length)
|
77
|
-
pixel_data.should eq instance.screen.data
|
78
|
-
end
|
79
|
-
|
80
|
-
it "calls #platform#screen#update" do
|
81
|
-
instance.platform.screen.should receive(:update)
|
82
|
-
method.call
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#screen' do
|
87
|
-
subject(:screen) { instance.screen }
|
88
|
-
|
89
|
-
it { should be_instance_of Surface }
|
90
|
-
its(:size) { should eq instance.resolution }
|
91
|
-
end
|
92
|
-
|
93
|
-
describe '#start' do
|
94
|
-
subject(:method) { instance.method(:start) }
|
95
|
-
|
96
|
-
it "calls #platform#each_tick with a block with #update and #draw calls" do
|
97
|
-
instance.platform.instance_eval "def each_tick; yield; end"
|
98
|
-
instance.should receive(:update)
|
99
|
-
instance.should receive(:draw)
|
100
|
-
method.call
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
data/spec/map_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Map do
|
4
|
-
let(:klass) { described_class }
|
5
|
-
let(:instance) { klass.new }
|
6
|
-
|
7
|
-
it { klass.should be_instance_of Class }
|
8
|
-
|
9
|
-
describe '#background' do
|
10
|
-
subject(:background) { instance.background }
|
11
|
-
|
12
|
-
it { should eq Color[] }
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#background=' do
|
16
|
-
subject(:method) { instance.method(:background=) }
|
17
|
-
|
18
|
-
it_behaves_like 'writer', Color[*[Random.rand(255)]*4]
|
19
|
-
end
|
20
|
-
end
|
data/spec/rectangle_spec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Rectangle do
|
4
|
-
let(:klass) { described_class }
|
5
|
-
let(:instance) { klass.new }
|
6
|
-
|
7
|
-
it { klass.should be_kind_of Class }
|
8
|
-
|
9
|
-
describe '::new' do
|
10
|
-
subject(:method) { klass.method(:new) }
|
11
|
-
|
12
|
-
it { method.call.should be_instance_of klass }
|
13
|
-
it { method.call.size.should eq Vector[] }
|
14
|
-
it { method.call.color.should eq Color[255, 255, 255, 255] }
|
15
|
-
|
16
|
-
it "assigns Vector first argument as #size" do
|
17
|
-
vector = Vector[Random.rand(40)]
|
18
|
-
method.call(vector).size.should eq vector
|
19
|
-
end
|
20
|
-
|
21
|
-
it "assigns second argument Color as #color" do
|
22
|
-
byte_array = (1..4).map { Random.rand(255) }
|
23
|
-
color = Color[*byte_array]
|
24
|
-
method.call(Vector[], color).color.should eq color
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#size' do
|
29
|
-
subject(:size) { instance.size }
|
30
|
-
|
31
|
-
it { should eq Vector[] }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#size=' do
|
35
|
-
subject(:method) { instance.method(:size=) }
|
36
|
-
|
37
|
-
it_behaves_like 'writer', Vector[Random.rand(40)]
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#color' do
|
41
|
-
subject(:color) { instance.color }
|
42
|
-
|
43
|
-
it { should eq Color[255, 255, 255, 255] }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#color=' do
|
47
|
-
subject(:method) { instance.method(:color=) }
|
48
|
-
|
49
|
-
it_behaves_like 'writer', Color[*[Random.rand(255)]*4]
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#draw' do
|
53
|
-
subject(:method) { instance.method(:draw) }
|
54
|
-
|
55
|
-
its(:call) { should be_instance_of Surface }
|
56
|
-
|
57
|
-
it "matches size" do
|
58
|
-
instance.size = Vector[Random.rand(49)+1, 50]
|
59
|
-
method.call.size.should eq instance.size
|
60
|
-
end
|
61
|
-
|
62
|
-
it "matches color" do
|
63
|
-
instance.size = Vector[10, 10]
|
64
|
-
instance.color = Color[*[Random.rand(255)]*4]
|
65
|
-
surface = method.call
|
66
|
-
surface.color_at(Vector[]).should eq instance.color
|
67
|
-
surface.color_at(instance.size/2).should eq instance.color
|
68
|
-
surface.color_at(instance.size-Vector[1, 1]).should eq instance.color
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'yeah'
|
2
|
-
include Yeah
|
3
|
-
|
4
|
-
shared_examples 'writer' do |value|
|
5
|
-
it "assigns its reader" do
|
6
|
-
writer = subject
|
7
|
-
reader_name = writer.name[0..-2].to_sym
|
8
|
-
reader = writer.receiver.method(reader_name)
|
9
|
-
|
10
|
-
writer.call(value)
|
11
|
-
reader.call.should eq value
|
12
|
-
end
|
13
|
-
end
|