[Ruby on Rails] undefined method `empty?' for nil:NilClass (ActionView::Template::Error)

2,033 views
Skip to first unread message

Vell

unread,
Mar 27, 2014, 12:40:30 PM3/27/14
to cu...@googlegroups.com
Hey guys,

I'm running into a problem that I am not quite understanding.

I am using cucumber / capybara to select an option from a dropdown list but it is giving me a failure on the select step.

I have run through these steps in the browser and didn't have any errors. Cucumber also doesn't error if I put the method directly in the view.

I am curious what is making this test fail when I have it implemented this way yet in the browser it works as expected.

Any thoughts are greatly appreciated.

My current code is as follows:

controller:

  def new
   
@discussion = Discussion.new
    form_instances
 
end

 
def edit
    form_instances
 
end



private
 
def form_instances
   
@categories = DiscussionCategory.all.collect{|category| [category.name, category.id]}
 
end


------
View [lines 15-8]:
  <div class="field">
   
<%= f.label :discussion_category %><br>
   
<%= f.select :discussion_category_id, @categories, prompt: true %>
 
</div>

Feature:
    Background: starting from the discussion group show page
       
Given there is a discussion group
       
And categories for that discussion group
       
And a user is on the discussion group index page
       
And clicks on the discussion group link
       
And the new discussion link is clicked

   
@discussion
   
Scenario: creating a valid discussion
       
And discussion group id is present
       
And the category is selected
       
...

Failing step in bold:
Given(/^there is a discussion group$/) do
 
@discussion_group = FactoryGirl.create :discussion_group
end

Given(/^categories for that discussion group$/) do
 
@discussion_categories = []
 
3.times{@discussion_categories << FactoryGirl.create(:discussion_category)}
end

Given(/^clicks on the discussion group link$/) do
  click_on
@discussion_group.name
end

Given(/^the new discussion link is clicked$/) do
  click_on
'create discussion'
end

Given(/^discussion group id is present$/) do
  page
.find_by_id('discussion_discussion_group_id').value.to_i.should eq @discussion_group.id
end

Given(/^the category is selected$/) do
 
select @discussion_categories.first.name, from: 'discussion_discussion_category_id'
end


The error I am getting is:

undefined method `empty?' for nil:NilClass (ActionView::Template::Error)
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/tags/select.rb:35:in `grouped_choices?'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/tags/select.rb:19:in `render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/form_options_helper.rb:156:in `select'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/form_options_helper.rb:774:in `select'
./app/views/discussions/_form.html.erb:17:in `block in _app_views_discussions__form_html_erb___3672191014114043450_70171974323000'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/capture_helper.rb:38:in `capture'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/form_helper.rb:435:in `form_for'
./app/views/discussions/_form.html.erb:1:in `_app_views_discussions__form_html_erb___3672191014114043450_70171974323000'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/template.rb:143:in `block in render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications.rb:161:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/template.rb:141:in `render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/partial_renderer.rb:306:in `render_partial'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/partial_renderer.rb:279:in `block in render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/partial_renderer.rb:278:in `render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/renderer.rb:47:in `render_partial'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/helpers/rendering_helper.rb:27:in `render'
./app/views/discussions/new.html.erb:3:in `_app_views_discussions_new_html_erb___1038348129427938293_70171926265080'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/template.rb:143:in `block in render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications.rb:161:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/template.rb:141:in `render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/template_renderer.rb:47:in `render_template'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/template_renderer.rb:17:in `render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/renderer.rb:42:in `render_template'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_view/renderer/renderer.rb:23:in `render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/abstract_controller/rendering.rb:127:in `_render_template'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/streaming.rb:219:in `_render_template'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/abstract_controller/rendering.rb:120:in `render_to_body'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/rendering.rb:33:in `render_to_body'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/renderers.rb:26:in `render_to_body'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/abstract_controller/rendering.rb:97:in `render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/rendering.rb:16:in `render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/lovell/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/core_ext/benchmark.rb:12:in `ms'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:41:in `block in render'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:40:in `render'
./app/controllers/discussions_controller.rb:36:in `block (2 levels) in create'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/mime_responds.rb:191:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/mime_responds.rb:191:in `respond_to'
./app/controllers/discussions_controller.rb:31:in `create'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/abstract_controller/base.rb:189:in `process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/rendering.rb:10:in `process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:413:in `_run__3725951962566406756__process_action__callbacks'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/rescue.rb:29:in `process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/abstract_controller/base.rb:136:in `process'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/abstract_controller/rendering.rb:44:in `process'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal.rb:195:in `dispatch'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_controller/metal.rb:231:in `block in action'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:80:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:48:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:71:in `block in call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:59:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:59:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:680:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/conditionalget.rb:35:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/flash.rb:241:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/cookies.rb:486:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/query_cache.rb:36:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:373:in `_run__2133552253308051269__call__callbacks'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-rails-1.4.0/lib/cucumber/rails/action_controller.rb:10:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/rack/logger.rb:38:in `call_app'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:in `block in call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:67:in `block in tagged'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:25:in `tagged'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:67:in `tagged'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.3/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.3/lib/action_dispatch/middleware/static.rb:64:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/engine.rb:511:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.3/lib/rails/application.rb:97:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-test-0.6.2/lib/rack/mock_session.rb:30:in `request'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-test-0.6.2/lib/rack/test.rb:230:in `process_request'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/rack-test-0.6.2/lib/rack/test.rb:66:in `post'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/rack_test/browser.rb:60:in `process'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/rack_test/browser.rb:35:in `process_and_follow_redirects'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/rack_test/browser.rb:26:in `submit'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/rack_test/form.rb:74:in `submit'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/rack_test/node.rb:56:in `click'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-rails-1.4.0/lib/cucumber/rails/capybara/javascript_emulation.rb:16:in `click_with_javascript_emulation'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/node/element.rb:118:in `block in click'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/node/base.rb:81:in `synchronize'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/node/element.rb:118:in `click'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/node/actions.rb:13:in `click_link_or_button'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/session.rb:396:in `block (2 levels) in <class:Session>'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.2.1/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
./features/step_definitions/creating_a_discussion_steps.rb:35:in `/^the discussion is submitted$/'
features/creating_a_discussion.feature:27:in `When the discussion is submitted'

Vell

unread,
Mar 28, 2014, 8:49:41 AM3/28/14
to cu...@googlegroups.com
Has no one has actually run into this problem? or Did I ask the question in a way that is not understandable?

Andrew Premdas

unread,
Mar 28, 2014, 10:02:58 AM3/28/14
to cu...@googlegroups.com
Vell,

To solve this you need to do 2 things

1. Learn to read stack traces
2. Learn to use the debugger

If we look at the first line in your stacktrace

undefined method `empty?' for nil:NilClass (ActionView::Template::Error)

This tells you that the empty? method has been called on a 'nil'. This
means that somewhere we are referring to a nil, when we think we have
an object with an empty? method. You can google nil pointer errors and
find out more about them, they are very common in programming, and
quite hard to debug.

The next four lines of your stacktrace are all in the actionpack gem.
Its much more likely that you've done something wrong rather than
actionpack being broken, so we'll ignore that. The following line is

./app/views/discussions/_form.html.erb:17:in `block in
_app_views_discussions__form_html_erb___3672191014114043450_70171974323000'

This is of great interest as its the first line to talk about some of
your code. This is the place where I would start my investigations.
However we can't do that, as you haven't provided the code.

Before you just reply and include that code, you need to Investigate
things at your end first.

Your investigations should look at how that form is being rendered,
starting from the scenario in your feature, through your step
definitions to the controller method and finally to the view code.
Your investigation tool is the debugger (debugger gem, or pry). When
making this investigation the following rules of thumb should be
applied

RULE 1 - Assume that you are responsible for the error.
RULE 2 - Even when you think the error is not yours, apply rule 1
again, because its probably your error.
RULE 3 - After you've composed your post asking for help, but BEFORE
you press send, read your post think about whether you have given
enough information for people on the list to be able to help. Then
apply rule 1 again. Then consider pressing send. (I often find that
writing the help mail prompts new ideas about that the problem could
be).

In this investigation you should

1. Debug from your step definition through the ruby code until you get the error
2. Expose yourself (at least a little bit) to some of the code that
isn't yours, but mostly skip that as you are assuming the error is
yours
3. Read the stacktrace and try and understand it. Use the trace to
choose points to debug e.g. debug in
./app/views/discussions/_form.html.erb before line 17

Your investigation should have one of two results

1. You find what you did wrong and fixit - YAY

2. You prove beyond reasonable doubt that the error is not yours. This
generally means that

2.1 You have a pretty good idea of how the errror occured
2.2 You know where the error occured, down to the line number in
the code, and you have looked at that code

Side effects of doing this are:

1. You will rapidly become a much better programmer
2. You will get stuck less often
3. You get much better at preventing mistakes
...

So thats about it. I hope this doesn't come across as anything other
than the friendly helpful advice its meant to be.

Good luck

Andrew
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas
blog.andrew.premdas.org

Vell

unread,
Mar 28, 2014, 10:21:29 AM3/28/14
to cu...@googlegroups.com
I will do just as you have suggested. I honestly feel like I did most of what you have stated. I know I have issues with not stating my issue correctly but I certainly will go back and do it step by step as you have suggested and hope that I figure this out.

Thanks for taking the time to write this it is definitely helpful.
 
Reply all
Reply to author
Forward
0 new messages