开发者

Can rspec test a view to make sure view syntax/helpers don't have errors?

Using rspec, is it possible to test a view to make sure all the syntax in the view doesn't have any errors?

Views call helpers, they might reference controller/action names like controller => 'blah', action => 'show' etc.

开发者_运维百科

If I rename/delete a controller I want to make sure that if my views reference them, I have a test that will fail.


A couple of things:

1) I wouldn't recommend using :controller or :action anywhere in your views, because RESTful helpers are much shorter. For instance:

:controller => :projects, :action => "show", :id => 1

vs.

project_path(1)

2) Rather than testing for syntax errors this way, have proper integration tests which test your application, performing the same actions a user would. Commonly, this is provided by RSpec+Capybara or Cucumber.


Now that we have the formalities out of the way, you can change the describe of your controller tests to this:

 describe ProjectsController
   render_views

By default, views in RSpec controller tests are stubbed out, meaning they are not accessed at all. By putting render_views inside your describe (or context) blocks, you enable this option.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜