flexmock 2.0.6 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33bb2c48e90a98ffbe177d885fdedd82aa7c7fc8
4
- data.tar.gz: 2c6dfcfac4032dd6fdd3110c204f5c91939e4104
3
+ metadata.gz: 13e2dc8c4ffe7a4747a9ee08ee54ab70a9c48b1c
4
+ data.tar.gz: 71aea49728f74c048c92a37a000288ef381ea0f0
5
5
  SHA512:
6
- metadata.gz: 74fdc213dda95788d74cfd973f2f7309611d0b21838c309d2c86a8013660f42057685d7f198498ff878f6fae34e3e4e3b27886ff5eb6e36a771bdfcca4e291fe
7
- data.tar.gz: 558319ae76251ca95e1eaedd13114ecf77540e95160700595a01a07f86cb027cc84b4c64317518ae7a189b18431343d55254204756e87d91943df2c6913c34fb
6
+ metadata.gz: 445fe45046e1ebea766c096ddfcf1aa31eabe3b166efd1027523deca681f6bec19d4c5cda8cd5e8d3af259839e25b04951ca2bca1a4ef65951c20f97d4ef9f1b
7
+ data.tar.gz: 3d20d7e3ea5caf5052236e109fbcf31178154467a28b42362a63a8cec7ff9a94655ea72ee6a673719400b79a4a61d1aac3a342d2235c8016eaf0c1dfb600b107
data/README.md CHANGED
@@ -16,6 +16,20 @@ You can install FlexMock with the following command.
16
16
  $ gem install flexmock
17
17
  ```
18
18
 
19
+ ## Changes
20
+
21
+ Only significant changes (new APIs, deprecated APIs or backward-compatible
22
+ changes) are documented here, a.k.a. minor or major version bumps. If you want a
23
+ detailed changelog, go over the commit log in github (it's pretty low-traffic)
24
+
25
+ 2.1.0:
26
+
27
+ - added `#and_iterates` to fix some shortcomings of `#and_yield` without
28
+ breaking backward compatibility
29
+ - strict partial mocks (and "based mocks" if `FlexMock.partials_are_based` is
30
+ set to true) are now based on the object's singleton class, instead of its
31
+ class.
32
+
19
33
  ## Simple Example
20
34
 
21
35
  We have a data acquisition class (<code>TemperatureSampler</code>)
@@ -572,6 +586,15 @@ determining whether a given expectation matches or not.
572
586
 
573
587
  Alias for `and_yield( ... )`.
574
588
 
589
+ * <b>and_iterates(<em>value1</em>, <em>value2></em>, ...)</b>
590
+
591
+ Declares that the mocked method will receive a block, and the mock
592
+ will iterate over the values given, calling the block once for each
593
+ value. Not providing a block will be an error. Providing more than one
594
+ `and_iterates` or `and_yield` clause one a single expectation will mean
595
+ that subsquent mock method calls will yield the values provided by the
596
+ additional `and_iterates`/`and_yield` clause.
597
+
575
598
  * <b>pass_thru</b>
576
599
  * <b>pass_thru { |<em>value</em>| .... }</b>
577
600
 
@@ -1,17 +1,13 @@
1
- # Detecting whether a class has a definition for a method or not
2
- # changes between Ruby 1.8 and Ruby 1.9. We introduce the
3
- # "flexmock_defined?" method on class objects to have a portable way
4
- # to determine that.
5
- #
6
- # NOTE: responds_to? isn't appropriate. We don't care if the object
7
- # responds to the method or not. We want to know if the class
8
- # has a definition for the method. A subtle difference.
9
- #
10
1
  class Class
11
-
12
- # Does a class directly define a method named "method_name"?
2
+ # Does a class directly defines an instance method named "method_name"?
3
+ #
4
+ # Unlike Ruby's Class#instance_methods or #method_defined?, it ignores methods
5
+ # that have been defined by flexmock's partial mock facility
13
6
  def flexmock_defined?(method_name)
14
- instance_methods.include?(method_name.flexmock_as_name)
7
+ ancestors.any? do |m|
8
+ methods = m.instance_methods(false)
9
+ next if methods.include?(:__flexmock_proxy) # This is a partial mock module
10
+ m.instance_methods(false).include?(method_name.flexmock_as_name)
11
+ end
15
12
  end
16
-
17
13
  end
@@ -116,7 +116,9 @@ class FlexMock
116
116
  block = args.last
117
117
  values = (@yield_queue.size == 1) ? @yield_queue.first : @yield_queue.shift
118
118
  if block && block.respond_to?(:call)
119
- @return_value = block.call(*values)
119
+ values.each do |v|
120
+ @return_value = block.call(*v)
121
+ end
120
122
  else
121
123
  fail MockError, "No Block given to mock with 'and_yield' expectation"
122
124
  end
@@ -251,10 +253,30 @@ class FlexMock
251
253
  # An error is raised if the mocked method is not called with a
252
254
  # block.
253
255
  def and_yield(*yield_values)
254
- @yield_queue << yield_values
256
+ @yield_queue << [yield_values]
255
257
  end
256
258
  alias :yields :and_yield
257
259
 
260
+ # Declare that the mocked method is expected to be given a block
261
+ # and that the block will iterate over the provided values.
262
+ # If the mock is called multiple times, mulitple
263
+ # <tt>and_iterates</tt> declarations can be used to supply different
264
+ # values on each call.
265
+ #
266
+ # The iteration is queued with the yield values provided with {#and_yield}.
267
+ #
268
+ # An error is raised if the mocked method is not called with a
269
+ # block.
270
+ #
271
+ # @example interaction of and_yield and and_iterates
272
+ # mock.should_receive(:each).and_yield(10).and_iterates(1, 2, 3).and_yield(20)
273
+ # mock.enum_for(:each).to_a # => [10]
274
+ # mock.enum_for(:each).to_a # => [1,2,3]
275
+ # mock.enum_for(:each).to_a # => [20]
276
+ #
277
+ def and_iterates(*yield_values)
278
+ @yield_queue << yield_values
279
+ end
258
280
 
259
281
  # :call-seq:
260
282
  # and_raise(an_exception)
@@ -95,7 +95,7 @@ class FlexMock
95
95
  # Set the base class if not defined and partials are based.
96
96
  def set_base_class(opts)
97
97
  if ! opts.base_class && opts.domain_obj && FlexMock.partials_are_based
98
- opts.base_class = opts.domain_obj.class
98
+ opts.base_class = opts.domain_obj.singleton_class
99
99
  end
100
100
  end
101
101
 
@@ -110,7 +110,7 @@ class FlexMock
110
110
  if !opts.domain_obj
111
111
  raise ArgumentError, "cannot use :strict outside a partial mock"
112
112
  end
113
- opts.base_class = opts.domain_obj.class
113
+ opts.base_class = opts.domain_obj.singleton_class
114
114
  else
115
115
  opts.base_class = args.shift
116
116
  end
@@ -1,3 +1,3 @@
1
1
  class FlexMock
2
- VERSION = "2.0.6"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,75 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
8
8
  - Sylvain Joyeux
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2016-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: minitest
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - ">="
19
18
  - !ruby/object:Gem::Version
20
19
  version: '0'
21
- type: :development
20
+ name: minitest
22
21
  prerelease: false
22
+ type: :development
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rake
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - ">="
33
32
  - !ruby/object:Gem::Version
34
33
  version: '0'
35
- type: :development
34
+ name: rake
36
35
  prerelease: false
36
+ type: :development
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: simplecov
44
43
  requirement: !ruby/object:Gem::Requirement
45
44
  requirements:
46
45
  - - ">="
47
46
  - !ruby/object:Gem::Version
48
47
  version: 0.11.0
49
- type: :development
48
+ name: simplecov
50
49
  prerelease: false
50
+ type: :development
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: 0.11.0
56
56
  - !ruby/object:Gem::Dependency
57
- name: coveralls
58
57
  requirement: !ruby/object:Gem::Requirement
59
58
  requirements:
60
59
  - - ">="
61
60
  - !ruby/object:Gem::Version
62
61
  version: '0'
63
- type: :development
62
+ name: coveralls
64
63
  prerelease: false
64
+ type: :development
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- description: "\n FlexMock is a extremely simple mock object class compatible\n
71
- \ with the Minitest framework. Although the FlexMock's\n interface is simple,
72
- it is very flexible.\n "
70
+ description: "\n FlexMock is a extremely simple mock object class compatible\n\
71
+ \ with the Minitest framework. Although the FlexMock's\n interface is simple,\
72
+ \ it is very flexible.\n "
73
73
  email: sylvain.joyeux@m4x.org
74
74
  executables: []
75
75
  extensions: []
@@ -169,7 +169,7 @@ homepage: https://github.com/doudou/flexmock
169
169
  licenses:
170
170
  - MIT
171
171
  metadata: {}
172
- post_install_message:
172
+ post_install_message:
173
173
  rdoc_options: []
174
174
  require_paths:
175
175
  - lib
@@ -184,10 +184,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0'
186
186
  requirements: []
187
- rubyforge_project:
188
- rubygems_version: 2.2.3
189
- signing_key:
187
+ rubyforge_project:
188
+ rubygems_version: 2.4.8
189
+ signing_key:
190
190
  specification_version: 4
191
191
  summary: Simple and Flexible Mock Objects for Testing
192
192
  test_files: []
193
- has_rdoc: