Skip to content

Commit

Permalink
ruby: Remove "multi-json" from dependencies
Browse files Browse the repository at this point in the history
Use "json" which is a part of Ruby stdlib since 1.9.0.
Closes SeleniumHQ#1632
  • Loading branch information
p0deje committed Feb 25, 2016
1 parent a74cfe8 commit 1ca810f
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 75 deletions.
6 changes: 6 additions & 0 deletions rb/CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.53.0 (Unreleased)
===================

Ruby:
* Removed dependency on "multi_json" (issue 1632)

2.52.0 (2016-02-12)
===================

Expand Down
4 changes: 1 addition & 3 deletions rb/lib/selenium/webdriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
require 'tmpdir'
require 'fileutils'
require 'date'
require 'json'

require 'multi_json'
require 'selenium/webdriver/common'

module Selenium
module WebDriver
extend JsonHelper

Point = Struct.new(:x, :y)
Dimension = Struct.new(:width, :height)
Location = Struct.new(:latitude, :longitude, :altitude)
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/chrome/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def write_prefs_to(dir)
prefs_file = prefs_file_for(dir)

FileUtils.mkdir_p File.dirname(prefs_file)
File.open(prefs_file, "w") { |file| file << WebDriver.json_dump(prefs) }
File.open(prefs_file, "w") { |file| file << JSON.generate(prefs) }
end

def prefs
Expand All @@ -96,7 +96,7 @@ def prefs

def read_model_prefs
return {} unless @model
WebDriver.json_load File.read(prefs_file_for(@model))
JSON.parse File.read(prefs_file_for(@model))
end

def prefs_file_for(dir)
Expand Down
1 change: 0 additions & 1 deletion rb/lib/selenium/webdriver/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@
require 'selenium/webdriver/common/keys'
require 'selenium/webdriver/common/bridge_helper'
require 'selenium/webdriver/common/profile_helper'
require 'selenium/webdriver/common/json_helper'
require 'selenium/webdriver/common/driver'
require 'selenium/webdriver/common/element'
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def ref
#

def to_json(*args)
WebDriver.json_dump as_json
JSON.generate as_json
end

#
Expand Down
53 changes: 0 additions & 53 deletions rb/lib/selenium/webdriver/common/json_helper.rb

This file was deleted.

4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/common/profile_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def as_json(opts = nil)
end

def to_json(*args)
WebDriver.json_dump as_json
JSON.generate as_json
end

private
Expand All @@ -65,7 +65,7 @@ def verify_model(model)

module ClassMethods
def from_json(json)
data = WebDriver.json_load(json).fetch('zip')
data = JSON.parse(json).fetch('zip')

# can't use Tempfile here since it doesn't support File::BINARY mode on 1.8
# can't use Dir.mktmpdir(&blk) because of http://jira.codehaus.org/browse/JRUBY-4082
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def as_json(opts = nil)
end

def to_json(*args)
WebDriver.json_dump as_json
JSON.generate as_json
end

class << self
Expand Down
6 changes: 3 additions & 3 deletions rb/lib/selenium/webdriver/firefox/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def from_name(name)
end

def default_preferences
@default_preferences ||= WebDriver.json_load(
@default_preferences ||= JSON.parse(
File.read(File.expand_path("#{WebDriver.root}/selenium/webdriver/firefox/extension/prefs.json"))
).freeze
end
Expand Down Expand Up @@ -261,7 +261,7 @@ def read_user_prefs(path)
key, value = $1.strip, $2.strip

# wrap the value in an array to make it a valid JSON string.
prefs[key] = WebDriver.json_load("[#{value}]").first
prefs[key] = JSON.parse("[#{value}]").first
end
end

Expand All @@ -271,7 +271,7 @@ def read_user_prefs(path)
def write_prefs(prefs, path)
File.open(path, "w") { |file|
prefs.each do |key, value|
file.puts %{user_pref("#{key}", #{WebDriver.json_dump value});}
file.puts %{user_pref("#{key}", #{value.to_json});}
end
}
end
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/remote/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def as_json(opts = nil)
end

def to_json(*args)
WebDriver.json_dump as_json
JSON.generate as_json
end

def ==(other)
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/remote/http/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def call(verb, url, command_hash)
headers['Cache-Control'] = "no-cache" if verb == :get

if command_hash
payload = WebDriver.json_dump(command_hash)
payload = JSON.generate(command_hash)
headers["Content-Type"] = "#{CONTENT_TYPE}; charset=utf-8"
headers["Content-Length"] = payload.bytesize.to_s if [:post, :put].include?(verb)

Expand Down Expand Up @@ -75,7 +75,7 @@ def create_response(code, body, content_type)

if content_type.include? CONTENT_TYPE
raise Error::WebDriverError, "empty body: #{content_type.inspect} (#{code})\n#{body}" if body.empty?
Response.new(code, WebDriver.json_load(body))
Response.new(code, JSON.parse(body))
elsif code == 204
Response.new(code)
else
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/remote/w3c_capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def as_json(opts = nil)
end

def to_json(*args)
WebDriver.json_dump as_json
JSON.generate as_json
end

def ==(other)
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/safari/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def stop
end

def send(command)
json = WebDriver.json_dump(command)
json = JSON.generate(command)
puts ">>> #{json}" if $DEBUG

frame = WebSocket::Frame::Outgoing::Server.new(:version => @version, :data => json, :type => :text)
Expand Down Expand Up @@ -76,7 +76,7 @@ def receive

puts "<<< #{msg}" if $DEBUG

WebDriver.json_load msg.to_s
JSON.parse msg.to_s
end

def ws_uri
Expand Down
1 change: 0 additions & 1 deletion rb/selenium-webdriver.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Gem::Specification.new do |s|
s.files = Dir[root + '/**/*'].reject { |e| e =~ /ruby\.iml|build\.desc/ }.map { |e| e.sub(root + '/', '') }
s.require_paths = ["lib"]

s.add_runtime_dependency "multi_json", ["~> 1.0"]
s.add_runtime_dependency "rubyzip", ["~> 1.0"]
s.add_runtime_dependency "childprocess", ["~> 0.5"]
s.add_runtime_dependency "websocket", ["~> 1.0"]
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/chrome/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Chrome

model_profile.layout_on_disk

result = WebDriver.json_load(mock_io.string)
result = JSON.parse(mock_io.string)

expect(result['autofill']['enabled']).to eq(false)
expect(result['some']['other']['pref']).to eq(123)
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/unit/selenium/webdriver/remote/bridge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Remote
end

it "raises WebDriverError if uploading non-files" do
request_body = WebDriver.json_dump(:sessionId => '11123', :value => {})
request_body = JSON.generate(:sessionId => '11123', :value => {})
headers = {'Content-Type' => 'application/json'}
stub_request(:post, "http://127.0.0.1:4444/wd/hub/session").to_return(
:status => 200, :body => request_body, :headers => headers)
Expand Down

0 comments on commit 1ca810f

Please sign in to comment.