lib/amqp-spec/rspec.rb in amqp-spec-0.3.2 vs lib/amqp-spec/rspec.rb in amqp-spec-0.3.3

- old
+ new

@@ -52,20 +52,20 @@ # Sets/retrieves default timeout for running evented specs for this # example group and its nested groups. # def default_timeout spec_timeout=nil - metadata[:em_timeout] = spec_timeout if spec_timeout - metadata[:em_timeout] + default_options[:spec_timeout] = spec_timeout || default_options[:spec_timeout] end # Sets/retrieves default AMQP.start options for this example group # and its nested groups. # def default_options opts=nil - metadata[:em_defaults] = opts if opts - metadata[:em_defaults] + metadata[:em_defaults] ||= {} + metadata[:em_defaults][self] ||= (superclass.default_options.dup rescue {}) + metadata[:em_defaults][self] = opts || metadata[:em_defaults][self] end # Add before hook that will run inside EM event loop def em_before scope = :each, &block raise ArgumentError, "em_before only supports :each scope" unless :each == scope @@ -73,55 +73,40 @@ end # Add after hook that will run inside EM event loop def em_after scope = :each, &block raise ArgumentError, "em_after only supports :each scope" unless :each == scope - em_hooks[:after] << block + em_hooks[:after].unshift block end - # Collection of evented hooks + # Collection of evented hooks for THIS example group def em_hooks metadata[:em_hooks] ||= {} - metadata[:em_hooks][self] ||= {:before => [], :after => []} -# p "#{self} < #{superclass}", em_metadata[:em_hooks].keys - metadata[:em_hooks][self] + metadata[:em_hooks][self] ||= + {before: (superclass.em_hooks[:before].clone rescue []), + after: (superclass.em_hooks[:after].clone rescue [])} end - -# # Returns a collection of all em hooks of given type -# # (including ancestor hooks) -# # -# def all_hooks type -# hooks = superclass.all_hooks(type) rescue [] -# hooks += em_hooks[type] -# end - - # Returns a collection of all em hooks of given type - # (including ancestor hooks) - # - def all_hooks type - hooks = superclass.all_hooks(type) rescue [] - hooks += em_hooks[type] -# :before == type ? hooks : hooks.reverse - hooks - end - end def self.included example_group unless example_group.respond_to? :default_timeout example_group.extend GroupMethods - example_group.metadata[:em_defaults] = {} - example_group.metadata[:em_timeout] = nil end end # Retrieves metadata passed in from enclosing example groups # def metadata @em_metadata ||= self.class.metadata.dup rescue {} end + # Retrieves default options passed in from enclosing example groups + # + def default_options + @em_default_options ||= self.class.default_options.dup rescue {} + end + # Yields to a given block inside EM.run and AMQP.start loops. This method takes # any option that is accepted by EventMachine::connect. Options for AMQP.start include: # * :user => String (default ‘guest’) - Username as defined by the AMQP server. # * :pass => String (default ‘guest’) - Password as defined by the AMQP server. # * :vhost => String (default ’/’) - Virtual host as defined by the AMQP server. @@ -131,12 +116,11 @@ # In addition to EM and AMQP options, :spec_timeout option (in seconds) is used # to force spec to timeout if something goes wrong and EM/AMQP loop hangs for some # reason. SpecTimeoutExceededError is raised if it happens. # def amqp opts={}, &block - opts = self.class.default_options.merge opts - opts[:spec_timeout] ||= self.class.default_timeout + opts = default_options.merge opts @evented_example = AMQPExample.new(opts, self, &block) @evented_example.run end # Yields to block inside EM loop, :spec_timeout option (in seconds) is used to @@ -145,14 +129,10 @@ # # For compatibility with EM-Spec API, em method accepts either options Hash # or numeric timeout in seconds. # def em opts = {}, &block - if opts.is_a? Hash - opts[:spec_timeout] ||= self.class.default_timeout - else - opts = {spec_timeout: opts} - end + opts = default_options.merge(opts.is_a?(Hash) ? opts : {spec_timeout: opts}) @evented_example = EMExample.new(opts, self, &block) @evented_example.run end # Breaks the event loop and finishes the spec. This should be called after \ No newline at end of file