Skip to content

Commit

Permalink
Merge pull request teampoltergeist#328 from kyrylo/327-multi-json
Browse files Browse the repository at this point in the history
Revert “Remove multi_json dependency”
  • Loading branch information
jonleighton committed Jun 10, 2013
2 parents c2495ea + c4065b1 commit c3c5106
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/capybara/poltergeist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Poltergeist
require 'capybara/poltergeist/web_socket_server'
require 'capybara/poltergeist/client'
require 'capybara/poltergeist/inspector'
require 'capybara/poltergeist/json'
require 'capybara/poltergeist/network_traffic'
require 'capybara/poltergeist/errors'
require 'capybara/poltergeist/cookie'
Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/poltergeist/browser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "capybara/poltergeist/errors"
require 'json'
require 'multi_json'
require 'time'

module Capybara::Poltergeist
Expand Down Expand Up @@ -221,7 +221,7 @@ def command(name, *args)
message = { 'name' => name, 'args' => args }
log message.inspect

json = JSON.load(server.send(JSON.generate(message)))
json = JSON.load(server.send(JSON.dump(message)))
log json.inspect

if json['error']
Expand Down
25 changes: 25 additions & 0 deletions lib/capybara/poltergeist/json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Capybara::Poltergeist
module JSON
def self.load(message)
if dumpy_multi_json?
MultiJson.load(message)
else
MultiJson.decode(message)
end
end

def self.dump(message)
if dumpy_multi_json?
MultiJson.dump(message)
else
MultiJson.encode(message)
end
end

private

def self.dumpy_multi_json?
MultiJson.respond_to?(:dump) && MultiJson.respond_to?(:load)
end
end
end
1 change: 1 addition & 0 deletions poltergeist.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Gem::Specification.new do |s|

s.add_dependency "capybara", "~> 2.1.0"
s.add_dependency "websocket-driver", ">= 0.2.0"
s.add_dependency "multi_json", "~> 1.0"

s.add_development_dependency 'rspec', '~> 2.12'
s.add_development_dependency 'sinatra', '~> 1.0'
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Capybara::Poltergeist
it 'logs requests and responses to the client' do
request = { 'name' => 'where is', 'args' => ["the love?"] }
response = { 'response' => '<3' }
server.stub(:send).with(JSON.generate(request)).and_return(JSON.generate(response))
server.stub(:send).with(MultiJson.dump(request)).and_return(JSON.dump(response))

subject.command('where is', 'the love?')

Expand Down

0 comments on commit c3c5106

Please sign in to comment.