私はRSpecのテストと使用の初心者であり、いくつかの助けが必要です。
サンプルグループを共有しました:
shared_examples_for 'request which do something' do |opts = {}|
respond.should redirect_to(opts[:redirect_to])
end
私のスペックファイル:
describe "behavior" do
it_should_behave_like 'request which do something', :redirect_to => root_path
end
見栄えは良いですが、次のエラーが発生します。
Exception encountered: #<NameError: undefined local variable or method `root_path' for #<Class:0x000000069e2838>>
そしてそれは'it_should_behave_like...'と一致します
Rails.application.routes.url_helperをspec_helperに含めようとしましたが、とにかく機能しません。
ちなみに、次のような例から完全に機能します。
describe "behavior" do
it "should redirect" do
response.should redirect_to(root_path)
end
end
(url_helpersを明示的に含めなくても)
助けてくれてありがとう。