Skip to content

Commit 7557420

Browse files
authored
Added section on the declaration order of subject, let!/let and before/after hooks (#135)
Added section on declaration order
1 parent f211af1 commit 7557420

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.adoc

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ describe '#summary' do
237237
end
238238
----
239239

240+
== Example Group Structure
241+
240242
=== Leading `subject`
241243

242244
When `subject` is used, it should be the first declaration in the example group.
@@ -272,7 +274,52 @@ describe Article do
272274
end
273275
----
274276

275-
== Example Group Structure
277+
=== Declaring `subject`, `let!`/`let` and `before`/`after` hooks
278+
279+
When declaring `subject`, `let!`/`let` and `before`/`after` hooks they should be in the following order:
280+
281+
* `subject`
282+
* `let!`/`let`
283+
* `before`/`after`
284+
285+
[source,ruby]
286+
----
287+
# bad
288+
describe Article do
289+
before do
290+
# ...
291+
end
292+
293+
after do
294+
# ...
295+
end
296+
297+
let(:user) { FactoryBot.create(:user) }
298+
subject { FactoryBot.create(:some_article) }
299+
300+
describe '#summary' do
301+
# ...
302+
end
303+
end
304+
305+
# good
306+
describe Article do
307+
subject { FactoryBot.create(:some_article) }
308+
let(:user) { FactoryBot.create(:user) }
309+
310+
before do
311+
# ...
312+
end
313+
314+
after do
315+
# ...
316+
end
317+
318+
describe '#summary' do
319+
# ...
320+
end
321+
end
322+
----
276323

277324
=== Use Contexts
278325

0 commit comments

Comments
 (0)