minitest_should 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/README.md +79 -56
- data/lib/minitest/should.rb +3 -7
- data/lib/minitest/should/test_case.rb +20 -0
- data/lib/minitest/should/version.rb +1 -1
- data/test/test_minitest_should.rb +24 -4
- metadata +9 -15
- data/lib/minitest/should/base.rb +0 -26
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,92 +1,115 @@
|
|
1
1
|
# MiniTest Should [![Build Status](https://secure.travis-ci.org/citrus/minitest_should.png)](http://travis-ci.org/citrus/minitest_should)
|
2
2
|
|
3
|
-
minitest_should allows you to write unit tests with [shoulda](https://github.com/thoughtbot/shoulda) style syntax.
|
4
|
-
|
3
|
+
minitest_should allows you to write unit tests with [shoulda](https://github.com/thoughtbot/shoulda) style syntax.
|
5
4
|
|
5
|
+
------------------------------------------------------------------------------
|
6
6
|
Usage
|
7
|
-
|
7
|
+
------------------------------------------------------------------------------
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
When writing your mini-tests, inherit from `MiniTest::Should::TestCase`.
|
10
|
+
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "minitest"
|
14
|
+
|
15
|
+
require "minitest/autorun"
|
16
|
+
require "minitest/should"
|
17
|
+
|
18
|
+
|
19
|
+
# instead of this
|
20
|
+
class TestWithUnderscores < MiniTest::Unit::TestCase
|
21
|
+
|
22
|
+
def test_should_just_work
|
23
|
+
assert true
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_something_else_should_be_nothing
|
27
|
+
@something = "nothing"
|
28
|
+
assert_equal "nothing", @something
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
# use this!
|
34
|
+
class TestWithShould < MiniTest::Should::TestCase
|
35
|
+
|
36
|
+
should "just work" do
|
37
|
+
assert true
|
38
|
+
end
|
39
|
+
|
40
|
+
context "Something else" do
|
14
41
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def test_should_just_work
|
19
|
-
assert true
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_something_else_should_be_nothing
|
23
|
-
@something = "nothing"
|
24
|
-
assert_equal "nothing", @something
|
25
|
-
end
|
26
|
-
|
42
|
+
setup do
|
43
|
+
@something = "nothing"
|
27
44
|
end
|
28
45
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
should "just work" do
|
33
|
-
assert true
|
34
|
-
end
|
35
|
-
|
36
|
-
context "Something else" do
|
37
|
-
|
38
|
-
def setup
|
39
|
-
@something = "nothing"
|
40
|
-
end
|
41
|
-
|
42
|
-
should "be nothing" do
|
43
|
-
assert_equal "nothing", @something
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
46
|
+
should "be nothing" do
|
47
|
+
assert_equal "nothing", @something
|
48
48
|
end
|
49
49
|
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
```
|
50
54
|
|
51
|
-
|
55
|
+
------------------------------------------------------------------------------
|
52
56
|
Installation
|
53
|
-
|
57
|
+
------------------------------------------------------------------------------
|
54
58
|
|
55
59
|
As usual, just use the `gem install` command:
|
56
60
|
|
57
|
-
|
61
|
+
```bash
|
62
|
+
(sudo) gem install minitest_should
|
63
|
+
```
|
58
64
|
|
59
65
|
Or add minitest_should as a gem in your Gemfile:
|
60
66
|
|
61
|
-
|
67
|
+
```bash
|
68
|
+
gem 'minitest_should', '~> 0.3.0'
|
69
|
+
```
|
62
70
|
|
63
71
|
Then run `bundle install`
|
64
72
|
|
65
73
|
|
66
|
-
|
74
|
+
------------------------------------------------------------------------------
|
67
75
|
Testing
|
68
|
-
|
76
|
+
------------------------------------------------------------------------------
|
69
77
|
|
70
78
|
Testing is done with minitest. (duh!) Run the tests with:
|
71
79
|
|
72
|
-
|
80
|
+
```bash
|
81
|
+
rake
|
82
|
+
```
|
73
83
|
|
74
84
|
|
85
|
+
------------------------------------------------------------------------------
|
75
86
|
Changelog
|
76
|
-
|
87
|
+
------------------------------------------------------------------------------
|
88
|
+
|
89
|
+
**2012/1/20 - v0.3.0**
|
90
|
+
|
91
|
+
- don't pollute minitest/unit/testcase
|
92
|
+
- subclass minitest/spec as minitest/should/test_case
|
93
|
+
- alias before and after as setup and teardown
|
94
|
+
|
77
95
|
|
78
|
-
|
79
|
-
- add contexts
|
96
|
+
**2011/12/8 - v0.2.0**
|
80
97
|
|
81
|
-
|
82
|
-
- ensure dynamic methods have safe names
|
98
|
+
- add contexts
|
83
99
|
|
84
|
-
|
85
|
-
|
100
|
+
|
101
|
+
**2011/11/8 - v0.1.1**
|
102
|
+
|
103
|
+
- ensure dynamic methods have safe names
|
104
|
+
|
105
|
+
|
106
|
+
**2011/11/8 - v0.1.0**
|
107
|
+
|
108
|
+
- it exists!
|
86
109
|
|
87
110
|
|
88
|
-
|
111
|
+
------------------------------------------------------------------------------
|
89
112
|
License
|
90
|
-
|
113
|
+
------------------------------------------------------------------------------
|
91
114
|
|
92
|
-
Copyright (c) 2011 Spencer Steffen & Citrus, released under the New BSD License All rights reserved.
|
115
|
+
Copyright (c) 2011 - 2012 Spencer Steffen & Citrus, released under the New BSD License All rights reserved.
|
data/lib/minitest/should.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
require "minitest/unit"
|
2
|
-
require "minitest/should/base"
|
3
2
|
require "minitest/should/version"
|
4
3
|
|
5
|
-
alias :context :describe
|
6
|
-
|
7
4
|
module MiniTest
|
8
|
-
module Should
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
module Should
|
6
|
+
class DuplicateMethodError < StandardError; end
|
7
|
+
autoload :TestCase, "minitest/should/test_case"
|
12
8
|
end
|
13
9
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
class MiniTest::Should::TestCase < MiniTest::Spec
|
4
|
+
|
5
|
+
class << self
|
6
|
+
alias :setup :before unless defined?(Rails)
|
7
|
+
alias :teardown :after unless defined?(Rails)
|
8
|
+
alias :context :describe
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.should(name, &block)
|
12
|
+
method_name = [ "test_should_", name.downcase.gsub(/[^a-z0-9\_\s]+/, ' ').strip.gsub(/\s+/, "_") ].join
|
13
|
+
if self.test_methods.include?(method_name)
|
14
|
+
raise MiniTest::Should::DuplicateMethodError, "Test named `#{method_name}` already exists in #{self.name}."
|
15
|
+
else
|
16
|
+
self.send(:define_method, method_name, block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -2,7 +2,7 @@ gem "minitest"
|
|
2
2
|
require "minitest/autorun"
|
3
3
|
require "minitest/should"
|
4
4
|
|
5
|
-
class TestMiniTestShould < MiniTest::
|
5
|
+
class TestMiniTestShould < MiniTest::Should::TestCase
|
6
6
|
|
7
7
|
def setup
|
8
8
|
@something = "nothing"
|
@@ -16,8 +16,8 @@ class TestMiniTestShould < MiniTest::Unit::TestCase
|
|
16
16
|
assert_equal String, MiniTest::Should::VERSION.class
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
assert self.class.
|
19
|
+
def test_case_extends_minitest_unit_test_case
|
20
|
+
assert self.class.ancestors.include?(MiniTest::Unit::TestCase)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_respond_to_should
|
@@ -80,13 +80,33 @@ class TestMiniTestShould < MiniTest::Unit::TestCase
|
|
80
80
|
should "make this true" do
|
81
81
|
assert true
|
82
82
|
end
|
83
|
+
|
84
|
+
should "work with the parent tests instance variables" do
|
85
|
+
assert_equal "nothing", @something
|
86
|
+
end
|
87
|
+
|
88
|
+
should "work with the parent tests instance methods" do
|
89
|
+
assert_equal "blank", nothing
|
90
|
+
end
|
83
91
|
|
84
92
|
context "with a another context" do
|
93
|
+
|
94
|
+
setup do
|
95
|
+
@something = "not-nothing"
|
96
|
+
end
|
85
97
|
|
98
|
+
teardown do
|
99
|
+
assert "not-nothing", @something
|
100
|
+
end
|
101
|
+
|
86
102
|
should "just keep on keepin' on" do
|
87
103
|
assert true
|
88
104
|
end
|
89
|
-
|
105
|
+
|
106
|
+
should "manipulate the parent tests instance variables in setup" do
|
107
|
+
assert_equal "not-nothing", @something
|
108
|
+
end
|
109
|
+
|
90
110
|
end
|
91
111
|
|
92
112
|
context "with the same method names as another context" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest_should
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70318086885480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>'
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70318086885480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70318086884980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>'
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70318086884980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: minitest
|
38
|
-
requirement: &
|
38
|
+
requirement: &70318086884520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>'
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '2'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70318086884520
|
47
47
|
description: Shoulda style syntax for minitest test::unit. Contexts are not yet supported,
|
48
48
|
but you can use `should "do something"` instead of those `pesky_underscored_test_names`.
|
49
49
|
Please see documentation for more information.
|
@@ -60,7 +60,7 @@ files:
|
|
60
60
|
- README.md
|
61
61
|
- Rakefile
|
62
62
|
- lib/minitest/should.rb
|
63
|
-
- lib/minitest/should/
|
63
|
+
- lib/minitest/should/test_case.rb
|
64
64
|
- lib/minitest/should/version.rb
|
65
65
|
- minitest_should.gemspec
|
66
66
|
- test/test_minitest_should.rb
|
@@ -76,18 +76,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- - ! '>='
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
hash: -18762255773632330
|
82
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
80
|
none: false
|
84
81
|
requirements:
|
85
82
|
- - ! '>='
|
86
83
|
- !ruby/object:Gem::Version
|
87
84
|
version: '0'
|
88
|
-
segments:
|
89
|
-
- 0
|
90
|
-
hash: -18762255773632330
|
91
85
|
requirements: []
|
92
86
|
rubyforge_project: minitest_should
|
93
87
|
rubygems_version: 1.8.10
|
data/lib/minitest/should/base.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module MiniTest
|
2
|
-
module Should
|
3
|
-
module Base
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
base.extend ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
|
11
|
-
def should(name, &block)
|
12
|
-
method_name = [ "test_should_", name.downcase.gsub(/[^a-z0-9\_\s]+/, ' ').strip.gsub(/\s+/, "_") ].join
|
13
|
-
if self.test_methods.include?(method_name)
|
14
|
-
raise MiniTest::Should::DuplicateMethodError, "Test named `#{method_name}` already exists in #{self.name}."
|
15
|
-
else
|
16
|
-
self.send(:define_method, method_name, block)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
MiniTest::Unit::TestCase.send(:include, MiniTest::Should::Base)
|