Unable to debug in RubyMine 4.5 using Ruby 1.9.3 - ruby-on-rails

My apologies for the length of the question, but I want to make it clear I am not making any stupid mistakes!
So, I am struggling to get debugging working in RubyMine 4.5 using Ruby 1.9.3, my steps are as follows:
Fresh (i.e. having removed all previous ruby and gem directories) install of Ruby 1.9.3, Ruby Gems, DevKit and Rails (following this guide) - that works fine.
I then try to begin working with my team's ruby code. I open up the directory in RubyMine (remembering first to delete the .idea directory) and am prompted to run bundle install which I do (from console) as requested. This completes successfully. Restart RubyMine.
I then ensure Ruby is working: Tools > IRB Console > puts "test" #test => nil - Works
I now try the debugger (SHIFT + F9) and see the message:
The gem ruby-debug-base19x required by the debugger is currently not installed. Would you like to install it?"
I click cancel and check my Gemfile, the only ones related to debugging present are:
# Debugging
gem 'debugger'
#gem 'ruby-debug-base19', :require => false
#gem 'ruby-debug19', :require => false
gem 'ruby-prof', :require => false #, :git => 'git://github.com/wycats/ruby-prof.git'
Looks like we have debugger in favour of ruby-debug. Reading here, however, it seems debugger is not sufficient. I need to install ruby-debug-base19x. So, following SO, I comment out debugger from Gemfile and run
gem install ruby-debug-base19x --pre
gem install ruby-debug-ide --pre
Which run fine, so I add
gem 'ruby-debug-base19x', '0.11.30.pre10'
gem 'ruby-debug-ide', '0.4.17.beta14'
to my Gemfile, and run a bundle install from the console.
Finally, i open the debugger inside RubyMine (SHIFT + F9). And puts "test" #test => nil works again. So i try double clicking in the gutter of my script to create a breakpoint, RubyMine pauses for a second and then i get:
D:\Ruby\Ruby193\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-debug-ide-0.4.17.beta14/bin/rdebug-ide --dispatcher-port 55451 --port 55452 -- S:/code/account_groups/script/rails console
Fast Debugger (ruby-debug-ide 0.4.17.beta14, ruby-debug-base 0.11.30.pre10) listens on 127.0.0.1:55452
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/debugger-1.1.4/lib/ruby_debug.so: warning: already initialized constant VERSION
5992: Exception in DebugThread loop: undefined method `errmsg' for #<Debugger::ControlState:0x2a2f3e8>
Backtrace:
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/debugger-1.1.4/lib/ruby-debug/command.rb:160:in `errmsg'
from: D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/debugger-1.1.4/lib/ruby-debug/commands/breakpoints.rb:81:in `execute'
from: D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide/ide_processor.rb:89:in `block in process_commands'
from: D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide/ide_processor.rb:86:in `catch'
from: D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide/ide_processor.rb:86:in `process_commands'
from: D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:160:in `block in start_control'
Process finished with exit code 0
I have also tried using a backup copy of the code and following the same steps, i also get the following error when trying to load up the debugger:
Uncaught exception: cannot load such file -- ruby-debug
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
S:/code/account_groups_so/lib/systematic-online/r_spec_runner.rb:5:in `<top (required)>'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
S:/code/account_groups_so/config/environment.rb:12:in `block in <top (required)>'
S:/code/account_groups_so/config/environment.rb:12:in `each'
S:/code/account_groups_so/config/environment.rb:12:in `<top (required)>'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:103:in `require_environment!'
D:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:40:in `<top (required)>'
S:/code/account_groups_so/script/rails:6:in `require'
S:/code/account_groups_so/script/rails:6:in `<top (required)>'
There is nothing wrong with the script (i have used it fine before) and the trace seems related to ruby-debug-ide - what's going on?
Thanks for any help - this is driving me mad!

UPDATE: RubyMine 6+ supports debugger gem.
Make sure to remove gem 'debugger' from your Gemfile, it's a known conflict that will break debugging from RubyMine. You need only 2 gems related to debugger, exactly as stated in my another answer linked in your question.
After removing the gem you need to ensure it's not referenced anywhere in the project. In this particular case r_spec_runner.rb had require 'ruby-debug' statement causing cannot load such file -- ruby-debug error when trying to run rails console.

To escape this problem I have this line in my Gemfile:
gem 'debugger' unless ENV["RM_INFO"]

Just to document the solution from jetbrains:
Use either:
gem 'debugger', {group: [:test, :development]}.merge(ENV['RM_INFO'] ? {require: false} : {})
Or:
gem 'pry-debug', {group: [:test, :development]}.merge(ENV['RM_INFO'] ? {require: false} : {})
This makes sure that the Gemfile.lock remains unchanged, so a group with mixed RubyMine and vi/sublime/whatever can work happily, by do not requiring the gem in a RubyMine environment.

I had the same issue, and it cost me hours to get it working. Here is what finally got the debugger going (this is using RVM):
Quit RubyMine
If Ruby 1.9.3 is installed, uninstall it: rvm remove 1.9.3
Install Ruby 1.9.3 under RVM: rvm install 1.9.3 --with-gcc=clang - this produces the error "unsupported option '--with-libyaml'", but I haven't seen any ill effects from this yet
Switch to the new ruby: rvm use 1.9.3
List and remove all ruby-debug* gems: gem list | grep debug - gem uninstall <found gems>
Download linecache19 from http://rubyforge.org/frs/?group_id=8883 and install the gem, i.e.: gem install linecache19-0.5.13.gem
Lauch RubyMine, and run the debugger; it will inform about missing debug gems (i.e. ruby-debug-ide); let RubyMine install those.
That's when the debugger started working. See also this RubyMine support discussion: http://devnet.jetbrains.com/message/5443846#5443846

Finally got this working today with a huge kludge hack. I think the step that did it was
sudo chmod -R 777 ~/.rvm
Let RubyMine do its thing
I also made sure to uninstall every gem I had besides rake. I think reby-debug-ide, ruby-debug-base19x, linecache19, ruby_core_source, archive-tar-minitar, and columnize are the important ones. I also uninstalled rvm and reinstalled with clang. But I'd try just doing the chmod thing first. I tried changing to 766, but RubyMine didn't like it. So huge kludge hack it is. I now get lots of warnings about Insecure world but at least the debugger is working. Pretty sure the next version of RubyMine will not use the old ruby-debug-base19x, but instead the more recently edited gems at https://github.com/ruby-debug. So hopefully someone at the awesome JetBrains will fix it. Btw also tried running RubyMine with sudo mine but that didn't do the trick either.

I had some problems with the debugger.
I installed Rails and set the path in configuration options to the ruby.exe in the rails installation and everything is working perfect.

Related

Rails 4.2.9 "cannot load such file" (multiple files)

So it's been a while since I fired up the old Rails server. It took a lot of tricks to even get the bundle to install... but eventually I upgraded from Rails 4.2.6 to 4.2.9. The bundle installs just fine. I'm on Ruby 2.3.0. But now the problem is... whenever I try to run:
rails s
I get the following error:
rails-html-sanitizer.rb:2:in `require': cannot load such file -- loofah (LoadError)
from /home/rainless/.rvm/gems/ruby-2.3.0#rails3.2.16/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `require'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:72:in `each'
Or some variation of that.
At first I was getting around this by uninstalling whatever the Gem that was said to be unable to load (in this case "loofah" but I've done it with many more), and then adding it to the Gemfile and installing it using Bundler. I now realize that the list is never-ending:
gem 'rails-html-sanitizer'
gem 'chronic'
gem 'multipart-post'
gem 'oauth-active-resource'
gem 'rack-test'
gem 'multi_json'
gem 'addressable'
gem 'orm_adapter'
All the above couldn't load. I ran Rails for years before this... and I know this isn't the way it's supposed to work. Any help/advice on what could be going wrong?
If you see carefully in the error message, it says ruby-2.3.0#rails3.2.16 but you mentioned "upgraded from Rails 4.2.6 to 4.2.9." . For some reason, it's still referring to rails3.2.16. Therefore it could be you need to install the rails-html-sanitizer globally. By the way, Loofah is only needed if you wanted to use it in a non-rails app. Refer to the docs here.
Rails Html Sanitizer is only intended to be used with Rails
applications. If you need similar functionality in non Rails apps
consider using Loofah directly (that's what handles sanitization under
the hood).
from /home/rainless/.rvm/gems/ruby-2.3.0#rails3.2.16/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'

When trying to use watir's #move_to method, getting "TypeError: expected Selenium::WebDriver::Element, got #<Watir::Button ...>"

After finding this stackoverflow q/a about how to click on an element based on its coordinates, I'm trying to do so to click on a button I've discussed in this question. Currently having to use the cliclick shell command for mac osx which is clunky. Anyway, here is the section of my Gemfile showing the watir related gems in order -- perhaps I've required more gems than is necessary?
gem 'selenium-webdriver'#, '2.45.0'
gem 'selenium'#, '0.2.11'
gem 'watir', '5.0.0'
Here's the full command I've run to get the error:
b = Watir::Browser.new #defaults to firefox
#...
element = b.span(:text => "Confirm Selection")
b.driver.action.move_to(element, 15, 15).click.perform
#=>
TypeError: expected Selenium::WebDriver::Element, got #<Watir::Button:0x39fe077c86d90f06 located=false selector={:id=>"id_280", :tag_name=>"button"}>:Watir::Button
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/mouse.rb:86:in `assert_element'
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/mouse.rb:69:in `move_to'
from (irb):79
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Let me know if any more details would help.
System details:
rails 4.0.0
mac osx el capitan 10.11.1
firefox 46.0.1
selenium gem 0.2.11
selenium-webdriver gem 2.53.0
watir gem 5.0.0
watir-webdriver gem 0.9.1
The problem is that a Watir::Element is being passed to Selenium's action builder. The action builder only knows about Selenium::WebDriver::Element.
To convert a Watir::Element to a Selenium::WebDriver::Element, use the wd method:
element.wd
The move_to call should be:
b.driver.action.move_to(element.wd, 15, 15).click.perform

Ruby Script API That Requires a gem

I have spent almost 8 hours on this and I know it's an easy fix.
I want to use this repository of the basecrm gem.
The problem: I don't know how to require/include the gem, neither locally as a cloned copy or as a regular "require gem_name" to find Leads
Ive download and put the gem files in /Users/username/Sites/basecrm/
and added the line below to my gem file.
gem 'basecrm', :git => 'git://github.com/basecrm/basecrm.git'
I ran "Bundle Install"
According to the Readme.md it says to call
require 'basecrm'
⌘ ~/Sites/basecrm/ irb
irb(main):001:0 require 'basecrm'
LoadError: cannot load such file -- basecrm
from /Users/username/.rbenv/versions/2.1.3/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/username/.rbenv/versions/2.1.3/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
from /Users/username/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'
irb(main):002:0session = BaseCrm::Session.new
NameError: uninitialized constant BaseCrm
from (irb):2
from /Users/username/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'
Any help is really appreciated. I am ready to tear my hair out on this.
If you use Gemfile you should run irb with bundler e.g. bundle exec irb and then require your gem require "basecrm"

error while running rake about command

I installed everything of ruby on rails on my linux system..and then when I type the command 'rake about' the following is the error..plz help
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/imobigeeks1/work/demo/jbuilder/ruby/1.8/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect'
/home/imobigeeks1/work/demo/jbuilder/ruby/1.8/gems/execjs-1.4.0/lib/execjs.rb:5
/home/imobigeeks1/work/demo/jbuilder/ruby/1.8/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
/home/imobigeeks1/work/demo/jbuilder/ruby/1.8/gems/coffee-script-2.2.0/lib/coffee_script.rb:1
/home/imobigeeks1/work/demo/jbuilder/ruby/1.8/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
/home/imobigeeks1/work/demo/jbuilder/ruby/1.8/gems/coffee-script-2.2.0/lib/coffee- script.rb:1
/home/imobigeeks1/work/demo/jbuilder/ruby/1.8/gems/coffee-rails-3.2.2/lib/coffee- rails.rb:1:in `require'
/home/imobigeeks1/work/demo/jbuilder/ruby/1.8/gems/coffee-rails-3.2.2/lib/coffee- rails.rb:1
/home/imobigeeks1/work/demo/config/application.rb:7
/home/imobigeeks1/work/demo/Rakefile:5
(See full trace by running task with --trace)
And I also installed javascript using gem install execjs command still its showing the same problem
put gem 'therubyracer' in your gemfile and then do bundle install from command line.
This gem is for-
Call JavaScript code and manipulate JavaScript objects from Ruby. Call
Ruby code and manipulate Ruby objects from JavaScript.
Source - http://rubydoc.info/gems/therubyracer/0.11.4/frames

"uninitialized constant" when running RSpec tests with Rails 2.3.8 and Bundler

I just changed my Rails 2.3.8 project to load gems using Bundler, rather than the default Rails 2.3 loading mechanism. I followed the official instructions and the site runs fine in development. I use RVM for gem management, and have a specific gemset loaded for the application.
My RSpec test suite is unable to run, however. I have tried running both the entire suite and single tests using a variety of commands:
autospec # My usual way of running tests
rake spec
spec .
spec spec/models/comment_spec.rb # Trying a single spec file in isolation
ruby spec/models/comment_spec.rb
I have also tried running them all prefixed with bundle exec. Everything returns the same error:
/Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant InheritedResources::Base (NameError)
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing_not_from_s3_library'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from /Users/casper/Projects/cf/darebusters/app/controllers/admin/base_controller.rb:1
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in `require_or_load'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in `depend_on'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:in `require_dependency'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:414:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:413:in `each'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:413:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:411:in `each'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:411:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:197:in `process'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:113:in `run'
from /Users/casper/Projects/cf/darebusters/config/environment.rb:9
from /Users/casper/Projects/cf/darebusters/spec/spec_helper.rb:5:in `require'
from /Users/casper/Projects/cf/darebusters/spec/spec_helper.rb:5
from spec/models/comment_spec.rb:1:in `require'
from spec/models/comment_spec.rb:1
I'm pretty sure the problem is not related to the Inherited Resources gem - I think gems are not loaded at all at this point, and Inherited Resources just happens to be the first one needed.
The thing that's baffling me is that /activesupport-2.3.8/lib/active_support/dependencies.rb:158 requires /app/controllers/admin/base_controller during the initialization phase. It shouldn't do that, and it certaintly doesn't do it in development mode. I can comment out gem 'inherited_resources' in my Gemfile, and site still runs. It's not until I hit an action that loads a controller that use Inherited Resources I get the "uninitialized constant" error.
For clarity, here's my Gemfile and spec_helper.rb.
Even older question, but I had the same issue with Bundler 1.0.3, Rspec-Rails 1.3.3 & Rails 2.3.8 and was able to boil it down to remarkable_rails. Remarkable-Rails seems to load rspec/rails before the initializers are run by the environment.
After adding :require => nil to it in the Gemfile and requiring it by hand in spec_helper AFTER requiring the rails-environment the issue disappeared.
I realize this is an old question, but I just came across the same problem.
I had the 1.3.0 version of rspec and rspec-rails required by my application. Looking at the rspec-rails changelog, I noticed there were a few bug fixes after 1.3.0. Upgrading rspec-rails to 1.3.2 fixed everything for me.
To fix this problem I changed by Gemfile from:
gem 'rspec-rails', '~> 1.3.2', :require => 'spec/rails'
to
gem 'rspec-rails', '~> 1.3.2'
and added the following to my spec helper
require 'spec/rails'

Resources