public
Created

  • Download Gist
at_least_n_times.spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 
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
output.2.09.0.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 
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
output.2.10.0.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.