Thursday, May 11, 2017

The stable version of minitest_plugin.rb 5.10.1 for Rails testing

Today, I have got a bad luck that there was an error when I ran the first test case in my newly created Ruby on Rails project. And it took me 2-3 hours to figure out it and fixed it.

I just created a new Rails project called myapp3 as usual.
$ cd ~
$ rails new myapp3
$ cd myapp3

I generated a Static Pages controller named home and about:
$ rails generate controller StaticPages home about

The generate controller command will create a new test case for the static pages controller respectively.
test/controllers/static_pages_controller_test.rb
require 'test_helper'

class StaticPagesControllerTest < ActionDispatch::IntegrationTest
  test "should get home" do
    get static_pages_home_url
    assert_response :success
  end

  test "should get about" do
    get static_pages_about_url
    assert_response :success
  end

end

It is a brand new static pages test and it is supposed to pass. However, it fails.
jimmyc@Jimmy-C-2017:~/myapp3$ rails test
Running via Spring preloader in process 3281
/home/jimmyc/myapp3/db/schema.rb doesn't exist yet. Run `rails db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /home/jimmyc/myapp3/config/application.rb to limit the frameworks that will be loaded.
Run options: --seed 61369

# Running:

..

Finished in 0.581275s, 3.4407 runs/s, 3.4407 assertions/s.
/home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/test_unit/minitest_plugin.rb:9:in `aggregated_results': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:597:in `report'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:687:in `each'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:687:in `report'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:141:in `run'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/test_unit/minitest_plugin.rb:72:in `run'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:63:in `block in autorun'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.1/lib/spring/application.rb:161:in `fork'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.1/lib/spring/application.rb:161:in `serve'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.1/lib/spring/application.rb:131:in `block in run'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.1/lib/spring/application.rb:125:in `loop'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.1/lib/spring/application.rb:125:in `run'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.1/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/jimmyc/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'
jimmyc@Jimmy-C-2017:~/myapp3$ 

I tried to to figure out the root cause of this error. At first, I tried to find out what argument (parameter) caused the error, but I did not sure what argument it specified. Next, I tried to go through the Gem file and look at each of the Gem, but no result.

After all, Google saves me when I search "minitest_plugin.rb error" in Google.


In according to the Github issue post on Getting error: aggregated_results: wrong number of arguments (given 1, expected 0) #689, I added a line in my Gemfile to revert to the older minitest version 5.10.1 that works properly.
gem "minitest", "5.10.1"

Then I ran bundle install instead of bundle update.
jimmyc@Jimmy-C-2017:~/myapp3$ bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
You have requested:
  minitest = 5.10.1

The bundle currently has minitest locked at 5.10.2.
Try running `bundle update minitest`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

So, I realized that bundle update minitest is the correct command.
jimmyc@Jimmy-C-2017:~/myapp3$ bundle update minitest
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.1
Using minitest 5.10.1 (was 5.10.2)
Using thread_safe 0.3.6
Using builder 3.2.3
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 2.0.2
Using nio4r 2.0.0
Using websocket-extensions 0.1.2
Using mime-types-data 3.2016.0521
Using arel 7.1.4
Using bindex 0.5.0
Using bundler 1.14.6
Using byebug 9.0.6
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using method_source 0.8.2
Using thor 0.19.4
Using ffi 1.9.18
Using multi_json 1.12.1
Using rb-fsevent 0.9.8
Using puma 3.8.2
Using sass 3.4.23
Using tilt 2.0.7
Using sqlite3 1.3.13
Using turbolinks-source 5.0.3
Using tzinfo 1.2.3
Using nokogiri 1.7.2
Using rack-test 0.6.3
Using sprockets 3.7.1
Using websocket-driver 0.6.5
Using mime-types 3.1
Using coffee-script 2.4.1
Using uglifier 3.2.0
Using rb-inotify 0.9.8
Using turbolinks 5.0.1
Using activesupport 5.0.2
Using loofah 2.0.3
Using mail 2.6.5
Using listen 3.0.8
Using rails-dom-testing 2.0.3
Using globalid 0.4.0
Using activemodel 5.0.2
Using jbuilder 2.6.4
Using spring 2.0.1
Using rails-html-sanitizer 1.0.3
Using activejob 5.0.2
Using activerecord 5.0.2
Using spring-watcher-listen 2.0.1
Using actionview 5.0.2
Using actionpack 5.0.2
Using actioncable 5.0.2
Using actionmailer 5.0.2
Using railties 5.0.2
Using sprockets-rails 3.2.0
Using coffee-rails 4.2.1
Using jquery-rails 4.3.1
Using web-console 3.5.0
Using rails 5.0.2
Using sass-rails 5.0.6
Bundle updated!
jimmyc@Jimmy-C-2017:~/myapp3$

Finally, I can pass the test successfully.
jimmyc@Jimmy-C-2017:~/myapp3$ rails test
Running via Spring preloader in process 3611
/home/jimmyc/myapp3/db/schema.rb doesn't exist yet. Run `rails db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /home/jimmyc/myapp3/config/application.rb to limit the frameworks that will be loaded.
Run options: --seed 47348

# Running:

..

Finished in 0.552503s, 3.6199 runs/s, 3.6199 assertions/s.

2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
jimmyc@Jimmy-C-2017:~/myapp3$

Reference
Getting error: aggregated_results: wrong number of arguments (given 1, expected 0) #689
https://github.com/seattlerb/minitest/issues/689

1 comment:

How to kill an abandoned process in Linux/Unix

I remembered it, then I forgot, then I remembered it, and then I forgot again. In case of a Linux/Unit process hang, I have to figure out ...