cucumber-core

It contains the core domain logic to execute Cucumber features. It has no user interface, just a Ruby API. If you're interested in how Cucumber works, or in building other tools that work with Gherkin documents, you've come to the right place.

Filters

Once we have the test cases, and they've been activated by the mappings, you may want to pass them through a filter or two. Filters can be used to do things like activate, sort, replace or remove some of the test cases or their steps before they're executed.

Events

Events are how you find out what is happening during your test run. As the test cases and steps are executed, the runner emits events to signal what's going on.

Example

require'cucumber/core'require'cucumber/core/filter'# This is the most complex part of the example. The filter takes test cases as input,
# activates each step with an action block, then passes a new test case with those activated
# steps in it on to the next filter in the chain.
classActivateSteps<Cucumber::Core::Filter.newdeftest_case(test_case)test_steps=test_case.test_steps.mapdo|step|activate(step)endtest_case.with_steps(test_steps).describe_to(receiver)endprivatedefactivate(step)casestep.textwhen/fail/step.with_action{raiseFailure}when/pass/step.with_action{}elsestependendend# Create a Gherkin document to run
feature=Cucumber::Core::Gherkin::Document.new(__FILE__,<<-GHERKIN)Feature:
Scenario:
Given passing
And failing
And undefined
GHERKIN
# Create a runner class that uses the Core's DSL
classMyRunnerincludeCucumber::Coreend# Now execute the feature, using the filter we built, and subscribing to
# an event so we can print the output.
MyRunner.new.execute([feature],[ActivateSteps.new])do|events|events.on(:test_step_finished)do|event|test_step,result=event.test_step,event.resultputs"#{test_step.text}#{result}"endend

If you run this little Ruby script, you should see the following output: