mocoso 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -3
  3. data/lib/mocoso.rb +19 -15
  4. data/mocoso.gemspec +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76a80a460d924893db612381bac7a81d3ffaa1a2
4
- data.tar.gz: 289580d3fea0301109093fc70445777dd4712d75
3
+ metadata.gz: 28d0d3a0e008702420b77c694201274bee0f074f
4
+ data.tar.gz: 7fc938881701274f8170549426e908623283a3c2
5
5
  SHA512:
6
- metadata.gz: a965a66f88678883c46863c3d95f93887c476616e715853f1f903e41c3eff399b6060633bc657da45912b8702f3514946477ef29bc71732e814674f44ec20545
7
- data.tar.gz: 1a82908dfd0d84c0119adc7f2eb3ec93b85e7f9cf6d8b05448325e493792beec2ab33f5f59f5f09095e96cfe754f9fc6c1286506fe5fd7cb11d58b4111d2ff2c
6
+ metadata.gz: 75c5b235d40842390adbf5f00ffbb7c0606a92352a5a0f8dcb1ba47a2ca00de81f55f64a8319e27f2e4b9a1f742a9e1f966e08d9cb14318066d3809e3154120d
7
+ data.tar.gz: ba1dfe75fc54f4ff04715a246d377a52009322234c83d42ebafb43fe5c2f890af5802d54f738734b422161340a67b3d63a56c0f87c06b41808a86efd04735b1c
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  Mocoso
2
2
  ======
3
3
 
4
- Yet Another Simple Stub & Mock library. This is stolen from tools such as
4
+ Yet Another Simple Stub & Mock library. This is inspired by (stolen from)
5
5
  [Minitest::Mock][minitest], [Override][override] and [Mocha][mocha].
6
6
 
7
- **Made in Peru.**
8
-
9
7
  Motivation
10
8
  ----------
11
9
 
@@ -42,6 +40,8 @@ A quick example (uses [Cutest][cutest]):
42
40
  expect User, :find, with: [1], returns: user do
43
41
  assert_equal user, User.find(1)
44
42
  end
43
+
44
+ assert_equal nil, User.find(1)
45
45
  end
46
46
 
47
47
  test 'stubbing an instance method' do
@@ -50,6 +50,8 @@ A quick example (uses [Cutest][cutest]):
50
50
  stub user, :valid?, true do
51
51
  assert user.valid?
52
52
  end
53
+
54
+ assert !user.valid?
53
55
  end
54
56
 
55
57
  Check [Official Documentation][docs] for more details.
@@ -26,19 +26,23 @@
26
26
  # expect User, :find, with: [1], returns: user do
27
27
  # assert_equal user, User.find(1)
28
28
  # end
29
+ #
30
+ # assert_equal nil, User.find(1)
29
31
  # end
30
32
  #
31
33
  # test 'stubbing an instance method' do
32
34
  # user = User.new
33
35
  #
34
- # stub user, valid?: true do
36
+ # stub user, :valid?, true do
35
37
  # assert user.valid?
36
38
  # end
39
+ #
40
+ # assert !user.valid?
37
41
  # end
38
42
  #
39
43
  # Note: this example uses the test framework Cutest[1]:
40
44
  #
41
- # Mocoso is stolen from Override[2], Minitest::Mock[3] and Mocha[4].
45
+ # Mocoso is inspired by (stolen from) Override[2], Minitest::Mock[3] and Mocha[4].
42
46
  #
43
47
  # * [1]: https://github.com/djanowski/cutest/
44
48
  # * [2]: https://github.com/soveran/override/
@@ -46,15 +50,6 @@
46
50
  # * [4]: https://github.com/freerange/mocha/
47
51
  #
48
52
  module Mocoso
49
- # Raised by #expect when a expectation is not fulfilled.
50
- #
51
- # Mocoso.expect object, :method, with: 'argument', returns: nil do
52
- # object.method 'unexpected argument'
53
- # # => Mocoso::ExpectationError: Expected ["argument"], got ["unexpected argument"]
54
- # end
55
- #
56
- ExpectationError = Class.new StandardError
57
-
58
53
  # Rewrites each method from +methods+ and defined in +object+. +methods+ is a
59
54
  # Hash that represents stubbed method name symbols as keys and corresponding
60
55
  # return values as values. The methods are restored after the given +block+
@@ -83,7 +78,7 @@ module Mocoso
83
78
  original = object.method method
84
79
 
85
80
  metaclass.send :define_method, method do |*args|
86
- result.respond_to?(:call) ? result.call(*args) : result
81
+ result.respond_to?(:call) ? result.(*args) : result
87
82
  end
88
83
 
89
84
  yield
@@ -92,7 +87,7 @@ module Mocoso
92
87
  metaclass.send :define_method, method, original
93
88
  end
94
89
 
95
- # Expect that method +method+ is called with the arguments specified in the
90
+ # Expects that method +method+ is called with the arguments specified in the
96
91
  # +:with+ option (defaults to +[]+ if it's not given) and returns the value
97
92
  # specified in the +:returns+ option. If expectations are not met, it raises
98
93
  # Mocoso::ExpectationError error. It uses #stub internally, so it will restore
@@ -113,11 +108,20 @@ module Mocoso
113
108
  #
114
109
  def expect object, method, options, &block
115
110
  expectation = -> *params {
116
- with = options.fetch(:with) { [] }
111
+ with = options.fetch :with, []
117
112
  raise ExpectationError, "Expected #{with}, got #{params}" if params != with
118
- options.fetch(:returns)
113
+ options.fetch :returns
119
114
  }
120
115
 
121
116
  stub object, method, expectation, &block
122
117
  end
118
+
119
+ # Raised by #expect when a expectation is not fulfilled.
120
+ #
121
+ # Mocoso.expect object, :method, with: 'argument', returns: nil do
122
+ # object.method 'unexpected argument'
123
+ # # => Mocoso::ExpectationError: Expected ["argument"], got ["unexpected argument"]
124
+ # end
125
+ #
126
+ ExpectationError = Class.new StandardError
123
127
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'mocoso'
5
- s.version = '1.1.0'
5
+ s.version = '1.1.1'
6
6
  s.summary = 'A simple stub & mock library'
7
7
  s.description = s.summary
8
8
  s.authors = ['Francesco Rodríguez']
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: 1.1.0
4
+ version: 1.1.1
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-14 00:00:00.000000000 Z
11
+ date: 2013-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest