ruby bowling_spec.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby bowling_spec.rb相关的知识,希望对你有一定的参考价值。

require './bowling'

describe Bowling do
  describe '#score' do

		let(:game) { Bowling.new }

		it 'should start at 0' do
			game.score.should == 0
		end

		it 'should be 300 for a perfect score' do
			12.times{ game.roll(10) }
			game.score.should == 300
		end

		it 'should be 5 if my first roll is a 5' do
			game.roll(5)
			game.score.should == 5
		end

		it 'shoud be 10 if my first frame is a spare' do
			2.times { game.roll(5) }
			game.score.should == 10
		end

		it 'should be 20 if I roll three fives to start' do
			3.times { game.roll(5) }
			game.score.should == 20
		end

		it 'should be 28 if I roll 10, 5, 4 to start' do
			game.roll(10)
			game.roll(5)
			game.roll(4)
			game.score.should == 28
		end

		it 'should throw an error if you hit more than 10 pins in a frame' do
			expect {
				game.roll(7)
				game.roll(7)
			}.to raise_exception(CheaterException)
		end
	end
end

以上是关于ruby bowling_spec.rb的主要内容,如果未能解决你的问题,请参考以下文章

Ruby运算符

Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速

如何学习ruby?Ruby学习技巧分享

ruby Ruby脚本,看看是否用openssl编译了ruby

什么是ruby?

ruby和ruby ee