async-rspec 1.5.0 → 1.6.0

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
  SHA256:
3
- metadata.gz: 4662aa08daa03184f72a9447f5c7d8567bd35f89692695f71febab03d4897297
4
- data.tar.gz: d68401193d009f2fb6147e325628f65b76e53e2e921946464cfc1fe63985e9fa
3
+ metadata.gz: d82743af426d13dd6463e49155abd2d3a1f4e5111ea1f8dc5607b78c1fd77545
4
+ data.tar.gz: ccf15bf3cd995e71e05866e3935f845ef4f42999acda0cf3172ece2eefc1269e
5
5
  SHA512:
6
- metadata.gz: 3ca947cc355d74542beec3b42de5e1c12dda183ff82cf119dc5537e6069842ede90995beafd2d597ecfd8e92cf4919237098ec187a50fd5ae5fa9bbdb59ccd7c
7
- data.tar.gz: afd1957e91eab763e8ed16fe5a53820ebb88b6263d5bffcab789bce9d229be04e2e1e31f2346b751e99b8c8017ec668b3d8a5ad0ec5dee4287ce3c1d34050930
6
+ metadata.gz: a6e607fd2d6bd68f5414c9ffa87ea306c17bf1ba1c599320855eadfa12998e9f857f066b7781d87c12c6b35c120fc5ed1cffd86647c6f8a24d943712bb5c549a
7
+ data.tar.gz: bb604e41f0da0e384ad361b27770aa48c0545ded1290c3d711559ad93c5ed66cb655f3f7c35cc56ab81531d602df2cbe04bfbc7e2ed5aed6b170b7c21677dce9
data/.travis.yml CHANGED
@@ -2,15 +2,21 @@ language: ruby
2
2
  sudo: false
3
3
  dist: trusty
4
4
  cache: bundler
5
- rvm:
6
- - 2.2
7
- - 2.3
8
- - 2.4
9
- - 2.5
10
- - jruby-head
11
- - ruby-head
12
- - rbx-3
5
+
6
+ before_script:
7
+ - gem update --system
8
+ - gem install bundler
9
+
13
10
  matrix:
11
+ include:
12
+ - rvm: 2.3
13
+ - rvm: 2.4
14
+ - rvm: 2.5
15
+ - rvm: 2.6
16
+ - rvm: jruby-head
17
+ env: JRUBY_OPTS="--debug -X+O"
18
+ - rvm: ruby-head
19
+ - rvm: rbx-3
14
20
  allow_failures:
15
21
  - rvm: ruby-head
16
22
  - rvm: jruby-head
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in async-rspec.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ unless RUBY_PLATFORM =~ /java/
8
+ gem "ruby-prof"
9
+ end
10
+ end
data/README.md CHANGED
@@ -68,6 +68,7 @@ RSpec.describe IO do
68
68
 
69
69
  output_task.wait
70
70
  expect(message).to be == "Hello World"
71
+ end
71
72
  end
72
73
  ```
73
74
 
data/async-rspec.gemspec CHANGED
@@ -15,12 +15,11 @@ Gem::Specification.new do |spec|
15
15
  end
16
16
 
17
17
  spec.require_paths = ["lib"]
18
-
18
+
19
19
  spec.add_dependency "rspec", "~> 3.0"
20
20
 
21
21
  # Since we test the shared contexts, we need some bits of async:
22
22
  spec.add_development_dependency "async", "~> 1.8"
23
- spec.add_development_dependency "ruby-prof"
24
23
 
25
24
  spec.add_development_dependency "bundler", "~> 1.13"
26
25
  spec.add_development_dependency "rake", "~> 10.0"
data/lib/async/rspec.rb CHANGED
@@ -20,3 +20,4 @@
20
20
 
21
21
  require_relative "rspec/version"
22
22
  require_relative "rspec/reactor"
23
+ require_relative "rspec/memory"
@@ -0,0 +1,147 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
20
+
21
+ require 'rspec/expectations'
22
+ require 'objspace'
23
+
24
+ module Async
25
+ module RSpec
26
+ module Memory
27
+ Allocation = Struct.new(:count, :size) do
28
+ def << object
29
+ self.count += 1
30
+ self.size += ObjectSpace.memsize_of(object)
31
+ end
32
+ end
33
+
34
+ class Trace
35
+ def self.supported?
36
+ ObjectSpace.respond_to? :trace_object_allocations
37
+ end
38
+
39
+ if supported?
40
+ def self.capture(&block)
41
+ self.new.tap do |trace|
42
+ trace.capture(&block)
43
+ end
44
+ end
45
+ else
46
+ def self.capture(&block)
47
+ yield
48
+
49
+ return nil
50
+ end
51
+ end
52
+
53
+ def initialize
54
+ @allocated = Hash.new{|h,k| h[k] = Allocation.new(0, 0)}
55
+ @retained = Hash.new{|h,k| h[k] = Allocation.new(0, 0)}
56
+ end
57
+
58
+ attr :allocated
59
+ attr :retained
60
+
61
+ def current_objects(generation)
62
+ allocations = []
63
+
64
+ ObjectSpace.each_object do |object|
65
+ if ObjectSpace.allocation_generation(object) == generation
66
+ allocations << object
67
+ end
68
+ end
69
+
70
+ return allocations
71
+ end
72
+
73
+ def capture(&block)
74
+ allocated = nil
75
+
76
+ begin
77
+ GC.disable
78
+
79
+ generation = GC.count
80
+ ObjectSpace.trace_object_allocations(&block)
81
+
82
+ allocated = current_objects(generation)
83
+ ensure
84
+ GC.enable
85
+ end
86
+
87
+ GC.start
88
+ retained = current_objects(generation)
89
+
90
+ allocated.each do |object|
91
+ @allocated[object.class] << object
92
+ end
93
+
94
+ retained.each do |object|
95
+ @retained[object.class] << object
96
+ end
97
+ end
98
+ end
99
+
100
+ class LimitAllocations
101
+ include ::RSpec::Matchers::Composable
102
+
103
+ def initialize(allocations)
104
+ @allocations = allocations
105
+ @errors = []
106
+ end
107
+
108
+ def supports_block_expectations?
109
+ true
110
+ end
111
+
112
+ def matches?(given_proc)
113
+ return true unless trace = Trace.capture(&given_proc)
114
+
115
+ @allocations.each do |klass, acceptable|
116
+ next unless allocation = allocation = trace.allocated[klass]
117
+
118
+ case acceptable
119
+ when Range
120
+ unless acceptable.include? allocation.count
121
+ @errors << "allocated #{allocation.count} instances (#{allocation.size} bytes) of #{klass}, expected within #{acceptable}"
122
+ end
123
+ when Integer
124
+ if allocation.count > acceptable
125
+ @errors << "allocated #{allocation.count} instances (#{allocation.size} bytes) of #{klass}, expected at most #{acceptable}"
126
+ end
127
+ end
128
+ end
129
+
130
+ return @errors.empty?
131
+ end
132
+
133
+ def failure_message
134
+ "exceeded allocation limit: #{@errors.join(', ')}"
135
+ end
136
+ end
137
+
138
+ def limit_allocations(allocations)
139
+ LimitAllocations.new(allocations)
140
+ end
141
+ end
142
+
143
+ RSpec.shared_context Memory do
144
+ include Memory
145
+ end
146
+ end
147
+ end
@@ -27,11 +27,15 @@ module Async
27
27
  require 'ruby-prof'
28
28
 
29
29
  RSpec.shared_context Profile do
30
- let(:profile) {RubyProf::Profile.new(merge_fibers: true)}
31
-
32
- after(:each) do |example|
33
- unless profile.threads.empty?
34
- # profile.eliminate_methods!([/RSpec::/])
30
+ around(:each) do |example|
31
+ profile = RubyProf::Profile.new(merge_fibers: true)
32
+
33
+ begin
34
+ profile.start
35
+
36
+ example.run
37
+ ensure
38
+ profile.stop
35
39
 
36
40
  printer = RubyProf::FlatPrinter.new(profile)
37
41
  printer.print(STDOUT)
@@ -41,7 +45,7 @@ module Async
41
45
  rescue LoadError
42
46
  RSpec.shared_context Profile do
43
47
  before(:all) do
44
- puts "Profiling not enabled/supported."
48
+ warn "Profiling not enabled/supported."
45
49
  end
46
50
  end
47
51
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module RSpec
23
- VERSION = "1.5.0"
23
+ VERSION = "1.6.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-29 00:00:00.000000000 Z
11
+ date: 2018-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
- - !ruby/object:Gem::Dependency
42
- name: ruby-prof
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'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +82,7 @@ files:
96
82
  - async-rspec.gemspec
97
83
  - lib/async/rspec.rb
98
84
  - lib/async/rspec/leaks.rb
85
+ - lib/async/rspec/memory.rb
99
86
  - lib/async/rspec/profile.rb
100
87
  - lib/async/rspec/reactor.rb
101
88
  - lib/async/rspec/ssl.rb