mock_zen 0.2.0 → 0.2.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.
- data/lib/{mock → mock_zen}/spy.rb +2 -2
- data/lib/{mock → mock_zen}/stub.rb +4 -4
- data/lib/{mock → mock_zen}/undefined_action_error.rb +2 -2
- data/lib/{mock.rb → mock_zen.rb} +7 -7
- data/test/spy_test.rb +20 -23
- data/test/stub_test.rb +23 -25
- data/test/test_helper.rb +2 -2
- metadata +7 -7
@@ -1,7 +1,7 @@
|
|
1
|
-
module
|
1
|
+
module MockZen
|
2
2
|
|
3
3
|
# A Stub is a class that will respond with the recorded action upon method calls.
|
4
|
-
class
|
4
|
+
class MockZen::Stub
|
5
5
|
# Creates the stub with the actions passed. The stub will respond to the keys in
|
6
6
|
# the hash and return the corresponding values.
|
7
7
|
# stub = Mock::Stub(method_call: false)
|
@@ -15,13 +15,13 @@ module Mock
|
|
15
15
|
# <br />
|
16
16
|
# Aliased as <code><<</code>
|
17
17
|
def add_behaviour(actions)
|
18
|
-
@actions.merge!(
|
18
|
+
@actions.merge!(MockZen::parse_actions(actions))
|
19
19
|
self
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
def method_missing(name, *args, &block)
|
24
|
-
raise
|
24
|
+
raise MockZen::UndefinedActionError, "Undefined action #{name}" unless @actions[name]
|
25
25
|
@actions[name]
|
26
26
|
end
|
27
27
|
|
data/lib/{mock.rb → mock_zen.rb}
RENAMED
@@ -1,22 +1,22 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
3
|
-
require_relative '
|
1
|
+
require_relative 'mock_zen/spy'
|
2
|
+
require_relative 'mock_zen/stub'
|
3
|
+
require_relative 'mock_zen/undefined_action_error'
|
4
4
|
|
5
|
-
module
|
5
|
+
module MockZen
|
6
6
|
|
7
7
|
# Creates a stub with the given actions
|
8
|
-
def
|
8
|
+
def MockZen::Stub(actions={})
|
9
9
|
Stub.new(parse_actions(actions))
|
10
10
|
end
|
11
11
|
|
12
12
|
# Creates a Spy.
|
13
|
-
def
|
13
|
+
def MockZen::Spy()
|
14
14
|
Spy.new
|
15
15
|
end
|
16
16
|
|
17
17
|
protected
|
18
18
|
# Ensures that the actions have Symbol or String keys
|
19
|
-
def
|
19
|
+
def MockZen::parse_actions(actions)
|
20
20
|
actions.each do |key, value|
|
21
21
|
if key.respond_to?(:to_sym)
|
22
22
|
actions.delete key
|
data/test/spy_test.rb
CHANGED
@@ -1,31 +1,28 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
3
|
class SpyTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@spy = MockZen::Spy()
|
7
|
+
end
|
9
8
|
|
10
|
-
|
9
|
+
test "record if a given method is called" do
|
10
|
+
@spy.method_call
|
11
|
+
assert @spy.called?(:method_call)
|
12
|
+
end
|
13
|
+
|
14
|
+
test "return false if the method wasn't called at all" do
|
15
|
+
assert not(@spy.called?(:method_call))
|
16
|
+
end
|
17
|
+
|
18
|
+
test "return 0 if the method wasn't called at all" do
|
19
|
+
assert_equal 0, @spy.times_called(:method_call)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "return the number of times a method was called" do
|
23
|
+
5.times do
|
11
24
|
@spy.method_call
|
12
|
-
assert @spy.called?(:method_call)
|
13
|
-
end
|
14
|
-
|
15
|
-
should "return false if the method wasn't called at all" do
|
16
|
-
assert not(@spy.called?(:method_call))
|
17
|
-
end
|
18
|
-
|
19
|
-
should "return 0 if the method wasn't called at all" do
|
20
|
-
assert_equal 0, @spy.times_called(:method_call)
|
21
|
-
end
|
22
|
-
|
23
|
-
should "return the number of times a method was called" do
|
24
|
-
5.times do
|
25
|
-
@spy.method_call
|
26
|
-
end
|
27
|
-
assert_equal 5, @spy.times_called(:method_call)
|
28
25
|
end
|
26
|
+
assert_equal 5, @spy.times_called(:method_call)
|
29
27
|
end
|
30
|
-
|
31
28
|
end
|
data/test/stub_test.rb
CHANGED
@@ -2,33 +2,31 @@ require_relative 'test_helper'
|
|
2
2
|
|
3
3
|
class StubTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
stub.method_call
|
10
|
-
end
|
5
|
+
test "fail if nothing is registered" do
|
6
|
+
stub = MockZen::Stub()
|
7
|
+
assert_raise MockZen::UndefinedActionError do
|
8
|
+
stub.method_call
|
11
9
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
should "return what is defined on the hash" do
|
21
|
-
stub = Mock::Stub(method_call: true)
|
22
|
-
assert stub.method_call
|
10
|
+
end
|
11
|
+
|
12
|
+
test "not fali if the method called is registered" do
|
13
|
+
stub = MockZen::Stub(method_call: true)
|
14
|
+
assert_nothing_raised do
|
15
|
+
stub.method_call
|
23
16
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
test "return what is defined on the hash" do
|
20
|
+
stub = MockZen::Stub(method_call: true)
|
21
|
+
assert stub.method_call
|
22
|
+
end
|
23
|
+
|
24
|
+
test "respond to an added behaviour" do
|
25
|
+
stub = MockZen::Stub()
|
26
|
+
assert_raise MockZen::UndefinedActionError do
|
27
|
+
stub.method_call
|
32
28
|
end
|
29
|
+
stub.add_behaviour(method_call: true)
|
30
|
+
assert stub.method_call
|
33
31
|
end
|
34
32
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'test/unit'
|
2
|
+
require 'mock_zen'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Guilherme Carvalho
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-10 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -27,10 +27,10 @@ extensions: []
|
|
27
27
|
extra_rdoc_files: []
|
28
28
|
|
29
29
|
files:
|
30
|
-
- lib/
|
31
|
-
- lib/
|
32
|
-
- lib/
|
33
|
-
- lib/
|
30
|
+
- lib/mock_zen.rb
|
31
|
+
- lib/mock_zen/spy.rb
|
32
|
+
- lib/mock_zen/stub.rb
|
33
|
+
- lib/mock_zen/undefined_action_error.rb
|
34
34
|
- Rakefile
|
35
35
|
- test/spy_test.rb
|
36
36
|
- test/stub_test.rb
|