diff options
| author | Tom Black <[email protected]> | 2017-06-04 21:11:56 -0400 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2017-06-04 21:11:56 -0400 |
| commit | 30c0f7ad8923ad1a90071234dcab7d4cc60268d4 (patch) | |
| tree | 52a57d8e0856c40dd6f758c6b2e8121f5b3887d9 | |
| parent | e87ee92576e6e9a1aec39c77d38a2e14f033c31d (diff) | |
| download | ruby2d-30c0f7ad8923ad1a90071234dcab7d4cc60268d4.tar.gz ruby2d-30c0f7ad8923ad1a90071234dcab7d4cc60268d4.zip | |
Test for bad event types
| -rw-r--r-- | lib/ruby2d/window.rb | 3 | ||||
| -rw-r--r-- | test/events_spec.rb | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb index 9970861..377523b 100644 --- a/lib/ruby2d/window.rb +++ b/lib/ruby2d/window.rb @@ -123,6 +123,9 @@ module Ruby2D end def on(event, &proc) + unless @events.has_key? event + raise Error, "`#{event}` is not a valid event type" + end event_id = new_event_key @events[event][event_id] = proc EventDescriptor.new(event, event_id) diff --git a/test/events_spec.rb b/test/events_spec.rb index f0e5411..a5fa279 100644 --- a/test/events_spec.rb +++ b/test/events_spec.rb @@ -1,6 +1,13 @@ require 'ruby2d' RSpec.describe Window do + describe 'on :bad_event' do + it "raises exception if a bad event type is given" do + window = Ruby2D::Window.new + expect { window.on(:bad_event) }.to raise_error(Ruby2D::Error) + end + end + [:key, :key_down, :key_held, :key_up].each do |key_event_type| describe "on #{key_event_type}" do it "allows binding of event" do |
