gorp 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
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.15.0"
5
+ s.version = "0.16.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{2009-12-25}
9
+ s.date = %q{2009-12-26}
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
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
16
16
  assertions based on selections (typically CSS) against the generated HTML.
17
17
  }
18
18
  s.email = %q{rubys@intertwingly.net}
19
- s.extra_rdoc_files = ["README", "lib/gorp.rb", "lib/gorp/env.rb", "lib/gorp/test.rb", "lib/version.rb"]
20
- s.files = ["Manifest", "README", "Rakefile", "gorp.gemspec", "lib/gorp.rb", "lib/gorp/env.rb", "lib/gorp/test.rb", "lib/version.rb"]
19
+ s.extra_rdoc_files = ["README", "lib/gorp.rb", "lib/gorp/edit.rb", "lib/gorp/env.rb", "lib/gorp/test.rb", "lib/version.rb"]
20
+ s.files = ["Manifest", "README", "Rakefile", "gorp.gemspec", "lib/gorp.rb", "lib/gorp/edit.rb", "lib/gorp/env.rb", "lib/gorp/test.rb", "lib/version.rb"]
21
21
  s.homepage = %q{http://github.com/rubys/gorp}
22
22
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Gorp", "--main", "README"]
23
23
  s.require_paths = ["lib"]
data/lib/gorp/edit.rb ADDED
@@ -0,0 +1,127 @@
1
+ class String
2
+ def unindent(n)
3
+ gsub Regexp.new("^#{' '*n}"), ''
4
+ end
5
+ def indent(n)
6
+ gsub /^/, ' '*n
7
+ end
8
+ end
9
+
10
+ module Gorp_string_editing_functions
11
+ def highlight
12
+ if self =~ /\n\z/
13
+ self[/(.*)/m,1] = "#START_HIGHLIGHT\n#{self}#END_HIGHLIGHT\n"
14
+ else
15
+ self[/(.*)/m,1] = "#START_HIGHLIGHT\n#{self}\n#END_HIGHLIGHT"
16
+ end
17
+ end
18
+
19
+ def mark name
20
+ return unless name
21
+ self[/(.*)/m,1] = "#START:#{name}\n#{self}#END:#{name}\n"
22
+ end
23
+
24
+ def edit(from, *options)
25
+ STDERR.puts options.inspect
26
+ STDERR.puts options.last.inspect
27
+ STDERR.puts options.last.respond_to? :[]
28
+ if from.instance_of? String
29
+ from = Regexp.new('.*' + Regexp.escape(from) + '.*')
30
+ end
31
+
32
+ sub!(from) do |base|
33
+ base.extend Gorp_string_editing_functions
34
+ yield base if block_given?
35
+ base.highlight if options.include? :highlight
36
+ base.mark(options.last[:mark]) if options.last.respond_to? :key
37
+ base
38
+ end
39
+ end
40
+
41
+ def dcl(name, *options)
42
+ self.sub!(/(\s*)(class|def|test)\s+"?#{name}"?.*?\n\1end\n/mo) do |lines|
43
+ lines.extend Gorp_string_editing_functions
44
+ yield lines
45
+ lines.mark(options.last[:mark]) if options.last.respond_to? :[]
46
+ lines
47
+ end
48
+ end
49
+
50
+ def clear_highlights
51
+ self.gsub! /^\s*(#|<!--)\s*(START|END)_HIGHLIGHT(\s*-->)?\n/, ''
52
+ self.gsub! /^\s*(#|<!--)\s*(START|END)_HIGHLIGHT(\s*-->)?\n/, ''
53
+ end
54
+
55
+ def clear_all_marks
56
+ self.gsub! /^ *#\s?(START|END)(_HIGHLIGHT|:\w+)\n/, ''
57
+ end
58
+
59
+ def msub pattern, replacement
60
+ self[pattern, 1] = replacement
61
+ end
62
+
63
+ def all=replacement
64
+ self[/(.*)/m,1]=replacement
65
+ end
66
+ end
67
+
68
+ def edit filename, tag=nil
69
+ $x.pre "edit #{filename}", :class=>'stdin'
70
+
71
+ stale = File.mtime(filename) rescue Time.now-2
72
+ data = open(filename) {|file| file.read} rescue ''
73
+ before = data.split("\n")
74
+
75
+ begin
76
+ data.extend Gorp_string_editing_functions
77
+ yield data
78
+
79
+ now = Time.now
80
+ usec = now.usec/1000000.0
81
+ sleep 1-usec if now-usec <= stale
82
+ open(filename,'w') {|file| file.write data}
83
+ File.utime(stale+2, stale+2, filename) if File.mtime(filename) <= stale
84
+
85
+ rescue Exception => e
86
+ $x.pre :class => 'traceback' do
87
+ STDERR.puts e.inspect
88
+ $x.text! "#{e.inspect}\n"
89
+ e.backtrace.each {|line| $x.text! " #{line}\n"}
90
+ end
91
+ tag = nil
92
+
93
+ ensure
94
+ log :edit, filename
95
+
96
+ include = tag.nil?
97
+ hilight = false
98
+ data.split("\n").each do |line|
99
+ if line =~ /START:(\w+)/
100
+ include = true if $1 == tag
101
+ elsif line =~ /END:(\w+)/
102
+ include = false if $1 == tag
103
+ elsif line =~ /START_HIGHLIGHT/
104
+ hilight = true
105
+ elsif line =~ /END_HIGHLIGHT/
106
+ hilight = false
107
+ elsif include
108
+ if hilight or ! before.include?(line)
109
+ outclass='hilight'
110
+ else
111
+ outclass='stdout'
112
+ end
113
+
114
+ if line.empty?
115
+ $x.pre ' ', :class=>outclass
116
+ else
117
+ $x.pre line, :class=>outclass
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ def read name
125
+ open(File.join($DATA, name)) {|file| file.read}
126
+ end
127
+
data/lib/gorp/test.rb CHANGED
@@ -38,6 +38,13 @@ class Book::TestCase < ActiveSupport::TestCase
38
38
  end
39
39
  end
40
40
 
41
+ def ticket number, info
42
+ return if info[:match] and not @raw =~ info[:match]
43
+ return if block_given? and not yield(@raw)
44
+
45
+ fail "Ticket #{number}: #{info[:title]}"
46
+ end
47
+
41
48
  # read and pre-process $input.html (only done once, and cached)
42
49
  def self.input filename
43
50
  # read $input output; remove front matter and footer
@@ -139,6 +146,8 @@ class HTMLRunner < Test::Unit::UI::Console::TestRunner
139
146
  sections[:contents][/<a href="#section-#{name}"()>/,1] =
140
147
  ' style="color:red; font-weight:bold"'
141
148
 
149
+ tickets = 'https://rails.lighthouseapp.com/projects/8994/tickets/'
150
+
142
151
  # provide details in the section itself
143
152
  x = Builder::XmlMarkup.new(:indent => 2)
144
153
  if fault.respond_to? :location
@@ -146,7 +155,14 @@ class HTMLRunner < Test::Unit::UI::Console::TestRunner
146
155
  "\n\nTraceback:\n " + fault.location.join("\n "),
147
156
  :class=>'traceback'
148
157
  else
149
- x.pre fault.message, :class=>'traceback'
158
+ if fault.message =~ /RuntimeError: Ticket (\d+): (.*)/
159
+ x.p :class => 'traceback' do
160
+ x.a "Ticket #{$1}", :href => tickets+$1
161
+ x.text! ': ' + $2
162
+ end
163
+ else
164
+ x.pre fault.message, :class=>'traceback'
165
+ end
150
166
  end
151
167
  sections[name][/<\/a>()/,1] = x.target!
152
168
 
@@ -154,11 +170,18 @@ class HTMLRunner < Test::Unit::UI::Console::TestRunner
154
170
  x = Builder::XmlMarkup.new(:indent => 2)
155
171
  x.li do
156
172
  x.a "Section #{name}", :href => "#section-#{name}"
157
- x.tt fault.message.sub(".\n<false> is not true",'').
158
- sub(/ but was\n.*/, '.').
159
- sub(/"((?:\\"|[^"])+)"/) {
160
- '"' + ($1.length>80 ? $1[0..72]+'...' : $1) + '"'
161
- }
173
+ if fault.message =~ /RuntimeError: Ticket (\d+): (.*)/
174
+ x.text! '['
175
+ x.a "Ticket #{$1}", :href => tickets+$1
176
+ x.text! ']: ' + $2
177
+ else
178
+ x.text! ': '
179
+ x.tt fault.message.sub(".\n<false> is not true",'').
180
+ sub(/ but was\n.*/, '.').
181
+ sub(/"((?:\\"|[^"])+)"/) {
182
+ '"' + ($1.length>80 ? $1[0..72]+'...' : $1) + '"'
183
+ }
184
+ end
162
185
  end
163
186
  sections[:todos][/() *<\/ul>/,1] = x.target!.gsub(/^/,' ')
164
187
  end
data/lib/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Gorp
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 15
4
+ MINOR = 16
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
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.15.0
4
+ version: 0.16.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: 2009-12-25 00:00:00 -05:00
12
+ date: 2009-12-26 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -121,6 +121,7 @@ extensions: []
121
121
  extra_rdoc_files:
122
122
  - README
123
123
  - lib/gorp.rb
124
+ - lib/gorp/edit.rb
124
125
  - lib/gorp/env.rb
125
126
  - lib/gorp/test.rb
126
127
  - lib/version.rb
@@ -130,6 +131,7 @@ files:
130
131
  - Rakefile
131
132
  - gorp.gemspec
132
133
  - lib/gorp.rb
134
+ - lib/gorp/edit.rb
133
135
  - lib/gorp/env.rb
134
136
  - lib/gorp/test.rb
135
137
  - lib/version.rb