Skip to content

Commit c3c3fe7

Browse files
committed
Add test coverage for Errors#to_json
1 parent 7faba28 commit c3c3fe7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

spec/simple_command/errors_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,18 @@
6666
it "returrns the full messages array" do
6767
expect(errors.full_messages).to eq ["Attr1 has an error", "Attr2 has an error", "Attr2 has two errors"]
6868
end
69-
7069
end
7170

71+
describe "#to_json" do
72+
it "groups errors by key values" do
73+
errors.add :attr1, 'has an error'
74+
errors.add :attr2, 'has an error'
75+
errors.add :attr2, 'has two errors'
76+
77+
expect(JSON.parse(errors.to_json)).to eq(
78+
"attr1" => ["has an error"],
79+
"attr2" => ["has an error", "has two errors"]
80+
)
81+
end
82+
end
7283
end

0 commit comments

Comments
 (0)