vigia 0.1.1 → 0.1.2
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 +8 -8
- data/Rakefile +6 -2
- data/lib/vigia/adapters/blueprint.rb +54 -5
- data/lib/vigia/formatter.rb +113 -0
- data/lib/vigia/hooks.rb +5 -0
- data/lib/vigia/http_client/options.rb +1 -0
- data/lib/vigia/rspec.rb +3 -4
- data/lib/vigia/sail/context.rb +36 -11
- data/lib/vigia/sail/example.rb +3 -2
- data/lib/vigia/sail/examples/default.rb +16 -10
- data/lib/vigia/sail/rspec_object.rb +4 -2
- data/lib/vigia/version.rb +1 -1
- data/lib/vigia.rb +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjZiMjEwOTE3OGMzMjM3NDFlMThmOTc3YTU5MjRjNTUwYjAxNGE2OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODQ1M2U3ZTZmODNiMjJhMGIwMGZmYTM0NzZiYzRjOGQ3Zjk2M2MyZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDYyYzJjZDYxNDFjNzdkOTQyN2MwY2Y3YjI2YzI0MDZiYTc0Y2U5NzljZmE4
|
10
|
+
MjAwYTY1YzZmN2VkNDBlOWM0ODJkMGIzZTA4MjYwZTBjZmM1ZjI4ZjZjYjJl
|
11
|
+
ZDk4NmMxZWQzOWZiMmZiNTJlYzNjZWIyODFhMzUzNzNjMGNiNzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWZmZGQ5NjJhN2ZkNTk2ZWM2YzhiOWMyMWQ0YWMyYjUwMjIxNTVkMzI2MTU0
|
14
|
+
M2IxZWYzYzZmYjA1NTQzMTQ2YmE3ZGM0ZmNkZDI4ZmNiYzVkOTc2ODZmNWE3
|
15
|
+
Njg0ZjcwZjkyYWZlZWM1NGRhYWJkMzBiMGM3OTUyMGYwNjYxNmI=
|
data/Rakefile
CHANGED
@@ -14,5 +14,9 @@ task :clobber do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Not sure why simplecov is preventing cucumber for being run after spec
|
17
|
-
# when running rake default
|
18
|
-
task :default
|
17
|
+
# when running rake default. That is why I am using commands to execute them
|
18
|
+
task :default do
|
19
|
+
raise 'Cucumber Failed' unless system('bundle exec rake cucumber')
|
20
|
+
raise 'RSpec Failed' unless system('bundle exec rake spec')
|
21
|
+
end
|
22
|
+
|
@@ -2,12 +2,13 @@ module Vigia
|
|
2
2
|
module Adapters
|
3
3
|
class Blueprint < Vigia::Adapter
|
4
4
|
|
5
|
-
attr_reader :apib
|
5
|
+
attr_reader :apib, :apib_source
|
6
6
|
|
7
7
|
setup_adapter do
|
8
8
|
|
9
9
|
after_initialize do
|
10
|
-
@
|
10
|
+
@apib_source = File.read(source_file)
|
11
|
+
@apib_parsed = RedSnow::parse(@apib_source, { :exportSourcemap => true })
|
11
12
|
@apib = @apib_parsed.ast
|
12
13
|
end
|
13
14
|
|
@@ -73,8 +74,43 @@ module Vigia
|
|
73
74
|
payload.body
|
74
75
|
end
|
75
76
|
|
77
|
+
def inspector object
|
78
|
+
case object
|
79
|
+
when RedSnow::ResourceGroup
|
80
|
+
locate_in_sourcemap(:resource_groups, object)
|
81
|
+
when RedSnow::Resource
|
82
|
+
locate_in_sourcemap(:resources, object)
|
83
|
+
when RedSnow::Action
|
84
|
+
locate_in_sourcemap(:actions, object)
|
85
|
+
when RedSnow::TransactionExample
|
86
|
+
first_response = object.responses.first
|
87
|
+
locate_in_sourcemap(:responses, first_response)
|
88
|
+
when RedSnow::Payload
|
89
|
+
locate_in_sourcemap(:responses, object)
|
90
|
+
else
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
76
95
|
private
|
77
96
|
|
97
|
+
def locate_in_sourcemap(key, object)
|
98
|
+
node_index = apib_structure[key].index(object)
|
99
|
+
source_node = apib_sourcemap[key][node_index]
|
100
|
+
character = source_node.name.first.first
|
101
|
+
|
102
|
+
{ line: return_line_number_at_character_count(character) }
|
103
|
+
end
|
104
|
+
|
105
|
+
def return_line_number_at_character_count(number)
|
106
|
+
total_chars = 0
|
107
|
+
@apib_source.lines.each_with_index do |line, index|
|
108
|
+
total_chars += line.length
|
109
|
+
next if total_chars < number
|
110
|
+
return index + 2
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
78
114
|
def compile_headers(headers)
|
79
115
|
headers.inject({}) do |hash, header|
|
80
116
|
normalize_header_name = header[:name].gsub('-', '_').downcase.to_sym
|
@@ -88,10 +124,23 @@ module Vigia
|
|
88
124
|
collection.flatten
|
89
125
|
end
|
90
126
|
|
91
|
-
|
92
|
-
|
93
|
-
|
127
|
+
def apib_sourcemap
|
128
|
+
@apib_sourcemap ||= build_structure(@apib_parsed.sourcemap)
|
129
|
+
end
|
94
130
|
|
131
|
+
def apib_structure
|
132
|
+
@apib_structure ||= build_structure(apib)
|
133
|
+
end
|
134
|
+
|
135
|
+
def build_structure(start_point)
|
136
|
+
{}.tap do |hash|
|
137
|
+
hash[:resource_groups] = start_point.resource_groups
|
138
|
+
hash[:resources] = hash[:resource_groups].map(&:resources).flatten
|
139
|
+
hash[:actions] = hash[:resources].map(&:actions).flatten
|
140
|
+
hash[:examples] = hash[:actions].map(&:examples).flatten
|
141
|
+
hash[:responses] = hash[:examples].map(&:responses).flatten
|
142
|
+
end
|
143
|
+
end
|
95
144
|
|
96
145
|
def headers_for_payload(transactional_example, response)
|
97
146
|
payload = get_payload(transactional_example, response)
|
@@ -0,0 +1,113 @@
|
|
1
|
+
RSpec::Support.require_rspec_core 'formatters/base_text_formatter'
|
2
|
+
|
3
|
+
module Vigia
|
4
|
+
class Formatter < RSpec::Core::Formatters::BaseTextFormatter
|
5
|
+
|
6
|
+
include RSpec::Core::Formatters::ConsoleCodes
|
7
|
+
|
8
|
+
RSpec::Core::Formatters.register self, :start, :example_group_started, :example_group_finished,
|
9
|
+
:example_pending, :example_passed, :example_failed
|
10
|
+
|
11
|
+
def initialize(output)
|
12
|
+
super
|
13
|
+
@example_collection = {}
|
14
|
+
@group_level = 0
|
15
|
+
@verbose = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def start(start_notification)
|
19
|
+
output.puts 'Starting Vigia::RSpec'
|
20
|
+
end
|
21
|
+
|
22
|
+
def example_group_started(example_group_notification)
|
23
|
+
@group_level += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
def example_group_finished(example_group_notification)
|
27
|
+
@group_level -= 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def example_pending(example_notification)
|
31
|
+
output_example_result(example_notification, :pending)
|
32
|
+
end
|
33
|
+
|
34
|
+
def example_passed(example_notification)
|
35
|
+
output_example_result(example_notification, :success)
|
36
|
+
end
|
37
|
+
|
38
|
+
def example_failed(failed_example_notification)
|
39
|
+
output_example_result(failed_example_notification, :failed)
|
40
|
+
end
|
41
|
+
|
42
|
+
def dump_failures(examples_notification)
|
43
|
+
@examples_notification = examples_notification
|
44
|
+
print_context_failures
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def print_context_failures
|
50
|
+
examples_by_context.each do |context, examples|
|
51
|
+
print_context_failure(context, examples)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def examples_by_context
|
56
|
+
@examples_notification.failed_examples.each_with_object({}) do |example, hash|
|
57
|
+
context = example.metadata[:example_group]
|
58
|
+
hash[context] ||= []
|
59
|
+
hash[context] << example
|
60
|
+
hash
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def print_context_failure(context, examples)
|
65
|
+
output.puts(''.tap do |string|
|
66
|
+
string << context_failure_title(context)
|
67
|
+
string << context_failure_examples(context, examples)
|
68
|
+
string << context_parents(context)
|
69
|
+
end)
|
70
|
+
end
|
71
|
+
|
72
|
+
def context_parents(context)
|
73
|
+
"\nGroups:\n#{ context_parent(context[:parent_example_group], '') }"
|
74
|
+
end
|
75
|
+
|
76
|
+
def context_parent(context, string)
|
77
|
+
unless context[:described_class] == context[:parent_example_group][:described_class]
|
78
|
+
string << " - #{ context[:described_class].group.name } #{ context[:described_class].to_s }"
|
79
|
+
if Vigia::Rspec.adapter.respond_to?(:inspector)
|
80
|
+
info = Vigia::Rspec.adapter.inspector(context[:described_class].described_object)
|
81
|
+
string << wrap(" # #{ Vigia.config.source_file }:#{ info[:line] }", :cyan)
|
82
|
+
end
|
83
|
+
string << "\n"
|
84
|
+
end
|
85
|
+
unless context[:parent_example_group][:described_class] == Vigia::Rspec
|
86
|
+
string = context_parent(context[:parent_example_group], string)
|
87
|
+
end
|
88
|
+
string
|
89
|
+
end
|
90
|
+
|
91
|
+
def context_failure_title(context)
|
92
|
+
wrap("\nContext `#{ wrap(context[:description], :cyan) }` FAILED:", :bold)
|
93
|
+
end
|
94
|
+
|
95
|
+
def context_failure_examples(context, examples)
|
96
|
+
context_examples = @examples_notification.examples.select do |e|
|
97
|
+
e.metadata[:example_group] == context and e.execution_result.status == :failed
|
98
|
+
end
|
99
|
+
|
100
|
+
context_examples.each_with_object("\n") do |example, text|
|
101
|
+
text << " - Example: #{ example.metadata[:description] }\n"
|
102
|
+
text << "#{ wrap(example.exception.to_s, :failure) }"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def output_example_result(notification, category)
|
107
|
+
if @verbose
|
108
|
+
else
|
109
|
+
output.print(wrap('.', category))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/vigia/hooks.rb
CHANGED
@@ -3,6 +3,11 @@ module Vigia
|
|
3
3
|
|
4
4
|
def execute_hook(filter_name, rspec_context)
|
5
5
|
hooks_for_object(filter_name).each do |hook|
|
6
|
+
if self.is_a?(Vigia::Sail::Context)
|
7
|
+
instance = self
|
8
|
+
rspec_context.define_singleton_method(:vigia_context, -> { instance })
|
9
|
+
end
|
10
|
+
|
6
11
|
rspec_context.instance_exec(&hook)
|
7
12
|
end
|
8
13
|
end
|
@@ -8,6 +8,7 @@ module Vigia
|
|
8
8
|
instance.options.each do |name, value|
|
9
9
|
instance[name] = context.contextual_object(object: value, context: in_let_context)
|
10
10
|
end
|
11
|
+
instance.headers ||= {}
|
11
12
|
instance.use_uri_template if instance.uri_template
|
12
13
|
instance.include_config_headers if Vigia.config.headers.any?
|
13
14
|
instance
|
data/lib/vigia/rspec.rb
CHANGED
@@ -21,10 +21,8 @@ module Vigia
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def run!
|
24
|
-
|
25
|
-
|
26
|
-
[ Vigia.spec_folder ], Vigia.config.stderr, Vigia.config.stdout)
|
27
|
-
end
|
24
|
+
RSpec::Core::Runner::run(
|
25
|
+
[ Vigia.spec_folder ], Vigia.config.stderr, Vigia.config.stdout)
|
28
26
|
end
|
29
27
|
|
30
28
|
def start_tests(rspec)
|
@@ -57,6 +55,7 @@ module Vigia
|
|
57
55
|
end
|
58
56
|
|
59
57
|
def configure_vigia_rspec(rspec_config)
|
58
|
+
rspec_config.formatter = Vigia::Formatter
|
60
59
|
return unless Vigia.config.rspec_config_block.respond_to?(:call)
|
61
60
|
Vigia.config.rspec_config_block.call(rspec_config)
|
62
61
|
end
|
data/lib/vigia/sail/context.rb
CHANGED
@@ -3,16 +3,7 @@ module Vigia
|
|
3
3
|
class Context < RSpecObject
|
4
4
|
|
5
5
|
def run
|
6
|
-
|
7
|
-
rspec.context instance.to_s do
|
8
|
-
instance.with_hooks(self) do
|
9
|
-
let(:http_client_options) { instance.set_http_client_options(self) }
|
10
|
-
let(:expectations) { instance.set_expectations(self) }
|
11
|
-
|
12
|
-
instance.run_examples(self)
|
13
|
-
instance.run_shared_examples(self)
|
14
|
-
end
|
15
|
-
end
|
6
|
+
run_rspec_context unless disabled?
|
16
7
|
end
|
17
8
|
|
18
9
|
def set_http_client_options(in_let_context)
|
@@ -42,7 +33,30 @@ module Vigia
|
|
42
33
|
end
|
43
34
|
|
44
35
|
def to_s
|
45
|
-
"context #{ name }"
|
36
|
+
(contextual_object(option_name: :description) || "context #{ name }").to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_rspec_context
|
40
|
+
instance = self
|
41
|
+
rspec.context instance.to_s do
|
42
|
+
|
43
|
+
define_singleton_method("context_#{ instance.name }", ->{ instance })
|
44
|
+
|
45
|
+
instance.with_hooks(self) do
|
46
|
+
let(:http_client_options) { instance.set_http_client_options(self) }
|
47
|
+
let(:expectations) { instance.set_expectations(self) }
|
48
|
+
|
49
|
+
instance.run_examples(self)
|
50
|
+
instance.run_children(self)
|
51
|
+
instance.run_shared_examples(self)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def run_children(in_context)
|
57
|
+
children.each do |context_name|
|
58
|
+
Vigia::Sail::Context.setup_and_run(context_name, in_context)
|
59
|
+
end
|
46
60
|
end
|
47
61
|
|
48
62
|
private
|
@@ -61,6 +75,17 @@ module Vigia
|
|
61
75
|
def default_expectations
|
62
76
|
[ :code, :headers, :body ]
|
63
77
|
end
|
78
|
+
|
79
|
+
def disabled?
|
80
|
+
return false unless options[:disable_if]
|
81
|
+
contextual_object(option_name: :disable_if, context: rspec)
|
82
|
+
end
|
83
|
+
|
84
|
+
def children
|
85
|
+
(self.class.collection.select do |k,v|
|
86
|
+
v.has_key?(:in_contexts) && [ *v[:in_contexts] ].include?(name)
|
87
|
+
end.keys + ([ *options[:contexts] ] || [])).uniq
|
88
|
+
end
|
64
89
|
end
|
65
90
|
end
|
66
91
|
end
|
data/lib/vigia/sail/example.rb
CHANGED
@@ -9,11 +9,12 @@ module Vigia
|
|
9
9
|
|
10
10
|
def run_in_context(context, rspec_context)
|
11
11
|
@collection.each do |name, options|
|
12
|
-
setup_and_run(name, rspec_context) if example_contexts_include?(context, options[:contexts])
|
12
|
+
setup_and_run(name, rspec_context) if example_contexts_include?(context, name, options[:contexts])
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def example_contexts_include?(context, enabled_contexts)
|
16
|
+
def example_contexts_include?(context, example_name, enabled_contexts)
|
17
|
+
return context.options[:examples].include?(example_name) if context.options[:examples].is_a?(Enumerable)
|
17
18
|
[ *(enabled_contexts || :default) ].include?(context.name)
|
18
19
|
end
|
19
20
|
end
|
@@ -1,11 +1,17 @@
|
|
1
|
-
Vigia::Sail::Example.register(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
)
|
1
|
+
Vigia::Sail::Example.register(
|
2
|
+
:code_match,
|
3
|
+
description: 'has the expected HTTP code',
|
4
|
+
expectation: -> {
|
5
|
+
if expectations.code.is_a?(Range)
|
6
|
+
expect(expectations.code.member?(result.code)).to be true
|
7
|
+
else
|
8
|
+
expect(result.code).to be(expectations.code)
|
9
|
+
end
|
10
|
+
}
|
11
|
+
)
|
6
12
|
|
7
|
-
Vigia::Sail::Example.register(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
)
|
13
|
+
Vigia::Sail::Example.register(
|
14
|
+
:include_headers,
|
15
|
+
description: 'includes the expected headers',
|
16
|
+
expectation: -> { expect(result.headers).to include(expectations.headers) }
|
17
|
+
)
|
@@ -10,8 +10,10 @@ module Vigia
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def setup_and_run(name, rspec)
|
13
|
-
|
14
|
-
|
13
|
+
items = collection.select{ |k,v| k == name }
|
14
|
+
raise "Cannot find #{ self.name } with name #{ name }" if items.empty?
|
15
|
+
name, options = items.first
|
16
|
+
instance = new(name, options, rspec)
|
15
17
|
instance.run
|
16
18
|
end
|
17
19
|
end
|
data/lib/vigia/version.rb
CHANGED
data/lib/vigia.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative 'vigia/adapter'
|
|
9
9
|
require_relative 'vigia/adapters/blueprint'
|
10
10
|
require_relative 'vigia/config'
|
11
11
|
require_relative 'vigia/hooks'
|
12
|
+
require_relative 'vigia/formatter'
|
12
13
|
require_relative 'vigia/http_client/options'
|
13
14
|
require_relative 'vigia/http_client/rest_client'
|
14
15
|
require_relative 'vigia/http_client/requests'
|
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.
|
4
|
+
version: 0.1.2
|
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-
|
12
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -194,19 +194,20 @@ files:
|
|
194
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/rspec.rb
|
198
197
|
- lib/vigia/adapters/blueprint.rb
|
199
198
|
- lib/vigia/parameters.rb
|
200
199
|
- lib/vigia/sail/group.rb
|
201
200
|
- lib/vigia/sail/group_instance.rb
|
201
|
+
- lib/vigia/sail/examples/default.rb
|
202
202
|
- lib/vigia/sail/context.rb
|
203
203
|
- lib/vigia/sail/example.rb
|
204
|
-
- lib/vigia/sail/examples/default.rb
|
205
204
|
- lib/vigia/sail/rspec_object.rb
|
206
205
|
- lib/vigia/adapter.rb
|
207
206
|
- lib/vigia/config.rb
|
208
|
-
- lib/vigia/hooks.rb
|
209
207
|
- lib/vigia/url.rb
|
208
|
+
- lib/vigia/formatter.rb
|
209
|
+
- lib/vigia/hooks.rb
|
210
|
+
- lib/vigia/rspec.rb
|
210
211
|
- lib/vigia/version.rb
|
211
212
|
- lib/vigia.rb
|
212
213
|
- README.md
|