and-son 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/and-son.gemspec CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency("sanford-protocol", ["~>0.6"])
21
21
 
22
- gem.add_development_dependency("assert", ["~>2.3"])
22
+ gem.add_development_dependency("assert", ["~>2.9"])
23
23
  gem.add_development_dependency("assert-mocha", ["~>1.0"])
24
24
  end
@@ -11,17 +11,19 @@ module AndSon
11
11
  @hash = {}
12
12
  end
13
13
 
14
- def add(name, params = nil)
14
+ def add(name, params = nil, &response_block)
15
15
  request_data = RequestData.new(name, params || {})
16
- response = yield
17
- if !response.kind_of?(Sanford::Protocol::Response)
18
- response = Sanford::Protocol::Response.new(200, response)
19
- end
20
- @hash[request_data] = AndSon::Response.new(response)
16
+ @hash[request_data] = response_block
21
17
  end
22
18
 
23
19
  def find(name, params = nil)
24
- @hash[RequestData.new(name, params || {})]
20
+ response_block = @hash[RequestData.new(name, params || {})]
21
+ return if !response_block
22
+ response = response_block.call
23
+ if !response.kind_of?(Sanford::Protocol::Response)
24
+ response = Sanford::Protocol::Response.new(200, response)
25
+ end
26
+ AndSon::Response.new(response)
25
27
  end
26
28
 
27
29
  def remove(name, params = nil)
@@ -1,3 +1,3 @@
1
1
  module AndSon
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -3,7 +3,7 @@ require 'and-son'
3
3
 
4
4
  module AndSon
5
5
 
6
- class BaseTests < Assert::Context
6
+ class UnitTests < Assert::Context
7
7
  desc "AndSon"
8
8
  subject{ AndSon }
9
9
 
@@ -6,7 +6,7 @@ require 'and-son/client'
6
6
 
7
7
  class AndSon::Client
8
8
 
9
- class BaseTests < Assert::Context
9
+ class UnitTests < Assert::Context
10
10
  include FakeServer::Helper
11
11
 
12
12
  desc "AndSon::Client"
@@ -73,7 +73,7 @@ class AndSon::Client
73
73
 
74
74
  end
75
75
 
76
- class CallTest < BaseTests
76
+ class CallTest < UnitTests
77
77
  desc "call"
78
78
  setup do
79
79
  @connection = AndSon::Connection.new('localhost', 12001)
@@ -3,7 +3,7 @@ require 'and-son/response'
3
3
 
4
4
  class AndSon::Response
5
5
 
6
- class BaseTests < Assert::Context
6
+ class UnitTests < Assert::Context
7
7
  desc "AndSon::Response"
8
8
  setup do
9
9
  @protocol_response = Sanford::Protocol::Response.new([ 200, 'message' ], 'data')
@@ -26,7 +26,7 @@ class AndSon::Response
26
26
 
27
27
  end
28
28
 
29
- class FailedResponseTests < BaseTests
29
+ class FailedResponseTests < UnitTests
30
30
  desc "given a failed response"
31
31
  setup do
32
32
  @protocol_response = Sanford::Protocol::Response.new([ 500, 'message' ])
@@ -45,7 +45,7 @@ class AndSon::Response
45
45
 
46
46
  end
47
47
 
48
- class Response5xxTests < BaseTests
48
+ class Response5xxTests < UnitTests
49
49
  desc "given a 5xx response"
50
50
  setup do
51
51
  @protocol_response = Sanford::Protocol::Response.new(500)
@@ -61,7 +61,7 @@ class AndSon::Response
61
61
 
62
62
  end
63
63
 
64
- class Response404Tests < BaseTests
64
+ class Response404Tests < UnitTests
65
65
  desc "given a 404 response"
66
66
  setup do
67
67
  @protocol_response = Sanford::Protocol::Response.new(404)
@@ -78,7 +78,7 @@ class AndSon::Response
78
78
 
79
79
  end
80
80
 
81
- class Response400Tests < BaseTests
81
+ class Response400Tests < UnitTests
82
82
  desc "given a 400 response"
83
83
  setup do
84
84
  @protocol_response = Sanford::Protocol::Response.new(400)
@@ -95,7 +95,7 @@ class AndSon::Response
95
95
 
96
96
  end
97
97
 
98
- class Response4xxTests < BaseTests
98
+ class Response4xxTests < UnitTests
99
99
  desc "given a 4xx response"
100
100
  setup do
101
101
  @protocol_response = Sanford::Protocol::Response.new(402)
@@ -3,7 +3,7 @@ require 'and-son/stored_responses'
3
3
 
4
4
  class AndSon::StoredResponses
5
5
 
6
- class BaseTest < Assert::Context
6
+ class UnitTests < Assert::Context
7
7
  desc "AndSon::StoredResponses"
8
8
  setup do
9
9
  @responses = AndSon::StoredResponses.new
@@ -14,7 +14,7 @@ class AndSon::StoredResponses
14
14
 
15
15
  end
16
16
 
17
- class AddTest < BaseTest
17
+ class AddTest < UnitTests
18
18
  desc "add"
19
19
 
20
20
  should "allow adding responses given an name and optional params" do
@@ -46,11 +46,13 @@ class AndSon::StoredResponses
46
46
 
47
47
  end
48
48
 
49
- class FindTest < BaseTest
49
+ class FindTest < UnitTests
50
50
  desc "find"
51
51
  setup do
52
52
  @responses.add('test', { 'id' => 1 }){ true }
53
53
  @responses.add('test'){ true }
54
+ @service_called = false
55
+ @responses.add('call_service'){ @service_called = true }
54
56
  end
55
57
 
56
58
  should "allow finding a response given a name and optional params" do
@@ -61,9 +63,15 @@ class AndSon::StoredResponses
61
63
  assert_equal true, response.data
62
64
  end
63
65
 
66
+ should "not call the response block until `find` is called" do
67
+ assert_false @service_called
68
+ subject.find('call_service')
69
+ assert_true @service_called
70
+ end
71
+
64
72
  end
65
73
 
66
- class RemoveTest < BaseTest
74
+ class RemoveTest < UnitTests
67
75
  desc "remove"
68
76
  setup do
69
77
  @responses.add('test', { 'id' => 1 }){ true }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: and-son
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Collin Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-10-14 00:00:00 Z
19
+ date: 2014-03-10 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -39,11 +39,11 @@ dependencies:
39
39
  requirements:
40
40
  - - ~>
41
41
  - !ruby/object:Gem::Version
42
- hash: 5
42
+ hash: 17
43
43
  segments:
44
44
  - 2
45
- - 3
46
- version: "2.3"
45
+ - 9
46
+ version: "2.9"
47
47
  type: :development
48
48
  requirement: *id002
49
49
  prerelease: false