reqres_rspec 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 732124d70415e37926cd069f84f5493b4b175f92
4
- data.tar.gz: 6d01be1fa076e1009bd24492bf060a7172fdcae4
3
+ metadata.gz: 3ef47ab9f939487583f2efd322e173120d15c8ea
4
+ data.tar.gz: fd9555da5430109cfd9a8f13cdd1411f7c513274
5
5
  SHA512:
6
- metadata.gz: bf658e46d38571f9657967b2833d4afebf5cab7ae4b5b8d64c5ea4bf17af89afd862640696c1b7ae39d2a55cfd757a38b314c1b18f904a42012b90c59fdb549a
7
- data.tar.gz: d5f2e7b8763670a4549644fbfa4f0da0c97f02a0365382e84be3d7d99613c19680f0ee1560a1990de5ff1755715540d4a61c25fcc2da4e579ad9ae3df5db56a9
6
+ metadata.gz: 2cdaf34b43028cf6951c2851d452ec095de2c76a3f6c98488b4c4d6904817b045afc69f6862d43d3107d9fe2c69b3704765b0ba19577d5955cc083231900a191
7
+ data.tar.gz: 06e8a973c4d0dcc532e17e30f122ee14961070dc30432bad9fb9dd611b08ad3444d4ccd9da91368f14aa57c24be11f9e7be8e4de97961e58699ef5ab3065b85f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ version 0.1.8
2
+
3
+ cleanup code
4
+ fix regression with skipping spec examples
5
+ improve function to create symbolized path
6
+
1
7
  version 0.1.7
2
8
 
3
9
  symbolized path moved to request key in record
data/README.md CHANGED
@@ -69,6 +69,10 @@ Each param text is started with `@param` and first word will be param name, then
69
69
  ### Sample rspec test
70
70
 
71
71
  ```ruby
72
+ it 'validates params', :skip_reqres do
73
+ ...
74
+ end
75
+
72
76
  context 'With valid params' do
73
77
  it 'bakes pie' do
74
78
  ...
@@ -82,7 +86,7 @@ Each param text is started with `@param` and first word will be param name, then
82
86
  end
83
87
  ```
84
88
 
85
- By default all examples will be added to docs. A context of examples (`context` and `describe` blocks)may be excluded from docs with option `:skip_reqres`
89
+ By default all examples will be added to docs. A context of examples (`context` and `describe` blocks) or any particular examples may be excluded from docs with option `:skip_reqres`
86
90
 
87
91
  Doc will use full example description, as a title for each separate spec
88
92
 
@@ -94,6 +98,10 @@ describe 'Something', reqres_section: 'Foo' do
94
98
  it 'works' do
95
99
  ...
96
100
  end
101
+
102
+ it 'tires baker', reqres_title: 'Tires baker' do
103
+ ...
104
+ end
97
105
  end
98
106
  end
99
107
  ```
data/lib/reqres_rspec.rb CHANGED
@@ -14,12 +14,13 @@ if defined?(RSpec) && ENV['REQRES_RSPEC'] == '1'
14
14
  collector = ReqresRspec::Collector.new
15
15
 
16
16
  RSpec.configure do |config|
17
- config.after(:each) do
17
+ config.after(:each) do |example|
18
18
  if defined?(Rails)
19
19
  meta_data = self.class.example.metadata
20
- if meta_data[:type] == :request && !meta_data[:skip_reqres] == true
20
+
21
+ if meta_data[:type] == :request && process_example?(meta_data, example)
21
22
  begin
22
- collector.collect(self, self.request, self.response)
23
+ collector.collect(self, example, self.request, self.response)
23
24
  rescue NameError
24
25
  raise $!
25
26
  end
@@ -43,4 +44,8 @@ if defined?(RSpec) && ENV['REQRES_RSPEC'] == '1'
43
44
  end
44
45
  end
45
46
  end
47
+
48
+ def process_example?(meta_data, example)
49
+ !(meta_data[:skip_reqres] || example.metadata[:skip_reqres])
50
+ end
46
51
  end
@@ -8,11 +8,11 @@ module ReqresRspec
8
8
 
9
9
  # Param types
10
10
  # NOTE: make sure sub-strings go at the end
11
- PARAM_TYPES = ['Boolean', 'Text', 'Float', 'DateTime', 'Date', 'File', 'UUID',
11
+ PARAM_TYPES = ['Boolean', 'Text', 'Float', 'DateTime', 'Date', 'File', 'UUID', 'Hash',
12
12
  'Array of Integer', 'Array of String', 'Array', 'Integer', 'String']
13
13
 
14
14
  # Exclude replacement in symbolized path
15
- EXCLUDE_PATH_SYMBOLS = %w[limit offset format description]
15
+ EXCLUDE_PARAMS = %w[limit offset format description controller action]
16
16
 
17
17
  # response headers contain many unnecessary information,
18
18
  # everything from this list will be stripped
@@ -60,7 +60,7 @@ module ReqresRspec
60
60
  end
61
61
 
62
62
  # collects spec data for further processing
63
- def collect(spec, request, response)
63
+ def collect(spec, example, request, response)
64
64
  # TODO: remove boilerplate code
65
65
  return if request.nil? || response.nil? || !defined?(request.env)
66
66
 
@@ -85,7 +85,7 @@ module ReqresRspec
85
85
  self.records << {
86
86
  filename: prepare_filename_for(spec.class.metadata),
87
87
  group: spec.class.metadata[:reqres_section] || section, # Top level example group
88
- title: spec.class.metadata[:reqres_title] || spec.class.example.full_description,
88
+ title: example_title(spec, example),
89
89
  description: description,
90
90
  params: params,
91
91
  request: {
@@ -137,10 +137,17 @@ module ReqresRspec
137
137
 
138
138
  # sorts records alphabetically
139
139
  def sort
140
- self.records.sort!{ |x,y| x[:request][:symbolized_path] <=> y[:request][:symbolized_path] }
140
+ self.records.sort! do |x,y|
141
+ comp = x[:request][:symbolized_path] <=> y[:request][:symbolized_path]
142
+ comp.zero? ? (x[:title] <=> y[:title]) : comp
143
+ end
141
144
  end
142
145
 
143
- private
146
+ private
147
+
148
+ def example_title(spec, example)
149
+ spec.class.metadata[:reqres_title] || example.metadata[:reqres_title] || spec.class.example.full_description
150
+ end
144
151
 
145
152
  # read and cleanup response headers
146
153
  # returns Hash
@@ -188,20 +195,15 @@ module ReqresRspec
188
195
  #
189
196
  def get_symbolized_path(request)
190
197
  request_path = request.path
191
- request_params = request.env['action_dispatch.request.parameters'] ||
192
- request.env['rack.request.form_hash'] ||
193
- request.env['rack.request.query_hash']
194
-
195
- request_params.
196
- reject { |param| %w[controller action].include? param }.
197
- each do |key, value|
198
- if value.is_a? String
199
- index = request_path.index(value)
200
- if index && index >= 0 && !EXCLUDE_PATH_SYMBOLS.include?(key)
201
- request_path = request_path.sub(value, ":#{key}")
202
- end
203
- end
204
- end
198
+ request_params =
199
+ request.env['action_dispatch.request.parameters'] ||
200
+ request.env['rack.request.form_hash'] ||
201
+ request.env['rack.request.query_hash']
202
+
203
+ request_params
204
+ .except(*EXCLUDE_PARAMS)
205
+ .select { |_, value| value.is_a?(String) }
206
+ .each { |key, value| request_path.sub!("/#{value}", "/:#{key}") }
205
207
 
206
208
  request_path
207
209
  end
@@ -1,3 +1,3 @@
1
1
  module ReqresRspec
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reqres_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - rilian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-14 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderay