rspec/rspec-rails — pull request #833 by JonRowe (2013-10-09 09:58:04+00:00)
Title: Cannot stub view methods in before blocks (undefined method `view_context' for nil:NilClass)

After upgrading rspec to 2.14 we started to get the errors:

```
1) campaigns/new
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `view_context' for nil:NilClass
# ./spec/support/sign_in_utils.rb:8:in `block (2 levels) in '
```

The reason [seem to be that it is not possible to stub view methods](http://stackoverflow.com/questions/15066417/view-stub-in-rails-partial-rspec-gives-undefined-method-view-context) from `before` blocks.

This is complete support file:

```ruby
# spec/support/sign_in_utils.rb

RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller

config.before(:each, type: :view) do
# RSpec doesn't expose the helper methods to the views
# so just stubbing it.
# Need to re-stub if we actually care about it in the specs
view.stub(current_company: nil, current_user: nil)
view.stub(current_currency: stub_model(Currency))
view.stub(current_portal: Portals::NoPortal.new)
end
end
```