micro_mock 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. data/README.md +31 -25
  2. data/lib/micro_mock.rb +37 -24
  3. metadata +39 -26
data/README.md CHANGED
@@ -1,43 +1,49 @@
1
1
  # MicroMock
2
2
 
3
- ### Perhaps the lightest mocking strategy available
3
+ ### A tiny mocking script.
4
4
 
5
- MicroMock is a tiny mocking script.
5
+ MicroMock doesn't make any assumptions about the testing framework.
6
+ It leaves assertions/expectations up to you.
6
7
 
7
- It doesn't make any assumptions about the testing framework
8
- and leaves assertions/expectations up to you.
9
-
10
- This proves to be quite powerful.
8
+ Calling it a mocking script is a bit of a misnomer
9
+ since its really a dynamic class generator.
10
+ The term "stub" is used loosely since it adds real behavior...
11
+ and "mocking" a class with real behavior proves to be quite useful.
11
12
 
12
13
  ## Intall
13
14
  ```bash
14
15
  gem install micro_mock
15
16
  ```
16
17
 
17
- ## Use
18
+ ## Usage
18
19
  ```ruby
19
20
  Mock = MicroMock.make
20
21
 
21
22
  # mock a class method
22
- Mock.stub :foo do |*args|
23
- assert_equal 1, args.length # Test::Unit
24
- args.length.should eq 1 # RSpec
25
- end
23
+ Mock.stub(:foo) { true }
26
24
 
27
- mock = Mock.new
25
+ # make assertions
26
+ assert Mock.foo # Test::Unit
27
+ Mock.foo.should be_true # RSpec
28
28
 
29
29
  # mock an instance method
30
- mock.stub :bar do |*args|
31
- assert_equal 2, args.length # Test::Unit
32
- args.length.should eq 2 # RSpec
33
- end
34
-
35
- # use the methods
36
- Mock.foo 1
37
- mock.bar 1, 2
38
-
39
- # use the result of a mocked method
40
- mock.stub(:baz) { true }
41
- assert mock.baz # Test::Unit
42
- mock.baz.should be_true # RSpec
30
+ m = Mock.new
31
+ m.stub(:bar) { false }
32
+
33
+ # make assertions
34
+ assert_equal false, m.bar # Test::Unit
35
+ m.bar.should eq false # RSpec
36
+
37
+ # setup mock internal behavior
38
+ count = 1
39
+ m.stub(:a) { count += 1 }
40
+ m.stub(:b) { |i| self.a if i > 5 }
41
+
42
+ # make assertions
43
+ 10.times { |i| m.b(i) }
44
+ assert_equal 5, count # Test::Unit
45
+ count.should eq 5 # RSpec
43
46
  ```
47
+
48
+ Of course you wouldn't normally test the mock itself... rather the code that uses the mock.
49
+ I'll work on adding some real world examples.
data/lib/micro_mock.rb CHANGED
@@ -1,36 +1,48 @@
1
1
  # MicroMock is a tiny mocking script.
2
- # It doesn't make any assumptions about the testing framework
3
- # and leaves assertions/expectations up to you.
4
2
  #
5
- # This proves to be quite powerful.
3
+ # It doesn't make any assumptions about the testing framework.
4
+ # It leaves assertions/expectations up to you.
5
+ #
6
+ # Calling it a mocking script is a bit of a misnomer
7
+ # since its really a dynamic class generator.
8
+ #
9
+ # The term "stub" is used loosely since it adds real behavior...
10
+ # and "mocking" a class with real behavior proves to be quite useful.
6
11
  #
7
12
  # @example
8
13
  # Mock = MicroMock.make
9
14
  #
10
15
  # # mock a class method
11
- # Mock.stub :foo do |*args|
12
- # assert_equal 1, args.length # Test::Unit
13
- # args.length.should eq 1 # RSpec
14
- # end
15
- #
16
- # mock = Mock.new
17
- #
18
- # mock an instance method
19
- # mock.stub :bar do |*args|
20
- # assert_equal 2, args.length # Test::Unit
21
- # args.length.should eq 2 # RSpec
22
- # end
23
- #
24
- # # use the methods
25
- # Mock.foo 1
26
- # mock.bar 1, 2
27
- #
28
- # # use the result of a mocked method
29
- # mock.stub(:baz) { true }
30
- # assert mock.baz # Test::Unit
31
- # mock.baz.should be_true # RSpec
16
+ # Mock.stub(:foo) { true }
17
+ #
18
+ # # make assertions
19
+ # assert Mock.foo # Test::Unit
20
+ # Mock.foo.should be_true # RSpec
21
+ #
22
+ # # mock an instance method
23
+ # m = Mock.new
24
+ # m.stub(:bar) { false }
25
+ #
26
+ # # make assertions
27
+ # assert_equal false, m.bar # Test::Unit
28
+ # m.bar.should eq false # RSpec
29
+ #
30
+ # # setup mock internal behavior
31
+ # count = 1
32
+ # m.stub(:a) { count += 1 }
33
+ # m.stub(:b) { |i| self.a if i > 5 }
34
+ #
35
+ # # make assertions
36
+ # 10.times { |i| m.b(i) }
37
+ # assert_equal 5, count # Test::Unit
38
+ # count.should eq 5 # RSpec
39
+ #
40
+ # Of course you wouldn't normally test the mock itself... rather the code that uses the mock.
41
+ # I'll work on adding some real world examples.
32
42
  module MicroMock
43
+
33
44
  # Stubs a method.
45
+ # The term stub is used loosely since it adds real functionality.
34
46
  # @param [Symbol] name The name of the method.
35
47
  # @yield The block that will serve as the method definition.
36
48
  def stub(name, &block)
@@ -46,4 +58,5 @@ module MicroMock
46
58
  include MicroMock
47
59
  end
48
60
  end
61
+
49
62
  end
metadata CHANGED
@@ -1,51 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: micro_mock
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Nathan Hopkins
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-09-23 00:00:00.000000000 Z
16
+
17
+ date: 2012-09-24 00:00:00 -06:00
18
+ default_executable:
13
19
  dependencies: []
14
- description: ! ' MicroMock might just be the lightest mocking strategy available.
15
20
 
16
- '
17
- email:
21
+ description: " MicroMock might just be the lightest mocking strategy available.\n"
22
+ email:
18
23
  - natehop@gmail.com
19
24
  executables: []
25
+
20
26
  extensions: []
27
+
21
28
  extra_rdoc_files: []
22
- files:
29
+
30
+ files:
23
31
  - lib/micro_mock.rb
24
32
  - README.md
33
+ has_rdoc: true
25
34
  homepage: http://hopsoft.github.com/micro_mock/
26
- licenses:
35
+ licenses:
27
36
  - MIT
28
37
  post_install_message:
29
38
  rdoc_options: []
30
- require_paths:
39
+
40
+ require_paths:
31
41
  - lib
32
- required_ruby_version: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- required_rubygems_version: !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
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"
44
56
  requirements: []
57
+
45
58
  rubyforge_project:
46
- rubygems_version: 1.8.24
59
+ rubygems_version: 1.3.6
47
60
  signing_key:
48
61
  specification_version: 3
49
62
  summary: A tiny mocking script.
50
63
  test_files: []
51
- has_rdoc:
64
+