cutest 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,8 +80,10 @@ To run the tests:
80
80
 
81
81
  If you get an error, the report will look like this:
82
82
 
83
+ >> should preserve the original values from the setup
83
84
  => assert 24 == params[:a]
84
- test/a_test.rb:14
85
+ test/a_test.rb +14
86
+
85
87
 
86
88
  Instead of a description of the error, you get to see the assertion
87
89
  that failed along with the file and line number. Adding a debugger and
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require File.expand_path("../lib/cutest", __FILE__)
3
3
  $VERBOSE = true
4
4
 
5
5
  task :test do
6
- Cutest.run(Dir["test/*"])
6
+ Cutest.run(Dir["test/*.rb"])
7
7
  end
8
8
 
9
9
  task :default => :test
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cutest"
3
- s.version = "0.1.0"
3
+ s.version = "0.1.1"
4
4
  s.summary = "Forking tests."
5
5
  s.description = "Run tests in separate processes to avoid shared state."
6
6
  s.authors = ["Damian Janowski", "Michel Martens"]
7
7
  s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
8
8
  s.homepage = "http://github.com/djanowski/cutest"
9
- s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cutest.rb", "cutest.gemspec", "test/assert.rb", "test/assert_raise.rb", "test/prepare.rb", "test/scopes.rb", "test/setup.rb"]
9
+ s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cutest.rb", "cutest.gemspec", "test/assert.rb", "test/assert_raise.rb", "test/prepare.rb", "test/run.rb", "test/scopes.rb", "test/setup.rb"]
10
10
  s.add_dependency "batch", "~> 0.0.3"
11
11
  end
@@ -1,7 +1,7 @@
1
1
  require "batch"
2
2
 
3
3
  class Cutest < Batch
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
 
6
6
  def report_error(_, error)
7
7
  $stderr.puts "#{error}\n"
@@ -16,10 +16,11 @@ class Cutest < Batch
16
16
 
17
17
  begin
18
18
  load(file, anonymous)
19
- rescue => e
20
- error = [e.message] + e.backtrace.take_while { |line| !line.start_with?(__FILE__) }
21
- write.write error.join("\n")
22
- write.write "\n"
19
+
20
+ rescue Exception => e
21
+ error = [e.message] +
22
+ e.backtrace.take_while { |line| !line.index(__FILE__) }
23
+ write.puts error.join("\n")
23
24
  write.close
24
25
  end
25
26
  end
@@ -34,7 +35,11 @@ class Cutest < Batch
34
35
  end
35
36
  end
36
37
 
37
- class AssertionFailed < StandardError; end
38
+ class AssertionFailed < StandardError
39
+ def backtrace
40
+ []
41
+ end
42
+ end
38
43
 
39
44
  class Scope
40
45
  def initialize(&scope)
@@ -124,17 +129,13 @@ private
124
129
  end
125
130
  end
126
131
 
127
- # Stop the tests and raise an error where the message is the last line executed
128
- # before flunking.
129
- def flunk(caller = caller[1])
130
- ex = Cutest::AssertionFailed.new(@_test)
131
- ex.set_backtrace(caller)
132
-
133
- file, line = ex.backtrace.shift.split(":")
132
+ # Stop the tests and raise an error where the message is the last line
133
+ # executed before flunking.
134
+ def flunk
135
+ file, line = caller[1].split(":")
134
136
  code = File.readlines(file)[line.to_i - 1]
137
+ msg = ">> #{@_test}\n=> #{code.strip}\n #{file} +#{line}"
135
138
 
136
- ex.message.replace(">> #{@_test}\n=> #{code.strip}\n #{file} +#{line}")
137
-
138
- raise ex
139
+ raise Cutest::AssertionFailed.new(msg)
139
140
  end
140
141
  end
@@ -0,0 +1,60 @@
1
+ require "stringio"
2
+
3
+ def capture
4
+ stdout, $stdout = $stdout, StringIO.new
5
+ stderr, $stderr = $stderr, StringIO.new
6
+ yield
7
+ [$stdout.string, $stderr.string]
8
+ ensure
9
+ $stdout = stdout
10
+ $stderr = stderr
11
+ end
12
+
13
+ test "output of successful run" do
14
+ expected = " 0% .\n100% \n"
15
+
16
+ stdout, stderr = capture do
17
+ Cutest.run(Dir["test/fixtures/success.rb"])
18
+ end
19
+
20
+ assert stdout == expected
21
+ end
22
+
23
+ test "output of failed run" do
24
+ alternatives = [
25
+ [" 0% E\n100% \n", "\nSome errors occured:\n\n>> failed assertion\n=> assert false\n test/fixtures/failure.rb +2\n\n"],
26
+ [" 0% E\n100% \n", "\nSome errors occured:\n\n>> failed assertion\n=> assert false\n ./test/fixtures/failure.rb +2\n\n"]
27
+ ]
28
+
29
+ stdout, stderr = capture do
30
+ Cutest.run(Dir["test/fixtures/failure.rb"])
31
+ end
32
+
33
+ assert alternatives.any? { |expected| [stdout, stderr] == expected }
34
+ end
35
+
36
+ test "output of failed run on a custom assertion" do
37
+ alternatives = [
38
+ [" 0% E\n100% \n", "\nSome errors occured:\n\n>> failed custom assertion\n=> assert_empty \"foo\"\n test/fixtures/fail_custom_assertion.rb +6\n\n"],
39
+ [" 0% E\n100% \n", "\nSome errors occured:\n\n>> failed custom assertion\n=> assert_empty \"foo\"\n ./test/fixtures/fail_custom_assertion.rb +6\n\n"]
40
+ ]
41
+
42
+ stdout, stderr = capture do
43
+ Cutest.run(Dir["test/fixtures/fail_custom_assertion.rb"])
44
+ end
45
+
46
+ assert alternatives.any? { |expected| [stdout, stderr] == expected }
47
+ end
48
+
49
+ test "output of failed run on an exception" do
50
+ alternatives = [
51
+ [" 0% E\n100% \n", "\nSome errors occured:\n\nOops\ntest/fixtures/exception.rb:2:in `foo'\ntest/fixtures/exception.rb:6:in `block in <top (required)>'\n\n"],
52
+ [" 0% E\n100% \n", "\nSome errors occured:\n\nOops\n./test/fixtures/exception.rb:2:in `foo'\n./test/fixtures/exception.rb:6\n\n"]
53
+ ]
54
+
55
+ stdout, stderr = capture do
56
+ Cutest.run(Dir["test/fixtures/exception.rb"])
57
+ end
58
+
59
+ assert alternatives.any? { |expected| [stdout, stderr] == expected }
60
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Damian Janowski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-20 00:00:00 -03:00
18
+ date: 2010-09-22 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,7 @@ files:
52
52
  - test/assert.rb
53
53
  - test/assert_raise.rb
54
54
  - test/prepare.rb
55
+ - test/run.rb
55
56
  - test/scopes.rb
56
57
  - test/setup.rb
57
58
  has_rdoc: true