From 65faff5832e7549bfad6ce0f4dba2c8c7ce70364 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan <tgx_world@hotmail.com> Date: Fri, 19 Oct 2018 14:31:17 +0800 Subject: [PATCH] DEV: Improve specs to provide a better error message. --- .../web_hook_topic_view_serializer_spec.rb | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/spec/serializers/web_hook_topic_view_serializer_spec.rb b/spec/serializers/web_hook_topic_view_serializer_spec.rb index d7ee1005555..ff1ac0cfdbc 100644 --- a/spec/serializers/web_hook_topic_view_serializer_spec.rb +++ b/spec/serializers/web_hook_topic_view_serializer_spec.rb @@ -11,20 +11,47 @@ RSpec.describe WebHookTopicViewSerializer do ) end - it 'should only include the required keys' do - count = serializer.as_json.keys.count - difference = count - 30 + before do + SiteSetting.tagging_enabled = true + end - expect(difference).to eq(0), lambda { - message = "" - - if difference < 0 - message << "#{difference * -1} key(s) have been removed from this serializer." - else - message << "#{difference} key(s) have been added to this serializer." - end - - message << "\nPlease verify if those key(s) are required as part of the web hook's payload." + it 'should only include the keys that are sent out in the webhook' do + expected_keys = %i{ + id + title + fancy_title + posts_count + created_at + views + reply_count + like_count + last_posted_at + visible + closed + archived + archetype + slug + category_id + word_count + deleted_at + user_id + featured_link + pinned_globally + pinned_at + pinned_until + unpinned + pinned + highest_post_number + deleted_by + bookmarked + participant_count + created_by + last_poster + tags } + + keys = serializer.as_json.keys + + expect(serializer.as_json.keys).to contain_exactly(*expected_keys) end end