Failure using AJAX in Michael Hartl's tutorial at 11.2 - ruby-on-rails

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

Related

WickedPdf and Rails 5.1.4: can't instantiate

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>'

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.

Getting undefined method `to_sym' from FactoryGirl create

I have a simple spec:
describe Setting do
subject { create(:setting) }
it { should be_valid }
end
with the factory:
FactoryGirl.define do
factory :setting do
key "some_key"
value "The appropriate value"
end
end
When I run the spec:
rake spec SPEC=spec/models/setting_spec.rb
I get the following error:
1) Setting should be valid
Failure/Error: it { should be_valid }
NoMethodError:
undefined method `to_sym' for nil:NilClass
# ./spec/models/setting_spec.rb:6:in `block (2 levels) in <top (required)>'
I tried using a let(:setting) in place of the subject line and got the same error.
EDIT Per comments:
The error refers to the line it { should be_valid }
The model is:
class Setting < ActiveRecord::Base
attr_accessor :key, :value
validates_uniqueness_of :key
end
Here's the trace:
# /var/lib/gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/validations/uniqueness.rb:26:in `validate_each'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:153:in `block in validate'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:150:in `each'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:150:in `validate'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:310:in `_callback_before_1986'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:407:in `_run__3464288744618424855__validate__1974049388273351148__callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations.rb:228:in `run_validations!'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:403:in `_run__3464288744618424855__validation__1974049388273351148__callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations.rb:195:in `valid?'
# /var/lib/gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/validations.rb:69:in `valid?'
# /var/lib/gems/1.9.1/gems/rspec-expectations-2.14.5/lib/rspec/expectations/handler.rb:24:in `handle_matcher'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/memoized_helpers.rb:68:in `should'
# ./spec/models/setting_spec.rb:6:in `block (2 levels) in <top (required)>'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `instance_eval'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `block in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:111:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `map'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `run_examples'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:371:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `map'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:58:in `report'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:25:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:77:in `rescue in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:73:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'
spec_helper.rb: http://pastebin.com/6fzDXnux
The direct cause for this error is that the class derives from ActiveRecord::Base, and ActiveRecord can't determine the primary key (required by AR for validating uniqueness). Most likely, this is happening either because you haven't run migrations to create the settings table, or you created the settings table without a primary key.
The offending line (based on the backtrace provided):
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
Note that to_sym is being called on finder_class.primary_key.
you can also solve same by adding below line in your model.
self.primary_key = 'id'
e.g.
Class Person
self.primary_key = 'id'
end

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.

Testing models with RSpec using devise

I am using devise for authentication in my rails app and I'm unable to test any model with RSpec. Controller specs work fine, but I'm unable to make model specs work.
I am getting this error:
Failures:
1) Group should create new group
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `env' for nil:NilClass
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/whiny_nil.rb:48:in `method_missing'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.4.2/lib/devise/test_helpers.rb:25:in `setup_controller_for_warden'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-rails-2.5.0/lib/rspec/rails/adapters.rb:11:in `block (2 levels) in setup'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `instance_eval'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `run_in'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `block in run_all'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `run_all'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:110:in `run_hook'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `block in eval_before_eachs'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:144:in `run_before_each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:48:in `block (2 levels) in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:106:in `with_around_hooks'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:46:in `block in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:99:in `block in with_pending_capture'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `catch'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `with_pending_capture'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:45:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:262:in `block in run_examples'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `map'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `run_examples'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:232:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block (2 levels) in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `map'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/reporter.rb:12:in `report'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:24:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:55:in `run_in_process'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:46:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:10:in `block in autorun'
I have included
config.include Devise::TestHelpers
in my spec_helper.rb.
Here is my model test file
require 'spec_helper'
describe Group do
before :each do
#group = Factory.build(:group)
end
it "should create new group" do
Group.create!(#group)
end
end
This is my factories.rb file
Factory.define :group do |group|
group.name "Example group"
group.description "Example description"
end
How to fix this?
config.include Devise::TestHelpers, :type => :controller

Resources