Class: Roby::Test::ExpectExecution::Context

Inherits:
Struct
  • Object
show all
Defined in:
lib/roby/test/expect_execution.rb

Overview

The context object that allows the expect_execution { }.to { } syntax

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, **kw, &block) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/roby/test/expect_execution.rb', line 59

def method_missing(m, *args, **kw, &block)
    if (to_method = m.to_s.match(/^to_/))
        return to { send(to_method.post_match, *args, **kw, &block) }
    end

    expectations.public_send(m, *args, **kw, &block)
    self
end

Instance Attribute Details

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



54
55
56
# File 'lib/roby/test/expect_execution.rb', line 54

def block
  @block
end

#expectationsObject

Returns the value of attribute expectations

Returns:

  • (Object)

    the current value of expectations



54
55
56
# File 'lib/roby/test/expect_execution.rb', line 54

def expectations
  @expectations
end

#testObject

Returns the value of attribute test

Returns:

  • (Object)

    the current value of test



54
55
56
# File 'lib/roby/test/expect_execution.rb', line 54

def test
  @test
end

Instance Method Details

#respond_to_missing?(m, include_private) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/roby/test/expect_execution.rb', line 55

def respond_to_missing?(m, include_private)
    SETUP_METHODS.include?(m)
end

#to(&expectation_block) ⇒ Object

Declare the expectations and run



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/roby/test/expect_execution.rb', line 77

def to(&expectation_block)
    test.setup_current_expect_execution(self)
    if expectation_block
        expectations.parse(&expectation_block)
    end
    expectations.verify(&block)
rescue Minitest::Assertion => e
    raise e, e.message, caller(2)
ensure
    test.reset_current_expect_execution
end

#to_runObject

Run the block without any expectations

Expectations might be added dynamically by the block given to expect_execution using Roby::Test::ExpectExecution#add_expectations



72
73
74
# File 'lib/roby/test/expect_execution.rb', line 72

def to_run
    to
end