Last active
March 4, 2017 02:09
-
-
Save thbar/7843643 to your computer and use it in GitHub Desktop.
Integration testing of a golang app with rspec and capybara-webkit.
This file contains hidden or 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
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 |
This file contains hidden or 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 '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