Skip to content

Commit

Permalink
* Rakefile : Clean the generated test.log in test/, new test task.
Browse files Browse the repository at this point in the history
* lib/camping[-unabridged].rb : Fixes #102. The layout wasn't captured in Mab.
* test/test_xhtml_trans.rb : The test case for #102. You'll need mosquito to
 be able to run it.
  • Loading branch information
Jonas Pfenniger committed Oct 24, 2006
1 parent 50023ad commit ae02dd3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ require 'rake'
require 'rake/clean'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'
require 'fileutils'
include FileUtils

NAME = "camping"
REV = File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil
VERS = ENV['VERSION'] || ("1.5" + (REV ? ".#{REV}" : ""))
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log']
RDOC_OPTS = ['--quiet', '--title', "Camping, the Documentation",
"--opname", "index.html",
"--line-numbers",
Expand Down Expand Up @@ -87,3 +88,9 @@ end
task :uninstall => [:clean] do
sh %{sudo gem uninstall #{NAME}}
end

Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/test_*.rb']
# t.warning = true
# t.verbose = true
end
2 changes: 1 addition & 1 deletion lib/camping-unabridged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def method_missing(*a,&b)
a.shift if a[0]==:render
m=Mab.new({},self)
s=m.capture{send(*a,&b)}
s=m.layout{s} if /^_/!~a[0].to_s and m.respond_to?:layout
s=m.capture{send(:layout){s}} if /^_/!~a[0].to_s and m.respond_to?:layout
s
end

Expand Down
7 changes: 4 additions & 3 deletions lib/camping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ module Camping;Apps=[];C=self;S=IO.read(__FILE__).sub(/S=I.+$/,'')
p[/^\//]?@root+p : p end;def errors_for o;ul.errors{o.errors.each_full{|x|li x}
}if o.errors.any?end end;module Base;include Helpers;attr_accessor:input,
:cookies,:env,:headers,:body,:status,:root;def method_missing*a,&b
a.shift if a[0]==:render;m=Mab.new({},self);s=m.capture{send(*a,&b)};s=m.layout{s}if
/^_/!~a[0].to_s and m.respond_to?:layout;s end;def r s,b,h={};@status=s;@headers.
merge!h;@body=b end;def redirect*a;r 302,'','Location'=>URL(*a)end;Z="\r\n"
a.shift if a[0]==:render;m=Mab.new({},self);s=m.capture{send(*a,&b)}
s=m.capture{send(:layout){s}} if /^_/!~a[0].to_s and m.respond_to?:layout
s end;def r s,b,h={};@status=s;@headers.merge!h;@body=b end
def redirect*a;r 302,'','Location'=>URL(*a)end;Z="\r\n"
def initialize r,e,m;e=H[e.to_hash];@status,@method,@env,@headers,@root=200,m.
downcase,e,{'Content-Type'=>"text/html"},e.SCRIPT_NAME.sub(/\/$/,'')
@k=C.kp e.HTTP_COOKIE;q=C.qsp e.QUERY_STRING;@in=r
Expand Down
55 changes: 55 additions & 0 deletions test/test_xhtml_trans.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'mosquito'

Camping.goes :XhtmlTrans

module XhtmlTrans
module Controllers
class WithLayout < R '/with_layout'
def get
render :with_layout
end
end

class WithoutLayout < R '/without_layout'
def get
render :_without_layout
end
end
end

module Views
def layout
xhtml_transitional do
head do title "title" end
body do capture { yield } end
end
end

def with_layout
h1 "With layout"
end

def _without_layout
xhtml_transitional do
head do title "title" end
body do h1 "Without layout" end
end
end
end
end

class XhtmlTransTest < Camping::FunctionalTest
def test_with_layout
get '/with_layout'

assert(@response.body =~ /DOCTYPE/, "No doctype defined")
end

def test_without_layout
get '/without_layout'

assert(@response.body =~ /DOCTYPE/, "No doctype defined")
end

end

0 comments on commit ae02dd3

Please sign in to comment.