<commit_before>var Q = require('q');
var assert = require('assert');

var app = require('../../lib/app');
var App = app.App;

var tester = require('../../lib/tester/tester');
var AppTester = tester.AppTester;

var tasks = require('../../lib/tester/tasks');
var AppTesterTasks = tasks.AppTesterTasks;
var AppTesterTaskSet = tasks.AppTesterTaskSet;


var ToyTasks = AppTesterTasks.extend(function(self, tester) {
    AppTesterTasks.call(self, tester);

    self.name = function() {
        return 'toys';
    };

    self.validate = function(name) {
        if (name == 'bad') {
            throw new Error();
        }
    };

    self.methods.lerp = function(obj) {
        obj.lerped = true;
        return obj;
    };

    self.methods.lerp.larp = function(obj) {
        self.methods.lerp(obj);
        obj.larped = true;
        return obj;
    };

    self.methods.foo = {};

    self.methods.foo.bar = function(obj) {
        obj.barred = true;
        return obj;
    };

    self.methods.foo.baz = function(obj) {
        obj.bazzed = true;
        return obj;
    };
});


var FlyingToyTasks = ToyTasks.extend(function(self, tester) {
    ToyTasks.call(self, tester);

    self.name = function() {
        return 'flying_toys';
    };

    var methods = self.methods;
    self.methods = {};
    self.methods.flying = methods;
});

describe("AppTesterTasks", function() {
    var tester;
    var tasks;

    beforeEach(function() {
        tester = new AppTester(new App('start'));
        tasks = new ToyTasks(tester);
        tester.tasks.add('toys', tasks);
    });

    describe(".attach", function() {
        it("should attach its methods to the tester", function() {
            assert(!('lerp' in tester));
            assert(!('foo' in tester));

            tasks.attach();

            var obj = {};
            return tester
                .foo.bar(obj)
                .foo.baz(obj)
                .lerp(obj)
                .lerp.larp(obj)
                .run()
                .then(function() {
                    assert.deepEqual(obj, {
                        barred: true,
                        bazzed: true,
                        lerped: true,
                        larped: true
                    });
                });
        });
        
        it("should build the methods' task names", function() {
            tasks.attach();
            assert.equal(tester.foo.bar.__task_name__, 'foo.bar');
            assert.equal(tester.foo.baz.__task_name__, 'foo.baz');<commit_msg>Improve AppTesterTask tests a bit<commit_after>var Q = require('q');
var assert = require('assert');

var app = require('../../lib/app');
var App = app.App;

var tester = require('../../lib/tester/tester');
var AppTester = tester.AppTester;

var tasks = require('../../lib/tester/tasks');
var AppTesterTasks = tasks.AppTesterTasks;
var AppTesterTaskSet = tasks.AppTesterTaskSet;


var ToyTasks = AppTesterTasks.extend(function(self, tester) {
    AppTesterTasks.call(self, tester);

    self.name = function() {
        return 'toys';
    };

    self.validate = function(name) {
        if (name == 'bad') {
            throw new Error();
        }
    };

    self.methods.lerp = function() {
        self.data.record.push('lerped');
    };

    self.methods.lerp.larp = function() {
        self.data.record.push('larped');
    };

    self.methods.foo = {};

    self.methods.foo.bar = function() {
        self.data.record.push('barred');
    };

    self.methods.foo.baz = function() {
        self.data.record.push('bazzed');
    };
});


var FlyingToyTasks = ToyTasks.extend(function(self, tester) {
    ToyTasks.call(self, tester);

    self.name = function() {
        return 'flying_toys';
    };

    var methods = self.methods;
    self.methods = {};
    self.methods.flying = methods;
});

describe("AppTesterTasks", function() {
    var tester;
    var tasks;
    var record;

    beforeEach(function() {
        tester = new AppTester(new App('start'));
        tasks = new ToyTasks(tester);
        tester.tasks.add('toys', tasks);
        record = tasks.data.record = [];
    });

    describe(".attach", function() {
        it("should attach its methods to the tester", function() {
            assert(!('lerp' in tester));
            assert(!('foo' in tester));

            tasks.attach();

            return tester
                .foo.bar()
                .foo.baz()
                .lerp()
                .lerp.larp()
                .run()
                .then(function() {
                    assert.deepEqual(record, [
                        'barred',
                        'bazzed',
                        'lerped',
                        'larped'
                    ]);
                });
        });
        
        it("should build the methods' task names", function() {
            tasks.attach();
            assert.equal(tester.foo.bar.__task_name__, 'foo.bar');
            assert.equal(tester.foo.baz.__task_name__, 'foo.baz');
{'fraction_non_alphanumeric': 0.14871897518014413, 'fraction_numerical': 0.0, 'mean_word_length': 1.7410861217772902, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4987336', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1452, 'n_words': 290}