capybara-webmock 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +57 -10
- data/capybara-webmock.gemspec +5 -1
- data/lib/capybara/webmock.rb +29 -2
- data/lib/capybara/webmock/config.ru +12 -0
- data/lib/capybara/webmock/proxy.rb +28 -0
- data/lib/capybara/webmock/version.rb +1 -1
- metadata +46 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e3c7f9c6e246d77b34e9f947b4af84a8531343f
|
4
|
+
data.tar.gz: d98c50cb3ee6dee0b686cafe14c3c71f636ab249
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef2b93c7683ed2b0b367c2d09f2c92ba4ac01148e1540b622eede9ed0dbb38fafcf114ddeb7aac7dcc6a6ab3ae61edbcbb1a20525d78cbf3582ff1401fbd3d88
|
7
|
+
data.tar.gz: cc9d48994dac4a77e5822f81cfde0bab5725c4909ede6eef26d4aa7e921d2f0b60bc941953d86aa71c98d5238fc9df69e30a154f6c007f29661da51e50605d62
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Capybara::Webmock
|
2
2
|
|
3
|
-
|
3
|
+
> Mock external requests for Capybara Firefox & Chrome drivers
|
4
4
|
|
5
|
-
|
5
|
+
This gem currently supports Ruby on Rails applications with an RSpec test
|
6
|
+
suite.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -14,28 +15,74 @@ gem 'capybara-webmock'
|
|
14
15
|
|
15
16
|
And then execute:
|
16
17
|
|
17
|
-
|
18
|
+
```
|
19
|
+
$ bundle
|
20
|
+
```
|
18
21
|
|
19
22
|
Or install it yourself as:
|
20
23
|
|
21
|
-
|
24
|
+
```
|
25
|
+
$ gem install capybara-webmock
|
26
|
+
```
|
22
27
|
|
23
28
|
## Usage
|
24
29
|
|
25
|
-
|
30
|
+
In your `spec/rails_helper.rb`, add the following:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'capybara/webmock'
|
34
|
+
```
|
35
|
+
|
36
|
+
Then in your RSpec configuration:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
RSpec.configure do |config|
|
40
|
+
config.before(:suite) do
|
41
|
+
Capybara::Webmock.start
|
42
|
+
end
|
43
|
+
|
44
|
+
config.after(:suite) do
|
45
|
+
Capybara::Webmock.stop
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
Then use the capybara-webmock JavaScript driver:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Capybara.javascript_driver = :capybara_webmock
|
54
|
+
```
|
26
55
|
|
27
56
|
## Development
|
28
57
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
59
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
60
|
+
prompt that will allow you to experiment.
|
30
61
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
63
|
+
release a new version, update the version number in `version.rb`, and then run
|
64
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
65
|
+
git commits and tags, and push the `.gem` file to
|
66
|
+
[rubygems.org](https://rubygems.org).
|
32
67
|
|
33
68
|
## Contributing
|
34
69
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at
|
36
|
-
|
70
|
+
Bug reports and pull requests are welcome on GitHub at
|
71
|
+
https://github.com/[USERNAME]/capybara-webmock. This project is intended to be
|
72
|
+
a safe, welcoming space for collaboration, and contributors are expected to
|
73
|
+
adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
|
74
|
+
conduct.
|
37
75
|
|
38
76
|
## License
|
39
77
|
|
40
|
-
The gem is available as open source under the terms of the [MIT
|
78
|
+
The gem is available as open source under the terms of the [MIT
|
79
|
+
License](http://opensource.org/licenses/MIT).
|
80
|
+
|
81
|
+
## About
|
82
|
+
|
83
|
+
[](https://hashrocket.com)
|
41
84
|
|
85
|
+
Capybara::Webmock is supported by the team at [Hashrocket, a multidisciplinary
|
86
|
+
design and development consultancy](https://hashrocket.com). If you'd like to
|
87
|
+
[work with us](https://hashrocket.com/contact-us/hire-us) or [join our
|
88
|
+
team](https://hashrocket.com/contact-us/jobs), don't hesitate to get in touch.
|
data/capybara-webmock.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Jake Worth', 'Dillon Hafer']
|
10
10
|
spec.email = ['dev@hashrocket.com']
|
11
11
|
|
12
|
-
spec.summary = %q{Mock external requests
|
12
|
+
spec.summary = %q{Mock external requests}
|
13
13
|
spec.description = %q{Mock external requests for Capybara Firefox & Chrome drivers}
|
14
14
|
spec.homepage = 'https://github.com/hashrocket/capybara-webmock'
|
15
15
|
spec.license = 'MIT'
|
@@ -21,6 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
spec.add_dependency "capybara", "~> 2.4"
|
25
|
+
spec.add_dependency "rack", "~> 1.4"
|
26
|
+
spec.add_dependency "rack-proxy", "0.6.0"
|
27
|
+
|
24
28
|
spec.add_development_dependency "bundler", "~> 1.13"
|
25
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
data/lib/capybara/webmock.rb
CHANGED
@@ -1,7 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require 'capybara'
|
2
|
+
require 'capybara/webmock/version'
|
3
|
+
require 'capybara/webmock/proxy'
|
2
4
|
|
3
5
|
module Capybara
|
4
6
|
module Webmock
|
5
|
-
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def start
|
11
|
+
log_file = File.join('log', 'test.log')
|
12
|
+
gem_path = File.dirname(__FILE__)
|
13
|
+
proxy_file = File.join(gem_path, 'webmock', 'config.ru')
|
14
|
+
IO.popen("rackup #{proxy_file} >> #{log_file} 2>&1")
|
15
|
+
end
|
16
|
+
|
17
|
+
def stop
|
18
|
+
if File.exists?(Capybara::Webmock::Proxy::PID_FILE)
|
19
|
+
rack_pid = File.read(Capybara::Webmock::Proxy::PID_FILE).to_i
|
20
|
+
Process.kill('HUP', rack_pid)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
6
25
|
end
|
7
26
|
end
|
27
|
+
|
28
|
+
Capybara.register_driver :capybara_webmock do |app|
|
29
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
30
|
+
profile["network.proxy.type"] = 1
|
31
|
+
profile["network.proxy.http"] = '127.0.0.1'
|
32
|
+
profile["network.proxy.http_port"] = 9292
|
33
|
+
Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
|
34
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'capybara/webmock/proxy'
|
3
|
+
|
4
|
+
at_exit { Capybara::Webmock::Proxy.remove_pid }
|
5
|
+
|
6
|
+
trap('SIGHUP') {
|
7
|
+
Capybara::Webmock::Proxy.remove_pid
|
8
|
+
exit!
|
9
|
+
}
|
10
|
+
|
11
|
+
app = Capybara::Webmock::Proxy.new(Process.pid)
|
12
|
+
Rack::Handler::WEBrick.run app, { Port: 9292 }
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rack/proxy'
|
2
|
+
|
3
|
+
class Capybara::Webmock::Proxy < Rack::Proxy
|
4
|
+
PID_FILE = File.join('tmp', 'pids', 'capybara_webmock_proxy.pid')
|
5
|
+
|
6
|
+
def initialize(pid)
|
7
|
+
write_pid(pid)
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform_request(env)
|
11
|
+
request = Rack::Request.new(env)
|
12
|
+
if request.host =~ %r{.*\.lvh.me}
|
13
|
+
super(env)
|
14
|
+
else
|
15
|
+
['200', {'Content-Type' => 'text/html'}, ['ok']]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.remove_pid
|
20
|
+
File.delete(PID_FILE) if File.exists?(PID_FILE)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def write_pid(pid)
|
26
|
+
File.write(PID_FILE, pid)
|
27
|
+
end
|
28
|
+
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Worth
|
@@ -11,6 +11,48 @@ bindir: exe
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2016-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capybara
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.4'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.4'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rack
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.4'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.4'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rack-proxy
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.6.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.6.0
|
14
56
|
- !ruby/object:Gem::Dependency
|
15
57
|
name: bundler
|
16
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,6 +113,8 @@ files:
|
|
71
113
|
- bin/setup
|
72
114
|
- capybara-webmock.gemspec
|
73
115
|
- lib/capybara/webmock.rb
|
116
|
+
- lib/capybara/webmock/config.ru
|
117
|
+
- lib/capybara/webmock/proxy.rb
|
74
118
|
- lib/capybara/webmock/version.rb
|
75
119
|
homepage: https://github.com/hashrocket/capybara-webmock
|
76
120
|
licenses:
|
@@ -95,5 +139,5 @@ rubyforge_project:
|
|
95
139
|
rubygems_version: 2.5.1
|
96
140
|
signing_key:
|
97
141
|
specification_version: 4
|
98
|
-
summary: Mock external requests
|
142
|
+
summary: Mock external requests
|
99
143
|
test_files: []
|