378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
# File 'lib/bparity/formal/bounded.rb', line 378
def call(result:, subject_name:, operation_name:)
return contract_spec(result, subject_name, operation_name) if result.counterexample["contracts"]
input = result.counterexample.fetch("input")
expected = result.counterexample.fetch("expected")
<<~RUBY
# frozen_string_literal: true
require "bparity"
require ENV["BPARITY_REPLACEMENT"] if ENV["BPARITY_REPLACEMENT"]
load ENV.fetch("BPARITY_ADAPTER")
RSpec.describe "F2 counterexample for #{subject_name}#{operation_name}" do
it "matches the legacy observation for #{input.inspect}" do
binding = Bparity.adapter_definition.subjects.fetch(#{subject_name.inspect})
operation = binding.operations.fetch(#{operation_name.inspect})
begin
value = operation.invoke(binding.build({}), #{input.inspect}, {})
value = operation.map_return(value)
actual = { "kind" => "return", "value" => Bparity::Recording::Serializer.dump(value) }
rescue StandardError => error
mapped = operation.map_error(error).transform_keys(&:to_s)
mapped["cause"] = error.cause&.class&.name unless mapped.key?("cause")
actual = { "kind" => "raise", **mapped }
end
expect(actual).to eq(#{expected.inspect})
end
end
RUBY
end
|