Running test from RubyMine gives 'cannot load such file'? - ruby-on-rails

I have a test which runs as expected from the command line with:
bundle exec rake test TEST=test/my_test.rb
However, when I run the test from RubyMine I get:
require': cannot load such file -- my_test_helper_gem/test_helper (LoadError)
When I cmd+click on the require statement in my_test, RubyMine opens the expected source code. Any suggestions of how to resolve this? Possibly it works for the command line due to some magic related to rake?

Related

how to fix error while running rake db:create

I was trying to run the following command but the result was not what i expected
rake db:create
the result:
rake aborted!
LoadError: cannot load such file -- /mnt/c/newapp/config/application
/mnt/c/newapp/rakefile:4:in require_relative' /mnt/c/newapp/rakefile:4:in <top (required)>'
(See full trace by running task with --trace)
i tried reinstalling postgres but that did not solve the problem, I also tried to install all ruby's packages but it did not work at all.
The error is telling you that on line 4 of your rakefile the require_relative "config/application" line is failing, "cannot load such file -- /mnt/c/newapp/config/application", do you somehow not have a config/application.rb file in your project?

Can't get past error in Rails Setup- `LoadError: cannot load such file -- active_storage/engine`

I'm trying to setup a new Rails application and having an issue that I can't seem to resolve. When trying to run rake db:drop or rake db:create I keep getting the error:
LoadError: cannot load such file -- active_storage/engine
At first I was getting an error:
LoadError: cannot load such file -- bootsnap/setup but was able to clear that after adding it to my gemfile.
I see some info on Github that suggests uncommenting require "active_storage/engine" but I've already done that. Not sure what to do.
I got this error whilst downgrading my app from rails 6.0 to 5.2
Check in your config/application.rb for the line
require "action_mailbox/engine"
and try commenting it out.

Ruby on rails project deploy to server

I have a ruby on rails project. It runs successfully on my PC with command "rails s". So I decided to deploy it to AWS using Capistrano. Server side, I am using Puma + Nginx + mysql stack. (I am following this guide: https://www.sitepoint.com/deploy-your-rails-app-to-aws/)
I got error when I run "cap production deploy":
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy2#111.21.5.197: rake exit status: 1
rake stdout: rake aborted!
Sass::SyntaxError: Invalid CSS after "...e bootstrap.min": expected "{", was ""
(sass):6648
I found out it was the file app/assets/stylesheets/application.css causes the error. In this file, I have only one line:
*= require bootstrap.min
I think it is correct. Because the app can run on my PC.
If I remove this line, there will be no error when I run "cap production deploy". The app can deploy to the server and run on the server. But no CSS for all the web pages. I am basically new to ruby on rails. So I don't know the details after all these files. Does anyone can suggest what should I do in order to make my app deploy to the server successfully?
Rename your stylesheet to application.scss (note the scss extension) and make sure it contains this line:
//= require bootstrap.min

Cannot access Rails console in Windows - LoadError

I'm using JRuby because it's better for SRS Ruby on Rails, on Windows.
My solution was to use jirb in cmd.exe or Powershell (not gitbash).
I've tried:
$ rails console
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.
require at org/jruby/RubyKernel.java:939
<top> at bin/rails:4
and:
$ bundle exec rails console
uri:classloader:/jruby/kernel/kernel.rb:17: warning: unsupported exec option: close_others
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.
require at org/jruby/RubyKernel.java:939
<top> at bin/rails:4
and:
$ jruby.exe -S bundle exec rails console
uri:classloader:/jruby/kernel/kernel.rb:17: warning: unsupported exec option: close_others
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.
require at org/jruby/RubyKernel.java:939
<top> at bin/rails:4
I tried the solution "Load error when running rails console", but restarting the computer has no effect. bin/spring has no mention of GEM_HOME. I reinstalled Rails and Spring.
Is this because of JRuby?
I'm entertaining the idea that jruby -S rails console requires C extensions. I found another way to access the console using JRuby's own jirc. I started with:
$ jirb
Switch to inspect mode.
then edited ~/.irbrc to include
IRB.conf[:PROMPT_MODE] = :SIMPLE
which produced:
$ jirb
Switch to inspect mode.
>>
which then immediately exits. Doing this:
$ jirb puts 'hello'
Switch to inspect mode.
Errno::ENOENT: No such file or directory - puts
initialize at org/jruby/RubyFile.java:342
open at org/jruby/RubyIO.java:1124
open at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/magic-file.rb:7
initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/input-method.rb:100
initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/context.rb:84
initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb.rb:426
start at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb.rb:381
<top> at G:/jruby-9.0.1.0/bin/jirb:13
Since my console is still not working and nothing about jirc is using C extensions, the question is not a duplicate to that one.
Yes, I would try and install jruby to resolve this
See http://jruby.org/getting-started
Then do bundle from the root of the project
TL;DR use jirb in Command Prompt to execute Ruby code.
I never resolved making rails console work. This may have to do with my ruby installation being a part of jRuby.
However, irb and jirb allow me to execute Ruby snippets on the command line with either Command Prompt or Powershell. GitBash doesn't work, says Switch to inspect mode. followed by >> and then exits.

Rspec command returns '`require': cannot load such file -- spec_helper' when rake spec does not

I am humming along running my unit tests. For each file, I write a test and then run rspec on it to make sure I've written things correctly. I'm using rvm, sourcing ruby v2.1.1. I successfully run the command ruby -S spec/controllers/current_spec.rb
At some point, I run rake spec for all tests
After this, when I run ruby -S spec/controllers/current_spec.rb again I get the following error:
ruby -S spec/controllers/current_spec.rb
/home/eggmatters/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext
/kernel_require.rb:55:in `require': cannot load such file -- spec_helper (LoadError)
from /home/eggmatters/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext
/kernel_require.rb:55:in `require'
from spec/controllers/current_spec.rb:1:in `<main>'
The top of my spec contains:
require 'spec_helper'
Which is throwing the error. spec_helper is where it is supposed to be: spec/spec_helper.rb
Also, when running rake spec, all it does is issue the spec commands for each individual file in the spec directory for example:
$ rake spec:controllers
/home/eggmatters/.rvm/rubies/ruby-2.1.1/bin/ruby -S rspec
./spec/controllers/some_controller_spec.rb
./spec/controllers/another_controller_spec.rb
./spec/controllers/this_controller_spec.rb
./spec/controllers/current_controller_spec.rb
I've verified that ruby -S does indeed point to /home/eggmatters/.rvm/rubies/ruby-2.1.1/bin/ruby -S (which ruby).
The Gemfile looks fine. Running bundle exec ruby -S ./spec/controllers/current_controller_spec.rb throws the same error.
I ran rails generate spec:install already as I started out issuing the command just fine. There were no changes to spec_helper between successful runs.
bundle install doesn't change anything.
What's going on? Why is rspec all of the sudden not finding spec_helper when it is where it needs to be? What did rake do to rspec to all of the sudden break it? Why does rake spec work and this one doesn't?

Resources