lib/speculation/spec/f_spec.rb in speculation-0.4.0 vs lib/speculation/spec/f_spec.rb in speculation-0.4.2
- old
+ new
@@ -12,30 +12,34 @@
attr_reader :args, :ret, :fn, :block
def initialize(args: nil, ret: nil, fn: nil, block: nil, gen: nil)
@args = args
- @ret = ret
+ @ret = ret || :"Speculation/any"
@fn = fn
@block = block
@gen = gen
end
def conform(f)
raise "Can't conform fspec without args spec: #{inspect}" unless @args
- return S::INVALID unless f.is_a?(Proc) || f.is_a?(Method)
+ return :"Speculation/invalid" unless f.is_a?(Proc) || f.is_a?(Method)
specs = { :args => @args, :ret => @ret, :fn => @fn, :block => @block }
if f.equal?(FSpec.validate_fn(f, specs, S.fspec_iterations))
f
else
- S::INVALID
+ :"Speculation/invalid"
end
end
+ def unform(f)
+ f
+ end
+
def explain(path, via, inn, f)
unless f.respond_to?(:call)
return [{ :path => path, :pred => [f.method(:respond_to?), [:call]], :val => f, :via => via, :in => inn }]
end
@@ -64,10 +68,10 @@
def with_gen(gen)
self.class.new(:args => @args, :ret => @ret, :fn => @fn, :block => @block, :gen => gen)
end
def gen(overrides, _path, _rmap)
- return @gen if @gen
+ return @gen.call if @gen
->(_rantly) do
->(*args, &block) do
unless S.pvalid?(@args, args)
raise S.explain_str(@args, args)