开发者

What is the best way to test interface of a command line application with Ruby?

开发者 https://www.devze.com 2023-04-12 01:30 出处:网络
Say that I have simple command line application, that looks something like this # solution.rb puts \"Enter your password:\"

Say that I have simple command line application, that looks something like this

# solution.rb

puts "Enter your password:"
password = gets

if password == "secret"
  puts "you're logged in"
else
  puts "wrong p开发者_开发百科assword"
end

and I need to create a script, that will test if it works correctly. I don't want to test the code itself, only it's user interface.

It would be a kind of homework checker, where a user can submit a script which is supposed to handle a certain task in a certain way, and this script will test it with given inputs.

The idea is, that I would run something like

ruby tester.rb solution.rb

and the tester.rb would first run it and pass secret and check if it got you're logged in as a response, and the same thing for the second case.

What would be the best way to achieve this?


I highly recommend you check out cucumber with aruba, which is specifically designed for this sort of thing.

There's a quick intro which might be a good place to start.

0

精彩评论

暂无评论...
验证码 换一张
取 消