You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kubsu-sm5-ruby/lab1/spec/spec_03.rb

35 lines
1.4 KiB

require_relative '../src/03_fork_02_with_exec_pasted_command.rb'
RSpec.describe "Main" do
before do
allow(STDIN).to receive(:gets).and_return("ruby\n", "puts 'Hello from Ruby!'\n", "echo 'Hello from shell!'\n")
allow(ARGV).to receive(:[]).with(0).and_return("test_user")
end
it "greets the user and processes ruby input" do
expect { main() }.to output(/Hello my catgirl test_user! \nWhat is your love language?\nruby\nc++\npy\одлиза \n/).to_stdout
end
it "executes valid ruby command" do
allow(STDIN).to receive(:gets).and_return("ruby\n", "puts 'Hello from Ruby!'\n")
expect { main() }.to output(/Hello from Ruby!/).to_stdout
end
it "handles ruby command execution error" do
allow(STDIN).to receive(:gets).and_return("ruby\n", "invalid_ruby_code\n")
expect { main() }.to output(/Ошибка выполнения команды Ruby: undefined local variable or method `invalid_ruby_code'/).to_stdout
end
it "executes shell command" do
allow(STDIN).to receive(:gets).and_return("ruby\n", "puts 'Hello from Ruby!'\n", "echo 'Hello from shell!'\n")
expect(main()).to include("Hello from shell!")
end
it "returns correct output for unknown programming language" do
allow(STDIN).to receive(:gets).and_return("java\n")
expect { main() }.to output(/Неизвестный язык: java/).to_stdout
end
end