aidmock 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,17 +24,27 @@ In order to use Aidmock, you need to configure it on your test environment. Sinc
24
24
 
25
25
  bc.. RSpec.configure do |config|
26
26
  config.before :all do
27
- Aidmock.setup # it will do any nescessary setup, like extending your framework mocks
27
+ Aidmock.setup! # it will do any nescessary setup, like extending your framework mocks
28
28
  end
29
29
 
30
30
  config.after :each do
31
- Aidmock.verify # it will verify created mocks after each spec
31
+ Aidmock.verify! # it will verify created mocks after each spec
32
32
  end
33
33
  end
34
34
 
35
35
  # load or write your interfaces here
36
36
 
37
- Aidmock::Sanity.sanitize # it will run sanity checks, just call it after have all interfaces defined
37
+ Aidmock::Sanity.sanitize! # it will run sanity checks, just call it after have all interfaces defined
38
+
39
+ h2. Automatic Interfacing
40
+
41
+ Since version 0.3.1 Aidmock supports automatic interfacing, this feature is enabled by default. With automatic interfacing Aidmock will define the class interface automatically for you if the interface is not already defined, we still encorage you to do some manual interface definitions since automatic interfacing can't be too much precise (it will generate method names and correct arity, but can't check value real types). But automatic interfaces is a nice start point for you at Aidmock, no need for big setups, work with third-part code (also built-in Ruby code too) and will give to you a new layer of safe to your mocks.
42
+
43
+ Even when you start doing interfaces by hand, you may want to still having this feature enabled, since it will interface third-part code and built-in code.
44
+
45
+ If you wanna do a hardcore Aidmock use, you can disable automatic interfacing with following snippet:
46
+
47
+ bc. Aidmock.autointerface = false
38
48
 
39
49
  h2. How It Works
40
50
 
@@ -214,6 +224,15 @@ Example:
214
224
  bc. method :something, s(nil) # will accept splat with anything(nil will be converted one AnythingMatcher)
215
225
  method :something, splat(nil) # same as above
216
226
 
227
+ h2. Mixing automatic and manual interfaces
228
+
229
+ Why just manual OR automatic interfacing? You can have both!
230
+ You can tell Aidmock to fill the interface with automatic generated methods, and them just override with manual interface, to do this, just send @:auto => true@ to interface definition:
231
+
232
+ bc.. Aidmock.interface Person, :auto => true do
233
+ method :name, String
234
+ end
235
+
217
236
  h2. Class Inheritance and Modules
218
237
 
219
238
  Aidmock respects your class inheritance and module definition, so, the below example will be valid:
@@ -238,6 +257,20 @@ end
238
257
 
239
258
  h2. Changelog
240
259
 
260
+ h3. 0.4.0
261
+
262
+ * Fixed automatic generation step
263
+ * Hability to mix automatic interfacing with manual interface
264
+ * Methods: Aidmock.setup, Aidmock.verify, Aidmock::Sanity.sanitize now requires ! (now you should use Aidmock.setup!, Aidmock.verify!, Aidmock::Sanity.sanitize!)
265
+
266
+ h3. 0.3.1
267
+
268
+ * Supporting automatic interfacing
269
+
270
+ h3. 0.3.0
271
+
272
+ * bad release, ignore this version please
273
+
241
274
  h3. 0.2.0
242
275
 
243
276
  * Added .constrained_to to mocks
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aidmock}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wilker Lucio"]
12
- s.date = %q{2011-01-24}
12
+ s.date = %q{2011-02-07}
13
13
  s.description = %q{Aidmock, safe mocking and interfacing for Ruby}
14
14
  s.email = %q{wilkerlucio@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  s.homepage = %q{http://github.com/wilkerlucio/aidmock}
50
50
  s.rdoc_options = ["--charset=UTF-8"]
51
51
  s.require_paths = ["lib"]
52
- s.rubygems_version = %q{1.3.7}
52
+ s.rubygems_version = %q{1.5.0}
53
53
  s.summary = %q{Aidmock, safe mocking and interfacing for Ruby}
54
54
  s.test_files = [
55
55
  "spec/aidmock/auto_interface_spec.rb",
@@ -66,7 +66,6 @@ Gem::Specification.new do |s|
66
66
  ]
67
67
 
68
68
  if s.respond_to? :specification_version then
69
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
69
  s.specification_version = 3
71
70
 
72
71
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -35,14 +35,13 @@ module Aidmock
35
35
  alias :warn_undefined_interface? :warn_undefined_interface
36
36
  alias :autointerface? :autointerface
37
37
 
38
- def interface(klass, &block)
39
- interfaces[klass] = create_or_update_interface(klass, &block)
38
+ def interface(klass, options = {}, &block)
39
+ options = {:auto => false}.merge(options)
40
+ AutoInterface.define(klass) if options[:auto]
41
+ interfaces[klass] = create_or_update_interface(klass, &block) if block
40
42
  end
41
43
 
42
- def stub(klass, stubs = {})
43
- end
44
-
45
- def verify
44
+ def verify!
46
45
  framework.mocks.each do |mock|
47
46
  verify_double(mock)
48
47
  end
@@ -64,7 +63,7 @@ module Aidmock
64
63
  ::Aidmock::TestFrameworks::RSpec
65
64
  end
66
65
 
67
- def setup
66
+ def setup!
68
67
  framework.extend_doubles
69
68
  end
70
69
 
@@ -72,12 +71,12 @@ module Aidmock
72
71
 
73
72
  def verify_double(double)
74
73
  klass = extract_class(double.object)
74
+ AutoInterface.define(klass) if autointerface? and !has_interface?(klass)
75
+
75
76
  chain = chain_for(klass)
76
77
 
77
78
  if chain.length > 0
78
79
  verify_double_on_chain(double, chain)
79
- elsif autointerface?
80
- AutoInterface.define(klass)
81
80
  else
82
81
  puts "Aidmock Warning: unsafe mocking on class #{klass}, please interface it" if warn_undefined_interface?
83
82
  end
@@ -31,12 +31,16 @@ module Aidmock
31
31
  end
32
32
 
33
33
  def method(name, type, *arguments)
34
+ @methods.delete_if { |md| md.name == name }
35
+
34
36
  method = MethodDescriptor.new(name, type, *arguments)
35
37
  @methods << method
36
38
  method
37
39
  end
38
40
 
39
41
  def class_method(name, type, *arguments)
42
+ @class_methods.delete_if { |md| md.name == name }
43
+
40
44
  method = MethodDescriptor.new(name, type, *arguments)
41
45
  method.class_method = true
42
46
  @class_methods << method
@@ -21,7 +21,7 @@
21
21
  module Aidmock
22
22
  module Sanity
23
23
  class << self
24
- def sanitize
24
+ def sanitize!
25
25
  describe "Aidmock Sanity Checks:" do
26
26
  Aidmock.interfaces.each_pair do |klass, interface|
27
27
  context klass.to_s do
@@ -23,8 +23,57 @@ require File.expand_path("../../spec_helper", __FILE__)
23
23
  describe Aidmock::Interface do
24
24
  Interface = Aidmock::Interface
25
25
  MockDescriptor = Aidmock::Frameworks::MockDescriptor
26
+ MethodDescriptor = Aidmock::MethodDescriptor
26
27
 
27
- context "finding the method" do
28
+ context "#method" do
29
+ it "add a new method" do
30
+ descriptor = mock "method descriptor"
31
+ MethodDescriptor.stub(:new).with("test", "type") { descriptor }
32
+
33
+ interface = Interface.new(Object)
34
+ interface.method("test", "type")
35
+ interface.methods.should include(descriptor)
36
+ end
37
+
38
+ it "remove old method if it has same name" do
39
+ descriptor = mock "method descriptor", :name => "test"
40
+ descriptor2 = mock "method descriptor"
41
+ MethodDescriptor.stub(:new).with("test", "type") { descriptor }
42
+ MethodDescriptor.stub(:new).with("test", "type2") { descriptor2 }
43
+
44
+ interface = Interface.new(Object)
45
+ interface.method("test", "type")
46
+ interface.method("test", "type2")
47
+ interface.methods.should include(descriptor2)
48
+ interface.methods.should_not include(descriptor)
49
+ end
50
+ end
51
+
52
+ context "#class_method" do
53
+ it "add a new method" do
54
+ descriptor = mock "method descriptor", :class_method= => true
55
+ MethodDescriptor.stub(:new).with("test", "type") { descriptor }
56
+
57
+ interface = Interface.new(Object)
58
+ interface.class_method("test", "type")
59
+ interface.class_methods.should include(descriptor)
60
+ end
61
+
62
+ it "remove old method if it has same name" do
63
+ descriptor = mock "method descriptor", :name => "test", :class_method= => true
64
+ descriptor2 = mock "method descriptor", :class_method= => true
65
+ MethodDescriptor.stub(:new).with("test", "type") { descriptor }
66
+ MethodDescriptor.stub(:new).with("test", "type2") { descriptor2 }
67
+
68
+ interface = Interface.new(Object)
69
+ interface.class_method("test", "type")
70
+ interface.class_method("test", "type2")
71
+ interface.class_methods.should include(descriptor2)
72
+ interface.class_methods.should_not include(descriptor)
73
+ end
74
+ end
75
+
76
+ context "#find_method" do
28
77
  it "find the method defined by exact name" do
29
78
  interface = Interface.new(Object)
30
79
  method = interface.method(:some, nil)
@@ -22,9 +22,20 @@ require File.expand_path("../spec_helper", __FILE__)
22
22
 
23
23
  describe Aidmock do
24
24
  context ".interface" do
25
- end
25
+ context "automatic interfacing" do
26
+ it "define interface if auto is specified" do
27
+ Aidmock::AutoInterface.should_receive(:define).with(String) {}
28
+ Aidmock.stub!(:interfaces) { {} }
29
+
30
+ Aidmock.interface String, :auto => true
31
+ end
32
+
33
+ it "don't automatic define interface if auto is false" do
34
+ Aidmock::AutoInterface.should_not_receive(:define)
26
35
 
27
- context ".stub" do
36
+ Aidmock.interface String
37
+ end
38
+ end
28
39
  end
29
40
 
30
41
  context ".verify" do
@@ -37,7 +48,7 @@ describe Aidmock do
37
48
  Aidmock.should_receive(:verify_double).with(m2) { nil }
38
49
  Aidmock.should_receive(:verify_double).with(m3) { nil }
39
50
 
40
- Aidmock.verify
51
+ Aidmock.verify!
41
52
  end
42
53
  end
43
54
 
@@ -59,7 +70,8 @@ describe Aidmock do
59
70
  double = Aidmock::Frameworks::MockDescriptor.new("object", :to_s, nil, [])
60
71
 
61
72
  Aidmock.stub!(:autointerface?) { true }
62
- Aidmock.stub!(:chain_for).with(String) { [] }
73
+ Aidmock.stub!(:has_interface?).with(String) { false }
74
+ Aidmock.stub!(:verify_double_on_chain)
63
75
  Aidmock::AutoInterface.should_receive(:define).with(String) {}
64
76
 
65
77
  Aidmock.send :verify_double, double
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aidmock
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 1
9
- version: 0.3.1
4
+ prerelease:
5
+ version: 0.4.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Wilker Lucio
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-24 00:00:00 -03:00
13
+ date: 2011-02-07 00:00:00 -03:00
18
14
  default_executable:
19
15
  dependencies: []
20
16
 
@@ -70,21 +66,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
66
  requirements:
71
67
  - - ">="
72
68
  - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
69
  version: "0"
76
70
  required_rubygems_version: !ruby/object:Gem::Requirement
77
71
  none: false
78
72
  requirements:
79
73
  - - ">="
80
74
  - !ruby/object:Gem::Version
81
- segments:
82
- - 0
83
75
  version: "0"
84
76
  requirements: []
85
77
 
86
78
  rubyforge_project:
87
- rubygems_version: 1.3.7
79
+ rubygems_version: 1.5.0
88
80
  signing_key:
89
81
  specification_version: 3
90
82
  summary: Aidmock, safe mocking and interfacing for Ruby