[rspec-users] Correct way to spec partials

David Chelimsky dchelimsky at gmail.com
Sun Oct 26 08:49:58 EDT 2008


On Thu, Oct 23, 2008 at 8:07 PM, Oleksandr Rudyk <alex.rudyk at gmail.com> wrote:
> Hi everybody,
> 1) Does anybody have full working example of how to test partial templates?
> 2) What the correct place to test partials: controller or view spec? If
> controller correct place,
> should I use integrate_views?

There are basically three options (from most granular to most coarse):

1. view examples rendering the partial directly
2. view examples rendering a template that includes the partial
3. controller examples with integrate_views

In practice, I don't think I ever go for #3, and the choice between #1
and #2 is largely context-dependent. In the end you want to (or
rather, I want you to ;) ) be equally comfortable with all three
approaches, understand the pros and cons of each, and make a decision
on a case by case basis.

> 3) Is it true that expect_render is deprecated and I have to
> use should_receive(:render)

Yes!

> 4) How to test that partial's locals hash is correct?

Do you mean that the partial gets the right hash? If so, that's
something you would expect from the including template:

describe "people/edit" do
  it "should render the _form partial" do
    assigns[:groups] = mock('groups')
    template.should_receive(:render).with(:partial => "form", :locals => {
      :groups => assigns[:groups]
    }
    render "people/edit"
  end
end

HTH,
David

> Thx
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list