Это довольно простой случай использования minitest и теста контроллера. Это выглядит примерно так:
# words_controller_test.rb
class WordTest < ActiveSupport::TestCase
it "should get random" do
get words_random_url
assert_response :success
end
end
# test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'
class ActiveSupport::TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
# word_controller.rb
class WordsController < ApplicationController
def random
@word = Word.random
end
end
# word.rb (model)
class Word < ApplicationRecord
validates :eng, presence: true
validates :ned, presence: true
def self.random
Word.all.sample
end
end
Это работает правильно, когда я запускаю сервер rails (в режиме dev или test) и посещаю / word / random
Когда я запускаю это с rails test
Я получаю эту дикую ошибку
~/m/p/r/railstestdemo (master →☡) rails test
Run options: --seed 33448
# Running:
.....Traceback (most recent call last):
20: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:68:in `block in autorun'
19: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:138:in `run'
18: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `start'
17: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `map'
16: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `each'
15: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `times'
14: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:75:in `block in start'
13: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:75:in `fork'
12: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:95:in `block (2 levels) in start'
11: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1138:in `method_missing'
10: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1158:in `with_friend'
9: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1139:in `block in method_missing'
8: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1227:in `open'
7: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1140:in `block (2 levels) in method_missing'
6: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1251:in `send_message'
5: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:929:in `send_request'
4: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:610:in `send_request'
3: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:610:in `each'
2: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:611:in `block in send_request'
1: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:565:in `dump'
/Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:565:in `dump': no _dump_data is defined for class Binding (TypeError)
25: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:68:in `block in autorun'
24: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:138:in `run'
23: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `start'
22: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `map'
21: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `each'
20: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `times'
19: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:75:in `block in start'
18: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:75:in `fork'
17: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:95:in `block (2 levels) in start'
16: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1138:in `method_missing'
15: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1158:in `with_friend'
14: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1139:in `block in method_missing'
13: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1227:in `open'
12: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1140:in `block (2 levels) in method_missing'
11: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1251:in `send_message'
10: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:929:in `send_request'
9: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:610:in `send_request'
8: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:610:in `each'
7: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:611:in `block in send_request'
6: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:564:in `dump'
5: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:567:in `rescue in dump'
4: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:650:in `make_proxy'
3: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:650:in `new'
2: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1101:in `initialize'
1: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1807:in `to_id'
/Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1738:in `current_server': DRb::DRbServerNotFound (DRb::DRbServerNotFound)
25: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:68:in `block in autorun'
24: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:138:in `run'
23: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `start'
22: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `map'
21: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `each'
20: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `times'
19: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:75:in `block in start'
18: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:75:in `fork'
17: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:95:in `block (2 levels) in start'
16: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1138:in `method_missing'
15: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1158:in `with_friend'
14: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1139:in `block in method_missing'
13: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1227:in `open'
12: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1140:in `block (2 levels) in method_missing'
11: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1251:in `send_message'
10: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:929:in `send_request'
9: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:610:in `send_request'
8: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:610:in `each'
7: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:611:in `block in send_request'
6: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:564:in `dump'
5: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:567:in `rescue in dump'
4: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:650:in `make_proxy'
3: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:650:in `new'
2: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1101:in `initialize'
1: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1807:in `to_id'
/Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/2.6.0/drb/drb.rb:1738:in `current_server': DRb::DRbServerNotFound (DRb::DRbConnError)
11: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:68:in `block in autorun'
10: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:138:in `run'
9: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `start'
8: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `map'
7: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `each'
6: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:74:in `times'
5: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:75:in `block in start'
4: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:75:in `fork'
3: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:94:in `block (2 levels) in start'
2: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:97:in `rescue in block (2 levels) in start'
1: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:97:in `each'
/Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:98:in `block (3 levels) in start': undefined method `exception=' for #<Minitest::UnexpectedError: Unexpected exception> (NoMethodError)
Did you mean? exception
Traceback (most recent call last):
2: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:68:in `block in autorun'
1: from /Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/minitest-5.14.0/lib/minitest.rb:145:in `run'
/Users/pitosalas/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/testing/parallelization.rb:118:in `shutdown': Queue not empty, but all workers have finished. This probably means that a worker crashed and 1 tests were missed. (RuntimeError)
~/m/p/r/railstestdemo (master →☡)