Sha256: b2998ac3c79b0ab5630c5123518eb8ca7a70c2e72bf6b6a3de87a396ed216f77

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

module Riot
  class Assertion < RunnableBlock
    class << self
      def macros; @@macros ||= {}; end

      def register_macro(name, assertion_macro, expect_exception=false)
        macros[name.to_s] = assertion_macro
      end
    end

    def initialize(description, &definition)
      super
      @expectings, @expectation_block = [], false, nil
      @macro = AssertionMacro.default
    end

    def run(situation)
      @expectings << situation.evaluate(&@expectation_block) if @expectation_block
      actual = situation.evaluate(&definition)
      @macro.evaluate((@macro.expects_exception? ? nil : actual), *@expectings)
    rescue Exception => e
      @macro.expects_exception? ? @macro.evaluate(e, *@expectings) : @macro.error(e)
    end
  private
    def enhance_with_macro(name, *expectings, &expectation_block)
      @expectings, @expectation_block = expectings, expectation_block
      @macro = self.class.macros[name.to_s].new
      raise(NoMethodError, name) unless @macro
      @macro.file, @macro.line = caller.first.match(/(.*):(\d+)/)[1..2]
      self
    end
    alias :method_missing :enhance_with_macro
  end # Assertion
end # Riot

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
riot-0.11.4 lib/riot/assertion.rb
riot-0.11.4.pre lib/riot/assertion.rb
riot-0.11.3 lib/riot/assertion.rb
riot-0.11.2 lib/riot/assertion.rb
riot-0.11.1 lib/riot/assertion.rb
riot-0.11.0 lib/riot/assertion.rb
riot-0.10.13 lib/riot/assertion.rb
riot-0.10.13.pre lib/riot/assertion.rb
riot-0.10.12 lib/riot/assertion.rb