exemplor 2010.2.0 → 3000.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.md +221 -0
  2. data/Rakefile +8 -4
  3. data/TODO +13 -6
  4. data/VERSION +1 -1
  5. data/examples.rb +62 -51
  6. data/examples/assertion_failure.rb +3 -5
  7. data/examples/assertion_success.rb +2 -3
  8. data/examples/assertion_success_and_failure.rb +8 -12
  9. data/examples/assertion_success_and_info.rb +8 -11
  10. data/examples/check_parsing.rb +8 -17
  11. data/examples/checking_nil.rb +6 -5
  12. data/examples/failure_halts_execution.rb +3 -5
  13. data/examples/foobar.rb +9 -0
  14. data/examples/helpers.rb +1 -1
  15. data/examples/{with_checks.rb → multi_show.rb} +3 -3
  16. data/examples/no_checks_non_string.rb +1 -1
  17. data/examples/{check_with_disambiguation.rb → show_with_disambiguation.rb} +2 -2
  18. data/examples/{dumping_classes.rb → showing_classes.rb} +1 -1
  19. data/examples/simple_show.rb +15 -0
  20. data/examples/ten_percent_failures.rb +10 -10
  21. data/examples/with_setup.rb +5 -7
  22. data/lib/checker.rb +30 -10
  23. data/lib/environment.rb +32 -23
  24. data/lib/examples.rb +2 -1
  25. data/lib/exemplor.rb +2 -1
  26. data/lib/result_printer.rb +40 -21
  27. data/vendor/orderedhash-0.0.6/gemspec.rb +37 -0
  28. data/vendor/orderedhash-0.0.6/install.rb +213 -0
  29. data/vendor/orderedhash-0.0.6/lib/orderedautohash.rb +25 -0
  30. data/vendor/orderedhash-0.0.6/lib/orderedhash.rb +200 -0
  31. data/vendor/term-ansicolor-1.0.5/CHANGES +28 -0
  32. data/vendor/term-ansicolor-1.0.5/COPYING +340 -0
  33. data/vendor/term-ansicolor-1.0.5/README +137 -0
  34. data/vendor/term-ansicolor-1.0.5/Rakefile +88 -0
  35. data/vendor/term-ansicolor-1.0.5/VERSION +1 -0
  36. data/vendor/term-ansicolor-1.0.5/bin/cdiff +19 -0
  37. data/vendor/term-ansicolor-1.0.5/bin/decolor +12 -0
  38. data/vendor/term-ansicolor-1.0.5/examples/example.rb +90 -0
  39. data/vendor/term-ansicolor-1.0.5/install.rb +15 -0
  40. data/vendor/term-ansicolor-1.0.5/lib/term/ansicolor.rb +102 -0
  41. data/vendor/term-ansicolor-1.0.5/lib/term/ansicolor/version.rb +10 -0
  42. data/vendor/term-ansicolor-1.0.5/tests/ansicolor_test.rb +66 -0
  43. metadata +34 -41
  44. 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
- Check(list.first).is(1)
6
- Check(list[1]).is(2)
7
- Check(list.last) # the info one
8
- Check(list[2]).is(3)
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
- result: 1
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
@@ -5,29 +5,26 @@ eg.helpers do
5
5
  end
6
6
 
7
7
  eg "plain call" do
8
- Check(foo)
8
+ Show(foo)
9
9
  end
10
10
 
11
11
  eg "whitespace after the call (seriously)" do
12
- Check(foo)
12
+ Show(foo)
13
13
  end
14
14
 
15
15
  eg "comment after the call" do
16
- Check(foo) # comment!
16
+ Show(foo) # comment!
17
17
  end
18
18
 
19
19
  eg "with brackets" do
20
- Check(String.new('test'))
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
- Check(foo)['bar'].is('bar')
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: success
55
+ status: info (with checks)
65
56
  result:
66
57
  - name: foo bar
67
- status: success
58
+ status: info
68
59
  result: bar
@@ -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
- Check(nil)
6
+ Show(nil)
5
7
  end
6
8
 
7
9
  eg "asserting for nil works correctly" do
8
- Check(nil).is(nil)
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
- Check(list.first).is(1_000_000) # fail!
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
@@ -0,0 +1,9 @@
1
+ require 'exemplor'
2
+
3
+ eg "foo" do
4
+ "foo"
5
+ end
6
+
7
+ eg "bar" do
8
+ "bar"
9
+ end
@@ -16,4 +16,4 @@ __END__
16
16
 
17
17
  - name: Example calling helper
18
18
  status: info (no checks)
19
- result: foo
19
+ result: foo
@@ -2,9 +2,9 @@ require 'exemplor'
2
2
 
3
3
  eg 'Accessing different parts of an array' do
4
4
  list = [1, 2, 3]
5
- Check(list.first)
6
- Check(list[1])
7
- Check(list.last)
5
+ Show(list.first)
6
+ Show(list[1])
7
+ Show(list.last)
8
8
  end
9
9
 
10
10
  __END__
@@ -15,4 +15,4 @@ __END__
15
15
  - name: Non-string return values get converted to yaml
16
16
  status: info (no checks)
17
17
  result: !ruby/object:MyClass
18
- foo: bar
18
+ foo: bar
@@ -2,9 +2,9 @@ require 'exemplor'
2
2
 
3
3
  eg 'Array appending' do
4
4
  list = [1, 42]
5
- Check(list.last)["before append"]
5
+ Show(list.last)["before append"]
6
6
  list << 2
7
- Check(list.last)["after append"]
7
+ Show(list.last)["after append"]
8
8
  end
9
9
 
10
10
  __END__
@@ -5,7 +5,7 @@ eg "class name is printed when example returns a class" do
5
5
  end
6
6
 
7
7
  eg "class name is printed when check is given a class" do
8
- Check(Object)
8
+ Show(Object)
9
9
  end
10
10
 
11
11
  __END__
@@ -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 { Check(1).is(1) }
4
- eg { Check(2).is(2) }
5
- eg { Check(3).is(3) }
6
- eg { Check(4).is(4) }
7
- eg { Check(5).is(5) }
8
- eg { Check(6).is(6) }
9
- eg { Check(7).is(7) }
10
- eg { Check(8).is(8) }
11
- eg { Check(9).is(9) }
12
- eg { Check(false).is(true) }
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) }
@@ -4,11 +4,11 @@ eg.setup { @str = "foo" }
4
4
 
5
5
  eg 'Modified env' do
6
6
  @str << " bar"
7
- Check(@str).is("foo bar")
7
+ Assert(@str == 'foo bar')
8
8
  end
9
9
 
10
10
  eg 'Unmodified env' do
11
- Check(@str).is("foo")
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
@@ -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
- # might be better to use throw here
22
- class Failure < StandardError; end
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
@@ -1,6 +1,6 @@
1
1
  module Exemplor
2
2
 
3
- class ExampleEnv
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 Check::Failure => failure
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
- failure = nil
59
- out = []
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
- file, line_number = caller.first.match(/^(.+):(\d+)/).captures
98
- line = File.readlines(file)[line_number.to_i - 1].strip
99
- name = line[/Check\((.+?)\)\s*($|#|\[|\.is.+)/,1]
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
- ExampleEnv
122
+ Environment
114
123
  end
115
124
  end
@@ -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, *ExampleEnv.run(&code))
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
@@ -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')