开发者

Is it possible to test a view page if the form_tags are correct?

Using rspec or similiar, is it possible to test a view page that the template logic is correct?

e.g. say my Model changes, and my form tag helpers are referencing a model property that doesn't exist anymore or was renamed.

Can I test render the template to se开发者_JAVA百科e if it breaks?


When you browse through RSpec documentation, you will notice that it is very insisting on model, view and controller tests being kept separate and with minimum interaction between tests of different layers (heavily relying on mocking instead). The way all your layers fit together falls more into the integration testing domain. If you have a decent suite of integration tests set up, you will inevitably notice when you break something that has an effect on another layer like in the example you described.

You could do integration testing of this kind with RSpec (have a look at integration mode in the RSpec documentation), but it's rather tedious and plain ugly:

response.should have_tag("input[name=?]", "foo")

Integration mode will invoke your controller and render the relevant view, at which point it will become obvious if the view refuses to render because it calls a non-existent model method (in that case, it wouldn't even matter what you have in your view test).

Or you could go the Cucumber/Steak/etc route (which is probably a better idea in the long run).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜