我应该使用它的()吗?

时间:2014-08-14 12:31:41

标签: rspec

Rspecs its函数已被抽象为separate gem

这仅仅是为了帮助rspec的开发人员保持井井有条吗?或者its被认为是代码味?

describe '#initialize' do
    subject{ location = Location.new(longitude: 123423, latitude: 444421) }

    its(:longitude).should eq 123423
    its(:latitude).should eq 444421
end

如果its是一种气味,我该怎么写上面的?

1 个答案:

答案 0 :(得分:0)

开发者在Rspec 3中删除了its因为根据他们its经常leads to documentation output that is essentially lies

考虑这样的事情(一般例子,你必须适应你的特定需求):

describe '#conditions_apply_to?' do
  let(:product){ Fabricate :product }
  it 'returns false when combining with other conditions' do
    subject.conditions_combination_operator = 'and'
    expect(subject.conditions_apply_to?(product)).to be_false
  end
end