Comments (8)
Heads up, this is changing in v0.11. Instead of relying on stubs, exit
will raise a Spectator::SystemExit
error. This mimics what RSpec does. See the related spec for this issue for an example.
from spectator.
It seems that Spectator isn't stubbing the exit method. There needs to be a stub defined prior to calling receive(:exit)
. For instance:
class SomeClass
def goodbye
exit
end
end
mock SomeClass do
stub exit
end
it "captures exit" do
expect(subject).to receive(:exit).with(0)
subject.goodbye
end
This code doesn't work though, since exit
isn't defined in SomeClass
- it's a top-level method. Another issue is that a type is required for the mock
block, but there isn't one for a top-level method. (maybe Object
?)
Do you have any code that shows this in action in RSpec?
from spectator.
Code: https://github.com/postmodern/command_kit/blob/a06a131ddde42fa7f7730debbdc66136282bae1f/lib/command_kit/main.rb#L46-L56
RSpec specs: https://github.com/postmodern/command_kit/blob/a06a131ddde42fa7f7730debbdc66136282bae1f/spec/main_spec.rb#L28-L100
from spectator.
This should be possible in v0.9.39 - Can you try it out and confirm?
The following spec works:
require "../spec_helper"
Spectator.describe "GitHub Issue #29" do
class SomeClass
def goodbye
exit 0
end
end
mock SomeClass do
stub exit(code)
end
describe SomeClass do
it "captures exit" do
expect(subject).to receive(:exit).with(0)
subject.goodbye
end
end
end
from spectator.
Ah, stubbing/capturing exit now works on instances, but not at the class-level. I'm guessing mock
/stub
is assuming exit
is an instance method?
require "./spec_helper"
Spectator.describe "test exit" do
class Foo
def self.test
exit 0
end
end
mock Foo do
stub exit(code)
end
subject { Foo }
it "must capture exit" do
expect(subject).to receive(:exit).with(0)
subject.test
end
end
$ crystal spec spec/test_spec.cr
test exit
from spectator.
I think I see why this is happening. I'll try to get a fix in.
from spectator.
Should be resolved in v0.9.40, can you verify?
For class methods that call exit
, it will need to stub self.exit(code)
.
from spectator.
Confirmed self.exit(code)
works.
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.