Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

MSpec tests not run when they contain 'Behaves_like'
SteveDunn
#1 Posted : Thursday, March 15, 2012 6:48:36 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/15/2012(UTC)
Posts: 4

MSpec has this notion of 'Behaves_like'.

e.g. here's the behaviour
Code:
[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:
Code:
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/ja...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:

Code:
 
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:
Quote:
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.
Remco
#2 Posted : Thursday, March 15, 2012 8:51:46 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
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
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.026 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download