micro_mock 0.0.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.
Files changed (3) hide show
  1. data/README.md +43 -0
  2. data/lib/micro_mock.rb +49 -0
  3. metadata +51 -0
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # MicroMock
2
+
3
+ ### Perhaps the lightest mocking strategy available
4
+
5
+ MicroMock is a tiny mocking script.
6
+
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.
11
+
12
+ ## Intall
13
+ ```bash
14
+ gem install micro_mock
15
+ ```
16
+
17
+ ## Use
18
+ ```ruby
19
+ Mock = MicroMock.make
20
+
21
+ # 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
26
+
27
+ mock = Mock.new
28
+
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
43
+ ```
data/lib/micro_mock.rb ADDED
@@ -0,0 +1,49 @@
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
+ #
5
+ # This proves to be quite powerful.
6
+ #
7
+ # @example
8
+ # Mock = MicroMock.make
9
+ #
10
+ # # 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
32
+ module MicroMock
33
+ # Stubs a method.
34
+ # @param [Symbol] name The name of the method.
35
+ # @yield The block that will serve as the method definition.
36
+ def stub(name, &block)
37
+ context = class << self; self; end if is_a? Class
38
+ context ||= self.class
39
+ context.send :define_method, name, &block
40
+ end
41
+
42
+ # Defines a mock class.
43
+ def self.make
44
+ Class.new do
45
+ extend MicroMock
46
+ include MicroMock
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micro_mock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathan Hopkins
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! ' MicroMock might just be the lightest mocking strategy available.
15
+
16
+ '
17
+ email:
18
+ - natehop@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/micro_mock.rb
24
+ - README.md
25
+ homepage: http://hopsoft.github.com/micro_mock/
26
+ licenses:
27
+ - MIT
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - 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'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.24
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: A tiny mocking script.
50
+ test_files: []
51
+ has_rdoc: