@@ -38,24 +38,32 @@ defmodule Calque do
3838 @ hint_review_message "Please review this snapshot using `mix calque review`"
3939
4040 @ doc """
41- Performs a snapshot test with the given title, saving the content to a new
42- snapshot file and comparing it to the accepted one.
41+ Performs a snapshot test with an explicit snapshot title.
4342
44- The `check/1` macro is usually preferred for convenience, as it automatically
45- infers the snapshot title from the calling function .
43+ This function writes the given content to a snapshot file (if none exists)
44+ and compares it against the previously accepted snapshot .
4645
47- ## Parameters
46+ In practice, you will usually prefer `check/1`, which automatically derives
47+ the snapshot title from the calling test. Use `check/2` when you need full
48+ control over the snapshot name.
4849
49- * `content` — The stringified output to snapshot.
50- * `title` — A unique identifier (string) for the snapshot. This is often the test name.
50+ ## Examples
5151
52- ## Returns
52+ Using an explicit snapshot title:
5353
54- * `:ok` — If the output matches the accepted snapshot.
55- * **Raises an error** (`no_return()`) — If a new snapshot is created or the content
56- differs from the accepted snapshot.
57- """
54+ test "renders order confirmation" do
55+ html = render_confirmation(order)
56+
57+ Calque.check(html, "order_confirmation")
58+ end
5859
60+ If the snapshot matches the accepted version, the test passes silently:
61+
62+ :ok
63+
64+ If no snapshot exists yet, or if the content differs, the test fails and
65+ prints a helpful diff.
66+ """
5967 @ spec check ( String . t ( ) , String . t ( ) ) :: :ok | no_return ( )
6068 def check ( content , title ) do
6169 case do_check ( content , title ) do
@@ -102,25 +110,32 @@ defmodule Calque do
102110 @ doc """
103111 Performs a snapshot test using the **calling function name** as the snapshot title.
104112
105- This macro is a ** convenience shorthand** for `check/2`, where the required
106- `title` parameter is automatically derived from the function in which the macro is
107- called (e.g., the `test` block name in `ExUnit`) .
113+ This macro is a convenience wrapper around `check/2`. The snapshot title is
114+ automatically inferred from the surrounding function or test name, making it
115+ the preferred API in most cases .
108116
109- It behaves exactly like `check/2`, comparing the given content to the accepted
110- snapshot and raising an error if a new or differing snapshot is found.
117+ It behaves exactly like `check/2`: the content is compared against the accepted
118+ snapshot, and the test fails if a new snapshot is created or a difference is
119+ detected.
111120
112- ## Parameters
121+ ## Examples
113122
114- * `content` — The stringified output to snapshot.
123+ Inside an ExUnit test:
115124
116- ## Returns
125+ test "renders empty state" do
126+ html = render_empty_state()
117127
118- * `:ok` — If the output matches the accepted snapshot.
119- * **Raises an error** (`no_return()`) — If a new snapshot is created or the content
120- differs from the accepted snapshot.
121- """
128+ Calque.check(html)
129+ end
130+
131+ The snapshot title will automatically be set to:
122132
123- @ spec check ( term ( ) , String . t ( ) ) :: :ok | no_return ( )
133+ "renders empty state"
134+
135+ This keeps snapshot names stable and closely aligned with test intent, without
136+ requiring any manual naming.
137+ """
138+ @ spec check ( term ( ) ) :: :ok | no_return ( )
124139 defmacro check ( content ) do
125140 defining_mod = __MODULE__
126141 { fun_name , _arity } = __CALLER__ . function || { :no_function , 0 }
0 commit comments