How to configure ReSharper to format MSpec tests in a readable manner?

I would like to configure ReSharper in a way that Code Cleanup automatically formats my tests as readable as possible.

The following things I couldn't figure out and would appreciate some help:

1) Remove the spaces inside the "fish" symbol:

Because of = () =>  { }

should be formatted a:


Because of =()=>  { }

2) If the code is a single expression, move it to a new line and indent:

Because of =()=> result = sut.DetectChanges(obj, obj);

should be formatted as:

Because of =()=>
     result = sut.DetectChanges(obj, obj);

3) If the code is a block that contains only a single line, it should be changed to an expression:

Establish context =()=> { obj = new Simple("value"); };

should be formatted as:

Establish context =()=>
     obj = new Simple("value");

If that's not possible, at least it should be formatted like this:

Establish context =()=>
{
     obj = new Simple("value");
};

4) Add blank lines around MSpec specific parts:

    public class when_the_same_object_is_passed_in_as_current_and_previous : with_initialized_SUT
     {
         static Simple obj;
         static IEnumerable<Change> result;
         Establish context =()=>

            obj = new Simple("value");
         Because of =()=>

            result = sut.DetectChanges(obj, obj);
         It should_return_no_changes =()=>

            result.ShouldBeEmpty();
     }


should be formatted as:

    public class when_the_same_object_is_passed_in_as_current_and_previous : with_initialized_SUT
    {
        static Simple obj;
        static IEnumerable<Change> result;

        Establish context =()=>

            obj = new Simple("value");

        Because of =()=>

            result = sut.DetectChanges(obj, obj);

        It should_return_no_changes =()=>

            result.ShouldBeEmpty();
    }


Is any of this possible? I would appreciate any pointers.
If the settings "mess up" normal code, that's fine, I am using separate settings for my unit test projects anyway. (As described here: http://blogs.jetbrains.com/dotnet/2012/01/per-project-settings-or-how-to-have-different-naming-styles-for-my-test-project/)


Thanks,

Daniel

2 comments

For code analysis, where tests don't follow the usual guidelines, it would be great to be able to tell R# to ignore certain files.

0

Please sign in to leave a comment.