exemplor 2.7.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -1,6 +1,7 @@
1
1
  * exemplor executable that can run multiple example files
2
2
  * #teardown
3
3
  * Use fancy unicode characters for tests status:
4
+ * TextMate bundle that does nice cmd+r output
4
5
  # (i) = ∙
5
6
  # (I) = •
6
7
  # (s) = ✓
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.7.0
1
+ 2.9.0
data/examples.rb CHANGED
@@ -1,5 +1,5 @@
1
- # TODO: switch to gem version
2
- require 'lib/exemplor'
1
+ # uses the gem version, not the one being tested
2
+ require 'exemplor'
3
3
 
4
4
  # slow because each test runs in a subshell
5
5
 
@@ -25,7 +25,8 @@ eg.helpers do
25
25
  end
26
26
 
27
27
  eg "version matches file" do
28
- Check(Exemplor.version).is(File.read(__FILE__.sub('examples.rb','VERSION')))
28
+ version = `ruby -Ilib -e "require 'exemplor' ; print Exemplor.version"`
29
+ Check(version).is(File.read(__FILE__.sub('examples.rb','VERSION')))
29
30
  end
30
31
 
31
32
  eg "errors are caught and nicely displayed" do
@@ -1,5 +1,21 @@
1
1
  require 'exemplor'
2
2
 
3
+ eg.helpers do
4
+ def foo() 'bar' end
5
+ end
6
+
7
+ eg "plain call" do
8
+ Check(foo)
9
+ end
10
+
11
+ eg "whitespace after the call (seriously)" do
12
+ Check(foo)
13
+ end
14
+
15
+ eg "comment after the call" do
16
+ Check(foo) # comment!
17
+ end
18
+
3
19
  eg "with brackets" do
4
20
  Check(String.new('test'))
5
21
  end
@@ -10,6 +26,12 @@ end
10
26
 
11
27
  __END__
12
28
 
29
+ (I) plain call:
30
+ (i) foo: bar
31
+ (I) whitespace after the call (seriously):
32
+ (i) foo: bar
33
+ (I) comment after the call:
34
+ (i) foo: bar
13
35
  (I) with brackets:
14
36
  (i) String.new('test'): test
15
37
  (s) with brackets and is:
@@ -1,10 +1,16 @@
1
1
  require 'exemplor'
2
2
 
3
- eg "checking for nil works correctly" do
3
+ eg "checking nil works correctly" do
4
+ Check(nil)
5
+ end
6
+
7
+ eg "asserting for nil works correctly" do
4
8
  Check(nil).is(nil)
5
9
  end
6
10
 
7
11
  __END__
8
12
 
9
- (s) checking for nil works correctly:
10
- (s) nil:
13
+ (I) checking nil works correctly:
14
+ (i) nil:
15
+ (s) asserting for nil works correctly:
16
+ (s) nil:
data/exemplor.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{exemplor}
8
- s.version = "2.7.0"
8
+ s.version = "2.9.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Myles Byrne"]
12
- s.date = %q{2009-10-23}
12
+ s.date = %q{2009-10-29}
13
13
  s.email = %q{myles@myles.id.au}
14
14
  s.extra_rdoc_files = [
15
15
  "README"
data/lib/exemplor.rb CHANGED
@@ -71,7 +71,7 @@ module Exemplor
71
71
  def Check(value)
72
72
  file, line_number = caller.first.match(/^(.+):(\d+)/).captures
73
73
  line = File.read(file).map[line_number.to_i - 1]
74
- name = line[/Check\((.+?)\)($|\.is.+)/,1]
74
+ name = line[/Check\((.+?)\)\s*($|#|\[|\.is.+)/,1]
75
75
  check = Check.new(name, value)
76
76
  _checks << check
77
77
  check
@@ -96,8 +96,9 @@ module Exemplor
96
96
  patterns = Regexp.new(patterns.join('|'))
97
97
  @examples.each do |name, body|
98
98
  if name =~ patterns
99
- status, out = run_example(body)
99
+ status, out, stderr = run_example(body)
100
100
  print_yaml("#{status_icon(status)} #{name}" => out)
101
+ print_stderr stderr
101
102
  end
102
103
  end
103
104
  end
@@ -114,6 +115,12 @@ module Exemplor
114
115
  print(out)
115
116
  end
116
117
 
118
+ def print_stderr(stderr)
119
+ unless stderr.empty?
120
+ $stdout.tty? ? $stdout.puts("#{Term::ANSIColor.reset}(STDERR):\n#{stderr}") : $stderr.puts(stderr)
121
+ end
122
+ end
123
+
117
124
  # hacky
118
125
  def colorize(out)
119
126
  require 'term/ansicolor'
@@ -127,7 +134,7 @@ module Exemplor
127
134
  start_color(line, :red)
128
135
  when /^(?:\s{2})?(\(i\))/i
129
136
  start_color(line, :blue)
130
- else
137
+ else
131
138
  line
132
139
  end
133
140
  end.join("\n") + "\n#{Term::ANSIColor.reset}"
@@ -140,7 +147,11 @@ module Exemplor
140
147
  def run_example(code)
141
148
  status = :info
142
149
  env = Example.new
150
+ stderr = StringIO.new
143
151
  out = begin
152
+ real_stderr = $stderr
153
+ $stderr = stderr
154
+
144
155
  env.instance_eval(&Example.setup_block) if Example.setup_block
145
156
  value = env.instance_eval(&code)
146
157
  if env._checks.empty?
@@ -154,8 +165,10 @@ module Exemplor
154
165
  rescue Object => error
155
166
  status = :error
156
167
  render_error(error)
168
+ ensure
169
+ $stderr = real_stderr
157
170
  end
158
- [status, out]
171
+ [status, out, stderr.rewind && stderr.read]
159
172
  end
160
173
 
161
174
  def render_checks(checks)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exemplor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myles Byrne
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-23 00:00:00 +11:00
12
+ date: 2009-10-29 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency