diff options
Diffstat (limited to 'spec/ruby/core/argf/filename_spec.rb')
| -rw-r--r-- | spec/ruby/core/argf/filename_spec.rb | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/spec/ruby/core/argf/filename_spec.rb b/spec/ruby/core/argf/filename_spec.rb index f7ebafa7c5..f4b6e922c6 100644 --- a/spec/ruby/core/argf/filename_spec.rb +++ b/spec/ruby/core/argf/filename_spec.rb @@ -1,6 +1,30 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/filename', __FILE__) +require_relative '../../spec_helper' describe "ARGF.filename" do - it_behaves_like :argf_filename, :filename + before :each do + @file1 = fixture __FILE__, "file1.txt" + @file2 = fixture __FILE__, "file2.txt" + end + + # NOTE: this test assumes that fixtures files have two lines each + it "returns the current file name on each file" do + argf [@file1, @file2] do + result = [] + # returns first current file even when not yet open + result << @argf.filename + result << @argf.filename while @argf.gets + # returns last current file even when closed + result << @argf.filename + + result.map! { |f| File.expand_path(f) } + result.should == [@file1, @file1, @file1, @file2, @file2, @file2] + end + end + + # NOTE: this test assumes that fixtures files have two lines each + it "sets the $FILENAME global variable with the current file name on each file" do + script = fixture __FILE__, "filename.rb" + out = ruby_exe(script, args: [@file1, @file2]) + out.should == "#{@file1}\n#{@file1}\n#{@file2}\n#{@file2}\n#{@file2}\n" + end end |
