diff --git a/lib/pry/code.rb b/lib/pry/code.rb index 82de80bf..aeaa8803 100644 --- a/lib/pry/code.rb +++ b/lib/pry/code.rb @@ -41,7 +41,7 @@ class Pry else if File.readable?(fn) f = File.open(fn, 'r') - code_type = type_from_filename(fn) + code_type ||= type_from_filename(fn) else raise MethodSource::SourceNotFoundError, "Cannot open #{fn.inspect} for reading." end diff --git a/test/test_code.rb b/test/test_code.rb index e9e4cfbb..51d3f145 100644 --- a/test/test_code.rb +++ b/test/test_code.rb @@ -23,6 +23,12 @@ describe Pry::Code do end end + should 'use the provided extension' do + temp_file('.c') do |f| + Pry::Code.from_file(f.path, :ruby).code_type.should == :ruby + end + end + should 'raise an error if the file doesn\'t exist' do proc do Pry::Code.from_file('/knalkjsdnalsd/alkjdlkq')