and-son 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/and-son.gemspec +1 -1
- data/lib/and-son/call_runner.rb +142 -0
- data/lib/and-son/client.rb +68 -100
- data/lib/and-son/stored_responses.rb +25 -7
- data/lib/and-son/version.rb +1 -1
- data/test/helper.rb +3 -2
- data/test/support/factory.rb +6 -0
- data/test/system/making_requests_tests.rb +1 -1
- data/test/unit/call_runner_tests.rb +287 -0
- data/test/unit/client_tests.rb +219 -84
- data/test/unit/stored_responses_tests.rb +67 -56
- metadata +13 -10
- data/test/support/fake_connection.rb +0 -29
@@ -6,84 +6,95 @@ class AndSon::StoredResponses
|
|
6
6
|
class UnitTests < Assert::Context
|
7
7
|
desc "AndSon::StoredResponses"
|
8
8
|
setup do
|
9
|
+
@name = Factory.string
|
10
|
+
@params = { Factory.string => Factory.string }
|
11
|
+
@response_data = Factory.string
|
12
|
+
|
9
13
|
@responses = AndSon::StoredResponses.new
|
10
14
|
end
|
11
15
|
subject{ @responses }
|
12
16
|
|
13
|
-
should have_imeths :add, :remove, :
|
14
|
-
|
15
|
-
end
|
17
|
+
should have_imeths :add, :get, :remove, :remove_all
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
should "allow adding and getting responses with response data" do
|
20
|
+
subject.add(@name, @params){ @response_data }
|
21
|
+
protocol_response = subject.get(@name, @params).protocol_response
|
22
|
+
assert_equal 200, protocol_response.code
|
23
|
+
assert_nil protocol_response.status.message
|
24
|
+
assert_equal @response_data, protocol_response.data
|
25
|
+
end
|
19
26
|
|
20
|
-
should "allow adding
|
21
|
-
|
22
|
-
|
27
|
+
should "allow adding and gettings responses being yielded a response" do
|
28
|
+
code = Factory.integer
|
29
|
+
message = Factory.string
|
30
|
+
data = Factory.string
|
31
|
+
|
32
|
+
yielded = nil
|
33
|
+
subject.add(@name, @params) do |response|
|
34
|
+
yielded = response
|
35
|
+
response.code = code
|
36
|
+
response.message = message
|
37
|
+
response.data = data
|
23
38
|
end
|
24
|
-
|
39
|
+
protocol_response = subject.get(@name, @params).protocol_response
|
25
40
|
|
26
|
-
|
27
|
-
assert_equal
|
28
|
-
assert_equal
|
29
|
-
|
30
|
-
subject.add('test'){ Sanford::Protocol::Response.new([ 404, 'not found' ]) }
|
31
|
-
response = subject.find('test').protocol_response
|
32
|
-
|
33
|
-
assert_equal 404, response.code
|
34
|
-
assert_equal 'not found', response.status.message
|
35
|
-
assert_equal nil, response.data
|
41
|
+
assert_instance_of Sanford::Protocol::Response, yielded
|
42
|
+
assert_equal code, protocol_response.code
|
43
|
+
assert_equal message, protocol_response.message
|
44
|
+
assert_equal data, protocol_response.data
|
36
45
|
end
|
37
46
|
|
38
|
-
should "
|
39
|
-
subject.add(
|
40
|
-
|
41
|
-
|
42
|
-
assert_equal 200, response.code
|
43
|
-
assert_equal nil, response.status.message
|
44
|
-
assert_equal true, response.data
|
47
|
+
should "allow adding and getting responses with no params" do
|
48
|
+
subject.add(@name){ @response_data }
|
49
|
+
protocol_response = subject.get(@name).protocol_response
|
50
|
+
assert_equal @response_data, protocol_response.data
|
45
51
|
end
|
46
52
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@responses.add('test'){ true }
|
54
|
-
@service_called = false
|
55
|
-
@responses.add('call_service'){ @service_called = true }
|
53
|
+
should "return a default response for a name/params that isn't configured" do
|
54
|
+
response = subject.get(@name, @params)
|
55
|
+
protocol_response = response.protocol_response
|
56
|
+
assert_equal 200, protocol_response.code
|
57
|
+
assert_nil protocol_response.status.message
|
58
|
+
assert_equal({}, protocol_response.data)
|
56
59
|
end
|
57
60
|
|
58
|
-
should "
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
should "not call a response block until it is retrieved" do
|
62
|
+
called = false
|
63
|
+
subject.add(@name){ called = true }
|
64
|
+
assert_false called
|
65
|
+
subject.get(@name)
|
66
|
+
assert_true called
|
64
67
|
end
|
65
68
|
|
66
|
-
should "
|
67
|
-
|
68
|
-
subject.
|
69
|
-
|
69
|
+
should "allow removing a response" do
|
70
|
+
subject.add(@name, @params){ @response_data }
|
71
|
+
protocol_response = subject.get(@name, @params).protocol_response
|
72
|
+
assert_equal @response_data, protocol_response.data
|
73
|
+
|
74
|
+
subject.remove(@name, @params)
|
75
|
+
protocol_response = subject.get(@name, @params).protocol_response
|
76
|
+
assert_not_equal @response_data, protocol_response.data
|
70
77
|
end
|
71
78
|
|
72
|
-
|
79
|
+
should "allow removing a response without params" do
|
80
|
+
subject.add(@name){ @response_data }
|
81
|
+
protocol_response = subject.get(@name).protocol_response
|
82
|
+
assert_equal @response_data, protocol_response.data
|
73
83
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
@responses.add('test', { 'id' => 1 }){ true }
|
78
|
-
@responses.add('test'){ true }
|
84
|
+
subject.remove(@name)
|
85
|
+
protocol_response = subject.get(@name).protocol_response
|
86
|
+
assert_not_equal @response_data, protocol_response.data
|
79
87
|
end
|
80
88
|
|
81
|
-
should "
|
82
|
-
subject.
|
83
|
-
|
89
|
+
should "allow removing all responses" do
|
90
|
+
subject.add(@name, @params){ @response_data }
|
91
|
+
subject.add(@name){ @response_data }
|
84
92
|
|
85
|
-
subject.
|
86
|
-
|
93
|
+
subject.remove_all
|
94
|
+
protocol_response = subject.get(@name, @params).protocol_response
|
95
|
+
assert_not_equal @response_data, protocol_response.data
|
96
|
+
protocol_response = subject.get(@name).protocol_response
|
97
|
+
assert_not_equal @response_data, protocol_response.data
|
87
98
|
end
|
88
99
|
|
89
100
|
end
|
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:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 0.7.0
|
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: 2014-
|
19
|
+
date: 2014-09-29 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -24,11 +24,11 @@ dependencies:
|
|
24
24
|
requirements:
|
25
25
|
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
hash:
|
27
|
+
hash: 31
|
28
28
|
segments:
|
29
29
|
- 0
|
30
|
-
-
|
31
|
-
version: "0.
|
30
|
+
- 10
|
31
|
+
version: "0.10"
|
32
32
|
version_requirements: *id001
|
33
33
|
type: :runtime
|
34
34
|
name: sanford-protocol
|
@@ -66,16 +66,18 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- and-son.gemspec
|
68
68
|
- lib/and-son.rb
|
69
|
+
- lib/and-son/call_runner.rb
|
69
70
|
- lib/and-son/client.rb
|
70
71
|
- lib/and-son/connection.rb
|
71
72
|
- lib/and-son/response.rb
|
72
73
|
- lib/and-son/stored_responses.rb
|
73
74
|
- lib/and-son/version.rb
|
74
75
|
- test/helper.rb
|
75
|
-
- test/support/
|
76
|
+
- test/support/factory.rb
|
76
77
|
- test/support/fake_server.rb
|
77
78
|
- test/system/making_requests_tests.rb
|
78
79
|
- test/unit/and-son_tests.rb
|
80
|
+
- test/unit/call_runner_tests.rb
|
79
81
|
- test/unit/client_tests.rb
|
80
82
|
- test/unit/response_tests.rb
|
81
83
|
- test/unit/stored_responses_tests.rb
|
@@ -114,10 +116,11 @@ specification_version: 3
|
|
114
116
|
summary: Simple Sanford client for Ruby.
|
115
117
|
test_files:
|
116
118
|
- test/helper.rb
|
117
|
-
- test/support/
|
119
|
+
- test/support/factory.rb
|
118
120
|
- test/support/fake_server.rb
|
119
121
|
- test/system/making_requests_tests.rb
|
120
122
|
- test/unit/and-son_tests.rb
|
123
|
+
- test/unit/call_runner_tests.rb
|
121
124
|
- test/unit/client_tests.rb
|
122
125
|
- test/unit/response_tests.rb
|
123
126
|
- test/unit/stored_responses_tests.rb
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class FakeConnection
|
2
|
-
|
3
|
-
attr_reader :written
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@written = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def peek(*args)
|
10
|
-
"peek_data"
|
11
|
-
end
|
12
|
-
|
13
|
-
def read(*args)
|
14
|
-
{ 'status' => [ 200 ], 'data' => {} }
|
15
|
-
end
|
16
|
-
|
17
|
-
def write(request_hash)
|
18
|
-
@written << request_hash
|
19
|
-
end
|
20
|
-
|
21
|
-
def close_write
|
22
|
-
@write_stream_closed = true
|
23
|
-
end
|
24
|
-
|
25
|
-
def write_stream_closed?
|
26
|
-
!!@write_stream_closed
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|