Last active
June 20, 2019 14:08
-
-
Save Drowze/8b61a58bdb4e773af26319630357f713 to your computer and use it in GitHub Desktop.
RSpec bug on allow with block syntax #rspec #ruby #bug #bug-report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'rspec' | |
end | |
puts 'Ruby Version ' + RUBY_VERSION.to_s | |
puts 'RSpec version ' + RSpec::Core::Version::STRING.to_s | |
class TestClass | |
def self.test_method(client_1:); end | |
end | |
RSpec.describe 'test with expect, block syntax' do | |
it 'passes' do | |
expect(TestClass).to receive(:test_method) do |args| | |
expect(args[:client_1]).to eq 'jonas' | |
'jonas' | |
end | |
expect(TestClass).to receive(:test_method) do |args| | |
expect(args[:client_1]).to eq 'julio' | |
'julio' | |
end | |
expect(TestClass.test_method(client_1: 'jonas')).to eq 'jonas' | |
expect(TestClass.test_method(client_1: 'julio')).to eq 'julio' | |
end | |
end | |
RSpec.describe 'test with allow, without blocks' do | |
it 'passes' do | |
allow(TestClass).to receive(:test_method) | |
.with(client_1: 'jonas') | |
.and_return('jonas') | |
allow(TestClass).to receive(:test_method) | |
.with(client_1: 'julio') | |
.and_return('julio') | |
expect(TestClass.test_method(client_1: 'jonas')).to eq 'jonas' | |
expect(TestClass.test_method(client_1: 'julio')).to eq 'julio' | |
end | |
end | |
RSpec.describe 'test with allow, block syntax' do | |
it 'fails' do | |
allow(TestClass).to receive(:test_method) do |args| | |
expect(args[:client_1]).to eq 'jonas' | |
'jonas' | |
end | |
allow(TestClass).to receive(:test_method) do |args| | |
expect(args[:client_1]).to eq 'julio' | |
'julio' | |
end | |
expect(TestClass.test_method(client_1: 'jonas')).to eq 'jonas' | |
expect(TestClass.test_method(client_1: 'julio')).to eq 'julio' | |
end | |
end | |
__END__ | |
Output: | |
Ruby Version 2.5.1 | |
RSpec version 3.8.0 | |
..F | |
Failures: | |
1) test with allow, block syntax fails | |
Failure/Error: expect(args[:client_1]).to eq 'julio' | |
expected: "julio" | |
got: "jonas" | |
(compared using ==) | |
# ./minimal-rspec.rb:55:in `block (3 levels) in <top (required)>' | |
# ./minimal-rspec.rb:59:in `block (2 levels) in <top (required)>' | |
Finished in 0.03656 seconds (files took 0.2744 seconds to load) | |
3 examples, 1 failure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment