Class: Pinspec::Runner::ProbeGenerator
- Inherits:
-
Object
- Object
- Pinspec::Runner::ProbeGenerator
- Defined in:
- lib/pinspec/runner/probe_generator.rb
Constant Summary collapse
- SERIALIZER_TEMPLATE =
File.("../../../templates/serializer.rb", __dir__)
- FACTORY_TEMPLATE =
File.("../../../templates/factory_build.rb", __dir__)
Class Method Summary collapse
- .factory_source ⇒ Object
- .generate(plan:, corpus:, fk_map:, target:, max_collection: 50) ⇒ Object
- .serializer_source ⇒ Object
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(plan:, corpus:, fk_map:, target:, max_collection: 50) ⇒ ProbeGenerator
constructor
A new instance of ProbeGenerator.
- #payload ⇒ Object
Constructor Details
#initialize(plan:, corpus:, fk_map:, target:, max_collection: 50) ⇒ ProbeGenerator
Returns a new instance of ProbeGenerator.
26 27 28 29 30 31 32 |
# File 'lib/pinspec/runner/probe_generator.rb', line 26 def initialize(plan:, corpus:, fk_map:, target:, max_collection: 50) @plan = plan @corpus = corpus @fk_map = fk_map @target = target @max_collection = max_collection end |
Class Method Details
.factory_source ⇒ Object
21 22 23 |
# File 'lib/pinspec/runner/probe_generator.rb', line 21 def factory_source File.read(FACTORY_TEMPLATE) end |
.generate(plan:, corpus:, fk_map:, target:, max_collection: 50) ⇒ Object
12 13 14 15 |
# File 'lib/pinspec/runner/probe_generator.rb', line 12 def generate(plan:, corpus:, fk_map:, target:, max_collection: 50) new(plan: plan, corpus: corpus, fk_map: fk_map, target: target, max_collection: max_collection).generate end |
.serializer_source ⇒ Object
17 18 19 |
# File 'lib/pinspec/runner/probe_generator.rb', line 17 def serializer_source File.read(SERIALIZER_TEMPLATE) end |
Instance Method Details
#generate ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/pinspec/runner/probe_generator.rb', line 54 def generate <<~RUBY # frozen_string_literal: true # # Generated by pinspec #{VERSION}. Do not edit: regenerate it. # # Runs inside the target application via `rails runner`. Requires only the # standard library beyond what the app already loads, and is held to a Ruby # 2.6 syntax floor because it runs in the app's Ruby, not pinspec's. # # Every case is wrapped in the plan's isolation regime and reversed # afterwards. Nothing here writes outside a transaction unless the plan says # the suite is untransacted, in which case the tables it touched are # truncated instead. require "json" #{indent(self.class.serializer_source, 0)} #{indent(self.class.factory_source, 0)} PINSPEC = JSON.parse(<<'PINSPEC_PAYLOAD_JSON') #{JSON.pretty_generate(payload)} PINSPEC_PAYLOAD_JSON #{indent(runtime, 0)} RUBY end |
#payload ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pinspec/runner/probe_generator.rb', line 34 def payload { "pinspec_probe_version" => PROBE_VERSION, "serializer" => SERIALIZER_VERSION, "plan_id" => @plan.plan_id, "isolation" => @plan.isolation.to_s, "env_fingerprint" => stringify(@plan.env_fingerprint), "fk_map" => @fk_map, "max_collection" => @max_collection, "target" => { "class" => @target.class_name, "method" => @target.method_name.to_s, "construction" => @target.construction_kind.to_s, "visibility" => @target.visibility.to_s }, "setup_plan" => @plan.steps.map { |step| { "kind" => step.kind.to_s, "payload" => stringify(step.payload) } }, "cases" => @corpus.cases.map { |input_case| case_payload(input_case) } } end |