xspec 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c981df6d76e0ee48d3cea0ebbe598d88e173c6ce
4
- data.tar.gz: 632dd6c9e7230c07d1edd1d4eac07127ae807b8b
3
+ metadata.gz: 43babe397ea759864cca9b9cf9f7b3f85574df64
4
+ data.tar.gz: 9bb1e2521e47fd442469f79c15f5ac0bb785a010
5
5
  SHA512:
6
- metadata.gz: 1c344141ce89c73cb27b7a7f365368f3dc79329f2d06e404397033a277bbff0fd7d8608d5d4f30e31011dc3cbface6917e7c4bf9e17d8f7d915d5700561455f8
7
- data.tar.gz: 2dd80e45854d14ea0ff1247469d27fda60fc73d0e07b8db7c60e2461d483496cb28f7d06d386a968cddfc673efba5a78e02e2471b7fc33a6152df75cfe05b1ee
6
+ metadata.gz: 4a3278a29ac464e56907888124acf872c5151282718286ee141cd57e933e2b28e15d817c81e20b1a5f29199b2097ba962264190d7df44b604ab974ddfed3e76f
7
+ data.tar.gz: 652428e1709ecb942d8e858f764489cf5681d40b8b09e4061c9b2814a93f956ddc8df5d48b39fc382b6ec755f455a2c3df8fb4fcf7f93bea7aebdd10b808fb3d
data/README.md CHANGED
@@ -138,4 +138,4 @@ Talk to me before embarking on anything large. Tests are written in XSpec,
138
138
  which might do your head in:
139
139
 
140
140
  bundle install
141
- bundle exec bin/run-specs
141
+ bin/test
@@ -162,16 +162,23 @@ EOS
162
162
  # is desired, it can be supplied as a block, for example:
163
163
  # `expect(double).some_method(1, 2) { "return value" }`
164
164
  def expect(obj)
165
- Recorder.new(obj)
165
+ Recorder.new(obj, :_expect)
166
+ end
167
+
168
+ # An allowed method will never be validated by `assert_exhausted`.
169
+ # Matching expectations are always given precendence to allows.
170
+ def allow(obj)
171
+ Recorder.new(obj, :_allow)
166
172
  end
167
173
 
168
174
  class Recorder
169
- def initialize(double)
175
+ def initialize(double, method)
170
176
  @double = double
177
+ @method = method
171
178
  end
172
179
 
173
180
  def method_missing(*args, &ret)
174
- @double._expect(args, &(ret || ->{}))
181
+ @double.__send__(@method, args, &(ret || ->{}))
175
182
  end
176
183
  end
177
184
 
@@ -183,15 +190,24 @@ EOS
183
190
  def initialize(klass)
184
191
  @klass = klass
185
192
  @expected = []
193
+ @allowed = []
186
194
  end
187
195
 
188
196
  def method_missing(*actual_args)
189
- i = @expected.find_index {|expected_args, ret|
197
+ expected_index = @expected.find_index {|expected_args, ret|
190
198
  expected_args == actual_args
191
199
  }
192
200
 
193
- if i
194
- @expected.delete_at(i)[1].call
201
+ matching_message = if expected_index
202
+ @expected.delete_at(expected_index)
203
+ else
204
+ @allowed.detect {|expected_args, ret|
205
+ expected_args == actual_args
206
+ }
207
+ end
208
+
209
+ if matching_message
210
+ matching_message[1].call
195
211
  else
196
212
  name, rest = *actual_args
197
213
  ::Kernel.raise DoubleFailure, "Unexpectedly received: %s(%s)" % [
@@ -201,7 +217,7 @@ EOS
201
217
  end
202
218
  end
203
219
 
204
- # The two methods needed on this object to set it up and verify it are
220
+ # The methods needed on this object to set it up and verify it are
205
221
  # prefixed by `_` to try to ensure they don't clash with any method
206
222
  # expectations. While not fail-safe, users should only be using
207
223
  # expectations for a public API, and `_` is traditionally only used
@@ -212,6 +228,12 @@ EOS
212
228
  @expected << [args, ret]
213
229
  end
214
230
 
231
+ def _allow(args, &ret)
232
+ @klass.validate_call! args
233
+
234
+ @allowed << [args, ret]
235
+ end
236
+
215
237
  def _verify
216
238
  return if @expected.empty?
217
239
 
@@ -116,6 +116,8 @@ module XSpec
116
116
  ]
117
117
  end
118
118
  out.puts
119
+
120
+ true
119
121
  end
120
122
 
121
123
  private
@@ -88,6 +88,26 @@ describe 'doubles assertion context' do
88
88
  assert_include 'foo(1, "abc")', e.message
89
89
  end
90
90
  end
91
+
92
+ it 'does not raise on uncalled allows' do
93
+ assert subject.instance_eval {
94
+ double = instance_double('Bogus')
95
+ allow(double).foo
96
+ assert_exhausted double
97
+ true
98
+ }
99
+ end
100
+
101
+ it 'gives precendence to expect' do
102
+ assert_equal 1, subject.instance_eval {
103
+ double = instance_double('Bogus')
104
+ allow(double).foo
105
+ expect(double).foo { 1 }
106
+ ret = double.foo
107
+ assert_exhausted double
108
+ ret
109
+ }
110
+ end
91
111
  end
92
112
 
93
113
  describe 'instance_double' do
@@ -154,6 +154,16 @@ describe 'null notifier' do
154
154
  it_behaves_like_a ComposableNotifier
155
155
  end
156
156
 
157
+ describe 'timings at end' do
158
+ let(:notifier) { XSpec::Notifier::TimingsAtEnd.new }
159
+
160
+ it 'always returns true' do
161
+ assert notifier.run_finish
162
+ end
163
+
164
+ it_behaves_like_a ComposableNotifier
165
+ end
166
+
157
167
  def make_nested_test(parent_names = [], work_name = nil)
158
168
  XSpec::NestedUnitOfWork.new(
159
169
  parent_names.map {|name| XSpec::Context.make(name, Module.new) },
data/xspec.gemspec CHANGED
@@ -22,6 +22,6 @@ Gem::Specification.new do |gem|
22
22
  gem.bindir = "bin"
23
23
  gem.executables << "xspec"
24
24
  gem.license = "Apache 2.0"
25
- gem.version = "0.0.1"
25
+ gem.version = "0.0.2"
26
26
  gem.has_rdoc = false
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Shay