diff options
Diffstat (limited to 'spec/ruby/language/execution_spec.rb')
| -rw-r--r-- | spec/ruby/language/execution_spec.rb | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/ruby/language/execution_spec.rb b/spec/ruby/language/execution_spec.rb new file mode 100644 index 0000000000..51bcde62e8 --- /dev/null +++ b/spec/ruby/language/execution_spec.rb @@ -0,0 +1,93 @@ +require_relative '../spec_helper' + +describe "``" do + it "returns the output of the executed sub-process" do + ip = 'world' + `echo disc #{ip}`.should == "disc world\n" + end + + it "can be redefined and receive a frozen string as argument" do + called = false + runner = Object.new + + runner.singleton_class.define_method(:`) do |str| + called = true + + str.should == "test command" + str.frozen?.should == true + end + + runner.instance_exec do + `test command` + end + + called.should == true + end + + it "the argument isn't frozen if it contains interpolation" do + called = false + runner = Object.new + + runner.singleton_class.define_method(:`) do |str| + called = true + + str.should == "test command" + str.frozen?.should == false + str << "mutated" + end + + 2.times do + runner.instance_exec do + `test #{:command}` # rubocop:disable Lint/LiteralInInterpolation + end + end + + called.should == true + end +end + +describe "%x" do + it "is the same as ``" do + ip = 'world' + %x(echo disc #{ip}).should == "disc world\n" + end + + it "can be redefined and receive a frozen string as argument" do + called = false + runner = Object.new + + runner.singleton_class.define_method(:`) do |str| + called = true + + str.should == "test command" + str.frozen?.should == true + end + + runner.instance_exec do + %x{test command} + end + + called.should == true + end + + it "the argument isn't frozen if it contains interpolation" do + called = false + runner = Object.new + + runner.singleton_class.define_method(:`) do |str| + called = true + + str.should == "test command" + str.frozen?.should == false + str << "mutated" + end + + 2.times do + runner.instance_exec do + %x{test #{:command}} # rubocop:disable Lint/LiteralInInterpolation + end + end + + called.should == true + end +end |
