<?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: Nick Ang</title>
    <description>The latest articles on DEV Community by Nick Ang (@nickangtc).</description>
    <link>https://dev.to/nickangtc</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%2F343818%2F76169434-0a22-4352-ae32-c7e9f8989a90.jpeg</url>
      <title>DEV Community: Nick Ang</title>
      <link>https://dev.to/nickangtc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nickangtc"/>
    <language>en</language>
    <item>
      <title>2 shortcuts that make referencing code easy in GitHub PRs &amp; Issues</title>
      <dc:creator>Nick Ang</dc:creator>
      <pubDate>Wed, 13 Apr 2022 15:59:49 +0000</pubDate>
      <link>https://dev.to/nickangtc/2-shortcuts-that-make-referencing-code-easy-in-github-prs-issues-530</link>
      <guid>https://dev.to/nickangtc/2-shortcuts-that-make-referencing-code-easy-in-github-prs-issues-530</guid>
      <description>&lt;p&gt;There are two parts to this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;know the command to copy relative file path in your IDE&lt;/li&gt;
&lt;li&gt;know the command to launch "go to file" on a GitHub repo&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;Cmd Shift P&lt;/code&gt; in Visual Studio Code
&lt;/h2&gt;

&lt;p&gt;I mostly use VS Code, which comes with a wonderful command palette that you can summon up with &lt;code&gt;Cmd Shift P&lt;/code&gt; on a Mac. Once summoned, I type "relative" &amp;gt; select File: Copy Relative Path of Active File &amp;gt; hit enter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U2S0Np9Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bnpksal6gjq2z8ozzeb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U2S0Np9Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bnpksal6gjq2z8ozzeb.png" alt="Image description" width="880" height="129"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that I have the relative path, I need to navigate to the corresponding page on GitHub that displays this page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Just &lt;code&gt;T&lt;/code&gt; in a GitHub repo
&lt;/h2&gt;

&lt;p&gt;I open the relevant GitHub repo and simply hit &lt;code&gt;T&lt;/code&gt; on my keyboard to launch the "Go to file" functionality:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IVmIA4IZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1z7pcp4vzsiazulz9kv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IVmIA4IZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1z7pcp4vzsiazulz9kv.png" alt="Image description" width="880" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And you guessed it: &lt;code&gt;Cmd V&lt;/code&gt; to paste, hit enter, and you're at the right page on GitHub!&lt;/p&gt;

&lt;h2&gt;
  
  
  Single or multi-line highlights in GitHub
&lt;/h2&gt;

&lt;p&gt;With those two nifty shortcuts, I've gotten to the right page very quickly. Now all that's left to do is to somehow refer to one or multiple lines of code.&lt;/p&gt;

&lt;p&gt;GitHub makes this easy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;click the starting line number of the code you're interested in&lt;/li&gt;
&lt;li&gt;hold shift&lt;/li&gt;
&lt;li&gt;click ending line number&lt;/li&gt;
&lt;li&gt;copy the URL, which has changed based on your clicks&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Pro tip: hit &lt;code&gt;Y&lt;/code&gt; after selecting the relevant line(s) of code to generate a snapshot of the code you've selected. If you don't do this, there's a chance that you may be referencing the &lt;code&gt;main&lt;/code&gt; branch's code by line number, which could refer to something else in the future. The snapshot prevents this by referring to a specific commit.&lt;/p&gt;

&lt;p&gt;Now I can paste this URL anywhere in GitHub's commenting surfaces like Pull Requests, Issues, or comments and it will either show up as a link or a rich preview. &lt;/p&gt;

&lt;p&gt;What I haven't figured out is why I sometimes get a rich preview and other times it shows up only as a hyperlink. If you know, please comment on this so I can learn. I love those rich previews!&lt;/p&gt;

</description>
      <category>github</category>
      <category>productivity</category>
    </item>
    <item>
      <title>An easy way to automate running Rails test (or any command) on file changes</title>
      <dc:creator>Nick Ang</dc:creator>
      <pubDate>Tue, 12 Apr 2022 19:52:15 +0000</pubDate>
      <link>https://dev.to/nickangtc/an-easy-way-to-automate-running-rails-test-or-any-command-on-file-changes-3n64</link>
      <guid>https://dev.to/nickangtc/an-easy-way-to-automate-running-rails-test-or-any-command-on-file-changes-3n64</guid>
      <description>&lt;p&gt;To my dismay, I realised today while going through unit testing in &lt;em&gt;Agile Web Development with Rails 6 by Ruby, Copeland &amp;amp; Thomas&lt;/em&gt; that the Rails CLI does not ship with a &lt;code&gt;--watch&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;It seems like a pretty jarring piece of missing functionality and I still don't know why it's not built into the CLI, so I &lt;a href="https://discuss.rubyonrails.org/t/why-does-rails-cli-not-come-with-watch-option/80435"&gt;posted a question in the Rails forum&lt;/a&gt; to ask for context, for a start. Let's see how that goes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Jest CLI has it out of the box
&lt;/h2&gt;

&lt;p&gt;Having used Jest CLI for running tests before, I was used to being able to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ jest --watchAll
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;... and have the CLI handle watching files for changes and re-running relevant tests.&lt;/p&gt;

&lt;p&gt;But as I've had to use Rails more recently, and I dug into why this was missing from the Rails CLI, I realised that "running relevant tests based on file changes" is actually quite complex. For example, if I changed a method, how should the watcher communicate to the test runner about which tests to re-run (rather than, say, re-running &lt;em&gt;all&lt;/em&gt; tests)?&lt;/p&gt;

&lt;p&gt;But that's a bit outside of the scope of this post. I brought it up just as a way of doing a head-nod to the complexity behind something like this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter &lt;code&gt;entr&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Anyway, as I sat at my desk thinking about how to make my TDD-ish (test driven development) workflow easier, I realised that &lt;strong&gt;perhaps 50 percent of the usefulness of an automated test runner comes from re-running all tests in a particular test file if it has just been saved&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For that, I learned today that there's a nice command line package called &lt;code&gt;entr&lt;/code&gt; that you can install with &lt;code&gt;homebrew&lt;/code&gt; (macOS).&lt;/p&gt;

&lt;p&gt;Here's how I used it to re-run rails tests based on changes to any file in the /test directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd rails-app
$ find ./test -name '*.rb' | entr -s 'rails test'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will re-run all tests whenever any test file has been re-saved (regardless of whether an actual modification was made). A great first step!&lt;/p&gt;

&lt;h2&gt;
  
  
  There are gems for that
&lt;/h2&gt;

&lt;p&gt;Just a quick note here that what I mentioned is just one of many ways to achieve the same thing. In fact, what I wrote is less convenient if you need to have this available to everyone in a team rather than just for yourself.&lt;/p&gt;

&lt;p&gt;There's a &lt;a href="http://railscasts.com/episodes/264-guard"&gt;video&lt;/a&gt; dated back to 2011 posted in RailsCast about how to use the &lt;code&gt;guard&lt;/code&gt; gem to watch files and run tests. This is probably a better approach if you want to implement test runner automation for a team. There is a boatload of other gems that have slightly different implementations but provide similar functionality - you can see them &lt;a href="https://www.ruby-toolbox.com/categories/continuous_testing"&gt;here&lt;/a&gt; on ruby-toolbox.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
