Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Factorize path-driven code in template_tests.

  • Loading branch information...
commit e7cb8f98c226fcfac6712f0982f59cc44093bb88 1 parent f8ebdd9
@blambeau authored
Showing with 14 additions and 20 deletions.
  1. +14 −20 test/templates_test.rb
View
34 test/templates_test.rb
@@ -34,6 +34,14 @@ def with_default_layout
File.unlink(layout) rescue nil
end
+ def with_hello_paths
+ require 'pathname'
+ path = File.dirname(__FILE__) + '/views/hello.test'
+ yield Struct.new(:path).new(path)
+ yield Struct.new(:to_path).new(path)
+ yield Pathname.new(path)
+ end
+
it 'renders String templates directly' do
render_app { render(:test, 'Hello World') }
assert ok?
@@ -52,26 +60,12 @@ def with_default_layout
assert_equal "Hello World!\n", body
end
- it 'renders Pathname from the underlying file' do
- require 'pathname'
- path = Pathname.new(File.dirname(__FILE__) + '/views/hello.test')
- render_app{ render(:test, path) }
- assert ok?
- assert_equal "Hello World!\n", body
- end
-
- it 'renders objects responding to :path from the file' do
- path = Struct.new(:path).new(File.dirname(__FILE__) + '/views/hello.test')
- render_app{ render(:test, path) }
- assert ok?
- assert_equal "Hello World!\n", body
- end
-
- it 'renders objects responding to :to_path from the file' do
- path = Struct.new(:to_path).new(File.dirname(__FILE__) + '/views/hello.test')
- render_app{ render(:test, path) }
- assert ok?
- assert_equal "Hello World!\n", body
+ it 'renders path-able objects from their file' do
+ with_hello_paths do |path|
+ render_app{ render(:test, path) }
+ assert ok?
+ assert_equal "Hello World!\n", body
+ end
end
it 'uses the default layout template if not explicitly overridden' do
Please sign in to comment.
Something went wrong with that request. Please try again.