ruby on rails - Is it worth testing low-level code such as scopes? -


is profitable test "core" features such scopes , sorting? have several tests test functionality similar what's below. seems me it's testing rails core features (scopes , sorting), well-tested already.

i know may seem "opinion" question, i'm trying find out if knows miss if assume scopes/sorting tested , not valuable developers test.

my thoughts if scopes/sorting "broken", there's nothing can if rails core code broken refuse touch core code without very, reason (makes updating later on nightmare...).

i feel "safe" more tests if these tests aren't providing value, taking space , time on test suite.

# user.rb model class user < activerecord::base   scope :alphabetical, -> { order("upper(first_name), upper(last_name)") } end  # user_spec.rb spec context "scopes"   describe ".alphabetical"     "sorts first_name, last_name (a z)"       user_one = create(:user, first_name: "albert", "johnson")       user_two = create(:user, first_name: "bob", "smith")       ...        expect(user.all.alphabetical.first.first_name).to eq("albert")     end   end end 

yes, should test scope. it's not built-in functionality; had write it. sorts on 2 criteria, needs 2 tests, 1 prove sorts first name (which test above shows), , prove falls on last name when first names same.

if scope simpler, skip unit-testing if tested in acceptance or higher-level unit test. scope needs more 1 test, should in tests of scope itself, not in tests of higher-level code. if tried in tests of higher-level code hard readers find details of scope tested, , lead duplication if tests of each caller tested of functionality of scope.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -