[rspec-users] calls with block in views

David Chelimsky dchelimsky at gmail.com
Mon Aug 11 06:46:22 EDT 2008


On Mon, Aug 11, 2008 at 2:05 AM, Yury Kotlyarov <yura at brainhouse.ru> wrote:
> Hi!
>
> I have a view:
>
> <% restrict_to 'admin' do %>
>  <div>
>   <%= render :partial => 'detail' %>
>  </div>
> <% end %>
>
> What's the best way to spec view in this case - I just want to yield block
> in restrict_to call.

Here's one way:

it "should render detail for admin" do
  template.should_receive(:restrict_to).with('admin').and_yield
  template.expect_render(:partial => 'detail')
  render 'path/to/view'
end

it "should not render detail for non-admin" do
  template.should_receive(:restrict_to).with('admin')
  template.expect_render(:partial => 'detail').never
  render 'path/to/view'
end

Cheers,
David

>
> Thanks in advance,
> Yury
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list