Permalink
Browse files

Merge pull request #7659 from HugoLnx/template_error_no_matches_rebased

REBASED: fixing assert_template bug when template matches expected, but not ends with
  • Loading branch information...
2 parents f655108 + 19dff78 commit d0d02bffe8dd12dcb2d113a60a6790d7a88e78be @rafaelfranca rafaelfranca committed Sep 30, 2012
@@ -1,5 +1,21 @@
## Rails 4.0.0 (unreleased) ##
+* `assert_template` no more passing with what ever string that matches.
+
+ Given Im rendering an template `/layout/hello.html.erb`, assert_template was
+ passing with any string that matches. This behavior allowed false passing like:
+
+ assert_template "layout"
+ assert_template "out/hello"
+
+ Now the passing possibilities are:
+
+ assert_template "layout/hello"
+ assert_template "hello"
+
+ *Hugolnx*
+
+
* `image_tag` will set the same width and height for image if numerical value
passed to `size` option.
@@ -86,16 +86,23 @@ def assert_template(options = {}, message = nil)
response.body
case options
- when NilClass, String, Symbol, Regexp
+ when NilClass, Regexp, String, Symbol
options = options.to_s if Symbol === options
rendered = @templates
msg = message || sprintf("expecting <%s> but rendering with <%s>",
options.inspect, rendered.keys)
- matches_template =
- if options
+ matches_template =
+ case options
+ when String
+ rendered.any? do |t, num|
+ options_splited = options.split(File::SEPARATOR)
+ t_splited = t.split(File::SEPARATOR)
+ t_splited.last(options_splited.size) == options_splited
+ end
+ when Regexp
rendered.any? { |t,num| t.match(options) }
- else
- @templates.blank?
+ when NilClass
+ rendered.blank?
end
assert matches_template, msg
when Hash
@@ -7,6 +7,7 @@ class ActionPackAssertionsController < ActionController::Base
def nothing() head :ok end
def hello_world() render :template => "test/hello_world"; end
+ def hello_repeating_in_path() render :template => "test/hello/hello"; end
def hello_xml_world() render :template => "test/hello_xml_world"; end
@@ -464,13 +465,34 @@ def test_fails_with_incorrect_string
end
end
+ def test_fails_with_incorrect_string_that_matches
+ get :hello_world
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template 'est/he'
+ end
+ end
+
+ def test_fails_with_repeated_name_in_path
+ get :hello_repeating_in_path
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template 'test/hello'
+ end
+ end
+
def test_fails_with_incorrect_symbol
get :hello_world
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_template :hello_planet
end
end
+ def test_fails_with_incorrect_symbol_that_matches
+ get :hello_world
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template :"est/he"
+ end
+ end
+
def test_fails_with_wrong_layout
get :render_with_layout
assert_raise(ActiveSupport::TestCase::Assertion) do
@@ -0,0 +1 @@
+Hello world!

0 comments on commit d0d02bf

Please sign in to comment.