changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb

changeset 16: 01fd3f10ae84
author: moriq@moriq.com
date: Mon Mar 10 10:13:18 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec_on_rails
1module Spec
2 module Rails
3 module Matchers
4
5 class RenderTemplate #:nodoc:
6
7 def initialize(expected, controller)
8 @controller = controller
9 @expected = expected
10 end
11
12 def matches?(response)
13 @actual = response.rendered_file
14 full_path(@actual) == full_path(@expected)
15 end
16
17 def failure_message
18 "expected #{@expected.inspect}, got #{@actual.inspect}"
19 end
20
21 def negative_failure_message
22 "expected not to render #{@expected.inspect}, but did"
23 end
24
25 def description
26 "render template #{@expected.inspect}"
27 end
28
29 private
30 def full_path(path)
31 return nil if path.nil?
32 path.include?('/') ? path : "#{@controller.class.to_s.underscore.gsub('_controller','')}/#{path}"
33 end
34
35 end
36
37 # :call-seq:
38 # response.should render_template(path)
39 # response.should_not render_template(path)
40 #
41 # Passes if the specified template is rendered by the response.
42 # Useful in controller specs (integration or isolation mode).
43 #
44 # <code>path</code> can include the controller path or not. It
45 # can also include an optional extension (no extension assumes .rhtml).
46 #
47 # Note that partials must be spelled with the preceding underscore.
48 #
49 # == Examples
50 #
51 # response.should render_template('list')
52 # response.should render_template('same_controller/list')
53 # response.should render_template('other_controller/list')
54 #
55 # #rjs
56 # response.should render_template('list.rjs')
57 # response.should render_template('same_controller/list.rjs')
58 # response.should render_template('other_controller/list.rjs')
59 #
60 # #partials
61 # response.should render_template('_a_partial')
62 # response.should render_template('same_controller/_a_partial')
63 # response.should render_template('other_controller/_a_partial')
64 def render_template(path)
65 RenderTemplate.new(path.to_s, @controller)
66 end
67
68 end
69 end
70end