For a little background, I'm a contributor to SquishIt and decided that I should start cleaning up the mess of unit tests (my updated version of one set of tests vs. original set of tests). After tackling only part of the "rewrite", I figured it would be a good opportunity to learn, try, and understand BDD style testing to hopefully help improve the unit tests being written and ran. I decided to go with NSpec after taking a look at some of the choices out there.
My problem is simply trying to break the tests down into the appropriate "groupings" that logically make sense and "conform" to xSpec. Here is what I've done so far and passes all tests as expected:
using NSpec;
using SquishIt.Framework;
using SquishIt.Framework.JavaScript;
namespace SquishIt.Tests
{
class describe_JavaScriptBundle : nspec
{
public JavaScriptBundle bundle;
public void AddTest1JS()
{
bundle.Add("test.js");
}
}
class when_I_create_a_bundle : describe_JavaScriptBundle
{
void before_each()
{
if (bundle == null)
{
bundle = Bundle.JavaScript();
}
}
void and_add_no_files()
{
it["GroupBundles containskey default"] = () => bundle.GroupBundles.ContainsKey("default").is_true();
it["has no Assets"] = () => bundle.GroupBundles["default"].Assets.Count.Is(0);
}
}
class then_I_add_a_file : when_I_create_a_bundle
{
void before_each()
{
AddTest1JS();
}
void it_should_contain_only_one_file()
{
bundle.GroupBundles["default"].Assets.Count.Is(1);
}
}
class then_I_add_the_same_file : then_I_add_a_file
{
void it_should_still_contain_only_one_file()
{
bundle.GroupBundles["default"].Assets.Count.Is(1);
}
}
}
How can I improve this or am I already on the right track?