gorp 0.21.2 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/gorp.gemspec +2 -2
- data/lib/gorp/commands.rb +27 -4
- data/lib/gorp/edit.rb +2 -1
- data/lib/gorp/env.rb +10 -0
- data/lib/gorp/output.rb +1 -3
- data/lib/gorp/rails.rb +4 -3
- data/lib/gorp/test.rb +59 -50
- data/lib/version.rb +2 -2
- metadata +2 -2
data/gorp.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{gorp}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.22.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sam Ruby"]
|
9
|
-
s.date = %q{2010-01-
|
9
|
+
s.date = %q{2010-01-09}
|
10
10
|
s.description = %q{ Enables the creation of scenarios that involve creating a rails project,
|
11
11
|
starting and stoppping of servers, generating projects, editing files,
|
12
12
|
issuing http requests, running of commands, etc. Output is captured as
|
data/lib/gorp/commands.rb
CHANGED
@@ -55,12 +55,13 @@ module Gorp
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def log type, message
|
58
|
-
type
|
59
|
-
$stdout.puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] #{type} #{message}")
|
58
|
+
Gorp.log type, message
|
60
59
|
end
|
61
60
|
|
61
|
+
@@section_number = 0
|
62
62
|
def head number, title
|
63
|
-
$section = "#{number} #{title}"
|
63
|
+
$section = "#{number} #{title}".strip
|
64
|
+
number ||= (@@section_number+=1)
|
64
65
|
log '====>', $section
|
65
66
|
|
66
67
|
$x.a(:class => 'toc', :id => "section-#{number}") {$x.h2 $section}
|
@@ -96,7 +97,11 @@ module Gorp
|
|
96
97
|
end
|
97
98
|
|
98
99
|
def ruby args
|
99
|
-
|
100
|
+
if args == 'script/server'
|
101
|
+
restart_server
|
102
|
+
else
|
103
|
+
cmd "ruby #{args}"
|
104
|
+
end
|
100
105
|
end
|
101
106
|
|
102
107
|
def rake args
|
@@ -194,3 +199,21 @@ module Gorp
|
|
194
199
|
end
|
195
200
|
end
|
196
201
|
end
|
202
|
+
|
203
|
+
# 1.8.8dev workaround for http://redmine.ruby-lang.org/issues/show/2468
|
204
|
+
x = Builder::XmlMarkup.new
|
205
|
+
x.a('b')
|
206
|
+
if x.target!.include?('*')
|
207
|
+
class Fixnum
|
208
|
+
def xchr(escape=true)
|
209
|
+
n = XChar::CP1252[self] || self
|
210
|
+
case n
|
211
|
+
when 0x9, 0xA, 0xD, (0x20..0xD7FF), (0xE000..0xFFFD), (0x10000..0x10FFFF)
|
212
|
+
XChar::PREDEFINED[n] or
|
213
|
+
(n<128 ? n.chr : (escape ? "&##{n};" : [n].pack('U*')))
|
214
|
+
else
|
215
|
+
'*'
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
data/lib/gorp/edit.rb
CHANGED
@@ -115,8 +115,9 @@ def edit filename, tag=nil
|
|
115
115
|
|
116
116
|
begin
|
117
117
|
data.extend Gorp::StringEditingFunctions
|
118
|
-
yield data
|
118
|
+
yield data if block_given?
|
119
119
|
|
120
|
+
# ensure that the file timestamp changed
|
120
121
|
now = Time.now
|
121
122
|
usec = now.usec/1000000.0
|
122
123
|
sleep 1-usec if now-usec <= stale
|
data/lib/gorp/env.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'pathname'
|
2
3
|
|
3
4
|
# determine port
|
4
5
|
if ARGV.find {|arg| arg =~ /--port=(\d+)/}
|
@@ -61,4 +62,13 @@ module Gorp
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
65
|
+
|
66
|
+
def self.log type, message
|
67
|
+
type = type.to_s.ljust(5).upcase
|
68
|
+
$stdout.puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] #{type} #{message}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.path *segments
|
72
|
+
Pathname.new($WORK).join(*segments).relative_path_from(Pathname.new($BASE))
|
73
|
+
end
|
64
74
|
end
|
data/lib/gorp/output.rb
CHANGED
@@ -67,8 +67,6 @@ at_exit do
|
|
67
67
|
end
|
68
68
|
ensure
|
69
69
|
if e.class != SystemExit
|
70
|
-
$cleanup.call if $cleanup
|
71
|
-
|
72
70
|
# terminate server
|
73
71
|
Gorp::Commands.stop_server
|
74
72
|
|
@@ -98,7 +96,7 @@ at_exit do
|
|
98
96
|
"<ul class=\"todos\">\n#{$todos.target!.gsub(/^/,' '*6)} </ul>"
|
99
97
|
$x.target!.gsub! '<strong/>', '<strong></strong>'
|
100
98
|
$x.target!.gsub! /(<textarea[^>]+)\/>/, '\1></textarea>'
|
101
|
-
log :WRITE, "#{$output}.html"
|
99
|
+
log :WRITE, Gorp.path("#{$output}.html")
|
102
100
|
open("#{$WORK}/#{$output}.html",'w') { |file| file.write $x.target! }
|
103
101
|
|
104
102
|
# run tests
|
data/lib/gorp/rails.rb
CHANGED
@@ -40,7 +40,7 @@ elsif File.directory?(ARGV.first.to_s.split(File::PATH_SEPARATOR).first.to_s)
|
|
40
40
|
|
41
41
|
$rails = File.expand_path($rails)
|
42
42
|
else
|
43
|
-
$rails = 'rails'
|
43
|
+
$rails = ENV['GORP_RAILS'] || 'rails'
|
44
44
|
end
|
45
45
|
|
46
46
|
# verify version of rails
|
@@ -67,7 +67,7 @@ else
|
|
67
67
|
Process.exit!
|
68
68
|
end
|
69
69
|
|
70
|
-
$bundle = ARGV.include?('bundle')
|
70
|
+
$bundle = ARGV.include?('bundle') || ARGV.include?('--bundle')
|
71
71
|
|
72
72
|
module Gorp
|
73
73
|
# determine which version of rails is running
|
@@ -176,11 +176,12 @@ module Gorp
|
|
176
176
|
|
177
177
|
# start/restart a rails server in a separate process
|
178
178
|
def restart_server
|
179
|
-
log :server, 'restart'
|
180
179
|
if $server
|
180
|
+
log :server, 'restart'
|
181
181
|
$x.h3 'Restart the server.'
|
182
182
|
Gorp::Commands.stop_server
|
183
183
|
else
|
184
|
+
log :CMD, 'ruby script/server'
|
184
185
|
$x.h3 'Start the server.'
|
185
186
|
end
|
186
187
|
|
data/lib/gorp/test.rb
CHANGED
@@ -4,34 +4,7 @@ require 'gorp/env'
|
|
4
4
|
require 'gorp/rails'
|
5
5
|
require 'gorp/commands'
|
6
6
|
|
7
|
-
module Gorp
|
8
|
-
class BuilderTee < BlankSlate
|
9
|
-
def initialize(one, two)
|
10
|
-
@one = one
|
11
|
-
@two = two
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing sym, *args, &block
|
15
|
-
if sym == :<<
|
16
|
-
@one << args.first
|
17
|
-
@two << args.first
|
18
|
-
else
|
19
|
-
@one.method_missing sym, *args, &block
|
20
|
-
@two.method_missing sym, *args, &block
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def pre! *args
|
25
|
-
$semaphore.synchronize do
|
26
|
-
@one.pre *args
|
27
|
-
@two.pre *args
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
7
|
class Gorp::TestCase < Test::Unit::TestCase
|
34
|
-
|
35
8
|
def self.suite
|
36
9
|
# Deferred loading of Rails infrastructure
|
37
10
|
if File.exist? "#{$WORK}/vendor/gems/environment.rb"
|
@@ -61,7 +34,13 @@ class Gorp::TestCase < Test::Unit::TestCase
|
|
61
34
|
end
|
62
35
|
|
63
36
|
def self.test(name, &block)
|
64
|
-
define_method("test_#{name.gsub(/\s+/,'_')}".to_sym
|
37
|
+
define_method("test_#{name.gsub(/\s+/,'_')}".to_sym) do
|
38
|
+
self.class.herald self, name
|
39
|
+
instance_eval &block
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.herald instance, name
|
65
44
|
end
|
66
45
|
|
67
46
|
# micro DSL allowing the definition of optional tests
|
@@ -88,8 +67,9 @@ class Gorp::TestCase < Test::Unit::TestCase
|
|
88
67
|
def ticket number, info
|
89
68
|
return if info[:match] and not @raw =~ info[:match]
|
90
69
|
return if block_given? and not yield(@raw)
|
70
|
+
info[:list] ||= :rails
|
91
71
|
|
92
|
-
fail "Ticket #{number}: #{info[:title]}"
|
72
|
+
fail "Ticket #{info[:list]}:#{number}: #{info[:title]}"
|
93
73
|
end
|
94
74
|
|
95
75
|
# read and pre-process $input.html (only done once, and cached)
|
@@ -99,6 +79,9 @@ class Gorp::TestCase < Test::Unit::TestCase
|
|
99
79
|
input.force_encoding('utf-8') if input.respond_to? :force_encoding
|
100
80
|
head, body, tail = input.split /<body>\s+|\s+<\/body>/m
|
101
81
|
|
82
|
+
# ruby 1.8.8 reverses the order
|
83
|
+
body.gsub! /<a (id="[-.\w]+") (class="\w+")>/,'<a \2 \1>'
|
84
|
+
|
102
85
|
# split into sections
|
103
86
|
@@sections = body.split(/<a class="toc" id="section-(.*?)">/)
|
104
87
|
@@sections[-1], env = @@sections.last.split(/<a class="toc" id="env">/)
|
@@ -164,18 +147,13 @@ class Gorp::TestCase < Test::Unit::TestCase
|
|
164
147
|
|
165
148
|
%w(cmd post rake ruby).each do |method|
|
166
149
|
define_method(method) do |*args, &block|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
@selected = HTML::Document.new(@raw).root.children
|
175
|
-
block.call
|
176
|
-
end
|
177
|
-
ensure
|
178
|
-
$x = $x.instance_eval { @one }
|
150
|
+
before = $x.target.length
|
151
|
+
@@base.send method, *args
|
152
|
+
|
153
|
+
if block
|
154
|
+
@raw = $x.target![before..-1]
|
155
|
+
@selected = HTML::Document.new(@raw).root.children
|
156
|
+
block.call
|
179
157
|
end
|
180
158
|
end
|
181
159
|
end
|
@@ -208,7 +186,10 @@ class HTMLRunner < Test::Unit::UI::Console::TestRunner
|
|
208
186
|
sections[:contents][/<a href="#section-#{name}"()>/,1] =
|
209
187
|
' style="color:red; font-weight:bold"'
|
210
188
|
|
211
|
-
tickets =
|
189
|
+
tickets = {
|
190
|
+
'rails' => 'https://rails.lighthouseapp.com/projects/8994/tickets/',
|
191
|
+
'ruby' => 'http://redmine.ruby-lang.org/issues/show/'
|
192
|
+
}
|
212
193
|
|
213
194
|
# provide details in the section itself
|
214
195
|
x = Builder::XmlMarkup.new(:indent => 2)
|
@@ -217,10 +198,10 @@ class HTMLRunner < Test::Unit::UI::Console::TestRunner
|
|
217
198
|
"\n\nTraceback:\n " + fault.location.join("\n "),
|
218
199
|
:class=>'traceback'
|
219
200
|
else
|
220
|
-
if fault.message =~ /RuntimeError: Ticket (\d+): (.*)/
|
201
|
+
if fault.message =~ /RuntimeError: Ticket (\w+):(\d+): (.*)/
|
221
202
|
x.p :class => 'traceback' do
|
222
|
-
x.a "Ticket #{$
|
223
|
-
x.text! ': ' + $
|
203
|
+
x.a "Ticket #{$2}", :href => tickets[$1]+$2
|
204
|
+
x.text! ': ' + $3
|
224
205
|
end
|
225
206
|
else
|
226
207
|
x.pre fault.message, :class=>'traceback'
|
@@ -251,7 +232,8 @@ class HTMLRunner < Test::Unit::UI::Console::TestRunner
|
|
251
232
|
|
252
233
|
def html_summary elapsed
|
253
234
|
# terminate server
|
254
|
-
|
235
|
+
Gorp::Commands.stop_server
|
236
|
+
$cleanup.call if $cleanup
|
255
237
|
|
256
238
|
open(File.join($WORK, "#{$output}.html"),'w') do |output|
|
257
239
|
sections = @@sections
|
@@ -300,8 +282,12 @@ end
|
|
300
282
|
|
301
283
|
# Produce output for standalone scripts
|
302
284
|
at_exit do
|
303
|
-
next if
|
304
|
-
|
285
|
+
next if $output
|
286
|
+
if caller and !caller.empty?
|
287
|
+
source = File.basename(caller.first.split(':').first)
|
288
|
+
else
|
289
|
+
source = File.basename($0).split('.').first
|
290
|
+
end
|
305
291
|
name = source.sub(Regexp.new(Regexp.escape(File.extname(source))+'$'), '')
|
306
292
|
$output = name
|
307
293
|
|
@@ -309,16 +295,39 @@ at_exit do
|
|
309
295
|
ObjectSpace.each_object(Class) do |c|
|
310
296
|
next unless c.superclass == Gorp::TestCase
|
311
297
|
suite << c.suite
|
298
|
+
def c.herald instance, name
|
299
|
+
instance.head nil, name
|
300
|
+
end
|
312
301
|
end
|
313
302
|
|
314
303
|
def suite.sections
|
315
304
|
style = open(File.join(File.dirname(__FILE__), 'output.css')) {|fh| fh.read}
|
316
|
-
head = "<head
|
317
|
-
|
305
|
+
head = "<html>\n<head>\n<title>#{$output}</title>\n<style></style>\n</head>"
|
306
|
+
$cleanup = Proc.new do
|
307
|
+
Dir['public/stylesheets/*.css'].each do |css|
|
308
|
+
File.open(css) {|file| style+= file.read}
|
309
|
+
end
|
310
|
+
head[/(<style><\/style>)/,1] = "<style>\n#{style}</style>"
|
311
|
+
end
|
312
|
+
{:head=>head, :tail=>"\n</html>"}
|
318
313
|
end
|
319
314
|
|
320
315
|
require 'gorp/xml'
|
321
316
|
require 'gorp/edit'
|
322
317
|
require 'gorp/net'
|
318
|
+
|
319
|
+
class HTMLRunner
|
320
|
+
def output(something, *args)
|
321
|
+
if something.respond_to?(:passed?)
|
322
|
+
Gorp::Commands.stop_server
|
323
|
+
at_exit {puts "\n#{something}"}
|
324
|
+
end
|
325
|
+
end
|
326
|
+
def output_single(something, *args)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
323
330
|
HTMLRunner.run(suite)
|
331
|
+
|
332
|
+
Gorp.log :WRITE, Gorp.path($output+'.html')
|
324
333
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gorp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-09 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|