Search code examples
ruby-on-railscucumberrenderpartial

Cucumber fails with "Undefined method render"


I have a link_tag in view which add rendered content to page

link_to("add",nil,:id=>"create_row_cycle",:onclick=>"$('div#cycle_form table').append('#{escape_javascript(render(:partial=>'cycles', :object=>Cycle.new))}');return false;", :href=>"")

I want to test that code in cucumber and cucumber fails that method RENDER undefined.

my step is

find('div#cycle_form table').text.should have_content(render(:partial=>'cycles', :object=>Cycle.new))

Help please, how can I test this with cucumber?


Solution

  • Cucumber doesn't understand the "render" part of the request - what you'd want to do is find some content that exists in the "cycles" partial and check for that. For example, if your "cycles" partial contained the text "Here are the cycles for object <%= object.name %>", then your cucumber test would look like

    find('div#cycle_form table').text.should have_content("Here are the cycles for object #{object.name}")
    

    In that way, you can ensure that your cycles partial is rendering correctly.