spec/eventer_spec.rb in eventer-0.0.1 vs spec/eventer_spec.rb in eventer-0.0.2

- old
+ new

@@ -1,62 +1,62 @@ #!/usr/bin/ruby require File.expand_path('../spec_helper', __FILE__) describe 'Eventer' do - it "Good event match" do - class Test - events :event - end + it "Good event match" do + class Test + events :event + end - t = Test.new + t = Test.new - t.on_event do |args| - "Matched" - end + t.on_event do |args| + "Matched" + end - o = (t.event :event).to_a.flatten.map do |x| x.class == String ? x : nil end.compact + o = t.event_rs :event - raise "Event result isn't matched" if o != [ "Matched" ] + raise "Event result isn't matched" if o != [ "Matched" ] + end + + it "Unknown event triggered" do + class Test + events :event end - it "Unknown event triggered" do - class Test - events :event - end + t = Test.new - t = Test.new + t.on_event do |args| + "Matched" + end - t.on_event do |args| - "Matched" - end + o = begin + t.event_rs :unknown + rescue Eventer::UnknownEventError + true + end - o = begin - (t.event :unknown).to_a.flatten.map do |x| x.class == String ? x : nil end.compact - rescue Eventer::EventerError - true - end + raise "Event result isn't matched" if (not o) or (o != true) + end - raise "Event result isn't matched" if (not o) or (o != true) + it "Try to register an unknown event" do + class Test + events :event end - it "Try to register an unknown event" do - class Test - events :event - end + t = Test.new - t = Test.new - - o = begin - t.on_unknown do |args| - "Matched" - end - false - rescue Eventer::EventerError - true + o = begin + t.on_unknown do |args| + "Matched" end - - raise "Event result isn't matched" if (not o) or (o != true) + false + rescue NoMethodError + true end + + raise "Event result isn't matched" if (not o) or (o != true) + end end