rspec-instrumentation-matcher 0.0.4 → 0.0.6

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
- SHA1:
3
- metadata.gz: 539ee1e205d5e7e5ca496e11c38af0a38f7d436e
4
- data.tar.gz: 962d456600fef1e8c4959a151c2eaf18e8e4f6a3
2
+ SHA256:
3
+ metadata.gz: 8467c604dd5d08c30de5e04b5e729cc0487fb1302c2cd7a960f72060f67a9505
4
+ data.tar.gz: 10946f0c6b8c829765b8d0aac9e86a2974ccf8693c24af6ed8821a385015b260
5
5
  SHA512:
6
- metadata.gz: de975bd43cf60ce0b7dee62f4e71c533f5a17001786e802d854a26691046bd9a6a630f265531c5d93da1588e66d93ec11d48f84b9290df6f4d1f9554c9d83351
7
- data.tar.gz: ae2a6afdd15bc84ec4cd2489c8cdc9edc72cb442a9a20438a463a7c219514cb08bf74bbebbcdd51f601e25e9650db07e5c86f78828739b3e87175a2cb1af98f5
6
+ metadata.gz: 24023b18d3d8559dc3cc42f23fe3d82de50519ac6981857863422dc585cff2372db0ce605a5f33481a84203721d4cf3429965bba29f996c65eab685957d7e649
7
+ data.tar.gz: 5794a1bbd85c4ae6416e7744e8fb156bc4430af4639f9377a7787d59492f225459aba44d24706f9a57445ec0910f88e83e08fadfecdaf2cac9907951d27b9898
data/Gemfile.lock CHANGED
@@ -1,22 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-instrumentation-matcher (0.0.3)
4
+ rspec-instrumentation-matcher (0.0.6)
5
5
  activesupport
6
6
  rspec-expectations
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (4.1.1)
12
- i18n (~> 0.6, >= 0.6.9)
13
- json (~> 1.7, >= 1.7.7)
11
+ activesupport (5.2.0)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
14
  minitest (~> 5.1)
15
- thread_safe (~> 0.1)
16
15
  tzinfo (~> 1.1)
17
16
  celluloid (0.15.2)
18
17
  timers (~> 1.1.0)
19
18
  coderay (1.1.0)
19
+ concurrent-ruby (1.0.5)
20
20
  diff-lcs (1.2.5)
21
21
  ffi (1.9.3)
22
22
  formatador (0.2.5)
@@ -29,15 +29,15 @@ GEM
29
29
  guard-rspec (4.2.9)
30
30
  guard (~> 2.1)
31
31
  rspec (>= 2.14, < 4.0)
32
- i18n (0.6.9)
33
- json (1.8.1)
32
+ i18n (1.0.1)
33
+ concurrent-ruby (~> 1.0)
34
34
  listen (2.7.6)
35
35
  celluloid (>= 0.15.2)
36
36
  rb-fsevent (>= 0.9.3)
37
37
  rb-inotify (>= 0.9)
38
38
  lumberjack (1.0.6)
39
39
  method_source (0.8.2)
40
- minitest (5.3.4)
40
+ minitest (5.11.3)
41
41
  pry (0.9.12.6)
42
42
  coderay (~> 1.0)
43
43
  method_source (~> 0.8)
@@ -59,9 +59,9 @@ GEM
59
59
  rspec-support (3.0.0)
60
60
  slop (3.5.0)
61
61
  thor (0.19.1)
62
- thread_safe (0.3.4)
62
+ thread_safe (0.3.6)
63
63
  timers (1.1.0)
64
- tzinfo (1.2.1)
64
+ tzinfo (1.2.5)
65
65
  thread_safe (~> 0.1)
66
66
 
67
67
  PLATFORMS
@@ -70,3 +70,6 @@ PLATFORMS
70
70
  DEPENDENCIES
71
71
  guard-rspec
72
72
  rspec-instrumentation-matcher!
73
+
74
+ BUNDLED WITH
75
+ 1.16.1
data/README.md CHANGED
@@ -20,6 +20,8 @@ Or install it yourself as:
20
20
 
21
21
  expect{ subject.do_something }.to instrument("key").with( foo: :bar )
22
22
  expect{ subject.do_something }.to instrument("key").once
23
+ expect{ subject.do_something }.to instrument("key").twice
24
+ expect{ subject.do_something }.to instrument("key").never
23
25
  expect{ subject.do_something }.to instrument("key").at_least(1)
24
26
  expect{ subject.do_something }.to instrument("key").at_most(10)
25
27
  expect{ subject.do_something }.to instrument("key").times(5)
@@ -1,4 +1,4 @@
1
- require "rspec-instrumentation-matcher/version"
1
+ require 'rspec-instrumentation-matcher/version'
2
2
  require 'active_support/notifications'
3
3
  module RSpec
4
4
  module Instrumentation
@@ -7,7 +7,6 @@ module RSpec
7
7
  InstrumentMatcher.new(subject)
8
8
  end
9
9
  class InstrumentMatcher
10
-
11
10
  def initialize(subject)
12
11
  @subject = subject
13
12
  @payload = nil
@@ -26,41 +25,43 @@ module RSpec
26
25
  def matches?(event_proc)
27
26
  raise_block_syntax_error if block_given?
28
27
 
29
- subscription = ActiveSupport::Notifications.subscribe @subject do |name, start, finish, id, _payload|
30
- @payload = _payload
28
+ callback = lambda do |_name, _start, _finish, _id, payload|
29
+ @payload = payload
31
30
  @received += 1
32
31
  end
32
+ ActiveSupport::Notifications.subscribed(callback, @subject) do
33
+ event_proc.call
34
+ end
33
35
 
34
- event_proc.call
35
-
36
- ActiveSupport::Notifications.unsubscribe(subscription)
37
-
38
- times? and at_least? and at_most? and with?
36
+ times? && at_least? && at_most? && with?
37
+ end
39
38
 
39
+ def negative_failure_message
40
+ failure_message(true)
40
41
  end
41
42
 
42
- def failure_message
43
- message = "Expected #{@subject} to be instrumented"
43
+ alias failure_message_when_negated negative_failure_message
44
+
45
+ def failure_message(negative = false)
46
+ message = "Expected #{@subject} #{'not ' if negative}to be instrumented"
44
47
  message << " at least #{count @at_least}" unless at_least?
45
48
  message << " at most #{count @at_most}" unless at_most?
46
49
  message << " exactly #{count @times}" unless times?
47
50
 
48
- if !at_least? or !at_most? or !times?
51
+ if !at_least? || !at_most? || !times?
49
52
  message << " but was instrumented #{count @received}"
50
- message << " and the payload should have been" unless with?
53
+ message << ' and the payload should have been' unless with?
51
54
  else
52
- message << " with" unless with?
55
+ message << ' with' unless with?
53
56
  end
54
57
 
55
58
  message << " #{@payload_expectation.inspect} instead of #{@payload.inspect}" unless with?
56
59
 
57
-
58
60
  message
59
-
60
61
  end
61
62
 
62
63
  def at_least(value)
63
- @at_least=value
64
+ @at_least = value
64
65
  self
65
66
  end
66
67
 
@@ -74,30 +75,31 @@ module RSpec
74
75
  times(1)
75
76
  end
76
77
 
78
+ def twice
79
+ times(2)
80
+ end
81
+
77
82
  def never
78
83
  times(0)
79
84
  end
80
85
 
81
-
82
-
83
86
  def times(value)
84
87
  @at_least = nil
85
88
  @times = value
86
89
  self
87
90
  end
88
91
 
89
-
90
92
  def with(expectation)
91
93
  @with = true
92
94
  @payload_expectation = expectation
93
95
  self
94
96
  end
95
97
 
96
-
97
98
  private
99
+
98
100
  def count(value)
99
101
  if value == 1
100
- "1 time"
102
+ '1 time'
101
103
  else
102
104
  "#{value} times"
103
105
  end
@@ -119,17 +121,16 @@ module RSpec
119
121
  end
120
122
 
121
123
  def delta_payload
122
- unmatched = @payload_expectation.reject do |key,value|
124
+ unmatched = @payload_expectation.reject do |key, value|
123
125
  matched_value?(value, @payload[key]) if @payload.key? key
124
126
  end
125
127
  end
126
128
 
127
129
  def with?
128
130
  return true unless @with
129
- !@payload.nil? and delta_payload.size == 0
131
+ !@payload.nil? && delta_payload.empty?
130
132
  end
131
133
 
132
-
133
134
  def matched_value?(expected, actual)
134
135
  case expected
135
136
  when actual then true
@@ -140,16 +141,13 @@ module RSpec
140
141
  end
141
142
 
142
143
  def expectation_message
143
- message = ""
144
+ message = ''
144
145
  message << "at least #{count @at_least}" unless @at_least.nil?
145
146
  message << "at most #{count @at_most}" unless @at_most.nil?
146
147
  message << "exactly #{count @times}" unless @times.nil?
147
- if @with
148
- message << " with payload #{@payload.inspect}"
149
- end
148
+ message << " with payload #{@payload.inspect}" if @with
150
149
  message
151
150
  end
152
-
153
151
  end
154
152
  end
155
153
  end
@@ -158,5 +156,3 @@ end
158
156
  module RSpec::Matchers
159
157
  include RSpec::Instrumentation::Matcher
160
158
  end
161
-
162
-
@@ -1,7 +1,7 @@
1
1
  module Rspec
2
2
  module Instrumentation
3
3
  module Matcher
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.6"
5
5
  end
6
6
  end
7
7
  end
@@ -11,10 +11,25 @@ describe RSpec::Instrumentation::Matcher do
11
11
  let(:notification) { 'a notification' }
12
12
 
13
13
  specify { expect { event(notification) }.to instrument(notification).once }
14
+ specify { expect { 2.times { event(notification) } }.to instrument(notification).twice }
14
15
  specify { expect { 2.times { event(notification) } }.not_to instrument(notification).never }
15
16
  specify { expect { 2.times { event(notification) } }.to instrument(notification).at_least(1) }
16
17
  specify { expect { 2.times { event(notification) } }.to instrument(notification).at_most(2) }
17
18
  specify { expect { event(notification,{ test_payload: true }) }.to instrument(notification).with(test_payload: true) }
18
19
 
19
-
20
+ context 'when the instrumented block raises an exception' do
21
+ it 'still unsubscribes the spy subscription' do
22
+ notifier = ActiveSupport::Notifications.notifier
23
+ expect {
24
+ begin
25
+ expect {
26
+ ActiveSupport::Notifications.instrument(notification) do
27
+ raise ZeroDivisionError
28
+ end
29
+ }.to instrument(notification)
30
+ rescue ZeroDivisionError
31
+ end
32
+ }.not_to change { notifier.listeners_for(notification).length }
33
+ end
34
+ end
20
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-instrumentation-matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Verestiuc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2018-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-expectations
@@ -90,11 +90,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.2.2
93
+ rubygems_version: 2.7.6
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Support for spec-ing ActiveSupport::Notifications.instrument calls
97
97
  test_files:
98
98
  - spec/rspec-instrumentation-matcher_spec.rb
99
99
  - spec/spec_helper.rb
100
- has_rdoc: