From aecb756b33510378d91d9737930d97a381cc9403 Mon Sep 17 00:00:00 2001 From: Tom Black Date: Fri, 28 Sep 2018 13:23:43 -0700 Subject: Style, docs, and consistency --- ext/ruby2d/extconf.rb | 2 +- lib/ruby2d/renderable.rb | 3 +++ test/dsl_spec.rb | 18 +++++++++--------- test/events_spec.rb | 18 +++++++++--------- test/text_spec.rb | 4 ++-- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/ext/ruby2d/extconf.rb b/ext/ruby2d/extconf.rb index 674dc9d..fb9d0b4 100644 --- a/ext/ruby2d/extconf.rb +++ b/ext/ruby2d/extconf.rb @@ -76,6 +76,6 @@ check_s2d_version # Add flags $CFLAGS << ' -std=c11 -I/usr/local/include' $LDFLAGS << ' ' << `bash simple2d --libs` -$LDFLAGS.gsub!(/\n/, ' ') # Remove newlines in flags, they cause problems +$LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they cause problems create_makefile('ruby2d/ruby2d') diff --git a/lib/ruby2d/renderable.rb b/lib/ruby2d/renderable.rb index 18c7a78..0e5da50 100644 --- a/lib/ruby2d/renderable.rb +++ b/lib/ruby2d/renderable.rb @@ -5,18 +5,21 @@ module Ruby2D attr_reader :z + # Set the z position (depth) of the object def z=(z) remove @z = z add end + # Add the object to the window def add if Module.const_defined? :DSL Window.add(self) end end + # Remove the object from the window def remove if Module.const_defined? :DSL Window.remove(self) diff --git a/test/dsl_spec.rb b/test/dsl_spec.rb index dd85f77..063abd2 100644 --- a/test/dsl_spec.rb +++ b/test/dsl_spec.rb @@ -5,25 +5,25 @@ RSpec.describe Ruby2D::DSL do describe "#get" do it "gets the default window attributes" do - expect(get :width).to eq 640 - expect(get :height).to eq 480 - expect(get :title).to eq "Ruby 2D" + expect(get :width).to eq(640) + expect(get :height).to eq(480) + expect(get :title).to eq("Ruby 2D") end end describe "#set" do it "sets a single window attribute" do set width: 300 - expect(get :width).to eq 300 - expect(get :height).to eq 480 - expect(get :title).to eq "Ruby 2D" + expect(get :width).to eq(300) + expect(get :height).to eq(480) + expect(get :title).to eq("Ruby 2D") end it "sets multiple window attributes at a time" do set width: 800, height: 600, title: "Hello tests!" - expect(get :width).to eq 800 - expect(get :height).to eq 600 - expect(get :title).to eq "Hello tests!" + expect(get :width).to eq(800) + expect(get :height).to eq(600) + expect(get :title).to eq("Hello tests!") end end diff --git a/test/events_spec.rb b/test/events_spec.rb index ab07209..cff8c95 100644 --- a/test/events_spec.rb +++ b/test/events_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Ruby2D::Window do end callback_event_name = key_event_type.to_s.gsub("key_", "").to_sym window.key_callback(callback_event_name, "example_key") - expect(value).to eq 1 + expect(value).to eq(1) end it "allows binding of multiple events" do @@ -33,7 +33,7 @@ RSpec.describe Ruby2D::Window do end callback_event_name = key_event_type.to_s.gsub("key_", "").to_sym window.key_callback(callback_event_name, "example_key") - expect(value).to eq 3 + expect(value).to eq(3) end it "returns value, which can be used to unbind event" do @@ -45,7 +45,7 @@ RSpec.describe Ruby2D::Window do window.off(event_descriptor) callback_event_name = key_event_type.to_s.gsub("key_", "").to_sym window.key_callback(callback_event_name, "example_key") - expect(value).to eq 0 + expect(value).to eq(0) end end end @@ -60,7 +60,7 @@ RSpec.describe Ruby2D::Window do end callback_event_name = key_event_type.to_s.gsub("mouse_", "").to_sym window.mouse_callback(callback_event_name, nil, nil, 0, 0, 0, 0) - expect(value).to eq 1 + expect(value).to eq(1) end it "allows binding of multiple events" do @@ -74,7 +74,7 @@ RSpec.describe Ruby2D::Window do end callback_event_name = key_event_type.to_s.gsub("mouse_", "").to_sym window.mouse_callback(callback_event_name, nil, nil, 0, 0, 0, 0) - expect(value).to eq 3 + expect(value).to eq(3) end it "returns value, which can be used to unbind event" do @@ -86,7 +86,7 @@ RSpec.describe Ruby2D::Window do window.off(event_descriptor) callback_event_name = key_event_type.to_s.gsub("mouse_", "").to_sym window.mouse_callback(callback_event_name, nil, nil, 0, 0, 0, 0) - expect(value).to eq 0 + expect(value).to eq(0) end end end @@ -101,7 +101,7 @@ RSpec.describe Ruby2D::Window do end callback_event_name = key_event_type.to_s.gsub("controller_", "").to_sym window.controller_callback(nil, callback_event_name, nil, nil, nil) - expect(value).to eq 1 + expect(value).to eq(1) end it "allows binding of multiple events" do @@ -115,7 +115,7 @@ RSpec.describe Ruby2D::Window do end callback_event_name = key_event_type.to_s.gsub("controller_", "").to_sym window.controller_callback(nil, callback_event_name, nil, nil, nil) - expect(value).to eq 3 + expect(value).to eq(3) end it "returns value, which can be used to unbind event" do @@ -127,7 +127,7 @@ RSpec.describe Ruby2D::Window do window.off(event_descriptor) callback_event_name = key_event_type.to_s.gsub("controller_", "").to_sym window.controller_callback(nil, callback_event_name, nil, nil, nil) - expect(value).to eq 0 + expect(value).to eq(0) end end end diff --git a/test/text_spec.rb b/test/text_spec.rb index 6e0ba09..9a79532 100644 --- a/test/text_spec.rb +++ b/test/text_spec.rb @@ -12,13 +12,13 @@ RSpec.describe Ruby2D::Text do it 'maps Time to string' do t = Text.new(font: "test/media/bitstream_vera/vera.ttf") t.text = Time.new(1, 1, 1, 1, 1, 1, 1) - expect(t.text).to eq "0001-01-01 01:01:01 +0000" + expect(t.text).to eq("0001-01-01 01:01:01 +0000") end it "maps Number to string" do t = Text.new(font: "test/media/bitstream_vera/vera.ttf") t.text = 0 - expect(t.text).to eq "0" + expect(t.text).to eq("0") end end -- cgit v1.2.3