vigia 0.1.0 → 0.1.1

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
- NzQzNmJmYjk4OTkzYjZmZDc0ZGQ3N2I4MTZiYjUyYmZhOTNkODExZQ==
4
+ ZjQ5YmJhYmRiNjc0MDI2NzFjZThlOGJhN2E0MjIwNTVmOTFlMjA5MA==
5
5
  data.tar.gz: !binary |-
6
- ZDI3MTQ4ZWYxNDY5MjIzMjA2MGM3OWVkN2EwNzA0NDU0NDhjODY5MQ==
6
+ MDJiZDJlNDNiZDJlYjg2YjRmYjJhNTNlNzJlNWZhM2E2ODA2ZTRmZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGI4ZWY0MjAxZGM5YzRmYjdhYTE0MTc0NTg0NmRjZTI1ZTE3NDBjMWQ0YmE2
10
- YmZmY2FhMWJhZTkzMDQ5NDU5N2U5MmE0ODAwNjhhYzk5MWRjODVmNjI0NmM0
11
- NmY3ZDliMjRlNDMyOGJiZGJiMmU0NDhlNzRkNDJkMWFjMmQwYmY=
9
+ MThhNTJkMDU1NGNmMGYxOTU0Nzk2Yjg5NTdmMzU2NWE1NmU5NzE2YzQyYjY0
10
+ NGNlNDg2NTdlYTcwYjM4NDliNzU1YWJhODJkZGVhZTE2YjMxMGY4ZGE4YjFh
11
+ NDBhMGUxZjNiYzEyOTkxZDRjYzkwNTY2YzkwZDRmOTIwOTc0OTI=
12
12
  data.tar.gz: !binary |-
13
- MzdkMDE5NjMzYmI5MGJmODY3MWQ1YWQwMDRjZDhhOWIwNzAxMWUxODVmMzQ5
14
- M2ExMmVkMDI3Y2MwYzg2MWRiYWI3YTAyZDY2ZTFjMjliZTgyYmEyNmNlMmIy
15
- MTlhM2I2NTc4NzM5OTY2Yzc0ZGY5ZDUyNjk1YTQ4NjVmZGY2NTU=
13
+ Y2Y5ODNhYmI0MzBiNDRmNTFlNTg5MjlkNTQxNmNkZDcyYzg2ZTAzYzZmMzJi
14
+ ZDEzZmQ4N2RjNzUzOTlmM2E2NTU4YzI3ZDQwYmZhZjI4ZDZlMDkxNDhmNDY1
15
+ MTI0MGE3MmM5YmMwMTFjODJiNWRiYTIyYTA2NGZmN2ZlNzNhNTk=
data/README.md CHANGED
@@ -269,7 +269,7 @@ Then, create your Rspec shared example and name the examples accordingly
269
269
  ```ruby
270
270
  # /my_project/shared_examples/apib_examples.rb
271
271
 
272
- shared_examples 'my custom examples' do |vigia_example, response|
272
+ shared_examples 'my custom examples' do
273
273
  it 'is a valid json response' do
274
274
  expect { JSON.parse(result.body) }.not_to raise_error
275
275
  end
data/lib/vigia/adapter.rb CHANGED
@@ -43,8 +43,8 @@ module Vigia
43
43
  def preload
44
44
  instance_exec(&template)
45
45
 
46
- Vigia::Sail::Group.collection = groups
47
- Vigia::Sail::Context.collection = contexts
46
+ groups.each { |name, options| Vigia::Sail::Group.register(name, options) }
47
+ contexts.each { |name, options| Vigia::Sail::Context.register(name, options) }
48
48
  end
49
49
 
50
50
  def after_initialize(&block)
@@ -39,7 +39,7 @@ module Vigia
39
39
 
40
40
  context :default,
41
41
  http_client_options: {
42
- headers: -> { adapter.headers_for(resource, action, transactional_example, response) },
42
+ headers: -> { adapter.headers_for(action, transactional_example, response) },
43
43
  method: -> { action.method },
44
44
  uri_template: -> { resource.uri_template },
45
45
  parameters: -> { adapter.parameters_for(resource, action) },
@@ -47,13 +47,13 @@ module Vigia
47
47
  },
48
48
  expectations: {
49
49
  code: -> { response.name.to_i },
50
- headers: -> { adapter.headers_for(resource, action, transactional_example, response, include_payload = false) },
50
+ headers: -> { adapter.headers_for(action, transactional_example, response, include_payload = false) },
51
51
  body: -> { response.body }
52
52
  }
53
53
  end
54
54
 
55
- def headers_for(resource, action, transactional_example, response, include_payload = true)
56
- headers = headers_for_response(resource, response)
55
+ def headers_for(action, transactional_example, response, include_payload = true)
56
+ headers = headers_for_response(response)
57
57
  headers += headers_for_payload(transactional_example, response) if with_payload?(action) && include_payload
58
58
  compile_headers(headers)
59
59
  end
@@ -82,13 +82,17 @@ module Vigia
82
82
  end
83
83
  end
84
84
 
85
- def headers_for_response(resource, response)
85
+ def headers_for_response(response)
86
86
  collection = []
87
- collection << [*resource.model.headers.collection]
88
87
  collection << [*response.headers.collection]
89
88
  collection.flatten
90
89
  end
91
90
 
91
+ # def resources
92
+ # apib.resource_groups.map(&:resources).flatten
93
+ # end
94
+
95
+
92
96
  def headers_for_payload(transactional_example, response)
93
97
  payload = get_payload(transactional_example, response)
94
98
  [ *payload.headers.collection ].flatten
data/lib/vigia/config.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  module Vigia
2
2
  class Config
3
3
  attr_accessor :source_file, :host, :custom_examples_paths, :custom_examples, :headers, :http_client_class
4
- attr_accessor :adapter, :hooks, :rspec_config_block, :stderr, :stdout
4
+ attr_accessor :adapter, :hooks, :rspec_config_block, :stderr, :stdout, :internal_hosts
5
5
 
6
6
  def initialize
7
7
  @host = nil
8
8
  @source_file = nil
9
9
  @rspec_config_block = nil
10
+ @internal_hosts = []
10
11
  @headers = {}
11
12
  @custom_examples_paths = []
12
13
  @custom_examples = []
@@ -42,6 +43,10 @@ module Vigia
42
43
  store_hook(Vigia::Sail::GroupInstance, :after, block)
43
44
  end
44
45
 
46
+ def extend_group(&block)
47
+ store_hook(Vigia::Sail::GroupInstance, :extend, block)
48
+ end
49
+
45
50
  def before_context(&block)
46
51
  store_hook(Vigia::Sail::Context, :before, block)
47
52
  end
@@ -50,6 +55,10 @@ module Vigia
50
55
  store_hook(Vigia::Sail::Context, :after, block)
51
56
  end
52
57
 
58
+ def extend_context(&block)
59
+ store_hook(Vigia::Sail::Context, :extend, block)
60
+ end
61
+
53
62
  def store_hook(rspec_class, filter, block)
54
63
  @hooks << { rspec_class: rspec_class, filter: filter, block: block }
55
64
  end
@@ -0,0 +1,46 @@
1
+ module Vigia
2
+ module Hooks
3
+
4
+ def execute_hook(filter_name, rspec_context)
5
+ hooks_for_object(filter_name).each do |hook|
6
+ rspec_context.instance_exec(&hook)
7
+ end
8
+ end
9
+
10
+ def hooks_for_object(filter_name)
11
+ config_hooks(filter_name) + object_hooks(filter_name)
12
+ end
13
+
14
+ def with_hooks(rspec_context)
15
+ instance = self
16
+
17
+ rspec_context.before(:context) do
18
+ instance.execute_hook(:before, self)
19
+ end
20
+
21
+ rspec_context.after(:context) do
22
+ instance.execute_hook(:after, self)
23
+ end
24
+
25
+ instance.execute_hook(:extend, rspec_context)
26
+
27
+ yield
28
+ end
29
+
30
+ private
31
+
32
+ def object_hooks(filter_name)
33
+ return [] unless respond_to?(:options)
34
+ option_name = "#{ filter_name }_#{ self.class.name.split('::').last.downcase }".to_sym
35
+ [ *options[option_name] ].compact
36
+
37
+ end
38
+
39
+ def config_hooks(filter_name)
40
+ Vigia.config.hooks.each_with_object([]) do |hook, collection|
41
+ next unless self.is_a?(hook[:rspec_class]) and filter_name == hook[:filter]
42
+ collection << hook[:block]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -22,9 +22,10 @@ module Vigia
22
22
  instance = self
23
23
  rspec.it instance do
24
24
  skip if instance.skip?(self) || (respond_to?(:skip?) and send(:skip?))
25
- skip('__vigia__') if instance.disabled?(self) || (respond_to?(:disabled?) and send(:disabled?))
26
25
 
27
- instance_exec(&instance.expectation)
26
+ unless instance.disabled?(self) || (respond_to?(:disabled?) and send(:disabled?))
27
+ instance_exec(&instance.expectation)
28
+ end
28
29
  end
29
30
  end
30
31
 
@@ -50,16 +51,3 @@ module Vigia
50
51
  end
51
52
  end
52
53
  end
53
-
54
-
55
- Vigia::Sail::Example.register(
56
- :code_match,
57
- description: 'has the expected HTTP code',
58
- expectation: -> { expect(result.code).to be(expectations.code) }
59
- )
60
-
61
- Vigia::Sail::Example.register(
62
- :include_headers,
63
- description: 'includes the expected headers',
64
- expectation: -> { expect(result[:headers]).to include(expectations[:headers]) }
65
- )
@@ -0,0 +1,11 @@
1
+ Vigia::Sail::Example.register(
2
+ :code_match,
3
+ description: 'has the expected HTTP code',
4
+ expectation: -> { expect(result.code).to be(expectations.code) }
5
+ )
6
+
7
+ Vigia::Sail::Example.register(
8
+ :include_headers,
9
+ description: 'includes the expected headers',
10
+ expectation: -> { expect(result[:headers]).to include(expectations[:headers]) }
11
+ )
@@ -2,7 +2,12 @@ module Vigia
2
2
  module Sail
3
3
  class RSpecObject
4
4
  class << self
5
- attr_accessor :collection
5
+ attr_reader :collection
6
+
7
+ def register(name, options)
8
+ @collection = {} if collection.nil?
9
+ @collection.merge!(name => options)
10
+ end
6
11
 
7
12
  def setup_and_run(name, rspec)
8
13
  name, options = collection.select{ |k,v| k == name }.first
@@ -11,6 +16,8 @@ module Vigia
11
16
  end
12
17
  end
13
18
 
19
+ include Vigia::Hooks
20
+
14
21
  attr_reader :name, :options, :rspec
15
22
 
16
23
  def initialize(name, options, rspec)
@@ -20,22 +27,6 @@ module Vigia
20
27
 
21
28
  end
22
29
 
23
- def execute_hook(filter_name, rspec_context)
24
- hooks_for_object(filter_name).each do |hook|
25
- rspec_context.instance_exec(&hook)
26
- end
27
- end
28
-
29
- def hooks_for_object(filter_name)
30
- config_hooks(filter_name) + object_hooks(filter_name)
31
- end
32
-
33
- def with_hooks(rspec_context)
34
- execute_hook(:before, rspec_context)
35
- yield
36
- execute_hook(:after, rspec_context)
37
- end
38
-
39
30
  def contextual_object(option_name: nil, object: nil, context: nil)
40
31
  context ||= rspec.described_class
41
32
  object ||= options[option_name]
@@ -55,19 +46,6 @@ module Vigia
55
46
  return block if block.respond_to?(:call)
56
47
  raise error_message
57
48
  end
58
-
59
- def object_hooks(filter_name)
60
- option_name = "#{ filter_name }_#{ self.class.name.split('::').last.downcase }".to_sym
61
- [ *options[option_name] ].compact
62
-
63
- end
64
-
65
- def config_hooks(filter_name)
66
- Vigia.config.hooks.each_with_object([]) do |hook, collection|
67
- next unless self.is_a?(hook[:rspec_class]) and filter_name == hook[:filter]
68
- collection << hook[:block]
69
- end
70
- end
71
49
  end
72
50
  end
73
51
  end
data/lib/vigia/url.rb CHANGED
@@ -1,7 +1,19 @@
1
1
  require 'uri'
2
+ require 'addressable/template'
3
+ require 'addressable/uri'
4
+
2
5
 
3
6
  module Vigia
4
7
  class Url
8
+ class << self
9
+ def template_defines_url?(template, url)
10
+ url_object = Addressable::URI.parse(url)
11
+ template_object = Addressable::Template.new(template)
12
+ url_parameters = template_object.extract(url_object) || {}
13
+ # recreate url and see if matches
14
+ template_object.expand(url_parameters) == url_object
15
+ end
16
+ end
5
17
 
6
18
  attr_reader :uri_template
7
19
 
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.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/vigia.rb CHANGED
@@ -8,6 +8,7 @@ require 'addressable/template'
8
8
  require_relative 'vigia/adapter'
9
9
  require_relative 'vigia/adapters/blueprint'
10
10
  require_relative 'vigia/config'
11
+ require_relative 'vigia/hooks'
11
12
  require_relative 'vigia/http_client/options'
12
13
  require_relative 'vigia/http_client/rest_client'
13
14
  require_relative 'vigia/http_client/requests'
@@ -39,3 +40,5 @@ module Vigia
39
40
  end
40
41
  end
41
42
  end
43
+
44
+ require_relative 'vigia/sail/examples/default'
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.0
4
+ version: 0.1.1
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-03 00:00:00.000000000 Z
12
+ date: 2014-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -190,22 +190,24 @@ files:
190
190
  - Rakefile
191
191
  - Gemfile
192
192
  - lib/vigia/http_client/requests.rb
193
- - lib/vigia/http_client/options.rb
194
193
  - lib/vigia/http_client/rest_client.rb
194
+ - lib/vigia/http_client/options.rb
195
195
  - lib/vigia/spec/support/utils.rb
196
196
  - lib/vigia/spec/api_spec.rb
197
- - lib/vigia/version.rb
197
+ - lib/vigia/rspec.rb
198
198
  - lib/vigia/adapters/blueprint.rb
199
199
  - lib/vigia/parameters.rb
200
200
  - lib/vigia/sail/group.rb
201
201
  - lib/vigia/sail/group_instance.rb
202
+ - lib/vigia/sail/context.rb
202
203
  - lib/vigia/sail/example.rb
204
+ - lib/vigia/sail/examples/default.rb
203
205
  - lib/vigia/sail/rspec_object.rb
204
- - lib/vigia/sail/context.rb
205
- - lib/vigia/url.rb
206
206
  - lib/vigia/adapter.rb
207
207
  - lib/vigia/config.rb
208
- - lib/vigia/rspec.rb
208
+ - lib/vigia/hooks.rb
209
+ - lib/vigia/url.rb
210
+ - lib/vigia/version.rb
209
211
  - lib/vigia.rb
210
212
  - README.md
211
213
  homepage: https://github.com/nogates/vigia