#[macro_export] macro_rules! reqwest_test { ($fn_name:ident, $stub:literal, $($(.$meth:ident($( $arg:expr ),*))+),+) => { paste::paste! { // blocking #[test] #[stubr::mock($stub)] fn []() { #[allow(unused_imports)] use asserhttp::*; $(reqwest::blocking::get(stubr.uri()).unwrap()$( .$meth($($arg),*) )+;)+ } #[test] #[stubr::mock($stub)] fn []() { #[allow(unused_imports)] use asserhttp::*; $(reqwest::blocking::get(stubr.uri())$( .$meth($($arg),*) )+;)+ } // async #[tokio::test] #[stubr::mock($stub)] async fn []() { #[allow(unused_imports)] use asserhttp::*; $(reqwest::get(stubr.uri()).await$( .$meth($($arg),*) )+;)+ } #[tokio::test] #[stubr::mock($stub)] async fn []() { #[allow(unused_imports)] use asserhttp::*; $(reqwest::get(stubr.uri()).await.unwrap()$( .$meth($($arg),*) )+;)+ } } }; ($fn_name:ident, $stub:literal, $panic_msg:literal, $($(.$meth:ident($( $arg:expr ),*))+),+) => { paste::paste! { // blocking #[should_panic(expected = $panic_msg)] #[stubr::mock($stub)] #[test] fn []() { #[allow(unused_imports)] use asserhttp::*; $(reqwest::blocking::get(stubr.uri()).unwrap()$( .$meth($($arg),*) )+;)+ } #[should_panic(expected = $panic_msg)] #[stubr::mock($stub)] #[test] fn []() { #[allow(unused_imports)] use asserhttp::*; $(reqwest::blocking::get(stubr.uri())$( .$meth($($arg),*) )+;)+ } // async #[should_panic(expected = $panic_msg)] #[stubr::mock($stub)] #[tokio::test] async fn []() { #[allow(unused_imports)] use asserhttp::*; $(reqwest::get(stubr.uri()).await.unwrap()$( .$meth($($arg),*) )+;)+ } #[should_panic(expected = $panic_msg)] #[stubr::mock($stub)] #[tokio::test] async fn []() { #[allow(unused_imports)] use asserhttp::*; $(reqwest::get(stubr.uri()).await$( .$meth($($arg),*) )+;)+ } } }; ($fn_name:ident, $stub:literal, $error:expr, $($(.$meth:ident($( $arg:expr ),*))+),+) => { paste::paste! { // blocking #[stubr::mock($stub)] #[test] fn []() { #[allow(unused_imports)] use asserhttp::*; $(assert_eq!(reqwest::blocking::get(stubr.uri()).unwrap()$( .$meth($($arg),*) )+.unwrap_err(), $error);)+ } #[stubr::mock($stub)] #[test] fn []() { #[allow(unused_imports)] use asserhttp::*; $(assert_eq!(reqwest::blocking::get(stubr.uri())$( .$meth($($arg),*) )+.unwrap_err(), $error);)+ } // async #[stubr::mock($stub)] #[tokio::test] async fn []() { #[allow(unused_imports)] use asserhttp::*; $(assert_eq!(reqwest::get(stubr.uri()).await.unwrap()$( .$meth($($arg),*) )+.unwrap_err(), $error);)+ } #[stubr::mock($stub)] #[tokio::test] async fn []() { #[allow(unused_imports)] use asserhttp::*; $(assert_eq!(reqwest::get(stubr.uri()).await$( .$meth($($arg),*) )+.unwrap_err(), $error);)+ } } }; }