Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
Created December 6, 2012 10:04
Show Gist options
  • Save natritmeyer/4223402 to your computer and use it in GitHub Desktop.
Save natritmeyer/4223402 to your computer and use it in GitHub Desktop.
Sinatra Stubs and Rake Tasks
require 'rspec/core/rake_task'
namespace :stubs do
namespace :schedule do
pid_file_path = "lib/stubs/schedule.pid"
desc "Start the schedule stub"
task :start do
`rackup -D lib/stubs/schedule.ru -P #{pid_file_path} -p 2000`
end
desc "Stop the schedule stub"
task :stop do
raise "Stub not running" unless File.exist? pid_file_path
pid = File.open(pid_file_path).read
`kill -9 #{pid}`
File.delete pid_file_path
end
desc "Restart the schedule stub"
task :restart do
Rake::Task["stubs:schedule:stop"].invoke
Rake::Task["stubs:schedule:start"].invoke
end
end
end
require 'sinatra'
require 'sinatra/base'
require 'json'
class ScheduleStub < Sinatra::Base
before /.*/ do
content_type :json
end
get '/stuff_in_schedule' do
{ :scheduled_things => ["001", "002", "003"]}.to_json
end
end
require './lib/stubs/schedule.rb'
run ScheduleStub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment