lacerda 2.0.1 → 2.1.0

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: 9e13fe3981ad5e7dc33070f0343f43745d032269
4
- data.tar.gz: 527ce7ff8b9e0a89a5d4e0d1f8c50a506b9b4cb5
3
+ metadata.gz: eaf17955acd73740444ef9eadfb624649845878c
4
+ data.tar.gz: 95faea39afed8806d21c1a38c03f690ed702154c
5
5
  SHA512:
6
- metadata.gz: 4ac94e6e2c6681138aa1dc83d6beb03d234ca0b8325e4c4aa5deb37967814ced69b38c866a77f98bbaed1051438a30a8ece9d59ae193d98740bc9a6b22ca515c
7
- data.tar.gz: cc41f55260d38599b36e4403f567c9ba09483452d3890b99fa722f75211b638603631aa653ab9f328e0ea3c5f2e4ab937cc8f3a027ee2e136c8016a4ba512f57
6
+ metadata.gz: 4706bfcb9a42d7c2b1eb0920d8b96ff83544fb2f6870f78b318b8ada1fc096d0f9b1fb947ceebb7fbcc459b2161db2988d8717544127b093f8c7d3f533384fd8
7
+ data.tar.gz: a1b8da1d419825b8718e68b001d7f52b19325937ddfaa98a5ceab8cbb3c7ed5ea96b4a44a2f2a0eae9061aede8a73c07286932e656237fe85e4d0f76b346b4ab
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.1.0
2
+ - Allow to validate objects without scopes
3
+ - Fix RSpec reporter, so it displayes publisher errors
4
+
1
5
  # 2.0.1
2
6
  - Merge (for real) add enum support to master
3
7
 
@@ -16,6 +16,7 @@ module Lacerda
16
16
  Lacerda.validate_reporter(reporter)
17
17
  @comparator = Compare::JsonSchema.new(@schema)
18
18
  result = @comparator.contains?(consumer.consume.scoped_schema(service), consumer.name)
19
+ reporter.try(:consume_specification_errors,consumer, errors)
19
20
  reporter.try(:consume_specification_satisfied, consumer, result)
20
21
  result
21
22
  end
@@ -25,16 +26,16 @@ module Lacerda
25
26
  !!@schema[:definitions][scoped_name]
26
27
  end
27
28
 
28
- def object(name)
29
- scoped_name = scopify_name(name)
29
+ def object(name, scoped: true)
30
+ object_name = scoped ? scopify_name(name) : Lacerda.underscore(name.to_s)
30
31
  schema_dup = Lacerda.deep_copy(@schema)
31
32
 
32
33
  # It's critical to delete this object from the definitions
33
34
  # or else the json validator gem will go into an endless loop
34
- object_schema = schema_dup['definitions'].delete scoped_name.to_s
35
+ object_schema = schema_dup['definitions'].delete object_name.to_s
35
36
 
36
37
  unless object_schema
37
- msg = "Unknown object type: #{scoped_name.to_s.to_json} not in #{schema['definitions'].keys.to_json} - did you specify it in publish.mson?"
38
+ msg = "Unknown object type: #{object_name.to_s.to_json} not in #{schema['definitions'].keys.to_json} - did you specify it in publish.mson?"
38
39
  raise Lacerda::Service::InvalidObjectTypeError.new(msg)
39
40
  end
40
41
 
@@ -42,7 +43,7 @@ module Lacerda
42
43
  # object in case its properties include json pointers
43
44
  object_schema['definitions'] = schema_dup['definitions']
44
45
 
45
- Lacerda::PublishedObject.new(service, scoped_name, object_schema)
46
+ Lacerda::PublishedObject.new(service, object_name, object_schema)
46
47
  end
47
48
 
48
49
  private
@@ -13,9 +13,11 @@ module Lacerda
13
13
  # Called before one single publisher is checked against its consumers
14
14
  end
15
15
 
16
- def object_publish_specification_valid(consumed_object, is_valid)
16
+
17
+ def object_publish_specification_errors(consumed_object, errors)
17
18
  # Called after a consumed object's specification has been checked against
18
- # the publisher's specification of that object.
19
+ # the publisher's specification of that object. It returns an array of
20
+ # errors
19
21
  end
20
22
 
21
23
  def check_consuming
@@ -7,21 +7,40 @@ module Lacerda
7
7
  @group = group
8
8
  end
9
9
 
10
+ def consume_specification_satisfied(consumer, is_valid)
11
+ @current_publisher.it "satisfies #{consumer.name}" do
12
+ expect(is_valid).to be true
13
+ end
14
+ end
15
+
16
+ # errors is a hash with the following structure:
17
+ # { "publisher_name -> consumer_name" => [
18
+ # { :error => :ERR_MISSING_DEFINITION,
19
+ # :message =>"Some text",
20
+ # :location => 'consumer_name/publisher_name::object_name
21
+ # }]
22
+ # }
23
+ def consume_specification_errors(consumer, errors)
24
+ error_messages = errors.map do |error|
25
+ "- #{error[:error]} in #{error[:location]}: #{error[:message]}"
26
+ end
27
+ msg = "expected #{@current_publisher.description} to satisfy "\
28
+ "#{consumer.name} but found these errors:\n"\
29
+ " #{error_messages.join("\n")}"
30
+ @current_publisher.it "satisfies #{consumer.name}" do
31
+ expect(error_messages).to be_empty, msg
32
+ end
33
+ end
34
+
10
35
  def check_publishing
36
+ @current_consumer.try(:run)
11
37
  @publish_group = @group.describe("publishers")
12
38
  end
13
39
 
14
40
  def check_publisher(service)
15
- @current_publisher.try(:run)
16
41
  @current_publisher = @publish_group.describe(service.try(:name))
17
42
  end
18
43
 
19
- def object_publish_specificaiton_valid(object, valid)
20
- @current_publisher.it "-> #{object.try(:consumer).try(:name)}" do
21
- expect(valid).to be true
22
- end
23
- end
24
-
25
44
  def check_consuming
26
45
  @current_publisher.try(:run)
27
46
  @consume_group = @group.describe("consumers")
@@ -39,8 +58,6 @@ module Lacerda
39
58
  end
40
59
 
41
60
  def result(errors)
42
- @current_consumer.try(:run)
43
- @group.run
44
61
  end
45
62
 
46
63
  end
@@ -78,6 +78,11 @@ module Lacerda
78
78
  object_description.validate_data!(data)
79
79
  end
80
80
 
81
+ def validate_internal_publish_object!(type, data)
82
+ object_description = @publish.object(type, scoped: false)
83
+ object_description.validate_data!(data)
84
+ end
85
+
81
86
  def validate_object_to_consume(type, data)
82
87
  validate_object_to_consume!(type, data)
83
88
  true
@@ -1,3 +1,3 @@
1
1
  module Lacerda
2
- VERSION = '2.0.1'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lacerda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jannis Hermanns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-22 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport