matest 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 +4 -4
- data/README.md +45 -23
- data/lib/matest.rb +25 -51
- data/lib/matest/spec_printer.rb +47 -0
- data/lib/matest/spec_status.rb +8 -6
- data/lib/matest/version.rb +1 -1
- data/spec/matest_specs/failing_spec.rb +7 -0
- data/spec/matest_specs/matchers_spec.rb +12 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19f65ecc765b4eb7cdb7eaf25c6f5648d9c901f2
|
4
|
+
data.tar.gz: ec5e805afbf404d59335d25815b37aeb6cbe4578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dfd3eb0dae94b317f4490b9f32ac0c74b0e8f1bb823c186137cd385bb6dca7d96ad9ad4901124254a3e5683f066142246d57bdb9eef6041e7f9736288ba5337
|
7
|
+
data.tar.gz: f41231aa62ed1453868d538734f6355ddc5409c0b9b9afaea4886d35a000f205ffa720f4750d40c2639bf3698a05a716119d7b7aa8e0d8eb4344f7894c82356b
|
data/README.md
CHANGED
@@ -11,24 +11,8 @@ It doesn't use the usual assertion style (`assert(1, 1)`) nor the rspec style(`1
|
|
11
11
|
It uses natural assertions.
|
12
12
|
|
13
13
|
This means that:
|
14
|
-
- A test will pass if it returns true
|
15
|
-
- A test will fail if it returns false
|
16
|
-
|
17
|
-
## Installation
|
18
|
-
|
19
|
-
Add this line to your application's Gemfile:
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
gem 'matest'
|
23
|
-
```
|
24
|
-
|
25
|
-
And then execute:
|
26
|
-
|
27
|
-
$ bundle
|
28
|
-
|
29
|
-
Or install it yourself as:
|
30
|
-
|
31
|
-
$ gem install matest
|
14
|
+
- A test will pass if it returns `true`
|
15
|
+
- A test will fail if it returns `false`
|
32
16
|
|
33
17
|
## Usage
|
34
18
|
|
@@ -61,7 +45,7 @@ scope do
|
|
61
45
|
end
|
62
46
|
```
|
63
47
|
|
64
|
-
If the return value of the `spec` block is `true`, the spec will pass and if it's false it will
|
48
|
+
If the return value of the `spec` block is `true`, the spec will pass and if it's `false` it will fail.
|
65
49
|
|
66
50
|
If you return anithing else, you'll get a `NOT A NATURAL ASSERTION` status.
|
67
51
|
|
@@ -85,10 +69,10 @@ You can skip a test in two possible ways: You can declare a spec whithout a bloc
|
|
85
69
|
|
86
70
|
```ruby
|
87
71
|
scope do
|
88
|
-
|
72
|
+
spec "I'll be skipped"
|
73
|
+
xspec "I'll be skipped too" do
|
89
74
|
true
|
90
75
|
end
|
91
|
-
spec "I'll be skipped too"
|
92
76
|
end
|
93
77
|
```
|
94
78
|
|
@@ -98,11 +82,11 @@ You can skip the whole scope by using `xscope` instead of `scope`.
|
|
98
82
|
|
99
83
|
Take into account that `xscope` is a no-op so you won't be informed when you skip a scope.
|
100
84
|
|
101
|
-
##
|
85
|
+
## `#let` and `#let!`
|
102
86
|
|
103
87
|
Matest steals the `let` and `let!` features from `RSpec` and `Minitest`.
|
104
88
|
|
105
|
-
With `let` you can declare a lazy variable valid on the current scope and all sub-scopes.
|
89
|
+
With `let` you can declare a lazy variable valid on the current scope and all sub-scopes. `let!` has the same efect, but it won't be lazy (it wil be loaded when defined).
|
106
90
|
|
107
91
|
Here are some examples of what you can do with them:
|
108
92
|
|
@@ -147,6 +131,28 @@ scope do
|
|
147
131
|
end
|
148
132
|
```
|
149
133
|
|
134
|
+
## Matchers
|
135
|
+
|
136
|
+
Matest doesn't come with predefined matchers, it doesn't need them. In fact, the concept of a matcher is not required, because of the natural assertions nature of the library.
|
137
|
+
|
138
|
+
But you can define helper methods to *assert* long, complex or repeated logic:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
def is_even?(val)
|
142
|
+
val % 2 == 0
|
143
|
+
end
|
144
|
+
|
145
|
+
scope do
|
146
|
+
spec do
|
147
|
+
is_even?(4)
|
148
|
+
end
|
149
|
+
|
150
|
+
spec do
|
151
|
+
! is_even?(5)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
150
156
|
## Aliases
|
151
157
|
|
152
158
|
You may be used to other keywords provenient from different testing frameworks. Matest has a couple of alias that you may use indistinctly to fit your style.
|
@@ -161,6 +167,22 @@ You may be used to other keywords provenient from different testing frameworks.
|
|
161
167
|
- `test` (and `xtest`)
|
162
168
|
- `example` (and `xexample`)
|
163
169
|
|
170
|
+
## Installation
|
171
|
+
|
172
|
+
Add this line to your application's Gemfile:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
gem 'matest'
|
176
|
+
```
|
177
|
+
|
178
|
+
And then execute:
|
179
|
+
|
180
|
+
$ bundle
|
181
|
+
|
182
|
+
Or install it yourself as:
|
183
|
+
|
184
|
+
$ gem install matest
|
185
|
+
|
164
186
|
## Contributing
|
165
187
|
|
166
188
|
1. Fork it ( https://github.com/[my-github-username]/matest/fork )
|
data/lib/matest.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
require "matest/version"
|
2
2
|
require "matest/spec_status"
|
3
|
+
require "matest/spec_printer"
|
4
|
+
|
5
|
+
|
3
6
|
module Matest
|
4
7
|
class Runner
|
5
8
|
attr_reader :example_groups
|
6
9
|
attr_reader :info
|
10
|
+
attr_reader :printer
|
7
11
|
|
8
|
-
def initialize
|
12
|
+
def initialize(printer: SpecPrinter.new)
|
9
13
|
@example_groups = []
|
10
|
-
@info
|
14
|
+
@info = {}
|
15
|
+
@printer = printer
|
11
16
|
end
|
12
17
|
|
13
18
|
def self.runner
|
@@ -26,60 +31,26 @@ module Matest
|
|
26
31
|
example_groups.each do |current_group|
|
27
32
|
current_group.execute!
|
28
33
|
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def print_messages
|
33
|
-
puts "\n\n### Messages ###"
|
34
|
-
|
35
|
-
statuses = []
|
36
|
-
info[:success] = true
|
37
|
-
info[:num_specs] = { total: 0 }
|
38
|
-
|
39
|
-
example_groups.each do |current_group|
|
40
|
-
current_group.statuses.each do |status|
|
41
|
-
info[:num_specs][:total] += 1
|
42
|
-
|
43
|
-
info[:num_specs][status.name] ||= 0
|
44
|
-
info[:num_specs][status.name] += 1
|
45
|
-
|
46
|
-
if status.is_a?(Matest::SpecPassed)
|
47
|
-
else
|
48
|
-
if status.is_a?(Matest::SpecFailed)
|
49
|
-
info[:success] = false
|
50
|
-
end
|
51
|
-
puts "\n[#{status.name}] #{status.description}"
|
52
|
-
if status.is_a?(Matest::NotANaturalAssertion)
|
53
|
-
info[:success] = false
|
54
|
-
puts " # => #{status.result.inspect}"
|
55
|
-
end
|
56
|
-
if status.is_a?(Matest::ExceptionRaised)
|
57
|
-
info[:success] = false
|
58
|
-
puts "EXCEPTION >> #{status.result}"
|
59
|
-
status.result.backtrace.each do |l|
|
60
|
-
puts " #{l}"
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
puts " #{status.location}:"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
34
|
+
printer.print(self)
|
68
35
|
end
|
69
36
|
end
|
70
37
|
|
71
38
|
class SkipMe; end
|
72
39
|
|
73
40
|
class Example
|
74
|
-
|
75
|
-
|
41
|
+
def example_block
|
42
|
+
@__example_block
|
43
|
+
end
|
44
|
+
def description
|
45
|
+
@__description
|
46
|
+
end
|
76
47
|
|
77
48
|
def initialize(example_block, description, lets)
|
78
|
-
@
|
79
|
-
@
|
49
|
+
@__example_block = example_block
|
50
|
+
@__description = description
|
80
51
|
lets.each do |let|
|
81
52
|
self.class.let(let.var_name, &let.block)
|
82
|
-
|
53
|
+
send(let.var_name) if let.and_call
|
83
54
|
end
|
84
55
|
end
|
85
56
|
|
@@ -92,20 +63,24 @@ module Matest
|
|
92
63
|
instance_variable_set(:"@#{var_name}", block.call)
|
93
64
|
end
|
94
65
|
end
|
66
|
+
|
67
|
+
def track
|
68
|
+
instance_variables.reject {|i| i.to_s =~ /\A@__/}.map {|i| [i, instance_variable_get(i)] }
|
69
|
+
end
|
95
70
|
end
|
96
71
|
|
97
72
|
class Let
|
98
73
|
attr_reader :var_name
|
99
74
|
attr_reader :block
|
100
75
|
attr_reader :and_call
|
101
|
-
|
76
|
+
|
102
77
|
def initialize(var_name, block, and_call=false)
|
103
78
|
@var_name = var_name
|
104
79
|
@block = block
|
105
80
|
@and_call = and_call
|
106
81
|
end
|
107
82
|
end
|
108
|
-
|
83
|
+
|
109
84
|
class ExampleGroup
|
110
85
|
attr_reader :scope_block
|
111
86
|
attr_reader :specs
|
@@ -169,14 +144,13 @@ module Matest
|
|
169
144
|
else
|
170
145
|
Matest::NotANaturalAssertion
|
171
146
|
end
|
172
|
-
status_class.new(spec
|
147
|
+
status_class.new(spec, result)
|
173
148
|
rescue Exception => e
|
174
|
-
Matest::ExceptionRaised.new(spec
|
149
|
+
Matest::ExceptionRaised.new(spec, e, spec.description)
|
175
150
|
end
|
176
151
|
@statuses << status
|
177
152
|
status
|
178
153
|
end
|
179
|
-
|
180
154
|
end
|
181
155
|
end
|
182
156
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Matest
|
2
|
+
|
3
|
+
class SpecPrinter
|
4
|
+
|
5
|
+
def print(runner)
|
6
|
+
puts "\n\n### Messages ###"
|
7
|
+
|
8
|
+
statuses = []
|
9
|
+
runner.info[:success] = true
|
10
|
+
runner.info[:num_specs] = { total: 0 }
|
11
|
+
|
12
|
+
runner.example_groups.each do |current_group|
|
13
|
+
current_group.statuses.each do |status|
|
14
|
+
runner.info[:num_specs][:total] += 1
|
15
|
+
|
16
|
+
runner.info[:num_specs][status.name] ||= 0
|
17
|
+
runner.info[:num_specs][status.name] += 1
|
18
|
+
|
19
|
+
if status.is_a?(Matest::SpecPassed)
|
20
|
+
else
|
21
|
+
puts "\n[#{status.name}] #{status.description}"
|
22
|
+
if status.is_a?(Matest::SpecFailed)
|
23
|
+
runner.info[:success] = false
|
24
|
+
puts "Variables: "
|
25
|
+
status.example.track.each do |var, val|
|
26
|
+
puts " #{var}: #{val.inspect}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
if status.is_a?(Matest::NotANaturalAssertion)
|
30
|
+
runner.info[:success] = false
|
31
|
+
puts " # => #{status.result.inspect}"
|
32
|
+
end
|
33
|
+
if status.is_a?(Matest::ExceptionRaised)
|
34
|
+
runner.info[:success] = false
|
35
|
+
puts "EXCEPTION >> #{status.result}"
|
36
|
+
status.result.backtrace.each do |l|
|
37
|
+
puts " #{l}"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
puts " #{status.location}:"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/matest/spec_status.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module Matest
|
2
2
|
class SpecStatus
|
3
|
-
attr_reader :
|
4
|
-
attr_reader :description
|
3
|
+
attr_reader :example
|
5
4
|
attr_reader :result
|
6
5
|
|
7
|
-
def initialize(
|
8
|
-
@
|
6
|
+
def initialize(example, result, description=nil)
|
7
|
+
@example = example
|
9
8
|
@result = result
|
10
|
-
@description = description
|
11
9
|
end
|
12
10
|
|
13
11
|
def location
|
14
|
-
"%s:%d" %
|
12
|
+
"%s:%d" % example.example_block.source_location
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
example.description
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
data/lib/matest/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
@@ -53,10 +53,13 @@ files:
|
|
53
53
|
- Rakefile
|
54
54
|
- bin/mt
|
55
55
|
- lib/matest.rb
|
56
|
+
- lib/matest/spec_printer.rb
|
56
57
|
- lib/matest/spec_status.rb
|
57
58
|
- lib/matest/version.rb
|
58
59
|
- matest.gemspec
|
59
60
|
- spec/matest_spec.rb
|
61
|
+
- spec/matest_specs/failing_spec.rb
|
62
|
+
- spec/matest_specs/matchers_spec.rb
|
60
63
|
- spec/matest_specs/nested_scopes_spec.rb
|
61
64
|
- spec/matest_specs/passing_spec.rb
|
62
65
|
- spec/matest_specs/scope_spec.rb
|
@@ -89,6 +92,8 @@ specification_version: 4
|
|
89
92
|
summary: Tests gasoleros (cheap tests).
|
90
93
|
test_files:
|
91
94
|
- spec/matest_spec.rb
|
95
|
+
- spec/matest_specs/failing_spec.rb
|
96
|
+
- spec/matest_specs/matchers_spec.rb
|
92
97
|
- spec/matest_specs/nested_scopes_spec.rb
|
93
98
|
- spec/matest_specs/passing_spec.rb
|
94
99
|
- spec/matest_specs/scope_spec.rb
|