SpecFlowOSS / SpecFlow.VisualStudio

Visual Studio extension of SpecFlow (extracted from the main SpecFlow repo)
Other
67 stars 73 forks source link

Misleading "Multiple matching bindings" message when step is bound to another feature #164

Open lucjanl opened 8 years ago

lucjanl commented 8 years ago

I use SpecFlow 2.0 and SpecFlow for VisualStudio 2015 version 2015.1.2. I wrote a feature:

Feature: Service selection - package selection
    In order to choose package
    As a receptionist
    I want to be define package requirement details

Background: 
    Given now is "2016-04-24 18:00"
    And hotel day starts at 14:00 and ends at 12:00

and steps definition ServiceSelectionTypeChoosingSteps.cs:

    [Scope(Feature = "Service selection type choosing")]
    [Scope(Feature = "Service selection - package selection")]
    [Scope(Feature = "Service selection defaults")]
    [Binding]
    public class ServiceSelectionTypeChoosingSteps
    {
        [Given(@"hotel day starts at (\d+):00 and ends at (\d+):00")]
        public void GivenHotelDayStartsAtAndEndsAt(Int32 startHour, Int32 endHour)
        {
            _mX.SetupGet(x => x.Night).Returns(new Night(startHour, endHour));
        }
...

Then I wrote another feature:

Feature: DateTimeExtensions - AddHotelDuration
    In order to ease use of dates
    As a programmes
    I want to be able to add duration to a given date

Scenario Outline: Add duration in minutes to given date
    Given hotel day starts at 14:00 and ends at 12:00

and step definition:

    [Binding]
    [Scope(Feature = "DateTimeExtensions - AddHotelDuration")]
    public class DateTimeExtensions_AddHotelDurationSteps
    {
        [Given(@"hotel day starts at (/d+):00 and ends at (/d+):00")]
        public void GivenHotelDayStartsAtAndEndsAt(Int32 startHour, Int32 endHour)
        {
            _night = new Night(startHour, endHour);
        }

Now in the first feature the line And hotel day starts at 14:00 and ends at 12:00 is black. In the second feature the line Given hotel day starts at 14:00 and ends at 12:00 is pink and when I select it and press F12, the SpecFlow addon tells me:

Multiple matching bindings found. Navigating to the first match...
ServiceSelectionTypeChoosingSteps.GivenHotelDayStartsAtAndEndsAt(Int32, Int32)

I suppose the feature scoping doesn't work. Am I right or I did something wrong?

lucjanl commented 8 years ago

After submitting this issue I saw it was my mistake: I used slash ((/d+)) in the second step regex instead of backslash ((\d+)). But ultimately the message "Multiple matching bindings" is misleading...

darrencauthon commented 8 years ago

This is unrelated to this issue, but reading this issue reminded me a video I recorded many years ago.... "SpecFlow Anti-Pattern: Using Private Members to Retain State Between Steps " https://www.youtube.com/watch?v=IGvxMPX55vE

samholder commented 8 years ago

I agree with the anti pattern assertion, but buyer beware, in the new parallel test world you don't want to be using ScenarioContext.Current but you should be requesting a ScenarioContext instance (or some other specific context class you've written) through the step class constructor

darrencauthon commented 8 years ago

@samholder That is correct... I'm going to have to record a new video!!!! :)

dirkrombauts commented 8 years ago

@lucenty this is caused by the visual studio integration component reads the code in a different way from the runtime component of SpecFlow. As of now, this is difficult to solve in a general way. You might want to look at the visual studio extension code and see if there is a simple fix to solve this particular issue.

An alternate approach would be that if the integration component detects multiple matches, it could show a list similar to the one shown when a step definition is used in multiple scenarios.

StarWars999123 commented 6 years ago

The issue is still open and occured for me too.

vukdanilovic commented 5 years ago

Hey guys, Specflow is binding two different sentences to the same method -

Test scenario - image

Method name - image

Also, "as draft" is highlighted as a parameter, although it is not.

Do you know where I'm making mistake?

SabotageAndi commented 5 years ago

The problem is your Regex. (.*) catches nearly everything. In you case it could help, if you add ' (single quotes) around your parameters.

vukdanilovic commented 5 years ago

That solved my problem. Thanks for help and fast answer!