lurker 0.5.6 → 0.5.7

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.
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
metadata.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ UIT�� LUn�Һ�����
2
+ �E2��Ƒ��8�5�"h��3�Di�'�I�|3�K�>�f�3�����k��E��J���r;>��L���%gB�sg2�=&l
3
+ �)�G��$3�S���;��.�~ �@A��WM�Jh��o,�l���:�z
checksums.yaml.gz.asc DELETED
@@ -1,12 +0,0 @@
1
- -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG v1
3
- Comment: GPGTools - http://gpgtools.org
4
-
5
- iQEcBAABCgAGBQJTccHbAAoJENcoxKfNVdjb6/IH/R1XMxCti1sKez8IUMA4eY2d
6
- u9QxT+0Z4lEkGNPs1ycqngH7fMnrN1qYnRK6KW+8HJAteUECdEOZ1qaQSpRXBC+c
7
- ugXow6Kei6TIO4432/AjApk00mDCsv3YosNMUOj6lXyt8K3GCh8PNt8L1bPhk3CV
8
- 6/mDw33hv9rKU0mCvzursiOxHpEsSQZ8lgi8O6q9YwouyHtEsrVMNEJPYIgU20sX
9
- TUmNSxBFwX0/1orF64egekpT5zxcHUB8BRz4VsVD50evtYCBqLAaMZLZIf6J8rQM
10
- cnHqMV2tS4SBKr4Tq7YKItTWGafIK3F1F6jeIgrzxWjNpVxt/wC0lCw9NHm+2Nc=
11
- =dHhQ
12
- -----END PGP SIGNATURE-----
data.tar.gz.asc DELETED
@@ -1,12 +0,0 @@
1
- -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG v1
3
- Comment: GPGTools - http://gpgtools.org
4
-
5
- iQEcBAABCgAGBQJTccHYAAoJENcoxKfNVdjbFuAIANv5LvoJolrzbd5jBPqb/u4u
6
- PqveFsfu/9//EVq9sB+vZQ1av7Hrn7OYXkibhmvrvHwqO9l8Ve3/V0dQeAztk9qK
7
- Xf9hA8hUBbP7uqbbhm+SfvL3I0oVE9nFYdG+eP853v2XqwNHcJSNb4D6vXWah1XU
8
- 6jiUSkaUZH2appqQRZfA5xLM9E+ZMq9iRktUWkKXSWUeRKOdizNSs+HtbCTiblqy
9
- IWwpSR2yJAg4/fHAC25X7DoOSCs6ENfl2ZuhOIISLykZHsT17ni22dqdCMnUDDl6
10
- YWsQcygfxDezC9WiIGrEJJwYv1KelMvGszHWyyqOT5R/v219KN4XjTdTuYLeNL8=
11
- =lqHA
12
- -----END PGP SIGNATURE-----
@@ -1,70 +0,0 @@
1
- require 'json'
2
- require 'lurker'
3
-
4
- module Lurker
5
- module ControllerSpecWatcher
6
- extend ActiveSupport::Concern
7
- include SpecWatcher
8
-
9
- included do
10
- # _describe = self # RSpec::ExampleGroups::... # class
11
- actions = [:get, :post, :put, :delete, :patch]
12
- actions.each do |verb|
13
- send(:define_method, "#{verb}_with_lurker") do |*params|
14
- @__action, @__request_params = params
15
- @__request_params ||= {}
16
-
17
- send("#{verb}_without_lurker", @__action, @__request_params)
18
-
19
- @__query_params = Hash[@__request_params.reject { |k,_| path_params.keys.include? k } .map do |k,v|
20
- [k.to_s, v.to_s]
21
- end]
22
- endpoint_path = explicit_path(@__example)
23
-
24
- return if endpoint_path.nil? # not lurker
25
-
26
- if inside_rails_controller_spec?
27
- if endpoint_path == true
28
- endpoint_path = path_regexp
29
- elsif endpoint_path.to_s.match(/^[^\/]/)
30
- endpoint_path = "#{path_regexp}-#{endpoint_path.gsub(/[^[[:alnum:]]]/, '_')}"
31
- end
32
- end
33
-
34
- if endpoint_path.blank?
35
- raise Lurker::ValidationError.new(<<-MSG.gsub(/^ {14}/, '')
36
- cannot determine path for .lurker, please, do it explicitly:
37
- it "tests", lurker: 'some-lurker-file-suffix' do
38
- ...
39
- end
40
- MSG
41
- )
42
- end
43
-
44
- verify(verb, endpoint_path)
45
- end
46
-
47
- begin
48
- send :alias_method_chain, verb, :lurker
49
- rescue NameError
50
- if verb == :patch
51
- alias_method :patch_without_lurker, :put_without_lurker
52
- alias_method :patch, :patch_with_lurker
53
- else
54
- raise
55
- end
56
- end
57
- end
58
-
59
- around do |example|
60
- wrapper(example)
61
- end
62
- end
63
- end
64
- end
65
-
66
- if defined?(RSpec)
67
- RSpec.configure do |config|
68
- config.include Lurker::ControllerSpecWatcher, type: :controller
69
- end
70
- end
@@ -1,80 +0,0 @@
1
- require 'json'
2
- require 'lurker'
3
-
4
- module Lurker
5
- module RequestSpecWatcher
6
- extend ActiveSupport::Concern
7
- include SpecWatcher
8
-
9
- included do
10
- # _describe = self # RSpec::ExampleGroups::... # class
11
- actions = [:get, :post, :put, :delete, :patch]
12
- actions.each do |verb|
13
- send(:define_method, "#{verb}_with_lurker") do |*params|
14
- @__action, @__request_params, @__env = params
15
-
16
- @__request_params ||= {}
17
- @__query_params ||= {}
18
- @__env ||= {}
19
-
20
- if @__action.is_a?(Symbol)
21
- unless @__example.metadata.described_class.is_a?(Class)
22
- raise 'cannot determine request url: provide proper described class like: "describe MyController do"'
23
- end
24
- controller_name = @__example.metadata.described_class.name.tableize.gsub(/_controllers$/, '')
25
- @__action = URI.parse(url_for({ controller: controller_name, action: @__action }.merge(@__request_params))).path
26
- end
27
-
28
- @__query_params.merge! ::Rack::Utils.parse_query URI.parse(@__action).query
29
-
30
- send("#{verb}_without_lurker", @__action, @__request_params, @__env)
31
-
32
- endpoint_path = explicit_path(@__example)
33
-
34
- return if endpoint_path.nil? # not lurker
35
-
36
- if inside_rails_controller_spec?
37
- if endpoint_path == true
38
- endpoint_path = path_regexp
39
- elsif endpoint_path.to_s.match(/^[^\/]/)
40
- endpoint_path = "#{path_regexp}-#{endpoint_path.gsub(/[^[[:alnum:]]]/, '_')}"
41
- end
42
- end
43
-
44
- if endpoint_path.blank?
45
- raise Lurker::ValidationError.new(<<-MSG.gsub(/^ {14}/, '')
46
- cannot determine path for .lurker, please, do it explicitly:
47
- it "tests", lurker: 'some-lurker-file-suffix' do
48
- ...
49
- end
50
- MSG
51
- )
52
- end
53
-
54
- verify(verb, endpoint_path)
55
- end
56
-
57
- begin
58
- send :alias_method_chain, verb, :lurker
59
- rescue NameError
60
- if verb == :patch
61
- alias_method :patch_without_lurker, :put_without_lurker
62
- alias_method :patch, :patch_with_lurker
63
- else
64
- raise
65
- end
66
- end
67
- end
68
-
69
- around do |example|
70
- wrapper(example)
71
- end
72
- end
73
- end
74
- end
75
-
76
- if defined?(RSpec)
77
- RSpec.configure do |config|
78
- config.include Lurker::RequestSpecWatcher, type: :request
79
- end
80
- end
@@ -1,124 +0,0 @@
1
- module Lurker
2
- module SpecWatcher
3
- extend ActiveSupport::Concern
4
-
5
- private
6
-
7
- def wrapper(example)
8
- # _it = self # RSpec::ExampleGroups::... # instance
9
- @__example = example
10
- @__lurker_service = if defined?(Rails)
11
- Lurker::Service.new(Rails.root.join(Lurker::DEFAULT_SERVICE_PATH).to_s, Rails.application.class.parent_name)
12
- else
13
- Lurker::Service.default_service
14
- end
15
-
16
- example.run.tap do |result|
17
- unless result.is_a? Exception
18
- @__lurker_service.persist! #rescue nil
19
- end
20
- end
21
- end
22
-
23
- def verify(verb, endpoint_path)
24
- if successful = Lurker.decide_success(response_params, real_response.status)
25
- @__request_params.stringify_keys! # FIXME
26
- @__lurker_service.verify!(
27
- verb, endpoint_path, extensions.merge(path_params: path_params),
28
- parsed_request_params(@__request_params), response_params,
29
- real_response.status, successful
30
- )
31
- end
32
- end
33
-
34
- def extensions
35
- @extensions = {
36
- path_info: request.env['PATH_INFO'],
37
- method: request.env['REQUEST_METHOD'],
38
- suffix: ''
39
- }
40
- if (suffix = explicit_path(@__example)).is_a?(String)
41
- @extensions[:suffix] = suffix.gsub(/[^[[:alnum:]]]/, '_')
42
- end
43
- if @__query_params.present?
44
- @extensions[:query_params] = @__query_params
45
- end
46
- @extensions
47
- end
48
-
49
- def path_regexp
50
- @__path_regexp ||= current_route_params.first.try(:path).try(:spec).to_s.sub('(.:format)', '')
51
- end
52
-
53
- def path_params
54
- @__path_params ||= current_route_params.last || {}
55
- end
56
-
57
- # ActionDispatch::Journey::Route || nil
58
- def current_route_params
59
- return [@__current_route, @__path_params] if @__current_route && @__path_params
60
- router.recognize(request) do |route, _, parameters|
61
- return [@__current_route = route, @__path_params = parameters]
62
- end
63
- [] # never?
64
- end
65
-
66
- # ActionDispatch::Journey::Router
67
- def router
68
- Rails.application.routes.router
69
- end
70
-
71
- def parsed_request_params request_params
72
- if request_params.kind_of?(Hash)
73
- request_params
74
- else
75
- begin
76
- JSON.parse(request_params)
77
- rescue
78
- {}
79
- end
80
- end
81
- end
82
-
83
- def explicit_path(_example=nil)
84
- if _example && _example.respond_to?(:metadata)
85
- _example.metadata[:lurker]
86
- elsif defined?(::RSpec) && ::RSpec.respond_to?(:current_example) # Rspec 3
87
- ::RSpec.current_example.metadata[:lurker]
88
- elsif respond_to?(:example) # Rspec 2
89
- example.metadata[:lurker]
90
- else # Rspec 1.3.2
91
- opts = {}
92
- __send__(:example_group_hierarchy).each do |example|
93
- opts.merge!(example.options)
94
- end
95
- opts.merge!(options)
96
- opts[:lurker]
97
- end
98
- end
99
-
100
- def inside_rails_controller_spec?
101
- defined?(ActionController::Base) && respond_to?(:controller) && controller.is_a?(ActionController::Base)
102
- end
103
-
104
- def real_response
105
- if respond_to? :response
106
- # we are on rails
107
- response
108
- else
109
- # we are on sinatra
110
- last_response
111
- end
112
- end
113
-
114
- def response_params
115
- begin
116
- JSON.parse(real_response.body)
117
- rescue
118
- {}
119
- end
120
- end
121
- end
122
- end
123
- require 'lurker/controller_spec_watcher'
124
- require 'lurker/request_spec_watcher'
metadata.gz.asc DELETED
@@ -1,12 +0,0 @@
1
- -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG v1
3
- Comment: GPGTools - http://gpgtools.org
4
-
5
- iQEcBAABCgAGBQJTccHSAAoJENcoxKfNVdjbi5EIALmXJQep/uEQJRyXv+ALjEk8
6
- kkMWaIplQ4eTug39IbYdfRGjf5PstX7kAC3qXCg127FJ2qoLUqajfoN3rFfP/nsC
7
- CNQqiTED5jew812Dcg7A7EYghiiwg0wU1zQirI22uBur2em9fCwdz4lIYguWGYFW
8
- 07EeFA80NiW+fKAG9dILZzZCCNzUFrutNoMiDiLuPXc47bAX8uK4+6M+L6R/r4vx
9
- qgFY3Pt0BII2rcXo0RG+iVfN10qaGXw1qpkv7x0xdSGAnL+Ly7WjFeri05UdyJl2
10
- cOSfW3LojNurm/yrB4w6kA9mB8Z0FM0tRU6wN1Jaab1SAR4UsfcizOgw0CNbukI=
11
- =ax3i
12
- -----END PGP SIGNATURE-----