Specflow.StepInterceptor

Allows a collection of Actions to be invoked before or after a step type seamlessly. E.g. Invoke .build() on a builder when the first 'When' step is called. Removing the need for a filler step to build the object.


Keywords
Specflow, specflow-plugin
License
GPL-3.0
Install
Install-Package Specflow.StepInterceptor -Version 1.0.22

Documentation

Specflow.StepInterceptor

Allows a collection of Actions to be invoked before or after a step type seamlessly.

E.g. Invoke .build() on a builder just before the first When step is called. Removing the need for a filler step to build the object.

Build status

Usage

  • Build repo
  • Add Specflow.StepInterceptor reference to your specs project
  • Add library reference to your app.config
  <specFlow>
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
    <stepAssemblies>
      <stepAssembly assembly="Specflow.StepInterceptor" />
    </stepAssemblies>
  </specFlow>

Example

    [Binding]
    public class ShopSteps
    {
        private Shop _shop;
        private ShopBuilder _shopBuilder;
        private readonly StepInterceptorBuilder _stepInterceptorBuilder;

        public ShopSteps(Shop shop, StepInterceptorBuilder stepInterceptorBuilder, ShopBuilder shopBuilder)
        {
            _shop = shop;         
            _stepInterceptorBuilder = stepInterceptorBuilder;            
            _shopBuilder = shopBuilder;

            _stepInterceptorBuilder.BeforeWhen(() =>
            {
                _shop = _shopBuilder.Build();
            });
        }

        [Given(@"I call my shop '(.*)' in the builder")]
        public void GivenTheReturnWasCreatedOn(string shopName)
        {
            _shopBuilder.WithName(shopName);
        }

        [When(@"The shop object is built by the inceptor")]
        public void WhenTheShopObjectIsBuiltByTheInceptor()
        {
            Console.Out.WriteLine("Builder invoked automatically");
        }
        
        [Then(@"My shop object is populated with the name '(.*)'")]
        public void ThenMyShopObjectIsPopulatedWithTheName(string name)
        {
            _shop.Name.Should().Be(name);
        }

    }