Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 4071 Bytes
1 | module Spec |
2 | module Rails |
3 | module Matchers |
4 | |
5 | class RenderTags |
6 | def initialize(content = nil) |
7 | @content = content |
8 | 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: false |
18 | when @expected: @actual == @expected |
19 | when @matching: @actual =~ @matching |
20 | when @not_matching: @actual !~ @not_matching |
21 | else true |
22 | end |
23 | rescue => @actual_error |
24 | if @expected_error_message |
25 | @actual_error.message === @expected_error_message |
26 | else |
27 | @error_thrown = true |
28 | false |
29 | end |
30 | end |
31 | |
32 | def failure_message |
33 | action = case |
34 | when @expected |
35 | "render as #{@expected.inspect}" |
36 | when @not_matching |
37 | "render but not match #{@not_matching.inspect}" |
38 | else |
39 | "render and match #{@matching.inspect}" |
40 | end |
41 | unless @error_thrown |
42 | unless @expected_error_message |
43 | if @content |
44 | "expected #{@content.inspect} to #{action}, but got #{@actual.inspect}" |
45 | else |
46 | "expected page to #{action}, but got #{@actual.inspect}" |
47 | end |
48 | else |
49 | if @actual_error |
50 | "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but was #{@actual_error.message.inspect}" |
51 | else |
52 | "expected rendering #{@content.inspect} to throw exception with message #{@expected_error_message.inspect}, but no exception thrown. Rendered #{@actual.inspect} instead." |
53 | end |
54 | end |
55 | else |
56 | "expected #{@content.inspect} to render, but an exception was thrown #{@actual_error.message}" |
57 | end |
58 | end |
59 | |
60 | def description |
61 | "render tags #{@expected.inspect}" |
62 | end |
63 | |
64 | def as(output) |
65 | @expected = output |
66 | self |
67 | end |
68 | |
69 | def matching(regexp) |
70 | @matching = regexp |
71 | self |
72 | end |
73 | |
74 | def not_matching(regexp) |
75 | @not_matching = regexp |
76 | self |
77 | end |
78 | |
79 | def with_error(message) |
80 | @expected_error_message = message |
81 | self |
82 | end |
83 | |
84 | def on(url) |
85 | url = test_host + "/" + url unless url =~ %r{^[^/]+\.[^/]+} |
86 | url = 'http://' + url unless url =~ %r{^http://} |
87 | uri = URI.parse(url) |
88 | @request_uri = uri.request_uri unless uri.request_uri == '/' |
89 | @host = uri.host |
90 | self |
91 | end |
92 | |
93 | def with_relative_root(url="/") |
94 | @relative_root = url |
95 | self |
96 | 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 | ActionController::Base.relative_url_root = @relative_root |
105 | page.response = ActionController::TestResponse.new |
106 | if tag_content.nil? |
107 | page.render |
108 | else |
109 | page.send(:parse, tag_content) |
110 | end |
111 | end |
112 | |
113 | def test_host |
114 | "testhost.tld" |
115 | end |
116 | end |
117 | |
118 | # page.should render(input).as(output) |
119 | # page.should render(input).as(output).on(url) |
120 | # page.should render(input).matching(/hello world/) |
121 | # page.should render(input).with_error(message) |
122 | def render(input) |
123 | RenderTags.new(input) |
124 | end |
125 | |
126 | # page.should render_as(output) |
127 | def render_as(output) |
128 | RenderTags.new.as(output) |
129 | end |
130 | |
131 | end |
132 | end |
133 | end |