Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Test::WWW::Stub
Shibuya Perl Mongersテクニカルトーク#17 LT
2015/06/02 @ast_j (GitHub astj / hatena id:astj)
HTTPリクエストする
モジュールのテストを安全に
LWPで
Test::WWW::Stub
外部アクセスのモック
use Test::WWW::Stub;
!
my $stubbed_res = [ 200, [], ['okay'] ];
my $guard = Test::WWW::Stub->register(
q<http://example.co...
"http://b.hatena.ne.jp/hotentry.rss"
qr<http://*[.]hatenablog[.]com/rss>
URI
[ 200, [], 'OK']
sub { [ 200, [], 'OK']; }
res
外部アクセスのブロック
LWP経由の全てのリクエストを塞ぐ
モックされてないリクエストにはdiag
use Test::WWW::Stub;
my $ua = LWP::UserAgent->new;
!
$ua->get('http://example.com/HOGE');
# Unexpected external access: GE...
類似モジュール
• Test::Mock::LWP
• Mock::LWP::Request
• Test::Mock::LWP::Conditional
• Test::Mock::LWP::Dispatch
• Test::LWP::MockSocket:...
useするだけで外部アクセスを塞げる
インターフェースがシンプル
PSGI res/appが使える
Why Test::WWW::Stub
LWP::Protocol::PSGI?
Your Code
!
LWP
HTTP
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Test::WWW::Stub
Upcoming SlideShare
Loading in …5
×

Test::WWW::Stub

2,529 views

Published on

2015/06/02 Shibuya.pm テクニカルトーク #7 LT

Published in: Engineering
  • Be the first to comment

Test::WWW::Stub

  1. 1. Test::WWW::Stub Shibuya Perl Mongersテクニカルトーク#17 LT 2015/06/02 @ast_j (GitHub astj / hatena id:astj)
  2. 2. HTTPリクエストする モジュールのテストを安全に LWPで
  3. 3. Test::WWW::Stub
  4. 4. 外部アクセスのモック
  5. 5. use Test::WWW::Stub; ! my $stubbed_res = [ 200, [], ['okay'] ]; my $guard = Test::WWW::Stub->register( q<http://example.com/TEST>, $stubbed_res ); ! my $ua = LWP::UserAgent->new; ! is $ua->get('http://example.com/TEST')->content, 'okay';
  6. 6. "http://b.hatena.ne.jp/hotentry.rss" qr<http://*[.]hatenablog[.]com/rss> URI [ 200, [], 'OK'] sub { [ 200, [], 'OK']; } res
  7. 7. 外部アクセスのブロック
  8. 8. LWP経由の全てのリクエストを塞ぐ モックされてないリクエストにはdiag
  9. 9. use Test::WWW::Stub; my $ua = LWP::UserAgent->new; ! $ua->get('http://example.com/HOGE'); # Unexpected external access: GET http://example.com/HOGE at t/ hogehoge.t line XX
  10. 10. 類似モジュール
  11. 11. • Test::Mock::LWP • Mock::LWP::Request • Test::Mock::LWP::Conditional • Test::Mock::LWP::Dispatch • Test::LWP::MockSocket::http • and more...
  12. 12. useするだけで外部アクセスを塞げる インターフェースがシンプル PSGI res/appが使える Why Test::WWW::Stub
  13. 13. LWP::Protocol::PSGI?
  14. 14. Your Code ! LWP HTTP

×