Search code examples
rubytestingfuzzy

Ruby, FuzzBert, can't convert Proc into String (TypeError)


I'm trying to use FuzzBert, but i can't make the random generator work.

This example comes from the 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

When I run it (fuzzbert myfile.rb) I've got this error:

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

I've tried on pry interpreter and I've got the same error:

> 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'

How can I fix it?


Solution

  • Unfortunately, this was simply a bug. It has been fixed and I also released a new version 1.0.3 with updated examples. The above example would now be written as

    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