Ruby中的fizz buzz代码中没有语法错误

时间:2016-02-04 20:03:32

标签: ruby rspec

无法弄清楚我的语法错误。从我的阅读来看,它期待一个结束关键字?

除了错误声明和代码之外,我还包含了测试我的代码的rspec文件。感谢所有帮助的人!

$rootScope.$on('$stateChangeSuccess', function() {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
});

RSPEC文件:

def fizzbuzz(int)
  if int % 3 == 0;
    puts "Fizz";
    if int % 5 == 0;
      puts "Buzz";
     if int % 3 && 5 == 0;
       puts "FizzBuzz"; 
end

ERROR:

require_relative './spec_helper.rb'

describe "fizzbuzz" do
  it 'returns "Fizz" when the number is divisible by 3' do
    fizz_3 = fizzbuzz(3)

    expect(fizz_3).to eq("Fizz")
  end
  it 'returns "Buzz" when the number is divisible by 5' do
    fizz_5 = fizzbuzz(5)

    expect(fizz_5).to eq("Buzz")
  end
  it 'returns "FizzBuzz" when the number is divisible by 3 and 5' do
    fizz_15 = fizzbuzz(15)

    expect(fizz_15).to eq("FizzBuzz")
  end
  it 'returns nil when the number is not divisible by 3 or 5' do
    fizz_4 = fizzbuzz(4)

    expect(fizz_4).to eq(nil)
  end
end

2 个答案:

答案 0 :(得分:0)

你需要终止你的if语句,这应该可以解决问题:

def fizzbuzz(int)
    if int % 3 == 0
        puts "Fizz"
    end
    if int % 5 == 0
        puts "Buzz"
    end
    if (int % 3 == 0) && (int % 5 == 0)
        puts "FizzBuzz"
    end
end

答案 1 :(得分:0)

你想要这样的东西:

  var chai = require('chai');
  var should = chai.should();
  var sinon = require('sinon');

  describe('BookRoute', function() {

  });

如果它是两者的倍数,则仅输出'FizzBu​​zz','Fizz'仅为3的倍数,而'Buzz'仅为5的倍数。