lurker 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +1 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +60 -24
  5. data/Rakefile +1 -1
  6. data/certs/razum2um.pem +21 -0
  7. data/features/controller_nested_schema_scaffolding.feature +5 -9
  8. data/features/controller_schema_scaffolding.feature +5 -9
  9. data/features/html_generation.feature +1 -1
  10. data/features/minitest.feature +140 -0
  11. data/features/multidomain_support.feature +1 -1
  12. data/features/partials.feature +3 -3
  13. data/features/request_nested_schema_scaffolding.feature +3 -3
  14. data/features/request_schema_scaffolding.feature +2 -2
  15. data/features/schema_suffixes.feature +4 -4
  16. data/features/step_definitions/additional_cli_steps.rb +9 -0
  17. data/features/support/env.rb +1 -1
  18. data/features/test_endpoint.feature +5 -5
  19. data/lib/lurker.rb +15 -0
  20. data/lib/lurker/cli.rb +2 -3
  21. data/lib/lurker/presenters/endpoint_presenter.rb +10 -4
  22. data/lib/lurker/request.rb +41 -0
  23. data/lib/lurker/response.rb +16 -0
  24. data/lib/lurker/schema.rb +0 -8
  25. data/lib/lurker/service.rb +2 -2
  26. data/lib/lurker/spec_helper.rb +2 -0
  27. data/lib/lurker/spec_helper/rails.rb +40 -0
  28. data/lib/lurker/spec_helper/rspec.rb +66 -0
  29. data/lib/lurker/spy.rb +88 -0
  30. data/lib/lurker/version.rb +1 -1
  31. data/lurker.gemspec +12 -9
  32. data/templates/generate_stuff.rb +29 -2
  33. data/templates/lurker_app.rb +27 -4
  34. data/templates/rails32_http_patch_support.rb +125 -0
  35. metadata +119 -57
  36. metadata.gz.sig +3 -0
  37. checksums.yaml.gz.asc +0 -12
  38. data.tar.gz.asc +0 -12
  39. data/lib/lurker/controller_spec_watcher.rb +0 -70
  40. data/lib/lurker/request_spec_watcher.rb +0 -80
  41. data/lib/lurker/spec_watcher.rb +0 -124
  42. metadata.gz.asc +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad859d0f48735e26b9982192d403652155d5b24c
4
- data.tar.gz: 52923c3207cb795bd749a599ece81ba0d2ac0fc7
3
+ metadata.gz: 0812edbd0dea8fa5b7e25895f2247af7ae966e4c
4
+ data.tar.gz: 08abda5c9954e5e59554deb6ca9e38db84bbb71a
5
5
  SHA512:
6
- metadata.gz: 7270039d305264702ad81589cf632ef42675bf76d32402db628b1c5c9decb0475e84c4bb4b5771653dfb34e5bbe9c95c7290947b88f7d78d3566e821a0938851
7
- data.tar.gz: 882a2631d4ff8333774bad0826fda58da98eff73e4df9d238f6bc07c6f96b86ee263433c594e4e104a3ab948ee41e0dad13c59b6cf674a99efcd5a631995d7e5
6
+ metadata.gz: 53ba7f03739d9b9f7dc35f3a0b727122677b2724699cf7bda2697d00f49d448317e53414fe99895ffd4283b93172e8c4141bf832320b1c80f1b42bd0eaa64d0c
7
+ data.tar.gz: 4531e95b5c5a0bcdfd632f614c8c908b40304686028c11ae4f23b4126ab0fe921c12133fd51d735df560b7f2d5b62f4bad705d73916846a47b374103b7996e33
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ <H�;"y���ϊ����ר�h�E3eL�d�8��&���wl�@��,M��D��9������1���l 4[d��T��\�����[���.Yd����Dž�-;���ZQ�BC����v�(��&��X�-sֱ�������ω������t�,>��Ʒ$�@�J��{����Aj{� ��V����J�/� } s������>E�8�.��O�Q5���NՔ��X�Y��,W� ��Āg>u��W������`
data.tar.gz.sig ADDED
Binary file
data/README.md CHANGED
@@ -10,19 +10,53 @@ Works on Rails 3.2, 4.0, 4.1 & Ruby 1.9.3, 2.0.0, 2.1.1.
10
10
 
11
11
  ## Installation
12
12
 
13
- Add this line to your application's Gemfile:
13
+ Add my public key:
14
+
15
+ gem cert --add <(curl -Ls https://raw.github.com/razum2um/lurker/master/certs/razum2um.pem)
16
+
17
+ $ gem install lurker # without key
18
+ $ gem install lurker -P HighSecurity # secure, with key added
19
+
20
+ Or this line to your application's Gemfile:
14
21
 
15
22
  gem 'lurker'
16
23
 
24
+ Inject into `test_helper.rb` or `spec_helper.rb`:
25
+
26
+ require 'lurker/spec_helper'
27
+
17
28
  ## Usage
18
29
 
19
- Write your [RSpec][rspec] [controller][rspec_controller_spec] or [request][rspec_request_spec] specs as usual,
30
+ Wrap your intergation test code, which does request like this
31
+
32
+ Lurker::Spy.on do
33
+ get "/api/v1/users.json"
34
+ end
35
+
36
+ And run the specs and commit your schemas. That's all, easy!
37
+
38
+ ## RSpec usage
39
+
40
+ Write your RSpec [controller][rspec_controller_spec] or [request][rspec_request_spec] specs as usual,
20
41
  but add `:lurker` mark (like documented [controller example][controler_spec_example] or [request spec example][request_spec_example]).
21
42
 
22
- describe Api::V1::UsersController, :lurker do
23
- ...
43
+ it "lists users", :lurker do
44
+ get "/api/v1/users.json"
45
+ end
46
+
47
+ ## Minitest usage
48
+
49
+ You can use [minitest-around][minitest_around] to wrap your test classes like this:
50
+
51
+ class DestroyRepoTest < ActionDispatch::IntegrationTest
52
+ def around(&block)
53
+ Lurker::Spy.on(&block)
54
+ end
55
+ end
24
56
 
25
- And run the specs. That's all, easy!
57
+ You also can wrap any block with api requests [manually][minitest_example].
58
+
59
+ ## Schemas
26
60
 
27
61
  Please, commit your files under `Rails.root/lurker` directory.
28
62
  Feel free to edit them according to [json-schema][json_schema] standart.
@@ -55,6 +89,20 @@ Let's run your `rails s` and visit [http://localhost:3000/lurker/](http://localh
55
89
 
56
90
  Now, you can test your API on-line (for real)
57
91
 
92
+ ## [Demo application][demo_app3]
93
+
94
+ You can clone the repo & run `rake build_example_docs && cd tmp/lurker_app && bin/rails s`
95
+ to get your running demo.
96
+
97
+ Lurker supports multiple domains (usually `staging` and `production`) and can be deployed
98
+ statically everywhere as well as be served by current `Rails` instance.
99
+
100
+ For example:
101
+
102
+ - [Github Pages][demo_app3] is deployed statically; no api endpoint
103
+ - [Custom domain][demo_app2] html deployed under nginx; passenger serves demo api production endpoint
104
+ - [Heroku][demo_app] html is served by unicorn as well as staging api endpoint in `Sandbox` mode
105
+
58
106
  ## Features
59
107
 
60
108
  - [Autoscaffolding for non-covered API endpoints][controler_spec_example]
@@ -72,6 +120,7 @@ Now, you can test your API on-line (for real)
72
120
  - JSON-Schema draft-v4 support
73
121
  - Static site deploy and milti-domain support
74
122
  - Builtin Rack middlware `Lurker::Server.to_rack` serves cached digested assets
123
+ - [RSpec][failed_spec_example] & [Minitest][minitest_example] support
75
124
 
76
125
  ## Token authentication with sandbox
77
126
 
@@ -90,20 +139,6 @@ are increasing notwithstanding ROLLBACK is called. As such:
90
139
  - ensure the same token to be accepted on your demo application
91
140
  - insert `Lurker::Sandbox` and the recorded examples should be ok to submit again
92
141
 
93
- ## [Demo application][demo_app3]
94
-
95
- You can clone the repo & run `rake build_example_docs && cd tmp/lurker_app && bin/rails s`
96
- to get your running demo.
97
-
98
- Lurker supports multiple domains (usually `staging` and `production`) and can be deployed
99
- statically everywhere as well as be served by current `Rails` instance.
100
-
101
- For example:
102
-
103
- - [Github Pages][demo_app3] is deployed statically; no api endpoint
104
- - [Custom domain][demo_app2] html deployed under nginx; passenger serves demo api production endpoint
105
- - [Heroku][demo_app] html is served by unicorn as well as staging api endpoint in `Sandbox` mode
106
-
107
142
  ## Contributions
108
143
 
109
144
  [![Code Climate][CC img]][Code Climate]
@@ -140,7 +175,7 @@ so there are `<label htmlFor` instead of `<label for>` and `<div className` inst
140
175
 
141
176
  Sponsored by [Evil Martians][evil_martians], thanks!
142
177
 
143
- This gem is quite opinionated and relies on rails & rspec - if you're
178
+ This gem is quite opinionated and relies on rails - if you're
144
179
  interested in anything else, please take a look at [api_taster][api_taster] or [fdoc][fdoc],
145
180
  This gem is heavily inspirated by them. Thanks, @square & @fredwu
146
181
 
@@ -154,16 +189,16 @@ Also thanks to
154
189
  [hljs]: http://highlightjs.org/
155
190
  [waffle]: https://waffle.io/razum2um/lurker
156
191
  [gh_api]: https://developer.github.com/v3/meta/
157
- [rspec]: https://github.com/rspec/rspec-rails
158
192
  [api_taster]: https://github.com/fredwu/api_taster
159
193
  [reactjs]: http://facebook.github.io/react/
160
194
  [fdoc]: https://github.com/square/fdoc
161
- [rspec_controller_spec]: https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs
162
- [rspec_request_spec]: https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec
163
195
  [json_schema]: http://json-schema.org/
164
196
  [json_schema_example]: http://json-schema.org/example2.html
165
197
  [json_schema_book]: http://spacetelescope.github.io/understanding-json-schema/
166
198
  [evil_martians]: http://evilmartians.com/
199
+ [rspec_controller_spec]: https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs
200
+ [rspec_request_spec]: https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec
201
+ [minitest_around]: https://github.com/splattael/minitest-around
167
202
 
168
203
  [failed_spec_example]: https://www.relishapp.com/razum2um/lurker/docs/test-endpoint
169
204
  [controler_spec_example]: https://www.relishapp.com/razum2um/lurker/docs/controller-schema-scaffolding
@@ -172,12 +207,13 @@ Also thanks to
172
207
  [html_generation_example]: https://www.relishapp.com/razum2um/lurker/docs/html-generation
173
208
  [partial_example]: https://www.relishapp.com/razum2um/lurker/docs/partials
174
209
  [suffixes_example]: https://www.relishapp.com/razum2um/lurker/docs/request-schema-suffixes
210
+ [minitest_example]: https://www.relishapp.com/razum2um/lurker/docs/minitest
175
211
 
176
212
  [demo_app]: http://lurker-app.herokuapp.com
177
213
  [demo_app2]: http://lurker.razum2um.me
178
214
  [demo_app3]: http://razum2um.github.io/lurker/
179
215
  [demo_live]: http://lurker.razum2um.me/lurker/api/v1/users-POST.html
180
- [pdf_example]: http://razum2um.github.io/lurker/LurkerApp.pdf
216
+ [pdf_example]: http://razum2um.github.io/lurker/Lurker%20Demo%20Application.pdf
181
217
  [partial_example_demo]: http://razum2um.github.io/lurker/api/v1/users/__user_id/repos-POST.html
182
218
 
183
219
  [Gem Version]: https://rubygems.org/gems/lurker
data/Rakefile CHANGED
@@ -302,7 +302,7 @@ task :publish do
302
302
  system "git tag v#{version}"
303
303
  system "relish versions:add razum2um/lurker:#{version}"
304
304
  system "relish push razum2um/lurker:#{version}"
305
- system "gem build lurker.gemspec --sign"
305
+ system "gem build lurker.gemspec"
306
306
  system "git push --tags"
307
307
  system "gem push lurker-#{version}.gem"
308
308
  end
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApib2tv
3
+ di52bGFkMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNj
4
+ b20wHhcNMTQwNTIwMjAyOTAyWhcNMTUwNTIwMjAyOTAyWjBBMRMwEQYDVQQDDApi
5
+ b2tvdi52bGFkMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
6
+ FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCibrb/aiZX3kWo
7
+ Fmzo3gvGBFS9N18Q5rp9UTJRc4KxZQOay2WcgLjy1oU61r2Urjz3VDT4sg/yw3N3
8
+ YXIPqSTRl+OPIaafe45TVpF4mtMSsc1Gm/O3Sfoz6URiMd9iDtc2sTpaMgatL4pV
9
+ EExER9emjrmElRFknJD65E3gVDX7KXvrZYYAScJR33DADIGUgpuyHm29S7G/4WAy
10
+ ol6XfmPx+x5rM49QytGSNCQDYQ3SMMCo9wKkEm3Zcx0O4qhO8INevl/mvkAWLhOA
11
+ +0qldtuUx9wbBQ0D0wVR8LTafqWrIUHQjWXqrhWBqXhYeR3jj5aehBhpPFclHuKU
12
+ 5GeILZrFAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
13
+ BBSiidH2CEJmkza+NBBJNLcnzQX57TAfBgNVHREEGDAWgRRib2tvdi52bGFkQGdt
14
+ YWlsLmNvbTAfBgNVHRIEGDAWgRRib2tvdi52bGFkQGdtYWlsLmNvbTANBgkqhkiG
15
+ 9w0BAQUFAAOCAQEAVEyF63kQT9HKm3YIw1WzLvuOMvEUThzBomMMsTp9CGXWvem6
16
+ wZdMhxykwk1lga0OwsCn+wr1tWZ/cNeWqGSY00vTfLWdriK60xuRW7zT1Z5tmxbD
17
+ dq2ULdhII/qCFQlzDB/+IptO1rJLzfxTckoArmeYtkBV6LaVd7wpaRZnw0Apm93e
18
+ ph03YddPDbB34xTivvu4d6BBbKGxj/YN+1NLD9rMi6FspgcA4P1UlmKqyCluTbZj
19
+ vzKbYclpJ7gENr/xiTjGqA/Md3zJMzmsFrzUXt4RVmo5SaCyZjC6gFfhSr+PODc7
20
+ ZaSbckvH/+m4boAsg0JkGGFcS3j5fgNmdwgA1A==
21
+ -----END CERTIFICATE-----
@@ -18,7 +18,7 @@ Feature: controller nested schema scaffolding
18
18
  end
19
19
 
20
20
  it "lists all the repos of the user" do
21
- get :index, user_id: user.id, limit: 1
21
+ get :index, user_id: user.id, limit: 1, format: 'json'
22
22
  expect(response).to be_success
23
23
  expect(JSON.parse(response.body).size).to eq 1
24
24
  end
@@ -39,10 +39,6 @@ Feature: controller nested schema scaffolding
39
39
  additionalProperties: false
40
40
  required: []
41
41
  properties:
42
- user_id:
43
- description: ''
44
- type: integer
45
- example: 1
46
42
  limit:
47
43
  description: ''
48
44
  type: integer
@@ -73,13 +69,13 @@ Feature: controller nested schema scaffolding
73
69
  example: 1
74
70
  extensions:
75
71
  method: GET
76
- path_info: "/api/v1/users/1/repos"
72
+ path_info: "/api/v1/users/1/repos.json"
77
73
  path_params:
78
- action: index
79
- controller: api/v1/repos
80
74
  user_id: '1'
75
+ controller: api/v1/repos
76
+ action: index
81
77
  query_params:
82
- limit: '1'
78
+ limit: 1
83
79
  suffix: ''
84
80
 
85
81
  """
@@ -17,7 +17,7 @@ Feature: controller schema scaffolding
17
17
  end
18
18
 
19
19
  it "shows user" do
20
- get :show, id: user.id
20
+ get :show, id: user.id, format: 'json'
21
21
  expect(response).to be_success
22
22
  end
23
23
  end
@@ -36,11 +36,7 @@ Feature: controller schema scaffolding
36
36
  type: object
37
37
  additionalProperties: false
38
38
  required: []
39
- properties:
40
- id:
41
- description: ''
42
- type: integer
43
- example: 1
39
+ properties: {}
44
40
  responseCodes:
45
41
  - status: 200
46
42
  successful: true
@@ -61,11 +57,11 @@ Feature: controller schema scaffolding
61
57
  example: razum2um
62
58
  extensions:
63
59
  method: GET
64
- path_info: "/api/v1/users/1"
60
+ path_info: "/api/v1/users/1.json"
65
61
  path_params:
66
- action: show
67
- controller: api/v1/users
68
62
  id: '1'
63
+ controller: api/v1/users
64
+ action: show
69
65
  suffix: ''
70
66
 
71
67
  """
@@ -36,7 +36,7 @@ Feature: html generation
36
36
  required: []
37
37
  extensions:
38
38
  method: POST
39
- path_info: "/api/v1/users"
39
+ path_info: "/api/v1/users.json"
40
40
  path_params:
41
41
  action: create
42
42
  controller: api/v1/users
@@ -0,0 +1,140 @@
1
+ Feature: minitest
2
+
3
+ When you're testing your api with `minitest` and
4
+ `ActionDispatch::IntegrationTest`: you can
5
+ simply wrap your code in `Lurker::Spy.on do ... end`
6
+
7
+ Scenario: scaffold a json schema for a "repos/destroy" in minitest
8
+ Given a file named "test/integration/destroy_repo_test.rb" with:
9
+ """ruby
10
+ require_relative '../test_helper'
11
+
12
+ class DestroyRepoTest < ActionDispatch::IntegrationTest
13
+ def test_destruction
14
+ user = User.where(name: 'razum2um').first_or_create!
15
+ repo = user.repos.first_or_create!(name: 'lurker')
16
+
17
+ assert_equal 1, Repo.count
18
+
19
+ Lurker::Spy.on do
20
+ delete "/api/v1/users/#{user.id}/repos/#{repo.id}.json"
21
+ end
22
+
23
+ assert_equal 200, status
24
+ assert_equal 0, Repo.count
25
+ end
26
+ end
27
+ """
28
+
29
+ When I run `ruby test/integration/destroy_repo_test.rb`
30
+ Then the output should contain unescaped these lines:
31
+ """
32
+ 1 (runs|tests), 3 assertions, 0 failures, 0 errors, 0 skips
33
+ """
34
+ Then a file named "lurker/api/v1/users/__user_id/repos/__id-DELETE.json.yml" should exist
35
+ Then the file "lurker/api/v1/users/__user_id/repos/__id-DELETE.json.yml" should contain exactly:
36
+ """yml
37
+ ---
38
+ description: repo descruction
39
+ prefix: repos management
40
+ requestParameters:
41
+ description: ''
42
+ type: object
43
+ additionalProperties: false
44
+ required: []
45
+ properties: {}
46
+ responseCodes:
47
+ - status: 200
48
+ successful: true
49
+ description: ''
50
+ responseParameters:
51
+ description: ''
52
+ type: object
53
+ additionalProperties: false
54
+ required: []
55
+ properties: {}
56
+ extensions:
57
+ method: DELETE
58
+ path_info: "/api/v1/users/1/repos/1.json"
59
+ path_params:
60
+ action: destroy
61
+ controller: api/v1/repos
62
+ user_id: '1'
63
+ id: '1'
64
+ suffix: ''
65
+
66
+ """
67
+
68
+ Scenario: json schema tests "users/update" in minitest
69
+ Given a file named "lurker/api/v1/users/__id-PATCH.json.yml" with:
70
+ """yml
71
+ ---
72
+ prefix: 'users management'
73
+ description: 'user updating'
74
+ requestParameters:
75
+ properties:
76
+ id:
77
+ type: integer
78
+ example: 1
79
+ user:
80
+ type: object
81
+ properties:
82
+ name:
83
+ type: string
84
+ example: Bob
85
+ responseCodes:
86
+ - status: 400
87
+ successful: true
88
+ description: ''
89
+ - status: 200
90
+ successful: true
91
+ description: ''
92
+ responseParameters:
93
+ properties:
94
+ id:
95
+ type: integer
96
+ example: 1
97
+ name:
98
+ type: string
99
+ example: Bob
100
+ extensions:
101
+ path_info: "/api/v1/users/1"
102
+ method: PATCH
103
+ suffix: ''
104
+ path_params:
105
+ action: update
106
+ controller: api/v1/users
107
+ id: 1
108
+ """
109
+
110
+ And a file named "test/integration/update_user_test.rb" with:
111
+ """ruby
112
+ require_relative '../test_helper'
113
+
114
+ class UpdateUserTest < ActionDispatch::IntegrationTest
115
+ def test_updating
116
+ user = User.where(name: 'razum2um').first_or_create!
117
+ assert_equal 1, User.count
118
+
119
+ Lurker::Spy.on do
120
+ patch "/api/v1/users/#{user.id}.json", user: { name: '' }
121
+ end
122
+
123
+ assert_equal 200, status
124
+ assert_equal 'John', user.reload.name
125
+ end
126
+ end
127
+ """
128
+
129
+ When I run `ruby test/integration/update_user_test.rb`
130
+ Then the output should contain failures:
131
+ """
132
+ Lurker::ValidationError:
133
+ Response
134
+ The property '#/' contains additional properties ["errors"]
135
+
136
+ """
137
+ And the output should contain unescaped these lines:
138
+ """
139
+ 1 (runs|tests), 1 assertions, 0 failures, 1 errors, 0 skips
140
+ """
@@ -45,7 +45,7 @@ Feature: mutidomain support
45
45
  properties: {}
46
46
  extensions:
47
47
  method: DELETE
48
- path_info: "/api/v1/users/1"
48
+ path_info: "/api/v1/users/1.json"
49
49
  path_params:
50
50
  action: destroy
51
51
  controller: api/v1/users
@@ -42,7 +42,7 @@ Feature: partials
42
42
  requestParameters:
43
43
  properties:
44
44
  user_id:
45
- type: integer
45
+ type: string
46
46
  example: 1
47
47
  repo:
48
48
  properties:
@@ -56,7 +56,7 @@ Feature: partials
56
56
  $ref: '../../../../definitions/repo.json#/'
57
57
  extensions:
58
58
  method: POST
59
- path_info: "/api/v1/users/1/repos"
59
+ path_info: "/api/v1/users/1/repos.json"
60
60
  path_params:
61
61
  action: create
62
62
  controller: api/v1/repos
@@ -75,7 +75,7 @@ Feature: partials
75
75
 
76
76
  it "creates a new repo" do
77
77
  expect {
78
- post "api/v1/users/#{user.id}/repos", repo: { name: 'new-gem' }
78
+ post "api/v1/users/#{user.id}/repos.json", repo: { name: 'new-gem' }
79
79
  expect(response).to be_success
80
80
  expect(JSON.parse(response.body)['user']).to eq JSON.parse(user.to_json)
81
81
  }.to change { Repo.count } .by(1)