tynn 1.1.0 → 1.2.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: caaa63933cf9306d02ec269daf58276c16cd28d3
4
- data.tar.gz: f42352bb844554c1dd98f020bbceec81e5f6a6bb
3
+ metadata.gz: a6cd976ef2725374c76761726c9c86a4714a0aed
4
+ data.tar.gz: f769dcbcabcc8ac1941a175e2280d860cdf3304e
5
5
  SHA512:
6
- metadata.gz: 22ca341ae338b0305f31632ee651dea757344c1e6185ef33f18d2821ea0af12202275e0dda1a811f2d4a89ffcc803f5cbad409e7e2188c85f7d773c0bf625c62
7
- data.tar.gz: 29923d6637a08a4d0d945ccfafe95b2ed9dbe2643c76085bc5ee1c476f0c55dff973e906bca95ab1c458d2b04a13503b1aaaef9b98bdb8f15f81038d31d9929e
6
+ metadata.gz: 304636238779f980affe65c6028814bcbe63823264baf249e599ec8fbf1dd002dd70947c0a3cce5b4e801afea6a20210dfcf1c64d07bd65b0835285d382ce53c
7
+ data.tar.gz: f48e2523ac152117c16c79972a8ada5ed7962fca259904fdd4ae1f3b562931ce0bf480c0684154b43379c0c739164578d3623697d14a3797760eb5807105702b
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- tynn [![Build Status](https://travis-ci.org/frodsan/tynn.svg)](https://travis-ci.org/frodsan/tynn) [![Code Climate](https://codeclimate.com/github/frodsan/tynn/badges/gpa.svg)](https://codeclimate.com/github/frodsan/tynn)
1
+ tynn [![Build Status](https://travis-ci.org/frodsan/tynn.svg)](https://travis-ci.org/frodsan/tynn)
2
2
  ====
3
3
 
4
4
  A thin library for web development.
@@ -14,7 +14,7 @@ class Tynn
14
14
  # Tynn.production? # => false
15
15
  # Tynn.test? # => false
16
16
  #
17
- # By default, the environment is based on `ENV["RACK_ENV"]`.
17
+ # By default, the environment is based on <tt>ENV["RACK_ENV"]</tt>.
18
18
  #
19
19
  # Examples
20
20
  #
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
- # 200 == app.res.status # => true
21
- # "hei" == app.res.body # => true
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
- alias_method :res, :last_response
50
- alias_method :req, :last_request
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
@@ -1,7 +1,7 @@
1
1
  class Tynn # :nodoc: all
2
2
  VERSION = [
3
3
  MAJOR_VERSION = 1,
4
- MINOR_VERSION = 1,
4
+ MINOR_VERSION = 2,
5
5
  PATCH_VERSION = 0,
6
6
  PRE_VERSION = nil
7
7
  ].compact.join(".")
data/test/helper.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  $VERBOSE = true
2
2
 
3
3
  require "cutest"
4
- require "rack/test"
5
4
  require_relative "../lib/tynn"
6
5
  require_relative "../lib/tynn/test"
7
6
 
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.1.0
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-29 00:00:00.000000000 Z
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