我正在尝试使用FuzzBert,但无法使随机生成器正常工作。

这个例子来自official repository

require 'fuzzbert'

fuzz "Web App" do
  deploy do |data|
    #send JSON data via HTTP
  end

  data "template" do
    t = FuzzBert::Template.new <<-EOS
      { user: { id: ${id}, name: "${name}" } }
    EOS
    t.set(:id) { FuzzBert::Generators.cycle(1..10000) }
    t.set(:name) { FuzzBert::Generators.random }
    t.generator
  end
end


当我运行它(fuzzbert myfile.rb)时,出现以下错误:

fuzzbert-1.0.1/lib/fuzzbert/template.rb:17:in `block (2 levels) in to_data': can't     convert Proc into String (TypeError)


我尝试了撬式解释器,但遇到了同样的错误:

> t = FuzzBert::Template.new '{ user: { name: "${name}" } }'
> t.set(:name) { FuzzBert::Generators.random }
> t.to_data
TypeError: can't convert Proc into String
from /home/you/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/fuzzbert-1.0.1/lib/fuzzbert/template.rb:17:in `block (2 levels) in to_data'


我该如何解决?

最佳答案

不幸的是,这仅仅是一个错误。它已得到修复,我还发布了带有更新示例的新版本1.0.3。上面的示例现在将写为

require 'fuzzbert'

fuzz "Web App" do
  deploy do |data|
    #send JSON data via HTTP
  end

  data "template" do
    t = FuzzBert::Template.new <<-EOS
      { user: { id: ${id}, name: "${name}" } }
    EOS
    t.set(:id, FuzzBert::Generators.cycle(1..10000))
    t.set(:name, FuzzBert::Generators.random)
    t.generator
  end
end

10-06 15:07