Class: ApprovalTests::Approvals
- Inherits:
-
Object
- Object
- ApprovalTests::Approvals
- Defined in:
- lib/approval_tests/approvals.rb
Class Method Summary collapse
- .approve(data) ⇒ Object
- .approve_html(data) ⇒ Object
- .approve_list(label, list) ⇒ Object
- .approve_map(map) ⇒ Object
- .approve_with_writer(writer) ⇒ Object
- .approve_xml(data) ⇒ Object
- .get_default_reporter ⇒ Object
- .namer ⇒ Object
- .namer=(namer) ⇒ Object
- .reporter(reporter) ⇒ Object
- .unregister_last_reporter ⇒ Object
- .unregister_reporter(reporter) ⇒ Object
Class Method Details
.approve(data) ⇒ Object
40 41 42 |
# File 'lib/approval_tests/approvals.rb', line 40 def approve(data) approve_with_writer(TextWriter.new(data)) end |
.approve_html(data) ⇒ Object
44 45 46 |
# File 'lib/approval_tests/approvals.rb', line 44 def approve_html(data) approve_with_writer(HtmlWriter.new(data)) end |
.approve_list(label, list) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/approval_tests/approvals.rb', line 23 def approve_list(label, list) i = -1; format = list.map do |m| i = i+1 "#{label}[#{i}] = #{m} \r" end format = "#{label}.count = 0" if list.empty? approve(format.to_s) end |
.approve_map(map) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/approval_tests/approvals.rb', line 33 def approve_map(map) out = ""; map.each do |key,value| out += "[#{key}] = #{value} \r" end approve(out) end |
.approve_with_writer(writer) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/approval_tests/approvals.rb', line 52 def approve_with_writer(writer) approver = FileApprover.new(writer, @namer) if approver.approve() approver.clean_up_after_success() else @reporter = get_default_reporter() approver.report_failure(@reporter) if @reporter.approved_when_reported() approver.clean_up_after_sucess() else approver.fail() end end end |
.approve_xml(data) ⇒ Object
48 49 50 |
# File 'lib/approval_tests/approvals.rb', line 48 def approve_xml(data) approve_with_writer(TextWriter.new(XmlWriter.pretty_xml(data))) end |
.get_default_reporter ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/approval_tests/approvals.rb', line 76 def get_default_reporter() @reporters ||= [] return @reporters.first() unless @reporters.empty? if defined? Spec::Mate TextMateReporter.instance else QuietReporter.instance end end |
.namer ⇒ Object
72 73 74 |
# File 'lib/approval_tests/approvals.rb', line 72 def namer @namer end |
.namer=(namer) ⇒ Object
68 69 70 |
# File 'lib/approval_tests/approvals.rb', line 68 def namer=(namer) @namer = namer end |
.reporter(reporter) ⇒ Object
86 87 88 89 |
# File 'lib/approval_tests/approvals.rb', line 86 def reporter(reporter) @reporters ||= [] @reporters.push(reporter); end |
.unregister_last_reporter ⇒ Object
95 96 97 |
# File 'lib/approval_tests/approvals.rb', line 95 def unregister_last_reporter() @reporters.pop() if @reporters end |
.unregister_reporter(reporter) ⇒ Object
91 92 93 |
# File 'lib/approval_tests/approvals.rb', line 91 def unregister_reporter(reporter) @reporters.remove(reporter); end |