minitest-spec-rails 5.0.0 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +36 -0
- data/.gitignore +1 -2
- data/.rubocop.yml +26 -0
- data/Appraisals +13 -1
- data/CHANGELOG.md +130 -46
- data/CODE_OF_CONDUCT.md +31 -0
- data/Gemfile +0 -4
- data/README.md +63 -67
- data/Rakefile +6 -14
- data/gemfiles/rails_v6.0.x.gemfile +8 -0
- data/gemfiles/rails_v6.0.x.gemfile.lock +172 -0
- data/gemfiles/rails_v6.1.x.gemfile +8 -0
- data/gemfiles/rails_v6.1.x.gemfile.lock +175 -0
- data/gemfiles/rails_v7.0.x.gemfile +8 -0
- data/gemfiles/rails_v7.0.x.gemfile.lock +174 -0
- data/gemfiles/rails_v7.1.x.gemfile +9 -0
- data/lib/minitest-spec-rails/dsl.rb +6 -10
- data/lib/minitest-spec-rails/init/action_cable.rb +28 -0
- data/lib/minitest-spec-rails/init/action_controller.rb +3 -7
- data/lib/minitest-spec-rails/init/action_dispatch.rb +1 -3
- data/lib/minitest-spec-rails/init/action_mailer.rb +2 -7
- data/lib/minitest-spec-rails/init/action_view.rb +1 -5
- data/lib/minitest-spec-rails/init/active_job.rb +24 -0
- data/lib/minitest-spec-rails/init/active_support.rb +8 -11
- data/lib/minitest-spec-rails/init/mini_shoulda.rb +2 -6
- data/lib/minitest-spec-rails/parallelize.rb +30 -0
- data/lib/minitest-spec-rails/railtie.rb +24 -17
- data/lib/minitest-spec-rails/version.rb +1 -1
- data/minitest-spec-rails.gemspec +10 -9
- data/test/cases/action_cable_test.rb +38 -0
- data/test/cases/action_controller_test.rb +13 -16
- data/test/cases/action_dispatch_test.rb +18 -21
- data/test/cases/action_mailer_test.rb +13 -16
- data/test/cases/action_view_test.rb +17 -20
- data/test/cases/active_job_test.rb +46 -0
- data/test/cases/active_support_test.rb +28 -18
- data/test/cases/mini_shoulda_test.rb +6 -11
- data/test/dummy_app/app/assets/config/manifest.js +1 -0
- data/test/dummy_app/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy_app/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy_app/app/controllers/application_controller.rb +1 -3
- data/test/dummy_app/app/controllers/users_controller.rb +1 -3
- data/test/dummy_app/app/helpers/application_helper.rb +0 -1
- data/test/dummy_app/app/helpers/foos_helper.rb +3 -1
- data/test/dummy_app/app/helpers/users_helper.rb +1 -3
- data/test/dummy_app/app/mailers/user_mailer.rb +2 -4
- data/test/dummy_app/app/models/post.rb +0 -3
- data/test/dummy_app/app/models/user.rb +0 -3
- data/test/dummy_app/config/routes.rb +1 -1
- data/test/dummy_app/config/storage.yml +34 -0
- data/test/dummy_app/init.rb +18 -21
- data/test/dummy_app/tmp/development_secret.txt +1 -0
- data/test/dummy_tests/application_controller_test.rb +19 -25
- data/test/dummy_tests/{foo_helper_test.rb → foos_helper_test.rb} +2 -5
- data/test/dummy_tests/integration_test.rb +5 -11
- data/test/dummy_tests/library_test.rb +3 -3
- data/test/dummy_tests/special_users_controller_test.rb +10 -0
- data/test/dummy_tests/user_mailer_test.rb +24 -26
- data/test/dummy_tests/user_test.rb +15 -21
- data/test/dummy_tests/users_controller_test.rb +8 -4
- data/test/dummy_tests/users_helper_test.rb +15 -21
- data/test/support/shared_test_case_behavior.rb +4 -7
- data/test/test_helper.rb +1 -5
- data/test/test_helper_dummy.rb +5 -7
- metadata +87 -74
- data/.travis.yml +0 -11
- data/Guardfile +0 -7
- data/test/support/minitest.rb +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d45d0f576ead81293a568b0d0a7de54b1c0f58db87a5146f321b6e2fe8a43433
|
4
|
+
data.tar.gz: 20dcff696a39c8e9994be10dd677c461a2a7dca0bf15f91c894f1a71f22c8cd6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93252710ba2a83ecfdddc34533498a0657ebca18ff0e53c78f283a53d0b2857df878741252fc40f70d55908e7d47dbf4a74461ba952e16fb89d8a9b485a0dd15
|
7
|
+
data.tar.gz: '058000caeba140b5860d79b38e63b59c5043bab0ef3f526342bb927cb53b12fb057746c88082e21149f3413e44596a209ed786ed4b7614b60a8c33e6229c4fda'
|
@@ -0,0 +1,36 @@
|
|
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
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
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/*'
|
data/Appraisals
CHANGED
@@ -1,3 +1,15 @@
|
|
1
1
|
|
2
|
-
appraise '
|
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'
|
3
15
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,117 +1,201 @@
|
|
1
|
+
## 7.2.0
|
2
|
+
|
3
|
+
- Wrap action_view init in config.to_prepare block. Fixes #122. Thanks @Hal-Sumi
|
4
|
+
|
5
|
+
## 7.1.0
|
6
|
+
|
7
|
+
- Use Minitest instead of MiniTest. Fixes #119. Thanks @evgeni
|
8
|
+
- Fix ActionCable::Channel::TestCase support. Fixes #118. Thanks @marcoroth
|
9
|
+
- Add support for ActionCable::Channel::TestCase. Fixes #117. Thanks @tijn
|
10
|
+
|
11
|
+
## 7.0.0
|
12
|
+
|
13
|
+
- Add support for ActionCable::Channel::TestCase. Fixed #117. Thanks @tijn
|
14
|
+
- Remove automated tests for Rails v5 and Ruby v2.
|
15
|
+
- Update all of our tests and examples to use non-global expectations.
|
16
|
+
- Remove `Rails.application.reloader.to_prepare` for `ActionViewBehavior`.
|
17
|
+
|
18
|
+
## 6.2.0
|
19
|
+
|
20
|
+
- Remove 'ENV['RAILS_ENV']=='test' from railtie.rb Fixes #114. Thanks @Qqwy
|
21
|
+
|
22
|
+
## 6.1.0
|
23
|
+
|
24
|
+
- Fix Rails v7 autoloading with ViewComponent. Thanks @woller
|
25
|
+
|
26
|
+
## 6.0.4
|
27
|
+
|
28
|
+
- Fixed parallel tests with relative paths. Thanks @jlsherrill
|
29
|
+
|
30
|
+
## 6.0.3
|
31
|
+
|
32
|
+
- Better ActionView load. Fixed #105. Thanks @zofrex
|
33
|
+
|
34
|
+
## 6.0.2
|
35
|
+
|
36
|
+
- Fixed parallel tests in Rails v6.
|
37
|
+
|
38
|
+
## 6.0.1
|
39
|
+
|
40
|
+
- Changed gemspec to `railties` vs `rails`. Thanks @seuros
|
41
|
+
|
42
|
+
## 6.0.0
|
43
|
+
|
44
|
+
- Bumping to be major with latest testing versions.
|
45
|
+
|
46
|
+
## 5.6.0
|
47
|
+
|
48
|
+
- Add Rails v6 via gem spec support.
|
49
|
+
|
50
|
+
## 5.5.0
|
51
|
+
|
52
|
+
- Fix source_location of methods defined with `test`. Fixes #91. Thanks @barrettkingram
|
53
|
+
|
54
|
+
## 5.4.0
|
55
|
+
|
56
|
+
- Use ENV['RAILS_ENV'] for initializer guards vs memo'ed Rails.env. Fixes #72.
|
57
|
+
|
58
|
+
## 5.3.0
|
59
|
+
|
60
|
+
- Allow Rails 4.1 to new 5.x to be supported.
|
61
|
+
|
62
|
+
## 5.2.2
|
63
|
+
|
64
|
+
- Fix ActiveJob support for `described_class`. Thanks @pschambacher.
|
65
|
+
|
66
|
+
## 5.2.1
|
67
|
+
|
68
|
+
- Only add our Thread.current[:current_spec] hack if needed. Fixes #45.
|
69
|
+
|
70
|
+
## 5.2.0
|
71
|
+
|
72
|
+
- Added ActiveJob support. Fixes #59. Thanks @xpepermint.
|
73
|
+
|
74
|
+
## 5.1.1
|
75
|
+
|
76
|
+
- Fix an issue where `describe` method was removed. Fixes #55 & #50
|
77
|
+
[41a0f851](https://github.com/metaskills/minitest-spec-rails/commit/41a0f851c8a290f59feb1cb8b20759f0e2a9697a)
|
78
|
+
|
79
|
+
## 5.1.0
|
80
|
+
|
81
|
+
No release notes yet. PRs welcome!
|
82
|
+
|
83
|
+
## 5.0.4
|
84
|
+
|
85
|
+
- Fixed ActiveSupport's Declarative#test forwarded implementation. Fixed #46.
|
86
|
+
|
87
|
+
## 5.0.3
|
88
|
+
|
89
|
+
- Fixed ActionView load order & url helpers. Fixes #42.
|
90
|
+
|
91
|
+
## 5.0.2
|
92
|
+
|
93
|
+
- Fixed initialization callbacks for latest Rails 4.1. Fixes #39.
|
94
|
+
|
95
|
+
## 5.0.1
|
96
|
+
|
97
|
+
- Change initialization so that ActiveSupport always comes first.
|
1
98
|
|
2
99
|
## 5.0.0
|
3
100
|
|
4
|
-
|
5
|
-
|
6
|
-
|
101
|
+
- Minitest 5.x and Rails 4.1 compatability. Fixes #36.
|
102
|
+
- Fix nested described test names along with Minitest::Spec.describe_stack. Fixed #21.
|
103
|
+
- Leverage `ActiveSupport::Testing::ConstantLookup` for our `described_class` interface.
|
7
104
|
|
105
|
+
## 4.7.6
|
8
106
|
|
9
|
-
|
107
|
+
- Fix nested described test names. Fixes #21.
|
10
108
|
|
11
|
-
|
109
|
+
## 4.7.5
|
12
110
|
|
111
|
+
- Fixed gemspec using '>= 3.0', '< 4.1'. Fixed #35.
|
13
112
|
|
14
|
-
## 4.7.
|
113
|
+
## 4.7.4
|
114
|
+
|
115
|
+
- Enforces case sensitivity on registered spec types. Fixes #26.
|
15
116
|
|
16
|
-
|
117
|
+
## 4.7.3
|
17
118
|
|
119
|
+
- Allow using ActiveSupport's Declarative#test as an alias to it. Thanks @ysbaddaden. Fixes #23.
|
18
120
|
|
19
121
|
## 4.7.2
|
20
122
|
|
21
|
-
|
22
|
-
|
123
|
+
- Register non ActiveRecord::Base classes correctly. Thanks @mptre.
|
23
124
|
|
24
125
|
## 4.7.1
|
25
126
|
|
26
|
-
|
27
|
-
|
127
|
+
- Only use a TU shim for Ruby 1.8. See README for info. Fixes #18.
|
28
128
|
|
29
129
|
## 4.7.0
|
30
130
|
|
31
|
-
|
32
|
-
|
131
|
+
- Use Minitest::Spec::DSL provided by Minitest 4.7.
|
33
132
|
|
34
133
|
## 4.3.8
|
35
134
|
|
36
|
-
|
37
|
-
|
135
|
+
- Less coupling to ActiveRecord ORM, works for MongoDB now. Thanks @kimsuelim
|
38
136
|
|
39
137
|
## v4.3.7
|
40
138
|
|
41
|
-
|
42
|
-
|
139
|
+
- Fix helper test bug where calling methods in first context block blew up. Fixes #13.
|
43
140
|
|
44
141
|
## v4.3.6
|
45
142
|
|
46
|
-
|
47
|
-
|
143
|
+
- Only require the freedom patches and autorun when Rails.env.test?
|
48
144
|
|
49
145
|
## v4.3.5
|
50
146
|
|
51
|
-
|
52
|
-
|
147
|
+
- Make sure #described_class works in ActiveSupport::TestCase class level.
|
53
148
|
|
54
149
|
## v4.3.4
|
55
150
|
|
56
|
-
|
57
|
-
|
151
|
+
- Add mini_should support and talk about matchers.
|
58
152
|
|
59
153
|
## v4.3.3
|
60
154
|
|
61
|
-
|
62
|
-
|
155
|
+
- Fix MiniTest::Unit::TestCase hack for Rails 4, ignore in Rails 3.
|
63
156
|
|
64
157
|
## v4.3.2
|
65
158
|
|
66
|
-
|
67
|
-
|
159
|
+
- Way better support for controller_class, mailer_class, and helper_class reflection.
|
68
160
|
|
69
161
|
## v4.3.1
|
70
162
|
|
71
|
-
|
72
|
-
|
163
|
+
- Eager load controller_class, mailer_class, and helper_class.
|
73
164
|
|
74
165
|
## v4.3.0
|
75
166
|
|
76
|
-
|
77
|
-
|
78
|
-
|
167
|
+
- All new MiniTest::Spec for Rails!!! Tested to the hilt!!!
|
168
|
+
- Track MiniTest's major/minior version number.
|
79
169
|
|
80
170
|
## v3.0.7
|
81
171
|
|
82
|
-
|
83
|
-
|
172
|
+
- Must use MiniTest version ~> 2.1. As 3.x will not work.
|
84
173
|
|
85
174
|
## v3.0.6
|
86
175
|
|
87
|
-
|
88
|
-
|
176
|
+
- Use #constantize vs. #safe_constantize for Rails 3.0 compatability.
|
89
177
|
|
90
178
|
## v3.0.5
|
91
179
|
|
92
|
-
|
93
|
-
|
180
|
+
- Use ActionController::IntegrationTest vs. ActionDispatch::IntegrationTest
|
94
181
|
|
95
182
|
## v3.0.4
|
96
183
|
|
97
|
-
|
98
|
-
|
184
|
+
- Use class app setter for integration tests.
|
99
185
|
|
100
186
|
## v3.0.3
|
101
187
|
|
102
|
-
|
188
|
+
- Stronger test case organization where we properly setup functional and integraiton tests
|
103
189
|
while also allowing an alternate pure MiniTest::Spec outter file describe block. [Jack Chu]
|
104
190
|
|
105
|
-
|
106
191
|
## v3.0.2
|
107
192
|
|
108
|
-
|
109
|
-
|
193
|
+
- Remove version deps on minitest since v3 is out. Should work with any v2/3 version.
|
110
194
|
|
111
195
|
## v3.0.1
|
112
196
|
|
113
|
-
|
197
|
+
- Add rails to the gemspec.
|
114
198
|
|
115
199
|
## v3.0.0
|
116
200
|
|
117
|
-
|
201
|
+
- Initial Release, targeted to Rails 3.x.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,31 @@
|
|
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/
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,28 +1,23 @@
|
|
1
|
-
<img src="
|
1
|
+
<a href="https://dhh.dk/2012/rails-is-omakase.html"><img src="https://user-images.githubusercontent.com/2381/34084174-246174da-e34a-11e7-9d36-94c9cde7b63d.png" width="233" height="154" /></a>
|
2
2
|
|
3
|
-
# Make Rails Use
|
3
|
+
# Make Rails Use Minitest::Spec!
|
4
|
+
##### https://dhh.dk/2012/rails-is-omakase.html
|
4
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.
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
[![
|
9
|
-
[![Build Status](https://secure.travis-ci.org/metaskills/minitest-spec-rails.png)](http://travis-ci.org/metaskills/minitest-spec-rails)
|
10
|
-
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/metaskills/minitest-spec-rails)
|
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
11
|
|
12
12
|
|
13
13
|
## Usage
|
14
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
|
16
|
-
|
17
|
-
|
18
|
-
#### Rails 4.1
|
19
|
-
|
20
|
-
Our master branch is tracking rails master which is active development for Rails 4.1 which uses minitest 5.0.
|
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.
|
21
16
|
|
22
17
|
|
23
|
-
####
|
18
|
+
#### Rails 4.1 to 6.0
|
24
19
|
|
25
|
-
Our
|
20
|
+
Our master branch is tracking rails 5.1 up to 6.x active development.
|
26
21
|
|
27
22
|
```ruby
|
28
23
|
group :test do
|
@@ -30,39 +25,29 @@ group :test do
|
|
30
25
|
end
|
31
26
|
```
|
32
27
|
|
33
|
-
#### For Rails
|
34
|
-
|
35
|
-
Our [2-3-stable](https://github.com/metaskills/minitest-spec-rails/tree/2-3-stable) branch tracks our 3.1 version number and is guaranteed to work on any Rails 2.3 version. Since Rails 2.3 does not have a configurable Railtie, we have enabled the [mini-shoulda](#mini_shoulda) option all the time. This means that if you are on Rails 2.3 under either Ruby 1.8 or 1.9, perhaps using Shoulda, you have a solid upgrade path! Get your tests running with minitest-spec-rails first and nothing in you test stack changes along the way!
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
group :test do
|
39
|
-
gem 'minitest-spec-rails', '~> 3.1'
|
40
|
-
end
|
41
|
-
```
|
42
|
-
|
43
|
-
#### Ruby 1.8 Users!!!
|
28
|
+
#### For Rails 3.x or 4.0
|
44
29
|
|
45
|
-
|
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.
|
46
31
|
|
47
32
|
```ruby
|
48
33
|
group :test do
|
49
|
-
gem 'minitest-spec-rails
|
34
|
+
gem 'minitest-spec-rails', '~> 4.7'
|
50
35
|
end
|
51
36
|
```
|
52
37
|
|
53
38
|
|
54
|
-
### How is this different than
|
39
|
+
### How is this different than Minitest::Rails?
|
55
40
|
|
56
|
-
To start off both Mike Moore (@blowmage) and I have worked together and we both LOVE
|
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)?
|
57
42
|
|
58
43
|
* We aim to leverage existing Rails test directories and files!
|
59
44
|
* No special test helper and/or generators.
|
60
45
|
* Easy migration path for existing Rails applications.
|
61
46
|
* How we go about freedom patching Rails.
|
62
47
|
* Fully support Ruby 1.8.7 with all legacy Test::Unit behavior.
|
63
|
-
*
|
48
|
+
* Compatibility with ActiveSupport::TestCase's setup and teardowns.
|
64
49
|
|
65
|
-
So the goal of this project is to make Rails 3 or 4 applications just work as if rails-core had decided to support
|
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!
|
66
51
|
|
67
52
|
```ruby
|
68
53
|
gem 'minitest-spec-rails'
|
@@ -71,14 +56,14 @@ gem 'minitest-spec-rails'
|
|
71
56
|
|
72
57
|
## Test Styles
|
73
58
|
|
74
|
-
This <a href="
|
59
|
+
This <a href="https://chriskottom.com/freebies/cheatsheets_free.pdf">cheat sheet</a> 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.
|
75
60
|
|
76
61
|
```ruby
|
77
|
-
#
|
62
|
+
# Minitest::Unit Assertion Style:
|
78
63
|
assert_equal 100, foo
|
79
64
|
|
80
|
-
#
|
81
|
-
foo.must_equal 100
|
65
|
+
# Minitest::Spec Assertion Style:
|
66
|
+
expect(foo).must_equal 100
|
82
67
|
```
|
83
68
|
|
84
69
|
|
@@ -87,7 +72,7 @@ require 'test_helper'
|
|
87
72
|
class UserTest < ActiveSupport::TestCase
|
88
73
|
let(:user_ken) { User.create! :email => 'ken@metaskills.net' }
|
89
74
|
it 'works' do
|
90
|
-
user_ken.must_be_instance_of User
|
75
|
+
expect(user_ken).must_be_instance_of User
|
91
76
|
end
|
92
77
|
end
|
93
78
|
```
|
@@ -95,24 +80,26 @@ end
|
|
95
80
|
```ruby
|
96
81
|
require 'test_helper'
|
97
82
|
describe User do
|
98
|
-
#
|
83
|
+
# THIS IS NOT RECOMMENDED!
|
99
84
|
end
|
100
85
|
```
|
101
86
|
|
102
|
-
|
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.
|
103
94
|
|
104
95
|
```ruby
|
105
|
-
# Model Test
|
96
|
+
# Model Test (or anything else not listed below)
|
106
97
|
class UserTest < ActiveSupport::TestCase
|
107
98
|
end
|
108
|
-
describe User do
|
109
|
-
end
|
110
99
|
|
111
100
|
# Controller Test
|
112
101
|
class UsersControllerTest < ActionController::TestCase
|
113
102
|
end
|
114
|
-
describe UsersController do
|
115
|
-
end
|
116
103
|
|
117
104
|
# Integration Tests - Must use subclass style!
|
118
105
|
class IntegrationTest < ActionDispatch::IntegrationTest
|
@@ -121,13 +108,13 @@ end
|
|
121
108
|
# Mailer Test
|
122
109
|
class UserMailerTest < ActionMailer::TestCase
|
123
110
|
end
|
124
|
-
describe UserMailer do
|
125
|
-
end
|
126
111
|
|
127
112
|
# View Helper Test
|
128
113
|
class UsersHelperTest < ActionView::TestCase
|
129
114
|
end
|
130
|
-
|
115
|
+
|
116
|
+
# Job Helper Test
|
117
|
+
class MyJobTest < ActiveJob::TestCase
|
131
118
|
end
|
132
119
|
```
|
133
120
|
|
@@ -165,9 +152,9 @@ class ActiveSupportCallbackTest < ActiveSupport::TestCase
|
|
165
152
|
before { @bat = 'biz' }
|
166
153
|
|
167
154
|
it 'works' do
|
168
|
-
@foo.must_equal 'foo'
|
169
|
-
@bar.must_equal 'bar'
|
170
|
-
@bat.must_equal 'biz'
|
155
|
+
expect(@foo).must_equal 'foo'
|
156
|
+
expect(@bar).must_equal 'bar'
|
157
|
+
expect(@bat).must_equal 'biz'
|
171
158
|
end
|
172
159
|
|
173
160
|
private
|
@@ -187,7 +174,7 @@ If you are migrating away from Shoulda, then minitest-spec-rails' mini_shoulda f
|
|
187
174
|
config.minitest_spec_rails.mini_shoulda = true
|
188
175
|
```
|
189
176
|
|
190
|
-
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 [
|
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.
|
191
178
|
|
192
179
|
```ruby
|
193
180
|
class PostTests < ActiveSupport::TestCase
|
@@ -204,19 +191,19 @@ class PostTests < ActiveSupport::TestCase
|
|
204
191
|
end
|
205
192
|
```
|
206
193
|
|
207
|
-
If you
|
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.
|
208
195
|
|
209
196
|
```ruby
|
210
|
-
assert_same_elements a, b
|
211
|
-
a.sort.must_equal b.sort
|
197
|
+
assert_same_elements a, b # From
|
198
|
+
expect(a.sort).must_equal b.sort # To
|
212
199
|
|
213
200
|
assert_does_not_contain a, b # From
|
214
|
-
a.wont_include b
|
201
|
+
expect(a).wont_include b # To
|
215
202
|
```
|
216
203
|
|
217
204
|
### Matchers
|
218
205
|
|
219
|
-
**I highly suggest that you stay away from matchers** since
|
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.
|
220
207
|
|
221
208
|
```ruby
|
222
209
|
describe Post do
|
@@ -226,19 +213,30 @@ describe Post do
|
|
226
213
|
end
|
227
214
|
```
|
228
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
|
+
```
|
229
227
|
|
230
228
|
## Gotchas
|
231
229
|
|
232
230
|
### Assertion Methods
|
233
231
|
|
234
|
-
If you are upgrading from Test::Unit, there are a few missing assertions that have been renamed or are no longer available within
|
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.
|
235
233
|
|
236
234
|
* The method `assert_raise` is renamed `assert_raises`.
|
237
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).
|
238
236
|
|
239
237
|
### Mocha
|
240
238
|
|
241
|
-
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
|
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 :)
|
242
240
|
|
243
241
|
```ruby
|
244
242
|
require 'mocha/deprecation'
|
@@ -265,18 +263,20 @@ If your view helper tests give you an eror like this: `RuntimeError: In order to
|
|
265
263
|
|
266
264
|
## Contributing
|
267
265
|
|
268
|
-
We run our tests on
|
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.
|
269
267
|
|
270
268
|
```shell
|
271
269
|
$ bundle install
|
272
|
-
$ bundle exec
|
273
|
-
$ bundle exec rake
|
270
|
+
$ bundle exec appraisal update
|
271
|
+
$ bundle exec appraisal rake test
|
274
272
|
```
|
275
273
|
|
276
|
-
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 `
|
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.
|
277
275
|
|
278
276
|
```shell
|
279
|
-
$ bundle exec rake
|
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
280
|
```
|
281
281
|
|
282
282
|
We have a few branches for each major Rails version.
|
@@ -284,7 +284,3 @@ We have a few branches for each major Rails version.
|
|
284
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
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
286
|
* master - Currently tracks Rails 4.1 which uses Minitest 5.0.
|
287
|
-
|
288
|
-
Our current build status is:
|
289
|
-
[![Build Status](https://secure.travis-ci.org/metaskills/minitest-spec-rails.png)](http://travis-ci.org/metaskills/minitest-spec-rails)
|
290
|
-
|