Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soh335/test-mock-furl-constraint
https://github.com/soh335/test-mock-furl-constraint
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/soh335/test-mock-furl-constraint
- Owner: soh335
- License: other
- Created: 2013-07-04T05:11:33.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-10-07T12:36:46.000Z (about 11 years ago)
- Last Synced: 2024-10-11T21:11:50.299Z (about 1 month ago)
- Language: Perl
- Size: 200 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
# NAME
Test::Mock::Furl::Constraint - yet another mock module for Furl
# SYNOPSIS
use Test::Mock::Furl::Constraint;
# global
Test::Mock::Furl::Constraint->stub_request(
any => "http://example.com/foo/bar",
{
query => [ baz => 1 ], headers => ...., content => ....
},
)->add( sub {
content => ..., headers => ....,;
})->add( sub {
content => ..., headers => ....,;
});my $furl = Furl->new;
my $res = $furl->get("http://example.com/foo/bar?baz=0"); # bad
my $res = $furl->get("http://example.com/foo/bar?baz=1"); # success# lexical
my $furl = Furl->new;
$furl->stub_request( get => "http://example.com/foo/bar" );
my $res = $furl->get("http://example.com/foo/bar?baz=0"); # ok
$furl->stub_reset;
my $res = $furl->get("http://example.com/foo/bar?baz=0"); # bad# DESCRIPTION
Test::Mock::Furl::Constraint is yet another mock module for Furl.
It provides mock interface for [Furl](http://search.cpan.org/perldoc?Furl).## METHODS
- Test::Mock::Furl::Constraint->stub\_request( method => url, { query => \[...\], headers => \[...\], content => \[\] })
stub Furl::HTTP::request by `url`. if passed `method` as "any" or `method` equal to your request method, stub is accepted. But, if your method not equal to `method`, croak from stub.
`{ query => [...], headers => [...], content => [...] }` is optional condition for stub. Also these condition keys is optional. If you add stub with these optional condition and incorrect request by furl, croak from stub.
You also can stub specific furl instance to call stub\_request method of `$furl` instance. It is higher priority than `Test::Mock::Furl::Constraint->stub_request`.
Default mocked response from stub is this.
(
minor_version => "0",
status => 200,
msg => "ok",
headers => [],
content => "",
)This method return `Test::Mock::Furl::Constraint::Cond`. And you can override response by calling `add` method of it like this.
Test::Mock::Furl::Constraint->stub_request(
method => url
)->add( sub {
content => ..., msg => ..., status ...,
})->add( sub {
content => ...
});If you call `add` method multiply, mocked response is changed order by calling this method. And in this case, Third furl request return second mocked response ( it is last mocked response ).
- Test::Mock::Furl::Constraint->stub\_reset
reset your stub.
## Configuration Variables
- $Test::Mock::Furl::Constraint::DISABLE\_EXTERNAL\_ACCESS
controll furl access to external. If it is true and try to access external, Test::Mock::Furl::Constraint croak. default is true.
# SEE ALSO
[Furl](http://search.cpan.org/perldoc?Furl)
[Test::Mock::Furl](http://search.cpan.org/perldoc?Test::Mock::Furl)
[Test::Mock::LWP::Conditional](http://search.cpan.org/perldoc?Test::Mock::LWP::Conditional)
[https://github.com/bblimke/webmock](https://github.com/bblimke/webmock)
# LICENSE
Copyright (C) soh335.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.# AUTHOR
soh335