我一直在为 Controller 和模型编写规范,但我从未编写过辅助规范。我不知道从哪里开始。
我在 application_helper.rb
中有以下片段
def title(page_title)
content_for(:title) { page_title }
end
- 我应该如何编写代码的辅助规范?
- 此外,如果有任何开源 Rails 应用程序可以显示良好的辅助测试/规范,请告诉我。
最佳答案
来自rspec-rails docs on Helper Specs :
Helper specs live in spec/helpers, and mix in ActionView::TestCase::Behavior.
Provides a helper object which mixes in the helper module being spec'd, along with ApplicationHelper (if present).
require 'spec_helper'
describe ApplicationHelper do
describe "#title" do
it "displays the title" do
# helper is an instance of ActionView::Base configured with the
# ApplicationHelper and all of Rails' built-in helpers
expect(helper.title).to match /Some Title/
end
end
end
关于ruby-on-rails - 使用 Ruby on Rails 和 RSpec 为 helper 编写规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1996757/