Skip to content

Commit

Permalink
refactor: vastly simplify guinness2 by removing all context.
Browse files Browse the repository at this point in the history
Almost everything that guinness does to keep track of suites
and tests is now also handles by package test. So, instead
of keeping tons of complex logic around, simply defer
to package:test functions when possible.

BREAKING CHANGE:

`iit` and `ddescribe` NO LONGER modify which tests will run. Instead,
they will mark those blocks with the tag "solo". To run only
`iit` or `ddescribe` blocks, use the command line
`pub run test --tags solo` (the same command you would use before,
with the additional tags "solo").

See #1
  • Loading branch information
juliemr committed Feb 11, 2016
1 parent a0ff1a5 commit d296e04
Show file tree
Hide file tree
Showing 24 changed files with 43 additions and 1,239 deletions.
33 changes: 7 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Guinness2 is a port of the Jasmine library to Dart. It is based on the AngularDa
Backed by `dart:test` instead of `dart:unittest`. Run via `pub run test` instead of a Karma setup.

Removed bits referring to 'runner' programatically - just use `pub run test`. Removed deprecated
showStats option.
showStats option. Remove all context-keeping, as this is now handles by package:test directly.

## Installation

Expand Down Expand Up @@ -41,7 +41,7 @@ Guinness specs are comprised of `describe`, `it`, `beforeEach`, and `afterEach`
```dart
import 'package:guinness2/guinness2.dart';
main(){
main() {
describe("syntax", () {
beforeEach(() {
print("outer before");
Expand Down Expand Up @@ -81,8 +81,7 @@ This will print:
* To exclude an `it`, change it to `xit`.
* To make a `describe` exclusive, change it to `ddescribe`.
* To make an `it` exclusive, change it to `iit`.

If there is an `iit` in your spec files, Guinness will run only `iit`s. In this case `ddescribe`s will be ignored.
* *Important:* to run exclusive tests, add `--tags solo` to your command line invocation.


### Pending Specs
Expand All @@ -92,11 +91,9 @@ Guinness supports pending describe and it blocks (blocks without a callback).
```dart
describe("pending describe");
xdescribe("pending xdescribe");
ddescribe("pending ddescribe");
it("pending it");
xit("pending xit");
iit("pending iit");
```

## Async
Expand Down Expand Up @@ -264,29 +261,13 @@ expect(s.invoke(1,2)).toEqual(3);

You can also use the `mock` and `dart_mocks` libraries with it.

## Status

There are a few things that are still not supported (e.g., handling named parameters in expectations).

## Implementation Details

### Key Ideas

The main idea is to treat the Jasmine syntax as a domain specific language. Therefore,
the implementation clearly separates such things as: syntax, semantic model, and execution model. Let's quickly look
at the benefits this approach provides:

#### The semantic model is separate from the syntax.

The semantic model consists of It, Describe, Suite, BeforeEach, and AfterEach objects. You can create and analyse
them without using the context-dependent nested Jasmine syntax.

#### The parsing of specs is separate from the execution of specs.

The library builds a tree of the It, Describe, Suite, BeforeEach, and AfterEach objects first. And after that,
as a separate step, executes them. It enables all sorts of preprocessing (e.g., filtering, reordering).

#### Pluggable backends.
Dart's `package:test` supports most of the original Guinness test organization natively,
so we simply forward to the appropriate `package:test` function.

Since the library is a DSL, there can be multiple backend libraries actually executing the specs. By default,
the library comes with the test backend.
The large exception is expectations, matchers, and spies, which are unchanged
from original Guinness.
2 changes: 1 addition & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:html';
class TestClass {}

main() {
GuinnessEnableHtmlMatchers();
guinnessEnableHtmlMatchers();

describe("guinness2", () {
it("has various built-in matchers", () {
Expand Down
7 changes: 1 addition & 6 deletions lib/guinness2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,17 @@ import 'dart:math' as math;

export 'package:test/test.dart' show TestOn;

part 'src/common/model.dart';
part 'src/common/context.dart';
part 'src/common/syntax.dart';
part 'src/common/expect.dart';
part 'src/common/spy.dart';
part 'src/common/interfaces.dart';
part 'src/common/guinness_config.dart';
part 'src/common/test_backend.dart';
part 'src/common/exclusive_visitor.dart';
part 'src/common/suite_info.dart';

class _Undefined {
const _Undefined();
}
const _u = const _Undefined();

final Guinness guinness = new Guinness(
matchers: new TestMatchers(),
initSpecs: testInitSpecs);
matchers: new TestMatchers());
43 changes: 0 additions & 43 deletions lib/src/common/context.dart

This file was deleted.

26 changes: 0 additions & 26 deletions lib/src/common/exclusive_visitor.dart

This file was deleted.

23 changes: 1 addition & 22 deletions lib/src/common/guinness_config.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
part of guinness2;

class Guinness {
Context _context = new Context();
dynamic matchers;
SpecRunner _initSpecs;
bool autoInit = true;

Guinness({this.matchers, SpecRunner initSpecs})
: _initSpecs = initSpecs {
_scheduleAutoInit();
Guinness({this.matchers}) {
}

SpyFunction createSpy([String name]) => new SpyFunction(name);

SpyFunction spyOn(obj, String name) {
throw "Not implemented";
}

void initSpecs() {
_initSpecs(_context.suite);
}

void resetContext([Context context]) {
_context = context == null ? new Context() : context;
}

SuiteInfo suiteInfo() => _suiteInfo(_context.suite);

void _scheduleAutoInit() {
async.scheduleMicrotask(() {
if (autoInit) initSpecs();
});
}
}
8 changes: 0 additions & 8 deletions lib/src/common/interfaces.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
part of guinness2;

typedef void SpecRunner(Suite suite);

abstract class SpecVisitor {
void visitSuite(Suite suite);
void visitDescribe(Describe describe);
void visitIt(It it);
}

abstract class Matchers {
dynamic get config;

Expand Down
123 changes: 0 additions & 123 deletions lib/src/common/model.dart

This file was deleted.

0 comments on commit d296e04

Please sign in to comment.