Question

I am having a real hard time figuring out what is going wrong with my spec flow feature in VS2012 and or VS2010

I am simply unable to use a single character as a parameter in a step if that character is contained anywhere else in the expression of the step

It never parses correctly and I have tried doing all sorts including using quotes etc, but it would appear that using a single character is just not possible.

Please can someone confirm this is expected or a know issue or even that I am just doing something wrong?

I have tried using SpecFlow 1.9.1 and 1.9.2 (the latest) but neither work.

A simple example that shows my problem would be the following feature/steps

Feature

Feature: Test1
    In order to check the id of an object using a character
    As a frustrated developer
    I want to define a step with a single char as a parameter

@mytag
Scenario: Test single char param of character existing in phrase
    Given I have an array of 8 characters   
    Then the array should contain the character a

Scenario: Test single char param of character not existing in phrase
    Given I have an array of 8 characters   
    Then the array should contain the character z

Steps

public class TestSpecFlow1Steps
{
    char[] charArray = new char[] { 'a', 'b', 'c', 'd', 'e', 'x', 'y', 'z' };

    [Given(@"I have an array of (.*) characters")]
    public void CheckArrayCount(int arrayCount)
    {
        Assert.AreEqual(charArray.Length, arrayCount);
    }


    [Then(@"the array should contain the character (.*)")]
    public void CheckCharaExists(char val)
    {
        Assert.AreEqual(true, charArray.Contains(val));
    }

}

Any help with this would be gratefully accepted.

thanks

Was it helpful?

Solution

I think this is a known bug in SpecFlow's VS addin. The Regex that they use to apply the formatting finds the wrong character as shown in the first Then. However that doesn't mean that there is anything wrong with your test. As you can see here the tests pass.

enter image description here

(Oops just spotted that you said exactly that above, when you update your question, I'll update this answer)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top