cutest-cj 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a68e884e7e86738b74f543cf51d04ea3317e8c77
4
+ data.tar.gz: 8155aa435a1c9193a28fb93e410adfd4f83e702d
5
+ SHA512:
6
+ metadata.gz: 50fd8d32c88a67c4c1adb9683436393e16572c52bb2244be9d7a6b169cbe135069358d96f25f0aecde655d39f176df02aed37211144862d4c52dd7ddbeb5f06f
7
+ data.tar.gz: abd4cd45d72285f1fb6a345dfe3fbd400142dbdd5b4d54403d995fa758d95dcdb206b2f3c6e9415979a6ea3b1a5becf773913ef22e113df3b013656a1aa886d8
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /pkg
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ 1.2.1 - 2013-08-14
2
+ ==================
3
+
4
+ * `cutest(1)` now exits with a non-zero status when a test fails.
5
+
6
+ Previous versions
7
+ =================
8
+
9
+ Check the commit list for earlier changes.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Damian Janowski & Michel Martens
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,167 @@
1
+ Cutest
2
+ =======
3
+
4
+ Forking tests.
5
+
6
+ Description
7
+ -----------
8
+
9
+ Each test file is run in a forked process to avoid shared state. Once a failure
10
+ is found, you get a report detailing what failed and how to locate the error
11
+ and the rest of the file is skipped.
12
+
13
+ You can use the `scope` command around tests: it guarantees that no instance
14
+ variables are shared between tests.
15
+
16
+ There are two commands very similar in nature, but with a subtle difference that
17
+ makes them easy to combine in order to satisfy different needs: `prepare` and
18
+ `setup`.
19
+
20
+ The `prepare` blocks are executed before each test. If you call `prepare` many
21
+ times, each passed block is appended to an array. When the test is run, all
22
+ those prepare blocks are executed in order. The result of the block is
23
+ discarded, so it is only useful for preparing the environment (flushing the
24
+ database, removing a directory, etc.).
25
+
26
+ The `setup` block is executed before each test and the result is passed as a
27
+ parameter to the `test` block. Unlike `prepare`, each definition of `setup`
28
+ overrides the previous one. Even if you can declare instance variables and
29
+ share them between tests, the recommended usage is to pass the result of the
30
+ block as a parameter to the `test` blocks.
31
+
32
+ The `test` method executes the passed block after running `prepare` and
33
+ `setup`. This is where assertions must be declared.
34
+
35
+ Three assertions are available: `assert`, that accepts a value and raises
36
+ if it's false or nil; `assert_equal`, that raises if its arguments are not
37
+ equal; and `assert_raise`, that executes a passed block and compares the raised
38
+ exception to the expected one. In all cases, if the expectation is no met, an
39
+ `AssertionFailed` exception is raised.
40
+
41
+ Usage
42
+ -----
43
+
44
+ In your terminal:
45
+
46
+ $ cutest test/*.rb
47
+
48
+ In your tests:
49
+
50
+ setup do
51
+ {:a => 23, :b => 43}
52
+ end
53
+
54
+ test "should receive the result of the setup block as a parameter" do |params|
55
+ assert params == {:a => 23, :b => 43}
56
+ end
57
+
58
+ test "should evaluate the setup block before each test" do |params|
59
+ params[:a] = nil
60
+ end
61
+
62
+ test "should preserve the original values from the setup" do |params|
63
+ assert 23 == params[:a]
64
+ end
65
+
66
+ An example working with a prepare block:
67
+
68
+ prepare do
69
+ Ohm.flush
70
+ end
71
+
72
+ setup do
73
+ Ohm.redis.get("foo")
74
+ end
75
+
76
+ test do |foo|
77
+ assert foo.nil?
78
+ end
79
+
80
+ And working with scopes:
81
+
82
+ setup do
83
+ @foo = true
84
+ end
85
+
86
+ @bar = true
87
+
88
+ scope do
89
+ test "should not share instance variables" do |foo|
90
+ assert !defined?(@foo)
91
+ assert !defined?(@bar)
92
+ assert foo == true
93
+ end
94
+ end
95
+
96
+ The tests in these two examples will pass.
97
+
98
+ Unlike other testing frameworks, Cutest does not compile all the tests before
99
+ running them.
100
+
101
+ Handling errors
102
+ ---------------
103
+
104
+ If you get an error when running the tests, this is what you will see:
105
+
106
+ Exception: assert_equal 24, params[:a] # 24 != 23
107
+ test/setup.rb +14
108
+
109
+ Running the build
110
+ -----------------
111
+
112
+ Using Rake:
113
+
114
+ task :test do
115
+ exec "cutest test/*.rb"
116
+ end
117
+
118
+ task :default => :test
119
+
120
+ Using Make:
121
+
122
+ .PHONY: test
123
+
124
+ test:
125
+ cutest test/*.rb
126
+
127
+ Command-line interface
128
+ ----------------------
129
+
130
+ The tool `cutest` accepts a list of files and sends them to `Cutest.run`. If
131
+ you need to require a file or library before running the tests, as is the case
132
+ with test helpers, use the `-r` flag:
133
+
134
+ $ cutest -r ./test/helper.rb ./test/*_test.rb
135
+
136
+ If you want to check which version you are running, try the `-v` flag.
137
+
138
+ Installation
139
+ ------------
140
+
141
+ $ gem install cutest
142
+
143
+ License
144
+ -------
145
+
146
+ Copyright (c) 2010 Damian Janowski and Michel Martens
147
+
148
+ Permission is hereby granted, free of charge, to any person
149
+ obtaining a copy of this software and associated documentation
150
+ files (the "Software"), to deal in the Software without
151
+ restriction, including without limitation the rights to use,
152
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
153
+ copies of the Software, and to permit persons to whom the
154
+ Software is furnished to do so, subject to the following
155
+ conditions:
156
+
157
+ The above copyright notice and this permission notice shall be
158
+ included in all copies or substantial portions of the Software.
159
+
160
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
161
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
162
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
163
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
164
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
165
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
166
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
167
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require File.expand_path("../lib/cutest", __FILE__)
2
+
3
+ $VERBOSE = true
4
+
5
+ task :test do
6
+ Cutest.run(Dir["test/*.rb"])
7
+ end
8
+
9
+ task :default => :test
data/bin/cutest ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV.empty?
4
+ puts "usage: cutest [-r lib] [-v] file [-b (backtrace) [-p (pry rescue)]]"
5
+ exit
6
+ end
7
+
8
+ require_relative "../lib/cutest"
9
+ require_relative "../lib/cutest/vendor/clap"
10
+
11
+ files = Clap.run ARGV,
12
+ "-r" => lambda { |file| require file },
13
+ "-t" => lambda { |name| cutest[:only] = name },
14
+ "-s" => lambda { |name| cutest[:scope] = name },
15
+ "-b" => lambda { cutest[:backtrace] = true },
16
+ "-p" => lambda { ENV['PRY_RESCUE'] = 'true'; cutest[:pry_rescue] = true },
17
+ "-v" => lambda { puts Cutest::VERSION }
18
+
19
+ if files.any?
20
+ begin
21
+ success = Cutest.run(Dir[*files])
22
+
23
+ exit(1) unless success
24
+ rescue ThreadError
25
+ # Ignore this as it's caused by Process.waitall when using -p
26
+ end
27
+ end
data/cutest.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ require "./lib/cutest"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "cutest-cj"
5
+ s.version = Cutest::VERSION
6
+ s.summary = "Forking tests."
7
+ s.description = "Run tests in separate processes to avoid shared state."
8
+ s.authors = ["Damian Janowski", "Michel Martens", "Cyril David"]
9
+ s.email = ["djanowski@dimaion.com", "michel@soveran.com", "me@cyrildavid.com"]
10
+ s.homepage = "https://github.com/djanowski/cutest"
11
+
12
+ s.license = "MIT"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+
16
+ s.executables.push "cutest"
17
+
18
+ s.add_dependency 'pry-rescue'
19
+ s.add_dependency 'pry-stack_explorer'
20
+ end
@@ -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
data/lib/cutest.rb ADDED
@@ -0,0 +1,217 @@
1
+ require 'benchmark'
2
+
3
+ class Cutest
4
+ unless defined?(VERSION)
5
+ VERSION = "1.2.2"
6
+ FILTER = %r[/(ruby|jruby|rbx)[-/]([0-9\.])+]
7
+ CACHE = Hash.new { |h, k| h[k] = File.readlines(k) }
8
+ end
9
+
10
+ def self.run(files)
11
+ status = files.all? do |file|
12
+ run_file(file)
13
+
14
+ if not cutest[:pry_rescue]
15
+ Process.wait
16
+ $?.success?
17
+ else
18
+ begin
19
+ Process.waitall
20
+ rescue ThreadError, Interrupt
21
+ # Ignore this as it's caused by Process.waitall when using -p
22
+ end
23
+ end
24
+ end
25
+
26
+ puts
27
+
28
+ status
29
+ end
30
+
31
+ def self.run_file(file)
32
+ fork do
33
+ begin
34
+ load(file)
35
+ rescue LoadError, SyntaxError
36
+ display_error
37
+ exit 1
38
+
39
+ rescue StandardError
40
+ trace = $!.backtrace
41
+ pivot = trace.index { |line| line.match(file) }
42
+
43
+ puts "\n \e[93mTest: \e[0m%s\e[31m✘\e[0m\n" % (cutest[:test] != '' ? "#{cutest[:test]} " : '')
44
+
45
+ if pivot
46
+ other = trace[0..pivot].select { |line| line !~ FILTER }
47
+ other.reverse.each { |line| display_trace(line) }
48
+ else
49
+ display_trace(trace.first)
50
+ end
51
+
52
+ display_error
53
+
54
+ if not cutest[:pry_rescue]
55
+ exit 1
56
+ else
57
+ begin
58
+ Process.waitall
59
+ rescue ThreadError, Interrupt
60
+ # Ignore this as it's caused by Process.waitall when using -p
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.code(fn, ln)
68
+ begin
69
+ CACHE[fn][ln.to_i - 1].strip
70
+ rescue
71
+ "(Can't display line)"
72
+ end
73
+ end
74
+
75
+ def self.display_error
76
+ if cutest[:backtrace]
77
+ bt = $!.backtrace
78
+ bt.each do |line|
79
+ display_trace line
80
+ end
81
+ end
82
+
83
+ print " \033[93m#{$!.class}: "
84
+ print "\033[31m#{$!.message}\n"
85
+ end
86
+
87
+ def self.display_trace(line)
88
+ fn, ln = line.split(":")
89
+
90
+ puts " → \033[0mfile: #{fn} ↪#{ln}\e[0m"
91
+ puts " → \033[90mline: #{code(fn, ln)}\e[0m"
92
+ end
93
+
94
+ class AssertionFailed < StandardError
95
+ end
96
+
97
+ class Scope
98
+ def initialize(&scope)
99
+ @scope = scope
100
+ end
101
+
102
+ def call
103
+ instance_eval(&@scope)
104
+ end
105
+ end
106
+ end
107
+
108
+ module Kernel
109
+ private
110
+
111
+ # Use Thread.current[:cutest] to store information about test preparation
112
+ # and setup.
113
+ Thread.current[:cutest] ||= { :prepare => [] }
114
+
115
+ # Shortcut to access Thread.current[:cutest].
116
+ def cutest
117
+ Thread.current[:cutest]
118
+ end
119
+
120
+ # Create a class where the block will be evaluated. Recommended to improve
121
+ # isolation between tests.
122
+ def scope(name = nil, &block)
123
+ cutest[:current_scope] = name
124
+ return if cutest[:scope] and cutest[:scope] != cutest[:current_scope]
125
+
126
+ print "\n \033[93mScope: \033[0m#{cutest[:current_scope]}\n\n "
127
+ Cutest::Scope.new(&block).call
128
+ end
129
+
130
+ # Prepare the environment in order to run the tests. This method can be
131
+ # called many times, and each new block is appended to a list of
132
+ # preparation blocks. When a test is executed, all the preparation blocks
133
+ # are ran in the order they were declared. If called without a block, it
134
+ # returns the array of preparation blocks.
135
+ def prepare(&block)
136
+ cutest[:prepare] << block if block_given?
137
+ cutest[:prepare]
138
+ end
139
+
140
+ # Setup parameters for the tests. The block passed to setup is evaluated
141
+ # before running each test, and the result of the setup block is passed to
142
+ # the test as a parameter. If the setup and the tests are declared at the
143
+ # same level (in the global scope or in a sub scope), it is possible to use
144
+ # instance variables, but the parameter passing pattern is recommended to
145
+ # ensure there are no side effects.
146
+ #
147
+ # If the setup blocks are declared in the global scope and the tests are
148
+ # declared in sub scopes, the parameter passing usage is required.
149
+ #
150
+ # Setup blocks can be defined many times, but each new definition overrides
151
+ # the previous one. It is recommended to split the tests in many different
152
+ # files (the report is per file, not per assertion). Usually one setup
153
+ # block per file is enough, but nothing forbids having different scopes
154
+ # with different setup blocks.
155
+ def setup(&block)
156
+ cutest[:setup] = block if block_given?
157
+ cutest[:setup]
158
+ end
159
+
160
+ # Kernel includes a test method for performing tests on files.
161
+ undef test if defined? test
162
+
163
+ # Call the prepare and setup blocks before executing the test. Even
164
+ # though the assertions can live anywhere (it's not mandatory to put them
165
+ # inside test blocks), it is necessary to wrap them in test blocks in order
166
+ # to execute preparation and setup blocks.
167
+ def test(name = nil, &block)
168
+ cutest[:test] = name
169
+
170
+ if !cutest[:scope] || cutest[:scope] == cutest[:current_scope]
171
+ if !cutest[:only] || cutest[:only] == name
172
+ time_taken = Benchmark.measure do
173
+ prepare.each { |blk| blk.call }
174
+ block.call(setup && setup.call)
175
+ end
176
+ print " \n \033[93mTest: \033[0m#{cutest[:test]} \033[32m✔\033[0m\n \e[94m#{time_taken}\033[0m\n "
177
+ end
178
+ end
179
+ end
180
+
181
+ # Assert that value is not nil or false.
182
+ def assert(value)
183
+ flunk("expression returned #{value.inspect}") unless value
184
+ success
185
+ end
186
+
187
+ # Assert that two values are equal.
188
+ def assert_equal(value, other)
189
+ flunk("#{value.inspect} != #{other.inspect}") unless value == other
190
+ success
191
+ end
192
+
193
+ # Assert that the block doesn't raise the expected exception.
194
+ def assert_raise(expected = Exception)
195
+ begin
196
+ yield
197
+ rescue => exception
198
+ ensure
199
+ flunk("got #{exception.inspect} instead") unless exception.kind_of?(expected)
200
+ success
201
+ end
202
+ end
203
+
204
+ # Stop the tests and raise an error where the message is the last line
205
+ # executed before flunking.
206
+ def flunk(message = nil)
207
+ exception = Cutest::AssertionFailed.new(message)
208
+ exception.set_backtrace([caller[1]])
209
+
210
+ raise exception
211
+ end
212
+
213
+ # Executed when an assertion succeeds.
214
+ def success
215
+ print "•"
216
+ end
217
+ end
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(Cutest::AssertionFailed) do
7
+ assert false
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ test do
2
+ assert_equal 1, 1
3
+ end
4
+
5
+ test "raises if the assertion fails" do
6
+ assert_raise(Cutest::AssertionFailed) do
7
+ assert_equal 1, 2
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ test "catches the right exception" do
2
+ assert_raise(RuntimeError) do
3
+ raise RuntimeError
4
+ end
5
+ end
6
+
7
+ test "raises if the expectation is not met" do
8
+ assert_raise(Cutest::AssertionFailed) do
9
+ assert_raise(RuntimeError) do
10
+ raise ArgumentError
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ def foo
2
+ raise "Oops"
3
+ end
4
+
5
+ test "some unhandled exception" do
6
+ foo
7
+ end
@@ -0,0 +1,8 @@
1
+ def assert_empty(string)
2
+ flunk("not empty") unless string.empty?
3
+ success
4
+ end
5
+
6
+ test "failed custom assertion" do
7
+ assert_empty "foo"
8
+ end
@@ -0,0 +1,3 @@
1
+ test "failed assertion" do
2
+ assert false
3
+ end
@@ -0,0 +1 @@
1
+ load("test/fixtures/failure.rb")
@@ -0,0 +1,25 @@
1
+ test do
2
+ raise "This is not raised"
3
+ end
4
+
5
+ scope "scope" do
6
+ test do
7
+ assert true
8
+ end
9
+ end
10
+
11
+ scope "another scope" do
12
+ test do
13
+ raise "This is not raised"
14
+ end
15
+ end
16
+
17
+ scope "scope" do
18
+ test "test" do
19
+ assert true
20
+ end
21
+
22
+ test do
23
+ raise "This is raised"
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ def foo
2
+ raise "Invalid code"
3
+ end
4
+
5
+ test "external exceptions" do
6
+ assert true
7
+ end
data/test/prepare.rb ADDED
@@ -0,0 +1,25 @@
1
+ prepare do
2
+ $foo = []
3
+ end
4
+
5
+ prepare do
6
+ $foo << true
7
+ end
8
+
9
+ test "all the prepare blocks are called" do
10
+ assert $foo == [true]
11
+ end
12
+
13
+ prepare do
14
+ $foo << false
15
+ end
16
+
17
+ test "and are cumulative" do
18
+ assert $foo == [true, false]
19
+ end
20
+
21
+ scope do
22
+ test "and run inside scopes" do
23
+ assert $foo = [true, false]
24
+ end
25
+ end
data/test/run.rb ADDED
@@ -0,0 +1,78 @@
1
+ test "output of successful run" do
2
+ expected = ".\n"
3
+
4
+ out = %x{./bin/cutest test/fixtures/success.rb}
5
+
6
+ assert_equal(expected, out)
7
+ end
8
+
9
+ test "exit code of successful run" do
10
+ %x{./bin/cutest test/fixtures/success.rb}
11
+ assert_equal 0, $?.to_i
12
+ end
13
+
14
+ test "output of failed run" do
15
+ expected = "\n" +
16
+ " test: failed assertion\n" +
17
+ " line: assert false\n" +
18
+ " file: test/fixtures/failure.rb +2\n\n" +
19
+ "Cutest::AssertionFailed: expression returned false\n\n"
20
+
21
+ out = %x{./bin/cutest test/fixtures/failure.rb}
22
+
23
+ assert_equal(expected, out)
24
+ end
25
+
26
+ test "output of failed run" do
27
+ expected = "\n" +
28
+ " test: some unhandled exception\n" +
29
+ " line: raise \"Oops\"\n" +
30
+ " file: test/fixtures/exception.rb +2\n\n" +
31
+ "RuntimeError: Oops\n\n"
32
+
33
+ out = %x{./bin/cutest test/fixtures/exception.rb}
34
+
35
+ assert_equal(expected, out)
36
+ end
37
+
38
+ test "exit code of failed run" do
39
+ %x{./bin/cutest test/fixtures/failure.rb}
40
+
41
+ assert $?.to_i != 0
42
+ end
43
+
44
+ test "output of custom assertion" do
45
+ expected = "\n" +
46
+ " test: failed custom assertion\n" +
47
+ " line: assert_empty \"foo\"\n" +
48
+ " file: test/fixtures/fail_custom_assertion.rb +7\n\n" +
49
+ "Cutest::AssertionFailed: not empty\n\n"
50
+
51
+ out = %x{./bin/cutest test/fixtures/fail_custom_assertion.rb}
52
+
53
+ assert_equal(expected, out)
54
+ end
55
+
56
+ test "output of failure in nested file" do
57
+ expected = "\n" +
58
+ " test: failed assertion\n" +
59
+ " line: assert false\n" +
60
+ " file: test/fixtures/failure.rb +2\n\n" +
61
+ "Cutest::AssertionFailed: expression returned false\n\n"
62
+
63
+ out = %x{./bin/cutest test/fixtures/failure_in_loaded_file.rb}
64
+
65
+ assert_equal(expected, out)
66
+ end
67
+
68
+ test "only runs given scope name" do
69
+ out = %x{./bin/cutest test/fixtures/only_run_given_scope_name.rb -s scope}
70
+
71
+ assert out =~ /This is raised/
72
+ end
73
+
74
+ test "runs by given scope and test names" do
75
+ %x{./bin/cutest test/fixtures/only_run_given_scope_name.rb -s scope -o test}
76
+
77
+ assert_equal 0, $?.to_i
78
+ end
data/test/scopes.rb ADDED
@@ -0,0 +1,27 @@
1
+ @bar = true
2
+
3
+ scope do
4
+ @foo = true
5
+
6
+ test "something" do
7
+ assert defined?(@foo)
8
+ assert !defined?(@bar)
9
+ end
10
+ end
11
+
12
+ scope do
13
+ test "something" do
14
+ assert !defined?(@foo)
15
+ assert !defined?(@bar)
16
+ end
17
+ end
18
+
19
+ scope do
20
+ @baz = true
21
+
22
+ scope do
23
+ test "something" do
24
+ assert !defined?(@baz)
25
+ end
26
+ end
27
+ end
data/test/setup.rb ADDED
@@ -0,0 +1,29 @@
1
+ setup do
2
+ {:a => 23, :b => 43}
3
+ end
4
+
5
+ test "should receive the result of the setup block as a parameter" do |params|
6
+ assert params == {:a => 23, :b => 43}
7
+ end
8
+
9
+ test "if the params are modified..." do |params|
10
+ params[:a] = nil
11
+ end
12
+
13
+ test "...it should preserve the original values from the setup" do |params|
14
+ assert_equal 23, params[:a]
15
+ end
16
+
17
+ setup do
18
+ "Hello world!"
19
+ end
20
+
21
+ test "only the most recently defined setup block is executed" do |value|
22
+ assert "Hello world!" == value
23
+ end
24
+
25
+ scope do
26
+ test "works inside scopes too" do |value|
27
+ assert "Hello world!" == value
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cutest-cj
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Damian Janowski
8
+ - Michel Martens
9
+ - Cyril David
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-05-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: pry-rescue
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: pry-stack_explorer
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ description: Run tests in separate processes to avoid shared state.
44
+ email:
45
+ - djanowski@dimaion.com
46
+ - michel@soveran.com
47
+ - me@cyrildavid.com
48
+ executables:
49
+ - cutest
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - ".gitignore"
54
+ - CHANGELOG.md
55
+ - LICENSE
56
+ - README.markdown
57
+ - Rakefile
58
+ - bin/cutest
59
+ - cutest.gemspec
60
+ - lib/cutest.rb
61
+ - lib/cutest/vendor/clap.rb
62
+ - test/assert.rb
63
+ - test/assert_equal.rb
64
+ - test/assert_raise.rb
65
+ - test/fixtures/exception.rb
66
+ - test/fixtures/fail_custom_assertion.rb
67
+ - test/fixtures/failure.rb
68
+ - test/fixtures/failure_in_loaded_file.rb
69
+ - test/fixtures/only_run_given_scope_name.rb
70
+ - test/fixtures/success.rb
71
+ - test/prepare.rb
72
+ - test/run.rb
73
+ - test/scopes.rb
74
+ - test/setup.rb
75
+ homepage: https://github.com/djanowski/cutest
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Forking tests.
99
+ test_files: []
100
+ has_rdoc: