capybara-typhoeus 0.4.2 → 0.5.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 +5 -5
- data/lib/capybara/typhoeus/browser.rb +15 -0
- data/spec/session/typhoeus_spec.rb +68 -31
- data/spec/spec_helper.rb +0 -21
- metadata +20 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 55d6e90d7b65fd3c7183b989c74e6532103382b684bda3b647e52d1dbfe04368
|
4
|
+
data.tar.gz: b1e22d5b2c32f7ac8ae85b6d13f05b8b16ab9ef2cc574368ba305824b14db16b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82ae5e119a7996fac56c8d24ac5551cd35aa466232e3f58a02cd4f1eec732ebafb096cd8134be1f37ae8cb1fcad0f1997279e8941f30e071288da16c682a371d
|
7
|
+
data.tar.gz: 4df5e80af597d8c6d90443cff1e705cc6aa51c394dee07b4c646d2a34b01f32a21029c2a5039a8f12d878095a715b1d5858d48fe90cb9b25f4823ecc166833b4
|
@@ -4,6 +4,8 @@ module Typhoeus
|
|
4
4
|
[301, 302, 303, 307].include? code
|
5
5
|
end
|
6
6
|
|
7
|
+
alias_method :status, :code
|
8
|
+
|
7
9
|
def [](key)
|
8
10
|
headers[key]
|
9
11
|
end
|
@@ -12,7 +14,14 @@ end
|
|
12
14
|
|
13
15
|
class Capybara::Typhoeus::Browser < Capybara::RackTest::Browser
|
14
16
|
|
17
|
+
LastRequest = Struct.new(:method, :url, :params, :headers) do
|
18
|
+
def path
|
19
|
+
URI.parse(url).path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
15
23
|
attr_accessor :request_body
|
24
|
+
attr_reader :last_request
|
16
25
|
attr_reader :last_response
|
17
26
|
|
18
27
|
def reset_cache!
|
@@ -21,6 +30,11 @@ class Capybara::Typhoeus::Browser < Capybara::RackTest::Browser
|
|
21
30
|
super
|
22
31
|
end
|
23
32
|
|
33
|
+
def refresh
|
34
|
+
reset_cache!
|
35
|
+
send(last_request.method, last_request.url, last_request.params, last_request.headers)
|
36
|
+
end
|
37
|
+
|
24
38
|
def current_url
|
25
39
|
last_response ? last_response.effective_url : ""
|
26
40
|
end
|
@@ -54,6 +68,7 @@ class Capybara::Typhoeus::Browser < Capybara::RackTest::Browser
|
|
54
68
|
|
55
69
|
[:get, :post, :put, :delete, :head, :patch, :request].each do |method|
|
56
70
|
define_method(method) do |url, params={}, headers={}, &block|
|
71
|
+
@last_request = LastRequest.new(method, url, params, headers)
|
57
72
|
uri = URI.parse url
|
58
73
|
opts = driver.with_options
|
59
74
|
opts[:method] = method
|
@@ -4,24 +4,59 @@ Capybara.register_driver :typhoeus_with_custom_timeout do |app|
|
|
4
4
|
Capybara::Typhoeus::Driver.new app, timeout: 1
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
:
|
9
|
-
:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
7
|
+
module TestSessions
|
8
|
+
TyphoeusTest = Capybara::Session.new(:typhoeus, TestApp)
|
9
|
+
TyphoeusTestCustomTimeout = Capybara::Session.new(:typhoeus_with_custom_timeout, TestApp)
|
10
|
+
end
|
11
|
+
|
12
|
+
skipped_tests = %i[
|
13
|
+
js
|
14
|
+
modals
|
15
|
+
screenshot
|
16
|
+
frames
|
17
|
+
windows
|
18
|
+
send_keys
|
19
|
+
server
|
20
|
+
hover
|
21
|
+
about_scheme
|
22
|
+
download
|
23
|
+
css
|
24
|
+
scroll
|
17
25
|
]
|
26
|
+
Capybara::SpecHelper.run_specs TestSessions::TyphoeusTest, 'Typhoeus', capybara_skip: skipped_tests do |example|
|
27
|
+
case example.metadata[:full_description]
|
28
|
+
when /#attach_file/
|
29
|
+
skip "Typhoeus driver doesn't support #attach_file"
|
30
|
+
when /#check/
|
31
|
+
skip "Typhoeus driver doesn't support #check"
|
32
|
+
when /#uncheck/
|
33
|
+
skip "Typhoeus driver doesn't support #uncheck"
|
34
|
+
when /#click/
|
35
|
+
skip "Typhoeus driver doesn't support #click"
|
36
|
+
when /#select/
|
37
|
+
skip "Typhoeus driver doesn't support #select"
|
38
|
+
when /#unselect/
|
39
|
+
skip "Typhoeus driver doesn't support #unselect"
|
40
|
+
when /has_css\? should support case insensitive :class and :id options/
|
41
|
+
skip "Nokogiri doesn't support case insensitive CSS attribute matchers"
|
42
|
+
end
|
43
|
+
end
|
18
44
|
|
19
|
-
describe Capybara::Typhoeus::Session do
|
45
|
+
RSpec.describe Capybara::Typhoeus::Session do
|
20
46
|
|
21
47
|
context "with typhoeus driver" do
|
22
|
-
|
23
|
-
|
24
|
-
|
48
|
+
let(:session) { TestSessions::TyphoeusTest }
|
49
|
+
|
50
|
+
describe '#driver' do
|
51
|
+
it 'should be a rack test driver' do
|
52
|
+
expect(session.driver).to be_an_instance_of(Capybara::Typhoeus::Driver)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#mode' do
|
57
|
+
it 'should remember the mode' do
|
58
|
+
expect( session.mode ).to eq(:typhoeus)
|
59
|
+
end
|
25
60
|
end
|
26
61
|
|
27
62
|
context "basic authentication" do
|
@@ -38,14 +73,14 @@ describe Capybara::Typhoeus::Session do
|
|
38
73
|
it "allow access with right credentials" do
|
39
74
|
subject.authenticate_with "admin", "secret"
|
40
75
|
subject.get "/"
|
41
|
-
subject.status_code.
|
42
|
-
subject.source.
|
76
|
+
expect( subject.status_code ).to be 200
|
77
|
+
expect( subject.source ).to eq "Success!"
|
43
78
|
end
|
44
79
|
|
45
80
|
it "deny access with wrong credentials" do
|
46
81
|
subject.authenticate_with "admin", "admin"
|
47
82
|
subject.get "/"
|
48
|
-
subject.status_code.
|
83
|
+
expect( subject.status_code ).to be 401
|
49
84
|
end
|
50
85
|
end
|
51
86
|
|
@@ -54,12 +89,12 @@ describe Capybara::Typhoeus::Session do
|
|
54
89
|
|
55
90
|
context "default" do
|
56
91
|
it "is 3 seconds" do
|
57
|
-
subject.timeout.
|
92
|
+
expect( subject.timeout ).to eq 3
|
58
93
|
end
|
59
94
|
|
60
95
|
it "is used during request" do
|
61
96
|
subject.get "/slow_response"
|
62
|
-
subject.
|
97
|
+
expect( subject ).not_to be_timed_out
|
63
98
|
end
|
64
99
|
end
|
65
100
|
|
@@ -67,12 +102,12 @@ describe Capybara::Typhoeus::Session do
|
|
67
102
|
subject{ described_class.new :typhoeus_with_custom_timeout, TestApp }
|
68
103
|
|
69
104
|
it "is stored in options" do
|
70
|
-
subject.timeout.
|
105
|
+
expect( subject.timeout ).to eq 1
|
71
106
|
end
|
72
107
|
|
73
108
|
it "is used during request" do
|
74
109
|
subject.get "/slow_response"
|
75
|
-
subject.
|
110
|
+
expect( subject ).to be_timed_out
|
76
111
|
end
|
77
112
|
end
|
78
113
|
end
|
@@ -81,15 +116,17 @@ describe Capybara::Typhoeus::Session do
|
|
81
116
|
subject{ described_class.new :typhoeus, TestApp }
|
82
117
|
|
83
118
|
it "with empty url" do
|
84
|
-
subject.host_url("").
|
119
|
+
expect( subject.host_url("") ).to match /\A#{Regexp.escape("http://127.0.0.1")}:\d+\z/
|
85
120
|
end
|
86
121
|
|
87
122
|
it "with relative url" do
|
88
|
-
subject.host_url("/demo/test").
|
123
|
+
expect( subject.host_url("/demo/test") ).to match /\A#{Regexp.escape("http://127.0.0.1")}:\d+\/demo\/test\z/
|
89
124
|
end
|
90
125
|
|
91
126
|
it "with absolute url" do
|
92
|
-
|
127
|
+
expect(
|
128
|
+
subject.host_url("http://www.example.com:443/demo/test")
|
129
|
+
).to eq "http://www.example.com:443/demo/test"
|
93
130
|
end
|
94
131
|
end
|
95
132
|
|
@@ -102,20 +139,20 @@ describe Capybara::Typhoeus::Session do
|
|
102
139
|
end
|
103
140
|
|
104
141
|
it "body is nil be default" do
|
105
|
-
subject.request_body.
|
142
|
+
expect( subject.request_body ).to be_nil
|
106
143
|
subject.post "/"
|
107
|
-
subject.status_code.
|
108
|
-
subject.source.
|
144
|
+
expect( subject.status_code ).to be 200
|
145
|
+
expect( subject.source ).to eq ""
|
109
146
|
end
|
110
147
|
|
111
148
|
it "I can send data by setting the body" do
|
112
149
|
body = "**raw file content**"
|
113
150
|
subject.request_body = body
|
114
|
-
subject.request_body.
|
151
|
+
expect( subject.request_body ).to eq body
|
115
152
|
subject.post "/"
|
116
|
-
subject.status_code.
|
117
|
-
subject.source.
|
118
|
-
subject.request_body.
|
153
|
+
expect( subject.status_code ).to be 200
|
154
|
+
expect( subject.source ).to eq body
|
155
|
+
expect( subject.request_body ).to be_nil
|
119
156
|
end
|
120
157
|
end
|
121
158
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,27 +3,6 @@ require "capybara/typhoeus"
|
|
3
3
|
require "capybara/spec/spec_helper"
|
4
4
|
require 'pry'
|
5
5
|
|
6
|
-
module Capybara
|
7
|
-
module SpecHelper
|
8
|
-
class << self
|
9
|
-
alias_method :run_specs_without_skip, :run_specs
|
10
|
-
def run_specs(session, name, options={})
|
11
|
-
skip = [
|
12
|
-
"#attach_file",
|
13
|
-
"#check",
|
14
|
-
"#click_button",
|
15
|
-
"#click_link",
|
16
|
-
"#select",
|
17
|
-
"#uncheck",
|
18
|
-
"#unselect",
|
19
|
-
]
|
20
|
-
@specs.reject!{|spec| skip.include? spec.first}
|
21
|
-
run_specs_without_skip session, name, options
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
6
|
RSpec.configure do |config|
|
28
7
|
Capybara::SpecHelper.configure config
|
29
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-typhoeus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph HALTER
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capybara
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '3.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: '3.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: typhoeus
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +95,20 @@ dependencies:
|
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: puma
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
98
112
|
description: Typhoeus driver for Capybara, allowing testing of REST APIs
|
99
113
|
email:
|
100
114
|
- jonathan.tron@metrilio.com
|
@@ -135,11 +149,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
149
|
- !ruby/object:Gem::Version
|
136
150
|
version: '0'
|
137
151
|
requirements: []
|
138
|
-
|
139
|
-
rubygems_version: 2.5.2
|
152
|
+
rubygems_version: 3.0.3
|
140
153
|
signing_key:
|
141
154
|
specification_version: 4
|
142
155
|
summary: Typhoeus driver for Capybara
|
143
156
|
test_files:
|
144
|
-
- spec/session/typhoeus_spec.rb
|
145
157
|
- spec/spec_helper.rb
|
158
|
+
- spec/session/typhoeus_spec.rb
|