From da0f7c1f4ce28db5dfd78fd660be91eef4ae60af Mon Sep 17 00:00:00 2001 From: Jessica Jones Date: Tue, 15 Oct 2024 11:43:33 +0100 Subject: [PATCH] Improve specificity of test This test is to check that the contents method returns the memoised @contents when repeatedly called, rather than running line 10 https://github.com/alphagov/government-frontend/blob/6dbefab2ed477a6328f57227494b4561f811f239/app/presenters/content_item/contents_list.rb#L10 The original test checked if the code on line 11 was run, ie the contents_items method. But the content_items method is called in two places in this module, within both the contents method (which this test is testing) but also within the show_contents_items? method.This means changes to the show_contents_items? code unexpectedly breaks this test. This commit reduces the scope of the test so that unexpected test failures no longer occur. --- test/presenters/content_item/contents_list_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/presenters/content_item/contents_list_test.rb b/test/presenters/content_item/contents_list_test.rb index a9e9fb3a7..6008b6dd1 100644 --- a/test/presenters/content_item/contents_list_test.rb +++ b/test/presenters/content_item/contents_list_test.rb @@ -17,7 +17,7 @@ def body end end - @contents_list.expects(:contents_items).returns([{ text: "A heading", id: "custom" }]).once + @contents_list.expects(:show_contents_list?).returns(true).once @contents_list.contents @contents_list.contents end