Unit Tests | Ruby#
Warning “circular require considered harmful”#
This problem seems to only shows up if you use
ruby -w to run a given program.
Something like this:
# # add.rb # ## # $ gem install rspec # $ rspec add.rb ## require 'rspec' def add(x, y) x + y end describe 'add()' do it 'should add x and y' do expect(add(-1, 1)).to eq 0 end end
This is OK and works well.
Except if we then try to include the
add.rb module into another module because you want to reuse the
add() method, then we might get strange warnings with
# # sum_arr.rb # require 'awesome_print' require_relative './add'
$ ruby -w sum-arr.rb warning: loading in progress, circular require considered harmful
sum_arr.rb does nothing but to require the two other files.
In this case, it seems something doesn’t go along well between
sum_arr.rb or not requiring
add.rb causes the warning to cease.