metro-ld26 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +14 -0
- data/Guardfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +177 -0
- data/Rakefile +18 -0
- data/bin/metro +16 -0
- data/changelog.md +153 -0
- data/lib/assets/menu-movement.wav +0 -0
- data/lib/assets/menu-selection.wav +0 -0
- data/lib/assets/missing.ogg +0 -0
- data/lib/assets/missing.png +0 -0
- data/lib/assets/missing.wav +0 -0
- data/lib/assets/missing_animation.png +0 -0
- data/lib/commands/generate_game.rb +13 -0
- data/lib/commands/generate_model.rb +25 -0
- data/lib/commands/generate_scene.rb +36 -0
- data/lib/commands/generate_view.rb +21 -0
- data/lib/commands/thor.rb +83 -0
- data/lib/core_ext/class.rb +14 -0
- data/lib/core_ext/numeric.rb +59 -0
- data/lib/gosu_ext/color.rb +62 -0
- data/lib/gosu_ext/gosu_constants.rb +53 -0
- data/lib/locale/en.yml +35 -0
- data/lib/locale/locale.rb +1 -0
- data/lib/metro.rb +144 -0
- data/lib/metro/animation.rb +135 -0
- data/lib/metro/animation/after_interval_factory.rb +12 -0
- data/lib/metro/animation/animation_factory.rb +15 -0
- data/lib/metro/animation/easing/ease_in.rb +15 -0
- data/lib/metro/animation/easing/easing.rb +51 -0
- data/lib/metro/animation/easing/linear.rb +15 -0
- data/lib/metro/animation/has_animations.rb +70 -0
- data/lib/metro/animation/implicit_animation.rb +100 -0
- data/lib/metro/animation/on_update_operation.rb +96 -0
- data/lib/metro/animation/scene_animation.rb +16 -0
- data/lib/metro/asset_path.rb +97 -0
- data/lib/metro/events/control_definition.rb +11 -0
- data/lib/metro/events/controls.rb +42 -0
- data/lib/metro/events/event_data.rb +60 -0
- data/lib/metro/events/event_dictionary.rb +52 -0
- data/lib/metro/events/event_factory.rb +17 -0
- data/lib/metro/events/event_relay.rb +342 -0
- data/lib/metro/events/event_state_manager.rb +70 -0
- data/lib/metro/events/events.rb +3 -0
- data/lib/metro/events/has_events.rb +108 -0
- data/lib/metro/events/hit_list.rb +75 -0
- data/lib/metro/events/unknown_sender.rb +5 -0
- data/lib/metro/font.rb +69 -0
- data/lib/metro/game.rb +102 -0
- data/lib/metro/game/dsl.rb +68 -0
- data/lib/metro/image.rb +75 -0
- data/lib/metro/logging.rb +33 -0
- data/lib/metro/missing_scene.rb +21 -0
- data/lib/metro/models/audio/song.rb +33 -0
- data/lib/metro/models/draws.rb +86 -0
- data/lib/metro/models/key_value_coding.rb +38 -0
- data/lib/metro/models/model.rb +246 -0
- data/lib/metro/models/model_factory.rb +32 -0
- data/lib/metro/models/models.rb +62 -0
- data/lib/metro/models/properties/animation_property.rb +115 -0
- data/lib/metro/models/properties/array_property.rb +24 -0
- data/lib/metro/models/properties/boolean_property.rb +27 -0
- data/lib/metro/models/properties/color_property.rb +116 -0
- data/lib/metro/models/properties/dimensions_property.rb +84 -0
- data/lib/metro/models/properties/font_property.rb +130 -0
- data/lib/metro/models/properties/image_property.rb +96 -0
- data/lib/metro/models/properties/model_property.rb +84 -0
- data/lib/metro/models/properties/numeric_property.rb +29 -0
- data/lib/metro/models/properties/options_property/no_option.rb +29 -0
- data/lib/metro/models/properties/options_property/options.rb +98 -0
- data/lib/metro/models/properties/options_property/options_property.rb +125 -0
- data/lib/metro/models/properties/position_property.rb +90 -0
- data/lib/metro/models/properties/property.rb +221 -0
- data/lib/metro/models/properties/property_owner.rb +137 -0
- data/lib/metro/models/properties/sample_property.rb +84 -0
- data/lib/metro/models/properties/scale_property.rb +80 -0
- data/lib/metro/models/properties/song_property.rb +89 -0
- data/lib/metro/models/properties/text_property.rb +75 -0
- data/lib/metro/models/ui/animated_sprite.rb +85 -0
- data/lib/metro/models/ui/border.rb +95 -0
- data/lib/metro/models/ui/fps.rb +54 -0
- data/lib/metro/models/ui/generic.rb +66 -0
- data/lib/metro/models/ui/grid_drawer.rb +74 -0
- data/lib/metro/models/ui/image.rb +87 -0
- data/lib/metro/models/ui/label.rb +175 -0
- data/lib/metro/models/ui/menu.rb +214 -0
- data/lib/metro/models/ui/model_label.rb +65 -0
- data/lib/metro/models/ui/model_labeler.rb +79 -0
- data/lib/metro/models/ui/rectangle.rb +59 -0
- data/lib/metro/models/ui/sprite.rb +79 -0
- data/lib/metro/models/ui/tile_map.rb +132 -0
- data/lib/metro/models/ui/tmx/isometric_position.rb +43 -0
- data/lib/metro/models/ui/tmx/orthogonal_position.rb +15 -0
- data/lib/metro/models/ui/tmx/tile_layer.rb +78 -0
- data/lib/metro/models/ui/ui.rb +13 -0
- data/lib/metro/parameters/command_line_args_parser.rb +68 -0
- data/lib/metro/parameters/options.rb +25 -0
- data/lib/metro/parameters/parameters.rb +2 -0
- data/lib/metro/sample.rb +40 -0
- data/lib/metro/scene.rb +478 -0
- data/lib/metro/scenes.rb +154 -0
- data/lib/metro/song.rb +56 -0
- data/lib/metro/template_message.rb +60 -0
- data/lib/metro/transitions/edit_transition_scene.rb +100 -0
- data/lib/metro/transitions/fade_transition_scene.rb +66 -0
- data/lib/metro/transitions/scene_transitions.rb +44 -0
- data/lib/metro/transitions/transition_scene.rb +19 -0
- data/lib/metro/units/bounds.rb +8 -0
- data/lib/metro/units/calculation_validations.rb +74 -0
- data/lib/metro/units/dimensions.rb +60 -0
- data/lib/metro/units/point.rb +51 -0
- data/lib/metro/units/rectangle_bounds.rb +148 -0
- data/lib/metro/units/scale.rb +46 -0
- data/lib/metro/units/units.rb +6 -0
- data/lib/metro/version.rb +32 -0
- data/lib/metro/views/json_view.rb +60 -0
- data/lib/metro/views/no_view.rb +34 -0
- data/lib/metro/views/parsers.rb +42 -0
- data/lib/metro/views/scene_view.rb +107 -0
- data/lib/metro/views/view.rb +133 -0
- data/lib/metro/views/writers.rb +43 -0
- data/lib/metro/views/yaml_view.rb +94 -0
- data/lib/metro/window.rb +95 -0
- data/lib/setup_handlers/exit_if_dry_run.rb +26 -0
- data/lib/setup_handlers/game_execution.rb +65 -0
- data/lib/setup_handlers/load_game_configuration.rb +65 -0
- data/lib/setup_handlers/load_game_files.rb +101 -0
- data/lib/setup_handlers/move_to_game_directory.rb +25 -0
- data/lib/setup_handlers/reload_game_on_game_file_changes.rb +79 -0
- data/lib/templates/game/README.md.tt +43 -0
- data/lib/templates/game/assets/brand.jpg +0 -0
- data/lib/templates/game/assets/hero.png +0 -0
- data/lib/templates/game/lib/custom_easing.rb +32 -0
- data/lib/templates/game/metro.tt +63 -0
- data/lib/templates/game/models/hero.rb +62 -0
- data/lib/templates/game/scenes/brand_scene.rb +19 -0
- data/lib/templates/game/scenes/brand_to_title_scene.rb +13 -0
- data/lib/templates/game/scenes/first_scene.rb +28 -0
- data/lib/templates/game/scenes/game_scene.rb +43 -0
- data/lib/templates/game/scenes/title_scene.rb +15 -0
- data/lib/templates/game/views/brand.yaml +4 -0
- data/lib/templates/game/views/brand_to_title.yaml +8 -0
- data/lib/templates/game/views/first.yaml +26 -0
- data/lib/templates/game/views/title.yaml +11 -0
- data/lib/templates/message.erb +23 -0
- data/lib/templates/model.rb.tt +111 -0
- data/lib/templates/scene.rb.tt +140 -0
- data/lib/templates/view.yaml.tt +11 -0
- data/lib/tmx_ext/object.rb +26 -0
- data/lib/tmx_ext/tile_set.rb +41 -0
- data/metro.gemspec +57 -0
- data/metro.png +0 -0
- data/spec/core_ext/numeric_spec.rb +78 -0
- data/spec/core_ext/string_spec.rb +33 -0
- data/spec/gosu_ext/color_spec.rb +80 -0
- data/spec/metro/image_spec.rb +33 -0
- data/spec/metro/models/key_value_coding_spec.rb +61 -0
- data/spec/metro/models/properties/array_property_spec.rb +60 -0
- data/spec/metro/models/properties/color_property_spec.rb +85 -0
- data/spec/metro/models/properties/dimensions_spec.rb +29 -0
- data/spec/metro/models/properties/font_property_spec.rb +127 -0
- data/spec/metro/models/properties/numeric_property_spec.rb +46 -0
- data/spec/metro/models/properties/options_property/no_option_spec.rb +25 -0
- data/spec/metro/models/properties/options_property/options_property_spec.rb +133 -0
- data/spec/metro/models/properties/options_property/options_spec.rb +125 -0
- data/spec/metro/models/properties/position_property_spec.rb +90 -0
- data/spec/metro/models/ui/label_spec.rb +259 -0
- data/spec/metro/parameters/command_line_args_parser_spec.rb +42 -0
- data/spec/metro/scene_spec.rb +15 -0
- data/spec/metro/scene_views/json_view_spec.rb +27 -0
- data/spec/metro/scene_views/yaml_view_spec.rb +38 -0
- data/spec/metro/scenes_spec.rb +77 -0
- data/spec/metro/units/point_spec.rb +132 -0
- data/spec/metro/units/rectangle_bounds_spec.rb +56 -0
- data/spec/metro/views/view_spec.rb +53 -0
- data/spec/setup_handlers/exit_if_dry_run_spec.rb +27 -0
- data/spec/setup_handlers/reload_game_on_game_file_changes_spec.rb +68 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/tmx_ext/object_spec.rb +96 -0
- data/spec/tmx_ext/tile_set_spec.rb +24 -0
- metadata +379 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Parameters::CommandLineArgsParser do
|
4
|
+
|
5
|
+
describe "Class Methods" do
|
6
|
+
|
7
|
+
subject { described_class }
|
8
|
+
|
9
|
+
describe "#parse" do
|
10
|
+
context "when given no parameters" do
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when given an array of parameters" do
|
15
|
+
|
16
|
+
subject { described_class.parse parameters }
|
17
|
+
let(:parameters) { [ '--upset-the-world', expected_filename, '--check-dependencies', 'unread_command' ] }
|
18
|
+
let(:expected_filename) { 'metro' }
|
19
|
+
|
20
|
+
it "should maintain an original parameter list" do
|
21
|
+
subject.execution_parameters.should eq parameters
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should consider the first non-flag the game file" do
|
25
|
+
subject.filename.should eq expected_filename
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should find all the flags" do
|
29
|
+
subject.upset_the_world?.should be_true
|
30
|
+
subject.check_dependencies?.should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return false when non-existant flags are present" do
|
34
|
+
subject.wants_food_mild?.should be_false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Scene do
|
4
|
+
|
5
|
+
class SpecScene < Metro::Scene ; end
|
6
|
+
|
7
|
+
subject { SpecScene.new }
|
8
|
+
|
9
|
+
let(:expected_view_name) { "spec" }
|
10
|
+
its(:view_name) { should eq expected_view_name }
|
11
|
+
|
12
|
+
let(:expected_scene_name) { "spec" }
|
13
|
+
its(:scene_name) { should eq expected_scene_name }
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Views::JSONView do
|
4
|
+
|
5
|
+
subject { described_class }
|
6
|
+
let(:view_name) { "example" }
|
7
|
+
|
8
|
+
before do
|
9
|
+
File.stub(:exists?).and_return(false)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".exists?" do
|
13
|
+
context "when a view file exists with the extension JSON" do
|
14
|
+
before do
|
15
|
+
File.stub(:exists?).with(filepath_that_exists).and_return(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:filepath_that_exists) { "#{view_name}.json" }
|
19
|
+
|
20
|
+
it "should return true" do
|
21
|
+
subject.exists?(view_name).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Views::YAMLView do
|
4
|
+
|
5
|
+
subject { described_class }
|
6
|
+
let(:view_name) { "example" }
|
7
|
+
|
8
|
+
before do
|
9
|
+
File.stub(:exists?).and_return(false)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".exists?" do
|
13
|
+
context "when a view file exists with the extension YAML" do
|
14
|
+
before do
|
15
|
+
File.stub(:exists?).with(filepath_that_exists).and_return(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:filepath_that_exists) { "#{view_name}.yaml" }
|
19
|
+
|
20
|
+
it "should return true" do
|
21
|
+
subject.exists?(view_name).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
context "when a view file exists with the extension YML" do
|
26
|
+
before :each do
|
27
|
+
File.stub(:exists?).with(filepath_that_exists).and_return(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:filepath_that_exists) { "#{view_name}.yml" }
|
31
|
+
|
32
|
+
it "should return true" do
|
33
|
+
subject.exists?(view_name).should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Scenes do
|
4
|
+
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
class SpecScene < Metro::Scene ; end
|
8
|
+
let(:existing_scene_name) { :spec }
|
9
|
+
|
10
|
+
describe ".find" do
|
11
|
+
context "when a scene does exist" do
|
12
|
+
|
13
|
+
let(:expected_value) { SpecScene }
|
14
|
+
|
15
|
+
it "should return the scene" do
|
16
|
+
subject.find(existing_scene_name).should eq expected_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when a scene does not exist" do
|
21
|
+
let(:unknown_scene_name) { :unknown }
|
22
|
+
|
23
|
+
it "should return a missing scene" do
|
24
|
+
missing_scene = subject.find(unknown_scene_name)
|
25
|
+
missing_scene.missing_scene.should eq unknown_scene_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".generate" do
|
31
|
+
let(:existing_scene_name) { :spec }
|
32
|
+
|
33
|
+
context "when the provided scene name does exist" do
|
34
|
+
|
35
|
+
let(:expected_scene_class) { SpecScene }
|
36
|
+
|
37
|
+
it "should return an instance of the scene" do
|
38
|
+
subject.generate(existing_scene_name).should be_kind_of expected_scene_class
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when the provided scene object does exist" do
|
43
|
+
|
44
|
+
let(:scene_instance) { SpecScene.new }
|
45
|
+
|
46
|
+
it "should return the same instance of scene" do
|
47
|
+
subject.generate(scene_instance).should eq scene_instance
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should process the scene through the post filters" do
|
52
|
+
subject.should_receive(:apply_post_filters)
|
53
|
+
subject.generate(existing_scene_name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".register_post_filter" do
|
58
|
+
|
59
|
+
class SpecScenesPostFilter
|
60
|
+
def self.filter(scene,options)
|
61
|
+
scene
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when a post filter is added" do
|
66
|
+
let(:post_filter) { SpecScenesPostFilter }
|
67
|
+
|
68
|
+
it "should be in the list of post filters" do
|
69
|
+
subject.register_post_filter SpecScenesPostFilter
|
70
|
+
subject.post_filters.should include(post_filter)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Units::Point do
|
4
|
+
|
5
|
+
subject { described_class.new x, y, z }
|
6
|
+
|
7
|
+
let(:x) { 12 }
|
8
|
+
let(:y) { 24 }
|
9
|
+
let(:z) { 36 }
|
10
|
+
|
11
|
+
its(:x) { should eq x }
|
12
|
+
its(:y) { should eq y }
|
13
|
+
its(:z) { should eq z }
|
14
|
+
its(:z_order) { should eq z }
|
15
|
+
|
16
|
+
let(:expected_string) { "#{x},#{y},#{z}" }
|
17
|
+
its(:to_s) { should eq expected_string }
|
18
|
+
|
19
|
+
describe "#+" do
|
20
|
+
context "when adding it to another point" do
|
21
|
+
let(:point) { described_class.at 1, 2, 3 }
|
22
|
+
let(:summed_point) { described_class.at 13, 26, 39 }
|
23
|
+
|
24
|
+
it "should be a sum of the two points" do
|
25
|
+
sum = subject + point
|
26
|
+
sum.should eq summed_point
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when adding it to another point-like object" do
|
31
|
+
let(:point) { stub('Point Like',x: 1, y: 2, z: 3) }
|
32
|
+
let(:summed_point) { described_class.at 13, 26, 39 }
|
33
|
+
|
34
|
+
it "should be a sum of the two points" do
|
35
|
+
sum = subject + point
|
36
|
+
sum.should eq summed_point
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when adding it to something not like a point" do
|
41
|
+
let(:point) { stub('Not Point Like') }
|
42
|
+
let(:summed_point) { described_class.at 13, 26, 39 }
|
43
|
+
|
44
|
+
it "should raise an error" do
|
45
|
+
expect { subject + point }.to raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#-" do
|
51
|
+
context "when adding it to another point" do
|
52
|
+
let(:point) { described_class.at 1, 2, 3 }
|
53
|
+
let(:summed_point) { described_class.at 11, 22, 33 }
|
54
|
+
|
55
|
+
it "should be a sum of the two points" do
|
56
|
+
sum = subject - point
|
57
|
+
sum.should eq summed_point
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when adding it to another point-like object" do
|
62
|
+
let(:point) { stub('Point Like',x: 1, y: 2, z: 3) }
|
63
|
+
let(:summed_point) { described_class.at 11, 22, 33 }
|
64
|
+
|
65
|
+
it "should be a sum of the two points" do
|
66
|
+
sum = subject - point
|
67
|
+
sum.should eq summed_point
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when adding it to something not like a point" do
|
72
|
+
let(:point) { stub('Not Point Like') }
|
73
|
+
let(:summed_point) { described_class.at 13, 26, 39 }
|
74
|
+
|
75
|
+
it "should raise an error" do
|
76
|
+
expect { subject - point }.to raise_error
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "Class Methods" do
|
82
|
+
|
83
|
+
subject { described_class }
|
84
|
+
|
85
|
+
describe "#zero" do
|
86
|
+
let(:expected_point) { Point.new 0,0,0 }
|
87
|
+
|
88
|
+
it "should create a zero point" do
|
89
|
+
subject.zero.should == expected_point
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#at" do
|
94
|
+
let(:expected_point) { Point.new 1,2,3 }
|
95
|
+
|
96
|
+
it "should be equal to a new created point" do
|
97
|
+
subject.at(1,2,3).should == expected_point
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#parse" do
|
102
|
+
context "when the input string is defined with 'x,y,z'" do
|
103
|
+
let(:input) { "1,2,3" }
|
104
|
+
let(:expected_value) { Point.at(1,2,3) }
|
105
|
+
|
106
|
+
it "should create the expected point" do
|
107
|
+
subject.parse(input).should eq expected_value
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when the input string is defined with 'x,y'" do
|
112
|
+
let(:input) { "1,2" }
|
113
|
+
let(:expected_value) { Point.at(1,2,0) }
|
114
|
+
|
115
|
+
it "should create the expected point" do
|
116
|
+
subject.parse(input).should eq expected_value
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when the input is a nil" do
|
121
|
+
let(:input) { nil }
|
122
|
+
let(:expected_value) { Point.at(0,0,0) }
|
123
|
+
|
124
|
+
it "should create the expected point" do
|
125
|
+
subject.parse(input).should eq expected_value
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RectangleBounds do
|
4
|
+
|
5
|
+
let(:subject) { described_class.new left: 20, top: 30, right: 40, bottom: 60 }
|
6
|
+
|
7
|
+
shared_examples "valid point" do
|
8
|
+
it "correct point" do
|
9
|
+
expect(given_point).to eq expected_point
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#top_left" do
|
14
|
+
it_behaves_like "valid point" do
|
15
|
+
let(:given_point) { subject.top_left }
|
16
|
+
let(:expected_point) { Point.at 20, 30 }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#top_right" do
|
21
|
+
it_behaves_like "valid point" do
|
22
|
+
let(:given_point) { subject.top_right }
|
23
|
+
let(:expected_point) { Point.at 40, 30 }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#bottom_left" do
|
28
|
+
it_behaves_like "valid point" do
|
29
|
+
let(:given_point) { subject.bottom_left }
|
30
|
+
let(:expected_point) { Point.at 20, 60 }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#bottom_right" do
|
35
|
+
it_behaves_like "valid point" do
|
36
|
+
let(:given_point) { subject.bottom_right }
|
37
|
+
let(:expected_point) { Point.at 40, 60 }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#center" do
|
42
|
+
it_behaves_like "valid point" do
|
43
|
+
let(:given_point) { subject.center }
|
44
|
+
let(:expected_point) { Point.at 30, 45 }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
describe "#dimensions" do
|
50
|
+
it "correct dimensions" do
|
51
|
+
expect(subject.dimensions).to eq Dimensions.of(20,30)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::View do
|
4
|
+
before do
|
5
|
+
subject.name = "spec"
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:expected_view_path) { "views/spec" }
|
9
|
+
its(:view_path) { should eq expected_view_path }
|
10
|
+
|
11
|
+
describe "#parser" do
|
12
|
+
before do
|
13
|
+
subject.stub(:supported_parsers) { [ mock(exists?: false), expected_parser ] }
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:expected_parser) { mock(exists?: true) }
|
17
|
+
|
18
|
+
it "should return the first parser which has a existing view" do
|
19
|
+
subject.parser.should eq expected_parser
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#writer" do
|
24
|
+
|
25
|
+
context "when the parser has a format that matches a writer" do
|
26
|
+
before do
|
27
|
+
subject.stub(:parser) { mock(format: :json) }
|
28
|
+
subject.stub(:supported_writers) { [ mock(format: :yaml), expected_writer ] }
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:expected_writer) { mock(format: :json) }
|
32
|
+
|
33
|
+
it "should match the parser format" do
|
34
|
+
subject.writer.format.should eq :json
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when the format has been specified" do
|
39
|
+
before do
|
40
|
+
subject.stub(:parser) { mock(format: :json) }
|
41
|
+
subject.stub(:supported_writers) { [ expected_writer, mock(format: :json) ] }
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:expected_writer) { mock(format: :yaml) }
|
45
|
+
|
46
|
+
it "should match the format (ignoring the parser format)" do
|
47
|
+
subject.format = :yaml
|
48
|
+
subject.writer.format.should eq :yaml
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|