Class: Riot::Assertion

Inherits:
RunnableBlock show all
Defined in:
lib/riot/runnable.rb,
lib/riot/assertion_macros.rb

Overview

Setup

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RunnableBlock

#initialize, #to_s

Constructor Details

This class inherits a constructor from Riot::RunnableBlock

Class Method Details

.assertion(name, expect_exception = false, &assertion_block) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/riot/runnable.rb', line 34

def self.assertion(name, expect_exception=false, &assertion_block)
  define_method(name) do |*expectings, &expectation_block|
    (class << self; self; end).send(:define_method, :run) do |situation|
      expectings << situation.evaluate(&expectation_block) if expectation_block
      process_macro(situation, expect_exception) { |actual| assertion_block.call(actual, *expectings) }
    end # redefine run method when the assertion is called
    self
  end # define_method for assertion
end

.error(e) ⇒ Object



26
# File 'lib/riot/runnable.rb', line 26

def self.error(e) [:error, e]; end

.fail(message) ⇒ Object



25
# File 'lib/riot/runnable.rb', line 25

def self.fail(message) [:fail, message]; end

.passObject



24
# File 'lib/riot/runnable.rb', line 24

def self.pass() [:pass]; end

Instance Method Details

#run(situation) ⇒ Object



28
29
30
31
32
# File 'lib/riot/runnable.rb', line 28

def run(situation)
  process_macro(situation, false) do |actual|
    actual ? Assertion.pass : Assertion.fail("Expected non-false but got #{actual.inspect} instead")
  end
end