runtime_analysis 1.0.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +115 -0
- data/LICENSE.txt +96 -0
- data/README.md +164 -0
- data/editor/nvim/README.md +278 -0
- data/editor/nvim/lua/runtime_analysis/connected.lua +565 -0
- data/editor/nvim/lua/runtime_analysis/go_to_class.lua +63 -0
- data/editor/nvim/lua/runtime_analysis/inline.lua +138 -0
- data/editor/nvim/lua/runtime_analysis/lens.lua +50 -0
- data/editor/nvim/lua/runtime_analysis/lsp.lua +92 -0
- data/editor/nvim/lua/runtime_analysis/menu.lua +98 -0
- data/editor/nvim/lua/runtime_analysis/preview.lua +70 -0
- data/editor/nvim/lua/runtime_analysis/project.lua +28 -0
- data/editor/nvim/lua/runtime_analysis/rerun.lua +39 -0
- data/editor/nvim/lua/runtime_analysis/text.lua +23 -0
- data/editor/nvim/lua/runtime_analysis/value_popup.lua +45 -0
- data/editor/nvim/plugin/runtime_analysis.lua +71 -0
- data/examples/trackers/PROMPT.md +86 -0
- data/examples/trackers/honeybadger.rb +19 -0
- data/examples/trackers/sentry.rb +16 -0
- data/ext/runtime_analysis/extconf.rb +68 -0
- data/ext/runtime_analysis/fast.c +775 -0
- data/ext/runtime_analysis/fast.h +59 -0
- data/ext/runtime_analysis/hold.c +560 -0
- data/ext/runtime_analysis/init.c +36 -0
- data/ext/runtime_analysis/names.c +78 -0
- data/ext/runtime_analysis/names.h +28 -0
- data/ext/runtime_analysis/novelty.c +139 -0
- data/ext/runtime_analysis/novelty.h +22 -0
- data/ext/runtime_analysis/os.c +73 -0
- data/ext/runtime_analysis/os.h +32 -0
- data/ext/runtime_analysis/ring.c +445 -0
- data/ext/runtime_analysis/rows.c +304 -0
- data/ext/runtime_analysis/sink.c +485 -0
- data/ext/runtime_analysis/sink.h +240 -0
- data/ext/runtime_analysis/state.c +254 -0
- data/ext/runtime_analysis/state.h +57 -0
- data/ext/runtime_analysis/wrapper.c +278 -0
- data/ext/runtime_analysis/wrapper.h +24 -0
- data/lib/runtime_analysis/errors.rb +34 -0
- data/lib/runtime_analysis/failsafe.rb +123 -0
- data/lib/runtime_analysis/host/controller_entry_point.rb +18 -0
- data/lib/runtime_analysis/host/declared.rb +152 -0
- data/lib/runtime_analysis/host/inject.rb +90 -0
- data/lib/runtime_analysis/host/job_runners.rb +27 -0
- data/lib/runtime_analysis/host/middleware.rb +23 -0
- data/lib/runtime_analysis/host/minitest_integration.rb +22 -0
- data/lib/runtime_analysis/host/railtie.rb +42 -0
- data/lib/runtime_analysis/host/reports.rb +54 -0
- data/lib/runtime_analysis/host/rspec_integration.rb +17 -0
- data/lib/runtime_analysis/host/web.rb +22 -0
- data/lib/runtime_analysis/host.rb +34 -0
- data/lib/runtime_analysis/inject.rb +5 -0
- data/lib/runtime_analysis/minitest.rb +9 -0
- data/lib/runtime_analysis/native/build.rb +17 -0
- data/lib/runtime_analysis/native/byte_size.rb +27 -0
- data/lib/runtime_analysis/native/call_site_logger/definitions.rb +51 -0
- data/lib/runtime_analysis/native/call_site_logger/held.rb +35 -0
- data/lib/runtime_analysis/native/call_site_logger/rows.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger/segments.rb +100 -0
- data/lib/runtime_analysis/native/call_site_logger/streams.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger.rb +80 -0
- data/lib/runtime_analysis/native/rotation_policy.rb +28 -0
- data/lib/runtime_analysis/native/sanitizer_runtime.rb +50 -0
- data/lib/runtime_analysis/native/sink.rb +12 -0
- data/lib/runtime_analysis/native.rb +74 -0
- data/lib/runtime_analysis/platform.rb +30 -0
- data/lib/runtime_analysis/query/index/anonymise.rb +98 -0
- data/lib/runtime_analysis/query/index/graph.rb +107 -0
- data/lib/runtime_analysis/query/index/graph_cache.rb +32 -0
- data/lib/runtime_analysis/query/index/reading/declared.rb +42 -0
- data/lib/runtime_analysis/query/index/reading/dict.rb +43 -0
- data/lib/runtime_analysis/query/index/reading/frame.rb +27 -0
- data/lib/runtime_analysis/query/index/reading/node.rb +45 -0
- data/lib/runtime_analysis/query/index/reading/path.rb +21 -0
- data/lib/runtime_analysis/query/index/reading/reruns.rb +30 -0
- data/lib/runtime_analysis/query/index/reading/rows.rb +128 -0
- data/lib/runtime_analysis/query/index/reading/stream.rb +82 -0
- data/lib/runtime_analysis/query/index/reading/tree.rb +66 -0
- data/lib/runtime_analysis/query/index/reading/tree_builder.rb +135 -0
- data/lib/runtime_analysis/query/index/reading/values.rb +49 -0
- data/lib/runtime_analysis/query/index/reading.rb +80 -0
- data/lib/runtime_analysis/query/index/shapes.rb +142 -0
- data/lib/runtime_analysis/query/index/signatures/active_support.rb +31 -0
- data/lib/runtime_analysis/query/index/signatures/core.json +1 -0
- data/lib/runtime_analysis/query/index/signatures/layers.rb +29 -0
- data/lib/runtime_analysis/query/index/signatures/lineage.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/overloads.rb +32 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/entry.rb +95 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/export.rb +76 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/library.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/overload.rb +66 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/project.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/types.rb +79 -0
- data/lib/runtime_analysis/query/index/signatures/rbs.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/sig.rb +48 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/signed.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/table.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/types.rb +96 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet.rb +150 -0
- data/lib/runtime_analysis/query/index/signatures/sources.rb +80 -0
- data/lib/runtime_analysis/query/index/signatures/written.rb +45 -0
- data/lib/runtime_analysis/query/index/signatures.rb +93 -0
- data/lib/runtime_analysis/query/index/source_named_graph.rb +84 -0
- data/lib/runtime_analysis/query/index/static/change_set.rb +20 -0
- data/lib/runtime_analysis/query/index/static/changes.rb +80 -0
- data/lib/runtime_analysis/query/index/static/code_visitor.rb +144 -0
- data/lib/runtime_analysis/query/index/static/klass.rb +13 -0
- data/lib/runtime_analysis/query/index/static/method.rb +19 -0
- data/lib/runtime_analysis/query/index/static/params.rb +52 -0
- data/lib/runtime_analysis/query/index/static/source.rb +69 -0
- data/lib/runtime_analysis/query/index/static/stub.rb +14 -0
- data/lib/runtime_analysis/query/index/static/stub_visitor.rb +133 -0
- data/lib/runtime_analysis/query/index/static/value.rb +17 -0
- data/lib/runtime_analysis/query/index/static/values.rb +71 -0
- data/lib/runtime_analysis/query/index/static/visibility.rb +40 -0
- data/lib/runtime_analysis/query/index/static.rb +85 -0
- data/lib/runtime_analysis/query/index.rb +32 -0
- data/lib/runtime_analysis/query/nodes.rb +60 -0
- data/lib/runtime_analysis/query/project/config.rb +108 -0
- data/lib/runtime_analysis/query/project.rb +40 -0
- data/lib/runtime_analysis/query/report/document.rb +84 -0
- data/lib/runtime_analysis/query/report/finding.rb +15 -0
- data/lib/runtime_analysis/query/report/json_renderer.rb +51 -0
- data/lib/runtime_analysis/query/report/list.rb +15 -0
- data/lib/runtime_analysis/query/report/location.rb +14 -0
- data/lib/runtime_analysis/query/report/one_row.rb +14 -0
- data/lib/runtime_analysis/query/report/outline.rb +15 -0
- data/lib/runtime_analysis/query/report/paint.rb +34 -0
- data/lib/runtime_analysis/query/report/related.rb +11 -0
- data/lib/runtime_analysis/query/report/table.rb +15 -0
- data/lib/runtime_analysis/query/report/text.rb +13 -0
- data/lib/runtime_analysis/query/report/text_renderer.rb +102 -0
- data/lib/runtime_analysis/query/report.rb +35 -0
- data/lib/runtime_analysis/query/surfaces/class_value.rb +17 -0
- data/lib/runtime_analysis/query/surfaces/cli/answer.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli/command_line.rb +77 -0
- data/lib/runtime_analysis/query/surfaces/cli/usage.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli.rb +101 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/lexical.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/notation.rb +33 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/observed.rb +102 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/outline.rb +111 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_file.rb +100 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_member.rb +50 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_notation.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/seen.rb +74 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sig_text.rb +49 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_edit.rb +106 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_notation.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/subject.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/crystallise.rb +94 -0
- data/lib/runtime_analysis/query/surfaces/mcp.rb +89 -0
- data/lib/runtime_analysis/query/surfaces/record/commands.rb +45 -0
- data/lib/runtime_analysis/query/surfaces/record/environment.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/record/ignore.rb +62 -0
- data/lib/runtime_analysis/query/surfaces/record/question.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/record/run.rb +30 -0
- data/lib/runtime_analysis/query/surfaces/record.rb +122 -0
- data/lib/runtime_analysis/query/surfaces/rerun.rb +87 -0
- data/lib/runtime_analysis/query/surfaces/setup/agents.rb +76 -0
- data/lib/runtime_analysis/query/surfaces/setup/changes.rb +107 -0
- data/lib/runtime_analysis/query/surfaces/setup/project.rb +80 -0
- data/lib/runtime_analysis/query/surfaces/setup/steps.md +205 -0
- data/lib/runtime_analysis/query/surfaces/setup.rb +98 -0
- data/lib/runtime_analysis/query/surfaces.rb +14 -0
- data/lib/runtime_analysis/query/tools/base.rb +86 -0
- data/lib/runtime_analysis/query/tools/method_lookup.rb +37 -0
- data/lib/runtime_analysis/query/tools/namespaces.rb +36 -0
- data/lib/runtime_analysis/query/tools/origins.rb +47 -0
- data/lib/runtime_analysis/query/tools/stubs.rb +53 -0
- data/lib/runtime_analysis/query/tools/unknown_method.rb +11 -0
- data/lib/runtime_analysis/query/tools/verify_mock.rb +145 -0
- data/lib/runtime_analysis/query/tools/what_calls.rb +67 -0
- data/lib/runtime_analysis/query/tools/what_it_receives.rb +142 -0
- data/lib/runtime_analysis/query/tools/where_nil_comes_from.rb +105 -0
- data/lib/runtime_analysis/query/tools/who_actually_answered.rb +82 -0
- data/lib/runtime_analysis/query/tools.rb +34 -0
- data/lib/runtime_analysis/query.rb +33 -0
- data/lib/runtime_analysis/recording/blob.rb +13 -0
- data/lib/runtime_analysis/recording/format.rb +32 -0
- data/lib/runtime_analysis/recording/opcodes.rb +30 -0
- data/lib/runtime_analysis/recording/raise_ids.rb +15 -0
- data/lib/runtime_analysis/recording/ruby_sink.rb +176 -0
- data/lib/runtime_analysis/recording/run_manifest.rb +110 -0
- data/lib/runtime_analysis/recording/seen/nothing.rb +15 -0
- data/lib/runtime_analysis/recording/seen/tally.rb +48 -0
- data/lib/runtime_analysis/recording/seen.rb +63 -0
- data/lib/runtime_analysis/recording/sink.rb +19 -0
- data/lib/runtime_analysis/recording/source_blob.rb +20 -0
- data/lib/runtime_analysis/recording.rb +52 -0
- data/lib/runtime_analysis/rspec.rb +8 -0
- data/lib/runtime_analysis/ruby_parsing/packages.rb +17 -0
- data/lib/runtime_analysis/ruby_parsing.rb +98 -0
- data/lib/runtime_analysis/trace/configuration/capturing.rb +32 -0
- data/lib/runtime_analysis/trace/configuration/per_run.rb +31 -0
- data/lib/runtime_analysis/trace/configuration/tier.rb +27 -0
- data/lib/runtime_analysis/trace/configuration.rb +115 -0
- data/lib/runtime_analysis/trace/entries.rb +47 -0
- data/lib/runtime_analysis/trace/hold/raises.rb +28 -0
- data/lib/runtime_analysis/trace/hold/requests.rb +47 -0
- data/lib/runtime_analysis/trace/hold/telling.rb +45 -0
- data/lib/runtime_analysis/trace/hold/unwound.rb +30 -0
- data/lib/runtime_analysis/trace/hold.rb +142 -0
- data/lib/runtime_analysis/trace/inclusion.rb +46 -0
- data/lib/runtime_analysis/trace/installer/alias_repair.rb +68 -0
- data/lib/runtime_analysis/trace/installer/answers.rb +24 -0
- data/lib/runtime_analysis/trace/installer/body_sync.rb +25 -0
- data/lib/runtime_analysis/trace/installer/built_classes.rb +43 -0
- data/lib/runtime_analysis/trace/installer/called_names.rb +33 -0
- data/lib/runtime_analysis/trace/installer/class_builders.rb +50 -0
- data/lib/runtime_analysis/trace/installer/deferral.rb +42 -0
- data/lib/runtime_analysis/trace/installer/hook.rb +170 -0
- data/lib/runtime_analysis/trace/installer/included_gems.rb +53 -0
- data/lib/runtime_analysis/trace/installer/probe.rb +28 -0
- data/lib/runtime_analysis/trace/installer/reflection.rb +50 -0
- data/lib/runtime_analysis/trace/installer/registry.rb +78 -0
- data/lib/runtime_analysis/trace/installer/sorbet.rb +29 -0
- data/lib/runtime_analysis/trace/installer/wrapping/ivar_writes.rb +62 -0
- data/lib/runtime_analysis/trace/installer/wrapping.rb +66 -0
- data/lib/runtime_analysis/trace/installer.rb +149 -0
- data/lib/runtime_analysis/trace/mechanism/block_entries.rb +29 -0
- data/lib/runtime_analysis/trace/mechanism/frame_readers.rb +61 -0
- data/lib/runtime_analysis/trace/mechanism/native_asks.rb +36 -0
- data/lib/runtime_analysis/trace/mechanism/native_sync.rb +28 -0
- data/lib/runtime_analysis/trace/mechanism/pure_wrapper.rb +41 -0
- data/lib/runtime_analysis/trace/mechanism/ruby_wrapper.rb +141 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper.rb +79 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper_shape.rb +40 -0
- data/lib/runtime_analysis/trace/mechanism.rb +28 -0
- data/lib/runtime_analysis/trace/nil_origin/answers.rb +24 -0
- data/lib/runtime_analysis/trace/nil_origin/beyond.rb +182 -0
- data/lib/runtime_analysis/trace/nil_origin/index.rb +164 -0
- data/lib/runtime_analysis/trace/nil_origin/lifetime.rb +29 -0
- data/lib/runtime_analysis/trace/nil_origin/named.rb +48 -0
- data/lib/runtime_analysis/trace/nil_origin/objects.rb +78 -0
- data/lib/runtime_analysis/trace/nil_origin/provenance.rb +136 -0
- data/lib/runtime_analysis/trace/nil_origin/receiver.rb +121 -0
- data/lib/runtime_analysis/trace/nil_origin/rows.rb +43 -0
- data/lib/runtime_analysis/trace/nil_origin/source.rb +315 -0
- data/lib/runtime_analysis/trace/nil_origin/stored.rb +159 -0
- data/lib/runtime_analysis/trace/nil_origin/told.rb +152 -0
- data/lib/runtime_analysis/trace/nil_origin/values.rb +47 -0
- data/lib/runtime_analysis/trace/nil_origin/weighed.rb +70 -0
- data/lib/runtime_analysis/trace/nil_origin/writers.rb +79 -0
- data/lib/runtime_analysis/trace/nil_origin.rb +278 -0
- data/lib/runtime_analysis/trace/novelty.rb +17 -0
- data/lib/runtime_analysis/trace/pure/novelty.rb +43 -0
- data/lib/runtime_analysis/trace/pure/state.rb +94 -0
- data/lib/runtime_analysis/trace/pure.rb +15 -0
- data/lib/runtime_analysis/trace/recorder/class_name.rb +63 -0
- data/lib/runtime_analysis/trace/recorder/fingerprint.rb +39 -0
- data/lib/runtime_analysis/trace/recorder/frame_key.rb +27 -0
- data/lib/runtime_analysis/trace/recorder/paths.rb +89 -0
- data/lib/runtime_analysis/trace/recorder/raise_site.rb +36 -0
- data/lib/runtime_analysis/trace/recorder/reachability.rb +46 -0
- data/lib/runtime_analysis/trace/recorder/row_emission.rb +137 -0
- data/lib/runtime_analysis/trace/recorder/safe_steps.rb +84 -0
- data/lib/runtime_analysis/trace/recorder/tree_steps.rb +42 -0
- data/lib/runtime_analysis/trace/recorder/unwinding.rb +23 -0
- data/lib/runtime_analysis/trace/recorder.rb +149 -0
- data/lib/runtime_analysis/trace/state.rb +16 -0
- data/lib/runtime_analysis/trace.rb +142 -0
- data/lib/runtime_analysis/version.rb +6 -0
- data/lib/runtime_analysis/web.rb +6 -0
- data/lib/runtime_analysis.rb +125 -0
- metadata +330 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Set up runtime_analysis
|
|
2
|
+
|
|
3
|
+
runtime_analysis records what your objects do while your code runs, and answers questions about it
|
|
4
|
+
from the command line, from a coding agent and from your editor.
|
|
5
|
+
|
|
6
|
+
`ra setup` does steps 1 to 4 below for you and says what it changed. This page is the
|
|
7
|
+
same steps by hand, for when your project is laid out differently, and the steps it leaves to you.
|
|
8
|
+
|
|
9
|
+
If you are a coding agent following this for someone: do the steps in order, check each one worked
|
|
10
|
+
before the next, change only the files named here, and finish with the report in step 9.
|
|
11
|
+
|
|
12
|
+
To try the gem before changing the project, skip steps 1 to 4: after `gem install runtime_analysis`,
|
|
13
|
+
`ra record` runs the tests with the recorder loaded from the installed gem, and `ra record dev` the
|
|
14
|
+
server. They change no file git would show. Run them as `ra`, without `bundle exec`. The steps below
|
|
15
|
+
are for a project that records in CI or needs its own settings, and once the gem is in the bundle
|
|
16
|
+
`ra record` uses the project's configuration.
|
|
17
|
+
|
|
18
|
+
## On your machine
|
|
19
|
+
|
|
20
|
+
### 1. Add the gem
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
bundle add runtime_analysis --group "development, test"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Switch recording on when asked for
|
|
27
|
+
|
|
28
|
+
Recording is opt-in for each process. It has to be configured before your own code loads, because
|
|
29
|
+
the gem wraps methods as they are defined and does not go back for ones already defined.
|
|
30
|
+
|
|
31
|
+
In a Rails app this goes in `config/initializers/runtime_analysis.rb`. Anywhere else it goes at the
|
|
32
|
+
top of `spec/spec_helper.rb` or `test/test_helper.rb`, above the lines that require your code, with
|
|
33
|
+
`require "runtime_analysis"` before it.
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
if ENV["RUNTIME_ANALYSIS_ENABLED"]
|
|
37
|
+
RuntimeAnalysis.configure do |c|
|
|
38
|
+
c.included = %w[app lib]
|
|
39
|
+
c.recording_dir = ENV.fetch("RUNTIME_ANALYSIS_OUTPUT", "tmp/runtime_analysis")
|
|
40
|
+
c.tier = ENV.fetch("RUNTIME_ANALYSIS_TIER", "raises")
|
|
41
|
+
end
|
|
42
|
+
RuntimeAnalysis.start!
|
|
43
|
+
at_exit { RuntimeAnalysis.finish! }
|
|
44
|
+
end
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`c.included` is the directories that hold your own code.
|
|
48
|
+
|
|
49
|
+
### 3. Name each test in the recording
|
|
50
|
+
|
|
51
|
+
For RSpec, near the top of `spec/spec_helper.rb`:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
require "runtime_analysis/rspec"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For Minitest, near the top of `test/test_helper.rb`:
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
require "runtime_analysis/minitest"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 4. Keep the recording out of git
|
|
64
|
+
|
|
65
|
+
Add `tmp/runtime_analysis/` to `.gitignore`, unless `tmp/` is already ignored.
|
|
66
|
+
|
|
67
|
+
### 5. Record your tests
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
RUNTIME_ANALYSIS_ENABLED=1 bundle exec rspec
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Use your own test command if it is different. If the suite takes more than a few minutes, record one
|
|
74
|
+
directory first so there is something to look at.
|
|
75
|
+
|
|
76
|
+
`tmp/runtime_analysis` should now hold files named `run.*.json`. If it does not, the configuration in
|
|
77
|
+
step 2 ran after your code loaded.
|
|
78
|
+
|
|
79
|
+
### 6. Ask it something
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
ra verify_mock spec
|
|
83
|
+
ra tools
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`verify_mock` lists the stubs whose return the real collaborator never produced. For Minitest pass
|
|
87
|
+
`test` instead of `spec`. `ra tools` lists everything else you can ask. The Pro tools are in the `ra`
|
|
88
|
+
binary, which reads the same recording: https://www.runtimeanalyz.ing says how to install it and
|
|
89
|
+
ask for a trial.
|
|
90
|
+
|
|
91
|
+
### 7. Connect your coding agent
|
|
92
|
+
|
|
93
|
+
The tools you can run are served over MCP, so an agent can ask them while it works:
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
bundle add mcp --group development
|
|
97
|
+
claude mcp add --scope user ra -- ra mcp
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The second line is for Claude Code. In another agent, add `ra mcp` to its MCP
|
|
101
|
+
configuration as a stdio server for this project.
|
|
102
|
+
|
|
103
|
+
### 8. Mount the stats endpoint, in a Rails app that records while it serves
|
|
104
|
+
|
|
105
|
+
Skip this if recording only ever happens in tests. If you are an agent, ask before you add the route.
|
|
106
|
+
|
|
107
|
+
`RuntimeAnalysis::Web` is a Rack app. `GET /_ra/stats` says whether the process that answered is
|
|
108
|
+
recording, and how many calls it recorded, skipped and dropped. It holds counts and nothing that was
|
|
109
|
+
recorded, and it has no authentication of its own, so the work here is choosing its guard.
|
|
110
|
+
|
|
111
|
+
A mounted Rack app does not run controller filters. The guard has to be in the routes. Look for one
|
|
112
|
+
the app already has, in this order:
|
|
113
|
+
|
|
114
|
+
1. **Another internal tool mounted in `config/routes.rb`**, such as `Sidekiq::Web`, `Flipper::UI`,
|
|
115
|
+
`PgHero::Engine`, `GoodJob::Engine` or `MissionControl::Jobs::Engine`. Mount this beside it,
|
|
116
|
+
inside the same block, so it gets the same guard:
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
require "runtime_analysis/web"
|
|
120
|
+
|
|
121
|
+
authenticate :user, ->(user) { user.admin? } do
|
|
122
|
+
mount Sidekiq::Web, at: "/sidekiq"
|
|
123
|
+
mount RuntimeAnalysis::Web, at: "/_ra"
|
|
124
|
+
end
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
That block is Devise's. Use whatever the app's own block is: `authenticate`, `authenticated`, a
|
|
128
|
+
`constraints` object or a lambda.
|
|
129
|
+
|
|
130
|
+
2. **No tool is mounted, but the app has admins.** Find how its admin pages are protected and write
|
|
131
|
+
the same check as a routes constraint.
|
|
132
|
+
|
|
133
|
+
3. **Neither.** Give it a password of its own, kept out of the code:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
require "runtime_analysis/web"
|
|
137
|
+
|
|
138
|
+
stats = Rack::Auth::Basic.new(RuntimeAnalysis::Web) do |_user, password|
|
|
139
|
+
ActiveSupport::SecurityUtils.secure_compare(password, ENV.fetch("RA_STATS_PASSWORD"))
|
|
140
|
+
end
|
|
141
|
+
mount stats, at: "/_ra"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
4. **It is only wanted on a laptop.** Mount it there and nowhere else:
|
|
145
|
+
|
|
146
|
+
```ruby
|
|
147
|
+
mount RuntimeAnalysis::Web, at: "/_ra" if Rails.env.development?
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Do not leave it open in production. If you cannot tell which guard is right, stop and ask.
|
|
151
|
+
|
|
152
|
+
Then check it. `bin/rails routes | grep _ra` shows the mount. A request with no credentials must be
|
|
153
|
+
refused, and one with them answers JSON that starts `{"running":`.
|
|
154
|
+
|
|
155
|
+
### 9. If you are an agent, report back
|
|
156
|
+
|
|
157
|
+
Say which files you changed, what `verify_mock` found, quoting its findings, the last line `ra tools`
|
|
158
|
+
printed, and that `RUNTIME_ANALYSIS_ENABLED=1` before the test command records again. If you mounted
|
|
159
|
+
the stats endpoint, say where and which guard it is behind.
|
|
160
|
+
|
|
161
|
+
## In your editor
|
|
162
|
+
|
|
163
|
+
`ra lsp` is a language server over stdio. It shows the classes each argument was given
|
|
164
|
+
and what each call returned as inline hints, the same on hover, and `verify_mock` findings as
|
|
165
|
+
diagnostics. "Go to type definition" opens the class of the value under the cursor, and for an
|
|
166
|
+
Array the class it held.
|
|
167
|
+
|
|
168
|
+
Neovim has a plugin, which ships in the gem. In it `gf` goes to that class, and `<leader>ra` opens a
|
|
169
|
+
menu of every tool:
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
ln -s "$(bundle info runtime_analysis --path)/editor/nvim" ~/.config/nvim/pack/local/start/runtime_analysis
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Any other editor with a language server client can run `ra lsp` for Ruby files, from the
|
|
176
|
+
project's root. No plugin exists yet for VS Code, Vim, Sublime Text or Zed.
|
|
177
|
+
|
|
178
|
+
## In CI
|
|
179
|
+
|
|
180
|
+
Record the suite in CI the same way, by setting `RUNTIME_ANALYSIS_ENABLED=1` on the step that runs
|
|
181
|
+
your tests. Keep `tmp/runtime_analysis` as a build artifact if you want to look at a run afterwards.
|
|
182
|
+
|
|
183
|
+
`ra verify_mock spec` exits 1 when it finds a stub the real code never agreed with, so
|
|
184
|
+
it can fail a build.
|
|
185
|
+
|
|
186
|
+
The `ra` binary's `ra check --since origin/main` reports only what a change introduced. It needs
|
|
187
|
+
your licence key in `RUNTIME_ANALYSIS_LICENCE` in CI.
|
|
188
|
+
|
|
189
|
+
## In production
|
|
190
|
+
|
|
191
|
+
The recorder can run in any Ruby process, and a recording of real traffic answers more than a test
|
|
192
|
+
suite can. The controls that keep its cost down in production are planned and not built: recording
|
|
193
|
+
for a few minutes after a deploy, on a share of servers, then removing itself. Until they exist,
|
|
194
|
+
record a running app in development or on a staging server.
|
|
195
|
+
|
|
196
|
+
One part is built: a server can record only the requests that fail, and tell your error tracker
|
|
197
|
+
where a nil came from. It takes a few lines beside your tracker's configuration, and
|
|
198
|
+
[Configuration](https://www.runtimeanalyz.ing/configuration#your-error-tracker) has them for Sentry
|
|
199
|
+
and Honeybadger, with a prompt that has a coding agent write them for any other tracker.
|
|
200
|
+
|
|
201
|
+
To watch the recorder in a running app, mount its stats endpoint behind your own guard, which is
|
|
202
|
+
step 8 above.
|
|
203
|
+
|
|
204
|
+
Sharing recordings with your team is also planned. A recording is a directory of files, so for now
|
|
205
|
+
it travels however your files do.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "runtime_analysis/query/report"
|
|
5
|
+
require_relative "setup/project"
|
|
6
|
+
require_relative "setup/changes"
|
|
7
|
+
require_relative "setup/agents"
|
|
8
|
+
|
|
9
|
+
module RuntimeAnalysis
|
|
10
|
+
module Query
|
|
11
|
+
module Surfaces
|
|
12
|
+
class Setup
|
|
13
|
+
STEPS = File.expand_path("setup/steps.md", __dir__)
|
|
14
|
+
MARKS = { done: %i[bold green], already: %i[dim], you: %i[yellow], optional: %i[cyan] }.freeze
|
|
15
|
+
RECORD = { rspec: "bundle exec rspec", minitest: "bundle exec rake test" }.freeze
|
|
16
|
+
NEXT = [["RUNTIME_ANALYSIS_ENABLED=1 %<record>s", "record your tests"],
|
|
17
|
+
["ra verify_mock %<tests>s", "the stubs your real code never agreed with"],
|
|
18
|
+
["ra tools", "everything else you can ask"]].freeze
|
|
19
|
+
MORE = "ra setup --print has every step, with your editor, CI and production."
|
|
20
|
+
YOURS = "Some of it is left to you, above."
|
|
21
|
+
HAND_OVER = " Or hand it to your coding agent: ra setup --agent"
|
|
22
|
+
|
|
23
|
+
def self.command(argv, out)
|
|
24
|
+
new(out).call(argv)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.steps
|
|
28
|
+
File.read(STEPS)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.project(root)
|
|
32
|
+
Project.new(root)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.record_command(framework)
|
|
36
|
+
RECORD[framework]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def initialize(out, root: Dir.pwd, path: ENV.fetch("PATH", ""), start: Kernel.public_method(:exec),
|
|
40
|
+
run: Kernel.public_method(:system))
|
|
41
|
+
@out = out
|
|
42
|
+
@project = Project.new(root)
|
|
43
|
+
@agents = Agents.new(out, path, start)
|
|
44
|
+
@run = run
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def call(argv)
|
|
48
|
+
return 0.tap { @out.puts Setup.steps } if argv.include?("--print")
|
|
49
|
+
return 0.tap { @agents.hand_over(name_after("--agent", argv)) } if argv.include?("--agent")
|
|
50
|
+
|
|
51
|
+
automate
|
|
52
|
+
0
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def name_after(flag, argv)
|
|
58
|
+
name = argv.at(argv.index(flag) + 1)
|
|
59
|
+
name unless name.to_s.start_with?("--")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def automate
|
|
63
|
+
@out.puts "Setting up runtime_analysis in #{@project.root} (#{@project})\n\n"
|
|
64
|
+
rows = Changes.new(@project, @run).rows
|
|
65
|
+
rows.each { |row| @out.puts line(row) }
|
|
66
|
+
@out.puts following(rows)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def line(row)
|
|
70
|
+
" #{paint.call(row.status.to_s.ljust(8), *MARKS.fetch(row.status))} #{row.file.ljust(42)} #{row.note}"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def following(rows)
|
|
74
|
+
"\nNext:\n#{commands.join("\n")}\n\n#{MORE}#{left(rows)}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def left(rows)
|
|
78
|
+
"\n#{YOURS}#{HAND_OVER if @agents.any?}" if rows.map(&:status).include?(:you)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def commands
|
|
82
|
+
width = filled.first.first.size
|
|
83
|
+
filled.map { |command, note| " #{command.ljust(width)} #{note}" }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def filled
|
|
87
|
+
framework = @project.framework || :rspec
|
|
88
|
+
words = { record: RECORD.fetch(framework), tests: framework == :minitest ? "test" : "spec" }
|
|
89
|
+
NEXT.map { |command, note| [format(command, words), note] }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def paint
|
|
93
|
+
@paint ||= Report.paint(@out)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: it names the namespace and the two entries the ra binary calls; nothing loads every surface,
|
|
4
|
+
# and without_the_recorder_spec.rb asserts both entries through Query.cli and Query.setup.
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Query
|
|
8
|
+
module Surfaces
|
|
9
|
+
def self.cli(argv) = Cli.run(argv)
|
|
10
|
+
|
|
11
|
+
def self.setup(argv, out) = Setup.command(argv, out)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: tools_spec.rb
|
|
4
|
+
|
|
5
|
+
require "runtime_analysis/query/report"
|
|
6
|
+
require "runtime_analysis/query/project"
|
|
7
|
+
require "runtime_analysis/query/index"
|
|
8
|
+
|
|
9
|
+
module RuntimeAnalysis
|
|
10
|
+
module Query
|
|
11
|
+
module Tools
|
|
12
|
+
class Base
|
|
13
|
+
class << self
|
|
14
|
+
attr_reader :tool_name, :description
|
|
15
|
+
|
|
16
|
+
def tool(name, description)
|
|
17
|
+
@tool_name = name
|
|
18
|
+
@description = description
|
|
19
|
+
Tools.register(self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def argument(name, description, type: :string, required: false, positional: false)
|
|
23
|
+
arguments << Argument.new(name: name, type: type, required: required, description: description,
|
|
24
|
+
positional: positional)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def arguments
|
|
28
|
+
@arguments ||= []
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def positional
|
|
32
|
+
arguments.find(&:positional)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
attr_reader :graph, :project
|
|
37
|
+
|
|
38
|
+
def initialize(graph, project: Project.new)
|
|
39
|
+
@graph = Index.as_named(graph, project)
|
|
40
|
+
@project = project
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def static
|
|
44
|
+
graph.static
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def document(title, summary = nil)
|
|
50
|
+
Report.document(title: title, summary: summary)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def relative(path)
|
|
54
|
+
project.relative(path)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def site(node)
|
|
58
|
+
"#{relative(node.call.call_file)}:#{node.call.call_line}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def caller_label(node)
|
|
62
|
+
node.container.main? ? relative(node.call.call_file) : node.container.identity
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def caller_edges(identity)
|
|
66
|
+
graph.edges_by(identity) { |node| caller_label(node) }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def parameter_names(identity)
|
|
70
|
+
method = static.method(identity)
|
|
71
|
+
method ? method.params.select { |_, kind| %i[req opt].include?(kind) }.map(&:first) : []
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def runs_phrase(count)
|
|
75
|
+
plural(count, "recorded run")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def plural(count, noun)
|
|
79
|
+
"#{count} #{noun}#{"s" unless count == 1}"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
require "runtime_analysis/query/tools"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/query/tools/base"
|
|
4
|
+
require_relative "unknown_method"
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Query
|
|
8
|
+
module Tools
|
|
9
|
+
module MethodLookup
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def resolve(graph, typed)
|
|
13
|
+
return typed if exact?(graph, typed)
|
|
14
|
+
|
|
15
|
+
candidates = by_name(graph, typed)
|
|
16
|
+
return candidates.first if candidates.size == 1
|
|
17
|
+
|
|
18
|
+
raise UnknownMethod, message_for(typed, candidates)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def exact?(graph, typed)
|
|
22
|
+
graph.method(typed)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def by_name(graph, name)
|
|
26
|
+
graph.methods.map(&:identity).select { |identity| identity.end_with?("##{name}", ".#{name}") }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def message_for(typed, candidates)
|
|
30
|
+
return "no recorded method matches #{typed}" if candidates.empty?
|
|
31
|
+
|
|
32
|
+
"#{typed} is ambiguous: #{candidates.sort.join(", ")}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module Query
|
|
5
|
+
module Tools
|
|
6
|
+
module Namespaces
|
|
7
|
+
LAYERS = %w[models controllers services jobs mailers helpers channels views].freeze
|
|
8
|
+
ROOTS = %w[app lib].freeze
|
|
9
|
+
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def of(klass, file, project)
|
|
13
|
+
return klass.split("::").first if klass.include?("::")
|
|
14
|
+
|
|
15
|
+
from_path(project.relative(file))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def from_path(path)
|
|
19
|
+
segments = path.sub(/\.rb\z/, "").split("/")
|
|
20
|
+
segments.shift if ROOTS.include?(segments.first)
|
|
21
|
+
segments.shift if segments.size > 1 && LAYERS.include?(segments.first)
|
|
22
|
+
segments.first
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def rule
|
|
26
|
+
"a namespace is a class's leading module, or for a top-level class the file's first path segment after " \
|
|
27
|
+
"app/<layer>/"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def same?(one, other)
|
|
31
|
+
one.casecmp?(other)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuntimeAnalysis
|
|
4
|
+
module Query
|
|
5
|
+
module Tools
|
|
6
|
+
module Origins
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def phrase(nodes)
|
|
10
|
+
trees = nodes.map(&:tree).uniq
|
|
11
|
+
placed = "from #{count(examples(trees), "spec example")} and #{count(trees.count(&:run?), "app run")}"
|
|
12
|
+
unknown = trees.count(&:unknown?)
|
|
13
|
+
unknown.zero? ? placed : "#{placed} and #{unplaced(unknown, "call tree")}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def unplaced(number, noun)
|
|
17
|
+
"#{count(number, noun)} with no entry point"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def examples(trees)
|
|
21
|
+
trees.select(&:spec?).map(&:entry_point).uniq.size
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def count(number, noun)
|
|
25
|
+
"#{number} #{noun}#{"s" unless number == 1}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def split(nodes)
|
|
29
|
+
trees = nodes.map(&:tree)
|
|
30
|
+
[trees.count(&:spec?), trees.count(&:run?), trees.count(&:unknown?)]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def messages(hash)
|
|
34
|
+
ordered(hash).map { |name, _| "##{name}" }.join(" ")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def classes(hash)
|
|
38
|
+
ordered(hash).map { |name, count| hash.size > 1 ? "#{name} #{count}" : name }.join(" \u00b7 ")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def ordered(hash)
|
|
42
|
+
hash.sort_by { |name, count| [-count, name] }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: verify_mock_spec.rb
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Query
|
|
7
|
+
module Tools
|
|
8
|
+
class Stubs
|
|
9
|
+
ASSIGNMENT =
|
|
10
|
+
/\A\s*(\w+)\s*=\s*(?:instance_double|class_double|object_double)\(\s*"?([A-Z]\w*(?:::\w+)*)"?\s*[,)]/
|
|
11
|
+
Resolved = Struct.new(:stub, :identity, keyword_init: true)
|
|
12
|
+
ANY_INSTANCE = %i[allow_any_instance expect_any_instance].freeze
|
|
13
|
+
|
|
14
|
+
def initialize(static, project)
|
|
15
|
+
@static = static
|
|
16
|
+
@project = project
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def under(path)
|
|
20
|
+
@static.stubs.select { |stub| stub.message && stub.file.start_with?(path) }
|
|
21
|
+
.filter_map { |stub| resolve(stub) }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def resolve(stub)
|
|
25
|
+
klass = stub.klass || local_double_class(stub)
|
|
26
|
+
return nil unless klass
|
|
27
|
+
|
|
28
|
+
Resolved.new(stub: stub, identity: "#{klass}#{class_method?(stub) ? "." : "#"}#{stub.message}")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def class_method?(stub)
|
|
34
|
+
return false if ANY_INSTANCE.include?(stub.kind)
|
|
35
|
+
|
|
36
|
+
stub.kind == :class_double || stub.receiver.match?(/\A[A-Z][\w:]*\z/)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def local_double_class(stub)
|
|
40
|
+
return nil unless stub.receiver&.match?(/\A\w+\z/)
|
|
41
|
+
|
|
42
|
+
assignment = example_lines(stub).reverse_each.find { |line| line.match?(/\A\s*#{stub.receiver}\s*=/) }
|
|
43
|
+
assignment && assignment[ASSIGNMENT, 2]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def example_lines(stub)
|
|
47
|
+
first = stub.example_location.to_s.split(":").last.to_i
|
|
48
|
+
first.upto(stub.line).filter_map { |number| @project.source_line(stub.file, number) }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|