micro_mock 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,8 +2,10 @@
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
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 quite handy.
7
+
8
+ *Be sure to checkout [MicroTest](https://github.com/hopsoft/micro_test) for a lightweight test framework with similar goals.*
7
9
 
8
10
  ## Intall
9
11
 
@@ -24,7 +26,7 @@ MyMock.attr(:foo)
24
26
  MyMock.attr(:attr_with_default, "Class value")
25
27
 
26
28
  # add a class method
27
- MyMock.meth(:say_foo) { |arg| "#{foo} #{arg}!" }
29
+ MyMock.def(:say_foo) { |arg| "#{foo} #{arg}!" }
28
30
 
29
31
  # create a mock instance
30
32
  mock = MyMock.new
@@ -36,7 +38,7 @@ mock.attr(:bar)
36
38
  mock.attr(:attr_with_default, "Instance value")
37
39
 
38
40
  # add an instance method
39
- mock.meth(:say_bar) { |arg| "#{bar} #{arg}!" }
41
+ mock.def(:say_bar) { |arg| "#{bar} #{arg}!" }
40
42
 
41
43
  # use the mock
42
44
  MyMock.attr_with_default # => "Class value"
@@ -71,7 +73,7 @@ list.concat [1, 2, 3]
71
73
  list.reverse_string # => "3,2,1"
72
74
 
73
75
  # add an instance method that does something interesting
74
- list.meth :prefixed do |prefix|
76
+ list.def :prefixed do |prefix|
75
77
  map { |value| "#{prefix}:#{value}"}
76
78
  end
77
79
  list.prefixed(:num) # => ["num:1", "num:2", "num:3"]
@@ -84,12 +86,12 @@ Here is an example that mocks part of ActiveRecord.
84
86
  ```ruby
85
87
  Model = MicroMock.make
86
88
  model = Model.new
87
- model.meth(:destroy) { @destroyed = true }
88
- model.meth(:destroyed?) { @destroyed }
89
- model.meth(:update_attributes) { |*args| @attributes_updated = true }
90
- model.meth(:save) { |*args| @saved = true }
91
- Model.meth(:find) { |*args| model.clone }
92
- Model.meth(:all) { (1..5).map { model.clone } }
89
+ model.def(:destroy) { @destroyed = true }
90
+ model.def(:destroyed?) { @destroyed }
91
+ model.def(:update_attributes) { |*args| @attributes_updated = true }
92
+ model.def(:save) { |*args| @saved = true }
93
+ Model.def(:find) { |*args| model.clone }
94
+ Model.def(:all) { (1..5).map { model.clone } }
93
95
 
94
96
  # try it out
95
97
  list = Model.all # => [#<MicroMock70331390241500:0x007fee9b1b1bb0 @args=[]>, #<MicroMock...]
@@ -1,3 +1,3 @@
1
1
  module MicroMock
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/micro_mock.rb CHANGED
@@ -30,10 +30,9 @@ module MicroMock
30
30
  # Creates a method.
31
31
  # @param [Symbol] name The name of the method.
32
32
  # @yield The block that will serve as the method body.
33
- def meth(name, &block)
33
+ def def(name, &block)
34
34
  context.send :define_method, name, &block
35
35
  end
36
- alias_method :stub, :meth
37
36
 
38
37
  private
39
38
 
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.2
4
+ version: 1.0.0
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-12-31 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Perhaps the lightest mocking strategy available.
15
15