micro_mock 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nathan Hopkins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -17,9 +17,8 @@ gem install micro_mock
17
17
 
18
18
  ## Usage
19
19
  ```ruby
20
- Mock = MicroMock.make
21
-
22
20
  # mock a class method
21
+ Mock = MicroMock.make
23
22
  Mock.stub(:foo) { true }
24
23
 
25
24
  # make assertions
@@ -45,5 +44,16 @@ assert_equal 5, count # Test::Unit
45
44
  count.should eq 5 # RSpec
46
45
  ```
47
46
 
47
+ ```ruby
48
+ # create a mock that subclasses Array
49
+ Mock = MicroMock.make(Array)
50
+ list = Mock.new
51
+ list << 1
52
+ list.stub :say_hi do |name|
53
+ "Hi #{name}!"
54
+ end
55
+ list.say_hi "Nate" # => "Hi Nate!"
56
+ ```
57
+
48
58
  Of course you wouldn't normally test the mock itself... rather the code that uses the mock.
49
59
  I'll work on adding some real world examples.
@@ -0,0 +1,3 @@
1
+ module MicroMock
2
+ VERSION = "0.0.3"
3
+ end
data/lib/micro_mock.rb CHANGED
@@ -10,9 +10,8 @@
10
10
  # and "mocking" a class with real behavior proves to be quite useful.
11
11
  #
12
12
  # @example
13
- # Mock = MicroMock.make
14
- #
15
13
  # # mock a class method
14
+ # Mock = MicroMock.make
16
15
  # Mock.stub(:foo) { true }
17
16
  #
18
17
  # # make assertions
@@ -39,6 +38,16 @@
39
38
  #
40
39
  # Of course you wouldn't normally test the mock itself... rather the code that uses the mock.
41
40
  # I'll work on adding some real world examples.
41
+ #
42
+ # @ example
43
+ # Mock with a superclass.
44
+ # Mock = MicroMock.make(Array)
45
+ # list = Mock.new
46
+ # list << 1
47
+ # list.stub :say_hi do |name|
48
+ # "Hi #{name}!"
49
+ # end
50
+ # list.say_hi "Nate" # => "Hi Nate!"
42
51
  module MicroMock
43
52
 
44
53
  # Stubs a method.
@@ -52,11 +61,12 @@ module MicroMock
52
61
  end
53
62
 
54
63
  # Defines a mock class.
55
- def self.make
56
- Class.new do
57
- extend MicroMock
58
- include MicroMock
59
- end
64
+ def self.make(superclass=nil)
65
+ klass = Class.new(superclass) if superclass
66
+ klass ||= Class.new
67
+ klass.extend MicroMock
68
+ klass.send :include, MicroMock
69
+ klass
60
70
  end
61
71
 
62
72
  end
metadata CHANGED
@@ -1,64 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: micro_mock
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Nathan Hopkins
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-09-24 00:00:00 -06:00
18
- default_executable:
12
+ date: 2012-11-15 00:00:00.000000000 Z
19
13
  dependencies: []
14
+ description: ! ' MicroMock might just be the lightest mocking strategy available.
20
15
 
21
- description: " MicroMock might just be the lightest mocking strategy available.\n"
22
- email:
16
+ '
17
+ email:
23
18
  - natehop@gmail.com
24
19
  executables: []
25
-
26
20
  extensions: []
27
-
28
21
  extra_rdoc_files: []
29
-
30
- files:
22
+ files:
23
+ - lib/micro_mock/version.rb
31
24
  - lib/micro_mock.rb
25
+ - LICENSE.txt
32
26
  - README.md
33
- has_rdoc: true
34
27
  homepage: http://hopsoft.github.com/micro_mock/
35
- licenses:
28
+ licenses:
36
29
  - MIT
37
30
  post_install_message:
38
31
  rdoc_options: []
39
-
40
- require_paths:
32
+ require_paths:
41
33
  - lib
42
- required_ruby_version: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- segments:
47
- - 0
48
- version: "0"
49
- required_rubygems_version: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
56
46
  requirements: []
57
-
58
47
  rubyforge_project:
59
- rubygems_version: 1.3.6
48
+ rubygems_version: 1.8.23
60
49
  signing_key:
61
50
  specification_version: 3
62
51
  summary: A tiny mocking script.
63
52
  test_files: []
64
-
53
+ has_rdoc: