junctions

Junctions

expect(actual).to.be(expected) uses Raku smartmatch (~~) through the built-in BeMatcher. Junctions on the right-hand side of a smartmatch auto-thread, so every junction form composes with expect without any extra DSL.

any: match any one alternative

expect($x).to.be(1 | 2 | 3);
expect($x).to.be(any(1, 2, 3));      # equivalent

Passes when $x smartmatches at least one of the alternatives.

expect($status).to.be('green' | 'yellow' | 'red');
expect($value).to.be(Int | Str);     # type-object alternatives

all: match every alternative

expect($x).to.be(Int & Numeric);
expect($x).to.be(all(Int, Numeric)); # equivalent

Passes when $x smartmatches every alternative. Mixing distinct literal values (1 & 2) is effectively unsatisfiable because a single value cannot equal two different literals. Combine all with type checks, ranges, or predicates instead.

my subset Positive of Int where * > 0;
expect($x).to.be(Int & Positive);

one: match exactly one alternative

expect($x).to.be(1 ^ 2 ^ 3);
expect($x).to.be(one(1, 2, 3));      # equivalent

Passes when exactly one alternative matches. Useful for mutually exclusive states.

none: match no alternative

expect($x).to.be(none(1, 2, 3));

Passes when $x matches none of the listed values.

Negation

.not flips the outer result. The junction collapses to a Bool first, then .not negates it:

expect(5).to.not.be(1 | 2 | 3);      # passes: 5 is not in the set
expect(2).to.not.be(none(1, 2, 3));  # passes: 2 is in the set

Failure metadata

When a junction expectation fails, Failure.expected carries the Junction itself and Failure.given carries the actual value:

expect(5).to.be(1 | 2 | 3);
# Failure.given    == 5
# Failure.expected == any(1, 2, 3)

Junction-aware diffs

When a junction expectation fails, the Diff: section collapses the junction to its constituent alternatives, marking each with āœ“ (matched) or āœ— (didn't match), so the reader sees exactly which alternatives didn't line up with the given value:

Expected: 5
to be: any(1, 2, 3)
Diff:
  - any(1, 2, 3)
  + 5
    Alternatives (none of 3 matched; expected at least one):
      āœ— 1
      āœ— 2
      āœ— 3

Each junction kind reports its own summary line:

  • any: none of N matched; expected at least one

  • all: K of N matched; expected all

  • one: K of N matched; expected exactly one

  • none: K of N matched; expected zero

Under .not, the summary phrases the inverted intent (e.g. expected none under negation for negated any, expected at least one under negation for negated none), so the diff stays useful when the matcher fires through negation.

Type-object alternatives (Int | Rat) render by name. Values render via .raku.

See also

  • Matchers: the matcher role and built-ins.

  • Diff Output: how the Diff: section is constructed for non-junction shapes.

  • Composable Matchers: .and / .or on Matcher objects (object-level alternative to Raku's literal junctions).

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.