minitest-spec-rails-orangejulius 5.0.3.pre.orangejulius

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.travis.yml +12 -0
  4. data/Appraisals +3 -0
  5. data/CHANGELOG.md +142 -0
  6. data/Gemfile +4 -0
  7. data/MIT-LICENSE +22 -0
  8. data/README.md +290 -0
  9. data/Rakefile +19 -0
  10. data/lib/minitest-spec-rails/dsl.rb +41 -0
  11. data/lib/minitest-spec-rails/init/action_controller.rb +26 -0
  12. data/lib/minitest-spec-rails/init/action_dispatch.rb +16 -0
  13. data/lib/minitest-spec-rails/init/action_mailer.rb +27 -0
  14. data/lib/minitest-spec-rails/init/action_view.rb +26 -0
  15. data/lib/minitest-spec-rails/init/active_support.rb +35 -0
  16. data/lib/minitest-spec-rails/init/mini_shoulda.rb +27 -0
  17. data/lib/minitest-spec-rails/railtie.rb +28 -0
  18. data/lib/minitest-spec-rails/version.rb +3 -0
  19. data/lib/minitest-spec-rails.rb +10 -0
  20. data/minitest-spec-rails.gemspec +24 -0
  21. data/test/cases/action_controller_test.rb +41 -0
  22. data/test/cases/action_dispatch_test.rb +50 -0
  23. data/test/cases/action_mailer_test.rb +42 -0
  24. data/test/cases/action_view_test.rb +44 -0
  25. data/test/cases/active_support_test.rb +68 -0
  26. data/test/cases/mini_shoulda_test.rb +38 -0
  27. data/test/dummy_app/app/controllers/application_controller.rb +7 -0
  28. data/test/dummy_app/app/controllers/users_controller.rb +12 -0
  29. data/test/dummy_app/app/helpers/application_helper.rb +3 -0
  30. data/test/dummy_app/app/helpers/foos_helper.rb +11 -0
  31. data/test/dummy_app/app/helpers/users_helper.rb +9 -0
  32. data/test/dummy_app/app/mailers/user_mailer.rb +10 -0
  33. data/test/dummy_app/app/models/post.rb +6 -0
  34. data/test/dummy_app/app/models/user.rb +6 -0
  35. data/test/dummy_app/app/views/users/index.html.erb +2 -0
  36. data/test/dummy_app/config/database.yml +6 -0
  37. data/test/dummy_app/config/routes.rb +4 -0
  38. data/test/dummy_app/init.rb +38 -0
  39. data/test/dummy_app/lib/library.rb +2 -0
  40. data/test/dummy_app/tmp/.gitkeep +0 -0
  41. data/test/dummy_tests/application_controller_test.rb +87 -0
  42. data/test/dummy_tests/foos_helper_test.rb +17 -0
  43. data/test/dummy_tests/integration_test.rb +49 -0
  44. data/test/dummy_tests/library_test.rb +15 -0
  45. data/test/dummy_tests/user_mailer_test.rb +85 -0
  46. data/test/dummy_tests/user_test.rb +76 -0
  47. data/test/dummy_tests/users_controller_test.rb +26 -0
  48. data/test/dummy_tests/users_helper_test.rb +77 -0
  49. data/test/support/shared_test_case_behavior.rb +31 -0
  50. data/test/test_helper.rb +11 -0
  51. data/test/test_helper_dummy.rb +9 -0
  52. metadata +196 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d87e7075302d785455b782511212e975fe042c5e
4
+ data.tar.gz: 9d175d652bb955068bb1d4ad2aa2ae5c15a36abc
5
+ SHA512:
6
+ metadata.gz: 929f40dedfad705694a76a7e4147544b803ed80dfb5bc8d8b84f0e533921ab8057b569aab2ac3345d67daa1dfe8d04793be8d11cd2277c297fd8767087e62de7
7
+ data.tar.gz: d0076efa0c9ccf441b4139eb0beae061484c6e59e4f426ca73372f5aa69d28cd633fc65210dc6fb494853db6766b30d9db602b92d9a6caa609751497f6a79098
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ .ruby-version
4
+ gemfiles/*
5
+ Gemfile.lock
6
+ pkg/*
7
+ *.log
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.1
5
+ install:
6
+ - gem install bundler
7
+ - bundle --version
8
+ - bundle install
9
+ before_script:
10
+ - bundle exec rake appraisal:setup
11
+ script:
12
+ - bundle exec rake appraisal test
data/Appraisals ADDED
@@ -0,0 +1,3 @@
1
+
2
+ appraise 'rails41' do
3
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,142 @@
1
+
2
+ ## 5.0.3
3
+
4
+ * Fixed ActionView load order & url helpers. Fixes #42.
5
+
6
+
7
+ ## 5.0.2
8
+
9
+ * Fixed initialization callbacks for latest Rails 4.1. Fixes #39.
10
+
11
+
12
+ ## 5.0.1
13
+
14
+ * Change initialization so that ActiveSupport always comes first.
15
+
16
+
17
+ ## 5.0.0
18
+
19
+ * Minitest 5.x and Rails 4.1 compatability. Fixes #36.
20
+ * Fix nested described test names along with Minitest::Spec.describe_stack. Fixed #21.
21
+ * Leverage `ActiveSupport::Testing::ConstantLookup` for our `described_class` interface.
22
+
23
+
24
+ ## 4.7.6
25
+
26
+ * Fix nested described test names. Fixes #21.
27
+
28
+
29
+ ## 4.7.5
30
+
31
+ * Fixed gemspec using '>= 3.0', '< 4.1'. Fixed #35.
32
+
33
+
34
+ ## 4.7.4
35
+
36
+ * Enforces case sensitivity on registered spec types. Fixes #26.
37
+
38
+
39
+ ## 4.7.3
40
+
41
+ * Allow using ActiveSupport's Declarative#test as an alias to it. Thanks @ysbaddaden. Fixes #23.
42
+
43
+
44
+ ## 4.7.2
45
+
46
+ * Register non ActiveRecord::Base classes correctly. Thanks @mptre.
47
+
48
+
49
+ ## 4.7.1
50
+
51
+ * Only use a TU shim for Ruby 1.8. See README for info. Fixes #18.
52
+
53
+
54
+ ## 4.7.0
55
+
56
+ * Use Minitest::Spec::DSL provided by Minitest 4.7.
57
+
58
+
59
+ ## 4.3.8
60
+
61
+ * Less coupling to ActiveRecord ORM, works for MongoDB now. Thanks @kimsuelim
62
+
63
+
64
+ ## v4.3.7
65
+
66
+ * Fix helper test bug where calling methods in first context block blew up. Fixes #13.
67
+
68
+
69
+ ## v4.3.6
70
+
71
+ * Only require the freedom patches and autorun when Rails.env.test?
72
+
73
+
74
+ ## v4.3.5
75
+
76
+ * Make sure #described_class works in ActiveSupport::TestCase class level.
77
+
78
+
79
+ ## v4.3.4
80
+
81
+ * Add mini_should support and talk about matchers.
82
+
83
+
84
+ ## v4.3.3
85
+
86
+ * Fix MiniTest::Unit::TestCase hack for Rails 4, ignore in Rails 3.
87
+
88
+
89
+ ## v4.3.2
90
+
91
+ * Way better support for controller_class, mailer_class, and helper_class reflection.
92
+
93
+
94
+ ## v4.3.1
95
+
96
+ * Eager load controller_class, mailer_class, and helper_class.
97
+
98
+
99
+ ## v4.3.0
100
+
101
+ * All new MiniTest::Spec for Rails!!! Tested to the hilt!!!
102
+ * Track MiniTest's major/minior version number.
103
+
104
+
105
+ ## v3.0.7
106
+
107
+ * Must use MiniTest version ~> 2.1. As 3.x will not work.
108
+
109
+
110
+ ## v3.0.6
111
+
112
+ * Use #constantize vs. #safe_constantize for Rails 3.0 compatability.
113
+
114
+
115
+ ## v3.0.5
116
+
117
+ * Use ActionController::IntegrationTest vs. ActionDispatch::IntegrationTest
118
+
119
+
120
+ ## v3.0.4
121
+
122
+ * Use class app setter for integration tests.
123
+
124
+
125
+ ## v3.0.3
126
+
127
+ * Stronger test case organization where we properly setup functional and integraiton tests
128
+ while also allowing an alternate pure MiniTest::Spec outter file describe block. [Jack Chu]
129
+
130
+
131
+ ## v3.0.2
132
+
133
+ * Remove version deps on minitest since v3 is out. Should work with any v2/3 version.
134
+
135
+
136
+ ## v3.0.1
137
+
138
+ * Add rails to the gemspec.
139
+
140
+ ## v3.0.0
141
+
142
+ * Initial Release, targeted to Rails 3.x.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Ken Collins, <ken@metaskills.net>
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.
data/README.md ADDED
@@ -0,0 +1,290 @@
1
+ <img src="http://cdn.metaskills.net/minitest-spec-rails.png" width="233" height="154" />
2
+
3
+ # Make Rails Use MiniTest::Spec!
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.
7
+
8
+ [![Gem Version](https://badge.fury.io/rb/minitest-spec-rails.png)](http://badge.fury.io/rb/minitest-spec-rails)
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)
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
19
+
20
+ Our master branch is tracking rails master which is active development for Rails 4.1 which uses minitest 5.0.
21
+
22
+
23
+ #### For Rails 3.x or 4.0
24
+
25
+ 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.
26
+
27
+ ```ruby
28
+ group :test do
29
+ gem 'minitest-spec-rails'
30
+ end
31
+ ```
32
+
33
+ #### For Rails 2.3
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!!!
44
+
45
+ If you are using Ruby 1.8, you must install a Test::Unit shim that subclasses MiniTest::Unit, just as Ruby 1.9 does. We have kindly packed up Ruby 1.9's `lib/test` directory in the [minitest-spec-rails-tu-shim](https://github.com/metaskills/minitest-spec-rails-tu-shim) gem. So just add this to your Gemfile.
46
+
47
+ ```ruby
48
+ group :test do
49
+ gem 'minitest-spec-rails-tu-shim'
50
+ end
51
+ ```
52
+
53
+
54
+ ### How is this different than MiniTest::Rails?
55
+
56
+ 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
+
58
+ * We aim to leverage existing Rails test directories and files!
59
+ * No special test helper and/or generators.
60
+ * Easy migration path for existing Rails applications.
61
+ * How we go about freedom patching Rails.
62
+ * Fully support Ruby 1.8.7 with all legacy Test::Unit behavior.
63
+ * Compatibility with ActiveSupport::TestCase's setup and teardowns.
64
+
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 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
+
67
+ ```ruby
68
+ gem 'minitest-spec-rails'
69
+ ```
70
+
71
+
72
+ ## Test Styles
73
+
74
+ 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 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
+
76
+ ```ruby
77
+ # MiniTest::Unit Assertion Style:
78
+ assert_equal 100, foo
79
+
80
+ # MiniTest::Spec Assertion Style:
81
+ foo.must_equal 100
82
+ ```
83
+
84
+
85
+ ```ruby
86
+ require 'test_helper'
87
+ class UserTest < ActiveSupport::TestCase
88
+ let(:user_ken) { User.create! :email => 'ken@metaskills.net' }
89
+ it 'works' do
90
+ user_ken.must_be_instance_of User
91
+ end
92
+ end
93
+ ```
94
+
95
+ ```ruby
96
+ require 'test_helper'
97
+ describe User do
98
+ # This will work too.
99
+ end
100
+ ```
101
+
102
+ 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.
103
+
104
+ ```ruby
105
+ # Model Test
106
+ class UserTest < ActiveSupport::TestCase
107
+ end
108
+ describe User do
109
+ end
110
+
111
+ # Controller Test
112
+ class UsersControllerTest < ActionController::TestCase
113
+ end
114
+ describe UsersController do
115
+ end
116
+
117
+ # Integration Tests - Must use subclass style!
118
+ class IntegrationTest < ActionDispatch::IntegrationTest
119
+ end
120
+
121
+ # Mailer Test
122
+ class UserMailerTest < ActionMailer::TestCase
123
+ end
124
+ describe UserMailer do
125
+ end
126
+
127
+ # View Helper Test
128
+ class UsersHelperTest < ActionView::TestCase
129
+ end
130
+ describe UsersHelper do
131
+ end
132
+ ```
133
+
134
+
135
+ ## Extras
136
+
137
+ 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.
138
+
139
+ ### #described_class
140
+ 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.
141
+
142
+ ```ruby
143
+ class UserTest < ActiveSupport::TestCase
144
+ described_class # => User(id: integer, email: string)
145
+ it 'works here' do
146
+ described_class # => User(id: integer, email: string)
147
+ end
148
+ describe 'and' do
149
+ it 'works here too' do
150
+ described_class # => User(id: integer, email: string)
151
+ end
152
+ end
153
+ end
154
+ ```
155
+
156
+ ### Setup & Teardown Compatability
157
+
158
+ 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!
159
+
160
+ ```ruby
161
+ class ActiveSupportCallbackTest < ActiveSupport::TestCase
162
+
163
+ setup :foo
164
+ setup :bar
165
+ before { @bat = 'biz' }
166
+
167
+ it 'works' do
168
+ @foo.must_equal 'foo'
169
+ @bar.must_equal 'bar'
170
+ @bat.must_equal 'biz'
171
+ end
172
+
173
+ private
174
+
175
+ def foo ; @foo = 'foo' ; end
176
+ def bar ; @bar = 'bar' ; end
177
+
178
+ end
179
+ ```
180
+
181
+ ### mini_shoulda
182
+
183
+ 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.
184
+
185
+ ```ruby
186
+ # In config/environments/test.rb
187
+ config.minitest_spec_rails.mini_shoulda = true
188
+ ```
189
+
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 [should-context](https://github.com/thoughtbot/shoulda-context) in a few lines of code.
191
+
192
+ ```ruby
193
+ class PostTests < ActiveSupport::TestCase
194
+ setup { @post = Post.create! :title => 'Test Title', :body => 'Test body' }
195
+ teardown { Post.delete_all }
196
+ should 'work' do
197
+ @post.must_be_instance_of Post
198
+ end
199
+ context 'with a user' do
200
+ should_eventually 'have a user' do
201
+ # ...
202
+ end
203
+ end
204
+ end
205
+ ```
206
+
207
+ 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.
208
+
209
+ ```ruby
210
+ assert_same_elements a, b # From
211
+ a.sort.must_equal b.sort # To
212
+
213
+ assert_does_not_contain a, b # From
214
+ a.wont_include b # To
215
+ ```
216
+
217
+ ### Matchers
218
+
219
+ **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.
220
+
221
+ ```ruby
222
+ describe Post do
223
+ subject { Post.new }
224
+ it { must have_valid(:title).when("Hello") }
225
+ it { wont have_valid(:title).when("", nil, "Bad") }
226
+ end
227
+ ```
228
+
229
+
230
+ ## Gotchas
231
+
232
+ ### Assertion Methods
233
+
234
+ 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
+
236
+ * The method `assert_raise` is renamed `assert_raises`.
237
+ * 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
+
239
+ ### Mocha
240
+
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 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
+
243
+ ```ruby
244
+ require 'mocha/deprecation'
245
+ Mocha::Deprecation.mode = :disabled
246
+ ```
247
+
248
+ ### Rails 3.0.x
249
+
250
+ 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.
251
+
252
+ ```ruby
253
+ class UsersControllerTest < ActionController::TestCase
254
+ tests UsersController
255
+ end
256
+ class UserMailerTest < ActionMailer::TestCase
257
+ tests UserMailer
258
+ end
259
+ ```
260
+
261
+ ### Rails 3.1 & 3.2
262
+
263
+ 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.
264
+
265
+
266
+ ## Contributing
267
+
268
+ We run our tests on [Travis CI](http://travis-ci.org/metaskills/minitest-spec-rails). 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
+
270
+ ```shell
271
+ $ bundle install
272
+ $ bundle exec rake appraisal:setup
273
+ $ bundle exec rake appraisal test
274
+ ```
275
+
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 `rake -T` for a list. For example, the following command will run the tests for Rails 4.1 only.
277
+
278
+ ```shell
279
+ $ bundle exec rake appraisal:rails41 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
+
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
+
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+ require 'appraisal'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs = ['lib','test']
8
+ t.test_files = Dir.glob("test/**/*_test.rb").sort
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
13
+
14
+ desc "Setup Appraisal."
15
+ task 'appraisal:setup' do
16
+ Rake::Task['appraisal:cleanup'].invoke
17
+ Rake::Task['appraisal:gemfiles'].invoke
18
+ Rake::Task['appraisal:install'].invoke
19
+ end
@@ -0,0 +1,41 @@
1
+ module MiniTestSpecRails
2
+ module DSL
3
+
4
+ def self.included(klass)
5
+ klass.extend ClassMethods
6
+ remove_method :test if method_defined?(:test)
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ def describe(*args, &block)
12
+ stack = Minitest::Spec.describe_stack
13
+ stack.push self if stack.empty?
14
+ super(*args) { class_eval(&block) }
15
+ stack.pop if stack.length == 1
16
+ end
17
+
18
+ def before(type = nil, &block)
19
+ setup { self.instance_eval(&block) }
20
+ end
21
+
22
+ def after(type = nil, &block)
23
+ teardown { self.instance_eval(&block) }
24
+ end
25
+
26
+ def test(name, &block)
27
+ it(name) { self.instance_eval(&block) }
28
+ end
29
+
30
+ def described_class
31
+ nil
32
+ end
33
+
34
+ end
35
+
36
+ def described_class
37
+ self.class.described_class
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActionControllerBehavior
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ extend Descriptions
9
+ register_spec_type(self) { |desc| Class === desc && desc < ActionController::Metal }
10
+ register_spec_type(/Controller( ?Test)?\z/, self)
11
+ register_spec_type(self) { |desc| Class === desc && desc < self }
12
+ end
13
+
14
+ module Descriptions
15
+
16
+ def described_class
17
+ determine_default_controller_class(name)
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+
26
+ ActionController::TestCase.send :include, MiniTestSpecRails::Init::ActionControllerBehavior
@@ -0,0 +1,16 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActionDispatchBehavior
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ register_spec_type(/(Acceptance|Integration) ?Test\z/, self)
9
+ register_spec_type(self) { |desc| Class === desc && desc < self }
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+
16
+ ActionDispatch::IntegrationTest.send :include, MiniTestSpecRails::Init::ActionDispatchBehavior
@@ -0,0 +1,27 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActionMailerBehavior
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ register_spec_type(self) { |desc| Class === desc && desc < ActionMailer::Base }
9
+ register_spec_type(/Mailer( ?Test)?\z/, self)
10
+ register_spec_type(self) { |desc| Class === desc && desc < self }
11
+ extend Descriptions
12
+ end
13
+
14
+ module Descriptions
15
+
16
+ def described_class
17
+ determine_default_mailer(name)
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+
26
+ ActionMailer::TestCase.send :include, MiniTestSpecRails::Init::ActionMailerBehavior
27
+
@@ -0,0 +1,26 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActionViewBehavior
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ class_attribute :_helper_class
9
+ register_spec_type(/(Helper|View)( ?Test)?\z/, self)
10
+ register_spec_type(self) { |desc| Class === desc && desc < self }
11
+ extend Descriptions
12
+ end
13
+
14
+ module Descriptions
15
+
16
+ def described_class
17
+ determine_default_helper_class(name)
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+
26
+ ActionView::TestCase.send :include, MiniTestSpecRails::Init::ActionViewBehavior
@@ -0,0 +1,35 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module ActiveSupportBehavior
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ singleton_class.class_eval { remove_method :describe }
9
+ extend MiniTest::Spec::DSL
10
+ include MiniTestSpecRails::DSL
11
+ include ActiveSupport::Testing::ConstantLookup
12
+ extend Descriptions
13
+ register_spec_type(self) { |desc| Class === desc }
14
+ end
15
+
16
+ module Descriptions
17
+
18
+ def described_class
19
+ determine_constant_from_test_name(name) do |constant|
20
+ Class === constant
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ def initialize(*args)
27
+ Thread.current[:current_spec] = self
28
+ super
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+
35
+ ActiveSupport::TestCase.send :include, MiniTestSpecRails::Init::ActiveSupportBehavior