Class: Rspec::Rails23::Matchers::Controllers::RenderTemplate
- Inherits:
-
Object
- Object
- Rspec::Rails23::Matchers::Controllers::RenderTemplate
- Defined in:
- lib/rspec/rails23/matchers/controllers/render_template.rb
Overview
:nodoc:
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected, controller) ⇒ RenderTemplate
constructor
A new instance of RenderTemplate.
- #matches?(response_or_controller) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected, controller) ⇒ RenderTemplate
Returns a new instance of RenderTemplate.
8 9 10 11 |
# File 'lib/rspec/rails23/matchers/controllers/render_template.rb', line 8 def initialize(expected, controller) @controller = controller @expected = expected end |
Instance Method Details
#description ⇒ Object
48 49 50 |
# File 'lib/rspec/rails23/matchers/controllers/render_template.rb', line 48 def description "render template #{@expected.inspect}" end |
#failure_message ⇒ Object
40 41 42 |
# File 'lib/rspec/rails23/matchers/controllers/render_template.rb', line 40 def "expected #{@expected.inspect}, got #{@actual.inspect}" end |
#matches?(response_or_controller) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rspec/rails23/matchers/controllers/render_template.rb', line 13 def matches?(response_or_controller) response = response_or_controller.respond_to?(:response) ? response_or_controller.response : response_or_controller if response.respond_to?(:rendered_file) @actual = response.rendered_file elsif response.respond_to?(:rendered) case template = response.rendered[:template] when nil unless response.rendered[:partials].empty? @actual = path_and_file(response.rendered[:partials].keys.first).join("/_") end when ActionView::Template @actual = template.path when String @actual = template end else @actual = response.rendered_template.to_s end return false if @actual.blank? given_controller_path, given_file = path_and_file(@actual) expected_controller_path, expected_file = path_and_file(@expected) given_controller_path == expected_controller_path && given_file.match(expected_file) end |
#negative_failure_message ⇒ Object
44 45 46 |
# File 'lib/rspec/rails23/matchers/controllers/render_template.rb', line 44 def "expected not to render #{@expected.inspect}, but did" end |