Class: Lacerda::Reporters::RSpec

Inherits:
Lacerda::Reporter show all
Defined in:
lib/lacerda/reporters/rspec.rb

Instance Method Summary collapse

Methods inherited from Lacerda::Reporter

#check_published_object, #object_publish_specification_errors

Constructor Details

#initialize(group = ::RSpec.describe("Lacerda infrastructure contract validation")) ⇒ RSpec

Returns a new instance of RSpec.



6
7
8
# File 'lib/lacerda/reporters/rspec.rb', line 6

def initialize(group = ::RSpec.describe("Lacerda infrastructure contract validation"))
  @group = group
end

Instance Method Details

#check_consumed_object(consumed_object_name, publisher_name, publisher_exists, is_published) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lacerda/reporters/rspec.rb', line 47

def check_consumed_object(consumed_object_name, publisher_name, publisher_exists, is_published)
  error = if !publisher_exists
            "Publisher #{publisher_name} does not exist"
          elsif !is_published
            "#{publisher_name} does not publish #{consumed_object_name}"
          end
  @current_consumer.it "#{consumed_object_name} from #{publisher_name}" do |example|
    # We need to set the location to avoid rspec STDOUT errors
    example.[:location] = 'spec/config/zeta_spec.rb'
    expect(publisher_exists && is_published).to eq(true), error
  end
end

#check_consumer(service) ⇒ Object



43
44
45
# File 'lib/lacerda/reporters/rspec.rb', line 43

def check_consumer(service)
  @current_consumer = @consume_group.describe("#{service.try(:name)} consuming")
end

#check_consumingObject



39
40
41
# File 'lib/lacerda/reporters/rspec.rb', line 39

def check_consuming
  @consume_group = @group.describe("consumers")
end

#check_publisher(service) ⇒ Object



35
36
37
# File 'lib/lacerda/reporters/rspec.rb', line 35

def check_publisher(service)
  @current_publisher = @publish_group.describe(service.try(:name))
end

#check_publishingObject



31
32
33
# File 'lib/lacerda/reporters/rspec.rb', line 31

def check_publishing
  @publish_group = @group.describe("publishers")
end

#consume_specification_errors(consumer, errors) ⇒ Object

errors is a hash with the following structure:

{ "publisher_name -> consumer_name" => [
   { :error => :ERR_MISSING_DEFINITION,
     :message =>"Some text",
     :location => 'consumer_name/publisher_name::object_name
   }]
}


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lacerda/reporters/rspec.rb', line 17

def consume_specification_errors(consumer, errors)
  error_messages = errors.map do |error|
    "- #{error[:error]} in #{error[:location]}: #{error[:message]}"
  end
  msg = "expected #{@current_publisher.description} to satisfy "\
    "#{consumer.name} but found these errors:\n"\
    "  #{error_messages.join("\n")}"
  @current_publisher.it "satisfies #{consumer.name}" do |example|
    # We need to set the location to avoid rspec STDOUT errors
    example.[:location] = 'spec/config/zeta_spec.rb'
    expect(error_messages).to be_empty, msg
  end
end

#result(errors) ⇒ Object



60
61
# File 'lib/lacerda/reporters/rspec.rb', line 60

def result(errors)
end