http_stub 0.13.1 → 0.13.2

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 (31) hide show
  1. checksums.yaml +8 -8
  2. data/lib/http_stub.rb +2 -2
  3. data/lib/http_stub/configurer.rb +2 -2
  4. data/lib/http_stub/configurer/command.rb +5 -5
  5. data/lib/http_stub/configurer/request/stub.rb +8 -8
  6. data/lib/http_stub/models/{hash_with_value_matchers.rb → hash_with_string_value_matchers.rb} +4 -4
  7. data/lib/http_stub/models/response.rb +13 -13
  8. data/lib/http_stub/models/{value_matcher.rb → string_value_matcher.rb} +4 -4
  9. data/lib/http_stub/models/stub.rb +8 -8
  10. data/lib/http_stub/models/stub_activator.rb +5 -5
  11. data/lib/http_stub/models/stub_headers.rb +1 -1
  12. data/lib/http_stub/models/stub_parameters.rb +1 -1
  13. data/lib/http_stub/models/stub_uri.rb +1 -1
  14. data/lib/http_stub/rake/server_daemon_tasks.rb +3 -3
  15. data/lib/http_stub/rake/server_tasks.rb +10 -10
  16. data/lib/http_stub/server_daemon.rb +3 -3
  17. data/lib/http_stub/version.rb +1 -1
  18. data/spec/lib/http_stub/configurer/command_spec.rb +3 -3
  19. data/spec/lib/http_stub/configurer/request/stub_spec.rb +14 -14
  20. data/spec/lib/http_stub/configurer_integration_spec.rb +90 -0
  21. data/spec/lib/http_stub/models/{hash_with_value_matchers_spec.rb → hash_with_string_value_matchers_spec.rb} +5 -5
  22. data/spec/lib/http_stub/models/response_spec.rb +5 -5
  23. data/spec/lib/http_stub/models/string_value_matcher_spec.rb +121 -0
  24. data/spec/lib/http_stub/models/stub_activator_spec.rb +7 -7
  25. data/spec/lib/http_stub/models/stub_headers_spec.rb +4 -4
  26. data/spec/lib/http_stub/models/stub_parameters_spec.rb +4 -4
  27. data/spec/lib/http_stub/models/stub_spec.rb +5 -5
  28. data/spec/lib/http_stub/models/stub_uri_spec.rb +3 -3
  29. data/spec/lib/http_stub/rake/server_tasks_spec.rb +4 -4
  30. metadata +8 -8
  31. data/spec/lib/http_stub/models/value_matcher_spec.rb +0 -81
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2JiODEwNjQzODFhNzU4ZjIyODg1Yjg0ZjU3Zjc4NDRlNzUxNmNhZQ==
4
+ YWIwNDc5MGFmMDA3OGU3MDBlMjM4ODdjZmY4YjliYjExOWI5NWQyYg==
5
5
  data.tar.gz: !binary |-
6
- YWUzNDU3YWMyNDVmNzI3ZGM2MTIzMjdhZTIwZThmNWI0NWQ2YTZhMQ==
6
+ ZGQ1OGE1OWMxOGJjYTI3MTI0MWQ4M2E5ZmMxNDQzYTU1NjhkZWI4OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTA5OGZiZDdkMTY3MjkyMTM3MTg5MThmYWM2MTU4OTY2MDcxODc2YjZhNTg1
10
- ZGM4Y2FmYTRkNTg0ZGJkZmE5ODBjOGZiNmVhZGU5ZDNmMjYzYTA4NmI1ZWM4
11
- YjA0NWJjZGQwOGIyZjc3ZDUwMGY4ZTcyYzc4YzZhMWZlYTk5ODM=
9
+ ZTFkYzhmMmQxNzYwZjQ2ZWZmYWJmMjAyMWZlNWFlYzdlMTAwMjE2NmQwY2E5
10
+ ZGQ4YzcxNWQxYmY0N2JlNmUxNWI0ZjA3YjJjYjViYzU3OGVmYTBhMjVjODFj
11
+ OWE0YjA0ZmFjYTU1ZGU4MDI1YTcxYTQwYWU4ZGIyYWQ2NzI0YWI=
12
12
  data.tar.gz: !binary |-
13
- YzMxNjAwNzU2NjAzZjVlYjI5MTEyOTcxODYwZmQ3MjVkZjQ5YmJkZDk0NjRi
14
- MmE4MTE5MmFhZjNmZWNkZWFlYjBiMWM1MWRjNjAwY2Q2MzI0ODZiNWRjNDA2
15
- ZDk1NGFlMmFhY2QyZDgwMTQwYzI0ZTllNTI2MDZjYmZiN2QwNjM=
13
+ YmQ2NGJiMmY1YmIxNDcyYTEyZGQ2OTY3MzA2YjBiZmEwYzJmMTc2ZTdmNmFl
14
+ MzY1YjUyZjY1MGM2YzgzYTk4ZWFiNTdiZWY3NWU1Zjg0YWQ0MzE2YzdmYWI4
15
+ MGM0YTc4NWQzMzM4OTU0Nzg2NGE1MTBlNmVmYjEwMTFkYzI1M2I=
data/lib/http_stub.rb CHANGED
@@ -12,8 +12,8 @@ require_relative 'http_stub/models/response'
12
12
  require_relative 'http_stub/models/omitted_value_matcher'
13
13
  require_relative 'http_stub/models/regexp_value_matcher'
14
14
  require_relative 'http_stub/models/exact_value_matcher'
15
- require_relative 'http_stub/models/value_matcher'
16
- require_relative 'http_stub/models/hash_with_value_matchers'
15
+ require_relative 'http_stub/models/string_value_matcher'
16
+ require_relative 'http_stub/models/hash_with_string_value_matchers'
17
17
  require_relative 'http_stub/models/request_header_parser'
18
18
  require_relative 'http_stub/models/stub_uri'
19
19
  require_relative 'http_stub/models/stub_headers'
@@ -75,9 +75,9 @@ module HttpStub
75
75
 
76
76
  private
77
77
 
78
- def handle(command_options)
78
+ def handle(command_args)
79
79
  effective_command_chain <<
80
- HttpStub::Configurer::Command.new({ processor: command_processor }.merge(command_options))
80
+ HttpStub::Configurer::Command.new({ processor: command_processor }.merge(command_args))
81
81
  end
82
82
 
83
83
  def effective_command_chain
@@ -5,11 +5,11 @@ module HttpStub
5
5
 
6
6
  attr_reader :request, :description
7
7
 
8
- def initialize(options)
9
- @processor = options[:processor]
10
- @request = options[:request]
11
- @description = options[:description]
12
- @resetable_flag = !!options[:resetable]
8
+ def initialize(args)
9
+ @processor = args[:processor]
10
+ @request = args[:request]
11
+ @description = args[:description]
12
+ @resetable_flag = !!args[:resetable]
13
13
  end
14
14
 
15
15
  def execute
@@ -4,19 +4,19 @@ module HttpStub
4
4
 
5
5
  class Stub < Net::HTTP::Post
6
6
 
7
- def initialize(uri, options)
7
+ def initialize(uri, args)
8
8
  super("/stubs")
9
9
  self.content_type = "application/json"
10
10
  self.body = {
11
11
  "uri" => HttpStub::Configurer::Request::ControllableValue.format(uri),
12
- "method" => options[:method],
13
- "headers" => HttpStub::Configurer::Request::ControllableValue.format(options[:headers] || {}),
14
- "parameters" => HttpStub::Configurer::Request::ControllableValue.format(options[:parameters] || {}),
12
+ "method" => args[:method],
13
+ "headers" => HttpStub::Configurer::Request::ControllableValue.format(args[:headers] || {}),
14
+ "parameters" => HttpStub::Configurer::Request::ControllableValue.format(args[:parameters] || {}),
15
15
  "response" => {
16
- "status" => options[:response][:status] || "",
17
- "headers" => options[:response][:headers] || {},
18
- "body" => options[:response][:body],
19
- "delay_in_seconds" => options[:response][:delay_in_seconds] || ""
16
+ "status" => args[:response][:status] || "",
17
+ "headers" => args[:response][:headers] || {},
18
+ "body" => args[:response][:body],
19
+ "delay_in_seconds" => args[:response][:delay_in_seconds] || ""
20
20
  }
21
21
  }.to_json
22
22
  end
@@ -1,16 +1,16 @@
1
1
  module HttpStub
2
2
  module Models
3
3
 
4
- class HashWithValueMatchers < Hash
4
+ class HashWithStringValueMatchers < Hash
5
5
 
6
6
  def initialize(stub_hash)
7
- stub_hash.each_pair { |key, value| self[key] = HttpStub::Models::ValueMatcher.new(value) }
7
+ stub_hash.each_pair { |key, value| self[key] = HttpStub::Models::StringValueMatcher.new(value) }
8
8
  end
9
9
 
10
10
  def match?(actual_hash)
11
11
  !(self.find do |key_and_value_matcher|
12
- other_value = actual_hash[key_and_value_matcher[0]]
13
- !key_and_value_matcher[1].match?(other_value)
12
+ key, value_matcher = key_and_value_matcher
13
+ !value_matcher.match?(actual_hash[key])
14
14
  end)
15
15
  end
16
16
 
@@ -5,13 +5,13 @@ module HttpStub
5
5
 
6
6
  private
7
7
 
8
- DEFAULT_OPTIONS = { "status" => 200, "delay_in_seconds" => 0 }.freeze
8
+ DEFAULT_ARGS = { "status" => 200, "delay_in_seconds" => 0 }.freeze
9
9
  DEFAULT_HEADERS = { "content-type" => "application/json" }.freeze
10
10
 
11
- def merge_default_options(options)
12
- options.clone.tap do |options|
13
- headers = options["headers"] ||= {}
14
- DEFAULT_OPTIONS.each { |key, value| options[key] = value if !options[key] || options[key] == "" }
11
+ def merge_default_arguments(args)
12
+ args.clone.tap do |result|
13
+ headers = result["headers"] ||= {}
14
+ DEFAULT_ARGS.each { |key, value| result[key] = value if !result[key] || result[key] == "" }
15
15
  DEFAULT_HEADERS.each { |key, value| headers[key] = value if !headers[key] || headers[key] == "" }
16
16
  end
17
17
  end
@@ -20,13 +20,13 @@ module HttpStub
20
20
 
21
21
  attr_reader :status, :body, :delay_in_seconds, :headers
22
22
 
23
- def initialize(options = {})
24
- @original_options = options
25
- resolved_options = merge_default_options(options)
26
- @status = resolved_options["status"]
27
- @body = resolved_options["body"]
28
- @delay_in_seconds = resolved_options["delay_in_seconds"]
29
- @headers = HttpStub::Models::Headers.new(resolved_options["headers"])
23
+ def initialize(args={})
24
+ @original_args = args
25
+ resolved_args = merge_default_arguments(args)
26
+ @status = resolved_args["status"]
27
+ @body = resolved_args["body"]
28
+ @delay_in_seconds = resolved_args["delay_in_seconds"]
29
+ @headers = HttpStub::Models::Headers.new(resolved_args["headers"])
30
30
  end
31
31
 
32
32
  SUCCESS = HttpStub::Models::Response.new("status" => 200, "body" => "OK")
@@ -34,7 +34,7 @@ module HttpStub
34
34
  EMPTY = HttpStub::Models::Response.new()
35
35
 
36
36
  def empty?
37
- @original_options.empty?
37
+ @original_args.empty?
38
38
  end
39
39
 
40
40
  end
@@ -1,7 +1,7 @@
1
1
  module HttpStub
2
2
  module Models
3
3
 
4
- class ValueMatcher
4
+ class StringValueMatcher
5
5
 
6
6
  private
7
7
 
@@ -12,15 +12,15 @@ module HttpStub
12
12
  public
13
13
 
14
14
  def initialize(stub_value)
15
- @stub_value = stub_value
15
+ @stub_match_value = stub_value ? stub_value.to_s : stub_value
16
16
  end
17
17
 
18
18
  def match?(actual_value)
19
- !!MATCHERS.find { |matcher| matcher.match?(@stub_value, actual_value) }
19
+ !!MATCHERS.find { |matcher| matcher.match?(@stub_match_value, actual_value) }
20
20
  end
21
21
 
22
22
  def to_s
23
- @stub_value
23
+ @stub_match_value
24
24
  end
25
25
 
26
26
  end
@@ -5,12 +5,12 @@ module HttpStub
5
5
 
6
6
  attr_reader :uri, :headers, :parameters, :response
7
7
 
8
- def initialize(options)
9
- @options = options
10
- @uri = HttpStub::Models::StubUri.new(options["uri"])
11
- @headers = HttpStub::Models::StubHeaders.new(options["headers"])
12
- @parameters = HttpStub::Models::StubParameters.new(options["parameters"])
13
- @response = HttpStub::Models::Response.new(options["response"])
8
+ def initialize(args)
9
+ @args = args
10
+ @uri = HttpStub::Models::StubUri.new(args["uri"])
11
+ @headers = HttpStub::Models::StubHeaders.new(args["headers"])
12
+ @parameters = HttpStub::Models::StubParameters.new(args["parameters"])
13
+ @response = HttpStub::Models::Response.new(args["response"])
14
14
  end
15
15
 
16
16
  def satisfies?(request)
@@ -21,11 +21,11 @@ module HttpStub
21
21
  end
22
22
 
23
23
  def method
24
- @options["method"]
24
+ @args["method"]
25
25
  end
26
26
 
27
27
  def to_s
28
- @options.to_s
28
+ @args.to_s
29
29
  end
30
30
 
31
31
  end
@@ -3,9 +3,9 @@ module HttpStub
3
3
 
4
4
  class StubActivator
5
5
 
6
- def initialize(options)
7
- @options = options
8
- @stub = HttpStub::Models::Stub.new(options)
6
+ def initialize(args)
7
+ @args = args
8
+ @stub = HttpStub::Models::Stub.new(args)
9
9
  end
10
10
 
11
11
  def satisfies?(request)
@@ -17,11 +17,11 @@ module HttpStub
17
17
  end
18
18
 
19
19
  def activation_uri
20
- @options["activation_uri"]
20
+ @args["activation_uri"]
21
21
  end
22
22
 
23
23
  def to_s
24
- @options.to_s
24
+ @args.to_s
25
25
  end
26
26
 
27
27
  end
@@ -5,7 +5,7 @@ module HttpStub
5
5
 
6
6
  def initialize(headers)
7
7
  super(headers)
8
- @headers = HttpStub::Models::HashWithValueMatchers.new((headers || {}).downcase_and_underscore_keys)
8
+ @headers = HttpStub::Models::HashWithStringValueMatchers.new((headers || {}).downcase_and_underscore_keys)
9
9
  end
10
10
 
11
11
  def match?(request)
@@ -4,7 +4,7 @@ module HttpStub
4
4
  class StubParameters
5
5
 
6
6
  def initialize(parameters)
7
- @parameters = HttpStub::Models::HashWithValueMatchers.new(parameters || {})
7
+ @parameters = HttpStub::Models::HashWithStringValueMatchers.new(parameters || {})
8
8
  end
9
9
 
10
10
  def match?(request)
@@ -4,7 +4,7 @@ module HttpStub
4
4
  class StubUri
5
5
 
6
6
  def initialize(uri)
7
- @uri = HttpStub::Models::ValueMatcher.new(uri)
7
+ @uri = HttpStub::Models::StringValueMatcher.new(uri)
8
8
  end
9
9
 
10
10
  def match?(request)
@@ -3,9 +3,9 @@ module HttpStub
3
3
 
4
4
  class ServerDaemonTasks < ::Rake::TaskLib
5
5
 
6
- def initialize(options)
7
- HttpStub::Rake::ServerTasks.new(options)
8
- namespace(options[:name]) { HttpServerManager::Rake::ServerTasks.new(HttpStub::ServerDaemon.new(options)) }
6
+ def initialize(args)
7
+ HttpStub::Rake::ServerTasks.new(args)
8
+ namespace(args[:name]) { HttpServerManager::Rake::ServerTasks.new(HttpStub::ServerDaemon.new(args)) }
9
9
  end
10
10
 
11
11
  end
@@ -3,31 +3,31 @@ module HttpStub
3
3
 
4
4
  class ServerTasks < ::Rake::TaskLib
5
5
 
6
- def initialize(options)
7
- namespace options[:name] do
8
- define_start_task(options)
9
- define_initialize_task(options) if options[:configurer]
6
+ def initialize(args)
7
+ namespace args[:name] do
8
+ define_start_task(args)
9
+ define_initialize_task(args) if args[:configurer]
10
10
  end
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def define_start_task(options)
15
+ def define_start_task(args)
16
16
  namespace :start do
17
- desc "Starts stub #{options[:name]} in the foreground"
17
+ desc "Starts stub #{args[:name]} in the foreground"
18
18
  task(:foreground) do
19
19
  HttpStub::Server.instance_eval do
20
20
  set :environment, :test
21
- set :port, options[:port]
21
+ set :port, args[:port]
22
22
  run!
23
23
  end
24
24
  end
25
25
  end
26
26
  end
27
27
 
28
- def define_initialize_task(options)
29
- desc "Configures stub #{options[:name]}"
30
- task(:configure) { options[:configurer].initialize! }
28
+ def define_initialize_task(args)
29
+ desc "Configures stub #{args[:name]}"
30
+ task(:configure) { args[:configurer].initialize! }
31
31
  end
32
32
 
33
33
  end
@@ -14,9 +14,9 @@ module HttpStub
14
14
 
15
15
  end
16
16
 
17
- def initialize(options)
18
- super({ host: "localhost" }.merge(options))
19
- @configurer = options[:configurer]
17
+ def initialize(args)
18
+ super({ host: "localhost" }.merge(args))
19
+ @configurer = args[:configurer]
20
20
  end
21
21
 
22
22
  def start!
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.13.1"
2
+ VERSION = "0.13.2"
3
3
  end
@@ -1,9 +1,9 @@
1
1
  describe HttpStub::Configurer::Command do
2
2
 
3
3
  let(:processor) { double(HttpStub::Configurer::CommandProcessor) }
4
- let(:options) { { processor: processor, request: double("HttpRequest"), description: "Some Description" } }
4
+ let(:args) { { processor: processor, request: double("HttpRequest"), description: "Some Description" } }
5
5
 
6
- let(:command) { HttpStub::Configurer::Command.new(options) }
6
+ let(:command) { HttpStub::Configurer::Command.new(args) }
7
7
 
8
8
  describe "#execute" do
9
9
 
@@ -19,7 +19,7 @@ describe HttpStub::Configurer::Command do
19
19
 
20
20
  describe "when created with a resetable flag that is true" do
21
21
 
22
- before(:each) { options.merge!(resetable: true) }
22
+ before(:each) { args.merge!(resetable: true) }
23
23
 
24
24
  it "should return true" do
25
25
  command.resetable?.should be_true
@@ -2,7 +2,7 @@ describe HttpStub::Configurer::Request::Stub do
2
2
 
3
3
  describe "#initialize" do
4
4
 
5
- context "when provided a uri and stub options" do
5
+ context "when provided a uri and stub arguments" do
6
6
 
7
7
  let(:uri) { "/some/uri" }
8
8
  let(:stub_method) { "Some Method" }
@@ -13,7 +13,7 @@ describe HttpStub::Configurer::Request::Stub do
13
13
  let(:response_body) { "Some body" }
14
14
  let(:response_delay_in_seconds) { 7 }
15
15
 
16
- let(:stub_options) do
16
+ let(:stub_args) do
17
17
  {
18
18
  method: stub_method,
19
19
  headers: request_headers,
@@ -27,7 +27,7 @@ describe HttpStub::Configurer::Request::Stub do
27
27
  }
28
28
  end
29
29
 
30
- let(:request) { HttpStub::Configurer::Request::Stub.new(uri, stub_options) }
30
+ let(:request) { HttpStub::Configurer::Request::Stub.new(uri, stub_args) }
31
31
  let(:request_body) { JSON.parse(request.body) }
32
32
 
33
33
  before(:each) { HttpStub::Configurer::Request::ControllableValue.stub(:format) }
@@ -44,7 +44,7 @@ describe HttpStub::Configurer::Request::Stub do
44
44
  request.content_type.should eql("application/json")
45
45
  end
46
46
 
47
- context "when a request header option is provided" do
47
+ context "when a request header argument is provided" do
48
48
 
49
49
  it "should format the headers into control values" do
50
50
  HttpStub::Configurer::Request::ControllableValue.should_receive(:format).with(request_headers)
@@ -66,7 +66,7 @@ describe HttpStub::Configurer::Request::Stub do
66
66
 
67
67
  end
68
68
 
69
- context "when a request parameter option is provided" do
69
+ context "when a request parameter argument is provided" do
70
70
 
71
71
  it "should format the request parameters into control values" do
72
72
  HttpStub::Configurer::Request::ControllableValue.should_receive(:format).with(request_parameters)
@@ -76,7 +76,7 @@ describe HttpStub::Configurer::Request::Stub do
76
76
 
77
77
  end
78
78
 
79
- context "when no request parameter option is provided" do
79
+ context "when no request parameter argument is provided" do
80
80
 
81
81
  let(:request_parameters) { nil }
82
82
 
@@ -96,7 +96,7 @@ describe HttpStub::Configurer::Request::Stub do
96
96
  request_body.should include("uri" => "uri as a string")
97
97
  end
98
98
 
99
- it "should have an entry for the method option" do
99
+ it "should have an entry for the method argument" do
100
100
  request_body.should include("method" => stub_method)
101
101
  end
102
102
 
@@ -114,15 +114,15 @@ describe HttpStub::Configurer::Request::Stub do
114
114
  request_body.should include("parameters" => "request parameters as string")
115
115
  end
116
116
 
117
- context "when a status response option is provided" do
117
+ context "when a status response argument is provided" do
118
118
 
119
- it "should have a response entry for the option" do
119
+ it "should have a response entry for the argument" do
120
120
  request_body["response"].should include("status" => response_status)
121
121
  end
122
122
 
123
123
  end
124
124
 
125
- context "when no status response option is provided" do
125
+ context "when no status response argument is provided" do
126
126
 
127
127
  let(:response_status) { nil }
128
128
 
@@ -132,19 +132,19 @@ describe HttpStub::Configurer::Request::Stub do
132
132
 
133
133
  end
134
134
 
135
- it "should have an entry for the response body option" do
135
+ it "should have an entry for the response body argument" do
136
136
  request_body["response"].should include("body" => response_body)
137
137
  end
138
138
 
139
- context "when a delay option is provided" do
139
+ context "when a delay argument is provided" do
140
140
 
141
- it "should have a response entry for the option" do
141
+ it "should have a response entry for the argument" do
142
142
  request_body["response"].should include("delay_in_seconds" => response_delay_in_seconds)
143
143
  end
144
144
 
145
145
  end
146
146
 
147
- context "when a delay option is not provided" do
147
+ context "when a delay argument is not provided" do
148
148
 
149
149
  let(:response_delay_in_seconds) { nil }
150
150
 
@@ -402,6 +402,96 @@ describe HttpStub::Configurer, "when the server is running" do
402
402
 
403
403
  end
404
404
 
405
+ context "whose values are numbers" do
406
+
407
+ before(:each) do
408
+ configurer.stub_response!("/stub_with_parameters", method: :get, parameters: { key: 88 },
409
+ response: { status: 203, body: "Body for parameter number" })
410
+ end
411
+
412
+ context "and that request is made" do
413
+
414
+ let(:response) { Net::HTTP.get_response(server_host, "/stub_with_parameters?key=88", server_port) }
415
+
416
+ it "should replay the stubbed response" do
417
+ response.code.should eql("203")
418
+ response.body.should eql("Body for parameter number")
419
+ end
420
+
421
+ end
422
+
423
+ end
424
+
425
+ context "whose values are regular expressions" do
426
+
427
+ before(:each) do
428
+ configurer.stub_response!(
429
+ "/stub_with_parameters", method: :get, parameters: { key: /^match.*/ },
430
+ response: { status: 202, body: "Another stub body" }
431
+ )
432
+ end
433
+
434
+ context "and a request that matches is made" do
435
+
436
+ let(:response) do
437
+ Net::HTTP.get_response(server_host, "/stub_with_parameters?key=matching_value", server_port)
438
+ end
439
+
440
+ it "should replay the stubbed response" do
441
+ response.code.should eql("202")
442
+ response.body.should eql("Another stub body")
443
+ end
444
+
445
+ end
446
+
447
+ context "and a request that does not match is made" do
448
+
449
+ let(:response) do
450
+ Net::HTTP.get_response(server_host, "/stub_with_parameters?key=does_not_match_value", server_port)
451
+ end
452
+
453
+ it "should respond with a 404 status code" do
454
+ response.code.should eql("404")
455
+ end
456
+
457
+ end
458
+
459
+ end
460
+
461
+ context "whose values indicate the parameters must be omitted" do
462
+
463
+ before(:each) do
464
+ configurer.stub_response!(
465
+ "/stub_with_omitted_parameters", method: :get, parameters: { key: :omitted },
466
+ response: { status: 202, body: "Omitted parameter stub body" }
467
+ )
468
+ end
469
+
470
+ context "and a request that matches is made" do
471
+
472
+ let(:response) { Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters", server_port) }
473
+
474
+ it "should replay the stubbed response" do
475
+ response.code.should eql("202")
476
+ response.body.should eql("Omitted parameter stub body")
477
+ end
478
+
479
+ end
480
+
481
+ context "and a request that does not match is made" do
482
+
483
+ let(:response) do
484
+ Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters?key=must_be_omitted", server_port)
485
+ end
486
+
487
+ it "should respond with a 404 status code" do
488
+ response.code.should eql("404")
489
+ end
490
+
491
+ end
492
+
493
+ end
494
+
405
495
  end
406
496
 
407
497
  end
@@ -1,4 +1,4 @@
1
- describe HttpStub::Models::HashWithValueMatchers do
1
+ describe HttpStub::Models::HashWithStringValueMatchers do
2
2
 
3
3
  let(:stubbed_hash) do
4
4
  (1..3).reduce({}) do |result, i|
@@ -8,13 +8,13 @@ describe HttpStub::Models::HashWithValueMatchers do
8
8
  end
9
9
 
10
10
  let(:value_matchers) do
11
- stubbed_hash.values.map { |value| double(HttpStub::Models::ValueMatcher, to_s: value).as_null_object }
11
+ stubbed_hash.values.map { |value| double(HttpStub::Models::StringValueMatcher, to_s: value).as_null_object }
12
12
  end
13
13
 
14
- let(:value_matcher_hash) { HttpStub::Models::HashWithValueMatchers.new(stubbed_hash) }
14
+ let(:value_matcher_hash) { HttpStub::Models::HashWithStringValueMatchers.new(stubbed_hash) }
15
15
 
16
16
  before(:each) do
17
- value_matchers.each { |value| HttpStub::Models::ValueMatcher.stub(:new).with(value.to_s).and_return(value) }
17
+ value_matchers.each { |value| HttpStub::Models::StringValueMatcher.stub(:new).with(value.to_s).and_return(value) }
18
18
  end
19
19
 
20
20
  it "should be hash" do
@@ -25,7 +25,7 @@ describe HttpStub::Models::HashWithValueMatchers do
25
25
 
26
26
  it "should create a value matcher representation of each value in the hash" do
27
27
  value_matchers.each do |value|
28
- HttpStub::Models::ValueMatcher.should_receive(:new).with(value.to_s).and_return(value)
28
+ HttpStub::Models::StringValueMatcher.should_receive(:new).with(value.to_s).and_return(value)
29
29
  end
30
30
 
31
31
  value_matcher_hash.values.should eql(value_matchers)
@@ -41,7 +41,7 @@ describe HttpStub::Models::Response do
41
41
 
42
42
  describe "#status" do
43
43
 
44
- context "when a value is provided in the options" do
44
+ context "when a value is provided in the arguments" do
45
45
 
46
46
  context "that is an integer" do
47
47
 
@@ -63,7 +63,7 @@ describe HttpStub::Models::Response do
63
63
 
64
64
  end
65
65
 
66
- context "when the status is not provided in the options" do
66
+ context "when the status is not provided in the arguments" do
67
67
 
68
68
  let(:response) { HttpStub::Models::Response.new("body" => body, "delay_in_seconds" => delay_in_seconds) }
69
69
 
@@ -77,7 +77,7 @@ describe HttpStub::Models::Response do
77
77
 
78
78
  describe "#body" do
79
79
 
80
- it "should return the value provided in the options" do
80
+ it "should return the value provided in the arguments" do
81
81
  response.body.should eql("A response body")
82
82
  end
83
83
 
@@ -85,7 +85,7 @@ describe HttpStub::Models::Response do
85
85
 
86
86
  describe "#delay_in_seconds" do
87
87
 
88
- context "when a value is provided in the options" do
88
+ context "when a value is provided in the arguments" do
89
89
 
90
90
  context "that is an integer" do
91
91
 
@@ -107,7 +107,7 @@ describe HttpStub::Models::Response do
107
107
 
108
108
  end
109
109
 
110
- context "when a value is not provided in the options" do
110
+ context "when a value is not provided in the arguments" do
111
111
 
112
112
  let(:response) { HttpStub::Models::Response.new("status" => status, "body" => body) }
113
113
 
@@ -0,0 +1,121 @@
1
+ describe HttpStub::Models::StringValueMatcher do
2
+
3
+ let(:stub_value) { "some stub value" }
4
+
5
+ let(:string_value_matcher) { HttpStub::Models::StringValueMatcher.new(stub_value) }
6
+
7
+ describe "#match?" do
8
+
9
+ let(:actual_value) { "some actual value" }
10
+
11
+ shared_examples_for "a StringValueMatcher that matches an expected stub value" do
12
+
13
+ it "should determine if actual value should be omitted" do
14
+ HttpStub::Models::OmittedValueMatcher.should_receive(:match?).with(expected_stub_match_value, actual_value)
15
+
16
+ perform_match
17
+ end
18
+
19
+ it "should determine if the actual value matches a regular expression" do
20
+ HttpStub::Models::RegexpValueMatcher.should_receive(:match?).with(expected_stub_match_value, actual_value)
21
+
22
+ perform_match
23
+ end
24
+
25
+ it "should determine if the actual value exactly matches the stub value" do
26
+ HttpStub::Models::ExactValueMatcher.should_receive(:match?).with(expected_stub_match_value, actual_value)
27
+
28
+ perform_match
29
+ end
30
+
31
+ it "should determine if actual value should be omitted" do
32
+ HttpStub::Models::OmittedValueMatcher.should_receive(:match?).with(expected_stub_match_value, actual_value)
33
+
34
+ perform_match
35
+ end
36
+
37
+ it "should determine if the actual value matches a regular expression" do
38
+ HttpStub::Models::RegexpValueMatcher.should_receive(:match?).with(expected_stub_match_value, actual_value)
39
+
40
+ perform_match
41
+ end
42
+
43
+ it "should determine if the actual value exactly matches the stub value" do
44
+ HttpStub::Models::ExactValueMatcher.should_receive(:match?).with(expected_stub_match_value, actual_value)
45
+
46
+ perform_match
47
+ end
48
+
49
+ end
50
+
51
+ context "when the provided stub value is a string" do
52
+
53
+ let(:stub_value) { "some stub value" }
54
+ let(:expected_stub_match_value) { "some stub value" }
55
+
56
+ it_should_behave_like "a StringValueMatcher that matches an expected stub value"
57
+
58
+ end
59
+
60
+ context "when the provided stub value is not a string" do
61
+
62
+ let(:stub_value) { 88 }
63
+ let(:expected_stub_match_value) { "88" }
64
+
65
+ it_should_behave_like "a StringValueMatcher that matches an expected stub value"
66
+
67
+ end
68
+
69
+ context "when an omitted match occurs" do
70
+
71
+ before(:each) { HttpStub::Models::OmittedValueMatcher.should_receive(:match?).and_return(true) }
72
+
73
+ it "should return true" do
74
+ perform_match.should be_true
75
+ end
76
+
77
+ end
78
+
79
+ context "when a regular expression match occurs" do
80
+
81
+ before(:each) { HttpStub::Models::RegexpValueMatcher.should_receive(:match?).and_return(true) }
82
+
83
+ it "should return true" do
84
+ perform_match.should be_true
85
+ end
86
+
87
+ end
88
+
89
+ context "when an exact match occurs" do
90
+
91
+ before(:each) { HttpStub::Models::ExactValueMatcher.should_receive(:match?).and_return(true) }
92
+
93
+ it "should return true" do
94
+ perform_match.should be_true
95
+ end
96
+
97
+ end
98
+
99
+ context "when no match occurs" do
100
+
101
+ it "should return false" do
102
+ perform_match.should be_false
103
+ end
104
+
105
+ end
106
+
107
+ def perform_match
108
+ string_value_matcher.match?(actual_value)
109
+ end
110
+
111
+ end
112
+
113
+ describe "#to_s" do
114
+
115
+ it "should return the stub value provided" do
116
+ string_value_matcher.to_s.should eql(stub_value)
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -1,10 +1,10 @@
1
1
  describe HttpStub::Models::StubActivator do
2
2
 
3
3
  let(:activation_uri) { "/some/activation/uri" }
4
- let(:options) do
4
+ let(:args) do
5
5
  { "activation_uri" => activation_uri }
6
6
  end
7
- let(:stub_activator) { HttpStub::Models::StubActivator.new(options) }
7
+ let(:stub_activator) { HttpStub::Models::StubActivator.new(args) }
8
8
 
9
9
  before(:each) { HttpStub::Models::Stub.stub(:new).and_return(double(HttpStub::Models::Stub)) }
10
10
 
@@ -46,9 +46,9 @@ describe HttpStub::Models::StubActivator do
46
46
 
47
47
  describe "#the_stub" do
48
48
 
49
- it "should return a HttpStub::Models::Stub constructed from the activator's options" do
49
+ it "should return a HttpStub::Models::Stub constructed from the activator's arguments" do
50
50
  stub = double(HttpStub::Models::Stub)
51
- HttpStub::Models::Stub.should_receive(:new).with(options).and_return(stub)
51
+ HttpStub::Models::Stub.should_receive(:new).with(args).and_return(stub)
52
52
 
53
53
  stub_activator.the_stub.should eql(stub)
54
54
  end
@@ -65,10 +65,10 @@ describe HttpStub::Models::StubActivator do
65
65
 
66
66
  describe "#to_s" do
67
67
 
68
- it "should return the string representation of the activation options" do
69
- options.should_receive(:to_s).and_return("activation options string")
68
+ it "should return the string representation of the activation arguments" do
69
+ args.should_receive(:to_s).and_return("activation args string")
70
70
 
71
- stub_activator.to_s.should eql("activation options string")
71
+ stub_activator.to_s.should eql("activation args string")
72
72
  end
73
73
 
74
74
  end
@@ -14,7 +14,7 @@ describe HttpStub::Models::StubHeaders do
14
14
  it "should create a regexpable representation of the stubbed headers whose keys are downcased and underscored" do
15
15
  downcased_and_underscored_hash = { "another_stub_key" => "value" }
16
16
  stubbed_headers.should_receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
17
- HttpStub::Models::HashWithValueMatchers.should_receive(:new).with(downcased_and_underscored_hash)
17
+ HttpStub::Models::HashWithStringValueMatchers.should_receive(:new).with(downcased_and_underscored_hash)
18
18
 
19
19
  stub_headers
20
20
  end
@@ -26,7 +26,7 @@ describe HttpStub::Models::StubHeaders do
26
26
  let(:stubbed_headers) { nil }
27
27
 
28
28
  it "should create a regexpable representation of an empty hash" do
29
- HttpStub::Models::HashWithValueMatchers.should_receive(:new).with({})
29
+ HttpStub::Models::HashWithStringValueMatchers.should_receive(:new).with({})
30
30
 
31
31
  stub_headers
32
32
  end
@@ -36,10 +36,10 @@ describe HttpStub::Models::StubHeaders do
36
36
  describe "#match?" do
37
37
 
38
38
  let(:request_headers) { { "request_key" => "value" } }
39
- let(:regexpable_stubbed_headers) { double(HttpStub::Models::HashWithValueMatchers).as_null_object }
39
+ let(:regexpable_stubbed_headers) { double(HttpStub::Models::HashWithStringValueMatchers).as_null_object }
40
40
 
41
41
  before(:each) do
42
- HttpStub::Models::HashWithValueMatchers.stub(:new).and_return(regexpable_stubbed_headers)
42
+ HttpStub::Models::HashWithStringValueMatchers.stub(:new).and_return(regexpable_stubbed_headers)
43
43
  HttpStub::Models::RequestHeaderParser.stub(:parse).with(request).and_return(request_headers)
44
44
  end
45
45
 
@@ -4,14 +4,14 @@ describe HttpStub::Models::StubParameters do
4
4
  let(:request) { double("HttpRequest", params: request_parameters) }
5
5
 
6
6
  let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
7
- let(:regexpable_stubbed_paremeters) { double(HttpStub::Models::HashWithValueMatchers).as_null_object }
7
+ let(:regexpable_stubbed_paremeters) { double(HttpStub::Models::HashWithStringValueMatchers).as_null_object }
8
8
 
9
9
  let(:stub_parameters) { HttpStub::Models::StubParameters.new(stubbed_parameters) }
10
10
 
11
11
  describe "when stubbed parameters are provided" do
12
12
 
13
13
  it "should create a regexpable representation of the stubbed parameters" do
14
- HttpStub::Models::HashWithValueMatchers.should_receive(:new).with(stubbed_parameters)
14
+ HttpStub::Models::HashWithStringValueMatchers.should_receive(:new).with(stubbed_parameters)
15
15
 
16
16
  stub_parameters
17
17
  end
@@ -23,7 +23,7 @@ describe HttpStub::Models::StubParameters do
23
23
  let(:stubbed_parameters) { nil }
24
24
 
25
25
  it "should create a regexpable representation of an empty hash" do
26
- HttpStub::Models::HashWithValueMatchers.should_receive(:new).with({})
26
+ HttpStub::Models::HashWithStringValueMatchers.should_receive(:new).with({})
27
27
 
28
28
  stub_parameters
29
29
  end
@@ -33,7 +33,7 @@ describe HttpStub::Models::StubParameters do
33
33
  describe "#match?" do
34
34
 
35
35
  it "should delegate to the regexpable representation of the stubbed parameters to determine a match" do
36
- HttpStub::Models::HashWithValueMatchers.stub(:new).and_return(regexpable_stubbed_paremeters)
36
+ HttpStub::Models::HashWithStringValueMatchers.stub(:new).and_return(regexpable_stubbed_paremeters)
37
37
  regexpable_stubbed_paremeters.should_receive(:match?).with(request_parameters).and_return(true)
38
38
 
39
39
  stub_parameters.match?(request).should be(true)
@@ -15,7 +15,7 @@ describe HttpStub::Models::Stub do
15
15
  }
16
16
  end
17
17
  let(:stub_method) { "get" }
18
- let(:stub_options) do
18
+ let(:stub_args) do
19
19
  {
20
20
  "uri" => "/a_path",
21
21
  "method" => stub_method,
@@ -31,7 +31,7 @@ describe HttpStub::Models::Stub do
31
31
  let(:stub_parameters) { double(HttpStub::Models::StubParameters, match?: true) }
32
32
  let(:stub_headers) { double(HttpStub::Models::StubHeaders, match?: true) }
33
33
 
34
- let(:the_stub) { HttpStub::Models::Stub.new(stub_options) }
34
+ let(:the_stub) { HttpStub::Models::Stub.new(stub_args) }
35
35
 
36
36
  before(:each) do
37
37
  HttpStub::Models::StubUri.stub(:new).and_return(stub_uri)
@@ -167,10 +167,10 @@ describe HttpStub::Models::Stub do
167
167
 
168
168
  describe "#to_s" do
169
169
 
170
- it "should return a string representation of the stub options" do
171
- stub_options.should_receive(:to_s).and_return("stub options string")
170
+ it "should return a string representation of the stub arguments" do
171
+ stub_args.should_receive(:to_s).and_return("stub arguments string")
172
172
 
173
- the_stub.to_s.should eql("stub options string")
173
+ the_stub.to_s.should eql("stub arguments string")
174
174
  end
175
175
  end
176
176
 
@@ -2,15 +2,15 @@ describe HttpStub::Models::StubUri do
2
2
 
3
3
  let(:stubbed_uri) { "/some/uri" }
4
4
  let(:request) { double("HttpRequest", path_info: request_uri) }
5
- let(:value_matcher) { double(HttpStub::Models::ValueMatcher).as_null_object }
5
+ let(:value_matcher) { double(HttpStub::Models::StringValueMatcher).as_null_object }
6
6
  let(:stub_uri) { HttpStub::Models::StubUri.new(stubbed_uri) }
7
7
 
8
- before(:each) { HttpStub::Models::ValueMatcher.stub(:new).and_return(value_matcher) }
8
+ before(:each) { HttpStub::Models::StringValueMatcher.stub(:new).and_return(value_matcher) }
9
9
 
10
10
  describe "constructor" do
11
11
 
12
12
  it "should create a value matcher for the provided uri" do
13
- HttpStub::Models::ValueMatcher.should_receive(:new).with(stubbed_uri)
13
+ HttpStub::Models::StringValueMatcher.should_receive(:new).with(stubbed_uri)
14
14
 
15
15
  stub_uri
16
16
  end
@@ -2,14 +2,14 @@ describe HttpStub::Rake::ServerTasks do
2
2
 
3
3
  describe "the configure task" do
4
4
 
5
- let(:default_options) { { port: 8001 } }
5
+ let(:default_args) { { port: 8001 } }
6
6
 
7
- before(:each) { HttpStub::Rake::ServerTasks.new(default_options.merge(options)) }
7
+ before(:each) { HttpStub::Rake::ServerTasks.new(default_args.merge(args)) }
8
8
 
9
9
  context "when a configurer is provided" do
10
10
 
11
11
  let(:configurer) { double(HttpStub::Configurer) }
12
- let(:options) { { name: :tasks_configurer_provided_test, configurer: configurer } }
12
+ let(:args) { { name: :tasks_configurer_provided_test, configurer: configurer } }
13
13
 
14
14
  context "and the task is executed" do
15
15
 
@@ -25,7 +25,7 @@ describe HttpStub::Rake::ServerTasks do
25
25
 
26
26
  context "when a configurer is not provided" do
27
27
 
28
- let(:options) { { name: :tasks_configurer_not_provided_test } }
28
+ let(:args) { { name: :tasks_configurer_not_provided_test } }
29
29
 
30
30
  it "should not generate a task" do
31
31
  lambda { Rake::Task["tasks_configurer_not_provided_test:configure"] }.should
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.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ueckerman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-27 00:00:00.000000000 Z
12
+ date: 2013-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -255,7 +255,7 @@ files:
255
255
  - ./lib/http_stub/controllers/stub_controller.rb
256
256
  - ./lib/http_stub/hash_extensions.rb
257
257
  - ./lib/http_stub/models/exact_value_matcher.rb
258
- - ./lib/http_stub/models/hash_with_value_matchers.rb
258
+ - ./lib/http_stub/models/hash_with_string_value_matchers.rb
259
259
  - ./lib/http_stub/models/headers.rb
260
260
  - ./lib/http_stub/models/omitted_value_matcher.rb
261
261
  - ./lib/http_stub/models/regexp_value_matcher.rb
@@ -263,12 +263,12 @@ files:
263
263
  - ./lib/http_stub/models/request_header_parser.rb
264
264
  - ./lib/http_stub/models/request_pipeline.rb
265
265
  - ./lib/http_stub/models/response.rb
266
+ - ./lib/http_stub/models/string_value_matcher.rb
266
267
  - ./lib/http_stub/models/stub.rb
267
268
  - ./lib/http_stub/models/stub_activator.rb
268
269
  - ./lib/http_stub/models/stub_headers.rb
269
270
  - ./lib/http_stub/models/stub_parameters.rb
270
271
  - ./lib/http_stub/models/stub_uri.rb
271
- - ./lib/http_stub/models/value_matcher.rb
272
272
  - ./lib/http_stub/rake/server_daemon_tasks.rb
273
273
  - ./lib/http_stub/rake/server_tasks.rb
274
274
  - ./lib/http_stub/rake/task_generators.rb
@@ -297,7 +297,7 @@ files:
297
297
  - ./spec/lib/http_stub/controllers/stub_controller_spec.rb
298
298
  - ./spec/lib/http_stub/hash_extensions_spec.rb
299
299
  - ./spec/lib/http_stub/models/exact_value_matcher_spec.rb
300
- - ./spec/lib/http_stub/models/hash_with_value_matchers_spec.rb
300
+ - ./spec/lib/http_stub/models/hash_with_string_value_matchers_spec.rb
301
301
  - ./spec/lib/http_stub/models/headers_spec.rb
302
302
  - ./spec/lib/http_stub/models/omitted_value_matcher_spec.rb
303
303
  - ./spec/lib/http_stub/models/regexp_value_matcher_spec.rb
@@ -305,12 +305,12 @@ files:
305
305
  - ./spec/lib/http_stub/models/request_header_parser_spec.rb
306
306
  - ./spec/lib/http_stub/models/request_pipeline_spec.rb
307
307
  - ./spec/lib/http_stub/models/response_spec.rb
308
+ - ./spec/lib/http_stub/models/string_value_matcher_spec.rb
308
309
  - ./spec/lib/http_stub/models/stub_activator_spec.rb
309
310
  - ./spec/lib/http_stub/models/stub_headers_spec.rb
310
311
  - ./spec/lib/http_stub/models/stub_parameters_spec.rb
311
312
  - ./spec/lib/http_stub/models/stub_spec.rb
312
313
  - ./spec/lib/http_stub/models/stub_uri_spec.rb
313
- - ./spec/lib/http_stub/models/value_matcher_spec.rb
314
314
  - ./spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb
315
315
  - ./spec/lib/http_stub/rake/server_tasks_smoke_spec.rb
316
316
  - ./spec/lib/http_stub/rake/server_tasks_spec.rb
@@ -361,7 +361,7 @@ test_files:
361
361
  - ./spec/lib/http_stub/controllers/stub_controller_spec.rb
362
362
  - ./spec/lib/http_stub/hash_extensions_spec.rb
363
363
  - ./spec/lib/http_stub/models/exact_value_matcher_spec.rb
364
- - ./spec/lib/http_stub/models/hash_with_value_matchers_spec.rb
364
+ - ./spec/lib/http_stub/models/hash_with_string_value_matchers_spec.rb
365
365
  - ./spec/lib/http_stub/models/headers_spec.rb
366
366
  - ./spec/lib/http_stub/models/omitted_value_matcher_spec.rb
367
367
  - ./spec/lib/http_stub/models/regexp_value_matcher_spec.rb
@@ -369,12 +369,12 @@ test_files:
369
369
  - ./spec/lib/http_stub/models/request_header_parser_spec.rb
370
370
  - ./spec/lib/http_stub/models/request_pipeline_spec.rb
371
371
  - ./spec/lib/http_stub/models/response_spec.rb
372
+ - ./spec/lib/http_stub/models/string_value_matcher_spec.rb
372
373
  - ./spec/lib/http_stub/models/stub_activator_spec.rb
373
374
  - ./spec/lib/http_stub/models/stub_headers_spec.rb
374
375
  - ./spec/lib/http_stub/models/stub_parameters_spec.rb
375
376
  - ./spec/lib/http_stub/models/stub_spec.rb
376
377
  - ./spec/lib/http_stub/models/stub_uri_spec.rb
377
- - ./spec/lib/http_stub/models/value_matcher_spec.rb
378
378
  - ./spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb
379
379
  - ./spec/lib/http_stub/rake/server_tasks_smoke_spec.rb
380
380
  - ./spec/lib/http_stub/rake/server_tasks_spec.rb
@@ -1,81 +0,0 @@
1
- describe HttpStub::Models::ValueMatcher do
2
-
3
- let(:stub_value) { "some stub value" }
4
-
5
- let(:value_matcher) { HttpStub::Models::ValueMatcher.new(stub_value) }
6
-
7
- describe "#match?" do
8
-
9
- let(:actual_value) { "some actual value" }
10
-
11
- it "should determine if actual value should be omitted" do
12
- HttpStub::Models::OmittedValueMatcher.should_receive(:match?).with(stub_value, actual_value)
13
-
14
- perform_match
15
- end
16
-
17
- it "should determine if the actual value matches a regular expression" do
18
- HttpStub::Models::RegexpValueMatcher.should_receive(:match?).with(stub_value, actual_value)
19
-
20
- perform_match
21
- end
22
-
23
- it "should determine if the actual value exactly matches the stub value" do
24
- HttpStub::Models::ExactValueMatcher.should_receive(:match?).with(stub_value, actual_value)
25
-
26
- perform_match
27
- end
28
-
29
- context "when an omitted match occurs" do
30
-
31
- before(:each) { HttpStub::Models::OmittedValueMatcher.should_receive(:match?).and_return(true) }
32
-
33
- it "should return true" do
34
- perform_match.should be_true
35
- end
36
-
37
- end
38
-
39
- context "when a regular expression match occurs" do
40
-
41
- before(:each) { HttpStub::Models::RegexpValueMatcher.should_receive(:match?).and_return(true) }
42
-
43
- it "should return true" do
44
- perform_match.should be_true
45
- end
46
-
47
- end
48
-
49
- context "when an exact match occurs" do
50
-
51
- before(:each) { HttpStub::Models::ExactValueMatcher.should_receive(:match?).and_return(true) }
52
-
53
- it "should return true" do
54
- perform_match.should be_true
55
- end
56
-
57
- end
58
-
59
- context "when no match occurs" do
60
-
61
- it "should return false" do
62
- perform_match.should be_false
63
- end
64
-
65
- end
66
-
67
- def perform_match
68
- value_matcher.match?(actual_value)
69
- end
70
-
71
- end
72
-
73
- describe "#to_s" do
74
-
75
- it "should return the stub value provided" do
76
- value_matcher.to_s.should eql(stub_value)
77
- end
78
-
79
- end
80
-
81
- end