Sha256: 865a6fb012eae3d365b572196c5a392d4e719b62f6c23e7ddcbdcddeee6849c4

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

module Micronaut

  class Example
  
    attr_reader :behaviour, :description, :metadata, :example_block
  
    def initialize(behaviour, desc, options, example_block=nil)
      @behaviour, @description, @options, @example_block = behaviour, desc, options, example_block
      @metadata = @behaviour.metadata.dup
      @metadata[:description] = description
      @metadata.update(options)
    end

    def inspect
      "#{@metadata[:behaviour][:name]} - #{@metadata[:description]}"
    end
    
    def to_s
      inspect
    end

    def run_before_each
      @behaviour_instance._setup_mocks
      @behaviour.eval_before_eachs(@behaviour_instance)
    end

    def run_after_each
      @behaviour.eval_after_eachs(@behaviour_instance)
      @behaviour_instance._verify_mocks
    ensure
      @behaviour_instance._teardown_mocks
    end

    def run_example
      if example_block
        @behaviour_instance.instance_eval(&example_block)
        @behaviour_instance._verify_mocks
        @reporter.example_passed(self)
      else
        @reporter.example_pending(self, 'Not yet implemented')
      end
    end

    def run(behaviour_instance, reporter)
      @behaviour_instance, @reporter = behaviour_instance, reporter
      @behaviour_instance.running_example = self
      @reporter.example_started(self)

      all_systems_nominal = true
      exception_encountered = nil
      
      begin
        run_before_each
        run_example
      rescue Exception => e
        exception_encountered = e
        all_systems_nominal = false
      end

      begin
        run_after_each
      rescue Exception => e
        exception_encountered ||= e
        all_systems_nominal = false
      ensure
        @behaviour_instance.running_example = nil
      end
      
      @reporter.example_failed(self, exception_encountered) if exception_encountered 

      all_systems_nominal
    end
  
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spicycode-micronaut-0.2.1.3 lib/micronaut/example.rb