samedi 7 mars 2015

TickSpec: How do I use the same step name in different features?

I am fiddling around with the Gilded Rose kata in F#. I am writing my tests in TickSpec and FsUnit so that they essentially mirror Jim Weirich's Gilded Rose tests written in RSpec.


When I run them in Visual Studio's Test Explorer, I get the following error:



Ambiguous step definition
(AgedBrieSpecs.I update the quality|NormalItemSpecs.I update the quality)
on line 5 in Feature: Aged Brie quality updates
"When I update the quality"


Basically, I'm trying to use the same function name in different features. But they are in different modules. I could even put them in different namespaces, but that doesn't help either.


So then, how do I use step names that happen to be the same, but in different features? Am I just "doing it wrong"?


My feature text and counterpart F# code is as follows:


NormalItemFeature.txt:



Feature: Normal item quality updates

Scenario 1: Each day the sell-in value decreases by one
Given a normal item with a sell-in value of 10
When I update the quality
Then its sell-in value should be 9


AgedBrieFeature.txt:



Feature: Aged Brie quality updates

Scenario 1: Each day the sell-in value decreases by one
Given Aged Brie with a sell-in value of 10
When I update the quality
Then its sell-in value should be 9


NormalItemSpec.fs:



module GildedRoseCsSpecs.NormalItemSpecs

open FsUnit
open TickSpec
open System.Linq
open GildedRoseCs

let mutable rose = GildedRose([].ToList())
let item = Item(Name = "Normal Item", SellIn = 10, Quality = 5)

let [<Given>] ``a normal item with a sell-in value of (\d+)`` (sellIn : int) =
item.SellIn <- sellIn

let [<When>] ``I update the quality`` () =
rose <- GildedRose([item].ToList())
rose.UpdateQuality()

let [<Then>] ``its sell-in value should be (\d+)`` (sellIn : int) =
rose.Items.First().SellIn |> should equal sellIn


AgedBrieSpecs.fs:



module GildedRoseCsSpecs.AgedBrieSpecs

open FsUnit
open TickSpec
open System.Linq
open GildedRoseCs

let mutable rose = GildedRose([].ToList())
let item = Item(Name = "Aged Brie", SellIn = 10, Quality = 5)

let [<Given>] ``Aged Brie with a sell-in value of (\d+)`` (sellIn : int) =
item.SellIn <- sellIn

let [<When>] ``I update the quality`` () =
rose <- GildedRose([item].ToList())
rose.UpdateQuality()

let [<Then>] ``its sell-in value should be (\d+)`` (sellIn : int) =
rose.Items.First().SellIn |> should equal sellIn


And finally, I have the following lines in my Fixtures.fs file:



// FeatureFixture definition omitted for brevity

type NormalItemFeature () = inherit FeatureFixture("NormalItemFeature.txt")
type AgedBrieFeature () = inherit FeatureFixture("AgedBrieFeature.txt")


P.S. Yes, I understand that there is a lot of duplication here that could be consolidated. While this is a contrived example, I can imagine that two entirely different features could have steps with the same descriptive text. It seems to me that TickSpec ought to be able to handle such name collisions.


Aucun commentaire:

Enregistrer un commentaire