Permalink
Browse files

working on the tag specs, major issue came from the radius gem.

  • Loading branch information...
1 parent de46789 commit c6e33a23b08acaea224e704337add13a69c3d3db Dirk Kelly committed Dec 27, 2010
@@ -1313,8 +1313,8 @@ def required_attr(tag, *attribute_names)
def dev?(request)
return false if request.nil?
- if dev_host = Radiant::Config['dev.host']
- dev_host == request.host
+ if Radiant::Config['dev.host'].present?
+ Radiant::Config['dev.host'] == request.host
else
request.host =~ /^dev\./
end
@@ -970,6 +970,9 @@
end
describe "<r:if_dev>" do
+ before :each do
+ Radiant::Config['dev.host'] = nil
+ end
it "should render the contained block when on the dev site" do
page.should render('-<r:if_dev>dev</r:if_dev>-').as('-dev-').on('dev.site.com')
end
@@ -979,7 +982,7 @@
end
it "should not render the contained block when no request is present" do
- page(:devtags).render_part('if_dev').should_not have_text('dev')
+ page(:devtags).render_part('if_dev').should_not include('dev')
end
describe "on an included page" do
@@ -994,6 +997,9 @@
end
describe "<r:unless_dev>" do
+ before :each do
+ Radiant::Config['dev.host'] = nil
+ end
it "should not render the contained block when not on the dev site" do
page.should render('-<r:unless_dev>not dev</r:unless_dev>-').as('--').on('dev.site.com')
end
@@ -1003,7 +1009,7 @@
end
it "should render the contained block when no request is present" do
- page(:devtags).render_part('unless_dev').should have_text('not dev')
+ page(:devtags).render_part('unless_dev').should include('not dev')
end
describe "on an included page" do
@@ -1,132 +1,134 @@
-module Spec
- module Rails
- module Matchers
+module RSpec
+ module Matchers
+
+ class RenderTags
+ def initialize(content = nil)
+ @content = content
+ end
- class RenderTags
- def initialize(content = nil)
- @content = content
+ def matches?(page)
+ @actual = render_content_with_page(@content, page)
+ if @expected.kind_of?(Regexp)
+ @expected = nil
+ @matching = @expected
end
-
- def matches?(page)
- @actual = render_content_with_page(@content, page)
- if @expected.kind_of?(Regexp)
- @expected = nil
- @matching = @expected
- end
- case
- when @expected_error_message
- false
- when @expected
- @actual == @expected
- when @matching
- @actual =~ @matching
- when @not_matching
- @actual !~ @not_matching
- else
- true
- end
- rescue => @actual_error
- if @expected_error_message
- @actual_error.message === @expected_error_message
- else
- @error_thrown = true
+ case
+ when @expected_error_message
false
- end
- end
-
- def failure_message
- action = case
when @expected
- "render as #{@expected.inspect}"
- when @not_matching
- "render but not match #{@not_matching.inspect}"
- else
- "render and match #{@matching.inspect}"
- end
- unless @error_thrown
- unless @expected_error_message
- if @content
- "expected #{@content.inspect} to #{action}, but got #{@actual.inspect}"
- else
- "expected page to #{action}, but got #{@actual.inspect}"
- end
- else
- if @actual_error
- "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but was #{@actual_error.message.inspect}"
- else
- "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but no exception thrown. Rendered #{@actual.inspect} instead."
- end
- end
- else
- "expected #{@content.inspect} to render, but an exception was thrown #{@actual_error.message}"
- end
- end
-
- def description
- "render tags #{@expected.inspect}"
- end
-
- def as(output)
- @expected = output
- self
- end
-
- def matching(regexp)
- @matching = regexp
- self
- end
-
- def not_matching(regexp)
- @not_matching = regexp
- self
+ @actual == @expected
+ when @matching
+ @actual =~ @matching
+ when @not_matching
+ @actual !~ @not_matching
+ else true
end
-
- def with_error(message)
- @expected_error_message = message
- self
+ rescue => @actual_error
+ if @expected_error_message
+ @actual_error.message === @expected_error_message
+ else
+ @error_thrown = true
+ false
end
-
- def on(url)
- url = test_host + "/" + url unless url =~ %r{^[^/]+\.[^/]+}
- url = 'http://' + url unless url =~ %r{^http://}
- uri = URI.parse(url)
- @request_uri = uri.request_uri unless uri.request_uri == '/'
- @host = uri.host
- self
+ end
+
+ def failure_message
+ action = case
+ when @expected
+ "render as #{@expected.inspect}"
+ when @not_matching
+ "render but not match #{@not_matching.inspect}"
+ else
+ "render and match #{@matching.inspect}"
end
-
- private
- def render_content_with_page(tag_content, page)
- page.request = ActionController::TestRequest.new
- page.request.params[:sample_param] = 'data'
- page.request.request_uri = @request_uri || page.url
- page.request.host = @host || test_host
- page.response = ActionController::TestResponse.new
- if tag_content.nil?
- page.render
+ unless @error_thrown
+ unless @expected_error_message
+ if @content
+ "expected #{@content.inspect} to #{action}, but got #{@actual.inspect}"
else
- page.send(:parse, tag_content)
+ "expected page to #{action}, but got #{@actual.inspect}"
+ end
+ else
+ if @actual_error
+ "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but was #{@actual_error.message.inspect}"
+ else
+ "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but no exception thrown. Rendered #{@actual.inspect} instead."
end
end
-
- def test_host
- "testhost.tld"
- end
+ else
+ "expected #{@content.inspect} to render, but an exception was thrown #{@actual_error.message}"
+ end
+ end
+
+ def description
+ "render tags #{@expected.inspect}"
+ end
+
+ def as(output)
+ @expected = output
+ self
+ end
+
+ def matching(regexp)
+ @matching = regexp
+ self
+ end
+
+ def not_matching(regexp)
+ @not_matching = regexp
+ self
end
- # page.should render(input).as(output)
- # page.should render(input).as(output).on(url)
- # page.should render(input).matching(/hello world/)
- # page.should render(input).with_error(message)
- def render(input)
- RenderTags.new(input)
+ def with_error(message)
+ @expected_error_message = message
+ self
end
- # page.should render_as(output)
- def render_as(output)
- RenderTags.new.as(output)
+ def on(url)
+ url = test_host + "/" + url unless url =~ %r{^[^/]+\.[^/]+}
+ url = 'http://' + url unless url =~ %r{^http://}
+ uri = URI.parse(url)
+ @request_uri = uri.request_uri unless uri.request_uri == '/'
+ @host = uri.host
+ self
end
+ def with_relative_root(url="/")
+ @relative_root = url
+ self
+ end
+
+ private
+ def render_content_with_page(tag_content, page)
+ page.request = ActionController::TestRequest.new
+ page.request.params[:sample_param] = 'data'
+ page.request.request_uri = @request_uri || page.url
+ page.request.host = @host || test_host
+ page.response = ActionController::TestResponse.new
+ if tag_content.nil?
+ page.render
+ else
+ page.send(:parse, tag_content)
+ end
+ end
+
+ def test_host
+ "testhost.tld"
+ end
+ end
+
+ # page.should render(input).as(output)
+ # page.should render(input).as(output).on(url)
+ # page.should render(input).matching(/hello world/)
+ # page.should render(input).with_error(message)
+ def render(input)
+ RenderTags.new(input)
+ end
+
+ # page.should render_as(output)
+ def render_as(output)
+ RenderTags.new.as(output)
end
+
end
end

0 comments on commit c6e33a2

Please sign in to comment.