Я пишу тест для моей модели user
. Пользовательская модель в сгенерированной пользовательской модели Devise
с некоторыми дополнительными атрибутами, которые я добавил.
Создал тест, следуя этому руководству o как создать контактную форму. Использовал ту же логику при тестировании моей модели user
.
Ошибка в консоли:
Failure:
UserTest#test_attributes_height,_weight,_age_and_gender_are_required_to_complete_profile [/vagrant/test/models/user_test.rb:58]:
Expected /blank/ to match # encoding: US-ASCII
"[]".
Пользовательский тест:
test 'attributes height, weight, age and gender are required to complete profile' do
user = User.new @attrs
assert_match /blank/, user.errors[ :height ].to_s
assert_match /blank/, user.errors[ :weight ].to_s
assert_match /blank/, user.errors[ :age ].to_s
assert_match /blank/, user.errors[ :gender ].to_s
end
Тест сообщения (проходит) Я использовал в качестве ссылки:
test 'name, email and body are required attributes' do
message = Message.new
refute message.valid? 'Blank message should be invalid'
assert_match /blank/, message.errors[ :name ].to_s
assert_match /blank/, message.errors[ :email ].to_s
assert_match /blank/, message.errors[ :title ].to_s
assert_match /blank/, message.errors[ :text ].to_s
end
Стек:
/var/lib/gems/2.3.0/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_attributes_height,_weight,_age_and_gender_are_required_to_complete_profile' for class `Minitest::Result' (NameError)
from /var/lib/gems/2.3.0/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
from /var/lib/gems/2.3.0/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:23:in `record'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:803:in `block in record'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:802:in `each'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:802:in `record'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:334:in `run_one_method'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:321:in `block (2 levels) in run'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:320:in `each'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:320:in `block in run'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:360:in `on_signal'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:347:in `with_info_handler'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:319:in `run'
from /var/lib/gems/2.3.0/gems/railties-5.0.7.2/lib/rails/test_unit/line_filtering.rb:9:in `run'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:159:in `block in __run'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:159:in `map'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:159:in `__run'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:136:in `run'
from /var/lib/gems/2.3.0/gems/minitest-5.11.3/lib/minitest.rb:63:in `block in autorun'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
Тест проверяет, являются ли атрибуты пустыми или нулевыми, но возвращает только Expected /blank/ to match # encoding: US-ASCII
"[]"
. Тест сообщения проходит без ошибок.
Тест message
проверяет только атрибуты, являющиеся строками, но тест user
также включает целые и логические значения.
Связана ли проблема с различными типами данных?