exemplor 2000.1.0 → 2000.2.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 +3 -3
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/examples.rb +5 -0
- data/examples/ten_percent_failures.rb +12 -0
- data/exemplor.gemspec +5 -3
- data/lib/exemplor.rb +14 -15
- metadata +5 -3
data/README
CHANGED
@@ -40,7 +40,7 @@ The simplest possible example:
|
|
40
40
|
|
41
41
|
The 'i' stands for 'info' which means the example ran without error.
|
42
42
|
|
43
|
-
Inspecting a few values, by default `Check` prints
|
43
|
+
Inspecting a few values, by default `Check` prints its argument and the value of the argument:
|
44
44
|
|
45
45
|
eg 'Accessing different parts of an array' do
|
46
46
|
list = [1, 2, 3]
|
@@ -58,7 +58,7 @@ Inspecting a few values, by default `Check` prints it's argument and the value o
|
|
58
58
|
|
59
59
|
The capital 'I' means all checks were 'info' checks.
|
60
60
|
|
61
|
-
|
61
|
+
Calls to `Check` with the same argument can be disambiguated with `[]`:
|
62
62
|
|
63
63
|
eg 'Array appending' do
|
64
64
|
list = [1, 42]
|
@@ -137,7 +137,7 @@ Running with `--list` or `-l` lists all examples:
|
|
137
137
|
- called with --l arg
|
138
138
|
- called with some other arg (always interpreted as a regex)
|
139
139
|
|
140
|
-
Otherwise the first argument is taken as a regex and only examples
|
140
|
+
Otherwise the first argument is taken as a regex and only examples whose titles match are run:
|
141
141
|
|
142
142
|
$> ruby examples.rb called
|
143
143
|
(s) called with --list arg:
|
data/Rakefile
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
task :default => [:test]
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'jeweler'
|
3
5
|
Jeweler::Tasks.new do |gs|
|
4
6
|
gs.name = "exemplor"
|
5
7
|
gs.homepage = "http://github.com/quackingduck/exemplor"
|
6
|
-
gs.summary = "A light-weight, low-fi way to provide executable usage examples
|
8
|
+
gs.summary = "A light-weight, low-fi way to provide executable usage examples of your code."
|
7
9
|
gs.email = "myles@myles.id.au"
|
8
10
|
gs.authors = ["Myles Byrne"]
|
9
11
|
gs.add_dependency('orderedhash', '>= 0.0.6')
|
@@ -15,7 +17,7 @@ rescue LoadError
|
|
15
17
|
end
|
16
18
|
|
17
19
|
task :examples do
|
18
|
-
|
20
|
+
ruby "examples.rb"
|
19
21
|
end
|
20
22
|
|
21
23
|
task :test => :examples
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2000.
|
1
|
+
2000.2.0
|
data/examples.rb
CHANGED
@@ -51,6 +51,11 @@ eg { check_output_matches_expected_for :checking_nil }
|
|
51
51
|
eg { check_output_matches_expected_for :dumping_classes }
|
52
52
|
eg { check_output_matches_expected_for :check_parsing }
|
53
53
|
|
54
|
+
eg "exit status is percent of issues that failed or errored" do
|
55
|
+
run_example :ten_percent_failures
|
56
|
+
Check($?.exitstatus).is(10)
|
57
|
+
end
|
58
|
+
|
54
59
|
eg "called with --list arg" do
|
55
60
|
list = YAML.load(run_example(:with_setup, '--list'))
|
56
61
|
Check(list).is(["Modified env", "Unmodified env"])
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'exemplor'
|
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) }
|
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 = "2000.
|
8
|
+
s.version = "2000.2.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-
|
12
|
+
s.date = %q{2009-11-03}
|
13
13
|
s.email = %q{myles@myles.id.au}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README"
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"examples/no_checks.rb",
|
34
34
|
"examples/no_checks_non_string.rb",
|
35
35
|
"examples/oneliner.rb",
|
36
|
+
"examples/ten_percent_failures.rb",
|
36
37
|
"examples/with_checks.rb",
|
37
38
|
"examples/with_setup.rb",
|
38
39
|
"exemplor.gemspec",
|
@@ -42,7 +43,7 @@ Gem::Specification.new do |s|
|
|
42
43
|
s.rdoc_options = ["--charset=UTF-8"]
|
43
44
|
s.require_paths = ["lib"]
|
44
45
|
s.rubygems_version = %q{1.3.5}
|
45
|
-
s.summary = %q{A light-weight, low-fi way to provide executable usage examples
|
46
|
+
s.summary = %q{A light-weight, low-fi way to provide executable usage examples of your code.}
|
46
47
|
s.test_files = [
|
47
48
|
"examples/an_error.rb",
|
48
49
|
"examples/assertion_failure.rb",
|
@@ -56,6 +57,7 @@ Gem::Specification.new do |s|
|
|
56
57
|
"examples/no_checks.rb",
|
57
58
|
"examples/no_checks_non_string.rb",
|
58
59
|
"examples/oneliner.rb",
|
60
|
+
"examples/ten_percent_failures.rb",
|
59
61
|
"examples/with_checks.rb",
|
60
62
|
"examples/with_setup.rb"
|
61
63
|
]
|
data/lib/exemplor.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rubygems' # TODO: remove
|
2
1
|
require 'orderedhash'
|
3
2
|
require 'yaml'
|
4
3
|
|
@@ -66,12 +65,9 @@ module Exemplor
|
|
66
65
|
@_checks = []
|
67
66
|
end
|
68
67
|
|
69
|
-
# fragile. doesnt work with calls like
|
70
|
-
# Check(get('/'))
|
71
|
-
# Check foo
|
72
68
|
def Check(value)
|
73
69
|
file, line_number = caller.first.match(/^(.+):(\d+)/).captures
|
74
|
-
line = File.
|
70
|
+
line = File.readlines(file)[line_number.to_i - 1].strip
|
75
71
|
name = line[/Check\((.+?)\)\s*($|#|\[|\.is.+)/,1]
|
76
72
|
check = Check.new(name, value)
|
77
73
|
_checks << check
|
@@ -93,15 +89,18 @@ module Exemplor
|
|
93
89
|
end
|
94
90
|
|
95
91
|
def run(patterns)
|
92
|
+
fails = 0
|
96
93
|
# unoffically supports multiple patterns
|
97
94
|
patterns = Regexp.new(patterns.join('|'))
|
98
|
-
@examples.
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
95
|
+
examples_to_run = @examples.select { |name,_| name =~ patterns }
|
96
|
+
return 0 if examples_to_run.empty?
|
97
|
+
examples_to_run.each do |name, body|
|
98
|
+
status, out, stderr = run_example(body)
|
99
|
+
print_yaml("#{status_icon(status)} #{name}" => out)
|
100
|
+
print_stderr stderr
|
101
|
+
fails +=1 if [:error,:failure].include?(status)
|
104
102
|
end
|
103
|
+
(fails.to_f/examples_to_run.size)*100
|
105
104
|
end
|
106
105
|
|
107
106
|
def list(patterns)
|
@@ -160,7 +159,7 @@ module Exemplor
|
|
160
159
|
else
|
161
160
|
status = :infos if env._checks.all? { |check| check.info? }
|
162
161
|
status = :success if env._checks.all? { |check| check.success? }
|
163
|
-
status = :
|
162
|
+
status = :failure if env._checks.any? { |check| check.failure? }
|
164
163
|
render_checks(env._checks)
|
165
164
|
end
|
166
165
|
rescue Object => error
|
@@ -222,8 +221,8 @@ def eg(name = nil, &example)
|
|
222
221
|
return Exemplor::Example if name.nil? && example.nil?
|
223
222
|
if name.nil?
|
224
223
|
file, line_number = caller.first.match(/^(.+):(\d+)/).captures
|
225
|
-
line = File.
|
226
|
-
name = line[
|
224
|
+
line = File.readlines(file)[line_number.to_i - 1].strip
|
225
|
+
name = line[/^eg\s*\{\s*(.+?)\s*\}$/,1] if name.nil?
|
227
226
|
raise Exemplor::ExampleDefinitionError, "example at #{caller.first} has no name so must be on one line" if name.nil?
|
228
227
|
end
|
229
228
|
Exemplor.examples.add(name, &example)
|
@@ -234,6 +233,6 @@ at_exit do
|
|
234
233
|
if args.delete('--list') || args.delete('-l')
|
235
234
|
Exemplor.examples.list(args)
|
236
235
|
else
|
237
|
-
Exemplor.examples.run(args)
|
236
|
+
exit Exemplor.examples.run(args)
|
238
237
|
end
|
239
238
|
end
|
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: 2000.
|
4
|
+
version: 2000.2.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-
|
12
|
+
date: 2009-11-03 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- examples/no_checks.rb
|
60
60
|
- examples/no_checks_non_string.rb
|
61
61
|
- examples/oneliner.rb
|
62
|
+
- examples/ten_percent_failures.rb
|
62
63
|
- examples/with_checks.rb
|
63
64
|
- examples/with_setup.rb
|
64
65
|
- exemplor.gemspec
|
@@ -90,7 +91,7 @@ rubyforge_project:
|
|
90
91
|
rubygems_version: 1.3.5
|
91
92
|
signing_key:
|
92
93
|
specification_version: 3
|
93
|
-
summary: A light-weight, low-fi way to provide executable usage examples
|
94
|
+
summary: A light-weight, low-fi way to provide executable usage examples of your code.
|
94
95
|
test_files:
|
95
96
|
- examples/an_error.rb
|
96
97
|
- examples/assertion_failure.rb
|
@@ -104,5 +105,6 @@ test_files:
|
|
104
105
|
- examples/no_checks.rb
|
105
106
|
- examples/no_checks_non_string.rb
|
106
107
|
- examples/oneliner.rb
|
108
|
+
- examples/ten_percent_failures.rb
|
107
109
|
- examples/with_checks.rb
|
108
110
|
- examples/with_setup.rb
|