Comments (6)
before(:all) should not work, but before(:each) should.
from rspec-mocks.
Thanks, confirming that before(:each) do work. Have no idea how I managed to being able to make it fail with the code I pasted above. Maybe I didn't manage to save file after changing before(:all) to :each or something stupid. Oh my fault. Thanks again! :-)
from rspec-mocks.
If it is possible to support before(:all), I think this issue should be re-opened. If it's just not possible, please add a runtime warning, or add a note to that effect in the docs.
https://www.relishapp.com/rspec/rspec-mocks/v/2-9/docs/method-stubs/stub-on-any-instance-of-a-class
from rspec-mocks.
👍
I agree, this is very confusing, there should be a warning.
from rspec-mocks.
Nothing mocking related should be done in a before(:all)
. These docs cover it: https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/scope
from rspec-mocks.
A random thought I just had: if we can come up with good solutions for both rspec/rspec-core#573 and #153, we can get things to a point where users aren't even allowed to try to setup a mock or stub in before(:all)
, which would help reduce the confusion here. Consider that if we replace before(:all)
with a new construct (e.g. before(:group)
) which doesn't share state, it's fairly intuitive that before(:group)
blocks aren't eval'd in the same context as examples. Combine that with a new syntax for mocking that doesn't globally add methods to objects that allow them to be mocked or stubbed from anywhere but rather only makes mocking available by wrapping an object with on
, allow
, expect
or something similar...and we can make those methods only available in the example and before(:each)
contexts, but not the before(:group)
context.
It's something to consider, at least.
from rspec-mocks.
Related Issues (20)
- Expecting kwargs does not work in Ruby 3.2. HOT 15
- and_wrap_original doesn't work with kwargs in Ruby 3.2 HOT 3
- array_excluding matcher? HOT 2
- Rails 7.1 breaks receive().with HOT 6
- Assertion that Array#reverse is not called always fails
- stub_const doesn't work with constant inside `class << self` block HOT 3
- update repository 'About' setting to use rspec.info docs url instead of Relish
- Mocking methods changes `Method#parameters`. HOT 1
- Keyword args not validated HOT 1
- RSpec 3.11 mistakes kwargs for hash, when `verify_partial_doubles` is set to true HOT 4
- stub_const does not restore Object.const_source_location after reset HOT 3
- doc: broken links (404) on rspec.info HOT 6
- hash_including deviates from a_hash_including HOT 1
- (Fixed in `3.13.0pre`) `ActiveSupport`'s `Object#with` core extension overrides `RSpec::Mocks::Matchers::Receive(Object)#with` HOT 1
- facing issue with rspec-mocks test cases HOT 1
- `stack level too deep` when stubbing :is_a? with allow_any_instance_of
- `stack level too deep` when stubbing :is_a? with allow_any_instance_of
- `stub_const` doesn't clear `Class#subclasses` HOT 15
- and_wrap_original failing in ruby 3.2
- Mutex cannot be mocked since 3.9.0 (Stack level too deep) HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rspec-mocks.