expect-call 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/expect-call.rb +20 -9
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8665a08b1332f778b203b8bcf996d40083dc1a44
4
- data.tar.gz: 387a04a8b8425c60c60b4e272dc66ad1fcd5aa81
3
+ metadata.gz: 828a763f2d8a6509e9a3a131bf549c630e73a41b
4
+ data.tar.gz: da8ecd4f4de5039b7fb4e3ec9df07ad94f46df6d
5
5
  SHA512:
6
- metadata.gz: 382dbd8558701953311cd43453319f658c131bfb72974e6c6b1b268028274f2f5945494f646fd5c42292a2d45dca4834f2e448f09ffe22b958b608e10c241ade
7
- data.tar.gz: 74f537b8c609cb01b39ea4e8aec6c308383b042edc28edb47dfa7c6bd17af7d06c283b068d74117e915baf7fe32df63fb1c7c467eea03ac200cf4e4b00ef864b
6
+ metadata.gz: 56bdb1316712b767db2676c7d0bd396ea423af528cb483ad0e4480658762301ec49f321414e12b94f841724ae9b9a8afa32c33d53fd6c4a53266059e4c69244c
7
+ data.tar.gz: d86c1926656c5834bf83f962baab2d08a969b1f8c9fafb5c12c1e96f03fbb29b9f8ecea42c5aacd314b76d12d00f3c99294773f799f825c95625e13b92364158
data/lib/expect-call.rb CHANGED
@@ -1,15 +1,23 @@
1
1
  class Object
2
- #
3
- # Partial mocking.
4
- # Stubs a regular object and expects a specific call on it.
5
- #
6
2
  def expect_call( method_name, params, val_or_callable, &block )
7
- assert_method = block.binding.eval( 'self' ).method( :assert )
3
+ context = block.binding.eval( 'self' )
4
+
5
+ if context.respond_to?( :assert )
6
+ assert_method = context.method( :assert )
7
+ else
8
+ assert_method = Proc.new do |condition, message|
9
+ raise RuntimeError, "expect-call assertion\n#{ message }" unless condition
10
+ end
11
+ end
8
12
 
9
13
  metaclass = class << self; self; end
10
14
 
11
15
  orig_method = nil
12
- orig_method = method( method_name ) if respond_to? method_name
16
+
17
+ if respond_to? method_name
18
+ orig_method = method( method_name )
19
+ metaclass.send :undef_method, method_name
20
+ end
13
21
 
14
22
  clean_up = Proc.new do
15
23
  metaclass.send :undef_method, method_name
@@ -24,8 +32,11 @@ class Object
24
32
  was_called = true
25
33
  clean_up.call
26
34
 
27
- assert_method.call params == args,
28
- "Params do not match\n Expected: %s\n Actual: %s" % [ params.inspect, args.inspect ]
35
+ assert_method.call params == args, <<-MSG % [ method_name, params.inspect, args.inspect ]
36
+ Method '%s' called with unexpected arguments
37
+ Expected: %s
38
+ Actual: %s
39
+ MSG
29
40
 
30
41
  if val_or_callable.respond_to?( :call )
31
42
  return val_or_callable.call( *args )
@@ -38,7 +49,7 @@ class Object
38
49
 
39
50
  yield
40
51
 
41
- assert_method.call was_called, "Was not called: #{ method_name }"
52
+ assert_method.call was_called, "Method '%s' was not called" % [ method_name ]
42
53
  ensure
43
54
  clean_up.call unless was_called
44
55
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expect-call
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Shubin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Stubs a regular object's method and expects a specific call to it.
13
+ description: Stubs a regular object's method and expects a certain call to it.
14
14
  email: andrey.shubin@gmail.com
15
15
  executables: []
16
16
  extensions: []