rspec/rspec-mocks — pull request #449 by samphippen (2013-11-02 15:13:59+00:00)
Title: Initial implementation of warning in before(:all) blocks

So this works, but I'm not sure I like the implementation.

The nice thing is that it doesn't talk to RSpec core at all and achieves the desired behaviour (I believe). On the minus side it requires tracking more state and because we can't do message expectations in before blocks I've had to stub Kernel.warn manually, also I'm not sure if the RSpec::Mocks class itself is the right place to track this state.

I'd love some design feedback here, it's a little rough and ready, but it definitely solves the problem.

An example of what it looks like when running outside of RSpec's own test suite:

```
(warn-stubbing-before-all)$ ber --color hi_spec.rb
/Users/sam/dev/rspec/rspec-dev/repos/rspec-support/lib/rspec/support/warnings.rb:28: warning: method redefined; discarding old warning
/Users/sam/dev/rspec/rspec-dev/repos/rspec-core/lib/rspec/core/warnings.rb:25: warning: previous definition of warning was here
/Users/sam/dev/rspec/rspec-dev/repos/rspec-support/lib/rspec/support/warnings.rb:35: warning: method redefined; discarding old warn_with
/Users/sam/dev/rspec/rspec-dev/repos/rspec-core/lib/rspec/core/warnings.rb:32: warning: previous definition of warn_with was here
/Users/sam/dev/rspec/rspec-dev/repos/rspec-mocks/lib/rspec/mocks.rb:19: warning: instance variable @usable not initialized
WARNING: calling stub on objects in `before(:all)` blocks is unsupported. Consider using `let` or `before(:each)` instead. Called from /Users/sam/dev/rspec/rspec-dev/repos/rspec-mocks/hi_spec.rb:5:in `block (2 levels) in '.
F

Failures:

1) qwoifej return nil
Failure/Error: Foo.find.should eq(nil)
NoMethodError:
undefined method `find' for Foo:Class
# ./hi_spec.rb:9:in `block (2 levels) in '

Finished in 0.00059 seconds
1 example, 1 failure

Failed examples:

rspec ./hi_spec.rb:8 # qwoifej return nil
```