Skip to content

Commit

Permalink
[spec] run the chat server as part of rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Aug 8, 2017
1 parent 18a8ce6 commit 2b2f64a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
18 changes: 0 additions & 18 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,4 @@ require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :server do
pid = 0
Bundler.with_clean_env do
nul = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'nul' : '/dev/null'
pid = spawn "bundle exec puma 'spec/chat_server.ru' 2>#{nul}"
end

at_exit do
$stderr.puts "Killing pid #{pid}"
Process.kill('KILL', pid)
Process.wait(pid)
end

sleep 3
end

task :spec => :server

task default: :spec
11 changes: 10 additions & 1 deletion spec/chat_server.ru → spec/chat_server_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@

# Run the Chat Sinatra app.
require "#{chat_example_path}/chat"
run Chat

RSpec.configure do |config|
config.around(:all) do |example|
server = Thread.new { Chat.run! }

example.run

server.kill
end
end

0 comments on commit 2b2f64a

Please sign in to comment.