tynn 1.1.0 → 1.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/README.md +1 -1
- data/lib/tynn/environment.rb +1 -1
- data/lib/tynn/test.rb +164 -15
- data/lib/tynn/version.rb +1 -1
- data/test/helper.rb +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6cd976ef2725374c76761726c9c86a4714a0aed
|
4
|
+
data.tar.gz: f769dcbcabcc8ac1941a175e2280d860cdf3304e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 304636238779f980affe65c6028814bcbe63823264baf249e599ec8fbf1dd002dd70947c0a3cce5b4e801afea6a20210dfcf1c64d07bd65b0835285d382ce53c
|
7
|
+
data.tar.gz: f48e2523ac152117c16c79972a8ada5ed7962fca259904fdd4ae1f3b562931ce0bf480c0684154b43379c0c739164578d3623697d14a3797760eb5807105702b
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
tynn [](https://travis-ci.org/frodsan/tynn)
|
1
|
+
tynn [](https://travis-ci.org/frodsan/tynn)
|
2
2
|
====
|
3
3
|
|
4
4
|
A thin library for web development.
|
data/lib/tynn/environment.rb
CHANGED
data/lib/tynn/test.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "rack/test"
|
2
|
-
|
3
1
|
class Tynn
|
4
2
|
# Public: A simple helper class to simulate requests to your application.
|
5
3
|
#
|
@@ -17,19 +15,10 @@ class Tynn
|
|
17
15
|
# app = Tynn::Test.new
|
18
16
|
# app.get("/")
|
19
17
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# In order to use this plugin, you need to install
|
24
|
-
# {rack-test}[https://rubygems.org/gems/rack-test].
|
18
|
+
# app.res.status # => 200
|
19
|
+
# app.res.body # => "hei"
|
25
20
|
#
|
26
21
|
class Test
|
27
|
-
include Rack::Test::Methods
|
28
|
-
|
29
|
-
# Internal: Returns the application class that handles the
|
30
|
-
# mock requests. Required by Rack::Test::Methods.
|
31
|
-
attr_reader :app
|
32
|
-
|
33
22
|
# Public: Initializes a new Tynn::Test object.
|
34
23
|
#
|
35
24
|
# app - The application class to test (default: Tynn).
|
@@ -46,7 +35,167 @@ class Tynn
|
|
46
35
|
@app = app
|
47
36
|
end
|
48
37
|
|
49
|
-
|
50
|
-
|
38
|
+
# Internal: Returns the application class that handles the
|
39
|
+
# mock requests. Required by Tynn::Test::InstanceMethods.
|
40
|
+
def app
|
41
|
+
return @app
|
42
|
+
end
|
43
|
+
|
44
|
+
# Internal: This module provides the Tynn::Test API methods.
|
45
|
+
# If you don't like the stand-alone version, you can integrate
|
46
|
+
# this module to your preferred testing environment.
|
47
|
+
#
|
48
|
+
# The following example uses Minitest:
|
49
|
+
#
|
50
|
+
# class HomeTest < Minitest::Test
|
51
|
+
# include Tynn::Test::InstanceMethods
|
52
|
+
#
|
53
|
+
# def app
|
54
|
+
# return Tynn
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# def test_home
|
58
|
+
# get("/")
|
59
|
+
#
|
60
|
+
# assert_equal 200, res.status
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
module InstanceMethods
|
65
|
+
# Public: Returns the current request object or +nil+ if no requests
|
66
|
+
# have been issued yet.
|
67
|
+
#
|
68
|
+
# Examples
|
69
|
+
#
|
70
|
+
# app = Tynn::Test.new
|
71
|
+
# app.get("/", {}, { "HTTP_USER_AGENT" => "Tynn::Test" })
|
72
|
+
#
|
73
|
+
# app.req.get?
|
74
|
+
# # => true
|
75
|
+
#
|
76
|
+
# app.req.env["HTTP_USER_AGENT"]
|
77
|
+
# # => "Tynn::Test"
|
78
|
+
#
|
79
|
+
# The returned object is an instance of
|
80
|
+
# {Rack::Request}[http://www.rubydoc.info/gems/rack/Rack/Request].
|
81
|
+
#
|
82
|
+
def req
|
83
|
+
@__req
|
84
|
+
end
|
85
|
+
|
86
|
+
# Public: Returns the current response object or +nil+ if no requests
|
87
|
+
# have been issued yet.
|
88
|
+
#
|
89
|
+
# Examples
|
90
|
+
#
|
91
|
+
# app = Tynn::Test.new
|
92
|
+
# app.get("/", name: "alice")
|
93
|
+
#
|
94
|
+
# app.res.status
|
95
|
+
# # => 200
|
96
|
+
#
|
97
|
+
# app.res.body
|
98
|
+
# # => "Hello alice!"
|
99
|
+
#
|
100
|
+
# The returned object is an instance of
|
101
|
+
# {Rack::MockResponse}[http://www.rubydoc.info/gems/rack/Rack/MockResponse]
|
102
|
+
#
|
103
|
+
def res
|
104
|
+
@__res
|
105
|
+
end
|
106
|
+
|
107
|
+
# Public: Issues a GET request for the given +path+ with the given
|
108
|
+
# +params+ and Rack environment.
|
109
|
+
#
|
110
|
+
# Examples
|
111
|
+
#
|
112
|
+
# app = Tynn::Test.new
|
113
|
+
# app.get("/search", name: "alice")
|
114
|
+
#
|
115
|
+
def get(path, params = {}, env = {})
|
116
|
+
request(path, env.merge(method: Rack::GET, params: params))
|
117
|
+
end
|
118
|
+
|
119
|
+
# Public: Issues a POST request for the given +path+ with the given
|
120
|
+
# +params+ and Rack environment.
|
121
|
+
#
|
122
|
+
# Examples
|
123
|
+
#
|
124
|
+
# app = Tynn::Test.new
|
125
|
+
# app.post("/signup", username: "alice", password: "secret")
|
126
|
+
#
|
127
|
+
def post(path, params = {}, env = {})
|
128
|
+
request(path, env.merge(method: "POST".freeze, params: params))
|
129
|
+
end
|
130
|
+
|
131
|
+
# Public: Issues a PUT request for the given +path+ with the given
|
132
|
+
# +params+ and Rack environment.
|
133
|
+
#
|
134
|
+
# Examples
|
135
|
+
#
|
136
|
+
# app = Tynn::Test.new
|
137
|
+
# app.put("/users/1", username: "bob", name: "Bob")
|
138
|
+
#
|
139
|
+
def put(path, params = {}, env = {})
|
140
|
+
request(path, env.merge(method: "PUT".freeze, params: params))
|
141
|
+
end
|
142
|
+
|
143
|
+
# Public: Issues a PATCH request for the given +path+ with the given
|
144
|
+
# +params+ and Rack environment.
|
145
|
+
#
|
146
|
+
# Examples
|
147
|
+
#
|
148
|
+
# app = Tynn::Test.new
|
149
|
+
# app.patch("/users/1", username: "alice")
|
150
|
+
#
|
151
|
+
def patch(path, params = {}, env = {})
|
152
|
+
request(path, env.merge(method: "PATCH".freeze, params: params))
|
153
|
+
end
|
154
|
+
|
155
|
+
# Public: Issues a DELETE request for the given +path+ with the given
|
156
|
+
# +params+ and Rack environment.
|
157
|
+
#
|
158
|
+
# Examples
|
159
|
+
#
|
160
|
+
# app = Tynn::Test.new
|
161
|
+
# app.delete("/users/1")
|
162
|
+
#
|
163
|
+
def delete(path, params = {}, env = {})
|
164
|
+
request(path, env.merge(method: "DELETE".freeze, params: params))
|
165
|
+
end
|
166
|
+
|
167
|
+
# Public: Issues a HEAD request for the given +path+ with the given
|
168
|
+
# +params+ and Rack environment.
|
169
|
+
#
|
170
|
+
# Examples
|
171
|
+
#
|
172
|
+
# app = Tynn::Test.new
|
173
|
+
# app.head("/users/1")
|
174
|
+
#
|
175
|
+
def head(path, params = {}, env = {})
|
176
|
+
request(path, env.merge(method: Rack::HEAD, params: params))
|
177
|
+
end
|
178
|
+
|
179
|
+
# Public: Issues a OPTIONS request for the given +path+ with the given
|
180
|
+
# +params+ and Rack environment.
|
181
|
+
#
|
182
|
+
# Examples
|
183
|
+
#
|
184
|
+
# app = Tynn::Test.new
|
185
|
+
# app.options("/users")
|
186
|
+
#
|
187
|
+
def options(path, params = {}, env = {})
|
188
|
+
request(path, env.merge(method: "OPTIONS".freeze, params: params))
|
189
|
+
end
|
190
|
+
|
191
|
+
private
|
192
|
+
|
193
|
+
def request(path, opts = {})
|
194
|
+
@__req = Rack::Request.new(Rack::MockRequest.env_for(path, opts))
|
195
|
+
@__res = Rack::MockResponse.new(*app.call(@__req.env))
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
include InstanceMethods
|
51
200
|
end
|
52
201
|
end
|
data/lib/tynn/version.rb
CHANGED
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tynn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodríguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.4'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rack-test
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.6'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.6'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: tilt
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|