简体   繁体   中英

How do I use the normal controller test assertions in Minitest Spec DSL

I usually write my specs in RSpec but I use Minitest too. Recently I learnt that there is a minitest dsl that could read like RSpec. They call it Minitest::Spec. I have checked it out and I think I like it. The gem 'minitest-rails' makes the setup configuration easy. There is however one limitation I have faced and that is in the integration specs. What is the equivalent for assertions like assert_response , assert_no_difference , and assert_template ?

I have seen an answer. It turned out that I got them in the very gem that supplied the test expectations. I looked into the source code of the minitest/rails/controller.rb and I saw the simple way those expectations were implemented is by aliasing the real minitest assertions. Here is my find

class ActionController::TestCase # :nodoc:
  alias :must_respond_with :assert_response
  alias :must_redirect_to :assert_redirected_to
  alias :must_render_template :assert_template
  alias :must_select :assert_select
  alias :must_select_email :assert_select_email
  alias :must_select_encoded :assert_select_encoded
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM