Skip to content

Commit

Permalink
Automated deployment: Tue Mar 26 17:33:18 UTC 2024 9f2956b
Browse files Browse the repository at this point in the history
  • Loading branch information
nrxus committed Mar 26, 2024
1 parent 5f3783a commit 960d317
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 83 deletions.
20 changes: 10 additions & 10 deletions blog/an-inside-look.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h1 id="-an-inside-look-"><a class="header" href="#-an-inside-look-">🔍 an ins
let mut client = NetworkClient::faux();

faux::when!(client.fetch).then(|i| {
assert_eq!(i, 3, &quot;expected service to send '3'&quot;);
assert_eq!(i, 3, "expected service to send '3'");
10
});

Expand All @@ -191,7 +191,7 @@ <h1 id="-an-inside-look-"><a class="header" href="#-an-inside-look-">🔍 an ins
</span><span class="boring"> let mut client = NetworkClient::faux();
</span><span class="boring">
</span><span class="boring"> faux::when!(client.fetch).then(|i| {
</span><span class="boring"> assert_eq!(i, 3, &quot;expected service to send '3'&quot;);
</span><span class="boring"> assert_eq!(i, 3, "expected service to send '3'");
</span><span class="boring"> 10
</span><span class="boring"> });
</span><span class="boring">
Expand Down Expand Up @@ -512,9 +512,9 @@ <h3 id="injecting-mock-methods"><a class="header" href="#injecting-mock-methods"
Self(MaybeNetworkClient::Fake(mock_store)) =&gt; {
mock_store
// retrieve the mock using the name of the function
.get_mock(&quot;fetch&quot;)
.get_mock("fetch")
// check the mock was setup; panic if it was not
.expect(&quot;no mock found for method 'fetch'&quot;)
.expect("no mock found for method 'fetch'")
// pass in fetch's parameter to the mocked method
.call(a)
}
Expand Down Expand Up @@ -565,10 +565,10 @@ <h3 id="injecting-mock-methods"><a class="header" href="#injecting-mock-methods"
match &amp;mut self.0 {
MaybeNetworkClient::Fake(store) =&gt; When {
store,
method_name: &quot;fetch&quot;,
method_name: "fetch",
_marker: std::marker::PhantomData,
},
MaybeNetworkClient::Real(_) =&gt; panic!(&quot;cannot mock a real instance&quot;),
MaybeNetworkClient::Real(_) =&gt; panic!("cannot mock a real instance"),
}
}
}
Expand Down Expand Up @@ -631,9 +631,9 @@ <h3 id="injecting-mock-methods"><a class="header" href="#injecting-mock-methods"
</span><span class="boring"> Self(MaybeNetworkClient::Fake(mock_store)) =&gt; {
</span><span class="boring"> mock_store
</span><span class="boring"> // retrieve the mock using the name of the function
</span><span class="boring"> .get_mock(&quot;fetch&quot;)
</span><span class="boring"> .get_mock("fetch")
</span><span class="boring"> // check the mock was setup; panic if it was not
</span><span class="boring"> .expect(&quot;no mock found for method 'fetch'&quot;)
</span><span class="boring"> .expect("no mock found for method 'fetch'")
</span><span class="boring"> // pass in fetch's parameter to the mocked method
</span><span class="boring"> .call(a)
</span><span class="boring"> }
Expand All @@ -646,10 +646,10 @@ <h3 id="injecting-mock-methods"><a class="header" href="#injecting-mock-methods"
</span><span class="boring"> match &amp;mut self.0 {
</span><span class="boring"> MaybeNetworkClient::Fake(store) =&gt; When {
</span><span class="boring"> store,
</span><span class="boring"> method_name: &quot;fetch&quot;,
</span><span class="boring"> method_name: "fetch",
</span><span class="boring"> _marker: std::marker::PhantomData,
</span><span class="boring"> },
</span><span class="boring"> MaybeNetworkClient::Real(_) =&gt; panic!(&quot;cannot mock a real instance&quot;),
</span><span class="boring"> MaybeNetworkClient::Real(_) =&gt; panic!("cannot mock a real instance"),
</span><span class="boring"> }
</span><span class="boring"> }
</span><span class="boring">}
Expand Down
4 changes: 2 additions & 2 deletions blog/introducing-faux.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ <h2 id="example"><a class="header" href="#example">Example</a></h2>
faux::when!(client.fetch_id_matching).then(|i| {
// we want to test do_stuff(), which should always call
// fetch_id_matching with the input 3.
assert_eq!(i, 3, &quot;expected service to send '3'&quot;);
assert_eq!(i, 3, "expected service to send '3'");
// mock fetch_id_matching to always return 10
10
});
Expand All @@ -206,7 +206,7 @@ <h2 id="example"><a class="header" href="#example">Example</a></h2>
</span><span class="boring">
</span><span class="boring"> // mock fetch_id_matching
</span><span class="boring"> faux::when!(client.fetch_id_matching).then(|i| {
</span><span class="boring"> assert_eq!(i, 3, &quot;expected service to send '3'&quot;);
</span><span class="boring"> assert_eq!(i, 3, "expected service to send '3'");
</span><span class="boring"> 10
</span><span class="boring"> });
</span><span class="boring">
Expand Down
16 changes: 8 additions & 8 deletions blog/landing-v-0-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ <h2 id="the-old-faux"><a class="header" href="#the-old-faux">The old faux</a></h
let mut bus_client = bus::Client::faux();

let expected_stops = vec![bus::StopInfo {
id: String::from(&quot;1_1234&quot;),
direction: String::from(&quot;N&quot;),
name: String::from(&quot;some bus&quot;),
id: String::from("1_1234"),
direction: String::from("N"),
name: String::from("some bus"),
lat: 34.3199,
lon: 23.12005,
}];
Expand Down Expand Up @@ -212,7 +212,7 @@ <h2 id="the-old-faux"><a class="header" href="#the-old-faux">The old faux</a></h
</span><span class="boring">
</span><span class="boring"> let actual_stops = subject
</span><span class="boring"> .bus_stops(&amp;area)
</span><span class="boring"> .expect(&quot;expected a succesful bus stop response&quot;);
</span><span class="boring"> .expect("expected a succesful bus stop response");
</span><span class="boring">
</span><span class="boring"> assert_eq!(actual_stops, expected_stops);
</span>}
Expand All @@ -230,9 +230,9 @@ <h2 id="the-new-faux"><a class="header" href="#the-new-faux">The new faux</a></h
let mut bus_client = bus::Client::faux();

let expected_stops = vec![bus::StopInfo {
id: String::from(&quot;1_1234&quot;),
direction: String::from(&quot;N&quot;),
name: String::from(&quot;some bus&quot;),
id: String::from("1_1234"),
direction: String::from("N"),
name: String::from("some bus"),
lat: 34.3199,
lon: 23.12005,
}];
Expand Down Expand Up @@ -262,7 +262,7 @@ <h2 id="the-new-faux"><a class="header" href="#the-new-faux">The new faux</a></h
</span><span class="boring">
</span><span class="boring"> let actual_stops = subject
</span><span class="boring"> .bus_stops(&amp;area)
</span><span class="boring"> .expect(&quot;expected a succesful bus stop response&quot;);
</span><span class="boring"> .expect("expected a succesful bus stop response");
</span><span class="boring">
</span><span class="boring"> assert_eq!(actual_stops, expected_stops);
</span>}
Expand Down
32 changes: 16 additions & 16 deletions guide/exporting-mocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ <h1 id="exporting-mocks-across-crates"><a class="header" href="#exporting-mocks-
your structs when testing their own library or application.</p>
<blockquote>
<p>The solution explored in this chapter applies not only to <code>faux</code> but
to any &quot;test&quot; code you want to export across crates.</p>
to any "test" code you want to export across crates.</p>
</blockquote>
<p>To better explain, let's start with an example. Let's say we are
building a graphics rendering library, <code>testable-renderer</code>. As
expected, <code>faux</code> is declared in <code>dev-dependencies</code></p>
<pre><code class="language-toml">[package]
name = &quot;testable-renderer&quot;
name = "testable-renderer"

[dev-dependencies]
faux = &quot;^0.1&quot;
faux = "^0.1"
</code></pre>
<p>And the code uses mocks:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">extern crate faux;
Expand Down Expand Up @@ -210,15 +210,15 @@ <h1 id="exporting-mocks-across-crates"><a class="header" href="#exporting-mocks-
faux::when!(renderer.render).then(|_| Ok(()));

let subject = Texture {};
subject.render(&amp;mut renderer).expect(&quot;failed to render the texture&quot;)
subject.render(&amp;mut renderer).expect("failed to render the texture")
}
}
<span class="boring">
</span><span class="boring">fn main() {
</span><span class="boring"> let mut renderer = Renderer::faux();
</span><span class="boring"> faux::when!(renderer.render).then(|_| Ok(()));
</span><span class="boring"> let subject = Texture {};
</span><span class="boring"> subject.render(&amp;mut renderer).expect(&quot;failed to render the texture&quot;)
</span><span class="boring"> subject.render(&amp;mut renderer).expect("failed to render the texture")
</span><span class="boring">}</span></code></pre></pre>
<h2 id="faux-as-a-feature"><a class="header" href="#faux-as-a-feature"><code>faux</code> as a feature</a></h2>
<p>For the mocks to be exported, they need to be built even outside of
Expand All @@ -228,12 +228,12 @@ <h2 id="faux-as-a-feature"><a class="header" href="#faux-as-a-feature"><code>fau
<pre><code class="language-toml">[dependencies]
# set up an optional feature outside of dev-dependencies so that users
# of this library can use our mocks in their own tests
faux = { version = &quot;^0.1&quot;, optional = true }
faux = { version = "^0.1", optional = true }

[dev-dependencies]
# our tests still depend on faux; so add it again but do not make it
# optional
faux = &quot;^0.1&quot;
faux = "^0.1"
</code></pre>
<p>Note that we still include <code>faux</code> in <code>dev-dependencies</code>. Our tests are
always dependent on <code>faux</code>, since they use mocks, so the dependency is
Expand All @@ -246,14 +246,14 @@ <h2 id="gating-mocks-to-feature-flag"><a class="header" href="#gating-mocks-to-f
created when that flag is turned on. This is accomplished using the
<code>any</code> attribute:</p>
<pre><pre class="playground"><code class="language-rust">// mocks are available for both test and the faux feature flag
#[cfg_attr(any(test, feature = &quot;faux&quot;), faux::create)]
#[cfg_attr(any(test, feature = "faux"), faux::create)]
pub struct Renderer {
/* snip */
<span class="boring"> _inner: u8,
</span>}

// mocks are available for both test and the faux feature flag
#[cfg_attr(any(test, feature = &quot;faux&quot;), faux::methods)]
#[cfg_attr(any(test, feature = "faux"), faux::methods)]
impl Renderer {
pub fn new() -&gt; Renderer {
/* snip */
Expand All @@ -273,7 +273,7 @@ <h2 id="gating-mocks-to-feature-flag"><a class="header" href="#gating-mocks-to-f
<pre><pre class="playground"><code class="language-rust">#[cfg_attr(test, ...)]
<span class="boring">fn main()</span></code></pre></pre>
<p>with</p>
<pre><pre class="playground"><code class="language-rust">#[cfg_attr(any(test, feature = &quot;faux&quot;), ...)]
<pre><pre class="playground"><code class="language-rust">#[cfg_attr(any(test, feature = "faux"), ...)]
<span class="boring">fn main()</span></code></pre></pre>
<p>This tells Rust to use the <code>faux</code> attributes (<code>create</code> and <code>methods</code>)
for either <code>test</code> or the <code>faux</code> feature flag. You can learn more about
Expand Down Expand Up @@ -344,7 +344,7 @@ <h2 id="using-the-faux-feature"><a class="header" href="#using-the-faux-feature"
# important so features turned on by dev-dependencies don't infect the
# binary when doing a normal build. This lets us have different feature
# flags in dev-dependencies vs normal dependencies.
resolver = &quot;2&quot;
resolver = "2"

[dependencies]
# our normal dependency does not activate `faux`, thus keeping it out of
Expand All @@ -354,15 +354,15 @@ <h2 id="using-the-faux-feature"><a class="header" href="#using-the-faux-feature"
[dev-dependencies]
# for tests, we activate the `faux` feature in our dependency so that
# we can use the exposed mocks
testable-renderer = { version = &quot;*&quot;, features = [&quot;faux&quot;] }
testable-renderer = { version = "*", features = ["faux"] }

# still depend on `faux` so we can use setup the mocks
faux = &quot;^0.1&quot;
faux = "^0.1"
</code></pre>
<p>The important takeaways are:</p>
<ul>
<li>
<p><code>resolver = &quot;2&quot;</code>. This is needed so <code>faux</code> stays out of our normal
<p><code>resolver = "2"</code>. This is needed so <code>faux</code> stays out of our normal
builds. See the <a href="https://doc.rust-lang.org/nightly/cargo/reference/features.html#feature-resolver-version-2">Cargo Reference</a>.</p>
</li>
<li>
Expand All @@ -383,7 +383,7 @@ <h2 id="using-the-faux-feature"><a class="header" href="#using-the-faux-feature"
faux::when!(renderer.render).then(|_| Ok(()));

let world = World::new();
world.render(&amp;mut renderer).expect(&quot;failed to render the world&quot;)
world.render(&amp;mut renderer).expect("failed to render the world")
}
}

Expand All @@ -403,7 +403,7 @@ <h2 id="recap"><a class="header" href="#recap">Recap</a></h2>
to:</p>
<ul>
<li>
<p>Change the feature resolver to &quot;2&quot; in its <code>Cargo.toml</code>. Be aware
<p>Change the feature resolver to "2" in its <code>Cargo.toml</code>. Be aware
that if you are using a workspace, this needs to be changed in the
workspace's <code>Cargo.toml</code>.</p>
</li>
Expand Down
10 changes: 5 additions & 5 deletions guide/getting-started.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h1 id="getting-started"><a class="header" href="#getting-started">Getting Start
<h2 id="installation"><a class="header" href="#installation">Installation</a></h2>
<p><code>faux</code> should be added under <code>[dev-dependencies]</code> in <code>Cargo.toml</code>.</p>
<pre><code class="language-toml">[dev-dependencies]
faux = &quot;^0.1&quot;
faux = "^0.1"
</code></pre>
<p>This makes sure that <code>faux</code> only gets included when compiling and
running tests, thus making it impossible to leak into production code.</p>
Expand Down Expand Up @@ -373,7 +373,7 @@ <h3 id="example"><a class="header" href="#example">Example</a></h3>
</span><span class="boring"> let subject = Concierge::new(client);
</span><span class="boring"> let options = Options { /* snip */ };
</span><span class="boring"> let reservation = subject
</span><span class="boring"> .reserve_matching(options).expect(&quot;expected successful reservation&quot;);
</span><span class="boring"> .reserve_matching(options).expect("expected successful reservation");
</span><span class="boring">
</span><span class="boring"> assert_eq!(reservation, expected_reservation);
</span><span class="boring">
Expand All @@ -385,7 +385,7 @@ <h3 id="example"><a class="header" href="#example">Example</a></h3>
</span><span class="boring"> let options = Options { /* snip */ };
</span><span class="boring"> let error = subject
</span><span class="boring"> .reserve_matching(options)
</span><span class="boring"> .expect_err(&quot;expected error reservation&quot;);
</span><span class="boring"> .expect_err("expected error reservation");
</span><span class="boring">
</span><span class="boring"> assert!(matches!(error, Error::NoReservations));
</span><span class="boring">}
Expand Down Expand Up @@ -417,7 +417,7 @@ <h3 id="example"><a class="header" href="#example">Example</a></h3>
let options = Options { /* snip */ };
let reservation = subject
.reserve_matching(options)
.expect(&quot;expected successful reservation&quot;);
.expect("expected successful reservation");

assert_eq!(reservation, expected_reservation);
}
Expand All @@ -431,7 +431,7 @@ <h3 id="example"><a class="header" href="#example">Example</a></h3>
let options = Options { /* snip */ };
let error = subject
.reserve_matching(options)
.expect_err(&quot;expected error reservation&quot;);
.expect_err("expected error reservation");

assert!(matches!(error, Error::NoReservations));
}
Expand Down
Loading

0 comments on commit 960d317

Please sign in to comment.