Skip to content

Commit

Permalink
add article for instance double
Browse files Browse the repository at this point in the history
  • Loading branch information
glaucocustodio committed Aug 2, 2024
1 parent 7ab5e7a commit 0a2cf09
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ nav_external_links:
- title: Expect vs should
url: "#expect-vs-should"
hide_icon: true
- title: Instance double over double
url: "#instance-double-over-double"
hide_icon: true
- title: Factories, not fixtures
url: "#factories-not-fixtures"
hide_icon: true
Expand Down
45 changes: 45 additions & 0 deletions _includes/instance_double_over_double.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<article>
<h2 id="instance-double-over-double">
<a href="#instance-double-over-double">
Instance double over double
</a>
</h2>

<p>Instance double ensures the object responds to methods being called, which is not true for double.</p>

<div class="example">
{% highlight ruby %}
class User
def full_name
"#{first_name} #{last_name}"
end
end
{% endhighlight %}
</div>

<div class="bad">
{% highlight ruby %}
it "passes" do
user = double(:user, name: "Ayrton Senna")
puts user.name
end
{% endhighlight %}
</div>

<div class="good">
{% highlight ruby %}
it "fails" do
user = instance_double(User, name: "Ayrton Senna")
puts user.name
end
{% endhighlight %}
</div>

<p>The above test will fail with the following message since the <code>name</code> method really doesn't exist.</p>

<div class="output">
{% highlight text %}
the User class does not implement the instance method: name. Perhaps you meant to use `class_double` instead?
{% endhighlight %}
</div>
</article>
4 changes: 2 additions & 2 deletions _sass/custom/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
}

.output {
color: #bbb;
color: #333;

&::before {
content: "FORMATTED OUTPUT";
content: "OUTPUT";
}
}

Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h2>
{% include group_expectations.html %}
{% include all_possible_cases.html %}
{% include expect_vs_should.html %}
{% include instance_double_over_double.html %}
{% include factories_not_fixtures.html %}
{% include lets_not.html %}
{% include avoid_hooks.html %}
Expand Down

0 comments on commit 0a2cf09

Please sign in to comment.