Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Nov 29, 2024
1 parent f8a36c1 commit b9f8193
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/integration/background_stdin_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require "test_helper"

class BackgroundStdinTest < Minitest::Test
def test_background_stdin_write
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
dir = Pathname(dir)
script = dir.join("script.rb")
script.write <<~'EOF'
$stdout.sync = true
print "> "
while line = gets
puts line
if line.strip == "exit"
puts "Bye"
return
else
puts "You said: #{line}"
end
print "> "
end
EOF

source_path = dir.join("RUNDOC.md")
source_path.write <<~EOF
```
:::>- background.start("ruby #{script}",
name: "script",
wait: ">",
timeout: 15
)
:::-- background.stdin_write("hello", name: "script", wait: "hello")
:::-- background.stdin_write("exit", name: "script", wait: "exit")
:::>> background.stop(name: "script")
```
EOF

io = StringIO.new
Rundoc::CLI.new(
io: io,
source_path: source_path,
on_success_dir: dir.join(SUCCESS_DIRNAME)
).call

readme = dir.join(SUCCESS_DIRNAME).join("README.md").read
expected = <<~EOF
> hello
You said: hello
> exit
Bye
EOF
assert readme.include?(expected)
end
end
end
end

0 comments on commit b9f8193

Please sign in to comment.