From 3a694ffebcff71305d79c6e8c15246d671ce3888 Mon Sep 17 00:00:00 2001 From: lstrzebinczyk Date: Sat, 27 May 2017 20:56:35 +0200 Subject: Use named arguments (#65) --- test/text_spec.rb | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'test/text_spec.rb') diff --git a/test/text_spec.rb b/test/text_spec.rb index 15038d2..d2b8430 100644 --- a/test/text_spec.rb +++ b/test/text_spec.rb @@ -4,13 +4,13 @@ RSpec.describe Ruby2D::Text do describe '#text=' do it 'maps Time to string' do - t = Text.new(0, 0, Time.now, 40, "test/media/bitstream_vera/vera.ttf") + 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" end it 'maps Number to string' do - t = Text.new(0, 0, 0, 40, "test/media/bitstream_vera/vera.ttf") + t = Text.new(font: "test/media/bitstream_vera/vera.ttf") t.text = 0 expect(t.text).to eq "0" end @@ -18,42 +18,44 @@ RSpec.describe Ruby2D::Text do describe "#width" do it "is known after creation" do - t = Text.new(0, 0, "Hello world!", 40, "test/media/bitstream_vera/vera.ttf") - expect(t.width).to eq(239) + t = Text.new(font: "test/media/bitstream_vera/vera.ttf") + expect(t.width).to eq(123) end it "is known after updating" do - t = Text.new(0, 0, "Good morning world!", 40, "test/media/bitstream_vera/vera.ttf") - t.text = "Hello world!" - expect(t.width).to eq(239) + t = Text.new(font: "test/media/bitstream_vera/vera.ttf") + t.text = "Hello!" + expect(t.width).to eq(59) end end describe "#height" do it "is known after creation" do - t = Text.new(0, 0, "Hello world!", 40, "test/media/bitstream_vera/vera.ttf") - expect(t.height).to eq(48) + t = Text.new(font: "test/media/bitstream_vera/vera.ttf") + expect(t.height).to eq(24) end it "is known after updating" do - t = Text.new(0, 0, "Good morning world!", 40, "test/media/bitstream_vera/vera.ttf") - t.text = "Hello world!" - expect(t.height).to eq(48) + t = Text.new(font: "test/media/bitstream_vera/vera.ttf") + t.text = "Good morning world!" + expect(t.height).to eq(24) end end describe '#contains?' do it "returns true if point is inside text" do - text = Text.new(0, 0, "Hello world!", 40, "test/media/bitstream_vera/vera.ttf") - expect(text.contains?(text.width / 2, text.height / 2)).to be true + t = Text.new(font: "test/media/bitstream_vera/vera.ttf") + t.text = "Hello world!" + expect(t.contains?(t.width / 2, t.height / 2)).to be true end it "returns true if point is not inside text" do - text = Text.new(0, 0, "Hello world!", 40, "test/media/bitstream_vera/vera.ttf") - expect(text.contains?( - text.width / 2, text.height / 2)).to be false - expect(text.contains?( text.width / 2, - text.height / 2)).to be false - expect(text.contains?(3 * text.width / 2, text.height / 2)).to be false - expect(text.contains?( text.width / 2, 3 * text.height / 2)).to be false + t = Text.new(font: "test/media/bitstream_vera/vera.ttf") + t.text = "Hello world!" + expect(t.contains?( - t.width / 2, t.height / 2)).to be false + expect(t.contains?( t.width / 2, - t.height / 2)).to be false + expect(t.contains?(3 * t.width / 2, t.height / 2)).to be false + expect(t.contains?( t.width / 2, 3 * t.height / 2)).to be false end end end -- cgit v1.2.3