vigia 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjZiMjEwOTE3OGMzMjM3NDFlMThmOTc3YTU5MjRjNTUwYjAxNGE2OQ==
4
+ MmE1ZDljN2M0MTU3NDI2NGE5ZTU2YjY4OTkyYWY1OTM4ZjgxMjQxOA==
5
5
  data.tar.gz: !binary |-
6
- ODQ1M2U3ZTZmODNiMjJhMGIwMGZmYTM0NzZiYzRjOGQ3Zjk2M2MyZA==
6
+ YTM0ZWFlYzYwNDBhODhjOGExZjUyZGY1MDkyYmY3Y2E0M2RiOWM5MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDYyYzJjZDYxNDFjNzdkOTQyN2MwY2Y3YjI2YzI0MDZiYTc0Y2U5NzljZmE4
10
- MjAwYTY1YzZmN2VkNDBlOWM0ODJkMGIzZTA4MjYwZTBjZmM1ZjI4ZjZjYjJl
11
- ZDk4NmMxZWQzOWZiMmZiNTJlYzNjZWIyODFhMzUzNzNjMGNiNzM=
9
+ YzU4YjhiZTgyNTMzZTU3ZDU2ZmJmMzFiNDQyY2M3MWQ1NjFhN2ExZjU5NWY5
10
+ MWM3N2ViNmRjMzM3MDAzMGVkODE2MWFiYTY0NTAwNWM0NGRiNTVlM2E2Yzll
11
+ ZGY3NzdhNTI2ZTgzOWQwMzE3ODA2MzkzOTQ1YzExMzdlMmYzM2E=
12
12
  data.tar.gz: !binary |-
13
- YWZmZGQ5NjJhN2ZkNTk2ZWM2YzhiOWMyMWQ0YWMyYjUwMjIxNTVkMzI2MTU0
14
- M2IxZWYzYzZmYjA1NTQzMTQ2YmE3ZGM0ZmNkZDI4ZmNiYzVkOTc2ODZmNWE3
15
- Njg0ZjcwZjkyYWZlZWM1NGRhYWJkMzBiMGM3OTUyMGYwNjYxNmI=
13
+ YmI2MTZlODQ1NjRmNGQ1YjdiYzFlOGFiOTI3OTE4Y2Y3ZDliZWU0OTZlZjEz
14
+ NWI1MGY0YzYyMDVkZmUwMGNkMDhiYjc4MDEwMGEwYTk4NDA0YWU2YmFiYThh
15
+ NDFlYTZjNzkxZmJlNmQxMzZkYzE3Y2FiZTI0M2Y1ZDExOWMyOWM=
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # RedSnow needs to download its git submodules before compiling
4
- gem 'redsnow', '>= 0.1.3', github: 'apiaryio/redsnow', submodules: true
4
+ gem 'redsnow', github: 'apiaryio/redsnow', submodules: true
5
5
  gem 'codeclimate-test-reporter', group: :test, require: nil
6
6
 
7
7
  gemspec
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Vigia
2
2
  ========
3
3
 
4
- [![Build Status](https://travis-ci.org/nogates/vigia.svg?branch=master)](https://travis-ci.org/nogates/vigia)
4
+ [![Build Status](https://travis-ci.org/lonelyplanet/vigia.svg?branch=master)](https://travis-ci.org/lonelyplanet/vigia)
5
5
  [![Code Climate](https://codeclimate.com/github/nogates/vigia/badges/gpa.svg)](https://codeclimate.com/github/nogates/vigia)
6
6
  [![Test Coverage](https://codeclimate.com/github/nogates/vigia/badges/coverage.svg)](https://codeclimate.com/github/nogates/vigia)
7
7
 
@@ -58,221 +58,3 @@ namespace :spec do
58
58
  end
59
59
  ```
60
60
 
61
- ## Configuration
62
-
63
- Vigia tries to be flexible enough in case that you need to run custom operations during the tests.
64
-
65
- ```ruby
66
-
67
- Vigia.configure do |config|
68
-
69
- # Define your source file. For example, within a Rails app
70
- config.source_file = "#{ Rails.root }/apibs/my_api.apib"
71
-
72
- # Define the host address where the request will be performed.
73
- config.host = 'http://localhost:3000'
74
-
75
- # Include a collection of custom headers in all the requests.
76
- config.headers = { authorization: 'Bearer <your hash here>' }
77
-
78
- # Reset rspec_config and set up documentation formatter
79
- config.rspec_config do |rspec_config|
80
- rspec_config.reset
81
- rspec_config.formatter = RSpec::Core::Formatters::DocumentationFormatter
82
- end
83
-
84
- # Attach a before_context hook to set up the database using Databasecleaner
85
- config.before_context do
86
- DatabaseCleaner.start
87
- end
88
-
89
- # Set a timer on the primary group and raise an exception if the
90
- # described group takes more than 5 seconds to run
91
- config.before_group do
92
- let!(:group_started_at) { Time.now } if described_class.options[:primary]
93
- end
94
-
95
- config.after_group do
96
- if described_class.options[:primary]
97
- it 'has taken less than 5 seconds to run this example' do
98
- expect(Time.now.to_i - group_started_at.to_i).to be < 5
99
- end
100
- end
101
- end
102
- end
103
-
104
- Vigia.rspec!
105
-
106
- ```
107
- For more information about config, see the `Vigia::Config` class.
108
-
109
- ## Adapters
110
-
111
- By default, Vigia uses `Vigia::Adapters::Blueprint` adapter. This adapter takes an Api Blueprint compatible file and parses it using [RedSnow](https://github.com/apiaryio/redsnow). Then, it builds up the test structure accordingly.
112
-
113
- If needed, Vigia can be configured to use a custom adapter. To do so, you just need to specify the adapter class inside the vigia configuration block:
114
-
115
- ```ruby
116
- Vigia.configure do |config|
117
- config.adapter = MyBlogAdapter
118
- end
119
- ```
120
-
121
- Then, insde your adapter class, you can use the `setup_adater` method to define the groups and contexts that the adapter will provide:
122
-
123
- ```ruby
124
-
125
- # Post
126
- class MyBlogAdapter < Vigia::Adapter
127
- setup_adapter do
128
- group :resource,
129
- primary: true,
130
- contexts: [ :default ]
131
- describes: [ :post, :pages ]
132
-
133
- context :default,
134
- http_client_options: {
135
- url: -> { "/#{ resource }" },
136
- method: :get
137
- },
138
- expectations: {
139
- code: 200,
140
- headers: {},
141
- body: -> { adapter.body_for(resource) }
142
- }
143
- end
144
-
145
- def body_for(resource)
146
- case resource
147
- when :post
148
- # Your post index expected body
149
- when :pages
150
- # Your pages index expected body
151
- else
152
- 'Unknown resource. WTH!'
153
- end
154
- end
155
- end
156
- ```
157
-
158
- When vigia starts, it fetchs the first group defined as primary. For each group, Vigia will loop on each element of the describes option (`:post, :page` in this example), and will set a rspec memoized object named as the group (`let(:resource) { :post }`). Then, it will run the children (if any) and the contexts in this group, setting up the `http_client_options` and `expectations` memoized objects per context.
159
-
160
- See `Vigia::Adapters::Blueprint` class for more information about configuring and setting up an adapter.
161
-
162
- ## Context Variables
163
-
164
- Vigia tries to be consistent with the way the RSpec are normally written. It creates the describe groups and context based on the adapter configuration and set up all the variables for the examples by using RSpec memoized objects.
165
-
166
- ```ruby
167
-
168
- # With an adapter `ExampleAdapter` with this config
169
- #
170
- # group :resource,
171
- # describes: [ :posts, :pages ],
172
- # children: [ :action ]
173
- #
174
- # group :action
175
- # describes: [ :get, :post ],
176
- # context: [ :default ]
177
- #
178
- # context :default,
179
- # http_client_options: {
180
- # method: -> { action.to_s.upcase }
181
- # url: -> { adapter.url_for(resource) }" }
182
- # headers: :headers
183
- # expectations:
184
- # code: :code
185
- # headers: {}
186
- # body: -> { Body.for(resource} }
187
- #
188
- # Vigia will generate this RSpec code
189
-
190
- describe Vigia::RSpec do
191
- let(:adapter) { ExampleAdapter.instance }
192
- let(:client) { Vigia.config.http_client_class.new(http_options) }
193
- let(:result) { client.run }
194
-
195
- # the loop starts...
196
- describe 'posts' do
197
- let(:resource) { :posts }
198
-
199
- describe 'action' do
200
- let(:action) { :get }
201
-
202
- context 'default' do
203
- let(:http_client_options) { Vigia::HttpClient::Options.new(context_options) }
204
- let(:expectations) { Vigia::HttpClient::ExpectedRequest.new(expectations) }
205
-
206
- # EXAMPLES RUN HERE!
207
- end
208
- # NEXT ACTION
209
- end
210
- # NEXT RESOURCE
211
- end
212
- end
213
- ```
214
-
215
- Also, It is important to mention that it is in this context where the adapter configuration will be executed. In the previous example, we configured the http_client option as follows:
216
-
217
- ```ruby
218
- # http_client_options: {
219
- # method: -> { action.to_s.upcase }
220
- # url: -> { adapter.url_for(resource) }" }
221
- # headers: :headers
222
- ```
223
-
224
- The option `method` is a lambda object. This object will be executed inside the RSpec memoized objects context. It is the same as doing:
225
-
226
- ```ruby
227
- # it has access to all context/group memoized objects
228
- let(:method) { action.to_s.upcase }
229
- ```
230
-
231
- You can also use the adapter like in option `url`, since it has been defined as a memoized object by Vigia::RSpec.
232
-
233
- Lastly, you can specify a symbol as the option value. In this case, the adapter will be the reciever of this method.
234
-
235
- ## Vigia Examples
236
-
237
- The first way to include examples on vigia is using `register`. Option `disabled_if` can be used to prevent the example for being executed on different situations. `contexts` limits the example to the listed contexts.
238
-
239
- ```ruby
240
-
241
- # On your config file, spec_helper, etc.
242
- Vigia::Sail::Example.register(
243
- :my_custom_body_validator,
244
- expectation: -> { expect { MyValidator(result.body) }.not.to raise_error } },
245
- contexts: [ :my_context ], # default: :default
246
- disable_if: -> { ! result.headers[:content_type].include?('my_validator_mime') }
247
- )
248
- ```
249
-
250
- ## Custom shared examples
251
-
252
- Vigia allows to include custom shared rspec examples in the test using some options in the config
253
-
254
- ```ruby
255
-
256
- Vigia.configure do |config|
257
- # Define where your examples are located
258
- config.custom_examples_paths = [ '/my_project/shared_examples/apib_examples.rb' ]
259
-
260
- # Define the custom examples you want to include in your test
261
-
262
- # To the example in all your requests use `:all` symbol
263
- config.add_custom_examples_on(:all, 'my custom examples')
264
- end
265
- ```
266
-
267
- Then, create your Rspec shared example and name the examples accordingly
268
-
269
- ```ruby
270
- # /my_project/shared_examples/apib_examples.rb
271
-
272
- shared_examples 'my custom examples' do
273
- it 'is a valid json response' do
274
- expect { JSON.parse(result.body) }.not_to raise_error
275
- end
276
- end
277
-
278
- ```
@@ -92,8 +92,22 @@ module Vigia
92
92
  end
93
93
  end
94
94
 
95
+ def find_action(url, method)
96
+ resources_by_url(url).map(&:actions).flatten.select do|action|
97
+ action && (method.nil? || action.method.downcase == method.to_s.downcase)
98
+ end.first
99
+ end
100
+
95
101
  private
96
102
 
103
+
104
+ def resources_by_url(url)
105
+ apib_resources.select do |resource|
106
+ path = URI.parse(url).path
107
+ Vigia::Url.template_defines_url?(resource.uri_template, path)
108
+ end
109
+ end
110
+
97
111
  def locate_in_sourcemap(key, object)
98
112
  node_index = apib_structure[key].index(object)
99
113
  source_node = apib_sourcemap[key][node_index]
@@ -132,6 +146,10 @@ module Vigia
132
146
  @apib_structure ||= build_structure(apib)
133
147
  end
134
148
 
149
+ def apib_resources
150
+ apib.resource_groups.map(&:resources).flatten
151
+ end
152
+
135
153
  def build_structure(start_point)
136
154
  {}.tap do |hash|
137
155
  hash[:resource_groups] = start_point.resource_groups
data/lib/vigia/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Vigia
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vigia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Tapiador
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-18 00:00:00.000000000 Z
12
+ date: 2015-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -189,25 +189,25 @@ extra_rdoc_files: []
189
189
  files:
190
190
  - Rakefile
191
191
  - Gemfile
192
+ - lib/vigia/adapter.rb
193
+ - lib/vigia/adapters/blueprint.rb
194
+ - lib/vigia/config.rb
195
+ - lib/vigia/formatter.rb
196
+ - lib/vigia/hooks.rb
197
+ - lib/vigia/http_client/options.rb
192
198
  - lib/vigia/http_client/requests.rb
193
199
  - lib/vigia/http_client/rest_client.rb
194
- - lib/vigia/http_client/options.rb
195
- - lib/vigia/spec/support/utils.rb
196
- - lib/vigia/spec/api_spec.rb
197
- - lib/vigia/adapters/blueprint.rb
198
200
  - lib/vigia/parameters.rb
199
- - lib/vigia/sail/group.rb
200
- - lib/vigia/sail/group_instance.rb
201
- - lib/vigia/sail/examples/default.rb
201
+ - lib/vigia/rspec.rb
202
202
  - lib/vigia/sail/context.rb
203
203
  - lib/vigia/sail/example.rb
204
+ - lib/vigia/sail/examples/default.rb
205
+ - lib/vigia/sail/group.rb
206
+ - lib/vigia/sail/group_instance.rb
204
207
  - lib/vigia/sail/rspec_object.rb
205
- - lib/vigia/adapter.rb
206
- - lib/vigia/config.rb
208
+ - lib/vigia/spec/api_spec.rb
209
+ - lib/vigia/spec/support/utils.rb
207
210
  - lib/vigia/url.rb
208
- - lib/vigia/formatter.rb
209
- - lib/vigia/hooks.rb
210
- - lib/vigia/rspec.rb
211
211
  - lib/vigia/version.rb
212
212
  - lib/vigia.rb
213
213
  - README.md