http_stub 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/http_stub.rb CHANGED
@@ -12,9 +12,9 @@ require 'json'
12
12
  require File.expand_path('../http_stub/response', __FILE__)
13
13
  require File.expand_path('../http_stub/models/parameters', __FILE__)
14
14
  require File.expand_path('../http_stub/models/stub', __FILE__)
15
- require File.expand_path('../http_stub/models/alias', __FILE__)
15
+ require File.expand_path('../http_stub/models/stub_activator', __FILE__)
16
16
  require File.expand_path('../http_stub/models/registry', __FILE__)
17
17
  require File.expand_path('../http_stub/controllers/stub_controller', __FILE__)
18
- require File.expand_path('../http_stub/controllers/alias_controller', __FILE__)
18
+ require File.expand_path('../http_stub/controllers/stub_activator_controller', __FILE__)
19
19
  require File.expand_path('../http_stub/server', __FILE__)
20
20
  require File.expand_path('../http_stub/configurer', __FILE__)
@@ -17,12 +17,12 @@ module HttpStub
17
17
  @port = port
18
18
  end
19
19
 
20
- def stub_alias(alias_uri, stub_uri, options)
20
+ def stub_activator(activation_uri, stub_uri, options)
21
21
  response_options = options[:response]
22
- request = Net::HTTP::Post.new("/stubs/aliases")
22
+ request = Net::HTTP::Post.new("/stubs/activators")
23
23
  request.content_type = "application/json"
24
24
  request.body = {
25
- "alias_uri" => alias_uri,
25
+ "activation_uri" => activation_uri,
26
26
  "uri" => stub_uri,
27
27
  "method" => options[:method],
28
28
  "parameters" => options[:parameters] || {},
@@ -31,20 +31,20 @@ module HttpStub
31
31
  "body" => response_options[:body]
32
32
  }
33
33
  }.to_json
34
- alias_requests << request
34
+ activator_requests << request
35
35
  end
36
36
 
37
37
  def initialize!
38
- alias_requests.each do |request|
38
+ activator_requests.each do |request|
39
39
  response = submit(request)
40
- raise "Unable to initialize stub alias: #{response.message}" unless response.code == "200"
40
+ raise "Unable to initialize stub activator: #{response.message}" unless response.code == "200"
41
41
  end
42
42
  end
43
43
 
44
- def clear_aliases!
45
- request = Net::HTTP::Delete.new("/stubs/aliases")
44
+ def clear_activators!
45
+ request = Net::HTTP::Delete.new("/stubs/activators")
46
46
  response = submit(request)
47
- raise "Unable to clear stub aliases: #{response.message}" unless response.code == "200"
47
+ raise "Unable to clear stub activators: #{response.message}" unless response.code == "200"
48
48
  end
49
49
 
50
50
  def submit(request)
@@ -53,8 +53,8 @@ module HttpStub
53
53
 
54
54
  private
55
55
 
56
- def alias_requests
57
- @alias_requests ||= []
56
+ def activator_requests
57
+ @activator_requests ||= []
58
58
  end
59
59
 
60
60
  end
@@ -83,7 +83,7 @@ module HttpStub
83
83
  def activate!(uri)
84
84
  request = Net::HTTP::Get.new(uri)
85
85
  response = self.class.submit(request)
86
- raise "Alias #{uri} not configured: #{response.message}" unless response.code == "200"
86
+ raise "Activator #{uri} not configured: #{response.message}" unless response.code == "200"
87
87
  end
88
88
 
89
89
  alias_method :activate_stub!, :activate!
@@ -0,0 +1,33 @@
1
+ module HttpStub
2
+ module Controllers
3
+
4
+ class StubActivatorController
5
+
6
+ def initialize(stub_activator_registry, stub_registry)
7
+ @stub_activator_registry = stub_activator_registry
8
+ @stub_registry = stub_registry
9
+ end
10
+
11
+ def register(request)
12
+ @stub_activator_registry.add(HttpStub::Models::StubActivator.new(JSON.parse(request.body.read)), request)
13
+ HttpStub::Response::SUCCESS
14
+ end
15
+
16
+ def activate(request)
17
+ activator = @stub_activator_registry.find_for(request)
18
+ if activator
19
+ @stub_registry.add(activator.the_stub, request)
20
+ HttpStub::Response::SUCCESS
21
+ else
22
+ HttpStub::Response::EMPTY
23
+ end
24
+ end
25
+
26
+ def clear(request)
27
+ @stub_activator_registry.clear(request)
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -1,23 +1,23 @@
1
1
  module HttpStub
2
2
  module Models
3
3
 
4
- class Alias
4
+ class StubActivator
5
5
 
6
6
  def initialize(options)
7
- @alias_options = options
7
+ @options = options
8
8
  @stub = HttpStub::Models::Stub.new(options)
9
9
  end
10
10
 
11
11
  def satisfies?(request)
12
- alias_uri == request.path_info
12
+ activation_uri == request.path_info
13
13
  end
14
14
 
15
15
  def the_stub
16
16
  @stub
17
17
  end
18
18
 
19
- def alias_uri
20
- @alias_options["alias_uri"]
19
+ def activation_uri
20
+ @options["activation_uri"]
21
21
  end
22
22
 
23
23
  end
@@ -9,9 +9,10 @@ module HttpStub
9
9
  def initialize
10
10
  super()
11
11
  @stub_registry = HttpStub::Models::Registry.new("stub")
12
- @alias_registry = HttpStub::Models::Registry.new("alias")
12
+ @stub_activator_registry = HttpStub::Models::Registry.new("stub_activator")
13
13
  @stub_controller = HttpStub::Controllers::StubController.new(@stub_registry)
14
- @alias_controller = HttpStub::Controllers::AliasController.new(@alias_registry, @stub_registry)
14
+ @stub_activator_controller =
15
+ HttpStub::Controllers::StubActivatorController.new(@stub_activator_registry, @stub_registry)
15
16
  end
16
17
 
17
18
  private
@@ -53,20 +54,20 @@ module HttpStub
53
54
 
54
55
  # Sample request body:
55
56
  # {
56
- # "alias_uri": "/some/path",
57
+ # "activation_uri": "/some/path",
57
58
  # ... see /stub ...
58
59
  # }
59
- post "/stubs/aliases" do
60
- response = @alias_controller.register(request)
60
+ post "/stubs/activators" do
61
+ response = @stub_activator_controller.register(request)
61
62
  halt(response.status, response.body)
62
63
  end
63
64
 
64
- get "/stubs/aliases" do
65
- haml :aliases, {}, aliases: @alias_registry.all.sort_by(&:alias_uri)
65
+ get "/stubs/activators" do
66
+ haml :stub_activators, {}, stub_activators: @stub_activator_registry.all.sort_by(&:activation_uri)
66
67
  end
67
68
 
68
- delete "/stubs/aliases" do
69
- @alias_controller.clear(request)
69
+ delete "/stubs/activators" do
70
+ @stub_activator_controller.clear(request)
70
71
  halt 200
71
72
  end
72
73
 
@@ -88,7 +89,7 @@ module HttpStub
88
89
 
89
90
  def handle_request
90
91
  response = @stub_controller.replay(request)
91
- response = @alias_controller.activate(request) if response.empty?
92
+ response = @stub_activator_controller.activate(request) if response.empty?
92
93
  response = HttpStub::Response::ERROR if response.empty?
93
94
  halt(response.status, response.body)
94
95
  end
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,6 @@
1
+ - stub_activators.each do |stub_activator|
2
+ %div
3
+ %span Response Activation URI:
4
+ %a{ href: stub_activator.activation_uri }= stub_activator.activation_uri
5
+ = partial :stub, locals: { the_stub: stub_activator.the_stub }
6
+ %br
@@ -1,20 +1,20 @@
1
1
  describe HttpStub::Configurer, "when the server is running" do
2
2
  include_context "server integration"
3
3
 
4
- let(:configurer) { HttpStub::Examples::ConfigurerWithAlias.new }
4
+ let(:configurer) { HttpStub::Examples::ConfigurerWithActivator.new }
5
5
 
6
6
  after(:each) do
7
7
  configurer.clear!
8
- configurer.class.clear_aliases!
8
+ configurer.class.clear_activators!
9
9
  end
10
10
 
11
11
  describe "and the configurer is initialized" do
12
12
 
13
13
  before(:each) { configurer.class.initialize! }
14
14
 
15
- describe "and a stub alias is activated" do
15
+ describe "and a stub is activated" do
16
16
 
17
- before(:each) { configurer.activate!("/an_alias") }
17
+ before(:each) { configurer.activate!("/an_activator") }
18
18
 
19
19
  describe "and the stub request is made" do
20
20
 
@@ -22,14 +22,14 @@ describe HttpStub::Configurer, "when the server is running" do
22
22
 
23
23
  it "should replay the stubbed response" do
24
24
  response.code.should eql("200")
25
- response.body.should eql("Stub alias body")
25
+ response.body.should eql("Stub activator body")
26
26
  end
27
27
 
28
28
  end
29
29
 
30
30
  end
31
31
 
32
- describe "and a stub alias is not activated" do
32
+ describe "and a stub is not activated" do
33
33
 
34
34
  describe "and the stub request is made" do
35
35
 
@@ -47,12 +47,12 @@ describe HttpStub::Configurer, "when the server is running" do
47
47
 
48
48
  describe "and the configurer is uninitialized" do
49
49
 
50
- describe "and an attempt is made to activate a stub alias" do
50
+ describe "and an attempt is made to activate a stub" do
51
51
 
52
52
  let(:response) { Net::HTTP.get_response("localhost", "/path1", 8001) }
53
53
 
54
- it "should respond raise an exception indicating the alias is not configured" do
55
- lambda { configurer.activate!("/an_alias") }.should raise_error(/alias \/an_alias not configured/i)
54
+ it "should respond raise an exception indicating the activator is not configured" do
55
+ lambda { configurer.activate!("/an_activator") }.should raise_error(/activator \/an_activator not configured/i)
56
56
  end
57
57
 
58
58
  end
@@ -0,0 +1,94 @@
1
+ describe HttpStub::Controllers::StubActivatorController do
2
+
3
+ let(:request_body) { "Some request body" }
4
+ let(:request) { double("HttpRequest", body: double("RequestBody", read: request_body)) }
5
+ let(:stub_activator_options) { double("StubActivatorOptions") }
6
+ let(:the_stub) { double(HttpStub::Models::Stub) }
7
+ let(:stub_activator) { double(HttpStub::Models::StubActivator, the_stub: the_stub) }
8
+ let(:stub_activator_registry) { double("HttpStub::Models::StubActivatorRegistry").as_null_object }
9
+ let(:stub_registry) { double("HttpStub::Models::StubRegistry").as_null_object }
10
+ let(:controller) { HttpStub::Controllers::StubActivatorController.new(stub_activator_registry, stub_registry) }
11
+
12
+ before(:each) { JSON.stub!(:parse).and_return(stub_activator_options) }
13
+
14
+ describe "#register" do
15
+
16
+ before(:each) do
17
+ HttpStub::Models::StubActivator.stub!(:new).and_return(stub_activator)
18
+ end
19
+
20
+ it "should parse an options hash from the JSON request body" do
21
+ JSON.should_receive(:parse).with(request_body).and_return(stub_activator_options)
22
+
23
+ controller.register(request)
24
+ end
25
+
26
+ it "should create a stub activator from the parsed options" do
27
+ HttpStub::Models::StubActivator.should_receive(:new).with(stub_activator_options).and_return(stub_activator)
28
+
29
+ controller.register(request)
30
+ end
31
+
32
+ it "should add the created activator to the activator registry" do
33
+ stub_activator_registry.should_receive(:add).with(stub_activator, request)
34
+
35
+ controller.register(request)
36
+ end
37
+
38
+ it "should return a success response" do
39
+ controller.register(request).should eql(HttpStub::Response::SUCCESS)
40
+ end
41
+
42
+ end
43
+
44
+ describe "#activate" do
45
+
46
+ describe "when a stub activator has been registered that is activated by the request" do
47
+
48
+ before(:each) do
49
+ stub_activator_registry.stub!(:find_for).with(request).and_return(stub_activator)
50
+ end
51
+
52
+ it "should add the activators stub to the stub registry" do
53
+ stub_registry.should_receive(:add).with(the_stub, request)
54
+
55
+ controller.activate(request)
56
+ end
57
+
58
+ it "should return a success response" do
59
+ controller.activate(request).should eql(HttpStub::Response::SUCCESS)
60
+ end
61
+
62
+ end
63
+
64
+ describe "when no stub activator is activated by the request" do
65
+
66
+ before(:each) do
67
+ stub_activator_registry.stub!(:find_for).with(request).and_return(nil)
68
+ end
69
+
70
+ it "should not add a stub to the registry" do
71
+ stub_registry.should_not_receive(:add)
72
+
73
+ controller.activate(request)
74
+ end
75
+
76
+ it "should return an empty response" do
77
+ controller.activate(request).should eql(HttpStub::Response::EMPTY)
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ describe "#clear" do
85
+
86
+ it "should clear the activator registry" do
87
+ stub_activator_registry.should_receive(:clear).with(request)
88
+
89
+ controller.clear(request)
90
+ end
91
+
92
+ end
93
+
94
+ end
@@ -0,0 +1,66 @@
1
+ describe HttpStub::Models::StubActivator do
2
+
3
+ let(:activation_uri) { "/some/activation/uri" }
4
+ let(:options) do
5
+ { "activation_uri" => activation_uri }
6
+ end
7
+ let(:stub_activator) { HttpStub::Models::StubActivator.new(options) }
8
+
9
+ before(:each) { HttpStub::Models::Stub.stub!(:new).and_return(double(HttpStub::Models::Stub)) }
10
+
11
+ describe "#satisfies?" do
12
+
13
+ let(:request) { double("HttpRequest", path_info: request_path_info) }
14
+
15
+ describe "when the request uri exactly matches the activator's activation uri" do
16
+
17
+ let(:request_path_info) { activation_uri }
18
+
19
+ it "should return true" do
20
+ stub_activator.satisfies?(request).should be_true
21
+ end
22
+
23
+ end
24
+
25
+ describe "when the activator's activation uri is a substring of the request uri" do
26
+
27
+ let(:request_path_info) { "#{activation_uri}/with/additional/paths" }
28
+
29
+ it "should return false" do
30
+ stub_activator.satisfies?(request).should be_false
31
+ end
32
+
33
+ end
34
+
35
+ describe "when the request uri is completely different to the activator's activation uri" do
36
+
37
+ let(:request_path_info) { "/completely/different/path" }
38
+
39
+ it "should return false" do
40
+ stub_activator.satisfies?(request).should be_false
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ describe "#the_stub" do
48
+
49
+ it "should return a HttpStub::Models::Stub constructed from the activator's options" do
50
+ stub = double(HttpStub::Models::Stub)
51
+ HttpStub::Models::Stub.should_receive(:new).with(options).and_return(stub)
52
+
53
+ stub_activator.the_stub.should eql(stub)
54
+ end
55
+
56
+ end
57
+
58
+ describe "#activation_uri" do
59
+
60
+ it "should return the value provided in the request body" do
61
+ stub_activator.activation_uri.should eql(activation_uri)
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -2,40 +2,40 @@ describe HttpStub::Server, "when the server is running" do
2
2
  include Rack::Utils
3
3
  include_context "server integration"
4
4
 
5
- let(:configurer) { HttpStub::Examples::ConfigurerWithManyAliases.new }
5
+ let(:configurer) { HttpStub::Examples::ConfigurerWithManyActivators.new }
6
6
 
7
- describe "and a configurer with multiple aliases is initialized" do
7
+ describe "and a configurer with multiple stub activators is initialized" do
8
8
 
9
9
  before(:all) { configurer.class.initialize! }
10
10
 
11
- describe "GET #stubs/aliases" do
11
+ describe "GET #stubs/activators" do
12
12
 
13
- let(:response) { Net::HTTP.get_response("localhost", "/stubs/aliases", 8001) }
13
+ let(:response) { Net::HTTP.get_response("localhost", "/stubs/activators", 8001) }
14
14
  let(:response_document) { Nokogiri::HTML(response.body) }
15
15
 
16
16
  it "should return a 200 response code" do
17
17
  response.code.should eql("200")
18
18
  end
19
19
 
20
- it "should return response whose body contains a link to each alias in alphabetical order" do
20
+ it "should return response whose body contains a link to each activator in alphabetical order" do
21
21
  response_document.css("a").each_with_index do |link, i|
22
- link['href'].should eql("/alias#{i + 1}")
22
+ link['href'].should eql("/activator#{i + 1}")
23
23
  end
24
24
  end
25
25
 
26
- it "should return a response whose body contains the uri of each alias stub" do
26
+ it "should return a response whose body contains the uri of each activators stub" do
27
27
  (1..3).each { |i| response.body.should match(/#{escape_html("/path#{i}")}/) }
28
28
  end
29
29
 
30
- it "should return a response whose body contains the parameters of each alias stub" do
30
+ it "should return a response whose body contains the parameters of each activators stub" do
31
31
  (1..3).each { |i| response.body.should match(/param#{i}=value#{i}/) }
32
32
  end
33
33
 
34
- it "should return a response whose body contains the response status of each alias stub" do
34
+ it "should return a response whose body contains the response status of each activators stub" do
35
35
  (1..3).each { |i| response.body.should match(/20#{i}/) }
36
36
  end
37
37
 
38
- it "should return a response whose body contains the response body of each alias stub" do
38
+ it "should return a response whose body contains the response body of each activators stub" do
39
39
  response.body.should match(/Plain text body/)
40
40
  response.body.should match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
41
41
  response.body.should match(/#{escape_html("<html><body>HTML body</body></html>")}/)
@@ -48,7 +48,7 @@ describe HttpStub::Server, "when the server is running" do
48
48
  describe "when multiple stubs are configured" do
49
49
 
50
50
  before(:all) do
51
- (1..3).each { |i| Net::HTTP.get_response("localhost", "/alias#{i}", 8001) }
51
+ (1..3).each { |i| Net::HTTP.get_response("localhost", "/activator#{i}", 8001) }
52
52
  end
53
53
 
54
54
  let(:response) { Net::HTTP.get_response("localhost", "/stubs", 8001) }
@@ -62,15 +62,15 @@ describe HttpStub::Server, "when the server is running" do
62
62
  (1..3).each { |i| response.body.should match(/#{escape_html("/path#{i}")}/) }
63
63
  end
64
64
 
65
- it "should return a response whose body contains the parameters of each alias stub" do
65
+ it "should return a response whose body contains the parameters of each stub" do
66
66
  (1..3).each { |i| response.body.should match(/param#{i}=value#{i}/) }
67
67
  end
68
68
 
69
- it "should return a response whose body contains the response status of each alias stub" do
69
+ it "should return a response whose body contains the response status of each stub" do
70
70
  (1..3).each { |i| response.body.should match(/20#{i}/) }
71
71
  end
72
72
 
73
- it "should return a response whose body contains the response body of each alias stub" do
73
+ it "should return a response whose body contains the response body of each stub" do
74
74
  response.body.should match(/Plain text body/)
75
75
  response.body.should match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
76
76
  response.body.should match(/#{escape_html("<html><body>HTML body</body></html>")}/)
@@ -5,18 +5,18 @@ describe HttpStub::Server do
5
5
  let(:response_body) { response.body.to_s }
6
6
 
7
7
  let(:stub_registry) { double(HttpStub::Models::Registry).as_null_object }
8
- let(:alias_registry) { double(HttpStub::Models::Registry).as_null_object }
8
+ let(:stub_activator_registry) { double(HttpStub::Models::Registry).as_null_object }
9
9
 
10
10
  let(:stub_controller) { double(HttpStub::Controllers::StubController).as_null_object }
11
- let(:alias_controller) { double(HttpStub::Controllers::AliasController).as_null_object }
11
+ let(:stub_activator_controller) { double(HttpStub::Controllers::StubActivatorController).as_null_object }
12
12
 
13
13
  let(:app) { HttpStub::Server.new }
14
14
 
15
15
  before(:each) do
16
16
  HttpStub::Models::Registry.stub!(:new).with("stub").and_return(stub_registry)
17
- HttpStub::Models::Registry.stub!(:new).with("alias").and_return(alias_registry)
17
+ HttpStub::Models::Registry.stub!(:new).with("stub_activator").and_return(stub_activator_registry)
18
18
  HttpStub::Controllers::StubController.stub!(:new).and_return(stub_controller)
19
- HttpStub::Controllers::AliasController.stub!(:new).and_return(alias_controller)
19
+ HttpStub::Controllers::StubActivatorController.stub!(:new).and_return(stub_activator_controller)
20
20
  end
21
21
 
22
22
  describe "when a stub insertion is received" do
@@ -48,25 +48,25 @@ describe HttpStub::Server do
48
48
 
49
49
  end
50
50
 
51
- describe "when a stub alias insertion request is received" do
51
+ describe "when a stub activator insertion request is received" do
52
52
 
53
- it "should register the insertion via the alias controller" do
54
- alias_controller.should_receive(:register).and_return(HttpStub::Response::SUCCESS)
53
+ it "should register the insertion via the stub activator controller" do
54
+ stub_activator_controller.should_receive(:register).and_return(HttpStub::Response::SUCCESS)
55
55
 
56
- issue_stub_alias_request
56
+ issue_stub_activator_request
57
57
  end
58
58
 
59
59
  it "should respond with the response provided by the controller" do
60
- alias_controller.stub!(:register).and_return(HttpStub::Response.new("status" => 302, "body" => ""))
60
+ stub_activator_controller.stub!(:register).and_return(HttpStub::Response.new("status" => 302, "body" => ""))
61
61
 
62
- issue_stub_alias_request
62
+ issue_stub_activator_request
63
63
 
64
64
  response.status.should eql(302)
65
65
  end
66
66
 
67
- def issue_stub_alias_request
68
- post "/stubs/aliases", {
69
- "alias_uri" => "/an_alias_path",
67
+ def issue_stub_activator_request
68
+ post "/stubs/activators", {
69
+ "activation_uri" => "/an_activation_path",
70
70
  "uri" => "/a_path",
71
71
  "method" => "a method",
72
72
  "response" => {
@@ -94,16 +94,16 @@ describe HttpStub::Server do
94
94
 
95
95
  end
96
96
 
97
- describe "when a request to clear the stub aliases has been received" do
97
+ describe "when a request to clear the stub activators has been received" do
98
98
 
99
- it "should delegate clearing to the stub controller" do
100
- alias_controller.should_receive(:clear)
99
+ it "should delegate clearing to the stub activator controller" do
100
+ stub_activator_controller.should_receive(:clear)
101
101
 
102
- delete "/stubs/aliases"
102
+ delete "/stubs/activators"
103
103
  end
104
104
 
105
105
  it "should respond with a 200 status code" do
106
- delete "/stubs/aliases"
106
+ delete "/stubs/activators"
107
107
 
108
108
  response.status.should eql(200)
109
109
  end
@@ -138,10 +138,10 @@ describe HttpStub::Server do
138
138
  stub_controller.stub!(:replay).and_return(HttpStub::Response::EMPTY)
139
139
  end
140
140
 
141
- describe "but the alias controller activates a stub" do
141
+ describe "but the stub activator controller activates a stub" do
142
142
 
143
143
  before(:each) do
144
- alias_controller.stub!(:activate).and_return(HttpStub::Response.new("status" => 300, "body" => "A body"))
144
+ stub_activator_controller.stub!(:activate).and_return(HttpStub::Response.new("status" => 300, "body" => "A body"))
145
145
  end
146
146
 
147
147
  it "should respond with the activation response status code" do
@@ -158,10 +158,10 @@ describe HttpStub::Server do
158
158
 
159
159
  end
160
160
 
161
- describe "and the alias controller does not activate a stub" do
161
+ describe "and the stub activator controller does not activate a stub" do
162
162
 
163
163
  before(:each) do
164
- alias_controller.stub!(:activate).and_return(HttpStub::Response::EMPTY)
164
+ stub_activator_controller.stub!(:activate).and_return(HttpStub::Response::EMPTY)
165
165
  end
166
166
 
167
167
  it "should respond with a 404 status code" do
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,7 @@ require 'nokogiri'
10
10
 
11
11
  require File.expand_path('../../lib/http_stub/start_server_rake_task', __FILE__)
12
12
  require File.expand_path('../../lib/http_stub', __FILE__)
13
- require File.expand_path('../../examples/configurer_with_alias', __FILE__)
14
- require File.expand_path('../../examples/configurer_with_many_aliases', __FILE__)
13
+ require File.expand_path('../../examples/configurer_with_activator', __FILE__)
14
+ require File.expand_path('../../examples/configurer_with_many_activators', __FILE__)
15
15
 
16
16
  Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |file| require file }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_stub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-28 00:00:00.000000000 Z
13
+ date: 2013-03-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
@@ -188,37 +188,36 @@ dependencies:
188
188
  - - ~>
189
189
  - !ruby/object:Gem::Version
190
190
  version: 1.6.0
191
- description: Configure server responses via requests to /stub. Intended as an acceptance
192
- / integration testing tool.
191
+ description: fakeweb for a HTTP server, informing it to stub / fake responses.
193
192
  email: matthew.ueckerman@myob.com
194
193
  executables: []
195
194
  extensions: []
196
195
  extra_rdoc_files: []
197
196
  files:
198
197
  - ./lib/http_stub/configurer.rb
199
- - ./lib/http_stub/controllers/alias_controller.rb
198
+ - ./lib/http_stub/controllers/stub_activator_controller.rb
200
199
  - ./lib/http_stub/controllers/stub_controller.rb
201
- - ./lib/http_stub/models/alias.rb
202
200
  - ./lib/http_stub/models/parameters.rb
203
201
  - ./lib/http_stub/models/registry.rb
204
202
  - ./lib/http_stub/models/stub.rb
203
+ - ./lib/http_stub/models/stub_activator.rb
205
204
  - ./lib/http_stub/response.rb
206
205
  - ./lib/http_stub/server.rb
207
206
  - ./lib/http_stub/start_server_rake_task.rb
208
207
  - ./lib/http_stub/version.rb
209
208
  - ./lib/http_stub/views/_stub.haml
210
- - ./lib/http_stub/views/aliases.haml
211
209
  - ./lib/http_stub/views/application.sass
212
210
  - ./lib/http_stub/views/layout.haml
211
+ - ./lib/http_stub/views/stub_activators.haml
213
212
  - ./lib/http_stub/views/stubs.haml
214
213
  - ./lib/http_stub.rb
215
214
  - ./spec/curl_samples.txt
216
215
  - ./spec/lib/http_stub/configurer_integration_spec.rb
217
- - ./spec/lib/http_stub/controllers/alias_controller_spec.rb
216
+ - ./spec/lib/http_stub/controllers/stub_activator_controller_spec.rb
218
217
  - ./spec/lib/http_stub/controllers/stub_controller_spec.rb
219
- - ./spec/lib/http_stub/models/alias_spec.rb
220
218
  - ./spec/lib/http_stub/models/parameters_spec.rb
221
219
  - ./spec/lib/http_stub/models/registry_spec.rb
220
+ - ./spec/lib/http_stub/models/stub_activator_spec.rb
222
221
  - ./spec/lib/http_stub/models/stub_spec.rb
223
222
  - ./spec/lib/http_stub/response_spec.rb
224
223
  - ./spec/lib/http_stub/server_integration_spec.rb
@@ -247,21 +246,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
246
  version: '0'
248
247
  segments:
249
248
  - 0
250
- hash: -3825897115098639918
249
+ hash: 3385338799402198881
251
250
  requirements: []
252
251
  rubyforge_project: http_stub
253
252
  rubygems_version: 1.8.25
254
253
  signing_key:
255
254
  specification_version: 3
256
- summary: A HTTP Server replaying configured stub responses
255
+ summary: A HTTP Server replaying configured stub responses.
257
256
  test_files:
258
257
  - ./spec/curl_samples.txt
259
258
  - ./spec/lib/http_stub/configurer_integration_spec.rb
260
- - ./spec/lib/http_stub/controllers/alias_controller_spec.rb
259
+ - ./spec/lib/http_stub/controllers/stub_activator_controller_spec.rb
261
260
  - ./spec/lib/http_stub/controllers/stub_controller_spec.rb
262
- - ./spec/lib/http_stub/models/alias_spec.rb
263
261
  - ./spec/lib/http_stub/models/parameters_spec.rb
264
262
  - ./spec/lib/http_stub/models/registry_spec.rb
263
+ - ./spec/lib/http_stub/models/stub_activator_spec.rb
265
264
  - ./spec/lib/http_stub/models/stub_spec.rb
266
265
  - ./spec/lib/http_stub/response_spec.rb
267
266
  - ./spec/lib/http_stub/server_integration_spec.rb
@@ -1,33 +0,0 @@
1
- module HttpStub
2
- module Controllers
3
-
4
- class AliasController
5
-
6
- def initialize(alias_registry, stub_registry)
7
- @alias_registry = alias_registry
8
- @stub_registry = stub_registry
9
- end
10
-
11
- def register(request)
12
- @alias_registry.add(HttpStub::Models::Alias.new(JSON.parse(request.body.read)), request)
13
- HttpStub::Response::SUCCESS
14
- end
15
-
16
- def activate(request)
17
- the_alias = @alias_registry.find_for(request)
18
- if the_alias
19
- @stub_registry.add(the_alias.the_stub, request)
20
- HttpStub::Response::SUCCESS
21
- else
22
- HttpStub::Response::EMPTY
23
- end
24
- end
25
-
26
- def clear(request)
27
- @alias_registry.clear(request)
28
- end
29
-
30
- end
31
-
32
- end
33
- end
@@ -1,6 +0,0 @@
1
- - aliases.each do |the_alias|
2
- %div
3
- %span Response Activation URI:
4
- %a{ href: the_alias.alias_uri }= the_alias.alias_uri
5
- = partial :stub, locals: { the_stub: the_alias.the_stub }
6
- %br
@@ -1,126 +0,0 @@
1
- describe HttpStub::Controllers::AliasController do
2
-
3
- let(:request_body) { "Some request body" }
4
- let(:request) { double("HttpRequest", body: double("RequestBody", read: request_body)) }
5
- let(:alias_options) { double("AliasOptions") }
6
- let(:the_stub) { double(HttpStub::Models::Stub) }
7
- let(:the_alias) { double(HttpStub::Models::Alias, the_stub: the_stub) }
8
- let(:alias_registry) { double("HttpStub::Models::AliasRegistry").as_null_object }
9
- let(:stub_registry) { double("HttpStub::Models::StubRegistry").as_null_object }
10
- let(:controller) { HttpStub::Controllers::AliasController.new(alias_registry, stub_registry) }
11
-
12
- before(:each) { JSON.stub!(:parse).and_return(alias_options) }
13
-
14
- describe "#list" do
15
-
16
- describe "when the alias registry contains multiple aliases" do
17
-
18
- before(:each) do
19
- alias_registry.stub!(:all).and_return((1..3).map { |i| double("#{HttpStub::Models::Alias}#{i}") })
20
- end
21
-
22
- it "should return a page containing each alias" do
23
-
24
- end
25
-
26
- end
27
-
28
- describe "when the alias registry contains one alias" do
29
-
30
- it "should return a page containing the one alias" do
31
-
32
- end
33
-
34
- end
35
-
36
- describe "when then alias registry is empty" do
37
-
38
- it "should return an empty page" do
39
-
40
- end
41
-
42
- end
43
-
44
- end
45
-
46
- describe "#register" do
47
-
48
- before(:each) do
49
- HttpStub::Models::Alias.stub!(:new).and_return(the_alias)
50
- end
51
-
52
- it "should parse an options hash from the JSON request body" do
53
- JSON.should_receive(:parse).with(request_body).and_return(alias_options)
54
-
55
- controller.register(request)
56
- end
57
-
58
- it "should create an alias from the parsed options" do
59
- HttpStub::Models::Alias.should_receive(:new).with(alias_options).and_return(the_alias)
60
-
61
- controller.register(request)
62
- end
63
-
64
- it "should add the created alias to the alias registry" do
65
- alias_registry.should_receive(:add).with(the_alias, request)
66
-
67
- controller.register(request)
68
- end
69
-
70
- it "should return a success response" do
71
- controller.register(request).should eql(HttpStub::Response::SUCCESS)
72
- end
73
-
74
- end
75
-
76
- describe "#activate" do
77
-
78
- describe "when an alias has been registered that is activated by the request" do
79
-
80
- before(:each) do
81
- alias_registry.stub!(:find_for).with(request).and_return(the_alias)
82
- end
83
-
84
- it "should add the aliases stub to the stub registry" do
85
- stub_registry.should_receive(:add).with(the_stub, request)
86
-
87
- controller.activate(request)
88
- end
89
-
90
- it "should return a success response" do
91
- controller.activate(request).should eql(HttpStub::Response::SUCCESS)
92
- end
93
-
94
- end
95
-
96
- describe "when no alias is activated by the request" do
97
-
98
- before(:each) do
99
- alias_registry.stub!(:find_for).with(request).and_return(nil)
100
- end
101
-
102
- it "should not add a stub to the registry" do
103
- stub_registry.should_not_receive(:add)
104
-
105
- controller.activate(request)
106
- end
107
-
108
- it "should return an empty response" do
109
- controller.activate(request).should eql(HttpStub::Response::EMPTY)
110
- end
111
-
112
- end
113
-
114
- end
115
-
116
- describe "#clear" do
117
-
118
- it "should clear the alias registry" do
119
- alias_registry.should_receive(:clear).with(request)
120
-
121
- controller.clear(request)
122
- end
123
-
124
- end
125
-
126
- end
@@ -1,66 +0,0 @@
1
- describe HttpStub::Models::Alias do
2
-
3
- let(:alias_uri) { "/some/alias/uri" }
4
- let(:alias_options) do
5
- { "alias_uri" => alias_uri }
6
- end
7
- let(:the_alias) { HttpStub::Models::Alias.new(alias_options) }
8
-
9
- before(:each) { HttpStub::Models::Stub.stub!(:new).and_return(double(HttpStub::Models::Stub)) }
10
-
11
- describe "#satisfies?" do
12
-
13
- let(:request) { double("HttpRequest", path_info: request_path_info) }
14
-
15
- describe "when the request uri exactly matches the aliases activation uri" do
16
-
17
- let(:request_path_info) { alias_uri }
18
-
19
- it "should return true" do
20
- the_alias.satisfies?(request).should be_true
21
- end
22
-
23
- end
24
-
25
- describe "when the alias activation uri is a substring of the request uri" do
26
-
27
- let(:request_path_info) { "#{alias_uri}/with/additional/paths" }
28
-
29
- it "should return false" do
30
- the_alias.satisfies?(request).should be_false
31
- end
32
-
33
- end
34
-
35
- describe "when the request uri is completely different to the aliases activation uri" do
36
-
37
- let(:request_path_info) { "/completely/different/path" }
38
-
39
- it "should return false" do
40
- the_alias.satisfies?(request).should be_false
41
- end
42
-
43
- end
44
-
45
- end
46
-
47
- describe "#the_stub" do
48
-
49
- it "should return a HttpStub::Models::Stub constructed from the alias options" do
50
- stub = double(HttpStub::Models::Stub)
51
- HttpStub::Models::Stub.should_receive(:new).with(alias_options).and_return(stub)
52
-
53
- the_alias.the_stub.should eql(stub)
54
- end
55
-
56
- end
57
-
58
- describe "#alias_uri" do
59
-
60
- it "should return the value provided in the request body" do
61
- the_alias.alias_uri.should eql(alias_uri)
62
- end
63
-
64
- end
65
-
66
- end