Comments (7)
Since new
is a class method, the stub name should have a self.
prefix.
mock TestFoo::TestClass do
stub self.new
end
But... looks like when I implemented the fix for stubbing exit
, a bug was introduced that prevents this from working.
from spectator.
Should be resolved in v0.9.40, can you verify?
Needs to be mocked by using stub self.new
(the self.
prefix is required since .new
is a class method).
from spectator.
Now I'm curious how one would stub self.new
, but have it return a copy of the class? This is to to ensure that new
is called under the hood by the class-method which one is testing, and to control the value new
returns so one can expect(instance).to receive(...)
.
from spectator.
Also having trouble stubbing File.file?
.
mock File do
stub self.file?, path : String, return_type: Bool
end
before_each do
expect(File).to receive(:file?).with("/etc/fedora-release").and_return(true)
end
it { expect(subject.linux_distro).to be(CommandKit::OS::Linux::LinuxDistro::Fedora) }
1) CommandKit::OS::Linux.linux_distro and the /etc/fedora-release file exists subject.linux_distro is CommandKit::OS::Linux::LinuxDistro::Fedora
Failure: File did not receive #file?("/etc/fedora-release") : Bool at spec/os/linux_spec.cr:22 at least once with any arguments
expected: At least once with any arguments
received: 0 time(s)
I think that error message is slightly misleading, since I'm not expecting the #file?
instance method, but the class-method.
from spectator.
The error is misleading, I think it's hard-coded to prefix stubbed method names with #
despite it being a class method.
Can you try this code with latest master
branch? There was a fix made the other day that might address it.
from spectator.
This functionality has been verified to work in the overhauled mock system. See the spec related to this issue for its implementation. This is coming in v0.11 and is currently available on master for testing.
Note that this uses inject_mock
, which is modify the existing types. They should behave the same as before, but their underlying code will have stub features added. This results in different compiled code for the type between test and non-test.
from spectator.
This issue should be resolved in v0.11. There is a spec dedicated to it. If your issue isn't resolved, please reopen this issue.
from spectator.
Related Issues (20)
- stub method(arg1,arg2,...) syntax seems to no longer work in 0.10/master HOT 3
- How to spec classes that contain class which shadow top-level primitives? HOT 4
- How to mock/stub IO::Memory#gets HOT 8
- Noticed line/column skew during incremental porting of RSpec files over to Spectator HOT 1
- Add RSpec's stub_const
- Better error when attempting to use string interpolation in it descriptions? HOT 11
- Problem with mock when using abstract class HOT 7
- Stubbed methods with default arguments not working HOT 3
- Mock not working for Process.run with block. HOT 10
- Runner filter -e tests equality instead of inclusion
- Example of custom matcher does not compile HOT 1
- Usage of keyword arguments as positional arguments in stubs HOT 1
- Mocks fail to compile for methods with free variables HOT 8
- Attempting to mock File results in error HOT 4
- Allow mocking libs
- Mocks on nameless splats HOT 2
- Re-run only failures HOT 1
- Segfault with nilable substring method call HOT 2
- `be_within` not respected during a `to have_received.with` check HOT 9
- subject with structs HOT 1
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 spectator.