micro_mock 0.1.0 → 0.1.1

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.
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  ### Perhaps the lightest mocking strategy available
4
4
 
5
- Calling it a mocking script is a bit of a misnomer since its really a dynamic class generator. The term "stub" is used loosely since it adds real behavior...
6
- and "mocking" with real behavior proves to be quite useful.
5
+ Calling it a mocking script is a bit of a misnomer since its really a dynamic class generator
6
+ ...and "mocking" with real behavior proves to be quite useful.
7
7
 
8
8
  ## Intall
9
9
 
@@ -23,8 +23,8 @@ MyMock.attr(:foo)
23
23
  # add a class attr with a default value
24
24
  MyMock.attr(:attr_with_default, "Class value")
25
25
 
26
- # stub a class method
27
- MyMock.stub(:say_foo) { |arg| "#{foo} #{arg}!" }
26
+ # add a class method
27
+ MyMock.meth(:say_foo) { |arg| "#{foo} #{arg}!" }
28
28
 
29
29
  # create a mock instance
30
30
  mock = MyMock.new
@@ -35,8 +35,8 @@ mock.attr(:bar)
35
35
  # add an instance attr with a default value
36
36
  mock.attr(:attr_with_default, "Instance value")
37
37
 
38
- # stub some instance methods
39
- mock.stub(:say_bar) { |arg| "#{bar} #{arg}!" }
38
+ # add an instance method
39
+ mock.meth(:say_bar) { |arg| "#{bar} #{arg}!" }
40
40
 
41
41
  # use the mock
42
42
  MyMock.attr_with_default # => "Class value"
@@ -58,8 +58,8 @@ MockList = MicroMock.make(Array)
58
58
 
59
59
  list = MockList.new
60
60
 
61
- # stub an instance method that does something interesting
62
- list.stub :prefixed do |prefix|
61
+ # add an instance method that does something interesting
62
+ list.meth :prefixed do |prefix|
63
63
  map { |value| "#{prefix}:#{value}"}
64
64
  end
65
65
 
@@ -74,12 +74,12 @@ Here is an example that mocks part of ActiveRecord.
74
74
  ```ruby
75
75
  Model = MicroMock.make
76
76
  model = Model.new
77
- model.stub(:destroy) { @destroyed = true }
78
- model.stub(:destroyed?) { @destroyed }
79
- model.stub(:update_attributes) { |*args| @attributes_updated = true }
80
- model.stub(:save) { |*args| @saved = true }
81
- Model.stub(:find) { |*args| model.clone }
82
- Model.stub(:all) { (1..5).map { model.clone } }
77
+ model.meth(:destroy) { @destroyed = true }
78
+ model.meth(:destroyed?) { @destroyed }
79
+ model.meth(:update_attributes) { |*args| @attributes_updated = true }
80
+ model.meth(:save) { |*args| @saved = true }
81
+ Model.meth(:find) { |*args| model.clone }
82
+ Model.meth(:all) { (1..5).map { model.clone } }
83
83
 
84
84
  # try it out
85
85
  list = Model.all # => [#<MicroMock70331390241500:0x007fee9b1b1bb0 @args=[]>, #<MicroMock...]
data/lib/micro_mock.rb CHANGED
@@ -23,13 +23,13 @@ module MicroMock
23
23
  instance_variable_set "@#{name}", default_value
24
24
  end
25
25
 
26
- # Stubs a method.
27
- # The term stub is used loosely since it adds real functionality.
26
+ # Creates a method.
28
27
  # @param [Symbol] name The name of the method.
29
- # @yield The block that will serve as the method definition.
30
- def stub(name, &block)
28
+ # @yield The block that will serve as the method body.
29
+ def meth(name, &block)
31
30
  context.send :define_method, name, &block
32
31
  end
32
+ alias_method :stub, :meth
33
33
 
34
34
  private
35
35
 
@@ -1,3 +1,3 @@
1
1
  module MicroMock
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-23 00:00:00.000000000 Z
12
+ date: 2012-11-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Perhaps the lightest mocking strategy available.
15
15