This project is read-only.

Test incorrectly showing as passed

Nov 25, 2009 at 11:03 AM

I have tried to run the following code through various test runners.  Although it should fail the second assertion it is showing as passed.  If I invalidate the first assertion then this shows correctly as a failed specification.  I am guessing the reason for the different behaviour is due to the use of a parameter in the second assertion.  Please can someone help me?

story.WithScenario("No year of account")
                .Given("An Oracle Input Importer", () => importer = CreateOracleInputImporter())
                .And("There is no year of account", () => yearOfAccountRepository.Expect(x => x.Get(2008)).Return(null))
                .When("Performing the import",
                      () => ex = CatchException(() => importer.MapExcelInputToDomainObject(sampleExcelData)))
                .Then("Should result in Excel Import Exception", () => ex.ShouldBeInstanceOfType(typeof(ExcelImportException)))                               
                .And("The error message should be say %errorMessage", "This is wrong", expectedError => ex.Message.ShouldEqual(expectedError));
Dec 2, 2009 at 4:19 PM

Which version are you using? If you arent using 0.4.5.183 I suggest you download that and try it.

I ran the following with nbehave-console.exe v0.4.8.183 and got an exception on the second outcome as expected.

    	[Story]
    	public void Throw_ex()
    	{
            var throwingStory = new Story("Throw");
			Exception ex = null;

            throwingStory
                .AsA("x")
                .IWant("y")
                .SoThat("z");

            throwingStory
                .WithScenario("throw")
            	.Given("an exception", ()=> ex = new ApplicationException("err"))
            	.When("nothing", ()=>{})
            	.Then("exception should be $ex", typeof(ApplicationException), e => ex.ShouldBeInstanceOfType(e))
            	.And("exception msg should be $msg", "this is wrong", e=> ex.Message.ShouldEqual(e));
    	}

        [Story]
        public void Throw_ex()
        {
            var throwingStory = new Story("Throw");
            Exception ex = null;

            throwingStory
                .AsA("x")
                .IWant("y")
                .SoThat("z");

            throwingStory
                .WithScenario("throw")
                .Given("an exception", ()=> ex = new ApplicationException("err"))
                .When("nothing", ()=>{})
                .Then("exception should be $ex", typeof(ApplicationException), e => ex.ShouldBeInstanceOfType(e))
                .And("exception msg should be $msg", "this is wrong", e=> ex.Message.ShouldEqual(e));
        }

Dec 2, 2009 at 4:22 PM

Ah, now I see it, you must at least change %errorMessage to $errorMessage in the last step.