feat: added tests for all tasks

main lab1
Artem-Darius Weber 4 months ago
parent b569973b38
commit c359fd755b

@ -0,0 +1,16 @@
require_relative '../src/02_user_interface.rb'
RSpec.describe "Main" do
before do
allow(STDIN).to receive(:gets).and_return("ruby\n")
end
it "greets the user and checks Ruby as language" do
expect { main() }.to output("Hello my catgirl test_user! \nWhat is your love language?\nruby\nc++\npy\nПодлиза \n").to_stdout
end
it "handles unknown language input" do
allow(STDIN).to receive(:gets).and_return("java\n")
expect { main() }.to output(/Неизвестный язык: java/).to_stdout
end
end

@ -0,0 +1,34 @@
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
Loading…
Cancel
Save