Skip to content

Instantly share code, notes, and snippets.

@thbar
Last active March 4, 2017 02:09
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbar/7843643 to your computer and use it in GitHub Desktop.
Save thbar/7843643 to your computer and use it in GitHub Desktop.
Integration testing of a golang app with rspec and capybara-webkit.
module GoBuild
extend self
def build(file)
process = ChildProcess.build('go', 'build', file)
err = Tempfile.new('stderr-spec')
process.io.stderr = err
process.start
process.poll_for_exit(10)
err.rewind
unless process.exit_code == 0
fail err.read
end
end
end
require 'capybara/rspec'
require 'capybara/webkit'
require 'childprocess'
require 'support/quiet_webkit'
require 'support/go_build'
Capybara.javascript_driver = :quiet_webkit
RSpec.configure do |config|
config.before(:all) do
GoBuild.build('server.go')
$child_process = ChildProcess.build('./server')
$child_process.start
Capybara.app_host = 'http://localhost:8080'
end
config.before(:each) do
fail "App is down" unless $child_process.alive?
end
config.after(:all) do
$child_process.stop if $child_process
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment