0

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

Kezza
  • 736
  • 9
  • 25

1 Answers1

0

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)

AlSki
  • 6,868
  • 1
  • 26
  • 39
  • Thanks for that, I think that I was experiencing a different problem as on one particular step where the last parameter was a character, for some reason it would read all the other lines in the scenario and include these as the parameter value, then throw an exception saying that it was expecting a char type. I had then done all sorts of variations and starting assuming that as the editor wasn't picking it up as a char then the test would fail. Anyway thanks for directing me to the known bug I'll try and re-create the problem I was having before and perhaps raise a new question. – Kezza Apr 24 '13 at 09:29