When I test my rails app using rspec, a bunch of long comments appear.
How can I remove them ?
ActionController::RoutingError:
No route matches [GET] "/events"
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/rack/logger.rb:36:in `call_app'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/rack/logger.rb:24:in `block in call'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/rack/logger.rb:24:in `call'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-2.0.1/lib/rack/method_override.rb:22:in `call'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-2.0.1/lib/rack/runtime.rb:22:in `call'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:522:in `call'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-2.0.1/lib/rack/urlmap.rb:68:in `block in call'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-2.0.1/lib/rack/urlmap.rb:53:in `each'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-2.0.1/lib/rack/urlmap.rb:53:in `call'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/rack-test-0.6.3/lib/rack/test.rb:58:in `get'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/rack_test/browser.rb:61:in `process'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/rack_test/browser.rb:36:in `process_and_follow_redirects'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/rack_test/browser.rb:22:in `visit'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/rack_test/driver.rb:43:in `visit'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/session.rb:233:in `visit'
# /Users/hadi/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'
# ./spec/features/list_movies_spec.rb:5:in `block (2 levels) in <top (required)>'
That's not comments that's a stack trace, to help you resolve the problem that rspec encountered.
A stack trace shows you each nested call that was made up to the point that the error was encountered, so that you can trace back to which line in your code a command was run that led to the error.
your spec/features/list_movies_spec.rb on line 5 it's performed a method that at some point is tryng to do `GET /events' but you don't have such a route in your route.rb
Fix the problem, and the "comments" will disappear.
Related
In my Ruby on Rails application I have model that looks like this:
class Schema < ActiveRecord::Base
has_many :schema_items
def self.from_cache(schema_id)
schema = Rails.cache.read("schema_#{schema_id}")
unless schema
schema = Schema.where(id: schema_id).includes(:schema_items).first
Rails.cache.write("schema_#{schema_id}", schema) if schema
end
schema
end
end
I'm using this class method in other class which is called by Sidekiq worker. From time to time it returns the following error:
NotImplementedError
Using google I found this issue in redis_store gem: https://github.com/redis-store/redis-store/issues/74
But they fix this bug. My app is hosted on Heroku and I'm using the RedisCloud. Any ideas how can I solve this?
EDIT:
Here is the full backtrace:
NotImplementedError: NotImplementedError
from celluloid/tasks/task_fiber.rb:15:in `block in create'
from celluloid/tasks.rb:57:in `block in initialize'
from celluloid/actor.rb:357:in `block in task'
from celluloid/cell.rb:71:in `block in task'
from celluloid/cell.rb:60:in `block in invoke'
from celluloid/calls.rb:122:in `dispatch'
from celluloid/calls.rb:26:in `dispatch'
from celluloid/calls.rb:26:in `public_send'
from sidekiq/processor.rb:50:in `process'
from sidekiq/processor.rb:98:in `stats'
from sidekiq/processor.rb:51:in `block in process'
from sidekiq/middleware/chain.rb:132:in `invoke'
from sidekiq/middleware/chain.rb:132:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/middleware/server/logging.rb:11:in `call'
from sidekiq/logging.rb:30:in `with_context'
from sidekiq/middleware/server/logging.rb:15:in `block in call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/failures/middleware.rb:9:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/middleware/server/retry_jobs.rb:74:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/middleware/server/active_record.rb:6:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/batch/middleware.rb:25:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq_unique_jobs/middleware/server/unique_jobs.rb:16:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidetiq/middleware/history.rb:8:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from new_relic/agent/instrumentation/sidekiq.rb:29:in `call'
from new_relic/agent/instrumentation/controller_instrumentation.rb:352:in `perform_action_with_newrelic_trace'
from new_relic/agent/instrumentation/sidekiq.rb:33:in `block in call'
from sidekiq/middleware/chain.rb:127:in `block in invoke'
from sidekiq/processor.rb:52:in `block (2 levels) in process'
from sidekiq/processor.rb:75:in `execute_job'
from app/workers/response_processor_worker.rb:8:in `perform'
from app/services/import/response_processor.rb:28:in `process'
from app/models/import/importer/raw_response_validator.rb:17:in `validate'
from app/models/survey_schema.rb:51:in `from_cache'
from active_record/relation/finder_methods.rb:127:in `first'
from active_record/relation/finder_methods.rb:484:in `find_nth'
from active_record/relation/finder_methods.rb:500:in `find_nth_with_limit'
from active_record/relation.rb:243:in `to_a'
from active_record/relation.rb:514:in `load'
from active_record/relation.rb:643:in `exec_queries'
from active_record/relation.rb:643:in `each'
from active_record/relation.rb:644:in `block in exec_queries'
from active_record/associations/preloader.rb:102:in `preload'
from active_record/associations/preloader.rb:102:in `flat_map'
from active_record/associations/preloader.rb:102:in `each'
from active_record/associations/preloader.rb:103:in `block in preload'
from active_record/associations/preloader.rb:115:in `preloaders_on'
from active_record/associations/preloader.rb:143:in `preloaders_for_one'
from active_record/associations/preloader.rb:143:in `flat_map'
from active_record/associations/preloader.rb:143:in `each'
from active_record/associations/preloader.rb:144:in `block in preloaders_for_one'
from active_record/associations/preloader.rb:144:in `map'
from active_record/associations/preloader.rb:144:in `each'
from active_record/associations/preloader.rb:146:in `block (2 levels) in preloaders_for_one'
from active_record/associations/preloader/association.rb:20:in `run'
from active_record/associations/preloader/collection_association.rb:13:in `preload'
from active_record/associations/preloader/association.rb:78:in `associated_records_by_owner'
from active_record/associations/preloader/association.rb:60:in `owners_by_key'
from active_record/associations/preloader/association.rb:103:in `key_conversion_required?'
from active_record/associations/preloader/association.rb:107:in `association_key_type'
from active_record/associations/preloader/association.rb:45:in `association_key_name'
and my worker looks like this:
class ResponseCreatorWorker
include Sidekiq::Worker
sidekiq_options queue: :response_processing
def perform(schema_id)
# some not important code
schema = Schema.from_cache(schema_id) # this line throws the error
Response.create(schema: schema)
end
end
A couple options without being able to go into the Pro code:
Error you found is redis-store related, try memcached
Try moving the cache to memcached, it should be a simple and non-disruptive action, cost-free on simple plans, and see if the problem goes away, or changes, could be useful for hunting the core bug down
memcache is a better caching service anyway for simple key-value stuff,
The worker you linked is not a part of the stack trace
You showed the ResponseCreatorWorker, but that does not appear in the stack trace. What appears is ResponseProcessorWorker, maybe link that worker instead?
Are you sure you are running the code you are running?
Mike Perham says that the Sidekiq backtrace doesn't match the version you have given him, and the wrong worker is in the stack trace? Are you really sure the server is updating? Review the deployment log and log in to the worker with heroku run bash and inspect a couple of key files, make sure nothing is off with the platform.
Can you rescue it? :D
It should be pretty safe to put in a rescue that catches NotImplementedError, tries once again, and logs a record of it into the logs. Update gems when appropriate and when warnings disappear open a whiskey and celebrate.
Put something like this in your model:
def wrap_me_scotty
yield
rescue NotImplementedError => e
warn "#{e} :-("
yield # try once more, let it explode if no joy
end
and then wrap Rails.cache calls
def self.from_cache(schema_id)
schema = wrap_me_scotty{ Rails.cache.read("schema_#{schema_id}") }
unless schema
schema = Schema.where(id: schema_id).includes(:schema_items).first
wrap_me_scotty{ Rails.cache.write("schema_#{schema_id}", schema) } if schema
end
schema
end
I'm trying to write a test that creates and object and then saves it. I want to make sure that the object is created and present on the redirected page after submission. But, I can't seem to click on the "Save" button.
relevant test:
describe 'Create a new contact list', :type => :feature do
it 'Creates a contact list with a name' do
visit new_contact_list_url
expect(page).to have_content("New Contact List")
fill_in "contact_list_name", with: "Group 1"
find('#save').click
expect(page).to have_content("Group 1")
end
end
Error I'm getting:
1) Create a new contact list Creates a contact list with a name
Failure/Error: find('#save').click
NoMethodError:
undefined method `id' for nil:NilClass
relevant HAML
=form_for(#contact_list, html: {multipart: true}) do |f|
.form-group
.field
=f.label "Contact List Name"
=f.text_field :contact_list_name, :class => 'form-contorl', :id => 'contact_list_name'
%h3 Contacts
=f.fields_for :contacts do |contact|
=render 'contact_fields', f: contact
.links
=link_to_add_association 'Add Contact', f, :contacts, :class => 'btn btn-primary', :id => 'add_contact'
=f.submit :class => 'btn btn-warning', :value => 'Save', :id => 'save'
rspec with --backtrace enabled
Failures:
1) Create a new contact list Creates a contact list with a name
Failure/Error: find("#new_contact_list").find("#save").click
NoMethodError:
undefined method `id' for nil:NilClass
# ./app/controllers/contact_lists_controller.rb:17:in `create'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller /metal/implicit_render.rb:4:in `send_action'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/abstract_controller/base.rb:198:in `process_action'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal/rendering.rb:10:in `process_action'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:117:in `call'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:117:in `call'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:505:in `call'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:505:in `call'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:92:in `_run_callbacks'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/abstract_controller/callbacks.rb:19:in `process_action'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal/rescue.rb:29:in `process_action'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/notifications.rb:164:in `block in instrument'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/notifications.rb:164:in `instrument'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# ./.bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/abstract_controller/base.rb:137:in `process'
# ./.bundle/ruby/2.2.0/gems/actionview-4.2.1/lib/action_view/rendering.rb:30:in `process'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal.rb:196:in `dispatch'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal.rb:237:in `block in action'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:74:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:43:in `serve'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/journey/router.rb:43:in `block in serve'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/journey/router.rb:30:in `each'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/journey/router.rb:30:in `serve'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:819:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/conditionalget.rb:38:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/flash.rb:260:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/cookies.rb:560:in `call'
# ./.bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/query_cache.rb:36:in `call'
# ./.bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:88:in `call'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:88:in `_run_callbacks'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
# ./.bundle/ruby/2.2.0/gems/web-console-2.2.1/lib/web_console/middleware.rb:39:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
# ./.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:38:in `call_app'
# ./.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:20:in `block in call'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:68:in `block in tagged'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:26:in `tagged'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:68:in `tagged'
# ./.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:20:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
# ./.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
# ./.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/static.rb:113:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
# ./.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:518:in `call'
# ./.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:164:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/urlmap.rb:66:in `block in call'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `each'
# ./.bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `call'
# ./.bundle/ruby/2.2.0/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# ./.bundle/ruby/2.2.0/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# ./.bundle/ruby/2.2.0/gems/rack-test-0.6.3/lib/rack/test.rb:67:in `post'
# ./.bundle/ruby/2.2.0/gems/capybara-2.5.0/lib/capybara/rack_test/browser.rb:60:in `process'
# ./.bundle/ruby/2.2.0/gems/capybara-2.5.0/lib/capybara/rack_test/browser.rb:35:in `process_and_follow_redirects'
# ./.bundle/ruby/2.2.0/gems/capybara-2.5.0/lib/capybara/rack_test/browser.rb:26:in `submit'
# ./.bundle/ruby/2.2.0/gems/capybara-2.5.0/lib/capybara/rack_test/form.rb:76:in `submit'
# ./.bundle/ruby/2.2.0/gems/capybara-2.5.0/lib/capybara/rack_test/node.rb:61:in `click'
# ./.bundle/ruby/2.2.0/gems/capybara-2.5.0/lib/capybara/node/element.rb:134:in `block in click'
# ./.bundle/ruby/2.2.0/gems/capybara-2.5.0/lib/capybara/node/base.rb:84:in `synchronize'
# ./.bundle/ruby/2.2.0/gems/capybara-2.5.0/lib/capybara/node/element.rb:134:in `click'
# ./spec/features/create_contact_list_spec.rb:10:in `block (2 levels) in <top (required)>'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:148:in `instance_exec'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:148:in `block in run'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `call'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# ./.bundle/ruby/2.2.0/gems/rspec-rails-3.0.2/lib/rspec/rails/adapters.rb:72:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `call'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:432:in `run'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:485:in `run'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:303:in `with_around_example_hooks'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:145:in `run'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:494:in `block in run_examples'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:490:in `map'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:490:in `run_examples'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:457:in `run'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `map'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/reporter.rb:54:in `report'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:108:in `run_specs'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:86:in `run'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
# ./.bundle/ruby/2.2.0/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
# /Users/cowan/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `load'
# /Users/cowan/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `<main>'
# /Users/cowan/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
# /Users/cowan/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
edit for relevant controller action (create)
def create
#contact_list = ContactList.new(contact_list_params)
#contact_list.user_id = current_user.id
if #contact_list.save
flash[:success] = "Contact List Created"
redirect_to contact_lists_url
else
render 'contact_lists/new'
end
end
How would I log in a user using rspec? Since my login helper methods
are in app/helpers/sessions_helper.rb
Just write some function where you're signing in via Capybara, i.e.
visit '/auth'
fill_in :login, with: 'John'
fill_in :password, with: '123'
click 'Login'
and then use it in your tests, for example, in before { } block.
If you have a lot of tests and this approach is too slow, take a look at Warden::Test::Helpers.
Also, take a look at this answer: Using Devise in rspec feature tests.
Instead of find("#save").click, have you tried using click('Save')?
If you have, were you unsuccessful? Answering why that is might help you here.
Preemptive apologies for the code dump. I've been banging my head against this one for a while (and doing a ton of Googling) and just have a pretty fuzzy idea what is and isn't relevant, and how to fix things. So I figured I'd get as much info as possible out there. Please let me know if there's anything else I should add that might be helpful. Thanks!
I'm starting up a Rails and Angular app and mostly still in development mode. I'm using Heroku, but I don't know if these issues are serious there as well, cause I've mostly been coding and bumping into them on local (have barely poked around on production). (Just mentioned, because most similar questions seem to be Heroku-specific).
The error I keep intermittently bumping into is this one:
Rack::Timeout::RequestTimeoutError: Request ran for longer than 5 seconds.
and its doppelganger:
ActionView::Template::Error: Request ran for longer than 5 seconds.
When it's raised, it points to different files as the immediate culprit -- but always a Java/CoffeeScript or CSS/SASS file. Occasionally reloading the browser on the local server will pinwheel eternally instead of raising the above error. Often, a refresh will work fine, but occasionally I have to restart the server to "unfreeze" it.
I could try increasing the Rack::Timeout to something larger, but it strikes me that that would be treating one of potentially many symptoms, rather than the underlying problem.
I'm convinced this has something to do with an asset precompilation mistake of some sort -- which I'm new to, as this is my first serious app from scratch, particularly combining Angular and Rails.
I've had a hard time finding really smooth combinations of Rails and Angular -- advice is definitely appreciated.
I've managed to pinpoint the error by running and rerunning some feature specs while messing with my manifest SASS file. Every time I change the application.sass file by commenting some #imports out, (some of) the feature specs fail, but if I re-run them, they pass again and again, until I comment in or out a different line. The specific line(s) don't seem relevant, but, just in case I'm wrong, here's my application.sass file:
#charset "utf-8"
#import "bootstrap-sprockets"
#import "bootstrap"
#import "bourbon"
#import "base/grid-settings"
#import "neat"
#import "base/base"
#import "leaflet"
#import "skeleton/base"
#import "skeleton/layout"
#import "skeleton/skeleton"
#import "sections/header"
#import "sections/footer"
#import "sections/user"
#import "sections/map"
#import "sections/tabs"
#import "sections/baseapp"
#import "markercluster/MarkerCluster"
#import "markercluster/MarkerCluster.Default"
#import "icons"
#import "font-awesome-sprockets"
#import "font-awesome"
Because I think my messy asset solution is possibly to blame, I'll paste most of the relevant code below. Basically, I'm using NPM (package.json) for server-side JS stuff like Jasmine for testing, and Bower for client-side stuff like Angular and Leaflet (for maps). To make the Bower JS available in the Rails app, I'm using Rails Assets in my Gemfile. (Though I don't get why I need the bower.json stuff if I'm doing that). So the relevant parts of those manifest files look like this:
package.json
{
"name": "whatever",
"dependencies": {
"rosie": "0.2.0",
"bower": "1.2.8",
"jasmine": "2.1.1",
"phantomjs": "1.9.13",
"sinon": "1.12.2",
"jasmine-sinon": "0.4.0",
"requirejs": "2.1.15"
},
"devDependencies": {
"grunt": "~0.4.4"
}
}
bower.json
{
"name": "whatever",
"version": "0.1.0",
"authors": [
"Whatever"
],
"ignore": [
"**/.*",
"node_modules",
"bower_compnents",
"test",
"tests"
],
"dependencies": {
"angular": "latest",
"angular-resource": "latest",
"angular-route": "latest",
"angular-mocks": "latest",
"active-support": "latest",
"async": "latest",
"lodash": "latest",
"leaflet": "latest",
"leaflet.markercluster": "latest"
}
}
I mean to tie down the versions before putting this in front of users.
Gemfile
gem 'rails-assets-angular'
gem 'rails-assets-angular-resource'
gem 'rails-assets-angular-route'
gem 'rails-assets-angular-mocks'
gem 'rails-assets-active-support'
gem 'rails-assets-async'
gem 'rails-assets-lodash'
gem 'rails-assets-leaflet'
gem 'rails-assets-requirejs'
gem 'rails-assets-sinon'
# gem 'rails-assets-leaflet.markercluster' -- wasn't working, so I included the relevant scripts in app/assets/javascripts/ -- seems to be working
I've also added these in the test group of my Gemfile. I'm worried about the overlap and sprawl of these JS inclusions, but this was what got the JS tests to work.
gem "jasmine-rails"
gem 'jasmine-headless-webkit'
gem 'guard-jasmine'
gem 'rails-assets-rosie'
gem "sinon-rails"
I have a handful of assets I manually precompile for a variety of reasons:
config/initializers/assets.rb
Rails.application.config.assets.precompile += [
'api/bookmarklets/view.js',
'sections/bookmarklet.css',
'icons.eot',
'icons.svg',
'icons.ttf',
'icons.woff'
]
Locally, (and on production for now), my assets are just hosted on the server (so at localhost:3000). Doubt the DB is related, but its pool is set to 2 and timeout to 5000. Searching for other possibly related code, I found this in config/environments/development.rb -- possible problem?:
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
EDIT -- adding a full stack trace from one of the errors I hit while running the feature specs:
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:125:in `[]'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:125:in `process_comment'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:88:in `s'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:82:in `block in stylesheet'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:545:in `block_contents'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:82:in `stylesheet'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:27:in `parse'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/engine.rb:342:in `_to_tree'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/engine.rb:315:in `_render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/engine.rb:262:in `render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/sass_compressor.rb:24:in `evaluate'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/context.rb:197:in `block in evaluate'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `each'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `evaluate'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/bundled_asset.rb:25:in `initialize'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/base.rb:377:in `new'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/base.rb:377:in `build_asset'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/base.rb:295:in `[]'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/helper.rb:123:in `asset_digest_path'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/helper.rb:76:in `compute_asset_path'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_url_helper.rb:132:in `asset_path'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/helper.rb:91:in `asset_path'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_url_helper.rb:256:in `stylesheet_path'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_tag_helper.rb:100:in `block in stylesheet_link_tag'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_tag_helper.rb:96:in `map'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_tag_helper.rb:96:in `stylesheet_link_tag'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/helper.rb:170:in `stylesheet_link_tag'
# ./app/views/layouts/application.html.haml:9:in `_app_views_layouts_application_html_haml__3935206380113339538_2226830520'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/template.rb:145:in `block in render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications.rb:161:in `instrument'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/template.rb:339:in `instrument'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/template.rb:143:in `render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiling_methods.rb:79:in `block in profile_method'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/template_renderer.rb:67:in `render_with_layout'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/template_renderer.rb:53:in `render_template'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/template_renderer.rb:17:in `render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/renderer.rb:42:in `render_template'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/renderer.rb:23:in `render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/rendering.rb:99:in `_render_template'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/streaming.rb:217:in `_render_template'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/rendering.rb:82:in `render_to_body'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/renderers.rb:32:in `render_to_body'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/rendering.rb:25:in `render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rendering.rb:16:in `render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/core_ext/benchmark.rb:12:in `ms'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:41:in `block in render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:40:in `render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/responder.rb:238:in `default_render'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/responder.rb:165:in `to_html'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/responder.rb:158:in `respond'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/responder.rb:151:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/mime_responds.rb:400:in `respond_with'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/app/controllers/devise/sessions_controller.rb:11:in `new'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/base.rb:189:in `process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:113:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:113:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:229:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:229:in `block in halting'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:86:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:86:in `run_callbacks'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications.rb:159:in `block in instrument'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications.rb:159:in `instrument'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/base.rb:136:in `process'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/rendering.rb:30:in `process'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiling_methods.rb:79:in `block in profile_method'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal.rb:196:in `dispatch'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal.rb:232:in `block in action'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:82:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:50:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:45:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/journey/router.rb:71:in `block in call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/journey/router.rb:59:in `each'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/journey/router.rb:59:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:678:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/flash.rb:254:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/cookies.rb:560:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/query_cache.rb:36:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:82:in `run_callbacks'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/airbrake-4.1.0/lib/airbrake/rails/middleware.rb:13:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/rack/logger.rb:38:in `call_app'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/rack/logger.rb:20:in `block in call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/tagged_logging.rb:68:in `block in tagged'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/tagged_logging.rb:26:in `tagged'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/tagged_logging.rb:68:in `tagged'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/rack/logger.rb:20:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/request_store-1.1.0/lib/request_store/middleware.rb:8:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/request_id.rb:21:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/static.rb:64:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/airbrake-4.1.0/lib/airbrake/user_informer.rb:16:in `_call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/airbrake-4.1.0/lib/airbrake/user_informer.rb:12:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-timeout-0.1.1/lib/rack/timeout.rb:104:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiler.rb:193:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/engine.rb:514:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application.rb:144:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-test-0.6.3/lib/rack/test.rb:58:in `get'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:60:in `process'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:38:in `block in process_and_follow_redirects'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:37:in `times'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:37:in `process_and_follow_redirects'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:21:in `visit'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:42:in `visit'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/session.rb:227:in `visit'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
# ./spec/features/authentication_spec.rb:7:in `block (3 levels) in <top (required)>'
# ./spec/support/background_jobs.rb:14:in `block (3 levels) in <top (required)>'
# ./spec/support/background_jobs.rb:5:in `run_background_jobs_immediately'
# ./spec/support/background_jobs.rb:13:in `block (2 levels) in <top (required)>'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus/rails.rb:208:in `test'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus.rb:148:in `block in command'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus.rb:135:in `fork'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus.rb:135:in `command'
# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus.rb:50:in `go'
Updates
Following coreyward's advice, I set the Rack timeout to 25 seconds and set up some profiling tools. The increase in the timeout (which was dev-environment specific) made the problem go away on localhost. But, perplexingly, I didn't seem to experience any load times of 5+ seconds at all, according to NewRelic and MiniProfiler. I think the longest load time I got was around 3 seconds, and I only got that once. I improved a query, and didn't bump into load times that high again. So it's weird that I bumped into that 5-second limit.
Basically, the load time problem seemed to disappear when I increased the Rack timeout. But I there's still something weird going on, cause the feature tests will still time out in Continuous Integration tests and occasionally on local .
I since cleaned up my asset situation (got rid of Bower and NPM, and did everything through the Gemfile, usually using the Rails-Assets gem). I also upgraded to Rails 4.2 and Ruby 2.2 for performance enhancements. Things generally appear to load a bit faster, according to profiling.
But I'm still getting the same test failures. Interestingly, on my Continuous Integration tool, the tests pretty much always fail, and when they do, they fail with a different error (I captured with a screenshot).
Internal Server Error
could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)
________________________________
WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25) at 127.0.0.1:47539
This suggests it's a DB issue. My DB set up (database.yml) for the Test environment (which my CI uses) is below:
adapter: postgresql
database: planit_development
encoding: utf8
host: localhost
min_messages: warning
pool: 2
timeout: 5000
But, weirdly, my local test suite, which has the same settings, tends to pass (unless I mess with an asset file, in which case there's a chance a feature spec will fail on the first, but not subsequent, run(s)). And the tests that are failing are the least database-intensive tests in the whole suite (just basic auth flow testing).
The profiling definitely helped me fix some mistakes, but I'm still pretty stumped here about what's the root cause of what appears to be a continuing problem. Any ideas based on this new info? Or any sense of what else I should look into?
There are a number of ways to debug this. To start, increase the Rack::Timeout time to 25 seconds — while this might seem like it's going to make matters worse, it will allow you to accurately assess the actual time the request is taking (5.1s is a different story than 25s).
Instrument a monitoring tool like NewRelic or Skylight. The former is more popular and can be easily configured to log traces on all requests over a certain threshold. This will allow you to see (roughly) where the time is being spent, as well as parameters/request information that relates to it.
If you think that the requests that are failing are to assets, I would double check that you have asset compilation turned off in production. You want this in production.rb:
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
This means that you need to make every asset you're serving precompile. You can test that your setup is correct by running rake assets:precompile and verifying that the output in public/assets is what you're anticipating.
Make sure you're also outputting logs somewhere you can access them later — I prefer Papertrail, but there are undoubtedly others. This will allow you to find errors when they occur, especially 404s (which is what you'll see if you have requests for assets that are not precompiled). Once you isolate and resolve the issue you can lower this, but I still wouldn't set it lower than 15s.
Garbage collection is another potential culprit for intermittently long request times, though 5 seconds is probably excessive. Newer versions of Ruby (notably, 2.2) are better about managing this, so if you can bump the version you're using that might improve things.
Good luck!
I'm trying to debug this mailer error in 4.1.1 and can't figure out how to get more information on what to look into:
TypeError (no implicit conversion of nil into String):
app/controllers/api/v1/contact_form_controller.rb:5:in `create'
Here's the controller, line 5 in the error is the second line here:
def create
#mail = ContactFormMailer.contact_email(contact_params).deliver
# ContactFormSender.perform_async(contact_params)
render nothing: true, status: 200
end
My mailer looks like this:
class ContactFormMailer < ActionMailer::Base
default from: ENV["CONTACT_EMAIL"]
def contact_email(args)
#from = args[:from]
#body = args[:body]
#title = args[:title]
mail(to: ENV["CONTACT_EMAIL"], subject: 'Contact form')
end
end
The error only throws when I call deliver, which leads me to believe that it's a mailer.config issue, but everything I've looked into for gmail seems correct:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => ENV["DOMAIN"] }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings =
{
address: ENV["SMTP_SERVER"],
port: 587,
domain: ENV["MAILER_DOMAIN"],
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["SMTP_USER"],
password: ENV["SMTP_PWD"]
}
I doubled checked all of my ENV variables and tried putting begin rescue end around my controller action to get more information on the error, but it just says it's a type error. Is there anyway I can get more information from a logger or something? The error makes me think it's a config setting or something that isn't being passed through, but I have no idea where to keep looking.
Edit: Here's the rest of the error:
Rendered /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.0ms)
Rendered /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.1ms)
Rendered /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.5ms)
Rendered /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (28.8ms)
Edit 2: here's the real backtrace:
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `initialize'
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `open'
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `tcp_socket'
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:551:in `block in do_start'
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `call'
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `timeout'
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:550:in `do_start'
# /Users/evan/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:520:in `start'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/mail-2.5.4/lib/mail/message.rb:248:in `deliver!'
# ./app/controllers/api/v1/contact_form_controller.rb:5:in `create'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/abstract_controller/base.rb:189:in `process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:113:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:113:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:229:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:229:in `block in halting'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:86:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:86:in `run_callbacks'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `block in instrument'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `instrument'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/abstract_controller/base.rb:136:in `process'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.1/lib/action_view/rendering.rb:30:in `process'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/test_case.rb:595:in `process'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/test_case.rb:64:in `process'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_controller/test_case.rb:501:in `post'
# ./spec/controllers/api/v1/contact_form_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:151:in `instance_exec'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:151:in `block in run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:221:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:221:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-rails-3.1.0/lib/rspec/rails/example/controller_example_group.rb:179:in `block (2 levels) in <module:ControllerExampleGroup>'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:321:in `instance_exec'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:321:in `instance_exec'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/hooks.rb:380:in `execute_with'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/hooks.rb:446:in `block (2 levels) in run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:221:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:221:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-rails-3.1.0/lib/rspec/rails/adapters.rb:72:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:321:in `instance_exec'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:321:in `instance_exec'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/hooks.rb:380:in `execute_with'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/hooks.rb:446:in `block (2 levels) in run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:221:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:221:in `call'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/hooks.rb:447:in `run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/hooks.rb:500:in `run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:330:in `with_around_example_hooks'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example.rb:148:in `run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example_group.rb:500:in `block in run_examples'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example_group.rb:496:in `map'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example_group.rb:496:in `run_examples'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example_group.rb:463:in `run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example_group.rb:464:in `block in run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example_group.rb:464:in `map'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/example_group.rb:464:in `run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/runner.rb:111:in `block (2 levels) in run_specs'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/runner.rb:111:in `map'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/runner.rb:111:in `block in run_specs'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/reporter.rb:53:in `report'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/runner.rb:107:in `run_specs'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/runner.rb:85:in `run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/runner.rb:69:in `run'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/lib/rspec/core/runner.rb:37:in `invoke'
# /Users/evan/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.1.1/exe/rspec:4:in `<top (required)>'
# /Users/evan/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load'
# /Users/evan/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>'
# /Users/evan/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
# /Users/evan/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Your SMTP_SERVER env variable is nil.
I can consistently reproduce this error with:
2.1.2 :004 > TCPSocket.open nil, 40
TypeError: no implicit conversion of nil into String
from (irb):4:in `initialize'
from (irb):4:in `open'
from (irb):4
from /Users/mauricio/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'
You can see the actual line where it breaks here.
You should force your code to validate there's a value for all the env variables you need right at the config file instead of assuming there are values for them.
I have set up Pundit together with Devise for authorization on my application. In one of my controllers, I have before_action :authorize.
I then have the following test:
describe SomeController do
before(:each) do
login_user(FactoryGirl.create(:user, :user_type => :admin))
end
describe "GET index" do
it "it retrieves the index" do
something = FactoryGirl.create(:Something)
get :index
assigns(:something).should eq([something])
end
end
end
I receive the error:
wrong number of arguments (0 for 1)
The login helper is fairly straight forward:
module ControllerMacros
def login_user(user)
if user.nil?
user = FactoryGirl.create(:user)
end
#request.env["devise.mapping"] = Devise.mappings[:user]
sign_in user
end
end
Update:
Stacktrace:
Failure/Error: get :index
ArgumentError:
wrong number of arguments (0 for 1..2)
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/pundit-0.2.3/lib/pundit.rb:62:in `authorize'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:424:in `block in make_lambda'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:160:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:160:in `block in halting'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:149:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:229:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:229:in `block in halting'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:149:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:166:in `block in halting'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:86:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:86:in `run_callbacks'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `block in instrument'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `instrument'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.1.1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/abstract_controller/base.rb:136:in `process'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionview-4.1.1/lib/action_view/rendering.rb:30:in `process'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/action_controller/test_case.rb:595:in `process'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/action_controller/test_case.rb:64:in `process'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.4/lib/devise/test_helpers.rb:19:in `block in process'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.4/lib/devise/test_helpers.rb:72:in `catch'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.4/lib/devise/test_helpers.rb:72:in `_catch_warden'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.4/lib/devise/test_helpers.rb:19:in `process'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.1/lib/action_controller/test_case.rb:495:in `get'
# ./spec/controllers/SomeController_spec.rb:31:in `block (4 levels) in <top (required)>'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:114:in `instance_eval'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:114:in `block in run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:179:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:179:in `run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:108:in `call'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:108:in `run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:446:in `run_hook'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:340:in `run_around_each_hooks'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:256:in `with_around_each_hooks'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:111:in `run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `map'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `run_examples'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:371:in `run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `block in run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `map'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `block in run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `map'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `map'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block in run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/reporter.rb:58:in `report'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:25:in `run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
# /Users/Me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
Pundit's authorize method is not intended to be called as a before_action. before_action calls a method with no arguments, and authorize takes a model object and an optional permission name. That's why you're getting the error you are.
You're not showing enough of the relevant code for me to see what you should do next, but I suggest getting Pundit to work in your controller action before pulling it out into a callback.
There is an example of the correct use of authorize here: https://github.com/elabs/pundit
You can define a private helper method in your controller(or in the application_controller if you will use it in all the controllers) which calls authorize current_user, and then call the private method before_action. Like this:
private
def perform_authorization
authorize current_user
end
and then call it as a before_action :
before_action :perform_authorization