Skip to content

Commit

Permalink
refactor: refactor tests to use setUp and tearDown
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Dec 12, 2015
1 parent 3edc96b commit cc960d1
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/kp_directory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import 'package:path/path.dart';
import 'package:test/test.dart';

void main() {
var tempDir;

setUp(() {
tempDir = Directory.systemTemp.createTempSync();
});

tearDown(() {
tempDir.deleteSync(recursive: true);
});

group("makeEmptySync", () {
test("it makes the directory empty", () {
// make a tempdir
final tempDir = Directory.systemTemp.createTempSync();

// make sure it is empty
expect(tempDir.listSync().isEmpty, isTrue);

Expand All @@ -20,33 +27,25 @@ void main() {

makeEmptySync(tempDir);
expect(tempDir.listSync().isEmpty, isTrue);
tempDir.deleteSync(recursive: true);
});
});

group("createFileSync", () {
test("it creates a file", () {
final tempDir = Directory.systemTemp.createTempSync();

final file = getFile(tempDir, 'hello_world.txt')..createSync();
expect(file.existsSync(), isTrue);
tempDir.deleteSync(recursive: true);
});
});

group("createDirSync", () {
test("it creates a dir", () {
final tempDir = Directory.systemTemp.createTempSync();

final dir = getDirectory(tempDir, 'hello_world')..createSync();
expect(dir.existsSync(), isTrue);
tempDir.deleteSync(recursive: true);
});
});

group("copySync", () {
test("it does copy", () {
final tempDir = Directory.systemTemp.createTempSync();
final fileInTempDir = getFile(tempDir, 'hello_world.txt')..createSync();

final newDir = Directory.systemTemp.createTempSync();
Expand All @@ -59,7 +58,6 @@ void main() {

expect(basename(newDir.listSync()[0].path), basename(fileInTempDir.path));
newDir.deleteSync(recursive: true);
tempDir.deleteSync(recursive: true);
});
});
}

0 comments on commit cc960d1

Please sign in to comment.