Created
December 6, 2012 10:04
-
-
Save natritmeyer/4223402 to your computer and use it in GitHub Desktop.
Sinatra Stubs and Rake Tasks
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 '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 |
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 '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 |
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 './lib/stubs/schedule.rb' | |
run ScheduleStub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment