define(["nifty"], function (nifty) {
    module("nifty.scrutinize", {});
    test("test can scrutinize a pretended object", 2, function () {
        var FooClass = nifty.compose({}, {
            nifty: function (arg1) {
            },
            other: function () {
            }
        });

        var BarClass = nifty.compose({foo: FooClass}, {
            init: function () {
                this.foo.nifty("hello world");
            }
        });

        var bar = nifty.pretend(BarClass);

        nifty.establish(bar.foo, 1).nifty("hello world");
        nifty.scrutinize(bar);
    });
    test("test can overlook methods for a mocked object", 1, function () {
        var FooClass = nifty.compose({}, {
            nifty: function (arg1) {
            },
            other: function () {
            }
        });

        var BarClass = nifty.compose({foo: FooClass}, {
            init: function () {
                this.foo.nifty("hello world");
            }
        });

        var bar = nifty.pretend(BarClass);

        nifty.overlook(bar.foo).nifty();
        nifty.scrutinize(bar);
    });
    test("test can only overlook on mocked object", 1, function () {
        var caughtException = false;
        try {
            nifty.overlook({});
        } catch (e) {
            caughtException = true;
        }
        ok(caughtException, "overlook throws exception on anything but a mocked object");
    });
    test("test using when will overlook methods for a mocked object", function () {
        var FooClass = nifty.compose({}, {
            getStuff: function (arg) {
                return arg;
            }
        });

        var BarClass = nifty.compose({foo: FooClass}, {
            saveStuff: function () {
                this.stuff = this.foo.getStuff("arg1");
            }
        });

        var bar = nifty.pretend(BarClass);
        nifty.when(bar.foo).getStuff("arg1").thenReturn("fake stuff");

        bar.saveStuff();
        equal(bar.getState("stuff"), "fake stuff", "when correctly mocked out function");
        nifty.scrutinize(bar);
    });
    test("test can only when on mocked object", 1, function () {
        var caughtException = false;
        try {
            nifty.when({});
        } catch (e) {
            caughtException = true;
        }
        ok(caughtException, "when throws exception on anything but a mocked object");
    });
});