Sha256: 9813fbf7bfa39a3b5004d4880cf2227fdb05a20e1f4e245382f5161037305b07

Contents?: true

Size: 1.57 KB

Versions: 28

Compression:

Stored size: 1.57 KB

Contents

Feature: One line step definitions

  Everybody knows you can do step definitions in Cucumber
  but did you know you can do this?

  Scenario: Call a method in World directly from a step def
    Given a file named "features/step_definitions/steps.rb" with:
      """
      module Driver
        def do_action
          @done = true
        end

        def assert_done
          expect(@done).to be true
        end
      end
      World(Driver)

      When /I do the action/, :do_action
      Then /The action should be done/, :assert_done
      """
    And a file named "features/action.feature" with:
      """
      Feature:
        Scenario:
          When I do the action
          Then the action should be done
      """
    When I run `cucumber`
    Then it should pass

  Scenario: Call a method on an actor in the World directly from a step def
    Given a file named "features/step_definitions/steps.rb" with:
      """
      class Thing
        def do_action
          @done = true
        end

        def assert_done
          expect(@done).to be true
        end
      end

      module Driver
        def thing
          @thing ||= Thing.new
        end
      end
      World(Driver)

      When /I do the action to the thing/, :do_action, :on => lambda { thing }
      Then /The thing should be done/, :assert_done, :on => lambda { thing }
      """
    And a file named "features/action.feature" with:
      """
      Feature:
        Scenario:
          When I do the action to the thing
          Then the thing should be done
      """
    When I run `cucumber`
    Then it should pass

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
cucumber-3.0.1 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.99.0 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-3.0.0 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-3.0.0.pre.2 features/docs/defining_steps/one_line_step_definitions.feature
mobiusloop-0.1.5 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-3.0.0.pre.1 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.4.0 features/docs/defining_steps/one_line_step_definitions.feature
mobiusloop-0.1.3 features/docs/defining_steps/one_line_step_definitions.feature
mobiusloop-0.1.2 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.3.3 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.3.2 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.3.1 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.3.0 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.2.0 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.1.0 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.0.2 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.0.1 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.0.0 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.0.0.rc.5 features/docs/defining_steps/one_line_step_definitions.feature
cucumber-2.0.0.rc.4 features/docs/defining_steps/one_line_step_definitions.feature