use mokito in the init tests

This commit is contained in:
Devon Carew 2015-09-11 16:12:27 -07:00
parent ab441685e2
commit e6b45c5023
4 changed files with 26 additions and 29 deletions

View File

@ -65,13 +65,10 @@ Or if the Sky APK is not already on your device, run:
stdout.addStream(process.stdout);
stderr.addStream(process.stderr);
int code = await process.exitCode;
if (code == 0) {
print('\n${message}');
}
} else {
print(message);
return 2;
if (code != 0) return code;
}
print(message);
return 0;
}
}
@ -146,6 +143,7 @@ name: {{projectName}}
description: {{description}}
dependencies:
sky: any
dev_dependencies:
sky_tools: any
''';

View File

@ -4,11 +4,13 @@
import 'dart:io';
import 'package:args/args.dart';
import 'package:mockito/mockito.dart';
import 'package:path/path.dart' as p;
import 'package:sky_tools/src/init.dart';
import 'package:test/test.dart';
import 'src/common.dart';
main() => defineTests();
defineTests() {
@ -26,10 +28,11 @@ defineTests() {
// Verify that we create a project that is well-formed.
test('init sky-simple', () async {
InitCommandHandler handler = new InitCommandHandler();
_MockArgResults results = new _MockArgResults();
results.values['help'] = false;
results.values['pub'] = true;
results.values['out'] = temp.path;
MockArgResults results = new MockArgResults();
when(results['help']).thenReturn(false);
when(results['pub']).thenReturn(true);
when(results.wasParsed('out')).thenReturn(true);
when(results['out']).thenReturn(temp.path);
await handler.processArgResults(results);
String path = p.join(temp.path, 'lib/main.dart');
expect(new File(path).existsSync(), true);
@ -40,14 +43,3 @@ defineTests() {
});
});
}
class _MockArgResults implements ArgResults {
Map values = {};
operator [](String name) => values[name];
List<String> get arguments => null;
ArgResults get command => null;
String get name => null;
Iterable<String> get options => values.keys;
List<String> get rest => null;
bool wasParsed(String name) => values.containsKey(name);
}

View File

@ -4,11 +4,12 @@
library install_test;
import 'package:args/args.dart';
import 'package:mockito/mockito.dart';
import 'package:sky_tools/src/install.dart';
import 'package:test/test.dart';
import 'src/common.dart';
main() => defineTests();
defineTests() {
@ -23,9 +24,3 @@ defineTests() {
});
});
}
@proxy
class MockArgResults extends Mock implements ArgResults {
@override
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

View File

@ -0,0 +1,12 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/args.dart';
import 'package:mockito/mockito.dart';
@proxy
class MockArgResults extends Mock implements ArgResults {
@override
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}