Class: CabezaDeTermo::JsonSpec::JsonExpectationsReporter

Inherits:
JsonExpectationsRunner show all
Defined in:
lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb

Instance Method Summary collapse

Methods inherited from JsonExpectationsRunner

#has_errors?, #in_isolation, #in_isolation_walk_each_field, #in_isolation_walk_on, #raise_validation_error, #unexpected_fields_from_current_value_holder, #walk_each_defined_field_of, #walk_each_field_name, #walk_each_field_value, #walk_expectation, #walk_expectation_runner, #walk_expectations_of, #walk_json_any_of, #walk_json_anything, #walk_json_each, #walk_json_each_field, #walk_json_field, #walk_json_field_name, #walk_json_list, #walk_json_object, #walk_json_scalar, #walk_json_spec, #walk_on, #walk_with_new_walker

Methods included from ValueHoldersStackBehaviour

#new_value_holder_on, #pop_value_holder, #push_value_holder, #walk_with_json, #walk_with_value_holder, #with_value_holder

Methods inherited from ExpressionWalker

#supressing, #walk_expectation, #walk_expectation_runner, #walk_json_any_of, #walk_json_anything, #walk_json_each, #walk_json_each_field, #walk_json_field, #walk_json_field_name, #walk_json_list, #walk_json_object, #walk_json_scalar, #walk_json_spec, #walk_on

Constructor Details

#initializeJsonExpectationsReporter

Returns a new instance of JsonExpectationsReporter.



8
9
10
11
12
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 8

def initialize()
	super()

	@expectation_reports = []
end

Instance Method Details

#add_all_expectation_reports(expectation_reports) ⇒ Object



78
79
80
81
82
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 78

def add_all_expectation_reports(expectation_reports)
	expectation_reports.each do |report|
		add_expectation_report(report)
	end
end

#add_expectation_report(expectation_report) ⇒ Object



74
75
76
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 74

def add_expectation_report(expectation_report)
	@expectation_reports << expectation_report
end

#expectation_reportsObject

Accessing



24
25
26
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 24

def expectation_reports()
	@expectation_reports
end

#expectation_reports_as_arrayObject



28
29
30
31
32
33
34
35
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 28

def expectation_reports_as_array()
	arrays = []
	expectation_reports.each do |expectation_report|
		arrays << expectation_report.to_array
	end

	arrays
end

#log_expectation(expectation, value_holder, was_satisfied) ⇒ Object

Logging Expectations reports



54
55
56
57
58
59
60
61
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 54

def log_expectation(expectation, value_holder, was_satisfied)
	expectation_report = new_expectation_report
					.set_expectation_method(expectation.expectation_method)
					.set_was_satisfied(was_satisfied)
					.set_failed_message( expectation.failed_message_on(value_holder) )

	add_expectation_report(expectation_report)
end

#log_unwalked_field(field) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 63

def log_unwalked_field(field)
	access_chain = @value_holder.accessors_chain.append_accessor(field).to_s

	expectation_report = new_expectation_report
					.set_expectation_method(:unexpected_field)
					.set_status(:unexpected_field)
					.set_failed_message("Unexpected field '#{access_chain}'.")

	add_expectation_report(expectation_report)
end

#new_expectation_reportObject

Instance creation



48
49
50
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 48

def new_expectation_report()
	ExpectationReport.new
end

#new_json_expectations_runnerObject

Instance creation



106
107
108
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 106

def new_json_expectations_runner()
	self.class.new
end

#no_errors?Boolean

Answer true if all the walked Expectations were satisfied.

Returns:

  • (Boolean)


42
43
44
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 42

def no_errors?()
	expectation_reports.all? { |expectation_report| expectation_report.was_satisfied? }
end

#on_json_any_of_failed_with_all_runners(expectations_runners) ⇒ Object



94
95
96
97
98
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 94

def on_json_any_of_failed_with_all_runners(expectations_runners)
	expectations_runners.each do |each_runner|
		add_all_expectation_reports(each_runner.expectation_reports)
	end
end

#on_json_any_of_was_satisfied_with_runner(expectations_runner) ⇒ Object



90
91
92
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 90

def on_json_any_of_was_satisfied_with_runner(expectations_runner)
	add_all_expectation_reports(expectations_runner.expectation_reports)
end

#on_unwalked_field(field_name, value_holder) ⇒ Object

Hooks



86
87
88
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 86

def on_unwalked_field(field_name, value_holder)
	log_unwalked_field(field_name)
end

#on_walked_expectation(expectation, value_holder, was_satisfied) ⇒ Object



100
101
102
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 100

def on_walked_expectation(expectation, value_holder, was_satisfied)
	log_expectation(expectation, value_holder, was_satisfied)
end

#run_on(json_expression, json) ⇒ Object



18
19
20
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 18

def run_on(json_expression, json)
	walk_with_json(json_expression, json)
end

#run_on_json_string(json_expression, json_string) ⇒ Object



14
15
16
# File 'lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb', line 14

def run_on_json_string(json_expression, json_string)
	run_on(json_expression, JSON.parse(json_string))
end