Tag: rspec3

RSpec中“be_true”和“be true”之间的区别是什么?

任何人都be true通过简单的例子向我解释be_true与Ruby之间的区别。 我也看到be_true和be_false被改为be_truthy和be_falsey 我有一个’be true’工作的例子,但是当我尝试使用’be_true’或’be_truthy’规格失败了。 我使用RSpec版本3.1.7

RSpec允许/期望vs期望/和_return

在RSpec中,特别是版本> = 3,之间有什么区别: 使用allow来设置返回测试双精度的参数的消息期望,然后使用expect对返回的测试双精度进行断言 只需使用expect来设置参数的期望并返回测试double 或者只是语义学? 我知道提供/指定带有expect的返回值是RSpec模拟2.13中的语法 ,但据我所知,RSpec模拟3中的语法改变为使用allow 。 但是,在下面的(传递)示例代码中,使用allow / expect或者只是expect / and_return似乎会生成相同的结果。 如果一种语法比另一种更受欢迎,也许我会期望有某种弃用通知,但由于没有,似乎两种语法都被认为是有效的: class Foo def self.bar(baz) # not important what happens to baz parameter # only important that it is passed in new end def qux # perform some action end end class SomethingThatCallsFoo def some_long_process(baz) # do some processing Foo.bar(baz).qux # […]

rspec失败错误:假设错误响应`false?`

我正在运行这部分测试: describe Dictionary do before do @d = Dictionary.new end it ‘can check whether a given keyword exists’ do @d.include?(‘fish’).should be_false end 使用此代码: class Dictionary def initialize @hash = {} end def add(new_entry) new_entry.class == String ? @hash[new_entry] = nil : new_entry.each { |noun, definition| @hash[noun] = definition} end def entries @hash end def keywords […]