[ruby/prism] Pop lex mode for heredocs in the lexer, not the parser
[ruby.git] / spec / ruby / command_line / dash_r_spec.rb
blob9f673c53dcc097152000c1104607b497d03002a0
1 require_relative '../spec_helper'
3 describe "The -r command line option" do
4   before :each do
5     @script = fixture __FILE__, "require.rb"
6     @test_file = fixture __FILE__, "test_file"
7   end
9   it "requires the specified file" do
10     out = ruby_exe(@script, options: "-r #{@test_file}")
11     out.should include("REQUIRED")
12     out.should include(@test_file + ".rb")
13   end
15   it "requires the file before parsing the main script" do
16     out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), options: "-r #{@test_file}", args: "2>&1", exit_status: 1)
17     $?.should_not.success?
18     out.should include("REQUIRED")
20     # it's tempting not to rely on error message and rely only on exception class name,
21     # but CRuby before 3.2 doesn't print class name for syntax error
22     out.should include_any_of("syntax error", "SyntaxError")
23   end
25   it "does not require the file if the main script file does not exist" do
26     out = `#{ruby_exe.to_a.join(' ')} -r #{@test_file} #{fixture(__FILE__, "does_not_exist.rb")} 2>&1`
27     $?.should_not.success?
28     out.should_not.include?("REQUIRED")
29     out.should.include?("No such file or directory")
30   end
31 end