Я заметил, что ответ Мэтта был 2 года назад, я не уверен, какую версию "rspec" он использовал.
но для моего случая моя версия rspec = 1.3.2, и сегмент кода не работает (всегда появляется ошибка:
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/configuration.rb:181:in `__send__'
from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/configuration.rb:181:in `add_callback'
from /usr/lib/ruby/gems/1.8/gems/rspec-1.3.2/lib/spec/runner/configuration.rb:101:in `before'
...
), пока я немного не изменю:
# here the ":each" symbol is very important and necessary.
# :type => :controller is the "option"
config.before(:each, :type => :controller) do
request.env["HTTP_REFERER"] = "/"
end
см. Документацию по rspec-1.3.2:
append_before(scope = :each, options={}, &proc)
Appends a global before block to all example groups. scope can be any of
:each (default), :all, or :suite.
When :each, the block is executed before each example.
When :all, the block is executed once per example group, before any of its examples are run.
When :suite the block is run once before the entire suite is run.