Skip to content
This repository
Browse code

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

  • Loading branch information...
commit c6e33a23b08acaea224e704337add13a69c3d3db 1 parent de46789
Dirk Kelly authored
4 app/models/standard_tags.rb
@@ -1313,8 +1313,8 @@ def required_attr(tag, *attribute_names)
1313 1313
1314 1314 def dev?(request)
1315 1315 return false if request.nil?
1316   - if dev_host = Radiant::Config['dev.host']
1317   - dev_host == request.host
  1316 + if Radiant::Config['dev.host'].present?
  1317 + Radiant::Config['dev.host'] == request.host
1318 1318 else
1319 1319 request.host =~ /^dev\./
1320 1320 end
10 test/railsapp/spec/models/standard_tags_spec.rb
@@ -970,6 +970,9 @@
970 970 end
971 971
972 972 describe "<r:if_dev>" do
  973 + before :each do
  974 + Radiant::Config['dev.host'] = nil
  975 + end
973 976 it "should render the contained block when on the dev site" do
974 977 page.should render('-<r:if_dev>dev</r:if_dev>-').as('-dev-').on('dev.site.com')
975 978 end
@@ -979,7 +982,7 @@
979 982 end
980 983
981 984 it "should not render the contained block when no request is present" do
982   - page(:devtags).render_part('if_dev').should_not have_text('dev')
  985 + page(:devtags).render_part('if_dev').should_not include('dev')
983 986 end
984 987
985 988 describe "on an included page" do
@@ -994,6 +997,9 @@
994 997 end
995 998
996 999 describe "<r:unless_dev>" do
  1000 + before :each do
  1001 + Radiant::Config['dev.host'] = nil
  1002 + end
997 1003 it "should not render the contained block when not on the dev site" do
998 1004 page.should render('-<r:unless_dev>not dev</r:unless_dev>-').as('--').on('dev.site.com')
999 1005 end
@@ -1003,7 +1009,7 @@
1003 1009 end
1004 1010
1005 1011 it "should render the contained block when no request is present" do
1006   - page(:devtags).render_part('unless_dev').should have_text('not dev')
  1012 + page(:devtags).render_part('unless_dev').should include('not dev')
1007 1013 end
1008 1014
1009 1015 describe "on an included page" do
228 test/railsapp/spec/support/render_matcher.rb
... ... @@ -1,132 +1,134 @@
1   -module Spec
2   - module Rails
3   - module Matchers
  1 +module RSpec
  2 + module Matchers
  3 +
  4 + class RenderTags
  5 + def initialize(content = nil)
  6 + @content = content
  7 + end
4 8
5   - class RenderTags
6   - def initialize(content = nil)
7   - @content = content
  9 + def matches?(page)
  10 + @actual = render_content_with_page(@content, page)
  11 + if @expected.kind_of?(Regexp)
  12 + @expected = nil
  13 + @matching = @expected
8 14 end
9   -
10   - def matches?(page)
11   - @actual = render_content_with_page(@content, page)
12   - if @expected.kind_of?(Regexp)
13   - @expected = nil
14   - @matching = @expected
15   - end
16   - case
17   - when @expected_error_message
18   - false
19   - when @expected
20   - @actual == @expected
21   - when @matching
22   - @actual =~ @matching
23   - when @not_matching
24   - @actual !~ @not_matching
25   - else
26   - true
27   - end
28   - rescue => @actual_error
29   - if @expected_error_message
30   - @actual_error.message === @expected_error_message
31   - else
32   - @error_thrown = true
  15 + case
  16 + when @expected_error_message
33 17 false
34   - end
35   - end
36   -
37   - def failure_message
38   - action = case
39 18 when @expected
40   - "render as #{@expected.inspect}"
41   - when @not_matching
42   - "render but not match #{@not_matching.inspect}"
43   - else
44   - "render and match #{@matching.inspect}"
45   - end
46   - unless @error_thrown
47   - unless @expected_error_message
48   - if @content
49   - "expected #{@content.inspect} to #{action}, but got #{@actual.inspect}"
50   - else
51   - "expected page to #{action}, but got #{@actual.inspect}"
52   - end
53   - else
54   - if @actual_error
55   - "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but was #{@actual_error.message.inspect}"
56   - else
57   - "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but no exception thrown. Rendered #{@actual.inspect} instead."
58   - end
59   - end
60   - else
61   - "expected #{@content.inspect} to render, but an exception was thrown #{@actual_error.message}"
62   - end
63   - end
64   -
65   - def description
66   - "render tags #{@expected.inspect}"
67   - end
68   -
69   - def as(output)
70   - @expected = output
71   - self
72   - end
73   -
74   - def matching(regexp)
75   - @matching = regexp
76   - self
77   - end
78   -
79   - def not_matching(regexp)
80   - @not_matching = regexp
81   - self
  19 + @actual == @expected
  20 + when @matching
  21 + @actual =~ @matching
  22 + when @not_matching
  23 + @actual !~ @not_matching
  24 + else true
82 25 end
83   -
84   - def with_error(message)
85   - @expected_error_message = message
86   - self
  26 + rescue => @actual_error
  27 + if @expected_error_message
  28 + @actual_error.message === @expected_error_message
  29 + else
  30 + @error_thrown = true
  31 + false
87 32 end
88   -
89   - def on(url)
90   - url = test_host + "/" + url unless url =~ %r{^[^/]+\.[^/]+}
91   - url = 'http://' + url unless url =~ %r{^http://}
92   - uri = URI.parse(url)
93   - @request_uri = uri.request_uri unless uri.request_uri == '/'
94   - @host = uri.host
95   - self
  33 + end
  34 +
  35 + def failure_message
  36 + action = case
  37 + when @expected
  38 + "render as #{@expected.inspect}"
  39 + when @not_matching
  40 + "render but not match #{@not_matching.inspect}"
  41 + else
  42 + "render and match #{@matching.inspect}"
96 43 end
97   -
98   - private
99   - def render_content_with_page(tag_content, page)
100   - page.request = ActionController::TestRequest.new
101   - page.request.params[:sample_param] = 'data'
102   - page.request.request_uri = @request_uri || page.url
103   - page.request.host = @host || test_host
104   - page.response = ActionController::TestResponse.new
105   - if tag_content.nil?
106   - page.render
  44 + unless @error_thrown
  45 + unless @expected_error_message
  46 + if @content
  47 + "expected #{@content.inspect} to #{action}, but got #{@actual.inspect}"
107 48 else
108   - page.send(:parse, tag_content)
  49 + "expected page to #{action}, but got #{@actual.inspect}"
  50 + end
  51 + else
  52 + if @actual_error
  53 + "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but was #{@actual_error.message.inspect}"
  54 + else
  55 + "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but no exception thrown. Rendered #{@actual.inspect} instead."
109 56 end
110 57 end
111   -
112   - def test_host
113   - "testhost.tld"
114   - end
  58 + else
  59 + "expected #{@content.inspect} to render, but an exception was thrown #{@actual_error.message}"
  60 + end
  61 + end
  62 +
  63 + def description
  64 + "render tags #{@expected.inspect}"
  65 + end
  66 +
  67 + def as(output)
  68 + @expected = output
  69 + self
  70 + end
  71 +
  72 + def matching(regexp)
  73 + @matching = regexp
  74 + self
  75 + end
  76 +
  77 + def not_matching(regexp)
  78 + @not_matching = regexp
  79 + self
115 80 end
116 81
117   - # page.should render(input).as(output)
118   - # page.should render(input).as(output).on(url)
119   - # page.should render(input).matching(/hello world/)
120   - # page.should render(input).with_error(message)
121   - def render(input)
122   - RenderTags.new(input)
  82 + def with_error(message)
  83 + @expected_error_message = message
  84 + self
123 85 end
124 86
125   - # page.should render_as(output)
126   - def render_as(output)
127   - RenderTags.new.as(output)
  87 + def on(url)
  88 + url = test_host + "/" + url unless url =~ %r{^[^/]+\.[^/]+}
  89 + url = 'http://' + url unless url =~ %r{^http://}
  90 + uri = URI.parse(url)
  91 + @request_uri = uri.request_uri unless uri.request_uri == '/'
  92 + @host = uri.host
  93 + self
128 94 end
129 95
  96 + def with_relative_root(url="/")
  97 + @relative_root = url
  98 + self
  99 + end
  100 +
  101 + private
  102 + def render_content_with_page(tag_content, page)
  103 + page.request = ActionController::TestRequest.new
  104 + page.request.params[:sample_param] = 'data'
  105 + page.request.request_uri = @request_uri || page.url
  106 + page.request.host = @host || test_host
  107 + page.response = ActionController::TestResponse.new
  108 + if tag_content.nil?
  109 + page.render
  110 + else
  111 + page.send(:parse, tag_content)
  112 + end
  113 + end
  114 +
  115 + def test_host
  116 + "testhost.tld"
  117 + end
  118 + end
  119 +
  120 + # page.should render(input).as(output)
  121 + # page.should render(input).as(output).on(url)
  122 + # page.should render(input).matching(/hello world/)
  123 + # page.should render(input).with_error(message)
  124 + def render(input)
  125 + RenderTags.new(input)
  126 + end
  127 +
  128 + # page.should render_as(output)
  129 + def render_as(output)
  130 + RenderTags.new.as(output)
130 131 end
  132 +
131 133 end
132 134 end

0 comments on commit c6e33a2

Please sign in to comment.
Something went wrong with that request. Please try again.