Class: Lacerda::Reporters::Stdout
Instance Method Summary
collapse
#check_published_object, #object_publish_specification_errors
Constructor Details
#initialize(options = {}) ⇒ Stdout
Returns a new instance of Stdout.
5
6
7
8
|
# File 'lib/lacerda/reporters/stdout.rb', line 5
def initialize(options = {})
@verbose = options.fetch(:verbose, true)
@io = options.fetch(:output, $stdout)
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/stdout.rb', line 47
def check_consumed_object(object)
error = if object.publisher.nil?
"Publisher #{object.publisher_name} does not exist"
elsif !object.publisher.publishes?(object.name)
"#{object.publisher.name} does not publish #{object.name}"
else
nil
end
@current_consumer.it "#{object.name} from #{object.publisher_name}" do
expect(error).to(be_nil, error)
end
end
|
#check_consumer(consuming_service) ⇒ Object
41
42
43
44
|
# File 'lib/lacerda/reporters/stdout.rb', line 41
def check_consumer(consuming_service)
return unless @verbose
@io.print "\nObjects consumed by #{consuming_service.name.camelize}: "
end
|
#check_consuming ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/lacerda/reporters/stdout.rb', line 30
def check_consuming
return unless @verbose
if @consumers == 0
@io.print " (no consumers)".yellow + "\n"
elsif @consume_errors == 0
@io.print " OK".green
else
@io.print " ERROR".red
end
end
|
#check_publisher(publisher) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/lacerda/reporters/stdout.rb', line 13
def check_publisher(publisher)
return unless @verbose
@consumers = 0
@consume_errors = 0
@io.print "\n#{publisher.name.camelize} satisfies: "
end
|
#check_publishing ⇒ Object
10
11
|
# File 'lib/lacerda/reporters/stdout.rb', line 10
def check_publishing
end
|
#consume_specification_satisfied(consumer, is_valid) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/lacerda/reporters/stdout.rb', line 20
def consume_specification_satisfied(consumer, is_valid)
@consumers += 1
if is_valid
@io.print "#{consumer.name.camelize.green} " if @verbose
else
@io.print "#{consumer.name.camelize.red} " if @verbose
@consume_errors += 1
end
end
|
#result(errors) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/lacerda/reporters/stdout.rb', line 68
def result(errors)
return unless @verbose
if errors.blank?
@io.puts "\n----------------------"
@io.puts "All contracts valid 🙌 ".green
else
@io.puts "--------------"
@io.puts "😱 Violations:".red
@io.puts JSON.pretty_generate(errors)
@io.puts "#{errors.length} contract violations".red
end
end
|