Stubbing a block in rspec
There're at least two ways to stub a block in rspec, the first version is using and_yield
config = double('Config', enabled: true)
allow(app).to receive(:config).and_yield(config)
app.config do |config|
expect(config.enabled).to be_truthy
end
The second version is receiving the block
config = double('Config', enabled: true)
allow(app).to receive(:config) do |_, &block|
block.call(config)
end|
app.config do |config|
expect(config.enabled).to be_truthy
end