capybara-webmock 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2c1c6bf43bd5b107c8f060e58c1fd108ae59b4b
4
- data.tar.gz: 8af76108b2d5287647ce73cb892387e6e519df7d
3
+ metadata.gz: 1c8941163a39745ce0f31270cde7858c787e00c1
4
+ data.tar.gz: fb8c98139687e3ccd5ecd7beedb46fe92e57663d
5
5
  SHA512:
6
- metadata.gz: 6925ef8010bb52e315b31d49ab067ac3af88b8830d10b7e46dc9d6299b0f3c29626cdef92a9b26e76d7cdf9964570b01a6d5870a7f0bbaf51a53d7aeea7f4906
7
- data.tar.gz: a6351773d12fd974572d514ab851bb6895161c7bacd5ae0c318613085418e416b6f2fe05627fe5767ce5aaa9554a7e6a9cc21c5c35655dca0d439a8de824f7e4
6
+ metadata.gz: 0379818df23512a9e8856657b5da11b01eb7c233c31d9f3f5f22f8b3e4aa74ba82af01d09fa2d9ccd3ae78e82450fd8bcd919fe7211e9a7d1290258fd5a25412
7
+ data.tar.gz: b9508aab67d153d8702b58984005130a9890f56361906e96f1f7b30cc54d1fa781bcaddefe16beab82817f88d28faf293e32661e5bc24a457f6a8b977ee843d4
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --order rand
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- [![CircleCI](https://circleci.com/gh/hashrocket/capybara-webmock.svg?style=svg)](https://circleci.com/gh/hashrocket/capybara-webmock)
1
+ [![CircleCI](https://img.shields.io/circleci/project/hashrocket/capybara-webmock/master.svg?maxAge=2592000)](https://circleci.com/gh/hashrocket/capybara-webmock)
2
2
  [![Version](https://img.shields.io/gem/v/capybara-webmock.svg?style=flat)](https://rubygems.org/gems/capybara-webmock)
3
3
 
4
4
  # Capybara::Webmock
5
5
 
6
+ > Mock external requests for Capybara JavaScript drivers.
7
+
6
8
  Browser integration tests are expensive. We can mock external requests in our
7
9
  tests, but once a browser is involved, we lose control.
8
10
 
@@ -12,14 +14,14 @@ integration test suite to a crawl.
12
14
  `Capybara::Webmock` is a Rack proxy server that sits between your Ruby on Rails
13
15
  Selenium test suite and the Internet, blocking external requests.
14
16
 
15
- Adding this gem to your project can significantly speed up the test suite. No
16
- more waiting on irrelevant external requests.
17
+ Use of this gem can significantly speed up the test suite. No more waiting on
18
+ irrelevant external requests.
17
19
 
18
- `localhost`, `127.0.0.1`, `*.lvh.me`, and `lvh.me` are the only whitelisted domains. Custom domain
19
- support is a planned feature.
20
+ `localhost`, `127.0.0.1`, `*.lvh.me`, and `lvh.me` are the only whitelisted
21
+ domains. Custom domain support is a planned feature.
20
22
 
21
- This gem currently supports Ruby on Rails applications with RSpec and
22
- Cucumber test suites, using the Selenium Firefox and Chrome drivers.
23
+ This gem currently supports Ruby on Rails applications
24
+ using the Selenium Firefox and Chrome drivers.
23
25
 
24
26
  ### Installation
25
27
 
@@ -52,6 +54,8 @@ require 'capybara/webmock'
52
54
  Then in your RSpec configuration:
53
55
 
54
56
  ```ruby
57
+ # spec/spec_helper.rb
58
+
55
59
  RSpec.configure do |config|
56
60
  config.before(:suite) do
57
61
  Capybara::Webmock.start
@@ -66,6 +70,8 @@ end
66
70
  Or, your Cucumber configuration:
67
71
 
68
72
  ```ruby
73
+ # features/support/env.rb
74
+
69
75
  Capybara::Webmock.start
70
76
 
71
77
  at_exit do
@@ -80,14 +86,23 @@ Then use the `capybara_webmock` JavaScript driver:
80
86
  Capybara.javascript_driver = :capybara_webmock
81
87
  ```
82
88
 
83
- or
89
+ or:
84
90
 
85
91
  ```ruby
86
92
  # Use Chrome Driver
87
93
  Capybara.javascript_driver = :capybara_webmock_chrome
88
94
  ```
89
95
 
90
- By default the proxy server run on port `9292`, but this can be customized
96
+ ```ruby
97
+ # Use Poltergeist Driver
98
+ Capybara.javascript_driver = :capybara_webmock_poltergeist
99
+ ```
100
+
101
+ *NOTE: These are just two default driver wrappers this gem provides. If you are
102
+ already using a custom driver profile you can still use `capybara-webmock`, you
103
+ just need to configure proxy settings to `127.0.0.1:9292`*
104
+
105
+ By default the proxy server runs on port `9292`, but this can be customized
91
106
  with the following configuration:
92
107
 
93
108
  ```ruby
data/bin/setup CHANGED
@@ -4,5 +4,3 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['dev@hashrocket.com']
11
11
 
12
12
  spec.summary = %q{Mock external requests}
13
- spec.description = %q{Mock external requests for Capybara Firefox drivers}
13
+ spec.description = %q{Mock external requests for Capybara JavaScript drivers}
14
14
  spec.homepage = 'https://github.com/hashrocket/capybara-webmock'
15
15
  spec.license = 'MIT'
16
16
 
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "capybara", "~> 2.4"
26
26
  spec.add_dependency "rack", ">= 1.4"
27
- spec.add_dependency "rack-proxy", "0.6.0"
28
- spec.add_dependency "selenium-webdriver", "~> 2.0"
27
+ spec.add_dependency "rack-proxy", ">= 0.6.0"
28
+ spec.add_dependency "selenium-webdriver", "~> 3.0"
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.13"
31
31
  spec.add_development_dependency "pry", "~> 0.10.4"
@@ -17,7 +17,7 @@ module Capybara
17
17
  end
18
18
 
19
19
  def stop
20
- if File.exists?(Capybara::Webmock::Proxy::PID_FILE)
20
+ if File.exist?(Capybara::Webmock::Proxy::PID_FILE)
21
21
  rack_pid = File.read(Capybara::Webmock::Proxy::PID_FILE).to_i
22
22
  Process.kill('HUP', rack_pid)
23
23
  end
@@ -38,6 +38,9 @@ module Capybara
38
38
  ["--proxy-server=127.0.0.1:#{port_number}"]
39
39
  end
40
40
 
41
+ def phantomjs_options
42
+ ["--proxy=127.0.0.1:#{port_number}"]
43
+ end
41
44
  end
42
45
  end
43
46
  end
@@ -51,3 +54,7 @@ end
51
54
  Capybara.register_driver :capybara_webmock_chrome do |app|
52
55
  Capybara::Selenium::Driver.new(app, browser: :chrome, switches: Capybara::Webmock.chrome_switches)
53
56
  end
57
+
58
+ Capybara.register_driver :capybara_webmock_poltergeist do |app|
59
+ Capybara::Poltergeist::Driver.new(app, phantomjs_options: Capybara::Webmock.phantomjs_options)
60
+ end
@@ -6,6 +6,7 @@ class Capybara::Webmock::Proxy < Rack::Proxy
6
6
 
7
7
  def initialize(pid)
8
8
  write_pid(pid)
9
+ ensure_log_exists
9
10
  end
10
11
 
11
12
  def perform_request(env)
@@ -20,7 +21,7 @@ class Capybara::Webmock::Proxy < Rack::Proxy
20
21
  end
21
22
 
22
23
  def self.remove_pid
23
- File.delete(PID_FILE) if File.exists?(PID_FILE)
24
+ File.delete(PID_FILE) if File.exist?(PID_FILE)
24
25
  end
25
26
 
26
27
  private
@@ -43,4 +44,10 @@ class Capybara::Webmock::Proxy < Rack::Proxy
43
44
  Dir.mkdir(pid_dir) unless Dir.exist?(pid_dir)
44
45
  File.write(PID_FILE, pid)
45
46
  end
47
+
48
+ def ensure_log_exists
49
+ log_file = File.join('log', 'test.log')
50
+ Dir.mkdir('log') unless Dir.exist?('log')
51
+ File.open(log_file, 'a') { |f| f.write "" }
52
+ end
46
53
  end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Webmock
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Worth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-09 00:00:00.000000000 Z
12
+ date: 2017-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -43,14 +43,14 @@ dependencies:
43
43
  name: rack-proxy
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: 0.6.0
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: 0.6.0
56
56
  - !ruby/object:Gem::Dependency
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '2.0'
62
+ version: '3.0'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '2.0'
69
+ version: '3.0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bundler
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +137,7 @@ dependencies:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
- description: Mock external requests for Capybara Firefox drivers
140
+ description: Mock external requests for Capybara JavaScript drivers
141
141
  email:
142
142
  - dev@hashrocket.com
143
143
  executables: []