Class: RiotRails::ActionController::RendersTemplateMacro

Inherits:
Riot::AssertionMacro
  • Object
show all
Defined in:
lib/riot/action_controller/assertion_macros.rb

Overview

Asserts that the name you provide is the basename of the rendered template. For instance, if you expect the rendered template is named “foo_bar.html.haml” and you pass “foo_bar” into renders_template, the assertion would pass. If instead you pass “foo” into renders_template, the assertion will fail. Using Rails’ assert_template both assertions would pass

controlling :things
controller.renders_template(:index)
controller.renders_template("index")
controller.renders_template("index.erb") # fails even if that's the name of the template

Instance Method Summary collapse

Instance Method Details

#evaluate(actual, expected_name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/riot/action_controller/assertion_macros.rb', line 34

def evaluate(actual, expected_name)
  name = expected_name.to_s
  actual_template_path = actual.response.rendered[:template].to_s
  actual_template_name = File.basename(actual_template_path)
  if actual_template_name.to_s.match(/^#{name}(\.\w+)*$/)
    pass("renders template #{name.inspect}")
  else
    fail("expected template #{name.inspect}, not #{actual_template_path.inspect}")
  end
end