http_stub 0.19.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +13 -5
  2. data/lib/http_stub.rb +26 -21
  3. data/lib/http_stub/configurer/server/command_processor.rb +1 -0
  4. data/lib/http_stub/server/application.rb +24 -46
  5. data/lib/http_stub/server/formatted_hash.rb +18 -0
  6. data/lib/http_stub/server/header_parser.rb +17 -0
  7. data/lib/http_stub/server/registry.rb +9 -9
  8. data/lib/http_stub/server/request.rb +19 -0
  9. data/lib/http_stub/server/request_pipeline.rb +27 -0
  10. data/lib/http_stub/server/response.rb +7 -3
  11. data/lib/http_stub/server/scenario.rb +1 -1
  12. data/lib/http_stub/server/scenario/activator.rb +4 -4
  13. data/lib/http_stub/server/scenario/controller.rb +8 -8
  14. data/lib/http_stub/server/scenario/{request_parser.rb → parser.rb} +2 -2
  15. data/lib/http_stub/server/scenario/{instance.rb → scenario.rb} +2 -2
  16. data/lib/http_stub/server/stub.rb +1 -1
  17. data/lib/http_stub/server/stub/controller.rb +8 -8
  18. data/lib/http_stub/server/stub/empty.rb +34 -0
  19. data/lib/http_stub/server/stub/match/exact_value_matcher.rb +17 -0
  20. data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +26 -0
  21. data/lib/http_stub/server/stub/match/match.rb +20 -0
  22. data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +23 -0
  23. data/lib/http_stub/server/stub/match/regexp_value_matcher.rb +18 -0
  24. data/lib/http_stub/server/stub/match/rule/body.rb +49 -0
  25. data/lib/http_stub/server/stub/match/rule/headers.rb +31 -0
  26. data/lib/http_stub/server/stub/match/rule/json_body.rb +39 -0
  27. data/lib/http_stub/server/stub/match/rule/method.rb +27 -0
  28. data/lib/http_stub/server/stub/match/rule/parameters.rb +27 -0
  29. data/lib/http_stub/server/stub/match/rule/simple_body.rb +27 -0
  30. data/lib/http_stub/server/stub/match/rule/uri.rb +27 -0
  31. data/lib/http_stub/server/stub/match/string_value_matcher.rb +33 -0
  32. data/lib/http_stub/server/stub/match/truthy_matcher.rb +25 -0
  33. data/lib/http_stub/server/stub/{request_parser.rb → parser.rb} +2 -2
  34. data/lib/http_stub/server/stub/payload_file_consolidator.rb +1 -1
  35. data/lib/http_stub/server/stub/registry.rb +16 -8
  36. data/lib/http_stub/server/stub/response/base.rb +2 -2
  37. data/lib/http_stub/server/stub/stub.rb +44 -0
  38. data/lib/http_stub/server/stub/triggers.rb +2 -2
  39. data/lib/http_stub/server/views/_match.haml +20 -0
  40. data/lib/http_stub/server/views/matches.haml +3 -0
  41. data/lib/http_stub/server/views/stub.haml +1 -0
  42. data/lib/http_stub/version.rb +1 -1
  43. data/spec/acceptance/stub_control_values_spec.rb +6 -3
  44. data/spec/acceptance/stub_match_spec.rb +142 -0
  45. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +4 -0
  46. data/spec/lib/http_stub/server/application_integration_spec.rb +17 -18
  47. data/spec/lib/http_stub/server/application_spec.rb +81 -53
  48. data/spec/lib/http_stub/server/formatted_hash_spec.rb +54 -0
  49. data/spec/lib/http_stub/server/{stub/request_header_parser_spec.rb → header_parser_spec.rb} +9 -9
  50. data/spec/lib/http_stub/server/{request_file_consolidator_spec.rb → payload_file_consolidator_spec.rb} +4 -4
  51. data/spec/lib/http_stub/server/registry_spec.rb +13 -14
  52. data/spec/lib/http_stub/server/request_pipeline_spec.rb +80 -0
  53. data/spec/lib/http_stub/server/request_spec.rb +113 -0
  54. data/spec/lib/http_stub/server/response_spec.rb +46 -12
  55. data/spec/lib/http_stub/server/scenario/activator_spec.rb +18 -18
  56. data/spec/lib/http_stub/server/scenario/controller_spec.rb +18 -15
  57. data/spec/lib/http_stub/server/scenario/{request_parser_spec.rb → parser_spec.rb} +8 -8
  58. data/spec/lib/http_stub/server/scenario/{instance_spec.rb → scenario_spec.rb} +7 -5
  59. data/spec/lib/http_stub/server/scenario_spec.rb +3 -3
  60. data/spec/lib/http_stub/server/stub/controller_spec.rb +29 -14
  61. data/spec/lib/http_stub/server/stub/empty_spec.rb +68 -0
  62. data/spec/lib/http_stub/server/stub/{exact_value_matcher_spec.rb → match/exact_value_matcher_spec.rb} +2 -2
  63. data/spec/lib/http_stub/server/stub/{hash_with_string_value_matchers_spec.rb → match/hash_with_string_value_matchers_spec.rb} +27 -19
  64. data/spec/lib/http_stub/server/stub/match/match_spec.rb +40 -0
  65. data/spec/lib/http_stub/server/stub/{omitted_value_matcher_spec.rb → match/omitted_value_matcher_spec.rb} +2 -2
  66. data/spec/lib/http_stub/server/stub/{regexp_value_matcher_spec.rb → match/regexp_value_matcher_spec.rb} +2 -2
  67. data/spec/lib/http_stub/server/stub/{request_body_spec.rb → match/rule/body_spec.rb} +12 -12
  68. data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +90 -0
  69. data/spec/lib/http_stub/server/stub/{json_request_body_spec.rb → match/rule/json_body_spec.rb} +9 -10
  70. data/spec/lib/http_stub/server/stub/{method_spec.rb → match/rule/method_spec.rb} +6 -5
  71. data/spec/lib/http_stub/server/stub/{request_parameters_spec.rb → match/rule/parameters_spec.rb} +16 -10
  72. data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +46 -0
  73. data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +46 -0
  74. data/spec/lib/http_stub/server/stub/{string_value_matcher_spec.rb → match/string_value_matcher_spec.rb} +30 -26
  75. data/spec/lib/http_stub/server/stub/match/truthy_matcher_spec.rb +24 -0
  76. data/spec/lib/http_stub/server/stub/{request_parser_spec.rb → parser_spec.rb} +7 -7
  77. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +5 -5
  78. data/spec/lib/http_stub/server/stub/registry_spec.rb +114 -43
  79. data/spec/lib/http_stub/server/stub/response/base_spec.rb +8 -2
  80. data/spec/lib/http_stub/server/stub/stub_spec.rb +294 -0
  81. data/spec/lib/http_stub/server/stub/triggers_spec.rb +4 -4
  82. data/spec/lib/http_stub/server/stub_spec.rb +3 -3
  83. data/spec/spec_helper.rb +7 -3
  84. data/spec/support/configurer_integration.rb +1 -0
  85. data/spec/support/http_stub/empty_configurer.rb +7 -0
  86. data/spec/support/{scenario_fixture.rb → http_stub/scenario_fixture.rb} +0 -0
  87. data/spec/support/http_stub/server/request_fixture.rb +25 -0
  88. data/spec/support/http_stub/server/scenario/scenario_fixture.rb +15 -0
  89. data/spec/support/http_stub/server/stub/match/match_fixture.rb +17 -0
  90. data/spec/support/{stub_fixture.rb → http_stub/stub_fixture.rb} +0 -0
  91. data/spec/support/server_integration.rb +1 -0
  92. metadata +315 -290
  93. data/lib/http_stub/server/stub/exact_value_matcher.rb +0 -15
  94. data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +0 -22
  95. data/lib/http_stub/server/stub/headers.rb +0 -19
  96. data/lib/http_stub/server/stub/instance.rb +0 -32
  97. data/lib/http_stub/server/stub/json_request_body.rb +0 -35
  98. data/lib/http_stub/server/stub/method.rb +0 -23
  99. data/lib/http_stub/server/stub/omitted_value_matcher.rb +0 -21
  100. data/lib/http_stub/server/stub/regexp_value_matcher.rb +0 -16
  101. data/lib/http_stub/server/stub/request_body.rb +0 -44
  102. data/lib/http_stub/server/stub/request_header_parser.rb +0 -19
  103. data/lib/http_stub/server/stub/request_headers.rb +0 -28
  104. data/lib/http_stub/server/stub/request_parameters.rb +0 -23
  105. data/lib/http_stub/server/stub/simple_request_body.rb +0 -23
  106. data/lib/http_stub/server/stub/string_value_matcher.rb +0 -31
  107. data/lib/http_stub/server/stub/truthy_request_matcher.rb +0 -23
  108. data/lib/http_stub/server/stub/uri.rb +0 -23
  109. data/spec/lib/http_stub/server/stub/headers_spec.rb +0 -51
  110. data/spec/lib/http_stub/server/stub/instance_spec.rb +0 -235
  111. data/spec/lib/http_stub/server/stub/request_headers_spec.rb +0 -68
  112. data/spec/lib/http_stub/server/stub/simple_request_body_spec.rb +0 -43
  113. data/spec/lib/http_stub/server/stub/truthy_request_matcher_spec.rb +0 -23
  114. data/spec/lib/http_stub/server/stub/uri_spec.rb +0 -43
@@ -0,0 +1,33 @@
1
+ module HttpStub
2
+ module Server
3
+ module Stub
4
+ module Match
5
+
6
+ class StringValueMatcher
7
+
8
+ private
9
+
10
+ MATCHERS = [ HttpStub::Server::Stub::Match::OmittedValueMatcher,
11
+ HttpStub::Server::Stub::Match::RegexpValueMatcher,
12
+ HttpStub::Server::Stub::Match::ExactValueMatcher ].freeze
13
+
14
+ public
15
+
16
+ def initialize(stub_value)
17
+ @stub_match_value = stub_value ? stub_value.to_s : stub_value
18
+ end
19
+
20
+ def matches?(actual_value)
21
+ !!MATCHERS.find { |matcher| matcher.match?(@stub_match_value, actual_value) }
22
+ end
23
+
24
+ def to_s
25
+ @stub_match_value
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module HttpStub
2
+ module Server
3
+ module Stub
4
+ module Match
5
+
6
+ class TruthyMatcher
7
+
8
+ class << self
9
+
10
+ def matches?(_request, _logger)
11
+ true
12
+ end
13
+
14
+ def to_s
15
+ ""
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,11 +2,11 @@ module HttpStub
2
2
  module Server
3
3
  module Stub
4
4
 
5
- class RequestParser
5
+ class Parser
6
6
 
7
7
  def self.parse(request)
8
8
  HttpStub::Server::Stub::PayloadFileConsolidator.consolidate!(
9
- JSON.parse(request.params["payload"] || request.body.read), request
9
+ JSON.parse(request.parameters["payload"] || request.body), request
10
10
  )
11
11
  end
12
12
 
@@ -5,7 +5,7 @@ module HttpStub
5
5
  class PayloadFileConsolidator
6
6
 
7
7
  def self.consolidate!(payload, request)
8
- response_file = request.params["response_file_#{payload["id"]}"]
8
+ response_file = request.parameters["response_file_#{payload["id"]}"]
9
9
  payload["response"]["body"] = response_file if response_file
10
10
  payload["triggers"].each { |trigger_payload| consolidate!(trigger_payload, request) } if payload["triggers"]
11
11
  payload
@@ -4,24 +4,32 @@ module HttpStub
4
4
 
5
5
  class Registry
6
6
 
7
- delegate :add, :concat, :all, :clear, to: :@registry
7
+ delegate :add, :concat, :all, to: :@stub_registry
8
8
 
9
- def initialize
10
- @registry = HttpStub::Server::Registry.new("stub")
9
+ def initialize(match_registry)
10
+ @match_registry = match_registry
11
+ @stub_registry = HttpStub::Server::Registry.new("stub")
11
12
  end
12
13
 
13
- def find_for(request)
14
- stub = @registry.find(criteria: request, request: request)
15
- stub.triggers.add_to(self, request) if stub
14
+ def find(criteria, logger)
15
+ stub = @stub_registry.find(criteria, logger)
16
+ if stub && criteria.is_a?(HttpStub::Server::Request)
17
+ @match_registry.add(HttpStub::Server::Stub::Match::Match.new(stub, criteria), logger)
18
+ stub.triggers.add_to(self, logger)
19
+ end
16
20
  stub
17
21
  end
18
22
 
19
23
  def remember
20
- @remembered_stub = @registry.last
24
+ @remembered_stub = @stub_registry.last
21
25
  end
22
26
 
23
27
  def recall
24
- @registry.rollback_to(@remembered_stub) if @remembered_stub
28
+ @stub_registry.rollback_to(@remembered_stub) if @remembered_stub
29
+ end
30
+
31
+ def clear(logger)
32
+ [ @match_registry, @stub_registry ].each { |registry| registry.clear(logger) }
25
33
  end
26
34
 
27
35
  end
@@ -33,15 +33,15 @@ module HttpStub
33
33
 
34
34
  end
35
35
 
36
- attr_reader :status, :body, :delay_in_seconds, :headers
36
+ attr_reader :status, :headers, :body, :delay_in_seconds
37
37
 
38
38
  def initialize(args={})
39
39
  @original_args = args
40
40
  resolved_args = self.class.merge_defaults(args)
41
41
  @status = resolved_args["status"]
42
+ @headers = HttpStub::Server::FormattedHash.new(resolved_args["headers"], ":")
42
43
  @body = resolved_args["body"]
43
44
  @delay_in_seconds = resolved_args["delay_in_seconds"]
44
- @headers = HttpStub::Server::Stub::Headers.new(resolved_args["headers"])
45
45
  end
46
46
 
47
47
  def empty?
@@ -0,0 +1,44 @@
1
+ module HttpStub
2
+ module Server
3
+ module Stub
4
+
5
+ class Stub
6
+
7
+ attr_reader :uri, :method, :headers, :parameters, :body, :response, :triggers, :stub_uri
8
+
9
+ def initialize(args)
10
+ @id = args["id"] || SecureRandom.uuid
11
+ @uri = HttpStub::Server::Stub::Match::Rule::Uri.new(args["uri"])
12
+ @method = HttpStub::Server::Stub::Match::Rule::Method.new(args["method"])
13
+ @headers = HttpStub::Server::Stub::Match::Rule::Headers.new(args["headers"])
14
+ @parameters = HttpStub::Server::Stub::Match::Rule::Parameters.new(args["parameters"])
15
+ @body = HttpStub::Server::Stub::Match::Rule::Body.create(args["body"])
16
+ @response = HttpStub::Server::Stub::Response.create(args["response"])
17
+ @triggers = HttpStub::Server::Stub::Triggers.new(args["triggers"])
18
+ @stub_uri = "/stubs/#{@id}"
19
+ @description = args.to_s
20
+ end
21
+
22
+ def matches?(criteria, logger)
23
+ criteria.is_a?(String) ? matches_by_id?(criteria) : matches_by_rules?(criteria, logger)
24
+ end
25
+
26
+ def to_s
27
+ @description
28
+ end
29
+
30
+ private
31
+
32
+ def matches_by_id?(criteria)
33
+ criteria == @id
34
+ end
35
+
36
+ def matches_by_rules?(request, logger)
37
+ [ @uri, @method, @headers, @parameters, @body ].all? { |matcher| matcher.matches?(request, logger) }
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -10,8 +10,8 @@ module HttpStub
10
10
  @triggers = (triggers || []).map { |trigger| HttpStub::Server::Stub.create(trigger) }
11
11
  end
12
12
 
13
- def add_to(registry, request)
14
- @triggers.each { |trigger| registry.add(trigger, request) }
13
+ def add_to(registry, logger)
14
+ @triggers.each { |trigger| registry.add(trigger, logger) }
15
15
  end
16
16
 
17
17
  def to_s
@@ -0,0 +1,20 @@
1
+ %table
2
+ %tr
3
+ %td URI:
4
+ %td=h(match.request.uri)
5
+ %tr
6
+ %td Method:
7
+ %td=match.request.method
8
+ %tr
9
+ %td Headers:
10
+ %td=h(match.request.headers)
11
+ %tr
12
+ %td Parameters:
13
+ %td=h(match.request.parameters)
14
+ %tr
15
+ %td Body:
16
+ %td=h(match.request.body)
17
+ %tr
18
+ %td Matched Stub:
19
+ %td
20
+ %a{ href: match.stub.stub_uri, class: :stub } Match
@@ -0,0 +1,3 @@
1
+ - matches.each do |match|
2
+ = partial :match, locals: { match: match }
3
+ %br
@@ -0,0 +1 @@
1
+ = partial :stub, locals: { the_stub: the_stub }
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.19.1".freeze
2
+ VERSION = "0.20.0".freeze
3
3
  end
@@ -84,7 +84,8 @@ describe "Stub control value acceptance" do
84
84
 
85
85
  context "and a request that matches is made" do
86
86
 
87
- let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=matching_value") }
87
+ let(:parameters) { { "key" => "matching_value" } }
88
+ let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters", query: parameters) }
88
89
 
89
90
  it "replays the stubbed response" do
90
91
  expect(response.code).to eql(202)
@@ -95,7 +96,8 @@ describe "Stub control value acceptance" do
95
96
 
96
97
  context "and a request that does not match is made" do
97
98
 
98
- let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=does_not_match_value") }
99
+ let(:parameters) { { "key" => "does_not_match_value" } }
100
+ let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters", query: parameters) }
99
101
 
100
102
  it "responds with a 404 status code" do
101
103
  expect(response.code).to eql(404)
@@ -127,7 +129,8 @@ describe "Stub control value acceptance" do
127
129
 
128
130
  context "and a request that does not match is made" do
129
131
 
130
- let(:response) { HTTParty.get("#{server_uri}/stub_with_omitted_parameters?key=must_be_omitted") }
132
+ let(:parameters) { { "key" => "must_be_omitted" } }
133
+ let(:response) { HTTParty.get("#{server_uri}/stub_with_omitted_parameters", query: parameters) }
131
134
 
132
135
  it "responds with a 404 status code" do
133
136
  expect(response.code).to eql(404)
@@ -0,0 +1,142 @@
1
+ describe "Stub match acceptance" do
2
+ include_context "configurer integration"
3
+
4
+ before(:example) { configurer.initialize! }
5
+
6
+ after(:example) { configurer.clear_stubs! }
7
+
8
+ describe "GET /stubs/matches" do
9
+
10
+ let(:uri) { "/some/uri" }
11
+ let(:request_method) { :get }
12
+ let(:headers) do
13
+ (1..3).reduce({}) { |result, i| result.tap { result["header_#{i}"] = "header value #{i}" } }
14
+ end
15
+ let(:parameters) { {} }
16
+ let(:body) { nil }
17
+
18
+ let(:response) { HTTParty.get("#{server_uri}/stubs/matches") }
19
+ let(:response_document) { Nokogiri::HTML(response.body) }
20
+
21
+ shared_context "behaviours of a request that is recorded in the stub match log" do
22
+
23
+ it "returns a response body that contains the uri of the request" do
24
+ expect(response.body).to match(/#{escape_html(uri)}/)
25
+ end
26
+
27
+ it "returns a response body that contains the method of the request" do
28
+ expect(response.body).to match(/#{escape_html(request_method)}/)
29
+ end
30
+
31
+ it "returns a response body that contains the headers of the request whose names are in uppercase" do
32
+ headers.each do |expected_header_key, expected_header_value|
33
+ expect(response.body).to match(/#{expected_header_key.upcase}:#{expected_header_value}/)
34
+ end
35
+ end
36
+
37
+ context "when the request contains parameters" do
38
+
39
+ let(:parameters) do
40
+ (1..3).reduce({}) { |result, i| result.tap { result["parameter_#{i}"] = "parameter value #{i}" } }
41
+ end
42
+
43
+ it "returns a response body that contain the parameters" do
44
+ parameters.each do |expected_parameter_key, expected_parameter_value|
45
+ expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
46
+ end
47
+ end
48
+
49
+ def issue_request
50
+ HTTParty.send(request_method, "#{server_uri}#{uri}", headers: headers, query: parameters)
51
+ end
52
+
53
+ end
54
+
55
+ context "when the request contains a body" do
56
+
57
+ let(:body) { "Some <strong>request body</strong>" }
58
+
59
+ it "returns a response body that contains the body" do
60
+ expect(response.body).to match(/#{escape_html(body)}/)
61
+ end
62
+
63
+ def issue_request
64
+ HTTParty.send(request_method, "#{server_uri}#{uri}", headers: headers, body: body)
65
+ end
66
+
67
+ end
68
+
69
+ def issue_request
70
+ HTTParty.send(request_method, "#{server_uri}#{uri}", headers: headers)
71
+ end
72
+
73
+ end
74
+
75
+ context "when a request has been made matching a stub" do
76
+
77
+ before(:example) do
78
+ register_stub
79
+
80
+ issue_request
81
+ end
82
+
83
+ include_context "behaviours of a request that is recorded in the stub match log"
84
+
85
+ it "returns a response body that contains a link to the matched stub" do
86
+ stub_link = response_document.css("a.stub").first
87
+ expect(full_stub_uri).to end_with(stub_link["href"])
88
+ end
89
+
90
+ def full_stub_uri
91
+ @register_stub_response.header["location"]
92
+ end
93
+
94
+ end
95
+
96
+ context "when a request has been made that does not match a stub" do
97
+
98
+ before(:example) { issue_request }
99
+
100
+ it_behaves_like "behaviours of a request that is recorded in the stub match log"
101
+
102
+ end
103
+
104
+ context "when a request has been made configuring a stub" do
105
+
106
+ before(:example) { register_stub }
107
+
108
+ it "should not be recorded in the stub request log" do
109
+ expect(response.body).to_not match(/#{uri}/)
110
+ end
111
+
112
+ end
113
+
114
+ context "when a request has been made configuring a scenarios" do
115
+
116
+ before(:example) { register_scenario }
117
+
118
+ it "should not be recorded in the stub request log" do
119
+ expect(response.body).to_not match(/#{uri}/)
120
+ end
121
+
122
+ def register_scenario
123
+ stub_server.add_scenario_with_one_stub!("some_scenario", build_stub)
124
+ end
125
+
126
+ end
127
+
128
+ def register_stub
129
+ @register_stub_response = stub_server.add_stub!(build_stub)
130
+ end
131
+
132
+ def build_stub
133
+ stub_server.build_stub do |stub|
134
+ stub.match_requests(uri: uri, method: request_method, headers: headers, parameters: parameters, body: body)
135
+ stub.respond_with(status: 200, body: "Some body")
136
+ end
137
+
138
+ end
139
+
140
+ end
141
+
142
+ end
@@ -28,6 +28,10 @@ describe HttpStub::Configurer::Server::CommandProcessor do
28
28
  expect { subject }.not_to raise_error
29
29
  end
30
30
 
31
+ it "returns the server response" do
32
+ expect(subject).to be_a(Net::HTTPResponse)
33
+ end
34
+
31
35
  end
32
36
 
33
37
  describe "and the server responds with a non-200 response" do
@@ -1,5 +1,4 @@
1
1
  describe HttpStub::Server::Application, "when the server is running" do
2
- include Rack::Utils
3
2
  include_context "server integration"
4
3
 
5
4
  let(:response_document) { Nokogiri::HTML(response.body) }
@@ -153,7 +152,7 @@ describe HttpStub::Server::Application, "when the server is running" do
153
152
 
154
153
  it "returns a response whose body contains the response body of a stub returning a file" do
155
154
  file_link = response_document.css("a.file").first
156
- expect(file_link['href']).to match(/^file:\/\/[^']+\.pdf$/)
155
+ expect(file_link["href"]).to match(/^file:\/\/[^']+\.pdf$/)
157
156
  end
158
157
 
159
158
  it "returns a response whose body contains the response body of each stub trigger" do
@@ -178,6 +177,20 @@ describe HttpStub::Server::Application, "when the server is running" do
178
177
 
179
178
  end
180
179
 
180
+ describe "GET /stubs" do
181
+
182
+ describe "when multiple stubs are configured" do
183
+
184
+ before(:context) { (1..3).each { |i| HTTParty.get("#{server_uri}/scenario_#{i}") } }
185
+
186
+ let(:response) { HTTParty.get("#{server_uri}/stubs") }
187
+
188
+ include_context "the response contains HTML describing the configurers stubs"
189
+
190
+ end
191
+
192
+ end
193
+
181
194
  describe "GET /stubs/scenarios" do
182
195
 
183
196
  let(:response) { HTTParty.get("#{server_uri}/stubs/scenarios") }
@@ -187,14 +200,14 @@ describe HttpStub::Server::Application, "when the server is running" do
187
200
  (1..3).map { |i| "/#{scenario_name_prefix}_#{i}" }
188
201
  end.flatten
189
202
 
190
- scenario_links = response_document.css("a.scenario").map { |link| link['href'] }
203
+ scenario_links = response_document.css("a.scenario").map { |link| link["href"] }
191
204
 
192
205
  expect(scenario_links).to eql(expected_scenario_links)
193
206
  end
194
207
 
195
208
  it "returns a response whose body contains links to the scenarios triggered by each scenario" do
196
209
  response_document.css("a.triggered_scenario").each_with_index do |link, i|
197
- expect(link['href']).to eql("/nested_scenario_#{i + 1}")
210
+ expect(link["href"]).to eql("/nested_scenario_#{i + 1}")
198
211
  end
199
212
  end
200
213
 
@@ -202,20 +215,6 @@ describe HttpStub::Server::Application, "when the server is running" do
202
215
 
203
216
  end
204
217
 
205
- describe "GET /stubs" do
206
-
207
- describe "when multiple stubs are configured" do
208
-
209
- before(:context) { (1..3).each { |i| HTTParty.get("#{server_uri}/scenario_#{i}") } }
210
-
211
- let(:response) { HTTParty.get("#{server_uri}/stubs") }
212
-
213
- include_context "the response contains HTML describing the configurers stubs"
214
-
215
- end
216
-
217
- end
218
-
219
218
  end
220
219
 
221
220
  end