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.
@@ -1,7 +1,7 @@
1
- module Mock
1
+ module MockZen
2
2
 
3
3
  # A Spy is a class that records every method call for further verification.
4
- class Mock::Spy
4
+ class MockZen::Spy
5
5
 
6
6
  # Creates the spy that will record any method calls on it.
7
7
  # spy = Spy.new
@@ -1,7 +1,7 @@
1
- module Mock
1
+ module MockZen
2
2
 
3
3
  # A Stub is a class that will respond with the recorded action upon method calls.
4
- class Mock::Stub
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!(Mock::parse_actions(actions))
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 Mock::UndefinedActionError, "Undefined action #{name}" unless @actions[name]
24
+ raise MockZen::UndefinedActionError, "Undefined action #{name}" unless @actions[name]
25
25
  @actions[name]
26
26
  end
27
27
 
@@ -1,7 +1,7 @@
1
- module Mock
1
+ module MockZen
2
2
 
3
3
  # Error thrown when a method that wasn't recorded is called on a stub.
4
- class Mock::UndefinedActionError < RuntimeError
4
+ class MockZen::UndefinedActionError < RuntimeError
5
5
  end
6
6
 
7
7
  end
@@ -1,22 +1,22 @@
1
- require_relative 'mock/spy'
2
- require_relative 'mock/stub'
3
- require_relative 'mock/undefined_action_error'
1
+ require_relative 'mock_zen/spy'
2
+ require_relative 'mock_zen/stub'
3
+ require_relative 'mock_zen/undefined_action_error'
4
4
 
5
- module Mock
5
+ module MockZen
6
6
 
7
7
  # Creates a stub with the given actions
8
- def Mock::Stub(actions={})
8
+ def MockZen::Stub(actions={})
9
9
  Stub.new(parse_actions(actions))
10
10
  end
11
11
 
12
12
  # Creates a Spy.
13
- def Mock::Spy()
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 Mock::parse_actions(actions)
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
- context "A spy" do
5
-
6
- setup do
7
- @spy = Mock::Spy()
8
- end
4
+
5
+ def setup
6
+ @spy = MockZen::Spy()
7
+ end
9
8
 
10
- should "record if a given method is called" do
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
- context "An stub" do
6
- should "fail if nothing is registered" do
7
- stub = Mock::Stub()
8
- assert_raise Mock::UndefinedActionError do
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
- should "not fali if the method called is registered" do
14
- stub = Mock::Stub(method_call: true)
15
- assert_nothing_raised do
16
- stub.method_call
17
- end
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
- should "respond to an added behaviour" do
26
- stub = Mock::Stub()
27
- assert_raise Mock::UndefinedActionError do
28
- stub.method_call
29
- end
30
- stub.add_behaviour(method_call: true)
31
- assert stub.method_call
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 'shoulda'
2
- require_relative '../lib/mock'
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
- - 0
9
- version: 0.2.0
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-08 00:00:00 -03:00
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/mock.rb
31
- - lib/mock/spy.rb
32
- - lib/mock/stub.rb
33
- - lib/mock/undefined_action_error.rb
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