Sha256: 580725c698ff76936f578e10b5b5191a23b3932ede0f3851eb4a03dbd39a6a5b

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

# order: 20
Feature: State
:!hardbreaks:
State is a Hash object that is shared between step executions.

It's used to share state between steps and communicate with external world.

User can provide initial state when calling the operation. By default it's empty.

State can be used as the operation output as it is accessible in the result object.

  Scenario: State is shared across step executions
    Given definition
    """ruby
    class Operation < Rung::Operation
      step do |state|
        state[:what] = "World!"
      end

      step do
        print_to_output "Hello "
      end

      step do |state|
        print_to_output state[:what]
      end
    end
    """
    When I run
    """
    Operation.new.call
    """
    Then I see output
    """
    Hello World!
    """

  Scenario: State is available in the result object
    Given definition
    """ruby
    class Operation < Rung::Operation
      step do |state|
        state[:output_text] = "Hello "
      end

      step do |state|
        state[:output_text] << "World!"
      end
    end
    """
    When I run
    """
    @result = Operation.new.call
    """
    Then I can assure that
    """
    @result[:output_text] == "Hello World!"
    """

  Scenario: Initial state can be passed to call method
    Given definition
    """ruby
    class Operation < Rung::Operation
      step do |state|
        state[:output_text] << "World!"
      end
    end
    """
    When I run
    """
    @result = Operation.new.call(output_text: "Hello ")
    """
    Then I can assure that
    """
    @result[:output_text] == "Hello World!"
    """
    And I can assure that
    """
    @result.to_h == { output_text: "Hello World!" }
    """

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rung-0.1 features/020_state.feature