Skip to content

@lsegal /at_least_n_times.spec.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'rspec'
describe 'at_least(n).times' do
# Pass
it 'RSpec 2.9.0+ allows at_least(N).times when N > 0' do
mymock = mock
mymock.should_receive(:run).at_least(1).times
mymock.run
mymock.run
end
# Fail
it 'RSpec 2.9.0+ does *not* allow at_least(N).times when N = 0' do
mymock = mock
mymock.should_receive(:run).at_least(0).times
mymock.run
end
# Pass
it 'RSpec 2.10.0 allows at_least(N).times when N = 0 if .and_return is added' do
mymock = mock
mymock.should_receive(:run).at_least(0).times.and_return(true)
mymock.run.should be_true
end
end
Desktop$ gem install rspec -v 2.9.0
Fetching: rspec-core-2.9.0.gem (100%)
Fetching: rspec-expectations-2.9.1.gem (100%)
Fetching: rspec-mocks-2.9.0.gem (100%)
Fetching: rspec-2.9.0.gem (100%)
Successfully installed rspec-core-2.9.0
Successfully installed rspec-expectations-2.9.1
Successfully installed rspec-mocks-2.9.0
Successfully installed rspec-2.9.0
4 gems installed
Desktop$ rspec -v
2.9.0
Desktop$ rspec at_least_n_times.spec.rb
.FF
Failures:
1) at_least(n).times RSpec 2.9.0+ does *not* allow at_least(N).times when N = 0
Failure/Error: mymock.run
(Mock).run(no args)
expected: 0 times
received: 1 time
# ./at_least_n_times.spec.rb:16:in `block (2 levels) in <top (required)>'
2) at_least(n).times RSpec 2.9.0+ allows at_least(N).times when N = 0 if .and_return is added
Failure/Error: mymock.run.should be_true
(Mock).run(no args)
expected: 0 times
received: 1 time
# ./at_least_n_times.spec.rb:23:in `block (2 levels) in <top (required)>'
Finished in 0.00131 seconds
3 examples, 2 failures
Failed examples:
rspec ./at_least_n_times.spec.rb:13 # at_least(n).times RSpec 2.9.0+ does *not* allow at_least(N).times when N = 0
rspec ./at_least_n_times.spec.rb:20 # at_least(n).times RSpec 2.9.0+ allows at_least(N).times when N = 0 if .and_return is added
Desktop$ gem install rspec
Fetching: rspec-core-2.10.0.gem (100%)
Fetching: rspec-expectations-2.10.0.gem (100%)
Fetching: rspec-mocks-2.10.0.gem (100%)
Fetching: rspec-2.10.0.gem (100%)
Successfully installed rspec-core-2.10.0
Successfully installed rspec-expectations-2.10.0
Successfully installed rspec-mocks-2.10.0
Successfully installed rspec-2.10.0
4 gems installed
Desktop$ rspec -v
2.10.0
Desktop$ rspec at_least_n_times.spec.rb
.F.
Failures:
1) at_least(n).times RSpec 2.9.0+ does *not* allow at_least(N).times when N = 0
Failure/Error: mymock.run
(Mock).run(no args)
expected: 0 times
received: 1 time
# ./at_least_n_times.spec.rb:16:in `block (2 levels) in <top (required)>'
Finished in 0.00352 seconds
3 examples, 1 failure
Failed examples:
rspec ./at_least_n_times.spec.rb:13 # at_least(n).times RSpec 2.9.0+ does *not* allow at_least(N).times when N = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.