|
| 1 | +import 'package:clock/clock.dart'; |
| 2 | +import 'package:mason/mason.dart'; |
| 3 | +import 'package:mocktail/mocktail.dart'; |
| 4 | +import 'package:test/test.dart'; |
| 5 | + |
| 6 | +import '../pre_gen.dart' as pre_gen; |
| 7 | + |
| 8 | +class _MockHookContext extends Mock implements HookContext {} |
| 9 | + |
| 10 | +void main() { |
| 11 | + group('pre_gen', () { |
| 12 | + late HookContext context; |
| 13 | + |
| 14 | + setUp(() { |
| 15 | + context = _MockHookContext(); |
| 16 | + }); |
| 17 | + |
| 18 | + test('populates variables', () { |
| 19 | + withClock(Clock.fixed(DateTime(2020)), () { |
| 20 | + final vars = { |
| 21 | + 'project_name': 'my_cli', |
| 22 | + 'executable_name': 'my_cli', |
| 23 | + 'description': 'A Very Good Dart CLI', |
| 24 | + 'publishable': false, |
| 25 | + 'org_name': 'Very Good Ventures', |
| 26 | + }; |
| 27 | + when(() => context.vars).thenReturn(vars); |
| 28 | + |
| 29 | + pre_gen.run(context); |
| 30 | + |
| 31 | + final newVars = |
| 32 | + verify(() => context.vars = captureAny()).captured.last |
| 33 | + as Map<String, dynamic>; |
| 34 | + |
| 35 | + expect( |
| 36 | + newVars, |
| 37 | + equals({ |
| 38 | + 'project_name': 'my_cli', |
| 39 | + 'executable_name': 'my_cli', |
| 40 | + 'description': 'A Very Good Dart CLI', |
| 41 | + 'publishable': false, |
| 42 | + 'org_name': 'Very Good Ventures', |
| 43 | + 'current_year': '2020', |
| 44 | + }), |
| 45 | + ); |
| 46 | + }); |
| 47 | + }); |
| 48 | + }); |
| 49 | +} |
0 commit comments