This repository has been archived by the owner on Sep 12, 2018. It is now read-only.
forked from ruby-rdf/spira
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.spec
76 lines (57 loc) · 1.64 KB
/
errors.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require File.dirname(File.expand_path(__FILE__)) + '/spec_helper'
describe Spira::Errors do
before :all do
end
context "when instantiating" do
it "should be instantiable" do
Spira::Errors.new.should_not be_nil
end
it "should not have any errors to start" do
Spira::Errors.new.should be_empty
end
end
context "when adding errors" do
before :each do
@errors = Spira::Errors.new
end
it "should allow adding errors" do
lambda {@errors.add(:field, "cannot be null")}.should_not raise_error
end
end
context "when retrieving errors" do
before :each do
@errors = Spira::Errors.new
@errors.add(:field, "cannot be null")
end
it "should not be empty" do
@errors.should_not be_empty
end
it "have errors for a field with errors" do
@errors.any_for?(:field).should be_true
end
it "should not have errors for a field without errors" do
@errors.any_for?(:other).should be_false
end
it "should have the correct error name for a given error" do
@errors.for(:field).should == ["cannot be null"]
end
it "should provide a list of all errors" do
@errors.should respond_to :each
@errors.each.should == ["field cannot be null"]
end
end
context "when clearing errors" do
before :each do
@errors = Spira::Errors.new
@errors.add(:field, "cannot be null")
end
it "should respond to :clear" do
@errors.should respond_to :clear
end
it "should clear errors on #clear" do
@errors.any_for?(:field).should be_true
@errors.clear
@errors.should be_empty
end
end
end