flunk 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -47,7 +47,10 @@ You write tests that SHOULD pass to test your app's basic functionality all work
47
47
  method :post
48
48
  body user: attrs = FactoryGirl.attributes_for(:user)
49
49
  status :created
50
- assertions {
50
+ before {
51
+ assert_equal 0, user.languages.count
52
+ }
53
+ after {
51
54
  assert_equal result[:name], attrs[:name]
52
55
  assert_equal result[:username], attrs[:username]
53
56
  assert_equal result[:email], attrs[:email]
@@ -57,23 +60,12 @@ You write tests that SHOULD pass to test your app's basic functionality all work
57
60
  }
58
61
  end
59
62
 
60
- test "User", "Log In" do
61
- desc "Obtain a users API token by logging in with their username and password"
62
- path "login"
63
- method :get
64
- body username: @user.username, password: @user.password
65
- status :ok
66
- assertions {
67
- assert_not_nil result[:api_token]
68
- }
69
- end
70
-
71
63
  test "User", "Log In With Email" do
72
64
  path "login"
73
65
  method :get
74
66
  body username: @user.email, password: @user.password
75
67
  status :ok
76
- assertions {
68
+ after {
77
69
  assert_not_nil result[:api_token]
78
70
  }
79
71
  end
@@ -86,56 +78,6 @@ You write tests that SHOULD pass to test your app's basic functionality all work
86
78
  status :ok
87
79
  end
88
80
 
89
- test "User", "Update" do
90
- desc "Update the username, e-mail, password and/or name"
91
- path "account"
92
- method :put
93
- username @user.api_token
94
- body user: { username: username = Faker::Internet.user_name }
95
- status :ok
96
- assertions {
97
- assert_equal result[:username], username
98
- }
99
- end
100
-
101
- test "User", "Update E-mail" do
102
- path "account"
103
- method :put
104
- username @user.api_token
105
- body user: { email: email = Faker::Internet.email }
106
- status :ok
107
- assertions {
108
- assert_equal result[:email], email
109
- }
110
- end
111
-
112
- test "User", "Update User Password" do
113
- path "account"
114
- method :put
115
- username @user.api_token
116
- body user: { password: Faker::Lorem.characters(10) }
117
- status :ok
118
- end
119
-
120
- test "User", "Update Name" do
121
- path "account"
122
- method :put
123
- username @user.api_token
124
- body user: { name: name = Faker::Name.first_name }
125
- status :ok
126
- assertions {
127
- assert_equal result[:name], name
128
- }
129
- end
130
-
131
- test "User", "Destroy" do
132
- path "account"
133
- method :delete
134
- username @user.api_token
135
- status :ok
136
- end
137
-
138
-
139
81
 
140
82
  Then, write tests that SHOULDN'T pass to make sure your app rejects bad requests correctly/gracefully:
141
83
 
@@ -154,139 +96,6 @@ Then, write tests that SHOULDN'T pass to make sure your app rejects bad requests
154
96
  body user: FactoryGirl.attributes_for(:user, username: @user.username)
155
97
  status :unprocessable_entity
156
98
  end
157
-
158
- flunk "User", "Create", "Invalid username" do
159
- path "signup"
160
- method :post
161
- body user: FactoryGirl.attributes_for(:user, username: "a234$2aa" )
162
- status :unprocessable_entity
163
- end
164
-
165
- flunk "User", "Create", "Missing e-mail" do
166
- desc "Attempting to create a user without a e-mail."
167
- path "signup"
168
- method :post
169
- body user: FactoryGirl.attributes_for(:user, email: nil)
170
- status :unprocessable_entity
171
- end
172
-
173
- flunk "User", "Create", "E-mail already taken" do
174
- desc "Attempting to create a user with an e-mail that's already taken."
175
- path "signup"
176
- method :post
177
- body user: FactoryGirl.attributes_for(:user, email: @user.email)
178
- status :unprocessable_entity
179
- end
180
-
181
- flunk "User", "Create", "Invalid e-mail" do
182
- path "signup"
183
- method :post
184
- body user: FactoryGirl.attributes_for(:user, email: "aaaa@aakk")
185
- status :unprocessable_entity
186
- end
187
-
188
- flunk "User", "Create", "Missing password" do
189
- desc "Attempting to create a user without a password."
190
- path "signup"
191
- method :post
192
- body user: FactoryGirl.attributes_for(:user, password: nil)
193
- status :unprocessable_entity
194
- end
195
-
196
- flunk "User", "Create", "Missing name" do
197
- path "signup"
198
- method :post
199
- body user: FactoryGirl.attributes_for(:user, name: nil)
200
- status :unprocessable_entity
201
- end
202
-
203
-
204
-
205
-
206
- flunk "User", "Log In", "No username" do
207
- desc "Attempting to obtain an API token with the wrong password"
208
- path "login"
209
- method :get
210
- body password: "a"
211
- status :unauthorized
212
- end
213
-
214
- flunk "User", "Log In", "Wrong password" do
215
- desc "Attempting to obtain an API token with the wrong password"
216
- path "login"
217
- method :get
218
- body username: @user.username, password: "a"
219
- status :unauthorized
220
- end
221
-
222
-
223
-
224
-
225
- flunk "User", "Read", "Wrong API token" do
226
- path "login"
227
- method :get
228
- username "a"
229
- status :unauthorized
230
- end
231
-
232
-
233
-
234
-
235
- flunk "User", "Update", "Wrong password" do
236
- path "account"
237
- method :put
238
- username "a"
239
- body user: FactoryGirl.attributes_for(:user)
240
- status :unauthorized
241
- end
242
-
243
- flunk "User", "Update", "Username already taken" do
244
- path "account"
245
- method :put
246
- username @user.api_token
247
- u = FactoryGirl.create(:user)
248
- body user: { username: u.username }
249
- status :unprocessable_entity
250
- end
251
-
252
- flunk "User", "Update", "Invalid username" do
253
- path "account"
254
- method :put
255
- username @user.api_token
256
- body user: { username: "a234$2aa" }
257
- status :unprocessable_entity
258
- end
259
-
260
- flunk "User", "Update", "E-mail already taken" do
261
- desc "Attempting to update a user with an e-mail that's already taken."
262
- path "account"
263
- method :put
264
- username @user.api_token
265
- u = FactoryGirl.create(:user)
266
- body user: { email: u.email }
267
- status :unprocessable_entity
268
- end
269
-
270
- flunk "User", "Update", "Invalid e-mail" do
271
- desc "Attempting to update the user with an invalid e-mail"
272
- path "account"
273
- method :put
274
- username @user.api_token
275
- body user: { email: "aaaa@aakk" }
276
- status :unprocessable_entity
277
- end
278
-
279
-
280
-
281
-
282
- flunk "User", "Delete", "Wrong password" do
283
- path "account"
284
- method :delete
285
- username "a"
286
- body user: FactoryGirl.attributes_for(:user)
287
- status :unauthorized
288
- end
289
-
290
99
  end
291
100
 
292
101
  ### Generator
data/flunk.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "flunk"
3
- s.version = "0.0.7"
3
+ s.version = "0.0.8"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Adam Kirk"]
6
6
  s.email = %q{atomkirk@gmail.com}
data/lib/flunk.rb CHANGED
@@ -4,9 +4,10 @@ class Flunk < ActionDispatch::IntegrationTest
4
4
 
5
5
  def self.test(resource, action, &block)
6
6
  new_proc = Proc.new do
7
+ @before.call unless @before.nil?
7
8
  instance_eval(&block)
8
9
  result
9
- @assertions.call unless @assertions.nil?
10
+ @after.call unless @after.nil?
10
11
  end
11
12
 
12
13
  if !action || !resource
@@ -91,8 +92,12 @@ class Flunk < ActionDispatch::IntegrationTest
91
92
  @desc = desc
92
93
  end
93
94
 
94
- def assertions(&block)
95
- @assertions = block
95
+ def before(&block)
96
+ @before = block
97
+ end
98
+
99
+ def after(&block)
100
+ @after = block
96
101
  end
97
102
 
98
103
  def rec_symbolize(obj)
@@ -13,14 +13,17 @@ class <%= class_name.pluralize %>Test < Flunk
13
13
  username @user.username
14
14
  password @user.password
15
15
  status :ok
16
- assertions {
16
+ before {
17
+ assert_equal 1, 1
18
+ }
19
+ after {
17
20
  assert_equal 2, 2
18
21
  }
19
22
  end
20
23
 
21
24
 
22
25
  # Write a test that SHOULD fail to ensure your application handles bad requests gracefully.
23
- flunk "Resource", "Action, "Why it flunks" do
26
+ flunk "Resource", "Action", "Why it flunks" do
24
27
  path "/resource/:id"
25
28
  method :get
26
29
  status :unauthorized
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
4
  prerelease:
5
+ version: 0.0.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Adam Kirk
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-25 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A gem for testing Ruby on Rails web APIs by simulating a client.
15
15
  email: atomkirk@gmail.com
@@ -33,20 +33,20 @@ rdoc_options: []
33
33
  require_paths:
34
34
  - lib
35
35
  required_ruby_version: !ruby/object:Gem::Requirement
36
- none: false
37
36
  requirements:
38
37
  - - ! '>='
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
- required_rubygems_version: !ruby/object:Gem::Requirement
42
40
  none: false
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
42
  requirements:
44
43
  - - ! '>='
45
44
  - !ruby/object:Gem::Version
46
45
  version: '0'
46
+ none: false
47
47
  requirements: []
48
48
  rubyforge_project:
49
- rubygems_version: 1.8.24
49
+ rubygems_version: 1.8.23
50
50
  signing_key:
51
51
  specification_version: 3
52
52
  summary: A gem for testing Ruby on Rails web APIs by simulating a client.