http_stub 0.22.4 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +15 -5
  3. data/lib/http_stub/configurer/dsl/request_attribute_referencer.rb +19 -0
  4. data/lib/http_stub/configurer/dsl/request_referencer.rb +24 -0
  5. data/lib/http_stub/configurer/dsl/scenario_activator.rb +2 -2
  6. data/lib/http_stub/configurer/dsl/scenario_builder.rb +2 -2
  7. data/lib/http_stub/configurer/dsl/server.rb +4 -4
  8. data/lib/http_stub/configurer/dsl/stub_builder.rb +5 -3
  9. data/lib/http_stub/configurer/request/controllable_value.rb +1 -3
  10. data/lib/http_stub/configurer/request/http/factory.rb +2 -2
  11. data/lib/http_stub/configurer/request/omittable.rb +2 -4
  12. data/lib/http_stub/configurer/request/regexpable.rb +3 -8
  13. data/lib/http_stub/configurer/server/command_processor.rb +5 -7
  14. data/lib/http_stub/configurer/server/facade.rb +2 -4
  15. data/lib/http_stub/extensions/core/hash.rb +4 -11
  16. data/lib/http_stub/extensions/core/hash/formatted.rb +23 -0
  17. data/lib/http_stub/extensions/core/hash/indifferent_and_insensitive_access.rb +24 -0
  18. data/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access.rb +18 -0
  19. data/lib/http_stub/extensions/rack/handler.rb +1 -1
  20. data/lib/http_stub/rake/task_generators.rb +1 -1
  21. data/lib/http_stub/server/application.rb +10 -11
  22. data/lib/http_stub/server/application_helpers.rb +3 -5
  23. data/lib/http_stub/server/daemon.rb +5 -6
  24. data/lib/http_stub/server/request.rb +3 -10
  25. data/lib/http_stub/server/request/headers.rb +25 -0
  26. data/lib/http_stub/server/request/parameters.rb +21 -0
  27. data/lib/http_stub/server/request/request.rb +21 -0
  28. data/lib/http_stub/server/scenario/links.rb +1 -1
  29. data/lib/http_stub/server/stub/controller.rb +1 -1
  30. data/lib/http_stub/server/stub/empty.rb +4 -0
  31. data/lib/http_stub/server/stub/match/hash_matcher.rb +19 -0
  32. data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +1 -3
  33. data/lib/http_stub/server/stub/match/rule/body.rb +2 -4
  34. data/lib/http_stub/server/stub/match/rule/headers.rb +5 -11
  35. data/lib/http_stub/server/stub/match/rule/json_body.rb +3 -5
  36. data/lib/http_stub/server/stub/match/rule/method.rb +1 -1
  37. data/lib/http_stub/server/stub/match/rule/parameters.rb +4 -7
  38. data/lib/http_stub/server/stub/match/rule/simple_body.rb +3 -3
  39. data/lib/http_stub/server/stub/match/rule/truthy.rb +27 -0
  40. data/lib/http_stub/server/stub/match/rule/uri.rb +3 -3
  41. data/lib/http_stub/server/stub/match/string_value_matcher.rb +4 -13
  42. data/lib/http_stub/server/stub/response.rb +5 -2
  43. data/lib/http_stub/server/stub/response/attribute/body.rb +32 -0
  44. data/lib/http_stub/server/stub/response/attribute/headers.rb +26 -0
  45. data/lib/http_stub/server/stub/response/attribute/interpolator.rb +26 -0
  46. data/lib/http_stub/server/stub/response/attribute/interpolator/headers.rb +27 -0
  47. data/lib/http_stub/server/stub/response/attribute/interpolator/parameters.rb +27 -0
  48. data/lib/http_stub/server/stub/response/base.rb +5 -16
  49. data/lib/http_stub/server/stub/response/file.rb +6 -2
  50. data/lib/http_stub/server/stub/response/text.rb +12 -0
  51. data/lib/http_stub/server/stub/stub.rb +4 -0
  52. data/lib/http_stub/version.rb +1 -1
  53. data/spec/acceptance/request_reference_spec.rb +44 -0
  54. data/spec/lib/http_stub/configurer/dsl/request_attribute_referencer_spec.rb +37 -0
  55. data/spec/lib/http_stub/configurer/dsl/request_referencer_spec.rb +37 -0
  56. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +14 -14
  57. data/spec/lib/http_stub/configurer/dsl/server_spec.rb +2 -6
  58. data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +34 -8
  59. data/spec/lib/http_stub/{server/formatted_hash_spec.rb → extensions/core/hash/formatted_spec.rb} +4 -6
  60. data/spec/lib/http_stub/{hash_with_indifferent_and_insensitive_access_spec.rb → extensions/core/hash/indifferent_and_insensitive_access_spec.rb} +8 -4
  61. data/spec/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access_spec.rb +41 -0
  62. data/spec/lib/http_stub/extensions/core/hash_spec.rb +11 -129
  63. data/spec/lib/http_stub/server/application_spec.rb +1 -1
  64. data/spec/lib/http_stub/server/payload_file_consolidator_spec.rb +1 -1
  65. data/spec/lib/http_stub/server/request/headers_spec.rb +89 -0
  66. data/spec/lib/http_stub/server/request/parameters_spec.rb +60 -0
  67. data/spec/lib/http_stub/server/request/request_spec.rb +84 -0
  68. data/spec/lib/http_stub/server/request_spec.rb +9 -98
  69. data/spec/lib/http_stub/server/response_spec.rb +2 -6
  70. data/spec/lib/http_stub/server/scenario/controller_spec.rb +1 -1
  71. data/spec/lib/http_stub/server/scenario/parser_spec.rb +3 -1
  72. data/spec/lib/http_stub/server/stub/controller_spec.rb +11 -4
  73. data/spec/lib/http_stub/server/stub/empty_spec.rb +10 -0
  74. data/spec/lib/http_stub/server/stub/match/hash_matcher_spec.rb +122 -0
  75. data/spec/lib/http_stub/server/stub/match/rule/body_spec.rb +4 -4
  76. data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +54 -45
  77. data/spec/lib/http_stub/server/stub/match/rule/json_body_spec.rb +5 -5
  78. data/spec/lib/http_stub/server/stub/match/rule/method_spec.rb +19 -17
  79. data/spec/lib/http_stub/server/stub/match/rule/parameters_spec.rb +26 -33
  80. data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +16 -25
  81. data/spec/lib/http_stub/server/stub/match/{truthy_matcher_spec.rb → rule/truthy_spec.rb} +3 -5
  82. data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +16 -25
  83. data/spec/lib/http_stub/server/stub/match/string_value_matcher_spec.rb +2 -12
  84. data/spec/lib/http_stub/server/stub/parser_spec.rb +5 -3
  85. data/spec/lib/http_stub/server/stub/response/attribute/body_spec.rb +98 -0
  86. data/spec/lib/http_stub/server/stub/response/attribute/headers_spec.rb +57 -0
  87. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/headers_spec.rb +53 -0
  88. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/parameters_spec.rb +53 -0
  89. data/spec/lib/http_stub/server/stub/response/attribute/interpolator_spec.rb +41 -0
  90. data/spec/lib/http_stub/server/stub/response/base_spec.rb +6 -53
  91. data/spec/lib/http_stub/server/stub/response/file_spec.rb +48 -7
  92. data/spec/lib/http_stub/server/stub/response/text_spec.rb +66 -1
  93. data/spec/lib/http_stub/server/stub/stub_spec.rb +25 -4
  94. data/spec/spec_helper.rb +1 -0
  95. data/spec/support/http_stub/server/request_fixture.rb +1 -1
  96. metadata +86 -26
  97. data/lib/http_stub/hash_with_indifferent_and_insensitive_access.rb +0 -18
  98. data/lib/http_stub/server/formatted_hash.rb +0 -18
  99. data/lib/http_stub/server/header_parser.rb +0 -17
  100. data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +0 -26
  101. data/lib/http_stub/server/stub/match/truthy_matcher.rb +0 -25
  102. data/spec/lib/http_stub/server/header_parser_spec.rb +0 -51
  103. data/spec/lib/http_stub/server/stub/match/hash_with_string_value_matchers_spec.rb +0 -166
@@ -1,13 +1,13 @@
1
1
  describe HttpStub::Server::Stub::Match::Rule::JsonBody do
2
2
 
3
- let(:stubbed_schema_definition) { { "type" => "object", "properties" => { "some_property" => "some_type" } } }
3
+ let(:stub_schema_definition) { { "type" => "object", "properties" => { "some_property" => "some_type" } } }
4
4
 
5
- let(:json_body) { described_class.new(stubbed_schema_definition) }
5
+ let(:json_body) { described_class.new(stub_schema_definition) }
6
6
 
7
7
  describe "#matches?" do
8
8
 
9
9
  let(:request_body) { { "some_json_property" => "some_json_value" }.to_json }
10
- let(:request) { instance_double(HttpStub::Server::Request, body: request_body) }
10
+ let(:request) { instance_double(HttpStub::Server::Request::Request, body: request_body) }
11
11
  let(:logger) { instance_double(Logger, info: nil) }
12
12
 
13
13
  let(:validation_errors) { [] }
@@ -17,7 +17,7 @@ describe HttpStub::Server::Stub::Match::Rule::JsonBody do
17
17
  before(:example) { allow(JSON::Validator).to receive(:fully_validate).and_return(validation_errors) }
18
18
 
19
19
  it "validates the request body using the stubbed schema definition" do
20
- expect(JSON::Validator).to receive(:fully_validate).with(stubbed_schema_definition, request_body, anything)
20
+ expect(JSON::Validator).to receive(:fully_validate).with(stub_schema_definition, request_body, anything)
21
21
 
22
22
  subject
23
23
  end
@@ -93,7 +93,7 @@ describe HttpStub::Server::Stub::Match::Rule::JsonBody do
93
93
  subject { json_body.to_s }
94
94
 
95
95
  it "returns the JSON representation of the schema definition" do
96
- expect(subject).to eql(stubbed_schema_definition.to_json)
96
+ expect(subject).to eql(stub_schema_definition.to_json)
97
97
  end
98
98
 
99
99
  end
@@ -1,20 +1,20 @@
1
1
  describe HttpStub::Server::Stub::Match::Rule::Method do
2
2
 
3
- let(:raw_stub_method) { "put" }
3
+ let(:stub_method) { "put" }
4
4
 
5
- let(:the_method) { described_class.new(raw_stub_method) }
5
+ let(:the_method) { described_class.new(stub_method) }
6
6
 
7
7
  describe "#matches?" do
8
8
 
9
9
  let(:request_method) { "get" }
10
- let(:request) { instance_double(HttpStub::Server::Request, method: request_method) }
10
+ let(:request) { instance_double(HttpStub::Server::Request::Request, method: request_method) }
11
11
  let(:logger) { instance_double(Logger) }
12
12
 
13
13
  subject { the_method.matches?(request, logger) }
14
14
 
15
15
  context "when the request method is identical to the stub method" do
16
16
 
17
- let(:request_method) { raw_stub_method }
17
+ let(:request_method) { stub_method }
18
18
 
19
19
  it "returns true" do
20
20
  expect(subject).to be(true)
@@ -22,9 +22,9 @@ describe HttpStub::Server::Stub::Match::Rule::Method do
22
22
 
23
23
  end
24
24
 
25
- context "when the request method and stub method are the the same value but have different casing" do
25
+ context "when the stub method and request method are the the same value but have different casing" do
26
26
 
27
- let(:raw_stub_method) { "GET" }
27
+ let(:stub_method) { "GET" }
28
28
 
29
29
  it "returns true" do
30
30
  expect(subject).to be(true)
@@ -36,7 +36,7 @@ describe HttpStub::Server::Stub::Match::Rule::Method do
36
36
 
37
37
  context "with a nil value" do
38
38
 
39
- let(:raw_stub_method) { nil }
39
+ let(:stub_method) { nil }
40
40
 
41
41
  it "returns true" do
42
42
  expect(subject).to be(true)
@@ -46,7 +46,7 @@ describe HttpStub::Server::Stub::Match::Rule::Method do
46
46
 
47
47
  context "with an empty string" do
48
48
 
49
- let(:raw_stub_method) { "" }
49
+ let(:stub_method) { "" }
50
50
 
51
51
  it "returns true" do
52
52
  expect(subject).to be(true)
@@ -56,10 +56,10 @@ describe HttpStub::Server::Stub::Match::Rule::Method do
56
56
 
57
57
  end
58
58
 
59
- context "when the request method is different to the stub method" do
59
+ context "when the stub method is different to the request method" do
60
60
 
61
+ let(:stub_method) { "delete" }
61
62
  let(:request_method) { "get" }
62
- let(:raw_stub_method) { "delete" }
63
63
 
64
64
  it "returns false" do
65
65
  expect(subject).to be(false)
@@ -71,22 +71,24 @@ describe HttpStub::Server::Stub::Match::Rule::Method do
71
71
 
72
72
  describe "#to_s" do
73
73
 
74
- context "when the stub method provided is not nil" do
74
+ subject { the_method.to_s }
75
75
 
76
- let(:raw_stub_method) { "not_nil" }
76
+ context "when the stub method is not nil" do
77
77
 
78
- it "returns the stub method provided" do
79
- expect(the_method.to_s).to eql(raw_stub_method)
78
+ let(:stub_method) { "present" }
79
+
80
+ it "returns the stub method" do
81
+ expect(subject).to eql(stub_method)
80
82
  end
81
83
 
82
84
  end
83
85
 
84
- context "when the stub method provided is nil" do
86
+ context "when the stub method is nil" do
85
87
 
86
- let(:raw_stub_method) { nil }
88
+ let(:stub_method) { nil }
87
89
 
88
90
  it "returns an empty string" do
89
- expect(the_method.to_s).to eql("")
91
+ expect(subject).to eql("")
90
92
  end
91
93
 
92
94
  end
@@ -1,64 +1,57 @@
1
1
  describe HttpStub::Server::Stub::Match::Rule::Parameters do
2
2
 
3
- let(:raw_request_parameters) { double("RequestParameters") }
4
- let(:request) { instance_double(HttpStub::Server::Request, parameters: raw_request_parameters) }
3
+ let(:stub_parameters) { (1..3).each_with_object({}) { |i, result| result["key#{i}"] = "value#{i}" } }
5
4
 
6
- let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
7
- let(:regexpable_stubbed_paremeters) do
8
- double(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).as_null_object
9
- end
5
+ let(:parameters) { described_class.new(stub_parameters) }
10
6
 
11
- let(:request_parameters) { described_class.new(stubbed_parameters) }
7
+ it "is a hash with indifferent access" do
8
+ expect(parameters).to be_a(::HashWithIndifferentAccess)
9
+ end
12
10
 
13
- describe "when stubbed parameters are provided" do
11
+ context "when no parameters are provided" do
14
12
 
15
- it "creates a regexpable representation of the stubbed parameters" do
16
- expect(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to receive(:new).with(stubbed_parameters)
13
+ let(:stub_parameters) { nil }
17
14
 
18
- request_parameters
15
+ it "is empty" do
16
+ expect(parameters.empty?).to be(true)
19
17
  end
20
18
 
21
19
  end
22
20
 
23
- describe "when the stubbed parameters are nil" do
21
+ describe "#matches?" do
24
22
 
25
- let(:stubbed_parameters) { nil }
23
+ let(:request_parameters) { instance_double(HttpStub::Server::Request::Parameters) }
24
+ let(:request) { instance_double(HttpStub::Server::Request::Request, parameters: request_parameters) }
25
+ let(:logger) { instance_double(Logger) }
26
26
 
27
- it "creates a regexpable representation of an empty hash" do
28
- expect(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to receive(:new).with({})
27
+ subject { parameters.matches?(request, logger) }
29
28
 
30
- request_parameters
31
- end
29
+ it "determines if the stub parameter and request parameter hashes match" do
30
+ expect(HttpStub::Server::Stub::Match::HashMatcher).to receive(:match?).with(parameters, request_parameters)
32
31
 
33
- end
34
-
35
- describe "#matches?" do
36
-
37
- let(:logger) { instance_double(Logger) }
32
+ subject
33
+ end
38
34
 
39
- it "delegates to the regexpable representation of the stubbed parameters to determine a match" do
40
- allow(HttpStub::Server::Stub::Match::HashWithStringValueMatchers).to(
41
- receive(:new).and_return(regexpable_stubbed_paremeters)
42
- )
43
- expect(regexpable_stubbed_paremeters).to receive(:matches?).with(raw_request_parameters).and_return(true)
35
+ it "returns the result of the match" do
36
+ allow(HttpStub::Server::Stub::Match::HashMatcher).to receive(:match?).and_return(true)
44
37
 
45
- expect(request_parameters.matches?(request, logger)).to be(true)
38
+ expect(subject).to eql(true)
46
39
  end
47
40
 
48
41
  end
49
42
 
50
43
  describe "#to_s" do
51
44
 
52
- subject { request_parameters.to_s }
45
+ subject { parameters.to_s }
53
46
 
54
47
  describe "when multiple parameters are provided" do
55
48
 
56
- let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
49
+ let(:stub_parameters) { (1..3).each_with_object({}) { |i, result| result["key#{i}"] = "value#{i}" } }
57
50
 
58
51
  it "returns a string containing each parameter formatted as a conventional request parameter" do
59
52
  result = subject
60
53
 
61
- stubbed_parameters.each { |key, value| expect(result).to match(/#{key}=#{value}/) }
54
+ stub_parameters.each { |key, value| expect(result).to match(/#{key}=#{value}/) }
62
55
  end
63
56
 
64
57
  it "separates each parameter with the conventional request parameter delimiter" do
@@ -69,7 +62,7 @@ describe HttpStub::Server::Stub::Match::Rule::Parameters do
69
62
 
70
63
  describe "when empty parameters are provided" do
71
64
 
72
- let(:stubbed_parameters) { {} }
65
+ let(:stub_parameters) { {} }
73
66
 
74
67
  it "returns an empty string" do
75
68
  expect(subject).to eql("")
@@ -79,7 +72,7 @@ describe HttpStub::Server::Stub::Match::Rule::Parameters do
79
72
 
80
73
  describe "when nil parameters are provided" do
81
74
 
82
- let(:stubbed_parameters) { nil }
75
+ let(:stub_parameters) { nil }
83
76
 
84
77
  it "returns an empty string" do
85
78
  expect(subject).to eql("")
@@ -1,44 +1,35 @@
1
1
  describe HttpStub::Server::Stub::Match::Rule::SimpleBody do
2
2
 
3
- let(:raw_body) { "some body" }
4
- let(:value_matcher) { instance_double(HttpStub::Server::Stub::Match::StringValueMatcher).as_null_object }
3
+ let(:stub_body) { "some body" }
5
4
 
6
- let(:simple_body) { described_class.new(raw_body) }
7
-
8
- before(:example) do
9
- allow(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).and_return(value_matcher)
10
- end
11
-
12
- describe "constructor" do
13
-
14
- it "creates a value matcher for the provided body" do
15
- expect(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).with(raw_body)
16
-
17
- simple_body
18
- end
19
-
20
- end
5
+ let(:simple_body) { described_class.new(stub_body) }
21
6
 
22
7
  describe "#matches?" do
23
8
 
24
9
  let(:request_body) { "some request body" }
25
- let(:request) { instance_double(HttpStub::Server::Request, body: request_body) }
10
+ let(:request) { instance_double(HttpStub::Server::Request::Request, body: request_body) }
26
11
  let(:logger) { instance_double(Logger) }
27
12
 
28
- it "delegates to the value matcher to match the request body" do
29
- expect(value_matcher).to receive(:matches?).with(request_body).and_return(true)
13
+ subject { simple_body.matches?(request, logger) }
14
+
15
+ it "determines if the stub uri and request uri strings match" do
16
+ expect(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:match?).with(stub_body, request_body)
17
+
18
+ subject
19
+ end
20
+
21
+ it "returns the result of the match" do
22
+ allow(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:match?).and_return(true)
30
23
 
31
- expect(simple_body.matches?(request, logger)).to be(true)
24
+ expect(subject).to eql(true)
32
25
  end
33
26
 
34
27
  end
35
28
 
36
29
  describe "#to_s" do
37
30
 
38
- it "delegates to the value matcher representation of the provided body" do
39
- expect(value_matcher).to receive(:to_s).and_return("some value matcher string")
40
-
41
- expect(simple_body.to_s).to eql("some value matcher string")
31
+ it "returns the stub body" do
32
+ expect(simple_body.to_s).to eql(stub_body)
42
33
  end
43
34
 
44
35
  end
@@ -1,6 +1,4 @@
1
- describe HttpStub::Server::Stub::Match::TruthyMatcher do
2
-
3
- let(:truthy_matcher) { described_class }
1
+ describe HttpStub::Server::Stub::Match::Rule::Truthy do
4
2
 
5
3
  describe "::matches?" do
6
4
 
@@ -8,7 +6,7 @@ describe HttpStub::Server::Stub::Match::TruthyMatcher do
8
6
  let(:logger) { instance_double(Logger) }
9
7
 
10
8
  it "returns true" do
11
- expect(truthy_matcher.matches?(request, logger)).to be(true)
9
+ expect(described_class.matches?(request, logger)).to be(true)
12
10
  end
13
11
 
14
12
  end
@@ -16,7 +14,7 @@ describe HttpStub::Server::Stub::Match::TruthyMatcher do
16
14
  describe "::to_s" do
17
15
 
18
16
  it "returns an empty string" do
19
- expect(truthy_matcher.to_s).to eql("")
17
+ expect(described_class.to_s).to eql("")
20
18
  end
21
19
 
22
20
  end
@@ -1,44 +1,35 @@
1
1
  describe HttpStub::Server::Stub::Match::Rule::Uri do
2
2
 
3
- let(:raw_uri) { "/some/uri" }
4
- let(:value_matcher) { instance_double(HttpStub::Server::Stub::Match::StringValueMatcher).as_null_object }
3
+ let(:stub_uri) { "/some/uri" }
5
4
 
6
- let(:uri) { described_class.new(raw_uri) }
7
-
8
- before(:example) do
9
- allow(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).and_return(value_matcher)
10
- end
11
-
12
- describe "constructor" do
13
-
14
- it "creates a value matcher for the provided uri" do
15
- expect(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:new).with(raw_uri)
16
-
17
- uri
18
- end
19
-
20
- end
5
+ let(:uri) { described_class.new(stub_uri) }
21
6
 
22
7
  describe "#matches?" do
23
8
 
24
9
  let(:request_uri) { "/some/uri" }
25
- let(:request) { instance_double(HttpStub::Server::Request, uri: request_uri) }
10
+ let(:request) { instance_double(HttpStub::Server::Request::Request, uri: request_uri) }
26
11
  let(:logger) { instance_double(Logger) }
27
12
 
28
- it "delegates to the value matcher representation of the provided uri" do
29
- expect(value_matcher).to receive(:matches?).with(request_uri).and_return(true)
13
+ subject { uri.matches?(request, logger) }
14
+
15
+ it "determines if the stub uri and request uri strings match" do
16
+ expect(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:match?).with(stub_uri, request_uri)
17
+
18
+ subject
19
+ end
20
+
21
+ it "returns the result of the match" do
22
+ allow(HttpStub::Server::Stub::Match::StringValueMatcher).to receive(:match?).and_return(true)
30
23
 
31
- expect(uri.matches?(request, logger)).to be(true)
24
+ expect(subject).to eql(true)
32
25
  end
33
26
 
34
27
  end
35
28
 
36
29
  describe "#to_s" do
37
30
 
38
- it "delegates to the value matcher representation of the provided uri" do
39
- expect(value_matcher).to receive(:to_s).and_return("some value matcher string")
40
-
41
- expect(uri.to_s).to eql("some value matcher string")
31
+ it "returns the stub uri" do
32
+ expect(uri.to_s).to eql(stub_uri)
42
33
  end
43
34
 
44
35
  end
@@ -2,13 +2,11 @@ describe HttpStub::Server::Stub::Match::StringValueMatcher do
2
2
 
3
3
  let(:stub_value) { "some stub value" }
4
4
 
5
- let(:string_value_matcher) { HttpStub::Server::Stub::Match::StringValueMatcher.new(stub_value) }
6
-
7
- describe "#matches?" do
5
+ describe "::match?" do
8
6
 
9
7
  let(:actual_value) { "some actual value" }
10
8
 
11
- subject { string_value_matcher.matches?(actual_value) }
9
+ subject { described_class.match?(stub_value, actual_value) }
12
10
 
13
11
  shared_examples_for "a StringValueMatcher that matches an expected stub value" do
14
12
 
@@ -126,12 +124,4 @@ describe HttpStub::Server::Stub::Match::StringValueMatcher do
126
124
 
127
125
  end
128
126
 
129
- describe "#to_s" do
130
-
131
- it "returns the stub value provided" do
132
- expect(string_value_matcher.to_s).to eql(stub_value)
133
- end
134
-
135
- end
136
-
137
127
  end
@@ -6,14 +6,16 @@ describe HttpStub::Server::Stub::Parser do
6
6
 
7
7
  let(:parameters) { {} }
8
8
  let(:body_hash) { {} }
9
- let(:request) { instance_double(HttpStub::Server::Request, parameters: parameters, body: body_hash.to_json) }
9
+ let(:request) do
10
+ instance_double(HttpStub::Server::Request::Request, parameters: parameters, body: body_hash.to_json)
11
+ end
10
12
 
11
13
  subject { parser.parse(request) }
12
14
 
13
15
  context "when the request contains a payload parameter" do
14
16
 
15
- let(:payload) { HttpStub::StubFixture.new.server_payload }
16
- let(:parameters) { { "payload" => payload.to_json } }
17
+ let(:payload) { HttpStub::StubFixture.new.server_payload }
18
+ let(:parameters) { { "payload" => payload.to_json } }
17
19
 
18
20
  it "consolidates any files into the payload" do
19
21
  expect(HttpStub::Server::Stub::PayloadFileConsolidator).to receive(:consolidate!).with(payload, request)
@@ -0,0 +1,98 @@
1
+ describe HttpStub::Server::Stub::Response::Attribute::Body do
2
+
3
+ let(:body) { described_class.new(stub_body) }
4
+
5
+ describe "#with_values_from" do
6
+
7
+ let(:request) { HttpStub::Server::Request::Request }
8
+
9
+ subject { body.with_values_from(request) }
10
+
11
+ context "when a body is provided" do
12
+
13
+ let(:stub_body) { "some stub body" }
14
+
15
+ it "interpolates the stub body with values from the request" do
16
+ expect(HttpStub::Server::Stub::Response::Attribute::Interpolator).to(
17
+ receive(:interpolate).with(stub_body, request)
18
+ )
19
+
20
+ subject
21
+ end
22
+
23
+ it "returns the interpolation result" do
24
+ interpolated_body = "some interpolated body"
25
+ allow(HttpStub::Server::Stub::Response::Attribute::Interpolator).to(
26
+ receive(:interpolate).and_return(interpolated_body)
27
+ )
28
+
29
+ expect(subject).to eql(interpolated_body)
30
+ end
31
+
32
+ end
33
+
34
+ context "when the body is nil" do
35
+
36
+ let(:stub_body) { nil }
37
+
38
+ it "returns nil" do
39
+ expect(subject).to eql(nil)
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe "#provided?" do
47
+
48
+ subject { body.provided? }
49
+
50
+ context "when the provided body is not nil" do
51
+
52
+ let(:stub_body) { "" }
53
+
54
+ it "returns true" do
55
+ expect(subject).to eql(true)
56
+ end
57
+
58
+ end
59
+
60
+ context "when the provided body is nil" do
61
+
62
+ let(:stub_body) { nil }
63
+
64
+ it "returns false" do
65
+ expect(subject).to eql(false)
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ describe "#to_s" do
73
+
74
+ subject { body.to_s }
75
+
76
+ context "when a body is provided" do
77
+
78
+ let(:stub_body) { "some stub body" }
79
+
80
+ it "returns the stub body" do
81
+ expect(subject).to eql(stub_body)
82
+ end
83
+
84
+ end
85
+
86
+ context "when the body is nil" do
87
+
88
+ let(:stub_body) { nil }
89
+
90
+ it "returns an empty string" do
91
+ expect(subject).to eql("")
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ end