flunk 0.0.12 → 0.0.13
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 +7 -0
- data/lib/flunk.rb +166 -11
- data/lib/generators/flunk_test/templates/flunk_test.rb +3 -3
- metadata +8 -14
- data/test/integration/bananas_test.rb +0 -37
- data/test/test_helper.rb +0 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a617a93d04bbd6c20b131f21271ed6d9c372bc3d
|
4
|
+
data.tar.gz: 33e9a15f41753fe0fd543d581c21154cc2daf8e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c15a389b2b9c0b56df060115d0c6129347fca4f8920041194316895f1d7c35ddd1ec028d435efd468a3bd92da74fdf44838baf5ec1d71f1cd9fae44b94e2f88d
|
7
|
+
data.tar.gz: a233c0b670c259fe4f5a162a76650084b4dc4078f313351b21b453faeb9dfa434375ecba3de0aa4804aa95fd0ec1d616987ca87ead489d00e1ab2c35cabb7e10
|
data/lib/flunk.rb
CHANGED
@@ -3,32 +3,47 @@ require 'rails/test_help'
|
|
3
3
|
class Flunk < ActionDispatch::IntegrationTest
|
4
4
|
|
5
5
|
def self.test(resource, action, &block)
|
6
|
+
|
7
|
+
if action.class == Hash
|
8
|
+
name = action[:name]
|
9
|
+
action = action[:action]
|
10
|
+
end
|
11
|
+
|
6
12
|
new_proc = Proc.new do
|
13
|
+
@resource ||= resource
|
14
|
+
@action ||= action
|
7
15
|
instance_eval(&block)
|
8
16
|
result
|
9
17
|
instance_eval(&@after) unless @after.nil?
|
10
18
|
end
|
11
19
|
|
12
|
-
|
13
|
-
name = action || resource
|
14
|
-
else
|
15
|
-
name = resource + ": " + action
|
16
|
-
end
|
17
|
-
|
20
|
+
name = resource + ": " + action if name.nil?
|
18
21
|
super name, &new_proc
|
19
22
|
end
|
20
23
|
|
21
24
|
def self.flunk(resource, action, failure_reason, &block)
|
22
|
-
|
25
|
+
name = "Flunked #{resource}: #{action} (#{failure_reason})"
|
26
|
+
test(resource, { action: action, name: name }, &block)
|
23
27
|
end
|
24
28
|
|
29
|
+
|
25
30
|
def result
|
26
31
|
if !@result_fetched
|
27
32
|
@result_fetched = true
|
28
33
|
|
34
|
+
@username ||= self.class.config.read_username
|
35
|
+
@password ||= self.class.config.read_password
|
36
|
+
@auth_token ||= self.class.config.read_auth_token
|
37
|
+
@headers ||= self.class.config.read_headers
|
38
|
+
@method ||= self.class.config.read_method
|
39
|
+
@ssl ||= self.class.config.read_ssl
|
40
|
+
|
29
41
|
if @username || @password
|
30
42
|
@headers ||= {}
|
31
43
|
@headers["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64(@username.to_s + ":" + @password.to_s)}".strip
|
44
|
+
elsif @auth_token
|
45
|
+
@headers ||= {}
|
46
|
+
@headers["HTTP_AUTHORIZATION"] = "Token token=\"#{@auth_token}\"".strip
|
32
47
|
end
|
33
48
|
|
34
49
|
send @method, @path, @body, @headers
|
@@ -44,53 +59,136 @@ class Flunk < ActionDispatch::IntegrationTest
|
|
44
59
|
@result = json
|
45
60
|
end
|
46
61
|
end
|
62
|
+
|
63
|
+
if not @desc.nil?
|
64
|
+
make_doc @resource, @action, @desc, @path, @method, @auth_token, @headers, @body, @status, @result
|
65
|
+
end
|
66
|
+
|
47
67
|
end
|
48
68
|
|
49
69
|
@result
|
50
70
|
end
|
51
71
|
|
72
|
+
def desc(desc)
|
73
|
+
@desc = desc
|
74
|
+
end
|
75
|
+
|
76
|
+
def read_desc
|
77
|
+
@desc
|
78
|
+
end
|
79
|
+
|
80
|
+
def base_url(base_url)
|
81
|
+
@base_url
|
82
|
+
end
|
83
|
+
|
84
|
+
def read_base_url
|
85
|
+
@base_url
|
86
|
+
end
|
87
|
+
|
52
88
|
def path(path)
|
53
89
|
@path = path
|
54
90
|
end
|
55
91
|
|
92
|
+
def read_path
|
93
|
+
@path
|
94
|
+
end
|
95
|
+
|
56
96
|
def method(method)
|
57
97
|
@method = method
|
58
98
|
end
|
59
99
|
|
100
|
+
def read_method
|
101
|
+
@method
|
102
|
+
end
|
103
|
+
|
60
104
|
def username(username)
|
61
105
|
@username = username
|
62
106
|
end
|
63
107
|
|
108
|
+
def read_username
|
109
|
+
@username
|
110
|
+
end
|
111
|
+
|
64
112
|
def password(password)
|
65
113
|
@password = password
|
66
114
|
end
|
67
115
|
|
116
|
+
def read_password
|
117
|
+
@password
|
118
|
+
end
|
119
|
+
|
120
|
+
def auth_token(auth_token)
|
121
|
+
@auth_token = auth_token
|
122
|
+
end
|
123
|
+
|
124
|
+
def read_auth_token
|
125
|
+
@auth_token
|
126
|
+
end
|
127
|
+
|
68
128
|
def ssl(ssl)
|
69
129
|
@ssl = ssl
|
70
130
|
end
|
71
131
|
|
132
|
+
def read_ssl
|
133
|
+
@ssl
|
134
|
+
end
|
135
|
+
|
72
136
|
def body(body)
|
73
137
|
@body = body
|
74
138
|
end
|
75
139
|
|
140
|
+
def read_body
|
141
|
+
@body
|
142
|
+
end
|
143
|
+
|
144
|
+
def status(status)
|
145
|
+
@status = status
|
146
|
+
end
|
147
|
+
|
148
|
+
def read_status
|
149
|
+
@status
|
150
|
+
end
|
151
|
+
|
76
152
|
def header(key, value)
|
77
153
|
@headers ||= {}
|
154
|
+
@headers = self.class.config.read_headers.merge @headers
|
78
155
|
@headers[key] = value
|
79
156
|
end
|
80
157
|
|
158
|
+
def read_headers
|
159
|
+
@headers
|
160
|
+
end
|
161
|
+
|
81
162
|
def param(key, value)
|
82
163
|
@params ||= {}
|
83
164
|
@params[key] = value
|
84
165
|
end
|
85
166
|
|
86
|
-
def
|
87
|
-
@
|
167
|
+
def read_params
|
168
|
+
@params
|
88
169
|
end
|
89
170
|
|
90
|
-
def
|
91
|
-
|
171
|
+
def doc_directory(doc_directory)
|
172
|
+
FileUtils.rm_r(doc_directory) if File.exists?(doc_directory)
|
173
|
+
FileUtils.mkdir_p(doc_directory)
|
174
|
+
@doc_directory = doc_directory
|
92
175
|
end
|
93
176
|
|
177
|
+
def read_config_doc_directory
|
178
|
+
@doc_directory
|
179
|
+
end
|
180
|
+
|
181
|
+
def read_doc_directory
|
182
|
+
@doc_directory = self.class.config.read_config_doc_directory || "docs/flunk"
|
183
|
+
FileUtils.mkdir_p(@doc_directory) unless File.exists?(@doc_directory)
|
184
|
+
@doc_directory
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
# before/after blocks
|
191
|
+
|
94
192
|
def before(&block)
|
95
193
|
@before = block
|
96
194
|
instance_eval(&@before)
|
@@ -100,6 +198,18 @@ class Flunk < ActionDispatch::IntegrationTest
|
|
100
198
|
@after = block
|
101
199
|
end
|
102
200
|
|
201
|
+
|
202
|
+
|
203
|
+
# global
|
204
|
+
|
205
|
+
def self.config
|
206
|
+
@@config ||= self.new "FlunkConfig"
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
# helpers
|
212
|
+
|
103
213
|
def rec_symbolize(obj)
|
104
214
|
if obj.class == Hash
|
105
215
|
obj.symbolize_keys!
|
@@ -110,4 +220,49 @@ class Flunk < ActionDispatch::IntegrationTest
|
|
110
220
|
nil
|
111
221
|
end
|
112
222
|
|
223
|
+
def make_doc resource, action, desc, path, method, auth_token, headers, body, status, response
|
224
|
+
body = body.class == String ? JSON.parse(body) : body
|
225
|
+
url = File.join(@@config.read_base_url.to_s, path.to_s)
|
226
|
+
contents = ""
|
227
|
+
contents += "# #{action.humanize}\n\n"
|
228
|
+
contents += "#{desc.humanize}\n\n"
|
229
|
+
contents += "## Request\n\n"
|
230
|
+
if not auth_token.nil?
|
231
|
+
contents += "- Requires Authentication\n"
|
232
|
+
end
|
233
|
+
contents += "- HTTP Method: #{method.to_s.upcase}\n"
|
234
|
+
contents += "- URL: #{url}\n"
|
235
|
+
if not body.nil?
|
236
|
+
contents += "- Body:\n\n```js\n#{JSON.pretty_generate(body)}\n```\n\n"
|
237
|
+
else
|
238
|
+
contents += "\n"
|
239
|
+
end
|
240
|
+
contents += "## Response\n\n"
|
241
|
+
contents += "- Status: #{status} #{status.to_s.humanize}\n"
|
242
|
+
if not response.nil?
|
243
|
+
contents += "- Body:\n\n```js\n#{JSON.pretty_generate(response)}\n```\n\n"
|
244
|
+
else
|
245
|
+
contents += "\n"
|
246
|
+
end
|
247
|
+
contents += "## Example\n\n"
|
248
|
+
contents +=
|
249
|
+
"```bash
|
250
|
+
curl -X #{method.to_s.upcase} \\\n"
|
251
|
+
headers.to_h.each do |key, value|
|
252
|
+
contents +=
|
253
|
+
" -H \"#{key}: #{value}\" \\\n"
|
254
|
+
end
|
255
|
+
if not body.nil?
|
256
|
+
contents +=
|
257
|
+
" -d '#{body.to_json}' \\"
|
258
|
+
end
|
259
|
+
contents +=
|
260
|
+
" \"#{url}\"
|
261
|
+
```"
|
262
|
+
resource_directory = File.join( read_doc_directory, resource.pluralize.capitalize )
|
263
|
+
FileUtils.mkdir_p(resource_directory) unless File.exists?( resource_directory )
|
264
|
+
file_path = File.join( resource_directory, "#{action.capitalize}.md" )
|
265
|
+
File.open(file_path, 'w') {|f| f.write(contents) }
|
266
|
+
end
|
267
|
+
|
113
268
|
end
|
@@ -7,15 +7,15 @@ class <%= class_name.pluralize %>Test < Flunk
|
|
7
7
|
|
8
8
|
# Write tests that should succeed to make sure the required functionality works.
|
9
9
|
test "Resource", "Action" do
|
10
|
+
before {
|
11
|
+
assert_equal 1, 1
|
12
|
+
}
|
10
13
|
desc "A description of the function this tests"
|
11
14
|
path "resource/:id"
|
12
15
|
method :get
|
13
16
|
username @user.username
|
14
17
|
password @user.password
|
15
18
|
status :ok
|
16
|
-
before {
|
17
|
-
assert_equal 1, 1
|
18
|
-
}
|
19
19
|
after {
|
20
20
|
assert_equal 2, 2
|
21
21
|
}
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flunk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.12
|
4
|
+
version: 0.0.13
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Adam Kirk
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A gem for testing Ruby on Rails web APIs by simulating a client.
|
15
14
|
email: atomkirk@gmail.com
|
@@ -22,32 +21,27 @@ files:
|
|
22
21
|
- lib/generators/flunk_test/flunk_test_generator.rb
|
23
22
|
- lib/generators/flunk_test/templates/flunk_test.rb
|
24
23
|
- lib/tasks/flunk.rake
|
25
|
-
- test/integration/bananas_test.rb
|
26
|
-
- test/test_helper.rb
|
27
24
|
homepage: https://github.com/mysterioustrousers/flunk
|
28
25
|
licenses: []
|
26
|
+
metadata: {}
|
29
27
|
post_install_message:
|
30
28
|
rdoc_options: []
|
31
29
|
require_paths:
|
32
30
|
- lib
|
33
31
|
required_ruby_version: !ruby/object:Gem::Requirement
|
34
32
|
requirements:
|
35
|
-
- -
|
33
|
+
- - '>='
|
36
34
|
- !ruby/object:Gem::Version
|
37
35
|
version: '0'
|
38
|
-
none: false
|
39
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- -
|
38
|
+
- - '>='
|
42
39
|
- !ruby/object:Gem::Version
|
43
40
|
version: '0'
|
44
|
-
none: false
|
45
41
|
requirements: []
|
46
42
|
rubyforge_project:
|
47
|
-
rubygems_version:
|
43
|
+
rubygems_version: 2.2.1
|
48
44
|
signing_key:
|
49
|
-
specification_version:
|
45
|
+
specification_version: 4
|
50
46
|
summary: A gem for testing Ruby on Rails web APIs by simulating a client.
|
51
|
-
test_files:
|
52
|
-
- test/integration/bananas_test.rb
|
53
|
-
- test/test_helper.rb
|
47
|
+
test_files: []
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'flunk'
|
3
|
-
|
4
|
-
class BananasTest < Flunk
|
5
|
-
|
6
|
-
setup do
|
7
|
-
end
|
8
|
-
|
9
|
-
# Write tests that should succeed to make sure the required functionality works.
|
10
|
-
test "Banana", "Create" do
|
11
|
-
before {
|
12
|
-
@count = 1
|
13
|
-
p "before was called"
|
14
|
-
}
|
15
|
-
|
16
|
-
p @count
|
17
|
-
desc "Create a Banana"
|
18
|
-
path "bananas"
|
19
|
-
method :post
|
20
|
-
status :created
|
21
|
-
body banana: { weight: 2 }
|
22
|
-
|
23
|
-
after {
|
24
|
-
assert_equal @count, 1
|
25
|
-
p "after was called"
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
# Write a test that SHOULD fail to ensure your application handles bad requests gracefully.
|
31
|
-
# flunk "Banana", "Create", "Not found" do
|
32
|
-
# path "/bananas/10000"
|
33
|
-
# method :get
|
34
|
-
# status :not_found
|
35
|
-
# end
|
36
|
-
|
37
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.expand_path('../../config/environment', __FILE__)
|
3
|
-
require 'rails/test_help'
|
4
|
-
|
5
|
-
class ActiveSupport::TestCase
|
6
|
-
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
-
#
|
8
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
-
# -- they do not yet inherit this setting
|
10
|
-
fixtures :all
|
11
|
-
|
12
|
-
# Add more helper methods to be used by all tests here...
|
13
|
-
end
|