Or am I misunderstanding something?
Partial lives in:
app/views/admin/command_templates/_fillerup.html.erb
This spec passes (there is no "fill" or "_fill" in the view directory):
describe "GET fillerup" do
it "assigns some stuff and renders a partial" do
should render_template "admin/command_templates/_fill" # I expected failure
should render_template "admin/command_templates/_fillerup" # "Correct" test
end
end
This fails (as I expect):
describe "GET fillerup" do
it "assigns some stuff and renders a partial" do
should render_template "admin/command_templates/_fillerupp" # extra "p"
end
end
It acts like it's doing a start_with?
on the path, perhaps to ignore extensions, or...?
rspec-rails 2.7.0, rails 3.1.2; other info available on request.
Verifying the behavior exists (or doesn't) would be helpful as a sanity check.
Check out the code for render_template
- many of those methods do pattern matching via regex, which is going to match similarly to a starts_with?
, at least in the same sense that the pattern "Joe" is going to match the string "Joe Smith", and "Joe Blank". I'm not doing the pattern matching justice here, but this is just an example.
Pattern matching this way is mostly for convenience, as I understand it, so you don't have to be overly specific in your tests, which makes your test framework a little less brittle. You can typically get away with this without worrying, because templates often don't have names that are so similar.
If you need to match only a specific template (and not the other) you can add an additional conditional test, something like:
should render_template('x')
should_not render_template('xy')
...or something similar, which should effectively filter out templates that start with similar names, but which are not the templates in which you are interested.