rspec-matcher 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: 949268732dd1527ea7670b3351218482dad1a2d1
4
- data.tar.gz: 9e2cecc4308ccbe2b8244283e1a6fbb079f0a7aa
3
+ metadata.gz: 7532489552ab193eb37e60fa4ce1842d8c0f4930
4
+ data.tar.gz: 6272b0ed34cfbfae5e47027beba52ed09a842ef1
5
5
  SHA512:
6
- metadata.gz: 293ba5441ee375f2cedf2744ac5c74b6bff5bb8e1a084c7c1023eacdedae8ef05540a74811d78f3780f53477f1fa1b99e9626db5ae1c12a4b2595ac1daadc46f
7
- data.tar.gz: b4288aedb72ed2487626fa9adb15f7764104f0e9a8c4f787d9502310a096a6c7a2af23f7e940554c625fb0cd14df9d1015fc719ce1d19d41a7856fc8e55b450d
6
+ metadata.gz: 8051875b6eccdfee13f989e4ac44f96ef241bed02b7c82adc72f7331653ea149c9d706915f11493c66afd22679c5ec3df173fe46317db40ca15f6311660784a8
7
+ data.tar.gz: 635c5c03852de53e9ee053ac664b1905f8ceda58f8c3a0150d4eb66c016f81967601160a0af992c3dd901274a38bb2f0f9ca990d1bf49493ba6b94ff4135cc3d
data/lib/rspec/matcher.rb CHANGED
@@ -42,6 +42,45 @@ module RSpec
42
42
  attr_accessor :expected, :actual
43
43
  end
44
44
 
45
+ # @api private
46
+ # Ensures hook is always called and takes care of control jumps.
47
+ class RescueAndCatch
48
+ attr_accessor :context, :catchable, :to_catch, :rescuable, :to_rescue
49
+
50
+ def initialize context, &block
51
+ self.context = context
52
+ instance_eval(&block)
53
+ end
54
+
55
+ def result
56
+ r = catch catchable do
57
+ cdo(&to_catch)
58
+ end
59
+ cdo(&to_rescue)
60
+
61
+ r
62
+ rescue rescuable => e
63
+ cdo(&to_rescue)
64
+ raise e
65
+ end
66
+
67
+ private
68
+
69
+ def catching catchable, &block
70
+ self.to_catch = block
71
+ self.catchable = catchable
72
+ end
73
+
74
+ def ensuring rescuable, &block
75
+ self.to_rescue = block
76
+ self.rescuable = rescuable
77
+ end
78
+
79
+ def cdo &block
80
+ context.instance_eval(&block)
81
+ end
82
+ end
83
+
45
84
  # @api private
46
85
  # Used to let user define initialize
47
86
  module PrependedMethods #:nodoc:
@@ -97,14 +136,13 @@ module RSpec
97
136
  # Hides RSpec internal api
98
137
  def matches? actual
99
138
  self.actual = actual
100
-
101
- catch(:resolution) do
102
- if method(:match).arity == 0
103
- match
104
- else
105
- match actual
139
+ RescueAndCatch.new self do
140
+ catching(:resolution) do
141
+ method(:match).arity == 0 ? match : match(actual)
106
142
  end
107
- end
143
+
144
+ ensuring(Exception) { clean_up }
145
+ end.result
108
146
  end
109
147
 
110
148
  # @method actual
@@ -171,6 +209,11 @@ module RSpec
171
209
  false
172
210
  end
173
211
 
212
+ # Always gets called after decision is made.
213
+ # @return [void]
214
+ def clean_up
215
+ end
216
+
174
217
  private
175
218
 
176
219
  # @api public
@@ -12,7 +12,7 @@ module RSpec
12
12
  end
13
13
 
14
14
  def self.version
15
- "0.1.3"
15
+ "0.1.4"
16
16
  end
17
17
 
18
18
  def self.version_label
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pooyan Khosravi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport