Exception: ReturnAssay

Inherits:
ExecutionAssay show all
Defined in:
lib/assay/return_assay.rb

Overview

Assert that a block of code returns a specific result, also fails if an error is raised in the block.

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Constants included from Assay::Assertable

Assay::Assertable::SIZE_LIMIT

Class Method Summary collapse

Methods inherited from ExecutionAssay

assert_message

Methods inherited from Assertion

by_name, by_operator, inherited, register, subclasses

Methods included from Assay::Assertable

#[], #assert!, #assert_message, #assertive_name, #assertor, #fail?, #operator, #pass?, #refute!, #refute_message

Class Method Details

.fail?(returns, *arguments) ⇒ Boolean

Check that a block does NOT return a specific value comparing the returns argument and actual returned value with the ‘#==` operator.

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/assay/return_assay.rb', line 29

def self.fail?(returns, *arguments)  #:yield:
  begin
    result = yield(*arguments)
    returns != result
  rescue Exception
    true
  end
end

.pass?(returns, *arguments) ⇒ Boolean

Check that a block returns a specific value comparing the returns argument and actual returned value with the ‘#==` operator.

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
# File 'lib/assay/return_assay.rb', line 15

def self.pass?(returns, *arguments)  #:yield:
  begin
    result = yield(*arguments)
    returns == result
  rescue Exception
    false
  end
end