minitest-spec-rails 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +31 -48
- data/lib/minitest-spec-rails/test_case.rb +33 -3
- data/lib/minitest-spec-rails/version.rb +1 -1
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
|
2
|
+
## v3.0.3
|
3
|
+
|
4
|
+
* Stronger test case organization where we properly setup functional and integraiton tests
|
5
|
+
while also allowing an alternate pure MiniTest::Spec outter file describe block. [Jack Chu]
|
6
|
+
|
2
7
|
## v3.0.2
|
3
8
|
|
4
9
|
* Remove version deps on minitest since v3 is out. Should work with any v2/3 version.
|
data/README.md
CHANGED
@@ -1,80 +1,63 @@
|
|
1
1
|
# MiniTest::Spec For Rails
|
2
2
|
|
3
|
-
|
4
3
|
This gem makes it easy to use the MiniTest Spec DSL in Rails 3 application tests.
|
5
4
|
|
6
|
-
|
7
|
-
# Example Gemfile
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'minitest-spec-rails'
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
# Example Test
|
15
|
-
|
16
|
-
# ./test/unit/myclass_test.rb
|
17
|
-
require 'test_helper'
|
18
|
-
class MyClassTest < ActiveSupport::TestCase
|
19
|
-
it "does something"
|
20
|
-
100.must_equal 100
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Example Run
|
25
|
-
|
26
|
-
$ ruby -Itest test/unit/myclass_test.rb
|
27
|
-
...
|
28
|
-
MyClassTest
|
29
|
-
PASS test_0001_does_something (0:00:00.002)
|
30
|
-
...
|
31
|
-
|
32
|
-
|
33
5
|
# Advantages
|
34
6
|
|
35
7
|
With minitest-spec-rails, we have a working solution by replacing MiniTest::Spec as the superclass for ActiveSupport::TestCase. This solution is simple and does not require you to recreate a new test case in your test_helper.rb or to use generators supplied by gems like minitest-rails.
|
36
8
|
|
37
|
-
MinitTest::Spec is built on top of MiniTest::Unit which a replacement for Test::Unit, so is stable and consistent.
|
38
|
-
|
39
|
-
It's easy to change an existing Rails application from Test Unit to MiniTest::Spec simply installing this gem.
|
40
|
-
|
41
|
-
As Rails evolves to leverage MiniTest::Spec, your test case code will not have to change.
|
42
|
-
|
9
|
+
MinitTest::Spec is built on top of MiniTest::Unit which a replacement for Test::Unit, so is stable and consistent. It's easy to change an existing Rails application from Test Unit to MiniTest::Spec simply installing this gem. As Rails evolves to leverage MiniTest::Spec, your test case code will not have to change at both the class definition and internals.
|
43
10
|
|
44
11
|
# How it works
|
45
12
|
|
46
|
-
|
47
|
-
This gem makes Test::Unit::TestCase a subclass of of MiniTest::Spec with a simple shim.
|
48
|
-
|
49
|
-
The gem tricks ActiveSupport::TestCase to use MiniTest::Spec instead. The gem includes any monkey patches to make using MiniTest::Spec a drop in behavior change for any Rails 3.x project.
|
13
|
+
This gem makes Test::Unit::TestCase a subclass of of MiniTest::Spec with a simple shim. The gem tricks ActiveSupport::TestCase to use MiniTest::Spec instead. The gem includes any monkey patches to make using MiniTest::Spec a drop in behavior change for any Rails 3.x project.
|
50
14
|
|
51
15
|
Full Details here:
|
52
16
|
|
53
17
|
http://metaskills.net/2011/03/26/using-minitest-spec-with-rails/
|
54
18
|
|
55
|
-
|
56
19
|
# Styles
|
57
20
|
|
21
|
+
This <a href="http://cheat.errtheblog.com/s/minitest/1">cheat sheet</a> shows the Test::Unit assert methods and the MiniTest::Spec methods. 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.
|
58
22
|
|
59
|
-
|
60
|
-
|
61
|
-
Test Unit style:
|
23
|
+
Test::Unit Style:
|
62
24
|
|
63
|
-
assert_equal 100, foo
|
25
|
+
assert_equal 100, foo
|
64
26
|
|
65
|
-
MiniTest::Spec
|
27
|
+
MiniTest::Spec Style:
|
66
28
|
|
67
29
|
foo.must_equal 100
|
68
30
|
|
31
|
+
There are a few missing assertions available in Test::Unit that are changed or no longer available in MiniTest.
|
69
32
|
|
70
|
-
|
33
|
+
* The method <code>assert_raise</code> is renamed <code>assert_raises</code>.
|
34
|
+
* There is no method <code>assert_nothing_raised</code>. There are good reasons for this on Ryan's blog.
|
71
35
|
|
72
|
-
|
36
|
+
# Alternate MiniTest::Spec Describe
|
73
37
|
|
74
|
-
|
38
|
+
It is also possible to change the style of your test files and their super classes. In these examples below, the gem will take care of setting your super class and proper setups.
|
75
39
|
|
76
|
-
|
40
|
+
# ./test/unit/post_test.rb
|
41
|
+
require 'test_helper'
|
42
|
+
describe Post do
|
43
|
+
it "must be valid" do
|
44
|
+
@post.must_be :valid?
|
45
|
+
end
|
46
|
+
end
|
77
47
|
|
48
|
+
# ./test/functional/posts_controller_test.rb
|
49
|
+
require 'test_helper'
|
50
|
+
describe PostController do
|
51
|
+
describe "on GET to :show" do
|
52
|
+
before do
|
53
|
+
get :show, id: "1"
|
54
|
+
end
|
55
|
+
it "returns a post object " do
|
56
|
+
post = assigns(:post)
|
57
|
+
post.wont_be_nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
78
61
|
|
79
62
|
# Issues
|
80
63
|
|
@@ -1,3 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
if defined?(ActiveSupport::TestCase)
|
2
|
+
class << ActiveSupport::TestCase
|
3
|
+
remove_method :describe
|
4
|
+
end
|
5
|
+
|
6
|
+
MiniTest::Spec.register_spec_type ActiveSupport::TestCase do |desc|
|
7
|
+
desc.respond_to?(:ancestors) && !(desc.ancestors.map(&:to_s) & ["ActiveRecord::Base", "Mongoid::Document", "MongoMapper::Document", "DataMapper::Resource"]).empty?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
if defined?(ActionController::TestCase)
|
12
|
+
class ActionController::TestCase
|
13
|
+
def self.determine_default_controller_class(name)
|
14
|
+
if name.match(/.*(?:^|::)(\w+Controller)/)
|
15
|
+
$1.safe_constantize
|
16
|
+
else
|
17
|
+
super(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
before { setup_controller_request_and_response }
|
22
|
+
end
|
23
|
+
|
24
|
+
MiniTest::Spec.register_spec_type /Controller/, ActionController::TestCase
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined?(ActionDispatch::IntegrationTest)
|
28
|
+
class ActionDispatch::IntegrationTest
|
29
|
+
before { self.app = Rails.application }
|
30
|
+
end
|
31
|
+
|
32
|
+
MiniTest::Spec.register_spec_type /Integration Test$/, ActionDispatch::IntegrationTest
|
33
|
+
end
|
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
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.
|
9
|
+
- 3
|
10
|
+
version: 3.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ken Collins
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-22 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|