Commit f9ac33d85270a2d4e68e2125b10d08697713ca24
1 parent
6451452d
Exists in
master
and in
29 other branches
A less fragile test for User#data_hash keys
The previous implementation will fail if you add new keys. Each new key should be tests separately instead. (ActionItem1608)
Showing
1 changed file
with
5 additions
and
5 deletions
Show diff stats
test/unit/user_test.rb
... | ... | @@ -312,11 +312,11 @@ class UserTest < Test::Unit::TestCase |
312 | 312 | assert user.respond_to?(:data_hash) |
313 | 313 | end |
314 | 314 | |
315 | - should "data_hash method have the following keys" do | |
316 | - person = create_user('coldplay').person | |
317 | - expected_keys = ['login','is_admin','since_month', 'since_year', 'email_domain','friends_list','amount_of_friends', 'enterprises'] | |
318 | - assert_equal [], expected_keys - person.user.data_hash.keys | |
319 | - assert_equal [], person.user.data_hash.keys - expected_keys | |
315 | + should "data_hash method have at least the following keys" do | |
316 | + user = create_user('coldplay') | |
317 | + expected_keys = ['login','is_admin','since_month', 'since_year', 'email_domain','friends_list','amount_of_friends', 'enterprises', 'bli'] | |
318 | + data = user.data_hash | |
319 | + assert(expected_keys.all? { |k| data.has_key?(k) }, "User#data_hash expected to have at least the following keys: #{expected_keys.inspect} (missing: #{(expected_keys-data.keys).inspect})") | |
320 | 320 | end |
321 | 321 | |
322 | 322 | should "data_hash friends_list method have the following keys" do | ... | ... |