I want to test rendering a particular partial according to some conditions.
For example, in model show action view show.html.erb
I have:
<% if condition1 %> <%= render :partial => "partial1" %> <% else %> <%= render :partial => "partial1" %> <% end %>
I tried:
response.should render_template("partial_name")
but it tells that it rendered "show" template
expecting <"partial1"> but rendering with <"model/show, layouts/application">
What I am doing wrong?
Running tests by their file or directory names is the most familiar way to run tests with RSpec. RSpec can take a file name or directory name and run the file or the contents of the directory. So you can do: rspec spec/jobs to run the tests found in the jobs directory.
RSpec is a Behavior-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.
Ruby on Rails Views Partials Partial templates (partials) are a way of breaking the rendering process into more manageable chunks. Partials allow you to extract pieces of code from your templates to separate files and also reuse them throughout your templates.
RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.
Also try this
response.should render_template(:partial => 'partial_name')
Latest rspec version suggest to use expect
syntax rather than should
:
expect(response).to render_template(partial: 'partial_name')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With