rspec-matcher 0.1.1 → 0.1.2

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: 2692798d25d46df0b76f619de32069e12838fc2d
4
- data.tar.gz: 67d773c64e7ad7b9d52c6f66d99278764886908e
3
+ metadata.gz: c7d9326b4509b1a13c2eeaa608dacc8af2129505
4
+ data.tar.gz: 66740b04f4576b8f1a042635e6b83ff34d20238c
5
5
  SHA512:
6
- metadata.gz: d007950a729f60b3af87dac44b2adfe43167b6acc90039d3265d5dab8716a32e9b00305173302d4a59c96a349a8cb5337d56bd4adb4695b820062ce7d21b6524
7
- data.tar.gz: 34a27ebf1ef52db458c50665bc650a6f89a235a7b9624fd8458afda197fa3f24a13ac85139f6b687a5b3629ee378fd5471b918bcb2d05d087f3c718cfd194242
6
+ metadata.gz: 972bf6776f9cedb65749f0a635e75237d855a28179f1337c02cb84c602d211c992e0f2ef68307ae375ebe4e54d0308329807073de2fb189725fb6295cffe72d8
7
+ data.tar.gz: d87f887352ca0badf3d903331a541ae0bd0b59516c2a84c3c6818119460e242ae8bead6852349ea9f87a93b8f8d09fe9f97ce090541eeb1b31194b66b460f2ef
data/.yardopts CHANGED
@@ -1 +1,3 @@
1
1
  --markup markdown
2
+ --private
3
+ --protected
data/README.md CHANGED
@@ -55,7 +55,7 @@ Add the following to your Gemfile:
55
55
  gem "rspec-matcher"
56
56
 
57
57
  # Usage
58
- [API Reference](http://www.rubydoc.info/gems/rspec-matcher/0.1.1/RSpec/Matcher)
58
+ [API Reference](http://www.rubydoc.info/gems/rspec-matcher/RSpec/Matcher)
59
59
 
60
60
  class BeNilMatcher
61
61
  include RSpec::Matcher
@@ -1,6 +1,7 @@
1
1
  require "rspec/matcher/identity"
2
2
  require "active_support/concern"
3
3
 
4
+ # Does not monkey patch but is inside RSpec namespace.
4
5
  module RSpec
5
6
  # Provides minimal interface for creating RSpec Matchers.
6
7
  #
@@ -44,36 +45,45 @@ module RSpec
44
45
  # @api private
45
46
  # Used to let user define initialize
46
47
  module PrependedMethods #:nodoc:
47
- # Stores expected and passes all args to super
48
+ # Stores expected and options then passes remaining args to super
48
49
  # @api private
49
50
  # @param [any] expected stored as expected and not passed to custom initializer
51
+ # @param [Hash] options stored by calling setter methods
50
52
  # @param [any] args... passed to custom initializer
51
53
  # @param [Proc] block passed to custom initializer
52
- def initialize expected = UNDEFINED, *args, &block
54
+ def initialize expected = UNDEFINED, options = {}, *args, &block
53
55
  self.expected = expected
56
+ options.to_a.each do |option|
57
+ key, value = option
58
+ send("#{key}=", value)
59
+ end
54
60
  super(*args, &block)
55
61
  end
56
62
  end
57
63
 
58
64
  # Methods added as class method to includer
59
65
  module ClassMethods
60
- # Registers this matcher in RSpec.
66
+ # Registers this matcher in RSpec. Optionally sets options via setter
67
+ # methods on initialize.
61
68
  # @example
62
69
  # class BeNil
63
70
  # include RSpec::Matcher
64
71
  # register_as "be_nil"
72
+ # register_as "be_empty", empty: true
65
73
  # #...
66
74
  # end
67
75
  #
68
- # expect(actual).to be_nil
76
+ # expect(nil).to be_nil
77
+ # expect([]).to be_empty
69
78
  #
79
+ # @note self.empty = true is called on initialize
70
80
  # @param [String] name what to register this matcher as
71
81
  # @return [void]
72
- def register_as name
82
+ def register_as name, options = {}
73
83
  s = self
74
84
  m = Module.new do
75
- define_method name do |*args, &block|
76
- s.new(*args, &block)
85
+ define_method name do |expected = UNDEFINED, *args, &block|
86
+ s.new(expected, options, *args, &block)
77
87
  end
78
88
  end
79
89
 
@@ -87,9 +97,14 @@ module RSpec
87
97
  # Hides RSpec internal api
88
98
  def matches? actual
89
99
  self.actual = actual
90
- return match if method(:match).arity == 0
91
100
 
92
- match actual
101
+ catch(:resolution) do
102
+ if method(:match).arity == 0
103
+ match
104
+ else
105
+ match actual
106
+ end
107
+ end
93
108
  end
94
109
 
95
110
  # @method actual
@@ -113,9 +128,10 @@ module RSpec
113
128
  raise "not implemented"
114
129
  end
115
130
 
116
- # Describes what this matcher does for composable matchers.
131
+ # Describes what this matcher does.
117
132
  # @example be an string with X length
118
133
  # @example match X regex
134
+ # @note for composable matchers
119
135
  # @note raises by default
120
136
  # @return [String]
121
137
  def description
@@ -154,5 +170,23 @@ module RSpec
154
170
  def supports_block_expectations?
155
171
  false
156
172
  end
173
+
174
+ private
175
+
176
+ # @api public
177
+ # Stops evaluation and tells RSpec there was a match.
178
+ # @throw :resolution
179
+ # @return [void]
180
+ def resolve_expectation
181
+ throw :resolution, true
182
+ end
183
+
184
+ # @api public
185
+ # Stops evaluation and tells RSpec there wasn't a match.
186
+ # @throw :resolution
187
+ # @return [void]
188
+ def reject_expectation
189
+ throw :resolution, false
190
+ end
157
191
  end
158
192
  end
@@ -12,7 +12,7 @@ module RSpec
12
12
  end
13
13
 
14
14
  def self.version
15
- "0.1.1"
15
+ "0.1.2"
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.1
4
+ version: 0.1.2
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-07 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport