puffing-billy 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  node_modules/
2
2
  log/test.log
3
+ .ruby-version
@@ -1,19 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- puffing-billy (0.1.3)
4
+ puffing-billy (0.2.1)
5
5
  capybara
6
6
  em-http-request
7
7
  eventmachine
8
8
  eventmachine_httpserver
9
9
  http_parser.rb
10
- rspec
11
- yajl-ruby
10
+ multi_json
12
11
 
13
12
  GEM
14
13
  remote: https://rubygems.org/
15
14
  specs:
16
15
  addressable (2.3.3)
16
+ builder (3.2.0)
17
17
  capybara (2.0.2)
18
18
  mime-types (>= 1.16)
19
19
  nokogiri (>= 1.3.3)
@@ -28,6 +28,11 @@ GEM
28
28
  ffi (~> 1.0, >= 1.0.11)
29
29
  coderay (1.0.9)
30
30
  cookiejar (0.3.0)
31
+ cucumber (1.2.5)
32
+ builder (>= 2.1.2)
33
+ diff-lcs (>= 1.1.3)
34
+ gherkin (~> 2.11.7)
35
+ multi_json (~> 1.3)
31
36
  daemons (1.1.9)
32
37
  diff-lcs (1.2.1)
33
38
  em-http-request (1.0.3)
@@ -45,6 +50,8 @@ GEM
45
50
  faye-websocket (0.4.7)
46
51
  eventmachine (>= 0.12.0)
47
52
  ffi (1.4.0)
53
+ gherkin (2.11.8)
54
+ multi_json (~> 1.3)
48
55
  guard (1.6.2)
49
56
  listen (>= 0.6.0)
50
57
  lumberjack (>= 1.0.2)
@@ -97,13 +104,13 @@ GEM
97
104
  websocket (1.0.7)
98
105
  xpath (1.0.0)
99
106
  nokogiri (~> 1.3)
100
- yajl-ruby (1.1.0)
101
107
 
102
108
  PLATFORMS
103
109
  ruby
104
110
 
105
111
  DEPENDENCIES
106
112
  capybara-webkit
113
+ cucumber
107
114
  faraday
108
115
  guard
109
116
  poltergeist
data/README.md CHANGED
@@ -34,7 +34,7 @@ You can also record HTTP interactions and replay them later. See
34
34
 
35
35
  Add this line to your application's Gemfile:
36
36
 
37
- gem 'puffing-billy', :require => 'billy'
37
+ gem 'puffing-billy'
38
38
 
39
39
  And then execute:
40
40
 
@@ -44,7 +44,7 @@ Or install it yourself as:
44
44
 
45
45
  $ gem install puffing-billy
46
46
 
47
- ## Usage
47
+ ## RSpec Usage
48
48
 
49
49
  In your `spec_helper.rb`:
50
50
 
@@ -64,6 +64,10 @@ In your tests:
64
64
  proxy.stub('http://example.com/text/').and_return(:text => 'Foobar')
65
65
  proxy.stub('http://example.com/json/').and_return(:json => { :foo => 'bar' })
66
66
  proxy.stub('http://example.com/jsonp/').and_return(:jsonp => { :foo => 'bar' })
67
+ proxy.stub('http://example.com/headers/').and_return({
68
+ :headers => { 'Access-Control-Allow-Origin' => '*' },
69
+ :json => { :foo => 'bar' }
70
+ })
67
71
  proxy.stub('http://example.com/wtf/').and_return(:body => 'WTF!?', :content_type => 'text/wtf')
68
72
 
69
73
  # Stub redirections and other return codes
@@ -88,6 +92,48 @@ proxy.stub('https://example.com/proc/').and_return(Proc.new { |params, headers,
88
92
  Stubs are reset between tests. Any requests that are not stubbed will be
89
93
  proxied to the remote server.
90
94
 
95
+ ## Cucumber Usage
96
+
97
+ In your `features/support/env.rb`:
98
+
99
+ ```ruby
100
+ require 'billy/cucumber'
101
+
102
+ After do
103
+ Capybara.use_default_driver
104
+ end
105
+ ```
106
+
107
+ An example feature:
108
+
109
+ ```
110
+ Feature: Stubbing via billy
111
+
112
+ @javascript @billy
113
+ Scenario: Test billy
114
+ And a stub for google
115
+ ```
116
+
117
+ And in steps:
118
+
119
+ ```
120
+ Before('@billy') do
121
+ Capybara.current_driver = :poltergeist_billy
122
+ Capybara.javascript_driver = :poltergeist_billy
123
+ end
124
+
125
+ And /^a stub for google$/ do
126
+ proxy.stub('http://www.google.com/').and_return(:text => "I'm not Google!")
127
+ visit 'http://www.google.com/'
128
+ page.should have_content("I'm not Google!")
129
+ end
130
+ ```
131
+
132
+ It's good practice to reset the driver after each scenario, so having an
133
+ `@billy` tag switches the drivers on for a given scenario. Also note that
134
+ stubs are reset after each step, so any usage of a stub should be in the
135
+ same step that it was created in.
136
+
91
137
  ## Caching
92
138
 
93
139
  Requests routed through the external proxy are cached.
@@ -4,3 +4,53 @@ require "billy/proxy_request_stub"
4
4
  require "billy/cache"
5
5
  require "billy/proxy"
6
6
  require "billy/proxy_connection"
7
+
8
+ $billy_proxy = Billy::Proxy.new
9
+ $billy_proxy.start
10
+
11
+ module Billy
12
+ def self.proxy
13
+ $billy_proxy
14
+ end
15
+
16
+ def self.register_drivers
17
+ ['capybara/poltergeist', 'capybara/webkit', 'selenium/webdriver'].each do |d|
18
+ begin
19
+ require d
20
+ rescue LoadError
21
+ end
22
+ end
23
+
24
+ if defined?(Capybara::Poltergeist)
25
+ Capybara.register_driver :poltergeist_billy do |app|
26
+ options = {
27
+ phantomjs_options: [
28
+ '--ignore-ssl-errors=yes',
29
+ "--proxy=#{Billy.proxy.host}:#{Billy.proxy.port}"
30
+ ]
31
+ }
32
+ Capybara::Poltergeist::Driver.new(app, options)
33
+ end
34
+ end
35
+
36
+ if defined?(Capybara::Webkit::Driver)
37
+ Capybara.register_driver :webkit_billy do |app|
38
+ driver = Capybara::Webkit::Driver.new(app)
39
+ driver.browser.set_proxy(:host => Billy.proxy.host,
40
+ :port => Billy.proxy.port)
41
+ driver.browser.ignore_ssl_errors
42
+ driver
43
+ end
44
+ end
45
+
46
+ if defined?(Selenium::WebDriver)
47
+ Capybara.register_driver :selenium_billy do |app|
48
+ profile = Selenium::WebDriver::Firefox::Profile.new
49
+ profile.proxy = Selenium::WebDriver::Proxy.new(
50
+ :http => "#{Billy.proxy.host}:#{Billy.proxy.port}",
51
+ :ssl => "#{Billy.proxy.host}:#{Billy.proxy.port}")
52
+ Capybara::Selenium::Driver.new(app, :profile => profile)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,19 @@
1
+ require 'cucumber'
2
+ require 'capybara/cucumber'
3
+ require 'billy'
4
+
5
+ Billy.register_drivers
6
+
7
+ module Billy
8
+ module CucumberHelper
9
+ def proxy
10
+ Billy.proxy
11
+ end
12
+ end
13
+ end
14
+
15
+ World(Billy::CucumberHelper)
16
+
17
+ After('@billy') do
18
+ proxy.reset
19
+ end
@@ -1,4 +1,4 @@
1
- require 'yajl'
1
+ require 'multi_json'
2
2
 
3
3
  module Billy
4
4
  class ProxyRequestStub
@@ -28,7 +28,7 @@ module Billy
28
28
 
29
29
  if res[:json]
30
30
  headers = {'Content-Type' => 'application/json'}.merge(headers)
31
- body = Yajl::Encoder.encode(res[:json])
31
+ body = MultiJson.dump(res[:json])
32
32
  elsif res[:jsonp]
33
33
  headers = {'Content-Type' => 'application/javascript'}.merge(headers)
34
34
  if res[:callback]
@@ -38,7 +38,7 @@ module Billy
38
38
  else
39
39
  callback = params['callback'][0]
40
40
  end
41
- body = "#{callback}(#{Yajl::Encoder::encode(res[:jsonp])})"
41
+ body = "#{callback}(#{MultiJson.dump(res[:jsonp])})"
42
42
  elsif res[:text]
43
43
  headers = {'Content-Type' => 'text/plain'}.merge(headers)
44
44
  body = res[:text]
@@ -2,14 +2,9 @@ require 'rspec'
2
2
  require 'capybara/rspec'
3
3
  require 'billy'
4
4
 
5
- $billy_proxy = Billy::Proxy.new
6
- $billy_proxy.start
5
+ Billy.register_drivers
7
6
 
8
7
  module Billy
9
- def self.proxy
10
- $billy_proxy
11
- end
12
-
13
8
  module RspecHelper
14
9
  def proxy
15
10
  Billy.proxy
@@ -24,42 +19,3 @@ RSpec.configure do |config|
24
19
  proxy.reset
25
20
  end
26
21
  end
27
-
28
- ['capybara/poltergeist', 'capybara/webkit', 'selenium/webdriver'].each do |d|
29
- begin
30
- require d
31
- rescue LoadError
32
- end
33
- end
34
-
35
- if defined?(Capybara::Poltergeist)
36
- Capybara.register_driver :poltergeist_billy do |app|
37
- options = {
38
- phantomjs_options: [
39
- '--ignore-ssl-errors=yes',
40
- "--proxy=#{Billy.proxy.host}:#{Billy.proxy.port}"
41
- ]
42
- }
43
- Capybara::Poltergeist::Driver.new(app, options)
44
- end
45
- end
46
-
47
- if defined?(Capybara::Webkit::Driver)
48
- Capybara.register_driver :webkit_billy do |app|
49
- driver = Capybara::Webkit::Driver.new(app)
50
- driver.browser.set_proxy(:host => Billy.proxy.host,
51
- :port => Billy.proxy.port)
52
- driver.browser.ignore_ssl_errors
53
- driver
54
- end
55
- end
56
-
57
- if defined?(Selenium::WebDriver)
58
- Capybara.register_driver :selenium_billy do |app|
59
- profile = Selenium::WebDriver::Firefox::Profile.new
60
- profile.proxy = Selenium::WebDriver::Proxy.new(
61
- :http => "#{Billy.proxy.host}:#{Billy.proxy.port}",
62
- :ssl => "#{Billy.proxy.host}:#{Billy.proxy.port}")
63
- Capybara::Selenium::Driver.new(app, :profile => profile)
64
- end
65
- end
@@ -1,3 +1,3 @@
1
1
  module Billy
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -24,11 +24,12 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency "rack"
25
25
  gem.add_development_dependency "guard"
26
26
  gem.add_development_dependency "rb-inotify"
27
+ gem.add_development_dependency "rspec"
28
+ gem.add_development_dependency "cucumber"
27
29
  gem.add_runtime_dependency "eventmachine"
28
30
  gem.add_runtime_dependency "em-http-request"
29
31
  gem.add_runtime_dependency "eventmachine_httpserver"
30
32
  gem.add_runtime_dependency "http_parser.rb"
31
- gem.add_runtime_dependency "yajl-ruby"
32
- gem.add_runtime_dependency "rspec"
33
+ gem.add_runtime_dependency "multi_json"
33
34
  gem.add_runtime_dependency "capybara"
34
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puffing-billy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-17 00:00:00.000000000 Z
12
+ date: 2013-05-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -156,14 +156,14 @@ dependencies:
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  - !ruby/object:Gem::Dependency
159
- name: eventmachine
159
+ name: rspec
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ! '>='
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0'
166
- type: :runtime
166
+ type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  none: false
@@ -172,7 +172,23 @@ dependencies:
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  - !ruby/object:Gem::Dependency
175
- name: em-http-request
175
+ name: cucumber
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: eventmachine
176
192
  requirement: !ruby/object:Gem::Requirement
177
193
  none: false
178
194
  requirements:
@@ -188,7 +204,7 @@ dependencies:
188
204
  - !ruby/object:Gem::Version
189
205
  version: '0'
190
206
  - !ruby/object:Gem::Dependency
191
- name: eventmachine_httpserver
207
+ name: em-http-request
192
208
  requirement: !ruby/object:Gem::Requirement
193
209
  none: false
194
210
  requirements:
@@ -204,7 +220,7 @@ dependencies:
204
220
  - !ruby/object:Gem::Version
205
221
  version: '0'
206
222
  - !ruby/object:Gem::Dependency
207
- name: http_parser.rb
223
+ name: eventmachine_httpserver
208
224
  requirement: !ruby/object:Gem::Requirement
209
225
  none: false
210
226
  requirements:
@@ -220,7 +236,7 @@ dependencies:
220
236
  - !ruby/object:Gem::Version
221
237
  version: '0'
222
238
  - !ruby/object:Gem::Dependency
223
- name: yajl-ruby
239
+ name: http_parser.rb
224
240
  requirement: !ruby/object:Gem::Requirement
225
241
  none: false
226
242
  requirements:
@@ -236,7 +252,7 @@ dependencies:
236
252
  - !ruby/object:Gem::Version
237
253
  version: '0'
238
254
  - !ruby/object:Gem::Dependency
239
- name: rspec
255
+ name: multi_json
240
256
  requirement: !ruby/object:Gem::Requirement
241
257
  none: false
242
258
  requirements:
@@ -291,6 +307,7 @@ files:
291
307
  - lib/billy.rb
292
308
  - lib/billy/cache.rb
293
309
  - lib/billy/config.rb
310
+ - lib/billy/cucumber.rb
294
311
  - lib/billy/mitm.crt
295
312
  - lib/billy/mitm.key
296
313
  - lib/billy/proxy.rb