diff options
| -rw-r--r-- | lib/ruby2d/sprite.rb | 8 | ||||
| -rw-r--r-- | test/sprite_spec.rb | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/ruby2d/sprite.rb b/lib/ruby2d/sprite.rb index e6a6efa..7c66f97 100644 --- a/lib/ruby2d/sprite.rb +++ b/lib/ruby2d/sprite.rb @@ -8,9 +8,11 @@ module Ruby2D def initialize(x, y, path, z=0) - # unless File.exists? path - # raise Error, "Cannot find image file `#{path}`" - # end + unless RUBY_ENGINE == 'opal' + unless File.exists? path + raise Error, "Cannot find sprite image file `#{path}`" + end + end @x, @y, @path = x, y, path @clip_x, @clip_y, @clip_w, @clip_h = 0, 0, 0, 0 diff --git a/test/sprite_spec.rb b/test/sprite_spec.rb index 441ca6e..e44ea62 100644 --- a/test/sprite_spec.rb +++ b/test/sprite_spec.rb @@ -3,8 +3,12 @@ require 'ruby2d' RSpec.describe Ruby2D::Sprite do describe '#new' do + it "raises exception if file doesn't exist" do + expect { Sprite.new(0, 0, "bad_sprite_sheet.png") }.to raise_error(Ruby2D::Error) + end + it 'creates a new sprite' do - Ruby2D::Sprite.new(0, 0, "tests/media/sprite_sheet.png") + Sprite.new(0, 0, "test/media/sprite_sheet.png") end end |
