diff options
| -rw-r--r-- | lib/ruby2d/text.rb | 6 | ||||
| -rw-r--r-- | test/text_spec.rb | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb index f9d46a2..c9f5bb2 100644 --- a/lib/ruby2d/text.rb +++ b/lib/ruby2d/text.rb @@ -18,6 +18,12 @@ module Ruby2D @font = opts[:font] + unless RUBY_ENGINE == 'opal' + unless File.exists? @font + raise Error, "Cannot find font file `#{@font}`" + end + end + self.color = opts[:color] || 'white' ext_text_init add diff --git a/test/text_spec.rb b/test/text_spec.rb index d2b8430..a787380 100644 --- a/test/text_spec.rb +++ b/test/text_spec.rb @@ -1,6 +1,11 @@ require 'ruby2d' RSpec.describe Ruby2D::Text do + describe '#new' do + it "raises exception if font file doesn't exist" do + expect { Text.new(font: 'bad_font.ttf') }.to raise_error(Ruby2D::Error) + end + end describe '#text=' do it 'maps Time to string' do |
