focus-skip

Focus and Skip

Behave provides DSL helpers for skipping examples that should not run and for focusing on a subset of examples while iterating on a feature. They behave like the corresponding helpers in RSpec.

Skipping examples

Use xit to register an example that should be reported but never executed. Its body is registered but never invoked.

describe 'Order', {
  it  'totals correctly', { ... }
  xit 'pending refactor', { ... }   # appears as SKIPPED, body never runs
}

Use xdescribe (or xcontext) to skip every example inside a group, including nested groups:

xdescribe 'Email delivery', {
  it 'sends the welcome email', { ... }
  it 'queues the digest',       { ... }   # both reported as SKIPPED
}

before-all, after-all, before-each, and after-each hooks are not run for examples inside a skipped group.

Focusing examples

Use fit to mark a single example as focused, and fdescribe (or fcontext) to focus an entire group. When any focused example or group exists in a suite, only focused examples run. Non-focused examples are silently filtered out.

describe 'User', {
  it  'persists the email',          { ... }   # filtered out
  fit 'sends a welcome email',       { ... }   # runs
  it  'enqueues the digest worker',  { ... }   # filtered out
}

fdescribe focuses every example in the group, including nested groups. Sibling groups in the same file are filtered out:

fdescribe 'OrderRefund', {
  it 'refunds the captured amount', { ... }   # runs
  it 'updates the audit log',       { ... }   # runs
}

describe 'OrderShipment', {
  it 'creates a shipping label', { ... }   # filtered out by focus mode
}

Focus mode is detected per suite (per spec file). Files without any fit/fdescribe continue to run every example as usual.

Combining focus and skip

Skipped examples are still reported as SKIPPED even when focus mode is on. A fit inside an xdescribe stays skipped: skip wins over focus.

fdescribe 'Account', {
  it  'creates an account',     { ... }   # focused, runs
  xit 'closes pending account', { ... }   # focused-by-inheritance, but skipped
}

xdescribe 'Legacy importer', {
  fit 'imports a CSV', { ... }   # still SKIPPED: skip wins over focus
}

Combining with tag filters

Focus and tag filtering compose. An example must match the tag filters and be focused (when focus mode is on) to run.

$ behave --tag fast               # tag filter alone
$ behave specs/users-spec.raku    # if the file has fit, only focused examples run

Output and counts

Skipped examples display in light blue with a SKIPPED marker. The summary line includes a skipped count alongside passed, failed, and pending:

9 examples, 6 skipped, 3 passed

Exit code stays 0 when only skips are present. Only failures cause a non-zero exit.

Inspecting focus / skip programmatically

Each Example and ExampleGroup exposes:

  • .focused: True if the node was registered with fit / fdescribe / :focused.

  • .skipped: True if the node was registered with xit / xdescribe / :skipped.

  • .effective-focused: True if the node or any ancestor is focused.

  • .effective-skipped: True if the node or any ancestor is skipped.

These mirror the tags / effective-tags helpers and are useful for custom reporters or tooling.

BDD::Behave v0.9.4

Behavior driven development framework

Authors

  • Greg Donald

License

Artistic-2.0

Dependencies

Provides

  • BDD::Behave
  • BDD::Behave::Benchmark
  • BDD::Behave::Benchmark::Baseline
  • BDD::Behave::Benchmark::Format
  • BDD::Behave::Bisect
  • BDD::Behave::Colors
  • BDD::Behave::Configuration
  • BDD::Behave::Coverage
  • BDD::Behave::DSL
  • BDD::Behave::Diff
  • BDD::Behave::DocExtractor
  • BDD::Behave::DryRun
  • BDD::Behave::Expectation
  • BDD::Behave::Failure
  • BDD::Behave::FailureStore
  • BDD::Behave::Failures
  • BDD::Behave::Files
  • BDD::Behave::Formatter
  • BDD::Behave::Formatter::Documentation
  • BDD::Behave::Formatter::HTML
  • BDD::Behave::Formatter::JSON
  • BDD::Behave::Formatter::JUnit
  • BDD::Behave::Formatter::JsonEvents
  • BDD::Behave::Formatter::Progress
  • BDD::Behave::Formatter::Registry
  • BDD::Behave::Formatter::TAP
  • BDD::Behave::Formatter::Tree
  • BDD::Behave::LetRuntime
  • BDD::Behave::Matcher
  • BDD::Behave::Matcher::Async
  • BDD::Behave::Matcher::Boolean
  • BDD::Behave::Matcher::Change
  • BDD::Behave::Matcher::Collection
  • BDD::Behave::Matcher::Core
  • BDD::Behave::Matcher::Custom
  • BDD::Behave::Matcher::Exception
  • BDD::Behave::Matcher::Numeric
  • BDD::Behave::Matcher::String
  • BDD::Behave::Matcher::Type
  • BDD::Behave::Mock::Allow
  • BDD::Behave::Mock::ArgMatcher
  • BDD::Behave::Mock::Double
  • BDD::Behave::Mock::HaveReceived
  • BDD::Behave::Mock::Spy
  • BDD::Behave::Mock::Stub
  • BDD::Behave::Parallel
  • BDD::Behave::Parallel::Distribution
  • BDD::Behave::Parallel::EventStream
  • BDD::Behave::Parallel::Manifest
  • BDD::Behave::Parallel::Queue
  • BDD::Behave::Parallel::WorkerPool
  • BDD::Behave::Runner
  • BDD::Behave::SharedContexts
  • BDD::Behave::SharedExamples
  • BDD::Behave::Slang
  • BDD::Behave::SpecLoader
  • BDD::Behave::SpecRegistry
  • BDD::Behave::SpecTree
  • BDD::Behave::SpecTree::Core
  • BDD::Behave::SpecTree::Example
  • BDD::Behave::SpecTree::ExampleGroup
  • BDD::Behave::SpecTree::Suite
  • BDD::Behave::Time
  • BDD::Behave::TypeName
  • BDD::Behave::Version
  • BDD::Behave::Watch
  • BDD::Behave::Watch::Session
  • BDD::Behave::Watch::SmartSelector
  • BDD::Behave::Watch::UI
  • BDD::Behave::Watch::Watcher
  • BDD::Behave::Worker

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.