Build/Test Issues

MSpec tests not run when they contain 'Behaves_like'

Started by SteveDunn on 6,985 views

MSpec has this notion of 'Behaves_like'.

e.g. here's the behaviour
[Behaviors]
public class VehicleThatHasBeenStartedBehaviors
{
  protected static IVehicle vehicle;

  It should_have_a_running_engine = () =>
    vehicle.IsEngineRunning.ShouldBeTrue();

  It should_have_a_running_engine = () =>
    vehicle.IsEngineRunning.ShouldBeTrue();

  It should_be_polluting_the_atmosphere = () =>
    vehicle.IsPolluting.ShouldBeTrue();

  It should_be_idling = () =>
    vehicle.RevCount.ShouldBeBetween(0, 1000);
}


And here's two things in common that use it:
public class when_a_car_is_started
{
  Establish context = () =>
    vehicle = new Car();

  Because of = () =>
    vehicle.StartEngine();

 [b] Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;[/b]

  protected static Car vehicle;
}

public class when_a_motorbike_is_started
{
  Establish context = () =>
    vehicle = new Motorbike();

  Because of = () =>
    vehicle.StartEngine();

 [b] Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;[/b]

  protected static Motorbike vehicle;
}


(taken from this page: http://lostechies.com/jamesgregory/2010/01/18/behaviours-in-mspec/)

This works fine in. The tests run in TestDriven.net and the R# test runner, and NCrunch.

However, if I enclose the tests in another class, e.g. this:

 
public class VehicleSpecs // <<<---- Problems arise when an enclosing class is defined
    {
        [Behaviors]
        public class VehicleThatHasBeenStartedBehaviors
        {
            protected static IVehicle vehicle;

            It should_have_a_running_engine = () =>
                                              vehicle.IsEngineRunning.ShouldBeTrue();

            It should_be_polluting_the_atmosphere = () =>
                                                    vehicle.IsPolluting.ShouldBeTrue();

            It should_be_idling = () =>
                                  vehicle.RevCount.ShouldEqual(1000);
        }

        public class when_a_car_is_started 
        {
            protected static Car vehicle;

            Establish context = () =>
                                vehicle = new Car();

            Because of = () =>
                         vehicle.StartEngine();

            Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;

        }

        public class when_a_motorbike_is_started
        {
            Establish context = () =>
                                vehicle = new Motorbike();

            Because of = () =>
                         vehicle.StartEngine();

            Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;

            protected static Motorbike vehicle;
        }
    }[


NCrunch doesn't run the tests. The TestDriven.net and R# test runners do run the tests. NCruch reports:
This test was not executed during a planned execution run. Ensure your test project is stable and does not contain issues in initialisation/teardown fixtures.


It'd be great to get this fixed as I like to enclose related tests in an enclosed class. Do let me know if I can provide any more information.

Cheers,

Steve.
Hi Steve,

Thanks for reporting this. It looks to me like the code searching for behaviors isn't taking nested classes into account. This should be fixable. I'll see what I can do about sorting it out.


Cheers,

Remco

Post a reply

Log in to reply.