Sha256: 4c255242d27db2c852ac3a9a6e2a09b18fb8046f60edd0c09c840775abd8b414

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

require 'spec'


module Spec
  class Context
  
    def initialize(specification=nil)
      @specification = specification
    end

    def run(result_listener)
      result = false
    
      result_listener.spec(@specification)
      setup
      begin
        __send__(@specification)
        result_listener.pass(@specification)
      rescue Exception
        result_listener.failure(@specification, $!)
      end
      teardown
      
      return result
    end

    def setup
    end
    
    def teardown
    end

    def self.collection
      specs = []
      self.specifications.each do |spec|
        specs << self.new(spec.to_sym)
      end
      
      return specs
    end
  
    def self.specifications
      return self.my_methods.select {|spec| self.specification_name?(spec)}
    end

    def self.my_methods
      self.instance_methods - self.superclass.instance_methods
    end

    def self.specification_name?(name)
      return false if not self.new.method(name).arity == 0
      return false if name[0..0] == '_'
      return true
    end
    
    def violated
      raise Spec::Exceptions::ExpectationNotMetError.new
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rspec-0.1.1 lib/spec/context.rb
rspec-0.1.3 lib/spec/context.rb
rspec-0.1.4 lib/spec/context.rb
rspec-0.1.0 lib/spec/context.rb
rspec-0.1.2 lib/spec/context.rb