Example #1
0
        function (feature) {
            if (feature.annotations.pending) {
                fileCount--;
            }

            before(function (done) {
                if (processed === 0) {
                    return beforeHook.call(global.testscope, beforeEachHook.bind(global.testscope, done));
                }

                beforeEachHook.call(global.testscope, done);
            });

            scenarios(
                feature.scenarios,
                function (scenario) {
                    var stepDefinitions = require('./step-definitions'),
                        yadda = new Yadda.Yadda(stepDefinitions, context);

                    if (runIsolateTestOnly &&
                        !scenario.annotations.isolate &&
                        !scenario.annotations.only
                    ) {
                        return;
                    }

                    steps(
                        scenario.steps,
                        function (step, done) {
                            var context = merge(global.testscope, config.env);

                            if (scenario.annotations.executedBy) {
                                context.browser = context.browser.select(scenario.annotations.executedBy);
                            }

                            yadda.run(step, context, done);
                        }
                    );
                }
            );

            Yadda.EventBus.instance().on(
                Yadda.EventBus.ON_EXECUTE,
                function (event) {
                    currentStep = event.data.step;
                }
            );

            after(function (done) {
                if (++processed === fileCount) {
                    return afterEachHook.call(global.testscope, afterHook.bind(global.testscope, done));
                }

                afterEachHook.call(global.testscope, done);
            });

        }
Example #2
0
var Macro = function(signature, signature_pattern, macro, ctx) {    
    
    var environment = new Environment(ctx);
    var signature_pattern = new RegularExpression(signature_pattern);
    var macro = macro || fn.async_noop;
    var event_bus = EventBus.instance();
    var _this = this;    

    var init = function(signature, signature_pattern) {
        _this.signature = normalise(signature);
    }

    this.is_identified_by = function(other_signature) {
        return this.signature == normalise(other_signature);        
    }; 

    this.can_interpret = function(step) {
        return signature_pattern.test(step);
    };  

    this.interpret = function(step, ctx, next) {   
        var env = environment.merge(ctx);
        var args = signature_pattern.groups(step);
        event_bus.send(EventBus.ON_EXECUTE, { step: step, ctx: ctx, pattern: signature_pattern.toString(), args: args });
        fn.invoke(macro, env.ctx, args.concat(next));            
    };

    this.levenshtein_signature = function() {
        return signature_pattern.without_expressions();            
    };

    var normalise = function(signature) {
        return new RegExp(signature).toString();
    }

    this.toString = function() {
        return this.signature;
    };   

    init(signature, signature_pattern);
};
Example #3
0
var Interpreter = function(libraries) {

    var libraries = $(libraries);
    var event_bus = EventBus.instance();
    var _this = this;

    this.requires = function(libraries) {
        libraries.push_all(libraries);
        return this;
    };

    this.interpret = function(scenario, scenario_context, next) {
        scenario_context = new Context().merge(scenario_context);
        event_bus.send(EventBus.ON_SCENARIO, { scenario: scenario, ctx: scenario_context.properties });        
        var iterator = make_step_iterator(scenario_context, next);
        $(scenario).each_async(iterator, next);
    };

    var make_step_iterator = function(scenario_context, next) {
        var iterator = function(step, index, callback) {
            _this.interpret_step(step, scenario_context, callback);
        };
        return next ? iterator : fn.asynchronize(null, iterator);        
    };

    this.interpret_step = function(step, scenario_context, next) {
        var context = new Context().merge(scenario_context);
        event_bus.send(EventBus.ON_STEP, { step: step, ctx: context.properties });        
        _this.rank_macros(step).clear_winner().interpret(step, context || {}, next);
    };  

    this.rank_macros = function(step) {
        return new Competition(step, compatible_macros(step));
    };

    var compatible_macros = function(step) {
        return libraries.inject([], function(macros, library) {
            return macros.concat(library.find_compatible_macros(step));
        });
    };
};
Example #4
0
 casper.then(function() {
     casper.test.info(step);
     EventBus.instance().send(EventBus.ON_STEP, { step: step, ctx: ctx });        
     _this.rank_macros(step).clear_winner().interpret(step, ctx, next);            
 });