Skip to content

A platform for community discussion. Free, open, simple.

DEV: Improve tests to provide better errors when it fails.

Guo Xiang Tand5df1db3c469
diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb
index f582af51aa5..aba72e8de17 100644
--- a/spec/requests/posts_controller_spec.rb
+++ b/spec/requests/posts_controller_spec.rb
@@ -839,11 +839,17 @@ describe PostsController do
raw = "this is a test post 123 #{SecureRandom.hash}"
title = "this is a title #{SecureRandom.hash}"
- post "/posts.json", params: { raw: raw, title: title, wpid: 1 }
+ expect do
+ post "/posts.json", params: { raw: raw, title: title, wpid: 1 }
+ end.to change { Post.count }
+
expect(response.status).to eq(200)
- post "/posts.json", params: { raw: raw, title: title, wpid: 2 }
- expect(response).not_to be_successful
+ expect do
+ post "/posts.json", params: { raw: raw, title: title, wpid: 2 }
+ end.to_not change { Post.count }
+
+ expect(response.status).to eq(422)
end
it 'can not create a post in a disallowed category' do