fluent_assertions 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new54

The Fluent Assertions library written in Dart.

It uses Dart's Extension Functions to provide a fluent wrapper around test assertions.

Usage #

Basic Assertions

These assertions are available for all objects.

Equality
'Hello'.shouldBeEqualTo('Hello');
'Hello'.shouldNotBeEqualTo('Word');
Reference equality
final me = Person(name: 'Karol');
final someoneElse = Person(name: 'Karol');
me.shouldBe(me);
me.shouldNotBe(someoneElse);
Subtypes
const num numberOfGirlsIAttract = 0;
numberOfGirlsIAttract.shouldBeInstanceOf<int>();
numberOfGirlsIAttract.shouldNotBeInstanceOf<double>();
Nullability
const hello = 'Hello';
hello.shouldNotBeNull();
const hello = null;
hello.shouldBeNull();
Booleans
const hasChildren = true;
hasChildren.shouldBeTrue();
hasChildren.shouldNotBeFalse();
const hasChildren = false;
hasChildren.shouldBeFalse();
hasChildren.shouldNotBeTrue();

Numerical Assertions

2.shouldBeGreaterOrEqualTo(2);
2.shouldBeGreaterThan(1);
2.shouldBeLessOrEqualTo(2);
1.shouldBeLessThan(2);
1.shouldBePositive();
1.shouldNotBeNegative();
(-1).shouldBeNegative();
(-1).shouldNotBePositive();
0.shouldBeZero();
1.shouldNotBeZero();
0.999.shouldBeNear(1, delta: 0.01);
0.shouldNotBeInRange(lowerBound: 1, upperBound: 6);
1.shouldBeInRange(lowerBound: 1, upperBound: 6);

CharSequence Assertions

Collection Assertions

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

0.2.0 #

Added assertions for numerical values.

0.1.0 #

Added assertions for:

  • Equality
  • Reference Equality
  • Nullability
  • Boolean
  • Subtype

example/fluent_assertions_example.dart

import 'package:test/test.dart';
import 'package:fluent_assertions/fluent_assertions.dart';

void main() {
  const adult = Person(name: 'Karol', age: 30);
  const teenager = Person(name: 'Karyna', age: 17);

  test('different persons should not be equal', () {
    adult.shouldNotBeEqualTo(teenager);
  });

  test('person name should not be null', () {
    adult.name.shouldNotBeNull();
  });

  test('person age should be integer', () {
    adult.age.shouldBeInstanceOf<int>();
  });

  test('a person over 18 should be adult', () {
    adult.isAdult.shouldBeTrue();
  });

  test('an adult person should be over 18', () {
    adult.age.shouldBeGreaterOrEqualTo(18);
  });

  test('a teenager can driver a car', () {
    teenager.age.shouldBeGreaterThan(16);
  });

  test('a teenager should be below 18', () {
    teenager.age.shouldBeLessThan(18);
  });

  test('a teenager should be below 18', () {
    teenager.age.shouldBeInRange(lowerBound: 0, upperBound: 17);
  });

  test('a person age should be positive', () {
    teenager.age.shouldBePositive();
  });
}


class Person {
  final String name;
  final int age;
  bool get isAdult => age >= 18;

  const Person({
    this.name,
    this.age,
  });

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
          other is Person &&
              runtimeType == other.runtimeType &&
              name == other.name &&
              age == other.age;

  @override
  int get hashCode => name.hashCode ^ age.hashCode;

  @override
  String toString() => '$name ($age)';
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fluent_assertions: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fluent_assertions/fluent_assertions.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
15
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
82
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Maintenance suggestions

The package description is too short. (-18 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
test ^1.14.4 1.15.2
Transitive dependencies
_fe_analyzer_shared 5.0.0
analyzer 0.39.12
args 1.6.0
async 2.4.2
boolean_selector 2.0.0
charcode 1.1.3
collection 1.14.13 1.15.0-nnbd
convert 2.1.1
coverage 0.14.0
crypto 2.1.5
csslib 0.16.1
glob 1.2.0
html 0.14.0+3
http 0.12.1
http_multi_server 2.2.0
http_parser 3.1.4
io 0.3.4
js 0.6.2
logging 0.11.4
matcher 0.12.8
meta 1.2.1
mime 0.9.6+3
node_interop 1.1.1
node_io 1.1.1
node_preamble 1.4.12
package_config 1.9.3
path 1.7.0
pedantic 1.9.1
pool 1.4.0
pub_semver 1.4.4
shelf 0.7.7
shelf_packages_handler 2.0.0
shelf_static 0.2.8
shelf_web_socket 0.2.3
source_map_stack_trace 2.0.0
source_maps 0.10.9
source_span 1.7.0
stack_trace 1.9.5
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
test_api 0.2.17
test_core 0.3.10
typed_data 1.2.0 1.3.0-nnbd
vm_service 4.1.0
watcher 0.9.7+15
web_socket_channel 1.1.0
webkit_inspection_protocol 0.7.3
yaml 2.2.1
Dev dependencies
lint ^1.2.0