|
2 | 2 | require File.expand_path('../fixtures/classes', __FILE__)
|
3 | 3 |
|
4 | 4 | describe 'Thread::Backtrace::Location#path' do
|
5 |
| - before :each do |
6 |
| - @frame = ThreadBacktraceLocationSpecs.locations[0] |
| 5 | + context 'outside a main script' do |
| 6 | + it 'returns an absolute path' do |
| 7 | + frame = ThreadBacktraceLocationSpecs.locations[0] |
| 8 | + |
| 9 | + frame.path.should == __FILE__ |
| 10 | + end |
7 | 11 | end
|
8 | 12 |
|
9 |
| - it 'returns the absolute path of the call frame' do |
10 |
| - @frame.path.should == __FILE__ |
| 13 | + context 'in a main script' do |
| 14 | + before do |
| 15 | + @script = fixture(__FILE__, 'main.rb') |
| 16 | + end |
| 17 | + |
| 18 | + context 'when the script is in the working directory' do |
| 19 | + before do |
| 20 | + @directory = File.dirname(@script) |
| 21 | + end |
| 22 | + |
| 23 | + context 'when using a relative script path' do |
| 24 | + it 'returns a path relative to the working directory' do |
| 25 | + ruby_exe('main.rb', :dir => @directory).should == 'main.rb' |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + context 'when using an absolute script path' do |
| 30 | + it 'returns an absolute path' do |
| 31 | + ruby_exe(@script, :dir => @directory).should == @script |
| 32 | + end |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + context 'when the script is in a sub directory of the working directory' do |
| 37 | + context 'when using a relative script path' do |
| 38 | + it 'returns a path relative to the working directory' do |
| 39 | + path = 'fixtures/main.rb' |
| 40 | + directory = File.dirname(__FILE__) |
| 41 | + |
| 42 | + ruby_exe(path, :dir => directory).should == path |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context 'when using an absolute script path' do |
| 47 | + it 'returns an absolute path' do |
| 48 | + ruby_exe(@script).should == @script |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + context 'when the script is outside of the working directory' do |
| 54 | + before do |
| 55 | + @parent_dir = tmp('path_outside_pwd') |
| 56 | + @sub_dir = File.join(@parent_dir, 'sub') |
| 57 | + @script = File.join(@parent_dir, 'main.rb') |
| 58 | + source = fixture(__FILE__, 'main.rb') |
| 59 | + |
| 60 | + mkdir_p(@sub_dir) |
| 61 | + |
| 62 | + cp(source, @script) |
| 63 | + end |
| 64 | + |
| 65 | + after do |
| 66 | + rm_r(@script) |
| 67 | + rm_r(@sub_dir) |
| 68 | + rm_r(@parent_dir) |
| 69 | + end |
| 70 | + |
| 71 | + context 'when using a relative script path' do |
| 72 | + it 'returns a path relative to the working directory' do |
| 73 | + ruby_exe('../main.rb', :dir => @sub_dir).should == '../main.rb' |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + context 'when using an absolute path' do |
| 78 | + it 'returns an absolute path' do |
| 79 | + ruby_exe(@script).should == @script |
| 80 | + end |
| 81 | + end |
| 82 | + end |
11 | 83 | end
|
12 | 84 | end
|
0 commit comments