solea 0.9.2 → 0.9.3

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/solea +36 -0
  3. data/lib/solea.rb +162 -148
  4. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8892aed1a89ac7902cd0354accfb10e6c6d69c0
4
- data.tar.gz: 907bd4155ed61518e04f5e2298f396e5c9756f81
3
+ metadata.gz: d9b5cf91a34deb5d67c30c7c3ce38e088a269d70
4
+ data.tar.gz: 197fc14c95d0f2572229d8db066a0fe96f937951
5
5
  SHA512:
6
- metadata.gz: a820bdddf834207afafb11a29fca10a7d0e597ee62a758b018b88126cd1bd7d0c887427a9f271ce2e497763a9d6c0c707c5b475a9a59edd8397da98f0b058313
7
- data.tar.gz: 04d3c9988dba0e5c4dbf59ed34cac7f0d40d45e5995bad5160c00c5b60b21c117e43a16f04c3678ee0b33647e2de5a867c426801c170ab5ea02f35448259ef4b
6
+ metadata.gz: 5d869ecd75a04511d01b70d2f8aa537b0b3e6a5cb5a89099fb88c7aee9f28911d838270b5bf43ddf7fdddb90437661f00558cc704676cc94c8dfaa0ccea50ffa
7
+ data.tar.gz: 7b49fcd52fe62ac61636a8a0d7343271a50908232a87eba73f94291916e45416209086fe6d2a8193201f8589b1e5781454d415b7d742e707a9df27f620f296de
data/bin/solea ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'solea.rb'
4
+
5
+ if ARGV[0]
6
+ if ARGV[0].match(/.+\.rb\z/)
7
+ file_name = ARGV[0]
8
+ else
9
+ dir_name = ARGV[0]
10
+ end
11
+ end
12
+ if ARGV[1]
13
+ class_test = Solea.module_eval(File.read(file_name))
14
+ requested = class_test.tests.flatten.find do |test|
15
+ test.metadata[:lineno] == ARGV[1].to_i
16
+ end
17
+ if ARGV[2]
18
+ print requested.metadata[ARGV[2].to_sym], "\n"
19
+ else
20
+ puts "Report requested".center(145, "-"), requested.report
21
+ end
22
+ else
23
+ tests = {}
24
+ if file_name
25
+ file_path = file_name
26
+ else
27
+ dir_name ||= 'spec'
28
+ file_path = "#{dir_name}/**/*_spec.rb"
29
+ end
30
+ Dir.glob(file_path).each do |file|
31
+ class_test = Solea.module_eval(File.read(file))
32
+ tests[file] = class_test.tests
33
+ end
34
+ puts "\nFiles loaded: #{tests.keys.join(", ")}"
35
+ puts Solea.report(tests)
36
+ end
data/lib/solea.rb CHANGED
@@ -1,162 +1,176 @@
1
- class ClassTest
2
- def initialize(class_name, &block)
3
- @class_name = class_name
4
- @tests = []
5
- block.call(self)
6
- print report
7
- end
8
-
9
- def test_method(method_name, &block)
10
- method_test = MethodTest.new(method_name)
11
- block.call(method_test)
12
- @tests << method_test.tests
13
- end
14
-
15
- def report
16
- @tests = @tests.flatten
17
- @passing_tests = @tests.select{|test| test.pass}
18
- @failing_tests = @tests.select{|test| !test.pass}
19
- text_color = (@failing_tests.any? ? "37;41;1" : "37;47;1")
20
- message = "\n\e[#{text_color}m" + "#{@passing_tests.count} of #{@tests.count} tests passed.".center(145) + "\e[0m\n\n" +
21
- "| lineno: pass/fail |".center(145, "-") + "\n\n|"
22
- @tests.each_with_index do |test, i|
23
- text_color = (test.pass ? "0" : "37;41;1")
24
- status = (test.pass ? "pass" : "fail")
25
- message += "\e[#{text_color}m #{"%3d" % test.state[:hypothesis_caller].lineno}: #{status} \e[0m|"
26
- message += "\n|" if (i + 1) % 12 == 0
27
- end
28
- message += "\n\nFor detailed information on any test, try \"m.print{|t| t.report}\" after the test's expect/assert statement."
29
- "#{message}\n\n"
30
- end
31
- end
32
-
33
- class MethodTest
34
- attr_accessor :method_name, :pass, :tests
35
-
36
- def initialize(method_name)
37
- @method_name = method_name
38
- @tests = []
39
- @exceptions = []
40
- @notes = []
41
- end
42
-
43
- def before(&block)
44
- @before = yield
45
- end
46
-
47
- def describe(&block)
48
- @description = yield
49
- @notes = []
50
- end
51
-
52
- def note(&block)
53
- @notes << yield
54
- end
55
-
56
- def example(&block)
57
- @example_caller = caller_locations(1,1)[0]
58
- @exceptions = []
59
- begin
60
- @example = block.call(@before)
61
- rescue Exception => e
62
- @example = block
63
- @exceptions << [e, @example_caller]
1
+ module Solea
2
+ def self.report(tests)
3
+ all_tests = []
4
+ passing_tests = []
5
+ tests.each do |filename, tests_array|
6
+ tests_array = tests_array.flatten
7
+ all_tests << tests_array
8
+ passing_tests << tests_array.select{|test| test.pass }
9
+ tests[filename] = tests_array.select{|test| !test.pass }
64
10
  end
11
+ all_tests, passing_tests = all_tests.flatten, passing_tests.flatten
12
+ text_color = (all_tests.count == passing_tests.count ? "37;47;1" : "37;41;1")
13
+ message = "\n\e[#{text_color}m" + "#{passing_tests.count} of #{all_tests.count} tests passed.".center(145) + "\e[0m\n\n"
14
+ unless all_tests.count == passing_tests.count
15
+ message += "Failing tests: \"file path: lineno\"".center(145, "-")
16
+ tests.each do |filename, failing_tests|
17
+ if failing_tests.any?
18
+ message += "\n" + failing_tests.map do |test|
19
+ "#{filename} #{test.metadata[:lineno]}"
20
+ end.join("\n") + "\n\n"
21
+ end
22
+ end
23
+ end
24
+ message
65
25
  end
66
26
 
67
- def assert(&block)
68
- @hypothesis_caller = caller_locations(1,1)[0]
69
- begin
70
- @pass = block.call(@example)
71
- rescue Exception => e
72
- @pass = false
73
- @exceptions << [e, @hypothesis_caller]
74
- end
75
- @tests << self.dup
76
- end
27
+ class ClassTest
28
+ attr_accessor :tests
77
29
 
78
- def assert!(&block)
79
- @hypothesis_caller = caller_locations(1,1)[0]
80
- begin
81
- @pass = !block.call(@example)
82
- rescue Exception => e
83
- @pass = false
84
- @exceptions << [e, @hypothesis_caller]
85
- end
86
- @tests << self.dup
30
+ def initialize(class_name, &block)
31
+ @class_name = class_name
32
+ @tests = []
33
+ instance_exec &block
34
+ end
35
+
36
+ def test_method(method_name, &block)
37
+ method_test = MethodTest.new(method_name)
38
+ method_test.execute &block
39
+ @tests << method_test.tests
40
+ end
41
+
42
+ def report
43
+ Solea.report({ @filename => @tests })
44
+ end
87
45
  end
46
+
47
+ class MethodTest
48
+ attr_accessor :method_name, :pass, :tests
49
+
50
+ def initialize(method_name)
51
+ @method_name = method_name
52
+ @tests = []
53
+ @exceptions = []
54
+ @notes = []
55
+ end
56
+
57
+ def execute(&block)
58
+ instance_exec &block
59
+ end
88
60
 
89
- def expect(exception_expected = nil, &block)
90
- @hypothesis_caller = caller_locations(1,1)[0]
91
- if exception_expected
92
- test_for_exception(exception_expected, block)
93
- else
61
+ def before(&block)
62
+ @before = yield
63
+ end
64
+
65
+ def describe(&block)
66
+ @description = yield
67
+ @notes = []
68
+ end
69
+
70
+ def note(&block)
71
+ @notes << yield
72
+ end
73
+
74
+ def example(&block)
75
+ @example_caller = caller_locations(1,1)[0]
76
+ @exceptions = []
77
+ begin
78
+ @example = block.call(@before)
79
+ rescue Exception => e
80
+ @example = block
81
+ @exceptions << [e, @example_caller]
82
+ end
83
+ end
84
+
85
+ def assert(&block)
86
+ @hypothesis_caller = caller_locations(1,1)[0]
94
87
  begin
95
- @pass = yield == @example
88
+ @pass = block.call(@example)
96
89
  rescue Exception => e
97
90
  @pass = false
98
91
  @exceptions << [e, @hypothesis_caller]
99
92
  end
93
+ @tests << self.dup
94
+ end
95
+
96
+ def assert!(&block)
97
+ @hypothesis_caller = caller_locations(1,1)[0]
98
+ begin
99
+ @pass = !block.call(@example)
100
+ rescue Exception => e
101
+ @pass = false
102
+ @exceptions << [e, @hypothesis_caller]
103
+ end
104
+ @tests << self.dup
105
+ end
106
+
107
+ def expect(exception_expected = nil, &block)
108
+ @hypothesis_caller = caller_locations(1,1)[0]
109
+ if exception_expected
110
+ test_for_exception(exception_expected, block)
111
+ else
112
+ begin
113
+ @pass = yield == @example
114
+ rescue Exception => e
115
+ @pass = false
116
+ @exceptions << [e, @hypothesis_caller]
117
+ end
118
+ end
119
+ @tests << self.dup
120
+ end
121
+
122
+ def expect!(&block)
123
+ @hypothesis_caller = caller_locations(1,1)[0]
124
+ begin
125
+ @pass = yield != @example
126
+ rescue Exception => e
127
+ @pass = false
128
+ @exceptions << [e, @hypothesis_caller]
129
+ end
130
+ @tests << self.dup
131
+ end
132
+
133
+ def test_for_exception(exception_expected, block)
134
+ begin
135
+ block_code = block.call(@example)
136
+ rescue Exception => e
137
+ block_code = block
138
+ @exceptions << [e, @hypothesis_caller]
139
+ end
140
+ if block_code.nil?
141
+ test = @example.is_a?(Proc)
142
+ else
143
+ test = block_code.is_a?(Proc)
144
+ end
145
+ @pass = test if exception_expected == :fail
146
+ @pass = !test if exception_expected == :pass
147
+ end
148
+
149
+ def metadata
150
+ { :before => @before,
151
+ :description => @description,
152
+ :example => @example,
153
+ :lineno => (@hypothesis_caller.lineno if @hypothesis_caller),
154
+ :exceptions => @exceptions,
155
+ :notes => @notes,
156
+ :pass => @pass
157
+ }
158
+ end
159
+
160
+ def print(&block)
161
+ puts block.call(self)
162
+ end
163
+
164
+ def report
165
+ report_caller = caller_locations(1,1)[0]
166
+ report = "method name: #{" " * ("description".length - "method name".length)}\"#{@method_name}\"\n"
167
+ metadata.each do |k, v|
168
+ spaces = " " * ("description".length - k.length)
169
+ v = "\"#{v}\"" if v.is_a?(String)
170
+ v = "[#{"." * v.length}]" if v.is_a?(Array) || v.is_a?(Hash)
171
+ report += "#{k}: #{spaces}#{v}\n"
172
+ end
173
+ report
100
174
  end
101
- @tests << self.dup
102
- end
103
-
104
- def expect!(&block)
105
- @hypothesis_caller = caller_locations(1,1)[0]
106
- begin
107
- @pass = yield != @example
108
- rescue Exception => e
109
- @pass = false
110
- @exceptions << [e, @hypothesis_caller]
111
- end
112
- @tests << self.dup
113
- end
114
-
115
- def test_for_exception(exception_expected, block)
116
- begin
117
- block_code = block.call(@example)
118
- rescue Exception => e
119
- block_code = block
120
- @exceptions << [e, @hypothesis_caller]
121
- end
122
- if block_code.nil?
123
- test = @example.is_a?(Proc)
124
- else
125
- test = block_code.is_a?(Proc)
126
- end
127
- @pass = test if exception_expected == :fail
128
- @pass = !test if exception_expected == :pass
129
- end
130
-
131
- def state
132
- { :before => @before,
133
- :description => @description,
134
- :example => @example,
135
- :example_caller => @example_caller,
136
- :exceptions => @exceptions,
137
- :hypothesis_caller => @hypothesis_caller,
138
- :notes => @notes,
139
- :pass => @pass
140
- }
141
- end
142
-
143
- def print(&block)
144
- puts block.call(self)
145
- end
146
-
147
- def report
148
- report_caller = caller_locations(1,1)[0]
149
- report = "\n" + "Report requested on line #{report_caller.lineno}".center(145, "-") + "\n\n" +
150
- "-Except for \"method name\", each of the terms in the lefthand column below is a key in the #state hash.\n" +
151
- "-Thus, for example, the @exceptions array can be accessed for more information with \"m.print{|t| t.state[:exceptions]}\".\n" +
152
- "-Arrays and hashes are abbreviated below; the number of dots represents their length.\n\n" +
153
- "method name: #{" " * ("hypothesis_caller".length - "Method name".length)}\"#{@method_name}\"\n"
154
- state.each do |k, v|
155
- spaces = " " * ("hypothesis_caller".length - k.length)
156
- v = "\"#{v}\"" if v.is_a?(String)
157
- v = "[#{"." * v.length}]" if v.is_a?(Array) || v.is_a?(Hash)
158
- report += "#{k}: #{spaces}#{v}\n"
159
- end
160
- report
161
175
  end
162
176
  end
metadata CHANGED
@@ -1,22 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Swetnam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-15 00:00:00.000000000 Z
11
+ date: 2013-09-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple, streamlined unit testing gem.
14
14
  email: jbswetnam@gmail.com
15
- executables: []
15
+ executables:
16
+ - solea
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
19
20
  - lib/solea.rb
21
+ - bin/solea
20
22
  homepage: https://github.com/crownyx/solea
21
23
  licenses: []
22
24
  metadata: {}