http_stub 0.15.5 → 0.16.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +37 -27
  3. data/lib/http_stub/configurer.rb +2 -2
  4. data/lib/http_stub/configurer/dsl/deprecated.rb +60 -0
  5. data/lib/http_stub/configurer/{server/dsl.rb → dsl/sanctioned.rb} +18 -18
  6. data/lib/http_stub/configurer/dsl/scenario_activator.rb +15 -0
  7. data/lib/http_stub/configurer/dsl/scenario_builder.rb +37 -0
  8. data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +24 -0
  9. data/lib/http_stub/configurer/{request → dsl}/stub_builder.rb +4 -3
  10. data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +21 -0
  11. data/lib/http_stub/configurer/request/http/factory.rb +8 -2
  12. data/lib/http_stub/configurer/request/scenario.rb +29 -0
  13. data/lib/http_stub/configurer/server/facade.rb +7 -7
  14. data/lib/http_stub/server/application.rb +21 -14
  15. data/lib/http_stub/server/registry.rb +7 -3
  16. data/lib/http_stub/server/response.rb +3 -3
  17. data/lib/http_stub/server/scenario.rb +12 -0
  18. data/lib/http_stub/server/scenario/activator.rb +25 -0
  19. data/lib/http_stub/server/scenario/controller.rb +36 -0
  20. data/lib/http_stub/server/scenario/instance.rb +36 -0
  21. data/lib/http_stub/server/scenario/request_parser.rb +19 -0
  22. data/lib/http_stub/server/stub.rb +3 -23
  23. data/lib/http_stub/server/stub/controller.rb +30 -0
  24. data/lib/http_stub/server/stub/exact_value_matcher.rb +15 -0
  25. data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +22 -0
  26. data/lib/http_stub/server/stub/headers.rb +19 -0
  27. data/lib/http_stub/server/stub/instance.rb +31 -0
  28. data/lib/http_stub/server/stub/method.rb +23 -0
  29. data/lib/http_stub/server/stub/omitted_value_matcher.rb +21 -0
  30. data/lib/http_stub/server/stub/payload_file_consolidator.rb +18 -0
  31. data/lib/http_stub/server/stub/regexp_value_matcher.rb +16 -0
  32. data/lib/http_stub/server/stub/registry.rb +31 -0
  33. data/lib/http_stub/server/stub/request_header_parser.rb +19 -0
  34. data/lib/http_stub/server/stub/request_headers.rb +28 -0
  35. data/lib/http_stub/server/stub/request_parameters.rb +23 -0
  36. data/lib/http_stub/server/stub/request_parser.rb +17 -0
  37. data/lib/http_stub/server/stub/response.rb +16 -0
  38. data/lib/http_stub/server/stub/response/base.rb +64 -0
  39. data/lib/http_stub/server/stub/response/file.rb +36 -0
  40. data/lib/http_stub/server/stub/response/text.rb +19 -0
  41. data/lib/http_stub/server/stub/string_value_matcher.rb +31 -0
  42. data/lib/http_stub/server/stub/triggers.rb +25 -0
  43. data/lib/http_stub/server/stub/uri.rb +23 -0
  44. data/lib/http_stub/server/views/_scenario.haml +16 -0
  45. data/lib/http_stub/server/views/application.sass +4 -0
  46. data/lib/http_stub/server/views/scenarios.haml +3 -0
  47. data/lib/http_stub/version.rb +1 -1
  48. data/spec/acceptance/activator_spec.rb +81 -0
  49. data/spec/acceptance/configurer_initialization_spec.rb +158 -0
  50. data/spec/acceptance/scenario_spec.rb +91 -0
  51. data/spec/acceptance/stub_control_values_spec.rb +160 -0
  52. data/spec/acceptance/stub_spec.rb +290 -0
  53. data/spec/acceptance/stub_trigger_spec.rb +144 -0
  54. data/spec/lib/http_stub/configurer/{deprecated_dsl_spec.rb → dsl/deprecated_spec.rb} +21 -13
  55. data/spec/lib/http_stub/configurer/{server/dsl_spec.rb → dsl/sanctioned_spec.rb} +74 -97
  56. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +62 -0
  57. data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +146 -0
  58. data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +120 -0
  59. data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +105 -0
  60. data/spec/lib/http_stub/configurer/{request → dsl}/stub_builder_spec.rb +33 -5
  61. data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +1 -1
  62. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +46 -5
  63. data/spec/lib/http_stub/configurer/request/omittable_spec.rb +1 -1
  64. data/spec/lib/http_stub/configurer/request/scenario_spec.rb +69 -0
  65. data/spec/lib/http_stub/configurer/request/stub_spec.rb +2 -2
  66. data/spec/lib/http_stub/configurer/server/facade_spec.rb +17 -17
  67. data/spec/lib/http_stub/configurer_spec.rb +1 -1
  68. data/spec/lib/http_stub/server/application_integration_spec.rb +23 -13
  69. data/spec/lib/http_stub/server/application_spec.rb +40 -38
  70. data/spec/lib/http_stub/server/daemon_spec.rb +2 -2
  71. data/spec/lib/http_stub/server/registry_spec.rb +66 -17
  72. data/spec/lib/http_stub/server/{request_parser_spec.rb → request_file_consolidator_spec.rb} +20 -33
  73. data/spec/lib/http_stub/server/response_pipeline_spec.rb +1 -1
  74. data/spec/lib/http_stub/server/scenario/activator_spec.rb +106 -0
  75. data/spec/lib/http_stub/server/scenario/controller_spec.rb +102 -0
  76. data/spec/lib/http_stub/server/scenario/instance_spec.rb +126 -0
  77. data/spec/lib/http_stub/server/scenario/request_parser_spec.rb +59 -0
  78. data/spec/lib/http_stub/server/scenario_spec.rb +24 -0
  79. data/spec/lib/http_stub/server/{stub_controller_spec.rb → stub/controller_spec.rb} +13 -17
  80. data/spec/lib/http_stub/server/{exact_value_matcher_spec.rb → stub/exact_value_matcher_spec.rb} +3 -3
  81. data/spec/lib/http_stub/server/{hash_with_string_value_matchers_spec.rb → stub/hash_with_string_value_matchers_spec.rb} +7 -5
  82. data/spec/lib/http_stub/server/{headers_spec.rb → stub/headers_spec.rb} +2 -2
  83. data/spec/lib/http_stub/server/stub/instance_spec.rb +201 -0
  84. data/spec/lib/http_stub/server/stub/method_spec.rb +95 -0
  85. data/spec/lib/http_stub/server/{omitted_value_matcher_spec.rb → stub/omitted_value_matcher_spec.rb} +3 -3
  86. data/spec/lib/http_stub/server/{regexp_value_matcher_spec.rb → stub/regexp_value_matcher_spec.rb} +3 -3
  87. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +56 -0
  88. data/spec/lib/http_stub/server/{stub_registry_spec.rb → stub/registry_spec.rb} +27 -14
  89. data/spec/lib/http_stub/server/{request_header_parser_spec.rb → stub/request_header_parser_spec.rb} +6 -6
  90. data/spec/lib/http_stub/server/stub/request_headers_spec.rb +68 -0
  91. data/spec/lib/http_stub/server/{stub_parameters_spec.rb → stub/request_parameters_spec.rb} +19 -17
  92. data/spec/lib/http_stub/server/stub/request_parser_spec.rb +56 -0
  93. data/spec/lib/http_stub/server/{stub_response → stub/response}/base_spec.rb +5 -5
  94. data/spec/lib/http_stub/server/{stub_response → stub/response}/file_spec.rb +3 -3
  95. data/spec/lib/http_stub/server/{stub_response → stub/response}/text_spec.rb +3 -3
  96. data/spec/lib/http_stub/server/{stub_response_spec.rb → stub/response_spec.rb} +8 -8
  97. data/spec/lib/http_stub/server/{string_value_matcher_spec.rb → stub/string_value_matcher_spec.rb} +25 -13
  98. data/spec/lib/http_stub/server/{stub_triggers_spec.rb → stub/triggers_spec.rb} +7 -9
  99. data/spec/lib/http_stub/server/stub/uri_spec.rb +43 -0
  100. data/spec/lib/http_stub/server/stub_spec.rb +10 -185
  101. data/spec/spec_helper.rb +10 -5
  102. data/spec/support/configurer_integration.rb +24 -0
  103. data/spec/support/scenario_fixture.rb +33 -0
  104. data/spec/support/stub_fixture.rb +1 -1
  105. metadata +126 -84
  106. data/lib/http_stub/configurer/deprecated_dsl.rb +0 -57
  107. data/lib/http_stub/configurer/request/stub_activator.rb +0 -26
  108. data/lib/http_stub/configurer/request/stub_activator_builder.rb +0 -25
  109. data/lib/http_stub/server/exact_value_matcher.rb +0 -13
  110. data/lib/http_stub/server/hash_with_string_value_matchers.rb +0 -20
  111. data/lib/http_stub/server/headers.rb +0 -17
  112. data/lib/http_stub/server/omitted_value_matcher.rb +0 -19
  113. data/lib/http_stub/server/regexp_value_matcher.rb +0 -14
  114. data/lib/http_stub/server/request_header_parser.rb +0 -17
  115. data/lib/http_stub/server/request_parser.rb +0 -29
  116. data/lib/http_stub/server/string_value_matcher.rb +0 -29
  117. data/lib/http_stub/server/stub_activator.rb +0 -30
  118. data/lib/http_stub/server/stub_activator_controller.rb +0 -34
  119. data/lib/http_stub/server/stub_controller.rb +0 -28
  120. data/lib/http_stub/server/stub_headers.rb +0 -24
  121. data/lib/http_stub/server/stub_parameters.rb +0 -21
  122. data/lib/http_stub/server/stub_registry.rb +0 -29
  123. data/lib/http_stub/server/stub_response.rb +0 -14
  124. data/lib/http_stub/server/stub_response/base.rb +0 -62
  125. data/lib/http_stub/server/stub_response/file.rb +0 -34
  126. data/lib/http_stub/server/stub_response/text.rb +0 -17
  127. data/lib/http_stub/server/stub_triggers.rb +0 -23
  128. data/lib/http_stub/server/stub_uri.rb +0 -21
  129. data/lib/http_stub/server/views/stub_activators.haml +0 -6
  130. data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +0 -119
  131. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +0 -45
  132. data/spec/lib/http_stub/configurer_integration_spec.rb +0 -837
  133. data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +0 -95
  134. data/spec/lib/http_stub/server/stub_activator_spec.rb +0 -83
  135. data/spec/lib/http_stub/server/stub_headers_spec.rb +0 -68
  136. data/spec/lib/http_stub/server/stub_registry_integration_spec.rb +0 -62
  137. data/spec/lib/http_stub/server/stub_uri_spec.rb +0 -42
@@ -0,0 +1,95 @@
1
+ describe HttpStub::Server::Stub::Method do
2
+
3
+ let(:raw_stub_method) { "put" }
4
+
5
+ let(:the_method) { HttpStub::Server::Stub::Method.new(raw_stub_method) }
6
+
7
+ describe "#match?" do
8
+
9
+ let(:request_method) { "get" }
10
+ let(:request) { instance_double(Rack::Request, request_method: request_method) }
11
+
12
+ subject { the_method.match?(request) }
13
+
14
+ context "when the request method is identical to the stub method" do
15
+
16
+ let(:request_method) { raw_stub_method }
17
+
18
+ it "returns true" do
19
+ expect(subject).to be(true)
20
+ end
21
+
22
+ end
23
+
24
+ context "when the request method and stub method are the the same value but have different casing" do
25
+
26
+ let(:raw_stub_method) { "GET" }
27
+
28
+ it "returns true" do
29
+ expect(subject).to be(true)
30
+ end
31
+
32
+ end
33
+
34
+ context "when the stub method is omitted" do
35
+
36
+ context "with a nil value" do
37
+
38
+ let(:raw_stub_method) { nil }
39
+
40
+ it "returns true" do
41
+ expect(subject).to be(true)
42
+ end
43
+
44
+ end
45
+
46
+ context "with an empty string" do
47
+
48
+ let(:raw_stub_method) { "" }
49
+
50
+ it "returns true" do
51
+ expect(subject).to be(true)
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ context "when the request method is different to the stub method" do
59
+
60
+ let(:request_method) { "get" }
61
+ let(:raw_stub_method) { "delete" }
62
+
63
+ it "returns false" do
64
+ expect(subject).to be(false)
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ describe "#to_s" do
72
+
73
+ context "when the stub method provided is not nil" do
74
+
75
+ let(:raw_stub_method) { "not_nil" }
76
+
77
+ it "returns the stub method provided" do
78
+ expect(the_method.to_s).to eql(raw_stub_method)
79
+ end
80
+
81
+ end
82
+
83
+ context "when the stub method provided is nil" do
84
+
85
+ let(:raw_stub_method) { nil }
86
+
87
+ it "returns an empty string" do
88
+ expect(the_method.to_s).to eql("")
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -1,6 +1,6 @@
1
- describe HttpStub::Server::OmittedValueMatcher do
1
+ describe HttpStub::Server::Stub::OmittedValueMatcher do
2
2
 
3
- describe ".match?" do
3
+ describe "::match?" do
4
4
 
5
5
  context "when the stubbed value is 'control:omitted'" do
6
6
 
@@ -50,7 +50,7 @@ describe HttpStub::Server::OmittedValueMatcher do
50
50
  end
51
51
 
52
52
  def perform_match
53
- HttpStub::Server::OmittedValueMatcher.match?(stub_value, actual_value)
53
+ HttpStub::Server::Stub::OmittedValueMatcher.match?(stub_value, actual_value)
54
54
  end
55
55
 
56
56
  end
@@ -1,6 +1,6 @@
1
- describe HttpStub::Server::RegexpValueMatcher do
1
+ describe HttpStub::Server::Stub::RegexpValueMatcher do
2
2
 
3
- describe ".match?" do
3
+ describe "::match?" do
4
4
 
5
5
  context "when the stub value is a string prefixed with 'regexp:'" do
6
6
 
@@ -40,7 +40,7 @@ describe HttpStub::Server::RegexpValueMatcher do
40
40
  end
41
41
 
42
42
  def perform_match
43
- HttpStub::Server::RegexpValueMatcher.match?(stub_value, actual_value)
43
+ HttpStub::Server::Stub::RegexpValueMatcher.match?(stub_value, actual_value)
44
44
  end
45
45
 
46
46
  end
@@ -0,0 +1,56 @@
1
+ describe HttpStub::Server::Stub::Registry, "integrating with real stubs" do
2
+
3
+ let(:logger) { double("Logger").as_null_object }
4
+ let(:request) { instance_double(Rack::Request, logger: logger) }
5
+
6
+ let(:stub_registry) { HttpStub::Server::Stub::Registry.new }
7
+
8
+ describe "#recall" do
9
+
10
+ subject { stub_registry.recall }
11
+
12
+ context "when stubs have been added" do
13
+
14
+ let(:stubs) { (1..3).map { |i| create_stub(i) } }
15
+
16
+ before(:example) { stubs.each { |stub| stub_registry.add(stub, request) } }
17
+
18
+ context "and remembered" do
19
+
20
+ before(:example) { stub_registry.remember }
21
+
22
+ context "and a stub subsequently added" do
23
+
24
+ let(:stub_to_add) { create_stub(4) }
25
+
26
+ before(:example) { stub_registry.add(stub_to_add, request) }
27
+
28
+ it "should restore all known stubs to the remembered state" do
29
+ subject
30
+
31
+ expect(stub_registry.all).not_to include(stub_to_add)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ def create_stub(number)
43
+ HttpStub::Server::Stub.create(
44
+ "uri" => "/uri#{number}",
45
+ "method" => "get",
46
+ "headers" => {"header_key_#{number}" => "header_value_#{number}"},
47
+ "parameters" => {"parameter_key_#{number}" => "parameter_value_#{number}"},
48
+ "response" => {
49
+ "status" => 200 + number,
50
+ "body" => "Body #{number}"
51
+ },
52
+ "triggers" => []
53
+ )
54
+ end
55
+
56
+ end
@@ -1,15 +1,15 @@
1
- describe HttpStub::Server::StubRegistry do
1
+ describe HttpStub::Server::Stub::Registry do
2
2
 
3
3
  let(:registry) { instance_double(HttpStub::Server::Registry) }
4
4
 
5
- let(:stub_registry) { HttpStub::Server::StubRegistry.new }
5
+ let(:stub_registry) { HttpStub::Server::Stub::Registry.new }
6
6
 
7
7
  before(:example) { allow(HttpStub::Server::Registry).to receive(:new).and_return(registry) }
8
8
 
9
9
  describe "#add" do
10
10
 
11
- let(:stub) { instance_double(HttpStub::Server::Stub) }
12
- let(:request) { double("HttpRequest") }
11
+ let(:stub) { instance_double(HttpStub::Server::Stub::Instance) }
12
+ let(:request) { instance_double(Rack::Request) }
13
13
 
14
14
  it "delegates to an underlying simple registry" do
15
15
  expect(registry).to receive(:add).with(stub, request)
@@ -19,24 +19,37 @@ describe HttpStub::Server::StubRegistry do
19
19
 
20
20
  end
21
21
 
22
+ describe "#concat" do
23
+
24
+ let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Instance) } }
25
+ let(:request) { instance_double(Rack::Request) }
26
+
27
+ it "delegates to an underlying simple registry" do
28
+ expect(registry).to receive(:concat).with(stubs, request)
29
+
30
+ stub_registry.concat(stubs, request)
31
+ end
32
+
33
+ end
34
+
22
35
  describe "#find_for" do
23
36
 
24
- let(:request) { double("HttpRequest") }
37
+ let(:request) { instance_double(Rack::Request) }
25
38
 
26
39
  subject { stub_registry.find_for(request) }
27
40
 
28
- it "delegates to an underlying simple registry" do
29
- expect(registry).to receive(:find_for).with(request)
41
+ it "delegates to an underlying simple registry to find based on the request" do
42
+ expect(registry).to receive(:find).with(criteria: request, request: request)
30
43
 
31
44
  subject
32
45
  end
33
46
 
34
47
  context "when a stub is found" do
35
48
 
36
- let(:triggers) { instance_double(HttpStub::Server::StubTriggers) }
37
- let(:stub) { instance_double(HttpStub::Server::Stub, triggers: triggers) }
49
+ let(:triggers) { instance_double(HttpStub::Server::Stub::Triggers) }
50
+ let(:stub) { instance_double(HttpStub::Server::Stub::Instance, triggers: triggers) }
38
51
 
39
- before(:example) { allow(registry).to receive(:find_for).and_return(stub) }
52
+ before(:example) { allow(registry).to receive(:find).and_return(stub) }
40
53
 
41
54
  it "should add the stubs triggers to the registry" do
42
55
  expect(triggers).to receive(:add_to).with(stub_registry, request)
@@ -54,7 +67,7 @@ describe HttpStub::Server::StubRegistry do
54
67
 
55
68
  context "when a stub is not found" do
56
69
 
57
- before(:example) { allow(registry).to receive(:find_for).and_return(nil) }
70
+ before(:example) { allow(registry).to receive(:find).and_return(nil) }
58
71
 
59
72
  it "returns the result from the underlying registry" do
60
73
  expect(subject).to eql(nil)
@@ -70,7 +83,7 @@ describe HttpStub::Server::StubRegistry do
70
83
 
71
84
  context "when the state of the registry has been remembered" do
72
85
 
73
- let(:last_stub_remembered) { instance_double(HttpStub::Server::Stub) }
86
+ let(:last_stub_remembered) { instance_double(HttpStub::Server::Stub::Instance) }
74
87
 
75
88
  before(:example) do
76
89
  allow(registry).to receive(:last).and_return(last_stub_remembered)
@@ -99,7 +112,7 @@ describe HttpStub::Server::StubRegistry do
99
112
 
100
113
  describe "#all" do
101
114
 
102
- let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub) } }
115
+ let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Instance) } }
103
116
 
104
117
  subject { stub_registry.all }
105
118
 
@@ -119,7 +132,7 @@ describe HttpStub::Server::StubRegistry do
119
132
 
120
133
  describe "#clear" do
121
134
 
122
- let(:request) { double("HttpRequest") }
135
+ let(:request) { instance_double(Rack::Request) }
123
136
 
124
137
  it "delegates to an underlying simple registry" do
125
138
  expect(registry).to receive(:clear).with(request)
@@ -1,4 +1,4 @@
1
- describe HttpStub::Server::RequestHeaderParser do
1
+ describe HttpStub::Server::Stub::RequestHeaderParser do
2
2
 
3
3
  let(:non_header_env_elements) do
4
4
  {
@@ -7,8 +7,8 @@ describe HttpStub::Server::RequestHeaderParser do
7
7
  "rack.multiprocess" => false
8
8
  }
9
9
  end
10
- let(:env) { non_header_env_elements.merge(header_env_elements) }
11
- let(:request) { double("HttpRequest", env: env) }
10
+ let(:env) { non_header_env_elements.merge(header_env_elements) }
11
+ let(:request) { instance_double(Rack::Request, env: env) }
12
12
 
13
13
  describe "::parse" do
14
14
 
@@ -17,7 +17,7 @@ describe HttpStub::Server::RequestHeaderParser do
17
17
  let(:header_env_elements) { { "KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3" } }
18
18
 
19
19
  it "returns a hash containing those entries" do
20
- expect(HttpStub::Server::RequestHeaderParser.parse(request)).to eql("KEY_1" => "value1",
20
+ expect(HttpStub::Server::Stub::RequestHeaderParser.parse(request)).to eql("KEY_1" => "value1",
21
21
  "KEY_2" => "value2",
22
22
  "KEY_3" => "value3")
23
23
  end
@@ -29,7 +29,7 @@ describe HttpStub::Server::RequestHeaderParser do
29
29
  let(:header_env_elements) { { "HTTP_KEY_1" => "value1", "HTTP_KEY_2" => "value2", "HTTP_KEY_3" => "value3" } }
30
30
 
31
31
  it "returns a hash containing those entries with the prefix removed" do
32
- expect(HttpStub::Server::RequestHeaderParser.parse(request)).to include("KEY_1" => "value1",
32
+ expect(HttpStub::Server::Stub::RequestHeaderParser.parse(request)).to include("KEY_1" => "value1",
33
33
  "KEY_2" => "value2",
34
34
  "KEY_3" => "value3")
35
35
  end
@@ -41,7 +41,7 @@ describe HttpStub::Server::RequestHeaderParser do
41
41
  let(:header_env_elements) { {} }
42
42
 
43
43
  it "returns an empty hash" do
44
- expect(HttpStub::Server::RequestHeaderParser.parse(request)).to eql({})
44
+ expect(HttpStub::Server::Stub::RequestHeaderParser.parse(request)).to eql({})
45
45
  end
46
46
 
47
47
  end
@@ -0,0 +1,68 @@
1
+ describe HttpStub::Server::Stub::RequestHeaders do
2
+
3
+ let(:request) { instance_double(Rack::Request) }
4
+ let(:stubbed_headers) { { "stub_key" => "value" } }
5
+
6
+ let(:request_headers) { HttpStub::Server::Stub::RequestHeaders.new(stubbed_headers) }
7
+
8
+ it "is Headers" do
9
+ expect(request_headers).to be_a(HttpStub::Server::Stub::Headers)
10
+ end
11
+
12
+ describe "when stubbed headers are provided" do
13
+
14
+ it "creates a regexpable representation of the stubbed headers whose keys are downcased and underscored" do
15
+ downcased_and_underscored_hash = { "another_stub_key" => "value" }
16
+ expect(stubbed_headers).to receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
17
+ expect(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).with(downcased_and_underscored_hash)
18
+
19
+ request_headers
20
+ end
21
+
22
+ end
23
+
24
+ describe "when the stubbed headers are nil" do
25
+
26
+ let(:stubbed_headers) { nil }
27
+
28
+ it "creates a regexpable representation of an empty hash" do
29
+ expect(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).with({})
30
+
31
+ request_headers
32
+ end
33
+
34
+ end
35
+
36
+ describe "#match?" do
37
+
38
+ let(:parsed_headers) { { "request_key" => "value" } }
39
+ let(:regexpable_stubbed_headers) { double(HttpStub::Server::Stub::HashWithStringValueMatchers).as_null_object }
40
+
41
+ before(:example) do
42
+ allow(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).and_return(regexpable_stubbed_headers)
43
+ allow(HttpStub::Server::Stub::RequestHeaderParser).to receive(:parse).with(request).and_return(parsed_headers)
44
+ end
45
+
46
+ it "parses the requests headers into a hash" do
47
+ expect(HttpStub::Server::Stub::RequestHeaderParser).to receive(:parse).with(request).and_return(parsed_headers)
48
+
49
+ request_headers.match?(request)
50
+ end
51
+
52
+ it "downcases and underscore the keys in the request header hash" do
53
+ expect(parsed_headers).to receive(:downcase_and_underscore_keys)
54
+
55
+ request_headers.match?(request)
56
+ end
57
+
58
+ it "delegates to the regexpable representation of the stubbed headers to determine a match" do
59
+ downcased_and_underscored_hash = { "another_request_key" => "value" }
60
+ allow(parsed_headers).to receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
61
+ expect(regexpable_stubbed_headers).to receive(:match?).with(downcased_and_underscored_hash).and_return(true)
62
+
63
+ expect(request_headers.match?(request)).to be_truthy
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -1,19 +1,19 @@
1
- describe HttpStub::Server::StubParameters do
1
+ describe HttpStub::Server::Stub::RequestParameters do
2
2
 
3
- let(:request_parameters) { double("RequestParameters") }
4
- let(:request) { double("HttpRequest", params: request_parameters) }
3
+ let(:raw_request_parameters) { double("RequestParameters") }
4
+ let(:request) { instance_double(Rack::Request, params: raw_request_parameters) }
5
5
 
6
- let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
7
- let(:regexpable_stubbed_paremeters) { double(HttpStub::Server::HashWithStringValueMatchers).as_null_object }
6
+ let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
7
+ let(:regexpable_stubbed_paremeters) { double(HttpStub::Server::Stub::HashWithStringValueMatchers).as_null_object }
8
8
 
9
- let(:stub_parameters) { HttpStub::Server::StubParameters.new(stubbed_parameters) }
9
+ let(:request_parameters) { HttpStub::Server::Stub::RequestParameters.new(stubbed_parameters) }
10
10
 
11
11
  describe "when stubbed parameters are provided" do
12
12
 
13
13
  it "creates a regexpable representation of the stubbed parameters" do
14
- expect(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).with(stubbed_parameters)
14
+ expect(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).with(stubbed_parameters)
15
15
 
16
- stub_parameters
16
+ request_parameters
17
17
  end
18
18
 
19
19
  end
@@ -23,9 +23,9 @@ describe HttpStub::Server::StubParameters do
23
23
  let(:stubbed_parameters) { nil }
24
24
 
25
25
  it "creates a regexpable representation of an empty hash" do
26
- expect(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).with({})
26
+ expect(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).with({})
27
27
 
28
- stub_parameters
28
+ request_parameters
29
29
  end
30
30
 
31
31
  end
@@ -33,28 +33,30 @@ describe HttpStub::Server::StubParameters do
33
33
  describe "#match?" do
34
34
 
35
35
  it "delegates to the regexpable representation of the stubbed parameters to determine a match" do
36
- allow(HttpStub::Server::HashWithStringValueMatchers).to receive(:new).and_return(regexpable_stubbed_paremeters)
37
- expect(regexpable_stubbed_paremeters).to receive(:match?).with(request_parameters).and_return(true)
36
+ allow(HttpStub::Server::Stub::HashWithStringValueMatchers).to receive(:new).and_return(regexpable_stubbed_paremeters)
37
+ expect(regexpable_stubbed_paremeters).to receive(:match?).with(raw_request_parameters).and_return(true)
38
38
 
39
- expect(stub_parameters.match?(request)).to be(true)
39
+ expect(request_parameters.match?(request)).to be(true)
40
40
  end
41
41
 
42
42
  end
43
43
 
44
44
  describe "#to_s" do
45
45
 
46
+ subject { request_parameters.to_s }
47
+
46
48
  describe "when multiple parameters are provided" do
47
49
 
48
50
  let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
49
51
 
50
52
  it "returns a string containing each parameter formatted as a conventional request parameter" do
51
- result = stub_parameters.to_s
53
+ result = subject
52
54
 
53
55
  stubbed_parameters.each { |key, value| expect(result).to match(/#{key}=#{value}/) }
54
56
  end
55
57
 
56
58
  it "separates each parameter with the conventional request parameter delimiter" do
57
- expect(stub_parameters.to_s).to match(/key\d.value\d\&key\d.value\d\&key\d.value\d/)
59
+ expect(subject).to match(/key\d.value\d\&key\d.value\d\&key\d.value\d/)
58
60
  end
59
61
 
60
62
  end
@@ -64,7 +66,7 @@ describe HttpStub::Server::StubParameters do
64
66
  let(:stubbed_parameters) { {} }
65
67
 
66
68
  it "returns an empty string" do
67
- expect(stub_parameters.to_s).to eql("")
69
+ expect(subject).to eql("")
68
70
  end
69
71
 
70
72
  end
@@ -74,7 +76,7 @@ describe HttpStub::Server::StubParameters do
74
76
  let(:stubbed_parameters) { nil }
75
77
 
76
78
  it "returns an empty string" do
77
- expect(stub_parameters.to_s).to eql("")
79
+ expect(subject).to eql("")
78
80
  end
79
81
 
80
82
  end