micro_mock 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,28 +42,38 @@ mock.meth(:say_bar) { |arg| "#{bar} #{arg}!" }
42
42
  MyMock.attr_with_default # => "Class value"
43
43
  MyMock.foo # => nil
44
44
  MyMock.foo = :foo
45
- MyMock.say_foo :bar # => "foobar!"
45
+ MyMock.say_foo :bar # => "foo bar!"
46
46
 
47
47
  mock.attr_with_default # => "Instance value"
48
48
  mock.bar # => nil
49
49
  mock.bar = :bar
50
- mock.say_bar :foo # => "barfoo!"
50
+ mock.say_bar :foo # => "bar foo!"
51
51
  ```
52
52
 
53
53
  ## Next Steps
54
54
 
55
55
  ```ruby
56
- # create a mock that subclasses Array
57
- MockList = MicroMock.make(Array)
56
+ # create a useless module to illustrate mocking with ancestors
57
+ module Useless
58
+ def reverse_string
59
+ reverse.join(",")
60
+ end
61
+ end
62
+
63
+ # create a mock that subclasses Array and mixes in the Useless module defined above
64
+ # note: the superclass must be passed before mixin modules
65
+ MockList = MicroMock.make(Array, Useless)
58
66
 
59
67
  list = MockList.new
60
68
 
69
+ # demonstrate that the mock has inherited behavior
70
+ list.concat [1, 2, 3]
71
+ list.reverse_string # => "3,2,1"
72
+
61
73
  # add an instance method that does something interesting
62
74
  list.meth :prefixed do |prefix|
63
75
  map { |value| "#{prefix}:#{value}"}
64
76
  end
65
-
66
- list.concat [1, 2, 3]
67
77
  list.prefixed(:num) # => ["num:1", "num:2", "num:3"]
68
78
  ```
69
79
 
@@ -1,3 +1,3 @@
1
1
  module MicroMock
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/micro_mock.rb CHANGED
@@ -2,8 +2,12 @@
2
2
  module MicroMock
3
3
 
4
4
  # Defines a mock class.
5
- def self.make(superclass=Object)
5
+ def self.make(*ancestors)
6
+ superclass = ancestors.shift if ancestors.first.is_a?(Class)
7
+ superclass ||= Object
8
+ mixins = ancestors
6
9
  klass = Class.new(superclass) do
10
+ mixins.each { |mixin| send :include, mixin }
7
11
  def initialize(*args)
8
12
  @args = args
9
13
  super unless self.class.superclass == Object
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.1
4
+ version: 0.1.2
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-24 00:00:00.000000000 Z
12
+ date: 2012-12-31 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Perhaps the lightest mocking strategy available.
15
15
 
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  version: '0'
46
46
  requirements: []
47
47
  rubyforge_project:
48
- rubygems_version: 1.8.23
48
+ rubygems_version: 1.8.24
49
49
  signing_key:
50
50
  specification_version: 3
51
51
  summary: A tiny mocking script.