Last active
February 26, 2020 08:33
-
-
Save kamiazya/bf6a12271631a5f29bb07f068f921c67 to your computer and use it in GitHub Desktop.
RSpec demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = gets.to_i | |
b,c = gets.chomp.split(" ").map(&:to_i) | |
s = gets.chomp | |
print("#{a + b + c} #{s}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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