加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何测试RSPEC中的类方法

发布时间:2020-12-16 19:42:41 所属栏目:百科 来源:网络整理
导读:我写了一个简单的类方法Buy.get_days(string),并试图用不同的文本字符串输入进行测试.但是我觉得这很冗长. 有没有更简洁的方法来测试以下内容? 有没有 相当于我可以继续通过的方法的主题 不同的参数和检查结果? 有没有办法避免不必要的描述呢? 谢谢 descr
我写了一个简单的类方法Buy.get_days(string),并试图用不同的文本字符串输入进行测试.但是我觉得这很冗长.

>有没有更简洁的方法来测试以下内容?
有没有
相当于我可以继续通过的方法的主题
不同的参数和检查结果?
有没有办法避免不必要的描述呢?

谢谢

describe Buy do
   describe '.get_days' do
    it 'should get days' do
      Buy.get_days('Includes a 1-weeknight stay for up to 4 people')
      .should == 1
      end
    it 'should get days' do
      Buy.get_days('Includes a 1-night stay in a King Studio Room with stone fireplace')
      .should == 1
    end
    it 'should get days' do
      Buy.get_days('Includes 4 nights/5 days at the Finisterra Hotel for up to two adults and two children (staying in the same room)')
      .should == 4
    end
  end
end

解决方法

This是一个有趣的,但也许更钝的方式使用“主题”块与类方法.

编辑:由Wayback Archive报告的破碎的link,我认为容易受到同样的问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读