spec/spec_helper.rb in larynx-0.1.2 vs spec/spec_helper.rb in larynx-0.1.3

- old
+ new

@@ -9,12 +9,18 @@ LARYNX_LOGGER = Logger.new(STDOUT) RESPONSES = {} Dir['spec/fixtures/*.rb'].each {|file| require file } +Larynx.module_eval do + def self.callbacks + @callbacks + end +end + class TestCallHandler < Larynx::CallHandler - attr_accessor :sent_data, :session, :state, :queue, :input, :timers + attr_accessor :sent_data, :session, :response, :state, :queue, :input, :timers def send_data(msg) @sent_data = msg end @@ -37,9 +43,25 @@ def should_not_be_called(&block) proc = mock('Proc should not be called') proc.should_not_receive(:call).instance_eval(&(block || lambda {})) lambda { |*args| proc.call(*args) } + end + + def with_global_callback(name, test_callback) + default = Larynx.callbacks[name] + Larynx.send(name, &test_callback) + yield + Larynx.send(name, &default) + end + + def reset_class(klass, &block) + name = klass.name.to_sym + Object.send(:remove_const, name) + eval "class #{klass}#{' < ' + klass.superclass.to_s if klass.superclass != Class}; end", TOPLEVEL_BINDING + new_klass = Object.const_get(name) + new_klass.class_eval &block if block_given? + new_klass end end Spec::Runner.configure do |config| config.include SpecHelper, EM::SpecHelper