TickSpec:如何在不同的功能中使用相同的步骤名称?

时间:2015-03-07 23:54:50

标签: testing f# bdd

我正在摆弄F#中的Gilded Rose kata。我正在TickSpecFsUnit编写测试,因此它们基本上反映了Jim Weirich's Gilded Rose tests中写的RSpec

当我在Visual Studio的测试资源管理器中运行它们时,我收到以下错误:

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"

基本上,我尝试在不同的功能中使用相同的功能名称。但它们处于不同的模块中。我甚至可以将它们放在不同的命名空间中,但这对它们都没有帮助。

那么,我如何使用碰巧相同但步长不同的步骤名称?我只是"做错了"?

我的专题文字和对应的F#代码如下:

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

最后,我在 Fixtures.fs 文件中有以下几行:

// FeatureFixture definition omitted for brevity

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

P.S。是的,我知道这里有一个很多重复,可以合并。虽然这是一个人为的例子,但我可以想象两个完全不同的功能可以使用相同的描述性文本。在我看来,TickSpec应该能够处理这样的名称冲突。

0 个答案:

没有答案