fsprojects / TickSpec

Lean .NET BDD framework with powerful F# integration
Apache License 2.0
133 stars 23 forks source link

Possible improvement on Interactive implementation #43

Closed jkone27 closed 3 years ago

jkone27 commented 3 years ago

the interactive implementation is way different than the other one, isn't there a way to make a consistent way of declaring the steps and just then invoke something like TickSpec.RunInteractive ?

#r "nuget: TickSpec"
//#load "FeatureRunner.fs" <-- avoiding this as all implementation is different, and cannot reuse attributes

open TickSpec
open System.Diagnostics
open System.Reflection
open System.IO
open Swensen.Unquote

type StockItem = { Count : int }

type MyFeature() =

    [<Given>]
    member _. ``a customer buys a black jumper`` () = ()

    [<Given>]
    member _. ``I have (.*) black jumpers left in stock`` (n:int) =
        { Count = n }

    [<When>]
    member _.``he returns the jumper for a refund`` (stockItem:StockItem) =
        { stockItem with Count = stockItem.Count + 1 }

    [<Then>]
    member _.``I should have (.*) black jumpers in stock`` (n:int) (stockItem:StockItem) =
        let passed = (stockItem.Count = n)
        Debug.Assert(passed)

let declaredTypes = [| typeof<MyFeature> |]

let definitions = new StepDefinitions(types = declaredTypes)

let feature1 = __SOURCE_DIRECTORY__ + "/Scenario.feature"

let feature = definitions.GenerateFeature feature1

let scenario = feature.Scenarios |> Seq.head

scenario.Action.Invoke()

Just a suggestion, from the documentation it seems very complicated and much different. I think this could provide benefits e.g. comparing with python behave: https://behave.readthedocs.io/en/latest/

Something like the above doesnt seem to work, as parsing is not effecting, might be issues with reflection, though we have a declared type in FSI, probably that part is not working as expected...

val scenario : Scenario =
  { Name = "Scenario: Refunded items should be returned to stock"
    Description =
                 "    Given a customer buys a black jumper
    And I have 2 bl"+[119 chars]
    Action = TickSpec.Action
    Parameters = [||]
    Tags = [||] }
val it : unit = ()
mchaloupka commented 3 years ago

Hi,

I am trying to understand what is the ask here. Is it to make the interactive mode simpler? Or is the mentioned script not working?

In the first case, can you suggest how it should ideally look like? In the other case, can you please provide the feature file and let us know which .NET are you using and what error do you get.

Thanks, Milos

jkone27 commented 3 years ago

I am using the feature file from tickspec example docs (just has different name Scenario.feature), using NET5, and F# interactive in a .fsx script. I saw there is a different version for the interactive mode and that works, but this one couldn't parse my feature file correctly maybe? will check better , thanks a lot for the quick reply!

Feature: Refunded or replaced items should be returned to stock

Scenario: Refunded items should be returned to stock
    Given a customer buys a black jumper
    And I have 3 black jumpers left in stock
    When he returns the jumper for a refund
    Then I should have 4 black jumpers in stock
mchaloupka commented 3 years ago

Hi, have you figured it out? If so, would you mind sharing? It could help others and may be a nice contribution if interested. If not, let us know if you need more help.

jkone27 commented 3 years ago

Unfortunately I didn't figure out in the end, and just used the standard advised interactive way