rack_toolkit 0.1.0 → 0.1.1

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: 017242be2ce01950ad46eafb4c9aea3855b57dbe
4
- data.tar.gz: 36138ff9218e813e4734074c118bd1606b3fd635
3
+ metadata.gz: 009958af4469932b2fe96d2723804d324fbd37ba
4
+ data.tar.gz: 020c1f6f086e758d4c181824faeecbd3fad2609d
5
5
  SHA512:
6
- metadata.gz: c2974c29604008d2446a65b7e39d6bf1d0bd344e5b26645587445db141ea3ba83cba87b3e3d84f1b1423103fd84dbc6e322363135e236855cd74ed0520ff18e5
7
- data.tar.gz: a9d9ef14206965cf3d6c54940ac51c69e85a1535f86f47d107449f5422dfe416e0332f23d6ebe08d8f8b6a4ba76a1625448f37b64dea7197ccd32e5fcc4ac039
6
+ metadata.gz: 0959a9012ded5531a54e8df5c83aa8756dd72df2eb7659caf47b2a216300ba6ca76a383bb17023da6b70ed289e18f0708311d6f328fd6dc6c516b095fd201286
7
+ data.tar.gz: f478e09c248e7f8d40c310cb52e00f5911483a1529c197bc71e2fb6b91d16186413f19889e1559d04a25799875936c4939c2ae2c254561aff0e288a39503a8dc
data/README.md CHANGED
@@ -64,7 +64,9 @@ server.post 'https://test-app.com/signin', follow_redirect: false # default is t
64
64
  server.env['HTTP_X_FORWARDED_PROTO'] == 'https'
65
65
  server.env['HTTP_HOST'] == 'test-app.com'
66
66
  server.last_response.status_code == 302 # assuming an app performing a redirect
67
+ server.current_path == '/signin'
67
68
  server.follow_redirect! # not necessary if follow_redirect: false is not specified
69
+ server.current_path == '/' # assuming it has been redirected to /
68
70
  server.last_response.ok? == true
69
71
 
70
72
  server.post '/signin', params: {user: 'guest', pass: 'secret'}
@@ -78,6 +80,18 @@ you can start it on each test file. Also, RackToolkit was designed so that you c
78
80
  multiple servers running different apps for example if you want them to communicate to each
79
81
  other for testing SSO for example.
80
82
 
83
+ Use the `headers` param in `get`/`post`/`post_data` to override headers sent to the server.
84
+ The `env_override` param can be used to override the `env` sent to the Rack app after the
85
+ server provided its own `env`. In both cases, the resulting `headers` or `env` will be merged
86
+ with the provided options:
87
+
88
+ ```ruby
89
+ server.get 'https://test-app.com/', headers: { 'Host' => 'mydomain.com' },
90
+ env_override: { 'rack.hijack' => 'custom hijack' }
91
+ server.env['HTTP_HOST'] == 'mydomain.com'
92
+ server.env['rack.hijack'] == 'custom hijack'
93
+ ```
94
+
81
95
  Take a look at this project's test suite to see an example on how it can be configured and how
82
96
  it works.
83
97
 
@@ -12,7 +12,7 @@ module RackToolkit
12
12
  class Server
13
13
  attr_accessor :app, :default_env, :referer, :default_headers
14
14
  attr_reader :bind_host, :host, :server, :default_domain, :last_response, :http, :cookie_jar,
15
- :env, :env_from_server, :rack_env, :virtual_hosts
15
+ :env, :env_from_server, :rack_env, :virtual_hosts, :current_uri
16
16
 
17
17
  def initialize(app: nil, port: nil, bind_host: '127.0.0.1', virtual_hosts: [], host: nil,
18
18
  dynamic_app: nil, default_env: {}, default_domain: nil, default_headers: {},
@@ -93,6 +93,14 @@ module RackToolkit
93
93
  @port ||= find_free_tcp_port
94
94
  end
95
95
 
96
+ def current_path
97
+ current_uri.path
98
+ end
99
+
100
+ def current_url
101
+ current_uri.to_s
102
+ end
103
+
96
104
  private
97
105
 
98
106
  def find_free_tcp_port
@@ -112,12 +120,14 @@ module RackToolkit
112
120
  end
113
121
  end
114
122
 
115
- def wrap_response(url_or_path, headers, env_override, params, follow_redirect, redirect_limit)
123
+ def wrap_response(url_or_path, headers, env_override, params, follow_redirect,
124
+ redirect_limit)
116
125
  uri = normalize_uri(url_or_path, params)
117
126
  h = prepare_headers headers, env_override, uri
118
127
  response = uri.host == host ? yield(uri, h, @http) :
119
128
  Net::HTTP.start(uri.host, uri.port){|http| yield uri, h, http }
120
129
  @last_response = response.extend ResponseEnhancer
130
+ @current_uri = uri.clone
121
131
  store_cookies uri
122
132
  self.referer = @original_uri.to_s
123
133
  @request_env = {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RackToolkit
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,80 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Rosenfeld Rosas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: bundler
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: '1.12'
19
- name: bundler
20
- prerelease: false
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.12'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: rake
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: '10.0'
33
- name: rake
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rspec
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '3.0'
47
- name: rspec
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: puma
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
61
  version: '3.5'
61
- name: puma
62
- prerelease: false
63
62
  type: :runtime
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.5'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: http-cookie
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - "~>"
73
74
  - !ruby/object:Gem::Version
74
75
  version: 1.0.2
75
- name: http-cookie
76
- prerelease: false
77
76
  type: :runtime
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
@@ -110,7 +110,7 @@ homepage: https://github.com/rosenfeld/rack_toolkit
110
110
  licenses:
111
111
  - MIT
112
112
  metadata: {}
113
- post_install_message:
113
+ post_install_message:
114
114
  rdoc_options: []
115
115
  require_paths:
116
116
  - lib
@@ -125,9 +125,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.6.4
130
- signing_key:
128
+ rubyforge_project:
129
+ rubygems_version: 2.5.1
130
+ signing_key:
131
131
  specification_version: 4
132
132
  summary: A dynamic Rack server and helper methods to help testing Rack apps.
133
133
  test_files: []