approval_tests 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README +0 -0
- data/Rakefile +22 -0
- data/VERSION +1 -0
- data/approval_tests.gemspec +68 -0
- data/lib/approval_tests.rb +10 -0
- data/lib/approval_tests/approvals.rb +101 -0
- data/lib/approval_tests/approvers/file_approver.rb +47 -0
- data/lib/approval_tests/extensions/rspec.rb +50 -0
- data/lib/approval_tests/namers/rspec_namer.rb +22 -0
- data/lib/approval_tests/reporters/diff_reporter.rb +18 -0
- data/lib/approval_tests/reporters/quiet_reporter.rb +21 -0
- data/lib/approval_tests/reporters/text_mate_reporter.rb +24 -0
- data/lib/approval_tests/writers/html_writer.rb +24 -0
- data/lib/approval_tests/writers/text_writer.rb +27 -0
- data/lib/approval_tests/writers/xml_writer.rb +81 -0
- data/spec/a.txt +7 -0
- data/spec/approvals_lists_should_show_empty_lists.approved.txt +1 -0
- data/spec/approvals_lists_should_write_arrays.approved.txt +1 -0
- data/spec/approvals_lists_should_write_maps.approved.txt +1 -0
- data/spec/approvals_multiple_describes_should_approve_multiple_describes.approved.txt +1 -0
- data/spec/approvals_should_approve_shared_behaviors.approved.txt +1 -0
- data/spec/approvals_should_successfully_approve_text.approved.txt +1 -0
- data/spec/approvals_spec.rb +75 -0
- data/spec/approvals_using_approval_blocks.approved.txt +1 -0
- data/spec/approvals_using_approval_blocks_the_last_statement.approved.txt +1 -0
- data/spec/approvals_xml_should_be_pretty.approved.txt +8 -0
- data/spec/b.txt +7 -0
- data/spec/cleanup_reporter.rb +9 -0
- data/spec/spec.opts +0 -0
- data/spec/spec_helper.rb +18 -0
- metadata +86 -0
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
Spec::Rake::SpecTask.new('specs') do |t|
|
5
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
6
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'jeweler'
|
11
|
+
Jeweler::Tasks.new do |gemspec|
|
12
|
+
gemspec.name = "approval_tests"
|
13
|
+
gemspec.summary = "Approval testing library"
|
14
|
+
gemspec.email = "approvaltests@dangilkerson.com"
|
15
|
+
gemspec.homepage = "http://github.com/approvaltests/approval_tests"
|
16
|
+
gemspec.description = "Approval testing library for ruby"
|
17
|
+
gemspec.authors = ["Dan Gilkerson, Llewellyn Falco"]
|
18
|
+
gemspec.rubyforge_project = 'approvaltests'
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
22
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.7
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{approval_tests}
|
5
|
+
s.version = "0.0.7"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Dan Gilkerson, Llewellyn Falco"]
|
9
|
+
s.date = %q{2009-07-03}
|
10
|
+
s.description = %q{Approval testing library for ruby}
|
11
|
+
s.email = %q{approvaltests@dangilkerson.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
"README",
|
17
|
+
"Rakefile",
|
18
|
+
"VERSION",
|
19
|
+
"approval_tests.gemspec",
|
20
|
+
"lib/approval_tests.rb",
|
21
|
+
"lib/approval_tests/approvals.rb",
|
22
|
+
"lib/approval_tests/approvers/file_approver.rb",
|
23
|
+
"lib/approval_tests/extensions/rspec.rb",
|
24
|
+
"lib/approval_tests/namers/rspec_namer.rb",
|
25
|
+
"lib/approval_tests/reporters/diff_reporter.rb",
|
26
|
+
"lib/approval_tests/reporters/quiet_reporter.rb",
|
27
|
+
"lib/approval_tests/reporters/text_mate_reporter.rb",
|
28
|
+
"lib/approval_tests/writers/html_writer.rb",
|
29
|
+
"lib/approval_tests/writers/text_writer.rb",
|
30
|
+
"lib/approval_tests/writers/xml_writer.rb",
|
31
|
+
"spec/a.txt",
|
32
|
+
"spec/approvals_lists_should_show_empty_lists.approved.txt",
|
33
|
+
"spec/approvals_lists_should_write_arrays.approved.txt",
|
34
|
+
"spec/approvals_lists_should_write_maps.approved.txt",
|
35
|
+
"spec/approvals_multiple_describes_should_approve_multiple_describes.approved.txt",
|
36
|
+
"spec/approvals_should_approve_shared_behaviors.approved.txt",
|
37
|
+
"spec/approvals_should_successfully_approve_text.approved.txt",
|
38
|
+
"spec/approvals_spec.rb",
|
39
|
+
"spec/approvals_using_approval_blocks.approved.txt",
|
40
|
+
"spec/approvals_using_approval_blocks_the_last_statement.approved.txt",
|
41
|
+
"spec/approvals_xml_should_be_pretty.approved.txt",
|
42
|
+
"spec/b.txt",
|
43
|
+
"spec/cleanup_reporter.rb",
|
44
|
+
"spec/spec.opts",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://github.com/approvaltests/approval_tests}
|
48
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubyforge_project = %q{approvaltests}
|
51
|
+
s.rubygems_version = %q{1.3.4}
|
52
|
+
s.summary = %q{Approval testing library}
|
53
|
+
s.test_files = [
|
54
|
+
"spec/approvals_spec.rb",
|
55
|
+
"spec/cleanup_reporter.rb",
|
56
|
+
"spec/spec_helper.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
64
|
+
else
|
65
|
+
end
|
66
|
+
else
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
__DIR__ = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift __DIR__ unless
|
4
|
+
$LOAD_PATH.include?(__DIR__) ||
|
5
|
+
$LOAD_PATH.include?(File.expand_path(__DIR__))
|
6
|
+
|
7
|
+
require "approval_tests/approvals"
|
8
|
+
require "approval_tests/extensions/rspec"
|
9
|
+
|
10
|
+
include ApprovalTests::Namers
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
__DIR__ = File.dirname(__FILE__)
|
3
|
+
require "#{__DIR__}/namers/rspec_namer"
|
4
|
+
require "#{__DIR__}/approvers/file_approver"
|
5
|
+
require "#{__DIR__}/writers/text_writer"
|
6
|
+
require "#{__DIR__}/writers/html_writer"
|
7
|
+
require "#{__DIR__}/writers/xml_writer"
|
8
|
+
require "#{__DIR__}/reporters/quiet_reporter"
|
9
|
+
require "#{__DIR__}/reporters/text_mate_reporter"
|
10
|
+
require "#{__DIR__}/reporters/diff_reporter"
|
11
|
+
#require "#{__DIR__}/reporters/html_reporter"
|
12
|
+
|
13
|
+
include ApprovalTests::Approvers
|
14
|
+
include ApprovalTests::Writers
|
15
|
+
include ApprovalTests::Reporters
|
16
|
+
|
17
|
+
module ApprovalTests
|
18
|
+
class ApprovalError < Exception
|
19
|
+
attr_accessor :received_filename
|
20
|
+
attr_accessor :approved_filename
|
21
|
+
end
|
22
|
+
class Approvals
|
23
|
+
class << self
|
24
|
+
def approve_list(label, list)
|
25
|
+
|
26
|
+
i = -1;
|
27
|
+
format = list.map do |m|
|
28
|
+
i = i+1
|
29
|
+
"#{label}[#{i}] = #{m} \r"
|
30
|
+
end
|
31
|
+
format = "#{label}.count = 0" if list.empty?
|
32
|
+
approve(format.to_s)
|
33
|
+
end
|
34
|
+
def approve_map(map)
|
35
|
+
out = "";
|
36
|
+
map.each do |key,value|
|
37
|
+
out += "[#{key}] = #{value} \r"
|
38
|
+
end
|
39
|
+
approve(out)
|
40
|
+
end
|
41
|
+
def approve(data)
|
42
|
+
approve_with_writer(TextWriter.new(data))
|
43
|
+
end
|
44
|
+
|
45
|
+
def approve_html(data)
|
46
|
+
approve_with_writer(HtmlWriter.new(data))
|
47
|
+
end
|
48
|
+
|
49
|
+
def approve_xml(data)
|
50
|
+
approve_with_writer(TextWriter.new(XmlWriter.pretty_xml(data)))
|
51
|
+
end
|
52
|
+
|
53
|
+
def approve_with_writer(writer)
|
54
|
+
approver = FileApprover.new(writer, @namer)
|
55
|
+
if approver.approve()
|
56
|
+
approver.clean_up_after_success()
|
57
|
+
else
|
58
|
+
@reporter = get_default_reporter()
|
59
|
+
approver.report_failure(@reporter)
|
60
|
+
|
61
|
+
if @reporter.approved_when_reported()
|
62
|
+
approver.clean_up_after_sucess()
|
63
|
+
else
|
64
|
+
approver.fail()
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def namer=(namer)
|
70
|
+
@namer = namer
|
71
|
+
end
|
72
|
+
|
73
|
+
def namer
|
74
|
+
@namer
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_default_reporter()
|
78
|
+
@reporters ||= []
|
79
|
+
return @reporters.first() unless @reporters.empty?
|
80
|
+
if defined? Spec::Mate
|
81
|
+
TextMateReporter.instance
|
82
|
+
else
|
83
|
+
QuietReporter.instance
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def reporter(reporter)
|
88
|
+
@reporters ||= []
|
89
|
+
@reporters.push(reporter);
|
90
|
+
end
|
91
|
+
|
92
|
+
def unregister_reporter(reporter)
|
93
|
+
@reporters.remove(reporter);
|
94
|
+
end
|
95
|
+
|
96
|
+
def unregister_last_reporter()
|
97
|
+
@reporters.pop() if @reporters
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module ApprovalTests
|
4
|
+
module Approvers
|
5
|
+
class FileApprover
|
6
|
+
def initialize(writer, namer)
|
7
|
+
@writer = writer
|
8
|
+
@namer = namer
|
9
|
+
end
|
10
|
+
|
11
|
+
def approve()
|
12
|
+
basename = "#{@namer.source_file_path}/#{@namer.approval_name}"
|
13
|
+
@approved = @writer.get_approval_filename(basename)
|
14
|
+
@received = @writer.get_received_filename(basename)
|
15
|
+
@received = @writer.write_received_file(@received)
|
16
|
+
|
17
|
+
unless File.exists?(@approved)
|
18
|
+
@failure = ApprovalError.new("Failed Approval: Approval File \"#{@approved}\" Not Found.")
|
19
|
+
@failure.received_filename = @received
|
20
|
+
@failure.approved_filename = @approved
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
|
24
|
+
unless FileUtils.cmp(@received, @approved)
|
25
|
+
@failure = ApprovalError.new("Failed Approval: Received file #{@received} does not match approved file #{@approved}.")
|
26
|
+
@failure.received_filename = @received
|
27
|
+
@failure.approved_filename = @approved
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
|
31
|
+
return true
|
32
|
+
end
|
33
|
+
|
34
|
+
def fail()
|
35
|
+
raise @failure
|
36
|
+
end
|
37
|
+
|
38
|
+
def report_failure(reporter)
|
39
|
+
reporter.report(@approved, @received);
|
40
|
+
end
|
41
|
+
|
42
|
+
def clean_up_after_success()
|
43
|
+
File.delete(@received)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../approvals"
|
2
|
+
|
3
|
+
module ApprovalTests
|
4
|
+
module Extensions
|
5
|
+
module RSpec
|
6
|
+
def approve(thing=nil, options={}, backtrace=nil, &implementation)
|
7
|
+
if block_given?
|
8
|
+
approve_description = "#{thing}"
|
9
|
+
else
|
10
|
+
approve_description = nil
|
11
|
+
result = thing
|
12
|
+
end
|
13
|
+
|
14
|
+
example(approve_description, options) do
|
15
|
+
if block_given?
|
16
|
+
result = yield implementation
|
17
|
+
end
|
18
|
+
Approvals.approve(result)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def approve_html(thing=nil, options={}, backtrace=nil, &implementation)
|
23
|
+
if block_given?
|
24
|
+
approve_description = "#{thing}"
|
25
|
+
else
|
26
|
+
approve_description = nil
|
27
|
+
result = thing
|
28
|
+
end
|
29
|
+
|
30
|
+
example(approve_description, options) do
|
31
|
+
if block_given?
|
32
|
+
result = yield implementation
|
33
|
+
end
|
34
|
+
Approvals.approve(result, :html)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Spec::Runner.configure do |config|
|
42
|
+
config.before(:each) do
|
43
|
+
Approvals.namer = RSpecNamer.new()
|
44
|
+
extra_description = ""
|
45
|
+
extra_description = "_#{self.description}" if !self.description.empty?
|
46
|
+
Approvals.namer.approval_name = "#{self.class.description}#{extra_description}".gsub("/", "__FORWARD_SLASH__");
|
47
|
+
Approvals.namer.source_file_path = File.dirname(self.class.location)
|
48
|
+
end
|
49
|
+
config.extend(ApprovalTests::Extensions::RSpec)
|
50
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ApprovalTests
|
2
|
+
module Namers
|
3
|
+
class RSpecNamer
|
4
|
+
|
5
|
+
def approval_name
|
6
|
+
@approval_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def approval_name=(name)
|
10
|
+
@approval_name = name.downcase.gsub(/ |\./, "_")
|
11
|
+
end
|
12
|
+
|
13
|
+
def source_file_path
|
14
|
+
@source_file_path ||= File.dirname(File.expand_path(@approval_name))
|
15
|
+
end
|
16
|
+
|
17
|
+
def source_file_path=(path)
|
18
|
+
@source_file_path = path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module ApprovalTests
|
4
|
+
module Reporters
|
5
|
+
class DiffReporter
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def report(approved, received)
|
9
|
+
TextWriter.write_file(approved,"") unless File.exists?(approved)
|
10
|
+
exec "/Applications/DiffMerge.app/Contents/MacOS/DiffMerge --nosplash \"#{received}\" \"#{approved}\""
|
11
|
+
end
|
12
|
+
|
13
|
+
def approved_when_reported()
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module ApprovalTests
|
4
|
+
module Reporters
|
5
|
+
class QuietReporter
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def report(approved, received)
|
9
|
+
if RUBY_PLATFORM =~ /mswin32/
|
10
|
+
puts "move /Y \"#{received}\" \"#{approved}\""
|
11
|
+
else
|
12
|
+
puts "mv \"#{received}\" \"#{approved}\""
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def approved_when_reported()
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module ApprovalTests
|
4
|
+
module Reporters
|
5
|
+
class TextMateReporter
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def report(approved, received)
|
9
|
+
puts "<script language='JavaScript'>
|
10
|
+
function move(received, approved) {
|
11
|
+
return TextMate.system('mv ' + received + ' ' + approved, null).outputString;
|
12
|
+
}
|
13
|
+
</script>"
|
14
|
+
puts "<a href='#' onclick='move(\"#{File.expand_path(received)}\",\"#{File.expand_path(approved)}\")'>Approve</a>"
|
15
|
+
puts "<a href='txmt://open?url=file://#{File.expand_path(received)}'>View</a>"
|
16
|
+
puts "<p></p><iframe src='tm-file://#{File.expand_path(received)}' width='100%' frameborder='0' style='border:solid 1px red'></iframe>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def approved_when_reported()
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ApprovalTests
|
2
|
+
module Writers
|
3
|
+
class HtmlWriter
|
4
|
+
def initialize(data)
|
5
|
+
@data = data
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_approval_filename(basename)
|
9
|
+
basename + ".approved.html"
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_received_filename(basename)
|
13
|
+
basename + ".received.html"
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_received_file(received)
|
17
|
+
f = File.new("#{received}", "w+")
|
18
|
+
f.write(@data)
|
19
|
+
f.close()
|
20
|
+
f.path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ApprovalTests
|
2
|
+
module Writers
|
3
|
+
class TextWriter
|
4
|
+
def initialize(data)
|
5
|
+
@data = data
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_approval_filename(basename)
|
9
|
+
basename + ".approved.txt"
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_received_filename(basename)
|
13
|
+
basename + ".received.txt"
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_received_file(received)
|
17
|
+
TextWriter.write_file(received, @data)
|
18
|
+
end
|
19
|
+
def self.write_file(name, data)
|
20
|
+
f = File.new("#{name}", "w+")
|
21
|
+
f.write(data)
|
22
|
+
f.close()
|
23
|
+
f.path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
include REXML
|
3
|
+
|
4
|
+
module ApprovalTests
|
5
|
+
module Writers
|
6
|
+
class XmlWriter
|
7
|
+
def initialize(data)
|
8
|
+
@data = data
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_approval_filename(basename)
|
12
|
+
basename + ".approved.xml"
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_received_filename(basename)
|
16
|
+
basename + ".received.xml"
|
17
|
+
end
|
18
|
+
|
19
|
+
def write_received_file(received)
|
20
|
+
f = File.new("#{received}", "w+")
|
21
|
+
f.write(@data)
|
22
|
+
f.close()
|
23
|
+
f.path
|
24
|
+
end
|
25
|
+
class << self
|
26
|
+
def pretty_print(parent_node, itab)
|
27
|
+
buffer = ''
|
28
|
+
|
29
|
+
parent_node.elements.each do |node|
|
30
|
+
|
31
|
+
buffer += ' ' * itab + "<#{node.name}#{get_att_list(node)}"
|
32
|
+
|
33
|
+
if node.to_a.length > 0
|
34
|
+
buffer += ">"
|
35
|
+
if node.text.nil?
|
36
|
+
buffer += "\n"
|
37
|
+
buffer += pretty_print(node,itab+2)
|
38
|
+
buffer += ' ' * itab + "</#{node.name}>\n"
|
39
|
+
else
|
40
|
+
node_text = node.text.strip
|
41
|
+
if node_text != ''
|
42
|
+
buffer += node_text
|
43
|
+
buffer += "</#{node.name}>\n"
|
44
|
+
else
|
45
|
+
buffer += "\n" + pretty_print(node,itab+2)
|
46
|
+
buffer += ' ' * itab + "</#{node.name}>\n"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
else
|
50
|
+
buffer += "/>\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
buffer
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_att_list(node)
|
58
|
+
att_list = ''
|
59
|
+
node.attributes.each { |attribute, val| att_list += " #{attribute}='#{val}'" }
|
60
|
+
att_list
|
61
|
+
end
|
62
|
+
|
63
|
+
def pretty_xml(xml_string)
|
64
|
+
doc = Document.new(xml_string)
|
65
|
+
|
66
|
+
buffer = ''
|
67
|
+
xml_declaration = doc.to_s.match('<\?.*\?>').to_s
|
68
|
+
buffer += "#{xml_declaration}\n" if not xml_declaration.nil?
|
69
|
+
xml_doctype = doc.to_s.match('<\!.*\">').to_s
|
70
|
+
buffer += "#{xml_doctype}\n" if not xml_doctype.nil?
|
71
|
+
buffer += "<#{doc.root.name}#{get_att_list(doc.root)}"
|
72
|
+
if doc.root.to_a.length > 0
|
73
|
+
buffer +=">\n#{pretty_print(doc.root,2)}</#{doc.root.name}>"
|
74
|
+
else
|
75
|
+
buffer += "/>\n"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
tv.count = 0
|
@@ -0,0 +1 @@
|
|
1
|
+
name[0] = tom
|
@@ -0,0 +1 @@
|
|
1
|
+
[name] = harry
|
@@ -0,0 +1 @@
|
|
1
|
+
multiple describes
|
@@ -0,0 +1 @@
|
|
1
|
+
shared behavior test
|
@@ -0,0 +1 @@
|
|
1
|
+
should be approved
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
shared_examples_for "Shared Behaviors" do
|
4
|
+
it "should approve shared behaviors" do
|
5
|
+
Approvals.approve("shared behavior test")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "Approvals" do
|
10
|
+
after(:each) do
|
11
|
+
Approvals.unregister_last_reporter()
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like "Shared Behaviors"
|
15
|
+
|
16
|
+
it "should successfully approve text" do
|
17
|
+
Approvals.approve("should be approved")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise mismatch error if received does not match approved" do
|
21
|
+
Approvals.reporter(CleanupReporter.new);
|
22
|
+
lambda { Approvals.approve("should fail with mismatch") }.should raise_error(ApprovalError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise missing approval error if has not been approved yet" do
|
26
|
+
Approvals.reporter(CleanupReporter.new);
|
27
|
+
lambda { Approvals.approve("should fail with a missing ") }.should raise_error(ApprovalError)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "Multiple describes" do
|
31
|
+
it "should approve multiple describes" do
|
32
|
+
Approvals.approve("multiple describes")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "lists" do
|
37
|
+
it "should write arrays" do
|
38
|
+
Approvals.approve_list("name",["tom","dick","harry"])
|
39
|
+
end
|
40
|
+
it "should show empty lists" do
|
41
|
+
Approvals.approve_list("tv", [])
|
42
|
+
end
|
43
|
+
it "should write maps" do
|
44
|
+
Approvals.approve_map(:name=> "harry", :age => 25, :sex => "male")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "xml" do
|
49
|
+
it "should be pretty" do
|
50
|
+
Approvals.approve_xml('<?xml version="1.0" encoding="ISO-8859-1"?><data><a><b>Bee</b><c>Sea</c></a></data>')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "DiffReporter" do
|
55
|
+
it "should launch" do
|
56
|
+
base = "approval_tests/spec/"
|
57
|
+
# DiffReporter.instance.report("approval_tests/spec/a.txt", "approval_tests/spec/b.txt")
|
58
|
+
end
|
59
|
+
it "should create and launch" do
|
60
|
+
base = "approval_tests/spec/"
|
61
|
+
File.delete("#{base}c.txt") if File.exists?("#{base}c.txt")
|
62
|
+
# DiffReporter.instance.report("#{base}c.txt", "#{base}a.txt")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
describe "Approvals", "using approval blocks" do
|
71
|
+
approve "the last statement" do
|
72
|
+
"approve this"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
approve this
|
@@ -0,0 +1 @@
|
|
1
|
+
approve this
|
data/spec/spec.opts
ADDED
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
__DIR__ = File.join(File.dirname(__FILE__))
|
5
|
+
$LOAD_PATH.unshift __DIR__ unless
|
6
|
+
$LOAD_PATH.include?(__DIR__) ||
|
7
|
+
$LOAD_PATH.include?(File.expand_path(__DIR__))
|
8
|
+
|
9
|
+
require 'cleanup_reporter'
|
10
|
+
|
11
|
+
__DIR__ = File.join(__DIR__, "..", "lib")
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift __DIR__ unless
|
14
|
+
$LOAD_PATH.include?(__DIR__) ||
|
15
|
+
$LOAD_PATH.include?(File.expand_path(__DIR__))
|
16
|
+
|
17
|
+
require 'approval_tests'
|
18
|
+
include ApprovalTests
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: approval_tests
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Gilkerson, Llewellyn Falco
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-03 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Approval testing library for ruby
|
17
|
+
email: approvaltests@dangilkerson.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- Rakefile
|
27
|
+
- VERSION
|
28
|
+
- approval_tests.gemspec
|
29
|
+
- lib/approval_tests.rb
|
30
|
+
- lib/approval_tests/approvals.rb
|
31
|
+
- lib/approval_tests/approvers/file_approver.rb
|
32
|
+
- lib/approval_tests/extensions/rspec.rb
|
33
|
+
- lib/approval_tests/namers/rspec_namer.rb
|
34
|
+
- lib/approval_tests/reporters/diff_reporter.rb
|
35
|
+
- lib/approval_tests/reporters/quiet_reporter.rb
|
36
|
+
- lib/approval_tests/reporters/text_mate_reporter.rb
|
37
|
+
- lib/approval_tests/writers/html_writer.rb
|
38
|
+
- lib/approval_tests/writers/text_writer.rb
|
39
|
+
- lib/approval_tests/writers/xml_writer.rb
|
40
|
+
- spec/a.txt
|
41
|
+
- spec/approvals_lists_should_show_empty_lists.approved.txt
|
42
|
+
- spec/approvals_lists_should_write_arrays.approved.txt
|
43
|
+
- spec/approvals_lists_should_write_maps.approved.txt
|
44
|
+
- spec/approvals_multiple_describes_should_approve_multiple_describes.approved.txt
|
45
|
+
- spec/approvals_should_approve_shared_behaviors.approved.txt
|
46
|
+
- spec/approvals_should_successfully_approve_text.approved.txt
|
47
|
+
- spec/approvals_spec.rb
|
48
|
+
- spec/approvals_using_approval_blocks.approved.txt
|
49
|
+
- spec/approvals_using_approval_blocks_the_last_statement.approved.txt
|
50
|
+
- spec/approvals_xml_should_be_pretty.approved.txt
|
51
|
+
- spec/b.txt
|
52
|
+
- spec/cleanup_reporter.rb
|
53
|
+
- spec/spec.opts
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/approvaltests/approval_tests
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project: approvaltests
|
79
|
+
rubygems_version: 1.3.4
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Approval testing library
|
83
|
+
test_files:
|
84
|
+
- spec/approvals_spec.rb
|
85
|
+
- spec/cleanup_reporter.rb
|
86
|
+
- spec/spec_helper.rb
|