Skip to content

Instantly share code, notes, and snippets.

@kamiazya
Last active February 26, 2020 08:33
Show Gist options
  • Save kamiazya/bf6a12271631a5f29bb07f068f921c67 to your computer and use it in GitHub Desktop.
Save kamiazya/bf6a12271631a5f29bb07f068f921c67 to your computer and use it in GitHub Desktop.
RSpec demo
a = gets.to_i
b,c = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
print("#{a + b + c} #{s}\n")
require "open3"
describe 'code test' do
[
["1\n1 2\na\n", "4 1"],
["3\n1 2\na\n", "6 1"],
].each do |input, expected|
it("should return #{expected} for input #{input}") do
Open3.capture3('ruby ./src/code.rb') do |i, o, e, w|
i.write input
i.close
expect(o).to eq expected
end
end
end
end
require "open3"
def run_on_container(target, ruby_version: 'latest')
image = "ruby:#{ruby_version}"
opts = ['-a', '-v', 'src:/src:ro', '--rm']
Open3.capture3("docker run #{opts.join(' ')} #{image} /src/#{target}")
end
describe 'code test' do
[
["1\n1 2\na\n", "4 1"],
["3\n1 2\na\n", "6 1"],
].each do |input, expected|
it("should return #{expected} for input #{input}") do
run_on_container('code.rb') do |i, o, e, w|
i.write input
i.close
expect(o).to eq expected
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment