nukadoko 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +553 -3
  3. data/README.ja.md +22 -6
  4. data/README.md +13 -7
  5. data/docs/ci.ja.md +542 -0
  6. data/docs/ci.md +635 -0
  7. data/docs/commands.ja.md +1524 -0
  8. data/docs/commands.md +1281 -0
  9. data/docs/engines.json +19 -0
  10. data/docs/execution-events.ja.md +336 -0
  11. data/docs/execution-events.md +423 -0
  12. data/docs/glossary.json +1348 -0
  13. data/docs/guide.ja.md +733 -0
  14. data/docs/guide.md +815 -0
  15. data/docs/intent.ja.md +133 -0
  16. data/docs/intent.md +156 -0
  17. data/docs/layout.ja.md +442 -0
  18. data/docs/layout.md +399 -0
  19. data/docs/releasing.ja.md +186 -0
  20. data/docs/releasing.md +237 -0
  21. data/docs/ruby/reference.ja.md +302 -0
  22. data/docs/ruby/reference.md +368 -0
  23. data/docs/spec.ja.md +8916 -0
  24. data/docs/spec.md +11250 -0
  25. data/docs/tutorial.ja.md +451 -0
  26. data/docs/tutorial.md +458 -0
  27. data/docs/typescript/adopting.ja.md +231 -0
  28. data/docs/typescript/adopting.md +251 -0
  29. data/docs/typescript/doors.ja.md +301 -0
  30. data/docs/typescript/doors.md +329 -0
  31. data/docs/typescript/migration-playwright-test.ja.md +189 -0
  32. data/docs/typescript/migration-playwright-test.md +212 -0
  33. data/docs/typescript/migration.ja.md +391 -0
  34. data/docs/typescript/migration.md +505 -0
  35. data/docs/typescript/reference.ja.md +176 -0
  36. data/docs/typescript/reference.md +197 -0
  37. data/docs/typescript/upgrading.ja.md +1774 -0
  38. data/docs/typescript/upgrading.md +2224 -0
  39. data/docs/web-app.ja.md +627 -0
  40. data/docs/web-app.md +659 -0
  41. data/docs/writing-scenarios.ja.md +544 -0
  42. data/docs/writing-scenarios.md +563 -0
  43. data/lib/nukadoko/base.rb +12 -5
  44. data/lib/nukadoko/changed_files.rb +95 -0
  45. data/lib/nukadoko/check.rb +459 -51
  46. data/lib/nukadoko/claim_drops.rb +271 -0
  47. data/lib/nukadoko/claim_line.rb +24 -4
  48. data/lib/nukadoko/claim_rules.rb +143 -1
  49. data/lib/nukadoko/claim_sides.rb +157 -9
  50. data/lib/nukadoko/cli.rb +403 -50
  51. data/lib/nukadoko/codes.json +246 -21
  52. data/lib/nukadoko/codes.rb +21 -4
  53. data/lib/nukadoko/command.rb +120 -13
  54. data/lib/nukadoko/command_help.rb +128 -0
  55. data/lib/nukadoko/compat.rb +469 -0
  56. data/lib/nukadoko/criteria.rb +1 -1
  57. data/lib/nukadoko/definition.rb +157 -7
  58. data/lib/nukadoko/error_frames.rb +6 -3
  59. data/lib/nukadoko/events/count.rb +146 -0
  60. data/lib/nukadoko/events/counted.rb +114 -0
  61. data/lib/nukadoko/events/format.rb +257 -0
  62. data/lib/nukadoko/events/lists.rb +154 -0
  63. data/lib/nukadoko/events/path.rb +285 -0
  64. data/lib/nukadoko/events/read.rb +284 -0
  65. data/lib/nukadoko/events/reader.rb +490 -0
  66. data/lib/nukadoko/events/selection.rb +252 -0
  67. data/lib/nukadoko/events/tally.rb +438 -0
  68. data/lib/nukadoko/features.rb +2 -2
  69. data/lib/nukadoko/fixtures.rb +160 -35
  70. data/lib/nukadoko/http_recording.rb +6 -2
  71. data/lib/nukadoko/intent.rb +364 -0
  72. data/lib/nukadoko/intent_file.rb +81 -0
  73. data/lib/nukadoko/intent_view.rb +190 -0
  74. data/lib/nukadoko/js_json.rb +2 -1
  75. data/lib/nukadoko/judge.rb +2 -2
  76. data/lib/nukadoko/judgment_file.rb +22 -1
  77. data/lib/nukadoko/judgments.rb +33 -3
  78. data/lib/nukadoko/measure_mcp.rb +202 -0
  79. data/lib/nukadoko/parts.rb +8 -2
  80. data/lib/nukadoko/path_view.rb +252 -0
  81. data/lib/nukadoko/place_rows.rb +161 -0
  82. data/lib/nukadoko/program.rb +1265 -51
  83. data/lib/nukadoko/program_log.rb +122 -0
  84. data/lib/nukadoko/program_shape.rb +385 -0
  85. data/lib/nukadoko/project_fixtures.rb +43 -10
  86. data/lib/nukadoko/project_program.rb +5 -4
  87. data/lib/nukadoko/repeated_prefix.rb +310 -0
  88. data/lib/nukadoko/report_run.rb +3 -3
  89. data/lib/nukadoko/run.rb +1156 -159
  90. data/lib/nukadoko/run_record.rb +70 -46
  91. data/lib/nukadoko/scaffold.rb +24 -6
  92. data/lib/nukadoko/schema.rb +15 -2
  93. data/lib/nukadoko/secrets.rb +55 -5
  94. data/lib/nukadoko/states.rb +478 -0
  95. data/lib/nukadoko/step.rb +71 -2
  96. data/lib/nukadoko/step_fixtures.rb +52 -3
  97. data/lib/nukadoko/summary.rb +803 -30
  98. data/lib/nukadoko/table.rb +4 -2
  99. data/lib/nukadoko/text_fit.rb +20 -7
  100. data/lib/nukadoko/trace.rb +152 -45
  101. data/lib/nukadoko/tree_passes.rb +95 -33
  102. data/lib/nukadoko/underneath.rb +311 -0
  103. data/lib/nukadoko/verdict.rb +18 -1
  104. data/lib/nukadoko/version.rb +1 -1
  105. data/lib/nukadoko/vocabulary.rb +166 -23
  106. data/lib/nukadoko/walk.rb +2 -2
  107. data/lib/nukadoko/walk_step.rb +1 -1
  108. data/lib/nukadoko.rb +23 -0
  109. data/llms.txt +42 -35
  110. data/sig/generated/nukadoko/base.rbs +4 -4
  111. data/sig/generated/nukadoko/changed_files.rbs +42 -0
  112. data/sig/generated/nukadoko/check.rbs +147 -10
  113. data/sig/generated/nukadoko/claim_drops.rbs +135 -0
  114. data/sig/generated/nukadoko/claim_line.rbs +11 -0
  115. data/sig/generated/nukadoko/claim_rules.rbs +49 -4
  116. data/sig/generated/nukadoko/claim_sides.rbs +63 -12
  117. data/sig/generated/nukadoko/cli.rbs +80 -7
  118. data/sig/generated/nukadoko/codes.rbs +19 -4
  119. data/sig/generated/nukadoko/command.rbs +68 -1
  120. data/sig/generated/nukadoko/command_help.rbs +18 -0
  121. data/sig/generated/nukadoko/compat.rbs +392 -0
  122. data/sig/generated/nukadoko/criteria.rbs +1 -1
  123. data/sig/generated/nukadoko/definition.rbs +50 -0
  124. data/sig/generated/nukadoko/error_frames.rbs +1 -1
  125. data/sig/generated/nukadoko/events/count.rbs +69 -0
  126. data/sig/generated/nukadoko/events/counted.rbs +70 -0
  127. data/sig/generated/nukadoko/events/format.rbs +163 -0
  128. data/sig/generated/nukadoko/events/lists.rbs +47 -0
  129. data/sig/generated/nukadoko/events/path.rbs +161 -0
  130. data/sig/generated/nukadoko/events/read.rbs +109 -0
  131. data/sig/generated/nukadoko/events/reader.rbs +226 -0
  132. data/sig/generated/nukadoko/events/selection.rbs +100 -0
  133. data/sig/generated/nukadoko/events/tally.rbs +227 -0
  134. data/sig/generated/nukadoko/features.rbs +6 -4
  135. data/sig/generated/nukadoko/fixtures.rbs +67 -11
  136. data/sig/generated/nukadoko/http_recording.rbs +1 -1
  137. data/sig/generated/nukadoko/intent.rbs +132 -0
  138. data/sig/generated/nukadoko/intent_file.rbs +46 -0
  139. data/sig/generated/nukadoko/intent_view.rbs +69 -0
  140. data/sig/generated/nukadoko/judgment_file.rbs +7 -1
  141. data/sig/generated/nukadoko/judgments.rbs +10 -0
  142. data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
  143. data/sig/generated/nukadoko/parts.rbs +2 -2
  144. data/sig/generated/nukadoko/path_view.rbs +105 -0
  145. data/sig/generated/nukadoko/place_rows.rbs +43 -0
  146. data/sig/generated/nukadoko/program.rbs +627 -23
  147. data/sig/generated/nukadoko/program_log.rbs +67 -0
  148. data/sig/generated/nukadoko/program_shape.rbs +147 -0
  149. data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
  150. data/sig/generated/nukadoko/project_program.rbs +2 -1
  151. data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
  152. data/sig/generated/nukadoko/report_run.rbs +1 -1
  153. data/sig/generated/nukadoko/run.rbs +286 -41
  154. data/sig/generated/nukadoko/run_record.rbs +20 -12
  155. data/sig/generated/nukadoko/scaffold.rbs +3 -0
  156. data/sig/generated/nukadoko/schema.rbs +5 -0
  157. data/sig/generated/nukadoko/secrets.rbs +26 -3
  158. data/sig/generated/nukadoko/states.rbs +214 -0
  159. data/sig/generated/nukadoko/step.rbs +58 -1
  160. data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
  161. data/sig/generated/nukadoko/summary.rbs +256 -2
  162. data/sig/generated/nukadoko/table.rbs +3 -2
  163. data/sig/generated/nukadoko/trace.rbs +108 -33
  164. data/sig/generated/nukadoko/tree_passes.rbs +36 -8
  165. data/sig/generated/nukadoko/underneath.rbs +141 -0
  166. data/sig/generated/nukadoko/verdict.rbs +8 -0
  167. data/sig/generated/nukadoko/vocabulary.rbs +45 -6
  168. data/skills/nukadoko/SKILL.md +18 -18
  169. data/skills/nukadoko/references/checking-steps.md +16 -83
  170. data/skills/nukadoko/references/diagnosing.md +6 -6
  171. data/skills/nukadoko/references/done.md +22 -0
  172. data/skills/nukadoko/references/evidence.md +19 -6
  173. data/skills/nukadoko/references/exploring.md +22 -7
  174. data/skills/nukadoko/references/fixtures.md +12 -32
  175. data/skills/nukadoko/references/judgments.md +18 -0
  176. data/skills/nukadoko/references/maintenance.md +1 -1
  177. data/skills/nukadoko/references/merge-risk.md +1 -1
  178. data/skills/nukadoko/references/parts.md +46 -23
  179. data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
  180. data/skills/nukadoko/references/program.md +168 -169
  181. data/skills/nukadoko/references/reviewing.md +20 -20
  182. data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
  183. data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
  184. data/skills/nukadoko/references/ruby/fixtures.md +34 -0
  185. data/skills/nukadoko/references/ruby/program.md +112 -0
  186. data/skills/nukadoko/references/ruby/step-files.md +115 -0
  187. data/skills/nukadoko/references/running.md +34 -34
  188. data/skills/nukadoko/references/scenario-rules.md +7 -6
  189. data/skills/nukadoko/references/states.md +7 -1
  190. data/skills/nukadoko/references/step-files.md +41 -120
  191. data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
  192. data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
  193. data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
  194. data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
  195. data/skills/nukadoko/references/typescript/fixtures.md +56 -0
  196. data/skills/nukadoko/references/typescript/program.md +111 -0
  197. data/skills/nukadoko/references/typescript/step-files.md +104 -0
  198. data/skills/nukadoko/references/verdicts.md +10 -10
  199. data/skills/nukadoko/references/writing-steps.md +67 -67
  200. data/skills/nukadoko/references/writing-the-feature.md +1 -1
  201. data/skills/nukadoko-verification/SKILL.md +13 -8
  202. metadata +103 -7
  203. data/skills/nukadoko/references/ruby.md +0 -80
@@ -0,0 +1,212 @@
1
+ # Worked example: a command-line program in Ruby
2
+
3
+ The project of `../../typescript/examples/cli.md`, with its steps in
4
+ Ruby. Every step file below is a file of `conformance/cases/cli/steps-rb/`
5
+ in the nukadoko repository, which CI runs against the gem, and every
6
+ output block is copied from a real run of that project with the gem
7
+ under Ruby 3.4. The rules it follows are in `../../scenario-rules.md`, and
8
+ the shape of a Ruby step file is in `../step-files.md`.
9
+
10
+ ## The ticket
11
+
12
+ `tally <file.csv> [--json]` sums amounts per category. The output is one
13
+ `category: total` line per category, sorted by name. `--json` prints the
14
+ same totals as one object. A file that cannot be read exits 2 with `tally:
15
+ cannot read <file>`. A line that is not `category,amount` exits 3 with
16
+ `tally: bad line: <line>`. The program is `src/cli.ts`, which `node` runs.
17
+
18
+ ## The feature
19
+
20
+ `features/tally.feature`. Every expected value comes from the ticket.
21
+
22
+ ```gherkin
23
+ Feature: tally sums amounts per category
24
+
25
+ Scenario: totals per category, sorted by name
26
+ Given a file "input.csv" with these lines
27
+ """
28
+ rent,100
29
+ food,3
30
+ food,2.5
31
+ """
32
+ When I run tally with "input.csv"
33
+ Then it exits with 0
34
+ And the output is
35
+ """
36
+ food: 5.5
37
+ rent: 100
38
+ """
39
+
40
+ Scenario: a file that cannot be read
41
+ Given an empty directory
42
+ When I run tally with "missing.csv"
43
+ Then it exits with 2
44
+ And the error says "tally: cannot read missing.csv"
45
+ ```
46
+
47
+ The project's feature has two more scenarios of the same shape: `--json`,
48
+ and a malformed line that exits 3.
49
+
50
+ ## The steps
51
+
52
+ The two Givens each return a fresh `scratch.dir`, which the engine
53
+ removes when the scenario ends. `features/steps/a_csv_file_with.rb`:
54
+
55
+ ```ruby
56
+ # conformance/cases/cli/steps-rb/a_csv_file_with.rb
57
+ class ACsvFileWith < Nukadoko::Step
58
+ description "Write the docstring to a named file in a fresh scratch directory"
59
+ pattern "a file {name:string} with these lines"
60
+ args do
61
+ string :name, "The file name, relative to the scratch directory"
62
+ string :lines, "The file's contents, verbatim"
63
+ end
64
+ returns do
65
+ string :dir, "The scratch directory the file was written in"
66
+ number :bytes, "Size of the file written, in bytes"
67
+ end
68
+ # Writes only inside the scenario's own scratch directory, which is removed after it.
69
+ mutates false
70
+
71
+ def run(scratch:, args:)
72
+ dir = scratch.dir
73
+ body = args.lines.end_with?("\n") ? args.lines : "#{args.lines}\n"
74
+ File.write(File.join(dir, args.name), body)
75
+ { dir: dir, bytes: body.bytesize }
76
+ end
77
+ end
78
+ ```
79
+
80
+ `an-empty-directory` is the same with no file: `def run(scratch:, args:)
81
+ = { dir: scratch.dir }`.
82
+
83
+ The When reads `dir` from whichever Given ran and runs the program there.
84
+ `features/steps/run_tally.rb`:
85
+
86
+ ```ruby
87
+ # conformance/cases/cli/steps-rb/run_tally.rb
88
+ class RunTally < Nukadoko::Step
89
+ description "Run tally with these arguments in the directory an earlier step prepared"
90
+ pattern "I run tally with {argv:string}"
91
+ args do
92
+ string :argv, "Arguments after `tally`, separated by spaces"
93
+ field :dir, ACsvFileWith.returns[:dir]
94
+ end
95
+ from dir: [[ACsvFileWith, :dir], [AnEmptyDirectory, :dir]]
96
+ returns do
97
+ number :exitCode, "The process exit code", null: true
98
+ string :stdout, "Everything the process wrote to stdout"
99
+ string :stderr, "Everything the process wrote to stderr"
100
+ end
101
+ # Runs the program under test in a scratch directory a Given step made.
102
+ mutates false
103
+
104
+ def run(args:) = Nukadoko.run_command("node", [File.expand_path("src/cli.ts"), *args.argv.split], cwd: args.dir)
105
+ end
106
+ ```
107
+
108
+ Each Then reads one key of `run-tally` through `from` and declares one
109
+ claim on it, with no `run`. `features/steps/output_is.rb`:
110
+
111
+ ```ruby
112
+ # conformance/cases/cli/steps-rb/output_is.rb
113
+ class OutputIs < Nukadoko::Step
114
+ description "stdout is exactly the docstring, ignoring a trailing newline"
115
+ pattern "the output is"
116
+ args do
117
+ string :expected, "The expected stdout, verbatim"
118
+ field :stdout, RunTally.returns[:stdout]
119
+ end
120
+ from stdout: [RunTally, :stdout]
121
+ # The program ends its output with a newline that the feature line does not show.
122
+ claims [{ actual: "stdout", view: "text", compare: "equal", expected: "expected" }]
123
+ end
124
+ ```
125
+
126
+ `features/steps/error_says.rb` claims the first line of stderr:
127
+
128
+ ```ruby
129
+ # conformance/cases/cli/steps-rb/error_says.rb
130
+ class ErrorSays < Nukadoko::Step
131
+ description "The first line of stderr is exactly this"
132
+ pattern "the error says {text:string}"
133
+ args do
134
+ string :text, "The expected first line of stderr"
135
+ field :stderr, RunTally.returns[:stderr]
136
+ end
137
+ from stderr: [RunTally, :stderr]
138
+ claims [{ actual: "stderr", view: "lines", at: "0", compare: "equal", expected: "text" }]
139
+ end
140
+ ```
141
+
142
+ `exits-with` is the same shape on `exitCode`, with `{code:int}` and
143
+ `compare: "equal"`.
144
+
145
+ ## The commands, in order
146
+
147
+ A producer declares its key in `returns` before a consumer is scaffolded
148
+ `--from` it. Scaffolding `run-tally` while `a-csv-file-with` was still a
149
+ stub:
150
+
151
+ ```
152
+ $ bundle exec nuka scaffold run-tally --pattern 'I run tally with {argv:string}' --command src/cli.ts --from a-csv-file-with.dir --argv argv
153
+ refused step-inputs-invalid - Refusing to scaffold: a-csv-file-with declares no returns, so it has no key to chain; declare returns with "dir" in features/steps/a_csv_file_with.rb
154
+ fix: Add a returns block with dir to features/steps/a_csv_file_with.rb and return dir from its run().
155
+ do: nuka scaffold run-tally --pattern 'I run tally with {argv:string}' --command src/cli.ts --from a-csv-file-with.dir --argv argv
156
+ ```
157
+
158
+ Once both Givens returned `dir`, one command wrote the When:
159
+
160
+ ```
161
+ $ bundle exec nuka scaffold run-tally --pattern 'I run tally with {argv:string}' --command src/cli.ts --from a-csv-file-with.dir --from an-empty-directory.dir --cwd dir --argv argv
162
+ features/steps/run_tally.rb
163
+ ```
164
+
165
+ It wrote the `from` entry, `cwd: args.dir`, the split of `argv`, and
166
+ `returns`, and it runs the entry point with the Ruby that runs `nuka`:
167
+
168
+ ```ruby
169
+ class RunTally < Nukadoko::Step
170
+ CLI = File.expand_path("src/cli.ts")
171
+ # ...
172
+ def run(args:)
173
+ Nukadoko.run_command(RbConfig.ruby, [CLI, *args.argv.split], cwd: args.dir)
174
+ end
175
+ end
176
+ ```
177
+
178
+ `src/cli.ts` is not Ruby, so the first run failed at the exit code:
179
+
180
+ ```
181
+ step 2/4 passed 0.3s I run tally with "input.csv"
182
+ step 3/4 failed 0.0s it exits with 0
183
+ claim broken: 1 (from:run-tally@16.exitCode) equal 0 (sentence:code)
184
+ ```
185
+
186
+ Putting `"node"` in place of `RbConfig.ruby` fixed it. A program in
187
+ another Ruby project keeps `RbConfig.ruby` (or its `bin/` script) and adds
188
+ `unbundled: true`: the program otherwise inherits the environment `bundle
189
+ exec` gave `nuka`, which names `nuka`'s Gemfile and not the program's.
190
+ The descriptions and `mutates false` are by hand: the scaffold writes
191
+ `mutates true`, because it cannot know what a program writes, and `tally`
192
+ writes nothing outside the scratch directory.
193
+
194
+ Each Then came from one command with `--then` and `--from`, such as
195
+ `bundle exec nuka scaffold output-is --pattern 'the output is' --then
196
+ --from run-tally.stdout`. A red run, with `rent: 101` in the docstring of
197
+ the first scenario, carries both values and where each came from:
198
+
199
+ ```
200
+ step 4/4 failed 0.0s the output is
201
+ claim broken: "food: 5.5\nrent: 100" (from:run-tally@16.stdout as text) equal "food: 5.5\nrent: 101" (sentence:expected); first difference at line 2: actual "rent: 100", expected "rent: 101"
202
+ ```
203
+
204
+ The run that passed:
205
+
206
+ ```
207
+ $ bundle exec nuka check
208
+ ok: no issues found
209
+ $ bundle exec nuka run
210
+ ...
211
+ 4 scenarios: 4 passed, 0 failed (0s)
212
+ ```
@@ -0,0 +1,34 @@
1
+ # Fixtures in Ruby
2
+
3
+ When to declare a fixture, and how setup and teardown run, are in
4
+ `../fixtures.md`. This page is how `nukadoko.config.rb` declares one.
5
+
6
+ ## A project fixture
7
+
8
+ `Nukadoko.fixture(:name)` in the config declares each one. The block
9
+ calls `use` with the value, and what follows is its teardown; a keyword
10
+ argument names a fixture it needs. `scope: :process` keeps one value for
11
+ the whole run of an environment.
12
+
13
+ ```ruby
14
+ # conformance/cases/workflow/config.rb
15
+ require_relative "src/signup"
16
+
17
+ Nukadoko.fixture(:store) { |use| use.(Signup::Store.new) }
18
+ ```
19
+
20
+ A step reaches the fixture the same way it reaches `page`, as a keyword
21
+ argument: `def run(store:, args:)`.
22
+
23
+ ## Replacing a built-in
24
+
25
+ A fixture named like a built-in replaces it for every step, and receives
26
+ the built-in under the same name.
27
+
28
+ ```ruby
29
+ # conformance/cases/page-override/config.rb
30
+ Nukadoko.fixture(:page) do |use, page:|
31
+ page.add_init_script(script: "window.wrapped = 'by the project'")
32
+ use.(page)
33
+ end
34
+ ```
@@ -0,0 +1,112 @@
1
+ # The program in Ruby
2
+
3
+ What the program is, how a system starts it, and every field are in
4
+ `../program.md`. This page is how `nukadoko.config.rb` writes it.
5
+
6
+ ## The program
7
+
8
+ `program:` is a lambda that returns how the program starts. The gem reads
9
+ every field `../program.md` names, and refuses any key it does not know. A command never
10
+ goes through a shell unless it names one (`["sh", "-c", "..."]`).
11
+ `setup`, a `url` that is not a fixed URL, and an environment's `version`
12
+ are lambdas; `setup` and a `url` lambda receive the system (`name`,
13
+ `root`, `dir`, `tree`, and, for `setup`, `url`, `port`, `env`,
14
+ `services`, and `conditions`).
15
+
16
+ ```ruby
17
+ Nukadoko.config(
18
+ program: -> {
19
+ {
20
+ build: [["bin/rails", "assets:precompile"]],
21
+ prepare: [["bin/rails", "db:prepare"]],
22
+ serve: { command: "ruby src/server.rb", ready: "/health" },
23
+ env: { PORT: "{port}", DATABASE_URL: "sqlite3:{dir}/db.sqlite3" },
24
+ setup: ->(system) { Seed.call(system.url) },
25
+ }
26
+ },
27
+ )
28
+ ```
29
+
30
+ ## Several services
31
+
32
+ Each service is an entry of `services:`, with its own fields and `root`,
33
+ and `primary:` names the one the steps reach. An environment moves a
34
+ service to a URL under its own `services:`, so the same steps run there:
35
+
36
+ ```ruby
37
+ Nukadoko.config(program: lambda {
38
+ {
39
+ primary: "shop",
40
+ services: {
41
+ shop: {
42
+ serve: { command: "node relay.mjs --port {port}", ready: "/whoami" },
43
+ env: { NAME: "shop", PEER_URL: "{service.billing.url}" }
44
+ },
45
+ billing: {
46
+ root: "billing",
47
+ serve: { command: "node ../relay.mjs --port {port}", ready: "/whoami" },
48
+ env: { NAME: "billing", PEER_URL: "{service.shop.url}" }
49
+ }
50
+ },
51
+ environments: {
52
+ local: {},
53
+ staging: { services: { shop: { url: "https://shop.staging.acme.example" }, billing: { url: "https://billing.staging.acme.example" } } }
54
+ },
55
+ defaultEnvironments: ["local"]
56
+ }
57
+ })
58
+ ```
59
+
60
+ A step names `services:` among its keyword arguments and reads a service
61
+ by name; a name the program does not write raises
62
+ `Nukadoko::UnknownServiceError`, a `KeyError`:
63
+
64
+ ```ruby
65
+ def run(request:, services:)
66
+ { name: request.get("#{services[:billing].url}/whoami").json["name"] }
67
+ end
68
+ ```
69
+
70
+ ## Steps reach
71
+
72
+ `stepsReach: "url"` makes a service URL the only way into the program, so
73
+ `Nukadoko.run_command` raises `Nukadoko::CommandRefused` there instead of
74
+ starting a process. The program's own test API, called by `setup`, is what
75
+ seeds the system then, and a step names `setup_result:` to read what
76
+ `setup` returned, with string keys:
77
+
78
+ ```ruby
79
+ Nukadoko.config(program: lambda {
80
+ {
81
+ stepsReach: "url",
82
+ serve: { command: "bin/rails server -p {port}", ready: "/up" },
83
+ setup: ->(system) {
84
+ answer = Net::HTTP.post(URI("#{system.url}/test/tenants"),
85
+ JSON.generate({ flags: system.conditions }),
86
+ "content-type" => "application/json")
87
+ { tenant: JSON.parse(answer.body)["tenant"] }
88
+ },
89
+ environments: { scratch: { stepsReach: "any" }, staging: { url: "https://staging.acme.example" } }
90
+ }
91
+ })
92
+ ```
93
+
94
+ ```ruby
95
+ def run(request:, setup_result:)
96
+ answer = request.get("/todos", headers: { "x-tenant" => setup_result["tenant"] })
97
+ { titles: answer.json.map { _1["title"] } }
98
+ end
99
+ ```
100
+
101
+ ## Environments
102
+
103
+ An entry of `environments` overrides any field of the program, and
104
+ `env` merges by key:
105
+
106
+ ```ruby
107
+ env: { CHECKOUT_V2: "{condition.checkout_v2}" },
108
+ environments: {
109
+ "checkout-v1": { conditions: { checkout_v2: false } },
110
+ "checkout-v2": { conditions: { checkout_v2: true } },
111
+ },
112
+ ```
@@ -0,0 +1,115 @@
1
+ # Step files in Ruby
2
+
3
+ The rules every step follows, whatever its engine, are in `../step-files.md`.
4
+ This page is how a Ruby step file writes them. Run every command as
5
+ `bundle exec nuka`.
6
+
7
+ ## A step file
8
+
9
+ One step per file under `featuresDir`, named in snake_case: the file name
10
+ with hyphens is the step's name (`add_todo.rb` is `add-todo`). The file
11
+ defines a class of the CamelCase name that inherits `Nukadoko::Step`.
12
+
13
+ ```ruby
14
+ # conformance/cases/todo/steps-rb/add_todo.rb
15
+ class AddTodo < Nukadoko::Step
16
+ pattern "a todo titled {title:string} is added"
17
+ description "Create a todo via POST /todos and return the created record"
18
+ args { string :title, "The title of the todo to create" }
19
+ returns do
20
+ string :id, "The id the server assigned"
21
+ string :title, "The title as the server stored it"
22
+ boolean :done, "Whether the todo is done; false for a new one"
23
+ end
24
+ mutates true
25
+
26
+ def run(request:, args:)
27
+ request.post("/todos", data: { title: args.title }).json
28
+ end
29
+ end
30
+ ```
31
+
32
+ `args` and `returns` take a block of fields: `string`, `number`,
33
+ `integer`, `boolean`, `object`, `array`, `unknown`, `table`, and the lists
34
+ `strings`, `numbers`, and `integers`, each with an optional description.
35
+ A field takes `null: true`, `optional: true`, `default:`, `min:`, `max:`,
36
+ `positive: true`, or `negative: true`; `enum :outcome, %w[accepted
37
+ refused]` allows only those words. A step that runs code mutates unless
38
+ it says `mutates false`. `patterns "another wording"` adds wordings
39
+ after `pattern`, each capturing the same keys. `timeout 5000` bounds
40
+ `run` or `observe` in milliseconds; without it the config's
41
+ `stepTimeout` applies (twenty minutes). `requires`, `gives`, and `ends`
42
+ name states a line needs, leaves, and ends: `requires ["signed-in",
43
+ :person]` for a state one person holds, `gives "book-open"` for one a
44
+ scenario holds once.
45
+
46
+ A claim step can read what an earlier step did instead of observing it.
47
+ `files written: { of: RunBuild, change: "added" }` lists the paths that
48
+ step's commands changed, and `events writes: { of: PlaceScore, count: {
49
+ kind: "db", op: %w[insert update delete other], committed: true } }`
50
+ counts that step's execution events. A claim names the key as its
51
+ actual.
52
+
53
+ ## Loading
54
+
55
+ Every `*.rb` file under `features/steps/` is loaded, a helper under
56
+ `features/steps/lib/` too, so a helper module named after its file can be
57
+ used from any step without a `require`. A file that raises while it loads,
58
+ or a class whose declaration cannot stand, is reported by `nuka check` as
59
+ `step-file-import-failed`.
60
+
61
+ ## The fixtures a step names
62
+
63
+ The keyword arguments of `run` and `observe` name the fixtures the step
64
+ needs; `nuka check` reads them with `Method#parameters` without calling
65
+ the body. `args:` is there only when the body reads the args. A keyword
66
+ that names no fixture is `fixture-structural-violation`. Each fixture has
67
+ the TypeScript name, and four also take a snake_case name that reaches the
68
+ same fixture: `base_url`, `require_env`, `page_as`, and `result_of`. A
69
+ fixture TypeScript calls as a function is a lambda, called with `.()`:
70
+ `section.("checkout")`, `require_env.("API_KEY")`, `page_as.("aki")`,
71
+ `result_of.(CreateTodo)`, and `poll.(description: "the order", interval:
72
+ 200) { value or nil }`. `evidence.attach`, `evidence.path`, `scratch.dir`,
73
+ and `scratch.copy` are methods. `request` is the gem's own client
74
+ (`get`, `post`, `put`, `patch`, `delete`, with `data:` sent as JSON), and
75
+ `Net::HTTP` calls a step makes itself are recorded too.
76
+
77
+ ## The deadline
78
+
79
+ A step's `run` or `observe` has a deadline: its own `timeout` in
80
+ milliseconds, or else `stepTimeout` in `nukadoko.config.rb`, twenty
81
+ minutes unless the project sets it. Ruby's `Timeout` stops the body where
82
+ it is, a program `run_command` started for it is stopped too, the step
83
+ fails with `error.kind` `timeout`, and the message names which of the two
84
+ set the deadline:
85
+
86
+ ```
87
+ Step "slow-probe" timed out after 500ms (the step's own timeout)
88
+ ```
89
+
90
+ `Nukadoko.run_command(..., timeout:)` bounds one program the step runs,
91
+ and its `timeout:` is in seconds, unlike the step's `timeout` and
92
+ `poll`'s `timeout_ms`, which are milliseconds: `timeout: 120` is two
93
+ minutes. A run it stops has no exit code, so `run_command` raises
94
+ `Timeout::Error` (`sleep did not finish in 1 seconds, so it has no exit
95
+ code`) and the step fails with `error.kind` `step_error`. A `timeout:`
96
+ past the step's deadline never fires: the step's deadline stops the
97
+ program first, and the step fails as `timeout`.
98
+
99
+ ## Parameter types
100
+
101
+ `parameterTypes:` in `nukadoko.config.rb` takes a
102
+ `{ name:, regexp:, transformer: }` hash per type, the transformer a
103
+ lambda: `{ name: "priority", regexp: /urgent|later/, transformer: ->(s) {
104
+ s == "urgent" ? "high" : "low" } }`. It only coerces the matched text; the `args` schema still
105
+ validates the value.
106
+
107
+ ## Several people in one scenario
108
+
109
+ `page_as.(name)` returns playwright-ruby-client's `Page` in a browser
110
+ context of that person's own, so each keeps their own cookies. Take the
111
+ name from the feature line, lowercased (`page_as.(args.name.downcase)`).
112
+ Its methods are snake_case (`page.get_by_role`). `page.wait_for_url`
113
+ takes a String or a Regexp, never a Proc, and `context.expect_page`
114
+ raises ArgumentError: wait for a new tab with
115
+ `context.expect_event("page") { page.get_by_text("Open").click }`.
@@ -3,30 +3,31 @@
3
3
  ## Setting up
4
4
 
5
5
  Run every `nuka` command from the directory that holds the config; in a
6
- workspace, that is the package, not the root. When there is no config,
7
- `nuka init` writes it, `features/steps/`, `.gitignore` lines for
8
- `.nukadoko/` and `.env` files, and a `test:scenarios` script in
6
+ workspace, that is the package, not the root. When there is no config, `nuka
7
+ init` writes it, `features/steps/`, and `.gitignore` lines for `.nukadoko/`
8
+ and `.env` files. A Ruby project's Rakefile gets a `scenarios` task that runs
9
+ `nuka run` through Bundler (`rake scenarios`); with no Rakefile, run `nuka
10
+ run` itself. A TypeScript project gets a `test:scenarios` script in
9
11
  `package.json`, so `npm run test:scenarios` runs `nuka run`, which checks
10
12
  `featuresDir` and then executes it. A `test:scenarios` script the project
11
- already has stays, and `init` says so on stderr; run `nuka run` directly
12
- then. It also adds the steps and the config to `tsconfig.json`'s
13
- `include`, and `"rewriteRelativeImportExtensions": true` to its `compilerOptions` so
14
- `tsc` accepts the `.ts` import names `nuka scaffold` writes, keeping its
15
- comments and trailing commas. When `compilerOptions` comes only through
16
- `extends`, `init` says on stderr what to add instead of editing.
13
+ already has stays, and `init` says so on stderr; run `nuka run` directly then.
14
+ It also adds the steps and the config to `tsconfig.json`'s `include`, and
15
+ `"rewriteRelativeImportExtensions": true` to its `compilerOptions` so `tsc`
16
+ accepts the `.ts` import names `nuka scaffold` writes. When `compilerOptions`
17
+ comes only through `extends`, `init` says on stderr what to add instead of
18
+ editing.
17
19
 
18
20
  A CommonJS project (no `"type": "module"` in `package.json`) gets
19
- `nukadoko.config.mts` and `.mts` step files from `nuka scaffold`. A `.ts`
20
- step file loads there with a Node warning, unless `"type": "commonjs"`
21
- is set, where it needs `.mts`. A hand-written
22
- `nukadoko.config.ts` there loads with a Node warning on every run (`nuka
23
- check` notes it as `package-type-missing`), and fails to import under
24
- `"type": "commonjs"`, with an error that names the file.
25
-
26
- A flag that takes one string or one number is refused when it is given
27
- more than once, and the command writes nothing. `--use`, `--fail-on`,
28
- `nuka run`'s `--env` and `--tag`, and `nuka scaffold`'s `--from` repeat, each value
29
- kept in the order given.
21
+ `nukadoko.config.mts` and `.mts` step files from `nuka scaffold`. A `.ts` step
22
+ file loads there with a Node warning, unless `"type": "commonjs"` is set,
23
+ where it needs `.mts`. A hand-written `nukadoko.config.ts` there loads with a
24
+ Node warning on every run (`nuka check` notes it as `package-type-missing`),
25
+ and fails to import under `"type": "commonjs"` with an error naming the file.
26
+
27
+ A flag that takes one string or one number is refused when it is given more
28
+ than once, and the command writes nothing. `--use`, `--fail-on`, `nuka
29
+ run`'s `--env` and `--tag`, and `nuka scaffold`'s `--from` repeat, each
30
+ value kept in the order given.
30
31
 
31
32
  ## The program under test
32
33
 
@@ -142,7 +143,7 @@ there is not checked and not run, and the skip reports nothing.
142
143
  records and screenshots (`references/diagnosing.md`): the count says
143
144
  how often, never why.
144
145
  4. A green run proves only the order it ran in: an environment's
145
- scenarios share one world, so one can pass on data an earlier one left.
146
+ scenarios share one system, so one can pass on data an earlier one left.
146
147
  Before reporting a feature of several scenarios, run it again with
147
148
  `--order shuffled`. A failed scenario's `do:` line replays what ran
148
149
  before it: red again there is an order dependence. Delete the line's
@@ -154,7 +155,7 @@ there is not checked and not run, and the skip reports nothing.
154
155
  Push the feature and its steps and open the pull request. CI runs the
155
156
  feature and posts the run summary on it (`docs/ci.md` in the nukadoko
156
157
  package has the workflow) from `nuka run --base <the base>`: its table
157
- says what changed in each criterion since the base and whether a world
158
+ says what changed in each criterion since the base and whether a system
158
159
  where the behaviour is absent shows its Then failing
159
160
  (`references/verdicts.md`). In a shallow clone, fetch the base first;
160
161
  the refusal's `do:` line is the command.
@@ -179,18 +180,17 @@ nuka report .nukadoko/runs/<run_id> --format allure --out reports/allure
179
180
 
180
181
  With no run directory it renders the newest run; stderr names what it wrote.
181
182
 
182
- Open the two report formats for different reasons. Allure is nukadoko's
183
- own dashboard: every step's trace, HTTP log, validated result, and a
184
- timeline of what it waited for and clicked, with zero project wiring.
185
- Render it with Allure's own CLI: `npx allure watch <dir> --output
186
- <report-dir>` picks up each render while you iterate, and `npx allure
187
- generate` and `npx allure open` serve a finished one. Nukadoko never renders
188
- HTML itself. The messages stream is for the opposite reason: feeding a
189
- suite's existing cucumber-js-era formatter or JUnit-based CI while it
190
- migrates, not for reading by hand. It leaves out every control, so JUnit
191
- reads a green run as green; under `--base` an `unproven` or `moved` row is
192
- no failure there, so gate on the exit code. Allure keeps a control as
193
- `<scenario> (control)`, failed if it was.
183
+ Open the two report formats for different reasons. Allure is nukadoko's own
184
+ dashboard: every step's trace, HTTP log, validated result, and a timeline of
185
+ what it waited for and clicked, with zero project wiring. Render it with
186
+ Allure's own CLI: `npx allure watch <dir> --output <report-dir>` picks up each
187
+ render while you iterate, and `npx allure generate` and `npx allure open`
188
+ serve a finished one. Nukadoko never renders HTML itself. The messages stream
189
+ is for the opposite reason: feeding a suite's existing cucumber-js-era
190
+ formatter or JUnit-based CI while it migrates, not for reading by hand. It
191
+ leaves out every control, so JUnit reads a green run as green; under `--base`
192
+ an `unproven` or `moved` row is no failure there, so gate on the exit code.
193
+ Allure keeps a control as `<scenario> (control)`, failed if it was.
194
194
 
195
195
  Rendering the same run again replaces what its last render wrote under
196
196
  `<stateDir>/export/`. Those files leave with their run: `nuka run` keeps the
@@ -4,9 +4,10 @@ The criteria are fixed before the implementation exists, so a scenario is
4
4
  evidence only if nothing in it came from the implementation. Each rule
5
5
  below says what to write, shows the weak form and the strong form, and
6
6
  names the finding that enforces it, or says `review` when no check can
7
- decide it without guessing. `examples/` beside this file holds three
7
+ decide it without guessing. `typescript/examples/` beside this file holds three
8
8
  finished projects (`cli.md`, `http-api.md`, `workflow.md`) that follow
9
- every rule, with the output of real runs.
9
+ every rule, with the output of real runs; `ruby/examples/cli.md` is the
10
+ CLI project with its steps in Ruby.
10
11
 
11
12
  ## S1. A Then claims a value, not a verdict
12
13
 
@@ -80,7 +81,7 @@ Checked by: `outline-rows-share-name`.
80
81
 
81
82
  Bad: scenario 2 reads the item scenario 1 created. The server
82
83
  the config's `program` starts serves every scenario of the run, as a
83
- fixture with `scope: "process"` does. Measured in `examples/http-api.md`:
84
+ fixture with `scope: "process"` does. Measured in `typescript/examples/http-api.md`:
84
85
  the read got `{"id":2,"name":"lamp"}` where the feature expected id 1.
85
86
  Good: `Given an item named "lamp" exists` in the scenario that reads it,
86
87
  and claims on what the scenario created (the body the Given returned),
@@ -111,7 +112,7 @@ A scenario that breaks a rule on purpose, such as signing in before
111
112
  confirming, uses a step that does not require what the rule demands
112
113
  (`states.md`).
113
114
  Checked by: `from-order-violation` when the action written as a Given has
114
- no Given before it to read from (`examples/cli.md`),
115
+ no Given before it to read from (`typescript/examples/cli.md`),
115
116
  `claims-outside-then` for a claim step in Given or When position, and
116
117
  `then-without-claims` for a step that runs in Then position; the rest is
117
118
  review.
@@ -121,7 +122,7 @@ review.
121
122
  `nuka run` prints the first line of the error beside the failed step; the
122
123
  rest is in the step record. A Then gets this from its claims: a broken
123
124
  claim's line names both values and where each came from. Measured in
124
- `examples/cli.md`: `claim broken: "food: 5.5\nrent: 100"
125
+ `typescript/examples/cli.md`: `claim broken: "food: 5.5\nrent: 100"
125
126
  (from:run-tally@16.stdout as text) equal "food: 5.5\nrent: 101"
126
127
  (sentence:expected); first difference at line 2: actual "rent: 100",
127
128
  expected "rent: 101"`.
@@ -171,7 +172,7 @@ A lesson from a real run is promoted in three stages, and each stage
171
172
  replaces the one before it:
172
173
 
173
174
  1. **An example row.** Add the decision to the "Decisions" table of the
174
- example for that kind of project (`examples/<shape>.md`): the date, the
175
+ example for that kind of project (`typescript/examples/<shape>.md`): the date, the
175
176
  decision, what was chosen, and why. Add a new example file when no
176
177
  existing shape fits.
177
178
  2. **A rule here.** A decision becomes a rule when it comes up in a second
@@ -7,6 +7,12 @@ cannot carry that, because nothing is returned. Declare it as a state, and
7
7
 
8
8
  ## Declaring one
9
9
 
10
+ ```ruby
11
+ requires ["signed-in", :person] # on the step that cannot work without it
12
+ gives ["signed-in", :person] # on the step that leaves it holding
13
+ ends ["signed-in", :person] # on the step that undoes it
14
+ ```
15
+
10
16
  ```ts
11
17
  requires: [["signed-in", "person"]], // on the step that cannot work without it
12
18
  gives: [["signed-in", "person"]], // on the step that leaves it holding
@@ -15,7 +21,7 @@ ends: [["signed-in", "person"]], // on the step that undoes it
15
21
 
16
22
  The second element names the args key whose value tells holders apart, so
17
23
  aki signed in says nothing about ben. A state one reader holds is the bare
18
- name: `requires: ["book-open"]`. Write each state the same way in every
24
+ name: `requires "book-open"` (`requires: ["book-open"]`). Write each state the same way in every
19
25
  step, keyed everywhere or bare everywhere; `state-shape-mismatch` names
20
26
  the steps that differ. A claim step may `requires`; it has no `gives` or
21
27
  `ends`, because it changes nothing.