From 53848e53e00eadc7ac44a32475eb05afb4d119d8 Mon Sep 17 00:00:00 2001 From: Steve Richert Date: Sun, 15 Dec 2013 09:14:53 -0500 Subject: [PATCH 1/2] 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). --- lib/capybara/poltergeist/browser.rb | 10 ++++++---- spec/integration/session_spec.rb | 2 +- spec/unit/browser_spec.rb | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/capybara/poltergeist/browser.rb b/lib/capybara/poltergeist/browser.rb index 2d5985d5..7ee05930 100644 --- a/lib/capybara/poltergeist/browser.rb +++ b/lib/capybara/poltergeist/browser.rb @@ -268,11 +268,13 @@ def debug=(val) end def command(name, *args) - message = { 'name' => name, 'args' => args } - log message.inspect + message = JSON.dump({ 'name' => name, 'args' => args }) + log message - json = JSON.load(server.send(JSON.dump(message))) - log json.inspect + response = server.send(message) + log response + + json = JSON.load(response) if json['error'] klass = ERROR_MAPPINGS[json['error']['name']] || BrowserError diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 0087e53c..67a59938 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -540,7 +540,7 @@ @session.visit("/") @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["y"]).to_not be_nil end diff --git a/spec/unit/browser_spec.rb b/spec/unit/browser_spec.rb index fac56d2d..bff01280 100644 --- a/spec/unit/browser_spec.rb +++ b/spec/unit/browser_spec.rb @@ -11,13 +11,13 @@ module Capybara::Poltergeist subject { Browser.new(server, client, logger) } it 'logs requests and responses to the client' do - request = { 'name' => 'where is', 'args' => ["the love?"] } - response = { 'response' => '<3' } - server.stub(:send).with(MultiJson.dump(request)).and_return(JSON.dump(response)) + request = %({"name":"where is","args":["the love?"]}) + response = %({"response":"<3"}) + server.stub(:send).with(request).and_return(response) 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 From ab56a04e0e5b959964fe6c9ef4b4f02ae980eb81 Mon Sep 17 00:00:00 2001 From: Steve Richert Date: Fri, 20 Dec 2013 09:31:33 -0500 Subject: [PATCH 2/2] Add JSON logging to the changelog --- CHANGELOG.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index beba702a..2dd1a730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ #### Features #### -* Added ability to set zoom_factor(Dmytro Budnyk) +* Added ability to set zoom_factor (Dmytro Budnyk) +* Write JSON to the logger, rather than Ruby [Issue #430] #### Bug fixes #### @@ -12,6 +13,7 @@ ### 1.5.0 ### #### Features #### + * Added ability to clear network traffic (Vick Vu) * Added ability to set paper_size via a driver setter (Philippe Lehoux) * Can support Basic HTTP authentication @@ -20,6 +22,7 @@ element and Capybara 2.2 support (Pedro CarriƧo) #### Bug fixes #### + * Use `Capybara::Helpers.normalize_whitespace` in filter_text to strip unicode whitespace (Wataru Miyaguni) * Fix missed interpolation on deprecated error classes @@ -32,6 +35,7 @@ ### 1.4.1 ### #### Bug fixes #### + * Kill thread first off and then close IO [Issue #385] ### 1.4.0 ### @@ -100,7 +104,7 @@ ### 1.1.2 ### -#### Bug fixes ##### +#### Bug fixes #### * Tie to faye-websocket 0.4 as 0.5 introduces incompatibilities. @@ -246,7 +250,7 @@ [Issue #83] * Added status code support. (Dmitriy Nesteryuk and Jon Leighton) [Issue #37] -#### Bug fixes ### +#### Bug fixes #### * Fix issue with `ClickFailed` exception happening with a negative co-ordinate (which should be impossible). (Jon Leighton, Gabriel