~/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.
Related
The instructions for using the mocha mocking library with minitest don't work, and I don't know why... minitest 4.2.0, minitest-rails 0.3, mocha 0.12.4. Per the instructions, at the bottom of Gemfile I have
group :test, :development do
gem 'mocha', :require => false
end
which is supposed to turn off auto-requiring. And then at the bottom of the test helper files, I have require 'mocha' - the instructions say require 'mocha/setup', which doesn't even exist. With these two bits of code in, all the tests that run fine without mocha in the gemfile all fail with "undefined method 'run' blah blah blah". Anyone see what I'm missing here?
Sigh, apparently those messages are indicative of having failed to install the mocha rails plugin. That was the problem here.
I am learning Ruby and have to do some homework, but have problem with executing code. I searched this forum and Google and found that this could be problem with different Ruby versions but I don't know how to fix this. I've tried to execute:
cucumber features/filter_movie_list.feature
and got this:
And I should not see 'G' #
features/step_definitions/movie_steps.rb:32
no such file to load -- rspec/matchers/built_in/has (LoadError)
./features/step_definitions/movie_steps.rb:34:in /^(?:|I )should not see '([^']*)'$/'
features/filter_movie_list.feature:37:inAnd I should not see 'G''
Can someone help me to solve this problem or give me link to solution?
EDIT:
movie_steps.rb relevant for this taks is:
Then /^(?:|I )should not see '([^']*)'$/ do |text|
if page.respond_to? :should
page.find('#movies').should have_no_content(text)
else
assert page.find('#movies').has_no_content?(text)
end
end
The error message says that Cucumber can't find RSpec.
To solve it, edit your Gemfile and add these and that should solve it.
group :test do
gem 'rspec' # Behavior Driven Development (BDD) for Ruby
gem 'rspec-core' # RSpec runner and example groups.
gem 'rspec-expectations' # RSpec matchers for should and should_not.
gem 'rspec-mocks' # RSpec test double framework with stubbing and mocking.
gem 'rspec-rails' # RSpec version 2.x for Rails version 3.x.
end
If that does solve it, you can probably remove all those lines except the first one (the 'rspec' one) because that line should take care of the others.
I'm following through the "Learn Rails by Example" book, and I'm trying to run the tests. For some reason I can't get rspec to work properly.
If I run the rspec spec/ command as he instructs, I get the following error:
$ rspec spec/
/home/desktop/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.21/lib/bundler/runtime.rb:31:in `block in setup':
You have already activated rspec-core 2.7.1, but your Gemfile requires rspec-core 2.6.4.
Using bundle exec may solve this. (Gem::LoadError)
The odd thing is my Gemfile doesn't specify version--
group :development do
gem 'rspec-rails'
end
group :test do
gem 'rspec'
gem 'webrat'
end
If I follow the advice from the error message and use bundle exec rspec spec/ then the first two tests pass-- but the new "about" page we built in the tutorial fails with the following error, even though as far as I can tell the page I'd built (and controller actions etc.) are exactly as they should be:
Failures:
1) PagesController GET 'about' should be successful
Failure/Error: response.should_be_success
NoMethodError:
undefined method `should_be_success' for #<ActionController::TestResponse:0x00000003539438>
# ./spec/controllers/pages_controller_spec.rb:23:in `block (3 levels) in <top (required)>'
Finished in 0.10861 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:21 # PagesController GET 'about' should be successful
I'm a pretty experienced programmer but I've run into endless issues with conflicting gem versions and a hundred different ways to accomplish all the different tasks using Rails (eg. "use RVM", "Don't use RVM", "install gems using sudo", "don't install gems using sudo" etc.)
My dev machine is running ubuntu linux.
Thanks for any help-- please explain if you would what I'm doing wrong in Ruby noob language!
Running bundle exec is correct, and is needed because you have a newer version of that gem installed that gets loaded instead of the one specified in your Gemfile.lock. Using bundle exec overrides the load path, causing only the gems specified in your Gemfile.lock to be loaded. (You may find it handy to alias bundle exec to something shorter.)
The answer to the second problem is right in the error messages:
undefined method `should_be_success'
it should be should be_success.
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.
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