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.
Related
~/Sites/sample_app$ rails test
Running via Spring preloader in process 24338
Run options: --seed 58780
Running:
..
Finished in 0.292172s, 6.8453 runs/s, 6.8453 assertions/s.
/var/lib/gems/2.3.0/gems/railties-5.1.0/lib/rails/test_unit/minitest_plugin.rb:9:in `aggregated_results': wrong number of arguments (given 1, expected 0) (ArgumentError)
I don't understand why I am getting this error. I Can't seem to find anyone with this specific error. I'm following the tutorial https://www.railstutorial.org/book/static_pages. This error follows the rails test command. Running Ubuntu and rails 5.1 if that helps. I'm not passing any arguments so I don't understand why I am getting this error.
My test file looks like :
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
test "should get home" do
get static_pages_home_url
assert_response :success
end
test "should get help" do
get static_pages_help_url
assert_response :success
end
This is actually a bug in rails, revealed by minitest update to 5.10.2 as said here and it has already been fixed here.
As the pull request is only 10 hours old (at the time of writing), it has not yet been released, although it's already merged.
In the mean time, you can specify in your Gemfile:
gem 'minitest', '~> 5.10', '!= 5.10.2'
Edit
Don't forget to bundle update minitest
Hey I'm doing this exact tutorial and followed the top solution and it fixed my issue, specifically (for us total noobs) I did this to my Gemfile
group :test do
gem 'rails-controller-testing', '0.1.1'
gem 'minitest-reporters', '1.1.9'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
gem 'minitest', '~> 5.10', '!= 5.10.2' # add this here to fix error
end
It turns out that in my test/test_helper.rb I needed a line of code that was missing. I added this before "class ActiveSupport::TestCase".
Minitest::Reporters.use!
This gave me a passing result for my test with no strange argument error. Hope this helps someone for the future!
Problem is in minitest 5.10.2. Downgrading to 5.10.1 fixes it.
Add this line in test group in Gemfile
gem 'minitest', '5.10.1'
Then run following commands
bundle update minitest
rails test
The issue is resolved
I also encountered this error. I tried using the top voted solution, but rails told me that bundle has locked minitest to 5.10.2. Instead, I just did a gem update minitest and my tests ran without the weird error.
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.
I have a rails 4 app. I have no tests at the moment, but when I created the app I didn't skip the default test unit so there are some empty test files (and other default settings) in my app.
Now I would like to use rspec + capybara, but don't know what the necessary extra steps are to properly install those and make sure the testing will work fine. I saw some answers on stackoverflow but thoose were pretty old.
As far as I know the installation looks like this if test unit is skipped on creation:
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'capybara'
end
then
rails g rspec:install
Can sby tell me what the extra steps are?
Follow these steps:
add code to your_app/config/application.rb file:
config.generators do |g|
g.test_framework :rspec
end
add below code to your_app's Gemfile:
group :test, :development do
gem 'rspec-rails'
end
save it, and run bundle install to install rspec gem
Initialize the spec/ directory
rails generate rspec:install
Use the rspec command to run your specs:
bundle exec rspec
Hopefully it helps.
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.
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