开发者

RSpec/Gem development: Stubbing rails templates

I'm currently working on a couple of different gems both of which mainly consist of rails view helpers.

My problem is that some of these helpers require rendered rails templates to test the output - but I am unsure of the best way to stub a template, without a rails applicati开发者_Python百科on. I presume that I should be able to leverage rspec-rails in some capacity, but i've been having trouble getting that to work without a rails app present.

Am I approaching this the wrong way? What's the current best-practice to test rails-specific features (in particular - things that happen only in the view) during gem development?


I use the excellent enginex gem, which helps you in setting up a gem skeleton with an embedded rails application for testing. This way you can easily test any rails dependency inside that application. To generate rspec tests run it as follows (default is test-unit):

enginex -t rspec your-gem-name

What I did to incorporate this into my gem, was run this inside some test folder, and copied the necessary files over to my gem. As an example, you could check it out inside my cocoon gem.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜