matest 0.0.1 → 0.0.2
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 +4 -4
- data/bin/mt +40 -0
- data/lib/matest.rb +184 -1
- data/lib/matest/version.rb +1 -1
- data/matest.gemspec +2 -2
- data/spec/matest_spec.rb +159 -0
- data/spec/matest_specs/nested_scopes_spec.rb +24 -0
- data/spec/matest_specs/scope_spec.rb +36 -0
- data/spec/matest_specs/spec_helper.rb +3 -0
- data/spec/spec_helper.rb +5 -0
- metadata +18 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0503943c0bc0e1cb9e6f7ce6b7dda83ffc9f36f
|
4
|
+
data.tar.gz: 377a6890e8bf973cd0eb95248de7012979af510f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9057ef4983f5b5830c6735c30c923dd366d11fb67791ab93ca147a596d25e0b3259e15b4078a6e73c60da6339823c2116b44811f5e20f93e3667810b5f5576e
|
7
|
+
data.tar.gz: 504844e60f56b6cf9a8cb290112f006e6d5d10e4c7b7b4dba9a28d3b7abc6dbb72edd62438e9ce596de477968a34713e72cdba5ce79347d35f9f36ec169eded3
|
data/bin/mt
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "time"
|
4
|
+
start_time = Time.now
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
7
|
+
|
8
|
+
require "pathname"
|
9
|
+
require "matest"
|
10
|
+
|
11
|
+
RUNNER = Matest::Runner.new
|
12
|
+
|
13
|
+
ARGV.each do |file|
|
14
|
+
RUNNER.load_file(Pathname(file).expand_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
RUNNER.execute!
|
18
|
+
|
19
|
+
time_elapsed = Time.now - start_time
|
20
|
+
|
21
|
+
puts
|
22
|
+
info = RUNNER.info
|
23
|
+
|
24
|
+
def spec_detail(info)
|
25
|
+
info[:num_specs].map { |name, num|
|
26
|
+
" #{num} #{name.downcase}."
|
27
|
+
}.join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
good_bye_message = <<-EOF
|
31
|
+
------------------------------------------
|
32
|
+
Specs:
|
33
|
+
#{spec_detail(info)}
|
34
|
+
|
35
|
+
EOF
|
36
|
+
|
37
|
+
puts good_bye_message
|
38
|
+
|
39
|
+
time_elapsed = Time.now - start_time
|
40
|
+
puts "Elapsed: #{time_elapsed} seconds."
|
data/lib/matest.rb
CHANGED
@@ -1,5 +1,188 @@
|
|
1
1
|
require "matest/version"
|
2
2
|
|
3
3
|
module Matest
|
4
|
-
|
4
|
+
class Runner
|
5
|
+
attr_reader :example_groups
|
6
|
+
attr_reader :info
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@example_groups = []
|
10
|
+
@info = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def <<(example_group)
|
14
|
+
example_groups << example_group
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_file(file)
|
18
|
+
load(file)
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute!
|
22
|
+
statuses = []
|
23
|
+
example_groups.each do |current_group|
|
24
|
+
current_group.execute!
|
25
|
+
end
|
26
|
+
|
27
|
+
puts
|
28
|
+
puts
|
29
|
+
puts "### Messages ###"
|
30
|
+
|
31
|
+
info[:num_specs] = { total: 0 }
|
32
|
+
example_groups.each do |current_group|
|
33
|
+
current_group.statuses.each do |status|
|
34
|
+
info[:num_specs][:total] += 1
|
35
|
+
|
36
|
+
info[:num_specs][status.name] ||= 0
|
37
|
+
info[:num_specs][status.name] += 1
|
38
|
+
|
39
|
+
if status.is_a?(Matest::SpecPassed)
|
40
|
+
else
|
41
|
+
puts
|
42
|
+
puts "[#{status.name}] #{status.description}"
|
43
|
+
if status.is_a?(Matest::NotANaturalAssertion)
|
44
|
+
puts "RESULT >> #{status.result.inspect}"
|
45
|
+
end
|
46
|
+
if status.is_a?(Matest::ExceptionRaised)
|
47
|
+
puts "EXCEPTION >> #{status.result}"
|
48
|
+
status.result.backtrace.each do |l|
|
49
|
+
puts " #{l}"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
puts " #{status.location}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class SpecStatus
|
61
|
+
attr_reader :block
|
62
|
+
attr_reader :description
|
63
|
+
attr_reader :result
|
64
|
+
|
65
|
+
def initialize(block, result, description=nil)
|
66
|
+
@block = block
|
67
|
+
@result = result
|
68
|
+
@description = description
|
69
|
+
end
|
70
|
+
|
71
|
+
def location
|
72
|
+
"%s:%d" % block.source_location
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
class SpecPassed < SpecStatus
|
78
|
+
def to_s
|
79
|
+
"."
|
80
|
+
end
|
81
|
+
|
82
|
+
def name
|
83
|
+
"PASSING"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
class SpecFailed < SpecStatus
|
87
|
+
def to_s
|
88
|
+
"F"
|
89
|
+
end
|
90
|
+
|
91
|
+
def name
|
92
|
+
"FAILING"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
class SpecSkipped < SpecStatus
|
96
|
+
def to_s
|
97
|
+
"S"
|
98
|
+
end
|
99
|
+
|
100
|
+
def name
|
101
|
+
"SKIPPED"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
class NotANaturalAssertion < SpecStatus
|
105
|
+
def to_s
|
106
|
+
"N"
|
107
|
+
end
|
108
|
+
|
109
|
+
def name
|
110
|
+
"NOT A NATURAL ASSERTION"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class ExceptionRaised < SpecStatus
|
115
|
+
attr_reader :exception
|
116
|
+
def to_s
|
117
|
+
"E"
|
118
|
+
end
|
119
|
+
|
120
|
+
def name
|
121
|
+
"ERROR"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class SkipMe; end
|
126
|
+
|
127
|
+
class ExampleGroup
|
128
|
+
attr_reader :scope_block
|
129
|
+
attr_reader :specs
|
130
|
+
attr_reader :statuses
|
131
|
+
|
132
|
+
def initialize(scope_block)
|
133
|
+
@scope_block = scope_block
|
134
|
+
@specs = []
|
135
|
+
@statuses = []
|
136
|
+
end
|
137
|
+
|
138
|
+
def execute!
|
139
|
+
instance_eval(&scope_block)
|
140
|
+
specs.shuffle.each do |spec, desc|
|
141
|
+
res = run_spec(spec, desc)
|
142
|
+
print res
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
def spec(description=nil, &block)
|
148
|
+
current_example = block_given? ? block : -> { Matest::SkipMe.new }
|
149
|
+
specs << [current_example, description]
|
150
|
+
end
|
151
|
+
|
152
|
+
def xspec(description=nil, &block)
|
153
|
+
spec(description)
|
154
|
+
end
|
155
|
+
|
156
|
+
[:it, :spec, :test, :example].each do |m|
|
157
|
+
alias m :spec
|
158
|
+
alias :"x#{m}" :xspec
|
159
|
+
end
|
160
|
+
|
161
|
+
def run_spec(spec, description)
|
162
|
+
status = begin
|
163
|
+
result = spec.call
|
164
|
+
status_class = case result
|
165
|
+
when true
|
166
|
+
Matest::SpecPassed
|
167
|
+
when false
|
168
|
+
Matest::SpecFailed
|
169
|
+
when Matest::SkipMe
|
170
|
+
Matest::SpecSkipped
|
171
|
+
else
|
172
|
+
Matest::NotANaturalAssertion
|
173
|
+
end
|
174
|
+
status_class.new(spec, result, description)
|
175
|
+
rescue Exception => e
|
176
|
+
Matest::ExceptionRaised.new(spec, e, description)
|
177
|
+
end
|
178
|
+
@statuses << status
|
179
|
+
status
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
def scope(description=nil, &block)
|
187
|
+
RUNNER.example_groups << Matest::ExampleGroup.new(block)
|
5
188
|
end
|
data/lib/matest/version.rb
CHANGED
data/matest.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Matest::VERSION
|
9
9
|
spec.authors = ["Federico Iachetti"]
|
10
10
|
spec.email = ["iachetti.federico@gmail.com"]
|
11
|
-
spec.summary = %q{Tests
|
12
|
-
spec.description = %q{Natural assertions test
|
11
|
+
spec.summary = %q{Tests gasoleros (cheap tests).}
|
12
|
+
spec.description = %q{Natural assertions test suite.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/spec/matest_spec.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "scope" do
|
4
|
+
it "can pass" do
|
5
|
+
res = scope do
|
6
|
+
spec do
|
7
|
+
true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
res.must_be_kind_of(Matest::SpecPassed)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "spec" do
|
15
|
+
describe "passing" do
|
16
|
+
it "passes" do
|
17
|
+
scope do
|
18
|
+
res = spec do
|
19
|
+
true
|
20
|
+
end
|
21
|
+
res.must_be_kind_of(Matest::SpecPassed)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "forwards the block" do
|
26
|
+
scope do
|
27
|
+
res = spec do
|
28
|
+
true
|
29
|
+
end
|
30
|
+
res.block.call.must_equal(true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "allows a description and forwards it" do
|
35
|
+
scope do
|
36
|
+
res = spec "THE DESCRIPTION" do
|
37
|
+
true
|
38
|
+
end
|
39
|
+
res.description.must_equal("THE DESCRIPTION")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "failing" do
|
45
|
+
it "fails" do
|
46
|
+
scope do
|
47
|
+
res = spec do
|
48
|
+
false
|
49
|
+
end
|
50
|
+
res.must_be_kind_of(Matest::SpecFailed)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "forwards the block" do
|
55
|
+
scope do
|
56
|
+
res = spec do
|
57
|
+
false
|
58
|
+
end
|
59
|
+
res.block.call.must_equal(false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "allows a description and forwards it" do
|
64
|
+
scope do
|
65
|
+
res = spec "THE DESCRIPTION" do
|
66
|
+
false
|
67
|
+
end
|
68
|
+
res.description.must_equal("THE DESCRIPTION")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "only allows natural assertions" do
|
74
|
+
scope do
|
75
|
+
res = spec do
|
76
|
+
:not_true_nor_false
|
77
|
+
end
|
78
|
+
res.must_be_kind_of(Matest::NotANaturalAssertion)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "skips if no block is given" do
|
83
|
+
scope do
|
84
|
+
res = spec
|
85
|
+
res.must_be_kind_of(Matest::SpecSkipped)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "allows raising an exception" do
|
90
|
+
scope do
|
91
|
+
res = spec do
|
92
|
+
raise RuntimeError
|
93
|
+
end
|
94
|
+
res.must_be_kind_of(Matest::ExceptionRaised)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "xspec" do
|
101
|
+
it "skips" do
|
102
|
+
scope do
|
103
|
+
res = xspec do
|
104
|
+
raise "Wanna raise an error? do it ... nothing will happen"
|
105
|
+
:whatever
|
106
|
+
end
|
107
|
+
res.must_be_kind_of(Matest::SpecSkipped)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it "forwards the block" do
|
112
|
+
scope do
|
113
|
+
res = xspec do
|
114
|
+
false
|
115
|
+
end
|
116
|
+
res.block.call.must_equal(false)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "allows a description and forwards it" do
|
121
|
+
scope do
|
122
|
+
res = spec "THE DESCRIPTION" do
|
123
|
+
false
|
124
|
+
end
|
125
|
+
res.description.must_equal("THE DESCRIPTION")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
####
|
131
|
+
#### spec do
|
132
|
+
#### 5 == 5
|
133
|
+
#### end
|
134
|
+
####
|
135
|
+
#### spec do
|
136
|
+
#### 5 == 6
|
137
|
+
#### end
|
138
|
+
####
|
139
|
+
#### spec do
|
140
|
+
#### skip
|
141
|
+
#### end
|
142
|
+
####
|
143
|
+
#### spec do
|
144
|
+
#### 10
|
145
|
+
#### end
|
146
|
+
####
|
147
|
+
####
|
148
|
+
####
|
149
|
+
####
|
150
|
+
#### # >> .
|
151
|
+
#### # >>
|
152
|
+
#### # >> F
|
153
|
+
#### # >>
|
154
|
+
#### # >> S
|
155
|
+
#### # >>
|
156
|
+
#### # >> X
|
157
|
+
#### # >>
|
158
|
+
#### # >> {:message=>"The spec needs to return either true or false, but it returned 10", :block=>#<Proc:0x00000001f61408@-:17>}
|
159
|
+
#
|
@@ -0,0 +1,36 @@
|
|
1
|
+
scope do
|
2
|
+
spec do
|
3
|
+
1 == 1
|
4
|
+
end
|
5
|
+
|
6
|
+
spec "I shall fail" do
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
spec do
|
11
|
+
@hola = 5
|
12
|
+
@hola == 5
|
13
|
+
end
|
14
|
+
|
15
|
+
spec do
|
16
|
+
@hola == nil
|
17
|
+
end
|
18
|
+
|
19
|
+
spec do
|
20
|
+
"not true nor false"
|
21
|
+
end
|
22
|
+
|
23
|
+
spec "I'm not natural" do
|
24
|
+
"not true nor false w/desc"
|
25
|
+
end
|
26
|
+
|
27
|
+
spec "I raise" do
|
28
|
+
raise IndexError
|
29
|
+
end
|
30
|
+
|
31
|
+
spec "I skip"
|
32
|
+
|
33
|
+
xspec "I skip too" do
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,10 +38,11 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description: Natural assertions test
|
41
|
+
description: Natural assertions test suite.
|
42
42
|
email:
|
43
43
|
- iachetti.federico@gmail.com
|
44
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- mt
|
45
46
|
extensions: []
|
46
47
|
extra_rdoc_files: []
|
47
48
|
files:
|
@@ -50,9 +51,15 @@ files:
|
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
54
|
+
- bin/mt
|
53
55
|
- lib/matest.rb
|
54
56
|
- lib/matest/version.rb
|
55
57
|
- matest.gemspec
|
58
|
+
- spec/matest_spec.rb
|
59
|
+
- spec/matest_specs/nested_scopes_spec.rb
|
60
|
+
- spec/matest_specs/scope_spec.rb
|
61
|
+
- spec/matest_specs/spec_helper.rb
|
62
|
+
- spec/spec_helper.rb
|
56
63
|
homepage: ''
|
57
64
|
licenses:
|
58
65
|
- MIT
|
@@ -76,5 +83,10 @@ rubyforge_project:
|
|
76
83
|
rubygems_version: 2.4.2
|
77
84
|
signing_key:
|
78
85
|
specification_version: 4
|
79
|
-
summary: Tests
|
80
|
-
test_files:
|
86
|
+
summary: Tests gasoleros (cheap tests).
|
87
|
+
test_files:
|
88
|
+
- spec/matest_spec.rb
|
89
|
+
- spec/matest_specs/nested_scopes_spec.rb
|
90
|
+
- spec/matest_specs/scope_spec.rb
|
91
|
+
- spec/matest_specs/spec_helper.rb
|
92
|
+
- spec/spec_helper.rb
|