adamh-html_render 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/html_render.gemspec +1 -1
- data/lib/html_render/render_test/rails.rb +62 -2
- metadata +1 -1
data/html_render.gemspec
CHANGED
@@ -100,7 +100,7 @@ module HTMLRender::RenderTest::Rails
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
module
|
103
|
+
module Common
|
104
104
|
def create_test_case_from_path(relative_path, options)
|
105
105
|
clazz = options[:base_class] || RenderTest
|
106
106
|
base_path = options[:test_prefix]
|
@@ -130,14 +130,74 @@ module HTMLRender::RenderTest::Rails
|
|
130
130
|
test_case.instance_eval(setup_code, setup_filename, 1)
|
131
131
|
end
|
132
132
|
end
|
133
|
+
module_function(:create_test_case_from_path)
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
def self.absolute_test_path(relative_path, base_path)
|
138
|
+
File.join(base_path, relative_path)
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.absolute_run_path(relative_path, base_path)
|
142
|
+
File.join(absolute_test_path(relative_path, base_path), 'run')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
if defined?(Spec)
|
147
|
+
class RenderExampleGroup < Spec::Example::ExampleGroup
|
148
|
+
def self.define_example(setup_path, base_path, servers, options)
|
149
|
+
relative_path = setup_path[(base_path.length + 1)..-10]
|
150
|
+
template_path = File.dirname(relative_path)
|
151
|
+
test_key = File.basename(relative_path)
|
152
|
+
|
153
|
+
it 'should render properly' do
|
154
|
+
test_case = Common::create_test_case_from_path(relative_path, options.merge(:test_prefix => base_path))
|
155
|
+
result = test_case.run(servers)
|
156
|
+
result.details.each do |server, detail|
|
157
|
+
detail.pass?.should == true
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.define_examples(base_path, options)
|
163
|
+
servers = options.delete(:servers)
|
133
164
|
|
165
|
+
if !servers || !servers.is_a?(Hash)
|
166
|
+
raise ArgumentError.new("options[:servers] must be a hash of :unique_identifier => \"http://path.to.server/which/renders/pngs\"")
|
167
|
+
end
|
168
|
+
|
169
|
+
cwd = []
|
170
|
+
context_stack = []
|
171
|
+
|
172
|
+
paths = Dir.glob(File.join(base_path, '**', 'setup.rb')).sort.each do |setup_path|
|
173
|
+
relative_path = File.dirname(setup_path[(base_path.length + 1)..-1])
|
174
|
+
path_parts = relative_path.split('/')
|
175
|
+
|
176
|
+
until relative_path =~ %r%^#{Regexp.quote(cwd.join('/'))}%
|
177
|
+
cwd.pop
|
178
|
+
context_stack.pop
|
179
|
+
end
|
180
|
+
|
181
|
+
until cwd.length == path_parts.length
|
182
|
+
cwd.push(path_parts[cwd.length])
|
183
|
+
context_stack.push((context_stack.last || self).describe("/#{cwd.join('/')}", :type => :render))
|
184
|
+
end
|
185
|
+
|
186
|
+
context_stack.last.define_example(setup_path, base_path, servers, options)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
Spec::Example::ExampleGroupFactory.register(:render, RenderExampleGroup)
|
191
|
+
end
|
192
|
+
|
193
|
+
module TestCaseDefinitions
|
134
194
|
def define_single_test(setup_path, base_path, servers, options)
|
135
195
|
relative_path = setup_path[(base_path.length + 1)..-10]
|
136
196
|
template_path = File.dirname(relative_path)
|
137
197
|
test_key = File.basename(relative_path)
|
138
198
|
|
139
199
|
self.test("Rendering #{template_path}, case '#{test_key}'") do
|
140
|
-
test_case =
|
200
|
+
test_case = Common::create_test_case_from_path(relative_path, options.merge(:test_prefix => base_path))
|
141
201
|
result = test_case.run(servers)
|
142
202
|
result.details.each do |server, detail|
|
143
203
|
assert(detail.pass?, "Should render properly on #{server}")
|