After adding the gem "webmock" I have "uninitialized constant Syck (NameError)" - ruby-on-rails

I've added gem "webmock" and started having an error:
$ rspec
/home/me/.gem/ruby/2.3.1/gems/safe_yaml-1.0.1/lib/safe_yaml/syck_node_monkeypatch.rb:42:in `<top (required)>': uninitialized constant Syck (NameError)
I've tried includig this:
module SafeYAML
YAML_ENGINE = defined?(YAML::ENGINE) ? YAML::ENGINE.yamler : (defined?(Psych) && YAML == Psych ? "psych" : "syck")
end
into different initialization files such as application.rb and initializers/my_init.rb, but it didn't help to fix the error. How can I fix it?

Related

How to create a custom formatter for Faraday logging?

In the Gemfile, the gem is listed like this:
gem "faraday"
This leads to the installation of the current version 1.10.0.
Then, following this documentation, I create a custom logger, but I get an error:
NameError: uninitialized constant Faraday::Logging
Did you mean? Logger
If open the Rails console and write the code Faraday::Logging::Formatter there, the error will be exactly the same.
Tell me, please, what is the matter and how to fix it?
UPD.
If I write this in the Rails console:
Faraday::Response::Logger::Formatter
Then I get this error:
NameError: uninitialized constant Faraday::Response::Logger::Formatter
Then I write this:
Faraday::Logging::Formatter
And there are no more errors. What is going on?
bundle exec rails c
Faraday::Logging::Formatter
=> NameError: uninitialized constant Faraday::Logging
Faraday::Logging::Formatter
=> NameError: uninitialized constant Faraday::Logging
Faraday::Response::Logger::Formatter
=> NameError: uninitialized constant Faraday::Response::Logger::Formatter
Faraday::Logging::Formatter
=> Faraday::Logging::Formatter

uninitialized constant ActiveRecord::ConnectionAdapters::ReconnectOnErrorManagement

ruby 2.7.1
rails 6.0.3
config/application.rb
# # for aurora failover bug
config.middleware.insert_before ActionDispatch::Executor,
ActiveRecord::ConnectionAdapters::ReconnectOnErrorManagement
then
rails c
I got
uninitialized constant ActiveRecord::ConnectionAdapters::ReconnectOnErrorManagement (NameError)
I have no idea.

Error initializing ShortCode Gem

I have a problem initializing the Rails Gem shortcode.
I have this code in initializers / shortcode.rb
Shortcode.setup do |config|
config.template_parser = :haml
config.template_path = "support/templates/chart"
config.block_tags = [:chart]
end
When I start the server rails (rails s) gives the following error.
/home/usuario/proyectos/rails/crowdfunding/config/initializers/shortcode.rb:3:in `<top (required)>': uninitialized constant Shortcode (NameError)
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/notifications.rb:166:in `instrument'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/engine.rb:651:in `load_config_initializer'
Note: I already did install bundle and bundle update sass-rails
Shortcode is not a Rails gem but the ruby gem [thus Rails come without this gem as its dependency]. Add gem 'shortcode' in your Gemfile, bundle the project and restart the application.

uninitialized constant Test::Unit::UI::XML (NameError) in Rails (or Ruby)

I'm trying to create an xml runner to make a result report of Rails unit testing. Here is a code I have:
require 'test/unit'
require 'test/unit/ui/console/testrunner'
class FastFailRunner < Test::Unit::UI::Console::TestRunner
def add_fault(fault)
#faults << fault
nl
output("%3d) %s" % [#faults.length, fault.long_display])
output("--")
#already_outputted = true
end
def finished(elapsed_time)
nl
output("Finished in #{elapsed_time} seconds.")
nl
output(#result)
end
end
Test::Unit::AutoRunner::RUNNERS[:fastfail] = proc do |r|
FastFailRunner
end
When I run it as TESTOPTS="/home/alex/RubymineProjects/app2/test/unit/runner.rb --runner=xml" rake test
... I get an error (pretty weird error)
/home/alex/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing': uninitialized constant Test::Unit::UI::XML (NameError)
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/runner/xml.rb:5:in `block in <module:Unit>'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `[]'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:58:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit.rb:501:in `block in <top (required)>'
gem install minitest
/home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/runner/xml.rb:5:in `block in <module:Unit>': uninitialized constant Test::Unit::UI::XML (NameError)
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `[]'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:58:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit.rb:501:in `block in <top (required)>'
Errors running test:units! #<RuntimeError: Command failed with status (1): [/home/alex/.rvm/rubies/ruby-1.9.3-p194/bin...]>
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [/home/alex/.rvm/rubies/ruby-1.9.3-p194/bin...]>
I tried to require test/unit/ui/xml/testrunner.rb but no luck.
Any thoughts?
If you are in Ruby 1.8.7 you can say:
require 'test/unit/ui/console/testrunner'
p Test::Unit::UI::Console::TestRunner # => no problem
(There is no such file as test/unit/ui/xml/testrunner.rb so I'm not sure what you were up to there.)
Look in the docs in test/unit.rb, there's actually sample code showing you how to do this require: http://www.ruby-doc.org/stdlib-1.8.7/libdoc/test/unit/rdoc/Test/Unit.html.
However, the problem is that you are in Ruby 1.9.3. There is no /test/unit in Ruby 1.9.3! Well, there is, but it's just a compatibility layer for basic tests; there is certainly no test/unit/ui/console/testrunner, and no module/class Test::Unit::UI::Console::TestRunner.
Instead, there's minitest. You can read the docs on minitest to see how to make a test runner. http://docs.seattlerb.org/minitest/
One thing to consider is that Test::Unit was included in the default Ruby 1.8.7 installation. If you want to use it in with a later version of Ruby then go ahead and install it as a gem.
sudo gem install test-unit
http://test-unit.rubyforge.org/

The gem I compiled broke my app, makes it so all the models are uninitialized contants

The deep_cloning gem is causing this error:
NameError: uninitialized constant %{AnyModel}
When I do bundle update, it tells me this:
deep_cloning at /Users/me! =D/.rvm/gems/ruby-1.8.7-p352#secret_gemset/bundler/gems/deep_cloning-423f1e30eeef did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
["deep_cloning-0.2.0.gem"] are not files
What am I doing wrong here?
In my Gemfile I specify the path to the gem like so:
gem "deep_cloning", :git => "git://github.com/DerNalia/deep_cloning.git"
Update: the stacktrace from the unitialized constant error:
> MyModel.find(455)
NameError: uninitialized constant MyModel
from /rvm_gemset_path/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant'
from /rvm_gemset_path/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `rake_original_const_missing'
from /rvm_gemset_path/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
from /rvm_gemset_path/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
from (irb):1
You should remove the line :
s.files = [
...
"deep_cloning-0.2.0.gem"
...
]
from your gemspec.

Resources