minitest-mustwonted 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +17 -17
- data/lib/minitest/mustwonted.rb +5 -5
- data/lib/minitest/mustwonted/matcher.rb +11 -3
- data/lib/minitest/mustwonted/matcher/awesome.rb +9 -8
- data/lib/minitest/mustwonted/matcher/have.rb +2 -2
- data/lib/minitest/mustwonted/matcher/legacy.rb +1 -1
- data/lib/minitest/mustwonted/matcher/magick.rb +2 -2
- data/lib/minitest/mustwonted/matcher/valid.rb +3 -3
- data/lib/minitest/mustwonted/object.rb +2 -2
- data/lib/minitest/mustwonted/run.rb +1 -1
- data/lib/minitest/mustwonted/spec.rb +21 -4
- data/test/mustwonted/matcher/awesome_test.rb +1 -1
- data/test/mustwonted/matcher/have_test.rb +1 -1
- data/test/mustwonted/matcher/legacy_test.rb +1 -1
- data/test/mustwonted/matcher/magick_test.rb +1 -1
- data/test/mustwonted/matcher/valid_test.rb +1 -1
- data/test/mustwonted/matcher_test.rb +2 -2
- data/test/mustwonted/object_test.rb +2 -2
- data/test/mustwonted/spec_test.rb +1 -1
- data/test/test_helper.rb +2 -2
- metadata +10 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4422bb0e2968257b82b63ed0cf419a1edc95ad51
|
4
|
+
data.tar.gz: 273572fb3c29f46dc47c96275a53f0e996f07a32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 19e55587e7cc6e3fb893058c563c2b1a72b98bb85b1aafb76b66e1b0c1edd84f30563a095c56e2c560b128ee47d364c648581c66bf4bb65436168eb6a7623194
|
7
|
+
data.tar.gz: ce9e182af0d0a8ce7c3357ed69f99470fcfa9a23e49a2a9eec953067546a2865aeedc3c0341a883ebc3caa16aa1da1b766d7389f13b98ff36fe92524df4abb4b
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# Most Wanted Things for Minitest
|
2
2
|
|
3
|
-
This is a little plugn for [
|
4
|
-
which contains a new `must/wont` matchers engine, a set of
|
5
|
-
and hooks for testing ruby/rails applications.
|
3
|
+
This is a little plugn for [Minitest](https://github.com/seattlerb/Minitest)
|
4
|
+
which contains a new rspec-like `must/wont` matchers engine, and a set of
|
5
|
+
essential matchers and hooks for testing ruby/rails applications.
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
9
|
-
1
|
10
|
-
2
|
9
|
+
1. Add `gem minitest-mustwonted` into your `Gemfile`
|
10
|
+
2. Enjoy!
|
11
11
|
|
12
12
|
|
13
13
|
## Awesome Matchers
|
@@ -15,7 +15,7 @@ and hooks for testing ruby/rails applications.
|
|
15
15
|
Awesome matchers are set of easy to read logic-like matchers
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
describe
|
18
|
+
describe Minitest::MustWonted do
|
19
19
|
it "must provide awesome matchers" do
|
20
20
|
22.must == 22
|
21
21
|
22.wont == 33
|
@@ -36,7 +36,7 @@ end
|
|
36
36
|
Magick matchers are `rspec` like `be_smth` matchers
|
37
37
|
|
38
38
|
```ruby
|
39
|
-
describe
|
39
|
+
describe Minitest::MustWonted do
|
40
40
|
it "must provide magick matchers" do
|
41
41
|
[].must be_empty
|
42
42
|
[0].wont be_empty
|
@@ -55,7 +55,7 @@ end
|
|
55
55
|
Additional `have` matcher will let you write easily readable collection checks
|
56
56
|
|
57
57
|
```ruby
|
58
|
-
describe
|
58
|
+
describe Minitest::MustWonted do
|
59
59
|
class User
|
60
60
|
def comments(type=nil)
|
61
61
|
if type
|
@@ -87,7 +87,7 @@ Most of the `assert_smth` | `refute_smth` methods are piped throught the `must`
|
|
87
87
|
`wont` interface automatically and resolved on fly.
|
88
88
|
|
89
89
|
```ruby
|
90
|
-
describe
|
90
|
+
describe Minitest::MustWonted do
|
91
91
|
it "must support legacy assertions" do
|
92
92
|
'2'.must equal(3)
|
93
93
|
'3'.wont equal(2)
|
@@ -108,7 +108,7 @@ as long as they take the subject as the first argument.
|
|
108
108
|
`minitest-matchers` validation package
|
109
109
|
|
110
110
|
```ruby
|
111
|
-
describe
|
111
|
+
describe Minitest::MustWonted do
|
112
112
|
it "must provide validation matchers" do
|
113
113
|
@user.must have_valid(:name).with("Nikolay", "Vasilisa")
|
114
114
|
@user.wont have_valid(:name).with(nil, '', false)
|
@@ -164,10 +164,10 @@ class MyAwesomeMatcher
|
|
164
164
|
end
|
165
165
|
```
|
166
166
|
|
167
|
-
Once you done, register your matcher with `
|
167
|
+
Once you done, register your matcher with `Minitest::MustWonted` and start using it
|
168
168
|
|
169
169
|
```ruby
|
170
|
-
|
170
|
+
Minitest::MustWonted :method_name, MyAwesomeMatcher
|
171
171
|
|
172
172
|
describe Something do
|
173
173
|
it "must do something" do
|
@@ -181,10 +181,10 @@ end
|
|
181
181
|
|
182
182
|
Most ideas were boldly taken from:
|
183
183
|
|
184
|
-
[minitest-rails](https://github.com/blowmage/minitest-rails)
|
185
|
-
[minitest-matchers](https://github.com/zenspider/minitest-matchers)
|
186
|
-
[shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers)
|
187
|
-
[rspec-rails](https://github.com/rspec/rspec-rails)
|
184
|
+
* [minitest-rails](https://github.com/blowmage/minitest-rails)
|
185
|
+
* [minitest-matchers](https://github.com/zenspider/minitest-matchers)
|
186
|
+
* [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers)
|
187
|
+
* [rspec-rails](https://github.com/rspec/rspec-rails)
|
188
188
|
|
189
189
|
|
190
190
|
## Copyright
|
data/lib/minitest/mustwonted.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'minitest/spec'
|
2
2
|
|
3
|
-
module
|
4
|
-
VERSION = '1.0.
|
3
|
+
module Minitest::MustWonted
|
4
|
+
VERSION = '1.0.1'
|
5
5
|
|
6
6
|
def self.add(*args)
|
7
|
-
|
7
|
+
Minitest::MustWonted::Matcher.add *args
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -23,5 +23,5 @@ end
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# registering the matchers
|
26
|
-
|
27
|
-
|
26
|
+
Minitest::MustWonted.add :have, Minitest::MustWonted::Matcher::Have
|
27
|
+
Minitest::MustWonted.add :have_valid, Minitest::MustWonted::Matcher::Valid
|
@@ -1,12 +1,12 @@
|
|
1
1
|
#
|
2
2
|
# The actual matcher engine
|
3
3
|
#
|
4
|
-
class
|
4
|
+
class Minitest::MustWonted::Matcher
|
5
5
|
|
6
6
|
class << self
|
7
7
|
def must(subject, matcher=nil, flipped=false)
|
8
8
|
if matcher == nil
|
9
|
-
|
9
|
+
Minitest::MustWonted::Matcher::Awesome.new(subject, flipped)
|
10
10
|
elsif matcher.respond_to?(:match?)
|
11
11
|
matcher.match?(subject, flipped)
|
12
12
|
subject # returning the reference to the subject in case of chained calls
|
@@ -20,11 +20,19 @@ class MiniTest::MustWonted::Matcher
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def add(name, klass)
|
23
|
-
|
23
|
+
Minitest::Spec.instance_eval do
|
24
24
|
define_method name do |*args|
|
25
25
|
klass.new *args
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
if defined?(ActiveSupport)
|
30
|
+
ActiveSupport::TestCase.instance_eval do
|
31
|
+
define_method name do |*args|
|
32
|
+
klass.new *args
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
28
36
|
end
|
29
37
|
end
|
30
38
|
|
@@ -6,26 +6,27 @@
|
|
6
6
|
# smth.must > smth
|
7
7
|
# ...
|
8
8
|
#
|
9
|
-
class
|
10
|
-
include
|
9
|
+
class Minitest::MustWonted::Matcher::Awesome
|
10
|
+
include Minitest::Assertions
|
11
11
|
|
12
|
-
|
12
|
+
attr_accessor :subject, :flipped, :assertions
|
13
13
|
|
14
14
|
def initialize(subject, flipped)
|
15
|
-
@subject
|
16
|
-
@flipped
|
15
|
+
@subject = subject
|
16
|
+
@flipped = flipped
|
17
|
+
@assertions = 0
|
17
18
|
end
|
18
19
|
|
19
20
|
def ==(value)
|
20
|
-
__call 'equal', false, @subject
|
21
|
+
__call 'equal', false, value, @subject
|
21
22
|
end
|
22
23
|
|
23
24
|
def !=(value)
|
24
|
-
__call 'equal', true, @subject
|
25
|
+
__call 'equal', true, value, @subject
|
25
26
|
end
|
26
27
|
|
27
28
|
def =~(regexp)
|
28
|
-
__call 'match', false, @subject
|
29
|
+
__call 'match', false, regexp, @subject
|
29
30
|
end
|
30
31
|
|
31
32
|
def > (value)
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# @user.must have(10).comments
|
5
5
|
# @array.must have(2).items
|
6
6
|
#
|
7
|
-
class
|
7
|
+
class Minitest::MustWonted::Matcher::Have
|
8
8
|
|
9
9
|
def initialize(size)
|
10
10
|
@size = size
|
@@ -18,7 +18,7 @@ class MiniTest::MustWonted::Matcher::Have
|
|
18
18
|
end
|
19
19
|
|
20
20
|
if wont ? items.size == @size : items.size != @size
|
21
|
-
raise
|
21
|
+
raise Minitest::Assertion, "Expected #{subject.inspect} to have #{
|
22
22
|
@size} ##{@name}(#{@args.join(',')})\nbut instead it has: #{size}"
|
23
23
|
end
|
24
24
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# The Magick `be_smth` matcher
|
3
3
|
#
|
4
|
-
class
|
4
|
+
class Minitest::MustWonted::Matcher::Magick
|
5
5
|
|
6
6
|
def initialize(name, args)
|
7
7
|
@name = name.slice(3, name.size)
|
@@ -14,7 +14,7 @@ class MiniTest::MustWonted::Matcher::Magick
|
|
14
14
|
match = subject.send @name, *@args
|
15
15
|
|
16
16
|
if wont ? match : !match
|
17
|
-
raise
|
17
|
+
raise Minitest::Assertion, "Expected #{subject.inspect} ##{
|
18
18
|
@name} to return: #{ wont ? "false" : "true"
|
19
19
|
}\nbut instead have: #{match.inspect}"
|
20
20
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
#
|
8
8
|
# Credits: we're mimicking the minitest-matchers validation matchers here
|
9
9
|
#
|
10
|
-
class
|
10
|
+
class Minitest::MustWonted::Matcher::Valid
|
11
11
|
def initialize(name)
|
12
12
|
@name = name.to_sym
|
13
13
|
@args = []
|
@@ -35,12 +35,12 @@ class MiniTest::MustWonted::Matcher::Valid
|
|
35
35
|
error = subject.errors[@name]
|
36
36
|
|
37
37
|
if error && !wont
|
38
|
-
raise
|
38
|
+
raise Minitest::Assertion, "Expected the #{
|
39
39
|
subject.inspect} to have valid #{@name
|
40
40
|
} with #{subject.send(@name).inspect
|
41
41
|
}\nbut had an error instead: #{error.inspect}"
|
42
42
|
elsif wont && !error
|
43
|
-
raise
|
43
|
+
raise Minitest::Assertion, "Expected the #{
|
44
44
|
subject.inspect} to have invalid #{@name
|
45
45
|
} with #{subject.send(@name).inspect
|
46
46
|
}\nbut had no errors for this field instead"
|
@@ -10,7 +10,7 @@ class Object
|
|
10
10
|
# ....
|
11
11
|
#
|
12
12
|
def must(*args)
|
13
|
-
|
13
|
+
Minitest::MustWonted::Matcher.must(self, *args)
|
14
14
|
end
|
15
15
|
|
16
16
|
#
|
@@ -21,6 +21,6 @@ class Object
|
|
21
21
|
# ....
|
22
22
|
#
|
23
23
|
def wont(*args)
|
24
|
-
|
24
|
+
Minitest::MustWonted::Matcher.wont(self, *args)
|
25
25
|
end
|
26
26
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
|
-
# Extra sweets for the
|
2
|
+
# Extra sweets for the Minitest::Spec unit
|
3
3
|
#
|
4
|
-
class
|
4
|
+
class Minitest::Spec
|
5
5
|
|
6
6
|
#
|
7
7
|
# A shortcut to `must` directly on current subject
|
@@ -30,12 +30,29 @@ class MiniTest::Spec
|
|
30
30
|
#
|
31
31
|
def method_missing(name, *args)
|
32
32
|
if name.slice(0, 3) == 'be_'
|
33
|
-
|
33
|
+
Minitest::MustWonted::Matcher::Magick.new(name, args)
|
34
34
|
elsif respond_to?("assert_#{name}")
|
35
|
-
|
35
|
+
Minitest::MustWonted::Matcher::Legacy.new(name, args, self)
|
36
36
|
else
|
37
37
|
super name, *args
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
42
|
+
|
43
|
+
if defined?(ActiveSupport)
|
44
|
+
class ActiveSupport::TestCase
|
45
|
+
#
|
46
|
+
# Catching up the magick `be_smthing?` matchers
|
47
|
+
#
|
48
|
+
def method_missing(name, *args)
|
49
|
+
if name.slice(0, 3) == 'be_'
|
50
|
+
Minitest::MustWonted::Matcher::Magick.new(name, args)
|
51
|
+
elsif respond_to?("assert_#{name}")
|
52
|
+
Minitest::MustWonted::Matcher::Legacy.new(name, args, self)
|
53
|
+
else
|
54
|
+
super name, *args
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Minitest::MustWonted::Matcher do
|
4
4
|
subject{ nil }
|
5
5
|
|
6
|
-
Matcher =
|
6
|
+
Matcher = Minitest::MustWonted::Matcher
|
7
7
|
|
8
8
|
describe ".must" do
|
9
9
|
describe "without a matcher" do
|
@@ -10,7 +10,7 @@ describe Object do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "must bypass the call into Matcher.must" do
|
13
|
-
|
13
|
+
Minitest::MustWonted::Matcher.expects(:must).with(subject, 'something')
|
14
14
|
|
15
15
|
subject.must 'something'
|
16
16
|
end
|
@@ -22,7 +22,7 @@ describe Object do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "must bypass the call into Matcher.wont" do
|
25
|
-
|
25
|
+
Minitest::MustWonted::Matcher.expects(:wont).with(subject, 'something')
|
26
26
|
|
27
27
|
subject.wont 'something'
|
28
28
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,9 +4,9 @@ require 'minitest/autorun'
|
|
4
4
|
require 'minitest/pride'
|
5
5
|
require 'mocha/setup'
|
6
6
|
|
7
|
-
class
|
7
|
+
class Minitest::Spec
|
8
8
|
def assert_fails_correctly
|
9
9
|
# TODO make sure that the errors are raised with correct file/line references
|
10
|
-
-> { yield }.must_raise
|
10
|
+
-> { yield }.must_raise Minitest::Assertion
|
11
11
|
end
|
12
12
|
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-mustwonted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nikolay Nemshilov
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: minitest
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: Provides a new unversal and esily extendable matchers engine
|
@@ -56,26 +53,25 @@ files:
|
|
56
53
|
- README.md
|
57
54
|
homepage: http://github.com/MadRabbit/minitest-mustwonted
|
58
55
|
licenses: []
|
56
|
+
metadata: {}
|
59
57
|
post_install_message:
|
60
58
|
rdoc_options: []
|
61
59
|
require_paths:
|
62
60
|
- lib
|
63
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
62
|
requirements:
|
66
|
-
- -
|
63
|
+
- - '>='
|
67
64
|
- !ruby/object:Gem::Version
|
68
65
|
version: '0'
|
69
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
67
|
requirements:
|
72
|
-
- -
|
68
|
+
- - '>='
|
73
69
|
- !ruby/object:Gem::Version
|
74
70
|
version: '0'
|
75
71
|
requirements: []
|
76
72
|
rubyforge_project:
|
77
|
-
rubygems_version:
|
73
|
+
rubygems_version: 2.0.3
|
78
74
|
signing_key:
|
79
|
-
specification_version:
|
80
|
-
summary: new must/wont matchers engine for
|
75
|
+
specification_version: 4
|
76
|
+
summary: new must/wont matchers engine for Minitest
|
81
77
|
test_files: []
|