pry-rails not rails console working with Rails 4.0 - ruby-on-rails

included 'pry-rails' in my Gemfile run console and get the following
#marketplace-rails/gems/pry-rails-0.2.0/lib/pry-rails/commands.rb:3:in `block in <module:PryRails>': undefined method `create_command' for #<Pry::CommandSet:0x007fcfaa67a878> (NoMethodError)

Step 1. don't use 'pry-rails' ? (not sure how to get that gem
working)
Step 2. in gemfile include gem 'pry'
Step 3. in application.rb include the following...
console do
require "pry"
config.console = Pry
end
run rails console be happy to have pry back in your life.

For what it's worth, I just tried this:
group :development, :test do
gem 'pry-rails'
end
Followed by a bundle install and a 'rails c' and pry came up.

Try stopping spring,
$ bin/spring stop
worked for me after installing the gem, didn't even have to change it in the config/environment/development file either

Make sure you have pry included in your Gemfile and add
config.console = Pry
to your config/environments/development.rb or to your config/application.rb if you want it in every environment.

Related

How do I get awesome_print to work without using ~/.irbrc file?

I want to use awesome print without putting it in my rails 5 app. Just in the console. The documentation for requiring it in irb is not working.
That's because bundler isolates the gems available to load to what's in your Gemfile.
The best way to get around this is to add the gem to your Gemfile
gem 'awesome_print', require: false, group: :development
And in your .irbrc, you can require it, so that it is only enabled for you:
begin
require 'awesome_print'
rescue LoadError => err
warn "could not require awesome_print: #{err}"
end
However, if you aren't permitted to add awesome_print to your repository for whatever reason, there are a few hacks to get gems installed, but not in your Gemfile to load in this GitHub Gist.
One such example that could be placed at the top of your .irbrc:
# Add all gems in the global gemset to the $LOAD_PATH so they can be used even
# in places like 'rails console'.
if defined?(::Bundler)
global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*#global/).first
$LOAD_PATH.concat(Dir.glob("#{global_gemset}/gems/*/lib")) if
global_gemset
end
cd your/rails/project
irb
inside irb, run:
require 'awesome_print'
require './config/environment'
and you have both rails console and awesome_print gem while the gem is installed outside of the bundler.

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.

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.

Gem available in irb but not rails console

I am trying to use the RedCloth gem in my rails project. When I used irb I can load the gem:
require 'rubygems'
require 'RedCloth'
and it works fine, but when I try the same thing in the rails console I get an error message stating that the gem cannot be found.
Does anyone have any idea what might cause this?
You can append gem path to ruby load path. Do this:
gem which faker
=> /usr/local/ruby/......../faker-0.1.1/lib/faker.rb
Start Rails console and do the following:
$: << '/usr/local/ruby/......../faker-0.1.1/lib/'
and now load faker gem
require 'faker'
=> true
Does your rails project's Gemfile include gem 'RedCloth' in it? Rails will only load the gems specified in that file.

Rails colour highlighting for the Test::Unit/rake command?

When running test/unit using the rake test command from the terminal within a rails 3 project directory, the test result output is not coloured. Hence, it cannot be interpreted at a glance.
Is there a way of getting colourised output for the results, as you can get in rspec?
>rspec --colour
I discovered that redgreen was abandoned years ago, and found this solution which works well and requires no script hacking. The output, however, shows which test is being run in real time. So it is a lot longer than built in test output. It does have nice colors.
http://rubygems.org/gems/turn
In my Gemfile:
group :test do
gem 'turn'
end
Then run:
$ bundle install
$ rake test
The gem 'turn' works great. The caveat is that it doesn't seem to work with Mocha, due to monkey-patching issues. If you are using Mocha, you can use the redgreen gem. See instructions above in the approved answer for this question.
Yes, you can use the redgreen gem. Include it in your gemfile:
group :development, :test do
gem 'redgreen'
end
And that's all you need for ruby 1.8. If you're using 1.9, there's a workaround. add the test-unit gem:
group :development, :test do
gem 'redgreen'
gem 'test-unit', '1.2.3
end
It's not perfect with 1.9 - test-unit seems to run an empty test suite after every rake task or generator call, which is harmless but annoying.
I am working on Rails 5.1 / minitest and I was also searching for a solution to make the reporting color. None of these test::unit solutions are working, so I googled and saw this solution. Just add the following:
# Gemfile
gem 'minitest-reporters'
# test/test_helper.rb
require "minitest/reporters"
Minitest::Reporters.use!
Github: minitest-reporters

Resources