Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing rails partial views standalone

I'm using Test/Unit with a standard rails 2.1 project. I would like to be able to test Partial Views in isolation from any particular controller / action.

It seemed as though ZenTest's Test::Rails::ViewTestCase would help, but I couldn't get it working, similarly with view_test http://www.continuousthinking.com/tags/view_test

Most of the stuff Google turns up seems quite out of date, so I'm guessing doesn't really work with Rails 2.1

Any help with this much appreciated.

Thanks, Roland

like image 650
Roland Avatar asked Oct 08 '08 13:10

Roland


2 Answers

We're using RSpec in our Rails 2.1 project, and we can do this sort of thing:

describe "/posts/_form" do
  before do
    render :partial => "posts/form"
  end
  it "says hello" do
    response.should match(/hello/i)
  end
  it "renders a form" do
    response.should have_tag("form")
  end
end

However I don't know how much of that you can do with the vanilla Rails testing apparatus.

like image 116
Sam Stokes Avatar answered Oct 20 '22 23:10

Sam Stokes


Found this which may be relevant:

http://broadcast.oreilly.com/2008/10/testing-rails-partials.html

like image 45
T. Zengerink Avatar answered Oct 20 '22 22:10

T. Zengerink