spec/approvals_spec.rb in approvals-0.0.22 vs spec/approvals_spec.rb in approvals-0.0.24
- old
+ new
@@ -49,10 +49,36 @@
end
Approvals.verify hello, :namer => namer
end
+ context "custom writer" do
+ let(:hello) { Object.new }
+
+ class MyCustomWriter < Approvals::Writers::TextWriter
+ def format(data)
+ filter(data)
+ end
+
+ def filter(data)
+ data.to_s.chars.reject {|c| c =~ /[a-zA-Z0-9]/}
+ end
+ end
+
+ it "verifies a complex object" do
+ Approvals.verify hello, :namer => namer, :format => "MyCustomWriter"
+ end
+
+ it "raises an error with an uninitialized custom writer class" do
+ expect{
+ Approvals.verify hello, :namer => namer, :format => "UninitializedWriter"
+ }.to raise_error.with_message(
+ /Please define a custom writer as outlined in README section 'Customizing formatted output':/
+ )
+ end
+ end
+
it "verifies html" do
html = <<-HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"><html><head><title>Approval</title></head><body><h1>An Approval</h1><p>It has a paragraph</p></body></html>
HTML
Approvals.verify html, :format => :html, :namer => namer
@@ -77,9 +103,14 @@
it "verifies json" do
json = '{"pet":{"species":"turtle","color":"green","name":"Anthony"}}'
Approvals.verify json, :format => :json, :namer => namer
end
+ it "ignores whitespace differences in json" do
+ hash = { foo: {} }
+
+ Approvals.verify hash, :format => :json, :namer => namer
+ end
it "verifies json and is newline agnostic" do
json = '{"pet":{"species":"turtle","color":"green","name":"Anthony"}}'
Approvals.verify json, :format => :json, :namer => namer
end