cutest 0.0.6 → 0.1.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.
@@ -8,16 +8,39 @@ Description
8
8
 
9
9
  Run tests in separate processes to avoid shared state.
10
10
 
11
- Each test file is loaded in a forked process and, if the second
12
- parameter to `Cutest.run` is true, inside an anonymous module. Once a
13
- failure is found in a file, the rest of the file is skipped and the
14
- error is reported. This way, running your test suite feels faster.
15
-
16
- There are no nested contexts, just the `setup` and `test` methods.
17
- Unlike other testing tools, the result of evaluating the setup is
18
- passed as a parameter to each test. Even if you can still use instance
19
- variables, the code in the examples is the suggested way to keep tests
20
- from sharing information.
11
+ Each test file is run in a forked process and, if the second parameter to
12
+ `Cutest.run` is true, it is also loaded inside an anonymous module. Once a
13
+ failure is found in a file, the rest of the file is skipped and the error is
14
+ reported. This way, running your test suite feels faster.
15
+
16
+ You can use the `scope` command around tests: it guarantees that no instance
17
+ variables are shared between tests.
18
+
19
+ There are two commands very similar in nature, but with a subtle difference that
20
+ makes them easy to combine in order to satisfy different needs: `prepare` and
21
+ `setup`.
22
+
23
+ The `prepare` blocks are executed before each test. If you call `prepare` many
24
+ times, each passed block is appended to an array. When the test is run, all
25
+ those prepare blocks are executed in order. The result of the block is
26
+ discarded, so it is only useful for preparing the environment (flushing the
27
+ database, removing a directory, etc.).
28
+
29
+ The `setup` block is executed before each test and the result is passed as a
30
+ parameter to the `test` block. Unlike `prepare`, each definition of `setup`
31
+ overrides the previous one. Even if you can declare instance variables and
32
+ share them between tests, the recommended usage is to pass the result of the
33
+ block as a parameter to the `test` blocks.
34
+
35
+ The `test` method executes the passed block after running `prepare` and
36
+ `setup`. This is where assertions must be declared.
37
+
38
+ Two assertions are available: `assert` and `assert_raise`. The first accepts a
39
+ value and raises an `AssertionFailed` exception if it's false or nil, and the
40
+ later receives an expected exception and a block: the block is executed and
41
+ the raised exception is compared with the expected one. An `AssertionFailed`
42
+ exception is raised if the block runs fine or if the raised exception doesn't
43
+ match the expectation.
21
44
 
22
45
  Usage
23
46
  -----
@@ -50,6 +73,7 @@ In your tests:
50
73
  assert 23 == params[:a]
51
74
  end
52
75
 
76
+
53
77
  To run the tests:
54
78
 
55
79
  $ rake
@@ -63,6 +87,43 @@ Instead of a description of the error, you get to see the assertion
63
87
  that failed along with the file and line number. Adding a debugger and
64
88
  fixing the bug is left as an exercise for the reader.
65
89
 
90
+ An example working with a prepare block:
91
+
92
+ prepare do
93
+ Ohm.flush
94
+ end
95
+
96
+ setup do
97
+ Ohm.redis.get("foo")
98
+ end
99
+
100
+ test do |foo|
101
+ assert foo.nil?
102
+ end
103
+
104
+ And working with scopes:
105
+
106
+ setup do
107
+ @foo = true
108
+ end
109
+
110
+ @bar = true
111
+
112
+ scope do
113
+ test "should not share instance variables" do |foo|
114
+ assert !defined?(@foo)
115
+ assert !defined?(@bar)
116
+ assert foo == true
117
+ end
118
+ end
119
+
120
+ The tests in these two examples will pass.
121
+
122
+ Unlike other testing frameworks, Cutest does not compile all the tests before
123
+ running them. Another shift in design is that one dot is shown after a file is
124
+ examined, and not the usual one-dot-per-assertion. And finally, the execution
125
+ of a file stops one the first failure is found.
126
+
66
127
  Installation
67
128
  ------------
68
129
 
@@ -71,7 +132,7 @@ Installation
71
132
  License
72
133
  -------
73
134
 
74
- Copyright (c) 2009 Damian Janowski and Michel Martens
135
+ Copyright (c) 2010 Damian Janowski and Michel Martens
75
136
 
76
137
  Permission is hereby granted, free of charge, to any person
77
138
  obtaining a copy of this software and associated documentation
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cutest"
3
- s.version = "0.0.6"
3
+ s.version = "0.1.0"
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
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"]
10
- s.add_dependency "batch", "~> 0.0.1"
10
+ s.add_dependency "batch", "~> 0.0.3"
11
11
  end
@@ -1,16 +1,10 @@
1
1
  require "batch"
2
2
 
3
3
  class Cutest < Batch
4
- VERSION = "0.0.6"
4
+ VERSION = "0.1.0"
5
5
 
6
- def report_errors
7
- return if @errors.empty?
8
-
9
- $stderr.puts "\nSome errors occured:\n\n"
10
-
11
- @errors.each do |item, error|
12
- $stderr.puts error, "\n"
13
- end
6
+ def report_error(_, error)
7
+ $stderr.puts "#{error}\n"
14
8
  end
15
9
 
16
10
  def self.run(files, anonymous = false)
@@ -65,14 +59,14 @@ private
65
59
  Thread.current[:cutest]
66
60
  end
67
61
 
68
- # Create a class where the block will be evaluated. Recomended to improve
62
+ # Create a class where the block will be evaluated. Recommended to improve
69
63
  # isolation between tests.
70
- def scope(&blk)
71
- Cutest::Scope.new(&blk).call
64
+ def scope(&block)
65
+ Cutest::Scope.new(&block).call
72
66
  end
73
67
 
74
68
  # Prepare the environment in order to run the tests. This method can be called
75
- # many times, and each new block is appened to a list of preparation blocks.
69
+ # many times, and each new block is appended to a list of preparation blocks.
76
70
  # When a test is executed, all the preparation blocks are ran in the order they
77
71
  # were declared. If called without a block, it returns the array of preparation
78
72
  # blocks.
@@ -101,7 +95,10 @@ private
101
95
  cutest[:setup]
102
96
  end
103
97
 
104
- # Call all the prepare blocks and setup blocks before executing the test. Even
98
+ # Kernel includes a test method for performing tests on files.
99
+ undef test if defined? test
100
+
101
+ # Call the prepare and setup blocks before executing the test. Even
105
102
  # though the assertions can live anywhere (it's not mandatory to put them
106
103
  # inside test blocks), it is necessary to wrap them in test blocks in order to
107
104
  # execute preparation and setup blocks.
@@ -18,8 +18,8 @@ test "and are cumulative" do
18
18
  assert $foo == [true, false]
19
19
  end
20
20
 
21
- module Foo
22
- test "and run inside modules" do
21
+ scope do
22
+ test "and run inside scopes" do
23
23
  assert $foo = [true, false]
24
24
  end
25
25
  end
@@ -1,12 +1,9 @@
1
1
  @bar = true
2
2
 
3
- prepare { $foo = false }
4
-
5
3
  scope do
6
4
  @foo = true
7
5
 
8
6
  test "something" do
9
- assert !$foo
10
7
  assert defined?(@foo)
11
8
  assert !defined?(@bar)
12
9
  end
@@ -14,7 +11,6 @@ end
14
11
 
15
12
  scope do
16
13
  test "something" do
17
- assert !$foo
18
14
  assert !defined?(@foo)
19
15
  assert !defined?(@bar)
20
16
  end
@@ -22,8 +22,8 @@ test "only the most recently defined setup block is executed" do |value|
22
22
  assert "Hello world!" == value
23
23
  end
24
24
 
25
- module Foo
26
- test "works inside modules too" do |value|
25
+ scope do
26
+ test "works inside scopes too" do |value|
27
27
  assert "Hello world!" == value
28
28
  end
29
29
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 6
9
- version: 0.0.6
9
+ version: 0.1.0
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-18 00:00:00 -03:00
18
+ date: 2010-09-20 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -29,8 +29,8 @@ dependencies:
29
29
  segments:
30
30
  - 0
31
31
  - 0
32
- - 1
33
- version: 0.0.1
32
+ - 3
33
+ version: 0.0.3
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  description: Run tests in separate processes to avoid shared state.