minispec 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.travis.yml +7 -0
- data/README.md +12 -10
- data/lib/minispec.rb +1 -1
- data/lib/minispec/api/instance/mocks/mocks.rb +16 -8
- data/lib/minispec/mocks/stubs.rb +8 -4
- data/lib/minispec/reporter.rb +10 -5
- data/lib/minispec/utils.rb +9 -7
- data/minispec.gemspec +4 -4
- data/test/mocks/expectations/yield.rb +1 -1
- data/test/mocks/test__mocks.rb +22 -20
- data/test/mocks/test__stubs.rb +34 -30
- data/test/test__raise.rb +4 -1
- metadata +66 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d04713dc3775ca118faf19307f4e56509aa582ea
|
4
|
+
data.tar.gz: acda21895ad4ab6241996d0b4d85d53896bcd5e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: feb5d79a7238d01431fa4c407e15b56749240d12252c5d1a75c863abf524ed054cce57644c6089e33c54133e9a17026c737693a3b5f6d80212b523a87d1dc6db
|
7
|
+
data.tar.gz: 4c82e730248e7a7084ea8d37e9d9712a7e6118b1a2ad7c9ba5349cdf012695cc3ff9a6be16c2a6a97db9f7a12114c1928ddf2a535b64a9911dcde569edccd5f6
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/sleewoo/minispec.svg?branch=master)](https://travis-ci.org/sleewoo/minispec)
|
1
2
|
|
2
3
|
### Minispec
|
3
4
|
|
@@ -11,21 +12,22 @@
|
|
11
12
|
|
12
13
|
## What and Why
|
13
14
|
|
14
|
-
Simply
|
15
|
+
Simply, I'm tired of syntax like `assert_equal(b, a)`, `a.should == b`, `expect(a).to eq(b)` etc.
|
15
16
|
|
16
|
-
`
|
17
|
+
Something closer to `a == b` would make more sense.
|
17
18
|
|
18
|
-
|
19
|
+
And I'm tired of learning framework specific techniques.<br>
|
20
|
+
I want simply to use **Ruby's native methods**:
|
19
21
|
|
20
22
|
```ruby
|
21
|
-
|
23
|
+
assert(a) == b
|
22
24
|
does(a).include?(b)
|
23
25
|
is(a).empty?
|
24
26
|
```
|
25
27
|
|
26
28
|
`==`, `include?`, `empty?` are all Ruby methods called on `a`.
|
27
29
|
|
28
|
-
What you see around `a` is a simple wrapper that passes messages to `a` and
|
30
|
+
What you see around `a` is a simple wrapper that passes messages to `a` and marks the assertion as passed or failed, depending on returned value.
|
29
31
|
|
30
32
|
|
31
33
|
## Install
|
@@ -163,9 +165,9 @@ end
|
|
163
165
|
|
164
166
|
### ↳ Nested Specs
|
165
167
|
|
166
|
-
Minispec allows to
|
168
|
+
Minispec allows you to nest specs using the same `describe`/`context`/`section` DSL:
|
167
169
|
|
168
|
-
Nested specs
|
170
|
+
Nested specs inherit everything (except tests) from parent spec, but do not change any parent specs state in any way:
|
169
171
|
|
170
172
|
```ruby
|
171
173
|
describe :A do
|
@@ -274,7 +276,7 @@ If you need all assertions to be evaluated regardless failures use `continue_on_
|
|
274
276
|
|
275
277
|
## Shared examples and setups
|
276
278
|
|
277
|
-
Often you need to share some setups and tests(a.k.a examples) between various specs.
|
279
|
+
Often you need to share some setups and tests (a.k.a examples) between various specs.
|
278
280
|
|
279
281
|
To define shared setups/examples simply define a module that includes `Minispec`.
|
280
282
|
|
@@ -350,7 +352,7 @@ end
|
|
350
352
|
|
351
353
|
## Local variables and subject
|
352
354
|
|
353
|
-
Minispec
|
355
|
+
Minispec provide a `let` method as a clean way to define local variables. Its block are executed only once per test, when given variable used for first time.
|
354
356
|
|
355
357
|
```ruby
|
356
358
|
describe Array do
|
@@ -362,7 +364,7 @@ describe Array do
|
|
362
364
|
end
|
363
365
|
```
|
364
366
|
|
365
|
-
`subject`
|
367
|
+
`subject` allows testing some object without repeatedly typing it. It is automatically set when a spec is defined using Minispec's DSL:
|
366
368
|
|
367
369
|
```ruby
|
368
370
|
describe Hash do
|
data/lib/minispec.rb
CHANGED
@@ -187,10 +187,14 @@ module MiniSpec
|
|
187
187
|
return self == nil if method_name == :nil?
|
188
188
|
return unless method
|
189
189
|
|
190
|
-
proc = block
|
191
|
-
|
192
|
-
|
193
|
-
|
190
|
+
proc = if block
|
191
|
+
Proc.new do |*a,&b|
|
192
|
+
message[:yielded] = a
|
193
|
+
block.call(*a,&b)
|
194
|
+
end
|
195
|
+
else
|
196
|
+
nil
|
197
|
+
end
|
194
198
|
|
195
199
|
begin
|
196
200
|
message[:returned] = method.bind(self).call(*args, &proc)
|
@@ -227,10 +231,14 @@ module MiniSpec
|
|
227
231
|
message = {object: object, method: meth, arguments: args}
|
228
232
|
messages.push(message)
|
229
233
|
|
230
|
-
proc = block
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
+
proc = if block
|
235
|
+
Proc.new do |*a,&b|
|
236
|
+
message[:yielded] = a
|
237
|
+
block.call(*a,&b)
|
238
|
+
end
|
239
|
+
else
|
240
|
+
nil
|
241
|
+
end
|
234
242
|
|
235
243
|
begin
|
236
244
|
message[:returned] = method.bind(self).call(meth, *args, &proc)
|
data/lib/minispec/mocks/stubs.rb
CHANGED
@@ -134,10 +134,14 @@ module MiniSpec
|
|
134
134
|
|
135
135
|
method = base.most_relevant_block_for(args)
|
136
136
|
|
137
|
-
proc = block
|
138
|
-
|
139
|
-
|
140
|
-
|
137
|
+
proc = if block
|
138
|
+
Proc.new do |*a,&b|
|
139
|
+
message[:yielded] = a
|
140
|
+
block.call(*a, &b)
|
141
|
+
end
|
142
|
+
else
|
143
|
+
nil
|
144
|
+
end
|
141
145
|
|
142
146
|
begin
|
143
147
|
message[:returned] = method.call(original, *args, &proc)
|
data/lib/minispec/reporter.rb
CHANGED
@@ -84,10 +84,10 @@ module MiniSpec
|
|
84
84
|
def totals__tests
|
85
85
|
print(info(' Tests: '))
|
86
86
|
print(send(@failed_tests.any? ? :info : :success, Minispec.tests))
|
87
|
-
failed = error('%s failed' % @failed_tests.values.map(&:size).reduce(:+)) if @failed_tests.any?
|
88
|
-
skipped = warn('%s skipped' % @skipped_tests.size) if @skipped_tests.any?
|
87
|
+
failed = error(' (%s failed)' % @failed_tests.values.map(&:size).reduce(:+)) if @failed_tests.any?
|
88
|
+
skipped = warn(' (%s skipped)' % @skipped_tests.size) if @skipped_tests.any?
|
89
89
|
report = [failed, skipped].compact.join(', ')
|
90
|
-
puts(report
|
90
|
+
puts(report)
|
91
91
|
end
|
92
92
|
|
93
93
|
def totals__assertions
|
@@ -149,8 +149,13 @@ module MiniSpec
|
|
149
149
|
def print(*args); @stdout.print(*indent_lines(*args)) end
|
150
150
|
def puts(*args); @stdout.puts(*indent_lines(*args)) end
|
151
151
|
|
152
|
-
{
|
153
|
-
|
152
|
+
{
|
153
|
+
success: [1, 32],
|
154
|
+
info: [0, 36],
|
155
|
+
warn: [0, 35],
|
156
|
+
error: [0, 31]
|
157
|
+
}.each_pair do |m,(esc,color)|
|
158
|
+
define_method(m) {|str| "\e[%i;%im%s\e[0m" % [esc, color, str]}
|
154
159
|
end
|
155
160
|
|
156
161
|
def failures?
|
data/lib/minispec/utils.rb
CHANGED
@@ -7,12 +7,6 @@ module MiniSpec
|
|
7
7
|
object.instance_eval('undef :%s' % method)
|
8
8
|
end
|
9
9
|
|
10
|
-
def method_defined? object, method
|
11
|
-
object.respond_to?(method) ||
|
12
|
-
object.protected_methods.include?(method) ||
|
13
|
-
object.private_methods.include?(method)
|
14
|
-
end
|
15
|
-
|
16
10
|
# @api private
|
17
11
|
# checking whether correct arguments passed to proxy methods.
|
18
12
|
#
|
@@ -68,10 +62,18 @@ module MiniSpec
|
|
68
62
|
protected: :protected_methods,
|
69
63
|
private: :private_methods
|
70
64
|
}.each_pair do |v,m|
|
71
|
-
|
65
|
+
if v == :public
|
66
|
+
# in case public_methods overridden to include method
|
67
|
+
# but method in fact does not exists,
|
68
|
+
# most notable ActiveRecord::Base#find which rely on method_missing
|
69
|
+
return v if object.respond_to?(method)
|
70
|
+
else
|
71
|
+
return v if object.send(m).include?(method)
|
72
|
+
end
|
72
73
|
end
|
73
74
|
nil
|
74
75
|
end
|
76
|
+
alias method_defined? method_visibility
|
75
77
|
|
76
78
|
def array_elements_map array
|
77
79
|
# borrowed from thoughtbot/shoulda
|
data/minispec.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
name, version = 'minispec 0.0.
|
3
|
+
name, version = 'minispec 0.0.2'.split
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = name
|
6
6
|
spec.version = version
|
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.required_ruby_version = '>= 1.9.2'
|
20
20
|
|
21
|
-
spec.add_dependency 'diff-lcs', '~> 1
|
22
|
-
spec.add_dependency 'coderay', '~> 1
|
21
|
+
spec.add_dependency 'diff-lcs', '~> 1'
|
22
|
+
spec.add_dependency 'coderay', '~> 1'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'minitest'
|
24
|
+
spec.add_development_dependency 'minitest', '~> 5'
|
25
25
|
spec.add_development_dependency 'bundler'
|
26
26
|
spec.add_development_dependency 'rake'
|
27
27
|
end
|
@@ -54,7 +54,7 @@ class MinispecTest::Expectations::Unit
|
|
54
54
|
|
55
55
|
should 'raise when arity not respected and lambda used' do
|
56
56
|
expect(o).to_receive(:y)
|
57
|
-
does { o.y(&lambda {|a|}) }.raise? ArgumentError, /2
|
57
|
+
does { o.y(&lambda {|a|}) }.raise? ArgumentError, /2.+1/
|
58
58
|
end
|
59
59
|
|
60
60
|
should 'use same expectation for all messages' do
|
data/test/mocks/test__mocks.rb
CHANGED
@@ -70,26 +70,28 @@ class MinispecTest
|
|
70
70
|
assert(o.send(:a)) == :b
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
73
|
+
if RUBY_VERSION.to_f >= 2
|
74
|
+
it 'keeps the visibility of existing methods' do
|
75
|
+
o = Class.new do
|
76
|
+
def a; end
|
77
|
+
protected
|
78
|
+
def b; p :blah; end
|
79
|
+
private
|
80
|
+
def c; end
|
81
|
+
end.new
|
82
|
+
|
83
|
+
mock(o, :a)
|
84
|
+
o.send(:a)
|
85
|
+
does(o.public_methods).include?(:a)
|
86
|
+
|
87
|
+
mock(o, :b)
|
88
|
+
o.send(:b)
|
89
|
+
does(o.protected_methods).include?(:b)
|
90
|
+
|
91
|
+
mock(o, :c)
|
92
|
+
o.send(:c)
|
93
|
+
does(o.private_methods).include?(:c)
|
94
|
+
end
|
93
95
|
end
|
94
96
|
|
95
97
|
it 'uses `with_any` with a block to define a catchall return' do
|
data/test/mocks/test__stubs.rb
CHANGED
@@ -162,23 +162,25 @@ class MinispecTest
|
|
162
162
|
assert(o.send(:a, 1)) == :one
|
163
163
|
end
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
165
|
+
if RUBY_VERSION.to_f >= 2
|
166
|
+
it 'keeps the visibility of existing methods' do
|
167
|
+
o = Class.new do
|
168
|
+
def a; end
|
169
|
+
protected
|
170
|
+
def b; end
|
171
|
+
private
|
172
|
+
def c; end
|
173
|
+
end.new
|
174
|
+
|
175
|
+
stub(o, :a)
|
176
|
+
does(o.public_methods).include?(:a)
|
177
|
+
|
178
|
+
stub(o, :b)
|
179
|
+
does(o.protected_methods).include?(:b)
|
180
|
+
|
181
|
+
stub(o, :c)
|
182
|
+
does(o.private_methods).include?(:c)
|
183
|
+
end
|
182
184
|
end
|
183
185
|
|
184
186
|
it 'enforces public visibility on protected methods' do
|
@@ -334,26 +336,28 @@ class MinispecTest
|
|
334
336
|
assert { o.a }.raise NoMethodError
|
335
337
|
end
|
336
338
|
|
337
|
-
|
338
|
-
|
339
|
+
unless RUBY_ENGINE == 'rbx'
|
340
|
+
it 'undefines early unexisting protected methods' do
|
341
|
+
assert(o.protected_methods).does_not.include? :a
|
339
342
|
|
340
|
-
|
341
|
-
|
343
|
+
protected_stub(o, :a) {:a}
|
344
|
+
does(o.protected_methods).include? :a
|
342
345
|
|
343
|
-
|
346
|
+
restore_originals
|
344
347
|
|
345
|
-
|
346
|
-
|
348
|
+
assert(o.protected_methods).does_not.include? :a
|
349
|
+
end
|
347
350
|
|
348
|
-
|
349
|
-
|
351
|
+
it 'undefines early unexisting private methods' do
|
352
|
+
assert(o.private_methods).does_not.include? :a
|
350
353
|
|
351
|
-
|
352
|
-
|
354
|
+
private_stub(o, :a) {:a}
|
355
|
+
does(o.private_methods).include? :a
|
353
356
|
|
354
|
-
|
357
|
+
restore_originals
|
355
358
|
|
356
|
-
|
359
|
+
assert(o.private_methods).does_not.include? :a
|
360
|
+
end
|
357
361
|
end
|
358
362
|
|
359
363
|
it 'uses `returns` with a block to define a catchall return' do
|
data/test/test__raise.rb
CHANGED
@@ -43,7 +43,10 @@ class MinispecTest
|
|
43
43
|
|
44
44
|
begin # error message as first argument
|
45
45
|
should 'pass when raised error message is equal to expected one' do
|
46
|
-
|
46
|
+
message = RUBY_ENGINE == 'rbx' ?
|
47
|
+
'Missing or uninitialized constant: MinispecTest::Raise::Unit::Blah' :
|
48
|
+
'uninitialized constant MinispecTest::Raise::Unit::Blah'
|
49
|
+
does { Blah }.raise_error? message
|
47
50
|
end
|
48
51
|
|
49
52
|
should ':fail when raised error message is NOT equal to expected one' do
|
metadata
CHANGED
@@ -1,94 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: minispec
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Slee Woo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
date: 2014-12-08 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
14
15
|
name: diff-lcs
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.2'
|
20
|
-
type: :runtime
|
21
16
|
prerelease: false
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: coderay
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.1'
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: "1"
|
34
22
|
type: :runtime
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: coderay
|
35
26
|
prerelease: false
|
36
|
-
|
37
|
-
requirements:
|
38
|
-
- -
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "1"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id002
|
34
|
+
- !ruby/object:Gem::Dependency
|
42
35
|
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
36
|
prerelease: false
|
50
|
-
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: bundler
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
37
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "5"
|
62
42
|
type: :development
|
43
|
+
version_requirements: *id003
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: bundler
|
63
46
|
prerelease: false
|
64
|
-
|
65
|
-
requirements:
|
66
|
-
-
|
67
|
-
-
|
68
|
-
|
69
|
-
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
47
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- &id005
|
50
|
+
- ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
76
53
|
type: :development
|
54
|
+
version_requirements: *id004
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
77
57
|
prerelease: false
|
78
|
-
|
79
|
-
requirements:
|
80
|
-
-
|
81
|
-
|
82
|
-
|
58
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- *id005
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id006
|
83
63
|
description: Simple, Intuitive, Full-featured Testing Framework
|
84
|
-
email:
|
64
|
+
email:
|
85
65
|
- mail@sleewoo.com
|
86
|
-
executables:
|
66
|
+
executables:
|
87
67
|
- minispec
|
88
68
|
extensions: []
|
69
|
+
|
89
70
|
extra_rdoc_files: []
|
90
|
-
|
91
|
-
|
71
|
+
|
72
|
+
files:
|
73
|
+
- .pryrc
|
74
|
+
- .travis.yml
|
92
75
|
- Gemfile
|
93
76
|
- LICENSE
|
94
77
|
- README.md
|
@@ -170,27 +153,29 @@ files:
|
|
170
153
|
- test/test__skip.rb
|
171
154
|
- test/test__throw.rb
|
172
155
|
homepage: https://github.com/sleewoo/minispec
|
173
|
-
licenses:
|
156
|
+
licenses:
|
174
157
|
- MIT
|
175
158
|
metadata: {}
|
159
|
+
|
176
160
|
post_install_message:
|
177
161
|
rdoc_options: []
|
178
|
-
|
162
|
+
|
163
|
+
require_paths:
|
179
164
|
- lib
|
180
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
-
requirements:
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
182
167
|
- - ">="
|
183
|
-
- !ruby/object:Gem::Version
|
168
|
+
- !ruby/object:Gem::Version
|
184
169
|
version: 1.9.2
|
185
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
-
requirements:
|
187
|
-
-
|
188
|
-
- !ruby/object:Gem::Version
|
189
|
-
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- *id005
|
190
173
|
requirements: []
|
174
|
+
|
191
175
|
rubyforge_project:
|
192
176
|
rubygems_version: 2.2.2
|
193
177
|
signing_key:
|
194
178
|
specification_version: 4
|
195
|
-
summary: minispec-0.0.
|
179
|
+
summary: minispec-0.0.2
|
196
180
|
test_files: []
|
181
|
+
|