From 0a2cf09d4dbf1e948193054670163bd407d7befd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Glauco=20Cust=C3=B3dio?= Date: Fri, 2 Aug 2024 17:16:37 +0100 Subject: [PATCH] add article for instance double --- _config.yml | 3 ++ _includes/instance_double_over_double.html | 45 ++++++++++++++++++++++ _sass/custom/custom.scss | 4 +- index.html | 1 + 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 _includes/instance_double_over_double.html diff --git a/_config.yml b/_config.yml index f07fba6..663fd3d 100644 --- a/_config.yml +++ b/_config.yml @@ -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 diff --git a/_includes/instance_double_over_double.html b/_includes/instance_double_over_double.html new file mode 100644 index 0000000..7c041ee --- /dev/null +++ b/_includes/instance_double_over_double.html @@ -0,0 +1,45 @@ +
+

+ + Instance double over double + +

+ +

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

+ +
+{% highlight ruby %} +class User + def full_name + "#{first_name} #{last_name}" + end +end +{% endhighlight %} +
+ +
+{% highlight ruby %} +it "passes" do + user = double(:user, name: "Ayrton Senna") + puts user.name +end +{% endhighlight %} +
+ +
+{% highlight ruby %} +it "fails" do + user = instance_double(User, name: "Ayrton Senna") + puts user.name +end +{% endhighlight %} +
+ +

The above test will fail with the following message since the name method really doesn't exist.

+ +
+{% highlight text %} +the User class does not implement the instance method: name. Perhaps you meant to use `class_double` instead? +{% endhighlight %} +
+
diff --git a/_sass/custom/custom.scss b/_sass/custom/custom.scss index 620d72e..61dafb8 100644 --- a/_sass/custom/custom.scss +++ b/_sass/custom/custom.scss @@ -31,10 +31,10 @@ } .output { - color: #bbb; + color: #333; &::before { - content: "FORMATTED OUTPUT"; + content: "OUTPUT"; } } diff --git a/index.html b/index.html index 2a00fc1..15bd0ad 100644 --- a/index.html +++ b/index.html @@ -32,6 +32,7 @@

{% 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 %}