Skip to content

Commit 1bb7a43

Browse files
committed
Add test coverage for Errors#to_json
1 parent 210198e commit 1bb7a43

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
@@ -78,7 +78,18 @@
7878
it "returrns the full messages array" do
7979
expect(errors.full_messages).to eq ["Attr1 has an error", "Attr2 has an error", "Attr2 has two errors"]
8080
end
81-
8281
end
8382

83+
describe "#to_json" do
84+
it "groups errors by key values" do
85+
errors.add :attr1, 'has an error'
86+
errors.add :attr2, 'has an error'
87+
errors.add :attr2, 'has two errors'
88+
89+
expect(JSON.parse(errors.to_json)).to eq(
90+
"attr1" => ["has an error"],
91+
"attr2" => ["has an error", "has two errors"]
92+
)
93+
end
94+
end
8495
end

0 commit comments

Comments
 (0)