minitest-around 0.1.0.pre2 → 0.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bf2caee1ef50c01ab6f46cbc01adc8b1dde4f2e
4
- data.tar.gz: 4634b4d4d16c34ce197cd959d1c15288783ce93b
3
+ metadata.gz: b8b6c586cacf0c22de37cbfcad9787667212d43d
4
+ data.tar.gz: 9f45e41f76cd08e01ce39c69167aa20c174d0d9a
5
5
  SHA512:
6
- metadata.gz: 4f6ceb34a1d7bd1044fd01e1c6be9de438282516242ebcdc74f394dd9829662f0ad7c9c29ebb0c23153e9ce71b288e4f5e7535eaa2a9135bf19d448bbb9bbcd1
7
- data.tar.gz: fafcdfbb46f67f25e4d9ba9e7b0d3e99b1b99c8a19abc515db2e3b06ff858256e35091816223d68a13e1cf6136d411ed76d6917e9def5ca81d8d9277438d2603
6
+ metadata.gz: a0875c6e0dbfa057708be548c4694bcd9a8598d97dd5ff9c31a15dd4297e431f4f5c24bac7dab9b412447169f7505d1e76eee0dd7d748ba26d885a6d6589dca8
7
+ data.tar.gz: 9ab900ca329d49d4ee3d124767b94edc0f52984c775e91a58e0de3efae6f3839fe2099bbdcb03c09db0c0ade9dac8d56d9c6b5ad64b4235c6c6c6badb31f034a
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg
5
5
  rdoc
6
+ .rvmrc
data/.travis.yml CHANGED
@@ -2,5 +2,10 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - jruby-19mode
6
- - rbx-19mode
5
+ - 2.1.0
6
+ - jruby
7
+ - rbx
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: rbx
11
+ fast_finish: true
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
- gem 'rake'
4
-
5
- # Specify your gem's dependencies in minitest-around.gemspec
6
- gemspec
3
+ gemspec # Specify dependencies in minitest-around.gemspec
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  {<img src="https://secure.travis-ci.org/splattael/minitest-around.png?branch=master" alt="Build Status" />}[http://travis-ci.org/splattael/minitest-around] {<img src="https://badge.fury.io/rb/minitest-around.png" alt="Gem Version" />}[http://badge.fury.io/rb/minitest-around] {<img src="https://codeclimate.com/github/splattael/minitest-around.png" />}[https://codeclimate.com/github/splattael/minitest-around]
4
4
 
5
- Around block for minitest 5.
5
+ Around block for minitest 5.X.
6
6
 
7
7
  Alternative for setup/teardown dance.
8
8
 
@@ -16,6 +16,8 @@ RDoc[http://rubydoc.info/github/splattael/minitest-around/master/file/README.rdo
16
16
 
17
17
  == Usage
18
18
 
19
+ See examples[https://github.com/splattael/minitest-around/tree/master/examples] directory for some example usage..
20
+
19
21
  === Unit tests
20
22
 
21
23
  require 'minitest/autorun'
@@ -32,40 +34,24 @@ RDoc[http://rubydoc.info/github/splattael/minitest-around/master/file/README.rdo
32
34
  end
33
35
  end
34
36
 
35
- class PassArgsTest < Minitest::Test
36
- def around
37
- yield 1, 2
38
- end
39
-
40
- def test_passes_args(a, b)
41
- assert_equal 3, a + b
42
- end
43
- end
44
-
45
37
  === Spec
46
38
 
47
39
  require 'minitest/autorun'
48
40
  require 'minitest/around/spec'
49
- require 'thread'
41
+ require 'tmpdir'
50
42
 
51
- describe "Mutex" do
43
+ describe "inside new directory" do
52
44
  around do |test|
53
- Mutex.new.synchronize(&test)
54
- end
55
-
56
- it "synchronized" do
57
- # ...
58
- end
59
-
60
- describe "pass args" do
61
- around do
62
- # No block arg "test",
63
- [ 1, 2 ]
45
+ Dir.mktmpdir do |dir|
46
+ $dir = dir
47
+ Dir.chdir(dir) do
48
+ test.call
49
+ end
64
50
  end
51
+ end
65
52
 
66
- it "passes args" do |a, b|
67
- (a + b).must_equal 3
68
- end
53
+ it "is in new directory" do
54
+ assert_equal $dir, Dir.pwd
69
55
  end
70
56
  end
71
57
 
@@ -77,14 +63,24 @@ Test bodies won't be run if you don't *yield* inside +around+.
77
63
 
78
64
  +minitest-around+ currently supports only +minitest+ 5.X.
79
65
 
80
- === Nesting
66
+ Please see the mt4[https://github.com/splattael/minitest-around/tree/mt4] branch
67
+ for +minitest+ 4.7.X support.
81
68
 
82
- Around block don't nest correctly. Please see GH issue[https://github.com/splattael/minitest-around/issues/2] for more info and workaround[https://github.com/splattael/minitest-around/issues/2#issuecomment-15769151].
83
69
 
84
70
  == License
85
71
 
86
72
  MIT License[http://www.opensource.org/licenses/mit-license.php]
87
73
 
74
+ == Authors
75
+
76
+ * Peter Suschlik (https://github.com/splattael)
77
+
78
+ == Contributors[https://github.com/splattael/minitest-around/graphs/contributors]
79
+
80
+ * Michael Grosser (https://github.com/grosser)
81
+ * Rick Martínez (https://github.com/rickmzp)
82
+ * Philip Nelson (https://github.com/pnelson)
83
+
88
84
  == Contributing
89
85
 
90
86
  1. Fork it
data/Rakefile CHANGED
@@ -28,3 +28,12 @@ RDoc::Task.new(:rdoc) do |rdoc|
28
28
  rdoc.main = 'README.rdoc'
29
29
  rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'lib/**/*.rb')
30
30
  end
31
+
32
+ # Examples
33
+ EXAMPLES = FileList["examples/*.rb"]
34
+ desc "Run all examples"
35
+ task :"test:examples" do
36
+ EXAMPLES.each do |example|
37
+ sh "bundle", "exec", "ruby", example
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/around/spec'
3
+ require 'tmpdir'
4
+
5
+ describe "inside new directory" do
6
+ around do |test|
7
+ Dir.mktmpdir do |dir|
8
+ $dir = dir
9
+ Dir.chdir(dir) do
10
+ test.call
11
+ end
12
+ end
13
+ end
14
+
15
+ it "is in new directory" do
16
+ assert_equal $dir, Dir.pwd
17
+ end
18
+ end
@@ -1,16 +1,29 @@
1
- require 'minitest/spec'
1
+ require 'minitest'
2
2
 
3
3
  require 'minitest/around/version'
4
4
  require 'minitest/around/unit'
5
5
 
6
- module Minitest::Spec::DSL
7
- def around(&outer)
8
- define_method(:around) do |&inner|
9
- if outer.arity == 1
10
- outer.call(inner)
11
- else
12
- inner.call *outer.call
6
+ class Minitest::Spec
7
+ module DSL
8
+ # - resume to call first part
9
+ # - execute test
10
+ # - resume fiber to execute last part
11
+ def around(&block)
12
+ fib = nil
13
+ before do
14
+ fib = Fiber.new { |context, resume| context.instance_exec(resume, &block) }
15
+ fib.resume(self, lambda { Fiber.yield })
13
16
  end
17
+ after { fib.resume }
18
+ end
19
+
20
+ # Minitest does not support multiple before/after blocks
21
+ def before(type=nil, &block)
22
+ include Module.new { define_method(:setup) { super(); instance_exec(&block) } }
23
+ end
24
+
25
+ def after(type=nil, &block)
26
+ include Module.new { define_method(:after) { super(); instance_exec(&block) } }
14
27
  end
15
28
  end
16
29
  end
@@ -1,12 +1,14 @@
1
- require 'minitest/unit'
1
+ require 'minitest'
2
2
  require 'minitest/around/version'
3
3
 
4
4
  class Minitest::Test
5
- def send(name)
6
- if defined?(around) && name.start_with?('test')
7
- around { |*args| super(name, *args) }
5
+ alias_method :run_without_around, :run
6
+ def run(*args)
7
+ if defined?(around)
8
+ around { run_without_around(*args) }
8
9
  else
9
- super(name)
10
+ run_without_around(*args)
10
11
  end
12
+ self
11
13
  end
12
14
  end
@@ -1,5 +1,5 @@
1
- module MiniTest
1
+ module Minitest
2
2
  module Around
3
- VERSION = '0.1.0.pre2'
3
+ VERSION = '0.2.0.pre'
4
4
  end
5
5
  end
@@ -1,25 +1,16 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require 'minitest/around/version'
1
+ require './lib/minitest/around/version'
4
2
 
5
- Gem::Specification.new do |s|
6
- s.name = "minitest-around"
7
- s.version = MiniTest::Around::VERSION
3
+ Gem::Specification.new "minitest-around", Minitest::Around::VERSION do |s|
8
4
  s.authors = ["Peter Suschlik"]
9
5
  s.email = ["peter-minitest-around@suschlik.de"]
10
6
  s.homepage = "https://github.com/splattael/minitest-around"
11
- s.summary = %q{Around block for minitest.}
12
- s.description = %q{Alternative for setup/teardown dance.}
7
+ s.summary = "Around block for minitest."
8
+ s.description = "Alternative for setup/teardown dance."
13
9
  s.license = 'MIT'
10
+ s.files = `git ls-files`.split("\n")
14
11
 
15
- s.rubyforge_project = "minitest-around"
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
21
-
22
- s.add_dependency 'minitest', '~> 5.0.8'
12
+ s.add_dependency 'minitest', '~> 5.0'
23
13
 
24
14
  s.add_development_dependency 'rdoc'
15
+ s.add_development_dependency 'rake'
25
16
  end
data/test/around_spec.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/around/spec'
3
3
 
4
- describe "MiniTest Around" do
4
+ describe "Minitest Around" do
5
5
  describe "without around" do
6
6
  it "works w/o defining parameters" do
7
7
  assert true
8
8
  end
9
9
  end
10
10
 
11
- describe "without args" do
11
+ describe "simple" do
12
12
  around do |test|
13
13
  $before = true
14
14
  test.call
@@ -20,25 +20,50 @@ describe "MiniTest Around" do
20
20
  end
21
21
  end
22
22
 
23
- describe "with single arg" do
24
- around { "string" }
23
+ describe "context" do
24
+ before { @x = 1 }
25
25
 
26
- it "passes string argument" do |name|
27
- name.must_equal "string"
26
+ around do |test|
27
+ @x = 2
28
+ test.call
29
+ assert_equal 2, @x
28
30
  end
29
31
 
30
- describe "nested" do
31
- it "string is still around" do |name|
32
- name.must_equal "string"
32
+ it "stays in context" do
33
+ @x.must_equal 2
34
+ end
35
+ end
36
+
37
+ describe "nested fun" do
38
+ let(:list) { [] }
39
+ before { list << 1 }
40
+ before { list << 2 }
41
+ after { list << 6 }
42
+ around { |t| list << 3; t.call; list << 7 }
43
+ before { list << 4 }
44
+ around { |t| list << 5; t.call; list << 8 }
45
+ after { list << 9 }
46
+ after do
47
+ if @xxx == 1
48
+ list.must_equal [1, 2, 3, 4, 5, 6, 7, 8, 9]
49
+ elsif @xxx == 2
50
+ list.must_equal [1, 2, 3, 4, 5, 51, 6, 7, 8, 9]
51
+ else
52
+ raise
33
53
  end
34
54
  end
35
55
 
36
- describe "with multiple args" do
37
- around { [ 1, 2 ] }
56
+ it "orders" do
57
+ @xxx = 1
58
+ list.must_equal [1, 2, 3, 4, 5]
59
+ end
60
+
61
+ describe "more nesting fun" do
62
+ before { list << 51 }
38
63
 
39
- it "passes multiple args" do |a, b|
40
- a.must_equal 1
41
- b.must_equal 2
64
+ it "orders" do
65
+ @xxx = 2
66
+ list.must_equal [1, 2, 3, 4, 5, 51]
42
67
  end
43
68
  end
44
69
  end
data/test/around_test.rb CHANGED
@@ -18,24 +18,3 @@ class TestWithoutArgs < Minitest::Test
18
18
  assert_equal true, $before
19
19
  end
20
20
  end
21
-
22
- class TestWithSingleArg < Minitest::Test
23
- def around
24
- yield "string"
25
- end
26
-
27
- def test_around_passes_string(string)
28
- assert_equal "string", string
29
- end
30
- end
31
-
32
- class TestWithMultipleArgs < Minitest::Test
33
- def around
34
- yield 1, 2
35
- end
36
-
37
- def test_passes_multiple_args(a, b)
38
- assert_equal 1, a
39
- assert_equal 2, b
40
- end
41
- end
@@ -0,0 +1,36 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/around'
3
+
4
+ $var = []
5
+
6
+ describe 'Outer' do
7
+ before do
8
+ $var << :before
9
+ end
10
+ after do
11
+ $var << :after
12
+ $var.must_equal [:before, :ibefore, :begin, :ibegin, :during, :iend, :end, :iafter, :after]
13
+ end
14
+ around do |test|
15
+ $var << :begin
16
+ test.call
17
+ $var << :end
18
+ end
19
+
20
+ describe 'Inner' do
21
+ before do
22
+ $var << :ibefore
23
+ end
24
+ after do
25
+ $var << :iafter
26
+ end
27
+ around do |test|
28
+ $var << :ibegin
29
+ test.call
30
+ $var << :iend
31
+ end
32
+ it 'testing' do
33
+ $var << :during
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/around/unit'
3
+
4
+ $var = []
5
+
6
+ class OuterNestedTest < Minitest::Test
7
+ def setup
8
+ $var << :before
9
+ end
10
+ def teardown
11
+ $var << :after
12
+ $var.must_equal [:before, :ibefore, :begin, :ibegin, :during, :iend, :end, :iafter, :after]
13
+ end
14
+ def around
15
+ $var << :begin
16
+ yield
17
+ $var << :end
18
+ end
19
+ end
20
+
21
+ class InnerNestedTest < OuterNestedTest
22
+ def setup
23
+ $var << :ibefore
24
+ end
25
+ def teardown
26
+ $var << :iafter
27
+ end
28
+ def around
29
+ $var << :ibegin
30
+ yield
31
+ $var << :iend
32
+ end
33
+ def test_nesting
34
+ $var << :during
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-around
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre2
4
+ version: 0.2.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Suschlik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-24 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.8
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.8
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Alternative for setup/teardown dance.
42
56
  email:
43
57
  - peter-minitest-around@suschlik.de
@@ -46,14 +60,12 @@ extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
62
  - .gitignore
49
- - .rvmrc
50
63
  - .travis.yml
51
64
  - Gemfile
52
65
  - LICENSE
53
66
  - README.rdoc
54
67
  - Rakefile
55
- - examples/mutex_spec.rb
56
- - examples/mutex_test.rb
68
+ - examples/chdir_spec.rb
57
69
  - lib/minitest/around.rb
58
70
  - lib/minitest/around/spec.rb
59
71
  - lib/minitest/around/unit.rb
@@ -61,6 +73,8 @@ files:
61
73
  - minitest-around.gemspec
62
74
  - test/around_spec.rb
63
75
  - test/around_test.rb
76
+ - test/nested_spec.rb
77
+ - test/nested_test.rb
64
78
  homepage: https://github.com/splattael/minitest-around
65
79
  licenses:
66
80
  - MIT
@@ -80,10 +94,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
94
  - !ruby/object:Gem::Version
81
95
  version: 1.3.1
82
96
  requirements: []
83
- rubyforge_project: minitest-around
97
+ rubyforge_project:
84
98
  rubygems_version: 2.0.3
85
99
  signing_key:
86
100
  specification_version: 4
87
101
  summary: Around block for minitest.
88
102
  test_files: []
89
- has_rdoc:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm @minitest-around --create
@@ -1,24 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'minitest/around'
3
- require 'thread'
4
-
5
- describe "Mutex" do
6
- around do |test|
7
- Mutex.new.synchronize(&test)
8
- end
9
-
10
- it "synchronized" do
11
- # ...
12
- end
13
-
14
- describe "pass args" do
15
- around do
16
- # No block arg "test",
17
- [ 1, 2 ]
18
- end
19
-
20
- it "passes args" do |a, b|
21
- (a + b).must_equal 3
22
- end
23
- end
24
- end
@@ -1,23 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'minitest/around'
3
- require 'thread'
4
-
5
- class MutexTest < Minitest::Test
6
- def around(&block)
7
- Mutex.new.synchronize(&block)
8
- end
9
-
10
- def test_synchronized
11
- # ...
12
- end
13
- end
14
-
15
- class PassArgsTest < Minitest::Test
16
- def around
17
- yield 1, 2
18
- end
19
-
20
- def test_passes_args(a, b)
21
- assert_equal 3, a + b
22
- end
23
- end