Successfully reported this slideshow.
Your SlideShare is downloading. ×

Test::WWW::Stub

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
ICHIGEKI-MT 2015/03/14
ICHIGEKI-MT 2015/03/14
Loading in …3
×

Check these out next

1 of 38 Ad

More Related Content

Slideshows for you (20)

Similar to Test::WWW::Stub (20)

Advertisement

Recently uploaded (20)

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

×