<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by chenxu zhao on Medium]]></title>
        <description><![CDATA[Stories by chenxu zhao on Medium]]></description>
        <link>https://medium.com/@zztczcx?source=rss-35f6e266f657------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tXNWUwFIUbhFLz_T</url>
            <title>Stories by chenxu zhao on Medium</title>
            <link>https://medium.com/@zztczcx?source=rss-35f6e266f657------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 03:20:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zztczcx/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Fell into an RSpec Pitfall and Failed the Interview]]></title>
            <link>https://medium.com/@zztczcx/how-i-fell-into-an-rspec-pitfall-and-failed-the-interview-56a7d57ff631?source=rss-35f6e266f657------2</link>
            <guid isPermaLink="false">https://medium.com/p/56a7d57ff631</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[rspec]]></category>
            <dc:creator><![CDATA[chenxu zhao]]></dc:creator>
            <pubDate>Wed, 30 Jul 2025 02:04:30 GMT</pubDate>
            <atom:updated>2025-07-30T02:17:10.740Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1M1U4dXoeMwhSHTzWeEWng.png" /></figure><h3>The Interview Challenge</h3><p>Recently, I was invited to complete a take-home coding exercise as part of the interview process with one of my favourite banking companies.</p><p>The exercise wasn’t particularly difficult. In fact, the instructions clearly stated:</p><blockquote><em>“We’re not looking for a polished solution — just something that meets the requirements, or attempts to, that we can then have a conversation about.”</em></blockquote><p>Encouraged by that, I jumped in immediately.</p><p>I set up the project using dry-rb as the CLI boilerplate, implemented graceful validation, and separated concerns by layering the validation and business logic. Once I had a working solution, I even went a step further and refactored the core logic using the <strong>Strategy</strong> design pattern to better align with SOLID principles.</p><p>Of course, I included RSpec tests and a well-documented README. It wasn’t over-engineered — just clean, well-organized code that solved the problem. I felt confident it was more than good enough for a first-round technical screen.</p><p>Then I submitted it… and waited.</p><p>A week later, I received a response:</p><blockquote><em>“Unfortunately, we won’t be proceeding.”</em></blockquote><p>That stung a bit — especially when I learned the reason: the reviewer couldn’t run the code or the tests. They pointed to an error triggered by a super call in one of the methods.</p><h3>The Surprising Discovery</h3><p>My first reaction was disbelief. How could there be errors when I had tested everything multiple times and seen all my RSpec tests pass?</p><p>When I tried running the second example from my README, it indeed raised errors:</p><pre>$ ruby term_deposit_calc.rb calculate --principal 5000 --rate 2.5 --term 2 --frequency quarterly</pre><pre>Argument Error: wrong number of arguments (given 1, expected 0)<br>Run &#39;term_deposit_calc.rb calculate --help&#39; for usage information.</pre><p>This made me wonder why my RSpec tests hadn’t caught this issue. Had I made a last-minute change without properly testing it?</p><h3>The Root Cause</h3><p>After careful analysis, I discovered an interesting issue that I believe is a quirk in RSpec. Here’s how I figured it out.</p><p>My editor had given me a code style suggestion based on the default RuboCop rule:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmbfF0sBX_etuekm-Hj03g.png" /></figure><p>I added super, thinking it wouldn’t do any harm. If the parent class happened to define an initialize method, I didn’t want to miss it. In hindsight, I should’ve thought twice about that decision — especially since, in this context, calling super didn’t actually make sense.</p><p>After this one-line change, I ran the RSpec tests:</p><pre>bundle exec rspec<br>Finished in 0.0183 seconds (files took 0.30766 seconds to load)<br>6 examples, 0 failures </pre><p>Since no errors were reported, I assumed everything was fine.</p><p>However, in my code, I called exit 1 when rescuing an ArgumentError. Since exit 1 raises a SystemExit exception, it triggered an interesting (and subtle) behavior in RSpec.</p><p>In RSpec, if a SystemExit is raised and not properly handled, it can cause subsequent tests to silently not run — with no clear indication of failure.</p><p>This behavior has been discussed in Github for nearly a decade. For example:</p><ul><li><a href="https://github.com/rspec/rspec-core/issues/2246">rspec-core#2246</a>: <em>Unhandled SystemExit causes later specs to silently not run</em></li><li><a href="https://github.com/rspec/rspec-core/issues/2413">rspec-core#2413</a>: <em>If the code under test calls </em><em>exit, failures become passes (overall)</em></li></ul><p>Both issues were eventually closed without a concrete fix. As one maintainer explained:</p><blockquote><em>“We can’t tell where a programmatic SystemExit occurs — it may be from your code under test, but it could also be from external factors.”</em></blockquote><p>In my case, I had split my tests across two RSpec files. But because of the unhandled SystemExit, only one of them actually ran — and I didn’t notice.</p><h3>How to Avoid This Mistake</h3><p>Here are three ways to prevent this kind of issue:</p><ul><li><strong>Run tests in random order</strong>: After setting config.order = :random, the tests will run in a random sequence, which can help expose failures. When I did this, I immediately saw the problems:</li></ul><pre>Finished in 0.02251 seconds (files took 0.30153 seconds to load)<br>10 examples, 6 failures</pre><ul><li><strong>Set up CI through GitHub Actions</strong>: Although RSpec didn’t show any failures in the terminal, it still exited with code 1 — which would have caused the CI pipeline to fail.</li><li><strong>Configure your shell prompt to display exit codes with colour</strong>: This visual indicator can alert you when something’s wrong, even if there’s no explicit error message.</li></ul><p>It’s a real shame that such a small mistake cost me an opportunity with a company I was genuinely excited about. Still, I hope that by sharing this experience, others can avoid falling into the same trap in their own coding journey.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — <br>This experience also made me miss how tests run in Go . I really wish RSpec had an option to enforce running all test files, similar to how Go does it.</p><pre>go test ./...</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56a7d57ff631" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>