matest 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/matest.rb +1 -0
- data/lib/matest/configure.rb +18 -0
- data/lib/matest/spec_printer.rb +72 -29
- data/lib/matest/version.rb +1 -1
- data/matest.gemspec +1 -0
- data/spec/matest_specs/aliases_spec.rb +4 -0
- data/spec/matest_specs/printing_assertion_spec.rb +3 -4
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 561537ac4f243f07f82db71412c6b2c33d5973c5
|
4
|
+
data.tar.gz: 727f060832067bf531677a83f8b623329e513415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8be26c780092220c71fdb57f70e287e1899a59e5d8f491f0ec34e5049cb2ca2ed82b3e5d528fae912754d9a6a630b9ee9f2d83d9615bb9c03b56ac3b517c8ed
|
7
|
+
data.tar.gz: f3edc5feb003a2f69efd06f61f918e6a38775d63e847d6475f3eed10574d8d048a41af3a28ffb0165620bc53fdb74518a541fed34e4bc45ebbe6ad1bc90844f5
|
data/Gemfile
CHANGED
data/lib/matest.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Matest
|
2
|
+
def self.configure(&block)
|
3
|
+
block.call(Configure) if block_given?
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
module Configure
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def use_color?
|
11
|
+
@use_color ||= false
|
12
|
+
end
|
13
|
+
|
14
|
+
def use_color=(use_color)
|
15
|
+
@use_color = use_color
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/matest/spec_printer.rb
CHANGED
@@ -1,13 +1,28 @@
|
|
1
1
|
require "matest/evaluator"
|
2
|
+
require 'term/ansicolor'
|
3
|
+
|
4
|
+
module Matest
|
5
|
+
module Color
|
6
|
+
module_function
|
7
|
+
|
8
|
+
Term::ANSIColor.attributes.each do |attr|
|
9
|
+
define_method(attr) do |str|
|
10
|
+
Matest::Configure.use_color? ? Term::ANSIColor.send(attr, str) : str
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
2
15
|
|
3
16
|
module Matest
|
4
17
|
class SpecPrinter
|
18
|
+
include Color
|
19
|
+
|
5
20
|
def print(res)
|
6
|
-
super res
|
21
|
+
super send(colors[res.class], res.to_s)
|
7
22
|
end
|
8
|
-
|
23
|
+
|
9
24
|
def print_messages(runner)
|
10
|
-
puts "\n\n### Messages ###"
|
25
|
+
puts bright_blue("\n\n### Messages ###")
|
11
26
|
|
12
27
|
statuses = []
|
13
28
|
runner.info[:success] = true
|
@@ -21,41 +36,39 @@ module Matest
|
|
21
36
|
runner.info[:num_specs][status.name] += 1
|
22
37
|
|
23
38
|
if !status.is_a?(Matest::SpecPassed)
|
24
|
-
puts "\n[#{status.name}] #{status.description}"
|
25
|
-
puts "Location
|
39
|
+
puts send(colors[status.class], "\n[#{status.name}] #{status.description}")
|
40
|
+
puts header("Location")
|
41
|
+
puts " #{status.location}:"
|
26
42
|
|
27
43
|
if status.is_a?(Matest::SpecFailed)
|
28
44
|
runner.info[:success] = false
|
29
|
-
puts "Assertion
|
30
|
-
puts "
|
31
|
-
status.example.track_variables.
|
32
|
-
puts "
|
45
|
+
puts header("Assertion")
|
46
|
+
puts " #{status.example.example_block.assertion}"
|
47
|
+
if status.example.track_variables.any?
|
48
|
+
puts header("Variables")
|
49
|
+
status.example.track_variables.each do |var, val|
|
50
|
+
puts " #{var}: #{val.inspect}"
|
51
|
+
end
|
33
52
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
53
|
+
if status.example.track_lets.any?
|
54
|
+
puts header("Lets")
|
55
|
+
status.example.track_lets.each do |var, val|
|
56
|
+
puts " #{var}: #{val.inspect}"
|
57
|
+
end
|
37
58
|
end
|
38
59
|
|
39
|
-
|
40
|
-
subexpressions = Sorcerer.subexpressions(status.example.example_block.assertion_sexp).reverse.uniq.reverse
|
41
|
-
subexpressions.each do |code|
|
42
|
-
print_subexpression(code, status)
|
43
|
-
end
|
60
|
+
print_explanation_for(status)
|
44
61
|
end
|
45
62
|
if status.is_a?(Matest::NotANaturalAssertion)
|
46
63
|
runner.info[:success] = false
|
47
64
|
puts " # => #{status.result.inspect}"
|
48
|
-
|
49
|
-
subexpressions = Sorcerer.subexpressions(status.example.example_block.assertion_sexp).reverse.uniq.reverse
|
50
|
-
subexpressions.each do |code|
|
51
|
-
print_subexpression(code, status)
|
52
|
-
end
|
65
|
+
print_explanation_for(status)
|
53
66
|
end
|
54
67
|
if status.is_a?(Matest::ExceptionRaised)
|
55
68
|
runner.info[:success] = false
|
56
|
-
puts "EXCEPTION >> #{status.result}"
|
69
|
+
puts bright_red("EXCEPTION >> #{status.result}")
|
57
70
|
status.result.backtrace.each do |l|
|
58
|
-
puts " #{l}"
|
71
|
+
puts red(" #{l}")
|
59
72
|
end
|
60
73
|
|
61
74
|
end
|
@@ -64,22 +77,52 @@ module Matest
|
|
64
77
|
end
|
65
78
|
end
|
66
79
|
|
80
|
+
def print_explanation_for(status)
|
81
|
+
subexpressions = Sorcerer.subexpressions(status.example.example_block.assertion_sexp).reverse.uniq.reverse
|
82
|
+
if subexpressions.any?
|
83
|
+
puts header("Explanation")
|
84
|
+
subexpressions.all? do |code|
|
85
|
+
print_subexpression(code, status)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
67
90
|
def print_subexpression(code, status)
|
68
91
|
just_before_assertion = status.example.just_before_assertion
|
69
92
|
result = Evaluator.new(just_before_assertion, just_before_assertion.before_assertion_block).eval_string(code)
|
70
93
|
if result.class != Matest::EvalErr
|
71
|
-
|
72
|
-
#{code}
|
73
|
-
|
74
|
-
|
94
|
+
explanation = []
|
95
|
+
explanation << yellow(" #{code}")
|
96
|
+
explanation << "\n"
|
97
|
+
explanation << bright_blue(" # => #{result}")
|
98
|
+
puts explanation.join
|
99
|
+
true
|
75
100
|
else
|
76
|
-
|
101
|
+
code = <<-CODE
|
77
102
|
The assertion couldn't be explained.
|
78
103
|
The error message was:
|
79
104
|
#{result}
|
80
105
|
Make sure you are not calling any local vaiables on your code assertion.
|
81
106
|
CODE
|
107
|
+
puts red(code)
|
108
|
+
false
|
82
109
|
end
|
83
110
|
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def header(str)
|
115
|
+
blue(str + ":")
|
116
|
+
end
|
117
|
+
|
118
|
+
def colors
|
119
|
+
{
|
120
|
+
Matest::SpecPassed => :green,
|
121
|
+
Matest::SpecFailed => :red,
|
122
|
+
Matest::SpecSkipped => :yellow,
|
123
|
+
Matest::NotANaturalAssertion => :cyan,
|
124
|
+
Matest::ExceptionRaised => :red,
|
125
|
+
}
|
126
|
+
end
|
84
127
|
end
|
85
128
|
end
|
data/lib/matest/version.rb
CHANGED
data/matest.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
scope do
|
2
2
|
let(:three) { 3 }
|
3
|
-
|
3
|
+
xspec "variables and lets" do
|
4
4
|
one = 2
|
5
5
|
two = 2
|
6
6
|
|
@@ -10,13 +10,13 @@ scope do
|
|
10
10
|
@one_plus_two_plus_three.to_i == @res
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
xspec "again?" do
|
14
14
|
@arr = %w[a b c d e]
|
15
15
|
|
16
16
|
@arr.pop == "k"
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
xspec "not natural" do
|
20
20
|
one = 2
|
21
21
|
two = 2
|
22
22
|
|
@@ -25,5 +25,4 @@ scope do
|
|
25
25
|
|
26
26
|
@res = @one_plus_two_plus_three.to_i + @res.to_i
|
27
27
|
end
|
28
|
-
|
29
28
|
end
|
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.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.0.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: term-ansicolor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.0
|
55
69
|
description: Natural assertions test suite.
|
56
70
|
email:
|
57
71
|
- iachetti.federico@gmail.com
|
@@ -67,6 +81,7 @@ files:
|
|
67
81
|
- Rakefile
|
68
82
|
- bin/matest
|
69
83
|
- lib/matest.rb
|
84
|
+
- lib/matest/configure.rb
|
70
85
|
- lib/matest/evaluator.rb
|
71
86
|
- lib/matest/example.rb
|
72
87
|
- lib/matest/example_block.rb
|