Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
require '../src/absrequire' describe 'absrequire' do before :all do @original_cwd = File.expand_path(File.dirname(__FILE__)) end before do @cwd = File.join(@original_cwd, 'fixtures') Dir.chdir @cwd @old_load_paths = $:.dup $LOADED_SCRIPTS.replace({}) end after do $:.replace(@old_load_paths) end it 'should add an unloaded file to $LOADED_SCRIPTS' do absrequire 'bar' $LOADED_SCRIPTS[File.join(@cwd, 'bar.rb')].should == 'bar' end it "should load an unloaded file" do should_receive(:load).with(File.join(@cwd, 'bar.rb')) absrequire 'bar' end it "should ignore subsequent calls to absrequire with the same argument" do should_receive(:load).with(File.join(@cwd, 'bar.rb')).once absrequire 'bar' absrequire 'bar' end it "should not load the same file more than once given different require paths" do should_receive(:load).with(File.join(@cwd, 'bar.rb')).once absrequire 'bar' absrequire 'lib/../bar' end it "should not allow files to shadow each other" do $:.replace(['lib', '.']) should_receive(:load).with(File.join(@cwd, 'lib', 'bar.rb')) should_receive(:load).with(File.join(@cwd, 'bar.rb')) absrequire 'lib/bar' absrequire 'bar' end it "should respect the load paths array when considering load order" do should_receive(:load).with(File.join(@cwd, 'lib', 'bar.rb')) $:.replace(['lib', '.']) absrequire 'bar' end it "should allow loading files that don't end in '.rb'" do should_receive(:load).with(File.join(@cwd, 'foo')) absrequire 'foo' end it "should allow loading with an explicit extension" do should_receive(:load).with(File.join(@cwd, 'lib', 'bar.rb')) absrequire 'lib/bar.rb' end it "should not prevent loading different files that were mapped from the same argument to absrequire" do should_receive(:load).with(File.join(@cwd, 'bar.rb')) should_receive(:load).with(File.join(@cwd, 'lib', 'bar.rb')) absrequire 'bar' Dir.chdir 'lib' absrequire 'bar' end end
From the Design Piracy series on my blog: