minitest-english 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/.travis.yml +3 -0
- data/Gemfile +0 -2
- data/README.md +53 -6
- data/lib/minitest/english.rb +86 -2
- data/lib/minitest/english/deny.rb +3 -0
- data/lib/minitest/english/must_not.rb +3 -0
- data/minitest-english.gemspec +8 -2
- data/test/{assertions_test.rb → assertion_deny_test.rb} +3 -2
- data/test/{expectations_test.rb → expectation_must_not_test.rb} +2 -1
- data/test/registration_test.rb +69 -0
- data/test/test_helper.rb +9 -0
- metadata +95 -9
- data/lib/minitest-english.rb +0 -1
- data/lib/minitest/english/assertions.rb +0 -8
- data/lib/minitest/english/expectations.rb +0 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODEwNzEwZTI2NGVhMTk3MGIxYzI2NTIzZTQxYzA5OGIxY2VlY2Q5NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmMwMjg3NWM5YzJjNTZlZDNiNTI4Mzg2YTg4ZDVlYTk5NzBkODZlYQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Yzk1MmUyYmUzY2UyMmU4OWU2MzY1MmU1NTRkZTVjNGM4YjViYzY5NGU0OTU0
|
10
|
+
MzkwYmFmMTRhOWRkN2UyZDFlYWQ2NTljZjM2MzMzM2M4NGNiNjM3ZDAwNDJi
|
11
|
+
MjFjNmJlOTk2ZDQ1Y2NkODY2ZjYyMDIzMzVlYjdhMjRiYzY4YzE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmJjMGY5NjllYmQwZmZmNTY1MWNhZWZiNjdjZmUyNTMwZjlmNzQ2YjFmOWVl
|
14
|
+
MDRiMDU1OTBmZDU3OTUxODAxZmI4NzNkNWU5ZDA4MjgwNGIzMDk1ZmI5MzBh
|
15
|
+
OTNjOTY4MjM3NTBjMjE2OGI4OWM4N2JjZGJhOGJjMGJmODhlNTA=
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# minitest-english
|
1
|
+
# minitest-english [](https://rubygems.org/gems/minitest-english) [](https://travis-ci.org/DomKM/minitest-english)
|
2
2
|
|
3
|
-
MiniTest is an awesome testing framework. It's small, fast, and has very little magic.
|
3
|
+
[MiniTest](https://github.com/seattlerb/minitest) is an awesome testing framework. It's small, fast, and has very little magic.
|
4
4
|
|
5
5
|
> There are two hard things in Computer Science: cache invalidation and naming things.
|
6
6
|
> — Phil Karlton
|
@@ -11,7 +11,7 @@ Unfortunately, MiniTest fails at the latter.
|
|
11
11
|
|
12
12
|
## What?
|
13
13
|
|
14
|
-
`minitest-english` augments MiniTest's assertion and expectation naming with semantically symmetric aliases.
|
14
|
+
`minitest-english` provides a simple interface for defining aliases in MiniTest assertions, expectations, and other modules/classes. It also optionally augments MiniTest's default assertion and expectation naming with semantically symmetric aliases.
|
15
15
|
|
16
16
|
## Why?
|
17
17
|
|
@@ -45,11 +45,11 @@ __"Must" is present tense but "wont" (contraction of "will not") is future tense
|
|
45
45
|
|
46
46
|
## How?
|
47
47
|
|
48
|
-
`minitest-english`
|
48
|
+
`minitest-english` provides an interface for watching and aliasing methods in MiniTest::Assertions, MiniTest::Expectations, and other modules. Once a module/class and aliasing rule is registered with `MiniTest::English`, all current and future methods in the module/class that match the rule will be aliased according to that rule.
|
49
49
|
|
50
|
-
|
50
|
+
`minitest-english` also _optionally_ aliases all `refute` assertions with `deny` assertions and all `wont` expectations with `must_not` expectations.
|
51
51
|
|
52
|
-
|
52
|
+
It's simple and does not use `method_missing` or any other inefficient techniques.
|
53
53
|
|
54
54
|
|
55
55
|
## Installation
|
@@ -65,18 +65,65 @@ And then execute:
|
|
65
65
|
Require it in your test_helper or spec_helper:
|
66
66
|
|
67
67
|
require 'minitest/english'
|
68
|
+
|
69
|
+
To alias all `refute*` assertions to `deny*` assertions:
|
70
|
+
|
71
|
+
require 'minitest/english/deny'
|
72
|
+
|
73
|
+
To alias all `wont*` expectations to `must_not*` expectations:
|
74
|
+
|
75
|
+
require 'minitest/english/must_not'
|
68
76
|
|
69
77
|
## Usage
|
70
78
|
|
79
|
+
### Registering assertions and expectations
|
80
|
+
|
81
|
+
The basic format is:
|
82
|
+
|
83
|
+
MiniTest::English.register_assertion/expectation, matcher_string, replacement_string
|
84
|
+
|
85
|
+
Let's register an expectation:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
MiniTest::English.register_expectation "wont*", "must_not*"
|
89
|
+
```
|
90
|
+
|
91
|
+
That will alias all expectations that begin with `wont` to ones that begin with `must_not`. `register_assertion` works the same way.
|
92
|
+
|
93
|
+
### Advanced registrations
|
94
|
+
|
95
|
+
`MiniTest::English`'s `register_assertion` and `register_expectation` methods are just sugar that transform their input and send it to `MinTest::English.register`.
|
96
|
+
|
97
|
+
`MiniTest::English.register` takes a module/class, a regex that matches undesirable methods and captures the desirable parts of those methods, and a block that receives the captures and returns a symbol/string of the new method name.
|
98
|
+
These two methods produce the same result:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
MiniTest::English.register_expectation "wont*", "must_not*"
|
102
|
+
```
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
MiniTest::English.register MiniTest::Expectations, /\Awont(.*)\z/ do |captures|
|
106
|
+
:"must_not#{captures[0]}"
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
`MiniTest::English.register` is provided as a more flexible but verbose interface to deal with other classes/modules and other edge cases.
|
111
|
+
|
112
|
+
### deny & must_not
|
113
|
+
|
114
|
+
##### minitest/english/deny
|
71
115
|
Write your negative assertions with `deny`.
|
72
116
|
```ruby
|
117
|
+
require 'minitest/english/deny'
|
73
118
|
refute_equal "English", "Do you speak it?"
|
74
119
|
# refute* becomes deny*
|
75
120
|
deny_equal "English", "Do you speak it?"
|
76
121
|
```
|
77
122
|
|
123
|
+
##### minitest/english/must_not
|
78
124
|
Write your negative expectations with `must_not`.
|
79
125
|
```ruby
|
126
|
+
require 'minitest/english/must_not
|
80
127
|
"Do you speak it?".wont_equal "English"
|
81
128
|
# wont* becomes must_not*
|
82
129
|
"Do you speak it?".must_not_equal "English"
|
data/lib/minitest/english.rb
CHANGED
@@ -1,2 +1,86 @@
|
|
1
|
-
require 'minitest/
|
2
|
-
require 'minitest/
|
1
|
+
require 'minitest/unit'
|
2
|
+
require 'minitest/spec'
|
3
|
+
|
4
|
+
module MiniTest
|
5
|
+
module English
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def register_assertion(matcher, replacement)
|
9
|
+
matcher, block = parse!(matcher, replacement)
|
10
|
+
register MiniTest::Assertions, matcher, &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def register_expectation(matcher, replacement)
|
14
|
+
matcher, block = parse!(matcher, replacement)
|
15
|
+
register MiniTest::Expectations, matcher, &block
|
16
|
+
end
|
17
|
+
|
18
|
+
def register(mod, matcher, &block)
|
19
|
+
validate! mod, matcher, &block
|
20
|
+
REGISTRATIONS[mod][matcher] = block
|
21
|
+
watch mod
|
22
|
+
scan mod
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
REGISTRATIONS = Hash.new { |hash, key| hash[key] = {} }
|
29
|
+
|
30
|
+
def scan(mod, method = nil)
|
31
|
+
if method
|
32
|
+
REGISTRATIONS[mod].each do |regex, block|
|
33
|
+
next unless match = regex.match(method)
|
34
|
+
mod.module_exec(match, block) do
|
35
|
+
alias_method block.(match.captures), match.to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
else
|
39
|
+
mod.instance_methods.each do |method|
|
40
|
+
scan mod, method
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# If only Ruby 1.9 had Module#prepend...
|
46
|
+
# Instead, we have to use this ugly thing.
|
47
|
+
def watch(mod)
|
48
|
+
return if mod.respond_to? :minitest_english_method_added
|
49
|
+
class << mod
|
50
|
+
alias_method :minitest_english_method_added, :method_added
|
51
|
+
def method_added(method)
|
52
|
+
MiniTest::English.send :scan, self, method
|
53
|
+
minitest_english_method_added method
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse!(matcher, replacement)
|
59
|
+
unless matcher.count('*') == replacement.count('*')
|
60
|
+
raise ArgumentError.new "Expected matching number of wildcards; got #{matcher}, #{replacement}"
|
61
|
+
end
|
62
|
+
[
|
63
|
+
/\A#{matcher.gsub('*','(.*)')}\z/,
|
64
|
+
proc do |captures|
|
65
|
+
captures.each_with_object(replacement.dup) do |cap, str|
|
66
|
+
str.sub! '*', cap
|
67
|
+
end
|
68
|
+
end
|
69
|
+
]
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate!(mod, matcher, &block)
|
73
|
+
unless mod.is_a? Module or mod.is_a? Class
|
74
|
+
raise ArgumentError.new "Expected Module or Class; received: #{mod.class}"
|
75
|
+
end
|
76
|
+
unless matcher.is_a? Regexp
|
77
|
+
raise ArgumentError.new "Expected Regex; received: #{matcher.class}"
|
78
|
+
end
|
79
|
+
unless block_given?
|
80
|
+
raise ArgumentError.new 'Expected a block to be passed'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/minitest-english.gemspec
CHANGED
@@ -2,17 +2,23 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'minitest-english'
|
5
|
-
gem.version = '0.0
|
5
|
+
gem.version = '0.1.0'
|
6
6
|
gem.author = 'Dom Kiva-Meyer'
|
7
7
|
gem.summary = 'Minitest + the English language'
|
8
8
|
gem.homepage = 'http://github.com/domkm/minitest-english'
|
9
9
|
gem.license = 'MIT'
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($/)
|
12
|
-
gem.test_files = gem.files.grep(%r
|
12
|
+
gem.test_files = gem.files.grep(%r(^test/))
|
13
13
|
|
14
|
+
gem.add_development_dependency 'bond'
|
14
15
|
gem.add_development_dependency 'bundler', '~> 1.3'
|
15
16
|
gem.add_development_dependency 'm'
|
16
17
|
gem.add_development_dependency 'minitest'
|
18
|
+
gem.add_development_dependency 'pry-awesome_print'
|
19
|
+
gem.add_development_dependency 'pry-coolline'
|
20
|
+
gem.add_development_dependency 'pry-debugger'
|
21
|
+
gem.add_development_dependency 'pry-rescue'
|
22
|
+
gem.add_development_dependency 'pry-stack_explorer'
|
17
23
|
gem.add_development_dependency 'rake'
|
18
24
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'minitest/english/deny'
|
2
3
|
|
3
4
|
describe MiniTest::Assertions do
|
4
|
-
MiniTest::Assertions.instance_methods.each do |method|
|
5
|
-
next unless match =
|
5
|
+
MiniTest::Assertions.instance_methods.each do |method|
|
6
|
+
next unless match = /\Arefute(.*)/.match(method)
|
6
7
|
it "aliases #{method} to deny#{match[1]}" do
|
7
8
|
assert_equal MiniTest::Assertions.instance_method(method),
|
8
9
|
MiniTest::Assertions.instance_method("deny#{match[1]}")
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'minitest/english/must_not'
|
2
3
|
|
3
4
|
describe MiniTest::Expectations do
|
4
5
|
MiniTest::Expectations.instance_methods.each do |method|
|
5
|
-
next unless match =
|
6
|
+
next unless match = /\Awont(.*)/.match(method)
|
6
7
|
it "aliases #{method} to must_not#{match[1]}" do
|
7
8
|
assert_equal MiniTest::Expectations.instance_method(method),
|
8
9
|
MiniTest::Expectations.instance_method("must_not#{match[1]}")
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe MiniTest::English do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@module = Module.new { def pre_reg; end }
|
7
|
+
@block = proc { |captures| "post#{captures.last}"}
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'before registration' do
|
11
|
+
it 'does not create aliases' do
|
12
|
+
@module.method_defined?(:post_reg).must_equal false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'after registration' do
|
17
|
+
before do
|
18
|
+
MiniTest::English.register @module, /\Apre(.*)\z/, &@block
|
19
|
+
end
|
20
|
+
it 'creates aliases upon registration' do
|
21
|
+
@module.method_defined?(:post_reg).must_equal true
|
22
|
+
end
|
23
|
+
it 'creates aliases upon method addition' do
|
24
|
+
@module.module_exec { def pre_add; end }
|
25
|
+
@module.method_defined?(:post_add).must_equal true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'invalid registration' do
|
30
|
+
describe 'imbalanced wildcards' do
|
31
|
+
it 'raises ArgumentError' do
|
32
|
+
assert_raises(ArgumentError) do
|
33
|
+
MiniTest::English.register_assertion 'foo*', '*bar*'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe 'invalid module/class' do
|
38
|
+
it 'raises ArgumentError' do
|
39
|
+
assert_raises(ArgumentError) do
|
40
|
+
MiniTest::English.register :foo, /\Apre(.*)\z/, &@block
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
describe 'invalid regex' do
|
45
|
+
it 'raises ArgumentError' do
|
46
|
+
assert_raises(ArgumentError) do
|
47
|
+
MiniTest::English.register @module, :not_a_regex, &@block
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
describe 'invalid block' do
|
52
|
+
it 'raises ArgumentError' do
|
53
|
+
assert_raises(ArgumentError) do
|
54
|
+
MiniTest::English.register @module, /\Apre(.*)\z/
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'custom block' do
|
61
|
+
it 'passes regex captures and assigns method alias' do
|
62
|
+
MiniTest::English.register @module, /(.*)reg(.*)/ do |captures|
|
63
|
+
:"#{captures.first}foo"
|
64
|
+
end
|
65
|
+
@module.method_defined?(:pre_foo).must_equal true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-english
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dom Kiva-Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bond
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,76 @@ dependencies:
|
|
52
66
|
- - ! '>='
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-coolline
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-debugger
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-rescue
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-stack_explorer
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
55
139
|
- !ruby/object:Gem::Dependency
|
56
140
|
name: rake
|
57
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,18 +158,19 @@ extra_rdoc_files: []
|
|
74
158
|
files:
|
75
159
|
- .gitignore
|
76
160
|
- .ruby-version
|
161
|
+
- .travis.yml
|
77
162
|
- Gemfile
|
78
163
|
- LICENSE.txt
|
79
164
|
- README.md
|
80
165
|
- Rakefile
|
81
|
-
- lib/minitest-english.rb
|
82
166
|
- lib/minitest/english.rb
|
83
|
-
- lib/minitest/english/
|
84
|
-
- lib/minitest/english/
|
167
|
+
- lib/minitest/english/deny.rb
|
168
|
+
- lib/minitest/english/must_not.rb
|
85
169
|
- minitest-english.gemspec
|
86
170
|
- pulp_fiction.gif
|
87
|
-
- test/
|
88
|
-
- test/
|
171
|
+
- test/assertion_deny_test.rb
|
172
|
+
- test/expectation_must_not_test.rb
|
173
|
+
- test/registration_test.rb
|
89
174
|
- test/test_helper.rb
|
90
175
|
homepage: http://github.com/domkm/minitest-english
|
91
176
|
licenses:
|
@@ -112,6 +197,7 @@ signing_key:
|
|
112
197
|
specification_version: 4
|
113
198
|
summary: Minitest + the English language
|
114
199
|
test_files:
|
115
|
-
- test/
|
116
|
-
- test/
|
200
|
+
- test/assertion_deny_test.rb
|
201
|
+
- test/expectation_must_not_test.rb
|
202
|
+
- test/registration_test.rb
|
117
203
|
- test/test_helper.rb
|
data/lib/minitest-english.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'minitest/english'
|