cutest 1.2.0.rc2 → 1.2.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cutest CHANGED
@@ -1,69 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative "../lib/cutest"
4
-
5
3
  if ARGV.empty?
6
4
  puts "usage: cutest [-r lib] [-v] file ..."
7
5
  exit
8
6
  end
9
7
 
10
- class Cutest
11
-
12
- # Clap: Command line argument parsing.
13
- # http://github.com/soveran/clap
14
- # http://rubygems.org/gems/clap
15
- class Clap
16
- VERSION = "0.0.2"
17
-
18
- attr :argv
19
- attr :opts
20
-
21
- def self.run(args, opts)
22
- new(args, opts).run
23
- end
24
-
25
- def initialize(argv, opts)
26
- @argv = argv.dup
27
- @opts = opts
28
- end
29
-
30
- def run
31
- args = []
32
-
33
- while argv.any?
34
-
35
- item = argv.shift
36
- flag = opts[item]
37
-
38
- if flag
39
-
40
- # Work around lambda semantics in 1.8.7.
41
- arity = [flag.arity, 0].max
42
-
43
- # Raise if there are not enough parameters
44
- # available for the flag.
45
- if argv.size < arity
46
- raise ArgumentError
47
- end
48
-
49
- # Call the lambda with N items from argv,
50
- # where N is the lambda's arity.
51
- flag.call(*argv.shift(arity))
52
- else
53
-
54
- # Collect the items that don't correspond to
55
- # flags.
56
- args << item
57
- end
58
- end
59
-
60
- args
61
- end
62
- end
63
- end
8
+ require_relative "../lib/cutest"
9
+ require_relative "../lib/cutest/vendor/clap"
64
10
 
65
- files = Cutest::Clap.run ARGV,
11
+ files = Clap.run ARGV,
66
12
  "-r" => lambda { |file| require file },
13
+ "-o" => lambda { |name| cutest[:only] = name },
67
14
  "-v" => lambda { puts Cutest::VERSION }
68
15
 
69
16
  if files.any?
@@ -1,7 +1,9 @@
1
1
  class Cutest
2
- VERSION = "1.2.0.rc2"
3
- FILTER = %r[/(ruby|jruby|rbx)[-/]([0-9\.])+]
4
- CACHE = Hash.new { |h, k| h[k] = File.readlines(k) }
2
+ unless defined?(VERSION)
3
+ VERSION = "1.2.0.rc3"
4
+ FILTER = %r[/(ruby|jruby|rbx)[-/]([0-9\.])+]
5
+ CACHE = Hash.new { |h, k| h[k] = File.readlines(k) }
6
+ end
5
7
 
6
8
  def self.run(files)
7
9
  files.each do |file|
@@ -28,6 +30,8 @@ class Cutest
28
30
  trace = $!.backtrace
29
31
  pivot = trace.index { |line| line.match(file) }
30
32
 
33
+ puts "\n test: %s" % cutest[:test]
34
+
31
35
  if pivot
32
36
  other = trace[0..pivot].select { |line| line !~ FILTER }
33
37
  other.reverse.each { |line| display_trace(line) }
@@ -134,8 +138,10 @@ private
134
138
  def test(name = nil, &block)
135
139
  cutest[:test] = name
136
140
 
137
- prepare.each { |blk| blk.call }
138
- block.call(setup && setup.call)
141
+ if !cutest[:only] || cutest[:only] == name
142
+ prepare.each { |blk| blk.call }
143
+ block.call(setup && setup.call)
144
+ end
139
145
  end
140
146
 
141
147
  # Assert that value is not nil or false.
@@ -0,0 +1,46 @@
1
+ class Clap
2
+ attr :argv
3
+ attr :opts
4
+
5
+ def self.run(args, opts)
6
+ new(args, opts).run
7
+ end
8
+
9
+ def initialize(argv, opts)
10
+ @argv = argv.dup
11
+ @opts = opts
12
+ end
13
+
14
+ def run
15
+ args = []
16
+
17
+ while argv.any?
18
+
19
+ item = argv.shift
20
+ flag = opts[item]
21
+
22
+ if flag
23
+
24
+ # Work around lambda semantics in 1.8.7.
25
+ arity = [flag.arity, 0].max
26
+
27
+ # Raise if there are not enough parameters
28
+ # available for the flag.
29
+ if argv.size < arity
30
+ raise ArgumentError
31
+ end
32
+
33
+ # Call the lambda with N items from argv,
34
+ # where N is the lambda's arity.
35
+ flag.call(*argv.shift(arity))
36
+ else
37
+
38
+ # Collect the items that don't correspond to
39
+ # flags.
40
+ args << item
41
+ end
42
+ end
43
+
44
+ args
45
+ end
46
+ end
@@ -7,7 +7,9 @@ test "output of successful run" do
7
7
  end
8
8
 
9
9
  test "output of failed run" do
10
- expected = " line: assert false\n" +
10
+ expected = "\n" +
11
+ " test: failed assertion\n" +
12
+ " line: assert false\n" +
11
13
  " file: test/fixtures/failure.rb +2\n\n" +
12
14
  "Cutest::AssertionFailed: expression returned false\n\n"
13
15
 
@@ -17,7 +19,9 @@ test "output of failed run" do
17
19
  end
18
20
 
19
21
  test "output of failed run" do
20
- expected = " line: raise \"Oops\"\n" +
22
+ expected = "\n" +
23
+ " test: some unhandled exception\n" +
24
+ " line: raise \"Oops\"\n" +
21
25
  " file: test/fixtures/exception.rb +2\n\n" +
22
26
  "RuntimeError: Oops\n\n"
23
27
 
@@ -27,7 +31,9 @@ test "output of failed run" do
27
31
  end
28
32
 
29
33
  test "output of custom assertion" do
30
- expected = " line: assert_empty \"foo\"\n" +
34
+ expected = "\n" +
35
+ " test: failed custom assertion\n" +
36
+ " line: assert_empty \"foo\"\n" +
31
37
  " file: test/fixtures/fail_custom_assertion.rb +7\n\n" +
32
38
  "Cutest::AssertionFailed: not empty\n\n"
33
39
 
@@ -37,7 +43,9 @@ test "output of custom assertion" do
37
43
  end
38
44
 
39
45
  test "output of failure in nested file" do
40
- expected = " line: assert false\n" +
46
+ expected = "\n" +
47
+ " test: failed assertion\n" +
48
+ " line: assert false\n" +
41
49
  " file: test/fixtures/failure.rb +2\n\n" +
42
50
  "Cutest::AssertionFailed: expression returned false\n\n"
43
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cutest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.rc2
4
+ version: 1.2.0.rc3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-16 00:00:00.000000000 Z
13
+ date: 2012-08-31 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Run tests in separate processes to avoid shared state.
16
16
  email:
@@ -24,6 +24,7 @@ files:
24
24
  - LICENSE
25
25
  - README.markdown
26
26
  - Rakefile
27
+ - lib/cutest/vendor/clap.rb
27
28
  - lib/cutest.rb
28
29
  - cutest.gemspec
29
30
  - test/assert.rb