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.
@@ -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, :find
14
-
15
- end
17
+ should have_imeths :add, :get, :remove, :remove_all
16
18
 
17
- class AddTest < UnitTests
18
- desc "add"
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 responses given an name and optional params" do
21
- subject.add('test', { 'id' => 1 }) do
22
- Sanford::Protocol::Response.new([ 404, 'not found' ])
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
- response = subject.find('test', { 'id' => 1 }).protocol_response
39
+ protocol_response = subject.get(@name, @params).protocol_response
25
40
 
26
- assert_equal 404, response.code
27
- assert_equal 'not found', response.status.message
28
- assert_equal nil, response.data
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 "default the response as a 200 when only given response data" do
39
- subject.add('test'){ true }
40
- response = subject.find('test').protocol_response
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
- end
48
-
49
- class FindTest < UnitTests
50
- desc "find"
51
- setup do
52
- @responses.add('test', { 'id' => 1 }){ true }
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 "allow finding a response given a name and optional params" do
59
- response = subject.find('test', { 'id' => 1 }).protocol_response
60
- assert_equal true, response.data
61
-
62
- response = subject.find('test').protocol_response
63
- assert_equal true, response.data
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 "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
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
- end
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
- class RemoveTest < UnitTests
75
- desc "remove"
76
- setup do
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 "remove responses given a name and optional params" do
82
- subject.remove('test', { 'id' => 1 })
83
- assert_nil subject.find('test', { 'id' => 1 })
89
+ should "allow removing all responses" do
90
+ subject.add(@name, @params){ @response_data }
91
+ subject.add(@name){ @response_data }
84
92
 
85
- subject.remove('test')
86
- assert_nil subject.find('test')
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: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 1
10
- version: 0.6.1
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-07-24 00:00:00 Z
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: 25
27
+ hash: 31
28
28
  segments:
29
29
  - 0
30
- - 9
31
- version: "0.9"
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/fake_connection.rb
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/fake_connection.rb
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