Missing Template when testing with the Brain Buster Captcha partial

When I run my functional tests, they throw an error with the following message:

ActionView::TemplateError: Missing template /_captcha.erb in view path app/views:test/vendor/plugins/brain_buster/views/brain_busters     On line #23 of app/views/contacts/_form.html.erb

        20: <%= f.label :message %><br />         21: <%= f.text_area :message %>         22: </div>         23: <%= render :partial => '/captcha' unless action_name == 'edit' %>         24: <div><%= f.submit "Submit" %></div>         25: <% end %>

        app/views/contacts/_form.html.erb:23         app/views/contacts/_form.html.erb:1         app/views/contacts/edit.html.erb:1         app/controllers/contacts_controller.rb:41:in `update'         functional/contacts_controller_test.rb:80:in `__bind_1244348412_114'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:271:in `call'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:271:in `run_current_setup_blocks'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:270:in `each'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:270:in `run_current_setup_blocks'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:252:in `test: on PUT to :update with invalid params should respond with success. '         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'         /usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb: 46:in `run_suite'         /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb: 67:in `start_mediator'         /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb: 41:in `start'         /usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb: 29:in `run'         /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'         /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'         /usr/local/lib/ruby/1.8/test/unit.rb:278         functional/contacts_controller_test.rb:88

I've checked to make sure the partial is in the right location, it is in this directory:

/vendor/plugins/brain_buster/views/brain_busters/_captcha.html.erb

Any ideas as to why the test can't find the partial? It works fine when I test it manually (via the browser).

Take off the slash?

   <%= render :partial => 'captcha' unless action_name == 'edit' %>

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

Thanks, but unfortunately, that had no affect…have you ever run into this kind of thing before?

Just to experiment, I used this instead:

<%= render :partial => "#{RAILS_ROOT}/vendor/plugins/brain_buster/ views/brain_busters/captcha.html.erb" unless action_name == 'edit' %>

and now I get the following error:

ActionView::TemplateError: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id     On line #4 of vendor/plugins/brain_buster/views/brain_busters/ _captcha.html.erb

        1: <% unless captcha_passed? %>         2: <span id="brain_buster_captcha" class="<%= if last_captcha_attempt_failed? then 'captcha_failed' end %>">         3:         4: <%= hidden_field_tag :captcha_id, @captcha.id %>         5:         6: <label for="captcha_answer">         7: Spam protection: <%= @captcha.question %>

        vendor/plugins/brain_buster/views/brain_busters/ _captcha.html.erb:4         app/views/contacts/_form.html.erb:23         app/views/contacts/_form.html.erb:1         app/views/contacts/edit.html.erb:1         app/controllers/contacts_controller.rb:41:in `update'         functional/contacts_controller_test.rb:80:in `__bind_1244416417_125477'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:271:in `call'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:271:in `run_current_setup_blocks'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:270:in `each'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:270:in `run_current_setup_blocks'         /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/ lib/shoulda/context.rb:252:in `test: on PUT to :update with invalid params should assign @contact with a kind of Contact. '         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'         /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'         /usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb: 46:in `run_suite'         /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb: 67:in `start_mediator'         /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb: 41:in `start'         /usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb: 29:in `run'         /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'         /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'         /usr/local/lib/ruby/1.8/test/unit.rb:278         functional/contacts_controller_test.rb:88

I feel like after that point I'm just chasing the white rabbit, seems that once I figure out the initial problem, things should be okay.

My original suggestion was based on the error message:

ActionView::TemplateError: Missing template /_captcha.erb in view path app/views:test/vendor/plugins/brain_buster/views/brain_busters

The partial you called out was   render :partial => '/captcha'

Your new error is clearly that the @captcha instance variable has no value in the partial. Have you tried something like:

  render :partial => 'captcha', :object => @captcha

and then within your _captcha.html.erb template using a local variable:

  <%= hidden_field_tag :captcha_id, captcha.id %>

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

Sorry, I didn't mean to confuse. I'd say the first error…

ActionView::TemplateError: Missing template /_captcha.erb in view path app/views:test/vendor/plugins/brain_buster/views/brain_busters

…is still the prominent one. I tried your suggestion and am getting the same error. Do you have any other suggestions?

I appreciate you taking the time!

Matt

I met the same problem and solved it.

When I run my functional tests, they throw an error with the following message:

ActionView::TemplateError: Missing template /_captcha.erb in view path app/views:test/vendor/plugins/brain_buster/views/brain_busters     On line #23 of app/views/contacts/_form.html.erb

        20: <%= f.label :message %><br />         21: <%= f.text_area :message %>         22: </div>         23: <%= render :partial => '/captcha' unless action_name == 'edit' %>         24: <div><%= f.submit "Submit" %></div>         25: <% end %>

I changed single quotation to double quotation. <%= render :partial => "captcha" %>