rspec - How would one test a custom Padrino FormBuilder? -


suppose have custom formbuilder in padrino, following:

class customformbuilder < padrino::helpers::formbuilder::abstractformbuilder   def foo(arg1, arg2, ...)     # #template   end end 

what's right way test this?

it seems correct thing like:

describe customformbuilder   "renders right output"     # ...     result = customformbuilder.new(...).template.render      expect(result).to include 'expected-content'   end end 

it's not clear me how pull off:

  • usually framework instantiates formbuilders, feels wrong i'm doing here. there better approach?
  • i don't know how pass object formbuilder accept template.
  • i don't know how result of rendering template.

what's right way test this?

i figured out after effort. idea make object represents template, pass formbuilder, make object model, , see if builder generates correct html.

describe customformbuilder   let(:template)     class.new       include padrino::helpers::outputhelpers       include padrino::helpers::formhelpers       include padrino::helpers::taghelpers     end.new   end    "makes class"     model    = class.new { include activemodel::model }.new     builder  = described_class.new template, model      expect(builder.helper_method :foo).to include 'class="expected-class"'      # or, if you're using rspec-html-matchers or similar...     expect(builder.helper_method :foo).to \       have_tag('div', :with => { :class => 'bar' })   end end 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -