rspec-message-within 1.0.0 → 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.
- checksums.yaml +4 -4
- data/lib/rspec/message/within.rb +44 -13
- data/lib/rspec/message/within/version.rb +1 -1
- data/spec/rspec_message_within_spec.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86005d7513d01eef6bd43ece104ea78d80ca2ff3
|
4
|
+
data.tar.gz: f243479b5a09274e53490ee6accf9097affdc423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f965dc638f52d4278c54dda068eda0088642576d0a4469ff98f0e4e14f48a29e707462de45cf75afb8173d279aa50d9051da4563598dfc4c8326ffbb75fe5423
|
7
|
+
data.tar.gz: f3054e941b22734f20ba54abcf8b57967bf7077b0f2fb0d2da9035ec1f50cd1dff81d12a9c45841165f8f6a45b2e2f490bbae888420704335eb1b147c3fcd48c
|
data/lib/rspec/message/within.rb
CHANGED
@@ -5,7 +5,17 @@ module RSpec
|
|
5
5
|
module Message
|
6
6
|
module Within
|
7
7
|
|
8
|
-
|
8
|
+
def self.until(within_time)
|
9
|
+
if within_time && within_time > 0.0
|
10
|
+
time = Time.now + within_time
|
11
|
+
while time > Time.now
|
12
|
+
break if yield
|
13
|
+
sleep 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module MessageExpectationPatch
|
9
19
|
def self.included(base)
|
10
20
|
# Seems to not work. Why?
|
11
21
|
base.send :include, InstanceMethods
|
@@ -17,14 +27,8 @@ module RSpec
|
|
17
27
|
|
18
28
|
module InstanceMethods
|
19
29
|
def verify_messages_received
|
20
|
-
@within_time
|
21
|
-
|
22
|
-
if @within_time
|
23
|
-
time = Time.now + @within_time
|
24
|
-
while time > Time.now
|
25
|
-
break if expected_messages_received? and !negative?
|
26
|
-
sleep 0
|
27
|
-
end
|
30
|
+
Within.until(@within_time || 0) do
|
31
|
+
expected_messages_received? and !negative?
|
28
32
|
end
|
29
33
|
|
30
34
|
orig_verify_messages_received
|
@@ -37,7 +41,7 @@ module RSpec
|
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
40
|
-
module
|
44
|
+
module ReceivePatch
|
41
45
|
def self.included(base)
|
42
46
|
base.send :include, InstanceMethods
|
43
47
|
end
|
@@ -52,9 +56,36 @@ module RSpec
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
55
|
-
end
|
56
59
|
|
57
|
-
|
58
|
-
|
60
|
+
module ExpectationChainPatch
|
61
|
+
def self.included(base)
|
62
|
+
base.send :alias_method, :orig_expectation_fulfilled?, :expectation_fulfilled?
|
63
|
+
base.send :undef_method, :expectation_fulfilled?
|
64
|
+
base.send :define_method, :expectation_fulfilled?, InstanceMethods.instance_method(:expectation_fulfilled?)
|
65
|
+
end
|
66
|
+
|
67
|
+
module InstanceMethods
|
68
|
+
def expectation_fulfilled?
|
69
|
+
Within.until(@within_time || 0) do
|
70
|
+
orig_expectation_fulfilled?
|
71
|
+
end
|
72
|
+
|
73
|
+
orig_expectation_fulfilled?
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module ChainPatch
|
79
|
+
def within(time)
|
80
|
+
@within_time = time
|
81
|
+
self
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
::RSpec::Mocks::MessageExpectation.send :include, MessageExpectationPatch
|
86
|
+
::RSpec::Mocks::AnyInstance::Chain.send :include, ChainPatch
|
87
|
+
::RSpec::Mocks::AnyInstance::ExpectationChain.send :include, ExpectationChainPatch
|
88
|
+
::RSpec::Mocks::Matchers::Receive.send :include, ReceivePatch
|
89
|
+
end
|
59
90
|
end
|
60
91
|
end
|
@@ -1,17 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class Reciv
|
4
|
+
def message; end
|
5
|
+
end
|
6
|
+
|
3
7
|
describe Rspec::Message::Within do
|
4
8
|
let(:obj) { double }
|
5
9
|
|
6
10
|
describe '#within' do
|
7
11
|
it 'should allow to time-box an asynchronous method call' do
|
8
|
-
expect(obj).to receive(:message).within(
|
12
|
+
expect(obj).to receive(:message).within(10).seconds
|
9
13
|
|
10
14
|
Thread.new do
|
15
|
+
sleep 1
|
11
16
|
obj.message
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
20
|
+
it 'any-instance' do
|
21
|
+
expect_any_instance_of(Reciv).to receive(:message).within(10).seconds
|
22
|
+
|
23
|
+
Thread.new do
|
24
|
+
sleep 1
|
25
|
+
Reciv.new.message
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
15
29
|
it 'should fail message expectation after timeout' do
|
16
30
|
expect(obj).to_not receive(:message).within(1).seconds
|
17
31
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-message-within
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-mocks
|