waiting_rspec_matchers 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/waiting_rspec_matchers.rb +84 -83
- data/lib/waiting_rspec_matchers/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99be2f59b452f566aa05847760a02bd088b4384d
|
4
|
+
data.tar.gz: 6b694444e1a1ded769882a57514f3abadbb4b498
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39d425a4a73b8ecaa10e9b80634db1ae6ccc423212f8ae5c7f019fe227a8e9816cdb85743426fa29c01e2a4d39083046dc1d25b0aef8594c3c7dc307433bb8b8
|
7
|
+
data.tar.gz: 51c18ae54c6b0dd88a6dde556b7652bdf8932189fa022cd0c57a6b457315c96ed691767cde3bddfed37ec8258e3f1e94f8ea2b520a9981b44b660076ed94371b
|
@@ -17,106 +17,107 @@ module WaitingRspecMatchers
|
|
17
17
|
config.default_delay = 0.05
|
18
18
|
end
|
19
19
|
|
20
|
-
private
|
21
|
-
|
22
|
-
|
20
|
+
# @api private
|
21
|
+
# Provides the implementation for `become_<matcher_name>`.
|
22
|
+
# Not intended to be instantiated directly.
|
23
|
+
class Become
|
24
|
+
include ::RSpec::Matchers
|
25
|
+
include ::RSpec::Matchers::Composable
|
26
|
+
|
27
|
+
def initialize(rspec_matcher_name, where_included, *args, &expected_block)
|
28
|
+
@rspec_matcher_name = rspec_matcher_name
|
29
|
+
@where_included = where_included
|
30
|
+
@args = args
|
31
|
+
@expected_block = expected_block
|
32
|
+
@chains = []
|
33
|
+
end
|
23
34
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
if ::WaitingRspecMatchers.const_defined?(matcher_class_name)
|
32
|
-
k = ::WaitingRspecMatchers.const_get(matcher_class_name)
|
33
|
-
else
|
34
|
-
k = define_matcher_class
|
35
|
-
::WaitingRspecMatchers.const_set(matcher_class_name, k)
|
36
|
-
end
|
35
|
+
# @api public
|
36
|
+
# Specifies a number of seconds that WaitingRspecMatchers should wait for a matcher to succeed
|
37
|
+
# @param [Numeric]
|
38
|
+
def during(max_wait_time_in_seconds)
|
39
|
+
@max_wait_time = max_wait_time_in_seconds
|
40
|
+
self
|
41
|
+
end
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
# @api public
|
44
|
+
# Specifies period between tries that WaitingRspecMatchers should make when waiting for a matcher to succeed
|
45
|
+
# @param [Numeric]
|
46
|
+
def delay(seconds)
|
47
|
+
@delay = seconds
|
48
|
+
self
|
41
49
|
end
|
42
|
-
end
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
51
|
+
def method_missing(method, *args)
|
52
|
+
@chains << [method, args]
|
53
|
+
self
|
54
|
+
end
|
47
55
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
include ::RSpec::Matchers::Composable
|
52
|
-
|
53
|
-
def initialize(rspec_matcher_name, where_included, *args, &expected_block)
|
54
|
-
@rspec_matcher_name = rspec_matcher_name
|
55
|
-
@where_included = where_included
|
56
|
-
@args = args
|
57
|
-
@expected_block = expected_block
|
58
|
-
@chains = []
|
59
|
-
end
|
56
|
+
def matches?(block)
|
57
|
+
match_helper(:to, &block)
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
60
|
+
def does_not_match?(block)
|
61
|
+
match_helper(:not_to, &block)
|
62
|
+
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
def failure_message
|
65
|
+
@failure_message
|
66
|
+
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
68
|
+
def failure_message_when_negated
|
69
|
+
@failure_message
|
70
|
+
end
|
74
71
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
72
|
+
def supports_block_expectations?
|
73
|
+
true
|
74
|
+
end
|
79
75
|
|
80
|
-
|
81
|
-
start_time = Time.now
|
82
|
-
begin
|
83
|
-
matcher = @where_included.__send__(@rspec_matcher_name.to_sym, *@args, &@expected_block)
|
84
|
-
@chains.each do |chain|
|
85
|
-
matcher = matcher.__send__(chain[0], *chain[1])
|
86
|
-
end
|
87
|
-
if matcher.respond_to?(:supports_block_expectations?) && matcher.supports_block_expectations?
|
88
|
-
expect { block.call }.__send__(to_or_not_to, matcher)
|
89
|
-
else
|
90
|
-
expect(block.call).__send__(to_or_not_to, matcher)
|
91
|
-
end
|
92
|
-
rescue RSpec::Expectations::ExpectationNotMetError => e
|
93
|
-
@failure_message = e.message
|
94
|
-
return false if (Time.now - start_time) >= max_wait_time
|
95
|
-
sleep @delay || WaitingRspecMatchers.default_delay
|
96
|
-
retry
|
97
|
-
end
|
98
|
-
true
|
99
|
-
end
|
76
|
+
private
|
100
77
|
|
101
|
-
|
102
|
-
|
103
|
-
|
78
|
+
def max_wait_time
|
79
|
+
@max_wait_time || WaitingRspecMatchers.default_wait_time
|
80
|
+
end
|
104
81
|
|
105
|
-
|
106
|
-
|
82
|
+
def match_helper(to_or_not_to, &block)
|
83
|
+
start_time = Time.now
|
84
|
+
begin
|
85
|
+
matcher = @where_included.__send__(@rspec_matcher_name.to_sym, *@args, &@expected_block)
|
86
|
+
@chains.each do |chain|
|
87
|
+
matcher = matcher.__send__(chain[0], *chain[1])
|
88
|
+
end
|
89
|
+
if matcher.respond_to?(:supports_block_expectations?) && matcher.supports_block_expectations?
|
90
|
+
expect { block.call }.__send__(to_or_not_to, matcher)
|
91
|
+
else
|
92
|
+
expect(block.call).__send__(to_or_not_to, matcher)
|
93
|
+
end
|
94
|
+
rescue ::RSpec::Expectations::ExpectationNotMetError => e
|
95
|
+
@failure_message = e.message
|
96
|
+
return false if (Time.now - start_time) >= max_wait_time
|
97
|
+
sleep @delay || WaitingRspecMatchers.default_delay
|
98
|
+
retry
|
107
99
|
end
|
100
|
+
true
|
101
|
+
end
|
102
|
+
end
|
108
103
|
|
109
|
-
|
110
|
-
@failure_message
|
111
|
-
end
|
104
|
+
private
|
112
105
|
|
113
|
-
|
114
|
-
@failure_message
|
115
|
-
end
|
106
|
+
BECOME_REGEX = /^become_(.+)/
|
116
107
|
|
117
|
-
|
118
|
-
|
108
|
+
def method_missing(method_name, *args, &expected_block)
|
109
|
+
if m = method_name.to_s.match(BECOME_REGEX)
|
110
|
+
rspec_matcher_name = m[1]
|
111
|
+
unless respond_to?(rspec_matcher_name)
|
112
|
+
raise ArgumentError, "Method `#{rspec_matcher_name}` doesn't exist. It was expected to exist and return instance of class that implements RSpec's matcher protocol."
|
119
113
|
end
|
114
|
+
Become.new(rspec_matcher_name, self, *args, &expected_block)
|
115
|
+
else
|
116
|
+
super
|
120
117
|
end
|
121
118
|
end
|
119
|
+
|
120
|
+
def respond_to_missing?(method_name, *)
|
121
|
+
method_name.to_s =~ BECOME_REGEX || super
|
122
|
+
end
|
122
123
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waiting_rspec_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Botalov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-expectations
|
@@ -97,5 +97,5 @@ rubyforge_project:
|
|
97
97
|
rubygems_version: 2.2.2
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
|
-
summary:
|
100
|
+
summary: become_* RSpec matchers that do the same as * matchers but also wait
|
101
101
|
test_files: []
|