mocoso 0.1.1 → 0.1.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: 1283ed93b23af638c9a86fd990401f029dcfdd9b
4
- data.tar.gz: 72c029be3e9ef334de2629a1cf0a29a2ed371257
3
+ metadata.gz: 035dcbfe0eaab282c1c61619e0fc79ba30cbdf79
4
+ data.tar.gz: 80e2a9211e3259a74ac859aa42bded85b7fdf9f3
5
5
  SHA512:
6
- metadata.gz: f22f6a0dd4ae5a4eaaf2236d079f1e9035a34ad247cbb3a107c583f5a082390b5bdd16a0f66119e0c8b0d9ae412c36069795941897e57635189ff696a4692724
7
- data.tar.gz: b24cf1f6dd2ef4e4177b63e11e845cb89914942ed5e4b3f2b39a587eef3d47fa91fd9f6b88abcbff212ea6bc86e95c5107b3dcfae260a35a89f31841c0ff07c2
6
+ metadata.gz: f2a16d9f8df3110a1096a1de5ab7d5af509cad145ff98e53ba2945d5b2d4613efed33f06ce277ac952f06fb01657f20339c17dd62a6c82e0d6841ac61fc9f751
7
+ data.tar.gz: 9ca6b09b6ac4e72432ae10b8a3a4ac40644f33704eb8ff52b2b21f6fc04fd133ce275fb2d50ec1a447b257d233d522471f30bdee21b868cfc16a4c0098e54c43
data/lib/mocoso.rb CHANGED
@@ -84,16 +84,22 @@ module Mocoso
84
84
  # Mocoso.stub Object.new, undefined: nil
85
85
  # # => NameError: undefined method `undefined' for class `Object'
86
86
  #
87
+ # The same thing happens if a stubbed method is not invoked:
88
+ #
89
+ # Mocoso.stub subject, :foo, 'value' do
90
+ # end
91
+ # # => Expected method foo not invoked
92
+ #
87
93
  def stub object, method, result, &block
88
94
  metaclass = object.singleton_class
89
95
  stubbed_method = "__mocoso_#{method}"
96
+ invoked = false
90
97
 
91
98
  metaclass.send :alias_method, stubbed_method, method
92
99
 
93
- if result.respond_to?(:call)
94
- metaclass.send(:define_method, method) { |*args| result.(*args) }
95
- else
96
- metaclass.send(:define_method, method) { result }
100
+ metaclass.send :define_method, method do |*args|
101
+ invoked = true
102
+ result.respond_to?(:call) ? result.call(*args) : result
97
103
  end
98
104
 
99
105
  begin
@@ -102,6 +108,7 @@ module Mocoso
102
108
  metaclass.send :undef_method, method
103
109
  metaclass.send :alias_method, method, stubbed_method
104
110
  metaclass.send :undef_method, stubbed_method
111
+ raise "Expected method #{method} not invoked" if !invoked
105
112
  end
106
113
  end
107
114
 
data/mocoso.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'mocoso'
5
- s.version = '0.1.1'
5
+ s.version = '0.1.2'
6
6
  s.summary = 'A simple stub & mock library'
7
7
  s.description = s.summary
8
8
  s.authors = ['Francesco Rodríguez']
@@ -80,3 +80,10 @@ test 'expectation with multiple arguments' do |subject|
80
80
  assert_equal 'new foo', subject.foo('new foo', optional: true)
81
81
  end
82
82
  end
83
+
84
+ test 'raises error if stubbed method is never invoked' do |subject|
85
+ assert_raise {
86
+ stub subject, :foo, 'value' do
87
+ end
88
+ }
89
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocoso
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
  - Francesco Rodríguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-08 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest