minitest-spec-rails 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -40
- data/Gemfile +2 -0
- data/README.md +2 -212
- data/lib/minitest-spec-rails/version.rb +1 -1
- data/minitest-spec-rails.gemspec +0 -1
- metadata +13 -29
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,48 +1,12 @@
|
|
1
1
|
|
2
|
-
##
|
2
|
+
## v3.1.1
|
3
3
|
|
4
|
-
*
|
4
|
+
* Only use a TU shim for Ruby 1.8. See README for info.
|
5
5
|
|
6
6
|
|
7
|
-
##
|
7
|
+
## v3.1.0
|
8
8
|
|
9
|
-
*
|
10
|
-
|
11
|
-
|
12
|
-
## v4.3.6
|
13
|
-
|
14
|
-
* Only require the freedom patches and autorun when Rails.env.test?
|
15
|
-
|
16
|
-
|
17
|
-
## v4.3.5
|
18
|
-
|
19
|
-
* Make sure #described_class works in ActiveSupport::TestCase class level.
|
20
|
-
|
21
|
-
|
22
|
-
## v4.3.4
|
23
|
-
|
24
|
-
* Add mini_should support and talk about matchers.
|
25
|
-
|
26
|
-
|
27
|
-
## v4.3.3
|
28
|
-
|
29
|
-
* Fix MiniTest::Unit::TestCase hack for Rails 4, ignore in Rails 3.
|
30
|
-
|
31
|
-
|
32
|
-
## v4.3.2
|
33
|
-
|
34
|
-
* Way better support for controller_class, mailer_class, and helper_class reflection.
|
35
|
-
|
36
|
-
|
37
|
-
## v4.3.1
|
38
|
-
|
39
|
-
* Eager load controller_class, mailer_class, and helper_class.
|
40
|
-
|
41
|
-
|
42
|
-
## v4.3.0
|
43
|
-
|
44
|
-
* All new MiniTest::Spec for Rails!!! Tested to the hilt!!!
|
45
|
-
* Track MiniTest's major/minior version number.
|
9
|
+
* Reborn and back! Fully supports Rails 2.3.
|
46
10
|
|
47
11
|
|
48
12
|
## v3.0.7
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,218 +3,8 @@
|
|
3
3
|
|
4
4
|
# Make Rails Use MiniTest::Spec!
|
5
5
|
|
6
|
+
Always read the latest:
|
6
7
|
|
7
|
-
|
8
|
+
https://github.com/metaskills/minitest-spec-rails#for-rails-23
|
8
9
|
|
9
|
-
The minitest-spec-rails gem makes it easy to use the MiniTest::Spec DSL within your existing Rails 3 or 4 test suite. It does this by forcing ActiveSupport::TestCase to subclass MiniTest::Spec.
|
10
|
-
|
11
|
-
[![Gem Version](https://badge.fury.io/rb/minitest-spec-rails.png)](http://badge.fury.io/rb/minitest-spec-rails)
|
12
|
-
[![Build Status](https://secure.travis-ci.org/metaskills/minitest-spec-rails.png)](http://travis-ci.org/metaskills/minitest-spec-rails)
|
13
|
-
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/metaskills/minitest-spec-rails)
|
14
|
-
|
15
|
-
|
16
|
-
## Usage
|
17
|
-
|
18
|
-
Existing or new Rails 3 or 4 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 MinitTest::Spec is built on top of MiniTest::Unit, a replacement for Test::Unit, all of your existing tests will continue to work.
|
19
|
-
|
20
|
-
### How is this different than MiniTest::Rails?
|
21
|
-
|
22
|
-
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)?
|
23
|
-
|
24
|
-
* We aim to leverage existing Rails test directories and files!
|
25
|
-
* No special test helper and/or generators.
|
26
|
-
* Easy migration path for existing Rails applications.
|
27
|
-
* How we go about freedom patching Rails.
|
28
|
-
|
29
|
-
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!
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
gem 'minitest-spec-rails'
|
33
|
-
```
|
34
|
-
|
35
|
-
|
36
|
-
## Test Styles
|
37
|
-
|
38
|
-
This <a href="http://cheat.errtheblog.com/s/minitest">cheat sheet</a> shows both the MiniTest::Unit assertions along with the MiniTest::Spec assertion syntax. Remember, MiniTest::Spec is build 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.
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
# MiniTest::Unit Assertion Style:
|
42
|
-
assert_equal 100, foo
|
43
|
-
|
44
|
-
# MiniTest::Spec Assertion Style:
|
45
|
-
foo.must_equal 100
|
46
|
-
```
|
47
|
-
|
48
|
-
All existing Rails test cases that subclass ActiveSupport::TestCase will continue to work and I personally suggest that you still **use the subclass convention** vs the outer describe test case convention. However either will work.
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
require 'test_helper'
|
52
|
-
class UserTest < ActiveSupport::TestCase
|
53
|
-
let(:user_ken) { User.create! :email => 'ken@metaskills.net' }
|
54
|
-
it 'works' do
|
55
|
-
user_ken.must_be_instance_of User
|
56
|
-
end
|
57
|
-
end
|
58
|
-
```
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
require 'test_helper'
|
62
|
-
describe User do
|
63
|
-
# This will work too.
|
64
|
-
end
|
65
|
-
```
|
66
|
-
|
67
|
-
Just for reference, here is a full list of each of Rails test case classes and the matching describe alternative if one exists. Remember, names are important when using the describe syntax. So you can not have a mailer named `FooBar` and expect it to work with the outer describe spec style since there is no way to map the spec type based on an existing naming convention.
|
68
|
-
|
69
|
-
```ruby
|
70
|
-
# Model Test
|
71
|
-
class UserTest < ActiveSupport::TestCase
|
72
|
-
end
|
73
|
-
describe User do
|
74
|
-
end
|
75
|
-
|
76
|
-
# Controller Test
|
77
|
-
class UsersControllerTest < ActionController::TestCase
|
78
|
-
end
|
79
|
-
describe UsersController do
|
80
|
-
end
|
81
|
-
|
82
|
-
# Integration Tests - Must use subclass style!
|
83
|
-
class IntegrationTest < ActionDispatch::IntegrationTest
|
84
|
-
end
|
85
|
-
|
86
|
-
# Mailer Test
|
87
|
-
class UserMailerTest < ActionMailer::TestCase
|
88
|
-
end
|
89
|
-
describe UserMailer do
|
90
|
-
end
|
91
|
-
|
92
|
-
# View Helper Test
|
93
|
-
class UsersHelperTest < ActionView::TestCase
|
94
|
-
end
|
95
|
-
describe UsersHelper do
|
96
|
-
end
|
97
|
-
```
|
98
|
-
|
99
|
-
|
100
|
-
## Extras
|
101
|
-
|
102
|
-
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.
|
103
|
-
|
104
|
-
### #described_class
|
105
|
-
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 build, much like Shoulda. Remember, it can only do this if you follow Rails naming conventions for your tests.
|
106
|
-
|
107
|
-
```ruby
|
108
|
-
class UserTest < ActiveSupport::TestCase
|
109
|
-
described_class # => User(id: integer, email: string)
|
110
|
-
it 'works here' do
|
111
|
-
described_class # => User(id: integer, email: string)
|
112
|
-
end
|
113
|
-
describe 'and' do
|
114
|
-
it 'works here too' do
|
115
|
-
described_class # => User(id: integer, email: string)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
```
|
120
|
-
|
121
|
-
### mini_shoulda
|
122
|
-
|
123
|
-
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.
|
124
|
-
|
125
|
-
```ruby
|
126
|
-
# In config/environments/test.rb
|
127
|
-
config.minitest_spec_rails.mini_shoulda = true
|
128
|
-
```
|
129
|
-
|
130
|
-
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 [should-context](https://github.com/thoughtbot/shoulda-context) in a few lines of code.
|
131
|
-
|
132
|
-
```ruby
|
133
|
-
class PostTests < ActiveSupport::TestCase
|
134
|
-
setup { @post = Post.create! :title => 'Test Title', :body => 'Test body' }
|
135
|
-
teardown { Post.delete_all }
|
136
|
-
should 'work' do
|
137
|
-
@post.must_be_instance_of Post
|
138
|
-
end
|
139
|
-
context 'with a user' do
|
140
|
-
should_eventually 'have a user' do
|
141
|
-
# ...
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
```
|
146
|
-
|
147
|
-
If you are in 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.
|
148
|
-
|
149
|
-
```ruby
|
150
|
-
assert_same_elements a, b # From
|
151
|
-
a.sort.must_equal b.sort # To
|
152
|
-
|
153
|
-
assert_does_not_contain a, b # From
|
154
|
-
a.wont_include b # To
|
155
|
-
```
|
156
|
-
|
157
|
-
### Matchers
|
158
|
-
|
159
|
-
**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/zenspider/minitest-matchers) gem. You can also check out the [valid_attribute](https://github.com/bcardarella/valid_attribute) gem built on top of minitest-matchers.
|
160
|
-
|
161
|
-
```ruby
|
162
|
-
describe Post do
|
163
|
-
subject { Post.new }
|
164
|
-
it { must have_valid(:title).when("Hello") }
|
165
|
-
it { wont have_valid(:title).when("", nil, "Bad") }
|
166
|
-
end
|
167
|
-
```
|
168
|
-
|
169
|
-
|
170
|
-
## Gotchas
|
171
|
-
|
172
|
-
### Assertion Methods
|
173
|
-
|
174
|
-
If you are upgrading from Test::Unit, there are a few missing assertions that have been renamed or are no longer available within MiniTest.
|
175
|
-
|
176
|
-
* The method `assert_raise` is renamed `assert_raises`.
|
177
|
-
* 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).
|
178
|
-
|
179
|
-
### Mocha
|
180
|
-
|
181
|
-
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 :)
|
182
|
-
|
183
|
-
```ruby
|
184
|
-
require 'mocha/deprecation'
|
185
|
-
Mocha::Deprecation.mode = :disabled
|
186
|
-
```
|
187
|
-
|
188
|
-
### Rails 3.0.x
|
189
|
-
|
190
|
-
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.
|
191
|
-
|
192
|
-
```ruby
|
193
|
-
class UsersControllerTest < ActionController::TestCase
|
194
|
-
tests UsersController
|
195
|
-
end
|
196
|
-
class UserMailerTest < ActionMailer::TestCase
|
197
|
-
tests UserMailer
|
198
|
-
end
|
199
|
-
```
|
200
|
-
|
201
|
-
|
202
|
-
## Contributing
|
203
|
-
|
204
|
-
The minitest-spec-rails gem is fully tested from Rails 3.0 to 4 and upward. We run our tests on [Travis CI](http://travis-ci.org/metaskills/minitest-spec-rails) in both Ruby 1.8 and 1.9. 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.
|
205
|
-
|
206
|
-
```shell
|
207
|
-
$ bundle install
|
208
|
-
$ bundle exec rake appraisal:setup
|
209
|
-
$ bundle exec rake appraisal test
|
210
|
-
```
|
211
|
-
|
212
|
-
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 `rake -T` for a list. For example, the following command will run the tests for Rails 3.2 only.
|
213
|
-
|
214
|
-
```shell
|
215
|
-
$ bundle exec rake appraisal:rails32 test
|
216
|
-
```
|
217
|
-
|
218
|
-
Our current build status is:
|
219
|
-
[![Build Status](https://secure.travis-ci.org/metaskills/minitest-spec-rails.png)](http://travis-ci.org/metaskills/minitest-spec-rails)
|
220
10
|
|
data/minitest-spec-rails.gemspec
CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.require_paths = ['lib']
|
18
18
|
gem.add_runtime_dependency 'minitest', '~> 4.7'
|
19
19
|
gem.add_runtime_dependency 'rails', '~> 2.3.0'
|
20
|
-
gem.add_runtime_dependency 'minitest_tu_shim', '~> 1.3.2'
|
21
20
|
gem.add_development_dependency 'guard-minitest'
|
22
21
|
gem.add_development_dependency 'minitest-emoji'
|
23
22
|
gem.add_development_dependency 'minitest-focus'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-spec-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 3.1.
|
9
|
+
- 1
|
10
|
+
version: 3.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ken Collins
|
@@ -48,27 +48,11 @@ dependencies:
|
|
48
48
|
- 0
|
49
49
|
version: 2.3.0
|
50
50
|
requirement: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
prerelease: false
|
53
|
-
type: :runtime
|
54
|
-
name: minitest_tu_shim
|
55
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- - ~>
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 31
|
61
|
-
segments:
|
62
|
-
- 1
|
63
|
-
- 3
|
64
|
-
- 2
|
65
|
-
version: 1.3.2
|
66
|
-
requirement: *id003
|
67
51
|
- !ruby/object:Gem::Dependency
|
68
52
|
prerelease: false
|
69
53
|
type: :development
|
70
54
|
name: guard-minitest
|
71
|
-
version_requirements: &
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
72
56
|
none: false
|
73
57
|
requirements:
|
74
58
|
- - ">="
|
@@ -77,12 +61,12 @@ dependencies:
|
|
77
61
|
segments:
|
78
62
|
- 0
|
79
63
|
version: "0"
|
80
|
-
requirement: *
|
64
|
+
requirement: *id003
|
81
65
|
- !ruby/object:Gem::Dependency
|
82
66
|
prerelease: false
|
83
67
|
type: :development
|
84
68
|
name: minitest-emoji
|
85
|
-
version_requirements: &
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
86
70
|
none: false
|
87
71
|
requirements:
|
88
72
|
- - ">="
|
@@ -91,12 +75,12 @@ dependencies:
|
|
91
75
|
segments:
|
92
76
|
- 0
|
93
77
|
version: "0"
|
94
|
-
requirement: *
|
78
|
+
requirement: *id004
|
95
79
|
- !ruby/object:Gem::Dependency
|
96
80
|
prerelease: false
|
97
81
|
type: :development
|
98
82
|
name: minitest-focus
|
99
|
-
version_requirements: &
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
100
84
|
none: false
|
101
85
|
requirements:
|
102
86
|
- - ">="
|
@@ -105,12 +89,12 @@ dependencies:
|
|
105
89
|
segments:
|
106
90
|
- 0
|
107
91
|
version: "0"
|
108
|
-
requirement: *
|
92
|
+
requirement: *id005
|
109
93
|
- !ruby/object:Gem::Dependency
|
110
94
|
prerelease: false
|
111
95
|
type: :development
|
112
96
|
name: rake
|
113
|
-
version_requirements: &
|
97
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
114
98
|
none: false
|
115
99
|
requirements:
|
116
100
|
- - ">="
|
@@ -119,12 +103,12 @@ dependencies:
|
|
119
103
|
segments:
|
120
104
|
- 0
|
121
105
|
version: "0"
|
122
|
-
requirement: *
|
106
|
+
requirement: *id006
|
123
107
|
- !ruby/object:Gem::Dependency
|
124
108
|
prerelease: false
|
125
109
|
type: :development
|
126
110
|
name: sqlite3
|
127
|
-
version_requirements: &
|
111
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
128
112
|
none: false
|
129
113
|
requirements:
|
130
114
|
- - ">="
|
@@ -133,7 +117,7 @@ dependencies:
|
|
133
117
|
segments:
|
134
118
|
- 0
|
135
119
|
version: "0"
|
136
|
-
requirement: *
|
120
|
+
requirement: *id007
|
137
121
|
description: The minitest-spec-rails gem makes it easy to use the MiniTest::Spec DSL within your existing Rails 3 or 4 test suite.
|
138
122
|
email:
|
139
123
|
- ken@metaskills.net
|