exemplor 2010.2.0 → 3000.1.0
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.
- data/README.md +221 -0
- data/Rakefile +8 -4
- data/TODO +13 -6
- data/VERSION +1 -1
- data/examples.rb +62 -51
- data/examples/assertion_failure.rb +3 -5
- data/examples/assertion_success.rb +2 -3
- data/examples/assertion_success_and_failure.rb +8 -12
- data/examples/assertion_success_and_info.rb +8 -11
- data/examples/check_parsing.rb +8 -17
- data/examples/checking_nil.rb +6 -5
- data/examples/failure_halts_execution.rb +3 -5
- data/examples/foobar.rb +9 -0
- data/examples/helpers.rb +1 -1
- data/examples/{with_checks.rb → multi_show.rb} +3 -3
- data/examples/no_checks_non_string.rb +1 -1
- data/examples/{check_with_disambiguation.rb → show_with_disambiguation.rb} +2 -2
- data/examples/{dumping_classes.rb → showing_classes.rb} +1 -1
- data/examples/simple_show.rb +15 -0
- data/examples/ten_percent_failures.rb +10 -10
- data/examples/with_setup.rb +5 -7
- data/lib/checker.rb +30 -10
- data/lib/environment.rb +32 -23
- data/lib/examples.rb +2 -1
- data/lib/exemplor.rb +2 -1
- data/lib/result_printer.rb +40 -21
- data/vendor/orderedhash-0.0.6/gemspec.rb +37 -0
- data/vendor/orderedhash-0.0.6/install.rb +213 -0
- data/vendor/orderedhash-0.0.6/lib/orderedautohash.rb +25 -0
- data/vendor/orderedhash-0.0.6/lib/orderedhash.rb +200 -0
- data/vendor/term-ansicolor-1.0.5/CHANGES +28 -0
- data/vendor/term-ansicolor-1.0.5/COPYING +340 -0
- data/vendor/term-ansicolor-1.0.5/README +137 -0
- data/vendor/term-ansicolor-1.0.5/Rakefile +88 -0
- data/vendor/term-ansicolor-1.0.5/VERSION +1 -0
- data/vendor/term-ansicolor-1.0.5/bin/cdiff +19 -0
- data/vendor/term-ansicolor-1.0.5/bin/decolor +12 -0
- data/vendor/term-ansicolor-1.0.5/examples/example.rb +90 -0
- data/vendor/term-ansicolor-1.0.5/install.rb +15 -0
- data/vendor/term-ansicolor-1.0.5/lib/term/ansicolor.rb +102 -0
- data/vendor/term-ansicolor-1.0.5/lib/term/ansicolor/version.rb +10 -0
- data/vendor/term-ansicolor-1.0.5/tests/ansicolor_test.rb +66 -0
- metadata +34 -41
- data/README +0 -152
@@ -2,10 +2,10 @@ require 'exemplor'
|
|
2
2
|
|
3
3
|
eg 'Some successes, then an info' do
|
4
4
|
list = [1, 2, 3]
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
Assert(list.first ==1)
|
6
|
+
Assert(list[1] == 2)
|
7
|
+
Show(list.last) # the info one
|
8
|
+
Assert(list[2] == 3)
|
9
9
|
end
|
10
10
|
|
11
11
|
__END__
|
@@ -13,15 +13,12 @@ __END__
|
|
13
13
|
- name: Some successes, then an info
|
14
14
|
status: info (with checks)
|
15
15
|
result:
|
16
|
-
- name: list.first
|
16
|
+
- name: list.first ==1
|
17
17
|
status: success
|
18
|
-
|
19
|
-
- name: list[1]
|
18
|
+
- name: list[1] == 2
|
20
19
|
status: success
|
21
|
-
result: 2
|
22
20
|
- name: list.last
|
23
21
|
status: info
|
24
22
|
result: 3
|
25
|
-
- name: list[2]
|
26
|
-
status: success
|
27
|
-
result: 3
|
23
|
+
- name: list[2] == 3
|
24
|
+
status: success
|
data/examples/check_parsing.rb
CHANGED
@@ -5,29 +5,26 @@ eg.helpers do
|
|
5
5
|
end
|
6
6
|
|
7
7
|
eg "plain call" do
|
8
|
-
|
8
|
+
Show(foo)
|
9
9
|
end
|
10
10
|
|
11
11
|
eg "whitespace after the call (seriously)" do
|
12
|
-
|
12
|
+
Show(foo)
|
13
13
|
end
|
14
14
|
|
15
15
|
eg "comment after the call" do
|
16
|
-
|
16
|
+
Show(foo) # comment!
|
17
17
|
end
|
18
18
|
|
19
19
|
eg "with brackets" do
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
eg "with brackets and is" do
|
24
|
-
Check(String.new('test')).is("test")
|
20
|
+
Show(String.new('test'))
|
25
21
|
end
|
26
22
|
|
27
23
|
eg "with disambiguation" do
|
28
|
-
|
24
|
+
Show(foo)['bar']
|
29
25
|
end
|
30
26
|
|
27
|
+
|
31
28
|
__END__
|
32
29
|
|
33
30
|
- name: plain call
|
@@ -54,15 +51,9 @@ __END__
|
|
54
51
|
- name: String.new('test')
|
55
52
|
status: info
|
56
53
|
result: test
|
57
|
-
- name: with brackets and is
|
58
|
-
status: success
|
59
|
-
result:
|
60
|
-
- name: String.new('test')
|
61
|
-
status: success
|
62
|
-
result: test
|
63
54
|
- name: with disambiguation
|
64
|
-
status:
|
55
|
+
status: info (with checks)
|
65
56
|
result:
|
66
57
|
- name: foo bar
|
67
|
-
status:
|
58
|
+
status: info
|
68
59
|
result: bar
|
data/examples/checking_nil.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'exemplor'
|
2
2
|
|
3
|
+
# this is kind of a compromise, looking for better ideas
|
4
|
+
|
3
5
|
eg "checking nil works correctly" do
|
4
|
-
|
6
|
+
Show(nil)
|
5
7
|
end
|
6
8
|
|
7
9
|
eg "asserting for nil works correctly" do
|
8
|
-
|
10
|
+
Assert(nil == nil)
|
9
11
|
end
|
10
12
|
|
11
13
|
__END__
|
@@ -19,6 +21,5 @@ __END__
|
|
19
21
|
- name: asserting for nil works correctly
|
20
22
|
status: success
|
21
23
|
result:
|
22
|
-
- name: nil
|
23
|
-
status: success
|
24
|
-
result:
|
24
|
+
- name: nil == nil
|
25
|
+
status: success
|
@@ -2,7 +2,7 @@ require 'exemplor'
|
|
2
2
|
|
3
3
|
eg 'Failures halt execution' do
|
4
4
|
list = [1, 2, 3]
|
5
|
-
|
5
|
+
Assert(list.first == 1_000_000) # fail!
|
6
6
|
raise "foo" # we never get here
|
7
7
|
end
|
8
8
|
|
@@ -11,7 +11,5 @@ __END__
|
|
11
11
|
- name: Failures halt execution
|
12
12
|
status: failure
|
13
13
|
result:
|
14
|
-
- name: list.first
|
15
|
-
status: failure
|
16
|
-
expected: 1000000
|
17
|
-
actual: 1
|
14
|
+
- name: list.first == 1_000_000
|
15
|
+
status: failure
|
data/examples/foobar.rb
ADDED
data/examples/helpers.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'exemplor'
|
2
|
+
|
3
|
+
eg 'Showing the value of some expression' do
|
4
|
+
list = [1, 2, 3]
|
5
|
+
Show(list.first)
|
6
|
+
end
|
7
|
+
|
8
|
+
__END__
|
9
|
+
|
10
|
+
- name: Showing the value of some expression
|
11
|
+
status: info (with checks)
|
12
|
+
result:
|
13
|
+
- name: list.first
|
14
|
+
status: info
|
15
|
+
result: 1
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'exemplor'
|
2
2
|
|
3
|
-
eg {
|
4
|
-
eg {
|
5
|
-
eg {
|
6
|
-
eg {
|
7
|
-
eg {
|
8
|
-
eg {
|
9
|
-
eg {
|
10
|
-
eg {
|
11
|
-
eg {
|
12
|
-
eg {
|
3
|
+
eg { Assert(1 == 1) }
|
4
|
+
eg { Assert(2 == 2) }
|
5
|
+
eg { Assert(3 == 3) }
|
6
|
+
eg { Assert(4 == 4) }
|
7
|
+
eg { Assert(5 == 5) }
|
8
|
+
eg { Assert(6 == 6) }
|
9
|
+
eg { Assert(7 == 7) }
|
10
|
+
eg { Assert(8 == 8) }
|
11
|
+
eg { Assert(9 == 9) }
|
12
|
+
eg { Assert(false == true) }
|
data/examples/with_setup.rb
CHANGED
@@ -4,11 +4,11 @@ eg.setup { @str = "foo" }
|
|
4
4
|
|
5
5
|
eg 'Modified env' do
|
6
6
|
@str << " bar"
|
7
|
-
|
7
|
+
Assert(@str == 'foo bar')
|
8
8
|
end
|
9
9
|
|
10
10
|
eg 'Unmodified env' do
|
11
|
-
|
11
|
+
Assert(@str == 'foo')
|
12
12
|
end
|
13
13
|
|
14
14
|
__END__
|
@@ -16,12 +16,10 @@ __END__
|
|
16
16
|
- name: Modified env
|
17
17
|
status: success
|
18
18
|
result:
|
19
|
-
- name: "@str"
|
19
|
+
- name: "@str == 'foo bar'"
|
20
20
|
status: success
|
21
|
-
result: foo bar
|
22
21
|
- name: Unmodified env
|
23
22
|
status: success
|
24
23
|
result:
|
25
|
-
- name: "@str"
|
26
|
-
status: success
|
27
|
-
result: foo
|
24
|
+
- name: "@str == 'foo'"
|
25
|
+
status: success
|
data/lib/checker.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
module Exemplor
|
2
2
|
class Check
|
3
3
|
|
4
|
-
attr_reader :expectation, :value, :status
|
5
|
-
|
6
4
|
def initialize(name, value)
|
7
5
|
@name = name
|
8
6
|
@value = value
|
9
|
-
@status = :info
|
10
7
|
end
|
11
8
|
|
12
9
|
def [](disambiguate)
|
@@ -18,13 +15,8 @@ module Exemplor
|
|
18
15
|
@name + (defined?(@disambiguate) ? " #{@disambiguate}" : '')
|
19
16
|
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def is(expectation)
|
25
|
-
@expectation = expectation
|
26
|
-
@status = (value == expectation) ? :success : :failure
|
27
|
-
raise Failure if failure?
|
18
|
+
def is(arg)
|
19
|
+
warn "Check().is() doesn't assert anymore, use Assert()"
|
28
20
|
end
|
29
21
|
|
30
22
|
def success?
|
@@ -40,4 +32,32 @@ module Exemplor
|
|
40
32
|
end
|
41
33
|
|
42
34
|
end
|
35
|
+
|
36
|
+
class Show < Check
|
37
|
+
|
38
|
+
attr_reader :value
|
39
|
+
|
40
|
+
def status
|
41
|
+
:info
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class Assert < Check
|
47
|
+
|
48
|
+
attr_reader :status
|
49
|
+
|
50
|
+
# todo remove
|
51
|
+
attr_reader :value
|
52
|
+
|
53
|
+
# might be better to use throw here
|
54
|
+
class Failure < StandardError; end
|
55
|
+
|
56
|
+
def run
|
57
|
+
@status = !!@value ? :success : :failure
|
58
|
+
raise Failure if failure?
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
43
63
|
end
|
data/lib/environment.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Exemplor
|
2
2
|
|
3
|
-
class
|
3
|
+
class Environment
|
4
4
|
|
5
5
|
class << self
|
6
6
|
|
@@ -24,7 +24,7 @@ module Exemplor
|
|
24
24
|
[env._status, render_checks(env._checks)]
|
25
25
|
end
|
26
26
|
|
27
|
-
rescue
|
27
|
+
rescue Assert::Failure => failure
|
28
28
|
[:failure, render_checks(env._checks)]
|
29
29
|
rescue Object => error
|
30
30
|
[:error, render_error(error)]
|
@@ -55,26 +55,13 @@ module Exemplor
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def render_checks(checks)
|
58
|
-
|
59
|
-
|
60
|
-
checks.each do |check|
|
61
|
-
failure = check if check.failure?
|
62
|
-
break if failure
|
63
|
-
out << OrderedHash do |o|
|
58
|
+
checks.map do |check|
|
59
|
+
OrderedHash do |o|
|
64
60
|
o['name'] = check.name
|
65
61
|
o['status'] = check.status.to_s
|
66
|
-
o['result'] = render_value check.value
|
62
|
+
o['result'] = render_value check.value if check.info?
|
67
63
|
end
|
68
64
|
end
|
69
|
-
if failure
|
70
|
-
out << OrderedHash do |o|
|
71
|
-
o['name'] = failure.name
|
72
|
-
o['status'] = failure.status.to_s
|
73
|
-
o['expected'] = failure.expectation
|
74
|
-
o['actual'] = render_value failure.value
|
75
|
-
end
|
76
|
-
end
|
77
|
-
out
|
78
65
|
end
|
79
66
|
|
80
67
|
def render_error(error)
|
@@ -93,15 +80,37 @@ module Exemplor
|
|
93
80
|
@_checks = []
|
94
81
|
end
|
95
82
|
|
83
|
+
def Show(value)
|
84
|
+
name = extract_argstring_from :Show, caller
|
85
|
+
check = Show.new(name, value)
|
86
|
+
_checks << check
|
87
|
+
check
|
88
|
+
end
|
89
|
+
|
90
|
+
def Assert(value)
|
91
|
+
name = extract_argstring_from :Assert, caller
|
92
|
+
check = Assert.new(name, value)
|
93
|
+
_checks << check
|
94
|
+
check.run
|
95
|
+
check
|
96
|
+
end
|
97
|
+
|
96
98
|
def Check(value)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
check = Check.new(name, value)
|
99
|
+
warn "Check is depreciated, use Show"
|
100
|
+
name = extract_argstring_from :Check, caller
|
101
|
+
check = Show.new(name, value)
|
101
102
|
_checks << check
|
102
103
|
check
|
103
104
|
end
|
104
105
|
|
106
|
+
def extract_argstring_from name, call_stack
|
107
|
+
file, line_number = call_stack.first.match(/^(.+):(\d+)/).captures
|
108
|
+
line = File.readlines(file)[line_number.to_i - 1].strip
|
109
|
+
argstring = line[/#{name}\((.+?)\)\s*($|#|\[|\})/,1]
|
110
|
+
raise "unable to extract name for #{name} from #{file} line #{line_number}:\n #{line}" unless argstring
|
111
|
+
argstring
|
112
|
+
end
|
113
|
+
|
105
114
|
def _status
|
106
115
|
(:success if _checks.all? { |c| c.success? }) ||
|
107
116
|
:infos
|
@@ -110,6 +119,6 @@ module Exemplor
|
|
110
119
|
end
|
111
120
|
|
112
121
|
def environment
|
113
|
-
|
122
|
+
Environment
|
114
123
|
end
|
115
124
|
end
|
data/lib/examples.rb
CHANGED
@@ -30,6 +30,7 @@ module Exemplor
|
|
30
30
|
class Examples
|
31
31
|
|
32
32
|
def initialize
|
33
|
+
# TODO: no OrderedHash here
|
33
34
|
@examples = OrderedHash.new
|
34
35
|
end
|
35
36
|
|
@@ -44,7 +45,7 @@ module Exemplor
|
|
44
45
|
examples_to_run = @examples.select { |name,_| name =~ patterns }
|
45
46
|
return 0 if examples_to_run.empty?
|
46
47
|
examples_to_run.each do |name, code|
|
47
|
-
result = ResultPrinter.new(name, *
|
48
|
+
result = ResultPrinter.new(name, *Environment.run(&code))
|
48
49
|
fails +=1 if result.failure?
|
49
50
|
puts($stdout.tty? ? result.fancy : result.yaml)
|
50
51
|
end
|
data/lib/exemplor.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# -- Implementation
|
2
2
|
|
3
|
-
require 'orderedhash'
|
4
3
|
require 'yaml'
|
5
4
|
|
6
5
|
module Exemplor
|
@@ -17,6 +16,8 @@ module Exemplor
|
|
17
16
|
|
18
17
|
end
|
19
18
|
|
19
|
+
require Exemplor.path('/../vendor/orderedhash-0.0.6/lib/orderedhash')
|
20
|
+
|
20
21
|
require Exemplor.path('/ext')
|
21
22
|
require Exemplor.path('/checker')
|
22
23
|
require Exemplor.path('/result_printer')
|