Skip to content

Commit 1f601f1

Browse files
committed
Refactor StrictModuleLayout tests slightly
1 parent 684a353 commit 1f601f1

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

test/credo/check/readability/strict_module_layout_test.exs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
66
describe "default order" do
77
test "no errors are reported on a successful layout" do
88
"""
9-
defmodule Test do
9+
defmodule CredoSampleModule do
1010
@shortdoc "shortdoc"
1111
@moduledoc "some doc"
1212
@@ -30,7 +30,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
3030

3131
test "only first-level parts are analyzed" do
3232
"""
33-
defmodule Test do
33+
defmodule CredoSampleModule do
3434
@x 1
3535
3636
def some_fun(), do: @x
@@ -43,7 +43,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
4343

4444
test "custom macro invocations are ignored" do
4545
"""
46-
defmodule Test do
46+
defmodule CredoSampleModule do
4747
import Foo
4848
4949
setup do
@@ -80,7 +80,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
8080
test "shortdoc must appear before moduledoc" do
8181
[issue] =
8282
"""
83-
defmodule Test do
83+
defmodule CredoSampleModule do
8484
@moduledoc "some doc"
8585
@shortdoc "shortdoc"
8686
end
@@ -95,7 +95,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
9595
test "moduledoc must appear before behaviour" do
9696
[issue] =
9797
"""
98-
defmodule Test do
98+
defmodule CredoSampleModule do
9999
@behaviour GenServer
100100
@moduledoc "some doc"
101101
end
@@ -110,7 +110,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
110110
test "behaviour must appear before use" do
111111
[issue] =
112112
"""
113-
defmodule Test do
113+
defmodule CredoSampleModule do
114114
use GenServer
115115
@behaviour GenServer
116116
end
@@ -125,7 +125,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
125125
test "use must appear before import" do
126126
[issue] =
127127
"""
128-
defmodule Test do
128+
defmodule CredoSampleModule do
129129
import GenServer
130130
use GenServer
131131
end
@@ -140,7 +140,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
140140
test "import must appear before alias" do
141141
[issue] =
142142
"""
143-
defmodule Test do
143+
defmodule CredoSampleModule do
144144
alias GenServer
145145
import GenServer
146146
end
@@ -155,7 +155,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
155155
test "alias must appear before require" do
156156
[issue] =
157157
"""
158-
defmodule Test do
158+
defmodule CredoSampleModule do
159159
require GenServer
160160
alias GenServer
161161
end
@@ -170,7 +170,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
170170
test "callback functions and macros are handled by the `:callback_impl` option" do
171171
assert [issue1, issue2] =
172172
"""
173-
defmodule Test do
173+
defmodule CredoSampleModule do
174174
@impl true
175175
def foo
176176
@@ -187,17 +187,17 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
187187
|> assert_issues
188188

189189
assert issue1.message == "public function must appear before callback implementation"
190-
assert issue1.scope == "Test.baz"
190+
assert issue1.scope == "CredoSampleModule.baz"
191191

192192
assert issue2.message == "public function must appear before callback implementation"
193-
assert issue2.scope == "Test.qux"
193+
assert issue2.scope == "CredoSampleModule.qux"
194194
end
195195
end
196196

197197
describe "custom order" do
198198
test "no errors are reported on a successful layout" do
199199
"""
200-
defmodule Test do
200+
defmodule CredoSampleModule do
201201
def foo, do: :ok
202202
defp bar, do: :ok
203203
end
@@ -209,7 +209,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
209209

210210
test "no errors are reported on a custom layout missing parts defined in :order" do
211211
"""
212-
defmodule Test do
212+
defmodule CredoSampleModule do
213213
def foo, do: :ok
214214
end
215215
"""
@@ -220,7 +220,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
220220

221221
test "no errors are reported on a custom layout with extra parts not defined in :order" do
222222
"""
223-
defmodule Test do
223+
defmodule CredoSampleModule do
224224
def foo, do: :ok
225225
226226
defp bar, do: :ok
@@ -238,7 +238,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
238238
test "reports errors" do
239239
assert [issue1, issue2] =
240240
"""
241-
defmodule Test do
241+
defmodule CredoSampleModule do
242242
@moduledoc ""
243243
defp bar, do: :ok
244244
def foo, do: :ok
@@ -257,7 +257,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
257257

258258
test "reports errors for guards" do
259259
"""
260-
defmodule Test do
260+
defmodule CredoSampleModule do
261261
@moduledoc ""
262262
263263
defguardp is_foo(term) when term == :foo
@@ -275,7 +275,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
275275
test "treats `:callback_fun` as `:callback_impl` for backward compatibility" do
276276
[issue] =
277277
"""
278-
defmodule Test do
278+
defmodule CredoSampleModule do
279279
@impl Foo
280280
def foo, do: :ok
281281
@@ -293,7 +293,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
293293
describe "ignored parts" do
294294
test "no errors are reported on ignored parts" do
295295
"""
296-
defmodule Test do
296+
defmodule CredoSampleModule do
297297
alias Foo
298298
import Bar
299299
use Baz
@@ -307,7 +307,9 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
307307

308308
test "no errors are reported on ignored parts for module attributes" do
309309
"""
310-
defmodule Test do
310+
defmodule CredoSampleModule do
311+
@moduledoc ""
312+
311313
@type foo :: :foo
312314
313315
def hello do
@@ -333,7 +335,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
333335
test "reports errors on non-ignored parts" do
334336
[issue] =
335337
"""
336-
defmodule Test do
338+
defmodule CredoSampleModule do
337339
require Qux
338340
import Bar
339341
use Baz
@@ -351,7 +353,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
351353
describe "ignored module attributes" do
352354
test "ignores custom module attributes" do
353355
"""
354-
defmodule Test do
356+
defmodule CredoSampleModule do
355357
use Baz
356358
357359
import Bar
@@ -377,7 +379,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
377379

378380
test "ignores enforce_keys module attribute" do
379381
"""
380-
defmodule Test do
382+
defmodule CredoSampleModule do
381383
@enforce_keys [:bar]
382384
defstruct bar: nil
383385
end
@@ -389,7 +391,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
389391

390392
test "only ignores set module attributes" do
391393
"""
392-
defmodule Test do
394+
defmodule CredoSampleModule do
393395
import Bar
394396
395397
@trace trace_fun()
@@ -412,7 +414,7 @@ defmodule Credo.Check.Readability.StrictModuleLayoutTest do
412414
|> assert_issue(fn issue ->
413415
assert issue.message == "module attribute must appear before public function"
414416
# TODO: It would be nicer if the trigger was the attribute in question
415-
assert issue.trigger == "Test"
417+
assert issue.trigger == "CredoSampleModule"
416418
end)
417419
end
418420
end

0 commit comments

Comments
 (0)