这可以在使用Ruby的一台机器上使用,但不能在另一台机器上使用。
码:
describe 'testing reverse string different ways' do
let :thing {'cba321'}
it 'the system method' do
source = '123abc'
result = source.reverse
expect(result).to eq 'cba321'
end
end
Run Code Online (Sandbox Code Playgroud)
错误:
SyntaxError:
/home/michael/Dropbox/90_2019/work/code/ruby__rails/ruby/reverse_string_tests_timing/test_spec.rb:12: syntax error, une
xpected '{', expecting keyword_end
let :thing {'cba321'}
^
/home/michael/Dropbox/90_2019/work/code/ruby__rails/ruby/reverse_string_tests_timing/test_spec.rb:12: syntax error, une
xpected '}', expecting end-of-input
let :thing {'cba321'}
Run Code Online (Sandbox Code Playgroud)
In Ruby 2.4.1 not having parens in the let was allowed but in Ruby 2.5.1 it is not.
So the fix is to add parens to the let, e.g.
change
let :source {'cba321'}
Run Code Online (Sandbox Code Playgroud)
to
let (:source) {'cba321'}
Run Code Online (Sandbox Code Playgroud)