NoMethodError in pry-stack_explorer when using rails console - ruby-on-rails

I am using pry for rails console.
Whenever I evaluate some value in console, NoMethodError is raised in bindings_equal?, that is a method of pry-stack_explorer gem. The input and output is as follows.
That is not harmful but a nuisance. I want to remove it.
Can anyone help?
> bundle exec rails console
Loading development environment (Rails 4.1.5)
Frame number: 0/21
[1] pry(main)>
[2] pry(main)>
[3] pry(main)> 1
when_started hook failed: NoMethodError: private method `eval' called for nil:NilClass
{My Bundle Directory}/ruby/2.1.0/gems/pry-stack_explorer-0.4.9.1/lib/pry-stack_explorer.rb:109:in `bindings_equal?'
(see _pry_.hooks.errors to debug)
=> 1
[4] pry(main)>
I use these gems relating to pry:
gem 'pry-rails'
gem 'pry-remote'
gem 'pry-byebug'
Thank you.

I had to add
require 'awesome_print'
AwesomePrint.pry!
to my ~/.pryrc (per the AwesomePrint docs) to fix this error.
Some are mentioning removing Pry.config.print from their ~/.pryrc but I didn't even have a ~/.pryrc, so it appears this can happen by just using awesome_print and pry together.

I'm not running the same gems as you, but have run across the same error.
I started an issue on the github project

Related

How can I use the Values gem with rails?

Gemfile:
gem 'values'
Also tried Gemfile:
gem 'values', require: 'values'
Gemfile.lock
values (1.8.0)
$ bundle install
Using values 1.8.0
But $ rails console
> Value
NameError (uninitialized constant Value)
> require 'values'
LoadError (cannot load such file -- values)
But if I just $ irb
require 'values'
=> true
How can I get to the Value object in rails?
Previously I faced such problem for awesome_print gem, the issue is due to spring preloader.
First, you need to stop spring from a terminal using the following command.
spring stop
Then restart your rails console.
Hope this will help for you.

Pry not loading local app environment in Rails 4.2

I recently installed pry to replace my irb. It was working fine at first, but now every time I run pry it doesn't recognize the local app environment at all. I get something like the following:
[3] pry(main)> show-models
NameError: undefined local variable or method `show' for main:Object
from (pry):2:in `__pry__'
I've tried uninstalling and reinstalling the pry-rails gem and I've added the following code to an initializer file:
Rails.application.configure do
# Use Pry instead of IRB
silence_warnings do
begin
require 'pry'
IRB = Pry
rescue LoadError
end
end
end
Any thoughts on what this could be? I can't seem to find any info on this.
My gem file looks like this:
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'pry-rails'
gem 'pry-byebug'
end
You probably run Pry using pry command, when you should be using rails console command (be sure that you run it from your Rails app directory). If that doesn't work for you, then try bin/rails console and bundle exec rails console commands.
I also Use pry
I'm also using pry and not seen command like show-models yet. It doesn't work for me too. And I never use such command. Using Model.all working fine.I don't if commands you are using is feature of pry. If so visit its documentation. I think its problem due to you gave wrong command.
I had some different problems using pry and byebug together.
i deleted byebug and all is well.
Hope it will also solve ur problem.
I use gem 'pry' in my gemfile instead of gem 'pry-rails' though
Not sure what it was, but a system restart did the trick. Problem solved.

How to I start a rails console with pry turned off?

Sometimes I have reason to want to start the rails console as an irb repl rather than pry (as awesome as pry is). It will default to pry because pry has in the Gemfile. Hows is that done nowadays?
I think there used to be a --irb option when running rails console but that seems to be gone now. I get a deprecation error message when I try it.
More details
If I just run "rails console" it takes me to pry.
If I run "rails console -irb=irb":
$ rails c -irb=irb
--irb option is no longer supported. Invoke `/your/choice/of/ruby script/rails console` instead
Relevent lines from my Gemfile:
gem 'rails', '3.2.18'
gem 'pry-rails'
gem 'pry-plus'
Launching pry when calling rails console or rails c is set up by the pry-rails gem. If you look in the pry-rails issues there is one that describes a solution.
Define the environment variable DISABLE_PRY_RAILS as 1.
So you can call rails console without pry with:
DISABLE_PRY_RAILS=1 rails c
Works in Rails 4: In your application.rb, inside your Application class, drop this puppy in.
# Use the IRB console instead of the Pry one
console do
require 'irb'
config.console = IRB
end
I couldn't take the Pry console anymore. It kept putting my cursor in odd places at unpredictable times. I can't even describe it but if you know what I'm talking about and know the solution, please let me know.
Inspired by the answers above, I added the following to the class definition in application.rb so that Pry is toggleable from the console:
console do
if ENV['IRB']
require 'irb'
config.console = IRB
end
end
You can then run rails c to get a Pry console, and IRB=true rails c to get an IRB console. This is easily modified if you want the inverse. Works in Rails 4 and 5.
For the benefit of anyone who runs into the same problem, this is my (crappy) workaround.
I wrapped the pry gems in Gemfile with this:
...
unless ENV['NOPRY']
gem 'pry-rails'
gem 'pry-plus'
end
...
Then run this from the unix terminal:
NOPRY=true bundle install
NOPRY=true rails console
Not pretty, but gets the job done...
You can also do it once console has already been started via IRB.start method.

Cannot load Gmail gem in console/app, but can in irb

I'm bewildered here. While I can run require "gmail" in irb and successfully load the Gmail gem, doing so in my rails console returns false. I made sure to include all the directories in $LOAD_PATH for irb in the $LOAD_PATH for my console, but still cannot get the gem to load in my console.
It may be that the gmail gem is conflicting with another gem that I have installed, but I don't know how to confirm this. It seems other people have had similar problems:
Why is autoload failing to load files for gems
Ruby autoload conflicts between gmail and parse_resource gems
Rails: Using ruby-gmail gem causes problems
I made sure to include 'gem "gmail"' in my Gemfile and run bundle install. Still no luck!
Stuck here, so would appreciate any help.
false doesn't mean that the gem is failing to load, it means that the gem is already loaded.
It the rails console could not find the gem you would get a LoadError. Here's an example of an app of mine that has gem 'haml' in the Gemfile.
1.9.2p320 :001 > require 'haml'
=> false
1.9.2p320 :002 > require 'foo'
LoadError: no such file to load -- foo
Another way to see this is to require 'gmail' a second time in your irb session.
You must add this line to your Gemfile:
gem 'gmail'
This is because the gems loaded by your application are restricted to just the ones specified inside the Gemfile, and their dependencies (and the dependencies of the dependencies, and so on).

Turn on full backtrace in Ruby on Rails TestCase

Only one line of backtrace is displayed when I run:
rake test
Output:
...
ERROR should get search for keywords (1.93s)
NoMethodError: undefined method `features' for #<Transcript:0x00000006243780>
/usr/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:385:in `method_missing'
...
I need more lines of backtrack information.
I have tried
rake test --trace
Rails.backtrace_cleaner.remove_silencers! in config/initializers/backtrace_silencers.rb
setting global $DEBUG=true
and it didn't work.
How can I turn it on?
BACKTRACE=blegga rake test
BACKTRACE=blegga rails test # rails 5+
Append --trace if you need rake related log.
Nowdays you can run:
rails test --backtrace
Finally figured this out. The issue is with the 'turn' gem included in Rails 3.1, or actually with turn v0.8.2, which is required by the default Gemfile:
group :test do
# Pretty printed test output
gem 'turn', '0.8.2', require: false
end
Turn v0.8.2 doesn't include the full backtrace, so you have to upgrade to get it. I did that by changing the above in my Gemfile to this:
group :test do
# Pretty printed test output
gem 'turn', require: false
gem 'minitest'
end
(I had to add minitest because otherwise turn throws a RuntimeError saying "MiniTest v1.6.0 is out of date.")
Then I ran bundle update turn and got the latest verion (0.9.2 as of this writing). That gives full backtraces.

Resources