Skip to content

Commit

Permalink
Fixed issue with stubbing requests with request body declared as a ha…
Browse files Browse the repository at this point in the history
…sh, when json was not required.
  • Loading branch information
bblimke committed Nov 5, 2010
1 parent 622912b commit a7cb4fa
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,8 @@
require 'webmock/rspec' require 'webmock/rspec'
require 'webmock/cucumber' require 'webmock/cucumber'


* Fixed issue with stubbing requests with request body declared as a hash, when json was not required. Thanks to Erik Michaels-Ober for reporting the issue.



## 1.5.0 ## 1.5.0


Expand Down
2 changes: 2 additions & 0 deletions lib/webmock/request_pattern.rb
@@ -1,3 +1,5 @@
require 'json'

module WebMock module WebMock


class RequestPattern class RequestPattern
Expand Down
1 change: 1 addition & 0 deletions spec/other_net_http_libs_spec.rb
Expand Up @@ -6,6 +6,7 @@ def capture_output_from_requiring(libs, additional_code = "")
requires = libs.map { |lib| "require '#{lib}'" } requires = libs.map { |lib| "require '#{lib}'" }
requires << " require 'addressable/uri'" requires << " require 'addressable/uri'"
requires << " require 'crack'" requires << " require 'crack'"
requires << " require 'json'"
requires = requires.join("; ") requires = requires.join("; ")
webmock_dir = "#{File.dirname(__FILE__)}/../lib" webmock_dir = "#{File.dirname(__FILE__)}/../lib"
vendor_dirs = Dir["#{File.dirname(__FILE__)}/vendor/*/lib"] vendor_dirs = Dir["#{File.dirname(__FILE__)}/vendor/*/lib"]
Expand Down
4 changes: 1 addition & 3 deletions spec/spec_helper.rb
Expand Up @@ -14,8 +14,6 @@


require 'network_connection' require 'network_connection'


require 'json'

RSpec.configure do |config| RSpec.configure do |config|
config.include WebMock::API config.include WebMock::API
unless NetworkConnection.is_network_available? unless NetworkConnection.is_network_available?
Expand Down Expand Up @@ -55,7 +53,7 @@ def client_specific_request_string(string)
default_headers = default_client_request_headers(method, has_body) default_headers = default_client_request_headers(method, has_body)
if default_headers if default_headers
if string.include?(" with headers") if string.include?(" with headers")
current_headers = JSON.parse(string.gsub(/.*with headers (\{[^}]+\}).*/, '\1').gsub("=>",":").gsub("'","\"")) current_headers = Crack::JSON.parse(string.gsub(/.*with headers (\{[^}]+\}).*/, '\1').gsub("=>",":").gsub("'","\""))
default_headers = WebMock::Util::Headers.normalize_headers(default_headers) default_headers = WebMock::Util::Headers.normalize_headers(default_headers)
default_headers.merge!(current_headers) default_headers.merge!(current_headers)
string.gsub!(/(.*) with headers.*/,'\1') string.gsub!(/(.*) with headers.*/,'\1')
Expand Down
Empty file added spec/vendor/json/lib/json.rb
Empty file.
3 changes: 2 additions & 1 deletion webmock.gemspec
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|


s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Bartosz Blimke"] s.authors = ["Bartosz Blimke"]
s.date = %q{2010-11-03} s.date = %q{2010-11-05}
s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.} s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.}
s.email = %q{bartosz.blimke@gmail.com} s.email = %q{bartosz.blimke@gmail.com}
s.extra_rdoc_files = [ s.extra_rdoc_files = [
Expand Down Expand Up @@ -122,6 +122,7 @@ Gem::Specification.new do |s|
"spec/vendor/addressable/lib/addressable/uri.rb", "spec/vendor/addressable/lib/addressable/uri.rb",
"spec/vendor/addressable/lib/uri.rb", "spec/vendor/addressable/lib/uri.rb",
"spec/vendor/crack/lib/crack.rb", "spec/vendor/crack/lib/crack.rb",
"spec/vendor/json/lib/json.rb",
"spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb", "spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb",
"spec/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb", "spec/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb",
"spec/vendor/right_http_connection-1.2.4/setup.rb", "spec/vendor/right_http_connection-1.2.4/setup.rb",
Expand Down

0 comments on commit a7cb4fa

Please sign in to comment.