ApprovalTests....Moving the assemblies after compile

442 views Asked by At

First up, great library!

If I compile, then move the assemblies when I verify it still looks for the *.approved.txt in the location it was compiled in, which in my case no longer exists.

I'm running into this issue on Teamcity where we build and test in separate tasks. So the build step will build in c:\BuildAgent\SomeGuid... I take the artifacts from the build and run the tests in c:\BuildAgent\SomeOtherGuid... This fails as Approvals.Verify still references "SomeGuid"

[Fact]
public void ShouldCreateCorrectOutgoingFiles() {
    var textToVerfiy = "Here's some text To Verify";
    Approvals.Verify(textToVerfiy);
}

...

: System.IO.DirectoryNotFoundException : Could not find a part of the path 'r:\w\254cbbd5ec9b56bc\project\ScenarioTests\myTests'.
Stack Trace:
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
   at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
   at System.IO.Directory.CreateDirectory(String path)
   at ApprovalTests.ApprovalTextWriter.WriteReceivedFile(String received)
   at ApprovalTests.Approvers.FileApprover.Approve()
   at ApprovalTests.Core.Approvals.Verify(IApprovalApprover approver, IApprovalFailureReporter reporter)
   at ApprovalTests.Approvals.Verify(IApprovalWriter writer, IApprovalNamer namer, IApprovalFailureReporter reporter)
   at ApprovalTests.Approvals.Verify(IApprovalWriter writer)
   at ApprovalTests.Approvals.Verify(String text)

Any ideas on how I can tweak it to look in relative directory to executable.

1

There are 1 answers

1
llewellyn falco On BEST ANSWER

You have to write a custom namer. It's pretty easy. Take a look at these files.

http://bit.ly/IApprovalNamer

http://bit.ly/XUnitStackTraceParser

http://bit.ly/AttributeStackTraceParser

Once you do that, you'll have to register the namer for use, to do that simply call.

Approvals.RegisterDefaultNamerCreation(()=> new MyCustomNamer());