em-minitest-spec 1.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.
File without changes
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2011-06-11
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/em/minitest/spec.rb
6
+ test/test_em_minitest_spec.rb
@@ -0,0 +1,75 @@
1
+ = em_minitest_spec
2
+
3
+ * https://github.com/phiggins/em-minitest-spec
4
+
5
+ == DESCRIPTION:
6
+
7
+ Utility to allow easy integration of MiniTest::Spec and Eventmachine.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Allows specs to run inside an EM reactor.
12
+ * Opt-in: this library does not automatically change how MiniTest::Spec works without your permission.
13
+ * before/after blocks and setup/teardown methods are not run in the reactor, and so cannot contain code that requires an EM reactor.
14
+
15
+ == SYNOPSIS:
16
+
17
+ # Get the gem version on 1.9.x
18
+ gem 'minitest'
19
+ require 'minitest/autorun'
20
+ require 'em/minitest/spec'
21
+
22
+ describe MyEventmachineSpec do
23
+ describe "these specs will run normally" do
24
+ it "tests things" do
25
+ puts "foo"
26
+ end
27
+
28
+ # ...
29
+ end
30
+
31
+ describe "these specs will run inside an EM reactor" do
32
+ include EM::MiniTest::Spec
33
+
34
+ it "runs this inside EM.run" do
35
+ puts EM.reactor_running? # true
36
+ end
37
+
38
+ # ...
39
+ end
40
+ end
41
+
42
+ == REQUIREMENTS:
43
+
44
+ * Eventmachine: no specific version, although 1.0.0.beta.3 was tested with.
45
+ * MiniTest: 2.2.2 was the current version as of writing this, so probably
46
+ that or newer.
47
+
48
+ == INSTALL:
49
+
50
+ * gem install em-minitest-spec
51
+
52
+ == LICENSE:
53
+
54
+ (The MIT License)
55
+
56
+ Copyright (c) 2011 Pete Higgins
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining
59
+ a copy of this software and associated documentation files (the
60
+ 'Software'), to deal in the Software without restriction, including
61
+ without limitation the rights to use, copy, modify, merge, publish,
62
+ distribute, sublicense, and/or sell copies of the Software, and to
63
+ permit persons to whom the Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright notice and this permission notice shall be
67
+ included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
70
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :git
7
+
8
+ Hoe.spec 'em-minitest-spec' do
9
+ developer('pete higgins', 'pete@peterhiggins.org')
10
+
11
+ extra_deps << ["eventmachine"]
12
+ extra_dev_deps << ["minitest", "~> 2.2"]
13
+
14
+ self.testlib = :minitest
15
+ self.test_prelude = 'gem "minitest"'
16
+ end
17
+
18
+ # vim: syntax=ruby
@@ -0,0 +1,98 @@
1
+ require 'eventmachine'
2
+ require 'minitest/spec'
3
+
4
+ module EM # :nodoc:
5
+ module MiniTest # :nodoc:
6
+ module Spec # :nodoc
7
+ VERSION = '1.1.0' # :nodoc:
8
+
9
+ ##
10
+ # +wait+ indicates that the spec is not expected to be completed when
11
+ # the block is finished running. A call to +done+ is required when using
12
+ # +wait+.
13
+ #
14
+ # # setup my spec to use EM::MiniTest::Spec
15
+ # describe MyClass do
16
+ # include EM::MiniTest::Spec
17
+ #
18
+ # # The call to defer will return immediately, so the spec code
19
+ # # needs to keep running until callback is called.
20
+ # it "does some async things" do
21
+ # defer_me = lambda do
22
+ # # some async stuff
23
+ # end
24
+ #
25
+ # callback = lambda do
26
+ # done!
27
+ # end
28
+ #
29
+ # EM.defer defer_me, callback
30
+ #
31
+ # wait!
32
+ # end
33
+ def wait
34
+ @wait = true
35
+ end
36
+ alias wait! wait
37
+
38
+ ##
39
+ # Indicates that an async spec is finished. See +wait+ for example usage.
40
+ def done
41
+ EM.cancel_timer(@timeout)
42
+ EM.stop
43
+ end
44
+ alias done! done
45
+
46
+ ##
47
+ # A helper method for the use case of waiting for some operation to
48
+ # complete that is not necessarily under the control of the spec code.
49
+ #
50
+ # # These are exactly equivalent
51
+ # it "waits with the helper" do
52
+ # wait_for do
53
+ # assert true
54
+ # end
55
+ # end
56
+ #
57
+ # it "waits manually" do
58
+ # EM.next_tick do
59
+ # assert true
60
+ # done!
61
+ # end
62
+ #
63
+ # wait!
64
+ # end
65
+ def wait_for
66
+ EM.next_tick do
67
+ yield
68
+ done!
69
+ end
70
+
71
+ wait!
72
+ end
73
+
74
+ def self.included base # :nodoc:
75
+ base.extend(ClassMethods)
76
+ end
77
+
78
+ module ClassMethods # :nodoc:
79
+ def it *args, &block # :nodoc:
80
+ return super unless block_given?
81
+
82
+ super do
83
+ @wait = false
84
+
85
+ EM.run do
86
+ @timeout = EM.add_timer(0.1) do
87
+ flunk "test timed out!"
88
+ end
89
+
90
+ instance_eval(&block)
91
+ done! unless @wait
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,86 @@
1
+ gem 'minitest'
2
+ require 'minitest/autorun'
3
+ require "em/minitest/spec"
4
+
5
+ class TestEmMinitestSpec < MiniTest::Unit::TestCase
6
+ def setup
7
+ @spec = describe "EM::MiniTest::Spec" do
8
+ include EM::MiniTest::Spec
9
+
10
+ it "runs vanilla specs" do
11
+ assert true
12
+ end
13
+
14
+ it "runs specs inside reactor" do
15
+ assert EM.reactor_running?
16
+ end
17
+
18
+ it "allows pending specs"
19
+
20
+ it "allows manual reactor control" do
21
+ EM.next_tick do
22
+ done!
23
+ end
24
+
25
+ wait!
26
+ end
27
+
28
+ it "has a manual control helper" do
29
+ wait_for do
30
+ pass
31
+ end
32
+
33
+ EM.add_timer(0.1) { flunk }
34
+ end
35
+
36
+ it "flunks long running specs" do
37
+ wait!
38
+ end
39
+ end
40
+ end
41
+
42
+ def run_test name
43
+ test_name = name.tr(' ', '_')
44
+ test = @spec.instance_methods.detect {|m| m =~ /test_[0-9]+_#{test_name}/ }
45
+
46
+ raise "no spec found matching: #{name}" unless test
47
+
48
+ @spec.new(test).run(MiniTest::Unit.new)
49
+ end
50
+
51
+ def assert_passes name
52
+ assert_equal '.', run_test(name)
53
+ end
54
+
55
+ def assert_skips name
56
+ assert_equal 'S', run_test(name)
57
+ end
58
+
59
+ def assert_fails name
60
+ assert_equal 'F', run_test(name)
61
+ end
62
+
63
+ def test_runs_regular_specs
64
+ assert_passes "runs vanilla specs"
65
+ end
66
+
67
+ def test_runs_specs_in_em_reactor
68
+ assert_passes "runs specs inside reactor"
69
+ end
70
+
71
+ def test_skips_specs_with_no_block
72
+ assert_skips "allows pending specs"
73
+ end
74
+
75
+ def test_allows_manual_event_loop_control
76
+ assert_passes "allows manual reactor control"
77
+ end
78
+
79
+ def test_wait_for
80
+ assert_passes "has a manual control helper"
81
+ end
82
+
83
+ def test_timeout
84
+ assert_fails "flunks long running specs"
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-minitest-spec
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.1.0
6
+ platform: ruby
7
+ authors:
8
+ - pete higgins
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-12 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: eventmachine
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: minitest
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: "2.2"
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: hoe
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.9.4
46
+ type: :development
47
+ version_requirements: *id003
48
+ description: Utility to allow easy integration of MiniTest::Spec and Eventmachine.
49
+ email:
50
+ - pete@peterhiggins.org
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - History.txt
57
+ - Manifest.txt
58
+ - README.txt
59
+ files:
60
+ - History.txt
61
+ - Manifest.txt
62
+ - README.txt
63
+ - Rakefile
64
+ - lib/em/minitest/spec.rb
65
+ - test/test_em_minitest_spec.rb
66
+ - .gemtest
67
+ homepage: https://github.com/phiggins/em-minitest-spec
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --main
73
+ - README.txt
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project: em-minitest-spec
91
+ rubygems_version: 1.8.2
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Utility to allow easy integration of MiniTest::Spec and Eventmachine.
95
+ test_files:
96
+ - test/test_em_minitest_spec.rb