aboutsummaryrefslogtreecommitdiffstats
path: root/test/scenario/SpecRunnerSpec.js
blob: 0926c3f8629adbe443f9d54e0e4c73631122907a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<
require "formula"

class AndroidPlatformTools < Formula
  homepage "http://developer.android.com/sdk"
  # the url is from:
  # http://dl-ssl.google.com/android/repository/repository-8.xml
  url "http://dl-ssl.google.com/android/repository/platform-tools_r19.0.1-macosx.zip"
  version '19.0.1'
  sha1 "340a497e4199d076ea93d4ee0e7a50858344d176"

  conflicts_with 'android-sdk',
    :because => "the Android Platform-tools are part of the Android SDK"

  def install
    bin.install "adb", "fastboot"
  end
end
ref='#n70'>70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
/**
 * Mock of all required UI classes/methods. (UI, Spec, Step).
 */
function UIMock() {
  this.log = [];
}
UIMock.prototype = {
  addSpec: function(spec) {
    var log = this.log;
    log.push('addSpec:' + spec.name);
    return {
      addStep: function(name) {
        log.push('addStep:' + name);
        return {
          finish: function(e) {
            log.push('step finish:' + (e ? e : ''));
            return this;
          },
          error: function(e) {
            log.push('step error:' + (e ? e : ''));
            return this;
          }
        };
      },
      finish: function(e) {
        log.push('spec finish:' + (e ? e : ''));
        return this;
      },
      error: function(e) {
        log.push('spec error:' + (e ? e : ''));
        return this;
      }
    };
  }
};

/**
 * Mock Application
 */
function ApplicationMock($window) {
  this.$window = $window;
}
ApplicationMock.prototype = {
  executeAction: function(callback) {
    callback.call(this.$window);
  }
};

describe('angular.scenario.SpecRunner', function() {
  var $window;
  var runner;

  beforeEach(function() {
    $window = {};
    runner = angular.scope();
    runner.application = new ApplicationMock($window);
    runner.$become(angular.scenario.SpecRunner);
  });

  it('should bind futures to the spec', function() {
    runner.addFuture('test future', function(done) {
      this.application.value = 10;
      done();
    });
    runner.futures[0].execute(angular.noop);
    expect(runner.application.value).toEqual(10);
  });

  it('should pass done to future action behavior', function() {
    runner.addFutureAction('test future', function(done) {
      expect(angular.isFunction(done)).toBeTruthy();
      done(10, 20);
    });
    runner.futures[0].execute(function(error, result) {
      expect(error).toEqual(10);
      expect(result).toEqual(20);
    });
  });

  it('should pass execute future action on the $window', function() {
    runner.addFutureAction('test future', function(done) {
      this.test = 'test value';
      done();
    });
    runner.futures[0].execute(angular.noop);
    expect($window.test).toEqual('test value');
  });

  it('should execute spec function and notify UI', function() {
    var finished = false;
    var ui = new UIMock();
    var spec = {name: 'test spec', fn: function() {
      this.test = 'some value';
    }};
    runner.addFuture('test future', function(done) {
      done();
    });
    runner.run(ui, spec, function() {
      finished = true;
    });
    expect(runner.test).toEqual('some value');
    expect(finished).toBeTruthy();
    expect(ui.log).toEqual([
      'addSpec:test spec',
      'addStep:test future',
      'step finish:',
      'spec finish:'
    ]);
  });

  it('should execute notify UI on spec setup error', function() {
    var finished = false;
    var ui = new UIMock();
    var spec = {name: 'test spec', fn: function() {
      throw 'message';
    }};
    runner.run(ui, spec, function() {
      finished = true;
    });
    expect(finished).toBeTruthy();
    expect(ui.log).toEqual([
      'addSpec:test spec',
      'spec error:message'
    ]);
  });

  it('should execute notify UI on step failure', function() {
    var finished = false;
    var ui = new UIMock();
    var spec = {name: 'test spec', fn: angular.noop};
    runner.addFuture('test future', function(done) {
      done('failure message');
    });
    runner.run(ui, spec, function() {
      finished = true;
    });
    expect(finished).toBeTruthy();
    expect(ui.log).toEqual([
      'addSpec:test spec',
      'addStep:test future',
      'step finish:failure message',
      'spec finish:failure message'
    ]);
  });

  it('should execute notify UI on step error', function() {
    var finished = false;
    var ui = new UIMock();
    var spec = {name: 'test spec', fn: angular.noop};
    runner.addFuture('test future', function(done) {
      throw 'error message';
    });
    runner.run(ui, spec, function() {
      finished = true;
    });
    expect(finished).toBeTruthy();
    expect(ui.log).toEqual([
      'addSpec:test spec',
      'addStep:test future',
      'step error:error message',
      'spec finish:error message'
    ]);
  });

});