Skip to content

Conversation

@SonOfSardaar
Copy link
Contributor

This PR addresses an issue where the fluent scanner could silently match a parameter name against multiple headers in an example table, potentially leading to incorrect behavior.

Changes

  1. Updated FluentScanner.CreateTitle() to detect when a parameter name matches multiple example table headers
  2. Added explicit error handling that throws an AmbiguousMatchException with a descriptive message
  3. Added test coverage to verify the ambiguous match detection

Example

// Before: Silently matched against both headers without warning
.WithExamples(new ExampleTable("count", "Count")
{
    { 5, 10 }
})
.Given(s => s.GivenInput(count))  // Which header should 'count' use?

// After: Throws helpful exception
AmbiguousMatchException: More than one headers for examples, match the parameter 'count' provided for 'GivenInput'

Testing

  • Added AmbiguousHeaderMatchTests class with test coverage for ambiguous header detection
  • Verified exception message provides clear context about which parameter and method caused the issue
  • All existing tests pass (323 tests in Tests project, 21 in Samples)

Why

  • Prevents subtle bugs where parameters might bind to unexpected example values
  • Makes the behavior explicit and fail-fast when ambiguity exists
  • Helps users quickly identify and fix header naming conflicts

Reviewer Notes

  • The error message format matches existing BDDfy conventions
  • The change only affects ambiguous matches; unique header matches work as before
  • Added test class follows existing test patterns in the fluent scanner tests

felix-v-net and others added 4 commits July 31, 2017 17:39
Added ArgumentException with a message to let user know that parameter name conflicts with header name in ExampleTable
@SonOfSardaar SonOfSardaar merged commit 13d9ace into main Oct 25, 2025
6 checks passed
@SonOfSardaar SonOfSardaar deleted the bugfix/handle-ambiguous-header-match branch October 25, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants