嗨,我是 Fly,用 Ruby 寫 Chatbot 並挑戰30天分享心得
為確保不會沒靈感
每日含 Ruby 主題文章增加內容
https://github.com/leo424y/clean-code-ruby
推薦工具 good coverage tool.
Bad:
require 'rspec'
describe 'Calculator' do
let(:calculator) { Calculator.new }
it 'performs addition, subtraction, multiplication and division' do
expect(calculator.calculate('1 + 2')).to eq(3)
expect(calculator.calculate('4 - 2')).to eq(2)
expect(calculator.calculate('2 * 3')).to eq(6)
expect(calculator.calculate('6 / 2')).to eq(3)
end
end
Good:
require 'rspec'
describe 'Calculator' do
let(:calculator) { Calculator.new }
it 'performs addition' do
expect(calculator.calculate('1 + 2')).to eq(3)
end
it 'performs subtraction' do
expect(calculator.calculate('4 - 2')).to eq(2)
end
it 'performs multiplication' do
expect(calculator.calculate('2 * 3')).to eq(6)
end
it 'performs division' do
expect(calculator.calculate('6 / 2')).to eq(3)
end
end