forked from caelum/restfulie
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
197 lines (170 loc) · 5.04 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# encoding: UTF-8
require 'rubygems'
require 'rubygems/specification'
require 'rake'
require 'rake/gempackagetask'
require 'spec/rake/spectask'
require 'rake/rdoctask'
require File.expand_path('lib/restfulie')
GEM = "restfulie"
GEM_VERSION = Restfulie::VERSION
SUMMARY = "Hypermedia aware resource based library in ruby (client side) and ruby on rails (server side)."
AUTHOR = "Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon"
EMAIL = "[email protected]"
HOMEPAGE = "http://restfulie.caelumobjects.com"
spec = Gem::Specification.new do |s|
s.name = GEM
s.version = GEM_VERSION
s.platform = Gem::Platform::RUBY
s.summary = SUMMARY
s.require_paths = ['lib']
s.files = FileList['lib/**/*.rb', '[A-Z]*', 'lib/**/*.rng'].to_a
s.add_dependency("nokogiri", [">= 1.4.2"])
s.add_dependency("actionpack", [">= 2.3.2"])
s.add_dependency("activesupport", [">= 2.3.2"])
s.add_dependency("responders_backport", ["~> 0.1.0"])
s.add_dependency("json_pure", [">= 1.2.4"])
s.author = AUTHOR
s.email = EMAIL
s.homepage = HOMEPAGE
end
# optionally loads a task if the required gems exist
def optionally
begin
yield
rescue LoadError; end
end
def execute_process(name)
sh "ruby ./spec/units/client/#{name}.rb &"
wait_server 4567
%x(ps -ef | grep #{name}).split[1]
end
def process(name)
%x(ps -ef | grep #{name} | grep -v grep).split[1] || execute_process(name)
end
def start_server_and_invoke_test(task_name)
kill_server "fake_server"
pid = process "fake_server"
Rake::Task[task_name].invoke
kill_server "fake_server"
end
def kill_server(where)
c = `(ps -ef | grep '#{where}')`.split(/\n/)
c.each do |line|
pid = line.split[1]
system "kill -9 #{pid}"
end
end
def 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
desc 'Start server'
task :server do
process 'fake_server'
end
namespace :test do
desc "Execute integration Order tests"
task :integration do
integration_path = "spec/integration/order/server"
Dir.chdir(File.join(File.dirname(__FILE__), integration_path)) do
system('rake db:drop db:create db:migrate')
system('rake')
end
end
namespace :spec do
spec_opts = ['--options', File.join(File.dirname(__FILE__) , 'spec', 'units', 'spec.opts')]
Spec::Rake::SpecTask.new(:all) do |t|
t.spec_files = FileList['spec/units/**/*_spec.rb']
t.spec_opts = spec_opts
end
Spec::Rake::SpecTask.new(:common) do |t|
t.spec_files = FileList['spec/common/**/*_spec.rb']
t.spec_opts = spec_opts
end
Spec::Rake::SpecTask.new(:client) do |t|
t.spec_files = FileList['spec/units/client/**/*_spec.rb']
t.spec_opts = spec_opts
end
Spec::Rake::SpecTask.new(:server) do |t|
t.spec_files = FileList['spec/units/server/**/*_spec.rb']
t.spec_opts = spec_opts
end
end
namespace :rcov do
Spec::Rake::SpecTask.new('rcov') do |t|
options_file = File.expand_path('spec/units/spec.opts')
t.spec_opts = %w(-fs -fh:doc/specs.html --color)
t.spec_files = FileList['spec/units/**/*_spec.rb']
t.rcov = true
t.rcov_opts = ["-e", "/Library*", "-e", "~/.rvm", "-e", "spec", "-i", "bin"]
end
desc 'Run coverage test with fake server'
task :run do
start_server_and_invoke_test('test:rcov:rcov')
end
end
namespace :run do
task :all do
start_server_and_invoke_test('test:spec:all')
puts "Execution integration tests... (task test:integration)"
Rake::Task["test:integration"].invoke()
Rake::Task["test:examples"].invoke()
end
task :common do
start_server_and_invoke_test('test:spec:common')
end
task :client do
start_server_and_invoke_test('test:spec:client')
end
task :server do
start_server_and_invoke_test('test:spec:server')
end
task :rcov do
start_server_and_invoke_test('test:rcov:rcov')
end
end
desc "runs all example tests"
task :examples do
Rake::Task["install"].invoke()
kill_server "script/server"
enter_dir = "cd full-examples/rest_from_scratch/part_3"
system "#{enter_dir} && rake db:reset db:seed && script/server -d"
wait_server
system "#{enter_dir} && rake spec"
kill_server "script/server"
end
end
Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
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 "Install the gem locally"
task :install => [:package] do
sh %{gem install pkg/#{GEM}-#{GEM_VERSION} -l}
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 "Builds the project"
task :build => :spec
desc "Default build will run specs"
task :default => ['test:run:all']