-
-
Save ainame/8712383 to your computer and use it in GitHub Desktop.
こういうテストを書こうとしたら、末端のsubtestでbeforeの処理が実行されて欲しくなる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnigns; | |
use Test::More; | |
use Test::More::Hooks; | |
package Foo { | |
sub new{ bless { counter => $_[1] }, $_[0]; } | |
sub count_up { shift->{counter} += shift; } | |
}; | |
subtest '100で初期化した時' => sub { | |
my $sut; | |
before { $sut = Foo->new(100) }; | |
# count_upに引数を与えると、Fooオブジェクトの状態が変わるとする | |
subtest '#count_upについて' => sub { | |
subtest '10を引数に与えたら' => sub { | |
is $sut->count_up(10), 110, '110が変える'; | |
}; | |
subtest '100を引数に与えたら' => sub { | |
# ここではbeforeは実行されないのでテスト通らない | |
is $sut->count_up(100), 200, '200が変える'; | |
}; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment