Skip to content

Commit

Permalink
Merge pull request teampoltergeist#430 from laserlemon/json-logger
Browse files Browse the repository at this point in the history
Log raw JSON messages/responses rather than Ruby-parsed and inspected
  • Loading branch information
route committed Dec 23, 2013
2 parents a2b1772 + ab56a04 commit 09c6570
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ####

Expand All @@ -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
Expand All @@ -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
Expand All @@ -32,6 +35,7 @@
### 1.4.1 ###

#### Bug fixes ####

* Kill thread first off and then close IO [Issue #385]

### 1.4.0 ###
Expand Down Expand Up @@ -100,7 +104,7 @@

### 1.1.2 ###

#### Bug fixes #####
#### Bug fixes ####

* Tie to faye-websocket 0.4 as 0.5 introduces incompatibilities.

Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions lib/capybara/poltergeist/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09c6570

Please sign in to comment.