muack 1.1.2 → 1.2.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: fa29c09257f78580be72e3872fc7d3ef05650e02
4
- data.tar.gz: 222e4d730c838c6f76d701c0505b41f7b3476d1e
3
+ metadata.gz: 2536a6bd8291b8510a652b7e8102c44e4d204586
4
+ data.tar.gz: b4ad06b8093fa3f241145a5586c07feb37487bc2
5
5
  SHA512:
6
- metadata.gz: 3e539ea17a87076e48f85d980ad7e2c58afb91c8c627af09f05266a2811ecf2d22efb7adbc49f117c240ffca3c34a5e95229457ab2d82a7e8174a132aa17798e
7
- data.tar.gz: 3b2de41a40ab1134c0952ec763423a0a07b0967ce180b076e129ecde0063ddc05853e278cf6b5fb2d0bb36ecb7ac6d612f3471bd3abefa0ff69a8b79fe0660e4
6
+ metadata.gz: e6c120cfe1b64fe2aa6a842de612c49eb7ec04166a1ac083fdc69f44deb6093fdc5e21a651faed82f76de70b8b25f25a94071311e61ef3a7d8a09700b91019ee
7
+ data.tar.gz: 692d50e023c30fa16a1906b18233d9c25a32839617c6a5ef951a7056ffced8ed5ed6173b6913e8824605e34aa8e4c26fa6e6832539e1183053f849b5b15b4273
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  /pkg/
2
+ /coverage/
@@ -1,9 +1,11 @@
1
- before_install: 'git submodule update --init'
2
- script: 'ruby -r bundler/setup -S rake test'
3
1
 
2
+ language: ruby
4
3
  rvm:
5
- - 1.9
6
4
  - 2.0
7
5
  - 2.1
6
+ - 2.2
8
7
  - rbx-2
9
8
  - jruby
9
+
10
+ install: 'bundle install --retry=3'
11
+ script: 'ruby -r bundler/setup -S rake test'
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGES
2
2
 
3
+ ## Muack 1.2.0 -- 2015-03-10
4
+
5
+ * Now stubs could be overwritten. Input from @mz026
6
+
3
7
  ## Muack 1.1.2 -- 2014-11-07
4
8
 
5
9
  * Introduced `Muack::API.coat`.
data/Gemfile CHANGED
@@ -6,6 +6,9 @@ gemspec
6
6
  gem 'rake'
7
7
  gem 'pork'
8
8
 
9
+ gem 'simplecov', :require => false if ENV['COV']
10
+ gem 'coveralls', :require => false if ENV['CI']
11
+
9
12
  platform :rbx do
10
13
  gem 'rubysl-singleton' # used in rake
11
14
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Muack [![Build Status](https://secure.travis-ci.org/godfat/muack.png?branch=master)](http://travis-ci.org/godfat/muack)
1
+ # Muack [![Build Status](https://secure.travis-ci.org/godfat/muack.png?branch=master)](http://travis-ci.org/godfat/muack) [![Coverage Status](https://coveralls.io/repos/godfat/muack/badge.png?branch=master)](https://coveralls.io/r/godfat/muack?branch=master)
2
2
 
3
3
  by Lin Jen-Shin ([godfat](http://godfat.org))
4
4
 
@@ -461,8 +461,8 @@ p obj.name # 2
461
461
  p Muack.verify # true
462
462
  ```
463
463
 
464
- Note that this does not apply to stubs because stubs never run out, thus
465
- making stubs defined later have no effects at all.
464
+ Note that this does not apply to stubs because stubs never run out. Instead,
465
+ the latter stub would overwrite the previous one.
466
466
 
467
467
  ``` ruby
468
468
  obj = Object.new
@@ -471,9 +471,9 @@ stub(obj) do |m|
471
471
  m.name{ 1 }
472
472
  m.name{ 2 }
473
473
  end
474
- p obj.name # 0
475
- p obj.name # 0
476
- p obj.name # 0
474
+ p obj.name # 2
475
+ p obj.name # 2
476
+ p obj.name # 2
477
477
  p Muack.verify # true
478
478
  ```
479
479
 
@@ -1078,6 +1078,38 @@ verifiers details.
1078
1078
  [dm-core]: https://github.com/datamapper/dm-core
1079
1079
  [ruby-lint]: https://github.com/YorickPeterse/ruby-lint
1080
1080
 
1081
+ #### Why didn't mocks nor stubs check if the injected method exists before?
1082
+
1083
+ Long story short. I can't find a set of good APIs along with good
1084
+ implementation. My ideal APIs would be that for mocks and stubs, they
1085
+ do check if the injected methods exist before, and if we don't want
1086
+ that check, we use `fake` instead of `mock` or `stub`.
1087
+
1088
+ However, how do we specify if `fake` should act like `mock` or `stub`?
1089
+ Introducing yet another name would make the terms even more confusing
1090
+ (which are already fairly confusing!), and I don't want something like:
1091
+ `fake.mock` or `mock.fake` or `fake_mock` or `mock_fake`. Using an option
1092
+ would also raise the other questions.
1093
+
1094
+ What if we make `mock.with_any_times` work exactly like `stub` then?
1095
+ Then we could have `fake.with_any_times` and that would be the stub
1096
+ version of fake. This should greatly reduce the complexity and confusion.
1097
+ However this won't work well because stub is not just mock without times.
1098
+ They are different in:
1099
+
1100
+ * Mocked methods are called in FIFO (queue) order
1101
+ * Stubbed methods are called in FILO (stack) order
1102
+ * Stubbed methods could do some pattern matching
1103
+
1104
+ Of course we could break them though, but do we really have to, just for
1105
+ this simple feature? Also, it could be pretty challenging to implement
1106
+ existing method checking for `any_instance_of`.
1107
+
1108
+ If you could find a good set of APIs while implementing it nicely, please
1109
+ do let me know. Compatibility is not an issue. We could always bump the
1110
+ major number to inform this incompatibility. I am open to breaking legacy.
1111
+ Or, I am happy to break legacy.
1112
+
1081
1113
  ## USERS:
1082
1114
 
1083
1115
  * [Rib][]
@@ -1092,7 +1124,7 @@ verifiers details.
1092
1124
 
1093
1125
  Apache License 2.0
1094
1126
 
1095
- Copyright (c) 2013-2014, Lin Jen-Shin (godfat)
1127
+ Copyright (c) 2013-2015, Lin Jen-Shin (godfat)
1096
1128
 
1097
1129
  Licensed under the Apache License, Version 2.0 (the "License");
1098
1130
  you may not use this file except in compliance with the License.
@@ -181,7 +181,7 @@ module Muack
181
181
  # used for __mock_dispatch_call
182
182
  def __mock_block_call context, block, actual_args, actual_block, splat
183
183
  return unless block
184
- # for AnyInstanceOf, we don't have actually context at the time
184
+ # for AnyInstanceOf, we don't have the actual context at the time
185
185
  # we're defining it, so we update it here
186
186
  block.context = context if block.kind_of?(Block)
187
187
  if splat
@@ -6,6 +6,13 @@ module Muack
6
6
  # used for Muack::Session#verify
7
7
  def __mock_verify; true; end
8
8
 
9
+ # used for Muack::Modifier#times
10
+ def __mock_defis_push defi
11
+ # since stubs never wear out, the reverse ordering would make more sense
12
+ # so that the latter wins over the previous one (overwrite)
13
+ __mock_defis[defi.msg].unshift(defi)
14
+ end
15
+
9
16
  # used for mocked object to dispatch mocked method
10
17
  def __mock_dispatch msg, actual_args
11
18
  if defi = __mock_defis[msg].find{ |d|
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Muack
3
- VERSION = '1.1.2'
3
+ VERSION = '1.2.0'
4
4
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: muack 1.1.2 ruby lib
2
+ # stub: muack 1.2.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "muack"
6
- s.version = "1.1.2"
6
+ s.version = "1.2.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-11-07"
11
+ s.date = "2015-03-10"
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 = [
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
48
48
  "test/test_stub.rb"]
49
49
  s.homepage = "https://github.com/godfat/muack"
50
50
  s.licenses = ["Apache License 2.0"]
51
- s.rubygems_version = "2.4.2"
51
+ s.rubygems_version = "2.4.6"
52
52
  s.summary = "Muack -- A fast, small, yet powerful mocking library."
53
53
  s.test_files = [
54
54
  "test/test_any_instance_of.rb",
@@ -38,6 +38,103 @@ module Gemgem
38
38
  self.spec = spec
39
39
  end
40
40
 
41
+ def gem_install
42
+ require 'rubygems/commands/install_command'
43
+ # read ~/.gemrc
44
+ Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
45
+ Gem::Command.extra_args = Gem.configuration[:gem]
46
+
47
+ # setup install options
48
+ cmd = Gem::Commands::InstallCommand.new
49
+ cmd.handle_options([])
50
+
51
+ # install
52
+ install = Gem::Installer.new(gem_path, cmd.options)
53
+ install.install
54
+ puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
55
+ end
56
+
57
+ def gem_spec
58
+ create
59
+ write
60
+ end
61
+
62
+ def gem_build
63
+ require 'fileutils'
64
+ require 'rubygems/package'
65
+ gem = nil
66
+ Dir.chdir(dir) do
67
+ gem = Gem::Package.build(Gem::Specification.load(spec_path))
68
+ FileUtils.mkdir_p(pkg_dir)
69
+ FileUtils.mv(gem, pkg_dir) # gem is relative path, but might be ok
70
+ end
71
+ puts "\e[35mGem built: \e[33m#{strip_path("#{pkg_dir}/#{gem}")}\e[0m"
72
+ end
73
+
74
+ def gem_release
75
+ sh_git('tag', gem_tag)
76
+ sh_git('push')
77
+ sh_git('push', '--tags')
78
+ sh_gem('push', gem_path)
79
+ end
80
+
81
+ def gem_check
82
+ ver = spec.version.to_s
83
+
84
+ if ENV['VERSION'].nil?
85
+ puts("\e[35mExpected " \
86
+ "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
87
+ exit(1)
88
+
89
+ elsif ENV['VERSION'] != ver
90
+ puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
91
+ "\e[35mbut got\n " \
92
+ "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
93
+ exit(2)
94
+ end
95
+ end
96
+
97
+ def test
98
+ return if test_files.empty?
99
+
100
+ if ENV['COV'] || ENV['CI']
101
+ require 'simplecov'
102
+ if ENV['CI']
103
+ begin
104
+ require 'coveralls'
105
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
106
+ rescue LoadError => e
107
+ puts "Cannot load coveralls, skip: #{e}"
108
+ end
109
+ end
110
+ SimpleCov.start do
111
+ add_filter('test/')
112
+ add_filter('test.rb')
113
+ end
114
+ end
115
+
116
+ test_files.each{ |file| require "#{dir}/#{file[0..-4]}" }
117
+ end
118
+
119
+ def clean
120
+ return if ignored_files.empty?
121
+
122
+ require 'fileutils'
123
+ trash = File.expand_path("~/.Trash/#{spec.name}")
124
+ puts "Move the following files into: \e[35m#{strip_path(trash)}\e[33m"
125
+
126
+ ignored_files.each do |file|
127
+ from = "#{dir}/#{file}"
128
+ to = "#{trash}/#{File.dirname(file)}"
129
+ puts strip_path(from)
130
+
131
+ FileUtils.mkdir_p(to)
132
+ FileUtils.mv(from, to)
133
+ end
134
+
135
+ print "\e[0m"
136
+ end
137
+
41
138
  def write
42
139
  File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
43
140
  end
@@ -173,82 +270,38 @@ namespace :gem do
173
270
 
174
271
  desc 'Install gem'
175
272
  task :install => [:build] do
176
- Gemgem.sh_gem('install', Gemgem.gem_path)
273
+ Gemgem.gem_install
177
274
  end
178
275
 
179
276
  desc 'Build gem'
180
277
  task :build => [:spec] do
181
- require 'fileutils'
182
- require 'rubygems/package'
183
- gem = nil
184
- Dir.chdir(Gemgem.dir) do
185
- gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
186
- FileUtils.mkdir_p(Gemgem.pkg_dir)
187
- FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
188
- end
189
- puts "\e[35mGem built: \e[33m" \
190
- "#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
278
+ Gemgem.gem_build
191
279
  end
192
280
 
193
281
  desc 'Generate gemspec'
194
282
  task :spec do
195
- Gemgem.create
196
- Gemgem.write
283
+ Gemgem.gem_spec
197
284
  end
198
285
 
199
286
  desc 'Release gem'
200
287
  task :release => [:spec, :check, :build] do
201
- Gemgem.module_eval do
202
- sh_git('tag', Gemgem.gem_tag)
203
- sh_git('push')
204
- sh_git('push', '--tags')
205
- sh_gem('push', Gemgem.gem_path)
206
- end
288
+ Gemgem.gem_release
207
289
  end
208
290
 
209
291
  task :check do
210
- ver = Gemgem.spec.version.to_s
211
-
212
- if ENV['VERSION'].nil?
213
- puts("\e[35mExpected " \
214
- "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
215
- exit(1)
216
-
217
- elsif ENV['VERSION'] != ver
218
- puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
219
- "\e[35mbut got\n " \
220
- "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
221
- exit(2)
222
- end
292
+ Gemgem.gem_check
223
293
  end
224
294
 
225
295
  end # of gem namespace
226
296
 
227
297
  desc 'Run tests'
228
298
  task :test do
229
- next if Gemgem.test_files.empty?
230
- Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
299
+ Gemgem.test
231
300
  end
232
301
 
233
302
  desc 'Trash ignored files'
234
303
  task :clean => ['gem:spec'] do
235
- next if Gemgem.ignored_files.empty?
236
-
237
- require 'fileutils'
238
- trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
239
- puts "Move the following files into:" \
240
- " \e[35m#{Gemgem.strip_path(trash)}\e[33m"
241
-
242
- Gemgem.ignored_files.each do |file|
243
- from = "#{Gemgem.dir}/#{file}"
244
- to = "#{trash}/#{File.dirname(file)}"
245
- puts Gemgem.strip_path(from)
246
-
247
- FileUtils.mkdir_p(to)
248
- FileUtils.mv(from, to)
249
- end
250
-
251
- print "\e[0m"
304
+ Gemgem.clean
252
305
  end
253
306
 
254
307
  task :default do
@@ -9,7 +9,12 @@ describe 'from README.md' do
9
9
  after{ Muack.reset }
10
10
 
11
11
  Context = Module.new{
12
- include Pork::API, Muack::API
12
+ include Muack::API
13
+
14
+ def describe desc, &block
15
+ @executor.describe(desc, &block)
16
+ @executor.execute(@stat)
17
+ end
13
18
 
14
19
  def results; @results ||= []; end
15
20
  def p res ; results << res ; end
@@ -29,7 +34,11 @@ describe 'from README.md' do
29
34
 
30
35
  codes.each.with_index do |code, index|
31
36
  would 'pass from README.md #%02d' % index do
32
- context = Module.new{extend Context}
37
+ executor, stat = Class.new(self.class){ init }, pork_stat
38
+ context = Module.new do
39
+ extend Context
40
+ @executor, @stat = executor, stat
41
+ end
33
42
  begin
34
43
  context.instance_eval(code, 'README.md', 0)
35
44
  rescue Muack::Failure => e
@@ -109,7 +109,7 @@ describe Muack::Stub do
109
109
  stub(Obj).say(0){ 'boo' }
110
110
  stub(Obj).say(1){ 'moo' }
111
111
  e = should.raise(Muack::Unexpected){ Obj.say(false) }
112
- e.expected.should.eq "obj.say(0)\n or: obj.say(1)"
112
+ e.expected.should.eq "obj.say(1)\n or: obj.say(0)"
113
113
  e.was .should.eq 'obj.say(false)'
114
114
  e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
115
115
  end
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.1.2
4
+ version: 1.2.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-11-07 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Muack -- A fast, small, yet powerful mocking library.
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  requirements: []
80
80
  rubyforge_project:
81
- rubygems_version: 2.4.2
81
+ rubygems_version: 2.4.6
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: Muack -- A fast, small, yet powerful mocking library.