1
0
Fork 0
mirror of https://github.com/teampoltergeist/poltergeist.git synced 2022-11-09 12:05:00 -05:00

Log raw JSON messages/responses rather than Ruby-parsed and inspected

This allows problems to be more easily reproduced and also allows for
the logger output to be programatically parsed (by languages other than
Ruby).
This commit is contained in:
Steve Richert 2013-12-15 09:14:53 -05:00
parent a2b1772ed4
commit 53848e53e0
3 changed files with 11 additions and 9 deletions

View file

@ -268,11 +268,13 @@ module Capybara::Poltergeist
end end
def command(name, *args) def command(name, *args)
message = { 'name' => name, 'args' => args } message = JSON.dump({ 'name' => name, 'args' => args })
log message.inspect log message
json = JSON.load(server.send(JSON.dump(message))) response = server.send(message)
log json.inspect log response
json = JSON.load(response)
if json['error'] if json['error']
klass = ERROR_MAPPINGS[json['error']['name']] || BrowserError klass = ERROR_MAPPINGS[json['error']['name']] || BrowserError

View file

@ -540,7 +540,7 @@ describe Capybara::Session do
@session.visit("/") @session.visit("/")
@session.find(:css, "a").click @session.find(:css, "a").click
position = eval(TestSessions.logger.messages.last)["response"]["position"] position = JSON.load(TestSessions.logger.messages.last)["response"]["position"]
expect(position["x"]).to_not be_nil expect(position["x"]).to_not be_nil
expect(position["y"]).to_not be_nil expect(position["y"]).to_not be_nil
end end

View file

@ -11,13 +11,13 @@ module Capybara::Poltergeist
subject { Browser.new(server, client, logger) } subject { Browser.new(server, client, logger) }
it 'logs requests and responses to the client' do it 'logs requests and responses to the client' do
request = { 'name' => 'where is', 'args' => ["the love?"] } request = %({"name":"where is","args":["the love?"]})
response = { 'response' => '<3' } response = %({"response":"<3"})
server.stub(:send).with(MultiJson.dump(request)).and_return(JSON.dump(response)) server.stub(:send).with(request).and_return(response)
subject.command('where is', 'the love?') subject.command('where is', 'the love?')
expect(logger.string).to eq("#{request.inspect}\n#{response.inspect}\n") expect(logger.string).to eq("#{request}\n#{response}\n")
end end
end end
end end