forked from caelum/restfulie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
119 lines (98 loc) · 2.57 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require 'rubygems'
require 'rubygems/specification'
require 'rake'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rspec'
require 'rspec/core'
require 'rspec/core/rake_task'
require "bundler"
Bundler::GemHelper.install_tasks
require File.join(File.dirname(__FILE__), 'lib', 'restfulie', 'version')
GEM = "restfulie"
GEM_VERSION = Restfulie::VERSION
module FakeServer
def self.wait_server(port=3000)
(1..15).each do
begin
Net::HTTP.get(URI.parse("http://localhost:#{port}/"))
return
rescue
sleep 1
end
end
raise "Waited for the server but it did not finish"
end
def self.start_sinatra
IO.popen("cd tests && ruby ./spec/requests/fake_server.rb") do |pipe|
wait_server 4567
yield
Process.kill 'INT', pipe.pid
end
end
def self.run(setup, process)
success = IO.popen(setup) do |pipe|
wait_server
success = system "rake spec"
Process.kill 'INT', pipe.pid
success
end
if !success
raise "Some of the specs failed"
end
end
def self.start_server_and_run_spec(target_dir)
success = Dir.chdir(File.join(File.dirname(__FILE__), target_dir)) do
system('bundle install')
system('rake db:drop db:create db:migrate')
self.run "rails server", "rake spec"
end
end
end
# optionally loads a task if the required gems exist
def optionally
begin
yield
rescue LoadError; end
end
namespace :test do
task :spec do
FakeServer.start_sinatra do
FakeServer.start_server_and_run_spec "tests"
end
end
task :integration do
FakeServer.start_server_and_run_spec "full-examples/rest_from_scratch/part_1"
FakeServer.start_server_and_run_spec "full-examples/rest_from_scratch/part_2"
FakeServer.start_server_and_run_spec "full-examples/rest_from_scratch/part_3"
end
task :sinatra do
FakeServer.start_sinatra do
puts "Press something to quit"
gets
end
end
task :all => ["spec","integration"]
end
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ['--colour', '--format progress']
end
Rake::RDocTask.new("rdoc") do |rdoc|
rdoc.options << '--line-numbers' << '--inline-source'
end
optionally do
require 'yard'
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/restfulie/**/*.rb', 'README.textile']
end
end
desc "Create a gemspec file"
task :make_spec do
File.open("#{GEM}.gemspec", "w") do |file|
file.puts spec.to_ruby
end
end
desc "Runs everything"
task :all => ["install", "test:spec"]
desc "Default build will run specs"
task :default => :all