flexmock 2.0.1 → 2.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: 7d8010b82bdccec43f2038e9b3698387e952027a
4
- data.tar.gz: c034d8b46dec2354c06df15491213f1987d30309
3
+ metadata.gz: 98384ea13adbc6183d9341511891b3a9f8f03d45
4
+ data.tar.gz: 3590aed927dd2b5639cd89bc5ef4a94721cc019a
5
5
  SHA512:
6
- metadata.gz: f3bde508002be38eced12ee24efe4ad0092556da26930bbec98b3aed7a631035d84c943d01da70411d60085f2eb48ba8ca98584be2617f8f7f6cbd1d858acab2
7
- data.tar.gz: 69a04f543a8a55765c354e061a94f1234dbfe8dc3c3963e7beeeccba74c534226936a0a528e96793f1a0a2349a9ba9c86706085fe001a191a421dfe3ce2ef931
6
+ metadata.gz: 81593e3d1ac8834dfa7a2984a5673979b9a609cd2269711be7ddaa989f31542066bbec7a26b927f9d268a0880a332d26b7db70e642abac4aa24579cadc09c933
7
+ data.tar.gz: 157647079491431589151fd0a1297c7b78d8b179b73ff2e97fc2d7415cf3f8b25bf0985d5577b210490633291e83e2e4bdae57014ff2cc5140640ed28cb5f6bf
data/lib/flexmock/core.rb CHANGED
@@ -106,6 +106,8 @@ class FlexMock
106
106
 
107
107
  # Handle missing methods by attempting to look up a handler.
108
108
  def method_missing(sym, *args, &block)
109
+ FlexMock.verify_mocking_allowed!
110
+
109
111
  enhanced_args = block_given? ? args + [block] : args
110
112
  call_record = CallRecord.new(sym, enhanced_args, block_given?)
111
113
  @calls << call_record
@@ -48,6 +48,34 @@ class FlexMock
48
48
  container.flexmock_teardown
49
49
  end
50
50
 
51
+ FORBID_MOCKING = :__flexmock_forbid_mocking
52
+
53
+ # Forbid mock calls to happen while the block is being evaluated
54
+ #
55
+ # @param [Object] mocking_forbidden_return the return value that should be
56
+ # used if a mocking call has happened. If no mocking calls happened,
57
+ # returns the return value of the block
58
+ def forbid_mocking(mocking_forbidden_return = nil)
59
+ current, Thread.current[FORBID_MOCKING] =
60
+ Thread.current[FORBID_MOCKING], true
61
+
62
+ catch(FORBID_MOCKING) do
63
+ return yield
64
+ end
65
+ mocking_forbidden_return
66
+
67
+ ensure
68
+ Thread.current[FORBID_MOCKING] = current
69
+ end
70
+
71
+ # Verify that mocking is allowed in the current context. Throws if it is
72
+ # not.
73
+ def verify_mocking_allowed!
74
+ if Thread.current[FORBID_MOCKING]
75
+ throw FORBID_MOCKING
76
+ end
77
+ end
78
+
51
79
  # Class method to format a method name and argument list as a nice
52
80
  # looking string.
53
81
  def format_call(sym, args) # :nodoc:
@@ -58,7 +86,12 @@ class FlexMock
58
86
  # parenthesis).
59
87
  def format_args(args)
60
88
  if args
61
- args.collect { |a| a.inspect }.join(', ')
89
+ args = args.map do |a|
90
+ FlexMock.forbid_mocking("<recursive call to mocked method in #inspect>") do
91
+ a.inspect
92
+ end
93
+ end
94
+ args.join(', ')
62
95
  else
63
96
  "*args"
64
97
  end
@@ -39,8 +39,9 @@ class FlexMock
39
39
  exp = find_expectation(*args)
40
40
  call_record.expectation = exp if call_record
41
41
  FlexMock.check(
42
- "no matching handler found for " +
43
- FlexMock.format_call(@sym, args)) { !exp.nil? }
42
+ proc { "no matching handler found for " +
43
+ FlexMock.format_call(@sym, args) }
44
+ ) { !exp.nil? }
44
45
  returned_value = exp.verify_call(*args)
45
46
  returned_value
46
47
  end
@@ -313,6 +313,7 @@ class FlexMock
313
313
  else
314
314
  proxy_module_eval <<-EOD
315
315
  def #{method_name}(*args, &block)
316
+ FlexMock.verify_mocking_allowed!
316
317
  __flexmock_proxy.mock.#{method_name}(*args, &block)
317
318
  end
318
319
  EOD
@@ -3,7 +3,7 @@ class FlexMock
3
3
  module SpyDescribers
4
4
  def spy_description(spy, sym, args, options)
5
5
  result = "have received "
6
- result << call_description(sym, args)
6
+ result << FlexMock.format_call(sym, args)
7
7
  result << times_description(options[:times])
8
8
  result << block_description(options[:with_block])
9
9
  result
@@ -19,7 +19,7 @@ class FlexMock
19
19
 
20
20
  def describe_spy(spy, sym, args, options, not_clause="")
21
21
  result = "expected "
22
- result << call_description(sym, args)
22
+ result << FlexMock.format_call(sym, args)
23
23
  result << " to#{not_clause} be received by " << spy.inspect
24
24
  result << times_description(options[:times])
25
25
  result << block_description(options[:with_block])
@@ -44,7 +44,7 @@ class FlexMock
44
44
  def append_call_record(result, call_record)
45
45
  result <<
46
46
  " " <<
47
- call_description(call_record.method_name, call_record.args)
47
+ FlexMock.format_call(call_record.method_name, call_record.args)
48
48
  if call_record.expectation
49
49
  result <<
50
50
  " matched by " <<
@@ -79,13 +79,6 @@ class FlexMock
79
79
  end
80
80
  end
81
81
 
82
- def call_description(sym, args)
83
- if args
84
- "#{sym}(#{args.map { |o| o.inspect }.join(', ')})"
85
- else
86
- "#{sym}(...)"
87
- end
88
- end
89
82
  extend SpyDescribers
90
83
  end
91
84
 
@@ -1,3 +1,3 @@
1
1
  class FlexMock
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-24 00:00:00.000000000 Z
12
+ date: 2015-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -176,3 +176,4 @@ signing_key:
176
176
  specification_version: 4
177
177
  summary: Simple and Flexible Mock Objects for Testing
178
178
  test_files: []
179
+ has_rdoc: