WickedPdf and Rails 5.1.4: can't instantiate - ruby-on-rails

I want to generate a PDF in a ruby service used by a Rails 5.1.4 app. It fails kind of quickly.
class PdfRenderer
require 'wicked_pdf'
def self.generate
WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
end
end
When I call PdfRenderer.generate in my rspec tests, I get that error:
NoMethodError Exception: undefined method `pdf_from_string' for nil:NilClass
I can't instantiate the WickedPdf class. When I call WickedPdf.new in byebug, I get nil.
The stacktrace:
NoMethodError:
undefined method `pdf_from_string' for nil:NilClass
# ./app/services/pdf_renderer.rb:25:in `generate'
# ./spec/services/pdf_renderer_spec.rb:40:in `block (2 levels) in <top (required)>'
# /usr/local/bundle/gems/spring-commands-rspec-1.0.4/lib/spring/commands/rspec.rb:18:in `call'
# /usr/local/bundle/gems/spring-2.0.2/lib/spring/command_wrapper.rb:38:in `call'
# /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:201:in `block in serve'
# /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
# /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
# /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
# /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
# /usr/local/bundle/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
# /usr/local/bundle/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
# -e:1:in `<main>'

Related

Undefined method `unloadable' when upgrade to rails 7

I have a controller SocketController inherit WebsocketRails::BaseController
class SocketController < WebsocketRails::BaseController
before_action :authenticate_user!
end
After upgrade rails version to 7.0.4
When I run rails s got this error
How to fix it, please!!
Failure/Error:
class SocketController < WebsocketRails::BaseController
before_action :authenticate_user!
NoMethodError:
undefined method `unloadable' for WebsocketRails::BaseController:Class
unloadable controller
^^^^^^^^^^
# ./vendor/bundle/ruby/3.1.0/gems/websocket-rails-0.7.0/lib/websocket_rails/base_controller.rb:45:in `inherited'
# ./app/controllers/socket_controller.rb:1:in `<top (required)>'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:30:in `require'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:30:in `require'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/helpers.rb:135:in `const_get'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/helpers.rb:135:in `cget'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/eager_load.rb:169:in `block in actual_eager_load_dir'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/helpers.rb:40:in `block in ls'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/helpers.rb:25:in `each'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/helpers.rb:25:in `ls'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/eager_load.rb:164:in `actual_eager_load_dir'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/eager_load.rb:17:in `block (2 levels) in eager_load'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/eager_load.rb:16:in `each'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/eager_load.rb:16:in `block in eager_load'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/eager_load.rb:10:in `synchronize'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader/eager_load.rb:10:in `eager_load'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader.rb:296:in `block in eager_load_all'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader.rb:294:in `each'
# ./vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.6/lib/zeitwerk/loader.rb:294:in `eager_load_all'
# ./vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/application/finisher.rb:74:in `block in <module:Finisher>'
# ./vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:32:in `instance_exec'
# ./vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:32:in `run'
# ./vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:61:in `block in run_initializers'
# ./vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/initializable.rb:60:in `run_initializers'
# ./vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:372:in `initialize!'
# ./config/environment.rb:5:in `<top (required)>'
I think:
Could it be that 1 gem version or 1 configuration is not suitable, causing it to fail?
I am not sure what is that for, your controller is reloadable because it is in app/controllers, like any other Ruby file in those directories.
That gem has not had activity for years. I'd suggest that you reopen WebsocketRails::BaseController in an initializer, define a dummy unloadable class method in it that does nothing, and see if your controllers reload as expected.

Factorybot doesn't recognize any attributes—"method missing" errors

I recently upgraded a bunch of gems, and since then I can't run rails server, console, or rspec.
Here's the error log I see:
NoMethodError:
undefined method 'name' in 'book' factory
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/definition_proxy.rb:97:in `method_missing'
# ./spec/factories/books.rb:3:in `block (2 levels) in <top (required)>'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:18:in `instance_eval'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:18:in `factory'
# ./spec/factories/books.rb:2:in `block in <top (required)>'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:49:in `instance_eval'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:49:in `run'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/syntax/default.rb:7:in `define'
# ./spec/factories/books.rb:1:in `<top (required)>'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:20:in `block (2 levels) in find_definitions'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:19:in `each'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:19:in `block in find_definitions'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:15:in `each'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/find_definitions.rb:15:in `find_definitions'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot-5.0.2/lib/factory_bot/reload.rb:6:in `reload'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot_rails-5.0.2/lib/factory_bot_rails/reloader.rb:25:in `block in build_reloader'
# /Users/regan/.rvm/gems/ruby-2.6.3/gems/factory_bot_rails-5.0.2/lib/factory_bot_rails/reloader.rb:35:in `block in register_reloader'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:3:in `require'
# ./spec/rails_helper.rb:3:in `<top (required)>'
# ./spec/controllers/api/v1/songs_controller_spec.rb:1:in `require'
# ./spec/controllers/api/v1/songs_controller_spec.rb:1:in `<top (required)>'
Part of the upgrade included upgrading rails to 5.2.3, which forced me to remove this line from new_framework_defaults.rb file:
# Do not halt callback chains when a callback returns false. Previous versions had true.
ActiveSupport.halt_callback_chains_on_return_false = false
I'm guessing this has something to do with it?
Edit: The factory code is below. This exact code was working 100% before upgrading the gems:
FactoryBot.define do
factory :book do
name "my songbook"
end
end
FactoryBot changed its syntax. It now expects a block when assigning values – even static values – to variables. Change your code to this:
FactoryBot.define do
factory :book do
name { "my songbook" }
end
end
See Defining Factories in their docs.

Why are my view specs behaving inconsistently?

I'm getting some strange results from view specs
Failure/Error: assert_select "div.fileinput-new.thumbnail"
ArgumentError:
wrong number of arguments (3 for 1)
Ok, so this seems self explanatory (though I'm not sure what are the 3 arguments referenced).
However, if I run the suite again, I might get 0 errors. And the next, 5 errors, of the same type as above but referencing different DOM elements.
There is nothing fancy in any of these specs
describe do
build :object / create :object
#object = assign(:object, object )
it 'displays the DOM elements' do
render
asset_select #DOM_elements
end
end
What could cause this kind of inconsistent coverage of view specs?
An example stack trace
Failure/Error: assert_select "div.fileinput-new.thumbnail"
ArgumentError:
wrong number of arguments (3 for 1)
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/actionview-4.2.6/lib/action_view/helpers/text_helper.rb:52:in `concat'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:165:in `evaluate'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:165:in `block in xpath'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:156:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:156:in `xpath'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:193:in `css_internal'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:76:in `block in css'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:187:in `block in each'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `upto'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `each'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:75:in `inject'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:75:in `css'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb:20:in `select'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `assert_select'
# ./spec/views/users/settings/profile.html.erb_spec.rb:24:in `block (4 levels) in <top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:295:in `nest_selection'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:177:in `block in assert_select'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `tap'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `assert_select'
# ./spec/views/users/settings/profile.html.erb_spec.rb:22:in `block (3 levels) in <top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:236:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:236:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:478:in `block in with_around_and_singleton_context_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:435:in `block in with_around_example_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:478:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:618:in `block in run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-rails-3.4.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:425:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:425:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:389:in `execute_with'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:620:in `block (2 levels) in run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:621:in `run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:478:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:435:in `with_around_example_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:478:in `with_around_and_singleton_context_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:233:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:581:in `block in run_examples'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:577:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:577:in `run_examples'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:543:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `block (3 levels) in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `block (2 levels) in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1680:in `with_suite_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:118:in `block in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/reporter.rb:77:in `report'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:117:in `run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:93:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/rspec:23:in `load'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/rspec:23:in `<main>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/ruby_executable_hooks:15:in `eval'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/ruby_executable_hooks:15:in `<main>'
This is not a definitive answer: it appears that, for some weird reason, the evaluate method in the Nokogiri's Searchable module considers the concat() function as a custom XPath function instead of the internal XPath function.
External XPath functions are called as normal ruby methods in the context of the handler attribute of evaluate. Normally the handler is the SubstitutionContext class but in your case it seems that sometimes this gets the context of the TextHelper module where the concat method is defined, accepting just 1 parameter (whereas the XPath's concat() function accepts any number of parameters). I think that this can lead to the errors you observe.
Could you open the searchable.rb file (see the stack trace for its location) on this line and add before it some debug messages to inspect the contents of the following variables?
puts "ctx #{ctx.inspect}"
puts "path #{path.inspect}"
puts "handler #{handler.inspect}"
if handler.respond_to?(:concat)
puts "concat #{handler.method(:concat).inspect}"
else
puts "not responding to :concat"
end
Then, can you provide the output printed for one of the failing tests?
Update: the output showed that indeed the tests context was being polluted by the ActionView::TextHelpers module and in the end it turned out that there was a ActionView::Helpers module included in a model used in the tests.

Failure using AJAX in Michael Hartl's tutorial at 11.2

When I run bundle exec rspec spec I've got 4 failures, and I really don't know what's going wrong. I think it is a problem with AJAX, impossible to solve it.
My errors in console :
An error occurred in an after hook
NoMethodError: undefined method `each' for nil:NilClass
occurred at /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:878:in `teardown_fixtures'
F
An error occurred in an after hook
NoMethodError: undefined method `each' for nil:NilClass
occurred at /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:878:in `teardown_fixtures'
F
An error occurred in an after hook
NoMethodError: undefined method `each' for nil:NilClass
occurred at /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:878:in `teardown_fixtures'
F
An error occurred in an after hook
NoMethodError: undefined method `each' for nil:NilClass
occurred at /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:878:in `teardown_fixtures'
F......[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
..................................................................................................................DEPRECATION: `expect { }.should` is deprecated. Use `expect { }.to` instead. Called from /home/tprails/RubyOnRails/new_app/spec/requests/micropost_pages_spec.rb:41:in `block (4 levels) in <top (required)>'.
.
Failures:
1) RelationshipsController creating a relationship with Ajax should increment the Relationship count
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `load_session' for nil:NilClass
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:151:in `load!'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:147:in `load_for_write!'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:100:in `replace'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:228:in `initialize'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:140:in `new'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:140:in `initialize'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/testing/test_request.rb:11:in `new'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/testing/test_request.rb:11:in `new'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:482:in `setup_controller_request_and_response'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-rails-2.14.1/lib/rspec/rails/adapters.rb:111:in `block (2 levels) in setup'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:237:in `instance_eval'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:237:in `instance_eval'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:21:in `run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:85:in `block in run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:85:in `each'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:85:in `run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:446:in `run_hook'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:345:in `run_before_each_hooks'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:294:in `run_before_each'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:113:in `block in run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-rails-2.14.1/lib/rspec/rails/example/controller_example_group.rb:158:in `call'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-rails-2.14.1/lib/rspec/rails/example/controller_example_group.rb:158:in `block (2 levels) in <module:ControllerExampleGroup>'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:104:in `call'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:104:in `run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:446:in `run_hook'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:340:in `run_around_each_hooks'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:256:in `with_around_each_hooks'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:111:in `run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `map'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `run_examples'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:371:in `run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `block in run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `map'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `map'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block in run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/reporter.rb:58:in `report'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:25:in `run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
# /home/tprails/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
2) RelationshipsController creating a relationship with Ajax should respond with success
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `load_session' for nil:NilClass
[...]
3) RelationshipsController destroying a relationship with Ajax should decrement the Relationship count
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `load_session' for nil:NilClass
[...]
4) RelationshipsController destroying a relationship with Ajax should respond with success
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `load_session' for nil:NilClass
[...]
Finished in 5.91 seconds
125 examples, 4 failures
Failed examples:
rspec ./spec/controllers/relationships_controller_spec.rb:12 # RelationshipsController creating a relationship with Ajax should increment the Relationship count
rspec ./spec/controllers/relationships_controller_spec.rb:18 # RelationshipsController creating a relationship with Ajax should respond with success
rspec ./spec/controllers/relationships_controller_spec.rb:31 # RelationshipsController destroying a relationship with Ajax should decrement the Relationship count
rspec ./spec/controllers/relationships_controller_spec.rb:37 # RelationshipsController destroying a relationship with Ajax should respond with success
Randomized with seed 29007
Do I have to add something to Gemfile ?
I hope you understand my problem, and sorry for my bad english
Thanks
NoMethodError: undefined method `each' for nil:NilClass
this mean you have nil value in your variable
for example:
a = nil
a.each do |i|
puts i
end
will raise the same error
you need check a value of a

ArgumentError (3 for 1) in Rails ActionView::Helpers::TextHelper when running rspec tests

I am in the process of upgrading our test suite to Capybara 2.1, and am running into the strangest issue when running the test suite.
Using:
ruby 1.9.3p392
rails 3.2.12
rspec 2.13.0
capybara 2.1.0
When I run my tests for an entire suite (failing at once with descriptive formatting):
rspec spec/acceptance/non-webdriver-dependent/ --fail-fast -f d
The following error is thrown:
Failure/Error: within(".sidebar") do
ArgumentError:
wrong number of arguments (3 for 1)
When running with the --backtrace option, the following is reported:
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/helpers/text_helper.rb:51:in `concat'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:159:in `evaluate'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:159:in `block in xpath'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/nokogiri-1..9/lib/nokogiri/xml/node.rb:150:in `map'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:150:in `xpath'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:214:in `css'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/rack_test/browser.rb:85:in `find'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/rack_test/driver.rb:70:in `find_css'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/node/finders.rb:152:in `block in resolve_query'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/node/base.rb:77:in `synchronize'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/node/finders.rb:150:in `resolve_query'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/node/finders.rb:35:in `block in find'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/node/base.rb:81:in `synchronize'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/node/finders.rb:30:in `find'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/session.rb:354:in `block (2 levels) in <class:Session>'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/session.rb:221:in `within'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
# ./spec/acceptance/non-webdriver-dependent/bronze/company_job_postings_index_sidebar_spec.rb:15:in `block (3 levels) in <top (required)>'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `instance_eval'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `block in run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:111:in `run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `map'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `run_examples'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:371:in `run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in `block in run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in `map'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in `run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `map'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block in run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in `report'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in `run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
# /Users/steve/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
However, when I run one test at a time, I have no problem whatsover. This is mind-boggling to me, and any insight anyone may have into this would be highly appreciated! It is important to know this only occurs on the acceptance tests using the default driver rather than the selenium tests. Additionally, this error occurred only AFTER upgrading to capybara 2.1.0.
I got the same error. Like some people saying, the problem is include ActionView::Helpers::TextHelper. In my case, I included it in a model. Fortunately I could remove it from the model and this error is cleared.

Resources