muack 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9ba1c6a1c4f4eb8a2a2899c4a140aaf344c0d4b
4
- data.tar.gz: e258c9b2c1351d7ab3e3d11c40855f07d5791893
3
+ metadata.gz: f1c224f1dd6be101ec8dada7a46d3df32f788d82
4
+ data.tar.gz: cc3f213b4d737ecea14fb3492467c985dcbbe685
5
5
  SHA512:
6
- metadata.gz: e3b9ee3b07c99e2a7522086045d7e1eaec8f90b989c8bd3113ad963c98d4735a14b6cfee956156802963fd75ec723559bfeff91b95dd578998c49b67de8ce78a
7
- data.tar.gz: 0db81e2e647e106f5173436caf64ebc5aa321089068263b64e6dc4b627d28edb730841c1b75406bbbb838da6eeaa86d6399078ff3e7092bf6b243d6f757e02a4
6
+ metadata.gz: 690163afe7968b15fde073e447d54604a20c431645fc56fd56e8fa5f52f1ea0d10bdec7e92ebb78c2b3a38c6291d79c242f49aec6744a7a2639c1abf44e52c90
7
+ data.tar.gz: 9b4ff0d87fd84b0f76b17983f1e2524fa60d435b5ad48c87f593dbde6c2fc0d5dead257beac7147bad5a37def75dd567c145dc07ab9760ed2310b3ebdaf356ad
data/CHANGES.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # CHANGES
2
2
 
3
+ ## Muack 1.1.0 -- 2014-04-17
4
+
5
+ Improvements:
6
+
7
+ * Now we show "Unexpected call" instead of "Expected ... was not called".
8
+ This should make it easier to read and understand.
9
+
10
+ Incompatible changes:
11
+
12
+ * Previously, if you're using a spy, it would examine all the messages for
13
+ the given stub. However this might not be desired as then we need to
14
+ specify everything in the stub for the say. Tedious. From now on, spies
15
+ would only examine specified messages, ignoring unspecified stubbed
16
+ methods. This sort of breaks the concept that "mocks = stubs + spies"
17
+ as spies would not fully examine the stubs now. It's now more like:
18
+ "mocks >= stubs + spies".
19
+
3
20
  ## Muack 1.0.4 -- 2014-03-29
4
21
 
5
22
  * Now we could `Muack.verify(obj)` or `Muack.reset(obj)` a single object.
data/README.md CHANGED
@@ -25,7 +25,7 @@ Muack is much simpler and thus much faster and much more consistent.
25
25
 
26
26
  ## REQUIREMENTS:
27
27
 
28
- * Tested with MRI (official CRuby) 2.0.0, 2.1.0, Rubinius and JRuby.
28
+ * Tested with MRI (official CRuby), Rubinius and JRuby.
29
29
 
30
30
  ## INSTALLATION:
31
31
 
@@ -77,9 +77,10 @@ There are also 3 different kinds of mocks in Muack, which are:
77
77
  * Stubs
78
78
  * Spies
79
79
 
80
- You could also think of _mocks_ are _stubs_ + _spies_. Here's the equation:
80
+ You could think of _mocks_ are sort of _stubs_ combined with _spies_. Here's
81
+ the inequation:
81
82
 
82
- mock = stub + spy
83
+ mock >= stub + spy
83
84
 
84
85
  Stubs help us inject methods into the objects we want to observe. Spies
85
86
  help us observe the behaviours of the objects. As for mocks, they inject
@@ -113,13 +114,21 @@ or not, but sometimes we do care. With stubs and spies, we could always put
113
114
  stubs in the before/setup block, and only when we really care if they are
114
115
  called or not, we put spies to examine.
115
116
 
116
- On the other hand, stubs aren't limited to testing. If we want to monkey
117
- patching something, stubs could be useful as we don't care how many times
118
- the injected methods are called. Jump to _Muack as a mocky patching library_
119
- section for more detail.
117
+ The other difference is that, spies could partially verify the corresponding
118
+ stubs, but not necessarily completely as mocks. For example, we could stub
119
+ two methods, but only verify one of them with a spy.
120
120
 
121
- Note that you could also mix mocks and stubs for a given object.
122
- Here's an example:
121
+ ``` ruby
122
+ obj = Object.new
123
+ stub(obj).name{ 'obj' }
124
+ stub(obj).id { 12345 }
125
+ p obj.name # 'obj'
126
+ p obj.id # 12345
127
+ spy(obj).name
128
+ p Muack.verify # true
129
+ ```
130
+
131
+ This is similar as mixing mocks and stubs, as in the following example:
123
132
 
124
133
  ``` ruby
125
134
  obj = Object.new
@@ -133,6 +142,11 @@ p Muack.verify # true
133
142
  However you should not mix mocks and stubs with the same method, or you
134
143
  might encounter some unexpected result. Jump to _Caveat_ for more detail.
135
144
 
145
+ On the other hand, stubs aren't limited to testing. If we want to monkey
146
+ patching something, stubs could be useful as we don't care how many times
147
+ the injected methods are called. Jump to _Muack as a mocky patching library_
148
+ section for more detail.
149
+
136
150
  ### reset and verify
137
151
 
138
152
  Calling `Muack.reset` is essentially resetting all mocks, returning all
data/lib/muack/failure.rb CHANGED
@@ -16,7 +16,7 @@ module Muack
16
16
  @was = "#{obj.inspect}.#{msg}(" \
17
17
  "#{args.map(&:inspect).join(', ')})"
18
18
  if expected_defis.empty?
19
- super("\nExpected: #{@was}\n was not called.")
19
+ super("\nUnexpected call: #{@was}")
20
20
  else
21
21
  build_expected(obj, expected_defis)
22
22
  super("\nExpected: #{expected}\n but was: #{was}")
data/lib/muack/spy.rb CHANGED
@@ -10,7 +10,9 @@ module Muack
10
10
 
11
11
  # used for Muack::Session#verify
12
12
  def __mock_verify
13
- @secret.each{ |defi| __mock_dispatch(defi.msg, defi.args) }
13
+ @secret.each do |defi|
14
+ __mock_dispatch(defi.msg, defi.args) if __mock_defis.key?(defi.msg)
15
+ end
14
16
  super # simulate dispatching before passing to mock to verify
15
17
  end
16
18
 
data/lib/muack/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Muack
3
- VERSION = '1.0.4'
3
+ VERSION = '1.1.0'
4
4
  end
data/muack.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: muack 1.0.4 ruby lib
2
+ # stub: muack 1.1.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "muack"
6
- s.version = "1.0.4"
6
+ s.version = "1.1.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Lin Jen-Shin (godfat)"]
11
- s.date = "2014-03-29"
11
+ s.date = "2014-04-17"
12
12
  s.description = "Muack -- A fast, small, yet powerful mocking library.\n\nInspired by [RR][], and it's 32x times faster (750s vs 23s) than RR\nfor running [Rib][] tests.\n\n[RR]: https://github.com/rr/rr\n[Rib]: https://github.com/godfat/rib"
13
13
  s.email = ["godfat (XD) godfat.org"]
14
14
  s.files = [
data/test/test_mock.rb CHANGED
@@ -160,7 +160,7 @@ describe Muack::Mock do
160
160
  rescue Muack::Unexpected => e
161
161
  e.expected.should.eq nil
162
162
  e.was .should.eq 'obj.say()'
163
- e.message .should.start_with "\nExpected: #{e.was}\n"
163
+ e.message .should.eq "\nUnexpected call: #{e.was}"
164
164
  end
165
165
  end
166
166
 
@@ -172,7 +172,7 @@ describe Muack::Mock do
172
172
  rescue Muack::Unexpected => e
173
173
  e.expected.should.eq nil
174
174
  e.was .should.eq 'obj.say(true)'
175
- e.message .should.start_with "\nExpected: #{e.was}\n"
175
+ e.message .should.eq "\nUnexpected call: #{e.was}"
176
176
  end
177
177
  end
178
178
 
data/test/test_stub.rb CHANGED
@@ -47,13 +47,13 @@ describe Muack::Stub do
47
47
  should 'work with spy' do
48
48
  stub(Obj).say{0}
49
49
  Obj.say.should.eq 0
50
- spy(Obj).say
50
+ spy(Obj).say
51
51
  end
52
52
 
53
53
  should 'work with spy twice' do
54
54
  stub(Obj).say{}
55
55
  2.times{ Obj.say.should.eq nil }
56
- spy(Obj).say.times(2)
56
+ spy(Obj).say.times(2)
57
57
  end
58
58
 
59
59
  should 'work with spy spy' do
@@ -65,13 +65,21 @@ describe Muack::Stub do
65
65
  should 'verify spy arguments' do
66
66
  stub(Obj).say(1){|a|a}
67
67
  Obj.say(1).should.eq 1
68
- spy( Obj).say(1)
68
+ spy(Obj).say(1)
69
69
  end
70
70
 
71
71
  should 'properly verify spy arguments' do
72
72
  stub(Obj).say(is_a(String)){|a|a}
73
73
  Obj.say('Hi!').should.eq 'Hi!'
74
- spy( Obj).say(is_a(String))
74
+ spy(Obj).say(is_a(String))
75
+ end
76
+
77
+ should 'ignore messages spies not interested' do
78
+ stub(Obj).saya{0}
79
+ stub(Obj).sayb{1}
80
+ Obj.saya.should.eq 0
81
+ Obj.sayb.should.eq 1
82
+ spy(Obj).saya
75
83
  end
76
84
  end
77
85
 
@@ -108,7 +116,7 @@ describe Muack::Stub do
108
116
 
109
117
  should 'raise Expected if the spy is not satisfied' do
110
118
  stub(Obj).say{}
111
- spy( Obj).say
119
+ spy(Obj).say
112
120
  begin
113
121
  Muack.verify
114
122
  'never'.should.eq 'reach'
@@ -124,7 +132,7 @@ describe Muack::Stub do
124
132
  should 'raise Expected if the spy is not satisfied enough' do
125
133
  stub(Obj).say{}
126
134
  Obj.say
127
- spy( Obj).say(0)
135
+ spy(Obj).say(0)
128
136
  begin
129
137
  Muack.verify
130
138
  'never'.should.eq 'reach'
@@ -138,7 +146,7 @@ describe Muack::Stub do
138
146
  should 'show correct times for under satisfaction' do
139
147
  stub(Obj).say{}
140
148
  2.times{ Obj.say }
141
- spy( Obj).say.times(3)
149
+ spy(Obj).say.times(3)
142
150
  begin
143
151
  Muack.verify
144
152
  'never'.should.eq 'reach'
@@ -154,7 +162,7 @@ describe Muack::Stub do
154
162
  should 'show correct times for over satisfaction' do
155
163
  stub(Obj).say{}
156
164
  2.times{ Obj.say }
157
- spy( Obj).say
165
+ spy(Obj).say
158
166
  begin
159
167
  Muack.verify
160
168
  'never'.should.eq 'reach'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-29 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Muack -- A fast, small, yet powerful mocking library.