🔬 Insight into code refactoring
Perl6
Latest commit 59f0b77 Feb 23, 2016 @MadcapJake Merge pull request #3 from atweiden/fix-meta
fix provides section

README.md

🔬 Test::Lab

Build Status Issues License Slack

Careful refactoring of critical paths. A port of Github's Scientist to Perl 6.

How do I start a lab?

Use the lab sub to build a default experiment for you:

use Test::Lab;

class MyWidget {
  method is-allowed($user) {
    lab 'widget-permissions', -> $e {
      $e.use: { $!model.check-user($user).is-valid } # old way
      $e.try: { $user.can('read', $!model) } # new way
    }
  }
}

Use the Test::Lab::Experiment class to instantiate a default experiment:

use Test::Lab::Experiment;

class MyWidget {
  method allows($user) {
    my $experiment = Test::Lab::Experiment.new(:name<widget-permissions>);
    $experiment.use: { $!model.check-user($user).is-valid } # old way
    $experiment.try: { $user.can :$!model :read } # new way

    $experiment.run;
  }
}

Change the default Experiment class to publish your results:

class MyExperiment is Test::Lab::Experiment {
  method is-enabled { ... }
  method publish($result) { ... }
}
Test::Lab::<$experiment-class> = MyExperiment;

Now you can use lab as before and it will utilize your own experiment class. This is highly useful as Test::Lab::Default provides no publishing and thus no way to gain access to the results.