0

After some fight, I was able to get some code completion and navigation from robe. Specifically, in the *pry* buffer I modified $LOAD_PATH to point at my project's source directories. However, now in order to get code navigation and completion for submodules I need to require all of them one by one... this seems very strange and, I hope, shouldn't be necessary...

So, what is the right way to make robe automatically discover all the submodules of my project?

1

That depends on what kind of project you're working on.

If it's a gem, it most likely require-s all modules in the top-level file (the one under lib). M-x inf-ruby-console-gem will load it and in turn, all modules.

If it's a Rails project, M-x inf-ruby-console-rails will load Rails console. Most modules use autoloads, but C-x C-k should load them all using ActionDispatch::Reloader. That's not a sure thing, though, if you have code outside of autoload_paths.

If it's some other kind of project, it should have a script that launches a console with all dependencies loaded (like bin/console). If it doesn't you should create one. M-x inf-ruby-console-script will launch it.

And, to be clear, M-x inf-ruby-console-auto should dispatch to the most appropriate of these commands.

  • OK, then I'm guessing it's up to me to write the script that loads Ruby code... it's a project which is, basically, built around Cucumber tests (a testing / automation suite for another project). I'm very new to Ruby, and this question my sound very naive: the project has env.rb file, which seems to have infrastructural significance - is it possible that that's somehow related to bin/console or the likes of it? – wvxvw Sep 25 '17 at 5:48
  • env.rb is used by Cucumber IIRC, but that's it. – Dmitry Sep 25 '17 at 10:33
0

Following Dmitry's answer, here's the bin/console file I ended up with:

#!/usr/bin/env ruby
# -*- mode: ruby -*-

$:.unshift *Dir.glob('../features/support/**/').map do |folder|
 File.absolute_path(folder)
end

require 'capybara'
require 'minitest/spec'
require 'capybara-webkit' unless Gem.win_platform?
require "bundler/setup"
Bundler.require

OPTIONS = {
  :autoload_code_paths => ["features/support", "features/step_definitions"],
  :filters             => [],
  :strict              => false,
  :require             => ['../features'],
  :dry_run             => false,
  :fail_fast           => false,
  :formats             => [],
  :excludes            => [],
  :tag_expressions     => [],
  :name_regexps        => [],
  :env_vars            => {},
  :diff_enabled        => true,
  :snippets            => true,
  :source              => true,
  :duration            => true,
}

RUNTIME = Cucumber::Runtime.new(OPTIONS)
RUNTIME.send(:load_step_definitions)
RUNTIME.send(:install_wire_plugin)

require "pry"
Pry.start

Obviously, some sections of this file will be different for you, but they should give you a general idea of what may be in this file. There's also the part where I tried to work around loading Cucumber's tests, but not executing them (the `RUNTIME.send() stuff). Unfortunately, I couldn't find a better way of just loading the tests.

  • Why load the tests, though? It's not like they contain Ruby methods that you want to use for navigation or completion. Right? – Dmitry Sep 25 '17 at 10:38
  • @Dmitry of course they do, this is the only code that exists in this project. Unfortunately, the code I posted above doesn't really work. It gets me half-way though because for some reason bundle exec does something different from just calling ruby... – wvxvw Sep 25 '17 at 11:21
  • You probably just need to add something to Gemfile. – Dmitry Sep 25 '17 at 17:22
  • @Dmitry actually, what I ended up doing was to recursively require all Ruby files in the project's directory. There might have been a better way of doing that, but given the insane amount of indirection in all the bundle-bundler-rbenv-shim-whatever scripts, at gave up at some point. – wvxvw Sep 26 '17 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.