<p><b>@gravitystorm</b> commented on this pull request.</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/2120#discussion_r250775195">test/jobs/trace_importer_job_test.rb</a>:</p>
<pre style='color:#555'>> +
+class TraceImporterJobTest < ActiveJob::TestCase
+  def test_success_notification
+    # Check that the user gets a success notification when the trace has valid points
+    trace = create(:trace)
+
+    gpx = Minitest::Mock.new
+    def gpx.actual_points
+      5
+    end
+
+    trace.stub(:import, gpx) do
+      perform_enqueued_jobs do
+        TraceImporterJob.perform_now(trace)
+      end
+    end
</pre>
<p>It's from minitest/mock.</p>
<p><a href="https://www.rubydoc.info/gems/minitest/4.2.0/Object:stub" rel="nofollow">https://www.rubydoc.info/gems/minitest/4.2.0/Object:stub</a></p>
<p>The stubbing takes a block, and the stub is only effective inside the block. So when we call <code>TraceImporterJob.perform_now(trace)</code>, the <code>trace.import</code> method has been overwritten to just return the (fake) gpx object and avoid doing anything else (parsing xml, creating images on disk etc).</p>
<p>I did all this before realising that I needed the FakeFS for other stuff anyway. So if you prefer, I could rework this to create a fully working <code>trace</code> object that actually runs <code>trace.import</code> for real, with suitable setup to put a valid xml file in the right place and clean up the side-effects of running the <code>.import</code> code. Or we can stick with mocking/stubbing, which is probably a better way to do it, but perhaps a bit impenetrable?</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/2120#discussion_r250775195">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABWnLeSTvoy1iq0jF2SPPPnA13sIBQmsks5vGh9UgaJpZM4aDUsB">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABWnLTsHZ68zS2pAH_R9Z9wCHynPtPZmks5vGh9UgaJpZM4aDUsB.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openstreetmap/openstreetmap-website","title":"openstreetmap/openstreetmap-website","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/openstreetmap/openstreetmap-website"}},"updates":{"snippets":[{"icon":"PERSON","message":"@gravitystorm commented on #2120"}],"action":{"name":"View Pull Request","url":"https://github.com/openstreetmap/openstreetmap-website/pull/2120#discussion_r250775195"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/2120#discussion_r250775195",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/2120#discussion_r250775195",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>