example-filter

Filtering examples by description

--example PATTERN (alias -e PATTERN) runs only examples whose full nested description matches PATTERN. The full nested description joins every enclosing describe / context description with the it description, separated by spaces:

describe 'User signup', {
  context 'with a referral code', {
    it 'awards bonus credits', { ... }
    # Full description: "User signup with a referral code awards bonus credits"
  }
}

Substring matching (default)

By default PATTERN is a plain substring:

$ behave --example 'User signup'        # every example under User signup
$ behave -e 'awards bonus'              # the single example

The pattern matches when it appears anywhere inside the full nested description.

Regex matching

Wrap PATTERN in /.../ to compile it as a Raku regex. Standard Raku regex rules apply, so whitespace is not significant. Use \s (or quote literal text) for spaces:

$ behave --example '/\d+/'              # examples whose description has a digit
$ behave --example '/User\s+signup/'    # User-signup-related examples via regex

Multiple patterns (OR)

Repeat the flag for OR semantics:

$ behave --example 'User signup' --example 'Order checkout'

An example runs if it matches any pattern.

Combining with tags

--example composes with --tag, --exclude-tag, and focus mode using AND semantics: an example must satisfy every active filter to run:

$ behave --example 'User signup' --tag fast        # signup AND fast
$ behave --example 'User signup' --exclude-tag flaky

Group hooks

Groups whose subtrees contain no matching examples are skipped, including their before-all / after-all / around-all hooks. This avoids running expensive group setup when nothing inside the group will execute.

No matches is success

If a pattern matches nothing, behave reports zero total examples and exits 0:

$ behave --example 'no-such-thing'
0 examples

This makes it safe to drop --example filters into CI matrix builds without worrying about tripping a "zero tests" failure for legitimately empty selections.

See also

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.