1 require_relative '../spec_helper'
3 describe "The -e command line option" do
4 it "evaluates the given string" do
5 ruby_exe("puts 'foo'").chomp.should == "foo"
8 it "joins multiple strings with newlines" do
9 ruby_exe(nil, args: %Q{-e "puts 'hello" -e "world'" 2>&1}).chomp.should == "hello\nworld"
12 it "uses 'main' as self" do
13 ruby_exe("puts self", escape: false).chomp.should == "main"
16 it "uses '-e' as file" do
17 ruby_exe("puts __FILE__", escape: false).chomp.should == "-e"
20 it "uses '-e' in $0" do
21 system(*ruby_exe, '-e', 'exit $0 == "-e"').should == true
24 #needs to test return => LocalJumpError
26 describe "with -n and an Integer range" do
28 @script = "-ne 'print if %s' #{fixture(__FILE__, "conditional_range.txt")}"
31 it "mimics an awk conditional by comparing an inclusive-end range with $." do
32 ruby_exe(nil, args: (@script % "2..3")).should == "2\n3\n"
33 ruby_exe(nil, args: (@script % "2..2")).should == "2\n"
36 it "mimics a sed conditional by comparing an exclusive-end range with $." do
37 ruby_exe(nil, args: (@script % "2...3")).should == "2\n3\n"
38 ruby_exe(nil, args: (@script % "2...2")).should == "2\n3\n4\n5\n"