testo-test 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/testo/test.rb +93 -0
  3. metadata +57 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 947684c06ed7578ba6f6934c4d5e940d4ab2717d
4
+ data.tar.gz: c97a2dce3ce78acb8ede19b772653090f7be2621
5
+ SHA512:
6
+ metadata.gz: f5d24a5e30fc49e5e68f65be3528732aef2a013528ab2f6df7b8152cd7e678167781c596676532d11ce43e6fc42081475a4f7d3cd807f05bcd42d2b930db58fd
7
+ data.tar.gz: dc56204a18e535bf5c2874e32eacc1a995250a236e0e955bdbb28629a364d3a08cb43259056b8a848a75ff4cb5c160fbd77c0078e413099d1ada95fff9bd60b6
@@ -0,0 +1,93 @@
1
+ module Testo
2
+ class Test
3
+ class Report
4
+ attr_reader :test, :error, :it
5
+ def initialize message
6
+ @test, @error, @it = message.values_at :test, :error, :it
7
+ end
8
+
9
+ def ok?
10
+ not error
11
+ end
12
+
13
+ def debug
14
+ test.debug it
15
+ end
16
+ end
17
+
18
+ require 'method_source'
19
+ require 'forwardable'
20
+ require 'timeout'
21
+
22
+ TIMEOUT = 5
23
+
24
+ def initialize &block
25
+ @block = block
26
+ end
27
+
28
+ extend Forwardable
29
+ def_delegator :@block, :source
30
+
31
+ attr_reader :it
32
+ def [] it = nil
33
+ message = { test: self, it: it }.merge in_isolation {
34
+ message = { pid: Process.pid }
35
+
36
+ begin
37
+ run it
38
+ rescue Exception
39
+ message[:error] = $!
40
+ end
41
+
42
+ message
43
+ }
44
+
45
+ Report.new message
46
+ end
47
+
48
+ # Currently, this method is expected to be run from a Pry session only.
49
+ def debug it
50
+ PryByebug::BreakCommand.new.send :add_breakpoint, "Testo::Test#run", nil
51
+ # How to "next next step" automatically when the breakpoint is hit?
52
+
53
+ begin
54
+ run it
55
+ raise "Cannot reproduce. It might be a heisebug."
56
+ rescue
57
+ $!
58
+ end
59
+ end
60
+
61
+ private
62
+ class FailedAssertion < StandardError
63
+ end
64
+
65
+ def run it
66
+ @it = it
67
+ raise FailedAssertion unless instance_exec &@block
68
+ end
69
+
70
+ # The timeout has to be enforced from the parent, because some code
71
+ # may cause MRI to become unresponsive indefinetely.
72
+ # https://github.com/mbj/mutant#the-crash--stuck-problem-mri
73
+ def in_isolation &block
74
+ reader, writer = IO.pipe
75
+
76
+ pid = fork do
77
+ reader.close
78
+ writer.write Marshal.dump block.call
79
+ writer.close
80
+ end
81
+ writer.close
82
+
83
+ begin
84
+ Timeout.timeout TIMEOUT do
85
+ Marshal.load reader.read
86
+ end
87
+ rescue Timeout::Error
88
+ Process.kill :KILL, pid
89
+ { pid: pid, error: $! }
90
+ end.tap { reader.close; Process.wait pid }
91
+ end
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testo-test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anatoly Chernow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: method_source
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/testo/test.rb
34
+ homepage:
35
+ licenses: []
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.6.11
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Run tests with proper isolation(in separate processes).
57
+ test_files: []