cutest 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/cutest.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cutest"
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
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/a_test.rb", "test/b_test.rb", "test/c_test.rb"]
9
+ s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cutest.rb", "cutest.gemspec", "test/assert.rb", "test/assert_raise.rb", "test/setup.rb"]
10
10
  s.add_dependency "batch", "~> 0.0.1"
11
11
  end
data/lib/cutest.rb CHANGED
@@ -1,17 +1,28 @@
1
1
  require "batch"
2
2
 
3
- AssertionFailed = Class.new(StandardError)
3
+ class AssertionFailed < StandardError; end
4
4
 
5
5
  def assert(value)
6
- return if value
6
+ flunk unless value
7
+ end
8
+
9
+ def assert_raise(expected = Exception)
10
+ begin
11
+ yield
12
+ rescue => exception
13
+ ensure
14
+ flunk unless exception.kind_of?(expected)
15
+ end
16
+ end
7
17
 
18
+ def flunk(caller = caller[1])
8
19
  ex = AssertionFailed.new(@_test)
9
20
  ex.set_backtrace(caller)
10
21
 
11
22
  file, line = ex.backtrace.shift.split(":")
12
23
  code = File.readlines(file)[line.to_i - 1]
13
24
 
14
- ex.message.replace("=> #{code.strip}\n#{file}:#{line}")
25
+ ex.message.replace(">> #{@_test}\n=> #{code.strip}\n #{file} +#{line}")
15
26
 
16
27
  raise ex
17
28
  end
@@ -28,7 +39,7 @@ def test(name = nil, &block)
28
39
  end
29
40
 
30
41
  class Cutest < Batch
31
- VERSION = "0.0.2"
42
+ VERSION = "0.0.3"
32
43
 
33
44
  def report_errors
34
45
  return if @errors.empty?
data/test/assert.rb ADDED
@@ -0,0 +1,9 @@
1
+ test "succeeds if the value is true" do
2
+ assert true
3
+ end
4
+
5
+ test "raises if the assertion fails" do
6
+ assert_raise(AssertionFailed) do
7
+ assert false
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ test "catches the right exception" do
2
+ assert_raise(RuntimeError) do
3
+ raise RuntimeError
4
+ end
5
+ end
6
+
7
+
8
+ test "raises if the expectation is not met" do
9
+ assert_raise(AssertionFailed) do
10
+ assert_raise(RuntimeError) do
11
+ raise ArgumentError
12
+ end
13
+ end
14
+ end
@@ -6,10 +6,10 @@ test "should receive the result of the setup block as a parameter" do |params|
6
6
  assert params == {:a => 23, :b => 43}
7
7
  end
8
8
 
9
- test "should evaluate the setup block before each test" do |params|
9
+ test "if the params are modified..." do |params|
10
10
  params[:a] = nil
11
11
  end
12
12
 
13
- test "should preserve the original values from the setup" do |params|
13
+ test "...it should preserve the original values from the setup" do |params|
14
14
  assert 23 == params[:a]
15
15
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
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-11 00:00:00 -03:00
18
+ date: 2010-09-13 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -49,9 +49,9 @@ files:
49
49
  - Rakefile
50
50
  - lib/cutest.rb
51
51
  - cutest.gemspec
52
- - test/a_test.rb
53
- - test/b_test.rb
54
- - test/c_test.rb
52
+ - test/assert.rb
53
+ - test/assert_raise.rb
54
+ - test/setup.rb
55
55
  has_rdoc: true
56
56
  homepage: http://github.com/djanowski/cutest
57
57
  licenses: []
data/test/b_test.rb DELETED
@@ -1,3 +0,0 @@
1
- test "should work if there's no setup block" do
2
- assert true
3
- end
data/test/c_test.rb DELETED
@@ -1,7 +0,0 @@
1
- setup do
2
- 42
3
- end
4
-
5
- test "should return the result of evaluating the block" do |value|
6
- assert value == 42
7
- end