matest 1.3.0 → 1.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84452e41b4f3cd9abc5a1bbc3f908700a9cc8861
4
- data.tar.gz: 68d2dabb2017c46bc31eb36d8b67e918e8eddab7
3
+ metadata.gz: 561537ac4f243f07f82db71412c6b2c33d5973c5
4
+ data.tar.gz: 727f060832067bf531677a83f8b623329e513415
5
5
  SHA512:
6
- metadata.gz: 16fa8463a914188a962999097d5c9b54182c56dc5ed3f528cf2a010dcf1bf75ae9b62dfa9d8c61ab6402c8116e6fce2181d2398afb2db80c35db6c822f7abd70
7
- data.tar.gz: 35dcf6b249937b2a4eed2491dd8d4f2d5ed5c319a1973b45d64189bd38991f4f3127692e084ecb0e0d555810184c3dcffd395159490b7aa676971f6de91d28ad
6
+ metadata.gz: b8be26c780092220c71fdb57f70e287e1899a59e5d8f491f0ec34e5049cb2ca2ed82b3e5d528fae912754d9a6a630b9ee9f2d83d9615bb9c03b56ac3b517c8ed
7
+ data.tar.gz: f3edc5feb003a2f69efd06f61f918e6a38775d63e847d6475f3eed10574d8d048a41af3a28ffb0165620bc53fdb74518a541fed34e4bc45ebbe6ad1bc90844f5
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "https://rubygems.org"
2
- gemspec
2
+ gemspec
3
3
 
data/lib/matest.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "matest/version"
2
2
 
3
+ require "matest/configure"
3
4
  require "matest/runner"
4
5
  require "matest/example_group"
5
6
  require "matest/example"
@@ -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
@@ -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:\n #{status.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: \n #{status.example.example_block.assertion}"
30
- puts "Variables: "
31
- status.example.track_variables.each do |var, val|
32
- puts " #{var}: #{val.inspect}"
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
- puts "Lets: "
35
- status.example.track_lets.each do |var, val|
36
- puts " #{var}: #{val.inspect}"
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
- puts "Explanation:"
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
- puts "Explanation:"
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
- puts <<-CODE
72
- #{code}
73
- # => #{result}
74
- CODE
94
+ explanation = []
95
+ explanation << yellow(" #{code}")
96
+ explanation << "\n"
97
+ explanation << bright_blue(" # => #{result}")
98
+ puts explanation.join
99
+ true
75
100
  else
76
- puts <<-CODE
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
@@ -1,3 +1,3 @@
1
1
  module Matest
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
data/matest.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
 
24
24
  spec.add_dependency "sorcerer", "~> 1.0.2"
25
+ spec.add_dependency "term-ansicolor", "~> 1.3.0"
25
26
  end
@@ -1,3 +1,7 @@
1
+ Matest.configure do |c|
2
+ c.use_color = true
3
+ end
4
+
1
5
  scope do
2
6
  spec { true }
3
7
  xspec { false }
@@ -1,6 +1,6 @@
1
1
  scope do
2
2
  let(:three) { 3 }
3
- spec "variables and lets" do
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
- spec "again?" do
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
- spec "not natural" do
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.0
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