<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lucas Rocha</title>
    <description>The latest articles on DEV Community by Lucas Rocha (@lucasgrocha).</description>
    <link>https://dev.to/lucasgrocha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1123106%2F708b94ff-9423-41f3-9346-05b8e86b8e8b.jpg</url>
      <title>DEV Community: Lucas Rocha</title>
      <link>https://dev.to/lucasgrocha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lucasgrocha"/>
    <language>en</language>
    <item>
      <title>That’s why I love interactive rebase</title>
      <dc:creator>Lucas Rocha</dc:creator>
      <pubDate>Thu, 09 Nov 2023 19:51:17 +0000</pubDate>
      <link>https://dev.to/lucasgrocha/thats-why-i-love-interactive-rebase-3a9j</link>
      <guid>https://dev.to/lucasgrocha/thats-why-i-love-interactive-rebase-3a9j</guid>
      <description>&lt;p&gt;You probably already struggled to change a specific commit, rename it, remove it, and anything else. I’m glad to welcome you to the interactive rebase power!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is interactive rebase?
&lt;/h2&gt;

&lt;p&gt;In my words, interactive rebasing allows you to manage anything you want to your commits. You can navigate through the history, pick the commit, and change it as you wish.&lt;/p&gt;

&lt;p&gt;Here’s everything you can do to every single commit:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flucasgrocha.com%2Fimages%2Fthats-why-i-love-interactive-rebase%2Fgit-commands.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flucasgrocha.com%2Fimages%2Fthats-why-i-love-interactive-rebase%2Fgit-commands.png" alt="git commands"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It lets you choose between the options (aka rebase commands) and perform the desired action without running many git commands manually, so you’ll have less work and headache.&lt;/p&gt;

&lt;p&gt;My top ones are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;fixup&lt;/code&gt; (similar to &lt;code&gt;squash&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;reword&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;drop&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;edit&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pick&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can also change history by changing the order of the commits!&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting into practice
&lt;/h2&gt;

&lt;p&gt;Given this highly complex javascript code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;math&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;year&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And the following commits for each function:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# git log --oneline&lt;/span&gt;

eaefd90 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main&lt;span class="o"&gt;)&lt;/span&gt; add year
f576984 add math
1e2458e add foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I want to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edit the &lt;code&gt;math&lt;/code&gt; function&lt;/li&gt;
&lt;li&gt;Rename the &lt;code&gt;year&lt;/code&gt; function commit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Firstly, we must tell the rebase command the range of commits we want to pick from the &lt;a href="https://www.geeksforgeeks.org/git-head/" rel="noopener noreferrer"&gt;HEAD&lt;/a&gt;. There are various ways, but I’ll use the command I most use&lt;/p&gt;

&lt;p&gt;Range from the top (but the initial)&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;~X&lt;/code&gt; is the count of commits from the latest one&lt;/p&gt;

&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pick 7d0bb76 add math
pick 6227988 add year
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Do you remember the rebase commands from the screenshot? Let’s use them now. Rename the &lt;code&gt;pick&lt;/code&gt; by the option you want to apply to a specific commit:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;edit 7d0bb76 add math
reword 6227988 add year
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now save, edit your &lt;code&gt;math&lt;/code&gt; commit changes, commit again, and continue the rebase&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git commit --amend&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git rebase --continue&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A new prompt will open, asking you to insert the update for the &lt;code&gt;add year&lt;/code&gt; commit message.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://lucasgrocha.com/videos/thats-why-i-love-interactive-rebase/rebase.mp4" rel="noopener noreferrer"&gt;
      lucasgrocha.com
    &lt;/a&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  Risk of data loss
&lt;/h2&gt;

&lt;p&gt;Since everything has pros and cons, It wouldn’t be different with interactive rebase, but don’t worry!&lt;/p&gt;

&lt;p&gt;There’s a chance to break the commit history and lose all of your changes. No problem, though. Let's continue using the git power to help us in this case. I have already failed thousands of times doing this, and here are my takeaways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If you are unsure about your rebase, create a backup branch before changing your working one&lt;/li&gt;
&lt;li&gt;Save the commit hash you will change (copy it into a text file, etc.)&lt;/li&gt;
&lt;li&gt;Push your changes to the remote (GitHub, Git Lab, etc…)&lt;/li&gt;
&lt;li&gt;Be aware of &lt;code&gt;git reflog&lt;/code&gt; superpower. With this fantastic tool, you can track all of your changes in your git branch and pull them easily by &lt;code&gt;git cherry-pick &amp;lt;&amp;lt;COMMIT HASH&amp;gt;&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Interactive rebase has way more functions and utilities than this example. Create your experimental repository, play with all the commands from there, and start using it daily.&lt;/p&gt;

&lt;p&gt;Also, don’t be afraid of losing any work. The git tracks ALL the things for you, and the only thing you’ll need to do for a worst-case scenario is figure out how to pull your commit again (&lt;code&gt;git reflog&lt;/code&gt; is the best starting point).&lt;/p&gt;

&lt;p&gt;Commits are malleable, git provides all the tooling, and we are in the ChatGPT age, so why not try out new things? We have countless sources for research and learning.&lt;/p&gt;

&lt;p&gt;Feel free to search and learn more about this fantastic tool! ✨&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Better Code QA - Benefit of Unit Testing</title>
      <dc:creator>Lucas Rocha</dc:creator>
      <pubDate>Tue, 07 Nov 2023 21:28:28 +0000</pubDate>
      <link>https://dev.to/lucasgrocha/better-code-qa-benefit-of-unit-testing-56jh</link>
      <guid>https://dev.to/lucasgrocha/better-code-qa-benefit-of-unit-testing-56jh</guid>
      <description>&lt;p&gt;Did you already find yourself trying to understand a complete rabbit hole code, or do you want to test your brand new bug fix without running a bunch of flows and business rules that may involve third-party endpoint calls?&lt;/p&gt;

&lt;p&gt;Let's try tasting small pieces instead of eating the whole pie.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VQX0l6ky--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwpfarjp54a6n273mc1w.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VQX0l6ky--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwpfarjp54a6n273mc1w.gif" alt="Gif" width="400" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why? What's the benefit?
&lt;/h2&gt;

&lt;p&gt;I already spent countless hours of my day just trying to prove that my code works by running the step-by-step to reproduce the issue, and in the end, I found myself very stressed because most of the time, you'll miss setting some attributes that will conditionally trigger your fix. V*oila,* stress level increased.&lt;/p&gt;

&lt;p&gt;In my personal experience, the benefits are these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster development/comprehensibility&lt;/li&gt;
&lt;li&gt;Faster QA&lt;/li&gt;
&lt;li&gt;Faster CI/CD&lt;/li&gt;
&lt;li&gt;It is more straightforward to track down a flow throughout the codebase&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The painful process
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;I need to create a new user, set their config to this, update this row, update this other thing, and make sure the payload is that… And while you are thinking through all of this, you have to answer some DM's, monitor logs, etc.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There may be a more straightforward way to test your code that doesn't require all these painful steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's play with some code
&lt;/h2&gt;

&lt;p&gt;Consider this concise ruby class that calculates the BMI number and returns &lt;code&gt;true/false&lt;/code&gt; if the user is underweight (you just added this functionality).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;:,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:)&lt;/span&gt;
    &lt;span class="vi"&gt;@weight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;weight&lt;/span&gt;
    &lt;span class="vi"&gt;@height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;bmi&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vi"&gt;@weight&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vi"&gt;@height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="vi"&gt;@height&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;underweight?&lt;/span&gt;
    &lt;span class="n"&gt;bmi&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;18.5&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here are the unit tests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test if the BMI amount is the expected one for the given weight and height&lt;/li&gt;
&lt;li&gt;Test if the given weight and height is underweight or not
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestUser&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Test&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Unit&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;TestCase&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_bmi&lt;/span&gt;
    &lt;span class="n"&gt;assert_equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;15.43&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;weight: &lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;height: &lt;/span&gt;&lt;span class="mf"&gt;1.80&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;bmi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_underweight?&lt;/span&gt;
    &lt;span class="n"&gt;assert_equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;weight: &lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;height: &lt;/span&gt;&lt;span class="mf"&gt;1.80&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;underweight?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;assert_equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;weight: &lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;height: &lt;/span&gt;&lt;span class="mf"&gt;1.80&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;underweight?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, how can I prove that this &lt;code&gt;#underweight?&lt;/code&gt; method work as expected? Someone may say: "It's easy. I know exactly the inputs I need to give to test that method, and I know the output value by calling the &lt;code&gt;#bmi&lt;/code&gt; method.” Yes, you're completely right, It’s already known all the business rules and the flow as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;weight: &lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;height: &lt;/span&gt;&lt;span class="mf"&gt;1.80&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bmi&lt;/span&gt;
&lt;span class="c1"&gt;#&amp;gt; 15.43&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;underweight?&lt;/span&gt; &lt;span class="c1"&gt;# 15.43 is less than 18.5&lt;/span&gt;
&lt;span class="c1"&gt;#&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's forget about the &lt;code&gt;#bmi&lt;/code&gt; for a brief moment so that it doesn't exist anymore. Now, we are entirely blind about what the calculation is. So, how can you prove the &lt;code&gt;#underweight?&lt;/code&gt; method works?&lt;/p&gt;

&lt;h2&gt;
  
  
  Take It Easy
&lt;/h2&gt;

&lt;p&gt;We don't need to know the math behind the BMI calculation. We only need to know the conditions that make the &lt;code&gt;#underweight?&lt;/code&gt; respond precisely to what we want. If the BMI is &lt;code&gt;15&lt;/code&gt;, the expected output is &lt;code&gt;true&lt;/code&gt; since you have this condition: &lt;code&gt;x &amp;lt; 18.5&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;We already know this condition, so we can hard-code the BMI amount and test our method again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;underweight?&lt;/span&gt;
  &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;18.5&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That looks simple, and it is what it is supposed to be, though. It’s the essence of unit testing: mocking values and method’s responses to make the other X method respond to what our automated tests are looking for, and at the end, everything is tested by attacking small pieces per time.&lt;/p&gt;

&lt;p&gt;Now we just have proven that &lt;code&gt;#underweight?&lt;/code&gt; the method works without having to instance the class, providing the right inputs, learning the calculation behind it, and so on. Get the target condition and hard-code the expected information to see Its desired behavior.&lt;/p&gt;

&lt;p&gt;Either &lt;code&gt;15&lt;/code&gt; or &lt;code&gt;&amp;lt; 18.5&lt;/code&gt; could be a completely different condition that could call a lot of methods in the chain, and you would need to know precisely the inputs, Their formats, and conditions behind the scenes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I've been doing this practice for a long time whenever I need to, and since I got this insight, I try to use this approach in my tickets as much as possible. It's effortless and helps me to have an general view depending on the case because I can keep iterating the perspective like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understanding the small pieces&lt;/li&gt;
&lt;li&gt;Take a step further and understand the small pieces from a different part&lt;/li&gt;
&lt;li&gt;Comprehend the whole thing without needing to run the entire thing at once&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>testing</category>
      <category>ruby</category>
      <category>code</category>
      <category>unittest</category>
    </item>
  </channel>
</rss>
