Sha256: 664d1e41c72cd06f40c9dd01f22f718a8abfc2253a2392048273dac16841744f
Contents?: true
Size: 1.75 KB
Versions: 2
Compression:
Stored size: 1.75 KB
Contents
require 'spec' module Spec # TODO: Could we try to make this a mixin (Module) instead? It would make it easier to # create extensions that can be mixed and matched (AH). class Context def initialize(specification=nil) @specification = specification @mocks = [] end def setup end def teardown end # Creates a new named mock that will be automatically verified after #teardown # has run. By using this method instead of Mock#new you don't have to worry about # forgetting to verify your mocks. def mock(name) mock = Mock.new(name) @mocks << mock mock end # Immediately violates the current specification with +message+. def violated(message="") raise Spec::Exceptions::ExpectationNotMetError.new(message) end def self.collection specs = [] self.specifications.each do |spec| specs << self.new(spec.to_sym) end return specs 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, $!) ensure teardown verify_mocks end return result end private def self.my_methods self.instance_methods - self.superclass.instance_methods end def self.specification_name?(name) return false unless self.new.method(name).arity == 0 return false if name[0..0] == '_' true end def self.specifications return self.my_methods.select {|spec| self.specification_name?(spec)} end def verify_mocks @mocks.each{|m| m.__verify} end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rspec-0.2.0 | lib/spec/context.rb |
rspec-0.1.7 | lib/spec/context.rb |