├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .rubocop.yml ├── Appraisals ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── Gemfile ├── MIT-LICENSE ├── README.md ├── Rakefile ├── gemfiles ├── rails_v6.0.x.gemfile ├── rails_v6.0.x.gemfile.lock ├── rails_v6.1.x.gemfile ├── rails_v6.1.x.gemfile.lock ├── rails_v7.0.x.gemfile ├── rails_v7.0.x.gemfile.lock └── rails_v7.1.x.gemfile ├── lib ├── minitest-spec-rails.rb └── minitest-spec-rails │ ├── dsl.rb │ ├── init │ ├── action_cable.rb │ ├── action_controller.rb │ ├── action_dispatch.rb │ ├── action_mailer.rb │ ├── action_view.rb │ ├── active_job.rb │ ├── active_support.rb │ └── mini_shoulda.rb │ ├── parallelize.rb │ ├── railtie.rb │ └── version.rb ├── minitest-spec-rails.gemspec └── test ├── cases ├── action_cable_test.rb ├── action_controller_test.rb ├── action_dispatch_test.rb ├── action_mailer_test.rb ├── action_view_test.rb ├── active_job_test.rb ├── active_support_test.rb └── mini_shoulda_test.rb ├── dummy_app ├── app │ ├── assets │ │ └── config │ │ │ └── manifest.js │ ├── channels │ │ └── application_cable │ │ │ ├── channel.rb │ │ │ └── connection.rb │ ├── controllers │ │ ├── application_controller.rb │ │ └── users_controller.rb │ ├── helpers │ │ ├── application_helper.rb │ │ ├── foos_helper.rb │ │ └── users_helper.rb │ ├── mailers │ │ └── user_mailer.rb │ ├── models │ │ ├── post.rb │ │ └── user.rb │ └── views │ │ └── users │ │ └── index.html.erb ├── config │ ├── database.yml │ ├── routes.rb │ └── storage.yml ├── init.rb ├── lib │ └── library.rb └── tmp │ ├── .gitkeep │ └── development_secret.txt ├── dummy_tests ├── application_controller_test.rb ├── foos_helper_test.rb ├── integration_test.rb ├── library_test.rb ├── special_users_controller_test.rb ├── user_mailer_test.rb ├── user_test.rb ├── users_controller_test.rb └── users_helper_test.rb ├── support └── shared_test_case_behavior.rb ├── test_helper.rb └── test_helper_dummy.rb /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push] 3 | jobs: 4 | test: 5 | runs-on: ubuntu-latest 6 | strategy: 7 | matrix: 8 | ruby: 9 | - "3.0" 10 | - "3.1" 11 | - "3.2" 12 | rails: 13 | - "rails_v6.0.x" 14 | - "rails_v6.1.x" 15 | - "rails_v7.0.x" 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v3 19 | - name: Setup System 20 | run: | 21 | sudo apt-get install libsqlite3-dev 22 | echo "MTSR_RAILS_VERSION=${{ matrix.rails }}" >> $GITHUB_ENV 23 | - name: Setup Ruby 24 | uses: ruby/setup-ruby@v1 25 | with: 26 | ruby-version: ${{ matrix.ruby }} 27 | - name: Bundle 28 | run: | 29 | export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${MTSR_RAILS_VERSION}.gemfile" 30 | gem uninstall -aIx bundler 31 | gem install bundler -v 1.17.3 32 | bundle install --jobs 4 --retry 3 33 | - name: Test 34 | run: | 35 | export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${MTSR_RAILS_VERSION}.gemfile" 36 | bundle exec rake 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | .ruby-version 4 | Gemfile.lock 5 | pkg/* 6 | *.log 7 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | 2 | Metrics/LineLength: 3 | Max: 120 4 | 5 | Metrics/MethodLength: 6 | Max: 15 7 | 8 | Metrics/BlockLength: 9 | Exclude: 10 | - 'test/dummy_tests/user_mailer_test.rb' 11 | 12 | Style/Documentation: 13 | Enabled: false 14 | 15 | Style/GlobalVars: 16 | AllowedVariables: 17 | - '$teardown_ran' 18 | 19 | Style/FileName: 20 | Exclude: 21 | - 'lib/minitest-spec-rails.rb' 22 | - 'Appraisals' 23 | 24 | AllCops: 25 | Exclude: 26 | - 'gemfiles/*' 27 | -------------------------------------------------------------------------------- /Appraisals: -------------------------------------------------------------------------------- 1 | 2 | appraise 'rails_v6.0.x' do 3 | gem 'rails', '~> 6.0.0' 4 | gem 'minitest' 5 | end 6 | 7 | appraise 'rails_v6.1.x' do 8 | gem 'rails', '~> 6.1.0' 9 | gem 'minitest' 10 | end 11 | 12 | appraise 'rails_v7.0.x' do 13 | gem 'rails', '~> 7.0.0' 14 | gem 'minitest' 15 | end 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 7.4.0, 7.4.1 2 | 3 | - Fix require `action_cable/channel/test_case` errors with Rails 5.x. Fixes #124 4 | 5 | ## 7.3.0 6 | 7 | - Fix require `action_cable/channel/test_case` errors with Rails 5.x. Fixes #124 8 | 9 | ## 7.2.0 10 | 11 | - Wrap action_view init in config.to_prepare block. Fixes #122. Thanks @Hal-Sumi 12 | 13 | ## 7.1.0 14 | 15 | - Use Minitest instead of MiniTest. Fixes #119. Thanks @evgeni 16 | - Fix ActionCable::Channel::TestCase support. Fixes #118. Thanks @marcoroth 17 | - Add support for ActionCable::Channel::TestCase. Fixes #117. Thanks @tijn 18 | 19 | ## 7.0.0 20 | 21 | - Add support for ActionCable::Channel::TestCase. Fixed #117. Thanks @tijn 22 | - Remove automated tests for Rails v5 and Ruby v2. 23 | - Update all of our tests and examples to use non-global expectations. 24 | - Remove `Rails.application.reloader.to_prepare` for `ActionViewBehavior`. 25 | 26 | ## 6.2.0 27 | 28 | - Remove 'ENV['RAILS_ENV']=='test' from railtie.rb Fixes #114. Thanks @Qqwy 29 | 30 | ## 6.1.0 31 | 32 | - Fix Rails v7 autoloading with ViewComponent. Thanks @woller 33 | 34 | ## 6.0.4 35 | 36 | - Fixed parallel tests with relative paths. Thanks @jlsherrill 37 | 38 | ## 6.0.3 39 | 40 | - Better ActionView load. Fixed #105. Thanks @zofrex 41 | 42 | ## 6.0.2 43 | 44 | - Fixed parallel tests in Rails v6. 45 | 46 | ## 6.0.1 47 | 48 | - Changed gemspec to `railties` vs `rails`. Thanks @seuros 49 | 50 | ## 6.0.0 51 | 52 | - Bumping to be major with latest testing versions. 53 | 54 | ## 5.6.0 55 | 56 | - Add Rails v6 via gem spec support. 57 | 58 | ## 5.5.0 59 | 60 | - Fix source_location of methods defined with `test`. Fixes #91. Thanks @barrettkingram 61 | 62 | ## 5.4.0 63 | 64 | - Use ENV['RAILS_ENV'] for initializer guards vs memo'ed Rails.env. Fixes #72. 65 | 66 | ## 5.3.0 67 | 68 | - Allow Rails 4.1 to new 5.x to be supported. 69 | 70 | ## 5.2.2 71 | 72 | - Fix ActiveJob support for `described_class`. Thanks @pschambacher. 73 | 74 | ## 5.2.1 75 | 76 | - Only add our Thread.current[:current_spec] hack if needed. Fixes #45. 77 | 78 | ## 5.2.0 79 | 80 | - Added ActiveJob support. Fixes #59. Thanks @xpepermint. 81 | 82 | ## 5.1.1 83 | 84 | - Fix an issue where `describe` method was removed. Fixes #55 & #50 85 | [41a0f851](https://github.com/metaskills/minitest-spec-rails/commit/41a0f851c8a290f59feb1cb8b20759f0e2a9697a) 86 | 87 | ## 5.1.0 88 | 89 | No release notes yet. PRs welcome! 90 | 91 | ## 5.0.4 92 | 93 | - Fixed ActiveSupport's Declarative#test forwarded implementation. Fixed #46. 94 | 95 | ## 5.0.3 96 | 97 | - Fixed ActionView load order & url helpers. Fixes #42. 98 | 99 | ## 5.0.2 100 | 101 | - Fixed initialization callbacks for latest Rails 4.1. Fixes #39. 102 | 103 | ## 5.0.1 104 | 105 | - Change initialization so that ActiveSupport always comes first. 106 | 107 | ## 5.0.0 108 | 109 | - Minitest 5.x and Rails 4.1 compatability. Fixes #36. 110 | - Fix nested described test names along with Minitest::Spec.describe_stack. Fixed #21. 111 | - Leverage `ActiveSupport::Testing::ConstantLookup` for our `described_class` interface. 112 | 113 | ## 4.7.6 114 | 115 | - Fix nested described test names. Fixes #21. 116 | 117 | ## 4.7.5 118 | 119 | - Fixed gemspec using '>= 3.0', '< 4.1'. Fixed #35. 120 | 121 | ## 4.7.4 122 | 123 | - Enforces case sensitivity on registered spec types. Fixes #26. 124 | 125 | ## 4.7.3 126 | 127 | - Allow using ActiveSupport's Declarative#test as an alias to it. Thanks @ysbaddaden. Fixes #23. 128 | 129 | ## 4.7.2 130 | 131 | - Register non ActiveRecord::Base classes correctly. Thanks @mptre. 132 | 133 | ## 4.7.1 134 | 135 | - Only use a TU shim for Ruby 1.8. See README for info. Fixes #18. 136 | 137 | ## 4.7.0 138 | 139 | - Use Minitest::Spec::DSL provided by Minitest 4.7. 140 | 141 | ## 4.3.8 142 | 143 | - Less coupling to ActiveRecord ORM, works for MongoDB now. Thanks @kimsuelim 144 | 145 | ## v4.3.7 146 | 147 | - Fix helper test bug where calling methods in first context block blew up. Fixes #13. 148 | 149 | ## v4.3.6 150 | 151 | - Only require the freedom patches and autorun when Rails.env.test? 152 | 153 | ## v4.3.5 154 | 155 | - Make sure #described_class works in ActiveSupport::TestCase class level. 156 | 157 | ## v4.3.4 158 | 159 | - Add mini_should support and talk about matchers. 160 | 161 | ## v4.3.3 162 | 163 | - Fix MiniTest::Unit::TestCase hack for Rails 4, ignore in Rails 3. 164 | 165 | ## v4.3.2 166 | 167 | - Way better support for controller_class, mailer_class, and helper_class reflection. 168 | 169 | ## v4.3.1 170 | 171 | - Eager load controller_class, mailer_class, and helper_class. 172 | 173 | ## v4.3.0 174 | 175 | - All new MiniTest::Spec for Rails!!! Tested to the hilt!!! 176 | - Track MiniTest's major/minior version number. 177 | 178 | ## v3.0.7 179 | 180 | - Must use MiniTest version ~> 2.1. As 3.x will not work. 181 | 182 | ## v3.0.6 183 | 184 | - Use #constantize vs. #safe_constantize for Rails 3.0 compatability. 185 | 186 | ## v3.0.5 187 | 188 | - Use ActionController::IntegrationTest vs. ActionDispatch::IntegrationTest 189 | 190 | ## v3.0.4 191 | 192 | - Use class app setter for integration tests. 193 | 194 | ## v3.0.3 195 | 196 | - Stronger test case organization where we properly setup functional and integraiton tests 197 | while also allowing an alternate pure MiniTest::Spec outter file describe block. [Jack Chu] 198 | 199 | ## v3.0.2 200 | 201 | - Remove version deps on minitest since v3 is out. Should work with any v2/3 version. 202 | 203 | ## v3.0.1 204 | 205 | - Add rails to the gemspec. 206 | 207 | ## v3.0.0 208 | 209 | - Initial Release, targeted to Rails 3.x. 210 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all 4 | people who contribute through reporting issues, posting feature requests, 5 | updating documentation, submitting pull requests or patches, and other 6 | activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, or religion. 12 | 13 | Examples of unacceptable behavior by participants include the use of sexual 14 | language or imagery, derogatory comments or personal attacks, trolling, public 15 | or private harassment, insults, or other unprofessional conduct. 16 | 17 | Project maintainers have the right and responsibility to remove, edit, or 18 | reject comments, commits, code, wiki edits, issues, and other contributions 19 | that are not aligned to this Code of Conduct. Project maintainers who do not 20 | follow the Code of Conduct may be removed from the project team. 21 | 22 | This code of conduct applies both within project spaces and in public spaces 23 | when an individual is representing the project or its community. 24 | 25 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 26 | reported by opening an issue or contacting one or more of the project 27 | maintainers. 28 | 29 | This Code of Conduct is adapted from the Contributor Covenant 30 | (http://contributor-covenant.org), version 1.1.0, available at 31 | http://contributor-covenant.org/version/1/1/0/ 32 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Ken Collins, 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Make Rails Use Minitest::Spec! 4 | ##### https://dhh.dk/2012/rails-is-omakase.html 5 | 6 | The minitest-spec-rails gem makes it easy to use the Minitest::Spec DSL within your existing Rails 2.3, 3.x or 4.x test suite. It does this by forcing ActiveSupport::TestCase to utilize the Minitest::Spec::DSL. 7 | 8 | [![Gem Version](https://badge.fury.io/rb/minitest-spec-rails.svg)](http://badge.fury.io/rb/minitest-spec-rails) 9 | [![CI Status](https://github.com/metaskills/minitest-spec-rails/workflows/CI/badge.svg)](https://launch-editor.github.com/actions?nwo=metaskills%2Fminitest-spec-rails&workflowID=CI) 10 | [![Maintainability](https://api.codeclimate.com/v1/badges/e67addda6fd009b68349/maintainability)](https://codeclimate.com/github/metaskills/minitest-spec-rails/maintainability) 11 | 12 | 13 | ## Usage 14 | 15 | Existing or new Rails applications that use the default Rails testing structure can simply drop in the minitest-spec-gem and start writing their tests in the new spec DSL. Since Minitest::Spec is built on top of Minitest::Unit, a replacement for Test::Unit, all of your existing tests will continue to work. 16 | 17 | 18 | #### Rails 4.1 to 6.0 19 | 20 | Our master branch is tracking rails 5.1 up to 6.x active development. 21 | 22 | ```ruby 23 | group :test do 24 | gem 'minitest-spec-rails' 25 | end 26 | ``` 27 | 28 | #### For Rails 3.x or 4.0 29 | 30 | Our [3-x-stable](https://github.com/metaskills/minitest-spec-rails/tree/3-x-stable) branch is meant for both Rails 3.x or 4.0 specifically. This version uses the latest 4.x series of minitest. 31 | 32 | ```ruby 33 | group :test do 34 | gem 'minitest-spec-rails', '~> 4.7' 35 | end 36 | ``` 37 | 38 | 39 | ### How is this different than Minitest::Rails? 40 | 41 | To start off both Mike Moore (@blowmage) and I have worked together and we both LOVE Minitest::Spec. Both projects aim to advocate Minitest and make Rails integration as easy as possible. However, there are a few key differences in our projects. Some of these differences may go away in time too. As always, choose the tool you think fits your needs. So how, is minitest-spec-rails different than [minitest-rails](https://github.com/blowmage/minitest-rails)? 42 | 43 | * We aim to leverage existing Rails test directories and files! 44 | * No special test helper and/or generators. 45 | * Easy migration path for existing Rails applications. 46 | * How we go about freedom patching Rails. 47 | * Fully support Ruby 1.8.7 with all legacy Test::Unit behavior. 48 | * Compatibility with ActiveSupport::TestCase's setup and teardowns. 49 | 50 | So the goal of this project is to make Rails 3 or 4 applications just work as if rails-core had decided to support Minitest::Spec all along. We believe that eventually that day will come and when it does, all your tests will still work! So bundle up and get started! 51 | 52 | ```ruby 53 | gem 'minitest-spec-rails' 54 | ``` 55 | 56 | 57 | ## Test Styles 58 | 59 | This cheat sheet shows both the Minitest::Unit assertions along with the Minitest::Spec assertion syntax. Remember, Minitest::Spec is built on top of Minitest::Unit which is a Test::Unit replacement. That means you can mix and match styles as you upgrade from Test::Unit to a more modern style. For example, both of these would work in Minitest::Spec and are interchangeable. 60 | 61 | ```ruby 62 | # Minitest::Unit Assertion Style: 63 | assert_equal 100, foo 64 | 65 | # Minitest::Spec Assertion Style: 66 | expect(foo).must_equal 100 67 | ``` 68 | 69 | 70 | ```ruby 71 | require 'test_helper' 72 | class UserTest < ActiveSupport::TestCase 73 | let(:user_ken) { User.create! :email => 'ken@metaskills.net' } 74 | it 'works' do 75 | expect(user_ken).must_be_instance_of User 76 | end 77 | end 78 | ``` 79 | 80 | ```ruby 81 | require 'test_helper' 82 | describe User do 83 | # THIS IS NOT RECOMMENDED! 84 | end 85 | ``` 86 | 87 | RSpec 3 is also moving away from the outer describe test type inference, as described in this line from their [release notes](https://www.relishapp.com/rspec/rspec-rails/v/3-1/docs/changelog). 88 | 89 | > Spec types are no longer inferred by location, they instead need to be explicitly tagged. The old behaviour is enabled by config.infer_spec_type_from_file_location!, which is still supplied in the default generated spec_helper.rb. (Xavier Shay, Myron Marston) 90 | 91 | Not that we want to mimic RSpec, but the aim of this gem is very straight forward and minimalistic. We simply want to expose the Minitest Spec::DSL and core assertion style within ActiveSupport. Period. So it is very possible that us matching outer describe to classes is simply going to go away one day soon. 92 | 93 | Just for reference, here is a full list of each of Rails test case we support. 94 | 95 | ```ruby 96 | # Model Test (or anything else not listed below) 97 | class UserTest < ActiveSupport::TestCase 98 | end 99 | 100 | # Controller Test 101 | class UsersControllerTest < ActionController::TestCase 102 | end 103 | 104 | # Integration Tests - Must use subclass style! 105 | class IntegrationTest < ActionDispatch::IntegrationTest 106 | end 107 | 108 | # Mailer Test 109 | class UserMailerTest < ActionMailer::TestCase 110 | end 111 | 112 | # View Helper Test 113 | class UsersHelperTest < ActionView::TestCase 114 | end 115 | 116 | # Job Helper Test 117 | class MyJobTest < ActiveJob::TestCase 118 | end 119 | ``` 120 | 121 | 122 | ## Extras 123 | 124 | We have baked in a few extra methods behind the scenes to minitest-spec-rails. Most directly support our needs to reflect on described classes, however, they may be useful to you too when meta-programming on top of minitest-spec-rails. 125 | 126 | ### #described_class 127 | The `described_class` method is available both via a class method and an instance method in any Rails test case. It is guaranteed to work despite the described level too. This allows class level macros to be built, much like Shoulda. Remember, it can only do this if you follow Rails naming conventions for your tests. 128 | 129 | ```ruby 130 | class UserTest < ActiveSupport::TestCase 131 | described_class # => User(id: integer, email: string) 132 | it 'works here' do 133 | described_class # => User(id: integer, email: string) 134 | end 135 | describe 'and' do 136 | it 'works here too' do 137 | described_class # => User(id: integer, email: string) 138 | end 139 | end 140 | end 141 | ``` 142 | 143 | ### Setup & Teardown Compatability 144 | 145 | Rails ActiveSupport::TestCase allows multiple setup and teardown methods per class. It also allows you to specify these either with a symbol or a block. Unlike normal ActiveSupport setup and teardown callbacks, our blocks are evaluated in the scope of the instance, just like before and after. So this just works! 146 | 147 | ```ruby 148 | class ActiveSupportCallbackTest < ActiveSupport::TestCase 149 | 150 | setup :foo 151 | setup :bar 152 | before { @bat = 'biz' } 153 | 154 | it 'works' do 155 | expect(@foo).must_equal 'foo' 156 | expect(@bar).must_equal 'bar' 157 | expect(@bat).must_equal 'biz' 158 | end 159 | 160 | private 161 | 162 | def foo ; @foo = 'foo' ; end 163 | def bar ; @bar = 'bar' ; end 164 | 165 | end 166 | ``` 167 | 168 | ### mini_shoulda 169 | 170 | If you are migrating away from Shoulda, then minitest-spec-rails' mini_shoulda feature will help. To enable it, set the following configuration in your test environment file. 171 | 172 | ```ruby 173 | # In config/environments/test.rb 174 | config.minitest_spec_rails.mini_shoulda = true 175 | ``` 176 | 177 | Doing so only enables a few aliases that allow the Shoulda `context`, `should`, and `should_eventually` methods. The following code demonstrates the full features of the mini_shoulda implementation. It basically replaces the shell of [shoulda-context](https://github.com/thoughtbot/shoulda-context) in a few lines of code. 178 | 179 | ```ruby 180 | class PostTests < ActiveSupport::TestCase 181 | setup { @post = Post.create! :title => 'Test Title', :body => 'Test body' } 182 | teardown { Post.delete_all } 183 | should 'work' do 184 | @post.must_be_instance_of Post 185 | end 186 | context 'with a user' do 187 | should_eventually 'have a user' do 188 | # ... 189 | end 190 | end 191 | end 192 | ``` 193 | 194 | If you prefer the assertions provided by shoulda-context like `assert_same_elements`, then you may want to consider copying them [from here](https://github.com/thoughtbot/shoulda-context/blob/master/lib/shoulda/context/assertions.rb) and including them in `Minitest::Spec` yourself. I personally recommend just replacing these assertions with something more modern. A few examples are below. 195 | 196 | ```ruby 197 | assert_same_elements a, b # From 198 | expect(a.sort).must_equal b.sort # To 199 | 200 | assert_does_not_contain a, b # From 201 | expect(a).wont_include b # To 202 | ``` 203 | 204 | ### Matchers 205 | 206 | **I highly suggest that you stay away from matchers** since Minitest::Spec gives you all the tools you need to write good tests. Staying away from matchers will make your code's tests live longer. So my advice is to stay away from things like `.should ==` and just write `.must_equal` instead. However, if matchers are really your thing, I recommend the [minitest-matchers](https://github.com/wojtekmach/minitest-matchers) gem. You can also check out the [valid_attribute](https://github.com/bcardarella/valid_attribute) gem built on top of minitest-matchers. 207 | 208 | ```ruby 209 | describe Post do 210 | subject { Post.new } 211 | it { must have_valid(:title).when("Hello") } 212 | it { wont have_valid(:title).when("", nil, "Bad") } 213 | end 214 | ``` 215 | 216 | Alternatively, try the [mintest-matchers_vaccine](https://github.com/rmm5t/minitest-matchers_vaccine) gem to avoid _infecting_ the objects that you want to test. 217 | 218 | ```ruby 219 | describe User do 220 | subject { User.new } 221 | it "should validate email" do 222 | must have_valid(:email).when("a@a.com", "foo@bar.com") 223 | wont have_valid(:email).when(nil, "", "foo", "foo@bar") 224 | end 225 | end 226 | ``` 227 | 228 | ## Gotchas 229 | 230 | ### Assertion Methods 231 | 232 | If you are upgrading from Test::Unit, there are a few missing assertions that have been renamed or are no longer available within Minitest. 233 | 234 | * The method `assert_raise` is renamed `assert_raises`. 235 | * There is no method `assert_nothing_raised`. There are good reasons for this on [Ryan's blog entry](http://blog.zenspider.com/blog/2012/01/assert_nothing_tested.html). 236 | 237 | ### Mocha 238 | 239 | If you are using [Mocha](https://github.com/freerange/mocha) for mocking and stubbing, please update to the latest, 0.13.1 or higher so it is compatible with the latest Minitest. If you do not like the deprecation warnings in older versions of Rails, just add this below the `require 'rails/all'` within your `application.rb` file :) 240 | 241 | ```ruby 242 | require 'mocha/deprecation' 243 | Mocha::Deprecation.mode = :disabled 244 | ``` 245 | 246 | ### Rails 3.0.x 247 | 248 | If you are using minitest-spec-rails with Rails 3.0, then your controller and mailer tests will need to use the `tests` interface for the assertions to be setup correctly within sub `describe` blocks. I think this is a bug with `class_attribute` within Rails 3.0 only. So use the following patterns. 249 | 250 | ```ruby 251 | class UsersControllerTest < ActionController::TestCase 252 | tests UsersController 253 | end 254 | class UserMailerTest < ActionMailer::TestCase 255 | tests UserMailer 256 | end 257 | ``` 258 | 259 | ### Rails 3.1 & 3.2 260 | 261 | If your view helper tests give you an eror like this: `RuntimeError: In order to use #url_for, you must include routing helpers explicitly.`, this is something that is broken only for Rails 3.1 and 3.2, both 3.0 and 4.0 and above do not exhibit this error. I have heard that if you `include Rails.application.routes.url_helpers` in your tests or inject them into the helper module before the test it may work. Lemme know what you find out. 262 | 263 | 264 | ## Contributing 265 | 266 | We run our tests on GitHub Actions. If you detect a problem, open up a github issue or fork the repo and help out. After you fork or clone the repository, the following commands will get you up and running on the test suite. 267 | 268 | ```shell 269 | $ bundle install 270 | $ bundle exec appraisal update 271 | $ bundle exec appraisal rake test 272 | ``` 273 | 274 | We use the [appraisal](https://github.com/thoughtbot/appraisal) gem from Thoughtbot to help us generate the individual gemfiles for each Rails version and to run the tests locally against each generated Gemfile. The `rake appraisal test` command actually runs our test suite against all Rails versions in our `Appraisal` file. If you want to run the tests for a specific Rails version, use `bundle exec appraisal -h` for a list. For example, the following command will run the tests for Rails 4.1 only. 275 | 276 | ```shell 277 | $ bundle exec appraisal rails_v6.0.x rake test 278 | $ bundle exec appraisal rails_v6.1.x rake test 279 | $ bundle exec appraisal rails_v7.0.x rake test 280 | ``` 281 | 282 | We have a few branches for each major Rails version. 283 | 284 | * [2-3-stable](https://github.com/metaskills/minitest-spec-rails/tree/2-3-stable) - Tracks Rails 2.3.x with MiniTest 4.x. 285 | * [3-x-stable](https://github.com/metaskills/minitest-spec-rails/tree/3-x-stable) - Oddly tracks Rails 3.x and 4.0 with MiniTest 4.x. 286 | * master - Currently tracks Rails 4.1 which uses Minitest 5.0. 287 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rake/testtask' 3 | 4 | Rake::TestTask.new do |t| 5 | t.libs = %w[lib test] 6 | t.test_files = Dir.glob('test/**/*_test.rb').sort 7 | t.verbose = false 8 | t.warning = false 9 | end 10 | 11 | task default: :test 12 | -------------------------------------------------------------------------------- /gemfiles/rails_v6.0.x.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails", "~> 6.0.0" 6 | gem "minitest" 7 | 8 | gemspec path: "../" 9 | -------------------------------------------------------------------------------- /gemfiles/rails_v6.0.x.gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: .. 3 | specs: 4 | minitest-spec-rails (7.4.1) 5 | minitest (>= 5.0) 6 | railties (>= 4.1) 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | actioncable (6.0.6.1) 12 | actionpack (= 6.0.6.1) 13 | nio4r (~> 2.0) 14 | websocket-driver (>= 0.6.1) 15 | actionmailbox (6.0.6.1) 16 | actionpack (= 6.0.6.1) 17 | activejob (= 6.0.6.1) 18 | activerecord (= 6.0.6.1) 19 | activestorage (= 6.0.6.1) 20 | activesupport (= 6.0.6.1) 21 | mail (>= 2.7.1) 22 | actionmailer (6.0.6.1) 23 | actionpack (= 6.0.6.1) 24 | actionview (= 6.0.6.1) 25 | activejob (= 6.0.6.1) 26 | mail (~> 2.5, >= 2.5.4) 27 | rails-dom-testing (~> 2.0) 28 | actionpack (6.0.6.1) 29 | actionview (= 6.0.6.1) 30 | activesupport (= 6.0.6.1) 31 | rack (~> 2.0, >= 2.0.8) 32 | rack-test (>= 0.6.3) 33 | rails-dom-testing (~> 2.0) 34 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 35 | actiontext (6.0.6.1) 36 | actionpack (= 6.0.6.1) 37 | activerecord (= 6.0.6.1) 38 | activestorage (= 6.0.6.1) 39 | activesupport (= 6.0.6.1) 40 | nokogiri (>= 1.8.5) 41 | actionview (6.0.6.1) 42 | activesupport (= 6.0.6.1) 43 | builder (~> 3.1) 44 | erubi (~> 1.4) 45 | rails-dom-testing (~> 2.0) 46 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 47 | activejob (6.0.6.1) 48 | activesupport (= 6.0.6.1) 49 | globalid (>= 0.3.6) 50 | activemodel (6.0.6.1) 51 | activesupport (= 6.0.6.1) 52 | activerecord (6.0.6.1) 53 | activemodel (= 6.0.6.1) 54 | activesupport (= 6.0.6.1) 55 | activestorage (6.0.6.1) 56 | actionpack (= 6.0.6.1) 57 | activejob (= 6.0.6.1) 58 | activerecord (= 6.0.6.1) 59 | marcel (~> 1.0) 60 | activesupport (6.0.6.1) 61 | concurrent-ruby (~> 1.0, >= 1.0.2) 62 | i18n (>= 0.7, < 2) 63 | minitest (~> 5.1) 64 | tzinfo (~> 1.1) 65 | zeitwerk (~> 2.2, >= 2.2.2) 66 | appraisal (2.4.1) 67 | bundler 68 | rake 69 | thor (>= 0.14.0) 70 | builder (3.2.4) 71 | coderay (1.1.3) 72 | concurrent-ruby (1.2.2) 73 | crass (1.0.6) 74 | date (3.3.3) 75 | erubi (1.12.0) 76 | globalid (1.1.0) 77 | activesupport (>= 5.0) 78 | i18n (1.13.0) 79 | concurrent-ruby (~> 1.0) 80 | loofah (2.21.3) 81 | crass (~> 1.0.2) 82 | nokogiri (>= 1.12.0) 83 | mail (2.8.1) 84 | mini_mime (>= 0.1.1) 85 | net-imap 86 | net-pop 87 | net-smtp 88 | marcel (1.0.2) 89 | method_source (1.0.0) 90 | mini_mime (1.1.2) 91 | minitest (5.18.0) 92 | minitest-focus (1.3.1) 93 | minitest (>= 4, < 6) 94 | net-imap (0.3.4) 95 | date 96 | net-protocol 97 | net-pop (0.1.2) 98 | net-protocol 99 | net-protocol (0.2.1) 100 | timeout 101 | net-smtp (0.3.3) 102 | net-protocol 103 | nio4r (2.5.9) 104 | nokogiri (1.15.1-arm64-darwin) 105 | racc (~> 1.4) 106 | pry (0.14.2) 107 | coderay (~> 1.1) 108 | method_source (~> 1.0) 109 | racc (1.6.2) 110 | rack (2.2.7) 111 | rack-test (2.1.0) 112 | rack (>= 1.3) 113 | rails (6.0.6.1) 114 | actioncable (= 6.0.6.1) 115 | actionmailbox (= 6.0.6.1) 116 | actionmailer (= 6.0.6.1) 117 | actionpack (= 6.0.6.1) 118 | actiontext (= 6.0.6.1) 119 | actionview (= 6.0.6.1) 120 | activejob (= 6.0.6.1) 121 | activemodel (= 6.0.6.1) 122 | activerecord (= 6.0.6.1) 123 | activestorage (= 6.0.6.1) 124 | activesupport (= 6.0.6.1) 125 | bundler (>= 1.3.0) 126 | railties (= 6.0.6.1) 127 | sprockets-rails (>= 2.0.0) 128 | rails-dom-testing (2.0.3) 129 | activesupport (>= 4.2.0) 130 | nokogiri (>= 1.6) 131 | rails-html-sanitizer (1.5.0) 132 | loofah (~> 2.19, >= 2.19.1) 133 | railties (6.0.6.1) 134 | actionpack (= 6.0.6.1) 135 | activesupport (= 6.0.6.1) 136 | method_source 137 | rake (>= 0.8.7) 138 | thor (>= 0.20.3, < 2.0) 139 | rake (13.0.6) 140 | sprockets (4.2.0) 141 | concurrent-ruby (~> 1.0) 142 | rack (>= 2.2.4, < 4) 143 | sprockets-rails (3.4.2) 144 | actionpack (>= 5.2) 145 | activesupport (>= 5.2) 146 | sprockets (>= 3.0.0) 147 | sqlite3 (1.6.3-arm64-darwin) 148 | thor (1.2.2) 149 | thread_safe (0.3.6) 150 | timeout (0.3.2) 151 | tzinfo (1.2.11) 152 | thread_safe (~> 0.1) 153 | websocket-driver (0.7.5) 154 | websocket-extensions (>= 0.1.0) 155 | websocket-extensions (0.1.5) 156 | zeitwerk (2.6.8) 157 | 158 | PLATFORMS 159 | arm64-darwin-22 160 | arm64-darwin-23 161 | 162 | DEPENDENCIES 163 | appraisal 164 | minitest 165 | minitest-focus 166 | minitest-spec-rails! 167 | pry 168 | rails (~> 6.0.0) 169 | rake 170 | sqlite3 171 | 172 | BUNDLED WITH 173 | 2.4.12 174 | -------------------------------------------------------------------------------- /gemfiles/rails_v6.1.x.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails", "~> 6.1.0" 6 | gem "minitest" 7 | 8 | gemspec path: "../" 9 | -------------------------------------------------------------------------------- /gemfiles/rails_v6.1.x.gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: .. 3 | specs: 4 | minitest-spec-rails (7.4.1) 5 | minitest (>= 5.0) 6 | railties (>= 4.1) 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | actioncable (6.1.7.3) 12 | actionpack (= 6.1.7.3) 13 | activesupport (= 6.1.7.3) 14 | nio4r (~> 2.0) 15 | websocket-driver (>= 0.6.1) 16 | actionmailbox (6.1.7.3) 17 | actionpack (= 6.1.7.3) 18 | activejob (= 6.1.7.3) 19 | activerecord (= 6.1.7.3) 20 | activestorage (= 6.1.7.3) 21 | activesupport (= 6.1.7.3) 22 | mail (>= 2.7.1) 23 | actionmailer (6.1.7.3) 24 | actionpack (= 6.1.7.3) 25 | actionview (= 6.1.7.3) 26 | activejob (= 6.1.7.3) 27 | activesupport (= 6.1.7.3) 28 | mail (~> 2.5, >= 2.5.4) 29 | rails-dom-testing (~> 2.0) 30 | actionpack (6.1.7.3) 31 | actionview (= 6.1.7.3) 32 | activesupport (= 6.1.7.3) 33 | rack (~> 2.0, >= 2.0.9) 34 | rack-test (>= 0.6.3) 35 | rails-dom-testing (~> 2.0) 36 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 37 | actiontext (6.1.7.3) 38 | actionpack (= 6.1.7.3) 39 | activerecord (= 6.1.7.3) 40 | activestorage (= 6.1.7.3) 41 | activesupport (= 6.1.7.3) 42 | nokogiri (>= 1.8.5) 43 | actionview (6.1.7.3) 44 | activesupport (= 6.1.7.3) 45 | builder (~> 3.1) 46 | erubi (~> 1.4) 47 | rails-dom-testing (~> 2.0) 48 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 49 | activejob (6.1.7.3) 50 | activesupport (= 6.1.7.3) 51 | globalid (>= 0.3.6) 52 | activemodel (6.1.7.3) 53 | activesupport (= 6.1.7.3) 54 | activerecord (6.1.7.3) 55 | activemodel (= 6.1.7.3) 56 | activesupport (= 6.1.7.3) 57 | activestorage (6.1.7.3) 58 | actionpack (= 6.1.7.3) 59 | activejob (= 6.1.7.3) 60 | activerecord (= 6.1.7.3) 61 | activesupport (= 6.1.7.3) 62 | marcel (~> 1.0) 63 | mini_mime (>= 1.1.0) 64 | activesupport (6.1.7.3) 65 | concurrent-ruby (~> 1.0, >= 1.0.2) 66 | i18n (>= 1.6, < 2) 67 | minitest (>= 5.1) 68 | tzinfo (~> 2.0) 69 | zeitwerk (~> 2.3) 70 | appraisal (2.4.1) 71 | bundler 72 | rake 73 | thor (>= 0.14.0) 74 | builder (3.2.4) 75 | coderay (1.1.3) 76 | concurrent-ruby (1.2.2) 77 | crass (1.0.6) 78 | date (3.3.3) 79 | erubi (1.12.0) 80 | globalid (1.1.0) 81 | activesupport (>= 5.0) 82 | i18n (1.13.0) 83 | concurrent-ruby (~> 1.0) 84 | loofah (2.21.3) 85 | crass (~> 1.0.2) 86 | nokogiri (>= 1.12.0) 87 | mail (2.8.1) 88 | mini_mime (>= 0.1.1) 89 | net-imap 90 | net-pop 91 | net-smtp 92 | marcel (1.0.2) 93 | method_source (1.0.0) 94 | mini_mime (1.1.2) 95 | minitest (5.18.0) 96 | minitest-focus (1.3.1) 97 | minitest (>= 4, < 6) 98 | net-imap (0.3.4) 99 | date 100 | net-protocol 101 | net-pop (0.1.2) 102 | net-protocol 103 | net-protocol (0.2.1) 104 | timeout 105 | net-smtp (0.3.3) 106 | net-protocol 107 | nio4r (2.5.9) 108 | nokogiri (1.15.1-arm64-darwin) 109 | racc (~> 1.4) 110 | pry (0.14.2) 111 | coderay (~> 1.1) 112 | method_source (~> 1.0) 113 | racc (1.6.2) 114 | rack (2.2.7) 115 | rack-test (2.1.0) 116 | rack (>= 1.3) 117 | rails (6.1.7.3) 118 | actioncable (= 6.1.7.3) 119 | actionmailbox (= 6.1.7.3) 120 | actionmailer (= 6.1.7.3) 121 | actionpack (= 6.1.7.3) 122 | actiontext (= 6.1.7.3) 123 | actionview (= 6.1.7.3) 124 | activejob (= 6.1.7.3) 125 | activemodel (= 6.1.7.3) 126 | activerecord (= 6.1.7.3) 127 | activestorage (= 6.1.7.3) 128 | activesupport (= 6.1.7.3) 129 | bundler (>= 1.15.0) 130 | railties (= 6.1.7.3) 131 | sprockets-rails (>= 2.0.0) 132 | rails-dom-testing (2.0.3) 133 | activesupport (>= 4.2.0) 134 | nokogiri (>= 1.6) 135 | rails-html-sanitizer (1.5.0) 136 | loofah (~> 2.19, >= 2.19.1) 137 | railties (6.1.7.3) 138 | actionpack (= 6.1.7.3) 139 | activesupport (= 6.1.7.3) 140 | method_source 141 | rake (>= 12.2) 142 | thor (~> 1.0) 143 | rake (13.0.6) 144 | sprockets (4.2.0) 145 | concurrent-ruby (~> 1.0) 146 | rack (>= 2.2.4, < 4) 147 | sprockets-rails (3.4.2) 148 | actionpack (>= 5.2) 149 | activesupport (>= 5.2) 150 | sprockets (>= 3.0.0) 151 | sqlite3 (1.6.3-arm64-darwin) 152 | thor (1.2.2) 153 | timeout (0.3.2) 154 | tzinfo (2.0.6) 155 | concurrent-ruby (~> 1.0) 156 | websocket-driver (0.7.5) 157 | websocket-extensions (>= 0.1.0) 158 | websocket-extensions (0.1.5) 159 | zeitwerk (2.6.8) 160 | 161 | PLATFORMS 162 | arm64-darwin-22 163 | arm64-darwin-23 164 | 165 | DEPENDENCIES 166 | appraisal 167 | minitest 168 | minitest-focus 169 | minitest-spec-rails! 170 | pry 171 | rails (~> 6.1.0) 172 | rake 173 | sqlite3 174 | 175 | BUNDLED WITH 176 | 2.4.12 177 | -------------------------------------------------------------------------------- /gemfiles/rails_v7.0.x.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails", "~> 7.0.0" 6 | gem "minitest" 7 | 8 | gemspec path: "../" 9 | -------------------------------------------------------------------------------- /gemfiles/rails_v7.0.x.gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: .. 3 | specs: 4 | minitest-spec-rails (7.4.1) 5 | minitest (>= 5.0) 6 | railties (>= 4.1) 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | actioncable (7.0.4.3) 12 | actionpack (= 7.0.4.3) 13 | activesupport (= 7.0.4.3) 14 | nio4r (~> 2.0) 15 | websocket-driver (>= 0.6.1) 16 | actionmailbox (7.0.4.3) 17 | actionpack (= 7.0.4.3) 18 | activejob (= 7.0.4.3) 19 | activerecord (= 7.0.4.3) 20 | activestorage (= 7.0.4.3) 21 | activesupport (= 7.0.4.3) 22 | mail (>= 2.7.1) 23 | net-imap 24 | net-pop 25 | net-smtp 26 | actionmailer (7.0.4.3) 27 | actionpack (= 7.0.4.3) 28 | actionview (= 7.0.4.3) 29 | activejob (= 7.0.4.3) 30 | activesupport (= 7.0.4.3) 31 | mail (~> 2.5, >= 2.5.4) 32 | net-imap 33 | net-pop 34 | net-smtp 35 | rails-dom-testing (~> 2.0) 36 | actionpack (7.0.4.3) 37 | actionview (= 7.0.4.3) 38 | activesupport (= 7.0.4.3) 39 | rack (~> 2.0, >= 2.2.0) 40 | rack-test (>= 0.6.3) 41 | rails-dom-testing (~> 2.0) 42 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 43 | actiontext (7.0.4.3) 44 | actionpack (= 7.0.4.3) 45 | activerecord (= 7.0.4.3) 46 | activestorage (= 7.0.4.3) 47 | activesupport (= 7.0.4.3) 48 | globalid (>= 0.6.0) 49 | nokogiri (>= 1.8.5) 50 | actionview (7.0.4.3) 51 | activesupport (= 7.0.4.3) 52 | builder (~> 3.1) 53 | erubi (~> 1.4) 54 | rails-dom-testing (~> 2.0) 55 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 56 | activejob (7.0.4.3) 57 | activesupport (= 7.0.4.3) 58 | globalid (>= 0.3.6) 59 | activemodel (7.0.4.3) 60 | activesupport (= 7.0.4.3) 61 | activerecord (7.0.4.3) 62 | activemodel (= 7.0.4.3) 63 | activesupport (= 7.0.4.3) 64 | activestorage (7.0.4.3) 65 | actionpack (= 7.0.4.3) 66 | activejob (= 7.0.4.3) 67 | activerecord (= 7.0.4.3) 68 | activesupport (= 7.0.4.3) 69 | marcel (~> 1.0) 70 | mini_mime (>= 1.1.0) 71 | activesupport (7.0.4.3) 72 | concurrent-ruby (~> 1.0, >= 1.0.2) 73 | i18n (>= 1.6, < 2) 74 | minitest (>= 5.1) 75 | tzinfo (~> 2.0) 76 | appraisal (2.4.1) 77 | bundler 78 | rake 79 | thor (>= 0.14.0) 80 | builder (3.2.4) 81 | coderay (1.1.3) 82 | concurrent-ruby (1.2.2) 83 | crass (1.0.6) 84 | date (3.3.3) 85 | erubi (1.12.0) 86 | globalid (1.1.0) 87 | activesupport (>= 5.0) 88 | i18n (1.13.0) 89 | concurrent-ruby (~> 1.0) 90 | loofah (2.21.3) 91 | crass (~> 1.0.2) 92 | nokogiri (>= 1.12.0) 93 | mail (2.8.1) 94 | mini_mime (>= 0.1.1) 95 | net-imap 96 | net-pop 97 | net-smtp 98 | marcel (1.0.2) 99 | method_source (1.0.0) 100 | mini_mime (1.1.2) 101 | minitest (5.18.0) 102 | minitest-focus (1.3.1) 103 | minitest (>= 4, < 6) 104 | net-imap (0.3.4) 105 | date 106 | net-protocol 107 | net-pop (0.1.2) 108 | net-protocol 109 | net-protocol (0.2.1) 110 | timeout 111 | net-smtp (0.3.3) 112 | net-protocol 113 | nio4r (2.5.9) 114 | nokogiri (1.15.1-arm64-darwin) 115 | racc (~> 1.4) 116 | pry (0.14.2) 117 | coderay (~> 1.1) 118 | method_source (~> 1.0) 119 | racc (1.6.2) 120 | rack (2.2.7) 121 | rack-test (2.1.0) 122 | rack (>= 1.3) 123 | rails (7.0.4.3) 124 | actioncable (= 7.0.4.3) 125 | actionmailbox (= 7.0.4.3) 126 | actionmailer (= 7.0.4.3) 127 | actionpack (= 7.0.4.3) 128 | actiontext (= 7.0.4.3) 129 | actionview (= 7.0.4.3) 130 | activejob (= 7.0.4.3) 131 | activemodel (= 7.0.4.3) 132 | activerecord (= 7.0.4.3) 133 | activestorage (= 7.0.4.3) 134 | activesupport (= 7.0.4.3) 135 | bundler (>= 1.15.0) 136 | railties (= 7.0.4.3) 137 | rails-dom-testing (2.0.3) 138 | activesupport (>= 4.2.0) 139 | nokogiri (>= 1.6) 140 | rails-html-sanitizer (1.5.0) 141 | loofah (~> 2.19, >= 2.19.1) 142 | railties (7.0.4.3) 143 | actionpack (= 7.0.4.3) 144 | activesupport (= 7.0.4.3) 145 | method_source 146 | rake (>= 12.2) 147 | thor (~> 1.0) 148 | zeitwerk (~> 2.5) 149 | rake (13.0.6) 150 | sqlite3 (1.6.3-arm64-darwin) 151 | thor (1.2.2) 152 | timeout (0.3.2) 153 | tzinfo (2.0.6) 154 | concurrent-ruby (~> 1.0) 155 | websocket-driver (0.7.5) 156 | websocket-extensions (>= 0.1.0) 157 | websocket-extensions (0.1.5) 158 | zeitwerk (2.6.8) 159 | 160 | PLATFORMS 161 | arm64-darwin-22 162 | arm64-darwin-23 163 | 164 | DEPENDENCIES 165 | appraisal 166 | minitest 167 | minitest-focus 168 | minitest-spec-rails! 169 | pry 170 | rails (~> 7.0.0) 171 | rake 172 | sqlite3 173 | 174 | BUNDLED WITH 175 | 2.4.12 176 | -------------------------------------------------------------------------------- /gemfiles/rails_v7.1.x.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails", "~> 7.1.0" 6 | gem "minitest" 7 | gem "view_component", require: "view_component/engine" 8 | 9 | gemspec path: "../" 10 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | end 3 | 4 | require 'rails' 5 | gem 'minitest' 6 | require 'minitest' 7 | require 'minitest/spec' 8 | require 'minitest-spec-rails/version' 9 | require 'minitest-spec-rails/dsl' 10 | require 'minitest-spec-rails/railtie' 11 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/dsl.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module DSL 3 | def self.included(klass) 4 | klass.extend ClassMethods 5 | remove_method :test if method_defined?(:test) 6 | end 7 | 8 | module ClassMethods 9 | def describe(*args, &block) 10 | stack = Minitest::Spec.describe_stack 11 | stack.push self if stack.empty? 12 | super(*args) { class_eval(&block) } 13 | stack.pop if stack.length == 1 14 | end 15 | 16 | def before(_type = nil, &block) 17 | setup { instance_eval(&block) } 18 | end 19 | 20 | def after(_type = nil, &block) 21 | teardown { instance_eval(&block) } 22 | end 23 | 24 | def test(name, &block) 25 | instance_eval { it(name, &block) } 26 | end 27 | 28 | def described_class 29 | nil 30 | end 31 | end 32 | 33 | def described_class 34 | self.class.described_class 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/init/action_cable.rb: -------------------------------------------------------------------------------- 1 | unless defined?(ActionCable::Channel) 2 | require 'action_cable/channel' 3 | end 4 | 5 | if Rails::VERSION::MAJOR >= 6 6 | require 'action_cable/channel/test_case' 7 | 8 | module MiniTestSpecRails 9 | module Init 10 | module ActionCableBehavior 11 | extend ActiveSupport::Concern 12 | 13 | included do 14 | class_attribute :_helper_class 15 | register_spec_type(/(Channel)( ?Test)?\z/, self) 16 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < self } 17 | extend Descriptions 18 | end 19 | 20 | module Descriptions 21 | def described_class 22 | determine_default_helper_class(name) 23 | end 24 | end 25 | end 26 | end 27 | end 28 | 29 | ActionCable::Channel::TestCase.include MiniTestSpecRails::Init::ActionCableBehavior 30 | end 31 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/init/action_controller.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module Init 3 | module ActionControllerBehavior 4 | extend ActiveSupport::Concern 5 | 6 | included do 7 | extend Descriptions 8 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < ActionController::Metal } 9 | register_spec_type(/Controller( ?Test)?\z/, self) 10 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < self } 11 | end 12 | 13 | module Descriptions 14 | def described_class 15 | determine_default_controller_class(name) 16 | end 17 | end 18 | end 19 | end 20 | end 21 | 22 | ActionController::TestCase.send :include, MiniTestSpecRails::Init::ActionControllerBehavior 23 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/init/action_dispatch.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module Init 3 | module ActionDispatchBehavior 4 | extend ActiveSupport::Concern 5 | 6 | included do 7 | register_spec_type(/(Acceptance|Integration) ?Test\z/, self) 8 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < self } 9 | end 10 | end 11 | end 12 | end 13 | 14 | ActionDispatch::IntegrationTest.send :include, MiniTestSpecRails::Init::ActionDispatchBehavior 15 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/init/action_mailer.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module Init 3 | module ActionMailerBehavior 4 | extend ActiveSupport::Concern 5 | 6 | included do 7 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < ActionMailer::Base } 8 | register_spec_type(/Mailer( ?Test)?\z/, self) 9 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < self } 10 | extend Descriptions 11 | end 12 | 13 | module Descriptions 14 | def described_class 15 | determine_default_mailer(name) 16 | end 17 | end 18 | end 19 | end 20 | end 21 | 22 | ActionMailer::TestCase.send :include, MiniTestSpecRails::Init::ActionMailerBehavior 23 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/init/action_view.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module Init 3 | module ActionViewBehavior 4 | extend ActiveSupport::Concern 5 | 6 | included do 7 | class_attribute :_helper_class 8 | register_spec_type(/(Helper|View)( ?Test)?\z/, self) 9 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < self } 10 | extend Descriptions 11 | end 12 | 13 | module Descriptions 14 | def described_class 15 | determine_default_helper_class(name) 16 | end 17 | end 18 | end 19 | end 20 | end 21 | 22 | ActionView::TestCase.send :include, MiniTestSpecRails::Init::ActionViewBehavior 23 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/init/active_job.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module Init 3 | module ActiveJobBehavior 4 | extend ActiveSupport::Concern 5 | 6 | included do 7 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < ActiveJob::Base } 8 | register_spec_type(/Job( ?Test)?\z/, self) 9 | register_spec_type(self) { |desc| desc.is_a?(Class) && desc < self } 10 | extend Descriptions 11 | end 12 | 13 | module Descriptions 14 | def described_class 15 | determine_constant_from_test_name(name) do |constant| 16 | constant.is_a?(Class) && constant < ActiveJob::Base 17 | end 18 | end 19 | end 20 | end 21 | end 22 | end 23 | 24 | ActiveJob::TestCase.send :include, MiniTestSpecRails::Init::ActiveJobBehavior 25 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/init/active_support.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module Init 3 | module ActiveSupportBehavior 4 | extend ActiveSupport::Concern 5 | 6 | included do 7 | extend Minitest::Spec::DSL 8 | include MiniTestSpecRails::DSL 9 | include ActiveSupport::Testing::ConstantLookup 10 | extend Descriptions 11 | register_spec_type(self) { |_desc| true } 12 | end 13 | 14 | module Descriptions 15 | def described_class 16 | determine_constant_from_test_name(name) do |constant| 17 | constant.is_a?(Class) 18 | end 19 | end 20 | end 21 | 22 | if Minitest::VERSION < '5.3.3' 23 | def initialize(*args) 24 | Thread.current[:current_spec] = self 25 | super 26 | end 27 | end 28 | end 29 | end 30 | end 31 | 32 | ActiveSupport::TestCase.send :include, MiniTestSpecRails::Init::ActiveSupportBehavior 33 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/init/mini_shoulda.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module Init 3 | module MiniShouldaBehavior 4 | extend ActiveSupport::Concern 5 | 6 | included do 7 | class << self 8 | alias_method :context, :describe 9 | alias_method :should, :it 10 | end 11 | extend ClassMethods 12 | end 13 | 14 | module ClassMethods 15 | def should_eventually(desc) 16 | it("should eventually #{desc}") { skip("Should eventually #{desc}") } 17 | end 18 | end 19 | end 20 | end 21 | end 22 | 23 | ActiveSupport::TestCase.send :include, MiniTestSpecRails::Init::MiniShouldaBehavior 24 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/parallelize.rb: -------------------------------------------------------------------------------- 1 | 2 | # HACK: stolen and altered from https://github.com/blowmage/minitest-rails/pull/218/files 3 | # Which was referenced in https://github.com/metaskills/minitest-spec-rails/issues/94 4 | 5 | module MiniTestSpecRails 6 | ## 7 | # This module is a placeholder for all the Test classes created using the 8 | # spec DSL. Normally all classes are created but not assigned to a constant. 9 | # This module is where constants will be created for these classes. 10 | module SpecTests #:nodoc: 11 | end 12 | end 13 | 14 | module Kernel #:nodoc: 15 | alias describe_before_minitest_spec_constant_fix describe 16 | private :describe_before_minitest_spec_constant_fix 17 | def describe *args, &block 18 | cls = describe_before_minitest_spec_constant_fix(*args, &block) 19 | cls_const = "Test__#{cls.name.to_s.split(/\W/).reject(&:empty?).join('_'.freeze)}" 20 | if block.source_location 21 | source_path, line_num = block.source_location 22 | source_path = Pathname.new(File.expand_path(source_path)).relative_path_from(Rails.root).to_s 23 | source_path = source_path.split(/\W/).reject(&:empty?).join("_".freeze) 24 | cls_const += "__#{source_path}__#{line_num}" 25 | end 26 | cls_const += "_1" while MiniTestSpecRails::SpecTests.const_defined? cls_const 27 | MiniTestSpecRails::SpecTests.const_set cls_const, cls 28 | cls 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/railtie.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | class Railtie < ::Rails::Railtie 3 | config.minitest_spec_rails = ActiveSupport::OrderedOptions.new 4 | config.minitest_spec_rails.mini_shoulda = false 5 | 6 | config.before_initialize do |_app| 7 | require 'active_support' 8 | require 'minitest-spec-rails/init/active_support' 9 | require 'minitest-spec-rails/parallelize' 10 | ActiveSupport.on_load(:action_cable) do 11 | require 'minitest-spec-rails/init/action_cable' 12 | end 13 | ActiveSupport.on_load(:action_controller) do 14 | require 'minitest-spec-rails/init/action_controller' 15 | require 'minitest-spec-rails/init/action_dispatch' 16 | end 17 | ActiveSupport.on_load(:action_mailer) do 18 | require 'minitest-spec-rails/init/action_mailer' 19 | end 20 | ActiveSupport.on_load(:active_job) do 21 | require 'minitest-spec-rails/init/active_job' 22 | end 23 | end 24 | 25 | initializer 'minitest-spec-rails.action_view', after: 'action_view.setup_action_pack', group: :all do |_app| 26 | Rails.application.config.to_prepare do 27 | ActiveSupport.on_load(:action_view) do 28 | require 'minitest-spec-rails/init/action_view' 29 | end 30 | end 31 | end 32 | 33 | initializer 'minitest-spec-rails.mini_shoulda', group: :all do |app| 34 | require 'minitest-spec-rails/init/mini_shoulda' if app.config.minitest_spec_rails.mini_shoulda 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/minitest-spec-rails/version.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | VERSION = '7.4.1'.freeze 3 | end 4 | -------------------------------------------------------------------------------- /minitest-spec-rails.gemspec: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.push File.expand_path('lib', __dir__) 2 | require 'minitest-spec-rails/version' 3 | 4 | Gem::Specification.new do |gem| 5 | gem.name = 'minitest-spec-rails' 6 | gem.version = MiniTestSpecRails::VERSION 7 | gem.platform = Gem::Platform::RUBY 8 | gem.authors = ['Ken Collins'] 9 | gem.email = ['ken@metaskills.net'] 10 | gem.homepage = 'http://github.com/metaskills/minitest-spec-rails' 11 | gem.summary = 'Make Rails Use Minitest::Spec!' 12 | gem.description = 'The minitest-spec-rails gem makes it easy to use the \ 13 | Minitest::Spec DSL within your existing Rails test suite.' 14 | gem.license = 'MIT' 15 | gem.files = `git ls-files`.split("\n") 16 | gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 17 | gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } 18 | gem.require_paths = ['lib'] 19 | gem.add_runtime_dependency 'minitest', '>= 5.0' 20 | gem.add_runtime_dependency 'railties', '>= 4.1' 21 | gem.add_development_dependency 'appraisal' 22 | gem.add_development_dependency 'minitest-focus' 23 | gem.add_development_dependency 'pry' 24 | gem.add_development_dependency 'rake' 25 | gem.add_development_dependency 'sqlite3' 26 | end 27 | -------------------------------------------------------------------------------- /test/cases/action_cable_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ModelsChannel < ApplicationCable::Channel; end 4 | 5 | class ActionCableChannelTest < MiniTestSpecRails::TestCase 6 | it 'matches spec type for class constants' do 7 | assert_channel_test Minitest::Spec.spec_type(ApplicationCable::Channel) 8 | assert_channel_test Minitest::Spec.spec_type(ModelsChannel) 9 | end 10 | 11 | it 'matches spec type for strings' do 12 | assert_channel_test Minitest::Spec.spec_type('WidgetChannel') 13 | assert_channel_test Minitest::Spec.spec_type('WidgetChannelTest') 14 | assert_channel_test Minitest::Spec.spec_type('Widget Channel Test') 15 | # And is case sensitive 16 | refute_channel_test Minitest::Spec.spec_type('widgetcontroller') 17 | refute_channel_test Minitest::Spec.spec_type('widgetcontrollertest') 18 | refute_channel_test Minitest::Spec.spec_type('widget controller test') 19 | end 20 | 21 | it 'wont match spec type for non space characters' do 22 | refute_channel_test Minitest::Spec.spec_type("Widget Channel\tTest") 23 | refute_channel_test Minitest::Spec.spec_type("Widget Channel\rTest") 24 | refute_channel_test Minitest::Spec.spec_type("Widget Channel\nTest") 25 | refute_channel_test Minitest::Spec.spec_type("Widget Channel\fTest") 26 | refute_channel_test Minitest::Spec.spec_type('Widget ChannelXTest') 27 | end 28 | 29 | private 30 | 31 | def assert_channel_test(actual) 32 | assert_equal ActionCable::Channel::TestCase, actual 33 | end 34 | 35 | def refute_channel_test(actual) 36 | refute_equal ActionCable::Channel::TestCase, actual 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /test/cases/action_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ModelsController < ApplicationController; end 4 | 5 | class ActionControllerTest < MiniTestSpecRails::TestCase 6 | it 'matches spec type for class constants' do 7 | assert_controller Minitest::Spec.spec_type(ApplicationController) 8 | assert_controller Minitest::Spec.spec_type(ModelsController) 9 | end 10 | 11 | it 'matches spec type for strings' do 12 | assert_controller Minitest::Spec.spec_type('WidgetController') 13 | assert_controller Minitest::Spec.spec_type('WidgetControllerTest') 14 | assert_controller Minitest::Spec.spec_type('Widget Controller Test') 15 | # And is case sensitive 16 | refute_controller Minitest::Spec.spec_type('widgetcontroller') 17 | refute_controller Minitest::Spec.spec_type('widgetcontrollertest') 18 | refute_controller Minitest::Spec.spec_type('widget controller test') 19 | end 20 | 21 | it 'wont match spec type for non space characters' do 22 | refute_controller Minitest::Spec.spec_type("Widget Controller\tTest") 23 | refute_controller Minitest::Spec.spec_type("Widget Controller\rTest") 24 | refute_controller Minitest::Spec.spec_type("Widget Controller\nTest") 25 | refute_controller Minitest::Spec.spec_type("Widget Controller\fTest") 26 | refute_controller Minitest::Spec.spec_type('Widget ControllerXTest') 27 | end 28 | 29 | private 30 | 31 | def assert_controller(actual) 32 | assert_equal ActionController::TestCase, actual 33 | end 34 | 35 | def refute_controller(actual) 36 | refute_equal ActionController::TestCase, actual 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /test/cases/action_dispatch_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ModelsController < ApplicationController; end 4 | 5 | class ActionControllerTest < MiniTestSpecRails::TestCase 6 | it 'resolves spec type for matching acceptance strings' do 7 | assert_dispatch Minitest::Spec.spec_type('WidgetAcceptanceTest') 8 | assert_dispatch Minitest::Spec.spec_type('Widget Acceptance Test') 9 | # And is case sensitive 10 | refute_dispatch Minitest::Spec.spec_type('widgetacceptancetest') 11 | refute_dispatch Minitest::Spec.spec_type('widget acceptance test') 12 | end 13 | 14 | it 'wont match spec type for space characters in acceptance strings' do 15 | refute_dispatch Minitest::Spec.spec_type("Widget Acceptance\tTest") 16 | refute_dispatch Minitest::Spec.spec_type("Widget Acceptance\rTest") 17 | refute_dispatch Minitest::Spec.spec_type("Widget Acceptance\nTest") 18 | refute_dispatch Minitest::Spec.spec_type("Widget Acceptance\fTest") 19 | refute_dispatch Minitest::Spec.spec_type('Widget AcceptanceXTest') 20 | end 21 | 22 | it 'resolves spec type for matching integration strings' do 23 | assert_dispatch Minitest::Spec.spec_type('WidgetIntegrationTest') 24 | assert_dispatch Minitest::Spec.spec_type('Widget Integration Test') 25 | # And is case sensitive 26 | refute_dispatch Minitest::Spec.spec_type('widgetintegrationtest') 27 | refute_dispatch Minitest::Spec.spec_type('widget integration test') 28 | end 29 | 30 | it 'wont match spec type for space characters in integration strings' do 31 | refute_dispatch Minitest::Spec.spec_type("Widget Integration\tTest") 32 | refute_dispatch Minitest::Spec.spec_type("Widget Integration\rTest") 33 | refute_dispatch Minitest::Spec.spec_type("Widget Integration\nTest") 34 | refute_dispatch Minitest::Spec.spec_type("Widget Integration\fTest") 35 | refute_dispatch Minitest::Spec.spec_type('Widget IntegrationXTest') 36 | end 37 | 38 | private 39 | 40 | def assert_dispatch(actual) 41 | assert_equal ActionDispatch::IntegrationTest, actual 42 | end 43 | 44 | def refute_dispatch(actual) 45 | refute_equal ActionDispatch::IntegrationTest, actual 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /test/cases/action_mailer_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class NotificationMailer < ActionMailer::Base; end 4 | class Notifications < ActionMailer::Base; end 5 | 6 | class ActionMailerTest < MiniTestSpecRails::TestCase 7 | it 'matches spec type for class constants' do 8 | assert_mailer Minitest::Spec.spec_type(NotificationMailer) 9 | assert_mailer Minitest::Spec.spec_type(Notifications) 10 | end 11 | 12 | it 'matches spec type for strings' do 13 | assert_mailer Minitest::Spec.spec_type('WidgetMailer') 14 | assert_mailer Minitest::Spec.spec_type('WidgetMailerTest') 15 | assert_mailer Minitest::Spec.spec_type('Widget Mailer Test') 16 | # And is case sensitive 17 | refute_mailer Minitest::Spec.spec_type('widgetmailer') 18 | refute_mailer Minitest::Spec.spec_type('widgetmailertest') 19 | refute_mailer Minitest::Spec.spec_type('widget mailer test') 20 | end 21 | 22 | it 'wont match spec type for non space characters' do 23 | refute_mailer Minitest::Spec.spec_type("Widget Mailer\tTest") 24 | refute_mailer Minitest::Spec.spec_type("Widget Mailer\rTest") 25 | refute_mailer Minitest::Spec.spec_type("Widget Mailer\nTest") 26 | refute_mailer Minitest::Spec.spec_type("Widget Mailer\fTest") 27 | refute_mailer Minitest::Spec.spec_type('Widget MailerXTest') 28 | end 29 | 30 | private 31 | 32 | def assert_mailer(actual) 33 | assert_equal ActionMailer::TestCase, actual 34 | end 35 | 36 | def refute_mailer(actual) 37 | refute_equal ActionMailer::TestCase, actual 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /test/cases/action_view_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ActionViewTest < MiniTestSpecRails::TestCase 4 | it 'resolves spec type for matching helper strings' do 5 | assert_view Minitest::Spec.spec_type('WidgetHelper') 6 | assert_view Minitest::Spec.spec_type('WidgetHelperTest') 7 | assert_view Minitest::Spec.spec_type('Widget Helper Test') 8 | # And is case sensitive 9 | refute_view Minitest::Spec.spec_type('widgethelper') 10 | refute_view Minitest::Spec.spec_type('widgethelpertest') 11 | refute_view Minitest::Spec.spec_type('widget helper test') 12 | end 13 | 14 | it 'resolves spec type for matching view strings' do 15 | assert_view Minitest::Spec.spec_type('WidgetView') 16 | assert_view Minitest::Spec.spec_type('WidgetViewTest') 17 | assert_view Minitest::Spec.spec_type('Widget View Test') 18 | # And is case sensitive 19 | refute_view Minitest::Spec.spec_type('widgetview') 20 | refute_view Minitest::Spec.spec_type('widgetviewtest') 21 | refute_view Minitest::Spec.spec_type('widget view test') 22 | end 23 | 24 | it 'wont match spec type for non space characters' do 25 | refute_view Minitest::Spec.spec_type("Widget Helper\tTest") 26 | refute_view Minitest::Spec.spec_type("Widget Helper\rTest") 27 | refute_view Minitest::Spec.spec_type("Widget Helper\nTest") 28 | refute_view Minitest::Spec.spec_type("Widget Helper\fTest") 29 | refute_view Minitest::Spec.spec_type('Widget HelperXTest') 30 | end 31 | 32 | private 33 | 34 | def assert_view(actual) 35 | assert_equal ActionView::TestCase, actual 36 | end 37 | 38 | def refute_view(actual) 39 | refute_equal ActionView::TestCase, actual 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /test/cases/active_job_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | if defined?(ActiveJob) 4 | class MyJob < ActiveJob::Base 5 | def perform(_record) 6 | true 7 | end 8 | end 9 | class TrashableCleanupJob < MyJob 10 | end 11 | 12 | class ActiveJobTest < MiniTestSpecRails::TestCase 13 | it 'matches spec type for class constants' do 14 | assert_job Minitest::Spec.spec_type(MyJob) 15 | assert_job Minitest::Spec.spec_type(TrashableCleanupJob) 16 | end 17 | 18 | it 'matches spec type for strings' do 19 | assert_job Minitest::Spec.spec_type('WidgetJob') 20 | assert_job Minitest::Spec.spec_type('WidgetJobTest') 21 | assert_job Minitest::Spec.spec_type('Widget Job Test') 22 | # And is case sensitive 23 | refute_job Minitest::Spec.spec_type('widgetmailer') 24 | refute_job Minitest::Spec.spec_type('widgetmailertest') 25 | refute_job Minitest::Spec.spec_type('widget mailer test') 26 | end 27 | 28 | it 'wont match spec type for non space characters' do 29 | refute_job Minitest::Spec.spec_type("Widget Job\tTest") 30 | refute_job Minitest::Spec.spec_type("Widget Job\rTest") 31 | refute_job Minitest::Spec.spec_type("Widget Job\nTest") 32 | refute_job Minitest::Spec.spec_type("Widget Job\fTest") 33 | refute_job Minitest::Spec.spec_type('Widget JobXTest') 34 | end 35 | 36 | private 37 | 38 | def assert_job(actual) 39 | assert_equal ActiveJob::TestCase, actual 40 | end 41 | 42 | def refute_job(actual) 43 | refute_equal ActiveJob::TestCase, actual 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /test/cases/active_support_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class SomeRandomModel < ActiveRecord::Base; end 4 | 5 | class ActiveSupportTest < MiniTestSpecRails::TestCase 6 | it 'resolves spec type for active record constants' do 7 | assert_support Minitest::Spec.spec_type(SomeRandomModel) 8 | assert_support Minitest::Spec.spec_type(User) 9 | end 10 | 11 | it 'wont resolve spec type for random strings' do 12 | assert_spec Minitest::Spec.spec_type('Unmatched String') 13 | end 14 | 15 | private 16 | 17 | def assert_support(actual) 18 | assert_equal ActiveSupport::TestCase, actual 19 | end 20 | 21 | def assert_spec(actual) 22 | assert_equal ActiveSupport::TestCase, actual 23 | end 24 | end 25 | 26 | class ActiveSupportCallbackTest < ActiveSupport::TestCase 27 | setup :foo 28 | setup :bar 29 | 30 | it 'works' do 31 | expect(@foo).must_equal 'foo' 32 | expect(@bar).must_equal 'bar' 33 | end 34 | 35 | private 36 | 37 | def foo 38 | @foo = 'foo' 39 | end 40 | 41 | def bar 42 | @bar = 'bar' 43 | end 44 | end 45 | 46 | class ActiveSupportSpecTest < ActiveSupport::TestCase 47 | it 'current spec name' do 48 | expect(Thread.current[:current_spec]).must_equal self 49 | end 50 | end 51 | 52 | class ActiveSupportDescribeNamesTest < ActiveSupport::TestCase 53 | it 'class name' do 54 | assert_equal 'ActiveSupportDescribeNamesTest', self.class.name 55 | end 56 | describe 'level1' do 57 | it 'haz name' do 58 | assert_equal 'ActiveSupportDescribeNamesTest::level1', self.class.name 59 | end 60 | describe 'level2' do 61 | it 'haz name' do 62 | assert_equal 'ActiveSupportDescribeNamesTest::level1::level2', self.class.name 63 | end 64 | end 65 | end 66 | end 67 | 68 | class ActiveSupportTestSyntaxTest < ActiveSupport::TestCase 69 | test 'records the correct test method line number' do 70 | method_name = public_methods(false).find do |name| 71 | name.to_s =~ /test.*records the correct test method line number/ 72 | end 73 | method_obj = method(method_name) 74 | 75 | assert_match %r{test\/cases\/active_support_test.rb}, method_obj.source_location[0] 76 | assert_equal 69, method_obj.source_location[1] 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /test/cases/mini_shoulda_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | class PostTests < ActiveSupport::TestCase 4 | i_suck_and_my_tests_are_order_dependent! 5 | 6 | $teardown_ran = false 7 | 8 | setup do 9 | @post = user_post 10 | end 11 | 12 | teardown do 13 | $teardown_ran = true 14 | end 15 | 16 | should 'setup correctly' do 17 | expect(@post).must_be_instance_of Post 18 | end 19 | 20 | should 'teardown correctly' do 21 | expect($teardown_ran).must_equal true 22 | end 23 | 24 | should_eventually 'will be skipped' do 25 | assert false 26 | end 27 | 28 | context 'level 1' do 29 | should 'work' do 30 | expect(@post).must_be_instance_of Post 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /test/dummy_app/app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/dummy_app/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy_app/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy_app/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | def index 3 | render html: '

Rendered Minitest::Spec

'.html_safe, layout: false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy_app/app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | def index 3 | @users = User.all 4 | render layout: false 5 | end 6 | 7 | def update 8 | redirect_to users_url 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/dummy_app/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy_app/app/helpers/foos_helper.rb: -------------------------------------------------------------------------------- 1 | module FoosHelper 2 | def passes 3 | true 4 | end 5 | 6 | def users_path_helper 7 | users_path 8 | end 9 | 10 | def users_url_helper 11 | users_url 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/dummy_app/app/helpers/users_helper.rb: -------------------------------------------------------------------------------- 1 | module UsersHelper 2 | def render_users_list(users) 3 | content_tag :ul do 4 | users.map { |user| content_tag :li, user.email }.join.html_safe 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy_app/app/mailers/user_mailer.rb: -------------------------------------------------------------------------------- 1 | class UserMailer < ActionMailer::Base 2 | default from: 'rails@minitest.spec' 3 | 4 | def welcome(user) 5 | @user = user 6 | mail to: @user.email, subject: 'Welcome', body: "Welcome to Minitest::Spec #{@user.email}!" 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/dummy_app/app/models/post.rb: -------------------------------------------------------------------------------- 1 | class Post < ActiveRecord::Base 2 | belongs_to :user 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy_app/app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ActiveRecord::Base 2 | has_many :posts 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy_app/app/views/users/index.html.erb: -------------------------------------------------------------------------------- 1 |

All <%= @users.size %> Users

2 | <%= render_users_list(@users) %> -------------------------------------------------------------------------------- /test/dummy_app/config/database.yml: -------------------------------------------------------------------------------- 1 | 2 | test: 3 | adapter: sqlite3 4 | database: ':memory:' 5 | pool: 5 6 | timeout: 5000 7 | -------------------------------------------------------------------------------- /test/dummy_app/config/routes.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.routes.draw do 2 | root to: 'application#index' 3 | resources :users 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy_app/config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket 23 | 24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /test/dummy_app/init.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __dir__) 3 | require 'bundler/setup' 4 | require 'rails/all' 5 | Bundler.require(:default, Rails.env) 6 | require 'minitest/focus' 7 | require 'pry' 8 | 9 | module Dummy 10 | class Application < ::Rails::Application 11 | # Basic Engine 12 | config.root = File.join __FILE__, '..' 13 | config.cache_store = :memory_store 14 | config.assets.enabled = false if Rails.version < '7.0.0' 15 | config.secret_token = '012345678901234567890123456789' 16 | config.active_support.test_order = :random 17 | # Mimic Test Environment Config. 18 | config.whiny_nils = true 19 | config.consider_all_requests_local = true 20 | config.action_controller.perform_caching = false 21 | config.action_dispatch.show_exceptions = false 22 | config.action_controller.allow_forgery_protection = false 23 | config.action_mailer.delivery_method = :test 24 | config.active_support.deprecation = :stderr 25 | config.allow_concurrency = true 26 | config.cache_classes = true 27 | config.dependency_loading = true 28 | config.preload_frameworks = true 29 | config.eager_load = true 30 | # Custom 31 | config.minitest_spec_rails.mini_shoulda = true 32 | end 33 | end 34 | 35 | Dummy::Application.initialize! 36 | require 'rails/test_help' 37 | 38 | # Avoids local NoMethodError: undefined method `split' for nil:NilClass 39 | Rails.backtrace_cleaner.remove_silencers! 40 | -------------------------------------------------------------------------------- /test/dummy_app/lib/library.rb: -------------------------------------------------------------------------------- 1 | class Library 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy_app/tmp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/metaskills/minitest-spec-rails/ab2b15b0c507198a5b16a5dc2d6a21c2f9c8429c/test/dummy_app/tmp/.gitkeep -------------------------------------------------------------------------------- /test/dummy_app/tmp/development_secret.txt: -------------------------------------------------------------------------------- 1 | f45200b1a337dea2b5a19a5ff07a057008eabe34dd706a01bd3c7f8b744e2d094f3fa3cd681d7d8aeb0a317d65cc26749c11acdada6684dc092e6bdc928c0884 -------------------------------------------------------------------------------- /test/dummy_tests/application_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | module ApplicationControllerTests 4 | extend ActiveSupport::Concern 5 | included do 6 | before { get :index } 7 | 8 | it 'works' do 9 | get :index 10 | expect(response.body).must_equal '

Rendered Minitest::Spec

' 11 | end 12 | 13 | it 'allows custom assertions' do 14 | assert_select 'h1', text: 'Rendered Minitest::Spec' 15 | end 16 | 17 | it 'can find the controller_class' do 18 | expect(self.class.controller_class).must_equal ApplicationController 19 | end 20 | 21 | it 'can access the setup ivars' do 22 | expect(@controller).must_be_kind_of ApplicationController 23 | end 24 | 25 | describe 'nested 1' do 26 | it('works') { skip } 27 | 28 | it 'can find the controller_class' do 29 | expect(self.class.controller_class).must_equal ApplicationController 30 | end 31 | 32 | describe 'nested 2' do 33 | it('works') { skip } 34 | end 35 | end 36 | end 37 | end 38 | 39 | class ApplicationControllerTest < ActionController::TestCase 40 | include ApplicationControllerTests 41 | it 'reflects' do 42 | expect(described_class).must_equal ApplicationController 43 | expect(self.class.described_class).must_equal ApplicationController 44 | end 45 | describe 'level 1' do 46 | it 'reflects' do 47 | expect(described_class).must_equal ApplicationController 48 | expect(self.class.described_class).must_equal ApplicationController 49 | end 50 | describe 'level 2' do 51 | it 'reflects' do 52 | expect(described_class).must_equal ApplicationController 53 | expect(self.class.described_class).must_equal ApplicationController 54 | end 55 | end 56 | end 57 | end 58 | 59 | describe ApplicationController do 60 | include ApplicationControllerTests 61 | it 'class reflects' do 62 | expect(described_class).must_equal ApplicationController 63 | expect(self.class.described_class).must_equal ApplicationController 64 | end 65 | it 'reflects' do 66 | expect(described_class).must_equal ApplicationController 67 | expect(self.class.described_class).must_equal ApplicationController 68 | end 69 | describe 'level 1' do 70 | it 'reflects' do 71 | expect(described_class).must_equal ApplicationController 72 | expect(self.class.described_class).must_equal ApplicationController 73 | end 74 | describe 'level 2' do 75 | it 'reflects' do 76 | expect(described_class).must_equal ApplicationController 77 | expect(self.class.described_class).must_equal ApplicationController 78 | end 79 | end 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /test/dummy_tests/foos_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | class FoosHelperTest < ActionView::TestCase 4 | it 'allows path and url helpers' do 5 | expect(users_path_helper).must_equal '/users' 6 | expect(users_url_helper).must_equal 'http://test.host/users' 7 | end 8 | 9 | describe 'level1' do 10 | it 'works for helper method called in describe block' do 11 | assert passes 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /test/dummy_tests/integration_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | module IntegrationTests 4 | extend ActiveSupport::Concern 5 | included do 6 | fixtures :all 7 | 8 | it 'works' do 9 | get root_path 10 | expect(status).must_equal 200 11 | end 12 | 13 | it 'works with assert_routing' do 14 | assert_routing '/', controller: 'application', action: 'index' 15 | end 16 | 17 | it 'can find the app' do 18 | expect(app).must_be_instance_of Dummy::Application 19 | end 20 | 21 | describe 'nested 1' do 22 | it('works') { skip } 23 | 24 | it 'can find the app' do 25 | expect(app).must_be_instance_of Dummy::Application 26 | end 27 | 28 | describe 'nested 2' do 29 | it('works') { skip } 30 | end 31 | end 32 | end 33 | end 34 | 35 | class IntegrationTest < ActionDispatch::IntegrationTest 36 | include IntegrationTests 37 | end 38 | 39 | class AppTest < ActionDispatch::IntegrationTest 40 | def test_homepage 41 | assert_routing '/', controller: 'application', action: 'index' 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /test/dummy_tests/library_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | require "#{Dummy::Application.root}/lib/library" 3 | 4 | class LibraryTest < ActiveSupport::TestCase 5 | it 'reflects' do 6 | expect(described_class).must_equal Library 7 | end 8 | end 9 | 10 | describe Library do 11 | it 'reflects' do 12 | expect(described_class).must_equal Library 13 | expect(self.class.described_class).must_equal Library 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /test/dummy_tests/special_users_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | class SpecialUsersControllerTest < ActionController::TestCase 4 | tests UsersController 5 | 6 | it 'works' do 7 | get :index 8 | assert_select 'h1', "All #{User.count} Users" 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/dummy_tests/user_mailer_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | module UserMailerTests 4 | extend ActiveSupport::Concern 5 | included do 6 | let(:deliveries) { ActionMailer::Base.deliveries } 7 | let(:user_mailer_class) { UserMailer } 8 | let(:user_email) do 9 | user_mailer_class.welcome(user_ken).tap do |mail| 10 | mail.deliver_now 11 | end 12 | end 13 | 14 | it 'works' do 15 | expect(deliveries).must_be :empty? 16 | user_email 17 | expect(deliveries).wont_be :empty? 18 | expect(user_email.to).must_equal [user_ken.email] 19 | expect(user_email.from).must_equal ['rails@minitest.spec'] 20 | expect(user_email.body.encoded).must_equal "Welcome to Minitest::Spec #{user_ken.email}!" 21 | end 22 | 23 | it 'allows custom assertions' do 24 | assert_emails(1) { user_email } 25 | end 26 | 27 | it 'can find the mailer_class' do 28 | expect(self.class.mailer_class).must_equal user_mailer_class 29 | end 30 | 31 | describe 'nested 1' do 32 | it('works') { skip } 33 | 34 | it 'can find the mailer_class' do 35 | expect(self.class.mailer_class).must_equal user_mailer_class 36 | end 37 | 38 | describe 'nested 2' do 39 | it('works') { skip } 40 | end 41 | end 42 | end 43 | end 44 | 45 | class UserMailerTest < ActionMailer::TestCase 46 | include UserMailerTests 47 | it 'reflects' do 48 | expect(described_class).must_equal UserMailer 49 | expect(self.class.described_class).must_equal UserMailer 50 | end 51 | describe 'level 1' do 52 | it 'reflects' do 53 | expect(described_class).must_equal UserMailer 54 | expect(self.class.described_class).must_equal UserMailer 55 | end 56 | describe 'level 2' do 57 | it 'reflects' do 58 | expect(described_class).must_equal UserMailer 59 | expect(self.class.described_class).must_equal UserMailer 60 | end 61 | end 62 | end 63 | end 64 | 65 | describe UserMailer do 66 | include UserMailerTests 67 | it 'reflects' do 68 | expect(described_class).must_equal UserMailer 69 | expect(self.class.described_class).must_equal UserMailer 70 | end 71 | describe 'level 1' do 72 | it 'reflects' do 73 | expect(described_class).must_equal UserMailer 74 | expect(self.class.described_class).must_equal UserMailer 75 | end 76 | describe 'level 2' do 77 | it 'reflects' do 78 | expect(described_class).must_equal UserMailer 79 | expect(self.class.described_class).must_equal UserMailer 80 | end 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /test/dummy_tests/user_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | module UserTests 4 | extend ActiveSupport::Concern 5 | included do 6 | it 'works' do 7 | expect(user_ken).must_be_instance_of User 8 | end 9 | 10 | test 'works with test' do 11 | expect(user_ken).must_be_instance_of User 12 | end 13 | 14 | it 'allows custom assertions' do 15 | assert_not false 16 | end 17 | 18 | describe 'nested 1' do 19 | it('works') { skip } 20 | 21 | describe 'nested 2' do 22 | it('works') { skip } 23 | end 24 | 25 | test 'works with test' do 26 | expect(user_ken).must_be_instance_of User 27 | end 28 | end 29 | end 30 | end 31 | 32 | class UserTest < ActiveSupport::TestCase 33 | include UserTests 34 | it 'reflects' do 35 | expect(described_class).must_equal User 36 | expect(self.class.described_class).must_equal User 37 | end 38 | describe 'level 1' do 39 | it 'reflects' do 40 | expect(described_class).must_equal User 41 | expect(self.class.described_class).must_equal User 42 | end 43 | describe 'level 2' do 44 | it 'reflects' do 45 | expect(described_class).must_equal User 46 | expect(self.class.described_class).must_equal User 47 | end 48 | end 49 | end 50 | end 51 | 52 | describe User do 53 | include UserTests 54 | it 'reflects' do 55 | expect(described_class).must_equal User 56 | expect(self.class.described_class).must_equal User 57 | end 58 | describe 'level 1' do 59 | it 'reflects' do 60 | expect(described_class).must_equal User 61 | expect(self.class.described_class).must_equal User 62 | end 63 | describe 'level 2' do 64 | it 'reflects' do 65 | expect(described_class).must_equal User 66 | expect(self.class.described_class).must_equal User 67 | end 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /test/dummy_tests/users_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | module UsersControllerTests 4 | extend ActiveSupport::Concern 5 | included do 6 | it 'works' do 7 | get :index 8 | assert_select 'h1', "All #{User.count} Users" 9 | end 10 | 11 | it 'redirects' do 12 | put_update_0 13 | assert_redirected_to users_url 14 | end 15 | 16 | private 17 | 18 | def put_update_0 19 | put :update, params: { id: 0 } 20 | end 21 | end 22 | end 23 | 24 | class UsersControllerTest < ActionController::TestCase 25 | include UsersControllerTests 26 | end 27 | 28 | describe UsersController do 29 | include UsersControllerTests 30 | end 31 | -------------------------------------------------------------------------------- /test/dummy_tests/users_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper_dummy' 2 | 3 | module UsersHelperTests 4 | extend ActiveSupport::Concern 5 | included do 6 | let(:users_list) { render_users_list User.all } 7 | 8 | before { user_ken } 9 | 10 | it 'works' do 11 | user_ken 12 | expect(users_list).must_equal "" 13 | end 14 | 15 | it 'can find the helper_class' do 16 | expect(self.class.helper_class).must_equal UsersHelper 17 | end 18 | 19 | describe 'nested 1' do 20 | it('works') { skip } 21 | 22 | it 'can find the helper_class' do 23 | expect(self.class.helper_class).must_equal UsersHelper 24 | end 25 | 26 | describe 'nested 2' do 27 | it('works') { skip } 28 | end 29 | end 30 | end 31 | end 32 | 33 | class UsersHelperTest < ActionView::TestCase 34 | include UsersHelperTests 35 | it 'reflects' do 36 | expect(described_class).must_equal UsersHelper 37 | expect(self.class.described_class).must_equal UsersHelper 38 | end 39 | describe 'level 1' do 40 | it 'reflects' do 41 | expect(described_class).must_equal UsersHelper 42 | expect(self.class.described_class).must_equal UsersHelper 43 | end 44 | describe 'level 2' do 45 | it 'reflects' do 46 | expect(described_class).must_equal UsersHelper 47 | expect(self.class.described_class).must_equal UsersHelper 48 | end 49 | end 50 | end 51 | end 52 | 53 | describe UsersHelper do 54 | include UsersHelperTests 55 | it 'reflects' do 56 | expect(described_class).must_equal UsersHelper 57 | expect(self.class.described_class).must_equal UsersHelper 58 | end 59 | describe 'level 1' do 60 | it 'reflects' do 61 | expect(described_class).must_equal UsersHelper 62 | expect(self.class.described_class).must_equal UsersHelper 63 | end 64 | describe 'level 2' do 65 | it 'reflects' do 66 | expect(described_class).must_equal UsersHelper 67 | expect(self.class.described_class).must_equal UsersHelper 68 | end 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /test/support/shared_test_case_behavior.rb: -------------------------------------------------------------------------------- 1 | module MiniTestSpecRails 2 | module SharedTestCaseBehavior 3 | extend ActiveSupport::Concern 4 | 5 | included do 6 | before { setup_dummy_schema } 7 | let(:app) { Dummy::Application } 8 | let(:user_ken) { User.create! email: 'ken@metaskills.net' } 9 | let(:user_post) { Post.create! title: 'Test Title', body: 'Test body. Test body.', user: user_ken } 10 | end 11 | 12 | private 13 | 14 | def setup_dummy_schema 15 | ActiveRecord::Base.class_eval do 16 | connection.instance_eval do 17 | create_table :users, force: true do |t| 18 | t.string :email 19 | end 20 | create_table :posts, force: true do |t| 21 | t.string :title, :body 22 | t.integer :user_id 23 | end 24 | end 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require 'dummy_app/init' 2 | require 'support/shared_test_case_behavior' 3 | 4 | module MiniTestSpecRails 5 | class TestCase < Minitest::Spec 6 | include MiniTestSpecRails::SharedTestCaseBehavior 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/test_helper_dummy.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | module ActiveSupport 4 | class TestCase 5 | fixtures :all 6 | include MiniTestSpecRails::SharedTestCaseBehavior 7 | end 8 | end 9 | --------------------------------------------------------------------------------